コード例 #1
0
        public void GenerateActionLinkForFeed_ThrowsArgumentNull_Action()
        {
            // Arrange
            FeedContext feedContext = new FeedContext();

            // Act & Assert
            Assert.ThrowsArgumentNull(() => feedContext.GenerateActionLink(action: null), "action");
        }
コード例 #2
0
        public void GenerateActionLinkForFeed_ThrowsArgumentNull_FeedContext()
        {
            // Arrange
            FeedContext feedContext = null;
            IEdmAction  action      = new Mock <IEdmAction>().Object;

            // Act & Assert
            Assert.ThrowsArgumentNull(() => feedContext.GenerateActionLink(action), "feedContext");
        }
コード例 #3
0
        public void GenerateActionLinkForFeed_ThrowsActionNotBoundToCollectionOfEntity_IfActionHasNoParameters()
        {
            // Arrange
            FeedContext       context = new FeedContext();
            Mock <IEdmAction> action  = new Mock <IEdmAction>();

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

            // Act & Assert
            Assert.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.");
        }
コード例 #4
0
        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 FeedContext
            {
                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);
        }
コード例 #5
0
        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 FeedContext
            {
                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);
        }
コード例 #6
0
        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 FeedContext
            {
                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);
        }
コード例 #7
0
        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 FeedContext
            {
                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);
        }
コード例 #8
0
        public void GenerateActionLinkForFeed_ThrowsActionNotBoundToCollectionOfEntity_IfActionHasNoParameters()
        {
            // Arrange
            FeedContext context = new FeedContext();
            Mock<IEdmAction> action = new Mock<IEdmAction>();
            action.Setup(a => a.Parameters).Returns(Enumerable.Empty<IEdmOperationParameter>());
            action.Setup(a => a.Name).Returns("SomeAction");

            // Act & Assert
            Assert.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.");
        }
コード例 #9
0
        public void GenerateActionLinkForFeed_ThrowsArgumentNull_Action()
        {
            // Arrange
            FeedContext feedContext = new FeedContext();

            // Act & Assert
            Assert.ThrowsArgumentNull(() => feedContext.GenerateActionLink(action: null), "action");
        }