public async Task DeleteEpaRecord() { // arrange long uln = 1234567890; string lastname = "Bloggs"; string standard = "1"; string epaReference = "123456790"; _MockHttp.When(HttpMethod.Delete, $"{apiBaseAddress}/api/v1/epa/{uln}/{lastname}/{standard}/{epaReference}") .Respond(HttpStatusCode.OK, "application/json", string.Empty); // act var request = new DeleteEpaRequest { Uln = uln, FamilyName = lastname, Standard = standard, EpaReference = epaReference }; var actual = await _ApiClient.DeleteEpaRecord(request); // assert Assert.That(actual.Error, Is.Null); }
public async Task DeleteEpaRecordExample() { long uln = 1234567890; string lastName = "Blogs"; string standard = "1"; string epaReference = "1234567890"; DeleteEpaRequest epaToDelete = new DeleteEpaRequest { Uln = uln, FamilyName = lastName, Standard = standard, EpaReference = epaReference }; if (epaToDelete.IsValid(out _)) { // NOTE: The External API performs validation, however it is a good idea to check beforehand await _EpaApiClient.DeleteEpaRecord(epaToDelete); } }
public async Task DeleteEpaRecordExample() { const string filePath = @"CsvFiles\deleteEpaRecords.csv"; IEnumerable <DeleteEpaRequest> epaRecordsToDelete; using (TextReader textReader = File.OpenText(filePath)) { using (CsvReader csv = new CsvReader(textReader)) { csv.Configuration.HeaderValidated = null; csv.Configuration.MissingFieldFound = null; epaRecordsToDelete = csv.GetRecords <DeleteEpaRequest>().ToList(); } } // NOTE: The External API performs validation, however it is a good idea to check beforehand. bool invalidDataSupplied = epaRecordsToDelete.Any(c => !c.IsValid(out _)); if (invalidDataSupplied) { throw new InvalidOperationException("The supplied CSV file contains invalid data. Please correct and then try again."); } else { // NOTE: The External API does not have an batch delete (for safety reasons). You'll have to loop. foreach (var request in epaRecordsToDelete) { var response = await _EpaApiClient.DeleteEpaRecord(request); if (response.Error != null) { // NOTE: You may want to deal with bad records separately } } } }