-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: get rid of some legacy code related to ExceptionInfo
- Loading branch information
1 parent
b80168b
commit ab20edf
Showing
13 changed files
with
284 additions
and
131 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,94 @@ | ||
using System.Text; | ||
using FluentAssertions; | ||
using Microsoft.Toolkit.HighPerformance.Buffers; | ||
using Newtonsoft.Json; | ||
using Xunit.Abstractions; | ||
|
||
namespace Stl.Testing; | ||
|
||
public class TypeEvolutionTester<TOld, TNew> | ||
{ | ||
public Action<TOld, TNew> AssertEqual { get; } | ||
public JsonSerializerOptions SystemJsonOptions { get; set; } | ||
public JsonSerializerSettings NewtonsoftJsonSettings { get; set; } | ||
public ITestOutputHelper? Output { get; } | ||
|
||
public TypeEvolutionTester(Action<TOld, TNew> assertEqual, ITestOutputHelper? output = null) | ||
{ | ||
AssertEqual = assertEqual; | ||
Output = output; | ||
SystemJsonOptions = MemberwiseCloner.Invoke(SystemJsonSerializer.DefaultOptions); | ||
NewtonsoftJsonSettings = MemberwiseCloner.Invoke(NewtonsoftJsonSerializer.DefaultSettings); | ||
NewtonsoftJsonSettings.Formatting = Formatting.Indented; | ||
} | ||
|
||
public void CheckAllSerializers(TOld value) | ||
{ | ||
CheckSystemJsonSerializer(value); | ||
CheckNewtonsoftJsonSerializer(value); | ||
CheckMessagePackByteSerializer(value); | ||
CheckMemoryPackByteSerializer(value); | ||
} | ||
|
||
// System.Text.Json serializer | ||
|
||
public void CheckSystemJsonSerializer(TOld value) | ||
{ | ||
var s = new SystemJsonSerializer(SystemJsonOptions); | ||
var json = s.Write(value); | ||
Output?.WriteLine($"SystemJsonSerializer: {json}"); | ||
var v0 = s.Read<TNew>(json); | ||
AssertEqual(value, v0); | ||
|
||
using var buffer = new ArrayPoolBufferWriter<byte>(); | ||
s.Write(buffer, value); | ||
var bytes = buffer.WrittenMemory; | ||
var json2 = Encoding.UTF8.GetDecoder().Convert(bytes.Span); | ||
json2.Should().Be(json); | ||
var v1 = s.Read<TNew>(bytes); | ||
AssertEqual(value, v1); | ||
} | ||
|
||
// Newtonsoft.Json serializer | ||
|
||
public void CheckNewtonsoftJsonSerializer(TOld value, ITestOutputHelper? output = null) | ||
{ | ||
var s = new NewtonsoftJsonSerializer(NewtonsoftJsonSettings); | ||
var json = s.Write(value); | ||
Output?.WriteLine($"NewtonsoftJsonSerializer: {json}"); | ||
var v0 = s.Read<TNew>(json); | ||
AssertEqual(value, v0); | ||
|
||
using var buffer = new ArrayPoolBufferWriter<byte>(); | ||
s.Write(buffer, value); | ||
var bytes = buffer.WrittenMemory; | ||
var json2 = Encoding.UTF8.GetDecoder().Convert(bytes.Span); | ||
json2.Should().Be(json); | ||
var v1 = s.Read<TNew>(bytes); | ||
AssertEqual(value, v1); | ||
} | ||
|
||
// MessagePack serializer | ||
|
||
public void CheckMessagePackByteSerializer(TOld value, ITestOutputHelper? output = null) | ||
{ | ||
var s = new MessagePackByteSerializer(); | ||
using var buffer = s.Write(value); | ||
var b0 = buffer.WrittenMemory.ToArray(); | ||
Output?.WriteLine($"MessagePackByteSerializer: {JsonFormatter.Format(b0)}"); | ||
var v0 = s.Read<TNew>(b0); | ||
AssertEqual(value, v0); | ||
} | ||
|
||
// MemoryPack serializer | ||
|
||
public void CheckMemoryPackByteSerializer(TOld value, ITestOutputHelper? output = null) | ||
{ | ||
var s = new MemoryPackByteSerializer(); | ||
using var buffer = s.Write(value); | ||
var b0 = buffer.WrittenMemory.ToArray(); | ||
Output?.WriteLine($"MemoryPackByteSerializer: {JsonFormatter.Format(b0)}"); | ||
var v0 = s.Read<TNew>(b0); | ||
AssertEqual(value, v0); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
using System.Buffers; | ||
|
||
namespace Stl.Serialization; | ||
|
||
public interface ITextSerializer : IByteSerializer | ||
|
This file was deleted.
Oops, something went wrong.
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.