public async Task When_serializing_without_description_should_produce_correct_binary_data() { byte[] expectedRawData = { 00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x6b, 0x77, 0x61, 0x73, 0x00 }; var chunk = new AuthorInfoChunk { Author = "skwas", Description = null }; using (var ms = new MemoryStream()) { // Act await chunk.SerializeAsync(ms, false); // Assert ms.ToArray().Should().BeEquivalentTo(expectedRawData); } }
public async Task Given_stream_contains_more_data_than_chunk_needs_should_advance_to_end() { var chunk = new AuthorInfoChunk { Author = "skwas", Description = "My file" }; using (var ms = new MemoryStream()) { await chunk.SerializeAsync(ms, false); // Add garbage to end. ms.Write(new byte[] { 0x1, 0x2 }, 0, 2); ms.Position = 0; // Act await chunk.DeserializeAsync(ms, false); // Assert ms.Should().BeEof(); } }
public async Task When_serializing_and_then_deserializing_should_produce_equivalent() { var chunk = new AuthorInfoChunk { Unknown = 123, Author = "skwas", Description = "My description" }; using (var ms = new MemoryStream()) { await chunk.SerializeAsync(ms, false); ms.Position = 0; // Act var deserializedChunk = new AuthorInfoChunk(); await deserializedChunk.DeserializeAsync(ms, false); // Assert deserializedChunk.Should().BeEquivalentTo(chunk, options => options.Excluding(c => c.UnknownData)); ms.Should().BeEof(); } }