public async Task <IActionResult> SearchRegistrationAsync(SearchRegistrationViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var searchResult = await _registrationLoader.FindUlnAsync(User.GetUkPrn(), model.SearchUln.ToLong());

            if (searchResult?.IsAllowed == true)
            {
                return(RedirectToRoute(RouteConstants.RegistrationDetails, new { profileId = searchResult.RegistrationProfileId }));
            }
            else
            {
                await _cacheService.SetAsync(Constants.RegistrationSearchCriteria, model.SearchUln);

                var ulnNotfoundModel = new UlnRegistrationNotFoundViewModel {
                    Uln = model.SearchUln.ToString(), BackLinkRouteName = RouteConstants.SearchRegistration
                };
                await _cacheService.SetAsync(string.Concat(CacheKey, Constants.SearchRegistrationUlnNotFound), ulnNotfoundModel, CacheExpiryTime.XSmall);

                return(RedirectToRoute(RouteConstants.SearchRegistrationNotFound));
            }
        }
Esempio n. 2
0
        public override void Setup()
        {
            HttpContextAccessor = Substitute.For <IHttpContextAccessor>();
            RegistrationLoader  = Substitute.For <IRegistrationLoader>();
            CacheService        = Substitute.For <ICacheService>();
            Logger     = Substitute.For <ILogger <RegistrationController> >();
            Controller = new RegistrationController(RegistrationLoader, CacheService, Logger);

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

            HttpContextAccessor.HttpContext.Returns(httpContext);
            TempData            = new TempDataDictionary(HttpContextAccessor.HttpContext, Substitute.For <ITempDataProvider>());
            Controller.TempData = TempData;

            var ulnRegistrationNotFoundViewModel = new UlnRegistrationNotFoundViewModel {
                Uln = SearchUln, IsAllowed = false
            };

            RegistrationLoader.FindUlnAsync(AoUkprn, SearchUln.ToLong()).Returns(ulnRegistrationNotFoundViewModel);
        }
        public override void Given()
        {
            SearchRegistrationViewModel = new SearchRegistrationViewModel {
                SearchUln = SearchUln
            };
            var mockResult = new UlnRegistrationNotFoundViewModel {
                IsAllowed = true, Uln = SearchUln
            };

            RegistrationLoader.FindUlnAsync(AoUkprn, SearchUln.ToLong()).Returns(mockResult);
        }
        public override void Given()
        {
            var findUln = new UlnRegistrationNotFoundViewModel
            {
                IsAllowed = true
            };

            UlnViewModel = new UlnViewModel {
                Uln = "1234567890"
            };
            RegistrationLoader.FindUlnAsync(Arg.Any <long>(), Arg.Any <long>()).Returns(findUln);
        }
Esempio n. 5
0
 public async override Task When()
 {
     ActualResult = await Loader.FindUlnAsync(Ukprn, Uln);
 }
Esempio n. 6
0
 public override void Given()
 {
     expectedViewModel = new UlnRegistrationNotFoundViewModel();
     CacheService.GetAndRemoveAsync <UlnRegistrationNotFoundViewModel>(Arg.Any <string>()).Returns(expectedViewModel);
 }