Ejemplo n.º 1
0
                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);
                }
Ejemplo n.º 2
0
                public void ShouldThrowExceptionIfMarkerByteNotString()
                {
                    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.UnpackString());

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

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

                    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);
                }
Ejemplo n.º 6
0
                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);
                }
Ejemplo n.º 7
0
                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 <ProtocolException>();
                    mockInput.Verify(x => x.ReadByte(), Times.Once);
                    mockInput.Verify(x => x.ReadInt(), Times.Once);
                }
Ejemplo n.º 8
0
                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);
                }