I have created a custom msmq service with WCF, which uses a custom binding as it needs to do some custom logic at the channel layer, where it calls another wcf service. The service is going to be a core pience of functionality for our systems for at the the next few years. i want to do what I can to make sure the service is robust, but, i'm not sure where to start. Ie testing the response, should I create a mock queue object? how do I test the service is calling another service ?
Best way I have found to unit test msmq services is to actually unit test the service implementation, then do an integration test using msmq with a mock repository. To see if writes are working.
Related
This is a different question than my previous post on testing WCF.
This time after I've created my service, I want to test it not via WSDL, but I want to send an ajax request using $.ajax via jQuery.
I'm not sure how to wire up the service so that it's ready to recieve requests. Do I need the service setup and running in IIS? Or is there a way I can run the WCF project to run the service and then somehow in my NUnit Unit test create the jquery to make an HttpRequest..meaning would it know that the service is up and running? how?
You can host your service in the IIS, As a windows service or in a console app. To me it sounds wrong to call the service in a Unit test. Normally you mock out all external dependencies in a Unit test.
My issue it regarding creating a dummy WCF service which can be used at development side, when the REAL WCF service is not available or is down.
In my current assignment, the issue is that the web hosted WCF service from client is not always available for developer side. This hampers the development work as we are not able to verify/unit test the client side code.
Any solutions in sight? I have been searching /reading about mocking wcf with different available mocking frameworks, but still not clear about the right way.
Thanks in advance !
Without talking about frameworks - to call your srevice, you create client (proxy) instance, right?
You can move its generation to separate method, which will return your mock (injected by DI, injected by setter property in Unit test,. . .).
I Develop WCF web services for enterprise project.I use NUnit testing in service logic business layer for test in server side and in client side I use WCFTestClient for invoke web services method.
I have to do automated test for my project,But I really don't know which approach is better?
I suggest you both. Service Logic testing is important from the perspective of the service as is, it must works just as expected and that's what you test.
Now, Client testing is also important from the perspective (as it names implies) of service clients. I mean, client testing helps you in the design of clear and usable service APIs. When you test what your service users will be doing you get another perspective of the situation.
In the past, I have created a "robust" WCF service that can accept a complex (consumption of the service in a project) or RESTful requests.
I'm creating a new service and wanted to ease the creation of the restful endpoints. So I see the WCF Rest Service Application, which I'm trying out.
The problem now, is that if I wanted to use this service from another .Net application, I would now have to go through the process of writing the completed event parsing/de-serialization.
I think in trying to over-simply the initial process, I will complicate the consumption process.
Are there any simpler ways around this, and is it best to stick to the main WCF service type and simply decorate the service contract methods appropriately.
I'm implementing a WCF web service based on WF. This web service consumes other web services which I'm not in charge of. So basically my service workflow contains several Send activities.
I'm following the TDD approach, so the service implementation is to be covered by unit tests. I want to test proper invocation of 3rd party services.
In a non-workflow case I would mock the external services via NMock. But in my case I cannot control the instantiation the workflow instance and I have no idea on how to trick the Send activities to use the mock objects instead of real services endpoints.
Although Unit Testing Workflows And Activities article on MSDN mentions mocks I couldn't find any complete example of mocking the remote end of Send activity.
Any idea on how to do that?
please try Moles framework. http://research.microsoft.com/en-us/projects/pex/
There are samples about how to mock the sharepoint service. I believe the same trick should apply to WF workflow.
I have tried to mock the sqlconnection, Entity framework, web service call, it works very neat. Basically, it can mock almost any .net objects.
Using ServiceAgents wrappers for your web services would be one possible way of doing it.
This is a pattern i have followed in previous projects of mine.
Since they are interface based, you can easily mock out the services.
There are other advantages to this pattern (besides unit testing) including being able to abstract your application from external dependencies to a certain extent. However it does add the overhead of creating another class layer on top of the services.