public void Ctor_Should_Set_All_Values_Correctly() { Guid customerId = Guid.NewGuid(); Guid addressId = Guid.NewGuid(); string address = "address"; string city = "city"; string postalCode = "12345"; string province = "province"; string country = "country"; bool isDefault = true; var ev = new ShippingAddressChangedEvent(customerId, addressId, address, city, postalCode, province, country, isDefault); Assert.Equal(customerId, ev.CustomerId); Assert.Equal(addressId, ev.AddressId); 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(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(ShippingAddressChangedEvent @event) { try { EventStore.Save(@event); } catch { throw; } }
public void ToString_Should_Return_Event_Formatted_As_String() { Guid customerId = Guid.NewGuid(); Guid addressId = Guid.NewGuid(); string address = "address"; string city = "city"; string postalCode = "12345"; string province = "province"; string country = "country"; bool isDefault = true; var ev = new ShippingAddressChangedEvent(customerId, addressId, address, city, postalCode, province, country, isDefault); string eventAsString = $"Address {addressId} changed for customer {customerId} with values {address}, {city} {postalCode}, {province} {country}"; Assert.Equal(eventAsString, ev.ToString()); }
/// <summary> /// Implementation of <see cref="ICustomerCommands.ChangeCustomerShippingAddress(Guid, Guid, string, string, string, string, string, bool)"/> /// </summary> /// <param name="customerId">The customer id</param> /// <param name="addressId">The address 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> /// <param name="isDefault">Whether the shipping address is the default address</param> /// <returns></returns> public async Task ChangeCustomerShippingAddress(Guid customerId, Guid addressId, string address, string city, string postalCode, string province, string country, bool isDefault) { if (customerId == Guid.Empty) { throw new ArgumentException("value cannot be empty", nameof(customerId)); } if (addressId == Guid.Empty) { throw new ArgumentException("value cannot be empty", nameof(addressId)); } 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.ChangeShippingAddress(addressId, address, city, postalCode, province, country, isDefault); await Repository.SaveChangesAsync(); var @event = new ShippingAddressChangedEvent(customerId, addressId, address, city, postalCode, province, country, isDefault); EventBus.RaiseEvent(@event); }