ASP.net Unit tests and web application set up using a header.

I have tried to use ASP.net unit tests against a web appilcation. The web applications URL looks somthing like, vdir.localhost.domain.com.

IE is able to access the website, no problem. But the unit tests are unable to find the directory. I notice that none of the help files discuss testing against a web application that has been created using host headers. The question is, is it posible to test a web application using host headers If so, what might I be doing wrong

Thanks guys!!

Dan




Answer this question

ASP.net Unit tests and web application set up using a header.

  • raj more

    Since I haven't been able to reproduce this myself, I don't think I'll be able to come up with anything else while you're not working on it. But if you do get back to this and can provide more information, go ahead and respond to this thread again. For now, I'm going to mark this thread as answered, even though it technically isn't--we use unanswered posts to keep track of active questions, so otherwise it will keep showing up on our lists when we can't do anything about it. If you do post again, you should be able to mark that response as a question (you may need to post first and then edit it to change the attribute), which will bring it to my attention again. It's too bad we couldn't figure out the problem more easily, but hopefully we can get to the bottom of it if you have a chance to get back to this later.


  • simian

    Hi Kevin,

    Sorry for taking so long to get back.

    Here is the URL, from the browser that returns the correct page, (using examples)

    http://linkformatgix.name1.domain.com/

    here is the Error message from the ASP.net Unit test that uses this exact url.

    The URL specified (http://linkformatgix.name1.domain.com/) does not correspond to a valid directory. Tests configured to run in ASP.NET in IIS require a valid directory to exist for the URL. The URL may be invalid or may not point to a valid web application.

    Using http://linkformatgix/ as the urlToTest attribute along with another host header of linkformatgix allows the unit test to find the site.

    In my host file I have the following settings...

    127.0.0.1 linkformatgix linkformatgix.name1.domain.com



  • Steve of Easyget.biz

    I'm having the same problem and would like to pickup the conversation.

    The problem:

    When I run the unit test I've created it fails with the following
    message,


    The URL specified http://dev.domain.com/aeden/project does not correspond to a valid directory. Tests
    configured to run in ASP.NET in IIS require a valid directory to exist
    for the URL. The URL may be invalid or may not point to a valid web
    application.


    Background:

    Facts about the dev server

    * Windows 2003
    * No host headers used

    My dev machince is

    * Windows XP
    * VSTS Team Suite

    I'm able to browse to the url in the UrlToTest attribute.


    The Test:

    <TestClass()> _
    Public Class PageTest


    Private testContextInstance As TestContext


    '''<summary>
    '''Gets or sets the test context which provides
    '''information about and functionality for the current test run.
    '''</summary>
    Public Property TestContext() As TestContext
    Get
    Return testContextInstance
    End Get
    Set(ByVal value As TestContext)
    testContextInstance = value
    End Set
    End Property


    <DeploymentItem("<SomeProgram.DLL>")> _
    <TestMethod()> _
    <HostType("ASP.NET")> _
    <UrlToTest("http://dev.domain.com/aeden/project/")> _
    Public Sub VerifyInitialLayout()
    Dim target As TestPage = New TestPage
    Dim accessor As PageAccessor = PageAccessor(target)


    Assert.Inconclusive("A method that does not return a value
    cannot be verified.")
    End Sub


    End Class


    Thanks for your time.


    Cheers,
    Aeden


  • sgollapu

    Hi Guys,

    Thanks for your interest. I am not sure when I am going to get time on this again. But yes, if it is something that I have set up incorrectly I would sure like to know. It would make life a lot easier around here.

    I haven't been doing anywork with our web classes as of late, so I don't know when I will get a chance to work at this again.

    I am currently trying to force a winform UI to behave nicely with threads in the load test feature. Ha ha ha ha .... ( I am not saying this to start a new thread by the way. I just want you all to feel sorry for me. )

    Hope to talk again soon!

    dan



  • chint

    Hi Kevin,

    Most of the time, I should be able to use the virtual directory name. The only time that it may not work is when the code itself is trying to map path based on the server. some of the older code here doesn't take into account how the website is running and expects all pages to be hosted by an application.

    No proxies. yes, I am using the value all unasigned for the host header value IP address. So, I guess the next couple questions is did I set up the host header correctly.

    Here is what I have setup for host headers in IIS. (I have tried both with and without the short name)

    linkformatgix.SEAW50681.gettyimages.com, port 80 , all unassigned.

    linkformatgix, port 80, all unassigned.

    In my host file..

    127.0.0.1 linkformatgix linkformatgix.SEAW50681.gettyimages.com

    The name of the file directory is linkformatgix.



  • ysfbil

    How about the physical directory structure for your IIS sites  Is linkformatgix located under wwwroot, or is it elsewhere
  • Radek Matej

    I've yet to be able to reproduce the problem on my machine, so I figure there must be some subtle configuration difference that we're not aware of. As stated earlier, we didn't specifically work to support host headers, so it's possible you've hit some scenario that simply isn't going to work--but I'd definitely like to figure out what that scenario is so we can possibly support it in the future and at least figure out a workaround for now. I'm not sure that there's much I can do from here right now, though, without a setup that reproduces this. Is there anything else unusual or interesting about your configuration of IIS, ASP.NET, etc. that you haven't already mentioned I may be able to poke at this a bit more if I have an idea of what settings may be different.

    If you have time, you may want to try recreating this scenario for a simpler test site of your own to see if it always fails for you. You could also try on another machine if you have one available to see if that works. If you see success in any case, you can compare and adjust the configurations to find what's different and may be relevant. Let me know if you come up with anything.


  • dpage2006

    Now it's my turn to apologize for taking so long to respond. Anyway, I still haven't been able to reproduce this on a simple setup, and both URLs are working correctly in the test for me. I wonder--do you go through a proxy to connect to the Internet This shouldn't matter since everything is on the local machine and the hosts file should prevent linkformatgix.name1.domain.com from ever trying to get to an external site, but there may be some way it could be relevant. Also, I assume your host headers are set to use all unassigned IP addresses, right Again, I don't think this should matter given what is working, but I want to make sure.

    If we're not able to figure this out, will you be able to just use linkformatgix instead of linkformatgix.name1.domain.com for your tests, since that is working


  • samForASP

    Hi Kevin,

    Thanks for your response. My answers are in line and off the top of my head until I get back to work on Monday.

    • This site is hosted in local IIS, right (just to be absolutely sure)
    • Yes, it is in IIS.
    • What's the text of the error message you get
    • I don’t remember, something to the effect that it can’t find the directory. When I get to work on Monday, I will rerun it and paste the full error message in the forum.
    • What version of Windows/IIS are you using (Windows 2000 = IIS 5.0, Windows Server 2003 = IIS 6.0)
    • Windows server 2003. IIS 6
    • Does the URL in the UrlToTest attribute exactly match the one you see in IE If not, does changing it help
    • Yes. When I use only the virtual directory name, it seems to find it. I will investigate this further when I get to work on Monday.
    • If it's feasible to check--does the same site work normally when not using host headers (changing as little else about the setup as possible)
    • Yes, unfortunately, the code is written to expect the path in an application. Our newer code will have this dependency removed.

    Thanks Again!!

    Dan



  • Jorge Gomez

    It is under wwwroot

  • Valentin

    Host headers aren't something that we explicitly worked to support in this version, so I can't guarantee that you'll be able to get this working. However, I was able to successfully run a test against a website using host headers in a basic case. To help figure out what might be going wrong, can you answer:

    • This site is hosted in local IIS, right (just to be absolutely sure)
    • What's the text of the error message you get
    • What version of Windows/IIS are you using (Windows 2000 = IIS 5.0, Windows Server 2003 = IIS 6.0)
    • Does the URL in the UrlToTest attribute exactly match the one you see in IE If not, does changing it help
    • If it's feasible to check--does the same site work normally when not using host headers (changing as little else about the setup as possible)

    As I said, I only tried a simple case, so it's possible there are complexities in your scenario that cause this to fail. Any information you can provide will 1) help determine if there's a way to fix this now, and 2) at least help us figure out what we may need to do to better support this in future versions.


  • Andrej Zeleznik

    • Does the URL in the UrlToTest attribute exactly match the one you see in IE If not, does changing it help
    • Yes. When I use only the virtual directory name, it seems to find it. I will investigate this further when I get to work on Monday.

    Can you post the exact URL that works and the one that doesn't If you were able to get it working in one case, then the problem may be related to the difference between the two.


  • ASP.net Unit tests and web application set up using a header.