-
-
Notifications
You must be signed in to change notification settings - Fork 756
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed CursorParser to use '\' as escape instead of ':' (#7962)
Co-authored-by: Michael Staib <[email protected]>
- Loading branch information
1 parent
b55d403
commit 6b01035
Showing
27 changed files
with
400 additions
and
263 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
121 changes: 121 additions & 0 deletions
121
src/HotChocolate/Pagination/test/Pagination.EntityFramework.Tests/CursorFormatterTests.cs
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,121 @@ | ||
using System.Linq.Expressions; | ||
using System.Text; | ||
using System.Text.Unicode; | ||
using HotChocolate.Pagination.Expressions; | ||
using HotChocolate.Pagination.Serialization; | ||
|
||
namespace HotChocolate.Data; | ||
|
||
public class CursorFormatterTests | ||
{ | ||
[Fact] | ||
public void Format_Single_Key() | ||
{ | ||
// arrange | ||
var entity = new MyClass { Name = "test" }; | ||
Expression<Func<MyClass, object>> selector = x => x.Name; | ||
var serializer = new StringCursorKeySerializer(); | ||
|
||
// act | ||
var result = CursorFormatter.Format(entity, [new CursorKey(selector, serializer)]); | ||
|
||
// assert | ||
Assert.Equal("dGVzdA==", result); | ||
Assert.Equal("test", Encoding.UTF8.GetString(Convert.FromBase64String(result))); | ||
} | ||
|
||
[Fact] | ||
public void Format_Single_Key_With_Colon() | ||
{ | ||
// arrange | ||
var entity = new MyClass { Name = "test:test" }; | ||
Expression<Func<MyClass, object>> selector = x => x.Name; | ||
var serializer = new StringCursorKeySerializer(); | ||
|
||
// act | ||
var result = CursorFormatter.Format(entity, [new CursorKey(selector, serializer)]); | ||
|
||
// assert | ||
Assert.Equal("dGVzdFw6dGVzdA==", result); | ||
Assert.Equal("test\\:test", Encoding.UTF8.GetString(Convert.FromBase64String(result))); | ||
} | ||
|
||
[Fact] | ||
public void Format_Two_Keys() | ||
{ | ||
// arrange | ||
var entity = new MyClass { Name = "test", Description = "description" }; | ||
Expression<Func<MyClass, object?>> selector1 = x => x.Name; | ||
Expression<Func<MyClass, object?>> selector2 = x => x.Description; | ||
var serializer = new StringCursorKeySerializer(); | ||
|
||
// act | ||
var result = CursorFormatter.Format( | ||
entity, | ||
[ | ||
new CursorKey(selector1, serializer), | ||
new CursorKey(selector2, serializer) | ||
]); | ||
|
||
// assert | ||
Assert.Equal("dGVzdDpkZXNjcmlwdGlvbg==", result); | ||
Assert.Equal("test:description", Encoding.UTF8.GetString(Convert.FromBase64String(result))); | ||
} | ||
|
||
[Fact] | ||
public void Format_Two_Keys_With_Colon() | ||
{ | ||
// arrange | ||
var entity = new MyClass { Name = "test:345", Description = "description:123" }; | ||
Expression<Func<MyClass, object?>> selector1 = x => x.Name; | ||
Expression<Func<MyClass, object?>> selector2 = x => x.Description; | ||
var serializer = new StringCursorKeySerializer(); | ||
|
||
// act | ||
var result = CursorFormatter.Format( | ||
entity, | ||
[ | ||
new CursorKey(selector1, serializer), | ||
new CursorKey(selector2, serializer) | ||
]); | ||
|
||
// assert | ||
Assert.Equal("dGVzdFw6MzQ1OmRlc2NyaXB0aW9uXDoxMjM=", result); | ||
Assert.Equal("test\\:345:description\\:123", Encoding.UTF8.GetString(Convert.FromBase64String(result))); | ||
} | ||
|
||
[Fact] | ||
public void Format_And_Parse_Two_Keys_With_Colon() | ||
{ | ||
// arrange | ||
var entity = new MyClass { Name = "test:345", Description = "description:123" }; | ||
Expression<Func<MyClass, object?>> selector1 = x => x.Name; | ||
Expression<Func<MyClass, object?>> selector2 = x => x.Description; | ||
var serializer = new StringCursorKeySerializer(); | ||
|
||
// act | ||
var formatted = CursorFormatter.Format( | ||
entity, | ||
[ | ||
new CursorKey(selector1, serializer), | ||
new CursorKey(selector2, serializer) | ||
]); | ||
var parsed =CursorParser.Parse( | ||
formatted, | ||
[ | ||
new CursorKey(selector1, serializer), | ||
new CursorKey(selector2, serializer) | ||
]); | ||
|
||
// assert | ||
Assert.Equal("test:345", parsed[0]); | ||
Assert.Equal("description:123", parsed[1]); | ||
} | ||
|
||
public class MyClass | ||
{ | ||
public string Name { get; set; } = default!; | ||
|
||
public string? Description { get; set; } = default!; | ||
} | ||
} |
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
Oops, something went wrong.