public async Task PostgresqlRecordCountScriptTest_Success()
        {
            var generator = new PostgresqlTestGenerator(options =>
            {
                options.AddDatabaseRecordsCountRule(
                new List<RecordCountRule>()
                {
                    new RecordCountRule()
                    {
                        TableName = "mytable",
                        Operator = "=",
                        Count = 100
                    }
                });
            });

            var results = new List<Models.Test>
            {
                new Models.Test(
                        "mytable",
                        $@"SELECT EXISTS (SELECT * FROM ""mytable"" WHERE (SELECT COUNT(*) AS ""count"" FROM ""mytable"") = 100);",
                        TestType.RecordCount,
                        DatabaseKind.PostgreSql)
            }.ToExpectedObject();

            results.ShouldEqual(await generator.Generate());
            Assert.Equal(DatabaseKind.PostgreSql, generator.DatabaseKind);
        }
        public async Task PostgresqlRecordExistScriptTest_Success()
        {
            var generator = new PostgresqlTestGenerator(options =>
            {
                options.AddDatabaseRecordExitsRule(
                new List<RecordExistRule>()
                {
                    new RecordExistRule()
                    {
                        TableName = "mytable",
                        ColumnName = "name",
                        Operator = "=",
                        Value = "myname"
                    }
                });
            });

            var results = new List<Models.Test>
            {
                new Models.Test(
                        "mytable",
                        $@"SELECT EXISTS(SELECT * FROM ""mytable"" WHERE ""name"" = 'myname');",
                        TestType.RecordExist,
                        DatabaseKind.PostgreSql)
            }.ToExpectedObject();

            results.ShouldEqual(await generator.Generate());
            Assert.Equal(DatabaseKind.PostgreSql, generator.DatabaseKind);
        }
コード例 #3
0
        public async Task PostgresqlCreateRunnerTest_Success()
        {
            var generator = new PostgresqlTestGenerator(options =>
            {
                options.AddDatabaseObjectExitsRule(new string[] { "mytable" }, DatabaseObjectType.Table);
            });

            var script = await generator.Generate();

            var options = Substitute.For <Action <TestRunnerOptions> >();
            var runner  = Substitute.For <PostgresqlTestRunnerFactory>(script, options);

            Assert.NotNull(runner);
        }
        public async Task PostgresqlStoredProcedureExistScriptTest_Success()
        {
            var generator = new PostgresqlTestGenerator(options =>
            {
                options.AddDatabaseObjectExitsRule(new string[] { "mystoredprocedure" }, DatabaseObjectType.StoredProcedure);
            });

            var results = new List<Models.Test>
            {
                new Models.Test(
                        "mystoredprocedure",
                        $@"SELECT EXISTS(SELECT * FROM ""information_schema"".""routines"" WHERE ""routine_name"" = 'mystoredprocedure');",
                        TestType.ObjectExist,
                        DatabaseKind.PostgreSql)
            }.ToExpectedObject();

            results.ShouldEqual(await generator.Generate());
            Assert.Equal(DatabaseKind.PostgreSql, generator.DatabaseKind);
        }
        public async Task PostgresqlCustomScriptTest_Success()
        {
            var generator = new PostgresqlTestGenerator(options =>
            {
                options.AddCustomSqlRule(
                new List<string>()
                {
                    @"SELECT * FROM ""mytable"" WHERE (SELECT COUNT(*) AS ""count"" FROM ""mytable"") = 10"
                });
            });

            var results = new List<Models.Test>
            {
                new Models.Test(
                        null,
                        $@"SELECT EXISTS(SELECT * FROM ""mytable"" WHERE (SELECT COUNT(*) AS ""count"" FROM ""mytable"") = 10);",
                        TestType.CustomScript,
                        DatabaseKind.PostgreSql)
            }.ToExpectedObject();

            results.ShouldEqual(await generator.Generate());
            Assert.Equal(DatabaseKind.PostgreSql, generator.DatabaseKind);
        }
        public async Task PostgresqlMultipleTableExistScriptTest_Success()
        {
            var generator = new PostgresqlTestGenerator(options =>
            {
                options.AddDatabaseObjectExitsRule(new string[] { "table1", "table2" }, DatabaseObjectType.Table);
            });

            var results = new List<Models.Test>
            {
               new Models.Test(
                        "table1",
                        $@"SELECT EXISTS(SELECT * FROM ""information_schema"".""tables"" WHERE ""table_name"" = 'table1');",
                        TestType.ObjectExist,
                        DatabaseKind.PostgreSql),
               new Models.Test(
                        "table2",
                        $@"SELECT EXISTS(SELECT * FROM ""information_schema"".""tables"" WHERE ""table_name"" = 'table2');",
                        TestType.ObjectExist,
                        DatabaseKind.PostgreSql)
            }.ToExpectedObject();

            results.ShouldEqual(await generator.Generate());
            Assert.Equal(DatabaseKind.PostgreSql, generator.DatabaseKind);
        }