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

            var results = new List <Models.Test>
            {
                new Models.Test(
                    "mytable",
                    $@"IF EXISTS (SELECT * FROM [mytable] WHERE (SELECT COUNT(*) AS [count] FROM [mytable]) = 100) BEGIN Select 1 END ELSE BEGIN Select 0 END;",
                    TestType.RecordCount,
                    DatabaseKind.SqlServer)
            }.ToExpectedObject();

            results.ShouldEqual(await generator.Generate());
            Assert.Equal(DatabaseKind.SqlServer, generator.DatabaseKind);
        }
        public async Task SqlServerRecordExistScriptTest_Success()
        {
            var generator = new SqlServerTestGenerator(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",
                    $@"IF EXISTS (SELECT * FROM [mytable] WHERE [name] = 'myname') BEGIN Select 1 END ELSE BEGIN Select 0 END;",
                    TestType.RecordExist,
                    DatabaseKind.SqlServer)
            }.ToExpectedObject();

            results.ShouldEqual(await generator.Generate());
            Assert.Equal(DatabaseKind.SqlServer, generator.DatabaseKind);
        }
        public async Task MysqlCreateRunnerTest_Success()
        {
            var generator = new SqlServerTestGenerator(options =>
            {
                options.AddDatabaseObjectExitsRule(new string[] { "mytable" }, DatabaseObjectType.Table);
            });

            var script = await generator.Generate();

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

            Assert.NotNull(runner);
        }
        public async Task SqlServerViewExistScriptTest_Success()
        {
            var generator = new SqlServerTestGenerator(options =>
            {
                options.AddDatabaseObjectExitsRule(new string[] { "myview" }, DatabaseObjectType.View);
            });

            var results = new List <Models.Test>
            {
                new Models.Test(
                    "myview",
                    $@"IF EXISTS (SELECT * FROM [sys].[views] WHERE [Name] = 'myview') BEGIN Select 1 END ELSE BEGIN Select 0 END;",
                    TestType.ObjectExist,
                    DatabaseKind.SqlServer)
            }.ToExpectedObject();

            results.ShouldEqual(await generator.Generate());
            Assert.Equal(DatabaseKind.SqlServer, generator.DatabaseKind);
        }
        public async Task SqlServerCustomScriptTest_Success()
        {
            var generator = new SqlServerTestGenerator(options =>
            {
                options.AddCustomSqlRule(
                    new List <string>()
                {
                    "SELECT * FROM [mytable] WHERE (SELECT COUNT(*) AS [count] FROM [mytable]) = 50"
                });
            });

            var results = new List <Models.Test>
            {
                new Models.Test(
                    null,
                    $@"IF EXISTS (SELECT * FROM [mytable] WHERE (SELECT COUNT(*) AS [count] FROM [mytable]) = 50) BEGIN Select 1 END ELSE BEGIN Select 0 END;",
                    TestType.CustomScript,
                    DatabaseKind.SqlServer)
            }.ToExpectedObject();

            results.ShouldEqual(await generator.Generate());
            Assert.Equal(DatabaseKind.SqlServer, generator.DatabaseKind);
        }
        public async Task SqlServerQueryStatisticsScriptWithIOTest_Success()
        {
            var generator = new SqlServerTestGenerator(options =>
            {
                options.CaptureQueryStatistics(
                    new[]
                {
                    "SELECT * FROM [mytable] WHERE (SELECT COUNT(*) AS [count] FROM [mytable]) = 50"
                },
                    new QueryStatisticsType[] { QueryStatisticsType.Io });
            });

            var results = new List <Models.Test>
            {
                new Models.Test(
                    null,
                    $@"SET STATISTICS IO ON;SELECT * FROM [mytable] WHERE (SELECT COUNT(*) AS [count] FROM [mytable]) = 50;SET STATISTICS IO OFF;",
                    TestType.QueryStatistics,
                    DatabaseKind.SqlServer)
            }.ToExpectedObject();

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