Owin.Testing TestServer with Windsor container and Moq - integration-testing

I have a WebApi where I am using Windsor Castle as a IoC framework. I am using Owin library and a startup file was created to centralized the configuration of the API. Everything works as expected.
I have integration tests where I am using Owin.Testing library and the server is started using a test startup class which is inheriting the real one. The Windsor container was successfully configured for the TestServer. The integration tests are executing web requests against the running self hosted server. Everything works fine.
There are two things which are not working when using the test server:
the ModelState of the controller is all the time valid even when I am passing an invalid json body for the POST request. When hosted with IIS it works as expected. Any idea what can be wrong with the test server?
I am using VS test runner and the Owin TestServer is initialized in a [ClassInitialize] method. I do not want to create a new test server after each test as Windsor container initialization is quite expensive. There are tests where I need to mock some 3rd party services (by using Register method of the container and Moq). At the end of each test I want to rollback all the mocks from the container which were done in the scope of executed test. Is it possible somehow to do it? I have tried to register within a scope but does not work.
Thanks

Related

WebApplicationFactory and release pipeline

I am new to WebApplicationFactory use and want to know
what is the use of this WebApplicationFactory class for integration tests. as my understanding, it is useful only for mocking external services (this is what we do in unit tests).
Should we use WebApplicationFactory for simple web api integration testing?
what happens in release pipelines?
when i run integration tests (written using WebApplicationFactory) open the web api automatically and uses overrided appsettings set in a custom WebApplicationFactory class.
so when i publish the tests code on azure and creates release pipeline stage for integration tests. does the above test code (custom WebApplicationFactory ) override the actual app dll's appsetting. ( i mean does it start the app and use test appsetting logic)
MSFT has pretty good documentation about integration testing and the usage of WebApplicationFactory to help facilitate this type of testing for Web Applications. This is a good place to learn why integration testing is done and how to do it with WebApplicationFactory.
What is the use of this WebApplicationFactory class for integration tests?
The WebApplicationFactory helps you build an in-memory Http Server and an HttpClient capable of making requests on that server.
By default, WebApplicationFactory will build this server using all the same services and dependencies that are registered in the application you are testing. You can, if desired, modify the services that are registered to the IServiceCollection so that Fakes or Mocks can be used instead of concrete implementations, but this is more of a feature of WebApplicationFactory and not its purpose. Whether you use Mocks or not should depend on what you're trying to test, and whether it's OK to use the application's services for testing purposes.
WebApplicationFactory helps test the configuration and middleware pipeline of your web application in a way that unit tests can't. By making HTTP requests into your in-memory server, you're able to ensure your application and its endpoints are working properly.
What happens in release pipelines?
Your integration tests should be in a separate project from your main application. You don't want the integration test project to be in your release pipeline and, unless you have a good reason to, it shouldn't be published to Azure.

Best Solution for Tracing/Loging Web Service

We have ASP.NET 4.5 web services (asmx) with a lot of projects and classes.
We need to recreate bugs in production enviroment so if a bug is reported we would like to view a log file so we can recreate the bug.
It will be a lot of work to write logger code lines in the solution projects.
Is there any logging add-in/extension that will do the work more rapidly?
We use WCF Message logging. It logs the entire xml that is sent into the web service.
If we have a problem in test or Production, we take the xml, put it into SOAP UI and run it against the web service. This Works well for stateless calculation services, for services that require state you could take a copy of Production to recreate the problem in test.
Here is how you can configure it: https://msdn.microsoft.com/en-us/library/ms730064(v=vs.110).aspx

integrate vert.x and Spring MVC

I have a running app in vert.x. I have many missing features or I just can say missing spring.
How can I integrate vert.x and Spring MVC working on a Tomcat server?
With Vert.x 3 I would think you would want to use the Vert.x Web capabilities as described here instead of Spring MVC if you want to give Vertx a go. It provides a different approach to developing a web application using the Multi-Reactor pattern than the traditional multi-threaded Servlet model which Spring MVC is based on. With the Servlet model every request runs on its own thread. In Vert.x there is an event loop that is single threaded. All requests are run on the same thread, which requires blocking I/O code to be written in special blocks (see Core Manual).
Depends on which Vert.x version you are using. 2.x requires a module. like mod-spring-appcontext. In Vert.x 3.x just create a Spring ApplicationContext in your code, typically in the entry point of your application, like your public static void main method. I can't get into more detail. Vert.x questions rarely, if ever, get noticed here.
I would not recommend working with vert.x on a tomcat container as there philosophies are completely different. Tomcat is a servlet container which creates different thread for each incoming call whereas vert.x works on a event-loop. If you are missing spring and will like to use its bean you can integrate it in vert.x environment and run any blocking code in worker verticles.
You can see an example here : https://github.com/vert-x3/vertx-examples/tree/master/spring-examples/spring-example

WebApi RoleEntryPoint 404

I have a strange problem for which I can't find a solution.
Currently we have a development Server (running a normal Azure Virtual Machine) and a production Server running a Web Role in Azure Cloud Services.
For the Web Role we need to add the "RoleEntrPoint" class.
But as soon this class is present, the Web Api on a normal VM on development server with IIS 8 returns a "404" for all routes.
This problem is similar to: http://jake.ginnivan.net/web-api-problem-404s-for-everything/
(As a side note, opposed to the blog post I'm not using EntityFramework. We just added the RoleEntryPoint class and copy local for Microsoft.WindowsAzure.ServiceRuntime is true)
But I can't find a solution or catch any errors thrown.
Do you have any ideas on this?
It makes sense that if you're not running as an Azure role, then RoleEntryPoint would break things. Can you make your development VM also a Web Role? If not, then don't use RoleEntryPoint and use ASP.NET lifecycle management methods instead.
From the documentation:
Web roles can optionally extend the RoleEntryPoint class, or can use the ASP.NET lifecycle management methods to handle the start and stop sequences.
So, the ASP.NET methods will work for both VM and Web Role. You didn't say what you're trying to do with the RoleEntryPoint, so I'm not sure what further guidance to give.

Wsdl, test web service, newbie

I have a few wsdl URLs (e.g. https://location?wsdl). And I need to automate the testing of these web services with asp.net. How can I do that ? I was told that http website request could do this (HttpRequest Class). I don't know much about web services except the basics.
Create a unit test project. Use "Add Service Reference" to reference the WSDLs within this project. Then, just create unit tests to call the service and confirm that the results are as expected.
Note that purists will say these are integration tests, not unit tests, but that's ok. They'll be automated, which is what you were looking for.
Soap UI works great if you can get around the requirement of having to using ASP.NET.
See the tutorial here...
http://www.soapui.org/Getting-Started/your-first-soapui-project.html
If you have to use .NET why can't you just make a proxy class of the webservice using wsdl.exe and then test it with the web service client that's generated from that?

Resources