void OnUpdateCustomer(string commandId, UpdateCustomerMessage message) { var customer = repository.Get(message.CustomerId); customer.SetName(message.Name); customer.SetEmail(message.Email); customer.SetVatNumber(message.VatNumber); repository.Save(customer, commandId); }
public void Get_should_throw_an_exception_when_there_are_no_evetns_with_specified_source_id() { var eventStoreMock = new Mock <IEventStore>(); eventStoreMock.Setup(eventStore => eventStore.Load(It.IsAny <Guid>(), 0)).Returns(Enumerable.Empty <Commit>); var repository = new EventSourcedRepository <CorrectEventSourced>(eventStoreMock.Object); var id = Guid.NewGuid(); Action action = () => repository.Get(id); action.ShouldThrow <EntityNotFoundException>() .Where(ex => ex.EntityId == id.ToString() && ex.EntityType == typeof(CorrectEventSourced).Name); }
public void Shoud_throw_concurrency_exception_when_there_was_an_attempt_to_save_changes_of_outdated_entity() { var source = new TestEventSourced(42, "forty-two"); repository.Save(source, Guid.NewGuid().ToString()); var source1 = repository.Get(source.Id); source1.UpdateNumber(43); repository.Save(source1, Guid.NewGuid().ToString()); source.UpdateNumber(44); Action action = () => repository.Save(source, Guid.NewGuid().ToString()); action.ShouldThrow <ConcurrencyException>() .Where(ex => ex.EntityId == source.Id && ex.EntityType == source.GetType().Name); }