forked from surrealdb/surrealdb.net
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ add Patch/PatchAll methods (surrealdb#48)
- Loading branch information
Showing
17 changed files
with
348 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System.Text; | ||
using SurrealDb.Net.Internals.Json; | ||
using SystemTextJsonPatch; | ||
|
||
namespace SurrealDb.Net.Tests; | ||
|
||
public class PatchAllTests | ||
{ | ||
[Theory] | ||
[InlineData("http://127.0.0.1:8000")] | ||
[InlineData("ws://127.0.0.1:8000/rpc")] | ||
public async Task ShouldPatchAllRecords(string url) | ||
{ | ||
IEnumerable<Post>? list = null; | ||
IEnumerable<Post>? results = null; | ||
|
||
Func<Task> func = async () => | ||
{ | ||
await using var surrealDbClientGenerator = new SurrealDbClientGenerator(); | ||
var dbInfo = surrealDbClientGenerator.GenerateDatabaseInfo(); | ||
|
||
string filePath = Path.Combine( | ||
AppDomain.CurrentDomain.BaseDirectory, | ||
"Schemas/post.surql" | ||
); | ||
string fileContent = File.ReadAllText(filePath, Encoding.UTF8); | ||
|
||
string query = fileContent; | ||
|
||
using var client = surrealDbClientGenerator.Create(url); | ||
await client.SignIn(new RootAuth { Username = "root", Password = "root" }); | ||
await client.Use(dbInfo.Namespace, dbInfo.Database); | ||
await client.Query(query); | ||
|
||
var jsonPatchDocument = new JsonPatchDocument<Post> | ||
{ | ||
Options = SurrealDbSerializerOptions.Default | ||
}; | ||
jsonPatchDocument.Replace(x => x.Content, "[Edit] Oops"); | ||
|
||
list = await client.Select<Post>("post"); | ||
|
||
results = await client.PatchAll("post", jsonPatchDocument); | ||
}; | ||
|
||
await func.Should().NotThrowAsync(); | ||
|
||
list.Should().NotBeNull().And.HaveCount(2); | ||
|
||
var expected = list!.Select( | ||
item => | ||
new Post | ||
{ | ||
Id = item.Id, | ||
Title = item.Title, | ||
Content = "[Edit] Oops", | ||
CreatedAt = item.CreatedAt, | ||
Status = item.Status, | ||
} | ||
); | ||
|
||
results.Should().BeEquivalentTo(expected); | ||
} | ||
} |
Oops, something went wrong.