Exemple #1
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 SimpleSaga
            {
                CorrelationId = _correlationId
            };
            await _simpleSaga.Consume(It.IsAny <ConsumeContext <CompleteSimpleSaga> >());

            await SagaRepository.Instance.InsertSaga(_simpleSaga);

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

            var sagaConsumeContext = new Mock <SagaConsumeContext <SimpleSaga, 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 <SimpleSaga>(), true))
            .Returns(sagaConsumeContext.Object);
            var repository = new DocumentDbSagaRepository <SimpleSaga>(SagaRepository.Instance.Client, SagaRepository.DatabaseName, SagaRepository.CollectionName, documentDbSagaConsumeContextFactory.Object);

            await repository.Send(context.Object, Mock.Of <ISagaPolicy <SimpleSaga, CompleteSimpleSaga> >(), null);
        }
        public async Task GivenADocumentDbSagaRepository_WhenSendingQuery()
        {
            _correlationId = Guid.NewGuid();
            var saga = new SimpleSaga {
                CorrelationId = _correlationId
            };

            await SagaRepository.Instance.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 <IDocumentDbSagaConsumeContextFactory>();
            _sagaConsumeContextFactory.Setup(
                m =>
                m.Create(It.IsAny <IDocumentClient>(), It.IsAny <string>(), It.IsAny <string>(), _sagaQueryConsumeContext.Object,
                         It.Is <SimpleSaga>(x => x.CorrelationId == _correlationId), true)).Returns(_sagaConsumeContext.Object);

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

            await repository.SendQuery(_sagaQueryConsumeContext.Object, _sagaPolicy.Object, _nextPipe.Object);
        }
        public async Task GivenADocumentDbSagaConsumeContext_WhenSettingComplete()
        {
            _saga = new SimpleSaga {
                CorrelationId = Guid.NewGuid()
            };

            await SagaRepository.Instance.InsertSaga(_saga);

            _documentDbSagaConsumeContext =
                new DocumentDbSagaConsumeContext <SimpleSaga, InitiateSimpleSaga>(SagaRepository.Instance.Client, SagaRepository.DatabaseName, SagaRepository.CollectionName,
                                                                                  Mock.Of <ConsumeContext <InitiateSimpleSaga> >(), _saga);

            await _documentDbSagaConsumeContext.SetCompleted();
        }
Exemple #5
0
        public async Task GivenAMissingPipe_WhenSendingAndProxyIncomplete()
        {
            _nextPipe = new Mock <IPipe <SagaConsumeContext <SimpleSaga, InitiateSimpleSaga> > >();
            _proxy    = new Mock <SagaConsumeContext <SimpleSaga, InitiateSimpleSaga> >();
            _proxy.SetupGet(m => m.IsCompleted).Returns(false);
            _consumeContextFactory = new Mock <IDocumentDbSagaConsumeContextFactory>();
            _saga = new SimpleSaga {
                CorrelationId = Guid.NewGuid()
            };
            _context = new Mock <SagaConsumeContext <SimpleSaga, InitiateSimpleSaga> >();
            _context.SetupGet(m => m.Saga).Returns(_saga);
            _consumeContextFactory.Setup(m => m.Create(SagaRepository.Instance.Client, SagaRepository.DatabaseName, SagaRepository.CollectionName, _context.Object, _context.Object.Saga, false)).Returns(_proxy.Object);

            _pipe = new MissingPipe <SimpleSaga, InitiateSimpleSaga>(SagaRepository.Instance.Client, SagaRepository.DatabaseName, SagaRepository.CollectionName, _nextPipe.Object, _consumeContextFactory.Object);

            await _pipe.Send(_context.Object);
        }
Exemple #6
0
        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 <SimpleSaga, InitiateSimpleSaga> >();
            _policy.Setup(x => x.PreInsertInstance(_context.Object, out _nullSimpleSaga)).Returns(false);

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

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

            await repository.Send(_context.Object, _policy.Object, _nextPipe.Object);
        }
Exemple #7
0
 public async Task InsertSaga(SimpleSaga saga)
 {
     await Client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(DatabaseName, CollectionName), saga);
 }