Ejemplo n.º 1
0
        public void QueryExprParse()
        {
            var result = _parser.DataQueryParse(@"Tasks
order #a# asc,#b# desc,#c# asc
group #aa#,#bb#,#cc#
select
alpha = #beta#
#gamma#
theta = #eta.sigma.pi#
#x.y.z#
select end
skip 1
take 2
table Id");

            result.Should().NotBeNull();

            result.Blocks.Should().NotBeNull();

            var order = result.Blocks.First() as DslOrderBlock;

            order.Should().NotBeNull();

            order.Should().NotBeNull();
            order.Items.Should().HaveCount(3);
            order.Items[0].OrderFieldName.Should().Be("a");
            order.Items[0].SortOrder.Should().Be(SortOrder.Ascending);

            order.Items[1].OrderFieldName.Should().Be("b");
            order.Items[1].SortOrder.Should().Be(SortOrder.Descending);

            order.Items[2].OrderFieldName.Should().Be("c");
            order.Items[2].SortOrder.Should().Be(SortOrder.Ascending);

            var groupBlock = result.Blocks.Skip(1).First() as DslGroupBlock;

            groupBlock.Should().NotBeNull();

            groupBlock.Items.Should().NotBeNullOrEmpty();
            groupBlock.Items.Select(_ => _.VariableName).Should().BeEquivalentTo("aa", "bb", "cc");

            var select = result.Blocks.Skip(2).First() as DslFormatBlock;

            select.Should().NotBeNull();

            select.Should().NotBeNull();
            select.Selects.Should().NotBeNullOrEmpty();
            select.Selects.Should().HaveCount(4);
            var first = select.Selects.First();

            first.Name.Should().Be("alpha");
            first.Value.Should().Be("#beta#");

            var second = select.Selects.Skip(1).First();

            second.Name.Should().BeNull();
            second.Value.Should().Be("#gamma#");

            var third = select.Selects.Skip(2).First();

            third.Name.Should().Be("theta");
            third.Value.Should().Be("#eta.sigma.pi#");

            var fourth = select.Selects.Skip(3).First();

            fourth.Name.Should().BeNull();
            fourth.Value.Should().Be("#x.y.z#");

            var skipLimit = result.Blocks.Skip(3).First() as DslLimitBlock;

            skipLimit.Should().NotBeNull();

            skipLimit.Skip.ShouldBeEquivalentTo(1);

            var takeLimit = result.Blocks.Skip(4).First() as DslLimitBlock;

            takeLimit.Should().NotBeNull();

            takeLimit.Take.ShouldBeEquivalentTo(2);

            result.TableKey.Should().Be("Id");
        }