public async Task CreateSupplier_New_Created() { var uniqueId = Guid.NewGuid().ToString().Substring(0, 4); var name = Formatters.ToCasSupplierName($"autotest-dev-{uniqueId}", $"autotest-dev-{uniqueId}"); var postalCode = "V1V1V1".ToCasPostalCode(); var createResponse = await client.CreateSupplierAsync(new CreateSupplierRequest { SubCategory = "Individual", SupplierName = name, SupplierAddress = new Supplieraddress[] { new Supplieraddress { ProviderId = "CAS_SU_AT_ESS", AddressLine1 = "123 test st.".StripSpecialCharacters(), PostalCode = postalCode, City = "test city".ToCasCity(), Province = "BC", Country = "CA" } } }, CancellationToken.None); createResponse.ShouldNotBeNull(); createResponse.IsSuccess().ShouldBeTrue(createResponse.CASReturnedMessages); createResponse.SupplierNumber.ShouldNotBeNullOrEmpty(); createResponse.SupplierSiteCode.ShouldNotBeNullOrEmpty(); var getResponse = await client.GetSupplierAsync(new GetSupplierRequest { PostalCode = postalCode, SupplierName = name }, CancellationToken.None); getResponse.ShouldNotBeNull(); getResponse.Suppliernumber.ShouldBe(createResponse.SupplierNumber); getResponse.SupplierAddress.ShouldHaveSingleItem().Suppliersitecode.ShouldBe(createResponse.SupplierSiteCode.StripCasSiteNumberBrackets()); }
public async Task <(string SupplierNumber, string SiteCode)> CreateSupplier(contact contact, CancellationToken ct) { if (string.IsNullOrEmpty(contact.address1_postalcode)) { throw new ArgumentNullException($"contact {contact.contactid}", nameof(contact.address1_postalcode)); } if (string.IsNullOrEmpty(contact.firstname)) { throw new ArgumentNullException($"contact {contact.contactid}", nameof(contact.firstname)); } if (string.IsNullOrEmpty(contact.lastname)) { throw new ArgumentNullException($"contact {contact.contactid}", nameof(contact.lastname)); } var config = await casSystemConfigurationProvider.Get(ct); var response = await casWebProxy.CreateSupplierAsync(new CreateSupplierRequest { SubCategory = "Individual", SupplierName = Formatters.ToCasSupplierName(contact.firstname, contact.lastname), SupplierAddress = new[] { new Supplieraddress { ProviderId = config.ProviderId, AddressLine1 = contact.address1_line1?.ToCasAddressLine(), AddressLine2 = contact.address1_line2?.ToCasAddressLine(), AddressLine3 = contact.address1_line3?.ToCasAddressLine(), City = (contact.era_City?.era_jurisdictionname ?? contact.address1_city).ToCasCity(), PostalCode = contact.address1_postalcode.ToCasPostalCode(), Province = contact.era_ProvinceState?.era_code ?? "BC", Country = "CA", } } }, ct); if (!response.IsSuccess()) { throw new CasException($"CAS supplier creation failed for payee {contact.contactid}: {response.CASReturnedMessages}"); } return(SupplierNumber : response.SupplierNumber, SiteCode : response.SupplierSiteCode.StripCasSiteNumberBrackets()); }