Пример #1
0
        public void IsSecureConnection_WhenHttpsConnection_ReturnsTrue()
        {
            filePayload.DownloadUri = new Uri("https://localhost/");

            bool actual = systemUnderTest.IsSecureConnection(filePayload);

            Assert.That(actual, Is.True);
        }
        public void DownloadFile_WhenSecureConnectionType_OnlyTrySecureDownload()
        {
            var webException = new WebException();

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

            var firstCall = true;

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

            Assert.Throws(Is.EqualTo(webException), () => systemUnderTest.DownloadFile(filePayload));

            secureFilePayloadServiceMock.DidNotReceive().DisableSecureFilePayload(Arg.Any <FilePayload>());
            loggingServiceMock.Received().LogException(webException);
        }
Пример #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 bool IsSecureConnection(FilePayload filePayload)
 {
     return(testHarnessSettingsService.IsSecureFilePayloadDisabled() ||
            secureFilePayloadService.IsSecureConnection(filePayload));
 }