~ruther/NosSmooth

c28ac80f49a6d98d6b396613a6e450f2c67f9583 — Rutherther 2 years ago ee3b207
feat(tests): add Ski packet test
1 files changed, 67 insertions(+), 0 deletions(-)

A Tests/NosSmooth.Packets.Tests/Converters/Packets/SkiPacketConverterTests.cs
A Tests/NosSmooth.Packets.Tests/Converters/Packets/SkiPacketConverterTests.cs => Tests/NosSmooth.Packets.Tests/Converters/Packets/SkiPacketConverterTests.cs +67 -0
@@ 0,0 1,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);
    }
}
\ No newline at end of file

Do not follow this link