forked from BeyondDimension/SteamTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModelsTest.cs
More file actions
96 lines (90 loc) · 3.02 KB
/
ModelsTest.cs
File metadata and controls
96 lines (90 loc) · 3.02 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
92
93
94
95
96
using Newtonsoft.Json;
using NUnit.Framework;
using System;
using System.Application.Models;
using System.Application.Services;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SJsonSerializer = System.Text.Json.JsonSerializer;
namespace System.Application
{
[TestFixture]
public class ModelsTest
{
static readonly object[] classs;
static ModelsTest()
{
classs = (from m in typeof(ApiResponse).Assembly.GetTypes()
let ctors = m.GetConstructors()
where m.IsClass && m.IsPublic && !m.IsAbstract && !m.IsGenericType
&& ctors.Length == 1
&& ctors[0].GetParameters().Length == 0
select Activator.CreateInstance(m)).ToArray();
}
[Test]
public void NewtonsoftJson()
{
foreach (var obj in classs)
{
try
{
var str = JsonConvert.SerializeObject(obj);
var obj2 = JsonConvert.DeserializeObject(str, obj.GetType());
var str2 = JsonConvert.SerializeObject(obj2);
Assert.IsTrue(str == str2, $"NJson not Equals, type: {obj.GetType()}");
}
catch (Exception ex)
{
throw new Exception($"NJson test error, type: {obj.GetType()}", ex);
}
}
}
[Test]
public void SystemTextJson()
{
foreach (var obj in classs)
{
try
{
var str = SJsonSerializer.Serialize(obj);
var obj2 = SJsonSerializer.Deserialize(str, obj.GetType());
var str2 = SJsonSerializer.Serialize(obj2);
Assert.IsTrue(str == str2, $"SJson not Equals, type: {obj.GetType()}");
}
catch (Exception ex)
{
throw new Exception($"SJson test error, type: {obj.GetType()}", ex);
}
}
}
[Test]
public void MessagePack()
{
foreach (var obj in classs)
{
try
{
var bytes = Serializable.SMP(obj.GetType(), obj);
var obj2 = Serializable.DMP(obj.GetType(), bytes);
var bytes2 = Serializable.SMP(obj2);
Assert.IsTrue(bytes.SequenceEqual(bytes2), $"MP not Equals, type: {obj.GetType()}");
}
catch (Exception ex)
{
throw new Exception($"MP test error, type: {obj.GetType()}", ex);
}
}
}
[Test]
public void Enums()
{
var appUpdateFailCodes = Enum2.GetAll<ApplicationUpdateFailCode>();
foreach (var item in appUpdateFailCodes)
{
_ = item.ToString2();
}
}
}
}