Exemplo n.º 1
0
        public async Task SubmitCertificate_Using_StandardCode()
        {
            // arrange
            var submitCertificate = new SubmitCertificateRequest {
                Uln = 9876543210, FamilyName = "Blogs", StandardCode = 1
            };

            var certificateData = Builder <CertificateData> .CreateNew().With(cd => cd.CertificateReference = "DRAFT CERTIFICATE")
                                  .With(cd => cd.Standard        = Builder <Standard> .CreateNew().With(s => s.StandardCode = 1).With(s => s.StandardReference = null).Build())
                                  .With(cd => cd.Learner         = Builder <Learner> .CreateNew().Build())
                                  .With(cd => cd.LearningDetails = Builder <LearningDetails> .CreateNew().Build())
                                  .With(cd => cd.PostalContact   = Builder <PostalContact> .CreateNew().Build())
                                  .Build();

            var status = new Status {
                CurrentStatus = "Submitted"
            };
            var created = new Created {
                CreatedAt = DateTime.UtcNow.AddHours(-1), CreatedBy = "Test"
            };
            var submitted = new Submitted {
                SubmittedAt = DateTime.UtcNow, SubmittedBy = "Test"
            };

            var certificate = new Certificate {
                CertificateData = certificateData, Status = status, Created = created, Submitted = submitted
            };

            var expectedResponse = new List <SubmitCertificateResponse>
            {
                new SubmitCertificateResponse {
                    Certificate = certificate
                }
            };

            _MockHttp.When(HttpMethod.Post, $"{apiBaseAddress}/api/v1/certificate/submit")
            .Respond(HttpStatusCode.OK, "application/json", JsonConvert.SerializeObject(expectedResponse));

            // act
            var actual = await _ApiClient.SubmitCertificates(new List <SubmitCertificateRequest> {
                submitCertificate
            });

            // assert
            Assert.That(actual, Has.Count.EqualTo(1));
            Assert.That(actual.First().ValidationErrors, Has.Count.EqualTo(0));
            Assert.That(actual.First().Certificate, Is.EqualTo(expectedResponse.First().Certificate));
        }
        public async Task SubmitCertificatesExample()
        {
            const string filePath = @"CsvFiles\submitCertificates.csv";

            IEnumerable <SubmitCertificateRequest> certificates;

            using (TextReader textReader = File.OpenText(filePath))
            {
                using (CsvReader csv = new CsvReader(textReader))
                {
                    csv.Configuration.HeaderValidated   = null;
                    csv.Configuration.MissingFieldFound = null;
                    certificates = csv.GetRecords <SubmitCertificateRequest>().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
            {
                var response = (await _CertificateApiClient.SubmitCertificates(certificates)).ToList();

                // NOTE: You may want to deal with good & bad records separately
                var goodCertificates = response.Where(c => c.Certificate != null && !c.ValidationErrors.Any());
                var badCertificates  = response.Except(goodCertificates);

                Console.WriteLine($"Good Certificates: {goodCertificates.Count()}, Bad Certificates: {badCertificates.Count()} ");
            }
        }
        public async Task SubmitCertificatesExample()
        {
            long   uln                  = 1234567890;
            string lastName             = "Blogs";
            int    standardCode         = 1;
            string standardReference    = "ST0127";
            string certificateReference = "00012001";

            SubmitCertificateRequest certificateToSubmit = new SubmitCertificateRequest
            {
                Uln                  = uln,
                FamilyName           = lastName,
                StandardCode         = standardCode,
                StandardReference    = standardReference,
                CertificateReference = certificateReference
            };

            if (certificateToSubmit.IsValid(out _))
            {
                // NOTE: The External API performs validation, however it is a good idea to check beforehand
                await _CertificateApiClient.SubmitCertificates(new List <SubmitCertificateRequest> {
                    certificateToSubmit
                });
            }
        }