-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for customizing JsonWriterOptions in JsonCoreSerial…
…izer
- Loading branch information
1 parent
9ccfd35
commit a30f81d
Showing
3 changed files
with
77 additions
and
7 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
48 changes: 48 additions & 0 deletions
48
src/KafkaFlow.UnitTests/Serializers/JsonCoreSerializerTests.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,48 @@ | ||
namespace KafkaFlow.UnitTests.Serializers | ||
{ | ||
using System.IO; | ||
using System.Text.Encodings.Web; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using KafkaFlow.Serializer; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
|
||
[TestClass] | ||
public class JsonCoreSerializerTests | ||
{ | ||
private readonly Mock<ISerializerContext> contextMock = new(); | ||
|
||
[TestMethod] | ||
public async Task SerializeAsync_PreventEscapeOfAccentedCharacter_SerializedObjectDoesNotHaveAccentedCharacterEscaped() | ||
{ | ||
// Arrange | ||
var message = new TestMessage { Text = "Café Façade" }; | ||
using var output = new MemoryStream(); | ||
|
||
var writerOptions = new JsonWriterOptions { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping }; | ||
|
||
var target = new JsonCoreSerializer(writerOptions); | ||
|
||
// Act | ||
await target.SerializeAsync(message, output, this.contextMock.Object); | ||
|
||
// Assert | ||
var result = GetStreamText(output); | ||
result.Should().Contain("Café Façade"); | ||
} | ||
|
||
private static string GetStreamText(MemoryStream output) | ||
{ | ||
output.Position = 0; | ||
var reader = new StreamReader(output); | ||
return reader.ReadToEnd(); | ||
} | ||
|
||
private class TestMessage | ||
{ | ||
public string Text { get; set; } | ||
} | ||
} | ||
} |