示例#1
0
        public void AppliesToActionForEntityActionWithEntityTypeNameSameAsEntityTypeOnEntitySetWorksAsExpected(string actionName)
        {
            // Arrange
            ControllerModel controller = ControllerModelHelpers.BuildControllerModel <CustomersController>(actionName);
            ActionModel     action     = controller.Actions.First();

            ODataControllerActionContext context = ODataControllerActionContextHelpers.BuildContext(string.Empty, EdmModel, controller);

            context.Action = action;

            EntityRoutingConvention entityConvention = ConventionHelpers.CreateConvention <EntityRoutingConvention>();

            // Act
            bool returnValue = entityConvention.AppliesToAction(context);

            Assert.True(returnValue);

            // Assert
            Assert.Equal(2, action.Selectors.Count);
            Assert.Equal(new[]
            {
                "Customers(FirstName={keyFirstName},LastName={keyLastName})",
                "Customers(FirstName={keyFirstName},LastName={keyLastName})/NS.Customer"
            },
                         action.Selectors.Select(s => s.AttributeRouteModel.Template));
        }
示例#2
0
        public void AppliesToActionForGetActionWorksAsExpected(string actionName, string expectedTemplate)
        {
            // Arrange
            ControllerModel controller = ControllerModelHelpers.BuildControllerModel <CustomersController>(actionName);
            ActionModel     action     = controller.Actions.First();

            ODataControllerActionContext context = ODataControllerActionContextHelpers.BuildContext(string.Empty, EdmModel, controller);

            context.Action = action;

            EntitySetRoutingConvention entitySetConvention = ConventionHelpers.CreateConvention <EntitySetRoutingConvention>();

            // Act
            bool returnValue = entitySetConvention.AppliesToAction(context);

            Assert.True(returnValue);

            // Assert
            Assert.Equal(2, action.Selectors.Count);
            Assert.Equal(new[]
            {
                $"/{expectedTemplate}",
                $"/{expectedTemplate}/$count"
            },
                         action.Selectors.Select(s => s.AttributeRouteModel.Template));
        }
示例#3
0
        public void AppliesToActionForBasicEntityActionWorksAsExpected(string actionName)
        {
            // Arrange
            ControllerModel controller = ControllerModelHelpers.BuildControllerModel <CustomersController>(actionName);
            ActionModel     action     = controller.Actions.First();

            ODataControllerActionContext context = ODataControllerActionContextHelpers.BuildContext(string.Empty, EdmModel, controller);

            context.Action = action;

            EntityRoutingConvention entityConvention = ConventionHelpers.CreateConvention <EntityRoutingConvention>();

            // Act
            bool returnValue = entityConvention.AppliesToAction(context);

            Assert.True(returnValue);

            // Assert
            Assert.Equal(2, action.Selectors.Count);
            Assert.Collection(action.Selectors,
                              e =>
            {
                Assert.Equal("/Customers(FirstName={keyFirstName},LastName={keyLastName})", e.AttributeRouteModel.Template);
            },
                              e =>
            {
                Assert.Equal("/Customers/FirstName={keyFirstName},LastName={keyLastName}", e.AttributeRouteModel.Template);
            });
        }
示例#4
0
        public void AppliesToActionForEntityActionWithDerivedEntityTypeAndCaseInsensitiveWorksAsExpected()
        {
            // Arrange
            ControllerModel controller = ControllerModelHelpers.BuildControllerModel <CaseInsensitiveCustomersController>("GetVIPCUSTOMER");
            ActionModel     action     = controller.Actions.First();

            ODataControllerActionContext context = ODataControllerActionContextHelpers.BuildContext(string.Empty, EdmModel, controller);

            context.Action = action;
            context.Options.RouteOptions.EnableActionNameCaseInsensitive = true;

            EntityRoutingConvention entityConvention = ConventionHelpers.CreateConvention <EntityRoutingConvention>();

            // Act
            bool returnValue = entityConvention.AppliesToAction(context);

            Assert.True(returnValue);

            // Assert
            Assert.Equal(2, action.Selectors.Count);
            Assert.Collection(action.Selectors,
                              e =>
            {
                Assert.Equal("/CaseInsensitiveCustomers(FirstName={keyFirstName},LastName={keyLastName})/NS.VipCustomer", e.AttributeRouteModel.Template);
            },
                              e =>
            {
                Assert.Equal("/CaseInsensitiveCustomers/FirstName={keyFirstName},LastName={keyLastName}/NS.VipCustomer", e.AttributeRouteModel.Template);
            });
        }
示例#5
0
        public void AppliesToControllerReturnsExpectedForController(Type controllerType, bool expected)
        {
            // Arrange
            ControllerModel controller                       = ControllerModelHelpers.BuildControllerModel(controllerType);
            ODataControllerActionContext context             = ODataControllerActionContextHelpers.BuildContext(string.Empty, EdmModel, controller);
            EntitySetRoutingConvention   entitySetConvention = ConventionHelpers.CreateConvention <EntitySetRoutingConvention>();

            // Act
            bool actual = entitySetConvention.AppliesToController(context);

            // Assert
            Assert.Equal(expected, actual);
        }
示例#6
0
        public void AppliesToActionDoesNothingForNonConventionAction(string actionName)
        {
            // Arrange
            ControllerModel controller = ControllerModelHelpers.BuildControllerModel <AnotherCustomersController>(actionName);
            ActionModel     action     = controller.Actions.First();

            ODataControllerActionContext context = ODataControllerActionContextHelpers.BuildContext(string.Empty, EdmModel, controller);

            context.Action = controller.Actions.First();

            EntitySetRoutingConvention entitySetConvention = ConventionHelpers.CreateConvention <EntitySetRoutingConvention>();

            // Act
            entitySetConvention.AppliesToAction(context);

            // Assert
            Assert.Empty(action.Selectors);
        }
示例#7
0
        public void AppliesToActionForPostActionWorksAsExpected(string actionName, string expected)
        {
            // Arrange
            ControllerModel controller = ControllerModelHelpers.BuildControllerModel <CustomersController>(actionName);
            ActionModel     action     = controller.Actions.First();

            ODataControllerActionContext context = ODataControllerActionContextHelpers.BuildContext(string.Empty, EdmModel, controller);

            context.Action = controller.Actions.First();

            EntitySetRoutingConvention entitySetConvention = ConventionHelpers.CreateConvention <EntitySetRoutingConvention>();

            // Act
            bool returnValue = entitySetConvention.AppliesToAction(context);

            Assert.True(returnValue);

            // Assert
            SelectorModel selector = Assert.Single(action.Selectors);

            Assert.Equal(expected, selector.AttributeRouteModel.Template);
        }
示例#8
0
        public void AppliesToActionDoesNothingForNotSupportedAction(string actionName)
        {
            // Arrange
            ControllerModel controller = ControllerModelHelpers.BuildControllerModel <AnotherCustomersController>(actionName);
            ActionModel     action     = controller.Actions.First();

            ODataControllerActionContext context = ODataControllerActionContextHelpers.BuildContext(string.Empty, EdmModel, controller);

            context.Action = controller.Actions.First();

            EntityRoutingConvention entityConvention = ConventionHelpers.CreateConvention <EntityRoutingConvention>();

            // Act
            bool returnValue = entityConvention.AppliesToAction(context);

            Assert.False(returnValue);

            // Assert
            SelectorModel selector = Assert.Single(action.Selectors);

            Assert.Null(selector.AttributeRouteModel);
        }
示例#9
0
        public void AppliesToActionForEntityActionWithDerivedEntityTypeWorksAsExpected(string actionName)
        {
            // Arrange
            ControllerModel controller = ControllerModelHelpers.BuildControllerModel <CustomersController>(actionName);
            ActionModel     action     = controller.Actions.First();

            ODataControllerActionContext context = ODataControllerActionContextHelpers.BuildContext(string.Empty, EdmModel, controller);

            context.Action = action;

            EntityRoutingConvention entityConvention = ConventionHelpers.CreateConvention <EntityRoutingConvention>();

            // Act
            bool returnValue = entityConvention.AppliesToAction(context);

            Assert.True(returnValue);

            // Assert
            SelectorModel selector = Assert.Single(action.Selectors);

            Assert.Equal("Customers(FirstName={keyFirstName},LastName={keyLastName})/NS.VipCustomer", selector.AttributeRouteModel.Template);
        }
        public void AppliesToAction_Works_ForPatchActionWorksAsExpected(Type controllerType, string actionName, string expected, bool ignoreCase)
        {
            // Arrange
            ControllerModel controller = ControllerModelHelpers.BuildControllerModel(controllerType, actionName);
            ActionModel     action     = controller.Actions.First();

            ODataControllerActionContext context = ODataControllerActionContextHelpers.BuildContext(string.Empty, EdmModel, controller);

            context.Action = controller.Actions.First();
            context.Options.RouteOptions.EnableActionNameCaseInsensitive = ignoreCase;

            EntitySetRoutingConvention entitySetConvention = ConventionHelpers.CreateConvention <EntitySetRoutingConvention>();

            // Act
            bool returnValue = entitySetConvention.AppliesToAction(context);

            Assert.True(returnValue);

            // Assert
            SelectorModel selector = Assert.Single(action.Selectors);

            Assert.Equal(expected, selector.AttributeRouteModel.Template);
        }