public void WHEN_saving_saga_with_a_batch_of_events_THEN_can_rehydrate() { this.sagaId = Guid.NewGuid(); var item = new Item { Id = 1, Name = "item1" }; var item2 = new Item { Id = 2, Name = "item2" }; var saga = new FakeItemsSaga(sagaId); saga.AddItem(item.Id, item.Name, 10); saga.AddItem(item2.Id, item2.Name, 10); saga.AddItem(item.Id, item.Name, 5); this.sut.Save(saga, new FakeCommand(Guid.Empty)); var retrivedSaga = this.sut.Find(sagaId); Assert.NotNull(retrivedSaga); Assert.True(retrivedSaga.itemsQuantity.ContainsKey(item.Id)); Assert.True(retrivedSaga.itemsQuantity.ContainsKey(item2.Id)); Assert.Equal(retrivedSaga.itemsQuantity[item2.Id], 10); Assert.Equal(retrivedSaga.itemsQuantity[item.Id], 15); }
public void WHEN_saving_saga_with_an_event_and_a_command_THEN_sends_command_to_the_bus_and_can_rehydrate() { this.sagaId = Guid.NewGuid(); var item = new Item { Id = 1, Name = "item1" }; var saga = new FakeItemsSaga(sagaId); saga.AddItem(item.Id, item.Name, 10); Assert.Empty(saga.Commands); this.sut.Save(saga, new FakeCommand(Guid.Empty)); var retrivedSaga = this.sut.Find(sagaId); Assert.NotNull(retrivedSaga); Assert.True(retrivedSaga.itemsQuantity.ContainsKey(item.Id)); Assert.Equal(retrivedSaga.itemsQuantity[item.Id], 10); retrivedSaga.MakeItemReservation(item, 2); Assert.NotEmpty(retrivedSaga.Commands); Assert.Equal(1, retrivedSaga.Commands.Count()); /* Command Publishing */ this.sut.Save(retrivedSaga, new FakeCommand(Guid.Empty)); var overRetrivedSaga = this.sut.Find(sagaId); Assert.NotNull(overRetrivedSaga); Assert.True(retrivedSaga.itemsQuantity.ContainsKey(item.Id)); Assert.Equal(retrivedSaga.itemsQuantity[item.Id], 8); }