public async Task GivenADocumentDbSagaRepository_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 SimpleSagaResource {
                CorrelationId = _correlationId
            };

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

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

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

            _sagaConsumeContextFactory = new Mock <IDocumentDbSagaConsumeContextFactory>();
            _sagaConsumeContextFactory.Setup(m => m.Create(It.IsAny <IDocumentClient>(), It.IsAny <string>(), It.IsAny <string>(), _context.Object, It.IsAny <SimpleSagaResource>(), It.IsAny <bool>(), It.IsAny <RequestOptions>())).Returns(
                _sagaConsumeContext.Object);


            var repository = new DocumentDbSagaRepository <SimpleSagaResource>(SagaRepository.Instance.Client, SagaRepository.DatabaseName, SagaRepository.CollectionName, _sagaConsumeContextFactory.Object, null);

            await repository.Send(_context.Object, _policy.Object, _nextPipe.Object);
        }
Exemplo n.º 2
0
        public async Task GivenADocumentDbSagaRepository_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 <IDocumentDbSagaConsumeContextFactory>();
            _sagaConsumeContextFactory.Setup(
                m => m.Create(It.IsAny <IDocumentClient>(), It.IsAny <string>(), It.IsAny <string>(), _context.Object, It.Is <SimpleSaga>(x => x.CorrelationId == _correlationId), true))
            .Returns(_sagaConsumeContext.Object);

            await SagaRepository.Instance.InsertSaga(_simpleSaga);

            var repository = new DocumentDbSagaRepository <SimpleSaga>(SagaRepository.Instance.Client, SagaRepository.DatabaseName, SagaRepository.CollectionName, _sagaConsumeContextFactory.Object);

            await repository.Send(_context.Object, _policy.Object, _nextPipe.Object);
        }
        public async Task GivenADocumentDbSagaRespository_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 SimpleSagaResource
            {
                CorrelationId = _correlationId
            };
            await _simpleSaga.Consume(It.IsAny <ConsumeContext <CompleteSimpleSaga> >());

            await SagaRepository.Instance.InsertSaga(_simpleSaga, true);

            _simpleSagaDocument = await SagaRepository.Instance.GetSagaDocument(_simpleSaga.CorrelationId);

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

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

            documentDbSagaConsumeContextFactory.Setup(x => x.Create(It.IsAny <IDocumentClient>(), It.IsAny <string>(), It.IsAny <string>(), context.Object, It.IsAny <SimpleSagaResource>(), true, It.IsAny <RequestOptions>()))
            .Returns(sagaConsumeContext.Object);
            var repository = new DocumentDbSagaRepository <SimpleSagaResource>(SagaRepository.Instance.Client, SagaRepository.DatabaseName, SagaRepository.CollectionName, documentDbSagaConsumeContextFactory.Object, null);

            await repository.Send(context.Object, Mock.Of <ISagaPolicy <SimpleSagaResource, CompleteSimpleSaga> >(), null);
        }
        public async Task GivenADocumentDbSagaRepository_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 <SimpleSagaResource, InitiateSimpleSaga> >();
            _policy.Setup(x => x.PreInsertInstance(_context.Object, out _nullSimpleSaga)).Returns(false);

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

            var repository = new DocumentDbSagaRepository <SimpleSagaResource>(SagaRepository.Instance.Client, SagaRepository.DatabaseName);

            await repository.Send(_context.Object, _policy.Object, _nextPipe.Object);
        }
        public async Task GivenADocumentDbSagaRepository_WhenSendingWithNullCorrelationId()
        {
            var context = new Mock <ConsumeContext <InitiateSimpleSaga> >();

            context.Setup(x => x.CorrelationId).Returns(default(Guid?));

            var repository = new DocumentDbSagaRepository <SimpleSagaResource>(Mock.Of <IDocumentClient>(), "sagaTest");

            try
            {
                await repository.Send(context.Object, Mock.Of <ISagaPolicy <SimpleSagaResource, InitiateSimpleSaga> >(),
                                      Mock.Of <IPipe <SagaConsumeContext <SimpleSagaResource, InitiateSimpleSaga> > >());
            }
            catch (SagaException exception)
            {
                _exception = exception;
            }
        }
Exemplo n.º 6
0
        public async Task GivenADocumentDbSagaRepository_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 SimpleSagaResource {
                CorrelationId = _correlationId
            };

            var sagaFactory = new FactoryMethodSagaFactory <SimpleSagaResource, InitiateSimpleSaga>(x => _simpleSaga);

            _policy = new NewOrExistingSagaPolicy <SimpleSagaResource, InitiateSimpleSaga>(sagaFactory, true);

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

            _repository = new DocumentDbSagaRepository <SimpleSagaResource>(SagaRepository.Instance.Client, SagaRepository.DatabaseName,
                                                                            SagaRepository.CollectionName);

            await _repository.Send(_context.Object, _policy, _nextPipe.Object);
        }