public void RouteWithCustomConstraintWithoutWithInlineConstrainResolverMethodCalledShouldThrowInvalidOperationException() { MyWebApi .Routes(TestObjectFactory.GetHttpConfigurationWithRoutes(false)) .ShouldMap("api/testcustomconstraint/custom/2") .To <CustomConstraintAttributesController>(c => c.WithAttributesAndParameters(2)); }
public void ResolveShouldWorkWithBindingAttributes() { var config = TestObjectFactory.GetHttpConfigurationWithRoutes(); var request = new HttpRequestMessage(HttpMethod.Post, "api/Route/PostMethodWithModelAndAttribute") { Content = new StringContent( "{\"NonRequiredString\": \"AnotherTest\", \"NotValidateInteger\": 2}") }; request.Content.Headers.ContentType = new MediaTypeHeaderValue(MediaType.ApplicationJson); var routeInfo = InternalRouteResolver.Resolve(config, request); Assert.IsTrue(routeInfo.IsResolved); Assert.IsFalse(routeInfo.IsIgnored); Assert.IsFalse(routeInfo.MethodIsNotAllowed); Assert.IsNullOrEmpty(routeInfo.UnresolvedError); Assert.AreEqual(typeof(RouteController), routeInfo.Controller); Assert.AreEqual("PostMethodWithModelAndAttribute", routeInfo.Action); Assert.AreEqual(1, routeInfo.ActionArguments.Count); Assert.IsNotNull(routeInfo.ActionArguments["someModel"]); Assert.IsAssignableFrom <RequestModel>(routeInfo.ActionArguments["someModel"].Value); Assert.AreEqual(0, ((RequestModel)routeInfo.ActionArguments["someModel"].Value).Integer); Assert.IsNullOrEmpty(((RequestModel)routeInfo.ActionArguments["someModel"].Value).RequiredString); Assert.IsNullOrEmpty(((RequestModel)routeInfo.ActionArguments["someModel"].Value).NonRequiredString); Assert.AreEqual(0, ((RequestModel)routeInfo.ActionArguments["someModel"].Value).NotValidateInteger); Assert.IsNull(routeInfo.HttpMessageHandler); Assert.IsFalse(routeInfo.ModelState.IsValid); }
public void WithCustomConfigurationShouldWorkCorrectly() { MyWebApi .Routes(TestObjectFactory.GetHttpConfigurationWithRoutes()) .ShouldMap("api/NoParameterlessConstructor/OkAction") .WithHttpMethod(HttpMethod.Post) .To <NoParameterlessConstructorController>(c => c.OkAction()); }
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 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 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 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 StartsAndStopsShouldWorkCorrectlyForHttpServers() { MyWebApi.Server().Starts(TestObjectFactory.GetHttpConfigurationWithRoutes()); 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 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 void AndProvideShouldReturnProperHttpConfiguration() { var config = TestObjectFactory.GetHttpConfigurationWithRoutes(); var actualConfig = MyWebApi .Controller <WebApiController>() .WithHttpConfiguration(config) .Calling(c => c.OkResultAction()) .ShouldReturn() .Ok() .AndProvideTheHttpConfiguration(); Assert.AreSame(config, actualConfig); }
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 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 ResolveShouldResolveCorrectlyWithRoutePrefixAndRouteAttribute() { var config = TestObjectFactory.GetHttpConfigurationWithRoutes(); var request = new HttpRequestMessage(HttpMethod.Post, "api/Routes/Test"); var routeInfo = InternalRouteResolver.Resolve(config, request); Assert.IsTrue(routeInfo.IsResolved); Assert.IsFalse(routeInfo.IsIgnored); Assert.IsFalse(routeInfo.MethodIsNotAllowed); Assert.IsNullOrEmpty(routeInfo.UnresolvedError); Assert.AreEqual(typeof(RouteController), routeInfo.Controller); Assert.AreEqual("WithRouteAttribute", routeInfo.Action); Assert.AreEqual(0, routeInfo.ActionArguments.Count); Assert.IsNull(routeInfo.HttpMessageHandler); Assert.IsTrue(routeInfo.ModelState.IsValid); }
public void ResolveShouldIgnoreRoutesWithStopRountingHandler() { var config = TestObjectFactory.GetHttpConfigurationWithRoutes(); var request = new HttpRequestMessage(HttpMethod.Get, "api/IgnoredRoute"); var routeInfo = InternalRouteResolver.Resolve(config, request); Assert.IsTrue(routeInfo.IsResolved); Assert.IsTrue(routeInfo.IsIgnored); Assert.IsFalse(routeInfo.MethodIsNotAllowed); Assert.IsNullOrEmpty(routeInfo.UnresolvedError); Assert.AreEqual(typeof(RouteController), routeInfo.Controller); Assert.AreEqual("GetMethod", routeInfo.Action); Assert.AreEqual(0, routeInfo.ActionArguments.Count); Assert.IsAssignableFrom <StopRoutingHandler>(routeInfo.HttpMessageHandler); Assert.IsTrue(routeInfo.ModelState.IsValid); }
public void ResolveShouldReturnProperErrorWhenTwoActionsAreMatched() { var config = TestObjectFactory.GetHttpConfigurationWithRoutes(); var request = new HttpRequestMessage(HttpMethod.Post, "api/Route/SameAction"); var routeInfo = InternalRouteResolver.Resolve(config, request); Assert.IsFalse(routeInfo.IsResolved); Assert.IsFalse(routeInfo.IsIgnored); Assert.IsFalse(routeInfo.MethodIsNotAllowed); Assert.AreEqual("it could not be resolved: 'Multiple actions were found that match the request'", routeInfo.UnresolvedError); Assert.IsNull(routeInfo.Controller); Assert.IsNull(routeInfo.Action); Assert.IsNull(routeInfo.ActionArguments); Assert.IsNull(routeInfo.HttpMessageHandler); Assert.IsNull(routeInfo.ModelState); }
public void ResolveShouldResolveCorrectControllerAndAction() { var config = TestObjectFactory.GetHttpConfigurationWithRoutes(); var request = new HttpRequestMessage(HttpMethod.Post, "api/NoParameterlessConstructor/OkAction"); var routeInfo = InternalRouteResolver.Resolve(config, request); Assert.IsTrue(routeInfo.IsResolved); Assert.IsFalse(routeInfo.IsIgnored); Assert.IsFalse(routeInfo.MethodIsNotAllowed); Assert.IsNullOrEmpty(routeInfo.UnresolvedError); Assert.AreEqual(typeof(NoParameterlessConstructorController), routeInfo.Controller); Assert.AreEqual("OkAction", routeInfo.Action); Assert.AreEqual(0, routeInfo.ActionArguments.Count); Assert.IsNull(routeInfo.HttpMessageHandler); Assert.IsTrue(routeInfo.ModelState.IsValid); }
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 void ResolveShouldNotResolveCorrectlyWithMissingQueryString() { var config = TestObjectFactory.GetHttpConfigurationWithRoutes(); var request = new HttpRequestMessage(HttpMethod.Post, "api/Route/QueryString"); var routeInfo = InternalRouteResolver.Resolve(config, request); Assert.IsFalse(routeInfo.IsResolved); Assert.IsFalse(routeInfo.IsIgnored); Assert.IsFalse(routeInfo.MethodIsNotAllowed); Assert.AreEqual("it could not be resolved: 'Not Found'", routeInfo.UnresolvedError); Assert.IsNull(routeInfo.Controller); Assert.IsNull(routeInfo.Action); Assert.IsNull(routeInfo.ActionArguments); Assert.IsNull(routeInfo.HttpMessageHandler); Assert.IsNull(routeInfo.ModelState); }
public void ResolveShouldResolveCorrectlyWithParameterAndQueryString() { var config = TestObjectFactory.GetHttpConfigurationWithRoutes(); var request = new HttpRequestMessage(HttpMethod.Post, "api/Route/WithParameterAndQueryString/5?value=test"); var routeInfo = InternalRouteResolver.Resolve(config, request); Assert.IsTrue(routeInfo.IsResolved); Assert.IsFalse(routeInfo.IsIgnored); Assert.IsFalse(routeInfo.MethodIsNotAllowed); Assert.IsNullOrEmpty(routeInfo.UnresolvedError); Assert.AreEqual(typeof(RouteController), routeInfo.Controller); Assert.AreEqual("WithParameterAndQueryString", routeInfo.Action); Assert.AreEqual(5, routeInfo.ActionArguments["id"].Value); Assert.AreEqual("test", routeInfo.ActionArguments["value"].Value); Assert.IsNull(routeInfo.HttpMessageHandler); Assert.IsTrue(routeInfo.ModelState.IsValid); }
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 RestoreConfiguration() { MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes()); }