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

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

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

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

            var country = new Country();

            country.Apply(new Events.CountryCreated
            {
                Id   = id,
                Name = name
            });

            return(country);
        }