53 lines
1.6 KiB
C#
53 lines
1.6 KiB
C#
using System.Text;
|
|
using FluentAssertions;
|
|
using Xunit;
|
|
|
|
namespace LedgerReplayHarness.Tests;
|
|
|
|
public class HarnessFixtureReaderTests
|
|
{
|
|
[Fact]
|
|
public async Task ReadDraftsAsync_ThrowsWithFixtureContextOnInvalidDate()
|
|
{
|
|
var line = "{" +
|
|
"\"chain_id\":\"11111111-1111-1111-1111-111111111111\"," +
|
|
"\"sequence_no\":1," +
|
|
"\"event_id\":\"22222222-2222-2222-2222-222222222222\"," +
|
|
"\"event_type\":\"test\"," +
|
|
"\"policy_version\":\"v1\"," +
|
|
"\"finding_id\":\"f1\"," +
|
|
"\"artifact_id\":\"a1\"," +
|
|
"\"actor_id\":\"u1\"," +
|
|
"\"actor_type\":\"user\"," +
|
|
"\"occurred_at\":\"not-a-date\"," +
|
|
"\"payload\":{}" +
|
|
"}";
|
|
|
|
var tempPath = Path.GetTempFileName();
|
|
await File.WriteAllTextAsync(tempPath, line, Encoding.UTF8, TestContext.Current.CancellationToken);
|
|
var fileInfo = new FileInfo(tempPath);
|
|
|
|
try
|
|
{
|
|
var action = async () =>
|
|
{
|
|
await foreach (var _ in HarnessFixtureReader.ReadDraftsAsync(fileInfo, "tenant-a", TimeProvider.System, TestContext.Current.CancellationToken))
|
|
{
|
|
}
|
|
};
|
|
|
|
var ex = await Assert.ThrowsAsync<HarnessFixtureException>(action);
|
|
ex.Message.Should().Contain("occurred_at invalid");
|
|
ex.Message.Should().Contain(Path.GetFileName(tempPath));
|
|
ex.LineNumber.Should().Be(1);
|
|
}
|
|
finally
|
|
{
|
|
if (File.Exists(tempPath))
|
|
{
|
|
File.Delete(tempPath);
|
|
}
|
|
}
|
|
}
|
|
}
|