public void CannotBindNavigationPropertyAutmatically_WhenMultipleEntitySetsOfPropertyType_Exist() { // Arrange ODataModelBuilder builder = ODataModelBuilderMocks.GetModelBuilderMock <ODataModelBuilder>(); builder.EntitySet <Motorcycle>("motorcycles1").HasRequiredBinding(m => m.Manufacturer, "NorthWestMotorcycleManufacturers"); builder.EntitySet <Motorcycle>("motorcycles2"); builder.EntitySet <MotorcycleManufacturer>("NorthWestMotorcycleManufacturers"); builder.EntitySet <MotorcycleManufacturer>("SouthWestMotorcycleManufacturers"); // Act IEdmModel model = builder.GetEdmModel(); // Assert IEdmEntitySet motorcycles1 = model.EntityContainer.FindEntitySet("motorcycles1"); Assert.NotNull(motorcycles1); var motorcycle = model.AssertHasEntityType(typeof(Motorcycle)); var manufacturerNav = motorcycle.AssertHasNavigationProperty(model, "Manufacturer", typeof(MotorcycleManufacturer), isNullable: false, multiplicity: EdmMultiplicity.One); var bindings = motorcycles1.FindNavigationPropertyBindings(manufacturerNav); IEdmNavigationPropertyBinding binding = Assert.Single(bindings); Assert.Equal("Manufacturer", binding.NavigationProperty.Name); Assert.Equal("NorthWestMotorcycleManufacturers", binding.Target.Name); Assert.Equal("Manufacturer", binding.Path.Path); IEdmEntitySet motorcycles2 = model.EntityContainer.FindEntitySet("motorcycles2"); Assert.Null(motorcycles2.FindNavigationPropertyBindings(manufacturerNav)); }
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("Microsoft.AspNet.OData.Test.Builder.TestModels.Motorcycle/Manufacturer", binding.Path.Path); }