コード例 #1
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>());
        }
        public void EmptyFinishedSessionsAreNotSent()
        {
            // given
            var clientIp = "127.0.0.1";

            finishedSessions.Enqueue(CreateEmptySession(clientIp));

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

            // when
            var target = new BeaconSendingCaptureOnState();

            target.Execute(context);

            // then
            httpClient.DidNotReceive().SendBeaconRequest(clientIp, Arg.Any <byte[]>());
            Assert.That(finishedSessions.Count, Is.EqualTo(0)); // assert empty sessions
            context.DidNotReceive().HandleStatusResponse(Arg.Any <StatusResponse>());
        }