Example #1
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);
            });
        }
Example #2
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));
        }
Example #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);
            });
        }
        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));
        }
Example #5
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));
        }
Example #6
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));
        }
        public void AppliesToActionWithLongTemplateWorksAsExpected()
        {
            // Arrange
            ControllerModel controller = ControllerModelHelpers.BuildControllerModel <WithoutPrefixController>("LongAction");
            ActionModel     action     = controller.Actions.First();

            SelectorModel selectorModel = Assert.Single(action.Selectors); // Guard

            Assert.Equal("Customers({key})/Orders({relatedKey})/NS.MyOrder/Title", selectorModel.AttributeRouteModel.Template);
            Assert.DoesNotContain(selectorModel.EndpointMetadata, a => a is ODataRoutingMetadata);

            ODataControllerActionContext context = new ODataControllerActionContext(string.Empty, _edmModel, controller)
            {
                Action  = action,
                Options = _options,
            };

            // Act
            bool ok = _attributeConvention.AppliesToAction(context);

            Assert.False(ok);

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

            Assert.Equal("/Customers({key})/Orders({relatedKey})/NS.MyOrder/Title", actualSelectorModel.AttributeRouteModel.Template);
            Assert.Contains(actualSelectorModel.EndpointMetadata, a => a is ODataRoutingMetadata);
        }
        private static ApplicationModelProviderContext CreateProviderContext(Type controllerType)
        {
            var             context         = new ApplicationModelProviderContext(new[] { controllerType.GetTypeInfo() });
            ControllerModel controllerModel = ControllerModelHelpers.BuildControllerModelWithAllActions(controllerType);

            context.Result.Controllers.Add(controllerModel);
            return(context);
        }
        public void AppliesToControllerReturnsExpectedForController(Type controllerType, bool expected)
        {
            // Arrange
            ControllerModel controller           = ControllerModelHelpers.BuildControllerModel(controllerType);
            ODataControllerActionContext context = ODataControllerActionContextHelpers.BuildContext(string.Empty, EdmModel, controller);

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

            // Assert
            Assert.Equal(expected, actual);
        }
        public void FunctionRoutingConventionResolveFunctionOverloadAsExpected(MethodInfo method, string[] templates)
        {
            // Arrange
            ControllerModel controller = ControllerModelHelpers.BuildControllerModelByMethodInfo <CustomersController>(method);
            ActionModel     action     = controller.Actions.First();

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

            context.Action = action;

            // Act
            FunctionConvention.AppliesToAction(context);

            // Assert
            Assert.Equal(templates.Length, action.Selectors.Count);
            Assert.Equal(templates, action.Selectors.Select(s => s.AttributeRouteModel.Template));
        }
Example #11
0
        public void SingletonRoutingConventionTestDataRunsAsExpected(string actionName, string[] templates)
        {
            // Arrange
            ControllerModel controller = ControllerModelHelpers.BuildControllerModel <RefCustomersController>(actionName);
            ActionModel     action     = controller.Actions.First();

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

            context.Action = action;

            // Act
            _refConvention.AppliesToAction(context);

            // Assert
            Assert.Equal(templates.Length, action.Selectors.Count);
            Assert.Equal(templates, action.Selectors.Select(s => s.AttributeRouteModel.Template));
        }
        public void AppliesToActionWithRoutePrefixWorksAsExpected()
        {
            // Arrange
            ControllerModel controller = ControllerModelHelpers.BuildControllerModel <WithPrefixController>("List");
            ActionModel     action     = controller.Actions.First();

            Assert.Equal(2, action.Selectors.Count);

            ODataControllerActionContext context = new ODataControllerActionContext(string.Empty, _edmModel, controller)
            {
                Action  = action,
                Options = _options,
            };

            AttributeRoutingConvention attributeConvention = CreateConvention();

            // Act
            bool ok = _attributeConvention.AppliesToAction(context);

            Assert.False(ok);

            // Assert
            Assert.Equal(4, action.Selectors.Count);
            Assert.Collection(action.Selectors,
                              e =>
            {
                Assert.Equal("/Customers/{key}", e.AttributeRouteModel.Template);
                Assert.Contains(e.EndpointMetadata, a => a is ODataRoutingMetadata);
            },
                              e =>
            {
                Assert.Equal("/Orders/{key}", e.AttributeRouteModel.Template);
                Assert.Contains(e.EndpointMetadata, a => a is ODataRoutingMetadata);
            },
                              e =>
            {
                Assert.Equal("/Customers", e.AttributeRouteModel.Template);
                Assert.Contains(e.EndpointMetadata, a => a is ODataRoutingMetadata);
            },
                              e =>
            {
                Assert.Equal("/Orders", e.AttributeRouteModel.Template);
                Assert.Contains(e.EndpointMetadata, a => a is ODataRoutingMetadata);
            });
        }
        public void ActionRoutingConventionTestDataWithCaseInsensitiveActionNameRunsAsExpected(Type controllerType, string actionName, string[] templates)
        {
            // Arrange
            ControllerModel controller = ControllerModelHelpers.BuildControllerModel(controllerType, actionName);
            ActionModel     action     = controller.Actions.First();

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

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

            // Act
            ActionConvention.AppliesToAction(context);

            // Assert
            Assert.Equal(templates.Length, action.Selectors.Count);
            Assert.Equal(templates, action.Selectors.Select(s => s.AttributeRouteModel.Template));
        }
Example #14
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);
        }
Example #15
0
        public void OperationImportRoutingConventionDoesNothingForNotSupportedAction(string actionName)
        {
            // Arrange
            ControllerModel controller = ControllerModelHelpers.BuildControllerModel <ODataOperationImportController>(actionName);
            ActionModel     action     = controller.Actions.First();

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

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

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

            Assert.True(returnValue);

            // Assert
            Assert.Empty(action.Selectors);
        }
        public void NavigationRoutingConventionTestDataRunsAsExpected(Type controllerType, string actionName, string[] templates)
        {
            // Arrange
            ControllerModel controller = ControllerModelHelpers.BuildControllerModel(controllerType, actionName);
            ActionModel     action     = controller.Actions.First();

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

            context.Action = action;

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

            Assert.True(returnValue);

            // Assert
            Assert.Equal(templates.Length, action.Selectors.Count);
            Assert.Equal(templates, action.Selectors.Select(s => s.AttributeRouteModel.Template));
        }
        public void ActionRoutingConventionDoesCaseSensitiveMatchingByDefault(Type controllerType, string actionName, string[] templates)
        {
            // Arrange
            ControllerModel controller = ControllerModelHelpers.BuildControllerModel(controllerType, actionName);
            ActionModel     action     = controller.Actions.First();

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

            context.Action = action;

            // Act
            ActionConvention.AppliesToAction(context);

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

            Assert.Null(selector.AttributeRouteModel);
            Assert.NotEmpty(templates);
        }
        public void AppliesToActionAddTemplateForServiceDocumentWithPrefix(string prefix)
        {
            // Arrange
            string          expected   = string.IsNullOrEmpty(prefix) ? "/" : $"/{prefix}/";
            ControllerModel controller = ControllerModelHelpers.BuildControllerModel <MetadataController>("GetServiceDocument");
            ActionModel     action     = controller.Actions.First();

            ODataControllerActionContext context = ODataControllerActionContextHelpers.BuildContext(prefix, EdmCoreModel.Instance, controller);

            context.Action = action;

            // Act
            _metadataConvention.AppliesToAction(context);

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

            Assert.Equal(expected, selector.AttributeRouteModel.Template);
        }
Example #19
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);
        }
Example #20
0
        public void RefRoutingConventionDoesNothingForNotSupportedAction(string actionName)
        {
            // Arrange
            ControllerModel controller = ControllerModelHelpers.BuildControllerModel <RefCustomersController>(actionName);
            ActionModel     action     = controller.Actions.First();

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

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

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

            Assert.False(returnValue);

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

            Assert.Null(selector.AttributeRouteModel);
        }
        public void AppliesToActionWithoutRoutePrefixWorksAsExpected()
        {
            // Arrange
            ControllerModel controller = ControllerModelHelpers.BuildControllerModel <WithoutPrefixController>("MyAction");
            ActionModel     action     = controller.Actions.First();

            Assert.Collection(action.Selectors, // Guard
                              e =>
            {
                Assert.Equal("Customers({key})", e.AttributeRouteModel.Template);
                Assert.DoesNotContain(e.EndpointMetadata, a => a is ODataRoutingMetadata);
            },
                              e =>
            {
                Assert.Equal("Customers/{key}/Name", e.AttributeRouteModel.Template);
                Assert.DoesNotContain(e.EndpointMetadata, a => a is ODataRoutingMetadata);
            });

            ODataControllerActionContext context = new ODataControllerActionContext(string.Empty, _edmModel, controller);

            context.Action  = action;
            context.Options = _options;

            // Act
            bool ok = _attributeConvention.AppliesToAction(context);

            Assert.False(ok);

            Assert.Equal(2, action.Selectors.Count);
            Assert.Collection(action.Selectors,
                              e =>
            {
                Assert.Equal("/Customers({key})", e.AttributeRouteModel.Template);
                Assert.Contains(e.EndpointMetadata, a => a is ODataRoutingMetadata);
            },
                              e =>
            {
                Assert.Equal("/Customers/{key}/Name", e.AttributeRouteModel.Template);
                Assert.Contains(e.EndpointMetadata, a => a is ODataRoutingMetadata);
            });
        }
Example #22
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);
        }
Example #23
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);
        }
        public void AppliesToActionForSingletonDoesnotWorksAsExpected()
        {
            // Arrange
            ControllerModel controller = ControllerModelHelpers.BuildControllerModel <SingletonTestControllerWithPrefix>("GetVipCustomerAliasWithPrefix");
            ActionModel     action     = controller.Actions.First();

            ODataControllerActionContext context = new ODataControllerActionContext(string.Empty, _edmModel, controller);

            context.Action  = action;
            context.Options = _options;

            // Act
            bool ok = _attributeConvention.AppliesToAction(context);

            Assert.False(ok);

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

            Assert.NotNull(selector.AttributeRouteModel);
            Assert.Equal("Alias", selector.AttributeRouteModel.Template);
            Assert.DoesNotContain(selector.EndpointMetadata, a => a is ODataRoutingMetadata);
        }