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.
- Loading branch information
Showing
8 changed files
with
383 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using System.Text; | ||
|
||
namespace SurrealDb.Net.Tests; | ||
|
||
public class MergeAllTests | ||
{ | ||
[Theory] | ||
[InlineData("http://localhost:8000")] | ||
[InlineData("ws://localhost:8000/rpc")] | ||
public async Task ShouldMergeAllRecords(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 merge = new PostMergeData { Content = "[Edit] Oops" }; | ||
|
||
list = await client.Select<Post>("post"); | ||
|
||
results = await client.MergeAll<PostMergeData, Post>("post", merge); | ||
}; | ||
|
||
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); | ||
} | ||
|
||
[Theory] | ||
[InlineData("http://localhost:8000")] | ||
[InlineData("ws://localhost:8000/rpc")] | ||
public async Task ShouldMergeAllRecordsUsingDictionary(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 thing = new Thing("post", "first"); | ||
var data = new Dictionary<string, object> { { "content", "[Edit] Oops" } }; | ||
|
||
list = await client.Select<Post>("post"); | ||
|
||
results = await client.MergeAll<Post>("post", data); | ||
}; | ||
|
||
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); | ||
} | ||
} |
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,68 @@ | ||
using System.Text; | ||
|
||
namespace SurrealDb.Net.Tests; | ||
|
||
public class UpdateAllTests | ||
{ | ||
[Theory] | ||
[InlineData("http://localhost:8000")] | ||
[InlineData("ws://localhost:8000/rpc")] | ||
public async Task ShouldUpdateAllRecords(string url) | ||
{ | ||
IEnumerable<Post>? list = null; | ||
IEnumerable<Post>? results = null; | ||
|
||
var now = DateTime.UtcNow; | ||
|
||
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 postUpdate = new Post | ||
{ | ||
Title = "# Title", | ||
Content = "# Content", | ||
CreatedAt = now, | ||
Status = "PUBLISHED" | ||
}; | ||
|
||
list = await client.Select<Post>("post"); | ||
|
||
results = await client.UpdateAll("post", postUpdate); | ||
}; | ||
|
||
await func.Should().NotThrowAsync(); | ||
|
||
list.Should().NotBeNull().And.HaveCount(2); | ||
|
||
results.Should().NotBeNull(); | ||
|
||
var expected = list!.Select( | ||
item => | ||
new Post | ||
{ | ||
Id = item.Id, | ||
Title = "# Title", | ||
Content = "# Content", | ||
CreatedAt = now, | ||
Status = "PUBLISHED", | ||
} | ||
); | ||
|
||
results.Should().BeEquivalentTo(expected); | ||
} | ||
} |
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
Oops, something went wrong.