public void Handle(ProductReviewAddedEvent @event) { try { EventStore.Save(@event); } catch { throw; } }
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); }
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; } }