Ejemplo n.º 1
0
        public void Apply_should_discover_self_referencing_association_pair()
        {
            EdmModel model
                = new TestModelBuilder()
                  .Entities("S")
                  .Association("S", RelationshipMultiplicity.ZeroOrOne, "S", RelationshipMultiplicity.Many)
                  .Association("S", RelationshipMultiplicity.Many, "S", RelationshipMultiplicity.ZeroOrOne);

            ((IEdmConvention) new AssociationInverseDiscoveryConvention()).Apply(model);

            Assert.Equal(1, model.GetAssociationTypes().Count());
            Assert.Equal(1, model.Containers.Single().AssociationSets.Count());

            var associationType = model.GetAssociationTypes().Single();

            Assert.Equal(RelationshipMultiplicity.ZeroOrOne, associationType.SourceEnd.RelationshipMultiplicity);
            Assert.Equal(RelationshipMultiplicity.Many, associationType.TargetEnd.RelationshipMultiplicity);
        }
        public void Apply_should_discover_collection_to_collection_association_pair()
        {
            EdmModel model
                = new TestModelBuilder()
                    .Entities("S", "T")
                    .Association("S", EdmAssociationEndKind.Optional, "T", EdmAssociationEndKind.Many)
                    .Association("T", EdmAssociationEndKind.Optional, "S", EdmAssociationEndKind.Many);

            ((IEdmConvention)new AssociationInverseDiscoveryConvention()).Apply(model);

            Assert.Equal(1, model.GetAssociationTypes().Count());
            Assert.Equal(1, model.Containers.Single().AssociationSets.Count());

            var associationType = model.GetAssociationTypes().Single();

            Assert.Equal(EdmAssociationEndKind.Many, associationType.SourceEnd.EndKind);
            Assert.Equal(EdmAssociationEndKind.Many, associationType.TargetEnd.EndKind);
        }
Ejemplo n.º 3
0
        public void Apply_should_not_discover_when_too_many_associations()
        {
            EdmModel model
                = new TestModelBuilder()
                  .Entities("S", "T")
                  .Association("S", RelationshipMultiplicity.ZeroOrOne, "T", RelationshipMultiplicity.Many)
                  .Association("S", RelationshipMultiplicity.ZeroOrOne, "T", RelationshipMultiplicity.Many)
                  .Association("T", RelationshipMultiplicity.ZeroOrOne, "S", RelationshipMultiplicity.Many);

            ((IEdmConvention) new AssociationInverseDiscoveryConvention()).Apply(model);

            Assert.Equal(3, model.GetAssociationTypes().Count());
            Assert.Equal(3, model.Containers.Single().AssociationSets.Count());
        }
        public void Apply_should_correct_dangling_navigation_properties()
        {
            EdmModel model
                = new TestModelBuilder()
                    .Entities("S", "T")
                    .Association("A1", "S", EdmAssociationEndKind.Optional, "T", "T", EdmAssociationEndKind.Many, null)
                    .Association("A2", "T", EdmAssociationEndKind.Many, "S", "S", EdmAssociationEndKind.Optional, null);

            ((IEdmConvention)new AssociationInverseDiscoveryConvention()).Apply(model);

            var navigationProperties
                = model.GetEntityTypes().SelectMany(e => e.NavigationProperties);

            Assert.Equal(2, navigationProperties.Count());

            var navigationProperty1 = navigationProperties.ElementAt(0);
            var navigationProperty2 = navigationProperties.ElementAt(1);
            var associationType = model.GetAssociationTypes().Single();

            Assert.Same(associationType, navigationProperty1.Association);
            Assert.Same(associationType, navigationProperty2.Association);
            Assert.Same(associationType.TargetEnd, navigationProperty1.ResultEnd);
            Assert.Same(associationType.SourceEnd, navigationProperty2.ResultEnd);
        }
Ejemplo n.º 5
0
        public void Apply_should_correct_dangling_navigation_properties()
        {
            EdmModel model
                = new TestModelBuilder()
                  .Entities("S", "T")
                  .Association("A1", "S", RelationshipMultiplicity.ZeroOrOne, "T", "T", RelationshipMultiplicity.Many, null)
                  .Association("A2", "T", RelationshipMultiplicity.Many, "S", "S", RelationshipMultiplicity.ZeroOrOne, null);

            ((IEdmConvention) new AssociationInverseDiscoveryConvention()).Apply(model);

            var navigationProperties
                = model.GetEntityTypes().SelectMany(e => e.NavigationProperties);

            Assert.Equal(2, navigationProperties.Count());

            var navigationProperty1 = navigationProperties.ElementAt(0);
            var navigationProperty2 = navigationProperties.ElementAt(1);
            var associationType     = model.GetAssociationTypes().Single();

            Assert.Same(associationType, navigationProperty1.Association);
            Assert.Same(associationType, navigationProperty2.Association);
            Assert.Same(associationType.TargetEnd, navigationProperty1.ResultEnd);
            Assert.Same(associationType.SourceEnd, navigationProperty2.ResultEnd);
        }
        public void Apply_should_not_discover_when_too_many_associations()
        {
            EdmModel model
                = new TestModelBuilder()
                    .Entities("S", "T")
                    .Association("S", EdmAssociationEndKind.Optional, "T", EdmAssociationEndKind.Many)
                    .Association("S", EdmAssociationEndKind.Optional, "T", EdmAssociationEndKind.Many)
                    .Association("T", EdmAssociationEndKind.Optional, "S", EdmAssociationEndKind.Many);

            ((IEdmConvention)new AssociationInverseDiscoveryConvention()).Apply(model);

            Assert.Equal(3, model.GetAssociationTypes().Count());
            Assert.Equal(3, model.Containers.Single().AssociationSets.Count());
        }
        public void Apply_should_discover_for_multiple_entities()
        {
            EdmModel model
                = new TestModelBuilder()
                    .Entities("S", "T", "U")
                    .Association("S", EdmAssociationEndKind.Many, "T", EdmAssociationEndKind.Optional)
                    .Association("T", EdmAssociationEndKind.Many, "S", EdmAssociationEndKind.Optional)
                    .Association("T", EdmAssociationEndKind.Many, "U", EdmAssociationEndKind.Optional)
                    .Association("U", EdmAssociationEndKind.Many, "T", EdmAssociationEndKind.Optional)
                    .Association("U", EdmAssociationEndKind.Many, "S", EdmAssociationEndKind.Optional)
                    .Association("S", EdmAssociationEndKind.Many, "U", EdmAssociationEndKind.Optional);

            ((IEdmConvention)new AssociationInverseDiscoveryConvention()).Apply(model);

            Assert.Equal(3, model.GetAssociationTypes().Count());
            Assert.Equal(3, model.Containers.Single().AssociationSets.Count());
        }