mirror of
https://github.com/Sea-Haven-Industries/proposal-system.git
synced 2026-09-30 05:23:14 +00:00
37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using FluentAssertions;
|
|
using ProposalSystem.Application.Common;
|
|
using Xunit;
|
|
|
|
namespace ProposalSystem.Tests.Common;
|
|
|
|
public class RowVersionCodecTests
|
|
{
|
|
[Theory(DisplayName = "Encode/TryDecode round-trips")]
|
|
[InlineData(1L)]
|
|
[InlineData(2L)]
|
|
[InlineData(long.MaxValue)]
|
|
public void RoundTrips(long version)
|
|
{
|
|
var token = RowVersionCodec.Encode(version);
|
|
|
|
RowVersionCodec.TryDecode(token, out var decoded).Should().BeTrue();
|
|
decoded.Should().Be(version);
|
|
}
|
|
|
|
[Fact(DisplayName = "Version 1 encodes to the SHOC-style opaque token")]
|
|
public void EncodesOpaqueBase64()
|
|
{
|
|
RowVersionCodec.Encode(1).Should().Be("AAAAAAAAAAE=");
|
|
}
|
|
|
|
[Theory(DisplayName = "TryDecode rejects missing/malformed/wrong-length tokens")]
|
|
[InlineData(null)]
|
|
[InlineData("")]
|
|
[InlineData("not base64!!")]
|
|
[InlineData("AAA=")] // valid base64 but not 8 bytes
|
|
[InlineData("AAAAAAAAAAAAAAAAAAAAAA==")] // 16 bytes
|
|
public void RejectsInvalid(string? token)
|
|
{
|
|
RowVersionCodec.TryDecode(token, out _).Should().BeFalse();
|
|
}
|
|
}
|