public void ABeaconSendingCaptureOnStateSendsFinishedSessions()
        {
            // given
            var target = new BeaconSendingCaptureOnState();

            var statusResponse = Substitute.For <IStatusResponse>();

            statusResponse.ResponseCode.Returns(StatusResponse.HttpOk);
            statusResponse.IsErroneousResponse.Returns(false);

            mockSession3Finished.SendBeacon(Arg.Any <IHttpClientProvider>(), Arg.Any <IAdditionalQueryParameters>())
            .Returns(statusResponse);
            mockSession3Finished.IsDataSendingAllowed.Returns(true);
            mockSession4Finished.SendBeacon(Arg.Any <IHttpClientProvider>(), Arg.Any <IAdditionalQueryParameters>())
            .Returns(statusResponse);
            mockSession4Finished.IsDataSendingAllowed.Returns(true);

            // when
            target.Execute(mockContext);

            // then
            mockSession3Finished.Received(1).SendBeacon(Arg.Any <IHttpClientProvider>(), mockContext);
            mockSession4Finished.Received(1).SendBeacon(Arg.Any <IHttpClientProvider>(), mockContext);

            // also verify that the sessions are removed
            mockContext.Received(1).RemoveSession(mockSession3Finished);
            mockContext.Received(1).RemoveSession(mockSession4Finished);
        }
        public void ABeaconSendingFlushSessionStateSendsAllOpenAndClosedBeacons()
        {
            // given
            var target = new BeaconSendingFlushSessionsState();

            // when
            target.Execute(mockContext);

            // then
            mockSession1Open.Received(1).SendBeacon(Arg.Any <IHttpClientProvider>(), mockContext);
            mockSession2Open.Received(1).SendBeacon(Arg.Any <IHttpClientProvider>(), mockContext);
            mockSession3Closed.Received(1).SendBeacon(Arg.Any <IHttpClientProvider>(), mockContext);
        }
Beispiel #3
0
        public void CloseOrEnqueueForClosingDoesNotAddSessionIfItCanBeClosed()
        {
            // given
            mockSession.TryEnd().Returns(true);
            var target = CreateContext();
            ISessionWatchdogContext targetExplicit = target;

            // when
            targetExplicit.CloseOrEnqueueForClosing(mockSession, 0);

            // then
            Assert.That(target.GetSessionsToClose().Count, Is.EqualTo(0));
            mockSession.Received(1).TryEnd();
        }
        public void ABeaconSendingCaptureOnStateSendsOpenSessionsIfNotExpired()
        {
            // given
            var target = new BeaconSendingCaptureOnState();

            mockSession1Open.IsDataSendingAllowed.Returns(true);
            mockSession2Open.IsDataSendingAllowed.Returns(true);

            // when
            target.Execute(mockContext);

            // then
            mockSession1Open.Received(1).SendBeacon(Arg.Any <IHttpClientProvider>(), mockContext);
            mockSession2Open.Received(1).SendBeacon(Arg.Any <IHttpClientProvider>(), mockContext);
            mockContext.Received(1).LastOpenSessionBeaconSendTime = Arg.Any <long>();
        }
        public void NewSessionRequestsAreMadeForAllNotConfiguredSessions()
        {
            // given
            const int multiplicity = 5;
            var       target       = new BeaconSendingCaptureOnState();

            var successResponse = StatusResponse.CreateSuccessResponse(mockLogger,
                                                                       ResponseAttributes.WithJsonDefaults().WithMultiplicity(multiplicity).Build(), 200,
                                                                       new Dictionary <string, List <string> >());

            var mockClient = Substitute.For <IHttpClient>();

            mockContext.GetHttpClient().Returns(mockClient);
            mockContext.GetAllNotConfiguredSessions()
            .Returns(new List <ISessionInternals> {
                mockSession5New, mockSession6New
            });
            mockContext.UpdateFrom(Arg.Any <StatusResponse>()).Returns(successResponse.ResponseAttributes);
            mockClient.SendNewSessionRequest(Arg.Any <IAdditionalQueryParameters>())
            .Returns(successResponse,
                     StatusResponse.CreateErrorResponse(mockLogger, StatusResponse.HttpBadRequest));
            mockSession5New.CanSendNewSessionRequest.Returns(true);
            mockSession6New.CanSendNewSessionRequest.Returns(true);

            IServerConfiguration serverConfigCapture = null;

            mockSession5New.UpdateServerConfiguration(Arg.Do <IServerConfiguration>(c => serverConfigCapture = c));

            // when
            target.Execute(mockContext);

            // verify for both new sessions a new session request has been made
            mockClient.Received(2).SendNewSessionRequest(mockContext);

            // verify first new session has been updated
            Assert.That(serverConfigCapture, Is.Not.Null);
            mockSession5New.Received(1).UpdateServerConfiguration(serverConfigCapture);
            Assert.That(serverConfigCapture.Multiplicity, Is.EqualTo(multiplicity));

            // verify second new session decreased number of retries
            mockSession6New.Received(1).DecreaseNumRemainingSessionRequests();
        }
        public void ABeaconSendingFlushSessionsStateClosesOpenSessions()
        {
            // given
            var target = new BeaconSendingFlushSessionsState();

            // when
            target.Execute(mockContext);

            // then
            mockSession1Open.Received(1).End(false);
            mockSession2Open.Received(1).End(false);
        }