示例#1
0
        public override void Given()
        {
            var lookupApiClientResponse = new List <LookupData> {
                new LookupData {
                    Id = 1, Code = "PCG1", Value = "A*"
                }
            };

            ViewModel = new ManageCoreResultViewModel
            {
                ProfileId         = ProfileId,
                ResultId          = 1,
                SelectedGradeCode = string.Empty
            };


            ExpectedApiResult = new ChangeResultResponse {
                IsSuccess = true, Uln = 1234567890, ProfileId = ProfileId
            };

            InternalApiClient.GetLookupDataAsync(LookupCategory.PathwayComponentGrade).Returns(lookupApiClientResponse);

            InternalApiClient
            .ChangeResultAsync(Arg.Is <ChangeResultRequest>(
                                   x => x.ProfileId == ViewModel.ProfileId &&
                                   x.AoUkprn == AoUkprn &&
                                   x.ResultId == ViewModel.ResultId &&
                                   x.ComponentType == ComponentType.Core &&
                                   x.LookupId == ViewModel.LookupId))
            .Returns(ExpectedApiResult);
        }
        public override void Setup()
        {
            HttpContextAccessor = Substitute.For <IHttpContextAccessor>();
            ResultLoader        = Substitute.For <IResultLoader>();
            CacheService        = Substitute.For <ICacheService>();
            Logger     = Substitute.For <ILogger <ResultController> >();
            Controller = new ResultController(ResultLoader, CacheService, Logger);

            AoUkprn = 1234567890;

            ViewModel = new ManageCoreResultViewModel
            {
                ProfileId         = 1,
                ResultId          = 11,
                SelectedGradeCode = "PCG1"
            };

            var httpContext = new ClaimsIdentityBuilder <ResultController>(Controller)
                              .Add(CustomClaimTypes.Ukprn, AoUkprn.ToString())
                              .Add(CustomClaimTypes.UserId, Guid.NewGuid().ToString())
                              .Build()
                              .HttpContext;

            HttpContextAccessor.HttpContext.Returns(httpContext);
            CacheKey   = CacheKeyHelper.GetCacheKey(httpContext.User.GetUserId(), CacheConstants.ResultCacheKey);
            MockResult = new ChangeResultResponse();
        }
        public override void Given()
        {
            grades = new List <LookupViewModel> {
                new LookupViewModel {
                    Id = 1, Code = "C1", Value = "V1"
                }, new LookupViewModel {
                    Id = 2, Code = "C2", Value = "V2"
                }
            };
            mockresult = new ManageCoreResultViewModel
            {
                ProfileId          = 1,
                PathwayDisplayName = "Pathway (7654321)",
                AssessmentSeries   = "Summer 2021",
                AssessmentId       = 11,
                ResultId           = 111,
                SelectedGradeCode  = string.Empty,
                Grades             = grades
            };

            _routeAttributes = new Dictionary <string, string> {
                { Constants.ProfileId, ProfileId.ToString() }
            };
            ResultLoader.GetManageCoreResultAsync(AoUkprn, ProfileId, AssessmentId, true).Returns(mockresult);
        }
        public async Task <IActionResult> ChangeCoreResultAsync(ManageCoreResultViewModel model)
        {
            var isResultChanged = await _resultLoader.IsCoreResultChangedAsync(User.GetUkPrn(), model);

            if (!isResultChanged.HasValue)
            {
                _logger.LogWarning(LogEvent.NoDataFound, $"ChangeCoreResult request data-mismatch. Method:IsCoreResultChanged({User.GetUkPrn()}, {model}), ProfileId: {model.ProfileId}, ResultId: {model.ResultId}");
                return(RedirectToRoute(RouteConstants.PageNotFound));
            }

            if (isResultChanged == false)
            {
                return(RedirectToRoute(RouteConstants.ResultDetails, new { profileId = model.ProfileId }));
            }

            var response = await _resultLoader.ChangeCoreResultAsync(User.GetUkPrn(), model);

            if (response == null || !response.IsSuccess)
            {
                return(RedirectToRoute(RouteConstants.ProblemWithService));
            }

            await _cacheService.SetAsync(string.Concat(CacheKey, Constants.ChangeResultConfirmationViewModel), new ResultConfirmationViewModel { Uln = response.Uln, ProfileId = response.ProfileId }, CacheExpiryTime.XSmall);

            return(RedirectToRoute(RouteConstants.ChangeResultConfirmation));
        }
示例#5
0
        public async Task <bool?> IsCoreResultChangedAsync(long aoUkprn, ManageCoreResultViewModel viewModel)
        {
            var existingResult = await _internalApiClient.GetResultDetailsAsync(aoUkprn, viewModel.ProfileId, RegistrationPathwayStatus.Active);

            if (existingResult == null || existingResult.PathwayResultId != viewModel.ResultId)
            {
                return(null);
            }

            var isResultChanged = !existingResult.PathwayResultCode.Equals(viewModel.SelectedGradeCode, StringComparison.InvariantCultureIgnoreCase);

            return(isResultChanged);
        }
示例#6
0
        public async Task <AddResultResponse> AddCoreResultAsync(long aoUkprn, ManageCoreResultViewModel viewModel)
        {
            var grades = await _internalApiClient.GetLookupDataAsync(LookupCategory.PathwayComponentGrade);

            var selectedGrade = grades?.FirstOrDefault(x => x.Code.Equals(viewModel.SelectedGradeCode, StringComparison.InvariantCultureIgnoreCase));

            if (selectedGrade == null)
            {
                return(null);
            }

            viewModel.LookupId = selectedGrade.Id;
            var request = _mapper.Map <AddResultRequest>(viewModel, opt => opt.Items["aoUkprn"] = aoUkprn);

            return(await _internalApiClient.AddResultAsync(request));
        }
        public override void Given()
        {
            ViewModel = new ManageCoreResultViewModel
            {
                ProfileId         = 1,
                SelectedGradeCode = "PCG1"
            };

            AddResultResponse = new AddResultResponse
            {
                IsSuccess = true,
                Uln       = 1234567890,
                ProfileId = 1
            };

            ResultLoader.AddCoreResultAsync(AoUkprn, ViewModel).Returns(AddResultResponse);
        }
        public async Task <IActionResult> AddCoreResultAsync(ManageCoreResultViewModel model)
        {
            if (string.IsNullOrWhiteSpace(model?.SelectedGradeCode))
            {
                return(RedirectToRoute(RouteConstants.ResultDetails, new { profileId = model.ProfileId }));
            }

            var response = await _resultLoader.AddCoreResultAsync(User.GetUkPrn(), model);

            if (response == null || !response.IsSuccess)
            {
                return(RedirectToRoute(RouteConstants.ProblemWithService));
            }

            await _cacheService.SetAsync(string.Concat(CacheKey, Constants.ResultConfirmationViewModel), new ResultConfirmationViewModel { Uln = response.Uln, ProfileId = response.ProfileId }, CacheExpiryTime.XSmall);

            return(RedirectToRoute(RouteConstants.AddResultConfirmation));
        }
        public override void Given()
        {
            ViewModel = new ManageCoreResultViewModel
            {
                ProfileId         = 1,
                ResultId          = 1,
                Uln               = 1234567890,
                SelectedGradeCode = "PCG1"
            };

            ChangeResultResponse = new ChangeResultResponse
            {
                IsSuccess = true,
                Uln       = 1234567890,
                ProfileId = 1
            };

            ResultLoader.IsCoreResultChangedAsync(AoUkprn, ViewModel).Returns(true);
            ResultLoader.ChangeCoreResultAsync(AoUkprn, ViewModel).Returns(ChangeResultResponse);
        }
        public void Then_Returns_Expected_Results()
        {
            var viewModel = new ManageCoreResultViewModel
            {
                ProfileId         = ProfileId,
                AssessmentId      = 1,
                SelectedGradeCode = "PCG1",
                LookupId          = 1
            };

            var result = Mapper.Map <AddResultRequest>(viewModel, opt => opt.Items["aoUkprn"] = AoUkprn);

            result.Should().NotBeNull();
            result.AoUkprn.Should().Be(AoUkprn);
            result.ProfileId.Should().Be(viewModel.ProfileId);
            result.AssessmentId.Should().Be(viewModel.AssessmentId);
            result.LookupId.Should().Be(viewModel.LookupId);
            result.ComponentType.Should().Be(ComponentType.Core);
            result.PerformedBy.Should().Be($"{Givenname} {Surname}");
        }
 public async override Task When()
 {
     ActualResult = await Loader.GetManageCoreResultAsync(AoUkprn, ProfileId, AssessmentId, IsChangeMode);
 }