-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAsyncSerializerTests.cs
More file actions
91 lines (86 loc) · 3.52 KB
/
AsyncSerializerTests.cs
File metadata and controls
91 lines (86 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using FluentAssertions;
using SerializersBenchmark.Base;
using SerializersBenchmark.Models;
using SerializersBenchmark.Serializers;
using Xunit;
namespace SerializerBenchmarks.UnitTests;
public class AsyncSerializerTests
{
[Theory]
[InlineData(typeof(Ceras<DataItem>))]
[InlineData(typeof(Utf8JsonSerializer<DataItem>))]
[InlineData(typeof(MessagePack<DataItem>))]
[InlineData(typeof(GroBuf<DataItem>))]
[InlineData(typeof(Bois<DataItem>))]
[InlineData(typeof(BoisLz4<DataItem>))]
[InlineData(typeof(Jil<DataItem>))]
[InlineData(typeof(ProtobufNet<DataItem>))]
[InlineData(typeof(GoogleProtobuf<ProtobufDataItem>))]
[InlineData(typeof(ServiceStack<DataItem>))]
[InlineData(typeof(FastJson<DataItem>))]
[InlineData(typeof(DataContractBinaryXml<DataItem>))]
[InlineData(typeof(DataContract<DataItem>))]
[InlineData(typeof(XmlSerializer<DataItem>))]
[InlineData(typeof(NewtonsoftJson<DataItem>))]
[InlineData(typeof(MsgPackCli<DataItem>))]
[InlineData(typeof(MsgPackCliDefaultAsync<DataItem>))]
[InlineData(typeof(SystemTextJson<DataItem>))]
#if (NET6_0_OR_GREATER)
[InlineData(typeof(MemoryPack<DataItemMemoryPack>))]
[InlineData(typeof(BinaryPack<DataItem>))]
[InlineData(typeof(SpanJson<DataItem>))]
[InlineData(typeof(SystemTextJsonSourceGen<DataItem>))]
#endif
#if NET48
[InlineData(typeof(BinaryFormatter<DataItem>))]
#endif
public async Task SerializeAsyncTest(Type serializerType)
{
var serializer = serializerType.CreateSerializerInstance();
Assert.NotNull(serializer);
serializer.Setup(1);
var memory = new MemoryStream();
await serializer.SerializeAsync(serializer.TestDataObject, memory);
Assert.NotEqual(0, memory.Length);
}
[Theory]
[InlineData(typeof(Ceras<DataItem>))]
[InlineData(typeof(Utf8JsonSerializer<DataItem>))]
[InlineData(typeof(MessagePack<DataItem>))]
[InlineData(typeof(GroBuf<DataItem>))]
[InlineData(typeof(Bois<DataItem>))]
[InlineData(typeof(BoisLz4<DataItem>))]
[InlineData(typeof(Jil<DataItem>))]
[InlineData(typeof(ProtobufNet<DataItem>))]
[InlineData(typeof(GoogleProtobuf<ProtobufDataItem>))]
[InlineData(typeof(ServiceStack<DataItem>))]
[InlineData(typeof(FastJson<DataItem>))]
[InlineData(typeof(DataContractBinaryXml<DataItem>))]
[InlineData(typeof(DataContract<DataItem>))]
[InlineData(typeof(XmlSerializer<DataItem>))]
[InlineData(typeof(NewtonsoftJson<DataItem>))]
[InlineData(typeof(MsgPackCli<DataItem>))]
[InlineData(typeof(MsgPackCliDefaultAsync<DataItem>))]
[InlineData(typeof(SystemTextJson<DataItem>))]
#if (NET6_0_OR_GREATER)
[InlineData(typeof(MemoryPack<DataItemMemoryPack>))]
[InlineData(typeof(BinaryPack<DataItem>))]
[InlineData(typeof(SpanJson<DataItem>))]
[InlineData(typeof(SystemTextJsonSourceGen<DataItem>))]
#endif
#if NET48
[InlineData(typeof(BinaryFormatter<DataItem>))]
#endif
public async Task DeserializeAsyncTest(Type serializerType)
{
var serializer = serializerType.CreateSerializerInstance();
Assert.NotNull(serializer);
serializer.Setup(1);
var stream = new MemoryStream();
await serializer.SerializeAsync(serializer.TestDataObject, stream);
stream.Position = 0;
var result = await serializer.DeserializeAsync(stream);
Assert.NotNull(result);
result.Should().BeEquivalentTo(serializer.TestDataObject);
}
}