public CompositeKey()
            {
                var sampleFactoryGenerator = new SampleGeneratorFactory(
                    CodeFirstGen.CompositeKey.Csdl(),
                    CodeFirstGen.CompositeKey.Ssdl(),
                    CodeFirstGen.CompositeKey.Msdl());

                var entityType = sampleFactoryGenerator.StoreItemCollection
                                 .OfType <EntityType>()
                                 .Single(x => x.Name == "Tables");

                var testSubject = new MappingPropertyViewFactory(new CodeGenEscaper());

                this.mappingPropertyViews = testSubject.Create(entityType).ToArray();
            }
Ejemplo n.º 2
0
        public void EntityConstructorViewFactoryShouldNotCreateOnlyForNonManyMultiplicity()
        {
            var sampleFactoryGenerator = new SampleGeneratorFactory(
                CodeFirstGen.OneToMany.Csdl(),
                CodeFirstGen.OneToMany.Ssdl(),
                CodeFirstGen.OneToMany.Msdl());

            var postConceptualEntityType = sampleFactoryGenerator.ConceptualItemCollection
                                           .OfType <EntityType>()
                                           .Single(x => x.Name == "Tag");

            var testSubject = new EntityConstructorViewFactory(new CodeGenEscaper());

            var views = testSubject.Create(postConceptualEntityType).ToArray();

            views.Should().BeEmpty();
        }
Ejemplo n.º 3
0
        public void Test()
        {
            var sampleGeneratorFactory = new SampleGeneratorFactory(
                CodeFirstGen.Simple.Csdl(),
                CodeFirstGen.Simple.Ssdl(),
                CodeFirstGen.Simple.Msdl());

            var entityType = sampleGeneratorFactory.StoreItemCollection.OfType <EntityType>()
                             .Single(x => x.Name == "Tables");

            var testSubject = new ContextEntityViewFactory();

            var view = testSubject.Create(entityType);

            view.ConceptualName.Should().Be("Table");
            view.ConceptualMappingName.Should().Be("TableMap");
            view.StoreName.Should().Be("Tables");
        }
Ejemplo n.º 4
0
        public void OneKeyShouldReturnOneHasKey()
        {
            var sampleGeneratorFactory = new SampleGeneratorFactory(
                CodeFirstGen.Simple.Csdl(),
                CodeFirstGen.Simple.Ssdl(),
                CodeFirstGen.Simple.Msdl());

            var entityType = sampleGeneratorFactory.StoreItemCollection.OfType <EntityType>()
                             .Single(x => x.Name == "Tables");

            var testSubject = new MappingKeyViewFactory(entityType);

            var mappingKeyView = testSubject.Create();

            mappingKeyView.Keys.Should().HaveCount(1);
            mappingKeyView.Keys.First().Should().Be("ID");
            mappingKeyView.AsStatement().Should().Be("this.HasKey(x => x.ID);");
        }
Ejemplo n.º 5
0
        public void EntityNavigationViewFactoryShouldMapToZeroOrOneMultiplicity()
        {
            var sampleFactoryGenerator = new SampleGeneratorFactory(
                CodeFirstGen.OneToMany.Csdl(),
                CodeFirstGen.OneToMany.Ssdl(),
                CodeFirstGen.OneToMany.Msdl());

            var entityType = sampleFactoryGenerator.ConceptualItemCollection
                             .OfType <EntityType>()
                             .Single(x => x.Name == "Tag");

            var testSubject = new EntityNavigationViewFactory(new CodeGenEscaper());

            var views = testSubject.Create(entityType).ToArray();

            views.Should().HaveCount(1);
            views[0].Name.Should().Be("Post");
            views[0].TypeName.Should().Be("Post");
        }
Ejemplo n.º 6
0
        public void ColumnNameShouldBeOrdered()
        {
            var sampleGeneratorFactory = new SampleGeneratorFactory(
                CodeFirstGen.Simple.Csdl(),
                CodeFirstGen.Simple.Ssdl(),
                CodeFirstGen.Simple.Msdl());

            var edmMapping = sampleGeneratorFactory.EdmMapping;

            var entityType = sampleGeneratorFactory.ConceptualItemCollection.OfType <EntityType>()
                             .Single(x => x.Name == "Table");

            var testSubject            = new MappingColumnNameViewFactory(edmMapping);
            var mappingColumnNameViews = testSubject.Create(entityType).ToArray();

            mappingColumnNameViews.Should().HaveCount(2);
            mappingColumnNameViews.Select(x => x.ConceptualName).Should().ContainInOrder("ID", "Name");
            mappingColumnNameViews.Select(x => x.StoreName).Should().ContainInOrder("ID", "Name");
        }
Ejemplo n.º 7
0
        public void EntityConstructorViewFactoryShouldCreateOnlyForManyMultiplicity()
        {
            var sampleFactoryGenerator = new SampleGeneratorFactory(
                CodeFirstGen.OneToMany.Csdl(),
                CodeFirstGen.OneToMany.Ssdl(),
                CodeFirstGen.OneToMany.Msdl());

            var postConceptualEntityType = sampleFactoryGenerator.ConceptualItemCollection
                                           .OfType <EntityType>()
                                           .Single(x => x.Name == "Post");

            var testSubject = new EntityConstructorViewFactory(new CodeGenEscaper());

            var views = testSubject.Create(postConceptualEntityType).ToArray();

            views.Should().HaveCount(1);
            views[0].Name.Should().Be("Tags");
            views[0].TypeName.Should().Be("global::System.Collections.Generic.List<Tag>");
        }
Ejemplo n.º 8
0
        public void Test()
        {
            var sampleGeneratorFactory = new SampleGeneratorFactory(
                CodeFirstGen.Simple.Csdl(),
                CodeFirstGen.Simple.Ssdl(),
                CodeFirstGen.Simple.Msdl());

            var entityTypes = sampleGeneratorFactory.StoreItemCollection.OfType <EntityType>().ToArray();

            var factory = new ContextViewFactory(
                "Context",
                new EntityNamespace("Fact"),
                entityTypes);

            var view = factory.Create();

            view.Name.Should().Be("Context");
            view.ModelNamespace.Should().Be("Fact.Models");
            view.ContextEntityViews.Should().HaveCount(1);
        }
Ejemplo n.º 9
0
        public void Test()
        {
            var sampleGeneratorFactory = new SampleGeneratorFactory(
                CodeFirstGen.Simple.Csdl(),
                CodeFirstGen.Simple.Ssdl(),
                CodeFirstGen.Simple.Msdl());

            var entityType = sampleGeneratorFactory.StoreItemCollection.OfType <EntityType>()
                             .Single(x => x.Name == "Tables");

            var testSubject = new EntityEntityViewFactory(new CodeGenEscaper());
            var views       = testSubject.Create(entityType).ToArray();

            views.Should().HaveCount(2);

            views[0].Name.Should().Be("ID");
            views[0].TypeName.Should().Be("global::System.Int32");
            views[0].MethodModifier.Should().BeNullOrEmpty();

            views[1].Name.Should().Be("Name");
            views[1].TypeName.Should().Be("global::System.String");
            views[1].MethodModifier.Should().BeNullOrEmpty();
        }
Ejemplo n.º 10
0
        public void OneToManyShouldHaveOneRelationship()
        {
            var sampleGeneratorFactory = new SampleGeneratorFactory(
                CodeFirstGen.OneToMany.Csdl(),
                CodeFirstGen.OneToMany.Ssdl(),
                CodeFirstGen.OneToMany.Msdl());

            var edmMapping = sampleGeneratorFactory.EdmMapping;

            edmMapping.EntityMappings.Should().HaveCount(2);
            var entityMappingsKeys    = edmMapping.EntityMappings.Keys.OrderBy(x => x.Name).ToArray();
            var entityMappingsKeyPost = entityMappingsKeys[0];
            var entityMappingsKeyTag  = entityMappingsKeys[1];

            entityMappingsKeyPost.Name.Should().Be("Post");
            entityMappingsKeyTag.Name.Should().Be("Tag");

            // Posts
            var entityMappingsValuesPost = edmMapping.EntityMappings[entityMappingsKeyPost];

            entityMappingsValuesPost.Item1.Name.Should().Be("Posts");

            entityMappingsValuesPost.Item2.Should().HaveCount(1);
            var edmPropertyDict1 = entityMappingsValuesPost.Item2.Single();

            edmPropertyDict1.Key.Name.Should().Be("ID");
            edmPropertyDict1.Value.Name.Should().Be("ID");

            // Tags
            var entityMappingsValuesTag = edmMapping.EntityMappings[entityMappingsKeyTag];

            entityMappingsValuesTag.Item1.Name.Should().Be("Tags");

            entityMappingsValuesTag.Item2.Should().HaveCount(2);
            entityMappingsValuesTag.Item2.Keys.Select(x => x.Name).Should().Contain("ID", "Post_ID");
            entityMappingsValuesTag.Item2.Values.Select(x => x.Name).Should().Contain("ID", "Post_ID");
        }
Ejemplo n.º 11
0
        public void DebugOnly()
        {
            var sampleGeneratorFactory = new SampleGeneratorFactory(
                CodeFirstGen.ManyToMany.Csdl(),
                CodeFirstGen.ManyToMany.Ssdl(),
                CodeFirstGen.ManyToMany.Msdl());

            var edmMapping = sampleGeneratorFactory.EdmMapping;

            var posts = sampleGeneratorFactory.ConceptualItemCollection.OfType <EntityType>().First(x => x.Name == "Post");

            var entityTypes = sampleGeneratorFactory.ConceptualItemCollection.OfType <EntityType>().ToArray();

            entityTypes.Should().HaveCount(2);

            //var tableSet = edmMapping.EntityMappings[posts].Item1;
            //var propertyToColumnMappings = edmMapping.EntityMappings[posts].Item2;

            ///////////////////////////////////////////////////////////////////
            // ManyToManyMappings:
            //  k: AssociationType (aka PostTags)
            //  v: Tuple<EntitySet, Dictionary<RelationshipEndMember, Dictionary<EdmMember, string>>>
            //    Item1: EntitySet (aka PostTags - the table in the store)
            //    Item2: Dictionary<RelationshipEndMember, Dictionary<EdmMember, string>>
            //      RelationshipEndMember: represents one end of a relationship, in the case of a many
            //                             to many it represents the entity that connects to the
            //                             many-to-many table.
            //      <EdmMember, string>:   PostId, PostId_Post
            //                             represents a mapping to the many-to-many table.  EdmMember
            //                             is the source, and string is the name of the target store
            //                             column.
            //var manyToManyMappings = edmMapping.ManyToManyMappings;

            posts.NavigationProperties.Should().HaveCount(1);
            var manyManyRelationship = posts
                                       .NavigationProperties
                                       .Where(x =>
                                              x.DeclaringType == posts &&
                                              x.FromEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many &&
                                              x.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many &&
                                              x.RelationshipType.RelationshipEndMembers.First() == x.FromEndMember);

            NavigationProperty navigationProperty = manyManyRelationship.Single();
            var otherNavigationProperty           = navigationProperty
                                                    .ToEndMember
                                                    .GetEntityType()
                                                    .NavigationProperties
                                                    .Single(x => x.RelationshipType == navigationProperty.RelationshipType && x != navigationProperty);

            var       association       = (AssociationType)navigationProperty.RelationshipType;
            var       mapping           = edmMapping.ManyToManyMappings[association];
            EntitySet storeEntitySet    = mapping.Item1;
            var       mappingTableName  = (string)storeEntitySet.MetadataProperties["Table"].Value ?? storeEntitySet.Name;
            var       mappingSchemaName = (string)storeEntitySet.MetadataProperties["Schema"].Value;

            EntityType leftType = (EntityType)navigationProperty.DeclaringType;

            leftType.Name.Should().Be("Post");
            Dictionary <EdmMember, string> leftKeyMappings = mapping.Item2[navigationProperty.FromEndMember];
            var leftColumns = string.Join(",", leftType.KeyMembers.Select(x => leftKeyMappings[x]));

            EntityType rightType = (EntityType)otherNavigationProperty.DeclaringType;

            rightType.Name.Should().Be("Tag");
            Dictionary <EdmMember, string> rightKeyMappings = mapping.Item2[otherNavigationProperty.FromEndMember];
            var rightColumns = string.Join(",", rightType.KeyMembers.Select(x => rightKeyMappings[x]));

            // HasMany
            navigationProperty.Name.Should().Be("Tags");

            // WithMany
            otherNavigationProperty.Name.Should().Be("Posts");

            // ToTable
            mappingTableName.Should().Be("PostTags");
            mappingSchemaName.Should().Be("dbo");

            // MapLeftKey
            leftColumns.Should().Be("Post_PostId");

            // MapRightKey
            rightColumns.Should().Be("Tag_TagId");
        }