コード例 #1
0
        /// <summary>
        /// Implementation of <see cref="IBrandCommands.CreateNewBrand(string, string, string, Image)"/>
        /// </summary>
        /// <param name="name">The brand's name</param>
        /// <param name="url">The brand's unique url</param>
        /// <param name="description">The brand's description</param>
        /// <param name="logo">The brand's logo</param>
        /// <returns>The brand id</returns>
        public virtual async Task <Guid> CreateNewBrand(string name, string url, string description, Image logo)
        {
            try
            {
                var brand = Brand.Create(name, url);
                if (!string.IsNullOrEmpty(description))
                {
                    brand.ChangeDescription(description);
                }

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

                Repository.Add(brand);
                await Repository.SaveChangesAsync();

                var @event = new BrandCreatedEvent(brand.Id, brand.Name);
                EventBus.RaiseEvent(@event);

                return(brand.Id);
            }
            catch
            {
                throw;
            }
        }
コード例 #2
0
        public void BrandCreatedEvent_Ctor_Should_Set_Arguments_Correctly()
        {
            Guid   brandId = Guid.NewGuid();
            string name    = "brand";

            var @event = new BrandCreatedEvent(brandId, name);

            Assert.Equal(brandId, @event.BrandId);
            Assert.Equal(name, @event.Name);

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