MyTested.WebApi
MyTested.WebApi copied to clipboard
Test full pipeline with dependency resolver
While trying to run test for full pipeline for controller that should run with dependencies I got an error that the controller should have parameters public constructor.
Error message:
MyTested.WebApi.Exceptions.HttpResponseMessageAssertionException: 'When testing ServerHttpMessageHandler expected HTTP response message result status code to be 200 (OK), but instead received 500 (InternalServerError).
The code:
MyWebApi .IsRegisteredWith(WebApiConfig.Register) .WithDependencyResolver(() => { SimpleInjectorWebApiInitializer.TestInitialize(); return new SimpleInjectorWebApiDependencyResolver(SimpleInjectorWebApiInitializer.Container); }) .AndStartsServer() .WithHttpRequestMessage(req => req .WithMethod(HttpMethod.Get) .WithRequestUri("api/values/5") ) .ShouldReturnHttpResponseMessage() .WithStatusCode(HttpStatusCode.OK) .WithResponseModel("value");