public void DownloadFile_WhenUnsecureConnectionTypeAndFirstDownloadThrowsWebException_TryUnsecureDownload()
        {
            var webException = new WebException();

            secureFilePayloadServiceMock.IsSecureConnection(filePayload).Returns(false);

            var firstCall = true;

            downloadServiceMock.When(service => service.DownloadFile(filePayload)).Do(info =>
            {
                if (firstCall)
                {
                    firstCall = false;
                    throw webException;
                }
            });

            systemUnderTest.DownloadFile(filePayload);

            Received.InOrder(() =>
            {
                secureFilePayloadServiceMock.EnableSecureFilePayload(filePayload);
                downloadServiceMock.DownloadFile(filePayload);
                loggingServiceMock.LogException(webException);
                secureFilePayloadServiceMock.DisableSecureFilePayload(filePayload);
                downloadServiceMock.DownloadFile(filePayload);
            });
        }
Beispiel #2
0
        public void DisableSecureFilePayload_WhenHttpsConnection_ChangesToHttp()
        {
            filePayload.DownloadUri = new Uri("https://localhost/");

            systemUnderTest.DisableSecureFilePayload(filePayload);

            Assert.That(filePayload.DownloadUri.Scheme, Is.EqualTo(Uri.UriSchemeHttp));
            loggingServiceMock.Received()
            .LogVerbose(
                $"Changing scheme https to http{Environment.NewLine}Old Uri: https://localhost/{Environment.NewLine}New Uri: http://localhost/");
        }
Beispiel #3
0
        public void DownloadFile(FilePayload filePayload)
        {
            bool originalWasNotSecure = !secureFilePayloadService.IsSecureConnection(filePayload);

            try
            {
                secureFilePayloadService.EnableSecureFilePayload(filePayload);
                downloadService.DownloadFile(filePayload);
            }
            catch (WebException webException)
            {
                loggingService.LogException(webException);

                if (originalWasNotSecure)
                {
                    secureFilePayloadService.DisableSecureFilePayload(filePayload);
                    downloadService.DownloadFile(filePayload);
                }
                else
                {
                    throw;
                }
            }
        }
 public void DisableSecureFilePayload(FilePayload filePayload)
 {
     secureFilePayloadService.DisableSecureFilePayload(filePayload);
 }