public void Select_TypeThatIsNotATable_AllFieldsFromProperties_JoinOnStringOrderByString_List() { var newPoco = new TestPoco { Name = "Name" }; connection.Save(newPoco); var newMany = new TestManyPoco { Toto = "Toto", Poco = newPoco }; connection.Save(newMany); var newMany2 = new TestManyPoco { Toto = "Tutu", Poco = newPoco }; connection.Save(newMany2); connection.Cache.Clear(); var manies = connection.Select <TestNotATable>().All(x => x.Poco).All(x => x.Many).From(x => x.Poco) .LeftJoin(x => x.Many).On(x => x.Many.Poco == x.Poco).AndOn(x => x.Many.Toto == "Titi").OrderBy(x => x.Poco.Name).ToList(); Assert.Equal(1, manies.Count); Assert.Equal(newPoco.Name, manies[0].Poco.Name); Assert.Equal(null, manies[0].Many); }
public void Load_WithAutoJoin() { var onePoco = new TestPoco { Name = "One" }; connection.Save(onePoco); var twoPoco = new TestPoco { Name = "Two" }; connection.Save(twoPoco); var three = new TestManyPoco { Toto = "Three", Poco = onePoco }; connection.Save(three); var all = new TestMultiPoco { Name = "All", One = onePoco, Three = three, Two = twoPoco }; connection.Save(all); connection.Cache.Clear(); var multi = connection.Load <TestMultiPoco>(all.Id, x => x.One, x => x.Two, x => x.Three); Assert.Equal(all.Name, multi.Name); Assert.Equal(onePoco.Name, multi.One.Name); Assert.Equal(twoPoco.Name, multi.Two.Name); Assert.Equal(three.Toto, multi.Three.Toto); }
public void Select_TableType_InnerJoinOnId_List() { var newPoco = new TestPoco { Name = "Name" }; connection.Save(newPoco); var newMany = new TestManyPoco { Toto = "Toto", Poco = newPoco }; connection.Save(newMany); var otherMany = new TestManyPoco { Toto = "OtherToto" }; connection.Save(otherMany); var pocos = connection.Select <TestManyPoco>() .All() .All(x => x.Poco) .From() .InnerJoin(x => x.Poco).OnId(x => x.Poco).ToList(); Assert.Equal(1, pocos.Count); Assert.Equal(newPoco.Name, pocos[0].Poco.Name); Assert.Equal(newMany.Toto, pocos[0].Toto); }
public void Select_Tuple_FromRightJoin_List() { var newPoco = new TestPoco { Name = "Name" }; connection.Save(newPoco); var newMany = new TestManyPoco { Toto = "Toto", Poco = newPoco }; connection.Save(newMany); var otherMany = new TestManyPoco { Toto = "OtherToto", Poco = newPoco }; connection.Save(otherMany); var pocos = connection.Select <FolkeTuple <TestPoco, TestManyPoco> >() .All(x => x.Item0) .All(x => x.Item1) .From(x => x.Item0) .RightJoin(x => x.Item1) .On(x => x.Item1.Poco == x.Item0) .ToList(); Assert.Equal(2, pocos.Count); Assert.Equal(newPoco.Name, pocos[0].Item0.Name); Assert.Equal(newMany.Toto, pocos[0].Item1.Toto); Assert.Equal(newPoco, pocos[0].Item1.Poco); Assert.Equal(newPoco.Name, pocos[1].Item0.Name); Assert.Equal(otherMany.Toto, pocos[1].Item1.Toto); Assert.Equal(newPoco, pocos[1].Item1.Poco); }
public void Select_Tuple_FromLeftJoinOnId_List() { var newPoco = new TestPoco { Name = "Name" }; connection.Save(newPoco); var newMany = new TestManyPoco { Toto = "Toto", Poco = newPoco }; connection.Save(newMany); var pocos = connection.Select <FolkeTuple <TestPoco, TestManyPoco> >() .All(x => x.Item0) .All(x => x.Item1) .From(x => x.Item0) .LeftJoin(x => x.Item1).On(x => x.Item1.Poco == x.Item0).ToList(); Assert.Equal(1, pocos.Count); Assert.NotNull(pocos[0].Item0); Assert.Equal(newPoco.Name, pocos[0].Item0.Name); Assert.Equal(newMany.Toto, pocos[0].Item1.Toto); Assert.Equal(newPoco, pocos[0].Item1.Poco); }
public void Save() { var newPoco = new TestPoco { Name = "Tutu " }; connection.Save(newPoco); Assert.NotEqual(0, newPoco.Id); }
public void SelectAllFrom_TableType_WhereStringIsNull_Single() { var newPoco = new TestPoco { Name = null }; connection.Save(newPoco); var foundPoco = connection.SelectAllFrom <TestPoco>().Single(t => t.Name == null); Assert.Equal(newPoco.Id, foundPoco.Id); }
public void SelectAllFrom_TableType_WhereStringEqual_Single() { var newPoco = new TestPoco { Name = "Tutu " }; connection.Save(newPoco); var foundPoco = connection.SelectAllFrom <TestPoco>().Single(t => t.Name == newPoco.Name); Assert.NotNull(foundPoco); Assert.Equal(newPoco.Name, foundPoco.Name); }
public void Select_TableType_ValuesTwoColumns_List() { var newPoco = new TestPoco { Name = "Ihihi" }; connection.Save(newPoco); connection.Cache.Clear(); var poco = connection.Select <TestPoco>().Values(x => x.Id, x => x.Name).From().ToList(); Assert.Equal(newPoco.Id, poco[0].Id); Assert.Equal(newPoco.Name, poco[0].Name); }
public void SelectAllFrom_TableType_WhereWithQuote_SingleOrDefault() { var newPoco = new TestPoco { Name = Guid.NewGuid().ToString() + "'azer'ty" }; connection.Save(newPoco); var result = connection.SelectAllFrom <TestPoco>().Where(x => x.Name == newPoco.Name).SingleOrDefault(); Assert.NotNull(result); Assert.Equal(newPoco.Name, result.Name); }
public void SelectFrom_TableType_OrderByStringDescLimit_List() { for (var i = 0; i < 10; i++) { var newPoco = new TestPoco { Name = "Name" + i }; connection.Save(newPoco); } var pocos = connection.SelectAllFrom <TestPoco>().OrderBy(x => x.Name).Desc().Limit(1, 2).ToList(); Assert.Equal(2, pocos.Count); Assert.Equal("Name8", pocos[0].Name); Assert.Equal("Name7", pocos[1].Name); }
public void Update_Set() { // Arrange var newPoco = new TestPoco { Name = "Name" }; connection.Save(newPoco); // Act connection.Update <TestPoco>().Set(x => x.Name, x => "Test").Execute(); // Assert var result = connection.Load <TestPoco>(newPoco.Id); Assert.Equal("Test", result.Name); }
public void Select_CountAll_Scalar() { // Arrange for (var i = 0; i < 10; i++) { var newPoco = new TestPoco { Name = "Name" + i }; connection.Save(newPoco); } // Act var result = connection.Select <TestPoco>().CountAll().From().Scalar <int>(); // Assert Assert.Equal(10, result); }
public void SelectAllFrom_TableType_WhereObject_ReturnedItemsHaveReferenceToCachedItem_List() { var newPoco = new TestPoco { Name = null }; connection.Save(newPoco); var newMany = new TestManyPoco { Toto = "Toto", Poco = newPoco }; connection.Save(newMany); var manies = connection.SelectAllFrom <TestManyPoco>().Where(t => t.Poco == newPoco).ToList(); Assert.Equal(1, manies.Count); Assert.Equal(newPoco, manies[0].Poco); }
public void SelectAllFrom_TableType_WhereLike_List() { var onePoco = new TestPoco { Name = "One" }; connection.Save(onePoco); var twoPoco = new TestPoco { Name = "Two" }; connection.Save(twoPoco); var result = connection.SelectAllFrom <TestPoco>().Where(x => x.Name.Like("On%")).ToList(); Assert.Equal(1, result.Count); Assert.Equal("One", result[0].Name); }
public void SelectAllFrom_TableType_OrderByAscLimitWithVariable_List() { // Arrange for (var i = 0; i < 10; i++) { var newPoco = new TestPoco { Name = "Name" + i }; connection.Save(newPoco); } // Act var results = connection.SelectAllFrom <TestPoco>().OrderBy(x => x.Name).Asc().Limit(x => 5, 5).ToList(); // Assert Assert.Equal(5, results.Count); Assert.Equal("Name5", results[0].Name); }
public void SelectAllFrom_Linq_WhereStringSelectAll_List() { var newPoco = new TestPoco { Name = Guid.NewGuid().ToString() }; connection.Save(newPoco); var otherPoco = new TestPoco { Name = Guid.NewGuid().ToString() }; connection.Save(otherPoco); var query = from toto in connection.SelectAllFrom <TestPoco>() where toto.Name == newPoco.Name select toto; var result = query.ToList(); Assert.Equal(1, result.Count); Assert.Equal(newPoco.Name, result[0].Name); }
public void Select_OneColumnAndIdInTableWithForeignKeys_List() { var newPoco = new TestPoco { Name = "Name" }; connection.Save(newPoco); var newMany = new TestManyPoco { Toto = "Toto", Poco = newPoco }; connection.Save(newMany); connection.Cache.Clear(); var response = connection.Select <TestManyPoco>().Values(x => x.Id).Values(x => x.Toto).From().ToList(); Assert.Equal(newMany.Toto, response[0].Toto); }
public void Select_TypeThatIsNotATable_AllFieldsFromProperties_List() { var newPoco = new TestPoco { Name = "Name" }; connection.Save(newPoco); var newMany = new TestManyPoco { Toto = "Toto", Poco = newPoco }; connection.Save(newMany); var manies = connection.Select <TestNotATable>().All(x => x.Poco).All(x => x.Many).From(x => x.Many) .LeftJoin(x => x.Poco).On(x => x.Many.Poco == x.Poco).ToList(); Assert.Equal(newPoco.Name, manies[0].Poco.Name); Assert.Equal(newMany.Toto, manies[0].Many.Toto); }
public void Select_TableType_LeftJoinOnIdWhereString_List() { var newPoco = new TestPoco { Name = "Name" }; connection.Save(newPoco); var newMany = new TestManyPoco { Toto = "Toto", Poco = newPoco }; connection.Save(newMany); connection.Cache.Clear(); var manies = connection.Select <TestManyPoco>().All().All(x => x.Poco).From().LeftJoinOnId(x => x.Poco).Where(t => t.Toto == "Toto").ToList(); Assert.Equal(1, manies.Count); Assert.Equal(newPoco.Id, manies[0].Poco.Id); Assert.Equal(newPoco.Name, manies[0].Poco.Name); }
public void SelectAllFrom_TableTypeAndAutoJoin_WhereString_List() { var newPoco = new TestPoco { Name = "Name" }; connection.Save(newPoco); var newMany = new TestManyPoco { Toto = "Toto", Poco = newPoco }; connection.Save(newMany); connection.Cache.Clear(); var manies = connection.SelectAllFrom <TestManyPoco>(t => t.Poco).Where(t => t.Toto == "Toto").ToList(); Assert.Equal(1, manies.Count); Assert.Equal(newPoco.Id, manies[0].Poco.Id); Assert.Equal(newPoco.Name, manies[0].Poco.Name); }
public void SelectAllFrom_LimitWithParameter_List() { // Arrange for (var i = 0; i < 10; i++) { var newPoco = new TestPoco { Name = "Name" + i }; connection.Save(newPoco); } // Act var results = FluentBaseBuilder <TestPoco, FolkeTuple <int> > .Select(connection.Driver, connection.Mapper).All() .From() .OrderBy(x => x.Name) .Limit((x, y) => y.Item0, 5).Build(connection, 5).ToList(); // Assert Assert.Equal(5, results.Count); Assert.Equal("Name5", results[0].Name); }
public void PreparedQueryBuilder_Static_AllFromWhereString_List() { var onePoco = new TestPoco { Name = "One" }; connection.Save(onePoco); var twoPoco = new TestPoco { Name = "Two" }; connection.Save(twoPoco); var result = staticQuery.Build(connection, "Two").ToList(); Assert.Equal(1, result.Count); Assert.Equal("Two", result[0].Name); result = staticQuery.Build(connection, "One").ToList(); Assert.Equal(1, result.Count); Assert.Equal("One", result[0].Name); }
public void PreparedQueryBuilder_AllFromWhereString_List() { var onePoco = new TestPoco { Name = "One" }; connection.Save(onePoco); var twoPoco = new TestPoco { Name = "Two" }; connection.Save(twoPoco); var query = new PreparedQueryBuilder <TestPoco, string>(q => q.All().From().Where((x, y) => x.Name == y.Item0)); var result = query.Build(connection, "Two").ToList(); Assert.Equal(1, result.Count); Assert.Equal("Two", result[0].Name); result = query.Build(connection, "One").ToList(); Assert.Equal(1, result.Count); Assert.Equal("One", result[0].Name); }
public void SelectAllFrom_TableType_WhereBooleanEqual_List() { var newPocoFalse = new TestPoco { Name = "Hihi" }; connection.Save(newPocoFalse); var newPocoTrue = new TestPoco { Name = "Huhu", Boolean = true }; connection.Save(newPocoTrue); var foundTrue = connection.SelectAllFrom <TestPoco>().Where(t => t.Boolean).ToList(); Assert.Equal(1, foundTrue.Count); Assert.Equal(newPocoTrue.Name, foundTrue[0].Name); var foundFalse = connection.SelectAllFrom <TestPoco>().Where(t => !t.Boolean).ToList(); Assert.Equal(1, foundFalse.Count); Assert.Equal(newPocoFalse.Name, foundFalse[0].Name); }
public void Select_Tuple_WhereExistsSubQuery_List() { var newPoco = new TestPoco { Name = "Name" }; connection.Save(newPoco); var newMany = new TestManyPoco { Toto = "Toto", Poco = newPoco }; connection.Save(newMany); var otherPoco = new TestPoco { Name = "OtherName" }; connection.Save(otherPoco); var pocos = connection.Select <FolkeTuple <TestPoco, TestManyPoco> >().All(x => x.Item0).From(x => x.Item0) .WhereExists(sub => sub.All(x => x.Item1).From(x => x.Item1).Where(x => x.Item1.Poco == x.Item0)).ToList(); Assert.Equal(1, pocos.Count); Assert.Equal(newPoco.Name, pocos[0].Item0.Name); }