Пример #1
0
        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();
        }
Пример #2
0
        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();
        }
Пример #3
0
        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");
        }
Пример #4
0
        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));
        }
Пример #5
0
        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();
        }
Пример #6
0
        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();
        }