RC4 changes #7

Merged
danieljsummers merged 7 commits from arr-cee-four into main 2024-09-17 02:33:57 +00:00
5 changed files with 50 additions and 26 deletions
Showing only changes of commit 14c80f32fe - Show all commits

View File

@ -314,21 +314,12 @@ public static class PostgresCSharpTests
}) })
]); ]);
private static readonly List<JsonDocument> 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 }
];
/// <summary> /// <summary>
/// Add the test documents to the database /// Add the test documents to the database
/// </summary> /// </summary>
internal static async Task LoadDocs() 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);
} }
/// <summary> /// <summary>
@ -881,6 +872,15 @@ public static class PostgresCSharpTests
[Field.EQ("Value", "another")]); [Field.EQ("Value", "another")]);
Expect.hasLength(docs, 1, "There should have been one document returned"); 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<JsonDocument>(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 () => TestCase("succeeds when documents are not found", async () =>
{ {
await using var db = PostgresDb.BuildDb(); await using var db = PostgresDb.BuildDb();

View File

@ -129,24 +129,12 @@ public static class SqliteCSharpTests
// Results are exhaustively executed in the context of other tests // Results are exhaustively executed in the context of other tests
/// <summary>
/// Documents used for integration tests
/// </summary>
private static readonly List<JsonDocument> 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 }
];
/// <summary> /// <summary>
/// Add the test documents to the database /// Add the test documents to the database
/// </summary> /// </summary>
internal static async Task LoadDocs() 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);
} }
/// <summary> /// <summary>
@ -608,6 +596,15 @@ public static class SqliteCSharpTests
[Field.GT("NumValue", 15)]); [Field.GT("NumValue", 15)]);
Expect.equal(docs.Count, 2, "There should have been two documents returned"); 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<JsonDocument>(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 () => TestCase("succeeds when documents are not found", async () =>
{ {
await using var db = await SqliteDb.BuildDb(); await using var db = await SqliteDb.BuildDb();

View File

@ -18,4 +18,16 @@ public class JsonDocument
public string Value { get; set; } = ""; public string Value { get; set; } = "";
public int NumValue { get; set; } = 0; public int NumValue { get; set; } = 0;
public SubDocument? Sub { get; set; } = null; public SubDocument? Sub { get; set; } = null;
/// <summary>
/// A set of documents used for integration tests
/// </summary>
public static readonly List<JsonDocument> 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 }
];
} }

View File

@ -719,8 +719,16 @@ let findTests = testList "Find" [
do! loadDocs () do! loadDocs ()
let! docs = let! docs =
Find.byFields<JsonDocument> PostgresDb.TableName All [ Field.EQ "Value" "purple"; Field.EX "Sub" ] Find.byFields<JsonDocument>
Expect.equal (List.length docs) 1 "There should have been one document returned" 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<JsonDocument> 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" { testTask "succeeds when documents are not found" {
use db = PostgresDb.BuildDb() use db = PostgresDb.BuildDb()

View File

@ -515,7 +515,14 @@ let findTests = testList "Find" [
do! loadDocs () do! loadDocs ()
let! docs = Find.byFields<JsonDocument> SqliteDb.TableName Any [ Field.GT "NumValue" 15 ] let! docs = Find.byFields<JsonDocument> 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<JsonDocument> 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" { testTask "succeeds when documents are not found" {
use! db = SqliteDb.BuildDb() use! db = SqliteDb.BuildDb()