Skip to content

Commit

Permalink
fix: ExceptionInfo - legacy type deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
alexyakunin committed Sep 18, 2023
1 parent ab20edf commit 5516a1a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Stl.Fusion.Authentication;
{
private static readonly ListFormat IdFormat = ListFormat.SlashSeparated;

public static UserIdentity None { get; } = default;
public static readonly UserIdentity None;
public static string DefaultSchema { get; } = "Default";

[DataMember(Order = 0), MemoryPackOrder(0)]
Expand Down
22 changes: 16 additions & 6 deletions src/Stl.Testing/TypeEvolutionTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,15 @@ public void CheckMessagePackByteSerializer(TOld value, ITestOutputHelper? output
{
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);
var bytes = buffer.WrittenMemory.ToArray();
Output?.WriteLine($"MessagePackByteSerializer: {JsonFormatter.Format(bytes)}");
s.Write(buffer, value);

bytes = buffer.WrittenMemory.ToArray();
var v0 = s.Read<TNew>(bytes, out var readLength);
AssertEqual(value, v0);
var v1 = s.Read<TNew>(bytes[readLength..]);
AssertEqual(value, v1);
}

// MemoryPack serializer
Expand All @@ -86,9 +91,14 @@ public void CheckMemoryPackByteSerializer(TOld value, ITestOutputHelper? output
{
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);
var bytes = buffer.WrittenMemory.ToArray();
Output?.WriteLine($"MemoryPackByteSerializer: {JsonFormatter.Format(bytes)}");
s.Write(buffer, value);

bytes = buffer.WrittenMemory.ToArray();
var v0 = s.Read<TNew>(bytes, out var readLength);
AssertEqual(value, v0);
var v1 = s.Read<TNew>(bytes[readLength..]);
AssertEqual(value, v1);
}
}
4 changes: 2 additions & 2 deletions src/Stl/Async/AsyncChain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ namespace Stl.Async;
[StructLayout(LayoutKind.Auto)]
public readonly record struct AsyncChain(string Name, Func<CancellationToken, Task> Start)
{
public static AsyncChain None { get; } = new("(no-operation)", _ => Task.CompletedTask);
public static AsyncChain NeverEnding { get; } = new("(never-ending)", _ => TaskExt.NeverEndingTask);
public static readonly AsyncChain None = new("(no-operation)", _ => Task.CompletedTask);
public static readonly AsyncChain NeverEnding = new("(never-ending)", _ => TaskExt.NeverEndingTask);

public AsyncChain(Func<CancellationToken, Task> start)
: this("(unnamed)", start) { }
Expand Down
4 changes: 2 additions & 2 deletions src/Stl/Serialization/ExceptionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Stl.Serialization;
private static readonly Type[] ExceptionCtorArgumentTypes1 = { typeof(string), typeof(Exception) };
private static readonly Type[] ExceptionCtorArgumentTypes2 = { typeof(string) };

public static ExceptionInfo None { get; } = default;
public static readonly ExceptionInfo None = default;
public static Func<TypeRef, Type>? UnknownExceptionTypeResolver { get; set; } = null;

private readonly string _message;
Expand Down Expand Up @@ -41,7 +41,7 @@ public ExceptionInfo(Exception? exception)
public override string ToString()
=> IsNone
? $"{GetType().Name}()"
: $"{GetType().Name}({TypeRef}, {JsonFormatter.Format(Message)})";
: $"{GetType().Name}({TypeRef.ToString()}, {JsonFormatter.Format(Message)})";

public Exception? ToException()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Stl.Tests/Serialization/ExceptionInfoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void BasicTest()
}

[Fact]
public void LegacyExceptionInfoTest()
public void OldExceptionInfoTest()
{
var t = new TypeEvolutionTester<OldExceptionInfo, ExceptionInfo>(
(li, i) => Assert.True(li.TypeRef == i.TypeRef && Equals(li.Message, i.Message)));
Expand Down
2 changes: 1 addition & 1 deletion tests/Stl.Tests/Serialization/OldExceptionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Stl.Tests.Serialization;
private static readonly Type[] ExceptionCtorArgumentTypes1 = { typeof(string), typeof(Exception) };
private static readonly Type[] ExceptionCtorArgumentTypes2 = { typeof(string) };

public static OldExceptionInfo None { get; } = default;
public static readonly OldExceptionInfo None = default;
public static Func<OldExceptionInfo, Exception?> ToExceptionConverter { get; set; } = DefaultToExceptionConverter;

private readonly string _message;
Expand Down

0 comments on commit 5516a1a

Please sign in to comment.