public async Task When_searching_for_all_records_in_a_table_not_matching_any_of_the_given_keywords() { using (var conn = new SQLiteInMemoryConnection()) { await Given_a_logTtable_and_an_ftsTable(conn); var logs = new[] { new FTSContext.Log { Level = FTSContext.Level.Debug, Message = "There is a Cat" }, new FTSContext.Log { Level = FTSContext.Level.Info, Message = "There is a Dog" }, new FTSContext.Log { Level = FTSContext.Level.Warn, Message = "There is a Cat and a Dog" }, new FTSContext.Log { Level = FTSContext.Level.Warn, Message = "There is a Parrot" } }; var repo = conn.GetDBContext <FTSContext.Log>(SQLiteDialect.Instance); await repo.Insert(logs); var term = Term <FTSContext.Log> .All .AndNot(Match.Any, l => l.Message, "Cat", "Dog"); var result = (await conn.Search(term)).ToArray(); result.Length.ShouldBe(1); result[0].Level.ShouldBe(logs[3].Level); result[0].Message.ShouldBe(logs[3].Message); } }
public async Task When_searching_for_records_in_a_table_for_all_of_the_supplied_keywords() { using (var conn = new SQLiteInMemoryConnection()) { await Given_a_logTtable_and_an_ftsTable(conn); var logs = new[] { new FTSContext.Log { Level = FTSContext.Level.Debug, Message = "John is playing football" }, new FTSContext.Log { Level = FTSContext.Level.Info, Message = "Mary is playing football" }, new FTSContext.Log { Level = FTSContext.Level.Warn, Message = "Someone is playing football" }, new FTSContext.Log { Level = FTSContext.Level.Warn, Message = "John with Mary are playing football" }, new FTSContext.Log { Level = FTSContext.Level.Warn, Message = "football is awesome" } }; var repo = conn.GetDBContext <FTSContext.Log>(SQLiteDialect.Instance); await repo.Insert(logs); var term = Term <FTSContext.Log> .All.And(Match.All, l => l.Message, "John", "Mary", "football"); var result1 = (await conn.Search(term)).ToArray(); result1.Length.ShouldBe(1); result1[0].Level.ShouldBe(logs[3].Level); result1[0].Message.ShouldBe(logs[3].Message); term.Clear(); term.And(Match.All, l => l.Message, "play*", "football"); var result2 = (await conn.Search(term)).ToArray(); result2.Length.ShouldBe(4); result2[0].Level.ShouldBe(logs[0].Level); result2[0].Message.ShouldBe(logs[0].Message); result2[1].Level.ShouldBe(logs[1].Level); result2[1].Message.ShouldBe(logs[1].Message); result2[2].Level.ShouldBe(logs[2].Level); result2[2].Message.ShouldBe(logs[2].Message); result2[3].Level.ShouldBe(logs[3].Level); result2[3].Message.ShouldBe(logs[3].Message); } }
public async Task When_searching_for_all_records_in_a_table() { using (var conn = new SQLiteInMemoryConnection()) { await Given_a_logTtable_and_an_ftsTable(conn); var logs = new[] { new FTSContext.Log { Level = FTSContext.Level.Debug, Message = "There is a Cat" }, new FTSContext.Log { Level = FTSContext.Level.Debug, Message = "There is a Dog" }, new FTSContext.Log { Level = FTSContext.Level.Debug, Message = "There is a Cat and a Dog" } }; var repo = conn.GetDBContext <FTSContext.Log>(SQLiteDialect.Instance); await repo.Insert(logs); var selectAllTerm = Term <FTSContext.Log> .All; var result = (await conn.Search(selectAllTerm)).ToArray(); result.Length.ShouldBe(3); result[0].Level.ShouldBe(logs[0].Level); result[0].Message.ShouldBe(logs[0].Message); result[1].Level.ShouldBe(logs[1].Level); result[1].Message.ShouldBe(logs[1].Message); result[1].Level.ShouldBe(logs[1].Level); result[1].Message.ShouldBe(logs[1].Message); result[2].Level.ShouldBe(logs[2].Level); result[2].Message.ShouldBe(logs[2].Message); } }
public async Task When_searching_for_all_records_in_a_table_matching_multiple_keywords() { using (var conn = new SQLiteInMemoryConnection()) { await Given_a_logTtable_and_an_ftsTable(conn); var logs = new[] { new FTSContext.Log { Level = FTSContext.Level.Debug, Message = "Linux can be fun" }, new FTSContext.Log { Level = FTSContext.Level.Info, Message = "Windows and linux are two operating systems" }, new FTSContext.Log { Level = FTSContext.Level.Warn, Message = "linux is a Unix like operating system" }, new FTSContext.Log { Level = FTSContext.Level.Fatal, Message = "software development in Mac OS operating system may be fun!" } }; var repo = conn.GetDBContext <FTSContext.Log>(SQLiteDialect.Instance); await repo.Insert(logs); var term = Term <FTSContext.Log> .All; var result = (await conn.Search(term)).ToArray(); result.Length.ShouldBe(4); term.AndNot(Match.Any, l => l.Message, "Mac Os"); result = (await conn.Search(term)).ToArray(); result.Length.ShouldBe(3); result[0].Level.ShouldBe(logs[0].Level); result[0].Message.ShouldBe(logs[0].Message); result[1].Level.ShouldBe(logs[1].Level); result[1].Message.ShouldBe(logs[1].Message); result[2].Level.ShouldBe(logs[2].Level); result[2].Message.ShouldBe(logs[2].Message); term.Clear(); term .AndNot(Match.Any, l => l.Message, "Mac Os") .And(Match.Any, l => l.Message, "operating system", "fun"); result = (await conn.Search(term)).ToArray(); result.Length.ShouldBe(2); result[0].Level.ShouldBe(logs[0].Level); result[0].Message.ShouldBe(logs[0].Message); result[1].Level.ShouldBe(logs[2].Level); result[1].Message.ShouldBe(logs[2].Message); term.Clear(); term .AndNot(Match.Any, l => l.Message, "Mac Os") .And(Match.Any, l => l.Message, "operating system*", "fun"); result = (await conn.Search(term)).ToArray(); result.Length.ShouldBe(3); result[0].Level.ShouldBe(logs[0].Level); result[0].Message.ShouldBe(logs[0].Message); result[1].Level.ShouldBe(logs[1].Level); result[1].Message.ShouldBe(logs[1].Message); result[2].Level.ShouldBe(logs[2].Level); result[2].Message.ShouldBe(logs[2].Message); } }
public async Task When_querying_multiple_multiple_rows() { using (var conn = new SQLiteInMemoryConnection()) { await conn.ExecuteAsync(SQLiteSQLGenerator.Table <ModelOne>()); await conn.ExecuteAsync(SQLiteSQLGenerator.Table <ModelTwo>()); var repoOne = conn.GetDBContext <ModelOne>(SQLiteDialect.Instance); var repoTwo = conn.GetDBContext <ModelTwo>(SQLiteDialect.Instance, "ModelTwo"); await repoOne.Insert(new[] { new ModelOne { Name = "M1-A" }, new ModelOne { Name = "M1-B" }, new ModelOne { Name = "M1-C" } }); await repoTwo.Insert(new[] { new ModelTwo { Category = "M2-C-A", Number = 1 }, new ModelTwo { Category = "M2-C-B", Number = 2 }, new ModelTwo { Category = "M2-C-C", Number = 3 }, new ModelTwo { Category = "M2-C-D", Number = 4 } }); using (var reader = await conn.QueryMultipleAsync("SELECT Id, Name FROM ModelOne; SELECT Id, Number, Category FROM ModelTwo;")) { reader.IsConsumed.ShouldBeFalse(); var modelOnes = (await reader.ReadAsync <ModelOne>(false)).ToArray(); reader.IsConsumed.ShouldBeFalse(); modelOnes.Length.ShouldBe(3); modelOnes[0].Name.ShouldBe("M1-A"); modelOnes[1].Name.ShouldBe("M1-B"); modelOnes[2].Name.ShouldBe("M1-C"); var modelTwos = (await reader.ReadAsync <ModelTwo>()).ToArray(); reader.IsConsumed.ShouldBeTrue(); modelTwos.Length.ShouldBe(4); modelTwos[0].Number.ShouldBe(1); modelTwos[0].Category.ShouldBe("M2-C-A"); modelTwos[1].Number.ShouldBe(2); modelTwos[1].Category.ShouldBe("M2-C-B"); modelTwos[2].Number.ShouldBe(3); modelTwos[2].Category.ShouldBe("M2-C-C"); modelTwos[3].Number.ShouldBe(4); modelTwos[3].Category.ShouldBe("M2-C-D"); } } }