public virtual void Detects_duplicate_column_names_within_hierarchy_with_different_DefaultValueSql()
        {
            var modelBuilder = new ModelBuilder(TestConventionalSetBuilder.Build());

            modelBuilder.Entity <Animal>();
            modelBuilder.Entity <Cat>().Ignore(e => e.Type).Property(c => c.Breed).HasDefaultValueSql("1");
            modelBuilder.Entity <Dog>().Ignore(e => e.Type);

            VerifyError(RelationalStrings.DuplicateColumnNameDefaultSqlMismatch(
                            nameof(Cat), nameof(Cat.Breed), nameof(Dog), nameof(Dog.Breed), nameof(Cat.Breed), ".Animal", "1", ""), modelBuilder.Model);
        }
        public virtual void Detects_duplicate_column_names_within_hierarchy_with_different_MaxLength()
        {
            var modelBuilder = new ModelBuilder(TestConventionalSetBuilder.Build());

            modelBuilder.Entity <Animal>();
            modelBuilder.Entity <Cat>().Ignore(e => e.Type).Property(c => c.Breed).HasMaxLength(30);
            modelBuilder.Entity <Dog>().Ignore(e => e.Type).Property(d => d.Breed).HasMaxLength(15);

            VerifyError(RelationalStrings.DuplicateColumnName(
                            nameof(Cat), nameof(Cat.Breed), nameof(Dog), nameof(Dog.Breed), nameof(Cat.Breed), ".Animal", "just_string(30)", "just_string(15)"), modelBuilder.Model);
        }
        public virtual void Detects_duplicate_columns_in_derived_types_with_different_types()
        {
            var modelBuilder = new ModelBuilder(TestConventionalSetBuilder.Build());

            modelBuilder.Entity <Animal>();
            modelBuilder.Entity <Cat>();
            modelBuilder.Entity <Dog>();

            VerifyError(RelationalStrings.DuplicateColumnName(
                            nameof(Cat), nameof(Cat.Type), nameof(Dog), nameof(Dog.Type), nameof(Cat.Type), ".Animal", "just_string(2000)", "default_int_mapping"), modelBuilder.Model);
        }
        public virtual void Detects_duplicate_column_names_within_hierarchy_with_different_nullability()
        {
            var modelBuilder = new ModelBuilder(TestConventionalSetBuilder.Build());

            modelBuilder.Entity <Animal>();
            modelBuilder.Entity <Cat>().Ignore(e => e.Type);
            modelBuilder.Entity <Dog>().Ignore(e => e.Type).Property(d => d.Type).HasColumnName("Id");

            VerifyError(RelationalStrings.DuplicateColumnNameNullabilityMismatch(
                            nameof(Animal), nameof(Animal.Id), nameof(Dog), nameof(Dog.Type), nameof(Animal.Id), ".Animal"), modelBuilder.Model);
        }
        public virtual void Detects_missing_non_string_discriminator_values()
        {
            var modelBuilder = new ModelBuilder(TestConventionalSetBuilder.Build());

            modelBuilder.Entity <C>();
            modelBuilder.Entity <A>().HasDiscriminator <byte>("ClassType")
            .HasValue <A>(0)
            .HasValue <D>(1);

            var model = modelBuilder.Model;

            VerifyError(RelationalStrings.NoDiscriminatorValue(typeof(C).Name), model);
        }
        public virtual void Detects_duplicate_discriminator_values()
        {
            var modelBuilder = new ModelBuilder(TestConventionalSetBuilder.Build());

            modelBuilder.Entity <A>().HasDiscriminator <byte>("ClassType")
            .HasValue <A>(1)
            .HasValue <C>(1)
            .HasValue <D>(2);

            var model = modelBuilder.Model;

            VerifyError(RelationalStrings.DuplicateDiscriminatorValue(typeof(C).Name, 1, typeof(A).Name), model);
        }
        public virtual void Does_not_detect_missing_discriminator_value_for_abstract_class()
        {
            var modelBuilder = new ModelBuilder(TestConventionalSetBuilder.Build());

            modelBuilder.Entity <Abstract>();
            modelBuilder.Entity <A>().HasDiscriminator <byte>("ClassType")
            .HasValue <A>(0)
            .HasValue <C>(1)
            .HasValue <D>(2)
            .HasValue <Generic <string> >(3);

            Validate(modelBuilder.Model);
        }
Пример #8
0
        public virtual void Passes_for_compatible_duplicate_index_names_within_hierarchy()
        {
            var modelBuilder = new ModelBuilder(TestConventionalSetBuilder.Build());

            modelBuilder.Entity <Animal>();
            var index1 = modelBuilder.Entity <Cat>().HasIndex(c => c.Breed).Metadata;
            var index2 = modelBuilder.Entity <Dog>().HasIndex(c => c.Breed).Metadata;

            Validate(modelBuilder.Model);

            Assert.NotSame(index1, index2);
            Assert.Equal(index1.Relational().Name, index2.Relational().Name);
        }
Пример #9
0
        public virtual void Detects_duplicate_foreignKey_names_within_hierarchy_with_different_uniqueness()
        {
            var modelBuilder = new ModelBuilder(TestConventionalSetBuilder.Build());

            modelBuilder.Entity <Animal>();
            modelBuilder.Entity <Cat>().HasOne <Person>().WithMany().HasForeignKey(c => c.Name).HasPrincipalKey(p => p.Name);
            modelBuilder.Entity <Dog>().HasOne <Person>().WithOne().HasForeignKey <Dog>(d => d.Name).HasPrincipalKey <Person>(p => p.Name);

            VerifyError(RelationalStrings.DuplicateForeignKeyUniquenessMismatch(
                            "{'" + nameof(Dog.Name) + "'}", nameof(Dog),
                            "{'" + nameof(Cat.Name) + "'}", nameof(Cat),
                            nameof(Animal), "FK_Animal_Person_Name"),
                        modelBuilder.Model);
        }
Пример #10
0
        public virtual void Detects_duplicate_index_names_within_hierarchy_with_different_uniqueness()
        {
            var modelBuilder = new ModelBuilder(TestConventionalSetBuilder.Build());

            modelBuilder.Entity <Animal>();
            modelBuilder.Entity <Cat>().HasIndex(c => c.Name).IsUnique();
            modelBuilder.Entity <Dog>().HasIndex(d => d.Name).IsUnique(false);

            VerifyError(RelationalStrings.DuplicateIndexUniquenessMismatch(
                            "{'" + nameof(Dog.Name) + "'}", nameof(Dog),
                            "{'" + nameof(Cat.Name) + "'}", nameof(Cat),
                            nameof(Animal), "IX_Animal_Name"),
                        modelBuilder.Model);
        }
Пример #11
0
        public virtual void Detects_duplicate_foreignKey_names_within_hierarchy_with_different_column_order()
        {
            var modelBuilder = new ModelBuilder(TestConventionalSetBuilder.Build());

            modelBuilder.Entity <Animal>();
            modelBuilder.Entity <Cat>().HasOne <Person>().WithMany().HasForeignKey(c => new { c.Name, c.Breed }).HasPrincipalKey(p => new { p.Name, p.FavoriteBreed }).HasConstraintName("FK");
            modelBuilder.Entity <Dog>().HasOne <Person>().WithMany().HasForeignKey(d => new { d.Breed, d.Name }).HasPrincipalKey(p => new { p.FavoriteBreed, p.Name }).HasConstraintName("FK");

            VerifyError(RelationalStrings.DuplicateForeignKeyColumnMismatch(
                            "{'" + nameof(Dog.Breed) + "', '" + nameof(Dog.Name) + "'}", nameof(Dog),
                            "{'" + nameof(Cat.Name) + "', '" + nameof(Cat.Breed) + "'}", nameof(Cat),
                            nameof(Animal), "FK",
                            "{'" + nameof(Dog.Breed) + "', '" + nameof(Dog.Name) + "'}",
                            "{'" + nameof(Cat.Name) + "', '" + nameof(Cat.Breed) + "'}"),
                        modelBuilder.Model);
        }
Пример #12
0
        public virtual void Detects_duplicate_foreignKey_names_within_hierarchy_with_different_column_count()
        {
            var modelBuilder = new ModelBuilder(TestConventionalSetBuilder.Build());

            modelBuilder.Entity <Animal>().Property <int>("Shadow");
            modelBuilder.Entity <Cat>().HasOne <Person>().WithMany().HasForeignKey(nameof(Cat.Name), "Shadow").HasConstraintName("FK");
            modelBuilder.Entity <Dog>().HasOne <Person>().WithMany().HasForeignKey(d => d.Name).HasConstraintName("FK");

            VerifyError(RelationalStrings.DuplicateForeignKeyColumnMismatch(
                            "{'" + nameof(Dog.Name) + "'}", nameof(Dog),
                            "{'" + nameof(Cat.Name) + "', 'Shadow'}", nameof(Cat),
                            nameof(Animal), "FK",
                            "{'" + nameof(Dog.Name) + "'}",
                            "{'" + nameof(Cat.Name) + "', 'Shadow'}"),
                        modelBuilder.Model);
        }
Пример #13
0
        public virtual void Detects_duplicate_index_names_within_hierarchy_with_different_column_count()
        {
            var modelBuilder = new ModelBuilder(TestConventionalSetBuilder.Build());

            modelBuilder.Entity <Animal>().Property <int>("Shadow");
            modelBuilder.Entity <Cat>().HasIndex(nameof(Cat.Name), "Shadow").HasName("IX");
            modelBuilder.Entity <Dog>().HasIndex(d => d.Name).HasName("IX");

            VerifyError(RelationalStrings.DuplicateIndexColumnMismatch(
                            "{'" + nameof(Dog.Name) + "'}", nameof(Dog),
                            "{'" + nameof(Cat.Name) + "', 'Shadow'}", nameof(Cat),
                            nameof(Animal), "IX",
                            "{'" + nameof(Dog.Name) + "'}",
                            "{'" + nameof(Cat.Name) + "', 'Shadow'}"),
                        modelBuilder.Model);
        }
Пример #14
0
        public virtual void Detects_duplicate_index_names_within_hierarchy_with_different_column_order()
        {
            var modelBuilder = new ModelBuilder(TestConventionalSetBuilder.Build());

            modelBuilder.Entity <Animal>();
            modelBuilder.Entity <Cat>().HasIndex(c => new { c.Name, c.Breed }).HasName("IX");
            modelBuilder.Entity <Dog>().HasIndex(d => new { d.Breed, d.Name }).HasName("IX");

            VerifyError(RelationalStrings.DuplicateIndexColumnMismatch(
                            "{'" + nameof(Dog.Breed) + "', '" + nameof(Dog.Name) + "'}", nameof(Dog),
                            "{'" + nameof(Cat.Name) + "', '" + nameof(Cat.Breed) + "'}", nameof(Cat),
                            nameof(Animal), "IX",
                            "{'" + nameof(Dog.Breed) + "', '" + nameof(Dog.Name) + "'}",
                            "{'" + nameof(Cat.Name) + "', '" + nameof(Cat.Breed) + "'}"),
                        modelBuilder.Model);
        }
Пример #15
0
        public virtual void Detects_duplicate_foreignKey_names_within_hierarchy_with_different_principal_tables()
        {
            var modelBuilder = new ModelBuilder(TestConventionalSetBuilder.Build());

            modelBuilder.Entity <Animal>();
            modelBuilder.Entity <Cat>().HasOne <Person>().WithMany().HasForeignKey("FriendId").HasConstraintName("FK");
            modelBuilder.Entity <Dog>().HasOne <Animal>().WithMany().HasForeignKey("FriendId").HasConstraintName("FK");

            VerifyError(RelationalStrings.DuplicateForeignKeyPrincipalTableMismatch(
                            "{'FriendId'}", nameof(Dog),
                            "{'FriendId'}", nameof(Cat),
                            nameof(Animal), "FK",
                            nameof(Animal),
                            nameof(Person)),
                        modelBuilder.Model);
        }
Пример #16
0
        public virtual void Detects_duplicate_foreignKey_names_within_hierarchy_with_different_delete_behavior()
        {
            var modelBuilder = new ModelBuilder(TestConventionalSetBuilder.Build());

            modelBuilder.Entity <Animal>();
            modelBuilder.Entity <Cat>().HasOne <Person>().WithMany().HasForeignKey(c => c.Name).HasPrincipalKey(p => p.Name)
            .OnDelete(DeleteBehavior.Cascade);
            modelBuilder.Entity <Dog>().HasOne <Person>().WithMany().HasForeignKey(d => d.Name).HasPrincipalKey(p => p.Name)
            .OnDelete(DeleteBehavior.SetNull);

            VerifyError(RelationalStrings.DuplicateForeignKeyDeleteBehaviorMismatch(
                            "{'" + nameof(Dog.Name) + "'}", nameof(Dog),
                            "{'" + nameof(Cat.Name) + "'}", nameof(Cat),
                            nameof(Animal), "FK_Animal_Person_Name",
                            DeleteBehavior.SetNull, DeleteBehavior.Cascade),
                        modelBuilder.Model);
        }
Пример #17
0
        public virtual void Detects_duplicate_foreignKey_names_within_hierarchy_referencing_different_columns()
        {
            var modelBuilder = new ModelBuilder(TestConventionalSetBuilder.Build());

            modelBuilder.Entity <Animal>();
            modelBuilder.Entity <Cat>()
            .HasOne <Person>().WithMany()
            .HasForeignKey(c => c.Name).HasPrincipalKey(p => p.Name).HasConstraintName("FK");
            modelBuilder.Entity <Dog>()
            .HasOne <Person>().WithMany()
            .HasForeignKey(d => d.Name).HasPrincipalKey(p => p.FavoriteBreed).HasConstraintName("FK");
            modelBuilder.Entity <Dog>().Property(d => d.Breed).HasColumnName("DogBreed");

            VerifyError(RelationalStrings.DuplicateForeignKeyPrincipalColumnMismatch(
                            "{'" + nameof(Dog.Name) + "'}", nameof(Dog),
                            "{'" + nameof(Cat.Name) + "'}", nameof(Cat),
                            nameof(Animal), "FK",
                            "{'" + nameof(Person.FavoriteBreed) + "'}",
                            "{'" + nameof(Person.Name) + "'}"),
                        modelBuilder.Model);
        }
        public virtual void Does_not_detect_duplicate_column_names_within_hierarchy()
        {
            var modelBuilder = new ModelBuilder(TestConventionalSetBuilder.Build());

            modelBuilder.Entity <Animal>();
            modelBuilder.Entity <Cat>(eb =>
            {
                eb.Ignore(e => e.Type);
                eb.Property(c => c.Breed).HasMaxLength(25);
                eb.Property(c => c.Breed).HasColumnName("BreedName");
                eb.Property(c => c.Breed).HasDefaultValue("None");
            });
            modelBuilder.Entity <Dog>(eb =>
            {
                eb.Ignore(e => e.Type);
                eb.Property(c => c.Breed).HasMaxLength(25);
                eb.Property(c => c.Breed).HasColumnName("BreedName");
                eb.Property(c => c.Breed).HasDefaultValue("None");
            });

            Validate(modelBuilder.Model);
        }
Пример #19
0
        public virtual void Passes_for_compatible_duplicate_foreignKey_names_within_hierarchy()
        {
            var modelBuilder = new ModelBuilder(TestConventionalSetBuilder.Build());

            modelBuilder.Entity <Animal>();
            var fk1 = modelBuilder.Entity <Cat>()
                      .HasOne <Person>()
                      .WithMany()
                      .HasForeignKey(c => new { c.Name, c.Breed })
                      .HasPrincipalKey(p => new { p.Name, p.FavoriteBreed })
                      .Metadata;
            var fk2 = modelBuilder.Entity <Dog>()
                      .HasOne <Customer>()
                      .WithMany()
                      .HasForeignKey(c => new { c.Name, c.Breed })
                      .HasPrincipalKey(p => new { p.Name, p.FavoriteBreed })
                      .Metadata;

            Validate(modelBuilder.Model);

            Assert.NotSame(fk1, fk2);
            Assert.Equal(fk1.Relational().Name, fk2.Relational().Name);
        }