Esempio n. 1
0
        public void GenerateFluentApi_IIndex_works_when_clustered(bool obsolete)
        {
            var generator    = new MySqlAnnotationCodeGenerator(new AnnotationCodeGeneratorDependencies());
            var modelBuilder = new ModelBuilder(MySqlConventionSetBuilder.Build());

            modelBuilder.Entity(
                "Post",
                x =>
            {
                x.Property <int>("Id");
                x.Property <string>("Name");
                if (obsolete)
                {
#pragma warning disable 618
                    x.HasIndex("Name").ForMySqlIsClustered();
#pragma warning restore 618
                }
                else
                {
                    x.HasIndex("Name").IsClustered();
                }
            });
            var index      = modelBuilder.Model.FindEntityType("Post").GetIndexes().Single();
            var annotation = index.FindAnnotation(MySqlAnnotationNames.Clustered);

            var result = generator.GenerateFluentApi(index, annotation);

            Assert.Equal("IsClustered", result.Method);

            Assert.Equal(0, result.Arguments.Count);
        }
Esempio n. 2
0
        public void GenerateFluentApi_IKey_works_when_nonclustered(bool obsolete)
        {
            var generator    = new MySqlAnnotationCodeGenerator(new AnnotationCodeGeneratorDependencies());
            var modelBuilder = new ModelBuilder(MySqlConventionSetBuilder.Build());

            modelBuilder.Entity(
                "Post",
                x =>
            {
                x.Property <int>("Id");

                if (obsolete)
                {
#pragma warning disable 618
                    x.HasKey("Id").ForMySqlIsClustered(false);
#pragma warning restore 618
                }
                else
                {
                    x.HasKey("Id").IsClustered(false);
                }
            });
            var key        = modelBuilder.Model.FindEntityType("Post").GetKeys().Single();
            var annotation = key.FindAnnotation(MySqlAnnotationNames.Clustered);

            var result = generator.GenerateFluentApi(key, annotation);

            Assert.Equal("IsClustered", result.Method);

            Assert.Equal(1, result.Arguments.Count);
            Assert.Equal(false, result.Arguments[0]);
        }
Esempio n. 3
0
        public void GenerateFluentApi_IIndex_works_with_includes(bool obsolete)
        {
            var generator    = new MySqlAnnotationCodeGenerator(new AnnotationCodeGeneratorDependencies());
            var modelBuilder = new ModelBuilder(MySqlConventionSetBuilder.Build());

            modelBuilder.Entity(
                "Post",
                x =>
            {
                x.Property <int>("Id");
                x.Property <string>("FirstName");
                x.Property <string>("LastName");
                if (obsolete)
                {
#pragma warning disable 618
                    x.HasIndex("LastName").ForMySqlInclude("FirstName");
#pragma warning restore 618
                }
                else
                {
                    x.HasIndex("LastName").IncludeProperties("FirstName");
                }
            });
            var index      = modelBuilder.Model.FindEntityType("Post").GetIndexes().Single();
            var annotation = index.FindAnnotation(MySqlAnnotationNames.Include);

            var result = generator.GenerateFluentApi(index, annotation);

            Assert.Equal("IncludeProperties", result.Method);

            Assert.Equal(1, result.Arguments.Count);
            var properties = Assert.IsType <string[]>(result.Arguments[0]);
            Assert.Equal(new[] { "FirstName" }, properties.AsEnumerable());
        }
        public void GenerateFluentApi_IKey_works_when_clustered()
        {
            var generator    = new MySqlAnnotationCodeGenerator(new AnnotationCodeGeneratorDependencies());
            var modelBuilder = new ModelBuilder(MySqlConventionSetBuilder.Build());

            modelBuilder.Entity(
                "Post",
                x =>
            {
                x.Property <int>("Id");
                x.HasKey("Id").ForMySqlIsClustered();
            });
            var key        = modelBuilder.Model.FindEntityType("Post").GetKeys().Single();
            var annotation = key.FindAnnotation(MySqlAnnotationNames.Clustered);

            var result = generator.GenerateFluentApi(key, annotation);

            Assert.Equal("ForMySqlIsClustered", result.Method);

            Assert.Equal(0, result.Arguments.Count);
        }
        public void GenerateFluentApi_IIndex_works_when_nonclustered()
        {
            var generator    = new MySqlAnnotationCodeGenerator(new AnnotationCodeGeneratorDependencies());
            var modelBuilder = new ModelBuilder(MySqlConventionSetBuilder.Build());

            modelBuilder.Entity(
                "Post",
                x =>
            {
                x.Property <int>("Id");
                x.Property <string>("Name");
                x.HasIndex("Name").ForMySqlIsClustered(false);
            });
            var index      = modelBuilder.Model.FindEntityType("Post").GetIndexes().Single();
            var annotation = index.FindAnnotation(MySqlAnnotationNames.Clustered);

            var result = generator.GenerateFluentApi(index, annotation);

            Assert.Equal("ForMySqlIsClustered", result.Method);

            Assert.Equal(1, result.Arguments.Count);
            Assert.Equal(false, result.Arguments[0]);
        }