I am in the process of writing some test for a server that is implemented in WCF, as the messages are complex and call-backs are made to the clients I wish to include WCF in the tests.
(You may wish to call these “fit” or “integration tests” not unit tests, the code on both side of WCF will have more detail unit test that don’t use WCF.)
As my server keeps state and I wish to check that all channels shut down without errors, I have code like:
[SetUp]
public void SetUp()
{
//TODO find a fee port rathern then hard coding
endPointAddress = "net.tcp://localhost:1234";
mockEngineManagerImp = new Mock<IEngineManagerImp>();
EngineManager engineManager = new EngineManager(mockEngineManagerImp.Object);
serviceHost = new ServiceHost(engineManager);
serviceHost.AddServiceEndpoint(
typeof(IEngineManager),
new NetTcpBinding(SecurityMode.None),
endPointAddress);
serviceHost.Open();
}
[TearDown]
public void TearDown()
{
serviceHost.Close();
}
However my tests are very slow….
How can I speed up the creation and destroying of my ServiceHost?
Thanks for all the great answers – they all contains helpful pointers,
I found that a lot of my tests were not closing the client chancel, this make the close on the server channel wait until the TCP connection from the client had timed out.
Sorting this out led to over a factor of 10 speed up.