コード例 #1
0
        public void GetMethodChain_returns_body_when_name()
        {
            var configuration = new ColumnConfiguration { Name = "Id" };
            var code = new CSharpCodeHelper();

            Assert.Equal(".HasColumnName(\"Id\")", configuration.GetMethodChain(code));
        }
コード例 #2
0
        public void GetMethodChain_returns_body_when_order()
        {
            var configuration = new ColumnConfiguration { Order = 0 };
            var code = new CSharpCodeHelper();

            Assert.Equal(".HasColumnOrder(0)", configuration.GetMethodChain(code));
        }
コード例 #3
0
        public void GetAttributeBody_returns_body_when_order()
        {
            var configuration = new ColumnConfiguration { Order = 0 };
            var code = new CSharpCodeHelper();

            Assert.Equal("Column(Order = 0)", configuration.GetAttributeBody(code));
        }
コード例 #4
0
        public void GetAttributeBody_returns_body_when_all()
        {
            var configuration = new ColumnConfiguration { Name = "Id", Order = 0, TypeName = "int" };
            var code = new CSharpCodeHelper();

            Assert.Equal("Column(\"Id\", Order = 0, TypeName = \"int\")", configuration.GetAttributeBody(code));
        }
コード例 #5
0
        public void GetMethodChain_returns_chain_when_one_key_property()
        {
            var configuration = new KeyConfiguration { KeyProperties = { new EdmProperty("Id") } };
            var code = new CSharpCodeHelper();

            Assert.Equal(".HasKey(e => e.Id)", configuration.GetMethodChain(code));
        }
コード例 #6
0
        public void GetMethodChain_returns_chan_when_many_to_many()
        {
            var modelBuilder = new DbModelBuilder();
            modelBuilder.Entity<Entity1>().HasMany(e => e.Entity2s).WithMany(e => e.Entity1s);
            modelBuilder.Entity<Entity1>().Ignore(e => e.Entity2);
            var model = modelBuilder.Build(new DbProviderInfo("System.Data.SqlClient", "2012"));
            var entityType = model.ConceptualModel.EntityTypes.First(t => t.Name == "Entity1");
            var navigationProperty = entityType.NavigationProperties.First(p => p.Name == "Entity2s");
            var otherEntityType = model.ConceptualModel.EntityTypes.First(t => t.Name == "Entity2");
            var otherNavigationProperty = otherEntityType.NavigationProperties.First(p => p.Name == "Entity1s");

            var configuration = new MultiplicityConfiguration
                {
                    LeftEntityType = entityType,
                    LeftNavigationProperty = navigationProperty,
                    RightNavigationProperty = otherNavigationProperty
                };
            var code = new CSharpCodeHelper();

            Assert.Equal(
                @".Entity<Entity1>()
                .HasMany(e => e.Entity2s)
                .WithMany(e => e.Entity1s)",
                configuration.GetMethodChain(code));
        }
コード例 #7
0
        public void GetMethodChain_returns_chain_when_table()
        {
            var configuration = new JoinTableConfiguration { Table = "Subscriptions" };
            var code = new CSharpCodeHelper();

            Assert.Equal(".Map(m => m.ToTable(\"Subscriptions\"))", configuration.GetMethodChain(code));
        }
コード例 #8
0
        public void GetMethodChain_returns_chain()
        {
            var configuration = new FixedLengthConfiguration();
            var code = new CSharpCodeHelper();

            Assert.Equal(".IsFixedLength()", configuration.GetMethodChain(code));
        }
コード例 #9
0
        public void GetMethodChain_returns_chain_when_one_left_key()
        {
            var configuration = new JoinTableConfiguration { LeftKeys = { "CustomerId" } };
            var code = new CSharpCodeHelper();

            Assert.Equal(".Map(m => m.MapLeftKey(\"CustomerId\"))", configuration.GetMethodChain(code));
        }
コード例 #10
0
        public void GetMethodChain_returns_chain_when_one_right_key()
        {
            var configuration = new JoinTableConfiguration { RightKeys = { "ServiceId" } };
            var code = new CSharpCodeHelper();

            Assert.Equal(".Map(m => m.MapRightKey(\"ServiceId\"))", configuration.GetMethodChain(code));
        }
コード例 #11
0
        public void GetMethodChain_returns_chain()
        {
            var configuration = new NonUnicodeConfiguration();
            var code = new CSharpCodeHelper();

            Assert.Equal(".IsUnicode(false)", configuration.GetMethodChain(code));
        }
コード例 #12
0
        public void GetAttributeBody_returns_body()
        {
            var configuration = new TimestampConfiguration();
            var code = new CSharpCodeHelper();

            Assert.Equal("Timestamp", configuration.GetAttributeBody(code));
        }
コード例 #13
0
        public void GetMethodChain_returns_chain()
        {
            var configuration = new TimestampConfiguration();
            var code = new CSharpCodeHelper();

            Assert.Equal(".IsRowVersion()", configuration.GetMethodChain(code));
        }
コード例 #14
0
        public void GetMethodChain_returns_body_when_type()
        {
            var configuration = new ColumnConfiguration { TypeName = "int" };
            var code = new CSharpCodeHelper();

            Assert.Equal(".HasColumnType(\"int\")", configuration.GetMethodChain(code));
        }
コード例 #15
0
        public void GetMethodChain_returns_chain()
        {
            var configuration = new PrecisionDateTimeConfiguration { Precision = 4 };
            var code = new CSharpCodeHelper();

            Assert.Equal(".HasPrecision(4)", configuration.GetMethodChain(code));
        }
コード例 #16
0
        public void GetAttributeBody_returns_body_when_name()
        {
            var configuration = new ColumnConfiguration { Name = "Id" };
            var code = new CSharpCodeHelper();

            Assert.Equal("Column(\"Id\")", configuration.GetAttributeBody(code));
        }
コード例 #17
0
        public void GetMethodChain_returns_chain()
        {
            var configuration = new NonUnicodeConfiguration();
            var code          = new CSharpCodeHelper();

            Assert.Equal(".IsUnicode(false)", configuration.GetMethodChain(code));
        }
コード例 #18
0
        public void GetAttributeBody_returns_body()
        {
            var configuration = new TableConfiguration { Table = "Entities" };
            var code = new CSharpCodeHelper();

            Assert.Equal("Table(\"Entities\")", configuration.GetAttributeBody(code));
        }
コード例 #19
0
        public void Type_returns_type_name()
        {
            var container = Model.ConceptualModel.EntityTypes.First();
            var code = new CSharpCodeHelper();

            Assert.Equal("Entity", code.Type(container));
        }
コード例 #20
0
        public void GetAttributeBody_returns_body()
        {
            var configuration = new KeyPropertyConfiguration();
            var code = new CSharpCodeHelper();

            Assert.Equal("Key", configuration.GetAttributeBody(code));
        }
コード例 #21
0
        public void Property_returns_member_name()
        {
            var member = Model.ConceptualModel.EntityTypes.First().Properties.First(p => p.Name == "Id");
            var code   = new CSharpCodeHelper();

            Assert.Equal("Id", code.Property(member));
        }
コード例 #22
0
        public void Property_returns_entity_set_name()
        {
            var entitySet = Model.ConceptualModel.Container.EntitySets.First();
            var code      = new CSharpCodeHelper();

            Assert.Equal("Entities", code.Property(entitySet));
        }
コード例 #23
0
        public void GetMethodChain_returns_chain()
        {
            var configuration = new RequiredConfiguration();
            var code          = new CSharpCodeHelper();

            Assert.Equal(".IsRequired()", configuration.GetMethodChain(code));
        }
コード例 #24
0
        public void GetAttributeBody_returns_body()
        {
            var configuration = new KeyPropertyConfiguration();
            var code          = new CSharpCodeHelper();

            Assert.Equal("Key", configuration.GetAttributeBody(code));
        }
コード例 #25
0
        public void Lambda_returns_property_accessor_when_one()
        {
            var code   = new CSharpCodeHelper();
            var member = Model.ConceptualModel.EntityTypes.First().Properties.First(p => p.Name == "Id");

            Assert.Equal("e => e.Id", code.Lambda(member));
        }
コード例 #26
0
        public void GetMethodChain_returns_chain()
        {
            var configuration = new MaxLengthConfiguration { MaxLength = 30 };
            var code = new CSharpCodeHelper();

            Assert.Equal(".HasMaxLength(30)", configuration.GetMethodChain(code));
        }
コード例 #27
0
        public void GetMethodChain_returns_chan_when_required_to_many()
        {
            var modelBuilder = new DbModelBuilder();

            modelBuilder.Entity <Entity1>().HasRequired(e => e.Entity2).WithMany(e => e.Entity1s);
            var model                   = modelBuilder.Build(new DbProviderInfo("System.Data.SqlClient", "2012"));
            var entityType              = model.ConceptualModel.EntityTypes.First(t => t.Name == "Entity1");
            var navigationProperty      = entityType.NavigationProperties.First(p => p.Name == "Entity2");
            var otherEntityType         = model.ConceptualModel.EntityTypes.First(t => t.Name == "Entity2");
            var otherNavigationProperty = otherEntityType.NavigationProperties.First(p => p.Name == "Entity1s");

            var configuration = new MultiplicityConfiguration
            {
                LeftEntityType          = entityType,
                LeftNavigationProperty  = navigationProperty,
                RightNavigationProperty = otherNavigationProperty
            };
            var code = new CSharpCodeHelper();

            Assert.Equal(
                @".Entity<Entity1>()
                .HasRequired(e => e.Entity2)
                .WithMany(e => e.Entity1s)",
                configuration.GetMethodChain(code));
        }
コード例 #28
0
        public void GetMethodChain_returns_body()
        {
            var configuration = new TableConfiguration { Table = "Entities" };
            var code = new CSharpCodeHelper();

            Assert.Equal(".ToTable(\"Entities\")", configuration.GetMethodChain(code));
        }
コード例 #29
0
        public void Type_returns_container_name()
        {
            var container = Model.ConceptualModel.Container;
            var code = new CSharpCodeHelper();

            Assert.Equal("CodeFirstContainer", code.Type(container));
        }
コード例 #30
0
        public void Type_returns_type_name()
        {
            var container = Model.ConceptualModel.EntityTypes.First();
            var code      = new CSharpCodeHelper();

            Assert.Equal("Entity", code.Type(container));
        }
コード例 #31
0
        public void GetAttributeBody_returns_body()
        {
            var configuration = new MaxLengthConfiguration { MaxLength = 30 };
            var code = new CSharpCodeHelper();

            Assert.Equal("MaxLength(30)", configuration.GetAttributeBody(code));
        }
コード例 #32
0
        public void GetAttributeBody_returns_body()
        {
            var configuration = new RequiredConfiguration();
            var code = new CSharpCodeHelper();

            Assert.Equal("Required", configuration.GetAttributeBody(code));
        }
コード例 #33
0
        public void GetMethodChain_returns_chain_when_none()
        {
            var configuration = new CascadeDeleteConfiguration { DeleteBehavior = OperationAction.None };
            var code = new CSharpCodeHelper();

            Assert.Equal(".WillCascadeOnDelete(false)", configuration.GetMethodChain(code));
        }
コード例 #34
0
        public void GetMethodChain_returns_chain_when_one_property()
        {
            var configuration = new ForeignKeyConfiguration { Properties = { new EdmProperty("EntityId") } };
            var code = new CSharpCodeHelper();

            Assert.Equal(".HasForeignKey(e => e.EntityId)", configuration.GetMethodChain(code));
        }
コード例 #35
0
        public void GetMethodChain_returns_chain()
        {
            var configuration = new TimestampConfiguration();
            var code          = new CSharpCodeHelper();

            Assert.Equal(".IsRowVersion()", configuration.GetMethodChain(code));
        }
コード例 #36
0
        public void GetAttributeBody_returns_body()
        {
            var configuration = new TimestampConfiguration();
            var code          = new CSharpCodeHelper();

            Assert.Equal("Timestamp", configuration.GetAttributeBody(code));
        }
コード例 #37
0
        public void Type_returns_container_name()
        {
            var container = Model.ConceptualModel.Container;
            var code      = new CSharpCodeHelper();

            Assert.Equal("CodeFirstContainer", code.Type(container));
        }
コード例 #38
0
        public void GetMethodChain_returns_chain()
        {
            var configuration = new PrecisionDecimalConfiguration { Precision = 8, Scale = 2 };
            var code = new CSharpCodeHelper();

            Assert.Equal(".HasPrecision(8, 2)", configuration.GetMethodChain(code));
        }
コード例 #39
0
        public void GetMethodChain_returns_chain()
        {
            var configuration = new FixedLengthConfiguration();
            var code          = new CSharpCodeHelper();

            Assert.Equal(".IsFixedLength()", configuration.GetMethodChain(code));
        }
コード例 #40
0
        public void GetMethodChain_returns_chain()
        {
            var configuration = new RequiredConfiguration();
            var code = new CSharpCodeHelper();

            Assert.Equal(".IsRequired()", configuration.GetMethodChain(code));
        }
コード例 #41
0
        public void Literal_returns_bool()
        {
            var code = new CSharpCodeHelper();

            Assert.Equal("true", code.Literal(true));
            Assert.Equal("false", code.Literal(false));
        }
コード例 #42
0
        public void GetAttributeBody_returns_body()
        {
            var configuration = new RequiredConfiguration();
            var code          = new CSharpCodeHelper();

            Assert.Equal("Required", configuration.GetAttributeBody(code));
        }
コード例 #43
0
        public void Type_unqualifies_property_type()
        {
            var property = Model.ConceptualModel.EntityTypes.First().Properties.First(
                p => p.Name == "Guid");
            var code = new CSharpCodeHelper();

            Assert.Equal("Guid", code.Type(property));
        }
コード例 #44
0
        public void Type_returns_collection_property_type()
        {
            var property = Model.ConceptualModel.EntityTypes.First().NavigationProperties.First(
                p => p.Name == "Children");
            var code = new CSharpCodeHelper();

            Assert.Equal("ICollection<Entity>", code.Type(property));
        }
コード例 #45
0
        public void Type_escapes_container_name()
        {
            var container = new Mock<EntityContainer>();
            container.SetupGet(c => c.Name).Returns("null");
            var code = new CSharpCodeHelper();

            Assert.Equal("_null", code.Type(container.Object));
        }
コード例 #46
0
        public void MethodChain_evaluates_preconditions()
        {
            var code = new CSharpCodeHelper();

            var ex = Assert.Throws <ArgumentNullException>(() => code.MethodChain(null));

            Assert.Equal("configuration", ex.ParamName);
        }
コード例 #47
0
        public void Lambda_returns_anonymous_type_when_one()
        {
            var code = new CSharpCodeHelper();
            var id   = Model.ConceptualModel.EntityTypes.First().Properties.First(p => p.Name == "Id");
            var name = Model.ConceptualModel.EntityTypes.First().Properties.First(p => p.Name == "Name");

            Assert.Equal("e => new { e.Id, e.Name }", code.Lambda(new[] { id, name }));
        }
コード例 #48
0
        public void Type_escapes_type_name()
        {
            var type = new Mock<EdmType>();
            type.SetupGet(c => c.Name).Returns("null");
            var code = new CSharpCodeHelper();

            Assert.Equal("_null", code.Type(type.Object));
        }
コード例 #49
0
        public void Type_returns_reference_property_type()
        {
            var property = Model.ConceptualModel.EntityTypes.First().NavigationProperties.First(
                p => p.Name == "Parent");
            var code = new CSharpCodeHelper();

            Assert.Equal("Entity", code.Type(property));
        }
コード例 #50
0
        public void Type_returns_property_type()
        {
            var property = Model.ConceptualModel.EntityTypes.First().Properties.First(
                p => p.Name == "Name");
            var code = new CSharpCodeHelper();

            Assert.Equal("string", code.Type(property));
        }
コード例 #51
0
        public void Type_returns_nullable_value_property_type()
        {
            var property = Model.ConceptualModel.EntityTypes.First().Properties.First(
                p => p.Name == "ParentId");
            var code = new CSharpCodeHelper();

            Assert.Equal("int?", code.Type(property));
        }
コード例 #52
0
        public void GetMethodChain_returns_body_when_order()
        {
            var configuration = new ColumnConfiguration {
                Order = 0
            };
            var code = new CSharpCodeHelper();

            Assert.Equal(".HasColumnOrder(0)", configuration.GetMethodChain(code));
        }
コード例 #53
0
        public void GetMethodChain_returns_body_when_name()
        {
            var configuration = new ColumnConfiguration {
                Name = "Id"
            };
            var code = new CSharpCodeHelper();

            Assert.Equal(".HasColumnName(\"Id\")", configuration.GetMethodChain(code));
        }
コード例 #54
0
        public void GetAttributeBody_returns_body()
        {
            var configuration = new MaxLengthConfiguration {
                MaxLength = 30
            };
            var code = new CSharpCodeHelper();

            Assert.Equal("MaxLength(30)", configuration.GetAttributeBody(code));
        }
コード例 #55
0
        public void GetAttributeBody_returns_body_when_name()
        {
            var configuration = new ColumnConfiguration {
                Name = "Id"
            };
            var code = new CSharpCodeHelper();

            Assert.Equal("Column(\"Id\")", configuration.GetAttributeBody(code));
        }
コード例 #56
0
        public void GetMethodChain_returns_chain()
        {
            var configuration = new MaxLengthConfiguration {
                MaxLength = 30
            };
            var code = new CSharpCodeHelper();

            Assert.Equal(".HasMaxLength(30)", configuration.GetMethodChain(code));
        }
コード例 #57
0
        public void GetMethodChain_returns_body_when_type()
        {
            var configuration = new ColumnConfiguration {
                TypeName = "int"
            };
            var code = new CSharpCodeHelper();

            Assert.Equal(".HasColumnType(\"int\")", configuration.GetMethodChain(code));
        }
コード例 #58
0
        public void GetMethodChain_returns_chain_when_one_left_key()
        {
            var configuration = new JoinTableConfiguration {
                LeftKeys = { "CustomerId" }
            };
            var code = new CSharpCodeHelper();

            Assert.Equal(".Map(m => m.MapLeftKey(\"CustomerId\"))", configuration.GetMethodChain(code));
        }
コード例 #59
0
        public void GetMethodChain_returns_chain_when_table()
        {
            var configuration = new JoinTableConfiguration {
                Table = "Subscriptions"
            };
            var code = new CSharpCodeHelper();

            Assert.Equal(".Map(m => m.ToTable(\"Subscriptions\"))", configuration.GetMethodChain(code));
        }
コード例 #60
0
        public void GetMethodChain_returns_chain_when_one_right_key()
        {
            var configuration = new JoinTableConfiguration {
                RightKeys = { "ServiceId" }
            };
            var code = new CSharpCodeHelper();

            Assert.Equal(".Map(m => m.MapRightKey(\"ServiceId\"))", configuration.GetMethodChain(code));
        }