public void GetNextChunkReturnsEmptyListWhenCollectionDoesNotExist(
            MongoTimeoutPersister sut,
            MongoDatabaseFactory factory)
        {
            factory.ResetTimeoutCollection();

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

            result.Should().BeEmpty();
            nextTimeToRunQuery.Should()
                              .BeOnOrAfter(
                                  startSlice.AddMinutes(MongoPersistenceConstants.DefaultNextTimeoutIncrementMinutes));
        }
        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 BasicMongoTimeoutPersisterConstruction(MongoDatabaseFactory factory)
 {
     var sut = new MongoTimeoutPersister(factory);
 }
        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 RemoveTimeoutByIdOnEmptyTimeoutCollection(
            MongoTimeoutPersister sut,
            MongoDatabaseFactory factory,
            Timeout.Core.TimeoutData timeoutData)
        {
            factory.ResetTimeoutCollection();

            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 TryRemoveEmptyTimeoutCollectionShouldReturnFalseAndNullData(
            MongoTimeoutPersister sut,
            MongoDatabaseFactory factory,
            string timeoutId)
        {
            factory.ResetTimeoutCollection();

            Timeout.Core.TimeoutData timeoutData;

            var result = sut.TryRemove(timeoutId, out timeoutData);

            result.Should().BeFalse();
            timeoutData.Should().BeNull();

            factory.RetrieveAllTimeouts().Should().HaveCount(0);
        }
        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);
        }