public override Providers.EventStore.Entities.BaseMemento ToProviderEntity(BaseMemento source) { var target = base.ToProviderEntity(source); target.Data = DatabaseEventStorage.Serialize <BaseMemento>(source); return(target); }
public override Providers.EventStore.Entities.Event ToProviderEntity(Event source) { var target = base.ToProviderEntity(source); target.Data = DatabaseEventStorage.Serialize <Event>(source); return(target); }
public async Task UserCategoriesFromHistoryCanPopulateQueryDbUsingGenericHandlerResolver() { var sh = _stateHelper; await _aggregateRepository.Create(new AggregateRoot { EventVersion = 0, Version = 0, Id = 2 }); UserCategoryCreatedEvent e2 = new UserCategoryCreatedEvent(2, "Category 2", DateTime.UtcNow); await _eventRepository.Create(new Event { Id = 2, AggregateId = 2, Data = DatabaseEventStorage.Serialize <UserCategoryCreatedEvent>(e2) }); UserCategoryNameChangedEvent e3 = new UserCategoryNameChangedEvent(2, "Category 2 Renamed Once", 0, DateTime.UtcNow); await _eventRepository.Create(new Event { Id = 3, AggregateId = 2, Data = DatabaseEventStorage.Serialize <UserCategoryNameChangedEvent>(e3) }); UserCategoryNameChangedEvent e4 = new UserCategoryNameChangedEvent(2, "Category 2 Renamed Twice", 1, DateTime.UtcNow); await _eventRepository.Create(new Event { Id = 4, AggregateId = 2, Data = DatabaseEventStorage.Serialize <UserCategoryNameChangedEvent>(e4) }); UserCategoryNameChangedEvent e5 = new UserCategoryNameChangedEvent(2, "Category 2 Renamed Three Times", 2, DateTime.UtcNow); await _eventRepository.Create(new Event { Id = 5, AggregateId = 2, Data = DatabaseEventStorage.Serialize <UserCategoryNameChangedEvent>(e5) }); UserCategoryNameChangedEvent e6 = new UserCategoryNameChangedEvent(2, "Category 2 Renamed Four Times", 3, DateTime.UtcNow); await _eventRepository.Create(new Event { Id = 6, AggregateId = 2, Data = DatabaseEventStorage.Serialize <UserCategoryNameChangedEvent>(e6) }); UserCategoryNameChangedEvent e7 = new UserCategoryNameChangedEvent(2, "Category 2 Renamed Five Times", 4, DateTime.UtcNow); await _eventRepository.Create(new Event { Id = 6, AggregateId = 2, Data = DatabaseEventStorage.Serialize <UserCategoryNameChangedEvent>(e7) }); await sh.RestoreState(); var cats = await _categoryRepo.FindByAsync(q => q.Id == 2).ConfigureAwait(false); var cat = cats.FirstOrDefault(); Assert.AreEqual("Category 2 Renamed Five Times", cat.Name); }
public async Task UserCategoriesFromHistoryCanPopulateQueryDb() { await _aggregateRepository.Create(new AggregateRoot { EventVersion = 0, Version = 0, Id = 1 }); UserCategoryCreatedEvent e2 = new UserCategoryCreatedEvent(1, "Category 1", DateTime.UtcNow); await _eventRepository.Create(new Event { Id = 2, AggregateId = 1, Data = DatabaseEventStorage.Serialize <UserCategoryCreatedEvent>(e2) }); UserCategoryNameChangedEvent e3 = new UserCategoryNameChangedEvent(1, "Category 1 Renamed Once", 0, DateTime.UtcNow); await _eventRepository.Create(new Event { Id = 3, AggregateId = 1, Data = DatabaseEventStorage.Serialize <UserCategoryNameChangedEvent>(e3) }); UserCategoryNameChangedEvent e4 = new UserCategoryNameChangedEvent(1, "Category 1 Renamed Twice", 1, DateTime.UtcNow); await _eventRepository.Create(new Event { Id = 4, AggregateId = 1, Data = DatabaseEventStorage.Serialize <UserCategoryNameChangedEvent>(e4) }); UserCategoryNameChangedEvent e5 = new UserCategoryNameChangedEvent(1, "Category 1 Renamed Three Times", 2, DateTime.UtcNow); await _eventRepository.Create(new Event { Id = 5, AggregateId = 1, Data = DatabaseEventStorage.Serialize <UserCategoryNameChangedEvent>(e5) }); UserCategoryNameChangedEvent e6 = new UserCategoryNameChangedEvent(1, "Category 1 Renamed Four Times", 3, DateTime.UtcNow); await _eventRepository.Create(new Event { Id = 6, AggregateId = 1, Data = DatabaseEventStorage.Serialize <UserCategoryNameChangedEvent>(e6) }); UserCategoryNameChangedEvent e7 = new UserCategoryNameChangedEvent(1, "Category 1 Renamed Five Times", 4, DateTime.UtcNow); await _eventRepository.Create(new Event { Id = 7, AggregateId = 1, Data = DatabaseEventStorage.Serialize <UserCategoryNameChangedEvent>(e7) }); foreach (var @event in (await _eventRepository.FindByAsync(x => true)).ToList()) { var e = DatabaseEventStorage.DeSerialize(@event.Data); if (e is UserCategoryNameChangedEvent) { var handlers = _eventHandlerFactory.GetHandlers <UserCategoryNameChangedEvent>(); foreach (var eventHandler in handlers) { eventHandler.Handle(e); } } if (e is UserCategoryCreatedEvent) { var handlers = _eventHandlerFactory.GetHandlers <UserCategoryCreatedEvent>(); foreach (var eventHandler in handlers) { eventHandler.Handle(e); } } } var cats = await _categoryRepo.FindByAsync(q => q.Id == 1).ConfigureAwait(false); var cat = cats.FirstOrDefault(); Assert.AreEqual("Category 1 Renamed Five Times", cat.Name); }
public async Task UserCategoriesCanBeReadFromHistoryWithMementos() { await _aggregateRepository.Create(new AggregateRoot { EventVersion = 0, Version = 0, Id = 1 }); UserCategoryCreatedEvent e2 = new UserCategoryCreatedEvent(2, "Category 2", DateTime.UtcNow); await _eventRepository.Create(new Event { Id = 2, AggregateId = 1, Data = DatabaseEventStorage.Serialize <UserCategoryCreatedEvent>(e2) }); UserCategoryNameChangedEvent e3 = new UserCategoryNameChangedEvent(1, "Category 2 Renamed Once", 0, DateTime.UtcNow); await _eventRepository.Create(new Event { Id = 3, AggregateId = 1, Data = DatabaseEventStorage.Serialize <UserCategoryNameChangedEvent>(e3) }); UserCategoryNameChangedEvent e4 = new UserCategoryNameChangedEvent(1, "Category 2 Renamed Twice", 1, DateTime.UtcNow); await _eventRepository.Create(new Event { Id = 4, AggregateId = 1, Data = DatabaseEventStorage.Serialize <UserCategoryNameChangedEvent>(e4) }); UserCategoryNameChangedEvent e5 = new UserCategoryNameChangedEvent(1, "Category 2 Renamed Three Times", 2, DateTime.UtcNow); await _eventRepository.Create(new Event { Id = 5, AggregateId = 1, Data = DatabaseEventStorage.Serialize <UserCategoryNameChangedEvent>(e5) }); UserCategoryNameChangedEvent e6 = new UserCategoryNameChangedEvent(1, "Category 2 Renamed Four Times", 3, DateTime.UtcNow); await _eventRepository.Create(new Event { Id = 6, AggregateId = 1, Data = DatabaseEventStorage.Serialize <UserCategoryNameChangedEvent>(e6) }); UserCategoryNameChangedEvent e7 = new UserCategoryNameChangedEvent(1, "Category 2 Renamed Five Times", 4, DateTime.UtcNow); await _eventRepository.Create(new Event { Id = 6, AggregateId = 1, Data = DatabaseEventStorage.Serialize <UserCategoryNameChangedEvent>(e7) }); UserCategoryMemento memento = new UserCategoryMemento(1, "Category 2 Renamed Three Times", 3); await _mementoRepository.Create(new BaseMemento { Id = 1, Version = 3, Data = DatabaseEventStorage.Serialize <UserCategoryMemento>(memento) }); var uc2 = await _userCategoryRepository.GetById(1).ConfigureAwait(false); Assert.AreEqual("Category 2 Renamed Five Times", uc2.Name); }
public async Task UserCategoriesCanBeReadFromHistoryWithoutMementos() { await _aggregateRepository.Create(new AggregateRoot { EventVersion = 0, Version = 0, Id = 1 }); await _aggregateRepository.Create(new AggregateRoot { EventVersion = 0, Version = 0, Id = 2 }); UserCategoryCreatedEvent e = new UserCategoryCreatedEvent(1, "Category 1", DateTime.UtcNow); await _eventRepository.Create(new Event { Id = 1, AggregateId = 1, Data = DatabaseEventStorage.Serialize <UserCategoryCreatedEvent>(e) }); UserCategoryCreatedEvent e2 = new UserCategoryCreatedEvent(2, "Category 2", DateTime.UtcNow); await _eventRepository.Create(new Event { Id = 2, AggregateId = 2, Data = DatabaseEventStorage.Serialize <UserCategoryCreatedEvent>(e2) }); UserCategoryNameChangedEvent e3 = new UserCategoryNameChangedEvent(2, "Category 2 Renamed", 0, DateTime.UtcNow); await _eventRepository.Create(new Event { Id = 3, AggregateId = 2, Data = DatabaseEventStorage.Serialize <UserCategoryNameChangedEvent>(e3) }); var uc1 = await _userCategoryRepository.GetById(1).ConfigureAwait(false); var uc2 = await _userCategoryRepository.GetById(2).ConfigureAwait(false); Assert.AreEqual("Category 1", uc1.Name); Assert.AreEqual("Category 2 Renamed", uc2.Name); }
public async Task UserCategoryUpdateCommandTriggersEventToUpdateQueryDbWithNewCategoryName() { //Arrange string newName = "NewCategoryNameForCategory2"; await _categoryRepo.Create(new Category { Id = 1, Name = "Category1", Version = 0 }); await _categoryRepo.Create(new Category { Id = 2, Name = "Category2", Version = 0 }); await _categoryRepo.Create(new Category { Id = 3, Name = "Category3", Version = 0 }); UserCategoryCreatedEvent e = new UserCategoryCreatedEvent(1, "Category2", DateTime.UtcNow); await _eventRepository.Create(new Event { Id = 2, AggregateId = 1, Data = DatabaseEventStorage.Serialize <UserCategoryCreatedEvent>(e) }); await _aggregateRepository.Create(new AggregateRoot { EventVersion = 0, Id = 1 }); //Act await _commandBus.Send(new UserCategoryNameChangeCommand(1, newName, 0)); var cats = await _categoryRepo.FindByAsync(q => q.Id == 1).ConfigureAwait(false); var cat = cats.FirstOrDefault(); //Assert Assert.AreEqual(newName, cat.Name); Assert.AreEqual(1, cat.Version); }