/// <summary> /// Implementation of <see cref="ICustomerCommands.RemoveCustomerAccount(Guid)"/> /// </summary> /// <param name="customerId">The customer id</param> /// <returns></returns> public async Task RemoveCustomerAccount(Guid customerId) { if (customerId == Guid.Empty) { throw new ArgumentException("value cannot be empty", nameof(customerId)); } var customer = await Repository.GetByKeyAsync <Customer>(customerId); if (customer == null) { throw new ArgumentOutOfRangeException(nameof(customerId)); } try { var accountId = customer.Account.UserId; string userName = customer.Account.UserName; customer.RemoveAccount(); await AuthClient.DisableAccount(accountId); await Repository.SaveChangesAsync(); var @event = new CustomerAccountRemovedEvent(customerId, userName); EventBus.RaiseEvent(@event); } catch { throw; } }
public void ToString_Should_Return_Event_Formatted_As_String() { Guid customerId = Guid.NewGuid(); string userName = "******"; var ev = new CustomerAccountRemovedEvent(customerId, userName); string eventAsString = $"Account {userName} removed from customer {customerId}"; Assert.Equal(eventAsString, ev.ToString()); }
/// <summary> /// <see cref="IHandleEvent{TEvent}.Handle(TEvent)"/> /// </summary> /// <param name="event"></param> public void Handle(CustomerAccountRemovedEvent @event) { try { EventStore.Save(@event); } catch { throw; } }
public void Ctor_Should_Set_All_Values_Correctly() { Guid customerId = Guid.NewGuid(); string userName = "******"; var ev = new CustomerAccountRemovedEvent(customerId, userName); Assert.Equal(customerId, ev.CustomerId); Assert.Equal(userName, ev.UserName); Assert.Equal(customerId, ev.AggregateId); Assert.Equal(typeof(Registries.Models.Customer), ev.AggregateType); }