/// <summary>
 /// <see cref="IHandleEvent{TEvent}.Handle(TEvent)"/>
 /// </summary>
 /// <param name="event"></param>
 public void Handle(CompanyLegalAddressChangedEvent @event)
 {
     try
     {
         EventStore.Save(@event);
     }
     catch
     {
         throw;
     }
 }
        public void ToString_Should_Return_Event_Formatted_As_String()
        {
            Guid   companyId  = Guid.NewGuid();
            string address    = "address";
            string city       = "city";
            string postalCode = "12345";
            string province   = "province";
            string country    = "italy";

            var ev = new CompanyLegalAddressChangedEvent(companyId, address, city, postalCode, province, country);

            string eventAsString = $"Company {companyId} legal address change. {address}, {city}, {postalCode}, {province}, {country}";

            Assert.Equal(eventAsString, ev.ToString());
        }
        public void Ctor_Should_Set_All_Values_Correctly()
        {
            Guid   companyId  = Guid.NewGuid();
            string address    = "address";
            string city       = "city";
            string postalCode = "12345";
            string province   = "province";
            string country    = "italy";

            var ev = new CompanyLegalAddressChangedEvent(companyId, address, city, postalCode, province, country);

            Assert.Equal(companyId, ev.CompanyId);
            Assert.Equal(address, ev.Address);
            Assert.Equal(city, ev.City);
            Assert.Equal(postalCode, ev.PostalCode);
            Assert.Equal(province, ev.Province);
            Assert.Equal(country, ev.Country);

            Assert.Equal(companyId, ev.AggregateId);
            Assert.Equal(typeof(Registries.Models.Customer), ev.AggregateType);
        }
示例#4
0
        /// <summary>
        /// Implementation of <see cref="ICustomerCommands.ChangeCompanyLegalAddress(Guid, string, string, string, string, string)"/>
        /// </summary>
        /// <param name="customerId">The customer id</param>
        /// <param name="address">The address</param>
        /// <param name="city">The city</param>
        /// <param name="postalCode">The postal code</param>
        /// <param name="province">The province</param>
        /// <param name="country">The country</param>
        /// <returns></returns>
        public async Task ChangeCompanyLegalAddress(Guid customerId, string address, string city, string postalCode, string province, string country)
        {
            if (customerId == Guid.Empty)
            {
                throw new ArgumentException("value cannot be empty", nameof(customerId));
            }

            if (string.IsNullOrWhiteSpace(address))
            {
                throw new ArgumentException("value cannot be empty", nameof(address));
            }

            if (string.IsNullOrWhiteSpace(city))
            {
                throw new ArgumentException("value cannot be empty", nameof(city));
            }

            if (string.IsNullOrWhiteSpace(province))
            {
                throw new ArgumentException("value cannot be empty", nameof(province));
            }

            var customer = await Repository.GetByKeyAsync <Company>(customerId);

            if (customer == null)
            {
                throw new ArgumentOutOfRangeException(nameof(customerId));
            }

            customer.ChangeLegalAddress(address, city, postalCode, province, country);
            await Repository.SaveChangesAsync();

            var @event = new CompanyLegalAddressChangedEvent(customerId, address, city, postalCode, province, country);

            EventBus.RaiseEvent(@event);
        }