public void GetNextChunkReturnsOneTimeoutWhenCollectionHasOneTimeout(
            MongoTimeoutPersister sut,
            MongoDatabaseFactory factory,
            Timeout.Core.TimeoutData timeoutData)
        {
            factory.ResetTimeoutCollection();

            timeoutData.Time = DateTime.UtcNow.AddMinutes(-1);
            sut.Add(timeoutData);

            var startSlice = DateTime.UtcNow.AddMinutes(-5);
            DateTime nextTimeToRunQuery;
            var result = sut.GetNextChunk(startSlice, out nextTimeToRunQuery);

            result.Should().HaveCount(1);
            nextTimeToRunQuery.Should().BeOnOrAfter(timeoutData.Time);
        }
        public void RemoveTimeoutByIdRemovesCorrectTimeoutAndDoesNotRemoveOtherTimeout(
            MongoTimeoutPersister sut,
            MongoDatabaseFactory factory,
            Timeout.Core.TimeoutData timeoutData1,
            Timeout.Core.TimeoutData timeoutData2)
        {
            factory.ResetTimeoutCollection();

            sut.Add(timeoutData1);
            sut.Add(timeoutData2);

            sut.RemoveTimeoutBy(timeoutData2.SagaId);

            var remainingTimeouts = factory.RetrieveAllTimeouts().ToList();
            remainingTimeouts.Should().HaveCount(1);

            remainingTimeouts.First().SagaId.Should().Be(timeoutData1.SagaId);
        }
        public void RemoveTimeoutByIdOnNonExistantIdDoesNotRemoveOtherTimeout(
            MongoTimeoutPersister sut,
            MongoDatabaseFactory factory,
            Timeout.Core.TimeoutData timeoutData)
        {
            factory.ResetTimeoutCollection();

            sut.Add(timeoutData);

            sut.RemoveTimeoutBy(Guid.NewGuid());

            factory.RetrieveAllTimeouts().Should().HaveCount(1);
        }
        public void RemoveTimeoutByIdRemovesTimeout(
            MongoTimeoutPersister sut,
            MongoDatabaseFactory factory,
            Timeout.Core.TimeoutData timeoutData)
        {
            factory.ResetTimeoutCollection();
            
            sut.Add(timeoutData);

            sut.RemoveTimeoutBy(timeoutData.SagaId);
            
            factory.RetrieveAllTimeouts().Should().HaveCount(0);
        }
        public void TryRemoveShouldSucceedAndReturnDataForOneTimeoutAndLeaveTheOther(
            MongoTimeoutPersister sut,
            MongoDatabaseFactory factory,
            Timeout.Core.TimeoutData timeoutData1,
            Timeout.Core.TimeoutData timeoutData2)
        {
            factory.ResetTimeoutCollection();

            sut.Add(timeoutData1);
            sut.Add(timeoutData2);
            Timeout.Core.TimeoutData returnedTimeoutData;

            var timeouts = factory.RetrieveAllTimeouts();

            var result = sut.TryRemove(timeouts.First().Id.ToString(), out returnedTimeoutData);

            result.Should().BeTrue();
            returnedTimeoutData.ShouldBeEquivalentTo(timeoutData1);

            var remainingTimeout = factory.RetrieveAllTimeouts().ToList();
            remainingTimeout.Should().HaveCount(1);
            remainingTimeout.First().ShouldBeEquivalentTo(timeoutData2);
        }
        public void AddTwoDifferentTimeouts(
            MongoTimeoutPersister sut,
            MongoDatabaseFactory factory,
            Timeout.Core.TimeoutData timeout1,
            Timeout.Core.TimeoutData timeout2)
        {
            factory.ResetTimeoutCollection();

            sut.Add(timeout1);
            sut.Add(timeout2);

            var result = factory.RetrieveAllTimeouts();

            result.Should().HaveCount(2);
        }