52 lines
1.9 KiB
C#
52 lines
1.9 KiB
C#
using System;
|
|
using CadParamPluging.Common;
|
|
|
|
public static class DropdownDisplayNameTests
|
|
{
|
|
public static int Main()
|
|
{
|
|
try
|
|
{
|
|
KeepsInternalValueWhenRenamingDisplayName();
|
|
RemovesRedundantOverrideWhenDisplayMatchesRawValue();
|
|
Console.WriteLine("All dropdown display-name tests passed.");
|
|
return 0;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.Error.WriteLine(ex.Message);
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
private static void KeepsInternalValueWhenRenamingDisplayName()
|
|
{
|
|
var options = DropdownOptions.CreateDefault();
|
|
|
|
options.SetDisplayNameOverride(DropdownOptionCategory.DeliveryStatus, "车加工", "粗加工");
|
|
|
|
AssertEqual("车加工", options.DeliveryStatuses[1], "Internal value must stay canonical.");
|
|
AssertEqual("粗加工", options.GetDisplayName(DropdownOptionCategory.DeliveryStatus, "车加工"), "Display name override should be used.");
|
|
}
|
|
|
|
private static void RemovesRedundantOverrideWhenDisplayMatchesRawValue()
|
|
{
|
|
var options = DropdownOptions.CreateDefault();
|
|
|
|
options.SetDisplayNameOverride(DropdownOptionCategory.DeliveryStatus, "车加工", "粗加工");
|
|
options.SetDisplayNameOverride(DropdownOptionCategory.DeliveryStatus, "车加工", "车加工");
|
|
options.Normalize();
|
|
|
|
AssertEqual("车加工", options.GetDisplayName(DropdownOptionCategory.DeliveryStatus, "车加工"), "Default display should fall back to raw value.");
|
|
AssertEqual(0, options.DisplayNameOverrides.Count, "Redundant override should be removed.");
|
|
}
|
|
|
|
private static void AssertEqual<T>(T expected, T actual, string message)
|
|
{
|
|
if (!object.Equals(expected, actual))
|
|
{
|
|
throw new InvalidOperationException(message + " Expected: " + expected + "; Actual: " + actual);
|
|
}
|
|
}
|
|
}
|