Exemplo n.º 1
0
        public async Task When_CreatingEpaRecord_CallsInternalApi_Then_ReturnEpaResponseWithResponseCode200(
            [Frozen] Mock <IHeaderInfo> headerInfo,
            [Frozen] Mock <IApiClient> apiClient,
            CreateEpaRequest request,
            IEnumerable <CreateEpaResponse> response,
            EpaController sut)
        {
            //Arrange
            apiClient.Setup(client => client.CreateEpas(It.Is <IEnumerable <CreateBatchEpaRequest> >(s =>
                                                                                                     s.First().UkPrn == headerInfo.Object.Ukprn &&
                                                                                                     s.First().RequestId == request.RequestId &&
                                                                                                     s.First().Learner == request.Learner &&
                                                                                                     s.First().LearningDetails == request.LearningDetails &&
                                                                                                     s.First().Standard == request.Standard &&
                                                                                                     s.First().EpaDetails == request.EpaDetails))).ReturnsAsync(response);

            //Act
            var result = await sut.CreateEpaRecords(new List <CreateEpaRequest> {
                request
            }) as ObjectResult;

            //Assert
            result.StatusCode.Should().Be((int)HttpStatusCode.OK);
            var model = result.Value as IEnumerable <CreateEpaResponse>;

            model.Should().BeEquivalentTo(response);
        }
        public async Task CreateEpaRecordsExample()
        {
            long     uln               = 1234567890;
            string   firstName         = "Fred";
            string   lastName          = "Blogs";
            int      standardCode      = 1;
            string   standardReference = "ST0127";
            string   epaOutcome        = "Fail";
            DateTime epaDate           = DateTime.UtcNow;

            CreateEpaRequest newEpa = new CreateEpaRequest
            {
                Learner = new Learner {
                    Uln = uln, GivenNames = firstName, FamilyName = lastName
                },
                Standard = new Standard {
                    StandardCode = standardCode, StandardReference = standardReference
                },
                EpaDetails = new EpaDetails {
                    Epas = new List <EpaRecord> {
                        new EpaRecord {
                            EpaOutcome = epaOutcome, EpaDate = epaDate
                        }
                    }
                }
            };

            if (newEpa.IsValid(out _))
            {
                // NOTE: The External API performs validation, however it is a good idea to check beforehand
                await _EpaApiClient.CreateEpaRecords(new List <CreateEpaRequest> {
                    newEpa
                });
            }
        }
        public async Task CreateEpaRecord_EpaExists()
        {
            // arrange
            var learner = Builder <Models.Certificates.Learner> .CreateNew().Build();

            var standard = Builder <Models.Certificates.Standard> .CreateNew().Build();

            var epaRecord = Builder <EpaRecord> .CreateNew().With(er => er.EpaOutcome = "Pass").Build();

            var epaDetails = Builder <EpaDetails> .CreateNew().With(ed => ed.Epas = new List <EpaRecord> {
                epaRecord
            }).Build();

            var epaRequest = new CreateEpaRequest
            {
                Learner    = learner,
                Standard   = standard,
                EpaDetails = epaDetails
            };

            var expectedValidationErrors = new List <string> {
                "EPA already provided for the learner"
            };

            var expectedResponse = new List <CreateEpaResponse>
            {
                new CreateEpaResponse {
                    EpaReference = null, ValidationErrors = expectedValidationErrors
                }
            };

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

            // act
            var actual = await _ApiClient.CreateEpaRecords(new List <CreateEpaRequest> {
                epaRequest
            });

            // assert
            Assert.That(actual, Has.Count.EqualTo(1));
            Assert.That(actual.First().ValidationErrors, Is.EqualTo(expectedResponse.First().ValidationErrors));
            Assert.That(actual.First().EpaReference, Is.Null);
        }
Exemplo n.º 4
0
        public async Task When_CreatingEpaRecord_WithTooManyRequestsInBatch_CallsInternalApi_Then_ReturnApiResponseWithResponseCode403(
            CreateEpaRequest request,
            EpaController sut)
        {
            //Arrange
            var requests = new List <CreateEpaRequest>();

            for (var i = 0; i < 26; i++)
            {
                requests.Add(request);
            }

            //Act
            var result = await sut.CreateEpaRecords(requests) as ObjectResult;

            //Assert
            result.StatusCode.Should().Be((int)HttpStatusCode.Forbidden);
            ((ApiResponse)result.Value).Message.Should().Be("Batch limited to 25 requests");
        }