public void GivenAMongoDbSagaRespository_WhenSendingCompletedInstance()
        {
            _correlationId     = Guid.NewGuid();
            _cancellationToken = new CancellationToken();

            var context = new Mock <ConsumeContext <CompleteSimpleSaga> >();

            context.Setup(x => x.CorrelationId).Returns(_correlationId);
            context.Setup(m => m.CancellationToken).Returns(_cancellationToken);

            _simpleSaga = new SimpleSaga
            {
                CorrelationId = _correlationId,
                Version       = 5
            };
            TaskUtil.Await(() => _simpleSaga.Consume(It.IsAny <ConsumeContext <CompleteSimpleSaga> >()));
            TaskUtil.Await(() => SagaRepository.InsertSaga(_simpleSaga));

            var sagaConsumeContext = new Mock <SagaConsumeContext <SimpleSaga, CompleteSimpleSaga> >();

            sagaConsumeContext.SetupGet(x => x.IsCompleted).Returns(true);
            var mongoDbSagaConsumeContextFactory = new Mock <IMongoDbSagaConsumeContextFactory>();

            mongoDbSagaConsumeContextFactory.Setup(x => x.Create(It.IsAny <IMongoCollection <SimpleSaga> >(), context.Object, It.IsAny <SimpleSaga>(), true)).Returns(sagaConsumeContext.Object);
            var repository = new MongoDbSagaRepository <SimpleSaga>(SagaRepository.Instance, mongoDbSagaConsumeContextFactory.Object);

            TaskUtil.Await(() => repository.Send(context.Object, Mock.Of <ISagaPolicy <SimpleSaga, CompleteSimpleSaga> >(), null));
        }
Пример #2
0
        public async Task GivenAMongoDbSagaRepository_WhenSendingQuery()
        {
            _correlationId = Guid.NewGuid();
            var saga = new SimpleSaga {
                CorrelationId = _correlationId
            };

            await SagaRepository.InsertSaga(saga);

            _sagaQueryConsumeContext = new Mock <SagaQueryConsumeContext <SimpleSaga, InitiateSimpleSaga> >();
            _sagaQueryConsumeContext.Setup(x => x.Query.FilterExpression).Returns(x => x.CorrelationId == _correlationId);
            _sagaPolicy = new Mock <ISagaPolicy <SimpleSaga, InitiateSimpleSaga> >();
            _nextPipe   = new Mock <IPipe <SagaConsumeContext <SimpleSaga, InitiateSimpleSaga> > >();

            _sagaConsumeContext = new Mock <SagaConsumeContext <SimpleSaga, InitiateSimpleSaga> >();
            _sagaConsumeContext.Setup(x => x.CorrelationId).Returns(_correlationId);

            _sagaConsumeContextFactory = new Mock <IMongoDbSagaConsumeContextFactory>();
            _sagaConsumeContextFactory.Setup(
                m =>
                m.Create(It.IsAny <IMongoCollection <SimpleSaga> >(), _sagaQueryConsumeContext.Object,
                         It.Is <SimpleSaga>(x => x.CorrelationId == _correlationId), true)).Returns(_sagaConsumeContext.Object);

            var repository = new MongoDbSagaRepository <SimpleSaga>(SagaRepository.Instance, _sagaConsumeContextFactory.Object);

            await repository.SendQuery(_sagaQueryConsumeContext.Object, _sagaPolicy.Object, _nextPipe.Object);
        }
        public void GivenAMongoDbSagaRepository_WhenSendingAndInstanceNotReturnedFromPolicy()
        {
            _correlationId     = Guid.NewGuid();
            _cancellationToken = new CancellationToken();

            _context = new Mock <ConsumeContext <InitiateSimpleSaga> >();
            _context.Setup(x => x.CorrelationId).Returns(_correlationId);
            _context.Setup(m => m.CancellationToken).Returns(_cancellationToken);

            _nullSimpleSaga = null;

            _policy = new Mock <ISagaPolicy <SimpleSaga, InitiateSimpleSaga> >();
            _policy.Setup(x => x.PreInsertInstance(_context.Object, out _nullSimpleSaga)).Returns(false);

            _nextPipe = new Mock <IPipe <SagaConsumeContext <SimpleSaga, InitiateSimpleSaga> > >();

            _simpleSaga = new SimpleSaga {
                CorrelationId = _correlationId
            };

            _sagaConsumeContext = new Mock <SagaConsumeContext <SimpleSaga, InitiateSimpleSaga> >();
            _sagaConsumeContext.Setup(x => x.CorrelationId).Returns(_correlationId);

            _sagaConsumeContextFactory = new Mock <IMongoDbSagaConsumeContextFactory>();
            _sagaConsumeContextFactory.Setup(
                m => m.Create(It.IsAny <IMongoCollection <SimpleSaga> >(), _context.Object, It.Is <SimpleSaga>(x => x.CorrelationId == _correlationId), true))
            .Returns(_sagaConsumeContext.Object);

            TaskUtil.Await(() => SagaRepository.InsertSaga(_simpleSaga));

            var repository = new MongoDbSagaRepository <SimpleSaga>(SagaRepository.Instance, _sagaConsumeContextFactory.Object);

            TaskUtil.Await(() => repository.Send(_context.Object, _policy.Object, _nextPipe.Object));
        }
Пример #4
0
        public async Task GivenAMongoDbQuerySagaRepository_WhenFindingSaga()
        {
            _correlationId = Guid.NewGuid();

            await SagaRepository.InsertSaga(new SimpleSaga { CorrelationId = _correlationId });

            var repository = new MongoDbSagaRepositoryContext <SimpleSaga, InitiateSimpleSaga>(SagaRepository.Instance.GetCollection <SimpleSaga>("sagas"),
                                                                                               Mock.Of <ConsumeContext <InitiateSimpleSaga> >(), new MongoDbSagaConsumeContextFactory <SimpleSaga>());

            _result = await repository.Load(_correlationId);
        }
        public void GivenAMongoDbSagaConsumeContext_WhenSettingComplete()
        {
            _saga = new SimpleSaga {CorrelationId = Guid.NewGuid()};

            TaskUtil.Await(() => SagaRepository.InsertSaga(_saga));

            _mongoDbSagaConsumeContext =
                new MongoDbSagaConsumeContext<SimpleSaga, InitiateSimpleSaga>(SagaRepository.Instance.GetCollection<SimpleSaga>("sagas"),
                    Mock.Of<ConsumeContext<InitiateSimpleSaga>>(), _saga);

            TaskUtil.Await(() => _mongoDbSagaConsumeContext.SetCompleted());
        }
        public async Task GivenAMongoDbQuerySagaRepository_WhenFindingSaga()
        {
            _correlationId = Guid.NewGuid();

            await SagaRepository.InsertSaga(new SimpleSaga { CorrelationId = _correlationId });

            var repository = new MongoDbQuerySagaRepository <SimpleSaga>(SagaRepository.Instance);

            ISagaQuery <SimpleSaga> query = new SagaQuery <SimpleSaga>(x => x.CorrelationId == _correlationId);

            _result = await repository.Find(query);
        }
Пример #7
0
        public void GivenAMongoDbQuerySagaRepository_WhenFindingSaga()
        {
            _correlationId = Guid.NewGuid();

            SagaRepository.InsertSaga(new SimpleSaga {
                CorrelationId = _correlationId
            }).GetAwaiter().GetResult();

            var repository = new MongoDbQuerySagaRepository <SimpleSaga>(SagaRepository.Instance);

            ISagaQuery <SimpleSaga> query = new SagaQuery <SimpleSaga>(x => x.CorrelationId == _correlationId);

            _result = repository.Find(query).GetAwaiter().GetResult();
        }
        public async Task GivenAMongoDbSagaConsumeContext_WhenSettingComplete()
        {
            _saga = new SimpleSaga {
                CorrelationId = Guid.NewGuid()
            };

            await SagaRepository.InsertSaga(_saga);

            _mongoDbSagaConsumeContext =
                new MongoDbSagaConsumeContext <SimpleSaga, InitiateSimpleSaga>(SagaRepository.Instance.GetCollection <SimpleSaga>("sagas"),
                                                                               Mock.Of <ConsumeContext <InitiateSimpleSaga> >(), _saga, SagaConsumeContextMode.Insert);

            await _mongoDbSagaConsumeContext.SetCompleted();
        }
        public async Task ThenSagaDoesNotExistInRepository()
        {
            var saga = await SagaRepository.GetSaga(_saga.CorrelationId);

            Assert.That(saga, Is.Null);
        }
Пример #10
0
 public async Task Kill()
 {
     await SagaRepository.DeleteSaga(_correlationId);
 }
Пример #11
0
        public async Task ThenVersionIncremeted()
        {
            var saga = await SagaRepository.GetSaga(_correlationId);

            Assert.That(saga.Version, Is.EqualTo(1));
        }
Пример #12
0
 public void Kill()
 {
     SagaRepository.DeleteSaga(_correlationId).GetAwaiter().GetResult();
 }
        public void ThenTheCompletedSagaIsNotUpdated()
        {
            var actual = TaskUtil.Await(() => SagaRepository.GetSaga(_correlationId));

            Assert.That(actual.Version, Is.EqualTo(_simpleSaga.Version));
        }
Пример #14
0
 public void ThenSagaInstanceStored()
 {
     Assert.That(SagaRepository.GetSaga(_correlationId), Is.Not.Null);
 }
        public async Task ThenSagaInsertedIntoMongo()
        {
            var saga = await SagaRepository.GetSaga(_saga.CorrelationId);

            Assert.That(saga, Is.Not.Null);
        }
 public Task Kill()
 {
     return(SagaRepository.DeleteSaga(_saga.CorrelationId));
 }
 public void Kill()
 {
     TaskUtil.Await(() => SagaRepository.DeleteSaga(_correlationId));
 }