public void CorrectlyIdentifiesTable()
        {
            var factory = new SelectQueryFactory();
            var query   = factory.ParseQuery("select * from users");

            query.Table.Name.Should().Be("users");
        }
        public void CorrectlyIdentifiesColumns()
        {
            var factory = new SelectQueryFactory();
            var query   = factory.ParseQuery("select col1, col2 from users");

            query.Columns.Count().Should().Be(2);
            query.Columns[0].Name.Should().Be("col1");
            query.Columns[1].Name.Should().Be("col2");
        }
示例#3
0
        public void WhenNoTableIsPresent_ThenFromIsNotGenerated()
        {
            var factory = new SelectQueryFactory();
            var query   = factory.GenerateQuery(new SelectQuery {
                Columns = new [] { new Column {
                                       Name = "12"
                                   } }
            });

            query.Should().Be("SELECT 12");
        }
示例#4
0
        public void WhenAColumnHasAnAlias_ThenTheAliasIsGenerated()
        {
            var factory = new SelectQueryFactory();
            var query   = factory.GenerateQuery(new SelectQuery {
                Columns = new [] { new Column {
                                       Name = "id", Alias = "pk"
                                   } },
                Table = new Table {
                    Name = "User"
                }
            });

            query.Should().Be("SELECT id AS pk FROM User");
        }
示例#5
0
        public void WhenATableIsPresent_ThenItIsGenerated()
        {
            var factory = new SelectQueryFactory();
            var query   = factory.GenerateQuery(new SelectQuery {
                Columns = new [] { new Column {
                                       Name = "name"
                                   } },
                Table = new Table {
                    Name = "User"
                }
            });

            query.Should().Be("SELECT name FROM User");
        }
示例#6
0
        public void WhenAColumnHasATableDefined_TheNameOfTheTableIsUsed()
        {
            var factory = new SelectQueryFactory();
            var query   = factory.GenerateQuery(new SelectQuery {
                Columns = new [] { new Column {
                                       Name = "id", Table = new Table {
                                           Name = "User"
                                       }
                                   } },
                Table = new Table {
                    Name = "User"
                }
            });

            query.Should().Be("SELECT User.id FROM User");
        }
示例#7
0
        public void WhenAColumnHasATableDefinedWithAnAlias_ThenTheNameOfTheTableAliasIsUsed()
        {
            var factory = new SelectQueryFactory();
            var query   = factory.GenerateQuery(new SelectQuery {
                Columns = new [] { new Column {
                                       Name = "id", Table = new Table {
                                           Name = "User", Alias = "u"
                                       }
                                   } },
                Table = new Table {
                    Name = "User", Alias = "u"
                }
            });

            query.Should().Be("SELECT u.id FROM User AS u");
        }
示例#8
0
        public void WhenMultipleColumnsArePresent_ThenEachIsGenerated()
        {
            var factory = new SelectQueryFactory();
            var query   = factory.GenerateQuery(new SelectQuery {
                Columns = new [] {
                    new Column {
                        Name = "id"
                    },
                    new Column {
                        Name = "lastname"
                    }
                },
                Table = new Table {
                    Name = "User"
                }
            });

            query.Should().Be("SELECT id, lastname FROM User");
        }
        public void CanParseSqlThatBeginsWithSelect()
        {
            var factory = new SelectQueryFactory();

            factory.CanParseQuery("select 1").Should().BeTrue();
        }