Add IN to some tests
This commit is contained in:
parent
fb2b397663
commit
14c80f32fe
|
@ -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>
|
||||
/// Add the test documents to the database
|
||||
/// </summary>
|
||||
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>
|
||||
|
@ -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<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 () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
|
|
|
@ -129,24 +129,12 @@ public static class SqliteCSharpTests
|
|||
|
||||
// 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>
|
||||
/// Add the test documents to the database
|
||||
/// </summary>
|
||||
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>
|
||||
|
@ -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<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 () =>
|
||||
{
|
||||
await using var db = await SqliteDb.BuildDb();
|
||||
|
|
|
@ -18,4 +18,16 @@ public class JsonDocument
|
|||
public string Value { get; set; } = "";
|
||||
public int NumValue { get; set; } = 0;
|
||||
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 }
|
||||
];
|
||||
}
|
||||
|
|
|
@ -719,8 +719,16 @@ let findTests = testList "Find" [
|
|||
do! loadDocs ()
|
||||
|
||||
let! docs =
|
||||
Find.byFields<JsonDocument> 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<JsonDocument>
|
||||
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" {
|
||||
use db = PostgresDb.BuildDb()
|
||||
|
|
|
@ -515,7 +515,14 @@ let findTests = testList "Find" [
|
|||
do! loadDocs ()
|
||||
|
||||
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" {
|
||||
use! db = SqliteDb.BuildDb()
|
||||
|
|
Loading…
Reference in New Issue
Block a user