Example #1
0
 public void Handle(ProductReviewAddedEvent @event)
 {
     try
     {
         EventStore.Save(@event);
     }
     catch
     {
         throw;
     }
 }
Example #2
0
        public void ProductReviewAddedEvent_Ctor_Should_Set_Arguments_Correctly()
        {
            Guid   productId = Guid.NewGuid();
            string name      = "review";
            int    rating    = 2;
            string comment   = "comment";

            var @event = new ProductReviewAddedEvent(productId, name, rating, comment);

            Assert.Equal(productId, @event.ProductId);
            Assert.Equal(name, @event.Name);
            Assert.Equal(rating, @event.Rating);
            Assert.Equal(comment, @event.Comment);

            Assert.Equal(productId, @event.AggregateId);
            Assert.Equal(typeof(Catalog.Models.Product), @event.AggregateType);
        }
Example #3
0
        public async Task AddProductReview(Guid productId, string name, int rating, string comment)
        {
            try
            {
                var product = await Repository.GetByKeyAsync <Product>(productId);

                product.AddReview(name, rating, comment);

                await Repository.SaveChangesAsync();

                var @event = new ProductReviewAddedEvent(productId, name, rating, comment);
                EventBus.RaiseEvent(@event);
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// Implementation of <see cref="IProductCommands.AddProductReview(Guid, string, int, string)"/>
        /// </summary>
        /// <param name="productId">The product id</param>
        /// <param name="name">The name of the user who leave the review</param>
        /// <param name="rating">The rate given</param>
        /// <param name="comment">The comment given</param>
        /// <returns></returns>
        public virtual async Task AddProductReview(Guid productId, string name, int rating, string comment)
        {
            try
            {
                if (productId == Guid.Empty)
                {
                    throw new ArgumentException("value cannot be empty", nameof(productId));
                }

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

                product.AddReview(name, rating, comment);

                await Repository.SaveChangesAsync();

                var @event = new ProductReviewAddedEvent(productId, name, rating, comment);
                EventBus.RaiseEvent(@event);
            }
            catch
            {
                throw;
            }
        }