~ruther/NosSmooth

ref: ba49ad7e1b0431be4a22b3209670e439050b2548 NosSmooth/Tests/NosSmooth.Packets.Tests/Converters/Packets/MovePacketConverterTests.cs -rw-r--r-- 1.9 KiB
ba49ad7e — František Boháček Merge pull request #14 from Rutherther/packets-span 3 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
//
//  MovePacketConverterTests.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.Attributes;
using NosSmooth.Packets.Converters;
using NosSmooth.Packets.Enums;
using NosSmooth.Packets.Extensions;
using NosSmooth.Packets.Packets.Server.Entities;
using Xunit;

namespace NosSmooth.Packets.Tests.Converters.Packets;

/// <summary>
/// Tests <see cref="MovePacketConverter"/>.
/// </summary>
public class MovePacketConverterTests
{
    private readonly IPacketSerializer _packetSerializer;

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

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

    /// <summary>
    /// Tests that the converter serializes mv packet correctly.
    /// </summary>
    [Fact]
    public void Converter_Serialization_SerializesCorrectly()
    {
        MovePacket packet = new MovePacket(EntityType.Monster, 122, 15, 20, 10);
        var result = _packetSerializer.Serialize(packet);
        Assert.True(result.IsSuccess);

        Assert.Equal("mv 3 122 15 20 10", result.Entity);
    }

    /// <summary>
    /// Tests that the converter serializes mv packet correctly.
    /// </summary>
    [Fact]
    public void Converter_Deserialization_DeserializesCorrectly()
    {
        var packetString = "mv 3 122 15 20 10";
        var result = _packetSerializer.Deserialize(packetString, PacketSource.Server);
        Assert.True(result.IsSuccess);

        MovePacket actualPacket = new MovePacket(EntityType.Monster, 122, 15, 20, 10);
        Assert.Equal(result.Entity, actualPacket);
    }
}
Do not follow this link