public void IsShutdownRequestedIsSetCorrectly() { var target = new BeaconSendingContext(config, clientProvider, timingProvider); Assert.False(target.IsShutdownRequested); target.RequestShutdown(); Assert.True(target.IsShutdownRequested); }
public void CanSleepCustomPeriod() { var expected = 1717; var target = new BeaconSendingContext(config, clientProvider, timingProvider); target.Sleep(expected); timingProvider.Received(1).Sleep(expected); }
public void IsInitializedOnInitFailed() { // given var target = new BeaconSendingContext(config, clientProvider, timingProvider); target.InitCompleted(false); // when, then Assert.That(target.IsInitialized, Is.False); }
public void InitializeTimeSyncDelegatesToTimingProvider() { // given var target = new BeaconSendingContext(logger, config, clientProvider, timingProvider); // when target.InitializeTimeSync(1L, true); // then timingProvider.Received(1).Initialze(1L, true); }
public void ExecuteIsCalledOnCurrentState() { var target = new BeaconSendingContext(config, clientProvider, timingProvider) { CurrentState = nonTerminalStateMock }; target.ExecuteCurrentState(); nonTerminalStateMock.Received(1).Execute(target); }
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); }
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); }
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); }
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); }
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); }
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(); }
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>()); }
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 }
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); }
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 }
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 }
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); }
public void TimeSyncSupportIsTrueByDefault() { var target = new BeaconSendingContext(config, clientProvider, timingProvider); Assert.That(target.IsTimeSyncSupported, Is.True); }