public async Task Given_request_content_is_empty_and_expected_content_is_also_empty_when_matching_should_match()
        {
            var request = new HttpRequestMessage();

            _sut = new ContentMatcher();

            // Act & assert
            (await _sut.IsMatchAsync(new MockHttpRequestContext(request))).Should().BeTrue();
        }
        public async Task Given_request_content_is_empty_and_expected_content_is_not_when_matching_should_not_match()
        {
            var request = new HttpRequestMessage();

            _sut = new ContentMatcher("some data", Encoding.UTF8);

            // Act & assert
            (await _sut.IsMatchAsync(new MockHttpRequestContext(request))).Should().BeFalse();
        }
        public void When_formatting_should_return_human_readable_representation(string content, string expectedText)
        {
            // If theory starts with ByteArray string, we will actually act as if the content was in binary form (thus no encoding)
            _sut = content.StartsWith("ByteArray")
                                ? new ContentMatcher(Encoding.UTF8.GetBytes(content))
                                : new ContentMatcher(content, Encoding.UTF8);

            // Act
            string displayText = _sut.ToString();

            // Assert
            displayText.Should().Be(expectedText);
        }
        public async Task Given_null_context_when_matching_it_should_throw()
        {
            _sut = new ContentMatcher("", null);
            MockHttpRequestContext requestContext = null;

            // Act
            // ReSharper disable once ExpressionIsAlwaysNull
            Func <Task> act = () => _sut.IsMatchAsync(requestContext);

            // Assert
            await act.Should()
            .ThrowAsync <ArgumentNullException>()
            .WithParamName(nameof(requestContext));
        }
        public async Task Given_request_content_does_not_equal_expected_content_when_matching_should_not_match()
        {
            const string content         = "some http request content";
            const string expectedContent = "expected content";

            var request = new HttpRequestMessage
            {
                Content = new StringContent(content)
            };

            _sut = new ContentMatcher(expectedContent, Encoding.UTF8);

            // Act & assert
            (await _sut.IsMatchAsync(new MockHttpRequestContext(request))).Should().BeFalse();
        }
        public async Task Given_request_content_equals_expected_content_when_matching_should_match(string content, string encoding)
        {
            string   expectedContent = content;
            Encoding enc             = Encoding.GetEncoding(encoding);

            var request = new HttpRequestMessage
            {
                Content = new StringContent(content, enc)
            };

            _sut = new ContentMatcher(expectedContent, enc);

            // Act & assert
            (await _sut.IsMatchAsync(new MockHttpRequestContext(request))).Should().BeTrue();
        }
        public async Task Given_request_content_equals_expected_content_when_matching_twice_should_match_twice()
        {
            const string content         = "some http request content";
            const string expectedContent = content;

            var request = new HttpRequestMessage
            {
                Content = new StringContent(content)
            };

            _sut = new ContentMatcher(expectedContent, Encoding.UTF8);

            // Act & assert
            var ctx = new MockHttpRequestContext(request);

            (await _sut.IsMatchAsync(ctx)).Should().BeTrue();
            (await _sut.IsMatchAsync(ctx)).Should().BeTrue("the content should be buffered and matchable more than once");
        }