public void WhenSavingEntity_ThenCanRetrieveIt() { var id = Guid.NewGuid(); using (var context = new TestOrmSagaRepository(Mock.Of <ICommandBus>())) { var conference = new OrmTestSaga(id); context.Save(conference); } using (var context = new TestOrmSagaRepository(Mock.Of <ICommandBus>())) { var conference = context.Find <OrmTestSaga>(id); Assert.NotNull(conference); } }
public void WhenEntityExposesEvent_ThenRepositoryPublishesIt() { var bus = new Mock <ICommandBus>(); var commands = new List <ICommand>(); bus.Setup(x => x.Send(It.IsAny <IEnumerable <Envelope <ICommand> > >())) .Callback <IEnumerable <Envelope <ICommand> > >(x => commands.AddRange(x.Select(e => e.Body))); var command = new TestCommand(); using (var context = new TestOrmSagaRepository(bus.Object)) { var aggregate = new OrmTestSaga(Guid.NewGuid()); aggregate.AddCommand(command); context.Save(aggregate); } Assert.Equal(1, commands.Count); Assert.True(commands.Contains(command)); }
public void WhenSavingEntityTwice_ThenCanReloadIt() { var id = Guid.NewGuid(); using (var context = new TestOrmSagaRepository(Mock.Of <ICommandBus>())) { var conference = new OrmTestSaga(id); context.Save(conference); } using (var context = new TestOrmSagaRepository(Mock.Of <ICommandBus>())) { var conference = context.Find <OrmTestSaga>(id); conference.Title = "CQRS Journey"; context.Save(conference); context.Entry(conference).Reload(); Assert.Equal("CQRS Journey", conference.Title); } }