예제 #1
0
        public async Task DeleteCertificate()
        {
            // arrange
            long   uln                  = 1234567890;
            string lastname             = "Bloggs";
            string standard             = "1";
            string certificateReference = "123456790";

            _MockHttp.When(HttpMethod.Delete, $"{apiBaseAddress}/api/v1/certificate/{uln}/{lastname}/{standard}/{certificateReference}")
            .Respond(HttpStatusCode.OK, "application/json", string.Empty);

            // act
            var request = new DeleteCertificateRequest {
                Uln = uln, FamilyName = lastname, Standard = standard, CertificateReference = certificateReference
            };
            var actual = await _ApiClient.DeleteCertificate(request);

            // assert
            Assert.That(actual.Error, Is.Null);
        }
        public async Task DeleteCertificateExample()
        {
            long   uln                  = 1234567890;
            string lastName             = "Blogs";
            string standard             = "1";
            string certificateReference = "00012001";

            DeleteCertificateRequest certificateToDelete = new DeleteCertificateRequest
            {
                Uln                  = uln,
                FamilyName           = lastName,
                Standard             = standard,
                CertificateReference = certificateReference
            };

            if (certificateToDelete.IsValid(out _))
            {
                // NOTE: The External API performs validation, however it is a good idea to check beforehand
                await _CertificateApiClient.DeleteCertificate(certificateToDelete);
            }
        }
        public async Task DeleteCertificateExample()
        {
            const string filePath = @"CsvFiles\deleteCertificates.csv";

            IEnumerable <DeleteCertificateRequest> certificates;

            using (TextReader textReader = File.OpenText(filePath))
            {
                using (CsvReader csv = new CsvReader(textReader))
                {
                    csv.Configuration.HeaderValidated   = null;
                    csv.Configuration.MissingFieldFound = null;
                    certificates = csv.GetRecords <DeleteCertificateRequest>().ToList();
                }
            }

            // NOTE: The External API performs validation, however it is a good idea to check beforehand.
            bool invalidDataSupplied = certificates.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 certificates)
                {
                    var response = await _CertificateApiClient.DeleteCertificate(request);

                    if (response.Error != null)
                    {
                        // NOTE: You may want to deal with bad records separately
                    }
                }
            }
        }