public async Task Constructor_AddsMetadataSaveTransactionToUoW() { unitOfWork.Received(1).AddInnerTransaction(Arg.Any <ITransaction>()); uowInnerTransaction.Should().NotBeNull(); Saga1 saga1 = new Saga1(Guid.NewGuid()); saga1.Do(); sut.Add(saga1); IEnumerable <KeyValuePair <string, string> > sagaKeys = null; sagaMetadataRepository.When(x => x.SetSagaKeysAsync(saga1.Id, Arg.Any <IEnumerable <KeyValuePair <string, string> > >())).Do( ci => sagaKeys = ci.ArgAt <IEnumerable <KeyValuePair <string, string> > >(1)); await uowInnerTransaction.CommitAsync(); sagaMetadataRepository.Received(1).SaveChangesAsync(); Received.InOrder(() => { sagaMetadataRepository.SetSagaKeysAsync(saga1.Id, Arg.Any <IEnumerable <KeyValuePair <string, string> > >()); sagaMetadataRepository.SaveChangesAsync(); }); sagaKeys.Should() .BeEquivalentTo(saga1.Keys.SelectMany(x => x.Value.Select(y => new KeyValuePair <string, string>(x.Key, y)))); }
public void Add_AddsToRepo() { Saga1 saga = new Saga1(Guid.NewGuid()); sut.Add(saga); repository.Received(1).Add(saga); }
public void Add_AddsToMetadataRepo() { Saga1 saga = new Saga1(Guid.NewGuid()); sut.Add(saga); sagaMetadataRepository.Received(1).AddSaga(saga.Id, saga1ClassId); }
public async Task GetAsync_ByClassIdGetsFromRepo() { Saga1 saga = new Saga1(Guid.NewGuid()); repository.Aggregates.Add(new FakeRepository.EntityEntry(saga, FakeRepository.EntityState.Unchanged)); var result = await sut.GetAsync(saga.Id, saga1ClassId); result.Should().Be(saga); }
public void Add_ThrowsForDuplicateIds() { Saga1 saga = new Saga1(Guid.NewGuid()); Saga1 saga2 = new Saga1(saga.Id); sut.Add(saga); sut.Invoking(x => x.Add(saga2)) .Should().Throw <ArgumentException>(); repository.Received(1).Add(saga); }
public async Task SendSagaCommandsAsync_SendsCommands() { Saga1 saga1 = new Saga1(Guid.NewGuid()); saga1.Do(); sut.Add(saga1); ICommandBase command = saga1.UncommitedCommands.First(); await sut.SendSagaCommandsAsync(); commandBus.Received(1).SendAsync(command); }
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 void GetSagaConfiguration_GetsEventInfos() { var configurationInfo = SagaConventionConfigurationScanner.GetSagaConfiguration(typeof(Saga1)); Assert.Equal(1, configurationInfo.Events.Count); Assert.True(configurationInfo.Events.TryGetValue(typeof(Event1), out var eventInfos)); Assert.Equal(1, eventInfos.Count); var eventInfo = eventInfos.ElementAt(0); Saga1 saga = new Saga1(Guid.NewGuid()); var event1 = new EventMessage <Event1>(new Event1(), new Dictionary <string, string>()); eventInfo.HandleDelegate(saga, event1); Assert.Equal(1, saga.HandledEvents.Count); Assert.Equal(event1, saga.HandledEvents[0]); }
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(); }