Skip to content

Instantly share code, notes, and snippets.

@MichalBrylka
Created May 6, 2022 19:27
Show Gist options
  • Select an option

  • Save MichalBrylka/fc4f3e2ecae81c7ae708145cc0731bc3 to your computer and use it in GitHub Desktop.

Select an option

Save MichalBrylka/fc4f3e2ecae81c7ae708145cc0731bc3 to your computer and use it in GitHub Desktop.
[TestCase(0, 0, "")]
[TestCase(1, 1, "3")]
[TestCase(2, 2, "3|4")]
[TestCase(3, 3, "3|4|5")]
[TestCase(4, 3, "3|4|5|0")]
[TestCase(5, 3, "3|4|5|0|0")]
public void Read_ToBuffer_ShouldBeAbleToReadBytes(int bufferSize, int expectedCount, string expectedArray)
{
var sut = new SpanBinaryReader(new byte[] { 1, 2, 3, 4, 5 }, 2);
// ^
Span<byte> buffer = stackalloc byte[bufferSize];
var count = sut.ReadTo(MemoryMarshal.CreateSpan(ref MemoryMarshal.GetReference(buffer), buffer.Length));
var actualText = string.Join("|", buffer.ToArray());
Assert.That(actualText, Is.EqualTo(expectedArray));
Assert.That(count, Is.EqualTo(expectedCount));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment