Beispiel #1
0
        public void When_reading_non_padded_hexadecimal_string_it_should_throw(string dataToParse, params byte[] expectedData)
        {
            // Arrange
            _parser = CreateSubject(dataToParse);
            int position = 0;

            // Act
            Func <byte> readByte = () => _parser.ReadByte();

            foreach (byte expectedByte in expectedData)
            {
                position += 2;
                readByte.Should()
                .NotThrow("two or more characters are still on the stream")
                .Which.Should()
                .Be(expectedByte);
            }

            // Assert
            _parser.AtEndOfStream()
            .Should()
            .BeFalse("the last char is not read yet");

            ProtocolReaderException ex = readByte
                                         .Should()
                                         .Throw <ProtocolReaderException>("the stream does not have enough hex chars left")
                                         .Which;

            ex.Message.Should().StartWith("Reached end of stream");
            ex.Position.Should().Be(position);
            ex.Length.Should().Be(dataToParse.Length);

            _parser.AtEndOfStream().Should().BeTrue();
        }
Beispiel #2
0
        public void When_reading_encapsulated_text_that_does_not_start_with_char_should_throw()
        {
            // Arrange
            _parser = CreateSubject("data");

            // Act
            Action act = () => _parser.ReadEncapsulatedString('|');

            // Assert
            ProtocolReaderException ex = act.Should().Throw <ProtocolReaderException>().Which;

            ex.Position.Should().Be(0);
            ex.Length.Should().Be(4);
        }
Beispiel #3
0
        public void When_reading_byte_from_data_that_is_not_hexadecimal_it_should_throw()
        {
            // Arrange
            _parser = CreateSubject("Zs");

            // Act
            Action readByte = () => _parser.ReadByte();

            // Assert
            ProtocolReaderException ex = readByte.Should()
                                         .Throw <ProtocolReaderException>()
                                         .Which;

            ex.InnerException.Should().BeOfType <FormatException>()
            .Which.Message.Should().Be("Could not find any recognizable digits.");
            ex.Position.Should().Be(0);
            ex.Length.Should().Be(2);

            _parser.AtEndOfStream().Should().BeTrue();
        }