예제 #1
0
        public void HasFeedFunctionLink_SetsFollowsConventions(bool value)
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            var function = builder.EntityType <Customer>().Collection.Function("IgnoreFunction");

            // Act
            function.HasFeedFunctionLink((a) => { throw new NotImplementedException(); }, followsConventions: value);

            // Assert
            Assert.Equal(value, function.FollowsConventions);
        }
예제 #2
0
        public void CreateEdmModelWithEntitySetFromAbstractEntityTypeWithoutKey_Throws()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();

            builder.EntityType <Customer>().Abstract().Property(c => c.CustomerId);
            builder.EntitySet <Customer>("Customers");

            // Act & Assert
            Assert.Throws <InvalidOperationException>(() => builder.GetEdmModel(),
                                                      "The entity set or singleton 'Customers' is based on type 'System.Web.OData.Builder.TestModels.Customer' that has no keys defined.");
        }
예제 #3
0
        public void DollarMetadata_Works_ForNullableReferencialConstraint_WithCustomReferentialConstraints()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();

            builder.EntityType <FkSupplier>().HasKey(c => c.Id);

            var product = builder.EntityType <FkProduct>().HasKey(o => o.Id);

            product.HasOptional(o => o.Supplier, (o, c) => o.SupplierId == c.Id);
            product.HasRequired(o => o.SupplierNav, (o, c) => o.SupplierKey == c.Id);

            IEdmModel model = builder.GetEdmModel();

            HttpConfiguration config = new[] { typeof(MetadataController) }.GetHttpConfiguration();
            HttpServer        server = new HttpServer(config);

            config.MapODataServiceRoute("odata", "odata", model);

            HttpClient client = new HttpClient(server);

            // Act
            HttpResponseMessage response = client.GetAsync("http://localhost/odata/$metadata").Result;

            // Assert
            Assert.True(response.IsSuccessStatusCode);

            Assert.Equal("application/xml", response.Content.Headers.ContentType.MediaType);
            string payload = response.Content.ReadAsStringAsync().Result;

            // non-nullable
            Assert.Contains("<Property Name=\"SupplierId\" Type=\"Edm.Int32\" />", payload);
            Assert.Contains("<NavigationProperty Name=\"Supplier\" Type=\"System.Web.OData.Formatter.FkSupplier\">", payload);
            Assert.Contains("<ReferentialConstraint Property=\"SupplierId\" ReferencedProperty=\"Id\" />", payload);

            // nullable
            Assert.Contains("<Property Name=\"SupplierKey\" Type=\"Edm.Int32\" Nullable=\"false\" />", payload);
            Assert.Contains("<NavigationProperty Name=\"SupplierNav\" Type=\"System.Web.OData.Formatter.FkSupplier\" Nullable=\"false\">", payload);
            Assert.Contains("<ReferentialConstraint Property=\"SupplierKey\" ReferencedProperty=\"Id\" />", payload);
        }
예제 #4
0
        public void HasFeedActionLink_ThrowsException_OnNoBoundToCollectionEntityActions()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            EntityTypeConfiguration <Customer> customer = builder.EntityType <Customer>();
            ActionConfiguration action = customer.Action("NonCollectionAction");

            // Act & Assert
            Assert.Throws <InvalidOperationException>(
                () => action.HasFeedActionLink(ctx => new Uri("http://any"), followsConventions: false),
                "To register an action link factory, actions must be bindable to the collection of entity. " +
                "Action 'NonCollectionAction' does not meet this requirement.");
        }
예제 #5
0
        public void CanCreateTransientAction()
        {
            ODataModelBuilder builder = new ODataModelBuilder();
            EntityTypeConfiguration <Customer> customer = builder.EntityType <Customer>();

            customer.TransientAction("Reward");

            ProcedureConfiguration action = builder.Procedures.SingleOrDefault();

            Assert.NotNull(action);
            Assert.True(action.IsBindable);
            Assert.False(action.IsAlwaysBindable);
        }
예제 #6
0
        public void ReturnsCollection_ThrowsInvalidOperationException_IfReturnTypeIsEntity()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();

            builder.EntityType <Movie>();
            var action = builder.Action("action");

            // Act & Assert
            Assert.Throws <InvalidOperationException>(() => action.ReturnsCollection <Movie>(),
                                                      "The EDM type 'System.Web.OData.Builder.Movie' is already declared as an entity type. Use the " +
                                                      "method 'ReturnsCollectionFromEntitySet' if the return type is an entity collection.");
        }
예제 #7
0
        public void HasFunctionLink_ThrowsException_OnNoBoundToEntityFunctions()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            EntityTypeConfiguration <Customer> customer = builder.EntityType <Customer>();
            FunctionConfiguration function = customer.Collection.Function("CollectionFunction");

            // Act & Assert
            Assert.Throws <InvalidOperationException>(
                () => function.HasFunctionLink(ctx => new Uri("http://any"), followsConventions: false),
                "To register a function link factory, functions must be bindable to a single entity. " +
                "Function 'CollectionFunction' does not meet this requirement.");
        }
예제 #8
0
        public void HasManyPath_AddBindindPath_Derived(bool contained)
        {
            // Assert
            ODataModelBuilder builder = new ODataModelBuilder();
            var customerType          = builder.EntityType <BindingCustomer>();
            var navigationSource      = builder.EntitySet <BindingCustomer>("Customers");

            StructuralTypeConfiguration addressType = builder.StructuralTypes.FirstOrDefault(c => c.Name == "BindingAddress");

            Assert.Null(addressType);              // Guard
            Assert.Empty(customerType.Properties); // Guard

            // Act
            var binding    = new BindingPathConfiguration <BindingCustomer>(builder, customerType, navigationSource.Configuration);
            var newBinding = binding.HasManyPath((BindingVipCustomer v) => v.VipAddresses, contained);

            // Assert
            addressType = builder.StructuralTypes.FirstOrDefault(c => c.Name == "BindingAddress");
            Assert.NotNull(addressType);
            Assert.Empty(customerType.Properties);

            StructuralTypeConfiguration vipCustomerType = builder.StructuralTypes.FirstOrDefault(c => c.Name == "BindingVipCustomer");

            Assert.NotNull(vipCustomerType);
            var vipAddressesProperty = Assert.Single(vipCustomerType.Properties);

            Assert.Equal("VipAddresses", vipAddressesProperty.Name);

            if (contained)
            {
                Assert.Equal(EdmTypeKind.Entity, addressType.Kind);
                Assert.Equal(PropertyKind.Navigation, vipAddressesProperty.Kind);
                NavigationPropertyConfiguration navigationProperty = Assert.IsType <NavigationPropertyConfiguration>(vipAddressesProperty);
                Assert.Equal(EdmMultiplicity.Many, navigationProperty.Multiplicity);
                Assert.True(navigationProperty.ContainsTarget);
            }
            else
            {
                Assert.Equal(EdmTypeKind.Complex, addressType.Kind);
                Assert.Equal(PropertyKind.Collection, vipAddressesProperty.Kind);
                CollectionPropertyConfiguration collection = Assert.IsType <CollectionPropertyConfiguration>(vipAddressesProperty);
                Assert.Equal(typeof(BindingAddress), collection.ElementType);
            }

            // different bindings
            Assert.NotSame(binding, newBinding);
            Assert.Equal("", binding.BindingPath);

            Assert.IsType <BindingPathConfiguration <BindingAddress> >(newBinding);
            Assert.Equal("System.Web.OData.Formatter.BindingVipCustomer/VipAddresses", newBinding.BindingPath);
        }
예제 #9
0
        public void CreateStreamPrimitiveProperty()
        {
            ODataModelBuilder builder = new ODataModelBuilder();
            var file = builder.EntityType <File>();
            var data = file.Property(f => f.StreamData);

            var model          = builder.GetServiceModel();
            var fileType       = model.SchemaElements.OfType <IEdmEntityType>().Single();
            var streamProperty = fileType.DeclaredProperties.SingleOrDefault(p => p.Name == "StreamData");

            Assert.Equal(PropertyKind.Primitive, data.Kind);

            Assert.NotNull(streamProperty);
            Assert.Equal("Edm.Stream", streamProperty.Type.FullName());
        }
예제 #10
0
        public void CanCreateFunctionThatBindsToEntityCollection()
        {
            // Arrange
            // Act
            ODataModelBuilder builder = new ODataModelBuilder();
            EntityTypeConfiguration <Customer> customer = builder.EntityType <Customer>();
            FunctionConfiguration sendEmail             = customer.Collection.Function("SendEmail");

            // Assert
            Assert.True(sendEmail.IsBindable);
            Assert.NotNull(sendEmail.Parameters);
            Assert.Equal(1, sendEmail.Parameters.Count());
            Assert.Equal(BindingParameterConfiguration.DefaultBindingParameterName, sendEmail.Parameters.Single().Name);
            Assert.Equal(string.Format("Collection({0})", typeof(Customer).FullName), sendEmail.Parameters.Single().TypeConfiguration.FullName);
        }
예제 #11
0
        public void DynamicDictionaryProperty_Works_ToSetEntityTypeAsOpen()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();

            // Act
            EntityTypeConfiguration <SimpleOpenEntityType> entityType = builder.EntityType <SimpleOpenEntityType>();

            entityType.HasKey(c => c.Id);
            entityType.Property(c => c.Name);
            entityType.HasDynamicProperties(c => c.DynamicProperties);

            // Act & Assert
            Assert.True(entityType.IsOpen);
        }
예제 #12
0
        public void HasKeyOnDerivedTypes_Works_ForBaseTypeWithoutKey()
        {
            // Arrange
            var builder = new ODataModelBuilder();

            builder.EntityType <Vehicle>().Abstract();
            builder.EntityType <Motorcycle>().DerivesFrom <Vehicle>().HasKey(m => m.ID);

            // Act
            IEdmModel model = builder.GetEdmModel();

            // Assert
            IEdmEntityType vehicleType = model.AssertHasEntityType(typeof(Vehicle));

            Assert.True(vehicleType.IsAbstract);
            Assert.Null(vehicleType.DeclaredKey);

            IEdmEntityType motorCycleType = model.AssertHasEntityType(typeof(Motorcycle), typeof(Vehicle));

            Assert.False(motorCycleType.IsAbstract);
            IEdmStructuralProperty keyProperty = Assert.Single(motorCycleType.DeclaredKey);

            Assert.Equal("ID", keyProperty.Name);
        }
예제 #13
0
        public void GetEdmModel_CanSetMultiReferentialConstraint_WithCustomPrincipal()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            EntityTypeConfiguration <MultiUser> userType = builder.EntityType <MultiUser>();

            userType.HasKey(c => c.UserId1)
            .HasKey(c => c.UserId2)
            .HasMany(c => c.Roles);

            EntityTypeConfiguration <MultiRole> roleType = builder.EntityType <MultiRole>();

            roleType.HasKey(r => r.RoleId)
            .HasRequired(r => r.User, (r, u) => r.UserKey1 == u.PrincipalUserKey1 && r.UserKey2 == u.PrincipalUserKey2)
            .CascadeOnDelete();

            // Act
            IEdmModel model = builder.GetEdmModel();

            // Assert
            Assert.NotNull(model);
            IEdmEntityType roleEntityType = model.AssertHasEntityType(typeof(MultiRole));

            IEdmNavigationProperty usersNav = roleEntityType.AssertHasNavigationProperty(model, "User",
                                                                                         typeof(MultiUser), isNullable: false, multiplicity: EdmMultiplicity.One);

            Assert.Equal(EdmOnDeleteAction.Cascade, usersNav.OnDelete);

            Assert.Equal(2, usersNav.DependentProperties().Count());
            Assert.Equal("UserKey1", usersNav.DependentProperties().First().Name);
            Assert.Equal("UserKey2", usersNav.DependentProperties().Last().Name);

            Assert.Equal(2, usersNav.PrincipalProperties().Count());
            Assert.Equal("PrincipalUserKey1", usersNav.PrincipalProperties().First().Name);
            Assert.Equal("PrincipalUserKey2", usersNav.PrincipalProperties().Last().Name);
        }
        public void NonbindingParameterConfigurationThrowsWhenParameterTypeIsEntity()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();

            builder.EntityType <Customer>();

            // Act & Assert
            ArgumentException exception = Assert.Throws <ArgumentException>(() =>
            {
                NonbindingParameterConfiguration configuration = new NonbindingParameterConfiguration("name", builder.GetTypeConfigurationOrNull(typeof(Customer)));
            });

            Assert.True(exception.Message.Contains(string.Format("'{0}'", typeof(Customer).FullName)));
            Assert.Equal("parameterType", exception.ParamName);
        }
예제 #15
0
        public void GetEdmModel_ThrowsException_WhenBoundActionOverloaded()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            EntityTypeConfiguration <Customer> customer = builder.EntityType <Customer>();

            customer.HasKey(c => c.CustomerId);
            customer.Property(c => c.Name);
            customer.Action("ActionOnCustomer");
            customer.Action("ActionOnCustomer").Returns <string>();

            // Act & Assert
            Assert.Throws <InvalidOperationException>(() => builder.GetEdmModel(),
                                                      "Found more than one action with name 'ActionOnCustomer' " +
                                                      "bound to the same type 'System.Web.OData.Builder.TestModels.Customer'. " +
                                                      "Each bound action must have a different binding type or name.");
        }
예제 #16
0
        public void CanCreateEdmModel_WithTransientBindableAction()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            EntityTypeConfiguration <Customer> customer = builder.EntityType <Customer>();

            customer.HasKey(c => c.CustomerId);
            customer.Property(c => c.Name);

            // Act
            ActionConfiguration sendEmail = customer.TransientAction("ActionName");
            IEdmModel           model     = builder.GetEdmModel();

            // Assert
            IEdmAction action = Assert.Single(model.SchemaElements.OfType <IEdmAction>());

            Assert.True(action.IsBound);
        }
예제 #17
0
        public void CanCreateEntityWithCompoundKey()
        {
            var builder  = new ODataModelBuilder();
            var customer = builder.EntityType <Customer>();

            customer.HasKey(c => new { c.CustomerId, c.Name });
            customer.Property(c => c.SharePrice);
            customer.Property(c => c.ShareSymbol);
            customer.Property(c => c.Website);

            var model        = builder.GetServiceModel();
            var customerType = model.FindType(typeof(Customer).FullName) as IEdmEntityType;

            Assert.Equal(5, customerType.Properties().Count());
            Assert.Equal(2, customerType.DeclaredKey.Count());
            Assert.NotNull(customerType.DeclaredKey.SingleOrDefault(k => k.Name == "CustomerId"));
            Assert.NotNull(customerType.DeclaredKey.SingleOrDefault(k => k.Name == "Name"));
        }
예제 #18
0
        public NavigationPropertyBindingConfiguration HasManyBinding <TTargetType, TDerivedEntityType>(
            Expression <Func <TDerivedEntityType, IEnumerable <TTargetType> > > navigationExpression, string entitySetName)
            where TTargetType : class
            where TDerivedEntityType : class, TEntityType
        {
            if (navigationExpression == null)
            {
                throw Error.ArgumentNull("navigationExpression");
            }

            if (String.IsNullOrEmpty(entitySetName))
            {
                throw Error.ArgumentNullOrEmpty("entitySetName");
            }

            EntityTypeConfiguration <TDerivedEntityType> derivedEntityType =
                _modelBuilder.EntityType <TDerivedEntityType>().DerivesFrom <TEntityType>();

            return(this.Configuration.AddBinding(derivedEntityType.HasMany(navigationExpression),
                                                 _modelBuilder.EntitySet <TTargetType>(entitySetName)._configuration));
        }
예제 #19
0
        public void CanAddPrimitiveProperty_ForTargetEntityType()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();

            // Act
            builder.EntityType <ForeignEntity>().HasRequired(c => c.Principal, (c, r) => c.ForeignKey1 == r.PrincipalKey1);

            // Assert
            EntityTypeConfiguration principalEntityType = Assert.Single(
                builder.StructuralTypes.OfType <EntityTypeConfiguration>().Where(e => e.Name == "ForeignPrincipal"));

            PropertyConfiguration          propertyConfig  = Assert.Single(principalEntityType.Properties);
            PrimitivePropertyConfiguration primitiveConfig =
                Assert.IsType <PrimitivePropertyConfiguration>(propertyConfig);

            Assert.Equal("PrincipalKey1", primitiveConfig.Name);
            Assert.Equal("System.Int32", primitiveConfig.RelatedClrType.FullName);
        }
예제 #20
0
        public void CanSetSinglePrincipalProperty_ForReferencialConstraint()
        {
            // Arrange
            PropertyInfo      expectDependentPropertyInfo = typeof(ForeignEntity).GetProperty("ForeignKey1");
            PropertyInfo      expectPrincipalPropertyInfo = typeof(ForeignPrincipal).GetProperty("PrincipalKey1");
            ODataModelBuilder builder = new ODataModelBuilder();

            // Act
            NavigationPropertyConfiguration navigationProperty =
                builder.EntityType <ForeignEntity>().HasRequired(c => c.Principal, (c, r) => c.ForeignKey1 == r.PrincipalKey1);

            // Assert
            PropertyInfo actualPropertyInfo = Assert.Single(navigationProperty.DependentProperties);

            Assert.Same(expectDependentPropertyInfo, actualPropertyInfo);

            actualPropertyInfo = Assert.Single(navigationProperty.PrincipalProperties);
            Assert.Same(expectPrincipalPropertyInfo, actualPropertyInfo);
        }
예제 #21
0
        public void CanConfig_PrecisionAndScaleOfDecimalType()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            var entity = builder.EntityType <PrecisionEnitity>().HasKey(p => p.Id);

            entity.Property(p => p.DecimalProperty).Precision = 5;
            entity.Property(p => p.DecimalProperty).Scale     = 3;

            // Act
            IEdmModel                model         = builder.GetEdmModel();
            IEdmEntityType           edmEntityType = model.SchemaElements.OfType <IEdmEntityType>().First(p => p.Name == "PrecisionEnitity");
            IEdmDecimalTypeReference decimalType   =
                (IEdmDecimalTypeReference)edmEntityType.DeclaredProperties.First(p => p.Name.Equals("DecimalProperty")).Type;

            // Assert
            Assert.Equal(decimalType.Precision.Value, 5);
            Assert.Equal(decimalType.Scale.Value, 3);
        }
예제 #22
0
        public void CanCreateAbstractEntityTypeWithoutKey()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();

            builder.EntityType <BaseAbstractShape>().Abstract();

            // Act
            IEdmModel model = builder.GetEdmModel();

            // Assert
            IEdmEntityType baseShapeType =
                model.SchemaElements.OfType <IEdmEntityType>().FirstOrDefault(e => e.Name == "BaseAbstractShape");

            Assert.NotNull(baseShapeType);
            Assert.True(baseShapeType.IsAbstract);
            Assert.Null(baseShapeType.DeclaredKey);
            Assert.Empty(baseShapeType.Properties());
        }
예제 #23
0
        public void CreateTimeOfDayPrimitiveProperty()
        {
            // Arrange
            ODataModelBuilder builder                = new ODataModelBuilder();
            EntityTypeConfiguration <File> file      = builder.EntityType <File>();
            PrimitivePropertyConfiguration timeOfDay = file.Property(f => f.TimeOfDayProperty);

            // Act
            IEdmModel model = builder.GetServiceModel();

            // Assert
            Assert.Equal(PropertyKind.Primitive, timeOfDay.Kind);

            IEdmEntityType fileType = Assert.Single(model.SchemaElements.OfType <IEdmEntityType>());

            IEdmProperty property = Assert.Single(fileType.DeclaredProperties.Where(p => p.Name == "TimeOfDayProperty"));

            Assert.NotNull(property);
            Assert.Equal("Edm.TimeOfDay", property.Type.FullName());
        }
예제 #24
0
        public void CanAddPrimitiveProperty_ForDependentEntityType()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();

            // Act
            builder.EntityType <ForeignEntity>().HasRequired(c => c.Principal, (c, r) => c.ForeignKey1 == r.PrincipalKey1);

            // Assert
            EntityTypeConfiguration dependentEntityType =
                builder.StructuralTypes.OfType <EntityTypeConfiguration>().FirstOrDefault(e => e.Name == "ForeignEntity");

            Assert.NotNull(dependentEntityType);

            PrimitivePropertyConfiguration primitiveConfig =
                Assert.Single(dependentEntityType.Properties.OfType <PrimitivePropertyConfiguration>());

            Assert.Equal("ForeignKey1", primitiveConfig.Name);
            Assert.Equal("System.Int32", primitiveConfig.RelatedClrType.FullName);
        }
예제 #25
0
        public void CanCreateEntityWithCompoundKey_ForDateAndTimeOfDay()
        {
            // Arrange
            var builder = new ODataModelBuilder();
            var entity  = builder.EntityType <EntityTypeWithDateAndTimeOfDay>();

            entity.HasKey(e => new { e.Date, e.TimeOfDay });

            // Act
            var model = builder.GetServiceModel();

            // Assert
            var entityType =
                model.SchemaElements.OfType <IEdmEntityType>().Single(e => e.Name == "EntityTypeWithDateAndTimeOfDay");

            Assert.Equal(2, entityType.Properties().Count());
            Assert.Equal(2, entityType.DeclaredKey.Count());
            Assert.NotNull(entityType.DeclaredKey.SingleOrDefault(k => k.Name == "Date"));
            Assert.NotNull(entityType.DeclaredKey.SingleOrDefault(k => k.Name == "TimeOfDay"));
        }
예제 #26
0
        public void GetEdmModel_PropertyWithETag_IsConcurrencyToken()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            EntityTypeConfiguration <Customer> customer = builder.EntityType <Customer>();

            customer.HasKey(c => c.Id);
            customer.Property(c => c.Id);
            customer.Property(c => c.Name).IsConcurrencyToken();

            // Act
            IEdmModel model = builder.GetEdmModel();

            // Assert
            IEdmEntityType         type     = model.AssertHasEntityType(typeof(Customer));
            IEdmStructuralProperty property =
                type.AssertHasPrimitiveProperty(model, "Name", EdmPrimitiveTypeKind.String, isNullable: true);

            Assert.Equal(EdmConcurrencyMode.Fixed, property.ConcurrencyMode);
        }
        public void CanCreateEdmModel_WithTransientBindableFunction()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            EntityTypeConfiguration <Customer> customer = builder.EntityType <Customer>();

            customer.HasKey(c => c.CustomerId);
            customer.Property(c => c.Name);

            // Act
            FunctionConfiguration sendEmail = customer.TransientFunction("FunctionName");

            sendEmail.Returns <bool>();
            IEdmModel model = builder.GetEdmModel();

            // Assert
            Assert.Equal(1, model.SchemaElements.OfType <IEdmFunction>().Count());
            IEdmFunction function = Assert.Single(model.SchemaElements.OfType <IEdmFunction>());

            Assert.True(function.IsBound);
        }
예제 #28
0
        public void CanSetBasePrincipalProperty_ForReferencialConstraint()
        {
            // Arrange
            PropertyInfo      expectPrincipalPropertyInfo = typeof(DerivedPrincipal).GetProperty("PrincipalId");
            PropertyInfo      expectDependentPropertyInfo = typeof(DependentEntity).GetProperty("PrincipalKey");
            ODataModelBuilder builder = new ODataModelBuilder();

            // Act
            NavigationPropertyConfiguration navigationProperty =
                builder.EntityType <DependentEntity>().HasRequired(d => d.Principal, (d, p) => d.PrincipalKey == p.PrincipalId);

            // Assert
            PropertyInfo actualPropertyInfo = Assert.Single(navigationProperty.DependentProperties);

            Assert.Same(expectDependentPropertyInfo, actualPropertyInfo);

            actualPropertyInfo = Assert.Single(navigationProperty.PrincipalProperties);
            Assert.NotSame(expectPrincipalPropertyInfo, actualPropertyInfo);

            Assert.Same(typeof(BasePrincipal).GetProperty("PrincipalId"), actualPropertyInfo);
        }
예제 #29
0
        public void CanConfig_MaxLengthOfStringAndBinaryType()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            var entity = builder.EntityType <PrecisionEnitity>().HasKey(p => p.Id);

            entity.Property(p => p.StringProperty).MaxLength = 5;
            entity.Property(p => p.BinaryProperty).MaxLength = 3;

            // Act
            IEdmModel               model         = builder.GetEdmModel();
            IEdmEntityType          edmEntityType = model.SchemaElements.OfType <IEdmEntityType>().First(p => p.Name == "PrecisionEnitity");
            IEdmStringTypeReference stringType    =
                (IEdmStringTypeReference)edmEntityType.DeclaredProperties.First(p => p.Name.Equals("StringProperty")).Type;
            IEdmBinaryTypeReference binaryType =
                (IEdmBinaryTypeReference)edmEntityType.DeclaredProperties.First(p => p.Name.Equals("BinaryProperty")).Type;

            // Assert
            Assert.Equal(stringType.MaxLength.Value, 5);
            Assert.Equal(binaryType.MaxLength.Value, 3);
        }
예제 #30
0
        public void DefaultValue_PrecisionScaleAndMaxLength()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            var entity = builder.EntityType <PrecisionEnitity>().HasKey(p => p.Id);

            entity.Property(p => p.DecimalProperty);
            entity.Property(p => p.StringProperty);

            // Act
            IEdmModel               model         = builder.GetEdmModel();
            IEdmEntityType          edmEntityType = model.SchemaElements.OfType <IEdmEntityType>().First(p => p.Name == "PrecisionEnitity");
            IEdmStringTypeReference stringType    =
                (IEdmStringTypeReference)edmEntityType.DeclaredProperties.First(p => p.Name.Equals("StringProperty")).Type;
            IEdmDecimalTypeReference decimalType =
                (IEdmDecimalTypeReference)edmEntityType.DeclaredProperties.First(p => p.Name.Equals("DecimalProperty")).Type;

            // Assert
            Assert.Equal(decimalType.Precision, null);
            Assert.Equal(decimalType.Scale, 0);
            Assert.Equal(stringType.MaxLength, null);
        }