Files
MBN_STOCK_WEBVIEW/tests/MBN_STOCK_WEBVIEW.LegacyBridge.Tests/LegacyRowDoubleClickBridgeTests.cs

87 lines
2.9 KiB
C#

using System.Text.Json;
using MBN_STOCK_WEBVIEW.LegacyApplication;
namespace MBN_STOCK_WEBVIEW.LegacyBridge.Tests;
public sealed class LegacyRowDoubleClickBridgeTests
{
[Theory]
[InlineData(
"activate-manual-financial-result",
"resultId",
"mf-row-0123456789abcdef",
typeof(LegacyActivateManualFinancialResultIntent))]
[InlineData(
"activate-theme-result",
"resultId",
"theme-result-001",
typeof(LegacyActivateThemeResultIntent))]
[InlineData(
"load-named-playlist-by-id",
"definitionId",
"named-definition-AAAAAAAAAAAB",
typeof(LegacyLoadNamedPlaylistByIdIntent))]
[InlineData(
"save-current-named-playlist-to",
"definitionId",
"named-definition-AAAAAAAAAAAB",
typeof(LegacySaveCurrentNamedPlaylistToIntent))]
public void Atomic_row_commands_accept_one_opaque_identity_only(
string command,
string property,
string value,
Type expectedType)
{
var json = JsonSerializer.Serialize(new
{
type = command,
payload = new Dictionary<string, string> { [property] = value }
});
Assert.True(LegacyBridgeProtocol.TryParseIntent(json, out var parsed, out _));
Assert.IsType(expectedType, parsed);
Assert.False(LegacyBridgeProtocol.TryParseIntent(
$"{{\"type\":\"{command}\",\"payload\":{{\"{property}\":\"{value}\",\"programCode\":\"00000001\"}}}}",
out _,
out _));
Assert.False(LegacyBridgeProtocol.TryParseIntent(
$"{{\"type\":\"{command}\",\"payload\":{{\"{property}\":\"../unsafe\"}}}}",
out _,
out _));
}
[Fact]
public void Projection_exposes_only_closed_command_receipt_and_opaque_target()
{
var snapshot = new LegacyOperatorSnapshot(
1,
string.Empty,
[],
null,
[],
[],
null,
string.Empty,
LegacyOperatorStatusKind.Information,
CommandResult: new LegacyOperatorCommandResult(
7,
"load-named-playlist-by-id",
"named-definition-AAAAAAAAAAAB",
true));
using var document = JsonDocument.Parse(
LegacyBridgeProtocol.SerializeState(snapshot));
var result = document.RootElement.GetProperty("payload")
.GetProperty("commandResult");
Assert.Equal(7, result.GetProperty("sequence").GetInt64());
Assert.Equal("load-named-playlist-by-id",
result.GetProperty("command").GetString());
Assert.Equal("named-definition-AAAAAAAAAAAB",
result.GetProperty("targetId").GetString());
Assert.True(result.GetProperty("succeeded").GetBoolean());
Assert.DoesNotContain("programCode", result.GetRawText(),
StringComparison.OrdinalIgnoreCase);
}
}