public void AttributeMappingsIsInitialized_WithRightActionAndTemplate(Type controllerType, string expectedPathTemplate, string expectedActionName) { // Arrange HttpControllerDescriptor controller = new HttpControllerDescriptor(DependencyInjectionHelper.CreateConfigurationWithRootContainer(), "TestController", controllerType); ODataPathTemplate pathTemplate = new ODataPathTemplate(); Mock <IODataPathTemplateHandler> pathTemplateHandler = new Mock <IODataPathTemplateHandler>(); pathTemplateHandler .Setup(p => p.ParseTemplate(expectedPathTemplate, controller.Configuration.GetODataRootContainer(RouteName))) .Returns(pathTemplate) .Verifiable(); AttributeRoutingConvention convention = new AttributeRoutingConvention(RouteName, new[] { controller }, pathTemplateHandler.Object); // Act convention.SelectController(new ODataPath(), new HttpRequestMessage()); // Assert pathTemplateHandler.VerifyAll(); Assert.NotNull(convention.AttributeMappings); Assert.Equal(expectedActionName, convention.AttributeMappings[pathTemplate].ActionName); }
public MockHttpServer(Func <HttpRequestMessage, HttpResponseMessage> action) : base(DependencyInjectionHelper.CreateConfigurationWithRootContainer()) { _action = request => { return(Task.FromResult(action(request))); }; }
public void CtorTakingModelAndConfigurationAndPathHandler_ThrowsArgumentNull_PathTemplateHandler() { HttpConfiguration configuration = DependencyInjectionHelper.CreateConfigurationWithRootContainer(); Assert.ThrowsArgumentNull( () => new AttributeRoutingConvention(configuration: configuration, routeName: RouteName, pathTemplateHandler: null), "pathTemplateHandler"); }
public void AttributeMappingsInitialization_ThrowsInvalidOperation_IfNoConfigEnsureInitialized() { // Arrange HttpConfiguration configuration = DependencyInjectionHelper.CreateConfigurationWithRootContainer(); AttributeRoutingConvention convention = new AttributeRoutingConvention(RouteName, configuration); // Act & Assert Assert.Throws <InvalidOperationException>( () => convention.AttributeMappings, "The object has not yet been initialized. Ensure that HttpConfiguration.EnsureInitialized() is called " + "in the application's startup code after all other initialization code."); }
public void Constructor_ThrowsInvalidOperation_IfFailsToParsePathTemplate() { // Arrange CustomersModelWithInheritance model = new CustomersModelWithInheritance(); HttpControllerDescriptor controller = new HttpControllerDescriptor(DependencyInjectionHelper.CreateConfigurationWithRootContainer(model.Model), "TestController", typeof(InvalidPathTemplateController)); // Act & Assert Assert.Throws <InvalidOperationException>( () => new AttributeRoutingConvention(RouteName, new[] { controller }), "The path template 'Customers/Order' on the action 'GetCustomers' in controller 'TestController' is not " + "a valid OData path template. The request URI is not valid. Since the segment 'Customers' refers to a " + "collection, this must be the last segment in the request URI or it must be followed by an function or " + "action that can be bound to it otherwise all intermediate segments must refer to a single resource."); }
public void CtorTakingHttpConfiguration_InitializesAttributeMappings_OnFirstSelectControllerCall() { // Arrange HttpConfiguration config = DependencyInjectionHelper.CreateConfigurationWithRootContainer(); ODataPathTemplate pathTemplate = new ODataPathTemplate(); Mock <IODataPathTemplateHandler> pathTemplateHandler = new Mock <IODataPathTemplateHandler>(); pathTemplateHandler.Setup(p => p.ParseTemplate("Customers", config.GetODataRootContainer(RouteName))) .Returns(pathTemplate).Verifiable(); AttributeRoutingConvention convention = new AttributeRoutingConvention(RouteName, config, pathTemplateHandler.Object); config.EnsureInitialized(); // Act convention.SelectController(new ODataPath(), new HttpRequestMessage()); // Assert pathTemplateHandler.VerifyAll(); Assert.NotNull(convention.AttributeMappings); Assert.Equal("GetCustomers", convention.AttributeMappings[pathTemplate].ActionName); }
public MockHttpServer(Func <HttpRequestMessage, Task <HttpResponseMessage> > action) : base(DependencyInjectionHelper.CreateConfigurationWithRootContainer()) { _action = action; }