Ejemplo n.º 1
0
        public SprocTests() : base()
        {
            var tableName = "Game";

            db.Execute(
                new Table(tableName)
                .AddColumn("Id", SqlType.Int, Syntax.Identity(1, 1))
                .AddColumn("Title", SqlType.VarChar(100), Syntax.NotNull)
                .AddColumn("Html", SqlType.VarCharMax, Syntax.NotNull)
                .AddColumn("DateCreated", SqlType.DateTime, Syntax.NotNull)
                .End().Sql
                );

            var admin = new AdminDb(db);

            admin.ExecuteRaw($@"DROP PROCEDURE IF EXISTS GetGames");
            admin.ExecuteRaw($"CREATE PROCEDURE GetGames AS SELECT * FROM {tableName}");

            admin.ExecuteRaw($@"DROP PROCEDURE IF EXISTS GetGamesByDateCreated");
            admin.ExecuteRaw($@"CREATE PROCEDURE GetGamesByDateCreated(@DateCreated DATETIME) AS 
                SELECT * FROM {tableName} WHERE DateCreated > @DateCreated");

            admin.ExecuteRaw($@"DROP PROCEDURE IF EXISTS GetGameById");
            admin.ExecuteRaw(
                $@"CREATE PROCEDURE GetGameById(@Id INT) AS BEGIN
                    SELECT * FROM {tableName} WHERE Id = @Id
                END");

            db.Insert(new Game()
            {
                Title = "A", Html = "B"
            });
        }