示例#1
0
        public void ShouldAcceptParseBlocks_WhenCreating_GivenValidRules()
        {
            GivenParser.WithRule("pre", text => new SqlCommandBlock("pre", text, SqlScriptPhase.Pre));

            When(Creating);

            Then.Parser.RegisteredKeywords().Should().HaveCount(1);
            Then.Parser.RegisteredKeywords().First().Should().Be("pre");
        }
示例#2
0
        public void ShouldProcessFallbackRule_WhenProcessingUnknownKeywords()
        {
            GivenParser.WithFallbackRule((kw, text) => new UnexpectedBlock(kw, text));
            Given.Text = "--:: unknown\nselect 1\nGO\n";

            When(Parsing);

            Then.SourceScript.ScriptBlocks.Should().HaveCount(1);

            var thenFirstBlock = Then.SourceScript.ScriptBlocks.First();

            thenFirstBlock.Keyword.Should().Be("unknown");
            thenFirstBlock.IsValid.Should().BeFalse();
            thenFirstBlock.Text.Should().Be("select 1\nGO");
        }
示例#3
0
        public void ShouldCreateSourceScript_WhenParsing_GivenValidText()
        {
            GivenParser
            .WithRule("pre", text => new SqlCommandBlock("pre", text, SqlScriptPhase.Pre))
            .WithRule("main", text => new SqlCommandBlock("main", text, SqlScriptPhase.Main))
            .WithRule("post", text => new SqlCommandBlock("post", text, SqlScriptPhase.Post));

            Given.Text = "--:: pre\nselect 1\n--:: main\nselect 2\n--:: post\nselect 3\nGO";

            When(Parsing);

            Then.SourceScript.ScriptBlocks.Should().HaveCount(3);
            Then.SourceScript.ScriptBlocks[2].Keyword.Should().Be("post");
            Then.SourceScript.ScriptBlocks[2].Text.Should().Be("select 3\nGO");
            Then.SourceScript.ScriptBlocks[2].As <ISqlCommandBlock>().Phase.Should().Be(SqlScriptPhase.Post);
        }