public void AndCertificateNotFound_ThrowsNotFound(
            DeleteBatchEpaRequest request)
        {
            //Arrange
            _mockCertificateRepository.Setup(s => s.GetCertificate(request.Uln, request.StandardCode)).ReturnsAsync((Certificate)null);

            //Act
            Func <Task> act = async() => { await _sut.Handle(request, new CancellationToken()); };

            //Assert
            act.Should().Throw <NotFoundException>();
        }
Beispiel #2
0
        public async Task WhenCallingDeleteEpa_EPANotFound_ReturnsNotFound(
            Standard standard,
            DeleteBatchEpaRequest request)
        {
            //Arrange
            _mockMediator.Setup(s => s.Send(It.IsAny <GetStandardVersionRequest>(), new System.Threading.CancellationToken())).ReturnsAsync(standard);
            _mockDeleteBatchValidator.Setup(s => s.ValidateAsync(It.IsAny <DeleteBatchEpaRequest>(), new System.Threading.CancellationToken())).ReturnsAsync(new ValidationResult());
            _mockMediator.Setup(a => a.Send(It.IsAny <DeleteBatchEpaRequest>(), new System.Threading.CancellationToken())).Throws <NotFoundException>();

            //Act
            var controllerResult = await _epaBatchController.Delete(request.Uln, request.FamilyName, request.StandardReference, request.EpaReference, request.UkPrn) as NotFoundResult;

            //Assert
            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.NotFound);
        }
Beispiel #3
0
        public async Task <IActionResult> DeleteEpaRecord(long uln, string familyName, [SwaggerParameter("Standard Code or Standard Reference Number")] string standard, string epaReference)
        {
            var deleteRequest = new DeleteBatchEpaRequest {
                UkPrn = _headerInfo.Ukprn, Uln = uln, FamilyName = familyName, Standard = standard, EpaReference = epaReference
            };
            var error = await _apiClient.DeleteEpa(deleteRequest);

            if (error is null)
            {
                return(NoContent());
            }
            else
            {
                return(StatusCode(error.StatusCode, error));
            }
        }
Beispiel #4
0
        public override async Task <ApiResponse> DeleteEpa(DeleteBatchEpaRequest request)
        {
            if (request != null)
            {
                _logger.LogInformation($"DeleteEpa called with request: {JsonConvert.SerializeObject(request)}");
                var details = await GetLearnerDetail(request.Standard, request.Uln);

                if (details != null)
                {
                    request.Standard = details.Standard?.ReferenceNumber ?? details.Standard?.StandardId.ToString();
                    request.UkPrn    = details.UkPrn;
                }
            }

            var response = await base.DeleteEpa(request);

            _logger.LogInformation($"DeleteEpa returned with response: {JsonConvert.SerializeObject(response)}");
            return(response);
        }
        public async Task <IActionResult> Delete(long uln, string lastname, string standard, string epaReference, int ukPrn)
        {
            var request = new DeleteBatchEpaRequest
            {
                Uln          = uln,
                FamilyName   = lastname,
                EpaReference = epaReference,
                UkPrn        = ukPrn
            };

            var collatedStandard = int.TryParse(standard, out int standardCode) ? await GetCollatedStandard(standardCode) : await GetCollatedStandard(standard);

            if (collatedStandard != null)
            {
                request.StandardCode      = collatedStandard.StandardId ?? int.MinValue;
                request.StandardReference = collatedStandard.ReferenceNumber;
            }

            var validationResult = await _deleteValidator.ValidateAsync(request);

            var isRequestValid   = validationResult.IsValid;
            var validationErrors = validationResult.Errors.Select(error => error.ErrorMessage).ToList();

            if (!validationErrors.Any() && isRequestValid)
            {
                try
                {
                    await _mediator.Send(request);

                    return(NoContent());
                }
                catch (NotFound)
                {
                    return(NotFound());
                }
            }
            else
            {
                ApiResponse response = new ApiResponse((int)HttpStatusCode.Forbidden, string.Join("; ", validationErrors));
                return(StatusCode(response.StatusCode, response));
            }
        }
Beispiel #6
0
        public async Task <IActionResult> Delete(long uln, string lastname, string standard, string epaReference, int ukPrn)
        {
            var request = new DeleteBatchEpaRequest
            {
                Uln          = uln,
                FamilyName   = lastname,
                EpaReference = epaReference,
                UkPrn        = ukPrn
            };

            var standardVersion = await _mediator.Send(new GetStandardVersionRequest { StandardId = standard });

            if (standardVersion != null)
            {
                request.StandardCode      = standardVersion.LarsCode;
                request.StandardReference = standardVersion.IfateReferenceNumber;
            }

            var validationResult = await _deleteValidator.ValidateAsync(request);

            var isRequestValid   = validationResult.IsValid;
            var validationErrors = validationResult.Errors.Select(error => error.ErrorMessage).ToList();

            if (!validationErrors.Any() && isRequestValid)
            {
                try
                {
                    await _mediator.Send(request);

                    return(NoContent());
                }
                catch (NotFoundException)
                {
                    return(NotFound());
                }
            }
            else
            {
                ApiResponse response = new ApiResponse((int)HttpStatusCode.Forbidden, string.Join("; ", validationErrors));
                return(StatusCode(response.StatusCode, response));
            }
        }
        public async Task AndCertificateFound_DeletesEPARecordInformation_And_DeletesCertificate(
            DeleteBatchEpaRequest request,
            CertificateData certificateData,
            Certificate certificate)
        {
            //Arrange
            certificate.CertificateData = JsonConvert.SerializeObject(certificateData);
            _mockCertificateRepository.Setup(s => s.GetCertificate(request.Uln, request.StandardCode)).ReturnsAsync(certificate);
            var certificateAction = CertificateActions.Epa;

            //Act
            var result = await _sut.Handle(request, new CancellationToken());

            //Assert
            _mockCertificateRepository.Verify(s => s.Update(It.IsAny <Certificate>(), "API", certificateAction, true, null), Times.Once);
            var modifiedCertificateData = JsonConvert.DeserializeObject <CertificateData>(certificate.CertificateData);

            modifiedCertificateData.EpaDetails.Should().BeEquivalentTo(new EpaDetails {
                Epas = new System.Collections.Generic.List <EpaRecord>()
            });

            _mockCertificateRepository.Verify(v => v.Delete(request.Uln, request.StandardCode, "API", CertificateActions.Delete, true, null, null));
        }
Beispiel #8
0
        public async Task WhenCallingDeleteEpa_WithNoValidationError_SendsDeleteRequest(
            Standard standard,
            DeleteBatchEpaRequest request)
        {
            //Arrange
            request.StandardCode = 0;
            _mockMediator.Setup(s => s.Send(It.IsAny <GetStandardVersionRequest>(), new System.Threading.CancellationToken())).ReturnsAsync(standard);
            _mockDeleteBatchValidator.Setup(s => s.ValidateAsync(It.IsAny <DeleteBatchEpaRequest>(), new System.Threading.CancellationToken())).ReturnsAsync(new ValidationResult());

            //Act
            var controllerResult = await _epaBatchController.Delete(request.Uln, request.FamilyName, request.StandardReference, request.EpaReference, request.UkPrn) as NoContentResult;

            //Assert
            _mockMediator.Verify(a => a.Send(It.Is <GetStandardVersionRequest>(b => b.StandardId == request.StandardReference && b.Version == null), new System.Threading.CancellationToken()), Times.Once);
            _mockMediator.Verify(a => a.Send(It.Is <DeleteBatchEpaRequest>(b =>
                                                                           b.StandardCode == standard.LarsCode &&
                                                                           b.StandardReference == standard.IfateReferenceNumber &&
                                                                           b.UkPrn == request.UkPrn &&
                                                                           b.Uln == request.Uln &&
                                                                           b.EpaReference == request.EpaReference &&
                                                                           b.FamilyName == request.FamilyName), new System.Threading.CancellationToken()), Times.Once);

            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.NoContent);
        }
Beispiel #9
0
        public virtual async Task <ApiResponse> DeleteEpa(DeleteBatchEpaRequest request)
        {
            var apiResponse = await Delete <ApiResponse>($"/api/v1/epas/batch/{request.Uln}/{request.FamilyName}/{request.Standard}/{request.EpaReference}/{request.UkPrn}");

            return(apiResponse);
        }