public async Task LocateSagasAsync_FindsExistingSagaByKey() { sagaRegistry.LookupRegistrations(typeof(Event1)) .Returns(new List <SagaEventRegistration>() { SagaEventRegistration.MatchedByKey(typeof(Saga1), typeof(Event1), x => ((Event1)x).Foo.ToString(), "foo", false) }); Guid sagaId1 = Guid.NewGuid(); sagaMetadataRepository.FindSagasByKeyAsync(typeof(Saga1).GetClassId(), "foo", "5") .Returns(new [] { new SagaMatch() { Id = sagaId1, ClassId = typeof(Saga1).GetClassId() } }); var result = await sut.LocateSagasAsync(new Event1() { Foo = 5 }.ToMessageDraft()); result.Should().BeEquivalentTo(new[] { LocatedSaga.FromId(sagaId1, typeof(Saga1)) }); }
public async Task DispatchEventsToSagas_DispatchesToExistingSaga() { var events = new List <IEventMessage <DomainEvent> >() { new Event1().ToMessageDraft() }; Saga1 saga = new Saga1(Guid.Parse("20D27705-FFB8-49F5-8331-99E3654B5B19")); sagaLocators[0].LocateSagasAsync(events[0]).Returns(new[] { LocatedSaga.FromId(saga.Id, typeof(Saga1)) }); sagaRepository.GetAsync <Saga1>(saga.Id).Returns(saga); await sut.DispatchEventsToSagas(events); saga.HandledEvents.Should().BeEquivalentTo(events); sagaRepository.Received(1).SendSagaCommandsAsync(); }
public async Task LocateSagasAsync_StartsSagaWhenNotFoundByKey() { sagaRegistry.LookupRegistrations(typeof(Event1)) .Returns(new List <SagaEventRegistration>() { SagaEventRegistration.MatchedByKey(typeof(Saga1), typeof(Event1), x => ((Event1)x).Foo.ToString(), "foo", true) }); var result = await sut.LocateSagasAsync(new Event1() { Foo = 5 }.ToMessageDraft()); result.Should().BeEquivalentTo(new[] { LocatedSaga.CreateNew(typeof(Saga1)) }); }
public async Task LocateSagasAsync_AlwaysStarting_StartsSaga() { sagaRegistry.LookupRegistrations(typeof(Event1)) .Returns(new List <SagaEventRegistration>() { SagaEventRegistration.AlwaysStarting(typeof(Saga1), typeof(Event1)) }); var result = await sut.LocateSagasAsync( new Event1() { Foo = 5 }.ToMessageDraft()); result.Should().BeEquivalentTo(new[] { LocatedSaga.CreateNew(typeof(Saga1)) }); }
public async Task LocateSagasAsync_DeliverToAllStartsNewWhenNoSagas() { sagaRegistry.LookupRegistrations(typeof(Event1)) .Returns(new List <SagaEventRegistration>() { SagaEventRegistration.ToAllExistingInstances(typeof(Saga1), typeof(Event1), true) }); Guid sagaId1 = Guid.NewGuid(); sagaMetadataRepository.FindSagasAsync(typeof(Saga1).GetClassId()) .Returns(new SagaMatch[] { }); var result = await sut.LocateSagasAsync(new Event1().ToMessageDraft()); result.Should().BeEquivalentTo(new[] { LocatedSaga.CreateNew(typeof(Saga1)) }); }
public async Task DispatchEventsToSagas_CreatesNewSaga() { var events = new List <IEventMessage <DomainEvent> >() { new Event1().ToMessageDraft() }; Saga1 saga = null; sagaLocators[0].LocateSagasAsync(events[0]).Returns(new[] { LocatedSaga.CreateNew(typeof(Saga1)) }); entityFactory.ConstructEntity(typeof(Saga1), Arg.Any <Guid>()).Returns(ci => { return(saga = new Saga1(ci.ArgAt <Guid>(1))); }); await sut.DispatchEventsToSagas(events); saga.Should().NotBeNull(); saga.HandledEvents.Should().BeEquivalentTo(events); sagaRepository.Received(1).SendSagaCommandsAsync(); }