public void GetTargetNavigationSource_Returns_Null_IfNoMatchingTargetNavigaitonSource() { // Arrange ODataModelBuilder builder = new ODataModelBuilder(); EntityTypeConfiguration motorcycle = builder.AddEntityType(typeof(Motorcycle)); NavigationPropertyConfiguration navigationProperty = motorcycle.AddNavigationProperty(typeof(Motorcycle).GetProperty("Manufacturer"), EdmMultiplicity.ZeroOrOne); // Act NavigationSourceConfiguration targetNavigationSource = AssociationSetDiscoveryConvention.GetTargetNavigationSource(navigationProperty, builder); // Assert Assert.Null(targetNavigationSource); }
public void GetTargetNavigationSource_Returns_TargetEntitySet() { // Arrange ODataModelBuilder builder = new ODataModelBuilder(); EntityTypeConfiguration motorcycle = builder.AddEntityType(typeof(Motorcycle)); EntityTypeConfiguration manufacturer = builder.AddEntityType(typeof(MotorcycleManufacturer)); NavigationPropertyConfiguration navigationProperty = motorcycle.AddNavigationProperty(typeof(Motorcycle).GetProperty("Manufacturer"), EdmMultiplicity.ZeroOrOne); EntitySetConfiguration manufacturers = builder.AddEntitySet("manufacturers", manufacturer); // Act NavigationSourceConfiguration targetNavigationSource = AssociationSetDiscoveryConvention.GetTargetNavigationSource(navigationProperty, builder); // Assert Assert.Same(manufacturers, targetNavigationSource); }
public void GetTargetNavigationSource_Returns_TargetSingleton() { // Arrange ODataModelBuilder builder = new ODataModelBuilder(); EntityTypeConfiguration companyType = builder.AddEntityType(typeof(Company)); EntityTypeConfiguration employeeType = builder.AddEntityType(typeof(Employee)); NavigationPropertyConfiguration navigationProperty = companyType.AddNavigationProperty(typeof(Company).GetProperty("CEO"), EdmMultiplicity.One); SingletonConfiguration gazes = builder.AddSingleton("Gazes", employeeType); // Act NavigationSourceConfiguration targetNavigationSource = AssociationSetDiscoveryConvention.GetTargetNavigationSource(navigationProperty, builder); // Assert Assert.Same(gazes, targetNavigationSource); }
public void GetTargetNavigationSource_Throws_IfTargetEntityTypeIsMissing() { // Arrange Mock <PropertyInfo> property = new Mock <PropertyInfo>(); property.Setup(p => p.PropertyType).Returns(typeof(Vehicle)); property.Setup(p => p.ReflectedType).Returns(typeof(AssociationSetDiscoveryConventionTest)); property.Setup(p => p.Name).Returns("SamplePropertyName"); Mock <EntityTypeConfiguration> entityTypeConfiguration = new Mock <EntityTypeConfiguration>(); NavigationPropertyConfiguration config = new NavigationPropertyConfiguration(property.Object, EdmMultiplicity.ZeroOrOne, entityTypeConfiguration.Object); Mock <ODataModelBuilder> modelBuilder = new Mock <ODataModelBuilder>(); // Act & Assert Assert.Throws <InvalidOperationException>( () => AssociationSetDiscoveryConvention.GetTargetNavigationSource(config, modelBuilder.Object), "Could not find the target entity type for the navigation property 'SamplePropertyName' on entity type 'System.Web.OData.Builder.Conventions.AssociationSetDiscoveryConventionTest'."); }