Exemple #1
0
        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);
        }
        public async Task Handle(UserCategoryCreatedEvent handle)
        {
            Category category = new Category()
            {
                Id          = handle.AggregateId,
                Name        = handle.Name,
                Version     = handle.Version,
                CreatedDate = handle.Timestamp
            };

            _logger.Trace("UserCategoryCreatedEvent", handle);

            await _categoryRepo.Create(category).ConfigureAwait(false);
        }