public override void Given() { BulkResultResponse = new BulkResultResponse { IsSuccess = true, Stats = new BulkUploadStats { TotalRecordsCount = 10 } }; UploadResultsRequestViewModel = new UploadResultsRequestViewModel { AoUkprn = Ukprn, File = FormFile }; UploadResultsResponseViewModel = new UploadResultsResponseViewModel { IsSuccess = true, Stats = new BulkUploadStatsViewModel { TotalRecordsCount = 10 } }; Mapper.Map <BulkProcessRequest>(UploadResultsRequestViewModel).Returns(BulkResultRequest); Mapper.Map <UploadResultsResponseViewModel>(BulkResultResponse).Returns(UploadResultsResponseViewModel); InternalApiClient.ProcessBulkResultsAsync(BulkResultRequest).Returns(BulkResultResponse); Loader = new ResultLoader(Mapper, Logger, InternalApiClient, BlobStorageService); }
public override void Given() { BulkResultResponse = new BulkResultResponse { IsSuccess = false, BlobUniqueReference = BlobUniqueReference, ErrorFileSize = 1.5 }; UploadResultsRequestViewModel = new UploadResultsRequestViewModel { AoUkprn = Ukprn, File = FormFile }; UploadResultsResponseViewModel = new UploadResultsResponseViewModel { IsSuccess = false, BlobUniqueReference = BlobUniqueReference, ErrorFileSize = 1.5 }; Mapper.Map <BulkProcessRequest>(UploadResultsRequestViewModel).Returns(BulkResultRequest); Mapper.Map <UploadResultsResponseViewModel>(BulkResultResponse).Returns(UploadResultsResponseViewModel); InternalApiClient.ProcessBulkResultsAsync(BulkResultRequest).Returns(BulkResultResponse); Loader = new ResultLoader(Mapper, Logger, InternalApiClient, BlobStorageService); }
public override void Given() { HttpContextAccessor = Substitute.For <IHttpContextAccessor>(); HttpContextAccessor.HttpContext.Returns(new DefaultHttpContext { User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.GivenName, _givename), new Claim(ClaimTypes.Surname, _surname), new Claim(ClaimTypes.Email, _email) })) }); CreateMapper(); BulkResultRequest = new BulkProcessRequest { AoUkprn = Ukprn }; BulkResultResponse = new BulkResultResponse { IsSuccess = true, Stats = new BulkUploadStats { TotalRecordsCount = 10 } }; UploadResultsRequestViewModel = new UploadResultsRequestViewModel { AoUkprn = Ukprn, File = FormFile }; InternalApiClient.ProcessBulkResultsAsync(BulkResultRequest).Returns(BulkResultResponse); Loader = new ResultLoader(Mapper, Logger, InternalApiClient, BlobStorageService); }
public override void Given() { HttpContextAccessor = Substitute.For <IHttpContextAccessor>(); HttpContextAccessor.HttpContext.Returns(new DefaultHttpContext { User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.GivenName, _givename), new Claim(ClaimTypes.Surname, _surname), new Claim(ClaimTypes.Email, _email) })) }); CreateMapper(); BulkResultRequest = new BulkProcessRequest { AoUkprn = Ukprn }; BulkResultResponse = new BulkResultResponse { IsSuccess = false, BlobUniqueReference = Guid.NewGuid(), ErrorFileSize = 1.5 }; UploadResultsRequestViewModel = new UploadResultsRequestViewModel { AoUkprn = Ukprn, File = FormFile }; InternalApiClient.ProcessBulkResultsAsync(BulkResultRequest).Returns(BulkResultResponse); Loader = new ResultLoader(Mapper, Logger, InternalApiClient, BlobStorageService); }
public IActionResult UploadResultsFile(int?requestErrorTypeId) { var model = new UploadResultsRequestViewModel { RequestErrorTypeId = requestErrorTypeId }; model.SetAnyModelErrors(ModelState); return(View(model)); }
public override void Setup() { Ukprn = 12345; HttpContextAccessor = Substitute.For <IHttpContextAccessor>(); ResultLoader = Substitute.For <IResultLoader>(); CacheService = Substitute.For <ICacheService>(); Logger = Substitute.For <ILogger <ResultController> >(); Controller = new ResultController(ResultLoader, CacheService, Logger); ViewModel = new UploadResultsRequestViewModel(); var httpContext = new ClaimsIdentityBuilder <ResultController>(Controller) .Add(CustomClaimTypes.Ukprn, Ukprn.ToString()) .Build() .HttpContext; HttpContextAccessor.HttpContext.Returns(httpContext); }
public async Task <UploadResultsResponseViewModel> ProcessBulkResultsAsync(UploadResultsRequestViewModel viewModel) { var bulkResultRequest = _mapper.Map <BulkProcessRequest>(viewModel); using (var fileStream = viewModel.File.OpenReadStream()) { await _blobStorageService.UploadFileAsync(new BlobStorageData { ContainerName = bulkResultRequest.DocumentType.ToString(), BlobFileName = bulkResultRequest.BlobFileName, SourceFilePath = $"{bulkResultRequest.AoUkprn}/{BulkProcessStatus.Processing}", FileStream = fileStream, UserName = bulkResultRequest.PerformedBy }); } var bulkResultResponse = await _internalApiClient.ProcessBulkResultsAsync(bulkResultRequest); return(_mapper.Map <UploadResultsResponseViewModel>(bulkResultResponse)); }
public async Task <IActionResult> UploadResultsFileAsync(UploadResultsRequestViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } viewModel.AoUkprn = User.GetUkPrn(); var response = await _resultLoader.ProcessBulkResultsAsync(viewModel); if (response.IsSuccess) { var successfulViewModel = new UploadSuccessfulViewModel { Stats = response.Stats }; await _cacheService.SetAsync(string.Concat(CacheKey, Constants.ResultsUploadSuccessfulViewModel), successfulViewModel, CacheExpiryTime.XSmall); return(RedirectToRoute(RouteConstants.ResultsUploadSuccessful)); } if (response.ShowProblemWithServicePage) { return(RedirectToRoute(RouteConstants.ProblemWithResultsUpload)); } var unsuccessfulViewModel = new UploadUnsuccessfulViewModel { BlobUniqueReference = response.BlobUniqueReference, FileSize = response.ErrorFileSize, FileType = FileType.Csv.ToString().ToUpperInvariant() }; await _cacheService.SetAsync(string.Concat(CacheKey, Constants.UploadUnsuccessfulViewModel), unsuccessfulViewModel, CacheExpiryTime.XSmall); return(RedirectToRoute(RouteConstants.ResultsUploadUnsuccessful)); }
public override void Setup() { ResultLoader = Substitute.For <IResultLoader>(); Controller = new ResultController(ResultLoader, CacheService, Logger); ViewModel = new UploadResultsRequestViewModel(); }