Example #1
0
        internal static Uri GenerateActionLink(this ResourceSetContext feedContext, string bindingParameterType,
                                               string actionName)
        {
            Contract.Assert(feedContext != null);

            if (feedContext.EntitySetBase is IEdmContainedEntitySet)
            {
                return(null);
            }

            if (feedContext.EdmModel == null)
            {
                return(null);
            }

            IEdmModel model       = feedContext.EdmModel;
            string    elementType = DeserializationHelpers.GetCollectionElementTypeName(bindingParameterType,
                                                                                        isNested: false);

            Contract.Assert(elementType != null);

            IEdmTypeReference typeReference = model.FindDeclaredType(elementType).ToEdmTypeReference(true);
            IEdmTypeReference collection    = new EdmCollectionTypeReference(new EdmCollectionType(typeReference));

            IEdmOperation operation = model.FindDeclaredOperations(actionName).First();

            return(feedContext.GenerateActionLink(collection, operation));
        }
        public void GenerateActionLinkForFeed_ThrowsArgumentNull_Action()
        {
            // Arrange
            ResourceSetContext resourceSetContext = new ResourceSetContext();

            // Act & Assert
            ExceptionAssert.ThrowsArgumentNull(() => resourceSetContext.GenerateActionLink(action: null), "action");
        }
        public void GenerateActionLinkForFeed_ThrowsArgumentNull_FeedContext()
        {
            // Arrange
            ResourceSetContext feedContext = null;
            IEdmAction         action      = new Mock <IEdmAction>().Object;

            // Act & Assert
            ExceptionAssert.ThrowsArgumentNull(() => feedContext.GenerateActionLink(action), "resourceSetContext");
        }
        public void GenerateActionLinkForFeed_ThrowsActionNotBoundToCollectionOfEntity_IfActionHasNoParameters()
        {
            // Arrange
            ResourceSetContext context = new ResourceSetContext();
            Mock <IEdmAction>  action  = new Mock <IEdmAction>();

            action.Setup(a => a.Parameters).Returns(Enumerable.Empty <IEdmOperationParameter>());
            action.Setup(a => a.Name).Returns("SomeAction");

            // Act & Assert
            ExceptionAssert.ThrowsArgument(
                () => context.GenerateActionLink(action.Object),
                "action",
                "The action 'SomeAction' is not bound to the collection of entity. Only actions that are bound to entities can have action links.");
        }
Example #5
0
        public void GenerateActionLinkForFeed_GeneratesLinkWithCast_IfEntitySetTypeDoesnotMatchActionEntityType()
        {
            // Arrange
            var        request = RequestFactory.Create(_model);
            IEdmAction action  = _model.SchemaElements.OfType <IEdmAction>().First(a => a.Name == "UpgradeSpecialAll");

            Assert.NotNull(action); // Guard
            ResourceSetContext context = new ResourceSetContext {
                EntitySetBase = _customers, Request = request
            };

            // Act
            Uri link = context.GenerateActionLink(action);

            // Assert
            Assert.Equal("http://localhost/Customers/NS.SpecialCustomer/NS.UpgradeSpecialAll", link.AbsoluteUri);
        }
Example #6
0
        public void GenerateActionLinkForFeed_GeneratesLinkWithDownCast_IfElementTypeDerivesFromBindingParameterType()
        {
            // Arrange
            var        request = RequestFactory.Create(_model);
            IEdmAction action  = _model.SchemaElements.OfType <IEdmAction>().First(a => a.Name == "UpgradeAll");

            Assert.NotNull(action); // Guard
            IEdmEntitySet specialCustomers = new EdmEntitySet(_model.EntityContainer, "SpecialCustomers", _specialCustomer);

            ResourceSetContext context = new ResourceSetContext {
                EntitySetBase = specialCustomers, Request = request
            };

            // Act
            Uri link = context.GenerateActionLink(action);

            // Assert
            Assert.Equal("http://localhost/SpecialCustomers/NS.Customer/NS.UpgradeAll", link.AbsoluteUri);
        }
        public void GenerateActionLinkForFeed_GeneratesLinkWithCast_IfEntitySetTypeDoesnotMatchActionEntityType()
        {
            // Arrange
            HttpRequestMessage request = GetODataRequest(_model.Model);
            IEdmAction         action  = _model.Model.SchemaElements.OfType <IEdmAction>().First(a => a.Name == "UpgradeSpecialAll");

            Assert.NotNull(action); // Guard
            var context = new ResourceSetContext
            {
                Request       = request,
                EntitySetBase = _model.Customers,
                Url           = request.GetUrlHelper(),
            };

            // Act
            Uri link = context.GenerateActionLink(action);

            // Assert
            Assert.Equal("http://localhost/Customers/NS.SpecialCustomer/NS.UpgradeSpecialAll", link.AbsoluteUri);
        }
        public void GenerateActionLinkForFeed_GeneratesLinkWithDownCast_IfElementTypeDerivesFromBindingParameterType()
        {
            // Arrange
            HttpRequestMessage request = GetODataRequest(_model.Model);
            IEdmAction         action  = _model.Model.SchemaElements.OfType <IEdmAction>().First(a => a.Name == "UpgradeAll");

            Assert.NotNull(action); // Guard
            IEdmEntitySet specialCustomers = new EdmEntitySet(_model.Container, "SpecialCustomers", _model.SpecialCustomer);

            var context = new ResourceSetContext
            {
                Request       = request,
                EntitySetBase = specialCustomers,
                Url           = request.GetUrlHelper(),
            };

            // Act
            Uri link = context.GenerateActionLink(action);

            // Assert
            Assert.Equal("http://localhost/SpecialCustomers/NS.Customer/NS.UpgradeAll", link.AbsoluteUri);
        }