public void ABeaconSendingFlushSessionStateStopsSendingIfTooManyRequestsResponseWasReceived()
        {
            // given
            var target = new BeaconSendingFlushSessionsState();

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

            response.ResponseCode.Returns(StatusResponse.HttpTooManyRequests);
            response.IsErroneousResponse.Returns(true);
            mockSession3Closed.SendBeacon(Arg.Any <IHttpClientProvider>(), Arg.Any <IAdditionalQueryParameters>())
            .Returns(response);

            // when
            target.Execute(mockContext);

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

            mockSession1Open.Received(0)
            .SendBeacon(Arg.Any <IHttpClientProvider>(), Arg.Any <IAdditionalQueryParameters>());
            mockSession1Open.Received(1).ClearCapturedData();

            mockSession2Open.Received(0)
            .SendBeacon(Arg.Any <IHttpClientProvider>(), Arg.Any <IAdditionalQueryParameters>());
            mockSession2Open.Received(1).ClearCapturedData();
        }
        public void ABeaconSendingFlushSessionStateDoesNotSendIfSendingIsNotAllowed()
        {
            // given
            var target = new BeaconSendingFlushSessionsState();

            mockSession1Open.IsDataSendingAllowed.Returns(false);
            mockSession2Open.IsDataSendingAllowed.Returns(false);
            mockSession3Closed.IsDataSendingAllowed.Returns(false);

            // when
            target.Execute(mockContext);

            // then
            mockSession1Open.Received(0)
            .SendBeacon(Arg.Any <IHttpClientProvider>(), Arg.Any <IAdditionalQueryParameters>());
            mockSession1Open.Received(1).ClearCapturedData();

            mockSession2Open.Received(0)
            .SendBeacon(Arg.Any <IHttpClientProvider>(), Arg.Any <IAdditionalQueryParameters>());
            mockSession2Open.Received(1).ClearCapturedData();

            mockSession3Closed.Received(0)
            .SendBeacon(Arg.Any <IHttpClientProvider>(), Arg.Any <IAdditionalQueryParameters>());
            mockSession3Closed.Received(1).ClearCapturedData();
        }
        public void ABeaconSendingFlushSessionStateHasTerminalStateBeaconSendingTerminalState()
        {
            // when
            var target = new BeaconSendingFlushSessionsState();

            // then
            Assert.That(target.ShutdownState, Is.InstanceOf(typeof(BeaconSendingTerminalState)));
        }
        public void ABeaconSendingFlushSessionStateIsNotATerminalState()
        {
            // when
            var target = new BeaconSendingFlushSessionsState();

            // then
            Assert.That(target.IsTerminalState, Is.False);
        }
        public void ToStringReturnStateName()
        {
            // given
            var target = new BeaconSendingFlushSessionsState();

            // then
            Assert.That(target.ToString(), Is.EqualTo("FlushSessions"));
        }
        public void ABeaconSendingFlushSessionsStateTransitionsToTerminalStateWhenDataIsSent()
        {
            // given
            var target = new BeaconSendingFlushSessionsState();

            // when
            target.Execute(mockContext);

            // then verify transition to terminal state
            mockContext.Received(1).NextState = Arg.Any <BeaconSendingTerminalState>();
        }
        public void ABeaconSendingFlushSessionsStateClosesOpenSessions()
        {
            // given
            var target = new BeaconSendingFlushSessionsState();

            // when
            target.Execute(mockContext);

            // then
            mockSession1Open.Received(1).End(false);
            mockSession2Open.Received(1).End(false);
        }
        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);
        }
        public void ABeaconSendingFlushSessionStateEnablesCaptureForNotConfiguredSessions()
        {
            // given
            mockContext.GetAllNotConfiguredSessions().Returns(new List <ISessionInternals> {
                mockSession1Open, mockSession2Open
            });
            var target = new BeaconSendingFlushSessionsState();

            // when
            target.Execute(mockContext);

            // then
            mockSession1Open.Received(1).EnableCapture();
            mockSession2Open.Received(1).EnableCapture();
        }
        public void FinishedSessionsAreSent()
        {
            // given
            finishedSessions.Enqueue(CreateValidSession("127.0.0.1"));
            finishedSessions.Enqueue(CreateValidSession("127.0.0.1"));

            httpClient.SendBeaconRequest(Arg.Any <string>(), Arg.Any <byte[]>()).Returns(x => new StatusResponse(string.Empty, 200));

            // when
            var target = new BeaconSendingFlushSessionsState();

            target.Execute(context);

            // then
            httpClient.Received(2).SendBeaconRequest(Arg.Any <string>(), Arg.Any <byte[]>());
        }
Esempio n. 11
0
        public void ABeaconSendingFlushSessionsStateClosesOpenSessions()
        {
            // given
            var target = new BeaconSendingFlushSessionsState();

            var sessionOne = new SessionWrapper(CreateValidSession("127.0.0.1"));

            sessionOne.UpdateBeaconConfiguration(new BeaconConfiguration(1, DataCollectionLevel.OFF, CrashReportingLevel.OFF));
            var sessionTwo = new SessionWrapper(CreateValidSession("127.0.0.2"));

            sessionTwo.UpdateBeaconConfiguration(new BeaconConfiguration(1, DataCollectionLevel.OFF, CrashReportingLevel.OFF));

            openSessions.AddRange(new[] { sessionOne, sessionTwo });

            // when
            target.Execute(context);

            // verify that open sessions are closed
            context.Received(1).FinishSession(sessionOne.Session);
            context.Received(1).FinishSession(sessionTwo.Session);
        }
Esempio n. 12
0
        public void ABeaconSendingFlushSessionsStateConfiguresAllUnconfiguredSessions()
        {
            // given
            var target = new BeaconSendingFlushSessionsState();

            var sessionOne   = new SessionWrapper(CreateValidSession("127.0.0.1"));
            var sessionTwo   = new SessionWrapper(CreateValidSession("127.0.0.2"));
            var sessionThree = new SessionWrapper(CreateValidSession("127.0.0.2"));

            // end one session to demonstrate that those which are already ended are also configured
            sessionThree.End();
            newSessions.AddRange(new[] { sessionOne, sessionTwo, sessionThree });

            // when
            target.Execute(context);

            // verify that all three sessions are configured
            Assert.That(sessionOne.IsBeaconConfigurationSet, Is.True);
            Assert.That(sessionOne.BeaconConfiguration.Multiplicity, Is.EqualTo(1));
            Assert.That(sessionTwo.IsBeaconConfigurationSet, Is.True);
            Assert.That(sessionTwo.BeaconConfiguration.Multiplicity, Is.EqualTo(1));
            Assert.That(sessionThree.IsBeaconConfigurationSet, Is.True);
            Assert.That(sessionThree.BeaconConfiguration.Multiplicity, Is.EqualTo(1));
        }