public void CountMessages_ShouldReturnZero_WhenResponseContainsEmptyBytes()
        {
            var reader = new ReceiveMessageResponseReader();

            var count = reader.CountMessages(Array.Empty <byte>());

            count.Should().Be(0);
        }
        public void CountMessages_ShouldReturnZero_WhenResponseContainsNoMessages()
        {
            var bytes = Encoding.UTF8.GetBytes(EmptyResponse);

            var reader = new ReceiveMessageResponseReader();

            var count = reader.CountMessages(bytes);

            count.Should().Be(0);
        }
        public void TryGetNextMessageBytes_ShouldReturnAppropriateTuple_WhenResponseBytesContainsEmptyBytes()
        {
            var reader = new ReceiveMessageResponseReader();

            var messageFound = reader.TryGetNextMessageBytes(Array.Empty <byte>(), out var messageBytes, out var endPosition);

            var isDefault = messageBytes == default;

            messageFound.Should().BeFalse();
            isDefault.Should().BeTrue();
            endPosition.Should().Be(0);
        }
        public void TryGetNextMessageBytes_ShouldReturnAppropriateTuple_WhenResponseBytesContainsNoMessage()
        {
            var bytes = Encoding.UTF8.GetBytes(EmptyResponse);

            var reader = new ReceiveMessageResponseReader();

            var messageFound = reader.TryGetNextMessageBytes(bytes, out var messageBytes, out var endPosition);

            var isDefault = messageBytes == default;

            messageFound.Should().BeFalse();
            isDefault.Should().BeTrue();
            endPosition.Should().Be(0);
        }
        public void CountMessages_ShouldNotReturnGreaterThanTen_EvenIfDataContainsMoreMessages()
        {
            var sb = new StringBuilder();

            sb.Append(ResponseStart);
            for (var i = 0; i < 15; i++) // response with 15 messages
            {
                sb.Append(Message);
            }
            sb.Append(ResponseEnd);

            var bytes = Encoding.UTF8.GetBytes(sb.ToString());

            var reader = new ReceiveMessageResponseReader();

            var count = reader.CountMessages(bytes);

            count.Should().Be(10, because: "An AWS SQS receive request returns a maximum of 10 messages");
        }
        public void CountMessages_ShouldReturnCorrectCount_WhenResponseContainsMessages(int messages)
        {
            var sb = new StringBuilder();

            sb.Append(ResponseStart);
            for (var i = 0; i < messages; i++)
            {
                sb.Append(Message);
            }
            sb.Append(ResponseEnd);

            var bytes = Encoding.UTF8.GetBytes(sb.ToString());

            var reader = new ReceiveMessageResponseReader();

            var count = reader.CountMessages(bytes);

            count.Should().Be(messages);
        }
        public void TryGetNextMessageBytes_ShouldReturnAppropriateTupleWithMessage_WhenResponseBytesContainsAMessage()
        {
            var sb = new StringBuilder();

            sb.Append(ResponseStart);
            sb.Append(Message);
            sb.Append(ResponseEnd);

            var bytes = Encoding.UTF8.GetBytes(sb.ToString());

            var reader = new ReceiveMessageResponseReader();

            var messageFound = reader.TryGetNextMessageBytes(bytes, out var messageBytes, out var endPosition);

            var messageSpanIsEqual = messageBytes.SequenceEqual(Encoding.UTF8.GetBytes(Message));

            messageFound.Should().BeTrue();
            messageSpanIsEqual.Should().BeTrue();
            endPosition.Should().Be(ResponseStart.Length + Message.Length);
        }
예제 #8
0
        public int CountMessages()
        {
            var reader = new ReceiveMessageResponseReader();

            return(reader.CountMessages(_responseBytes));
        }