public void TestNextQueryTimeIsResetWhenNewTimeoutIsInserted()
        {
            // Arrange
            var expiredTimeoutsPoller = new ExpiredTimeoutsPoller(_mockBus.Object);// todo: pass time provider to make testing easier
            var nextTimeoutQueryTime = DateTime.UtcNow.AddSeconds(-10);

            // Act
            _mockProcessManagerFinder.Raise(e => e.TimeoutInserted += null, nextTimeoutQueryTime);

            // Assert
            Assert.Equal(expiredTimeoutsPoller.NextQueryUtc, nextTimeoutQueryTime);
        }
        public void TestDispatchedTimeoutMessageIsRemoved()
        {
            // Arrange
            SetupProcessManagerFinderMock(DateTime.UtcNow.AddSeconds(30));
            var expiredTimeoutsPoller = new ExpiredTimeoutsPoller(_mockBus.Object);

            // Act
            expiredTimeoutsPoller.InnerPoll(new CancellationToken(false));

            // Assert
            _mockProcessManagerFinder.Verify(i => i.RemoveDispatchedTimeout(_tdId), Times.Once);
        }
        public void TestNextQueryTimeIsResetToNextTimeoutDue()
        {
            // Arrange
            var nextTimeoutQueryTime = DateTime.UtcNow.AddSeconds(30);
            SetupProcessManagerFinderMock(nextTimeoutQueryTime);
            var expiredTimeoutsPoller = new ExpiredTimeoutsPoller(_mockBus.Object);

            // Act
            expiredTimeoutsPoller.InnerPoll(new CancellationToken(false));

            // Assert
            Assert.Equal(nextTimeoutQueryTime, expiredTimeoutsPoller.NextQueryUtc);
        }
        public void TestNextQueryTimeIsResetToMaxAlowedValue()
        {
            // Arrange
            var nextTimeoutQueryTime = DateTime.UtcNow.AddDays(1);
            SetupProcessManagerFinderMock(nextTimeoutQueryTime);
            var expiredTimeoutsPoller = new ExpiredTimeoutsPoller(_mockBus.Object);

            // Act
            expiredTimeoutsPoller.InnerPoll(new CancellationToken(false));

            // Assert
            Assert.True(expiredTimeoutsPoller.NextQueryUtc < nextTimeoutQueryTime);
        }
        public void TestTimeoutMessageIsDispatched()
        {
            // Arrange
            SetupProcessManagerFinderMock(DateTime.UtcNow.AddSeconds(30));
            var expiredTimeoutsPoller = new ExpiredTimeoutsPoller(_mockBus.Object);

            // Act
            expiredTimeoutsPoller.InnerPoll(new CancellationToken(false));

            // Assert
            _mockBus.Verify(i => i.Send("TestDest", It.Is<TimeoutMessage>(p => p.CorrelationId == _pmId), null), Times.Once);
        }