/// <summary> /// Implementation of <see cref="ICustomerCommands.MarkCustomerBillingInformationAsDefault(Guid, Guid)"/> /// </summary> /// <param name="customerId">The customer id</param> /// <param name="billingInfoId">The billing info id</param> /// <returns></returns> public async Task MarkCustomerBillingInformationAsDefault(Guid customerId, Guid billingInfoId) { 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)); } var customer = await Repository.GetByKeyAsync <Customer>(customerId); if (customer == null) { throw new ArgumentOutOfRangeException(nameof(customerId)); } customer.MarkBillingInfoAsDefault(billingInfoId); await Repository.SaveChangesAsync(); var @event = new BillingInformationMarkedAsDefaultEvent(customerId, billingInfoId); EventBus.RaiseEvent(@event); }
public void ToString_Should_Return_Event_Formatted_As_String() { Guid customerId = Guid.NewGuid(); Guid billingInfoId = Guid.NewGuid(); var ev = new BillingInformationMarkedAsDefaultEvent(customerId, billingInfoId); string eventAsString = $"Billing info {billingInfoId} marked as default for customer {customerId}"; Assert.Equal(eventAsString, ev.ToString()); }
/// <summary> /// <see cref="IHandleEvent{TEvent}.Handle(TEvent)"/> /// </summary> /// <param name="event"></param> public void Handle(BillingInformationMarkedAsDefaultEvent @event) { try { EventStore.Save(@event); } catch { throw; } }
public void Ctor_Should_Set_All_Values_Correctly() { Guid customerId = Guid.NewGuid(); Guid billingInfoId = Guid.NewGuid(); var ev = new BillingInformationMarkedAsDefaultEvent(customerId, billingInfoId); Assert.Equal(customerId, ev.CustomerId); Assert.Equal(billingInfoId, ev.BillingInfoId); Assert.Equal(customerId, ev.AggregateId); Assert.Equal(typeof(Registries.Models.Customer), ev.AggregateType); }