public void ABeaconSendingCaptureOffStateStaysInOffStateWhenServerRespondsWithTooManyRequests() { //given var target = new BeaconSendingCaptureOffState(12345); var responseHeaders = new Dictionary <string, List <string> > { { Response.ResponseKeyRetryAfter, new List <string> { "1234" } } }; var tooManyRequestsResponse = new StatusResponse(logger, string.Empty, Response.HttpTooManyRequests, responseHeaders); httpClient.SendStatusRequest().Returns(tooManyRequestsResponse); context.IsCaptureOn.Returns(false); AbstractBeaconSendingState capturedState = null; context.NextState = Arg.Do <AbstractBeaconSendingState>(x => capturedState = x); // when calling execute target.Execute(context); // then verify next state Assert.That(capturedState, Is.Not.Null); Assert.That(capturedState, Is.InstanceOf <BeaconSendingCaptureOffState>()); Assert.That(((BeaconSendingCaptureOffState)capturedState).sleepTimeInMilliseconds, Is.EqualTo(1234 * 1000)); }
public void ABeaconSendingCaptureOffStateStaysInOffStateWhenServerRespondsWithTooManyRequests() { //given var target = new BeaconSendingCaptureOffState(12345); const int retryTimeout = 1234; var tooManyRequestsResponse = Substitute.For <IStatusResponse>(); tooManyRequestsResponse.ResponseCode.Returns(StatusResponse.HttpTooManyRequests); tooManyRequestsResponse.IsErroneousResponse.Returns(true); tooManyRequestsResponse.GetRetryAfterInMilliseconds().Returns(retryTimeout); mockHttpClient.SendStatusRequest(Arg.Any <IAdditionalQueryParameters>()).Returns(tooManyRequestsResponse); mockContext.IsCaptureOn.Returns(false); AbstractBeaconSendingState capturedState = null; mockContext.NextState = Arg.Do <AbstractBeaconSendingState>(x => capturedState = x); // when calling execute target.Execute(mockContext); // then verify next state Assert.That(capturedState, Is.Not.Null); Assert.That(capturedState, Is.InstanceOf <BeaconSendingCaptureOffState>()); Assert.That(((BeaconSendingCaptureOffState)capturedState).SleepTimeInMilliseconds, Is.EqualTo(retryTimeout)); }
public void SleepIsCalledOnEntry() { // given var target = new BeaconSendingCaptureOffState(); // when target.Execute(mockContext); // then mockContext.Received(1).Sleep(BeaconSendingCaptureOffState.StatusCheckInterval); }
public void SleepIsNotCalledIfShutdownIsRequested() { // given mockContext.IsShutdownRequested.Returns(true); var target = new BeaconSendingCaptureOffState(); // when target.Execute(mockContext); // then mockContext.DidNotReceive().Sleep(Arg.Any <int>()); }
public void StatusRequestIsRetried() { // given mockHttpClient.SendStatusRequest(Arg.Any <IAdditionalQueryParameters>()).Returns((StatusResponse)null); // always return null var target = new BeaconSendingCaptureOffState(); // when target.Execute(mockContext); // then mockHttpClient.Received(6).SendStatusRequest(mockContext); }
public void TransitionToFlushStateIsPerformedOnShutdown() { // given mockContext.IsShutdownRequested.Returns(true); var target = new BeaconSendingCaptureOffState(); // when target.Execute(mockContext); // then mockContext.Received(1).NextState = Arg.Any <BeaconSendingFlushSessionsState>(); }
public void ABeaconSendingCaptureOffStateWaitsForGivenTime() { //given var target = new BeaconSendingCaptureOffState(12345); context.IsCaptureOn.Returns(true); // when calling execute target.Execute(context); // then verify the custom amount of time was waited context.Received(1).Sleep(12345); }
public void StatusRequestIsRetried() { // given httpClient.SendStatusRequest().Returns((StatusResponse)null); // always return null // when var target = new BeaconSendingCaptureOffState(); target.Execute(context); // then httpClient.Received(6).SendStatusRequest(); }
public void TransitionToCaptureOnStateIsPerformed() { // given context.IsCaptureOn.Returns(true); httpClient.SendStatusRequest().Returns(new StatusResponse(logger, string.Empty, 200, new Dictionary <string, List <string> >())); // when var target = new BeaconSendingCaptureOffState(); target.Execute(context); // then context.Received(1).NextState = Arg.Any <BeaconSendingCaptureOnState>(); }
public void ABeaconSendingCaptureOffStateWaitsForGivenTime() { //given const int sleepTime = 12345; var target = new BeaconSendingCaptureOffState(sleepTime); mockContext.IsCaptureOn.Returns(true); // when target.Execute(mockContext); // then mockContext.Received(1).Sleep(sleepTime); }
public void SleepIsCalledOnEntry() { // given context.CurrentTimestamp.Returns(0); context.LastStatusCheckTime.Returns(0); httpClient.SendStatusRequest().Returns(new StatusResponse(logger, string.Empty, 200, new Dictionary <string, List <string> >())); // when var target = new BeaconSendingCaptureOffState(); target.Execute(context); // then context.Received(1).Sleep(BeaconSendingCaptureOffState.STATUS_CHECK_INTERVAL); }
public void ABeaconSendingCaptureOffStateTransitionsToCaptureOnStateWhenCapturingActive() { // given var target = new BeaconSendingCaptureOffState(); mockContext.IsCaptureOn.Returns(true); // when target.Execute(mockContext); // then mockContext.Received(1).DisableCaptureAndClear(); mockContext.Received(1).LastStatusCheckTime = Arg.Any <long>(); mockContext.Received(1).NextState = Arg.Any <BeaconSendingCaptureOnState>(); }
public void SleepIsNotCalledIfShutdownIsRequested() { // given context.IsShutdownRequested.Returns(true); context.CurrentTimestamp.Returns(0); context.LastStatusCheckTime.Returns(0); httpClient.SendStatusRequest().Returns(new StatusResponse(logger, string.Empty, 200, new Dictionary <string, List <string> >())); // when var target = new BeaconSendingCaptureOffState(); target.Execute(context); // then context.DidNotReceive().Sleep(Arg.Any <int>()); }
public void TransitionToTimeSyncIsPerformedIfNotDoneYet() { // given context.IsCaptureOn.Returns(true); context.IsTimeSyncSupported.Returns(true); httpClient.SendStatusRequest().Returns(new StatusResponse(string.Empty, 200, new Dictionary <string, List <string> >())); var target = new BeaconSendingCaptureOffState(); // when target.Execute(context); // then context.Received(1).NextState = Arg.Any <BeaconSendingTimeSyncState>(); context.Received(1).NextState = Arg.Is <BeaconSendingTimeSyncState>(arg => arg.IsInitialTimeSync == true); }
public void TransitionToCaptureOnStateIsPerformed() { // given context.IsCaptureOn.Returns(true); context.IsTimeSyncSupported.Returns(true); context.IsTimeSynced.Returns(true); httpClient.SendStatusRequest().Returns(new StatusResponse(string.Empty, 200)); // when var target = new BeaconSendingCaptureOffState(); target.Execute(context); // then context.Received(1).NextState = Arg.Any <BeaconSendingCaptureOnState>(); }