Esempio n. 1
0
        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))
            });
        }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
        public async Task LocateSagasAsync_DeliversToAll()
        {
            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[] { new SagaMatch()
                             {
                                 Id = sagaId1, ClassId = typeof(Saga1).GetClassId()
                             } });

            var result = await sut.LocateSagasAsync(new Event1().ToMessageDraft());

            result.Should().BeEquivalentTo(new[]
            {
                LocatedSaga.FromId(sagaId1, typeof(Saga1))
            });
        }