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));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        public async Task GivenAMongoDbSagaRepository_WhenSendingAndPolicyReturnsInstance()
        {
            _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);

            _simpleSaga = new SimpleSaga {
                CorrelationId = _correlationId
            };

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

            _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> >(), _context.Object, _simpleSaga, true)).Returns(
                _sagaConsumeContext.Object);


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

            await repository.Send(_context.Object, _policy.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));
        }
        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 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();
        }
Ejemplo n.º 7
0
        public void GivenAMongoDbSagaRepository_WhenSendingAndInstanceNotFound()
        {
            _context = new Mock <ConsumeContext <InitiateSimpleSaga> >();
            _context.Setup(x => x.CorrelationId).Returns(It.IsAny <Guid>());
            _context.Setup(m => m.CancellationToken).Returns(It.IsAny <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> > >();

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

            TaskUtil.Await(() => repository.Send(_context.Object, _policy.Object, _nextPipe.Object));
        }
        public void GivenAMissingPipe_WhenSendingAndProxyIncomplete()
        {
            IMongoCollection <SimpleSaga> collection = SagaRepository.Instance.GetCollection <SimpleSaga>("sagas");

            _nextPipe = new Mock <IPipe <SagaConsumeContext <SimpleSaga, InitiateSimpleSaga> > >();
            _proxy    = new Mock <SagaConsumeContext <SimpleSaga, InitiateSimpleSaga> >();
            _proxy.SetupGet(m => m.IsCompleted).Returns(false);
            _consumeContextFactory = new Mock <IMongoDbSagaConsumeContextFactory>();
            _saga = new SimpleSaga {
                CorrelationId = Guid.NewGuid()
            };
            _context = new Mock <SagaConsumeContext <SimpleSaga, InitiateSimpleSaga> >();
            _context.SetupGet(m => m.Saga).Returns(_saga);
            _consumeContextFactory.Setup(m => m.Create(collection, _context.Object, _context.Object.Saga, false)).Returns(_proxy.Object);

            _pipe = new MissingPipe <SimpleSaga, InitiateSimpleSaga>(collection, _nextPipe.Object, _consumeContextFactory.Object);

            TaskUtil.Await(() => _pipe.Send(_context.Object));
        }
Ejemplo n.º 9
0
 public static async Task InsertSaga(SimpleSaga saga)
 {
     await Instance.GetCollection <SimpleSaga>("sagas").InsertOneAsync(saga);
 }
Ejemplo n.º 10
0
 public static Task InsertSaga(SimpleSaga saga)
 {
     return(Instance.GetCollection <SimpleSaga>("sagas").InsertOneAsync(saga));
 }