Created
February 23, 2016 11:11
-
-
Save janierdavila/8bda2a895eb3578a3fc8 to your computer and use it in GitHub Desktop.
How to configure AutoFixture to work with Web API 2.0. Note to self (and maybe others)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Net.Http; | |
| using System.Web.Http; | |
| using System.Web.Http.Controllers; | |
| using System.Web.Http.Hosting; | |
| using Ploeh.AutoFixture; | |
| using Ploeh.AutoFixture.AutoNSubstitute; | |
| namespace TracfoneDap.API.Tests.AutoMockingCustomizations | |
| { | |
| public class WebApiCustomization : CompositeCustomization | |
| { | |
| public WebApiCustomization() : base(new AutoNSubstituteCustomization(), new ControllerCustomization()) | |
| { | |
| } | |
| private class ControllerCustomization : ICustomization | |
| { | |
| public void Customize(IFixture fixture) | |
| { | |
| fixture.Customize<HttpConfiguration>(c => c | |
| .OmitAutoProperties()); | |
| fixture.Customize<HttpRequestMessage>(c => c | |
| .Do(x => | |
| x.Properties.Add( | |
| HttpPropertyKeys.HttpConfigurationKey, | |
| fixture.Create<HttpConfiguration>()))); | |
| fixture.Customize<HttpRequestContext>(c => c | |
| .Without(x => x.ClientCertificate)); | |
| } | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also, using NSubstitute as my AutoMocking provider. Change for your own.