Esempio n. 1
0
        public void BuilderIncludesMapFromEntityTypeToBindableProcedures()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            EntityTypeConfiguration <Customer> customer = builder.EntitySet <Customer>("Customers").EntityType;

            customer.HasKey(c => c.Id);
            customer.Property(c => c.Name);
            customer.Action("Reward");
            IEdmModel      model        = builder.GetEdmModel();
            IEdmEntityType customerType = model.SchemaElements.OfType <IEdmEntityType>().SingleOrDefault();

            // Act
            BindableProcedureFinder finder = model.GetAnnotationValue <BindableProcedureFinder>(model);

            // Assert
            Assert.NotNull(finder);
            Assert.NotNull(finder.FindProcedures(customerType).SingleOrDefault());
            Assert.Equal("Reward", finder.FindProcedures(customerType).SingleOrDefault().Name);
        }
Esempio n. 2
0
        public void CanCreateEdmModel_WithTransientBindableAction()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            EntityTypeConfiguration <Customer> customer = builder.Entity <Customer>();

            customer.HasKey(c => c.CustomerId);
            customer.Property(c => c.Name);
            // Act
            ActionConfiguration sendEmail = customer.TransientAction("ActionName");
            IEdmModel           model     = builder.GetEdmModel();

            // Assert
            IEdmEntityContainer container = model.EntityContainers().SingleOrDefault();

            Assert.NotNull(container);
            Assert.Equal(1, container.Elements.OfType <IEdmFunctionImport>().Count());
            IEdmFunctionImport action = container.Elements.OfType <IEdmFunctionImport>().Single();

            Assert.True(action.IsBindable);
            Assert.False(model.IsAlwaysBindable(action));
        }
Esempio n. 3
0
        public void GetEdmModel_Works_WithMultiForeignKeys()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            EntityTypeConfiguration <MultiUser> userType = builder.Entity <MultiUser>();

            userType.HasKey(u => new { u.UserId1, u.UserId2 })
            .HasMany(u => u.Roles);

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

            roleType.HasKey(r => r.RoleId)
            .HasOptional(r => r.User, (r, u) => r.UserKey1 == u.UserId1 && r.UserKey2 == u.UserId2)
            .CascadeOnDelete();

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

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

            IEdmNavigationProperty usersNav = roleEntityType.AssertHasNavigationProperty(model, "User",
                                                                                         typeof(MultiUser), true, EdmMultiplicity.ZeroOrOne);

            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);

            IEdmProperty edmProperty = Assert.Single(roleEntityType.Properties().Where(c => c.Name == "UserKey1"));

            Assert.False(edmProperty.Type.IsNullable);

            edmProperty = Assert.Single(roleEntityType.Properties().Where(c => c.Name == "UserKey2"));
            Assert.False(edmProperty.Type.IsNullable);
        }