public void Init() { var config = new HttpConfiguration(); WebApiConfig.Register(config); MyWebApi.IsUsing(WebApiConfig.Config); }
/// <summary> /// Sets custom inline constraint resolver to http configuration /// </summary> /// <param name="inlineConstraintResolver">Custom route constraint resolver to use.</param> /// <returns>New HTTP configuration builder.</returns> public IHttpConfigurationBuilder WithInlineConstraintResolver(IInlineConstraintResolver inlineConstraintResolver) { var config = InitializeHttpConfiguration(); config.MapHttpAttributeRoutes(inlineConstraintResolver); return(MyWebApi.IsUsing(config)); }
public void DefaultErrorDetailPolicyShouldBeAlways() { MyWebApi.IsUsingDefaultHttpConfiguration(TestObjectFactory.GetCustomInlineConstraintResolver()); Assert.AreEqual(IncludeErrorDetailPolicy.Always, MyWebApi.Configuration.IncludeErrorDetailPolicy); MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes()); }
public void WithErrorDetailPolicyShouldSetCorrectErrorDetailPolicy() { MyWebApi.IsUsingDefaultHttpConfiguration().WithErrorDetailPolicy(IncludeErrorDetailPolicy.LocalOnly); Assert.AreEqual(IncludeErrorDetailPolicy.LocalOnly, MyWebApi.Configuration.IncludeErrorDetailPolicy); MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes()); }
public static void AssemblyInit(TestContext context) { AutoMapperConfig.RegisterMappings(Assembly.Load("Teleimot.WepApi")); var config = new HttpConfiguration(); WebApiConfig.Register(config); MyWebApi.IsUsing(config); }
public void IsUsingDefaultConfigurationShouldWorkCorrectly() { MyWebApi.IsUsingDefaultHttpConfiguration(TestObjectFactory.GetCustomInlineConstraintResolver()); Assert.IsNotNull(MyWebApi.Configuration); Assert.IsTrue(MyWebApi.Configuration.Routes.ContainsKey("API Default")); MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes()); }
public void IsRegisteredWithShouldWorkCorrectly() { MyWebApi.IsRegisteredWith(WebApiConfig.Register); Assert.IsNotNull(MyWebApi.Configuration); Assert.AreEqual(1, MyWebApi.Configuration.Routes.Count); MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes()); }
public static void AssemblyInitialize(TestContext context) { AutoMapperConfig.RegisterMappings(Assembly.Load(Assemblies.BALKAN_AIR_API)); var config = new HttpConfiguration(); WebApiConfig.Register(config); MyWebApi.IsUsing(config); }
public void IsUsingDefaultConfigurationShouldWorkCorrectly() { MyWebApi.IsUsingDefaultHttpConfiguration(); Assert.IsNotNull(MyWebApi.Configuration); Assert.AreEqual(0, MyWebApi.Configuration.Routes.Count); MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes()); }
public void WithoutAnyConfigurationShouldInstantiateDefaultOne() { MyWebApi.IsUsing(null); var config = MyWebApi .Handler <CustomDelegatingHandler>() .AndProvideTheHttpConfiguration(); Assert.IsNotNull(config); MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes()); }
public void WhenWithInlineConstraintResolverCalledShouldSetNewHttpConfigurationInstance() { var oldHttpConfiguration = MyWebApi.Configuration; MyWebApi .IsUsingDefaultHttpConfiguration() .WithInlineConstraintResolver(TestObjectFactory.GetCustomInlineConstraintResolver()); Assert.AreNotSame(MyWebApi.Configuration, oldHttpConfiguration); MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes()); }
public void LinkGenerationShouldWorkCorrectlyWithDefaultConfiguration() { MyWebApi.IsUsingDefaultHttpConfiguration(TestObjectFactory.GetCustomInlineConstraintResolver()); MyWebApi .Controller <WebApiController>() .Calling(c => c.WithGeneratedLink(1)) .ShouldReturn() .Created() .AtLocation("http://localhost/api/test?id=1"); MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes()); }
public void WithoutAnyConfigurationServersShouldThrowException() { MyWebApi.IsUsing(null); MyWebApi .Server() .Working() .WithHttpRequestMessage(req => req.WithMethod(HttpMethod.Post).WithRequestUri("api/NoAttributes/WithParameter/5")) .ShouldReturnHttpResponseMessage() .WithStatusCode(HttpStatusCode.OK) .AndAlso() .WithResponseModelOfType <int>(); }
public void OwinServerStartsShouldReturnCorrectTestBuilder() { MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes()); var server = MyWebApi.Server().Starts <CustomStartup>(); server .WithHttpRequestMessage(req => req.WithHeader("CustomHeader", "CustomValue")) .ShouldReturnHttpResponseMessage() .WithStatusCode(HttpStatusCode.OK); MyWebApi.Server().Stops(); }
public void AndStartsServerShouldStartServerCorrectly() { MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes()).AndStartsServer(); Assert.IsNotNull(HttpTestServer.GlobalServer); Assert.IsNotNull(HttpTestServer.GlobalClient); Assert.IsTrue(HttpTestServer.GlobalIsStarted); MyWebApi.Server().Stops(); Assert.IsNull(HttpTestServer.GlobalServer); Assert.IsNull(HttpTestServer.GlobalClient); Assert.IsFalse(HttpTestServer.GlobalIsStarted); }
public static void AssemblyInit(TestContext context) { AutoMapperConfig.RegisterMappings(Assembly.Load(Constants.DataTransferModelsAssembly)); Mapper.CreateMap <AttachmentRequestModel, Attachment>(); Mapper.CreateMap <ProjectRequestModel, Project>(); Mapper.CreateMap <ProjectWorkLogRequestModel, WorkLog>(); Mapper.CreateMap <CategoryRequestModel, Category>(); var config = new HttpConfiguration(); WebApiConfig.Register(config); MyWebApi.IsUsing(config); // DatabaseConfig.Initialize(); }
public void LinkGenerationShouldWorkCorrectlyWithCustomBaseAddress() { MyWebApi .IsUsingDefaultHttpConfiguration(TestObjectFactory.GetCustomInlineConstraintResolver()) .WithBaseAddress("http://mytestedasp.net"); MyWebApi .Controller <WebApiController>() .Calling(c => c.WithGeneratedLink(1)) .ShouldReturn() .Created() .AtLocation("http://mytestedasp.net/api/test?id=1"); RemoteServer.DisposeGlobal(); MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes()); }
public void ServerStartsShouldReturnCorrectTestBuilder() { MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes()); var server = MyWebApi.Server().Starts(); server .WithHttpRequestMessage(req => req.WithMethod(HttpMethod.Post).WithRequestUri("api/NoAttributes/WithParameter/5")) .ShouldReturnHttpResponseMessage() .WithStatusCode(HttpStatusCode.OK) .AndAlso() .WithResponseModelOfType <int>() .Passing(m => m == 5); MyWebApi.Server().Stops(); }
public void WithoutAnyConfigurationShouldInstantiateDefaultOne() { MyWebApi.IsUsing(null); var config = MyWebApi .Controller <WebApiController>() .WithHttpRequestMessage(request => request.WithMethod(HttpMethod.Get)) .Calling(c => c.CustomRequestAction()) .ShouldReturn() .BadRequest() .AndProvideTheController() .Configuration; Assert.IsNotNull(config); MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes()); }
public static void Initialize(TestContext testContext) { NinjectConfig.DependenciesRegistration = kernel => { kernel.Bind(typeof(IRepository <User>)).ToConstant(Repositories.GetUsersRepository()); kernel.Bind(typeof(IRepository <RealEstate>)).ToConstant(Repositories.GetRealEstatesRepository()); kernel.Bind(typeof(IRepository <Comment>)).ToConstant(Repositories.GetCommentsRepository()); }; AutoMapperConfig.RegisterMappings(Assemblies.WebApi); var config = new HttpConfiguration(); WebApiConfig.Register(config); MyWebApi.IsUsing(config); }
public void WithBaseAddressShouldChangedDefaultAddress() { Assert.IsFalse(RemoteServer.GlobalIsConfigured); Assert.AreEqual(MyWebApi.DefaultHost, MyWebApi.BaseAddress.OriginalString); string address = "http://mytestedasp.net"; MyWebApi .IsUsingDefaultHttpConfiguration(TestObjectFactory.GetCustomInlineConstraintResolver()) .WithBaseAddress(address); Assert.AreEqual(address, MyWebApi.BaseAddress.OriginalString); Assert.IsTrue(RemoteServer.GlobalIsConfigured); MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes()); Assert.AreEqual(MyWebApi.DefaultHost, MyWebApi.BaseAddress.OriginalString); RemoteServer.DisposeGlobal(); }
public void GetAnIssue() { // starts HTTP server with global configuration // set with MyWebApi.IsUsing // * the server is disposed after the test // * HTTP request can be set just like in the controller unit tests // * HTTP response can be tested just like in the controller unit tests //MyWebApi.IsUsing(GlobalConfiguration.Configuration) var config = new HttpConfiguration { IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always }; config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "TestRoute", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional }); var controllerFactory = new TestIssuesControllerActivator(); config.Services.Replace( typeof(IHttpControllerActivator), controllerFactory); MyWebApi.IsUsing(config); MyWebApi .Server() .Working() // working will instantiate new HTTP server with the global configuration .WithHttpRequestMessage( request => request .WithMethod(HttpMethod.Get) .WithRequestUri("api/issues")) .ShouldReturnHttpResponseMessage() .WithStatusCode(HttpStatusCode.OK); }
public void RestoreConfiguration() { MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes()); }
public void StartsShouldThrowExceptionWithoutAnyConfiguration() { MyWebApi.IsUsing(null); MyWebApi.Server().Starts(); }