Re: unit testing in visual studio

2010-02-25 Thread silky
Well, I believe you can read the current random port that it wants
to use from the config (so if you desired, you could do that).

However, you should be able to simply change the project properties so
that instead of using the inbuilt asp.net webservice, it uses your
local IIS one. Infact, you can just set the port in the same
properties area (right click the web project, select Properties go
to the Web tab).




On Fri, Feb 26, 2010 at 12:27 PM, Geoff Appleby geoff.appl...@gmail.com wrote:
 I've got a weird situation going on. Hopefully someone knows which
 (probably simple) button to click to do to get it working the way i
 want it.

 I've got a largish solution full of different projects. also part of
 the solution is a set of testing projects. one of the projects in the
 solution is a web service (simple boring web service, not wcf or
 anything). the web service project is set to, when debugging etc, use
 the asp net file system based development web server, and is set to
 always start listening on the same port (say, ). and that works
 fine and when just running in the debugger everything is good and the
 web service gets called on port .

 When i run unit tests, however, it somehow knows there's a web
 service involved - and it starts the web service, but starts it on a
 random port. All well and good, except that all my code that in the
 other projects that call the web wervice pull the url to use from the
 app.config file that specifies the port of . End result - all the
 calls to the web service fail because its been started on some other
 port.

 Interestingly, i've noticed two strange behaviours:
 1) if i manually start a new debugging instance of the web service, it
 will start on . If i leave it running and then start the unit
 tests, it ALSO starts teh web service on a random port, but the tests
 i have that call code that invokes web service succeed because it can
 connect on .
 2) one of my tests, so far, test a function that lives INSIDE the web
 service and relies on a the HttpContext object. Iv'e decorated this
 unit test saying HostType(ASP.NET),
 AspNetDevelopmentServerHost(file system path to the web service) and
 UrlToTest(http://localhost:/WebForm1.aspx;) ... and it happily
 runs the test inside the file system web server...on the RANDOM port,
 not port  - which means the test always succeeds, regardless of
 point 1) above.

 I've read up on the webtesthelper.redirecturl (or words to that
 effect) helper class, but that's no good because it works on a web
 service reference object - and in my case the web service reference
 object is buried deep within a class library - my test is calling a
 public method on the class library that internally instantiates teh
 web service object and invokes it, all based on config file values.


 so in short - anyone know how to stop the test engine starting the web
 service on a random port, but to start it on a fixed port instead?


 --
 Geoff Appleby
 Blog: http://blogs.crankygoblin.com/blogs/geoff.appleby/




-- 
silky

  http://www.programmingbranch.com/


Re: unit testing in visual studio

2010-02-25 Thread Geoff Appleby
But you're pretty fool. 
--Original Message--
From: silky
To: Geoff Appleby
Cc: ausDotNet
ReplyTo: michaelsli...@gmail.com
Subject: Re: unit testing in visual studio
Sent: Feb 26, 2010 14:45

On Fri, Feb 26, 2010 at 2:46 PM, Geoff Appleby geoff.appl...@gmail.com wrote:
 Heh.

I'm a fool.

 I've already set the port that way. And that works in all cases _except_ when 
 launching unit tests.


-- 
silky

  http://www.programmingbranch.com/


Sent from my BlackBerry Storm


Re: unit testing in visual studio

2010-02-25 Thread silky
On Fri, Feb 26, 2010 at 2:50 PM, Geoff Appleby geoff.appl...@gmail.com wrote:
 But you're pretty fool.

...

So, what system are you using to run the unit tests though? Test Driven.NET?

I'm now slightly intrigued as to why it's randomly changing the port on you.

-- 
silky

  http://www.programmingbranch.com/


Re: unit testing in visual studio

2010-02-25 Thread Geoff Appleby
Just the built in test projects that are part of 2008 team developer. 
--Original Message--
From: silky
To: Geoff Appleby
Cc: ausDotNet
ReplyTo: michaelsli...@gmail.com
Subject: Re: unit testing in visual studio
Sent: Feb 26, 2010 14:51

On Fri, Feb 26, 2010 at 2:50 PM, Geoff Appleby geoff.appl...@gmail.com wrote:
 But you're pretty fool.

...

So, what system are you using to run the unit tests though? Test Driven.NET?

I'm now slightly intrigued as to why it's randomly changing the port on you.

-- 
silky

  http://www.programmingbranch.com/


Sent from my BlackBerry Storm


Re: unit testing in visual studio

2010-02-25 Thread silky
On Fri, Feb 26, 2010 at 2:55 PM, Geoff Appleby geoff.appl...@gmail.com wrote:
 Just the built in test projects that are part of 2008 team developer.

ohhh, I see. Well, I've never used that.

Have you looked at things like this?
http://msdn.microsoft.com/en-us/library/ms404693(VS.80).aspx

-- 
silky

  http://www.programmingbranch.com/


Re: unit testing in visual studio

2010-02-25 Thread Geoff Appleby
No I hadn't.  But it have me an idea. Inside that file that I'd never thought 
to look inside. In there the web service URL had a port specified of 0. So in 
notepad I changed it to  and its all behaving as expected now. 

Cheers :)

--Original Message--
From: silky
To: Geoff Appleby
Cc: ausDotNet
ReplyTo: michaelsli...@gmail.com
Subject: Re: unit testing in visual studio
Sent: Feb 26, 2010 14:55

On Fri, Feb 26, 2010 at 2:55 PM, Geoff Appleby geoff.appl...@gmail.com wrote:
 Just the built in test projects that are part of 2008 team developer.

ohhh, I see. Well, I've never used that.

Have you looked at things like this?
http://msdn.microsoft.com/en-us/library/ms404693(VS.80).aspx

-- 
silky

  http://www.programmingbranch.com/


Sent from my BlackBerry Storm


Re: unit testing in visual studio

2010-02-25 Thread Geoff Appleby
And how many times have you said that? :)
--Original Message--
From: silky
To: Geoff Appleby
Cc: ausDotNet
ReplyTo: michaelsli...@gmail.com
Subject: Re: unit testing in visual studio
Sent: Feb 26, 2010 15:18

On Fri, Feb 26, 2010 at 3:19 PM, Geoff Appleby geoff.appl...@gmail.com wrote:
 No I hadn't.  But it have me an idea. Inside that file that I'd never thought 
 to look inside. In there the
 web service URL had a port specified of 0. So in notepad I changed it to  
 and its all behaving
 as expected now.

Phew.

I'm glad I slightly redeemed my initial foolishness in this thread,
otherwise I may have had to quit programming.


 Cheers :)

De nada


-- 
silky

  http://www.programmingbranch.com/


Sent from my BlackBerry Storm

Re: unit testing in visual studio

2010-02-25 Thread Mark Hurd
On Fri, Feb 26, 2010 at 2:49 PM, Geoff Appleby geoff.appl...@gmail.com wrote:
 No I hadn't.  But it have me an idea. Inside that file that I'd never thought 
 to look inside. In there the web service URL had a port specified of 0. So in 
 notepad I changed it to  and its all behaving as expected now.

 Cheers :)

Can you confirm what file that is?

BTW I have worked with the Unit Testing random port like so:

TestMethod(), _
 AspNetDevelopmentServer(WebService1, _
  C:\My Projects\MGM\Snc\Web Interface, /) _
Public Sub HelloWorldTest()
Dim target As OurMultiUrlService = New OurMultiUrlService
Dim expected As String = Hello, world!
Dim actual As String

target.Urls.Clear()
target.Urls.AddRange(WebSetup(TestContext, WebService1))

actual = target.HelloWorld()

Assert.AreEqual(expected, actual)

End Sub

'''-
''' Function: WebSetup
'''
''' summary
'''   Determines the actual URL for the web services named.
''' /summary
'''
''' param name=TestContextThe current test context./param
''' param name=WebServiceNames
'''   The name of the web service, as specified in the
'''  see cref=Web.AspNetDevelopmentServerAttribute.Name /
'''  parameter.
''' /param
'''
''' returnsThe array of actual URLs./returns
'''
''' remarks/remarks
'''
''' revisionhistory
'''   081017 MEH Created.
''' /revisionhistory
'''-
Public Function WebSetup(ByVal TestContext As TestContext, _
 ByVal ParamArray WebServiceNames() As String) As String()
For i = LBound(WebServiceNames) To UBound(WebServiceNames)
Dim url = http://localhost/;
Dim webservice = New HttpPostClientProtocol
webservice.Url = url
Assert.IsTrue(WebServiceHelper.TryUrlRedirection(webservice,
TestContext,  _
  WebServiceNames(i)))
Assert.IsTrue(i = LBound(WebServiceNames) _
  OrElse WebServiceNames(i - 1)  webservice.Url)
WebServiceNames(i) = webservice.Url
Next
Return WebServiceNames
End Function
-- 
Regards,
Mark Hurd, B.Sc.(Ma.)(Hons.)