Exemplo n.º 1
0
 /// <summary>
 /// <see cref="IHandleEvent{TEvent}.Handle(TEvent)"/>
 /// </summary>
 /// <param name="event"></param>
 public void Handle(BrandInfoUpdatedEvent @event)
 {
     try
     {
         EventStore.Save(@event);
     }
     catch
     {
         throw;
     }
 }
        /// <summary>
        /// Implementation of <see cref="IBrandCommands.UpdateBrandInfo(Guid, string, string, string, Image)"/>
        /// </summary>
        /// <param name="brandId">The brand's id</param>
        /// <param name="name">The brand's new name</param>
        /// <param name="url">The brand's new url</param>
        /// <param name="description">The brand's new description</param>
        /// <param name="logo">The brand's new logo</param>
        /// <returns></returns>
        public virtual async Task UpdateBrandInfo(Guid brandId, string name, string url, string description, Image logo)
        {
            try
            {
                if (brandId == Guid.Empty)
                {
                    throw new ArgumentException("value cannot be empty", nameof(brandId));
                }

                var brand = await Repository.GetByKeyAsync <Brand>(brandId);

                if (brand.Name != name)
                {
                    brand.ChangeName(name);
                }

                if (brand.Url != url)
                {
                    brand.ChangeUrl(url);
                }

                if (brand.Description != description)
                {
                    brand.ChangeDescription(description);
                }

                if (brand.Logo != logo)
                {
                    brand.SetLogo(logo);
                }

                await Repository.SaveChangesAsync();

                var @event = new BrandInfoUpdatedEvent(brandId, name, url, description, logo);
                EventBus.RaiseEvent(@event);
            }
            catch
            {
                throw;
            }
        }
        public void BrandInfoUpdatedEvent_Ctor_Should_Set_Arguments_Correctly()
        {
            Guid   brandId     = Guid.NewGuid();
            string name        = "brand";
            string url         = "brand";
            string description = "description";
            Image  logo        = new Image {
                MimeType = "image/jpg", Data = new byte[0]
            };

            var @event = new BrandInfoUpdatedEvent(brandId, name, url, description, logo);

            Assert.Equal(brandId, @event.BrandId);
            Assert.Equal(name, @event.Name);
            Assert.Equal(url, @event.Url);
            Assert.Equal(description, @event.Description);
            Assert.Equal(logo, @event.Logo);

            Assert.Equal(brandId, @event.AggregateId);
            Assert.Equal(typeof(Catalog.Models.Brand), @event.AggregateType);
        }