예제 #1
0
        public string GetText(IResponse response)
        {
            if (response == null)
            {
                throw new ArgumentNullException(nameof(response));
            }

            if (response.Body == null)
            {
                return(string.Empty);
            }

            if (response.Body.Length == 0)
            {
                return(string.Empty);
            }

            var charSetName = _contentTypeProvider.GetCharSet(response.Headers);
            var encoding    = string.IsNullOrEmpty(charSetName) ?
                              Config.DefaultEncoding :
                              GetEncoding(charSetName);

            try
            {
                return(encoding.GetString(response.Body));
            }
            catch (Exception ex)
            {
                throw new ExpectationException("Failed to convert response into text.", ex);
            }
        }
예제 #2
0
        public void GetText_When_CharSet_Not_Found_Should_Use_Default_Encoding(string charSet)
        {
            A.CallTo(() => _contentTypeProvider.GetCharSet(_headers)).Returns(charSet);

            _underTest.GetText(_response).Should().Be(ResponseBodyContent);
        }