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 void AddAndLookupRegistrations() { var s1e1 = SagaEventRegistration.AlwaysStarting(typeof(Saga1), typeof(Event1)); var s1e2 = SagaEventRegistration.AlwaysStarting(typeof(Saga1), typeof(Event2)); var s2e1 = SagaEventRegistration.AlwaysStarting(typeof(Saga2), typeof(Event1)); sut.Add(s1e1); sut.Add(s1e2); sut.Add(s2e1); var registrations = sut.LookupRegistrations(typeof(Event1)); registrations.Should().BeEquivalentTo(new[] { s1e1, s2e1 }); }
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)) }); }