public void ToString_Should_Return_Event_Formatted_As_String() { Guid companyId = Guid.NewGuid(); string companyName = "company"; string vatNumber = "1234567890"; string nationalIdentificationNumber = "number"; var ev = new CompanyInfoChangedEvent(companyId, companyName, vatNumber, nationalIdentificationNumber); string eventAsString = $"Company {companyId} info changed. Company name: {companyName}, VAT number: {vatNumber}, National identification number: {nationalIdentificationNumber}"; Assert.Equal(eventAsString, ev.ToString()); }
public void Ctor_Should_Set_All_Values_Correctly() { Guid companyId = Guid.NewGuid(); string companyName = "company"; string vatNumber = "1234567890"; string nationalIdentificationNumber = "number"; var ev = new CompanyInfoChangedEvent(companyId, companyName, vatNumber, nationalIdentificationNumber); Assert.Equal(companyId, ev.CompanyId); Assert.Equal(companyName, ev.CompanyName); Assert.Equal(vatNumber, ev.VatNumber); Assert.Equal(nationalIdentificationNumber, ev.NationalIdentificationNumber); Assert.Equal(companyId, ev.AggregateId); Assert.Equal(typeof(Registries.Models.Customer), ev.AggregateType); }
/// <summary> /// Implementation of <see cref="ICustomerCommands.ChangeCompanyInfo(Guid, string, string, string)"/> /// </summary> /// <param name="customerId">The customer id</param> /// <param name="companyName">The company name</param> /// <param name="vatNumber">The company vat number</param> /// <param name="nationalIdentificationNumber">The company national identification number</param> /// <returns></returns> public async Task ChangeCompanyInfo(Guid customerId, string companyName, string vatNumber, string nationalIdentificationNumber) { if (customerId == Guid.Empty) { throw new ArgumentException("value cannot be empty", nameof(customerId)); } if (string.IsNullOrWhiteSpace(companyName)) { throw new ArgumentException("value cannot be empty", nameof(companyName)); } if (string.IsNullOrWhiteSpace(vatNumber)) { throw new ArgumentException("value cannot be empty", nameof(vatNumber)); } var customer = await Repository.GetByKeyAsync <Company>(customerId); if (customer == null) { throw new ArgumentOutOfRangeException(nameof(customerId)); } if (customer.CompanyName != companyName) { customer.ChangeCompanyName(companyName); } if (customer.VatNumber != vatNumber) { customer.ChangeVatNumber(vatNumber); } if (customer.NationalIdentificationNumber != nationalIdentificationNumber) { customer.SetNationalIdentificationNumber(nationalIdentificationNumber); } await Repository.SaveChangesAsync(); var @event = new CompanyInfoChangedEvent(customerId, companyName, vatNumber, nationalIdentificationNumber); EventBus.RaiseEvent(@event); }