/// <summary>
        /// Implementation of <see cref="IProductCommands.RemoveProductCategory(Guid, Guid)"/>
        /// </summary>
        /// <param name="productId"></param>
        /// <param name="categoryId"></param>
        /// <returns></returns>
        public async Task RemoveProductCategory(Guid productId, Guid categoryId)
        {
            try
            {
                if (productId == Guid.Empty)
                {
                    throw new ArgumentException("value cannot be empty", nameof(productId));
                }

                if (categoryId == Guid.Empty)
                {
                    throw new ArgumentException("value cannot be empty", nameof(categoryId));
                }

                var product = await Repository.GetByKeyAsync <Product>(productId);

                var category = await Repository.GetByKeyAsync <Category>(categoryId);

                product.RemoveCategory(category);

                var @event = new ProductCategoryRemovedEvent(productId, categoryId);
                EventBus.RaiseEvent(@event);

                await Repository.SaveChangesAsync();
            }
            catch
            {
                throw;
            }
        }
 /// <summary>
 /// <see cref="IHandleEvent{TEvent}.Handle(TEvent)"/>
 /// </summary>
 /// <param name="event"></param>
 public void Handle(ProductCategoryRemovedEvent @event)
 {
     try
     {
         EventStore.Save(@event);
     }
     catch
     {
         throw;
     }
 }
Exemplo n.º 3
0
        public void ProductCategoryRemovedEvent_Ctor_Should_Set_Arguments_Correctly()
        {
            Guid productId  = Guid.NewGuid();
            Guid categoryId = Guid.NewGuid();

            var @event = new ProductCategoryRemovedEvent(productId, categoryId);

            Assert.Equal(productId, @event.ProductId);
            Assert.Equal(categoryId, @event.CategoryId);

            Assert.Equal(productId, @event.AggregateId);
            Assert.Equal(typeof(Catalog.Models.Product), @event.AggregateType);
        }