public void Feature_not_enabled_returns_is_valid_true() { var mockFeature = new Mock <IAllowedPostcodeFeature>(); mockFeature.Setup(f => f.IsEnabled).Returns(false); var sut = new PostCodeAllowedValidator(mockFeature.Object); Assert.IsTrue(sut.IsAllowedPostcode("SO30 2UN")); }
public void Feature_enabled_empty_postcode_list_returns_false() { var mockFeature = new Mock <IAllowedPostcodeFeature>(); mockFeature.Setup(f => f.IsEnabled).Returns(true); SetupMockCCGResultWithoutValidPostcode(); var sut = new PostCodeAllowedValidator(mockFeature.Object, mockCCGBuilder.Object); Assert.AreEqual(PostcodeValidatorResponse.PostcodeNotFound, sut.IsAllowedPostcode("SO30 2UN")); }
public void Feature_not_enabled_returns_is_valid_true() { var mockFeature = new Mock <IAllowedPostcodeFeature>(); mockFeature.Setup(f => f.IsEnabled).Returns(false); SetupMockCCGResultWithApp(); var sut = new PostCodeAllowedValidator(mockFeature.Object, mockCCGBuilder.Object); Assert.AreEqual(PostcodeValidatorResponse.InPathwaysArea, sut.IsAllowedPostcode("SO30 2UN")); }
public void Feature_enabled_missing_file_path_returns_false() { var mockFeature = new Mock <IAllowedPostcodeFeature>(); mockFeature.Setup(f => f.IsEnabled).Returns(true); SetupMockCCGResultWithoutApp(); var sut = new PostCodeAllowedValidator(mockFeature.Object, mockCCGBuilder.Object); Assert.AreEqual(PostcodeValidatorResponse.OutsidePathwaysArea, sut.IsAllowedPostcode("SO30 2UN")); }
public void Feature_enabled_missing_file_path_returns_false() { var mockFeature = new Mock <IAllowedPostcodeFeature>(); mockFeature.Setup(f => f.IsEnabled).Returns(true); mockFeature.Setup(f => f.PostcodeFile).Returns((TextReader.Null)); var sut = new PostCodeAllowedValidator(mockFeature.Object); Assert.IsFalse(sut.IsAllowedPostcode("SO30 2UN")); }
public async Task <ActionResult> ServiceDetails([Bind(Prefix = "FindService")] OutcomeViewModel model, [FromUri] bool?overrideFilterServices, DosEndpoint?endpoint) { if (!ModelState.IsValidField("FindService.CurrentPostcode")) { return(View(model.CurrentView, model)); } var postcodeValidator = await PostCodeAllowedValidator.IsAllowedPostcodeAsync(model.CurrentPostcode).ConfigureAwait(false); if (postcodeValidator == PostcodeValidatorResponse.InvalidSyntax) { ModelState.AddModelError("FindService.CurrentPostcode", "Enter a valid postcode."); return(View(model.CurrentView, model)); } if (!postcodeValidator.IsInAreaForOutcome()) { ModelState.AddModelError("FindService.CurrentPostcode", "Sorry, this service is not currently available in your area. Please call NHS 111 for advice now"); return(View(model.CurrentView, model)); } var dosCase = Mapper.Map <DosViewModel>(model); _auditLogger.LogDosRequest(model, dosCase); var modelFilterServices = overrideFilterServices.HasValue ? overrideFilterServices.Value : model.FilterServices; model.DosCheckCapacitySummaryResult = await _dosBuilder.FillCheckCapacitySummaryResult(dosCase, modelFilterServices, endpoint).ConfigureAwait(false); _auditLogger.LogDosResponse(model, model.DosCheckCapacitySummaryResult); if (model.DosCheckCapacitySummaryResult.Error == null && !model.DosCheckCapacitySummaryResult.ResultListEmpty) { model.GroupedDosServices = _dosBuilder.FillGroupedDosServices(model.DosCheckCapacitySummaryResult.Success.Services); model = await _outcomeViewModelBuilder.ServiceDetailsBuilder(model).ConfigureAwait(false);; if (model.OutcomeGroup.IsAutomaticSelectionOfItkResult()) { AutoSelectFirstItkService(model); if (model.SelectedService != null) { var personalDetailsController = DependencyResolver.Current.GetService <PersonalDetailsController>(); personalDetailsController.ControllerContext = new ControllerContext(ControllerContext.RequestContext, personalDetailsController); return(await personalDetailsController.PersonalDetails(Mapper.Map <PersonalDetailViewModel>(model)) .ConfigureAwait(false)); } } return(View("~\\Views\\Outcome\\ServiceDetails.cshtml", model)); //explicit path to view because, when direct-linking, the route is no longer /outcome causing convention based view lookup to fail } return(View(model.CurrentView, model)); }
public void Feature_enabled_postcode_case_insensitive_returns_true() { var mockPostcodeList = new[] { "Postcode", "SO30 2UN" }; var mockFeature = new Mock <IAllowedPostcodeFeature>(); mockFeature.Setup(f => f.IsEnabled).Returns(true); mockFeature.Setup(f => f.PostcodeFile).Returns(new StringReader(string.Join(Environment.NewLine, mockPostcodeList))); var sut = new PostCodeAllowedValidator(mockFeature.Object); Assert.IsTrue(sut.IsAllowedPostcode("So30 2uN")); }
public void Feature_enabled_empty_postcode_list_returns_false() { var mockPostcodeList = @"Postcode"; var mockFeature = new Mock <IAllowedPostcodeFeature>(); mockFeature.Setup(f => f.IsEnabled).Returns(true); mockFeature.Setup(f => f.PostcodeFile).Returns(new StringReader(mockPostcodeList)); var sut = new PostCodeAllowedValidator(mockFeature.Object); Assert.IsFalse(sut.IsAllowedPostcode("SO30 2UN")); }
public void Feature_enabled_allowed_postcode_space_returns_true() { var mockPostcodeList = new[] { "Postcode", "SO30 2UN" }; SetupMockCCGResultWithApp(); var mockFeature = new Mock <IAllowedPostcodeFeature>(); mockFeature.Setup(f => f.IsEnabled).Returns(true); mockFeature.Setup(f => f.PostcodeFile).Returns(new StringReader(string.Join(Environment.NewLine, mockPostcodeList))); var sut = new PostCodeAllowedValidator(mockFeature.Object, mockCCGBuilder.Object); Assert.AreEqual(PostcodeValidatorResponse.InPathwaysArea, sut.IsAllowedPostcode("SO30 2UN")); }
public void EP_enabled_area_returns_pathway_with_pharmacy_area() { var mockPostcodeList = new[] { "Postcode", "SO30 2UN" }; mockCCGBuilder.Setup(f => f.FillCCGDetailsModelAsync(It.IsAny <string>())).ReturnsAsync(new CCGDetailsModel() { App = "Pathways", Postcode = "TS19 7TG", PharmacyReferralServiceIdWhitelist = new ServiceListModel("123|456") }); var mockFeature = new Mock <IAllowedPostcodeFeature>(); mockFeature.Setup(f => f.IsEnabled).Returns(true); mockFeature.Setup(f => f.PostcodeFile).Returns(new StringReader(string.Join(Environment.NewLine, mockPostcodeList))); var sut = new PostCodeAllowedValidator(mockFeature.Object, mockCCGBuilder.Object); Assert.AreEqual(PostcodeValidatorResponse.InPathwaysAreaWithPharmacyServices, sut.IsAllowedPostcode("So30 2uN")); }
public async Task <ActionResult> DispositionWithServices(OutcomeViewModel model, string submitAction, DosEndpoint?endpoint = null, DateTime?dosSearchTime = null) { ModelState.Clear(); if (submitAction == "manualpostcode") { return(View("../Outcome/ChangePostcode", model)); } var postcodeValidatorResponse = PostCodeAllowedValidator.IsAllowedPostcode(model.CurrentPostcode); if (postcodeValidatorResponse == PostcodeValidatorResponse.InvalidSyntax) { ModelState.AddModelError("CurrentPostcode", "Enter a valid postcode."); return(View("../Outcome/ChangePostcode", model)); } if (postcodeValidatorResponse == PostcodeValidatorResponse.PostcodeNotFound) { ModelState.AddModelError("CurrentPostcode", "We can't find any services in '" + model.CurrentPostcode + "'. Check the postcode is correct."); return(View("../Outcome/ChangePostcode", model)); } model = PopulateCCGAndStp(model); if (postcodeValidatorResponse == PostcodeValidatorResponse.PostcodeNotFound) { if (model.IsEmergencyPrescriptionOutcome) { return(View("../Pathway/EmergencyPrescriptionsOutOfArea", model)); } return(View("../Outcome/OutOfArea", model)); } var outcomeModel = await _outcomeViewModelBuilder.PopulateGroupedDosResults(model, dosSearchTime, null, endpoint).ConfigureAwait(false); var viewRouter = _viewRouter.Build(outcomeModel, ControllerContext); return(View(viewRouter.ViewName, outcomeModel)); }
public async Task <ActionResult> ServiceList([Bind(Prefix = "FindService")] OutcomeViewModel model, [FromUri] DateTime?overrideDate, [FromUri] bool?overrideFilterServices, DosEndpoint?endpoint) { // Set model.OutcomePage to "Other ways to get help" page so that survey link can be created correctly model.OutcomePage = OutcomePage.OtherServices; var reason = Request.Form["reason"]; _auditLogger.LogPrimaryCareReason(model, reason); if (Request.Form["OtherServices"] != null) { _auditLogger.LogPrimaryCareReason(model, "Patient clicked other things you can do"); } if (!ModelState.IsValidField("FindService.CurrentPostcode")) { return(View(model.CurrentView, model)); } var postcodeValidatorResponse = await PostCodeAllowedValidator.IsAllowedPostcodeAsync(model.CurrentPostcode).ConfigureAwait(false); if (!postcodeValidatorResponse.IsInAreaForOutcome()) { ModelState.AddModelError("FindService.CurrentPostcode", "Sorry, this service is not currently available in your area. Please call NHS 111 for advice now"); return(View(model.CurrentView, model)); } var modelFilterServices = overrideFilterServices.HasValue ? overrideFilterServices.Value : model.FilterServices; //need to capture this value and reapply now we have other services option for Serivce first var isValidationRequery = model.DosCheckCapacitySummaryResult.IsValidationRequery; model.DosCheckCapacitySummaryResult = await GetServiceAvailability(model, overrideDate, modelFilterServices, endpoint).ConfigureAwait(false); model.DosCheckCapacitySummaryResult.IsValidationRequery = isValidationRequery; _auditLogger.LogDosResponse(model, model.DosCheckCapacitySummaryResult); model.NodeType = NodeType.Outcome; if (model.DosCheckCapacitySummaryResult.Error == null && !model.DosCheckCapacitySummaryResult.ResultListEmpty) { if (model.OutcomeGroup.Is999NonUrgent && !model.DosCheckCapacitySummaryResult.HasITKServices) { model.CurrentView = _viewRouter.Build(model, this.ControllerContext).ViewName; return(View(model.CurrentView, model)); } model.GroupedDosServices = _dosBuilder.FillGroupedDosServices(model.DosCheckCapacitySummaryResult.Success.Services); model = await _outcomeViewModelBuilder.PrimaryCareBuilder(model, reason).ConfigureAwait(false); if (model.OutcomeGroup.IsAutomaticSelectionOfItkResult()) { AutoSelectFirstItkService(model); if (model.SelectedService != null) { var personalDetailsController = DependencyResolver.Current.GetService <PersonalDetailsController>(); personalDetailsController.ControllerContext = new ControllerContext(ControllerContext.RequestContext, personalDetailsController); return(await personalDetailsController.PersonalDetails(Mapper.Map <PersonalDetailViewModel>(model)).ConfigureAwait(false)); } } if (model.OutcomeGroup.IsServiceFirst || model.OutcomeGroup.IsPrimaryCare || model.OutcomeGroup.IsPharmacy || model.OutcomeGroup.IsAccidentAndEmergencySexualAssault) { var otherServices = await _recommendedServiceBuilder.BuildRecommendedServicesList(model.DosCheckCapacitySummaryResult.Success.Services).ConfigureAwait(false); var otherServicesModel = Mapper.Map <OtherServicesViewModel>(model); //Somehow got here despite only 1 service (refresh after service close) so go back to recommendedservice page. if (otherServices.Count() == 1 && model.OutcomeGroup.IsServiceFirst) { otherServicesModel.RecommendedService = otherServices.First(); return(RecommendedService(otherServicesModel)); } //Very weird mapper issue ignoring this property for some reason //unit test specifically testing this passes fine so can really fathow what is going on //forcing it instead if (otherServicesModel.RecommendedService != null) { otherServicesModel.RecommendedService.ReasonText = model.RecommendedService.ReasonText; otherServicesModel.OtherServices = otherServices.Skip(1); } else { otherServicesModel.OtherServices = otherServices; } if (model.OutcomeGroup.IsPharmacy) { var serviceTypeOffered = otherServices.GetServiceTypeOffered(); _auditLogger.LogEvent(otherServicesModel, EventType.CallbackServiceTypeOffered, serviceTypeOffered.ToString(), "~\\Views\\Outcome\\ServiceList.cshtml"); } return(View("~\\Views\\Outcome\\Service_First\\OtherServices.cshtml", otherServicesModel)); } return(View("~\\Views\\Outcome\\ServiceList.cshtml", model)); } if (model.OutcomeGroup.Is999NonUrgent) { model.CurrentView = _viewRouter.Build(model, this.ControllerContext).ViewName; } return(View(model.OutcomeGroup.IsServiceFirst ? string.Format("~\\Views\\Outcome\\Service_First\\{0}\\ServiceNotOffered.cshtml", model.ServiceGroup.Id) : model.CurrentView, model)); }