diff --git a/src/Tests.CSharp/PostgresCSharpTests.cs b/src/Tests.CSharp/PostgresCSharpTests.cs index a224094..63460ed 100644 --- a/src/Tests.CSharp/PostgresCSharpTests.cs +++ b/src/Tests.CSharp/PostgresCSharpTests.cs @@ -314,21 +314,12 @@ public static class PostgresCSharpTests }) ]); - private static readonly List TestDocuments = - [ - new() { Id = "one", Value = "FIRST!", NumValue = 0 }, - new() { Id = "two", Value = "another", NumValue = 10, Sub = new() { Foo = "green", Bar = "blue" } }, - new() { Id = "three", Value = "", NumValue = 4 }, - new() { Id = "four", Value = "purple", NumValue = 17, Sub = new() { Foo = "green", Bar = "red" } }, - new() { Id = "five", Value = "purple", NumValue = 18 } - ]; - /// /// Add the test documents to the database /// internal static async Task LoadDocs() { - foreach (var doc in TestDocuments) await Document.Insert(SqliteDb.TableName, doc); + foreach (var doc in JsonDocument.TestDocuments) await Document.Insert(SqliteDb.TableName, doc); } /// @@ -881,6 +872,15 @@ public static class PostgresCSharpTests [Field.EQ("Value", "another")]); Expect.hasLength(docs, 1, "There should have been one document returned"); }), + TestCase("succeeds when documents are found using IN with numeric field", async () => + { + await using var db = PostgresDb.BuildDb(); + await LoadDocs(); + + var docs = await Find.ByFields(PostgresDb.TableName, FieldMatch.All, + [Field.IN("NumValue", [2, 4, 6, 8])]); + Expect.hasLength(docs, 1, "There should have been one document returned"); + }), TestCase("succeeds when documents are not found", async () => { await using var db = PostgresDb.BuildDb(); diff --git a/src/Tests.CSharp/SqliteCSharpTests.cs b/src/Tests.CSharp/SqliteCSharpTests.cs index 71d38b4..44a50c3 100644 --- a/src/Tests.CSharp/SqliteCSharpTests.cs +++ b/src/Tests.CSharp/SqliteCSharpTests.cs @@ -129,24 +129,12 @@ public static class SqliteCSharpTests // Results are exhaustively executed in the context of other tests - /// - /// Documents used for integration tests - /// - private static readonly List TestDocuments = - [ - new() { Id = "one", Value = "FIRST!", NumValue = 0 }, - new() { Id = "two", Value = "another", NumValue = 10, Sub = new() { Foo = "green", Bar = "blue" } }, - new() { Id = "three", Value = "", NumValue = 4 }, - new() { Id = "four", Value = "purple", NumValue = 17, Sub = new() { Foo = "green", Bar = "red" } }, - new() { Id = "five", Value = "purple", NumValue = 18 } - ]; - /// /// Add the test documents to the database /// internal static async Task LoadDocs() { - foreach (var doc in TestDocuments) await Document.Insert(SqliteDb.TableName, doc); + foreach (var doc in JsonDocument.TestDocuments) await Document.Insert(SqliteDb.TableName, doc); } /// @@ -608,6 +596,15 @@ public static class SqliteCSharpTests [Field.GT("NumValue", 15)]); Expect.equal(docs.Count, 2, "There should have been two documents returned"); }), + TestCase("succeeds when documents are found using IN with numeric field", async () => + { + await using var db = await SqliteDb.BuildDb(); + await LoadDocs(); + + var docs = await Find.ByFields(SqliteDb.TableName, FieldMatch.All, + [Field.IN("NumValue", [2, 4, 6, 8])]); + Expect.hasLength(docs, 1, "There should have been one document returned"); + }), TestCase("succeeds when documents are not found", async () => { await using var db = await SqliteDb.BuildDb(); diff --git a/src/Tests.CSharp/Types.cs b/src/Tests.CSharp/Types.cs index ce63230..88d8830 100644 --- a/src/Tests.CSharp/Types.cs +++ b/src/Tests.CSharp/Types.cs @@ -18,4 +18,16 @@ public class JsonDocument public string Value { get; set; } = ""; public int NumValue { get; set; } = 0; public SubDocument? Sub { get; set; } = null; + + /// + /// A set of documents used for integration tests + /// + public static readonly List TestDocuments = + [ + new() { Id = "one", Value = "FIRST!", NumValue = 0 }, + new() { Id = "two", Value = "another", NumValue = 10, Sub = new() { Foo = "green", Bar = "blue" } }, + new() { Id = "three", Value = "", NumValue = 4 }, + new() { Id = "four", Value = "purple", NumValue = 17, Sub = new() { Foo = "green", Bar = "red" } }, + new() { Id = "five", Value = "purple", NumValue = 18 } + ]; } diff --git a/src/Tests/PostgresTests.fs b/src/Tests/PostgresTests.fs index fd83d72..7e04c94 100644 --- a/src/Tests/PostgresTests.fs +++ b/src/Tests/PostgresTests.fs @@ -719,8 +719,16 @@ let findTests = testList "Find" [ do! loadDocs () let! docs = - Find.byFields PostgresDb.TableName All [ Field.EQ "Value" "purple"; Field.EX "Sub" ] - Expect.equal (List.length docs) 1 "There should have been one document returned" + Find.byFields + PostgresDb.TableName All [ Field.IN "Value" [ "purple"; "blue" ]; Field.EX "Sub" ] + Expect.hasLength docs 1 "There should have been one document returned" + } + testTask "succeeds when documents are found using IN with numeric field" { + use db = PostgresDb.BuildDb() + do! loadDocs () + + let! docs = Find.byFields PostgresDb.TableName All [ Field.IN "NumValue" [ 2; 4; 6; 8 ] ] + Expect.hasLength docs 1 "There should have been one document returned" } testTask "succeeds when documents are not found" { use db = PostgresDb.BuildDb() diff --git a/src/Tests/SqliteTests.fs b/src/Tests/SqliteTests.fs index 1cf4aa8..de02b9f 100644 --- a/src/Tests/SqliteTests.fs +++ b/src/Tests/SqliteTests.fs @@ -515,7 +515,14 @@ let findTests = testList "Find" [ do! loadDocs () let! docs = Find.byFields SqliteDb.TableName Any [ Field.GT "NumValue" 15 ] - Expect.equal (List.length docs) 2 "There should have been two documents returned" + Expect.hasLength docs 2 "There should have been two documents returned" + } + testTask "succeeds when documents are found using IN with numeric field" { + use! db = SqliteDb.BuildDb() + do! loadDocs () + + let! docs = Find.byFields SqliteDb.TableName All [ Field.IN "NumValue" [ 2; 4; 6; 8 ] ] + Expect.hasLength docs 1 "There should have been one document returned" } testTask "succeeds when documents are not found" { use! db = SqliteDb.BuildDb()