public void CanConfigureDerivedTypeConstraints()
        {
            // Arrange
            ODataModelBuilder builder = ODataModelBuilderMocks.GetModelBuilderMock <ODataModelBuilder>();

            builder.EntityType <Animal>().DerivesFrom <Creature>();
            builder.EntityType <Human>().DerivesFrom <Creature>();
            var creaturesConfiguration = builder.EntitySet <Creature>("Creatures");

            creaturesConfiguration.HasDerivedTypeConstraint <Animal>().HasDerivedTypeConstraint <Human>();

            // Act
            IEdmModel model = builder.GetEdmModel();
            string    csdl  = MetadataTest.GetCSDL(model);

            // Assert
            Assert.NotNull(csdl);
            string expected = "<EntitySet Name=\"Creatures\" EntityType=\"Microsoft.AspNet.OData.Test.Builder.TestModels.Creature\">" +
                              "<Annotation Term=\"Org.OData.Validation.V1.DerivedTypeConstraint\">" +
                              "<Collection>" +
                              "<String>Microsoft.AspNet.OData.Test.Builder.TestModels.Animal</String>" +
                              "<String>Microsoft.AspNet.OData.Test.Builder.TestModels.Human</String>" +
                              "</Collection>" +
                              "</Annotation>" +
                              "</EntitySet>";

            Assert.Contains(expected, csdl);
        }
예제 #2
0
        public void CanConfigureDerivedTypeConstraints()
        {
            ODataModelBuilder builder = new ODataModelBuilder();

            builder.EntitySet <Creature>("Creatures").EntityType.HasKey(c => c.Id);
            builder.EntityType <Animal>().DerivesFrom <Creature>();
            builder.EntityType <Human>().DerivesFrom <Creature>();
            builder.EntityType <Gene>().DerivesFrom <Creature>(); // No restriction
            builder.EntityType <StateZoo>().DerivesFrom <Zoo>();  // No restriction
            builder.EntityType <NationZoo>().DerivesFrom <Zoo>();
            builder.EntityType <SeaZoo>().DerivesFrom <Zoo>();
            var zooType = builder.EntityType <Zoo>();

            var function = zooType.Function("MyFunction").ReturnsFromEntitySet <Creature>("Creatures");

            function.BindingParameter.HasDerivedTypeConstraint <SeaZoo>().HasDerivedTypeConstraint <NationZoo>();
            function.HasDerivedTypeConstraintForReturnType <Animal>().HasDerivedTypeConstraintForReturnType <Human>();
            function.ReturnTypeConstraints.Location = Microsoft.OData.Edm.Csdl.EdmVocabularyAnnotationSerializationLocation.OutOfLine;

            function.BindingParameter.DerivedTypeConstraints.Location = Microsoft.OData.Edm.Csdl.EdmVocabularyAnnotationSerializationLocation.OutOfLine;

            IEdmModel model = builder.GetEdmModel();

            string csdl = MetadataTest.GetCSDL(model);

            Assert.NotNull(csdl);

            Assert.Contains("<Annotations Target=\"Default.MyFunction(Microsoft.AspNet.OData.Test.Builder.TestModels.Zoo)/$ReturnType\">" +
                            "<Annotation Term=\"Org.OData.Validation.V1.DerivedTypeConstraint\">" +
                            "<Collection>" +
                            "<String>Microsoft.AspNet.OData.Test.Builder.TestModels.Animal</String>" +
                            "<String>Microsoft.AspNet.OData.Test.Builder.TestModels.Human</String>" +
                            "</Collection>" +
                            "</Annotation>" +
                            "</Annotations>" +
                            "<Annotations Target=\"Default.MyFunction(Microsoft.AspNet.OData.Test.Builder.TestModels.Zoo)/bindingParameter\">" +
                            "<Annotation Term=\"Org.OData.Validation.V1.DerivedTypeConstraint\">" +
                            "<Collection>" +
                            "<String>Microsoft.AspNet.OData.Test.Builder.TestModels.SeaZoo</String>" +
                            "<String>Microsoft.AspNet.OData.Test.Builder.TestModels.NationZoo</String>" +
                            "</Collection>" +
                            "</Annotation>" +
                            "</Annotations>", csdl);
        }
예제 #3
0
        public void CanConfigureDerivedTypeConstraints()
        {
            ODataModelBuilder builder = new ODataModelBuilder();

            builder.EntitySet <Creature>("Creatures").EntityType.HasKey(c => c.Id);
            builder.EntityType <Animal>().DerivesFrom <Creature>();
            builder.EntityType <Human>().DerivesFrom <Creature>();
            builder.EntityType <Gene>().DerivesFrom <Creature>(); // No restriction
            builder.EntityType <StateZoo>().DerivesFrom <Zoo>();  // No restriction
            builder.EntityType <NationZoo>().DerivesFrom <Zoo>();
            builder.EntityType <SeaZoo>().DerivesFrom <Zoo>();
            var zooType = builder.EntityType <Zoo>();

            var action = zooType.Action("MyAction").ReturnsFromEntitySet <Creature>("Creatures");

            action.BindingParameter.HasDerivedTypeConstraint <SeaZoo>().HasDerivedTypeConstraint <NationZoo>();
            action.HasDerivedTypeConstraintForReturnType <Animal>().HasDerivedTypeConstraintForReturnType <Human>();
            IEdmModel model = builder.GetEdmModel();

            string csdl = MetadataTest.GetCSDL(model);

            Assert.NotNull(csdl);

            Assert.Contains("<Action Name=\"MyAction\" IsBound=\"true\">" +
                            "<Parameter Name=\"bindingParameter\" Type=\"Microsoft.AspNet.OData.Test.Builder.TestModels.Zoo\">" +
                            "<Annotation Term=\"Org.OData.Validation.V1.DerivedTypeConstraint\">" +
                            "<Collection>" +
                            "<String>Microsoft.AspNet.OData.Test.Builder.TestModels.SeaZoo</String>" +
                            "<String>Microsoft.AspNet.OData.Test.Builder.TestModels.NationZoo</String>" +
                            "</Collection>" +
                            "</Annotation>" +
                            "</Parameter>" +
                            "<ReturnType Type=\"Microsoft.AspNet.OData.Test.Builder.TestModels.Creature\">" +
                            "<Annotation Term=\"Org.OData.Validation.V1.DerivedTypeConstraint\">" +
                            "<Collection>" +
                            "<String>Microsoft.AspNet.OData.Test.Builder.TestModels.Animal</String>" +
                            "<String>Microsoft.AspNet.OData.Test.Builder.TestModels.Human</String>" +
                            "</Collection>" +
                            "</Annotation>" +
                            "</ReturnType>" +
                            "</Action>", csdl);
        }