Ejemplo n.º 1
0
        private void When(object @event)
        {
            switch (@event)
            {
            case Events.BrandCreated e:
                Id   = new BrandId(e.Id);
                Name = e.Name;
                break;

            case Events.BrandNameChanged e:
                Name = e.Name;
                break;

            case Events.BrandDeleted e:
                Id   = new BrandId(e.Id);
                Name = e.Name;
                break;
            }
        }
Ejemplo n.º 2
0
        public static Brand Create(BrandId id, string name)
        {
            if (id is null)
            {
                throw new ArgumentNullException(nameof(id), "Brand without unique identifier cannot be created.");
            }

            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name), "Brand without name cannot be created.");
            }

            var brand = new Brand();

            brand.Apply(new Events.BrandCreated
            {
                Id   = id,
                Name = name
            });

            return(brand);
        }