Exemplo n.º 1
0
        public void TryDeserialize_ReturnsNullWhenReaderIsNull()
        {
            HttpClient     httpClient     = new HttpClient();
            HttpClientBase httpClientBase = new HttpClientBase(httpClient, loggerMock.Object);

            var result = httpClientBase.TryDeserialize <ServiceDTO>(null, true);

            result.Should().BeNull();
        }
Exemplo n.º 2
0
        public void TryDeserialize_ReturnsNullWhenResponseNotUnderstandableAndThrowIsFalse()
        {
            HttpClient     httpClient     = new HttpClient();
            HttpClientBase httpClientBase = new HttpClientBase(httpClient, loggerMock.Object);

            using (MemoryStream ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes("")))
            {
                using (StreamReader streamReader = new StreamReader(ms))
                {
                    using (JsonTextReader reader = new JsonTextReader(streamReader))
                    {
                        var result = httpClientBase.TryDeserialize <ServiceDTO>(reader, false);

                        result.Should().BeNull();
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void TryDeserialize_ThrowsExceptionWhenResponseNotUnderstandableAndThrowIsTrue()
        {
            HttpClient     httpClient     = new HttpClient();
            HttpClientBase httpClientBase = new HttpClientBase(httpClient, loggerMock.Object);

            using (MemoryStream ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes("")))
            {
                using (StreamReader streamReader = new StreamReader(ms))
                {
                    using (JsonTextReader reader = new JsonTextReader(streamReader))
                    {
                        Action act = () => httpClientBase.TryDeserialize <bool>(reader, true); // use non-nullable here

                        act.Should()
                        .Throw <Exception>()
                        .WithMessage("Response not understandable");
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void TryDeserialize_ReturnsDeserializedService()
        {
            HttpClient     httpClient     = new HttpClient();
            HttpClientBase httpClientBase = new HttpClientBase(httpClient, loggerMock.Object);

            ServiceDTO dto = new ServiceDTO {
                Code = "dummyservice"
            };

            using (MemoryStream ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes("{\"Code\":\"dummyservice\"}")))
            {
                using (StreamReader streamReader = new StreamReader(ms))
                {
                    using (JsonTextReader reader = new JsonTextReader(streamReader))
                    {
                        var result = httpClientBase.TryDeserialize <ServiceDTO>(reader, true);

                        result.Should().BeEquivalentTo(dto);
                    }
                }
            }
        }