Beispiel #1
0
        public void StartMonitoring_NormalBehavior_CallbackInvokedMultipleTimes()
        {
            // Arrange
            WeatherMonitorStrategy target = new WeatherMonitorStrategy();
            int callbackCount             = 0;

            // Act
            target.StartMonitoring(TimeSpan.FromMilliseconds(100), () => callbackCount++);
            Waiter.Until(() => callbackCount >= 2);
            target.StopMonitoring();

            // Assert
            callbackCount.Should().BeGreaterOrEqualTo(2);
        }
Beispiel #2
0
        public void StartMonitoring_CallbackInvokedBeforeMonitoringStarts()
        {
            // Arrange
            WeatherMonitorStrategy target = new WeatherMonitorStrategy();
            int callbackCount             = 0;

            // Act
            // Make interval large so test completes before it triggers.
            target.StartMonitoring(TimeSpan.FromMilliseconds(10000), () => callbackCount++);
            Waiter.Until(() => callbackCount > 0);
            target.StopMonitoring();

            // Assert
            callbackCount.Should().BeGreaterOrEqualTo(1);
        }
Beispiel #3
0
        public void StopMonitoring_EndOfIntervalCallbackNotCalledAfterwards()
        {
            // Arrange
            WeatherMonitorStrategy target = new WeatherMonitorStrategy();
            int callBackCount             = 0;

            target.StartMonitoring(TimeSpan.FromMilliseconds(200), () => callBackCount++);

            // Act
            Waiter.Until(() => callBackCount > 0);
            target.StopMonitoring();
            Waiter.Until(() =>
            {
                bool result = callBackCount == 0;

                callBackCount = 0;
                return(result);
            });

            // Assert
            callBackCount.Should().Be(0);
        }