Ejemplo n.º 1
0
        public async Task Given_stream_contains_more_data_than_chunk_needs_should_advance_to_end()
        {
            var chunk = new ControllerChunk
            {
                Name = "ControllerName"
            };

            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();
            }
        }
Ejemplo n.º 2
0
        public async Task When_serializing_should_produce_correct_binary_data(string controllerName)
        {
            byte[] expectedRawData = new byte[] { 0xc8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
            .Concat(controllerName == null ? new byte[0] : FileEncoding.Default.GetBytes(controllerName + '\0'))
            .ToArray()
            ;
            var chunk = new ControllerChunk
            {
                Id       = 456,
                ParentId = 123,
                Name     = controllerName
            };

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

                // Assert
                ms.ToArray().Should().BeEquivalentTo(expectedRawData);
            }
        }
Ejemplo n.º 3
0
        public async Task When_serializing_and_then_deserializing_should_produce_equivalent(string controllerName)
        {
            var chunk = new ControllerChunk
            {
                Id       = 456,
                ParentId = 123,
                Name     = controllerName
            };

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

                ms.Position = 0;

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

                // Assert
                deserializedChunk.Should().BeEquivalentTo(chunk);
                ms.Should().BeEof();
            }
        }