Пример #1
0
        public async Task SslCertFailureResultsInSendFailureException()
        {
            // Arrange
            var mockHttpClientProxy = new MockHttpClientRequestProxy();
            mockHttpClientProxy.SetupException(new WebException("Message", WebExceptionStatus.SendFailure));
            IApiRequestHandler handler = new ApiRequestHandler(new TestHttpUriBuilder(new Uri("http://www.nokia.com")), null, mockHttpClientProxy);
            var rawMessage = "This is the raw body of the message";
            var command = new MockApiCommand(rawMessage, HttpMethod.Head, true);

            // Act
            var response = await handler.SendRequestAsync(command, new MockMusicClientSettings("test", null, null), null, command.HandleRawData, null, null);

            // Assert
            Assert.IsFalse(response.Succeeded);
            Assert.IsTrue(response.Error is SendFailureException);
        }
Пример #2
0
        public async Task ContentIsGzippedIfCommandSpecifies()
        {
            // Arrange
            var mockHttpClientProxy = new MockHttpClientRequestProxy();
            IApiRequestHandler handler = new ApiRequestHandler(new TestHttpUriBuilder(new Uri("http://www.nokia.com")), null, mockHttpClientProxy);
            var rawMessage = "This is the raw body of the message";
            string actualMessage;
            var command = new MockApiCommand(rawMessage, HttpMethod.Head, true);

            // Act
            await handler.SendRequestAsync(command, new MockMusicClientSettings("test", null, null), null, command.HandleRawData, null, null);
            using (Stream decompressedStream = new GZipStream(await mockHttpClientProxy.RequestMessage.Content.ReadAsStreamAsync(), CompressionMode.Decompress, true))
            {
                using (TextReader reader = new StreamReader(decompressedStream, Encoding.UTF8))
                {
                    actualMessage = reader.ReadToEnd();
                }    
            }

            // Assert
            Assert.AreEqual(rawMessage, actualMessage);
            Assert.AreEqual("gzip", mockHttpClientProxy.RequestMessage.Content.Headers.ContentEncoding.First());
        }