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); }
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_WhenSendingQuery() { _correlationId = Guid.NewGuid(); var saga = new SimpleSagaResource { CorrelationId = _correlationId }; await SagaRepository.Instance.InsertSaga(saga, true); _sagaQueryConsumeContext = new Mock <SagaQueryConsumeContext <SimpleSagaResource, InitiateSimpleSaga> >(); _sagaQueryConsumeContext.Setup(x => x.Query.FilterExpression).Returns(x => x.CorrelationId == _correlationId); _sagaPolicy = new Mock <ISagaPolicy <SimpleSagaResource, InitiateSimpleSaga> >(); _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>(), _sagaQueryConsumeContext.Object, It.Is <SimpleSagaResource>(x => x.CorrelationId == _correlationId), true, It.IsAny <RequestOptions>())).Returns(_sagaConsumeContext.Object); var repository = new DocumentDbSagaRepository <SimpleSagaResource>(SagaRepository.Instance.Client, SagaRepository.DatabaseName, SagaRepository.CollectionName, _sagaConsumeContextFactory.Object, null); await repository.SendQuery(_sagaQueryConsumeContext.Object, _sagaPolicy.Object, _nextPipe.Object); }
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 <SimpleSagaResource, InitiateSimpleSaga> >(); _policy.Setup(x => x.PreInsertInstance(_context.Object, out _nullSimpleSaga)).Returns(false); _nextPipe = new Mock <IPipe <SagaConsumeContext <SimpleSagaResource, InitiateSimpleSaga> > >(); _simpleSaga = new SimpleSagaResource { CorrelationId = _correlationId }; _sagaConsumeContext = new Mock <SagaConsumeContext <SimpleSagaResource, InitiateSimpleSaga> >(); _sagaConsumeContext.Setup(x => x.CorrelationId).Returns(_correlationId); await SagaRepository.Instance.InsertSaga(_simpleSaga, true); var repository = new DocumentDbSagaRepository <SimpleSagaResource>(SagaRepository.Instance.Client, SagaRepository.DatabaseName, SagaRepository.CollectionName); await repository.Send(_context.Object, _policy.Object, _nextPipe.Object); }
public async Task GivenAMissingPipe_WhenSendingAndProxyIncomplete() { _nextPipe = new Mock <IPipe <SagaConsumeContext <SimpleSagaResource, InitiateSimpleSaga> > >(); _proxy = new Mock <SagaConsumeContext <SimpleSagaResource, InitiateSimpleSaga> >(); _proxy.SetupGet(m => m.IsCompleted).Returns(false); _consumeContextFactory = new Mock <IDocumentDbSagaConsumeContextFactory>(); _saga = new SimpleSagaResource { CorrelationId = Guid.NewGuid() }; _context = new Mock <SagaConsumeContext <SimpleSagaResource, InitiateSimpleSaga> >(); _context.SetupGet(m => m.Saga).Returns(_saga); _consumeContextFactory.Setup(m => m.Create(SagaRepository.Instance.Client, SagaRepository.DatabaseName, SagaRepository.CollectionName, _context.Object, It.IsAny <SimpleSagaResource>(), false, null)).Returns(_proxy.Object); _pipe = new MissingPipe <SimpleSagaResource, InitiateSimpleSaga>(SagaRepository.Instance.Client, SagaRepository.DatabaseName, SagaRepository.CollectionName, _nextPipe.Object, _consumeContextFactory.Object, null); await _pipe.Send(_context.Object); }
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_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); }