Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SiuTung08 committed Nov 9, 2024
1 parent 6053a21 commit f6d9e38
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/NATS.Client.CoreUnit.Tests/NatsHeaderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,23 @@ public void GetLastValueTests(string text, bool expectedResult, string? expected
Assert.Equal(result, expectedResult);
Assert.Equal(lastValue, expectedLastValue);
}

[Fact]
public void GetBytesLengthTest()
{
var headers = new NatsHeaders
{
["k1"] = "v1",
["k2"] = new[] { "v2-0", "v2-1" },
["a-long-header-key"] = "value",
["key"] = "a-long-header-value",
};
var writer = new HeaderWriter(Encoding.UTF8);
var bytesLength = writer.GetBytesLength(headers);

var text = "NATS/1.0\r\nk1: v1\r\nk2: v2-0\r\nk2: v2-1\r\na-long-header-key: value\r\nkey: a-long-header-value\r\n\r\n";
var expected = new ReadOnlySequence<byte>(Encoding.UTF8.GetBytes(text));

Assert.Equal(expected.Length, bytesLength);
}
}

0 comments on commit f6d9e38

Please sign in to comment.