コード例 #1
0
        public void AppliesToControllerWithLongTemplateWorksAsExpected()
        {
            // Arrange
            ControllerModel controller = ControllerModelHelpers.BuildControllerModel <WithoutPrefixController>("LongAction");
            ActionModel     action     = controller.Actions.First();

            ODataControllerActionContext context             = new ODataControllerActionContext(string.Empty, EdmModel, controller);
            AttributeRoutingConvention   attributeConvention = CreateConvention();

            // Act
            bool ok = attributeConvention.AppliesToController(context);

            Assert.False(ok);

            // Assert
            Assert.Equal(4, action.Selectors.Count);
            Assert.Equal(new[]
            {
                "/Customers({key})/Orders({relatedKey})/NS.MyOrder/Title",
                "/Customers({key})/Orders/{relatedKey}/NS.MyOrder/Title",
                "/Customers/{key}/Orders({relatedKey})/NS.MyOrder/Title",
                "/Customers/{key}/Orders/{relatedKey}/NS.MyOrder/Title"
            },
                         action.Selectors.Select(s => s.AttributeRouteModel.Template));
        }
コード例 #2
0
        public void AppliesToControllerWithRoutePrefixWorksAsExpected()
        {
            // Arrange
            ControllerModel controller = ControllerModelHelpers.BuildControllerModel <WithPrefixController>("List");
            ActionModel     action     = controller.Actions.First();

            ODataControllerActionContext context             = new ODataControllerActionContext(string.Empty, EdmModel, controller);
            AttributeRoutingConvention   attributeConvention = CreateConvention();

            // Act
            bool ok = attributeConvention.AppliesToController(context);

            Assert.False(ok);

            // Assert
            Assert.Equal(6, action.Selectors.Count);
            Assert.Equal(new[]
            {
                "Customers({key})",
                "Customers/{key}",
                "Customers",
                "Orders({key})",
                "Orders/{key}",
                "Orders",
            },
                         action.Selectors.Select(s => s.AttributeRouteModel.Template));
        }
コード例 #3
0
        public void AppliesToControllerForSingletonWorksAsExpected(string actionName, string expectedTemplate)
        {
            // Arrange
            ControllerModel controller = ControllerModelHelpers.BuildControllerModel <SingletonTestControllerWithPrefix>(actionName);
            ActionModel     action     = controller.Actions.First();

            ODataControllerActionContext context             = new ODataControllerActionContext(string.Empty, EdmModel, controller);
            AttributeRoutingConvention   attributeConvention = CreateConvention();

            // Act
            bool ok = attributeConvention.AppliesToController(context);

            Assert.False(ok);

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

            Assert.NotNull(selector.AttributeRouteModel);
            Assert.Equal(expectedTemplate, selector.AttributeRouteModel.Template);
        }