add reflection-based test coverage for DiscoveryService.GetModelNameFromId
Ensures the 0x20 => "POS895" registration is actually tested. Without this, the line could be deleted and the whole suite would still pass. Claude-Session: https://claude.ai/code/session_01E6N3P4nSZLtp4BC2LXVref
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using Inspectron.Epson;
|
||||
using Inspectron.Epson.PrintServer.Printers;
|
||||
using Inspectron.Epson.PrintServer.Printers.Utils;
|
||||
|
||||
@@ -82,4 +83,40 @@ public class PrinterRegistrationTests
|
||||
Assert.NotNull(factory.Create((int)type, 0x20));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetModelNameFromId_maps_0x20_to_POS895()
|
||||
{
|
||||
Assert.Equal("POS895", ModelNameFor(0x20));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetModelNameFromId_still_maps_the_existing_epson_ids()
|
||||
{
|
||||
// Guards against a change that makes every id report as POS895.
|
||||
Assert.Equal("TM-T30III", ModelNameFor(0x01));
|
||||
Assert.Equal("TM-U220II", ModelNameFor(0x0D));
|
||||
Assert.Equal("TM-U220II", ModelNameFor(0x13));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetModelNameFromId_falls_back_for_an_unknown_id()
|
||||
{
|
||||
Assert.Equal("Unknown (0x99)", ModelNameFor(0x99));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes DiscoveryService.GetModelNameFromId, which is private static and
|
||||
/// otherwise reachable only through a live TCP connection. Reflection keeps the
|
||||
/// production code untouched; if the method is renamed this fails loudly rather
|
||||
/// than silently passing.
|
||||
/// </summary>
|
||||
private static string ModelNameFor(byte printerId)
|
||||
{
|
||||
var method = typeof(DiscoveryService).GetMethod("GetModelNameFromId",
|
||||
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
|
||||
|
||||
Assert.NotNull(method);
|
||||
return (string)method!.Invoke(null, new object[] { printerId })!;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user