コード例 #1
0
        public void IsShutdownRequestedIsSetCorrectly()
        {
            var target = new BeaconSendingContext(config, clientProvider, timingProvider);

            Assert.False(target.IsShutdownRequested);

            target.RequestShutdown();

            Assert.True(target.IsShutdownRequested);
        }
コード例 #2
0
        public void CanSleepCustomPeriod()
        {
            var expected = 1717;

            var target = new BeaconSendingContext(config, clientProvider, timingProvider);

            target.Sleep(expected);

            timingProvider.Received(1).Sleep(expected);
        }
コード例 #3
0
        public void IsInitializedOnInitFailed()
        {
            // given
            var target = new BeaconSendingContext(config, clientProvider, timingProvider);

            target.InitCompleted(false);

            // when, then
            Assert.That(target.IsInitialized, Is.False);
        }
コード例 #4
0
        public void InitializeTimeSyncDelegatesToTimingProvider()
        {
            // given
            var target = new BeaconSendingContext(logger, config, clientProvider, timingProvider);

            // when
            target.InitializeTimeSync(1L, true);

            // then
            timingProvider.Received(1).Initialze(1L, true);
        }
コード例 #5
0
        public void ExecuteIsCalledOnCurrentState()
        {
            var target = new BeaconSendingContext(config, clientProvider, timingProvider)
            {
                CurrentState = nonTerminalStateMock
            };

            target.ExecuteCurrentState();

            nonTerminalStateMock.Received(1).Execute(target);
        }
コード例 #6
0
        public void WaitForInitWhenTimeoutExpires()
        {
            // given
            var target = new BeaconSendingContext(config, clientProvider, timingProvider);

            // when waiting for init completion with a timeout of 1ms
            var obtained = target.WaitForInit(1);

            // then the result must be false, since init was never set, but timeout expired
            Assert.That(obtained, Is.False);
        }
コード例 #7
0
        public void GetHttpClientUsesCurrentHttpConfig()
        {
            clientProvider
            .CreateClient(Arg.Any <HTTPClientConfiguration>())
            .Returns(Substitute.For <HTTPClient>(new DefaultLogger(true), new HTTPClientConfiguration("", 0, "", null)));

            var target = new BeaconSendingContext(config, clientProvider, timingProvider);

            var actual = target.GetHTTPClient();

            clientProvider.Received(1).CreateClient(config.HTTPClientConfig);
        }
コード例 #8
0
        public void LastTimeSyncTimeIsSet()
        {
            var target = new BeaconSendingContext(config, clientProvider, timingProvider);

            Assert.AreEqual(-1, target.LastTimeSyncTime);

            var expected = 17;

            target.LastTimeSyncTime = expected;

            Assert.AreEqual(expected, target.LastTimeSyncTime);
        }
コード例 #9
0
        public void LastStatusCheckTimeIsSet()
        {
            var target = new BeaconSendingContext(logger, config, clientProvider, timingProvider);

            Assert.AreEqual(0, target.LastStatusCheckTime);

            var expected = 17;

            target.LastStatusCheckTime = expected;

            Assert.AreEqual(expected, target.LastStatusCheckTime);
        }
コード例 #10
0
        public void DisableCaptureDisablesItInTheConfiguration()
        {
            // given
            var target = new BeaconSendingContext(config, clientProvider, timingProvider);

            config.EnableCapture();

            // when disabling capture
            target.DisableCapture();

            // then it's disabled again
            Assert.That(config.IsCaptureOn, Is.False);
        }
コード例 #11
0
        public void CanGetCurrentTimestamp()
        {
            var expected = 12356789;

            timingProvider.ProvideTimestampInMilliseconds().Returns(expected);

            var target = new BeaconSendingContext(config, clientProvider, timingProvider);

            var actual = target.CurrentTimestamp;

            Assert.AreEqual(expected, actual);
            timingProvider.Received(1).ProvideTimestampInMilliseconds();
        }
コード例 #12
0
        public void CanGetHttpClient()
        {
            var expected = Substitute.For <HTTPClient>(new DefaultLogger(true), new HTTPClientConfiguration("", 0, "", null));

            clientProvider.CreateClient(Arg.Any <HTTPClientConfiguration>()).Returns(expected);

            var target = new BeaconSendingContext(config, clientProvider, timingProvider);

            var actual = target.GetHTTPClient();

            Assert.NotNull(actual);
            Assert.AreSame(expected, actual);
            clientProvider.Received(1).CreateClient(Arg.Any <HTTPClientConfiguration>());
        }
コード例 #13
0
        public void CanSleepCustomPeriod()
        {
            var expected = 1717;

            var target = new BeaconSendingContext(config, clientProvider, timingProvider);

            target.Sleep(expected);

#if !NETCOREAPP1_0
            timingProvider.Received(1).Sleep(expected);
#else
            timingProvider.Received(2).Sleep(Arg.Any <int>());
            timingProvider.Received(1).Sleep(1000);
            timingProvider.Received(1).Sleep(717);
#endif
        }
コード例 #14
0
        public void SessionIsMovedToFinished()
        {
            // given
            var target = new BeaconSendingContext(config, clientProvider, timingProvider);

            var session = new Session(new BeaconSender(target), new Beacon(Substitute.For <ILogger>(), new BeaconCache(),
                                                                           config, "127.0.0.1", Substitute.For <IThreadIDProvider>(), timingProvider));

            Assert.That(target.GetAllOpenSessions().Count, Is.EqualTo(1));

            // when
            target.FinishSession(session);

            // then
            Assert.That(target.GetAllOpenSessions(), Is.Empty);
            Assert.That(target.GetNextFinishedSession(), Is.SameAs(session));
            Assert.That(target.GetNextFinishedSession(), Is.Null);
        }
コード例 #15
0
        public void CanInterruptLongSleep()
        {
            // given
            var expected = 101717;
            var target   = new BeaconSendingContext(logger, config, clientProvider, timingProvider);

            target.RequestShutdown();
            target.Sleep(expected);

            // then
#if !NETCOREAPP1_0 || !NETCOREAPP1_1
            // normal sleep as thread interrupt exception exists
            timingProvider.Received(1).Sleep(expected);
#else
            // no interrupt exception exists, therefore "sliced" sleep break after first iteration
            timingProvider.Received(1).Sleep(Arg.Any <int>());
            timingProvider.Received(1).Sleep(BeaconSendingContext.DEFAULT_SLEEP_TIME_MILLISECONDS);
#endif
        }
コード例 #16
0
        public void CanSleepLonger()
        {
            // given
            var expected = 101717;
            var target   = new BeaconSendingContext(logger, config, clientProvider, timingProvider);

            target.Sleep(expected);

            // then
#if !NETCOREAPP1_0 || !NETCOREAPP1_1
            // normal sleep as thread interrupt exception exists
            timingProvider.Received(1).Sleep(expected);
#else
            // no interrupt exception exists, therefore "sliced" sleeps until total sleep amount
            var expectedCount = (int)Math.Ceiling(expected / (double)BeaconSendingContext.DEFAULT_SLEEP_TIME_MILLISECONDS);
            timingProvider.Received(expectedCount).Sleep(Arg.Any <int>());
            timingProvider.Received(expectedCount - 1).Sleep(BeaconSendingContext.DEFAULT_SLEEP_TIME_MILLISECONDS);
            timingProvider.Received(1).Sleep(expected % BeaconSendingContext.DEFAULT_SLEEP_TIME_MILLISECONDS);
#endif
        }
コード例 #17
0
        public void FinishingANewSessionStillLeavesItNew()
        {
            // given
            var target = new BeaconSendingContext(logger, config, clientProvider, timingProvider);

            var session = new Session(logger, new BeaconSender(logger, target), new Beacon(logger, new BeaconCache(logger),
                                                                                           config, "127.0.0.1", Substitute.For <IThreadIDProvider>(), timingProvider));

            // then
            Assert.That(target.NewSessions.Select(s => s.Session), Is.EquivalentTo(new[] { session }));
            Assert.That(target.OpenAndConfiguredSessions, Is.Empty);
            Assert.That(target.FinishedAndConfiguredSessions, Is.Empty);

            // and when finishing the session
            target.FinishSession(session);

            // then it's in the list of new ones
            Assert.That(target.NewSessions.Select(s => s.Session), Is.EquivalentTo(new[] { session }));
            Assert.That(target.OpenAndConfiguredSessions, Is.Empty);
            Assert.That(target.FinishedAndConfiguredSessions, Is.Empty);
        }
コード例 #18
0
        public void TimeSyncSupportIsTrueByDefault()
        {
            var target = new BeaconSendingContext(config, clientProvider, timingProvider);

            Assert.That(target.IsTimeSyncSupported, Is.True);
        }