Ejemplo n.º 1
0
                public void ShouldThrowExceptionIfMarkerByteNotBytes()
                {
                    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.UnpackBytes());

                    ex.Should().BeOfType <ArgumentOutOfRangeException>();
                    mockInput.Verify(x => x.ReadByte(), Times.Once);
                }
Ejemplo n.º 2
0
                public void ShouldThrowExceptionIfMarkerByteNotBytes()
                {
                    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.UnpackBytes());

                    ex.Should().BeOfType <ProtocolException>();
                    mockInput.Verify(x => x.ReadByte(), Times.Once);
                }
Ejemplo n.º 3
0
                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);
                }
Ejemplo n.º 4
0
                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);
                }
Ejemplo n.º 5
0
                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, new BigEndianTargetBitConverter());

                    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);
                }
Ejemplo n.º 6
0
                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);

                    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);
                }