From 6334c0f5e711b3d9567687ae3ebf72fa41691b43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Sun, 15 Jan 2023 19:50:14 +0100 Subject: [PATCH] tests: add ptctl deserialization test --- .../Packets/PtctlPacketConverterTests.cs | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Tests/NosSmooth.Packets.Tests/Converters/Packets/PtctlPacketConverterTests.cs diff --git a/Tests/NosSmooth.Packets.Tests/Converters/Packets/PtctlPacketConverterTests.cs b/Tests/NosSmooth.Packets.Tests/Converters/Packets/PtctlPacketConverterTests.cs new file mode 100644 index 0000000..5cd1648 --- /dev/null +++ b/Tests/NosSmooth.Packets.Tests/Converters/Packets/PtctlPacketConverterTests.cs @@ -0,0 +1,68 @@ +// +// PtctlPacketConverterTests.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 System.Collections.Generic; +using Microsoft.Extensions.DependencyInjection; +using NosSmooth.Packets.Client.Mates; +using NosSmooth.PacketSerializer; +using NosSmooth.PacketSerializer.Abstractions.Attributes; +using NosSmooth.PacketSerializer.Extensions; +using NosSmooth.PacketSerializer.Packets; +using Shouldly; +using Xunit; + +namespace NosSmooth.Packets.Tests.Converters.Packets; + +/// +/// Tests PtctlPacketConverter. +/// +public class PtctlPacketConverterTests +{ + private readonly IPacketSerializer _packetSerializer; + + /// + /// Initializes a new instance of the class. + /// + public PtctlPacketConverterTests() + { + var provider = new ServiceCollection() + .AddPacketSerialization() + .BuildServiceProvider(); + + _packetSerializer = provider.GetRequiredService(); + provider.GetRequiredService().AddDefaultPackets(); + } + + /// + /// Tests that deserialization of raid packet of list members. + /// + [Fact] + public void Converter_Deserialization_Succeeds() + { + var packetResult = _packetSerializer.Deserialize + ( + "ptctl 1 1 123 26 21 123 13", + PacketSource.Server + ); + packetResult.IsSuccess.ShouldBeTrue(); + var packet = (PtctlPacket)packetResult.Entity; + packet.ShouldBeEquivalentTo + ( + new PtctlPacket + ( + 1, + 1, + new List + ( + new[] + { + new PtctlSubPacket(123, 26, 21) + } + ) + ) + ); + } +} \ No newline at end of file -- 2.49.0