public void Ctor_Should_Set_All_Values_Correctly() { Guid customerId = Guid.NewGuid(); Guid billingInfoId = 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 BillingInformationChangedEvent(customerId, billingInfoId, fullName, address, city, postalCode, province, country, nationalIdentificationNumber, vatNumber, isDefault); Assert.Equal(customerId, ev.CustomerId); Assert.Equal(billingInfoId, ev.BillingInfoId); 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); }
/// <summary> /// <see cref="IHandleEvent{TEvent}.Handle(TEvent)"/> /// </summary> /// <param name="event"></param> public void Handle(BillingInformationChangedEvent @event) { try { EventStore.Save(@event); } catch { throw; } }
/// <summary> /// Implementation of <see cref="ICustomerCommands.ChangeCustomerBillingInformation(Guid, Guid, string, string, string, string, string, string, string, string, bool)"/> /// </summary> /// <param name="customerId">The customer id</param> /// <param name="billingInfoId">The billing info 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 ChangeCustomerBillingInformation(Guid customerId, Guid billingInfoId, 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 (billingInfoId == Guid.Empty) { throw new ArgumentException("value cannot be empty", nameof(billingInfoId)); } 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.ChangeBillingInfo(billingInfoId, fullName, address, city, postalCode, province, country, nationalIdentificationNumber, vatNumber, isDefault); await Repository.SaveChangesAsync(); var @event = new BillingInformationChangedEvent(customerId, billingInfoId, fullName, address, city, postalCode, province, country, nationalIdentificationNumber, vatNumber, isDefault); EventBus.RaiseEvent(@event); }
public void ToString_Should_Return_Event_Formatted_As_String() { Guid customerId = Guid.NewGuid(); Guid billingInfoId = 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 BillingInformationChangedEvent(customerId, billingInfoId, fullName, address, city, postalCode, province, country, nationalIdentificationNumber, vatNumber, isDefault); string eventAsString = $"Billing info {billingInfoId} changed for customer {customerId} with values {fullName}, {nationalIdentificationNumber} {vatNumber}, {address} {city}, {postalCode}, {province} {country}"; Assert.Equal(eventAsString, ev.ToString()); }