public void A_correlated_message_should_find_the_correct_saga() { try { using (IUnitOfWork work = UnitOfWork.Start()) using (var repository = new NHibernateSagaRepository <TestSaga>()) { var ping = new PingMessage(_sagaId); var initiatePolicy = new InitiatingSagaPolicy <TestSaga, PingMessage>(x => false); var message = new PingMessage(_sagaId); repository.Send(x => x.CorrelationId == message.CorrelationId, initiatePolicy, message, saga => saga.Name = "Joe"); 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); } } finally { UnitOfWork.Finish(); } }
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, PingMessage>(x => false); var message = new PingMessage(_sagaId); _repository.Send(x => x.CorrelationId == message.CorrelationId, initiatePolicy, message, saga => saga.Name = "Joe"); message = new PingMessage(CombGuid.Generate()); _repository.Send(x => x.CorrelationId == message.CorrelationId, initiatePolicy, message, saga => saga.Name = "Chris"); }
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 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() { _sagaId = CombGuid.Generate(); _repository = new InMemorySagaRepository <TestSaga>(); var initiatePolicy = new InitiatingSagaPolicy <TestSaga, PingMessage>(x => false); var message = new PingMessage(_sagaId); _repository.Send(x => x.CorrelationId == message.CorrelationId, initiatePolicy, message, saga => saga.Name = "Joe"); message = new PingMessage(CombGuid.Generate()); _repository.Send(x => x.CorrelationId == message.CorrelationId, initiatePolicy, message, saga => saga.Name = "Chris"); }
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 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 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); IConsumeContext<InitiateSimpleSaga> 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 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 => 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() { _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)); }
protected virtual UnsubscribeAction Connect <TComponent, TMessage>(ISubscriberContext context) where TMessage : class, CorrelatedBy <Guid> where TComponent : class, InitiatedBy <TMessage>, ISaga { MessageRouterConfigurator routerConfigurator = MessageRouterConfigurator.For(context.Pipeline); var router = routerConfigurator.FindOrCreate <TMessage>(); var repository = context.Builder.GetInstance <ISagaRepository <TComponent> >(); var policy = new InitiatingSagaPolicy <TComponent, TMessage>(x => false); var sink = new CorrelatedSagaMessageSink <TComponent, TMessage>(context, context.Data as IServiceBus, repository, policy); if (sink == null) { throw new ConfigurationException("Could not build the initiating message sink for " + typeof(TComponent).FullName); } var result = router.Connect(sink); UnsubscribeAction remove = context.SubscribedTo <TMessage>(); return(() => result() && (router.SinkCount == 0) && remove()); }
public void A_correlated_message_should_find_the_correct_saga() { try { using (IUnitOfWork work = UnitOfWork.Start()) using (var repository = new NHibernateSagaRepository<TestSaga>()) { var ping = new PingMessage(_sagaId); var initiatePolicy = new InitiatingSagaPolicy<TestSaga, PingMessage>(x => false); var message = new PingMessage(_sagaId); repository.Send(x => x.CorrelationId == message.CorrelationId, initiatePolicy, message, saga => saga.Name = "Joe"); 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); } } finally { UnitOfWork.Finish(); } }