public void OpenSessionsAreSentIfSendIntervalIsExceeded()
        {
            // given
            var clientIp = "127.0.0.1";

            var lastSendTime   = 1;
            var sendInterval   = 1000;
            var statusResponse = new StatusResponse(logger, string.Empty, Response.HttpOk, new Dictionary <string, List <string> >());

            context.LastOpenSessionBeaconSendTime.Returns(lastSendTime);
            context.SendInterval.Returns(sendInterval);
            context.CurrentTimestamp.Returns(lastSendTime + sendInterval + 1);

            httpClient.SendBeaconRequest(Arg.Any <string>(), Arg.Any <byte[]>()).Returns(x => statusResponse);

            var session = new SessionWrapper(CreateValidSession(clientIp));

            session.UpdateBeaconConfiguration(new BeaconConfiguration(1, DataCollectionLevel.OFF, CrashReportingLevel.OFF));
            openSessions.Add(session);

            // when
            var target = new BeaconSendingCaptureOnState();

            target.Execute(context);

            // then
            httpClient.Received(1).SendBeaconRequest(clientIp, Arg.Any <byte[]>());
            context.Received(1).HandleStatusResponse(statusResponse);
            Assert.That(context.LastOpenSessionBeaconSendTime, Is.EqualTo(context.CurrentTimestamp)); // assert send time update
        }
Beispiel #2
0
        public void OpenSessionsAreNotSentIfSendIntervalIsNotExceeded()
        {
            // given
            var clientIp = "127.0.0.1";

            var lastSendTime = 1;
            var sendInterval = 1000;

            context.LastOpenSessionBeaconSendTime.Returns(lastSendTime);
            context.SendInterval.Returns(sendInterval);
            context.CurrentTimestamp.Returns(lastSendTime + 1);

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

            var session = new SessionWrapper(CreateValidSession(clientIp));

            session.UpdateBeaconConfiguration(new BeaconConfiguration(1, DataCollectionLevel.OFF, CrashReportingLevel.OFF));
            openSessions.Add(session);

            // when
            var target = new BeaconSendingCaptureOnState();

            target.Execute(context);

            // then
            httpClient.DidNotReceive().SendBeaconRequest(clientIp, Arg.Any <byte[]>());
            context.DidNotReceive().HandleStatusResponse(Arg.Any <StatusResponse>());
        }
Beispiel #3
0
        public void WhenBeaconConfigurationIsSetSendingIsDisallowedIfMultiplicityIsLessThanZero()
        {
            // given
            var target = new SessionWrapper(wrappedSession);

            // when
            target.UpdateBeaconConfiguration(new BeaconConfiguration(-1, DataCollectionLevel.OFF, CrashReportingLevel.OFF));

            // then
            Assert.That(target.IsDataSendingAllowed, Is.False);
        }
Beispiel #4
0
        public void AfterUpdatingTheBeaconConfigurationTheBeaconConfigurationIsSet()
        {
            // given
            var target           = new SessionWrapper(wrappedSession);
            var newConfiguration = new BeaconConfiguration(42, DataCollectionLevel.OFF, CrashReportingLevel.OFF);

            // when updating
            target.UpdateBeaconConfiguration(newConfiguration);

            // then
            Assert.That(target.IsBeaconConfigurationSet, Is.True);

            // also verify that Session has been invoked
            Assert.That(wrappedSession.BeaconConfiguration, Is.SameAs(newConfiguration));
        }
Beispiel #5
0
        public void UnsuccessfulFinishedSessionsAreNotRemovedFromCache()
        {
            //given
            var target = new BeaconSendingCaptureOnState();

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

            finishedSession.UpdateBeaconConfiguration(new BeaconConfiguration(1, DataCollectionLevel.OFF, CrashReportingLevel.OFF));
            finishedSessions.Add(finishedSession);
            httpClient.SendBeaconRequest(Arg.Any <string>(), Arg.Any <byte[]>()).Returns((StatusResponse)null);

            //when calling execute
            target.Execute(context);

            var tmp = context.Received(1).FinishedAndConfiguredSessions;

            context.Received(0).RemoveSession(finishedSession);
        }
Beispiel #6
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);
        }
Beispiel #7
0
        public void TransitionToCaptureOffStateIsPerformed()
        {
            // given
            var clientIp = "127.0.0.1";

            context.IsCaptureOn.Returns(false);
            var statusResponse = new StatusResponse(string.Empty, 200, new Dictionary <string, List <string> >());

            var session = new SessionWrapper(CreateValidSession(clientIp));

            session.UpdateBeaconConfiguration(new BeaconConfiguration(1, DataCollectionLevel.OFF, CrashReportingLevel.OFF));
            finishedSessions.Add(session);
            httpClient.SendBeaconRequest(Arg.Any <string>(), Arg.Any <byte[]>()).Returns(x => statusResponse);

            // when
            var target = new BeaconSendingCaptureOnState();

            target.Execute(context);

            // then
            context.Received(1).NextState = Arg.Any <BeaconSendingCaptureOffState>();
        }