public void WhenServerReturnDnsErrorRequestWillBeRetried() { int peekCounts = 0; // Setup transmission.SendAsync() to throw WebException with ProxyNameResolutionFailure failure WebException webException = new WebException( string.Empty, new Exception(), WebExceptionStatus.ProxyNameResolutionFailure, null); TransmissionMock.Setup(transmission => transmission.SendAsync()).Throws(webException); // Setup Storage.Peek() to return the mocked transmission, and stop the loop after 10 peeks. StorageBaseMock.Setup(storage => storage.Peek()) .Returns(TransmissionMock.Object) .Callback(() => { if (peekCounts++ == 10) { Sender.StopAsync(); } }); // Act Sender.SendLoop(); _deleteCount.Should().Be(0, "delete is not expected to be called on Dns errors since it , request is expected to be retried forever."); }
public void WhenServerReturn400IntervalWillBe10Seconds() { int peekCounts = 0; // Setup transmission.SendAsync() to throw WebException that has 400 status Code TransmissionMock.Setup(transmission => transmission.SendAsync()) .Throws(GenerateWebException((HttpStatusCode)400)); // Setup Storage.Peek() to return the mocked transmission, and stop the loop after 10 peeks. StorageBaseMock.Setup(storage => storage.Peek()) .Returns(TransmissionMock.Object) .Callback(() => { if (peekCounts++ == 10) { Sender.StopAsync(); } }); // Cache the interval (it is a parameter passed to the Send method). TimeSpan intervalOnSixIteration = TimeSpan.Zero; Sender.OnSend = interval => intervalOnSixIteration = interval; // Act Sender.SendLoop(); intervalOnSixIteration.TotalSeconds.Should().Be(5); _deleteCount.Should().Be(10, "400 should not be retried so delete should always be called."); }
public void WhenServerReturn503TransmissionWillBeRetried() { var Sender = GetSenderUnderTest(); int peekCounts = 0; // Setup transmission.SendAsync() to throw WebException that has 503 status Code TransmissionMock.Setup(transmission => transmission.SendAsync()) .Throws(GenerateWebException((HttpStatusCode)503)); // Setup Storage.Peek() to return the mocked transmission, and stop the loop after 10 peeks. StorageBaseMock.Setup(storage => storage.Peek()) .Returns(TransmissionMock.Object) .Callback(() => { if (peekCounts++ == 10) { Sender.StopAsync(); } }); // Act Sender.SendLoop(); _deleteCount.Should().Be(0, "delete is not expected to be called on 503, request is expected to be send forever."); }