Skip to content

Commit

Permalink
MSDP Report Tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
HarryCordewener committed Jan 29, 2024
1 parent 3a657a7 commit a60073b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 11 deletions.
56 changes: 53 additions & 3 deletions TelnetNegotiationCore.UnitTests/MSDPTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestCaseData> 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<TestCaseData> FSharpScanTestSequences
{
get
{
Expand Down Expand Up @@ -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<TestCaseData> 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]);
}
}
}
}
9 changes: 1 addition & 8 deletions TelnetNegotiationCore/Handlers/MSDPServerHandler.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down

0 comments on commit a60073b

Please sign in to comment.