示例#1
0
        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 SaveMemento(Framework.DesignPatterns.CQRS.Domain.BaseMemento memento)
 {
     await _mementoRepository.Create(_mementoMapper.ToProviderEntity(memento)).ConfigureAwait(false);
 }