public void ShouldUnpackTinyStruct() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()).Returns(0xB2); var u = new PackStream.Unpacker(mockInput.Object, null); u.UnpackStructHeader().Should().Be(2); mockInput.Verify(x => x.ReadByte(), Times.Once); }
public void ShouldUnpackBooleanFalseSuccessfully() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()).Returns(PackStream.FALSE); var u = new PackStream.Unpacker(mockInput.Object, null); u.UnpackBoolean().Should().BeFalse(); mockInput.Verify(x => x.ReadByte(), Times.Once); }
public void ShouldUnpackTinyStringAsEmptyString() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()).Returns(PackStream.TINY_STRING); var u = new PackStream.Unpacker(mockInput.Object, null); u.UnpackString().Should().BeEmpty(); //.Equals(String.Empty); mockInput.Verify(x => x.ReadByte(), Times.Once); }
public void ShouldCallReadByteOnce() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()).Returns(0xFF); var u = new PackStream.Unpacker(mockInput.Object, new BigEndianTargetBitConverter()); u.UnpackStructSignature().Should().Be(0xFF); mockInput.Verify(x => x.ReadByte(), Times.Once); }
internal void ShouldPeekTypeCorrectly(byte marker, PackStream.PackType expected) { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.PeekByte()).Returns(marker); var u = new PackStream.Unpacker(mockInput.Object, null); u.PeekNextType().Should().Be(expected); mockInput.Verify(x => x.PeekByte(), Times.Once); }
public void ShouldUnpackNullSuccessfully() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()).Returns(PackStream.NULL); var u = new PackStream.Unpacker(mockInput.Object, null); u.UnpackNull().Should().BeNull(); mockInput.Verify(x => x.ReadByte(), Times.Once); }
public void ShouldThrowExceptionIfMarkerByteNotTrueOrFalse() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()).Returns(PackStream.BYTES_16); var unpacker = new PackStream.Unpacker(mockInput.Object, null); var ex = Xunit.Record.Exception(() => unpacker.UnpackBoolean()); ex.Should().BeOfType <ArgumentOutOfRangeException>(); }
public void ShouldUnpackStruct8() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()) .Returns(new Queue <byte>(new[] { PackStream.STRUCT_8, (byte)1 }).Dequeue); var u = new PackStream.Unpacker(mockInput.Object, new BigEndianTargetBitConverter()); u.UnpackStructHeader().Should().Be(1); mockInput.Verify(x => x.ReadByte(), Times.Exactly(2)); }
public void ShouldThrowExceptionIfMarkerByteNotNull() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()).Returns(PackStream.BYTES_16); var unpacker = new PackStream.Unpacker(mockInput.Object); var ex = Xunit.Record.Exception(() => unpacker.UnpackNull()); ex.Should().BeOfType <ProtocolException>(); }
public void ShouldUnpackList8() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()) .Returns(new Queue <byte>(new[] { PackStream.LIST_8, (byte)1 }).Dequeue); var u = new PackStream.Unpacker(mockInput.Object); u.UnpackListHeader().Should().Be(1); mockInput.Verify(x => x.ReadByte(), Times.Exactly(2)); }
public void ShouldUnpackList16() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()).Returns(PackStream.LIST_16); mockInput.Setup(x => x.ReadShort()).Returns(1); var u = new PackStream.Unpacker(mockInput.Object); u.UnpackListHeader().Should().Be(1); mockInput.Verify(x => x.ReadByte(), Times.Once); mockInput.Verify(x => x.ReadShort(), Times.Once); }
public void ShouldThrowExceptionIfMarkerByteNotStruct() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()).Returns(PackStream.FALSE); var u = new PackStream.Unpacker(mockInput.Object); var ex = Xunit.Record.Exception(() => u.UnpackStructHeader()); ex.Should().BeOfType <ProtocolException>(); mockInput.Verify(x => x.ReadByte(), Times.Once); }
public void ShouldThrowExceptionIfMarkerByteUnDefined() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.PeekByte()).Returns(PackStream.RESERVED_C4); var u = new PackStream.Unpacker(mockInput.Object); var ex = Xunit.Record.Exception(() => u.PeekNextType()); ex.Should().BeOfType <ProtocolException>(); mockInput.Verify(x => x.PeekByte(), Times.Once); }
public void ShouldThrowExceptionIfMarkerByteUnDefined() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.PeekByte()).Returns(PackStream.RESERVED_C4); var u = new PackStream.Unpacker(mockInput.Object, new BigEndianTargetBitConverter()); var ex = Xunit.Record.Exception(() => u.PeekNextType()); ex.Should().BeOfType <ArgumentOutOfRangeException>(); mockInput.Verify(x => x.PeekByte(), Times.Once); }
public void ShouldUnpackStruct16() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()).Returns(PackStream.STRUCT_16); mockInput.Setup(x => x.ReadShort()).Returns(1); var u = new PackStream.Unpacker(mockInput.Object, new BigEndianTargetBitConverter()); u.UnpackStructHeader().Should().Be(1); mockInput.Verify(x => x.ReadByte(), Times.Once); mockInput.Verify(x => x.ReadShort(), Times.Once); }
public void ShouldThrowExceptionIfMarkerByteNotStruct() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()).Returns(PackStream.FALSE); var u = new PackStream.Unpacker(mockInput.Object, new BigEndianTargetBitConverter()); var ex = Xunit.Record.Exception(() => u.UnpackStructHeader()); ex.Should().BeOfType <ArgumentOutOfRangeException>(); mockInput.Verify(x => x.ReadByte(), Times.Once); }
public void ShouldUnpackList32() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()).Returns(PackStream.LIST_32); mockInput.Setup(x => x.ReadInt()).Returns(-1); var u = new PackStream.Unpacker(mockInput.Object, new BigEndianTargetBitConverter()); u.UnpackListHeader().Should().Be(uint.MaxValue); mockInput.Verify(x => x.ReadByte(), Times.Once); mockInput.Verify(x => x.ReadInt(), Times.Once); }
public void ShouldUnpackMap32() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()).Returns(PackStream.MAP_32); mockInput.Setup(x => x.ReadInt()).Returns(-1); var u = new PackStream.Unpacker(mockInput.Object); u.UnpackMapHeader().Should().Be(uint.MaxValue); mockInput.Verify(x => x.ReadByte(), Times.Once); mockInput.Verify(x => x.ReadInt(), Times.Once); }
public void ShouldUnpackStringLessThan16Chars() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()).Returns(0x81); mockInput.Setup(x => x.ReadBytes(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int?>())) .Callback <byte[], int, int?>((buffer, offset, size) => { buffer[0] = 0x61; }); var u = new PackStream.Unpacker(mockInput.Object, new BigEndianTargetBitConverter()); u.UnpackString().Should().Be("a"); mockInput.Verify(x => x.ReadByte(), Times.Once); mockInput.Verify(x => x.ReadBytes(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int?>()), Times.Once); }
public void ShouldUnpackLongAsLong() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()).Returns(PackStream.INT_64); long expected = 1024; mockInput.Setup(x => x.ReadLong()).Returns(expected); var u = new PackStream.Unpacker(mockInput.Object, null); Assert.Equal(expected, u.UnpackLong()); mockInput.Verify(x => x.ReadByte(), Times.Once); mockInput.Verify(x => x.ReadLong(), Times.Once); }
public void ShouldThrowExceptionWhenUnpackBytes32ReturnsBytesSizeLonggerThanIntMax() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()).Returns(PackStream.BYTES_32); mockInput.Setup(x => x.ReadInt()).Returns(-1); var u = new PackStream.Unpacker(mockInput.Object); var ex = Xunit.Record.Exception(() => u.UnpackBytes()); ex.Should().BeOfType <ProtocolException>(); mockInput.Verify(x => x.ReadByte(), Times.Once); mockInput.Verify(x => x.ReadInt(), Times.Once); }
public void ShouldThrowExceptionWhenUnpackString32ReturnsStringSizeLonggerThanIntMax() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()).Returns(PackStream.STRING_32); mockInput.Setup(x => x.ReadInt()).Returns(-1); var u = new PackStream.Unpacker(mockInput.Object); var ex = Xunit.Record.Exception(() => u.UnpackString()); ex.Should().BeOfType <ArgumentOutOfRangeException>(); mockInput.Verify(x => x.ReadByte(), Times.Once); mockInput.Verify(x => x.ReadInt(), Times.Once); }
[InlineData(0x7F, 127)] // 7F to FF public void ShouldUnpackLongAsTinyByte(byte data, sbyte expected) { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()).Returns(data); var u = new PackStream.Unpacker(mockInput.Object, null); sbyte real = (sbyte)u.UnpackLong(); real.Should().Be(expected); mockInput.Verify(x => x.ReadByte(), Times.Once); mockInput.Verify(x => x.ReadSByte(), Times.Never); }
public void ShouldUnpackDoubleCorrectly() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()).Returns(PackStream.FLOAT_64); double expected = 1.12; mockInput.Setup(x => x.ReadDouble()).Returns(expected); var u = new PackStream.Unpacker(mockInput.Object, null); Assert.Equal(expected, u.UnpackDouble()); mockInput.Verify(x => x.ReadByte(), Times.Once); mockInput.Verify(x => x.ReadDouble(), Times.Once); }
public void ShouldUnpackString8() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()) .Returns(new Queue <byte>(new[] { PackStream.STRING_8, (byte)1 }).Dequeue); mockInput.Setup(x => x.ReadBytes(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int?>())) .Callback <byte[], int, int?>((buffer, offset, size) => { buffer[0] = 0x61; }); var u = new PackStream.Unpacker(mockInput.Object, new BigEndianTargetBitConverter()); u.UnpackString().Should().Be("a"); mockInput.Verify(x => x.ReadByte(), Times.Exactly(2)); mockInput.Verify(x => x.ReadBytes(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int?>()), Times.Once); }
public void ShouldThrowExceptionWhenUnpackBytes32ReturnsBytesSizeLonggerThanIntMax() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()).Returns(PackStream.BYTES_32); mockInput.Setup(x => x.ReadInt()).Returns(-1); var u = new PackStream.Unpacker(mockInput.Object, new BigEndianTargetBitConverter()); var ex = Xunit.Record.Exception(() => u.UnpackBytes()); ex.Should().BeOfType <ArgumentOutOfRangeException>(); mockInput.Verify(x => x.ReadByte(), Times.Once); mockInput.Verify(x => x.ReadInt(), Times.Once); }
public void ShouldUnpackString32() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()).Returns(PackStream.STRING_32); mockInput.Setup(x => x.ReadInt()).Returns(1); mockInput.Setup(x => x.ReadBytes(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int?>())) .Callback <byte[], int, int?>((buffer, offset, size) => { buffer[0] = 0x61; }); var u = new PackStream.Unpacker(mockInput.Object); u.UnpackString().Should().Be("a"); mockInput.Verify(x => x.ReadByte(), Times.Once); mockInput.Verify(x => x.ReadInt(), Times.Once); mockInput.Verify(x => x.ReadBytes(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int?>()), Times.Once); }
public void ShouldUnpackLongAsSignedByte() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()).Returns(PackStream.INT_8); sbyte expected = 1; mockInput.Setup(x => x.ReadSByte()).Returns(expected); var u = new PackStream.Unpacker(mockInput.Object, null); sbyte real = (sbyte)u.UnpackLong(); Assert.Equal(expected, real); mockInput.Verify(x => x.ReadByte(), Times.Once); mockInput.Verify(x => x.ReadSByte(), Times.Once); }
public void ShouldUnpackBytes8() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()) .Returns(new Queue <byte>(new[] { PackStream.BYTES_8, (byte)1 }).Dequeue); mockInput.Setup(x => x.ReadBytes(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int?>())) .Callback <byte[], int, int?>((buffer, offset, size) => { buffer[0] = 0x61; }); var u = new PackStream.Unpacker(mockInput.Object); var actual = u.UnpackBytes(); actual.Length.Should().Be(1); actual.Should().Contain(0x61); mockInput.Verify(x => x.ReadByte(), Times.Exactly(2)); mockInput.Verify(x => x.ReadBytes(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int?>()), Times.Once); }
public void ShouldUnpackBytes32() { var mockInput = new Mock <IInputStream>(); mockInput.Setup(x => x.ReadByte()).Returns(PackStream.BYTES_32); mockInput.Setup(x => x.ReadInt()).Returns(1); mockInput.Setup(x => x.ReadBytes(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int?>())) .Callback <byte[], int, int?>((buffer, offset, size) => { buffer[0] = 0x61; }); var u = new PackStream.Unpacker(mockInput.Object, new BigEndianTargetBitConverter()); var actual = u.UnpackBytes(); actual.Length.Should().Be(1); actual.Should().Contain(0x61); mockInput.Verify(x => x.ReadByte(), Times.Once); mockInput.Verify(x => x.ReadInt(), Times.Once); mockInput.Verify(x => x.ReadBytes(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int?>()), Times.Once); }