From a60073b7c04bb7c4381c3c65bfb0eebf01a67027 Mon Sep 17 00:00:00 2001 From: Harry Cordewener Date: Mon, 29 Jan 2024 17:32:17 -0600 Subject: [PATCH] MSDP Report Tests. --- TelnetNegotiationCore.UnitTests/MSDPTests.cs | 56 ++++++++++++++++++- .../Handlers/MSDPServerHandler.cs | 9 +-- 2 files changed, 54 insertions(+), 11 deletions(-) diff --git a/TelnetNegotiationCore.UnitTests/MSDPTests.cs b/TelnetNegotiationCore.UnitTests/MSDPTests.cs index 337d987..28884fc 100644 --- a/TelnetNegotiationCore.UnitTests/MSDPTests.cs +++ b/TelnetNegotiationCore.UnitTests/MSDPTests.cs @@ -12,15 +12,23 @@ public class MSDPTests : BaseTest { static readonly Encoding encoding = Encoding.ASCII; - [TestCaseSource(nameof(FSharpTestSequences))] - public void TestFSharp(byte[] testcase, dynamic expectedObject) + [TestCaseSource(nameof(FSharpScanTestSequences))] + public void TestFSharpScan(byte[] testcase, dynamic expectedObject) { var result = Functional.MSDPLibrary.MSDPScan(testcase, encoding); logger.LogInformation("Serialized: {Serialized}", JsonSerializer.Serialize(result)); Assert.AreEqual(JsonSerializer.Serialize(expectedObject), JsonSerializer.Serialize(result)); } - public static IEnumerable FSharpTestSequences + [TestCaseSource(nameof(FSharpReportTestSequences))] + public void TestFSharpReport(dynamic obj, byte[] expectedSequence) + { + byte[] result = Functional.MSDPLibrary.Report(JsonSerializer.Serialize(obj), encoding); + logger.LogInformation("Sequence: {@Serialized}", result); + Assert.AreEqual(expectedSequence, result); + } + + public static IEnumerable FSharpScanTestSequences { get { @@ -80,5 +88,47 @@ .. encoding.GetBytes("6012"), new { ROOM = new { AREA = "Haon Dor", EXITS = new { e = "6012", n = "6011" }, NAME = "The Forest clearing", VNUM = "6008" } }); } } + public static IEnumerable FSharpReportTestSequences + { + get + { + yield return new TestCaseData(new { LIST = "COMMANDS" }, (byte[])[ + (byte)Trigger.MSDP_TABLE_OPEN, + (byte)Trigger.MSDP_VAR, + .. encoding.GetBytes("LIST"), + (byte)Trigger.MSDP_VAL, + .. encoding.GetBytes("COMMANDS"), + (byte)Trigger.MSDP_TABLE_CLOSE]); + + yield return new TestCaseData(new { LIST = (string[])["COMMANDS", "JIM"] }, (byte[])[ + (byte)Trigger.MSDP_TABLE_OPEN, + (byte)Trigger.MSDP_VAR, + .. encoding.GetBytes("LIST"), + (byte)Trigger.MSDP_VAL, + (byte)Trigger.MSDP_ARRAY_OPEN, + (byte)Trigger.MSDP_VAL, + .. encoding.GetBytes("COMMANDS"), + (byte)Trigger.MSDP_VAL, + .. encoding.GetBytes("JIM"), + (byte)Trigger.MSDP_ARRAY_CLOSE, + (byte)Trigger.MSDP_TABLE_CLOSE]); + + yield return new TestCaseData(new { LIST = (dynamic[])["COMMANDS", (dynamic[])["JIM"]] }, (byte[])[ + (byte)Trigger.MSDP_TABLE_OPEN, + (byte)Trigger.MSDP_VAR, + .. encoding.GetBytes("LIST"), + (byte)Trigger.MSDP_VAL, + (byte)Trigger.MSDP_ARRAY_OPEN, + (byte)Trigger.MSDP_VAL, + .. encoding.GetBytes("COMMANDS"), + (byte)Trigger.MSDP_VAL, + (byte)Trigger.MSDP_ARRAY_OPEN, + (byte)Trigger.MSDP_VAL, + .. encoding.GetBytes("JIM"), + (byte)Trigger.MSDP_ARRAY_CLOSE, + (byte)Trigger.MSDP_ARRAY_CLOSE, + (byte)Trigger.MSDP_TABLE_CLOSE]); + } + } } } diff --git a/TelnetNegotiationCore/Handlers/MSDPServerHandler.cs b/TelnetNegotiationCore/Handlers/MSDPServerHandler.cs index 71e633a..0a0298c 100644 --- a/TelnetNegotiationCore/Handlers/MSDPServerHandler.cs +++ b/TelnetNegotiationCore/Handlers/MSDPServerHandler.cs @@ -1,16 +1,9 @@ -using Microsoft.FSharp.Data.UnitSystems.SI.UnitNames; -using System; +using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Reflection.Emit; -using System.Runtime.Intrinsics.X86; using System.Text.Json; using System.Threading.Tasks; -using System.Xml.Linq; -using System.Xml; using TelnetNegotiationCore.Functional; using TelnetNegotiationCore.Interpreters; -using static System.Runtime.InteropServices.JavaScript.JSType; namespace TelnetNegotiationCore.Handlers {