//
// PinitPacketConverterTest.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 NosCore.Shared.Enumerations;
using NosSmooth.Packets.Attributes;
using NosSmooth.Packets.Converters;
using NosSmooth.Packets.Extensions;
using NosSmooth.Packets.Packets.Server.Groups;
using NosSmooth.Packets.Packets.Server.Map;
using Xunit;
namespace NosSmooth.Packets.Tests.Converters.Packets;
///
/// Tests .
///
public class PinitPacketConverterTest
{
private readonly IPacketSerializer _packetSerializer;
///
/// Initializes a new instance of the class.
///
public PinitPacketConverterTest()
{
var provider = new ServiceCollection()
.AddSingleton()
.AddPacketSerialization()
.BuildServiceProvider();
_packetSerializer = provider.GetRequiredService();
}
///
/// Tests that the converter serializes mv packet correctly.
///
[Fact]
public void Converter_Serialization_SerializesCorrectly()
{
var packet = new PinitPacket(2, new[]
{
new PinitSubPacket(VisualType.Npc, 345377, 0, 83, "Kliff", -1, 319, 1, 0),
new PinitSubPacket(VisualType.Npc, 345384, 1, 83, "@", -1, 2105, 0, 0)
});
var result = _packetSerializer.Serialize(packet);
Assert.True(result.IsSuccess);
Assert.Equal("pinit 2 2|345377|0|83|Kliff|-1|319|1|0 2|345384|1|83|@|-1|2105|0|0", result.Entity);
}
///
/// Tests that the converter serializes mv packet correctly.
///
[Fact]
public void Converter_Deserialization_DeserializesCorrectly()
{
var packetString = "pinit 2 2|345377|0|83|Kliff|-1|319|1|0 2|345384|1|83|@|-1|2105|0|0";
var result = _packetSerializer.Deserialize(packetString, PacketSource.Server);
Assert.True(result.IsSuccess);
var actualPacket = new PinitPacket(2, new[]
{
new PinitSubPacket(VisualType.Npc, 345377, 0, 83, "Kliff", -1, 319, 1, 0),
new PinitSubPacket(VisualType.Npc, 345384, 1, 83, "@", -1, 2105, 0, 0)
});
Assert.Equal(result.Entity, actualPacket);
}
}