Esempio n. 1
0
        public void CreateEdmModel_WithSingleton_CanAddBindingToDerivedNavigationProperty()
        {
            // Arrange
            ODataModelBuilder builder = ODataModelBuilderMocks.GetModelBuilderMock <ODataModelBuilder>();

            var vehicle      = builder.AddEntityType(typeof(Vehicle));
            var motorcycle   = builder.AddEntityType(typeof(Motorcycle)).DerivesFrom(vehicle);
            var manufacturer = builder.AddEntityType(typeof(MotorcycleManufacturer));
            var yamaha       = builder.AddSingleton("Yamaha", manufacturer);
            var navProperty  = motorcycle.AddNavigationProperty(typeof(Motorcycle).GetProperty("Manufacturer"), EdmMultiplicity.One);

            var r7 = builder.AddSingleton("Yamaha-R7", motorcycle);

            r7.AddBinding(navProperty, yamaha);

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

            // Assert
            var motorcycleEdmType = model.AssertHasEntityType(typeof(Motorcycle));
            var edmNavProperty    = motorcycleEdmType.AssertHasNavigationProperty(model, "Manufacturer", typeof(MotorcycleManufacturer), isNullable: false, multiplicity: EdmMultiplicity.One);

            Assert.Equal(
                "Yamaha",
                model.EntityContainer.FindSingleton("Yamaha-R7").FindNavigationTarget(edmNavProperty).Name);
        }
Esempio n. 2
0
        public void CreateEdmModel_WithSingleton_CanAddNavigationLinkToDerivedNavigationProperty()
        {
            // Arrange
            ODataModelBuilder builder = ODataModelBuilderMocks.GetModelBuilderMock <ODataModelBuilder>();

            var vehicle      = builder.AddEntityType(typeof(Vehicle));
            var car          = builder.AddEntityType(typeof(Car)).DerivesFrom(vehicle);
            var manufacturer = builder.AddEntityType(typeof(CarManufacturer));
            var fordo        = builder.AddSingleton("Fordo", manufacturer);
            var navProperty  = car.AddNavigationProperty(typeof(Car).GetProperty("Manufacturer"), EdmMultiplicity.One);

            var contoso = builder.AddSingleton("Contoso", vehicle);
            var binding = contoso.AddBinding(navProperty, fordo);

            contoso.HasNavigationPropertyLink(navProperty, new NavigationLinkBuilder((ctxt, property) => new Uri("http://works/"), followsConventions: false));

            // Act & assert
            IEdmModel model             = builder.GetEdmModel();
            var       motorcycleEdmType = model.AssertHasEntityType(typeof(Car));
            var       edmNavProperty    = motorcycleEdmType.AssertHasNavigationProperty(model, "Manufacturer", typeof(CarManufacturer), isNullable: false, multiplicity: EdmMultiplicity.One);
            var       edmContoso        = model.EntityContainer.FindSingleton("Contoso");

            Assert.NotNull(model.GetNavigationSourceLinkBuilder(edmContoso));
            Assert.Equal(
                "http://works/",
                model.GetNavigationSourceLinkBuilder(edmContoso).BuildNavigationLink(new ResourceContext(), edmNavProperty, ODataMetadataLevel.MinimalMetadata).AbsoluteUri);
        }
Esempio n. 3
0
        public void CanAddNavigationLink_For_DerivedNavigationProperty()
        {
            ODataModelBuilder builder = ODataModelBuilderMocks.GetModelBuilderMock <ODataModelBuilder>();

            var vehicle       = builder.AddEntityType(typeof(Vehicle));
            var motorcycle    = builder.AddEntityType(typeof(Motorcycle)).DerivesFrom(vehicle);
            var manufacturer  = builder.AddEntityType(typeof(MotorcycleManufacturer));
            var manufacturers = builder.AddEntitySet("manufacturers", manufacturer);
            var navProperty   = motorcycle.AddNavigationProperty(typeof(Motorcycle).GetProperty("Manufacturer"), EdmMultiplicity.One);

            var vehicles = builder.AddEntitySet("vehicles", vehicle);
            var binding  = vehicles.AddBinding(navProperty, manufacturers);

            vehicles.HasNavigationPropertyLink(navProperty, new NavigationLinkBuilder((ctxt, property) => new Uri("http://works/"), followsConventions: false));

            IEdmModel model             = builder.GetEdmModel();
            var       motorcycleEdmType = model.AssertHasEntityType(typeof(Motorcycle));
            var       edmNavProperty    = motorcycleEdmType.AssertHasNavigationProperty(model, "Manufacturer", typeof(MotorcycleManufacturer), isNullable: false, multiplicity: EdmMultiplicity.One);
            var       vehiclesEdmSet    = model.EntityContainer.FindEntitySet("vehicles");

            Assert.NotNull(model.GetNavigationSourceLinkBuilder(vehiclesEdmSet));
            Assert.Equal(
                "http://works/",
                model.GetNavigationSourceLinkBuilder(vehiclesEdmSet).BuildNavigationLink(new ResourceContext(), edmNavProperty, ODataMetadataLevel.MinimalMetadata).AbsoluteUri);
        }
Esempio n. 4
0
        public void SettingBaseTypeToNull_AlsoUpdatesBaseTypeConfigured()
        {
            var builder    = new ODataModelBuilder();
            var motorcycle = builder.AddEntityType(typeof(Motorcycle));
            var vehicle    = builder.AddEntityType(typeof(Vehicle));

            motorcycle.DerivesFromNothing();

            Assert.True(motorcycle.BaseTypeConfigured);
        }
Esempio n. 5
0
        public void SingletonAddBinding_DoesnotThrows_IfBindingNavigationPropertyIsNotPartOfEntityType()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();

            var vehicleType      = builder.AddEntityType(typeof(Vehicle));
            var carType          = builder.AddEntityType(typeof(Car));
            var manufacturerType = builder.AddEntityType(typeof(CarManufacturer));
            var fordo            = builder.AddSingleton("Fordo", manufacturerType);
            var navProperty      = carType.AddNavigationProperty(typeof(Car).GetProperty("Manufacturer"), EdmMultiplicity.One);
            var myVehicle        = builder.AddSingleton("MyVehicle", vehicleType);

            // Act & Assert
            Assert.DoesNotThrow(() => myVehicle.AddBinding(navProperty, fordo));
        }
Esempio n. 6
0
        public void BaseTypeConfigured_IsFalseByDefault()
        {
            var builder    = new ODataModelBuilder();
            var motorcycle = builder.AddEntityType(typeof(Motorcycle));

            Assert.False(motorcycle.BaseTypeConfigured);
        }
        public void FunctionLink_PreservesFollowsConventions(bool value)
        {
            // Arrange
            ODataModelBuilder     builder       = ODataModelBuilderMocks.GetModelBuilderMock <ODataModelBuilder>();
            FunctionConfiguration configuration = new FunctionConfiguration(builder, "IgnoreFunction");

            configuration.Returns <int>();
            Mock <IEdmTypeConfiguration> bindingParameterTypeMock = new Mock <IEdmTypeConfiguration>();

            bindingParameterTypeMock.Setup(o => o.Kind).Returns(EdmTypeKind.Entity);
            Type entityType = typeof(object);

            bindingParameterTypeMock.Setup(o => o.ClrType).Returns(entityType);
            configuration.SetBindingParameter("IgnoreParameter", bindingParameterTypeMock.Object);
            configuration.HasFunctionLink((a) => { throw new NotImplementedException(); }, followsConventions: value);
            builder.AddOperation(configuration);
            builder.AddEntityType(entityType);

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

            // Assert
            var function = Assert.Single(model.SchemaElements.OfType <IEdmFunction>());
            OperationLinkBuilder functionLinkBuilder = model.GetOperationLinkBuilder(function);

            Assert.NotNull(functionLinkBuilder);
            Assert.Equal(value, functionLinkBuilder.FollowsConventions);
        }
Esempio n. 8
0
        public void CreateEdmModel_WithSingleton_CanAddBindingPath_ToNavigationProperty_WithComplex()
        {
            // Arrange
            ODataModelBuilder builder = ODataModelBuilderMocks.GetModelBuilderMock <ODataModelBuilder>();

            var motorcycle = builder.AddEntityType(typeof(Motorcycle));
            var myMotor    = builder.AddSingleton("MyMotor", motorcycle);

            var manufacturer = builder.AddComplexType(typeof(MotorcycleManufacturer));
            var address      = builder.AddEntityType(typeof(ManufacturerAddress));

            motorcycle.AddComplexProperty(typeof(Motorcycle).GetProperty("Manufacturer"));
            var navProperty = manufacturer.AddNavigationProperty(typeof(Manufacturer).GetProperty("Address"), EdmMultiplicity.One);

            var addresses = builder.AddEntitySet("Addresses", address);

            myMotor.AddBinding(navProperty, addresses, new List <MemberInfo>
            {
                typeof(Motorcycle).GetProperty("Manufacturer"),
                typeof(Manufacturer).GetProperty("Address")
            });

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

            // Assert
            var motorcycleEdmType = model.AssertHasEntityType(typeof(Motorcycle));

            Assert.Empty(motorcycleEdmType.NavigationProperties());

            var manufacturerEdmType = model.AssertHasComplexType(typeof(MotorcycleManufacturer));

            var edmNavProperty = manufacturerEdmType.AssertHasNavigationProperty(model, "Address",
                                                                                 typeof(ManufacturerAddress), isNullable: false, multiplicity: EdmMultiplicity.One);

            var myMotorSingleton = model.EntityContainer.FindSingleton("MyMotor");

            Assert.NotNull(myMotorSingleton);

            var bindings = myMotorSingleton.FindNavigationPropertyBindings(edmNavProperty);
            var binding  = Assert.Single(bindings);

            Assert.Equal("Address", binding.NavigationProperty.Name);
            Assert.Equal("Addresses", binding.Target.Name);
            Assert.Equal("Manufacturer/Address", binding.Path.Path);
        }
Esempio n. 9
0
        public void AddBinding_For_NavigationPropertyInHierarchy_DoesnotThrows()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();

            var vehicle       = builder.AddEntityType(typeof(Vehicle));
            var motorcycle    = builder.AddEntityType(typeof(Motorcycle));
            var manufacturer  = builder.AddEntityType(typeof(MotorcycleManufacturer));
            var manufacturers = builder.AddEntitySet("manufacturers", manufacturer);

            var navProperty = motorcycle.AddNavigationProperty(typeof(Motorcycle).GetProperty("Manufacturer"), EdmMultiplicity.One);

            var vehicles = builder.AddEntitySet("vehicles", vehicle);

            // Act & Assert
            Assert.DoesNotThrow(() => vehicles.AddBinding(navProperty, manufacturers));
        }
Esempio n. 10
0
        public void SingletonAddBinding_Throws_IfBindingNavigationPropertyIsNotPartOfEntityType()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();

            var vehicleType      = builder.AddEntityType(typeof(Vehicle));
            var carType          = builder.AddEntityType(typeof(Car));
            var manufacturerType = builder.AddEntityType(typeof(CarManufacturer));
            var fordo            = builder.AddSingleton("Fordo", manufacturerType);
            var navProperty      = carType.AddNavigationProperty(typeof(Car).GetProperty("Manufacturer"), EdmMultiplicity.One);
            var myVehicle        = builder.AddSingleton("MyVehicle", vehicleType);

            // Act & Assert
            Assert.ThrowsArgument(
                () => myVehicle.AddBinding(navProperty, fordo),
                "navigationConfiguration",
                "The declaring entity type 'System.Web.OData.Builder.TestModels.Car' of the given navigation property is not a part of " +
                "the entity type 'System.Web.OData.Builder.TestModels.Vehicle' hierarchy of the entity set or singleton 'MyVehicle'.");
        }
        public void HasConstraint_Throws_ReferentialConstraintPropertyTypeNotValid()
        {
            // Arrange
            PropertyInfo principalPropertyInfo = typeof(Principal).GetProperty("MockPrincipal");
            PropertyInfo dependentPropertyInfo = typeof(Dependent).GetProperty("MockDependent");

            ODataModelBuilder builder = new ODataModelBuilder();

            builder.AddEntityType(typeof(Principal));
            EntityTypeConfiguration         dependentEntity    = builder.AddEntityType(typeof(Dependent));
            NavigationPropertyConfiguration navigationProperty =
                new NavigationPropertyConfiguration(typeof(Dependent).GetProperty("Principal"), EdmMultiplicity.One,
                                                    dependentEntity);

            // Act & Assert
            Assert.Throws <InvalidOperationException>(
                () => navigationProperty.HasConstraint(dependentPropertyInfo, principalPropertyInfo),
                String.Format(SRResources.ReferentialConstraintPropertyTypeNotValid, "System.Web.OData.MockType"));
        }
        public void HasConstraint_Throws_DependentAndPrincipalTypeNotMatch()
        {
            // Arrange
            PropertyInfo principalPropertyInfo = typeof(Principal).GetProperty("PrincipalKey2");
            PropertyInfo dependentPropertyInfo = typeof(Dependent).GetProperty("DependentKey1");

            ODataModelBuilder builder = new ODataModelBuilder();

            builder.AddEntityType(typeof(Principal));
            EntityTypeConfiguration         dependentEntity    = builder.AddEntityType(typeof(Dependent));
            NavigationPropertyConfiguration navigationProperty =
                new NavigationPropertyConfiguration(typeof(Dependent).GetProperty("Principal"), EdmMultiplicity.One,
                                                    dependentEntity);

            // Act & Assert
            Assert.Throws <InvalidOperationException>(
                () => navigationProperty.HasConstraint(dependentPropertyInfo, principalPropertyInfo),
                String.Format(SRResources.DependentAndPrincipalTypeNotMatch, "System.Int32", "System.String"));
        }
        public void HasConstraint_CanSetDependentAndPrincipalProperty()
        {
            // Arrange
            PropertyInfo      principalPropertyInfo = typeof(Principal).GetProperty("PrincipalKey1");
            PropertyInfo      dependentPropertyInfo = typeof(Dependent).GetProperty("DependentKey1");
            ODataModelBuilder builder = new ODataModelBuilder();

            builder.AddEntityType(typeof(Principal));
            EntityTypeConfiguration         dependentEntity    = builder.AddEntityType(typeof(Dependent));
            NavigationPropertyConfiguration navigationProperty =
                new NavigationPropertyConfiguration(typeof(Dependent).GetProperty("Principal"), EdmMultiplicity.One,
                                                    dependentEntity);

            // Act
            navigationProperty.HasConstraint(dependentPropertyInfo, principalPropertyInfo);

            // Assert
            Assert.Same(principalPropertyInfo, Assert.Single(navigationProperty.PrincipalProperties));
            Assert.Same(dependentPropertyInfo, Assert.Single(navigationProperty.DependentProperties));
        }
Esempio n. 14
0
        public void AddNavigationLink_For_NavigationPropertyInHierarchy_Throws()
        {
            ODataModelBuilder builder = new ODataModelBuilder();

            var vehicle       = builder.AddEntityType(typeof(Vehicle));
            var motorcycle    = builder.AddEntityType(typeof(Motorcycle));
            var manufacturer  = builder.AddEntityType(typeof(MotorcycleManufacturer));
            var manufacturers = builder.AddEntitySet("manufacturers", manufacturer);

            var navProperty = motorcycle.AddNavigationProperty(typeof(Motorcycle).GetProperty("Manufacturer"), EdmMultiplicity.One);

            var vehicles = builder.AddEntitySet("vehicles", vehicle);

            Assert.ThrowsArgument(
                () => vehicles.HasNavigationPropertyLink(navProperty, new NavigationLinkBuilder((ctxt, property) => new Uri("http://works/"), followsConventions: false)),
                "navigationProperty",
                "The declaring entity type 'System.Web.OData.Builder.TestModels.Motorcycle' " +
                "of the given navigation property is not a part of the entity type " +
                "'System.Web.OData.Builder.TestModels.Vehicle' hierarchy of the entity set or singleton 'vehicles'.");
        }
Esempio n. 15
0
        public void RemoveKey_ThrowsArgumentNull()
        {
            // Arrange
            var builder    = new ODataModelBuilder();
            var motorcycle = builder.AddEntityType(typeof(Motorcycle));

            // Act & Assert
            Assert.ThrowsArgumentNull(
                () => motorcycle.RemoveKey(keyProperty: null),
                "keyProperty");
        }
Esempio n. 16
0
        public void RemoveStructuralType_RemovesEntityType()
        {
            ODataModelBuilder builder = new ODataModelBuilder();

            builder.AddEntityType(typeof(Customer));

            Assert.NotEmpty(builder.StructuralTypes);

            builder.RemoveStructuralType(typeof(Customer));
            Assert.Empty(builder.StructuralTypes);
        }
Esempio n. 17
0
        public void AddBinding_For_NavigationPropertyInHierarchy_Throws()
        {
            ODataModelBuilder builder = new ODataModelBuilder();

            var vehicle       = builder.AddEntityType(typeof(Vehicle));
            var motorcycle    = builder.AddEntityType(typeof(Motorcycle));
            var manufacturer  = builder.AddEntityType(typeof(MotorcycleManufacturer));
            var manufacturers = builder.AddEntitySet("manufacturers", manufacturer);

            var navProperty = motorcycle.AddNavigationProperty(typeof(Motorcycle).GetProperty("Manufacturer"), EdmMultiplicity.One);

            var vehicles = builder.AddEntitySet("vehicles", vehicle);

            Assert.ThrowsArgument(
                () => vehicles.AddBinding(navProperty, manufacturers),
                "navigationConfiguration",
                "The declaring entity type 'System.Web.OData.Builder.TestModels.Motorcycle' of " +
                "the given navigation property is not a part of the entity type " +
                "'System.Web.OData.Builder.TestModels.Vehicle' hierarchy of the entity set or singleton 'vehicles'.");
        }
Esempio n. 18
0
        public void SingletonAddNavigationLink_Throws_IfNavigationPropertyInHierarchyIsNotPartOfEntityType()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();

            var vehicleType      = builder.AddEntityType(typeof(Vehicle));
            var carType          = builder.AddEntityType(typeof(Car));
            var manufacturerType = builder.AddEntityType(typeof(CarManufacturer));
            var fordo            = builder.AddSingleton("Fordo", manufacturerType);

            var navProperty = carType.AddNavigationProperty(typeof(Car).GetProperty("Manufacturer"), EdmMultiplicity.One);
            var myVehicle   = builder.AddSingleton("MyVehicle", vehicleType);

            // Act & Assert
            Assert.ThrowsArgument(
                () => myVehicle.HasNavigationPropertyLink(navProperty, new NavigationLinkBuilder((ctxt, property) => new Uri("http://works/"), followsConventions: false)),
                "navigationProperty",
                "The declaring entity type 'System.Web.OData.Builder.TestModels.Car' of the given navigation property is not a part of the " +
                "entity type 'System.Web.OData.Builder.TestModels.Vehicle' hierarchy of the entity set or singleton 'MyVehicle'.");
        }
Esempio n. 19
0
        public void CanAddBinding_For_DerivedNavigationProperty()
        {
            ODataModelBuilder builder = ODataModelBuilderMocks.GetModelBuilderMock <ODataModelBuilder>();

            var vehicle       = builder.AddEntityType(typeof(Vehicle));
            var motorcycle    = builder.AddEntityType(typeof(Motorcycle)).DerivesFrom(vehicle);
            var manufacturer  = builder.AddEntityType(typeof(MotorcycleManufacturer));
            var manufacturers = builder.AddEntitySet("manufacturers", manufacturer);
            var navProperty   = motorcycle.AddNavigationProperty(typeof(Motorcycle).GetProperty("Manufacturer"), EdmMultiplicity.One);

            var vehicles = builder.AddEntitySet("vehicles", vehicle);

            vehicles.AddBinding(navProperty, manufacturers);

            IEdmModel model             = builder.GetEdmModel();
            var       motorcycleEdmType = model.AssertHasEntityType(typeof(Motorcycle));
            var       edmNavProperty    = motorcycleEdmType.AssertHasNavigationProperty(model, "Manufacturer", typeof(MotorcycleManufacturer), isNullable: false, multiplicity: EdmMultiplicity.One);

            Assert.Equal(
                "manufacturers",
                model.EntityContainer.FindEntitySet("vehicles").FindNavigationTarget(edmNavProperty).Name);
        }
        public void HasConstraint_Throws_ReferentialConstraintAlreadyConfigured_Principal()
        {
            // Arrange
            PropertyInfo principalPropertyInfo      = typeof(Principal).GetProperty("PrincipalKey1");
            PropertyInfo dependentPropertyInfo      = typeof(Dependent).GetProperty("DependentKey1");
            PropertyInfo otherPrincipalPropertyInfo = typeof(Dependent).GetProperty("DependentKey2");

            ODataModelBuilder builder = new ODataModelBuilder();

            builder.AddEntityType(typeof(Principal));
            EntityTypeConfiguration         dependentEntity    = builder.AddEntityType(typeof(Dependent));
            NavigationPropertyConfiguration navigationProperty =
                new NavigationPropertyConfiguration(typeof(Dependent).GetProperty("Principal"), EdmMultiplicity.One,
                                                    dependentEntity);

            navigationProperty.HasConstraint(dependentPropertyInfo, principalPropertyInfo);

            // Act & Assert
            Assert.Throws <InvalidOperationException>(
                () => navigationProperty.HasConstraint(otherPrincipalPropertyInfo, principalPropertyInfo),
                String.Format(SRResources.ReferentialConstraintAlreadyConfigured,
                              "principal", "PrincipalKey1", "dependent", "DependentKey1"));
        }
Esempio n. 21
0
        public void CanAddBinding_For_DerivedNavigationProperty()
        {
            // Arrange
            ODataModelBuilder builder = ODataModelBuilderMocks.GetModelBuilderMock <ODataModelBuilder>();

            var vehicle       = builder.AddEntityType(typeof(Vehicle));
            var motorcycle    = builder.AddEntityType(typeof(Motorcycle)).DerivesFrom(vehicle);
            var manufacturer  = builder.AddEntityType(typeof(MotorcycleManufacturer));
            var manufacturers = builder.AddEntitySet("manufacturers", manufacturer);
            var navProperty   = motorcycle.AddNavigationProperty(typeof(Motorcycle).GetProperty("Manufacturer"), EdmMultiplicity.One);

            var vehicles = builder.AddEntitySet("vehicles", vehicle);

            vehicles.AddBinding(navProperty, manufacturers);

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

            // Assert
            var motorcycleEdmType = model.AssertHasEntityType(typeof(Motorcycle));
            var edmNavProperty    = motorcycleEdmType.AssertHasNavigationProperty(model, "Manufacturer",
                                                                                  typeof(MotorcycleManufacturer), isNullable: false, multiplicity: EdmMultiplicity.One);

            IEdmEntitySet entitySet = model.EntityContainer.FindEntitySet("vehicles");

            Assert.NotNull(entitySet);

            var target = entitySet.FindNavigationTarget(edmNavProperty);

            Assert.NotNull(target);
            Assert.Equal("manufacturers", target.Name);

            var binding = Assert.Single(entitySet.FindNavigationPropertyBindings(edmNavProperty));

            Assert.Same(target, binding.Target);
            Assert.Equal("System.Web.OData.Builder.TestModels.Motorcycle/Manufacturer", binding.Path.Path);
        }
Esempio n. 22
0
        public void RemoveKey_Removes_KeyProperty()
        {
            // Arrange
            var builder    = new ODataModelBuilder();
            var motorcycle = builder.AddEntityType(typeof(Motorcycle));
            PrimitivePropertyConfiguration modelProperty = motorcycle.AddProperty(typeof(Motorcycle).GetProperty("Model"));

            motorcycle.HasKey(typeof(Motorcycle).GetProperty("Model"));
            Assert.Equal(new[] { modelProperty }, motorcycle.Keys);

            // Act
            motorcycle.RemoveKey(modelProperty);

            // Assert
            Assert.Empty(motorcycle.Keys);
        }
Esempio n. 23
0
        public void RemoveEnumKey_Removes_EnumKeyProperty()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            var enumEntityType        = builder.AddEntityType(typeof(EnumModel));

            enumEntityType.HasKey(typeof(EnumModel).GetProperty("Simple"));

            EnumPropertyConfiguration enumProperty =
                enumEntityType.AddEnumProperty(typeof(EnumModel).GetProperty("Simple"));

            Assert.Equal(new[] { enumProperty }, enumEntityType.EnumKeys); // Guard

            // Act
            enumEntityType.RemoveKey(enumProperty);

            // Assert
            Assert.Empty(enumEntityType.EnumKeys);
        }
        public void HasNavigationPropertyLink_CanReplaceExistingLinks()
        {
            // Arrange
            var entity             = _builder.AddEntityType(typeof(Motorcycle));
            var navigationProperty = entity.AddNavigationProperty(typeof(Motorcycle).GetProperty("Manufacturer"), EdmMultiplicity.One);
            var entityset          = _builder.AddEntitySet("vehicles", entity);
            Uri link1 = new Uri("http://link1");
            Uri link2 = new Uri("http://link2");

            entityset.HasNavigationPropertyLink(navigationProperty, new NavigationLinkBuilder((entityContext, property) => link1, followsConventions: true));

            // Act
            entityset.HasNavigationPropertyLink(navigationProperty, new NavigationLinkBuilder((entityContext, property) => link2, followsConventions: false));

            // Assert
            var navigationLink = entityset.GetNavigationPropertyLink(navigationProperty);

            Assert.False(navigationLink.FollowsConventions);
            Assert.Equal(link2, navigationLink.Factory(null, null));
        }
        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());
        }
 public NavigationSourceLinkBuilderAnnotationTest()
 {
     _modelBuilder = ODataModelBuilderMocks.GetModelBuilderMock <ODataModelBuilder>();
     _entitySet    = _modelBuilder.AddEntitySet("Customers", _modelBuilder.AddEntityType(typeof(Customer)));
 }