forked from VerifyTests/Verify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better task serialization (VerifyTests#512)
- Loading branch information
1 parent
2a3b735
commit 61083a0
Showing
14 changed files
with
401 additions
and
46 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
Large diffs are not rendered by default.
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
41 changes: 41 additions & 0 deletions
41
src/Verify.Tests/Serialization/SerializationTests.Tasks.Core.verified.txt
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,41 @@ | ||
{ | ||
finished: { | ||
Status: RanToCompletion | ||
}, | ||
running: { | ||
Status: WaitingForActivation | ||
}, | ||
withResult: { | ||
Status: RanToCompletion, | ||
Result: Value | ||
}, | ||
withException: { | ||
Status: Faulted, | ||
Exception: { | ||
Type: AggregateException, | ||
InnerExceptions: [ | ||
{ | ||
Type: Exception, | ||
Message: the exception | ||
} | ||
], | ||
Message: One or more errors occurred. (the exception) | ||
} | ||
}, | ||
withExceptionAndResult: { | ||
Status: Faulted, | ||
Exception: { | ||
Type: AggregateException, | ||
InnerExceptions: [ | ||
{ | ||
Type: Exception, | ||
Message: the exception | ||
} | ||
], | ||
Message: One or more errors occurred. (the exception) | ||
} | ||
}, | ||
canceledAndResult: { | ||
Status: Canceled | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/Verify.Tests/Serialization/SerializationTests.Tasks.DotNet.verified.txt
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,41 @@ | ||
{ | ||
finished: { | ||
Status: RanToCompletion | ||
}, | ||
running: { | ||
Status: WaitingForActivation | ||
}, | ||
withResult: { | ||
Status: RanToCompletion, | ||
Result: Value | ||
}, | ||
withException: { | ||
Status: Faulted, | ||
Exception: { | ||
Type: AggregateException, | ||
InnerExceptions: [ | ||
{ | ||
Type: Exception, | ||
Message: the exception | ||
} | ||
], | ||
Message: One or more errors occurred. (the exception) | ||
} | ||
}, | ||
withExceptionAndResult: { | ||
Status: Faulted, | ||
Exception: { | ||
Type: AggregateException, | ||
InnerExceptions: [ | ||
{ | ||
Type: Exception, | ||
Message: the exception | ||
} | ||
], | ||
Message: One or more errors occurred. (the exception) | ||
} | ||
}, | ||
canceledAndResult: { | ||
Status: Canceled | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/Verify.Tests/Serialization/SerializationTests.Tasks.Net.verified.txt
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,41 @@ | ||
{ | ||
finished: { | ||
Status: RanToCompletion | ||
}, | ||
running: { | ||
Status: WaitingForActivation | ||
}, | ||
withResult: { | ||
Status: RanToCompletion, | ||
Result: Value | ||
}, | ||
withException: { | ||
Status: Faulted, | ||
Exception: { | ||
Type: AggregateException, | ||
InnerExceptions: [ | ||
{ | ||
Type: Exception, | ||
Message: the exception | ||
} | ||
], | ||
Message: One or more errors occurred. | ||
} | ||
}, | ||
withExceptionAndResult: { | ||
Status: Faulted, | ||
Exception: { | ||
Type: AggregateException, | ||
InnerExceptions: [ | ||
{ | ||
Type: Exception, | ||
Message: the exception | ||
} | ||
], | ||
Message: One or more errors occurred. | ||
} | ||
}, | ||
canceledAndResult: { | ||
Status: Canceled | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/Verify.Tests/Serialization/SerializationTests.Tasks.verified.txt
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,41 @@ | ||
{ | ||
finished: { | ||
Status: RanToCompletion | ||
}, | ||
running: { | ||
Status: WaitingForActivation | ||
}, | ||
withResult: { | ||
Status: RanToCompletion, | ||
Result: Value | ||
}, | ||
withException: { | ||
Status: Faulted, | ||
Exception: { | ||
Type: AggregateException, | ||
InnerExceptions: [ | ||
{ | ||
Type: Exception, | ||
Message: the exception | ||
} | ||
], | ||
Message: One or more errors occurred. | ||
} | ||
}, | ||
withExceptionAndResult: { | ||
Status: Faulted, | ||
Exception: { | ||
Type: AggregateException, | ||
InnerExceptions: [ | ||
{ | ||
Type: Exception, | ||
Message: the exception | ||
} | ||
], | ||
Message: One or more errors occurred. | ||
} | ||
}, | ||
canceledAndResult: { | ||
Status: Canceled | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Verify.Tests/Serialization/SerializationTests.ValueTasks.DotNet.verified.txt
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,21 @@ | ||
{ | ||
withResult: { | ||
IsCanceled: false, | ||
IsCompleted: true, | ||
IsFaulted: false, | ||
Result: Value | ||
}, | ||
withException: { | ||
IsCanceled: false, | ||
IsCompleted: true, | ||
IsFaulted: true | ||
}, | ||
withExceptionAndResult: { | ||
IsCanceled: false, | ||
IsCompleted: true, | ||
IsFaulted: true | ||
}, | ||
canceledAndResult: { | ||
Status: Canceled | ||
} | ||
} |
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,46 @@ | ||
class TaskConverter : | ||
WriteOnlyJsonConverter<Task> | ||
{ | ||
public override void Write(VerifyJsonWriter writer, Task task) | ||
{ | ||
writer.WriteStartObject(); | ||
writer.WriteProperty(task, task.Status, "Status"); | ||
|
||
if (task.CreationOptions != TaskCreationOptions.None) | ||
{ | ||
writer.WriteProperty(task, task.CreationOptions, "CreationOptions"); | ||
} | ||
|
||
writer.WriteProperty(task, task.Exception, "Exception"); | ||
WriteResult(writer, task); | ||
|
||
writer.WriteEndObject(); | ||
} | ||
|
||
static void WriteResult(VerifyJsonWriter writer, Task task) | ||
{ | ||
if (!task.IsCompleted || | ||
task.IsCanceled || | ||
task.IsFaulted) | ||
{ | ||
return; | ||
} | ||
|
||
var type = task.GetType(); | ||
|
||
if (!type.IsGenericType) | ||
{ | ||
return; | ||
} | ||
|
||
var name = type.GenericTypeArguments.First().Name; | ||
if (name == "VoidTaskResult") | ||
{ | ||
return; | ||
} | ||
|
||
var resultProperty = type.GetProperty("Result")!; | ||
var result = resultProperty.GetValue(task); | ||
writer.WriteProperty(task, result, "Result"); | ||
} | ||
} |
Oops, something went wrong.