Example #1
0
        public void Ctor_Should_Set_All_Values_Correctly()
        {
            Guid   customerId = Guid.NewGuid();
            string fullName   = "fullname";
            string address    = "address";
            string city       = "city";
            string postalCode = "12345";
            string province   = "province";
            string country    = "country";
            string nationalIdentificationNumber = "number";
            string vatNumber = "1234567890";
            bool   isDefault = true;

            var ev = new BillingInformationAddedEvent(customerId, fullName, address, city, postalCode, province, country, nationalIdentificationNumber, vatNumber, isDefault);

            Assert.Equal(customerId, ev.CustomerId);
            Assert.Equal(fullName, ev.FullName);
            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(nationalIdentificationNumber, ev.NationalIdentificationNumber);
            Assert.Equal(vatNumber, ev.VatNumber);
            Assert.Equal(isDefault, ev.IsDefault);

            Assert.Equal(customerId, ev.AggregateId);
            Assert.Equal(typeof(Registries.Models.Customer), ev.AggregateType);
        }
Example #2
0
        public void ToString_Should_Return_Event_Formatted_As_String()
        {
            Guid   customerId = Guid.NewGuid();
            string fullName   = "fullname";
            string address    = "address";
            string city       = "city";
            string postalCode = "12345";
            string province   = "province";
            string country    = "country";
            string nationalIdentificationNumber = "number";
            string vatNumber = "1234567890";
            bool   isDefault = true;

            var ev = new BillingInformationAddedEvent(customerId, fullName, address, city, postalCode, province, country, nationalIdentificationNumber, vatNumber, isDefault);

            string eventAsString = $"Billingo info {fullName}, {nationalIdentificationNumber} {vatNumber}, {address} {city}, {postalCode}, {province} {country} added to customer {customerId}";

            Assert.Equal(eventAsString, ev.ToString());
        }
Example #3
0
        /// <summary>
        /// Implementation of <see cref="ICustomerCommands.AddCustomerBillingInformation(Guid, string, string, string, string, string, string, string, string, bool)"/>
        /// </summary>
        /// <param name="customerId">The customer id</param>
        /// <param name="fullName">The full name</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>
        /// <param name="nationalIdentificationNumber">The national identification number</param>
        /// <param name="vatNumber">The vat number</param>
        /// <param name="isDefault">Whether the billing information is the default one</param>
        /// <returns></returns>
        public async Task AddCustomerBillingInformation(Guid customerId, string fullName, string address, string city, string postalCode, string province, string country, string nationalIdentificationNumber, string vatNumber, bool isDefault)
        {
            if (customerId == Guid.Empty)
            {
                throw new ArgumentException("value cannot be empty", nameof(customerId));
            }

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

            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 <Customer>(customerId);

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

            customer.AddBillingInformation(fullName, address, city, postalCode, province, country, nationalIdentificationNumber, vatNumber, isDefault);
            await Repository.SaveChangesAsync();

            var @event = new BillingInformationAddedEvent(customerId, fullName, address, city, postalCode, province, country, nationalIdentificationNumber, vatNumber, isDefault);

            EventBus.RaiseEvent(@event);
        }