Skip to content

Commit 208dd31

Browse files
committed
Add unit tests
Fix type inference in some serializers Signed-off-by: Aliaksandr Kukrash <multiarc@gmail.com>
1 parent 96fc19b commit 208dd31

12 files changed

Lines changed: 5590 additions & 17 deletions
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
using SerializersBenchmark;
2+
using SerializersBenchmark.Models;
3+
using SerializersBenchmark.Serializers;
4+
using Xunit;
5+
6+
namespace SerializerBenchmarks.UnitTests;
7+
8+
public class BenchmarkTests
9+
{
10+
private readonly Benchmarks _benchmark = new()
11+
{
12+
N = 1
13+
};
14+
15+
[Fact]
16+
public void SetupTest()
17+
{
18+
_benchmark.SerializerType = typeof(MessagePack<DataItem>);
19+
_benchmark.Setup();
20+
Assert.NotNull(_benchmark.SerializerTest);
21+
Assert.NotNull(_benchmark.SerializedValue);
22+
Assert.NotEqual(0, _benchmark.SerializedValue.Length);
23+
}
24+
25+
[Theory]
26+
[InlineData(typeof(Ceras<DataItem>))]
27+
[InlineData(typeof(Utf8JsonSerializer<DataItem>))]
28+
[InlineData(typeof(MessagePack<DataItem>))]
29+
[InlineData(typeof(GroBuf<DataItem>))]
30+
[InlineData(typeof(Bois<DataItem>))]
31+
[InlineData(typeof(BoisLz4<DataItem>))]
32+
[InlineData(typeof(Jil<DataItem>))]
33+
[InlineData(typeof(ProtobufNet<DataItem>))]
34+
[InlineData(typeof(GoogleProtobuf<ProtobufDataItem>))]
35+
[InlineData(typeof(ServiceStack<DataItem>))]
36+
[InlineData(typeof(FastJson<DataItem>))]
37+
[InlineData(typeof(DataContractBinaryXml<DataItem>))]
38+
[InlineData(typeof(DataContract<DataItem>))]
39+
[InlineData(typeof(XmlSerializer<DataItem>))]
40+
[InlineData(typeof(NewtonsoftJson<DataItem>))]
41+
[InlineData(typeof(MsgPackCli<DataItem>))]
42+
[InlineData(typeof(SystemTextJson<DataItem>))]
43+
#if (NET6_0_OR_GREATER)
44+
[InlineData(typeof(MemoryPack<DataItem>))]
45+
[InlineData(typeof(BinaryPack<DataItem>))]
46+
[InlineData(typeof(SpanJson<DataItem>))]
47+
#endif
48+
#if NET8_0
49+
[InlineData(typeof(SystemTextJsonSourceGen<DataItem>))]
50+
#endif
51+
#if NET48
52+
[InlineData(typeof(BinaryFormatter<DataItem>))]
53+
#endif
54+
public void EndToEndTest(Type serializerType)
55+
{
56+
_benchmark.SerializerType = serializerType;
57+
_benchmark.Setup();
58+
var value = _benchmark.EndToEnd();
59+
Assert.NotNull(value);
60+
}
61+
62+
[Theory]
63+
[InlineData(typeof(Ceras<DataItem>))]
64+
[InlineData(typeof(Utf8JsonSerializer<DataItem>))]
65+
[InlineData(typeof(MessagePack<DataItem>))]
66+
[InlineData(typeof(GroBuf<DataItem>))]
67+
[InlineData(typeof(Bois<DataItem>))]
68+
[InlineData(typeof(BoisLz4<DataItem>))]
69+
[InlineData(typeof(Jil<DataItem>))]
70+
[InlineData(typeof(ProtobufNet<DataItem>))]
71+
[InlineData(typeof(GoogleProtobuf<ProtobufDataItem>))]
72+
[InlineData(typeof(ServiceStack<DataItem>))]
73+
[InlineData(typeof(FastJson<DataItem>))]
74+
[InlineData(typeof(DataContractBinaryXml<DataItem>))]
75+
[InlineData(typeof(DataContract<DataItem>))]
76+
[InlineData(typeof(XmlSerializer<DataItem>))]
77+
[InlineData(typeof(NewtonsoftJson<DataItem>))]
78+
[InlineData(typeof(MsgPackCli<DataItem>))]
79+
[InlineData(typeof(SystemTextJson<DataItem>))]
80+
#if (NET6_0_OR_GREATER)
81+
[InlineData(typeof(MemoryPack<DataItem>))]
82+
[InlineData(typeof(BinaryPack<DataItem>))]
83+
[InlineData(typeof(SpanJson<DataItem>))]
84+
#endif
85+
#if NET8_0
86+
[InlineData(typeof(SystemTextJsonSourceGen<DataItem>))]
87+
#endif
88+
#if NET48
89+
[InlineData(typeof(BinaryFormatter<DataItem>))]
90+
#endif
91+
public void SerializeTest(Type serializerType)
92+
{
93+
_benchmark.SerializerType = serializerType;
94+
_benchmark.Setup();
95+
var stream = _benchmark.TestSerialize();
96+
Assert.NotNull(stream);
97+
Assert.NotEqual(0, stream.Length);
98+
}
99+
100+
[Theory]
101+
[InlineData(typeof(Ceras<DataItem>))]
102+
[InlineData(typeof(Utf8JsonSerializer<DataItem>))]
103+
[InlineData(typeof(MessagePack<DataItem>))]
104+
[InlineData(typeof(GroBuf<DataItem>))]
105+
[InlineData(typeof(Bois<DataItem>))]
106+
[InlineData(typeof(BoisLz4<DataItem>))]
107+
[InlineData(typeof(Jil<DataItem>))]
108+
[InlineData(typeof(ProtobufNet<DataItem>))]
109+
[InlineData(typeof(GoogleProtobuf<ProtobufDataItem>))]
110+
[InlineData(typeof(ServiceStack<DataItem>))]
111+
[InlineData(typeof(FastJson<DataItem>))]
112+
[InlineData(typeof(DataContractBinaryXml<DataItem>))]
113+
[InlineData(typeof(DataContract<DataItem>))]
114+
[InlineData(typeof(XmlSerializer<DataItem>))]
115+
[InlineData(typeof(NewtonsoftJson<DataItem>))]
116+
[InlineData(typeof(MsgPackCli<DataItem>))]
117+
[InlineData(typeof(SystemTextJson<DataItem>))]
118+
#if (NET6_0_OR_GREATER)
119+
[InlineData(typeof(MemoryPack<DataItem>))]
120+
[InlineData(typeof(BinaryPack<DataItem>))]
121+
[InlineData(typeof(SpanJson<DataItem>))]
122+
#endif
123+
#if NET8_0
124+
[InlineData(typeof(SystemTextJsonSourceGen<DataItem>))]
125+
#endif
126+
#if NET48
127+
[InlineData(typeof(BinaryFormatter<DataItem>))]
128+
#endif
129+
public void DeserializeTest(Type serializerType)
130+
{
131+
_benchmark.SerializerType = serializerType;
132+
_benchmark.Setup();
133+
var value = _benchmark.TestDeserialize();
134+
Assert.NotNull(value);
135+
}
136+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net48;net6.0;net8.0</TargetFrameworks>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>disable</Nullable>
7+
<LangVersion>12.0</LangVersion>
8+
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
9+
</PropertyGroup>
10+
11+
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
12+
<PlatformTarget>x64</PlatformTarget>
13+
</PropertyGroup>
14+
15+
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
16+
<PlatformTarget>x64</PlatformTarget>
17+
</PropertyGroup>
18+
19+
<ItemGroup>
20+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
21+
<PackageReference Include="xunit" Version="2.8.0" />
22+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.0">
23+
<PrivateAssets>all</PrivateAssets>
24+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
25+
</PackageReference>
26+
</ItemGroup>
27+
28+
<ItemGroup>
29+
<ProjectReference Include="..\SerializersBenchmark\SerializersBenchmark.csproj" />
30+
</ItemGroup>
31+
32+
</Project>

0 commit comments

Comments
 (0)