public void ReconstitutedNewAccountHasCorrectName() { var accountId = new Guid("A34C7724-F9FE-4A14-89A2-C8F1D662EE2A"); var eventStore = new EventStore(); var prevouslyCreatedAccount = new Account(accountId, "Test2"); eventStore.Add(prevouslyCreatedAccount.Events); var account = new Account(accountId, eventStore.GetEvents()); Assert.AreEqual("Test2", account.Name); }
/// <summary> /// Find (rehydrate) an account aggregate. /// </summary> /// <param name="id">Account Id</param> /// <param name="unitOfWork">Unit of work</param> /// <returns>Rehydrated aggregate</returns> /// <remarks>TODO: Could it happen that there are new events for the aggregate that are not on the aggregate in our unit of work?</remarks> public Account Find(Guid id, IAggregateUnitOfWork unitOfWork) { // This assumes that the aggregate in the unit of work is up-to-date var fromUnitOfWork = unitOfWork.Get<Account>(id); if (fromUnitOfWork != null) { return fromUnitOfWork; } var newAccount = new Account(id, this.eventStore.GetEventsFor(id)); unitOfWork.Register(newAccount); return newAccount; }
/// <summary> /// Save the (new) account (in the unit of work) /// </summary> /// <param name="account">Account to save</param> /// <param name="unitOfWork">Unit of work to use</param> public void Save(Account account, IAggregateUnitOfWork unitOfWork) { unitOfWork.Register(account); }
public void NewAccountHasName() { var account = new Account(new Guid("DB1C3C3E-C8C4-47A0-AD43-F154FDDB0577"), "Test1"); Assert.AreEqual("Test1", account.Name); }