public async Task Should_publish_after_db_create() { var message = new InitiateSimpleSaga(); var product = new Product { Name = "Should_publish_after_db_create" }; var transactionOutbox = new TransactionalBus(Bus); using (var dbContext = GetDbContext()) using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { dbContext.Products.Add(product); await dbContext.SaveChangesAsync(); await transactionOutbox.Publish(message); // Hasn't published yet Assert.That(async() => await _received.OrTimeout(s: 3), Throws.TypeOf <TimeoutException>()); transaction.Complete(); } // Now has published await _received; using (var dbContext = GetDbContext()) { Assert.IsTrue(await dbContext.Products.AnyAsync(x => x.Id == product.Id)); } }
public void Setup() { _sagaId = NewId.NextGuid(); _initiateSaga = new InitiateSimpleSaga { CorrelationId = _sagaId, Name = "Chris" }; InputQueueSendEndpoint.Send(_initiateSaga) .Wait(TestCancellationToken); _repository.ShouldContainSaga(_sagaId, TestTimeout) .Wait(TestCancellationToken); _otherSagaId = Guid.NewGuid(); _initiateOtherSaga = new InitiateSimpleSaga { CorrelationId = _otherSagaId, Name = "Dru" }; InputQueueSendEndpoint.Send(_initiateOtherSaga) .Wait(TestCancellationToken); _repository.ShouldContainSaga(_otherSagaId, TestTimeout) .Wait(TestCancellationToken); _observeSaga = new ObservableSagaMessage { Name = "Chris" }; }
public void Setup() { _repository = new InMemorySagaRepository <SimpleSaga>(); var initiatePolicy = new InitiatingSagaPolicy <SimpleSaga, InitiateSimpleSaga>(x => x.CorrelationId, x => false); _sagaId = CombGuid.Generate(); _initiateSaga = new InitiateSimpleSaga { CorrelationId = _sagaId, Name = "Chris" }; var context = _initiateSaga.ToConsumeContext(); _repository.GetSaga(context, _sagaId, (i, c) => InstanceHandlerSelector.ForInitiatedBy <SimpleSaga, InitiateSimpleSaga>(i), initiatePolicy) .Each(x => x(context)); _initiateOtherSaga = new InitiateSimpleSaga { CorrelationId = _otherSagaId, Name = "Dru" }; _otherSagaId = Guid.NewGuid(); context = _initiateOtherSaga.ToConsumeContext(); _repository.GetSaga(context, _otherSagaId, (i, c) => InstanceHandlerSelector.ForInitiatedBy <SimpleSaga, InitiateSimpleSaga>(i), initiatePolicy) .Each(x => x(context)); _observeSaga = new ObservableSagaMessage { Name = "Chris" }; }
public async Task GivenACorrelatedMessage_WhenInitiatingAndObservedMessageForSagaArrives_ThenSagaShouldBeLoaded() { _correlationId = Guid.NewGuid(); var initiationMessage = new InitiateSimpleSaga(_correlationId) { Name = "Lee" }; var busControl = await Bus.StartAsync(); await busControl.Publish(initiationMessage); var sagaRepository = new MongoDbQuerySagaRepository <SimpleSaga>(SagaRepository.Instance); var foundId = await sagaRepository.ShouldContainSaga(x => x.Initiated && x.CorrelationId == _correlationId, TimeSpan.FromSeconds(30)); var observableMessage = new ObservableSagaMessage { Name = "Lee" }; await busControl.Publish(observableMessage); foundId = await sagaRepository.ShouldContainSaga(x => x.Observed && x.CorrelationId == _correlationId, TimeSpan.FromSeconds(30)); Assert.That(foundId.HasValue, Is.True); }
public void The_saga_should_be_created_when_an_initiating_message_is_received() { InitiateSimpleSaga message = new InitiateSimpleSaga(_sagaId); LocalBus.InboundPipeline.Dispatch(message); var saga = _repository.ShouldContainSaga(_sagaId); saga.WasInitiated.ShouldBeTrue(); }
public async Task An_initiating_message_should_start_the_saga() { Guid sagaId = NewId.NextGuid(); var message = new InitiateSimpleSaga(sagaId); await InputQueueSendEndpoint.Send(message); Guid?foundId = await _sagaRepository.Value.ShouldContainSaga(message.CorrelationId, TestTimeout); foundId.HasValue.ShouldBe(true); }
public async void An_initiating_message_should_start_the_saga() { Guid sagaId = NewId.NextGuid(); var message = new InitiateSimpleSaga(sagaId); await InputQueueSendEndpoint.Send(message); Guid? foundId = await _sagaRepository.Value.ShouldContainSaga(message.CorrelationId, TestTimeout); foundId.HasValue.ShouldBe(true); }
public async Task GivenAnInitiatingMessage_WhenPublishing() { _correlationId = Guid.NewGuid(); var message = new InitiateSimpleSaga(_correlationId); var busControl = await Bus.StartAsync(); await busControl.Publish(message); var sagaRepository = new MongoDbQuerySagaRepository <SimpleSaga>(SagaRepository.Instance); _foundId = await sagaRepository.ShouldContainSaga(_correlationId, TimeSpan.FromSeconds(30)); }
public void An_exception_should_be_thrown() { InitiateSimpleSaga message = new InitiateSimpleSaga(_sagaId); LocalBus.InboundPipeline.Dispatch(message); try { LocalBus.InboundPipeline.Dispatch(message); } catch (SagaException sex) { Assert.AreEqual(sex.MessageType, typeof(InitiateSimpleSaga)); } }
public void CorrelatedMessageShouldFindTheCorrectSaga() { var repository = new MongoDbStateMachineSagaRepository<TestSaga>(this._db); var initiatePolicy = new InitiatingSagaPolicy<TestSaga, InitiateSimpleSaga>(x => x.CorrelationId, x => false); var message = new InitiateSimpleSaga(this._sagaId); var context = new ConsumeContext<InitiateSimpleSaga>(ReceiveContext.Empty(), message); repository.GetSaga(context, message.CorrelationId, this.GetHandlers, initiatePolicy).Each(x => x(context)); List<TestSaga> sagas = repository.ByCorrelationId(this._sagaId).ToList(); Assert.AreEqual(1, sagas.Count); Assert.IsNotNull(sagas[0]); Assert.AreEqual(this._sagaId, sagas[0].CorrelationId); }
public void CorrelatedMessageShouldFindTheCorrectSaga() { var repository = new MongoDbStateMachineSagaRepository <TestSaga>(this._db); var initiatePolicy = new InitiatingSagaPolicy <TestSaga, InitiateSimpleSaga>(x => x.CorrelationId, x => false); var message = new InitiateSimpleSaga(this._sagaId); var context = new ConsumeContext <InitiateSimpleSaga>(ReceiveContext.Empty(), message); repository.GetSaga(context, message.CorrelationId, this.GetHandlers, initiatePolicy).Each(x => x(context)); List <TestSaga> sagas = repository.ByCorrelationId(this._sagaId).ToList(); Assert.AreEqual(1, sagas.Count); Assert.IsNotNull(sagas[0]); Assert.AreEqual(this._sagaId, sagas[0].CorrelationId); }
public void Setup() { _repository = new InMemorySagaRepository<SimpleSaga>(); var initiatePolicy = new InitiatingSagaPolicy<SimpleSaga,InitiateSimpleSaga>(x => false); _sagaId = CombGuid.Generate(); _initiateSaga = new InitiateSimpleSaga { CorrelationId = _sagaId, Name = "Chris" }; _repository.Send(x => x.CorrelationId == _sagaId, initiatePolicy, _initiateSaga, saga => saga.Consume(_initiateSaga)); _initiateOtherSaga = new InitiateSimpleSaga {CorrelationId = _otherSagaId, Name = "Dru"}; _otherSagaId = Guid.NewGuid(); _repository.Send(x => x.CorrelationId == _otherSagaId, initiatePolicy, _initiateOtherSaga, saga => saga.Consume(_initiateOtherSaga)); _observeSaga = new ObservableSagaMessage {Name = "Chris"}; }
public async Task A_correlated_message_should_find_the_correct_saga() { Guid sagaId = NewId.NextGuid(); var message = new InitiateSimpleSaga(sagaId); await InputQueueSendEndpoint.Send(message); var found = await _sagaRepository.Value.ShouldContainSaga(message.CorrelationId, TestTimeout); found.ShouldBe(sagaId); var nextMessage = new CompleteSimpleSaga {CorrelationId = sagaId}; await InputQueueSendEndpoint.Send(nextMessage); found = await _sagaRepository.Value.ShouldContainSaga(x => x.CorrelationId == sagaId && x.Completed, TestTimeout); found.ShouldBe(sagaId); }
public void A_correlated_message_should_find_the_correct_saga() { var repository = new RavenDbSagaRepository<TestSaga>(_store); var ping = new PingMessage(_sagaId); var initiatePolicy = new InitiatingSagaPolicy<TestSaga, InitiateSimpleSaga>(x => x.CorrelationId, x => false); var message = new InitiateSimpleSaga(_sagaId); IConsumeContext<InitiateSimpleSaga> context = new ConsumeContext<InitiateSimpleSaga>(ReceiveContext.Empty(), message); ; repository.GetSaga(context, message.CorrelationId, GetHandlers, initiatePolicy) .Each(x => x(context)); List<TestSaga> sagas = repository.Where(x => x.CorrelationId == _sagaId).ToList(); Assert.AreEqual(1, sagas.Count); Assert.IsNotNull(sagas[0]); Assert.AreEqual(_sagaId, sagas[0].CorrelationId); }
public void A_correlated_message_should_find_the_correct_saga() { var repository = new NHibernateSagaRepository <TestSaga>(_sessionFactory); var ping = new PingMessage(_sagaId); var initiatePolicy = new InitiatingSagaPolicy <TestSaga, InitiateSimpleSaga>(x => x.CorrelationId, x => false); var message = new InitiateSimpleSaga(_sagaId); var context = message.ToConsumeContext(); repository.GetSaga(context, message.CorrelationId, GetHandlers, initiatePolicy) .Each(x => x(context)); List <TestSaga> sagas = repository.Where(x => x.CorrelationId == _sagaId).ToList(); Assert.AreEqual(1, sagas.Count); Assert.IsNotNull(sagas[0]); Assert.AreEqual(_sagaId, sagas[0].CorrelationId); }
public async Task A_correlated_message_should_update_inner_saga_dependency() { var sagaId = NewId.NextGuid(); var message = new InitiateSimpleSaga(sagaId); await InputQueueSendEndpoint.Send(message); Guid?foundId = await _sagaRepository.Value.ShouldContainSaga(message.CorrelationId, TestTimeout); foundId.HasValue.ShouldBe(true); var propertyValue = "expected saga property value"; var updateInnerProperty = new UpdateSagaDependency(sagaId, propertyValue); await InputQueueSendEndpoint.Send(updateInnerProperty); foundId = await _sagaRepository.Value.ShouldContainSaga( x => x.CorrelationId == sagaId && x.Completed && x.Dependency.SagaInnerDependency.Name == propertyValue, TestTimeout); foundId.HasValue.ShouldBe(true); }
public async Task A_correlated_message_should_find_the_correct_saga() { Guid sagaId = NewId.NextGuid(); var message = new InitiateSimpleSaga(sagaId); await InputQueueSendEndpoint.Send(message); Guid?foundId = await _sagaRepository.Value.ShouldContainSaga(message.CorrelationId, TestTimeout); foundId.HasValue.ShouldBe(true); var nextMessage = new CompleteSimpleSaga { CorrelationId = sagaId }; await InputQueueSendEndpoint.Send(nextMessage); foundId = await _sagaRepository.Value.ShouldContainSaga(x => x.CorrelationId == sagaId && x.Completed, TestTimeout); foundId.HasValue.ShouldBe(true); }
public void Setup() { _sagaId = NewId.NextGuid(); _initiateSaga = new InitiateSimpleSaga {CorrelationId = _sagaId, Name = "Chris"}; InputQueueSendEndpoint.Send(_initiateSaga) .Wait(TestCancellationToken); _repository.ShouldContainSaga(_sagaId, TestTimeout) .Wait(TestCancellationToken); _otherSagaId = Guid.NewGuid(); _initiateOtherSaga = new InitiateSimpleSaga {CorrelationId = _otherSagaId, Name = "Dru"}; InputQueueSendEndpoint.Send(_initiateOtherSaga) .Wait(TestCancellationToken); _repository.ShouldContainSaga(_otherSagaId, TestTimeout) .Wait(TestCancellationToken); _observeSaga = new ObservableSagaMessage {Name = "Chris"}; }
public void Setup() { _repository = new InMemorySagaRepository<SimpleSaga>(); var initiatePolicy = new InitiatingSagaPolicy<SimpleSaga, InitiateSimpleSaga>(x => x.CorrelationId, x => false); _sagaId = CombGuid.Generate(); _initiateSaga = new InitiateSimpleSaga {CorrelationId = _sagaId, Name = "Chris"}; var context = _initiateSaga.ToConsumeContext(); _repository.GetSaga(context, _sagaId, (i, c) => InstanceHandlerSelector.ForInitiatedBy<SimpleSaga, InitiateSimpleSaga>(i), initiatePolicy) .Each(x => x(context)); _initiateOtherSaga = new InitiateSimpleSaga {CorrelationId = _otherSagaId, Name = "Dru"}; _otherSagaId = Guid.NewGuid(); context = _initiateOtherSaga.ToConsumeContext(); _repository.GetSaga(context, _otherSagaId, (i, c) => InstanceHandlerSelector.ForInitiatedBy<SimpleSaga, InitiateSimpleSaga>(i), initiatePolicy) .Each(x => x(context)); _observeSaga = new ObservableSagaMessage {Name = "Chris"}; }
public void Setup() { _sagaId = CombGuid.Generate(); _repository = new InMemorySagaRepository<TestSaga>(); var initiatePolicy = new InitiatingSagaPolicy<TestSaga, InitiateSimpleSaga>(x => x.CorrelationId, x => false); var message = new InitiateSimpleSaga(_sagaId); IConsumeContext<InitiateSimpleSaga> context = message.ToConsumeContext(); _repository.GetSaga(context, message.CorrelationId, (i, c) => InstanceHandlerSelector.ForDataEvent(i, TestSaga.Initiate), initiatePolicy) .Each(x => x(context)); message = new InitiateSimpleSaga(CombGuid.Generate()); context = message.ToConsumeContext(); _repository.GetSaga(context, message.CorrelationId, (i, c) => InstanceHandlerSelector.ForDataEvent(i, TestSaga.Initiate), initiatePolicy) .Each(x => x(context)); }
public void Setup() { _repository = new InMemorySagaRepository <SimpleSaga>(); var initiatePolicy = new InitiatingSagaPolicy <SimpleSaga, InitiateSimpleSaga>(x => false); _sagaId = CombGuid.Generate(); _initiateSaga = new InitiateSimpleSaga { CorrelationId = _sagaId, Name = "Chris" }; _repository.Send(x => x.CorrelationId == _sagaId, initiatePolicy, _initiateSaga, saga => saga.Consume(_initiateSaga)); _initiateOtherSaga = new InitiateSimpleSaga { CorrelationId = _otherSagaId, Name = "Dru" }; _otherSagaId = Guid.NewGuid(); _repository.Send(x => x.CorrelationId == _otherSagaId, initiatePolicy, _initiateOtherSaga, saga => saga.Consume(_initiateOtherSaga)); _observeSaga = new ObservableSagaMessage { Name = "Chris" }; }
public void Setup() { _sagaId = NewId.NextGuid(); _repository = new InMemorySagaRepository <TestSaga>(); var initiatePolicy = new InitiatingSagaPolicy <TestSaga, InitiateSimpleSaga>(x => x.CorrelationId, x => false); var message = new InitiateSimpleSaga(_sagaId); IConsumeContext <InitiateSimpleSaga> context = message.ToConsumeContext(); _repository.GetSaga(context, message.CorrelationId, (i, c) => InstanceHandlerSelector.ForDataEvent(i, TestSaga.Initiate), initiatePolicy) .Each(x => x(context)); message = new InitiateSimpleSaga(NewId.NextGuid()); context = message.ToConsumeContext(); _repository.GetSaga(context, message.CorrelationId, (i, c) => InstanceHandlerSelector.ForDataEvent(i, TestSaga.Initiate), initiatePolicy) .Each(x => x(context)); }
public async Task GivenACorrelatedMessage_TheCorrectSagaShouldBeFound() { _correlationId = Guid.NewGuid(); var message = new InitiateSimpleSaga(_correlationId); var busControl = await Bus.StartAsync(); await busControl.Publish(message); var sagaRepository = new MongoDbQuerySagaRepository <SimpleSaga>(SagaRepository.Instance); var foundId = await sagaRepository.ShouldContainSaga(_correlationId, TimeSpan.FromSeconds(5)); Assert.That(foundId.HasValue, Is.True); var nextMessage = new CompleteSimpleSaga(_correlationId); await busControl.Publish(nextMessage); foundId = await sagaRepository.ShouldContainSaga(x => x.CorrelationId == _correlationId && x.Completed, TimeSpan.FromSeconds(5)); Assert.That(foundId.HasValue, Is.True); }
public async Task Should_not_publish_properly() { var message = new InitiateSimpleSaga(); var product = new Product { Name = "Should_not_publish_properly" }; var transactionOutbox = new TransactionalBus(Bus); using (var dbContext = GetDbContext()) using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { EntityEntry <Product> entity = dbContext.Products.Add(product); await dbContext.SaveChangesAsync(); await transactionOutbox.Publish(message); } Assert.That(async() => await _received.OrTimeout(s: 3), Throws.TypeOf <TimeoutException>()); using (var dbContext = GetDbContext()) { Assert.IsFalse(await dbContext.Products.AnyAsync(x => x.Id == product.Id)); } }
public async Task An_observed_message_should_find_and_update_the_correct_saga() { Guid sagaId = NewId.NextGuid(); var message = new InitiateSimpleSaga(sagaId) { Name = "MySimpleSaga" }; await InputQueueSendEndpoint.Send(message); Guid?found = await _sagaRepository.Value.ShouldContainSaga(message.CorrelationId, TestTimeout); found.ShouldBe(sagaId); var nextMessage = new ObservableSagaMessage { Name = "MySimpleSaga" }; await InputQueueSendEndpoint.Send(nextMessage); found = await _sagaRepository.Value.ShouldContainSaga(x => x.CorrelationId == sagaId && x.Observed, TestTimeout); found.ShouldBe(sagaId); }
public void An_exception_should_be_thrown() { InitiateSimpleSaga message = new InitiateSimpleSaga(_sagaId); LocalBus.InboundPipeline.Dispatch(message); try { LocalBus.InboundPipeline.Dispatch(message); } catch (SagaException sex) { Assert.AreEqual(sex.MessageType, typeof (InitiateSimpleSaga)); } }