RC4 changes (#7)
- Add `In` and `InArray` comparisons - Replace `Op` with `Comparison` (internal API, but was public) - Spell out comparisons in `Field` constructor functions Reviewed-on: #7
This commit was merged in pull request #7.
This commit is contained in:
@@ -221,7 +221,8 @@ public static class SqliteCSharpExtensionTests
|
||||
await using var conn = Sqlite.Configuration.DbConn();
|
||||
await LoadDocs();
|
||||
|
||||
var theCount = await conn.CountByFields(SqliteDb.TableName, FieldMatch.Any, [Field.EQ("Value", "purple")]);
|
||||
var theCount = await conn.CountByFields(SqliteDb.TableName, FieldMatch.Any,
|
||||
[Field.Equal("Value", "purple")]);
|
||||
Expect.equal(theCount, 2L, "There should have been 2 matching documents");
|
||||
}),
|
||||
TestList("ExistsById",
|
||||
@@ -253,7 +254,8 @@ public static class SqliteCSharpExtensionTests
|
||||
await using var conn = Sqlite.Configuration.DbConn();
|
||||
await LoadDocs();
|
||||
|
||||
var exists = await conn.ExistsByFields(SqliteDb.TableName, FieldMatch.Any, [Field.GE("NumValue", 10)]);
|
||||
var exists = await conn.ExistsByFields(SqliteDb.TableName, FieldMatch.Any,
|
||||
[Field.GreaterOrEqual("NumValue", 10)]);
|
||||
Expect.isTrue(exists, "There should have been existing documents");
|
||||
}),
|
||||
TestCase("succeeds when no matching documents exist", async () =>
|
||||
@@ -263,7 +265,7 @@ public static class SqliteCSharpExtensionTests
|
||||
await LoadDocs();
|
||||
|
||||
var exists =
|
||||
await conn.ExistsByFields(SqliteDb.TableName, FieldMatch.Any, [Field.EQ("Nothing", "none")]);
|
||||
await conn.ExistsByFields(SqliteDb.TableName, FieldMatch.Any, [Field.Equal("Nothing", "none")]);
|
||||
Expect.isFalse(exists, "There should not have been any existing documents");
|
||||
})
|
||||
]),
|
||||
@@ -357,7 +359,7 @@ public static class SqliteCSharpExtensionTests
|
||||
await LoadDocs();
|
||||
|
||||
var docs = await conn.FindByFields<JsonDocument>(SqliteDb.TableName, FieldMatch.Any,
|
||||
[Field.GT("NumValue", 15)]);
|
||||
[Field.Greater("NumValue", 15)]);
|
||||
Expect.equal(docs.Count, 2, "There should have been two documents returned");
|
||||
}),
|
||||
TestCase("succeeds when documents are not found", async () =>
|
||||
@@ -367,7 +369,7 @@ public static class SqliteCSharpExtensionTests
|
||||
await LoadDocs();
|
||||
|
||||
var docs = await conn.FindByFields<JsonDocument>(SqliteDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("Value", "mauve")]);
|
||||
[Field.Equal("Value", "mauve")]);
|
||||
Expect.isEmpty(docs, "There should have been no documents returned");
|
||||
})
|
||||
]),
|
||||
@@ -380,7 +382,7 @@ public static class SqliteCSharpExtensionTests
|
||||
await LoadDocs();
|
||||
|
||||
var docs = await conn.FindByFieldsOrdered<JsonDocument>(SqliteDb.TableName, FieldMatch.Any,
|
||||
[Field.GT("NumValue", 15)], [Field.Named("Id")]);
|
||||
[Field.Greater("NumValue", 15)], [Field.Named("Id")]);
|
||||
Expect.equal(string.Join('|', docs.Select(x => x.Id)), "five|four",
|
||||
"There should have been two documents returned");
|
||||
}),
|
||||
@@ -391,7 +393,7 @@ public static class SqliteCSharpExtensionTests
|
||||
await LoadDocs();
|
||||
|
||||
var docs = await conn.FindByFieldsOrdered<JsonDocument>(SqliteDb.TableName, FieldMatch.Any,
|
||||
[Field.GT("NumValue", 15)], [Field.Named("Id DESC")]);
|
||||
[Field.Greater("NumValue", 15)], [Field.Named("Id DESC")]);
|
||||
Expect.equal(string.Join('|', docs.Select(x => x.Id)), "four|five",
|
||||
"There should have been two documents returned");
|
||||
})
|
||||
@@ -405,7 +407,7 @@ public static class SqliteCSharpExtensionTests
|
||||
await LoadDocs();
|
||||
|
||||
var doc = await conn.FindFirstByFields<JsonDocument>(SqliteDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("Value", "another")]);
|
||||
[Field.Equal("Value", "another")]);
|
||||
Expect.isNotNull(doc, "There should have been a document returned");
|
||||
Expect.equal(doc!.Id, "two", "The incorrect document was returned");
|
||||
}),
|
||||
@@ -416,7 +418,7 @@ public static class SqliteCSharpExtensionTests
|
||||
await LoadDocs();
|
||||
|
||||
var doc = await conn.FindFirstByFields<JsonDocument>(SqliteDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("Sub.Foo", "green")]);
|
||||
[Field.Equal("Sub.Foo", "green")]);
|
||||
Expect.isNotNull(doc, "There should have been a document returned");
|
||||
Expect.contains(["two", "four"], doc!.Id, "An incorrect document was returned");
|
||||
}),
|
||||
@@ -427,7 +429,7 @@ public static class SqliteCSharpExtensionTests
|
||||
await LoadDocs();
|
||||
|
||||
var doc = await conn.FindFirstByFields<JsonDocument>(SqliteDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("Value", "absent")]);
|
||||
[Field.Equal("Value", "absent")]);
|
||||
Expect.isNull(doc, "There should not have been a document returned");
|
||||
})
|
||||
]),
|
||||
@@ -440,7 +442,7 @@ public static class SqliteCSharpExtensionTests
|
||||
await LoadDocs();
|
||||
|
||||
var doc = await conn.FindFirstByFieldsOrdered<JsonDocument>(SqliteDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("Sub.Foo", "green")], [Field.Named("Sub.Bar")]);
|
||||
[Field.Equal("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");
|
||||
}),
|
||||
@@ -451,7 +453,7 @@ public static class SqliteCSharpExtensionTests
|
||||
await LoadDocs();
|
||||
|
||||
var doc = await conn.FindFirstByFieldsOrdered<JsonDocument>(SqliteDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("Sub.Foo", "green")], [Field.Named("Sub.Bar DESC")]);
|
||||
[Field.Equal("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");
|
||||
})
|
||||
@@ -547,9 +549,9 @@ public static class SqliteCSharpExtensionTests
|
||||
await using var conn = Sqlite.Configuration.DbConn();
|
||||
await LoadDocs();
|
||||
|
||||
await conn.PatchByFields(SqliteDb.TableName, FieldMatch.Any, [Field.EQ("Value", "purple")],
|
||||
await conn.PatchByFields(SqliteDb.TableName, FieldMatch.Any, [Field.Equal("Value", "purple")],
|
||||
new { NumValue = 77 });
|
||||
var after = await conn.CountByFields(SqliteDb.TableName, FieldMatch.Any, [Field.EQ("NumValue", 77)]);
|
||||
var after = await conn.CountByFields(SqliteDb.TableName, FieldMatch.Any, [Field.Equal("NumValue", 77)]);
|
||||
Expect.equal(after, 2L, "There should have been 2 documents returned");
|
||||
}),
|
||||
TestCase("succeeds when no document is updated", async () =>
|
||||
@@ -560,7 +562,7 @@ public static class SqliteCSharpExtensionTests
|
||||
Expect.isEmpty(before, "There should have been no documents returned");
|
||||
|
||||
// This not raising an exception is the test
|
||||
await conn.PatchByFields(SqliteDb.TableName, FieldMatch.Any, [Field.EQ("Value", "burgundy")],
|
||||
await conn.PatchByFields(SqliteDb.TableName, FieldMatch.Any, [Field.Equal("Value", "burgundy")],
|
||||
new { Foo = "green" });
|
||||
})
|
||||
]),
|
||||
@@ -604,7 +606,7 @@ public static class SqliteCSharpExtensionTests
|
||||
await using var conn = Sqlite.Configuration.DbConn();
|
||||
await LoadDocs();
|
||||
|
||||
await conn.RemoveFieldsByFields(SqliteDb.TableName, FieldMatch.Any, [Field.EQ("NumValue", 17)],
|
||||
await conn.RemoveFieldsByFields(SqliteDb.TableName, FieldMatch.Any, [Field.Equal("NumValue", 17)],
|
||||
["Sub"]);
|
||||
var updated = await Find.ById<string, JsonDocument>(SqliteDb.TableName, "four");
|
||||
Expect.isNotNull(updated, "The updated document should have been retrieved");
|
||||
@@ -617,7 +619,7 @@ public static class SqliteCSharpExtensionTests
|
||||
await LoadDocs();
|
||||
|
||||
// This not raising an exception is the test
|
||||
await conn.RemoveFieldsByFields(SqliteDb.TableName, FieldMatch.Any, [Field.EQ("NumValue", 17)],
|
||||
await conn.RemoveFieldsByFields(SqliteDb.TableName, FieldMatch.Any, [Field.Equal("NumValue", 17)],
|
||||
["Nothing"]);
|
||||
}),
|
||||
TestCase("succeeds when no document is matched", async () =>
|
||||
@@ -626,8 +628,8 @@ public static class SqliteCSharpExtensionTests
|
||||
await using var conn = Sqlite.Configuration.DbConn();
|
||||
|
||||
// This not raising an exception is the test
|
||||
await conn.RemoveFieldsByFields(SqliteDb.TableName, FieldMatch.Any, [Field.NE("Abracadabra", "apple")],
|
||||
["Value"]);
|
||||
await conn.RemoveFieldsByFields(SqliteDb.TableName, FieldMatch.Any,
|
||||
[Field.NotEqual("Abracadabra", "apple")], ["Value"]);
|
||||
})
|
||||
]),
|
||||
TestList("DeleteById",
|
||||
@@ -661,7 +663,7 @@ public static class SqliteCSharpExtensionTests
|
||||
await using var conn = Sqlite.Configuration.DbConn();
|
||||
await LoadDocs();
|
||||
|
||||
await conn.DeleteByFields(SqliteDb.TableName, FieldMatch.Any, [Field.NE("Value", "purple")]);
|
||||
await conn.DeleteByFields(SqliteDb.TableName, FieldMatch.Any, [Field.NotEqual("Value", "purple")]);
|
||||
var remaining = await conn.CountAll(SqliteDb.TableName);
|
||||
Expect.equal(remaining, 2L, "There should have been 2 documents remaining");
|
||||
}),
|
||||
@@ -671,7 +673,7 @@ public static class SqliteCSharpExtensionTests
|
||||
await using var conn = Sqlite.Configuration.DbConn();
|
||||
await LoadDocs();
|
||||
|
||||
await conn.DeleteByFields(SqliteDb.TableName, FieldMatch.Any, [Field.EQ("Value", "crimson")]);
|
||||
await conn.DeleteByFields(SqliteDb.TableName, FieldMatch.Any, [Field.Equal("Value", "crimson")]);
|
||||
var remaining = await conn.CountAll(SqliteDb.TableName);
|
||||
Expect.equal(remaining, 5L, "There should have been 5 documents remaining");
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user