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"); }
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"); }
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"); }
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"); }
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"); }
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"); }
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(); }