Ejemplo n.º 1
0
        public void CanCreateEntityWithCompoundEnumKeys()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            var enumEntityType        = builder.EntityType <EnumModel>();

            enumEntityType.HasKey(c => new { c.Simple, c.Long });

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

            // Assert
            IEdmEntityType entityType = model.SchemaElements.OfType <IEdmEntityType>()
                                        .FirstOrDefault(c => c.Name == "EnumModel");

            Assert.NotNull(entityType);
            Assert.Equal(2, entityType.Properties().Count());

            Assert.Equal(2, entityType.DeclaredKey.Count());
            IEdmStructuralProperty simpleKey = entityType.DeclaredKey.First(k => k.Name == "Simple");

            Assert.Equal(EdmTypeKind.Enum, simpleKey.Type.TypeKind());
            Assert.Equal("Microsoft.OData.ModelBuilder.Tests.TestModels.SimpleEnum", simpleKey.Type.Definition.FullTypeName());

            IEdmStructuralProperty longKey = entityType.DeclaredKey.First(k => k.Name == "Long");

            Assert.Equal(EdmTypeKind.Enum, longKey.Type.TypeKind());
            Assert.Equal("Microsoft.OData.ModelBuilder.Tests.TestModels.LongEnum", longKey.Type.Definition.FullTypeName());
        }
Ejemplo n.º 2
0
        public void CreateEntityTypeWithRelationship()
        {
            var builder = new ODataModelBuilder().Add_Customer_EntityType().Add_Order_EntityType().Add_OrderCustomer_Relationship();

            var model     = builder.GetServiceModel();
            var orderType = model.SchemaElements.OfType <IEdmEntityType>().SingleOrDefault(t => t.Name == "Order");

            Assert.NotNull(orderType);
            Assert.Equal("Order", orderType.Name);
            Assert.Equal(typeof(Order).Namespace, orderType.Namespace);
            Assert.Equal("OrderId", orderType.DeclaredKey.Single().Name);
            Assert.Equal(5, orderType.DeclaredProperties.Count());
            Assert.Single(orderType.NavigationProperties());
            var deliveryDateProperty = orderType.DeclaredProperties.Single(dp => dp.Name == "DeliveryDate");

            Assert.NotNull(deliveryDateProperty);
            Assert.True(deliveryDateProperty.Type.IsNullable);

            Assert.Equal("Customer", orderType.NavigationProperties().First().Name);
            Assert.Equal("Customer", orderType.NavigationProperties().First().ToEntityType().Name);

            var customerType = model.SchemaElements.OfType <IEdmEntityType>().SingleOrDefault(t => t.Name == "Customer");

            Assert.NotNull(customerType);
            Assert.Equal("Customer", customerType.Name);
            Assert.Equal(typeof(Customer).Namespace, customerType.Namespace);
            Assert.Equal("CustomerId", customerType.DeclaredKey.Single().Name);
            Assert.Equal(5, customerType.DeclaredProperties.Count());
        }
Ejemplo n.º 3
0
        public void CanCreateEntityWithPrimitiveAndEnumKey()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            var enumEntityType        = builder.EntityType <EnumModel>();

            enumEntityType.HasKey(c => new { c.Simple, c.Id });

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

            // Assert
            IEdmEntityType entityType = model.SchemaElements.OfType <IEdmEntityType>()
                                        .FirstOrDefault(c => c.Name == "EnumModel");

            Assert.NotNull(entityType);
            Assert.Equal(2, entityType.Properties().Count());

            Assert.Equal(2, entityType.DeclaredKey.Count());
            IEdmStructuralProperty enumKey = entityType.DeclaredKey.First(k => k.Name == "Simple");

            Assert.Equal(EdmTypeKind.Enum, enumKey.Type.TypeKind());
            Assert.Equal("Microsoft.AspNet.OData.Test.Common.Types.SimpleEnum", enumKey.Type.Definition.FullTypeName());

            IEdmStructuralProperty primitiveKey = entityType.DeclaredKey.First(k => k.Name == "Id");

            Assert.Equal(EdmTypeKind.Primitive, primitiveKey.Type.TypeKind());
            Assert.Equal("Edm.Int32", primitiveKey.Type.Definition.FullTypeName());
        }
Ejemplo n.º 4
0
        public void CreateDatePrimitiveProperty_FromDateTime()
        {
            // Arrange
            ODataModelBuilder builder           = new ODataModelBuilder();
            EntityTypeConfiguration <File> file = builder.EntityType <File>();

            file.Property(f => f.Birthday).AsDate();
            file.Property(f => f.PublishDay).AsDate();

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

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

            IEdmProperty birthdayProperty = Assert.Single(fileType.DeclaredProperties.Where(p => p.Name == "Birthday"));

            Assert.NotNull(birthdayProperty);
            Assert.False(birthdayProperty.Type.IsNullable);
            Assert.Equal("Edm.Date", birthdayProperty.Type.FullName());

            IEdmProperty publishDayProperty = Assert.Single(fileType.DeclaredProperties.Where(p => p.Name == "PublishDay"));

            Assert.NotNull(publishDayProperty);
            Assert.True(publishDayProperty.Type.IsNullable);
            Assert.Equal("Edm.Date", publishDayProperty.Type.FullName());
        }
        public void AnnotationsAreAddedToModelOnBuild()
        {
            var modelBuilder           = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet();
            var entitySetConfiguration = modelBuilder.EntitySet <Customer>("Customers");

            var deleteRestrictionsBuilder = entitySetConfiguration
                                            .HasDeleteRestrictions()
                                            .IsDeletable(false)
                                            .HasDescription(Description);

            var model     = modelBuilder.GetServiceModel();
            var container = model.SchemaElements.OfType <IEdmEntityContainer>().SingleOrDefault();
            var customers = container.EntitySets().SingleOrDefault(e => e.Name == "Customers");

            var term       = model.FindTerm("Org.OData.Capabilities.V1.DeleteRestrictions");
            var annotation = customers.VocabularyAnnotations(model).FirstOrDefault(a => a.Term == term);

            Assert.NotNull(annotation);

            var annotationValue = annotation.Value as EdmRecordExpression;

            Assert.NotNull(annotationValue);

            var descriptionValue = GetRecordValue <EdmStringConstant>(annotationValue, "Description");

            Assert.Equal(Description, descriptionValue.Value);
        }
        public void PermissionsCanBeAddedToEntitySet()
        {
            var modelBuilder = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet();

            var deleteRestrictionsBuilder = modelBuilder
                                            .EntitySet <Customer>("Customers")
                                            .HasDeleteRestrictions()
                                            .IsDeletable(false)
                                            .HasDescription(Description)
                                            .HasPermissions(
                permission => permission
                .HasSchemeName(SchemeName)
                .HasScopes(scope => scope
                           .HasScope(CustomerReadWriteAllScope)
                           .HasRestrictedProperties("*")))
                                            .HasLongDescription(LongDescription);

            var model     = modelBuilder.GetServiceModel();
            var container = model.SchemaElements.OfType <IEdmEntityContainer>().SingleOrDefault();
            var customers = container.EntitySets().SingleOrDefault(e => e.Name == "Customers");

            var term       = model.FindTerm("Org.OData.Capabilities.V1.DeleteRestrictions");
            var annotation = customers.VocabularyAnnotations(model).FirstOrDefault(a => a.Term == term);

            Assert.NotNull(annotation);

            var annotationValue = annotation.Value as EdmRecordExpression;

            Assert.NotNull(annotationValue);

            var permissionsCollection = GetRecordValue <EdmCollectionExpression>(annotationValue, "Permissions");

            Assert.NotNull(permissionsCollection);

            var singlePermission = Assert.Single(permissionsCollection.Elements) as EdmRecordExpression;

            Assert.NotNull(singlePermission);

            var schemeNameValue = GetRecordValue <EdmStringConstant>(singlePermission, "SchemeName");

            Assert.NotNull(schemeNameValue);

            Assert.Equal(SchemeName, schemeNameValue.Value);

            var scopesProperty = GetRecordValue <EdmCollectionExpression>(singlePermission, "Scopes");

            Assert.NotNull(scopesProperty);

            var singleScope = Assert.Single(scopesProperty.Elements) as EdmRecordExpression;

            Assert.NotNull(singleScope);

            var scopeValue = GetRecordValue <EdmStringConstant>(singleScope, "Scope");

            Assert.Equal(CustomerReadWriteAllScope, scopeValue.Value);

            var restrictedPropertiesValue = GetRecordValue <EdmStringConstant>(singleScope, "RestrictedProperties");

            Assert.Equal("*", restrictedPropertiesValue.Value);
        }
Ejemplo n.º 7
0
        public void CreateTimeOfDayPrimitiveProperty_FromTimeSpan()
        {
            // Arrange
            ODataModelBuilder builder           = new ODataModelBuilder();
            EntityTypeConfiguration <File> file = builder.EntityType <File>();

            file.Property(f => f.CreatedTime).AsTimeOfDay();
            file.Property(f => f.EndTime).AsTimeOfDay();

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

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

            IEdmProperty createProperty = Assert.Single(fileType.DeclaredProperties.Where(p => p.Name == "CreatedTime"));

            Assert.NotNull(createProperty);
            Assert.False(createProperty.Type.IsNullable);
            Assert.Equal("Edm.TimeOfDay", createProperty.Type.FullName());

            IEdmProperty endProperty = Assert.Single(fileType.DeclaredProperties.Where(p => p.Name == "EndTime"));

            Assert.NotNull(endProperty);
            Assert.True(endProperty.Type.IsNullable);
            Assert.Equal("Edm.TimeOfDay", endProperty.Type.FullName());
        }
Ejemplo n.º 8
0
        public void CreateEntityTypeWithRelationship()
        {
            var builder = new ODataModelBuilder().Add_Customer_EntityType().Add_Order_EntityType().Add_OrderCustomer_Relationship();

            var model = builder.GetServiceModel();
            var orderType = model.SchemaElements.OfType<IEdmEntityType>().SingleOrDefault(t => t.Name == "Order");
            Assert.NotNull(orderType);
            Assert.Equal("Order", orderType.Name);
            Assert.Equal(typeof(Order).Namespace, orderType.Namespace);
            Assert.Equal("OrderId", orderType.DeclaredKey.Single().Name);
            Assert.Equal(5, orderType.DeclaredProperties.Count());
            Assert.Equal(1, orderType.NavigationProperties().Count());
            var deliveryDateProperty = orderType.DeclaredProperties.Single(dp => dp.Name == "DeliveryDate");
            Assert.NotNull(deliveryDateProperty);
            Assert.True(deliveryDateProperty.Type.IsNullable);

            Assert.Equal("Customer", orderType.NavigationProperties().First().Name);
            Assert.Equal("Customer", orderType.NavigationProperties().First().ToEntityType().Name);

            var customerType = model.SchemaElements.OfType<IEdmEntityType>().SingleOrDefault(t => t.Name == "Customer");
            Assert.NotNull(customerType);
            Assert.Equal("Customer", customerType.Name);
            Assert.Equal(typeof(Customer).Namespace, customerType.Namespace);
            Assert.Equal("CustomerId", customerType.DeclaredKey.Single().Name);
            Assert.Equal(5, customerType.DeclaredProperties.Count());
        }
        public void AnnotationsAreAddedToModelOnBuild()
        {
            var modelBuilder        = new ODataModelBuilder();
            var actionConfiguration = modelBuilder.Action("MyAction");

            var operationRestrictionsBuilder = actionConfiguration
                                               .HasOperationRestrictions()
                                               .IsFilterSegmentSupported(true);

            var model  = modelBuilder.GetServiceModel();
            var action = model.SchemaElements.OfType <IEdmAction>().Single();

            var term       = model.FindTerm("Org.OData.Capabilities.V1.OperationRestrictions");
            var annotation = action.VocabularyAnnotations(model).FirstOrDefault(a => a.Term == term);

            Assert.NotNull(annotation);

            var annotationValue = annotation.Value as EdmRecordExpression;

            Assert.NotNull(annotationValue);

            var filterSegmentSupportedValue = GetRecordValue <EdmBooleanConstant>(annotationValue, "FilterSegmentSupported");

            Assert.True(filterSegmentSupportedValue.Value);
        }
Ejemplo n.º 10
0
        public void CanCreateEntityWithCollectionProperties()
        {
            var builder  = new ODataModelBuilder();
            var customer = builder.EntityType <Customer>();

            customer.HasKey(c => c.CustomerId);
            customer.CollectionProperty(c => c.Aliases);
            customer.CollectionProperty(c => c.Addresses);


            var aliasesProperty   = customer.Properties.OfType <CollectionPropertyConfiguration>().SingleOrDefault(p => p.Name == "Aliases");
            var addressesProperty = customer.Properties.OfType <CollectionPropertyConfiguration>().SingleOrDefault(p => p.Name == "Addresses");

            Assert.Equal(3, customer.Properties.Count());
            Assert.Equal(2, customer.Properties.OfType <CollectionPropertyConfiguration>().Count());
            Assert.NotNull(aliasesProperty);
            Assert.Equal(typeof(string), aliasesProperty.ElementType);
            Assert.NotNull(addressesProperty);
            Assert.Equal(typeof(Address), addressesProperty.ElementType);

            Assert.Equal(2, builder.StructuralTypes.Count());
            var addressType = builder.StructuralTypes.Skip(1).FirstOrDefault();

            Assert.NotNull(addressType);
            Assert.Equal(EdmTypeKind.Complex, addressType.Kind);
            Assert.Equal(typeof(Address).FullName, addressType.FullName);

            var model           = builder.GetServiceModel();
            var edmCustomerType = model.FindType(typeof(Customer).FullName) as IEdmEntityType;
            var edmAddressType  = model.FindType(typeof(Address).FullName) as IEdmComplexType;
        }
        public void PermissionsCanBeAddedToOperation()
        {
            var modelBuilder        = new ODataModelBuilder();
            var actionConfiguration = modelBuilder.Action("MyAction");

            var operationRestrictionsBuilder = actionConfiguration
                                               .HasOperationRestrictions()
                                               .IsFilterSegmentSupported(true)
                                               .HasPermissions(
                new PermissionTypeConfiguration()
                .HasSchemeName(SchemeName)
                .HasScopes(
                    new ScopeTypeConfiguration()
                    .HasScope(CustomerReadWriteAllScope)
                    .HasRestrictedProperties("*")));

            var model  = modelBuilder.GetServiceModel();
            var action = model.SchemaElements.OfType <IEdmAction>().Single();

            var term       = model.FindTerm("Org.OData.Capabilities.V1.OperationRestrictions");
            var annotation = action.VocabularyAnnotations(model).FirstOrDefault(a => a.Term == term);

            Assert.NotNull(annotation);

            var annotationValue = annotation.Value as EdmRecordExpression;

            Assert.NotNull(annotationValue);

            var permissionsCollection = GetRecordValue <EdmCollectionExpression>(annotationValue, "Permissions");

            Assert.NotNull(permissionsCollection);

            var singlePermission = Assert.Single(permissionsCollection.Elements) as EdmRecordExpression;

            Assert.NotNull(singlePermission);

            var schemeNameValue = GetRecordValue <EdmStringConstant>(singlePermission, "SchemeName");

            Assert.NotNull(schemeNameValue);

            Assert.Equal(SchemeName, schemeNameValue.Value);

            var scopesProperty = GetRecordValue <EdmCollectionExpression>(singlePermission, "Scopes");

            Assert.NotNull(scopesProperty);

            var singleScope = Assert.Single(scopesProperty.Elements) as EdmRecordExpression;

            Assert.NotNull(singleScope);

            var scopeValue = GetRecordValue <EdmStringConstant>(singleScope, "Scope");

            Assert.Equal(CustomerReadWriteAllScope, scopeValue.Value);

            var restrictedPropertiesValue = GetRecordValue <EdmStringConstant>(singleScope, "RestrictedProperties");

            Assert.Equal("*", restrictedPropertiesValue.Value);
        }
Ejemplo n.º 12
0
 public void CreateComplexTypeProperty()
 {
     var builder = new ODataModelBuilder().Add_Customer_EntityType().Add_Address_ComplexType();
     builder.EntityType<Customer>().ComplexProperty(c => c.Address);
     var model = builder.GetServiceModel();
     var customerType = model.SchemaElements.OfType<IEdmEntityType>().Single();
     var addressProperty = customerType.FindProperty("Address");
     Assert.NotNull(addressProperty);
 }
Ejemplo n.º 13
0
 public void CreateComplexTypeProperty()
 {
     var builder = new ODataModelBuilder().Add_Customer_EntityType().Add_Address_ComplexType();
     builder.Entity<Customer>().ComplexProperty(c => c.Address);
     var model = builder.GetServiceModel();
     var customerType = model.SchemaElements.OfType<IEdmEntityType>().Single();
     var addressProperty = customerType.FindProperty("Address");
     Assert.NotNull(addressProperty);
 }
        public void CreateModelUsingProgrammableApi()
        {
            var builder = new ODataModelBuilder();
            var customerConfig = builder.AddEntityType(typeof(Customer));
            customerConfig.HasKey(typeof(Customer).GetProperty("CustomerId"));
            customerConfig.AddProperty(typeof(Customer).GetProperty("Name"));
            var ordersPropertyConfig = customerConfig.AddNavigationProperty(typeof(Customer).GetProperty("Orders"), EdmMultiplicity.Many);

            var orderConfig = builder.AddEntityType(typeof(Order));
            orderConfig.HasKey(typeof(Order).GetProperty("OrderId"));
            orderConfig.AddProperty(typeof(Order).GetProperty("Cost"));

            var customersSetConfig = builder.AddEntitySet("Customers", customerConfig);
            var ordersSetConfig = builder.AddEntitySet("Orders", orderConfig);
            customersSetConfig.AddBinding(ordersPropertyConfig, ordersSetConfig);

            var meConfig = builder.AddSingleton("Me", customerConfig);

            var model = builder.GetServiceModel();
            var customerType = model.SchemaElements.OfType<IEdmEntityType>().Single(e => e.Name == "Customer");
            Assert.NotNull(customerType);
            Assert.Equal(typeof(Customer).Namespace, customerType.Namespace);
            Assert.Equal(3, customerType.DeclaredProperties.Count());

            var key = customerType.DeclaredKey.SingleOrDefault();
            Assert.NotNull(key);
            Assert.Equal("CustomerId", key.Name);
            Assert.True(key.Type.IsInt32());
            Assert.False(key.Type.IsNullable);

            var nameProperty = customerType.DeclaredProperties.SingleOrDefault(dp => dp.Name == "Name");
            Assert.NotNull(nameProperty);
            Assert.True(nameProperty.Type.IsString());
            Assert.True(nameProperty.Type.IsNullable);

            Assert.Equal(1, customerType.NavigationProperties().Count());
            var ordersProperty = customerType.NavigationProperties().Single();
            Assert.Equal("Orders", ordersProperty.Name);
            Assert.Equal(EdmTypeKind.Collection, ordersProperty.Type.Definition.TypeKind);
            Assert.Equal(typeof(Order).FullName, (ordersProperty.Type.Definition as IEdmCollectionType).ElementType.FullName());

            var entityContainer = model.EntityContainer;
            Assert.NotNull(entityContainer);

            var customers = entityContainer.FindEntitySet("Customers");
            Assert.NotNull(customers);
            Assert.Equal(typeof(Customer).FullName, customers.EntityType().FullName());

            var orders = entityContainer.FindEntitySet("Orders");
            Assert.NotNull(orders);

            Assert.Equal(typeof(Order).FullName, orders.EntityType().FullName());

            var me = entityContainer.FindSingleton("Me");
            Assert.NotNull(me);
            Assert.Equal(typeof(Customer).FullName, me.EntityType().FullName());
        }
Ejemplo n.º 15
0
 public void CreateEntityType()
 {
     var builder = new ODataModelBuilder().Add_Customer_EntityType();
     var model = builder.GetServiceModel();
     var customerType = model.SchemaElements.OfType<IEdmEntityType>().SingleOrDefault(t => t.Name == "Customer");
     Assert.NotNull(customerType);
     Assert.Equal("Customer", customerType.Name);
     Assert.Equal(typeof(Customer).Namespace, customerType.Namespace);
     Assert.Equal("CustomerId", customerType.DeclaredKey.Single().Name);
     Assert.Equal(5, customerType.DeclaredProperties.Count());
 }
Ejemplo n.º 16
0
 public void CanEmitModelWithTwoEntitiesAndARelationshipWithNoBinding()
 {
     var builder = new ODataModelBuilder()
         .Add_Order_EntityType()
         .Add_Customer_EntityType()
         .Add_CustomerOrders_Relationship()
         .Add_Customers_EntitySet()
         .Add_Orders_EntitySet();
     var model = builder.GetServiceModel();
     var csdl = GetCSDL(model);
 }
Ejemplo n.º 17
0
 public void CanEmitModelWithTwoEntitiesAndARelationshipWithNoBinding()
 {
     var builder = new ODataModelBuilder()
                   .Add_Order_EntityType()
                   .Add_Customer_EntityType()
                   .Add_CustomerOrders_Relationship()
                   .Add_Customers_EntitySet()
                   .Add_Orders_EntitySet();
     var model = builder.GetServiceModel();
     var csdl  = GetCSDL(model);
 }
Ejemplo n.º 18
0
        public void CreateModelWithEntitySet()
        {
            var builder = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet();
            builder.EntitySet<Customer>("Customers");

            var model = builder.GetServiceModel();
            var container = model.SchemaElements.OfType<IEdmEntityContainer>().SingleOrDefault();
            Assert.NotNull(container);
            var customers = container.EntitySets().SingleOrDefault(e => e.Name == "Customers");
            Assert.NotNull(customers);
            Assert.Equal("Customer", customers.ElementType.Name);
        }
Ejemplo n.º 19
0
        public void CreateEntityType()
        {
            var builder      = new ODataModelBuilder().Add_Customer_EntityType();
            var model        = builder.GetServiceModel();
            var customerType = model.SchemaElements.OfType <IEdmEntityType>().SingleOrDefault(t => t.Name == "Customer");

            Assert.NotNull(customerType);
            Assert.Equal("Customer", customerType.Name);
            Assert.Equal(typeof(Customer).Namespace, customerType.Namespace);
            Assert.Equal("CustomerId", customerType.DeclaredKey.Single().Name);
            Assert.Equal(5, customerType.DeclaredProperties.Count());
        }
Ejemplo n.º 20
0
 public void CanEmitModelWithTwoEntitiesAndATwoWayRelationship()
 {
     var builder = new ODataModelBuilder()
                   .Add_Order_EntityType()
                   .Add_Customer_EntityType()
                   .Add_Customers_EntitySet()
                   .Add_Orders_EntitySet()
                   .Add_CustomerOrders_Binding() // creates nav prop too
                   .Add_OrderCustomer_Binding(); // creates nav prop too
     var model = builder.GetServiceModel();
     var csdl  = GetCSDL(model);
 }
Ejemplo n.º 21
0
 public void CanEmitModelWithTwoEntitiesAndATwoWayRelationship()
 {
     var builder = new ODataModelBuilder()
         .Add_Order_EntityType()
         .Add_Customer_EntityType()
         .Add_Customers_EntitySet()
         .Add_Orders_EntitySet()
         .Add_CustomerOrders_Binding() // creates nav prop too
         .Add_OrderCustomer_Binding(); // creates nav prop too
     var model = builder.GetServiceModel();
     var csdl = GetCSDL(model);
 }
Ejemplo n.º 22
0
        public void CanEmitModelWithSingleton()
        {
            // Arrange
            var builder = new ODataModelBuilder()
                          .Add_Company_Singleton();

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

            // Assert
            var csdl = GetCSDL(model);
        }
Ejemplo n.º 23
0
        public void CanEmitPartnerRelationship()
        {
            var builder = new ODataModelBuilder()
                          .Add_Company_EntityType()
                          .Add_Employee_EntityType()
                          .Add_CompanyEmployees_Relationship();
            var model    = builder.GetServiceModel();
            var company  = model.SchemaElements.Single(e => e.Name == nameof(Company)) as EdmEntityType;
            var ceo      = company.Properties().Single(p => p.Name == nameof(Company.CEO)) as EdmNavigationProperty;
            var employee = model.SchemaElements.Single(e => e.Name == nameof(Employee)) as EdmEntityType;
            var isCeoOf  = employee.Properties().Single(p => p.Name == nameof(Employee.IsCeoOf)) as EdmNavigationProperty;

            Assert.Equal(ceo.Partner, isCeoOf);
            var csdl = GetCSDL(model);
        }
Ejemplo n.º 24
0
        public void CreateStreamPrimitiveProperty()
        {
            ODataModelBuilder builder = new ODataModelBuilder();
            var file = builder.Entity<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());
        }
Ejemplo n.º 25
0
        public void CreateModelWithEntitySet()
        {
            var builder = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet();

            builder.EntitySet <Customer>("Customers");

            var model     = builder.GetServiceModel();
            var container = model.SchemaElements.OfType <IEdmEntityContainer>().SingleOrDefault();

            Assert.NotNull(container);
            var customers = container.EntitySets().SingleOrDefault(e => e.Name == "Customers");

            Assert.NotNull(customers);
            Assert.Equal("Customer", customers.EntityType().Name);
        }
Ejemplo n.º 26
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());
        }
Ejemplo n.º 27
0
        public void CanCreateEntityWithCompoundKey()
        {
            var builder = new ODataModelBuilder();
            var customer = builder.Entity<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"));
        }
Ejemplo n.º 28
0
        public void CanEmitModelWithSingletonHasEntitysetBinding()
        {
            // Arrange
            var builder = new ODataModelBuilder()
                          .Add_Company_EntityType()
                          .Add_Employee_EntityType()
                          .Add_CompanyEmployees_Relationship()
                          .Add_EmployeeComplany_Relationship()
                          .Add_MicrosoftEmployees_Binding();

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

            // Assert
            var csdl = GetCSDL(model);
        }
Ejemplo n.º 29
0
        public void CreateComplexTypePropertyInComplexType()
        {
            var builder = new ODataModelBuilder()
                .Add_Address_ComplexType();

            var address = builder.ComplexType<Address>();
            address.ComplexProperty(a => a.ZipCode);

            var model = builder.GetServiceModel();
            var addressType = model.SchemaElements.OfType<IEdmComplexType>().SingleOrDefault(se => se.Name == "Address");
            var zipCodeType = model.SchemaElements.OfType<IEdmComplexType>().SingleOrDefault(se => se.Name == "ZipCode");
            Assert.NotNull(addressType);
            Assert.NotNull(zipCodeType);
            var zipCodeProperty = addressType.FindProperty("ZipCode");
            Assert.NotNull(zipCodeProperty);
            Assert.Equal(zipCodeType.FullName(), zipCodeProperty.Type.AsComplex().ComplexDefinition().FullName());
        }
Ejemplo n.º 30
0
        public void CreateInfiniteRecursiveComplexTypeDefinitionSucceeds()
        {
            var builder = new ODataModelBuilder().Add_RecursiveZipCode_ComplexType();

            var zipCode = builder.ComplexType <RecursiveZipCode>();

            zipCode.ComplexProperty(z => z.Recursive);

            var model = builder.GetServiceModel();
            var recursiveZipCodeType = model.SchemaElements.OfType <IEdmComplexType>().SingleOrDefault(se => se.Name == "RecursiveZipCode");

            Assert.NotNull(recursiveZipCodeType);
            var recursiveZipCodeProperty = recursiveZipCodeType.FindProperty("Recursive");

            Assert.NotNull(recursiveZipCodeProperty);
            Assert.Equal(recursiveZipCodeType.FullName(), recursiveZipCodeProperty.Type.AsComplex().ComplexDefinition().FullName());
        }
Ejemplo n.º 31
0
        public void CreateComplexTypePropertyInComplexType()
        {
            var builder = new ODataModelBuilder()
                .Add_Address_ComplexType();

            var address = builder.ComplexType<Address>();
            address.ComplexProperty(a => a.ZipCode);

            var model = builder.GetServiceModel();
            var addressType = model.SchemaElements.OfType<IEdmComplexType>().SingleOrDefault(se => se.Name == "Address");
            var zipCodeType = model.SchemaElements.OfType<IEdmComplexType>().SingleOrDefault(se => se.Name == "ZipCode");
            Assert.NotNull(addressType);
            Assert.NotNull(zipCodeType);
            var zipCodeProperty = addressType.FindProperty("ZipCode");
            Assert.NotNull(zipCodeProperty);
            Assert.Equal(zipCodeType.FullName(), zipCodeProperty.Type.AsComplex().ComplexDefinition().FullName());
        }
Ejemplo n.º 32
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"));
        }
Ejemplo n.º 33
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"));
        }
Ejemplo n.º 34
0
        public void CreateDatePrimitiveProperty()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            EntityTypeConfiguration<File> file = builder.EntityType<File>();
            PrimitivePropertyConfiguration date = file.Property(f => f.DateProperty);

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

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

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

            IEdmProperty dateProperty = Assert.Single(fileType.DeclaredProperties.Where(p => p.Name == "DateProperty"));
            Assert.NotNull(dateProperty);
            Assert.Equal("Edm.Date", dateProperty.Type.FullName());
        }
Ejemplo n.º 35
0
        public void CreateModelWithTwoEntitySetsAndABinding()
        {
            var builder = new ODataModelBuilder()
                            .Add_Customer_EntityType()
                            .Add_Order_EntityType()
                            .Add_CustomerOrders_Relationship()
                            .Add_CustomerOrders_Binding();

            var model = builder.GetServiceModel();
            var container = model.SchemaElements.OfType<IEdmEntityContainer>().SingleOrDefault();
            Assert.NotNull(container);
            var customers = container.EntitySets().SingleOrDefault(e => e.Name == "Customers");
            Assert.NotNull(customers);
            var orders = container.EntitySets().SingleOrDefault(e => e.Name == "Orders");
            Assert.NotNull(orders);
            var customerOrders = customers.NavigationTargets.First(nt => nt.NavigationProperty.Name == "Orders");
            Assert.NotNull(customerOrders);
            Assert.Equal("Orders", customerOrders.TargetEntitySet.Name);
        }
Ejemplo n.º 36
0
        public void CreateDatePrimitiveProperty()
        {
            // Arrange
            ODataModelBuilder builder           = new ODataModelBuilder();
            EntityTypeConfiguration <File> file = builder.EntityType <File>();
            PrimitivePropertyConfiguration date = file.Property(f => f.DateProperty);

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

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

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

            IEdmProperty dateProperty = Assert.Single(fileType.DeclaredProperties.Where(p => p.Name == "DateProperty"));

            Assert.NotNull(dateProperty);
            Assert.Equal("Edm.Date", dateProperty.Type.FullName());
        }
Ejemplo n.º 37
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"));
        }
Ejemplo n.º 38
0
        public void CreateComplexTypeByConvention()
        {
            var builder = new ODataModelBuilder().Add_Address_ComplexType();

            var model = builder.GetServiceModel();
            var addressType = model.SchemaElements.OfType<IEdmComplexType>().Single();
            Assert.Equal("Address", addressType.Name);
            Assert.Equal(4, addressType.DeclaredProperties.Count());
            var houseNumberProperty = addressType.DeclaredProperties.SingleOrDefault(p => p.Name == "HouseNumber");
            var streetProperty = addressType.DeclaredProperties.SingleOrDefault(p => p.Name == "Street");
            var cityProperty = addressType.DeclaredProperties.SingleOrDefault(p => p.Name == "City");
            var stateProperty = addressType.DeclaredProperties.SingleOrDefault(p => p.Name == "State");
            var zipCodeProperty = addressType.DeclaredProperties.SingleOrDefault(p => p.Name == "ZipCode");

            Assert.NotNull(houseNumberProperty);
            Assert.NotNull(streetProperty);
            Assert.NotNull(cityProperty);
            Assert.NotNull(stateProperty);
            Assert.Null(zipCodeProperty);
            Assert.Equal("Edm.Int32", houseNumberProperty.Type.FullName());
            Assert.Equal("Edm.String", streetProperty.Type.FullName());
        }
Ejemplo n.º 39
0
        public void CreateComplexTypeByConvention()
        {
            var builder = new ODataModelBuilder().Add_Address_ComplexType();

            var model = builder.GetServiceModel();
            var addressType = model.SchemaElements.OfType<IEdmComplexType>().Single();
            Assert.Equal("Address", addressType.Name);
            Assert.Equal(4, addressType.DeclaredProperties.Count());
            var houseNumberProperty = addressType.DeclaredProperties.SingleOrDefault(p => p.Name == "HouseNumber");
            var streetProperty = addressType.DeclaredProperties.SingleOrDefault(p => p.Name == "Street");
            var cityProperty = addressType.DeclaredProperties.SingleOrDefault(p => p.Name == "City");
            var stateProperty = addressType.DeclaredProperties.SingleOrDefault(p => p.Name == "State");
            var zipCodeProperty = addressType.DeclaredProperties.SingleOrDefault(p => p.Name == "ZipCode");

            Assert.NotNull(houseNumberProperty);
            Assert.NotNull(streetProperty);
            Assert.NotNull(cityProperty);
            Assert.NotNull(stateProperty);
            Assert.Null(zipCodeProperty);
            Assert.Equal("Edm.Int32", houseNumberProperty.Type.FullName());
            Assert.Equal("Edm.String", streetProperty.Type.FullName());
        }
Ejemplo n.º 40
0
        public void CreateModelWithTwoEntitySetsAndABinding()
        {
            var builder = new ODataModelBuilder()
                          .Add_Customer_EntityType()
                          .Add_Order_EntityType()
                          .Add_CustomerOrders_Relationship()
                          .Add_CustomerOrders_Binding();

            var model     = builder.GetServiceModel();
            var container = model.SchemaElements.OfType <IEdmEntityContainer>().SingleOrDefault();

            Assert.NotNull(container);
            var customers = container.EntitySets().SingleOrDefault(e => e.Name == "Customers");

            Assert.NotNull(customers);
            var orders = container.EntitySets().SingleOrDefault(e => e.Name == "Orders");

            Assert.NotNull(orders);
            var customerOrders = customers.NavigationPropertyBindings.FirstOrDefault(nt => nt.NavigationProperty.Name == "Orders");

            Assert.NotNull(customerOrders);
            Assert.Equal("Orders", customerOrders.Target.Name);
        }
Ejemplo n.º 41
0
        public void CreateDatePrimitiveProperty_FromDateTime()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            EntityTypeConfiguration<File> file = builder.EntityType<File>();
            file.Property(f => f.Birthday).AsDate();
            file.Property(f => f.PublishDay).AsDate();

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

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

            IEdmProperty birthdayProperty = Assert.Single(fileType.DeclaredProperties.Where(p => p.Name == "Birthday"));
            Assert.NotNull(birthdayProperty);
            Assert.False(birthdayProperty.Type.IsNullable);
            Assert.Equal("Edm.Date", birthdayProperty.Type.FullName());

            IEdmProperty publishDayProperty = Assert.Single(fileType.DeclaredProperties.Where(p => p.Name == "PublishDay"));
            Assert.NotNull(publishDayProperty);
            Assert.True(publishDayProperty.Type.IsNullable);
            Assert.Equal("Edm.Date", publishDayProperty.Type.FullName());
        }
Ejemplo n.º 42
0
        public void CanEmitModelWithSingletonHasEntitysetBinding()
        {
            // Arrange
            var builder = new ODataModelBuilder()
                .Add_Company_EntityType()
                .Add_Employee_EntityType()
                .Add_CompanyEmployees_Relationship()
                .Add_EmployeeComplany_Relationship()
                .Add_MicrosoftEmployees_Binding();

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

            // Assert
            var csdl = GetCSDL(model);
        }
Ejemplo n.º 43
0
        public void CanEmitModelWithSingleton()
        {
            // Arrange
            var builder = new ODataModelBuilder()
                .Add_Company_Singleton();

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

            // Assert
            var csdl = GetCSDL(model);
        }
Ejemplo n.º 44
0
        public void ODataModelBuilder_Throws_AddCollectionOfEnumPropertyWithoutEnumType()
        {
            // Arrange
            var builder = new ODataModelBuilder();
            var complexTypeConfiguration = builder.ComplexType<ComplexTypeWithEnumTypePropertyTestModel>();
            complexTypeConfiguration.CollectionProperty(c => c.Colors);

            // Act & Assert
            Assert.Throws<InvalidOperationException>(
                () => builder.GetServiceModel(),
                "The enum type 'Color' does not exist.");
        }
Ejemplo n.º 45
0
 public void CanEmitModelWithSingleComplexType()
 {
     var builder = new ODataModelBuilder().Add_Address_ComplexType();
     var model   = builder.GetServiceModel();
     var csdl    = GetCSDL(model);
 }
Ejemplo n.º 46
0
 public void CanEmitModelWithSingleComplexType()
 {
     var builder = new ODataModelBuilder().Add_Address_ComplexType();
     var model = builder.GetServiceModel();
     var csdl = GetCSDL(model);
 }
Ejemplo n.º 47
0
 public void CanEmitModelWithSingleEntity()
 {
     var builder = new ODataModelBuilder().Add_Customer_EntityType();
     var model = builder.GetServiceModel();
     var csdl = GetCSDL(model);
 }
Ejemplo n.º 48
0
        public void CanCreateEntityWithEnumKey()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            var enumEntityType = builder.EntityType<EnumModel>();
            enumEntityType.HasKey(c => c.Simple);
            enumEntityType.Property(c => c.Id);

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

            // Assert
            IEdmEntityType entityType = model.SchemaElements.OfType<IEdmEntityType>()
                .FirstOrDefault(c => c.Name == "EnumModel");
            Assert.NotNull(entityType);
            Assert.Equal(2, entityType.Properties().Count());

            Assert.Equal(1, entityType.DeclaredKey.Count());
            IEdmStructuralProperty key = entityType.DeclaredKey.First();
            Assert.Equal(EdmTypeKind.Enum, key.Type.TypeKind());
            Assert.Equal("Microsoft.TestCommon.Types.SimpleEnum", key.Type.Definition.FullTypeName());
        }
Ejemplo n.º 49
0
        public void CanCreateEntityWithCollectionProperties()
        {
            var builder = new ODataModelBuilder();
            var customer = builder.Entity<Customer>();
            customer.HasKey(c => c.CustomerId);
            customer.CollectionProperty(c => c.Aliases);
            customer.CollectionProperty(c => c.Addresses);


            var aliasesProperty = customer.Properties.OfType<CollectionPropertyConfiguration>().SingleOrDefault(p => p.Name == "Aliases");
            var addressesProperty = customer.Properties.OfType<CollectionPropertyConfiguration>().SingleOrDefault(p => p.Name == "Addresses");

            Assert.Equal(3, customer.Properties.Count());
            Assert.Equal(2, customer.Properties.OfType<CollectionPropertyConfiguration>().Count());
            Assert.NotNull(aliasesProperty);
            Assert.Equal(typeof(string), aliasesProperty.ElementType);
            Assert.NotNull(addressesProperty);
            Assert.Equal(typeof(Address), addressesProperty.ElementType);

            Assert.Equal(2, builder.StructuralTypes.Count());
            var addressType = builder.StructuralTypes.Skip(1).FirstOrDefault();
            Assert.NotNull(addressType);
            Assert.Equal(EdmTypeKind.Complex, addressType.Kind);
            Assert.Equal(typeof(Address).FullName, addressType.FullName);

            var model = builder.GetServiceModel();
            var edmCustomerType = model.FindType(typeof(Customer).FullName) as IEdmEntityType;
            var edmAddressType = model.FindType(typeof(Address).FullName) as IEdmComplexType;
        }
        public void CreateModelusingProgrammableApi()
        {
            var builder        = new ODataModelBuilder();
            var customerConfig = builder.AddEntityType(typeof(Customer));

            customerConfig.HasKey(typeof(Customer).GetProperty("CustomerId"));
            customerConfig.AddProperty(typeof(Customer).GetProperty("Name"));
            var ordersPropertyConfig = customerConfig.AddNavigationProperty(typeof(Customer).GetProperty("Orders"), EdmMultiplicity.Many);

            var orderConfig = builder.AddEntityType(typeof(Order));

            orderConfig.HasKey(typeof(Order).GetProperty("OrderId"));
            orderConfig.AddProperty(typeof(Order).GetProperty("Cost"));

            var customersSetConfig = builder.AddEntitySet("Customers", customerConfig);
            var ordersSetConfig    = builder.AddEntitySet("Orders", orderConfig);

            customersSetConfig.AddBinding(ordersPropertyConfig, ordersSetConfig);

            var meConfig = builder.AddSingleton("Me", customerConfig);

            var model        = builder.GetServiceModel();
            var customerType = model.SchemaElements.OfType <IEdmEntityType>().Single(e => e.Name == "Customer");

            Assert.NotNull(customerType);
            Assert.Equal(typeof(Customer).Namespace, customerType.Namespace);
            Assert.Equal(3, customerType.DeclaredProperties.Count());

            var key = customerType.DeclaredKey.SingleOrDefault();

            Assert.NotNull(key);
            Assert.Equal("CustomerId", key.Name);
            Assert.True(key.Type.IsInt32());
            Assert.False(key.Type.IsNullable);

            var nameProperty = customerType.DeclaredProperties.SingleOrDefault(dp => dp.Name == "Name");

            Assert.NotNull(nameProperty);
            Assert.True(nameProperty.Type.IsString());
            Assert.True(nameProperty.Type.IsNullable);

            Assert.Single(customerType.NavigationProperties());
            var ordersProperty = customerType.NavigationProperties().Single();

            Assert.Equal("Orders", ordersProperty.Name);
            Assert.Equal(EdmTypeKind.Collection, ordersProperty.Type.Definition.TypeKind);
            Assert.Equal(typeof(Order).FullName, (ordersProperty.Type.Definition as IEdmCollectionType).ElementType.FullName());

            var entityContainer = model.EntityContainer;

            Assert.NotNull(entityContainer);

            var customers = entityContainer.FindEntitySet("Customers");

            Assert.NotNull(customers);
            Assert.Equal(typeof(Customer).FullName, customers.EntityType().FullName());

            var orders = entityContainer.FindEntitySet("Orders");

            Assert.NotNull(orders);

            Assert.Equal(typeof(Order).FullName, orders.EntityType().FullName());

            var me = entityContainer.FindSingleton("Me");

            Assert.NotNull(me);
            Assert.Equal(typeof(Customer).FullName, me.EntityType().FullName());
        }
Ejemplo n.º 51
0
        public void CreateTimeOfDayPrimitiveProperty_FromTimeSpan()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            EntityTypeConfiguration<File> file = builder.EntityType<File>();
            file.Property(f => f.CreatedTime).AsTimeOfDay();
            file.Property(f => f.EndTime).AsTimeOfDay();

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

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

            IEdmProperty createProperty = Assert.Single(fileType.DeclaredProperties.Where(p => p.Name == "CreatedTime"));
            Assert.NotNull(createProperty);
            Assert.False(createProperty.Type.IsNullable);
            Assert.Equal("Edm.TimeOfDay", createProperty.Type.FullName());

            IEdmProperty endProperty = Assert.Single(fileType.DeclaredProperties.Where(p => p.Name == "EndTime"));
            Assert.NotNull(endProperty);
            Assert.True(endProperty.Type.IsNullable);
            Assert.Equal("Edm.TimeOfDay", endProperty.Type.FullName());
        }
Ejemplo n.º 52
0
        public void ValueOfEnumMemberCannotBeConvertedToLongShouldThrowException()
        {
            // Arrange
            var builder = new ODataModelBuilder();
            var color = builder.EnumType<ValueOutOfRangeEnum>();
            color.Member(ValueOutOfRangeEnum.Member);

            // Act & Assert
            Assert.ThrowsArgument(
                () => builder.GetServiceModel(),
                "value",
                "The value of enum member 'Member' cannot be converted to a long type.");
        }
Ejemplo n.º 53
0
 public void CanEmitModelWithSingleEntity()
 {
     var builder = new ODataModelBuilder().Add_Customer_EntityType();
     var model   = builder.GetServiceModel();
     var csdl    = GetCSDL(model);
 }