public void OneTypeWithContainsOnWhere() { var testList = new List <string>() { "AA", "BB", "CC" }; var generatedSql = QueryFactory.AsMySqlQuery <Customer>().Select(c => new { c.Id, c.FirstName, c.MiddleInitial, c.LastName, c.DateofBirth, c.SSN }) .Where(c => testList.Contains(c.FirstName) && c.LastName == "BB") .ToString(); var expectedSql = AsSqlString( "SELECT `customers`.`Id`, `customers`.`FirstName`, `customers`.`MiddleInitial`, `customers`.`LastName`, `customers`.`DateofBirth`, `customers`.`SSN`", "FROM `customers`", "WHERE `customers`.`FirstName` IN (`AA`, `BB`, `CC`) AND `customers`.`LastName`=`BB`"); generatedSql.ShouldBe(expectedSql); }
public void SelectStarWithoutWhere() { var generatedSql = QueryFactory.AsMySqlQuery <Customer>().Select().ToString(); var expectedSql = AsSqlString( "SELECT *", "FROM `customers`", ""); generatedSql.ShouldBe(expectedSql); }
public void JoinClauseWithoutWhere() { var generatedSql = QueryFactory .AsMySqlQuery <Customer, CustomerOrders>() .Select() .InnerJoin((c, o) => c.Id == o.CustomerId) .ToString(); var expectedSql = AsSqlString( "SELECT *", "FROM `customers`", new List <string>() { "INNER JOIN `customerorders` ON `customers`.`Id`=`customerorders`.`CustomerId`" }, ""); generatedSql.ShouldBe(expectedSql); }
public void OneTypeWithoutWhere() { var generatedSql = QueryFactory.AsMySqlQuery <Customer>().Select(c => new { c.Id, c.FirstName, c.MiddleInitial, c.LastName, c.DateofBirth, c.SSN }) .ToString(); var expectedSql = AsSqlString( "SELECT `customers`.`Id`, `customers`.`FirstName`, `customers`.`MiddleInitial`, `customers`.`LastName`, `customers`.`DateofBirth`, `customers`.`SSN`", "FROM `customers`", ""); generatedSql.ShouldBe(expectedSql); }
public void SelectClauseWithThreeEntity() { var generatedSql = QueryFactory .AsMySqlQuery <Customer, CustomerOrders, CustomerAddress>() .Select((customer, orders, address) => new { customer.Id, customer.FirstName, orders.OrderDate, address.AddressState }) .ToString(); var expectedSql = AsSqlString( "SELECT `customers`.`Id`, `customers`.`FirstName`, `customerorders`.`OrderDate`, `customeraddresses`.`AddressState`", "FROM `customers`, `customerorders`, `customeraddresses`", ""); generatedSql.ShouldBe(expectedSql); }
public void JoinClauseWithWhere() { var generatedSql = QueryFactory .AsMySqlQuery <Customer, CustomerOrders>() .Select() .InnerJoin((c, o) => c.Id == o.CustomerId) .Where((c, o) => c.MiddleInitial == "A") .ToString(); var expectedSql = AsSqlString( "SELECT *", "FROM `customers`", new List <string>() { "INNER JOIN `customerorders` ON `customers`.`Id`=`customerorders`.`CustomerId`" }, "WHERE `customers`.`MiddleInitial`=`A`"); //Assert.AreEqual(generatedSql, expectedSql); generatedSql.ShouldBe(expectedSql); }
public void OneTypeWithWhereWithVariable() { var testVar = "AA"; var generatedSql = QueryFactory.AsMySqlQuery <Customer>().Select(c => new { c.Id, c.FirstName, c.MiddleInitial, c.LastName, c.DateofBirth, c.SSN }) .Where(c => c.FirstName == testVar && c.LastName == "BB") .ToString(); var expectedSql = AsSqlString( "SELECT `customers`.`Id`, `customers`.`FirstName`, `customers`.`MiddleInitial`, `customers`.`LastName`, `customers`.`DateofBirth`, `customers`.`SSN`", "FROM `customers`", "WHERE `customers`.`FirstName`=`AA` AND `customers`.`LastName`=`BB`"); generatedSql.ShouldBe(expectedSql); }
public void ToStringWithoutSelectException() { var expected = QueryFactory.AsMySqlQuery <Customer>(); Should.Throw <InvalidOperationException>(() => expected.ToString()); }