Ejemplo n.º 1
0
        public void ReadValue_DataIsEqualToSize_ShouldProperlyReturnValue()
        {
            // Arrange
            byte[] buffer = { 1, 2, 3, 4, 5 };
            var    stream = new MemoryStream(buffer);

            // Act
            var dialog = new ProtocolDialogServer(stream);
            var value  = dialog.ReadValue(5, data => data);

            // Assert
            Assert.Equal(5, value.Length);
            Assert.Equal(buffer, value);
            Assert.True(dialog.HasData());
        }
Ejemplo n.º 2
0
        public void ReadValue_DataIsMoreThanSize_ShouldProperlyReturnValue()
        {
            // Arrange
            byte[] buffer = { 1, 2, 3, 4, 5, 6, 7, 8 };
            var    stream = new MemoryStream(buffer);

            // Act
            var dialog        = new ProtocolDialogServer(stream);
            var firstSegment  = dialog.ReadValue(5, data => data);
            var secondSegment = dialog.ReadValue(5, data => data);

            // Assert
            Assert.Equal(5, firstSegment.Length);
            Assert.Equal(buffer.Take(5), firstSegment);
            Assert.Equal(3, secondSegment.Length);
            Assert.Equal(buffer.Skip(5).Take(5), secondSegment);
            Assert.False(dialog.HasData());
        }