Пример #1
0
        public void Given_content_is_null_when_matching_should_not_throw()
        {
            _sut = new MediaTypeHeaderMatcher(MediaTypeHeaderValue.Parse("text/plain"));

            // Act
            bool?  result = null;
            Action act    = () => result = _sut.IsMatch(new MockHttpRequestContext(new HttpRequestMessage()));

            // Assert
            act.Should().NotThrow();
            result.Should().BeFalse();
        }
Пример #2
0
        public void When_formatting_should_return_human_readable_representation()
        {
            const string expectedText = "MediaType: text/html";

            _sut = new MediaTypeHeaderMatcher(MediaTypeHeaderValue.Parse("text/html"));

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

            // Assert
            displayText.Should().Be(expectedText);
        }
Пример #3
0
        public void Given_null_context_when_matching_it_should_throw()
        {
            _sut = new MediaTypeHeaderMatcher(new MediaTypeHeaderValue("text/plain"));
            MockHttpRequestContext requestContext = null;

            // Act
            // ReSharper disable once ExpressionIsAlwaysNull
            Action act = () => _sut.IsMatch(requestContext);

            // Assert
            act.Should()
            .Throw <ArgumentNullException>()
            .WithParamName(nameof(requestContext));
        }
Пример #4
0
        public void Given_headerValue_equals_expected_headerValue_when_matching_should_match(string headerValue)
        {
            var request = new HttpRequestMessage
            {
                Content = new StringContent("")
                {
                    Headers =
                    {
                        ContentType = MediaTypeHeaderValue.Parse(headerValue)
                    }
                }
            };

            _sut = new MediaTypeHeaderMatcher(MediaTypeHeaderValue.Parse(headerValue));

            // Act & assert
            _sut.IsMatch(new MockHttpRequestContext(request)).Should().BeTrue();
        }
Пример #5
0
        public void Given_headerValue_does_not_equal_expected_headerValue_when_matching_should_not_match()
        {
            const string headerValue         = "text/plain";
            const string expectedHeaderValue = "text/html";

            var request = new HttpRequestMessage
            {
                Content = new StringContent("")
                {
                    Headers =
                    {
                        ContentType = MediaTypeHeaderValue.Parse(headerValue)
                    }
                }
            };

            _sut = new MediaTypeHeaderMatcher(MediaTypeHeaderValue.Parse(expectedHeaderValue));

            // Act & assert
            _sut.IsMatch(new MockHttpRequestContext(request)).Should().BeFalse();
        }