~ruther/NosSmooth

ref: c28ac80f49a6d98d6b396613a6e450f2c67f9583 NosSmooth/Tests/NosSmooth.Packets.Tests/Converters/Packets/SkiPacketConverterTests.cs -rw-r--r-- 2.2 KiB
c28ac80f — Rutherther feat(tests): add Ski packet test 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
//
//  SkiPacketConverterTests.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;
using NosSmooth.Packets.Extensions;
using NosSmooth.Packets.Packets;
using NosSmooth.Packets.Server.Groups;
using NosSmooth.Packets.Server.Skills;
using NosSmooth.PacketSerializer.Abstractions.Attributes;
using Xunit;

namespace NosSmooth.Packets.Tests.Converters.Packets;

/// <summary>
/// Tests ski packet serializer.
/// </summary>
public class SkiPacketConverterTests
{
    private readonly IPacketSerializer _packetSerializer;

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

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

    /// <summary>
    /// Tests that ski packet is deserialized correctly.
    /// </summary>
    [Fact]
    public void Converter_Deserialization_DeserializesCorrectly()
    {
        var deserialized = _packetSerializer.Deserialize
        (
            "ski 0 220 221 220 221 697|4 706|0 310 311",
            PacketSource.Server
        );

        Assert.True(deserialized.IsSuccess);
        var expected = new SkiPacket
        (
            0,
            220,
            221,
            new[]
            {
                new SkiSubPacket(220, null), new SkiSubPacket(221, null), new SkiSubPacket(697, 4),
                new SkiSubPacket(706, 0), new SkiSubPacket(310, null), new SkiSubPacket(311, null)
            }
        );
        var skiPacket = (SkiPacket)deserialized.Entity;
        Assert.Equal(expected.PrimarySkillVNum, skiPacket.PrimarySkillVNum);
        Assert.Equal(expected.SecondarySkillVNum, skiPacket.SecondarySkillVNum);
        Assert.Equal(expected.SkillSubPackets, skiPacket.SkillSubPackets);
    }
}
Do not follow this link