Version 4 rc1 (#6)
Changes in this version: - **BREAKING CHANGE**: All `*byField`/`*ByField` functions are now `*byFields`/`*ByFields`, and take a `FieldMatch` case before the list of fields. The `Compat` namespace in both libraries will assist in this transition. In support of this change, the `Field` parameter name is optional; the library will generate parameter names for it if they are not specified. - **BREAKING CHANGE**: The `Query` namespaces have had some significant work, particularly from the full-query perspective. Most have been broken up into the base query and modifiers `by*` that will combine the base query with the `WHERE` clause needed to satisfy the criteria. - **FEATURE / BREAKING CHANGE**: PostgreSQL document fields will now be cast to numeric if the parameter value passed to the query is numeric. This drove the `Query` breaking changes, as the fields need to have their intended value for the library to generate the appropriate SQL. Additionally, if code assumes the library can be given something like `8` and transform it to `"8"`, this is no longer the case. - **FEATURE**: All `Find` queries (except `byId`/`ById`) now have a version with the `Ordered` suffix. These take a list of fields by which the query should be ordered. A new `Field` method called `Named` can assist with creating these fields. Prefixing the field name with `n:` will cast the field to numeric in PostgreSQL (and will be ignored by SQLite); adding " DESC" to the field name will sort it descending (Z-A, high to low) instead of ascending (A-Z, low to high). - **BREAKING CHANGE** (PostgreSQL only): `fieldNameParam`/`Parameters.FieldName` are now plural. The function still only generates one parameter, but the name is now the same between PostgreSQL and SQLite. The goal of this library is to abstract the differences away as much as practical, and this furthers that end. There are functions with these names in the `Compat` namespace. - **FEATURE**: In the F# v3 library, lists of parameters were expected to be F#'s `List` type, and the C# version took either `List<T>` or `IEnumerable<T>`. In this version, these all expect `seq`/`IEnumerable<T>`. F#'s `List` satisfies the `seq` constraints, so this should not be a breaking change. - **FEATURE**: `Field`s now may have qualifiers; this allows tables to be aliased when joining multiple tables (as all have the same `data` column). F# users can use `with` to specify this at creation, and both F# and C# can use the `WithQualifier` method to create a field with the qualifier specified. Parameter names for fields may be specified in a similar way, substituting `ParameterName` for `Qualifier`. Reviewed-on: #6
This commit was merged in pull request #6.
This commit is contained in:
@@ -31,17 +31,17 @@ public class PostgresCSharpExtensionTests
|
||||
/// Integration tests for the SQLite extension methods
|
||||
/// </summary>
|
||||
[Tests]
|
||||
public static readonly Test Integration = TestList("Postgres.C#.Extensions", new[]
|
||||
{
|
||||
TestList("CustomList", new[]
|
||||
{
|
||||
public static readonly Test Integration = TestList("Postgres.C#.Extensions",
|
||||
[
|
||||
TestList("CustomList",
|
||||
[
|
||||
TestCase("succeeds when data is found", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
var docs = await conn.CustomList(Query.SelectFromTable(PostgresDb.TableName), Parameters.None,
|
||||
var docs = await conn.CustomList(Query.Find(PostgresDb.TableName), Parameters.None,
|
||||
Results.FromData<JsonDocument>);
|
||||
Expect.equal(docs.Count, 5, "There should have been 5 documents returned");
|
||||
}),
|
||||
@@ -53,13 +53,13 @@ public class PostgresCSharpExtensionTests
|
||||
|
||||
var docs = await conn.CustomList(
|
||||
$"SELECT data FROM {PostgresDb.TableName} WHERE data @? @path::jsonpath",
|
||||
new[] { Tuple.Create("@path", Sql.@string("$.NumValue ? (@ > 100)")) },
|
||||
[Tuple.Create("@path", Sql.@string("$.NumValue ? (@ > 100)"))],
|
||||
Results.FromData<JsonDocument>);
|
||||
Expect.isEmpty(docs, "There should have been no documents returned");
|
||||
})
|
||||
}),
|
||||
TestList("CustomSingle", new[]
|
||||
{
|
||||
]),
|
||||
TestList("CustomSingle",
|
||||
[
|
||||
TestCase("succeeds when a row is found", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
@@ -67,7 +67,7 @@ public class PostgresCSharpExtensionTests
|
||||
await LoadDocs();
|
||||
|
||||
var doc = await conn.CustomSingle($"SELECT data FROM {PostgresDb.TableName} WHERE data ->> 'Id' = @id",
|
||||
new[] { Tuple.Create("@id", Sql.@string("one")) }, Results.FromData<JsonDocument>);
|
||||
[Tuple.Create("@id", Sql.@string("one"))], Results.FromData<JsonDocument>);
|
||||
Expect.isNotNull(doc, "There should have been a document returned");
|
||||
Expect.equal(doc.Id, "one", "The incorrect document was returned");
|
||||
}),
|
||||
@@ -78,12 +78,12 @@ public class PostgresCSharpExtensionTests
|
||||
await LoadDocs();
|
||||
|
||||
var doc = await conn.CustomSingle($"SELECT data FROM {PostgresDb.TableName} WHERE data ->> 'Id' = @id",
|
||||
new[] { Tuple.Create("@id", Sql.@string("eighty")) }, Results.FromData<JsonDocument>);
|
||||
[Tuple.Create("@id", Sql.@string("eighty"))], Results.FromData<JsonDocument>);
|
||||
Expect.isNull(doc, "There should not have been a document returned");
|
||||
})
|
||||
}),
|
||||
TestList("CustomNonQuery", new[]
|
||||
{
|
||||
]),
|
||||
TestList("CustomNonQuery",
|
||||
[
|
||||
TestCase("succeeds when operating on data", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
@@ -102,12 +102,12 @@ public class PostgresCSharpExtensionTests
|
||||
await LoadDocs();
|
||||
|
||||
await conn.CustomNonQuery($"DELETE FROM {PostgresDb.TableName} WHERE data @? @path::jsonpath",
|
||||
new[] { Tuple.Create("@path", Sql.@string("$.NumValue ? (@ > 100)")) });
|
||||
[Tuple.Create("@path", Sql.@string("$.NumValue ? (@ > 100)"))]);
|
||||
|
||||
var remaining = await conn.CountAll(PostgresDb.TableName);
|
||||
Expect.equal(remaining, 5, "There should be 5 documents remaining in the table");
|
||||
})
|
||||
}),
|
||||
]),
|
||||
TestCase("Scalar succeeds", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
@@ -119,58 +119,64 @@ public class PostgresCSharpExtensionTests
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
var tableExists = () => conn.CustomScalar(
|
||||
"SELECT EXISTS (SELECT 1 FROM pg_class WHERE relname = 'ensured') AS it", Parameters.None,
|
||||
Results.ToExists);
|
||||
var keyExists = () => conn.CustomScalar(
|
||||
"SELECT EXISTS (SELECT 1 FROM pg_class WHERE relname = 'idx_ensured_key') AS it", Parameters.None,
|
||||
Results.ToExists);
|
||||
|
||||
var exists = await tableExists();
|
||||
var alsoExists = await keyExists();
|
||||
var exists = await TableExists();
|
||||
var alsoExists = await KeyExists();
|
||||
Expect.isFalse(exists, "The table should not exist already");
|
||||
Expect.isFalse(alsoExists, "The key index should not exist already");
|
||||
|
||||
await conn.EnsureTable("ensured");
|
||||
exists = await tableExists();
|
||||
alsoExists = await keyExists();
|
||||
exists = await TableExists();
|
||||
alsoExists = await KeyExists();
|
||||
Expect.isTrue(exists, "The table should now exist");
|
||||
Expect.isTrue(alsoExists, "The key index should now exist");
|
||||
return;
|
||||
|
||||
Task<bool> KeyExists() =>
|
||||
conn.CustomScalar("SELECT EXISTS (SELECT 1 FROM pg_class WHERE relname = 'idx_ensured_key') AS it",
|
||||
Parameters.None, Results.ToExists);
|
||||
Task<bool> TableExists() =>
|
||||
conn.CustomScalar("SELECT EXISTS (SELECT 1 FROM pg_class WHERE relname = 'ensured') AS it",
|
||||
Parameters.None, Results.ToExists);
|
||||
}),
|
||||
TestCase("EnsureDocumentIndex succeeds", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
var indexExists = () => conn.CustomScalar(
|
||||
"SELECT EXISTS (SELECT 1 FROM pg_class WHERE relname = 'idx_ensured_document') AS it", Parameters.None,
|
||||
Results.ToExists);
|
||||
|
||||
var exists = await indexExists();
|
||||
var exists = await IndexExists();
|
||||
Expect.isFalse(exists, "The index should not exist already");
|
||||
|
||||
await conn.EnsureTable("ensured");
|
||||
await conn.EnsureDocumentIndex("ensured", DocumentIndex.Optimized);
|
||||
exists = await indexExists();
|
||||
exists = await IndexExists();
|
||||
Expect.isTrue(exists, "The index should now exist");
|
||||
return;
|
||||
|
||||
Task<bool> IndexExists() =>
|
||||
conn.CustomScalar("SELECT EXISTS (SELECT 1 FROM pg_class WHERE relname = 'idx_ensured_document') AS it",
|
||||
Parameters.None, Results.ToExists);
|
||||
}),
|
||||
TestCase("EnsureFieldIndex succeeds", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
var indexExists = () => conn.CustomScalar(
|
||||
"SELECT EXISTS (SELECT 1 FROM pg_class WHERE relname = 'idx_ensured_test') AS it", Parameters.None,
|
||||
Results.ToExists);
|
||||
|
||||
var exists = await indexExists();
|
||||
var exists = await IndexExists();
|
||||
Expect.isFalse(exists, "The index should not exist already");
|
||||
|
||||
await conn.EnsureTable("ensured");
|
||||
await conn.EnsureFieldIndex("ensured", "test", new[] { "Id", "Category" });
|
||||
exists = await indexExists();
|
||||
await conn.EnsureFieldIndex("ensured", "test", ["Id", "Category"]);
|
||||
exists = await IndexExists();
|
||||
Expect.isTrue(exists, "The index should now exist");
|
||||
return;
|
||||
|
||||
Task<bool> IndexExists() =>
|
||||
conn.CustomScalar("SELECT EXISTS (SELECT 1 FROM pg_class WHERE relname = 'idx_ensured_test') AS it",
|
||||
Parameters.None, Results.ToExists);
|
||||
}),
|
||||
TestList("Insert", new[]
|
||||
{
|
||||
TestList("Insert",
|
||||
[
|
||||
TestCase("succeeds", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
@@ -198,9 +204,9 @@ public class PostgresCSharpExtensionTests
|
||||
// This is what should have happened
|
||||
}
|
||||
})
|
||||
}),
|
||||
TestList("save", new[]
|
||||
{
|
||||
]),
|
||||
TestList("save",
|
||||
[
|
||||
TestCase("succeeds when a document is inserted", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
@@ -230,7 +236,7 @@ public class PostgresCSharpExtensionTests
|
||||
Expect.isNotNull(after, "There should have been a document returned post-update");
|
||||
Expect.equal(after.Sub!.Foo, "c", "The updated document is not correct");
|
||||
})
|
||||
}),
|
||||
]),
|
||||
TestCase("CountAll succeeds", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
@@ -240,13 +246,14 @@ public class PostgresCSharpExtensionTests
|
||||
var theCount = await conn.CountAll(PostgresDb.TableName);
|
||||
Expect.equal(theCount, 5, "There should have been 5 matching documents");
|
||||
}),
|
||||
TestCase("CountByField succeeds", async () =>
|
||||
TestCase("CountByFields succeeds", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
var theCount = await conn.CountByField(PostgresDb.TableName, Field.EQ("Value", "purple"));
|
||||
var theCount = await conn.CountByFields(PostgresDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("Value", "purple")]);
|
||||
Expect.equal(theCount, 2, "There should have been 2 matching documents");
|
||||
}),
|
||||
TestCase("CountByContains succeeds", async () =>
|
||||
@@ -267,8 +274,8 @@ public class PostgresCSharpExtensionTests
|
||||
var theCount = await conn.CountByJsonPath(PostgresDb.TableName, "$.NumValue ? (@ > 5)");
|
||||
Expect.equal(theCount, 3, "There should have been 3 matching documents");
|
||||
}),
|
||||
TestList("ExistsById", new[]
|
||||
{
|
||||
TestList("ExistsById",
|
||||
[
|
||||
TestCase("succeeds when a document exists", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
@@ -287,16 +294,16 @@ public class PostgresCSharpExtensionTests
|
||||
var exists = await conn.ExistsById(PostgresDb.TableName, "seven");
|
||||
Expect.isFalse(exists, "There should not have been an existing document");
|
||||
})
|
||||
}),
|
||||
TestList("ExistsByField", new[]
|
||||
{
|
||||
]),
|
||||
TestList("ExistsByField",
|
||||
[
|
||||
TestCase("succeeds when documents exist", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
var exists = await conn.ExistsByField(PostgresDb.TableName, Field.EX("Sub"));
|
||||
var exists = await conn.ExistsByFields(PostgresDb.TableName, FieldMatch.Any, [Field.EX("Sub")]);
|
||||
Expect.isTrue(exists, "There should have been existing documents");
|
||||
}),
|
||||
TestCase("succeeds when documents do not exist", async () =>
|
||||
@@ -305,12 +312,13 @@ public class PostgresCSharpExtensionTests
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
var exists = await conn.ExistsByField(PostgresDb.TableName, Field.EQ("NumValue", "six"));
|
||||
var exists =
|
||||
await conn.ExistsByFields(PostgresDb.TableName, FieldMatch.Any, [Field.EQ("NumValue", "six")]);
|
||||
Expect.isFalse(exists, "There should not have been existing documents");
|
||||
})
|
||||
}),
|
||||
TestList("ExistsByContains", new[]
|
||||
{
|
||||
]),
|
||||
TestList("ExistsByContains",
|
||||
[
|
||||
TestCase("succeeds when documents exist", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
@@ -329,9 +337,9 @@ public class PostgresCSharpExtensionTests
|
||||
var exists = await conn.ExistsByContains(PostgresDb.TableName, new { Nothing = "none" });
|
||||
Expect.isFalse(exists, "There should not have been any existing documents");
|
||||
})
|
||||
}),
|
||||
TestList("ExistsByJsonPath", new[]
|
||||
{
|
||||
]),
|
||||
TestList("ExistsByJsonPath",
|
||||
[
|
||||
TestCase("succeeds when documents exist", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
@@ -350,9 +358,9 @@ public class PostgresCSharpExtensionTests
|
||||
var exists = await conn.ExistsByJsonPath(PostgresDb.TableName, "$.NumValue ? (@ > 1000)");
|
||||
Expect.isFalse(exists, "There should not have been any existing documents");
|
||||
})
|
||||
}),
|
||||
TestList("FindAll", new[]
|
||||
{
|
||||
]),
|
||||
TestList("FindAll",
|
||||
[
|
||||
TestCase("succeeds when there is data", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
@@ -372,9 +380,47 @@ public class PostgresCSharpExtensionTests
|
||||
var results = await conn.FindAll<JsonDocument>(PostgresDb.TableName);
|
||||
Expect.isEmpty(results, "There should have been no documents returned");
|
||||
})
|
||||
}),
|
||||
TestList("FindById", new[]
|
||||
{
|
||||
]),
|
||||
TestList("FindAllOrdered",
|
||||
[
|
||||
TestCase("succeeds when ordering numerically", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
var results =
|
||||
await conn.FindAllOrdered<JsonDocument>(PostgresDb.TableName, [Field.Named("n:NumValue")]);
|
||||
Expect.hasLength(results, 5, "There should have been 5 documents returned");
|
||||
Expect.equal(string.Join('|', results.Select(x => x.Id)), "one|three|two|four|five",
|
||||
"The documents were not ordered correctly");
|
||||
}),
|
||||
TestCase("succeeds when ordering numerically descending", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
var results =
|
||||
await conn.FindAllOrdered<JsonDocument>(PostgresDb.TableName, [Field.Named("n:NumValue DESC")]);
|
||||
Expect.hasLength(results, 5, "There should have been 5 documents returned");
|
||||
Expect.equal(string.Join('|', results.Select(x => x.Id)), "five|four|two|three|one",
|
||||
"The documents were not ordered correctly");
|
||||
}),
|
||||
TestCase("succeeds when ordering alphabetically", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
var results = await conn.FindAllOrdered<JsonDocument>(PostgresDb.TableName, [Field.Named("Id DESC")]);
|
||||
Expect.hasLength(results, 5, "There should have been 5 documents returned");
|
||||
Expect.equal(string.Join('|', results.Select(x => x.Id)), "two|three|one|four|five",
|
||||
"The documents were not ordered correctly");
|
||||
})
|
||||
]),
|
||||
TestList("FindById",
|
||||
[
|
||||
TestCase("succeeds when a document is found", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
@@ -394,16 +440,17 @@ public class PostgresCSharpExtensionTests
|
||||
var doc = await conn.FindById<string, JsonDocument>(PostgresDb.TableName, "three hundred eighty-seven");
|
||||
Expect.isNull(doc, "There should not have been a document returned");
|
||||
})
|
||||
}),
|
||||
TestList("FindByField", new[]
|
||||
{
|
||||
]),
|
||||
TestList("FindByFields",
|
||||
[
|
||||
TestCase("succeeds when documents are found", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
var docs = await conn.FindByField<JsonDocument>(PostgresDb.TableName, Field.EQ("Value", "another"));
|
||||
var docs = await conn.FindByFields<JsonDocument>(PostgresDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("Value", "another")]);
|
||||
Expect.equal(docs.Count, 1, "There should have been one document returned");
|
||||
}),
|
||||
TestCase("succeeds when documents are not found", async () =>
|
||||
@@ -412,12 +459,40 @@ public class PostgresCSharpExtensionTests
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
var docs = await conn.FindByField<JsonDocument>(PostgresDb.TableName, Field.EQ("Value", "mauve"));
|
||||
var docs = await conn.FindByFields<JsonDocument>(PostgresDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("Value", "mauve")]);
|
||||
Expect.isEmpty(docs, "There should have been no documents returned");
|
||||
})
|
||||
}),
|
||||
TestList("FindByContains", new[]
|
||||
{
|
||||
]),
|
||||
TestList("FindByFieldsOrdered",
|
||||
[
|
||||
TestCase("succeeds when documents are found", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
var docs = await conn.FindByFieldsOrdered<JsonDocument>(PostgresDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("Value", "purple")], [Field.Named("Id")]);
|
||||
Expect.hasLength(docs, 2, "There should have been two document returned");
|
||||
Expect.equal(string.Join('|', docs.Select(x => x.Id)), "five|four",
|
||||
"The documents were not ordered correctly");
|
||||
}),
|
||||
TestCase("succeeds when documents are not found", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
var docs = await conn.FindByFieldsOrdered<JsonDocument>(PostgresDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("Value", "purple")], [Field.Named("Id DESC")]);
|
||||
Expect.hasLength(docs, 2, "There should have been two document returned");
|
||||
Expect.equal(string.Join('|', docs.Select(x => x.Id)), "four|five",
|
||||
"The documents were not ordered correctly");
|
||||
})
|
||||
]),
|
||||
TestList("FindByContains",
|
||||
[
|
||||
TestCase("succeeds when documents are found", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
@@ -437,9 +512,37 @@ public class PostgresCSharpExtensionTests
|
||||
var docs = await conn.FindByContains<JsonDocument>(PostgresDb.TableName, new { Value = "mauve" });
|
||||
Expect.isEmpty(docs, "There should have been no documents returned");
|
||||
})
|
||||
}),
|
||||
TestList("FindByJsonPath", new[]
|
||||
{
|
||||
]),
|
||||
TestList("FindByContainsOrdered",
|
||||
[
|
||||
// Id = two, Sub.Bar = blue; Id = four, Sub.Bar = red
|
||||
TestCase("succeeds when sorting ascending", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
var docs = await conn.FindByContainsOrdered<JsonDocument>(PostgresDb.TableName,
|
||||
new { Sub = new { Foo = "green" } }, [Field.Named("Sub.Bar")]);
|
||||
Expect.hasLength(docs, 2, "There should have been two documents returned");
|
||||
Expect.equal(string.Join('|', docs.Select(x => x.Id)), "two|four",
|
||||
"Documents not ordered correctly");
|
||||
}),
|
||||
TestCase("succeeds when sorting descending", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
var docs = await conn.FindByContainsOrdered<JsonDocument>(PostgresDb.TableName,
|
||||
new { Sub = new { Foo = "green" } }, [Field.Named("Sub.Bar DESC")]);
|
||||
Expect.hasLength(docs, 2, "There should have been two documents returned");
|
||||
Expect.equal(string.Join('|', docs.Select(x => x.Id)), "four|two",
|
||||
"Documents not ordered correctly");
|
||||
})
|
||||
]),
|
||||
TestList("FindByJsonPath",
|
||||
[
|
||||
TestCase("succeeds when documents are found", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
@@ -458,16 +561,45 @@ public class PostgresCSharpExtensionTests
|
||||
var docs = await conn.FindByJsonPath<JsonDocument>(PostgresDb.TableName, "$.NumValue ? (@ < 0)");
|
||||
Expect.isEmpty(docs, "There should have been no documents returned");
|
||||
})
|
||||
}),
|
||||
TestList("FindFirstByField", new[]
|
||||
{
|
||||
]),
|
||||
TestList("FindByJsonPathOrdered",
|
||||
[
|
||||
// Id = one, NumValue = 0; Id = two, NumValue = 10; Id = three, NumValue = 4
|
||||
TestCase("succeeds when sorting ascending", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
var docs = await conn.FindByJsonPathOrdered<JsonDocument>(PostgresDb.TableName, "$.NumValue ? (@ < 15)",
|
||||
[Field.Named("n:NumValue")]);
|
||||
Expect.hasLength(docs, 3, "There should have been 3 documents returned");
|
||||
Expect.equal(string.Join('|', docs.Select(x => x.Id)), "one|three|two",
|
||||
"Documents not ordered correctly");
|
||||
}),
|
||||
TestCase("succeeds when sorting descending", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
var docs = await conn.FindByJsonPathOrdered<JsonDocument>(PostgresDb.TableName, "$.NumValue ? (@ < 15)",
|
||||
[Field.Named("n:NumValue DESC")]);
|
||||
Expect.hasLength(docs, 3, "There should have been 3 documents returned");
|
||||
Expect.equal(string.Join('|', docs.Select(x => x.Id)), "two|three|one",
|
||||
"Documents not ordered correctly");
|
||||
})
|
||||
]),
|
||||
TestList("FindFirstByFields",
|
||||
[
|
||||
TestCase("succeeds when a document is found", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
var doc = await conn.FindFirstByField<JsonDocument>(PostgresDb.TableName, Field.EQ("Value", "another"));
|
||||
var doc = await conn.FindFirstByFields<JsonDocument>(PostgresDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("Value", "another")]);
|
||||
Expect.isNotNull(doc, "There should have been a document returned");
|
||||
Expect.equal(doc.Id, "two", "The incorrect document was returned");
|
||||
}),
|
||||
@@ -477,9 +609,10 @@ public class PostgresCSharpExtensionTests
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
var doc = await conn.FindFirstByField<JsonDocument>(PostgresDb.TableName, Field.EQ("Value", "purple"));
|
||||
var doc = await conn.FindFirstByFields<JsonDocument>(PostgresDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("Value", "purple")]);
|
||||
Expect.isNotNull(doc, "There should have been a document returned");
|
||||
Expect.contains(new[] { "five", "four" }, doc.Id, "An incorrect document was returned");
|
||||
Expect.contains(["five", "four"], doc.Id, "An incorrect document was returned");
|
||||
}),
|
||||
TestCase("succeeds when a document is not found", async () =>
|
||||
{
|
||||
@@ -487,12 +620,38 @@ public class PostgresCSharpExtensionTests
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
var doc = await conn.FindFirstByField<JsonDocument>(PostgresDb.TableName, Field.EQ("Value", "absent"));
|
||||
var doc = await conn.FindFirstByFields<JsonDocument>(PostgresDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("Value", "absent")]);
|
||||
Expect.isNull(doc, "There should not have been a document returned");
|
||||
})
|
||||
}),
|
||||
TestList("FindFirstByContains", new[]
|
||||
{
|
||||
]),
|
||||
TestList("FindFirstByFieldsOrdered",
|
||||
[
|
||||
TestCase("succeeds when sorting ascending", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
var doc = await conn.FindFirstByFieldsOrdered<JsonDocument>(PostgresDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("Value", "purple")], [Field.Named("Id")]);
|
||||
Expect.isNotNull(doc, "There should have been a document returned");
|
||||
Expect.equal("five", doc.Id, "An incorrect document was returned");
|
||||
}),
|
||||
TestCase("succeeds when a document is not found", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
var doc = await conn.FindFirstByFieldsOrdered<JsonDocument>(PostgresDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("Value", "purple")], [Field.Named("Id DESC")]);
|
||||
Expect.isNotNull(doc, "There should have been a document returned");
|
||||
Expect.equal("four", doc.Id, "An incorrect document was returned");
|
||||
})
|
||||
]),
|
||||
TestList("FindFirstByContains",
|
||||
[
|
||||
TestCase("succeeds when a document is found", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
@@ -512,7 +671,7 @@ public class PostgresCSharpExtensionTests
|
||||
var doc = await conn.FindFirstByContains<JsonDocument>(PostgresDb.TableName,
|
||||
new { Sub = new { Foo = "green" } });
|
||||
Expect.isNotNull(doc, "There should have been a document returned");
|
||||
Expect.contains(new[] { "two", "four" }, doc.Id, "An incorrect document was returned");
|
||||
Expect.contains(["two", "four"], doc.Id, "An incorrect document was returned");
|
||||
}),
|
||||
TestCase("succeeds when a document is not found", async () =>
|
||||
{
|
||||
@@ -523,9 +682,34 @@ public class PostgresCSharpExtensionTests
|
||||
var doc = await conn.FindFirstByContains<JsonDocument>(PostgresDb.TableName, new { Value = "absent" });
|
||||
Expect.isNull(doc, "There should not have been a document returned");
|
||||
})
|
||||
}),
|
||||
TestList("FindFirstByJsonPath", new[]
|
||||
{
|
||||
]),
|
||||
TestList("FindFirstByContainsOrdered",
|
||||
[
|
||||
TestCase("succeeds when sorting ascending", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
var doc = await conn.FindFirstByContainsOrdered<JsonDocument>(PostgresDb.TableName,
|
||||
new { Sub = new { Foo = "green" } }, [Field.Named("Value")]);
|
||||
Expect.isNotNull(doc, "There should have been a document returned");
|
||||
Expect.equal("two", doc.Id, "An incorrect document was returned");
|
||||
}),
|
||||
TestCase("succeeds when sorting descending", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
var doc = await conn.FindFirstByContainsOrdered<JsonDocument>(PostgresDb.TableName,
|
||||
new { Sub = new { Foo = "green" } }, [Field.Named("Value DESC")]);
|
||||
Expect.isNotNull(doc, "There should have been a document returned");
|
||||
Expect.equal("four", doc.Id, "An incorrect document was returned");
|
||||
})
|
||||
]),
|
||||
TestList("FindFirstByJsonPath",
|
||||
[
|
||||
TestCase("succeeds when a document is found", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
@@ -546,7 +730,7 @@ public class PostgresCSharpExtensionTests
|
||||
var doc = await conn.FindFirstByJsonPath<JsonDocument>(PostgresDb.TableName,
|
||||
"$.Sub.Foo ? (@ == \"green\")");
|
||||
Expect.isNotNull(doc, "There should have been a document returned");
|
||||
Expect.contains(new[] { "two", "four" }, doc.Id, "An incorrect document was returned");
|
||||
Expect.contains(["two", "four"], doc.Id, "An incorrect document was returned");
|
||||
}),
|
||||
TestCase("succeeds when a document is not found", async () =>
|
||||
{
|
||||
@@ -557,9 +741,34 @@ public class PostgresCSharpExtensionTests
|
||||
var doc = await conn.FindFirstByJsonPath<JsonDocument>(PostgresDb.TableName, "$.Id ? (@ == \"nope\")");
|
||||
Expect.isNull(doc, "There should not have been a document returned");
|
||||
})
|
||||
}),
|
||||
TestList("UpdateById", new[]
|
||||
{
|
||||
]),
|
||||
TestList("FindFirstByJsonPathOrdered",
|
||||
[
|
||||
TestCase("succeeds when sorting ascending", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
var doc = await conn.FindFirstByJsonPathOrdered<JsonDocument>(PostgresDb.TableName,
|
||||
"$.Sub.Foo ? (@ == \"green\")", [Field.Named("Sub.Bar")]);
|
||||
Expect.isNotNull(doc, "There should have been a document returned");
|
||||
Expect.equal("two", doc.Id, "An incorrect document was returned");
|
||||
}),
|
||||
TestCase("succeeds when sorting descending", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
var doc = await conn.FindFirstByJsonPathOrdered<JsonDocument>(PostgresDb.TableName,
|
||||
"$.Sub.Foo ? (@ == \"green\")", [Field.Named("Sub.Bar DESC")]);
|
||||
Expect.isNotNull(doc, "There should have been a document returned");
|
||||
Expect.equal("four", doc.Id, "An incorrect document was returned");
|
||||
})
|
||||
]),
|
||||
TestList("UpdateById",
|
||||
[
|
||||
TestCase("succeeds when a document is updated", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
@@ -588,9 +797,9 @@ public class PostgresCSharpExtensionTests
|
||||
await conn.UpdateById(PostgresDb.TableName, "test",
|
||||
new JsonDocument { Id = "x", Sub = new() { Foo = "blue", Bar = "red" } });
|
||||
})
|
||||
}),
|
||||
TestList("UpdateByFunc", new[]
|
||||
{
|
||||
]),
|
||||
TestList("UpdateByFunc",
|
||||
[
|
||||
TestCase("succeeds when a document is updated", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
@@ -617,9 +826,9 @@ public class PostgresCSharpExtensionTests
|
||||
await conn.UpdateByFunc(PostgresDb.TableName, doc => doc.Id,
|
||||
new JsonDocument { Id = "one", Value = "le un", NumValue = 1 });
|
||||
})
|
||||
}),
|
||||
TestList("PatchById", new[]
|
||||
{
|
||||
]),
|
||||
TestList("PatchById",
|
||||
[
|
||||
TestCase("succeeds when a document is updated", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
@@ -641,17 +850,19 @@ public class PostgresCSharpExtensionTests
|
||||
// This not raising an exception is the test
|
||||
await conn.PatchById(PostgresDb.TableName, "test", new { Foo = "green" });
|
||||
})
|
||||
}),
|
||||
TestList("PatchByField", new[]
|
||||
{
|
||||
]),
|
||||
TestList("PatchByFields",
|
||||
[
|
||||
TestCase("succeeds when a document is updated", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
await conn.PatchByField(PostgresDb.TableName, Field.EQ("Value", "purple"), new { NumValue = 77 });
|
||||
var after = await conn.CountByField(PostgresDb.TableName, Field.EQ("NumValue", "77"));
|
||||
await conn.PatchByFields(PostgresDb.TableName, FieldMatch.Any, [Field.EQ("Value", "purple")],
|
||||
new { NumValue = 77 });
|
||||
var after = await conn.CountByFields(PostgresDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("NumValue", "77")]);
|
||||
Expect.equal(after, 2, "There should have been 2 documents returned");
|
||||
}),
|
||||
TestCase("succeeds when no document is updated", async () =>
|
||||
@@ -662,11 +873,12 @@ public class PostgresCSharpExtensionTests
|
||||
Expect.equal(before, 0, "There should have been no documents returned");
|
||||
|
||||
// This not raising an exception is the test
|
||||
await conn.PatchByField(PostgresDb.TableName, Field.EQ("Value", "burgundy"), new { Foo = "green" });
|
||||
await conn.PatchByFields(PostgresDb.TableName, FieldMatch.Any, [Field.EQ("Value", "burgundy")],
|
||||
new { Foo = "green" });
|
||||
})
|
||||
}),
|
||||
TestList("PatchByContains", new[]
|
||||
{
|
||||
]),
|
||||
TestList("PatchByContains",
|
||||
[
|
||||
TestCase("succeeds when a document is updated", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
@@ -687,9 +899,9 @@ public class PostgresCSharpExtensionTests
|
||||
// This not raising an exception is the test
|
||||
await conn.PatchByContains(PostgresDb.TableName, new { Value = "burgundy" }, new { Foo = "green" });
|
||||
})
|
||||
}),
|
||||
TestList("PatchByJsonPath", new[]
|
||||
{
|
||||
]),
|
||||
TestList("PatchByJsonPath",
|
||||
[
|
||||
TestCase("succeeds when a document is updated", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
@@ -710,16 +922,16 @@ public class PostgresCSharpExtensionTests
|
||||
// This not raising an exception is the test
|
||||
await conn.PatchByJsonPath(PostgresDb.TableName, "$.NumValue ? (@ < 0)", new { Foo = "green" });
|
||||
})
|
||||
}),
|
||||
TestList("RemoveFieldsById", new[]
|
||||
{
|
||||
]),
|
||||
TestList("RemoveFieldsById",
|
||||
[
|
||||
TestCase("succeeds when multiple fields are removed", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
await conn.RemoveFieldsById(PostgresDb.TableName, "two", new[] { "Sub", "Value" });
|
||||
await conn.RemoveFieldsById(PostgresDb.TableName, "two", ["Sub", "Value"]);
|
||||
var updated = await Find.ById<string, JsonDocument>(PostgresDb.TableName, "two");
|
||||
Expect.isNotNull(updated, "The updated document should have been retrieved");
|
||||
Expect.equal(updated.Value, "", "The string value should have been removed");
|
||||
@@ -731,7 +943,7 @@ public class PostgresCSharpExtensionTests
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
await conn.RemoveFieldsById(PostgresDb.TableName, "two", new[] { "Sub" });
|
||||
await conn.RemoveFieldsById(PostgresDb.TableName, "two", ["Sub"]);
|
||||
var updated = await Find.ById<string, JsonDocument>(PostgresDb.TableName, "two");
|
||||
Expect.isNotNull(updated, "The updated document should have been retrieved");
|
||||
Expect.notEqual(updated.Value, "", "The string value should not have been removed");
|
||||
@@ -744,7 +956,7 @@ public class PostgresCSharpExtensionTests
|
||||
await LoadDocs();
|
||||
|
||||
// This not raising an exception is the test
|
||||
await conn.RemoveFieldsById(PostgresDb.TableName, "two", new[] { "AFieldThatIsNotThere" });
|
||||
await conn.RemoveFieldsById(PostgresDb.TableName, "two", ["AFieldThatIsNotThere"]);
|
||||
}),
|
||||
TestCase("succeeds when no document is matched", async () =>
|
||||
{
|
||||
@@ -752,19 +964,19 @@ public class PostgresCSharpExtensionTests
|
||||
await using var conn = MkConn(db);
|
||||
|
||||
// This not raising an exception is the test
|
||||
await conn.RemoveFieldsById(PostgresDb.TableName, "two", new[] { "Value" });
|
||||
await conn.RemoveFieldsById(PostgresDb.TableName, "two", ["Value"]);
|
||||
})
|
||||
}),
|
||||
TestList("RemoveFieldsByField", new[]
|
||||
{
|
||||
]),
|
||||
TestList("RemoveFieldsByFields",
|
||||
[
|
||||
TestCase("succeeds when multiple fields are removed", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
await conn.RemoveFieldsByField(PostgresDb.TableName, Field.EQ("NumValue", "17"),
|
||||
new[] { "Sub", "Value" });
|
||||
await conn.RemoveFieldsByFields(PostgresDb.TableName, FieldMatch.Any, [Field.EQ("NumValue", "17")],
|
||||
["Sub", "Value"]);
|
||||
var updated = await Find.ById<string, JsonDocument>(PostgresDb.TableName, "four");
|
||||
Expect.isNotNull(updated, "The updated document should have been retrieved");
|
||||
Expect.equal(updated.Value, "", "The string value should have been removed");
|
||||
@@ -776,7 +988,8 @@ public class PostgresCSharpExtensionTests
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
await conn.RemoveFieldsByField(PostgresDb.TableName, Field.EQ("NumValue", "17"), new[] { "Sub" });
|
||||
await conn.RemoveFieldsByFields(PostgresDb.TableName, FieldMatch.Any, [Field.EQ("NumValue", "17")],
|
||||
["Sub"]);
|
||||
var updated = await Find.ById<string, JsonDocument>(PostgresDb.TableName, "four");
|
||||
Expect.isNotNull(updated, "The updated document should have been retrieved");
|
||||
Expect.notEqual(updated.Value, "", "The string value should not have been removed");
|
||||
@@ -789,7 +1002,8 @@ public class PostgresCSharpExtensionTests
|
||||
await LoadDocs();
|
||||
|
||||
// This not raising an exception is the test
|
||||
await conn.RemoveFieldsByField(PostgresDb.TableName, Field.EQ("NumValue", "17"), new[] { "Nothing" });
|
||||
await conn.RemoveFieldsByFields(PostgresDb.TableName, FieldMatch.Any, [Field.EQ("NumValue", "17")],
|
||||
["Nothing"]);
|
||||
}),
|
||||
TestCase("succeeds when no document is matched", async () =>
|
||||
{
|
||||
@@ -797,20 +1011,19 @@ public class PostgresCSharpExtensionTests
|
||||
await using var conn = MkConn(db);
|
||||
|
||||
// This not raising an exception is the test
|
||||
await conn.RemoveFieldsByField(PostgresDb.TableName, Field.NE("Abracadabra", "apple"),
|
||||
new[] { "Value" });
|
||||
await conn.RemoveFieldsByFields(PostgresDb.TableName, FieldMatch.Any,
|
||||
[Field.NE("Abracadabra", "apple")], ["Value"]);
|
||||
})
|
||||
}),
|
||||
TestList("RemoveFieldsByContains", new[]
|
||||
{
|
||||
]),
|
||||
TestList("RemoveFieldsByContains",
|
||||
[
|
||||
TestCase("succeeds when multiple fields are removed", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
await conn.RemoveFieldsByContains(PostgresDb.TableName, new { NumValue = 17 },
|
||||
new[] { "Sub", "Value" });
|
||||
await conn.RemoveFieldsByContains(PostgresDb.TableName, new { NumValue = 17 }, ["Sub", "Value"]);
|
||||
var updated = await Find.ById<string, JsonDocument>(PostgresDb.TableName, "four");
|
||||
Expect.isNotNull(updated, "The updated document should have been retrieved");
|
||||
Expect.equal(updated.Value, "", "The string value should have been removed");
|
||||
@@ -822,7 +1035,7 @@ public class PostgresCSharpExtensionTests
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
await conn.RemoveFieldsByContains(PostgresDb.TableName, new { NumValue = 17 }, new[] { "Sub" });
|
||||
await conn.RemoveFieldsByContains(PostgresDb.TableName, new { NumValue = 17 }, ["Sub"]);
|
||||
var updated = await Find.ById<string, JsonDocument>(PostgresDb.TableName, "four");
|
||||
Expect.isNotNull(updated, "The updated document should have been retrieved");
|
||||
Expect.notEqual(updated.Value, "", "The string value should not have been removed");
|
||||
@@ -835,7 +1048,7 @@ public class PostgresCSharpExtensionTests
|
||||
await LoadDocs();
|
||||
|
||||
// This not raising an exception is the test
|
||||
await conn.RemoveFieldsByContains(PostgresDb.TableName, new { NumValue = 17 }, new[] { "Nothing" });
|
||||
await conn.RemoveFieldsByContains(PostgresDb.TableName, new { NumValue = 17 }, ["Nothing"]);
|
||||
}),
|
||||
TestCase("succeeds when no document is matched", async () =>
|
||||
{
|
||||
@@ -843,20 +1056,18 @@ public class PostgresCSharpExtensionTests
|
||||
await using var conn = MkConn(db);
|
||||
|
||||
// This not raising an exception is the test
|
||||
await conn.RemoveFieldsByContains(PostgresDb.TableName, new { Abracadabra = "apple" },
|
||||
new[] { "Value" });
|
||||
await conn.RemoveFieldsByContains(PostgresDb.TableName, new { Abracadabra = "apple" }, ["Value"]);
|
||||
})
|
||||
}),
|
||||
TestList("RemoveFieldsByJsonPath", new[]
|
||||
{
|
||||
]),
|
||||
TestList("RemoveFieldsByJsonPath",
|
||||
[
|
||||
TestCase("succeeds when multiple fields are removed", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
await conn.RemoveFieldsByJsonPath(PostgresDb.TableName, "$.NumValue ? (@ == 17)",
|
||||
new[] { "Sub", "Value" });
|
||||
await conn.RemoveFieldsByJsonPath(PostgresDb.TableName, "$.NumValue ? (@ == 17)", ["Sub", "Value"]);
|
||||
var updated = await Find.ById<string, JsonDocument>(PostgresDb.TableName, "four");
|
||||
Expect.isNotNull(updated, "The updated document should have been retrieved");
|
||||
Expect.equal(updated.Value, "", "The string value should have been removed");
|
||||
@@ -868,7 +1079,7 @@ public class PostgresCSharpExtensionTests
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
await conn.RemoveFieldsByJsonPath(PostgresDb.TableName, "$.NumValue ? (@ == 17)", new[] { "Sub" });
|
||||
await conn.RemoveFieldsByJsonPath(PostgresDb.TableName, "$.NumValue ? (@ == 17)", ["Sub"]);
|
||||
var updated = await Find.ById<string, JsonDocument>(PostgresDb.TableName, "four");
|
||||
Expect.isNotNull(updated, "The updated document should have been retrieved");
|
||||
Expect.notEqual(updated.Value, "", "The string value should not have been removed");
|
||||
@@ -881,7 +1092,7 @@ public class PostgresCSharpExtensionTests
|
||||
await LoadDocs();
|
||||
|
||||
// This not raising an exception is the test
|
||||
await conn.RemoveFieldsByJsonPath(PostgresDb.TableName, "$.NumValue ? (@ == 17)", new[] { "Nothing" });
|
||||
await conn.RemoveFieldsByJsonPath(PostgresDb.TableName, "$.NumValue ? (@ == 17)", ["Nothing"]);
|
||||
}),
|
||||
TestCase("succeeds when no document is matched", async () =>
|
||||
{
|
||||
@@ -889,12 +1100,11 @@ public class PostgresCSharpExtensionTests
|
||||
await using var conn = MkConn(db);
|
||||
|
||||
// This not raising an exception is the test
|
||||
await conn.RemoveFieldsByJsonPath(PostgresDb.TableName, "$.Abracadabra ? (@ == \"apple\")",
|
||||
new[] { "Value" });
|
||||
await conn.RemoveFieldsByJsonPath(PostgresDb.TableName, "$.Abracadabra ? (@ == \"apple\")", ["Value"]);
|
||||
})
|
||||
}),
|
||||
TestList("DeleteById", new[]
|
||||
{
|
||||
]),
|
||||
TestList("DeleteById",
|
||||
[
|
||||
TestCase("succeeds when a document is deleted", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
@@ -915,16 +1125,16 @@ public class PostgresCSharpExtensionTests
|
||||
var remaining = await conn.CountAll(PostgresDb.TableName);
|
||||
Expect.equal(remaining, 5, "There should have been 5 documents remaining");
|
||||
})
|
||||
}),
|
||||
TestList("DeleteByField", new[]
|
||||
{
|
||||
]),
|
||||
TestList("DeleteByFields",
|
||||
[
|
||||
TestCase("succeeds when documents are deleted", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
await conn.DeleteByField(PostgresDb.TableName, Field.NE("Value", "purple"));
|
||||
await conn.DeleteByFields(PostgresDb.TableName, FieldMatch.Any, [Field.NE("Value", "purple")]);
|
||||
var remaining = await conn.CountAll(PostgresDb.TableName);
|
||||
Expect.equal(remaining, 2, "There should have been 2 documents remaining");
|
||||
}),
|
||||
@@ -934,13 +1144,13 @@ public class PostgresCSharpExtensionTests
|
||||
await using var conn = MkConn(db);
|
||||
await LoadDocs();
|
||||
|
||||
await conn.DeleteByField(PostgresDb.TableName, Field.EQ("Value", "crimson"));
|
||||
await conn.DeleteByFields(PostgresDb.TableName, FieldMatch.Any, [Field.EQ("Value", "crimson")]);
|
||||
var remaining = await conn.CountAll(PostgresDb.TableName);
|
||||
Expect.equal(remaining, 5, "There should have been 5 documents remaining");
|
||||
})
|
||||
}),
|
||||
TestList("DeleteByContains", new[]
|
||||
{
|
||||
]),
|
||||
TestList("DeleteByContains",
|
||||
[
|
||||
TestCase("succeeds when documents are deleted", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
@@ -961,9 +1171,9 @@ public class PostgresCSharpExtensionTests
|
||||
var remaining = await conn.CountAll(PostgresDb.TableName);
|
||||
Expect.equal(remaining, 5, "There should have been 5 documents remaining");
|
||||
})
|
||||
}),
|
||||
TestList("DeleteByJsonPath", new[]
|
||||
{
|
||||
]),
|
||||
TestList("DeleteByJsonPath",
|
||||
[
|
||||
TestCase("succeeds when documents are deleted", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
@@ -984,6 +1194,6 @@ public class PostgresCSharpExtensionTests
|
||||
var remaining = await conn.CountAll(PostgresDb.TableName);
|
||||
Expect.equal(remaining, 5, "There should have been 5 documents remaining");
|
||||
})
|
||||
}),
|
||||
});
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user