Пример #1
0
        public async Task Given_stream_contains_more_data_than_chunk_needs_should_advance_to_end()
        {
            var chunk = new IndexChunk();

            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();
            }
        }
Пример #2
0
        public async Task When_serializing_and_then_deserializing_should_produce_equivalent()
        {
            var referenceChunks = new Collection <DatChunk>
            {
                new TextureMapChunk
                {
                    Id         = 987654,
                    FileOffset = 123456
                },
                new TextureMapChunk
                {
                    Id         = 987654321,
                    FileOffset = 123456789
                }
            };
            var parentFileMock = new Mock <IChunkFile>();

            parentFileMock
            .Setup(m => m.Chunks)
            .Returns(referenceChunks);

            var chunk = new IndexChunk
            {
                ParentFile = parentFileMock.Object
            };

            using (var ms = new MemoryStream())
            {
                await chunk.SerializeAsync(ms, false);

                ms.Position = 0;

                // Act
                var deserializedChunk = new IndexChunk();
                await deserializedChunk.DeserializeAsync(ms, false);

                // Assert
                deserializedChunk.Should().BeEquivalentTo(chunk, options => options.Excluding(c => c.ParentFile));
                ms.Should().BeEof();
            }
        }