~ruther/NosSmooth

ref: 56dfefc0597f6a6683c109908e3b8bea46761f15 NosSmooth/Tests/NosSmooth.Packets.Tests/Converters/Packets/CListPacketConverterTests.cs -rw-r--r-- 5.2 KiB
56dfefc0 — Rutherther feat(tests): add tests structure 2 years ago
                                                                                
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
//
//  CListPacketConverterTests.cs
//
//  Copyright (c) František Boháček. All rights reserved.
//  Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Extensions.DependencyInjection;
using NosSmooth.Packets.Enums.Players;
using NosSmooth.Packets.Server.Login;
using NosSmooth.PacketSerializer;
using NosSmooth.PacketSerializer.Abstractions.Attributes;
using NosSmooth.PacketSerializer.Extensions;
using NosSmooth.PacketSerializer.Packets;
using Xunit;

namespace NosSmooth.Packets.Tests.Converters.Packets;

/// <summary>
/// Tests CListPacketConverter.
/// </summary>
public class CListPacketConverterTests
{
    private readonly IPacketSerializer _packetSerializer;

    /// <summary>
    /// Initializes a new instance of the <see cref="CListPacketConverterTests"/> class.
    /// </summary>
    public CListPacketConverterTests()
    {
        var provider = new ServiceCollection()
            .AddPacketSerialization()
            .BuildServiceProvider();

        _packetSerializer = provider.GetRequiredService<IPacketSerializer>();
        provider.GetRequiredService<IPacketTypesRepository>().AddDefaultPackets();
    }

    /// <summary>
    /// Tests that the serialization runs correctly.
    /// </summary>
    [Fact]
    public void Converter_Serialization_SerializesCorrectly()
    {
        var packet = new CListPacket
        (
            1,
            "derfy",
            0,
            SexType.Female,
            HairStyle.HairStyleA,
            HairColor.FlashPurple,
            0,
            PlayerClass.Archer,
            99,
            80,
            new CListEquipmentSubPacket
            (
                null,
                null,
                4452,
                4468,
                4468,
                4840,
                4131,
                null
            ),
            1,
            string.Empty,
            1,
            1,
            new[]
            {
                new CListPetSubPacket(0, 2105),
                new CListPetSubPacket(0, 319),
                new CListPetSubPacket(0, 2106),
                new CListPetSubPacket(0, 2107),
                new CListPetSubPacket(0, 2108),
                new CListPetSubPacket(0, 2100),
                new CListPetSubPacket(0, 2102),
                new CListPetSubPacket(0, 317),
                new CListPetSubPacket(null, null),
                new CListPetSubPacket(null, null),
                new CListPetSubPacket(null, null),
                new CListPetSubPacket(null, null),
                new CListPetSubPacket(null, null),
                new CListPetSubPacket(null, null),
                new CListPetSubPacket(null, null),
                new CListPetSubPacket(null, null),
                new CListPetSubPacket(null, null),
            },
            0,
            0
        );
        var packetResult = _packetSerializer.Serialize(packet);
        Assert.True(packetResult.IsSuccess);

        Assert.Equal
        (
            "clist 1 derfy 0 1 0 106 0 2 99 80 -1.-1.4452.4468.4840.4131.-1.-1 99  1 1 0.2105.0.319.0.2106.0.2107.0.2108.0.2100.0.2102.0.317.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1 0 0",
            packetResult.Entity
        );
    }

    /// <summary>
    /// Tests that the deserialization runs correctly.
    /// </summary>
    [Fact]
    public void Converter_Deserialization_DeserializesCorrectly()
    {
        var packetResult = _packetSerializer.Deserialize
        (
            "clist 2 KexpExp 0 1 0 9 0 0 22 0 -1.12.1.8.-1.-1.-1.-1.-1.-1 20  1 1 -1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1. 0 0",
            PacketSource.Server
        );
        Assert.True(packetResult.IsSuccess);

        var expectedPacket = new CListPacket
        (
            1,
            "derfy",
            0,
            SexType.Female,
            HairStyle.HairStyleA,
            HairColor.FlashPurple,
            0,
            PlayerClass.Archer,
            99,
            80,
            new CListEquipmentSubPacket
            (
                null,
                null,
                4452,
                4468,
                4840,
                4131,
                null,
                null
            ),
            1,
            string.Empty,
            1,
            1,
            new[]
            {
                new CListPetSubPacket(0, 2105),
                new CListPetSubPacket(0, 319),
                new CListPetSubPacket(0, 2106),
                new CListPetSubPacket(0, 2107),
                new CListPetSubPacket(0, 2108),
                new CListPetSubPacket(0, 2100),
                new CListPetSubPacket(0, 2102),
                new CListPetSubPacket(0, 317),
                new CListPetSubPacket(null, null),
                new CListPetSubPacket(null, null),
                new CListPetSubPacket(null, null),
                new CListPetSubPacket(null, null),
                new CListPetSubPacket(null, null),
                new CListPetSubPacket(null, null),
                new CListPetSubPacket(null, null),
                new CListPetSubPacket(null, null),
                new CListPetSubPacket(null, null),
            },
            0,
            0
        );
        Assert.Equal(expectedPacket, packetResult.Entity);
    }
}
Do not follow this link