Adding a reference of a WCF task hosted into a test Harness
TDD is the in thing...
Recently I had to write a WCF task which was to be hosted in Windows services rather than IIS.
Although I did write a some test cases around it, the business case I was working on required me to write a test harness (it was a long running process & hence the decision to host it in Windows service & write a test harness)
Now since I already had a WCF service host client within the solution (see this post for more details), I could not add the reference to the test harness without an error as shown below
at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at System.ServiceModel.Channels.SocketConnectionListener.Listen()
--- End of inner exception stack trace ---
at System.ServiceModel.Channels.SocketConnectionListener.Listen()
at System.ServiceModel.Channels.BufferedConnectionListener.Listen()
at System.ServiceModel.Channels.ExclusiveTcpTransportManager.OnOpen()
at System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener)
at System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback selectTransportManagerCallback)
at System.ServiceModel.Channels.ConnectionOrientedTransportChannelListener.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.TcpChannelListener`2.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo info)Only one usage of each socket address (protocol/network address/port) is normally permitted
The reason for this error is that as soon as your try and add a reference to the WCF task, it will spin up the existing WCF host client in the solution and hence the error above. To be fair, it will still add the reference to the test harness.
I wanted to get rid of this, it is then that I had a chat with Mr. Fenton and he suggested me a quick work around for this issue. Here's what I did.
* Remove the test harness from the solution
* spin up the test harness project as a separate project.
* then add the reference to the wcf task.
lo, job done.
Adding a reference of a WCF task hosted into a test Harness – Invalid Class Defination
One of the difference that I found between hosting a WCF in IIS against hosting it in Windows Services is that you can't start the service if its not interfaced properly.
Let me give you an example
[ServiceBehavior(Namespace = "some Namespace", Name = "some name")]
public class ServiceClass: BaseClass
{
// some code
}
The above example failed in my case because the BaseClass was implementing and interface IBaseClass. To make the above example work I had to implement the interface as well.
[ServiceBehavior(Namespace = "some Namespace", Name = "some name")]
public class ServiceClass: BaseClass, IBaseClass
{
// some code
}
integrating MVC 1.0 NUnit project template in Visual Studio
I found some interesting links to add Nunit project templates to visual studio. It also creates Item templates for MVC based .net development and traditional .net development.
Getting Started With TDD in Visual Studio - Alan Stevens
Updated NUnit Templates for ASP.Net MVC - Joe Ca rtano
Setting Up ASP.NET MVC with NUnit for Visual Studio - Nik Markis
How to: Add a Custom MVC Test Framework


