public void ShouldAssignLocalAuthorityCodeOnUpdatingVacancyLocationsWithMultipleAddresses() { // Arrange. var geopoint = new Fixture().Create <GeoPoint>(); var geopoint2 = new Fixture().Create <GeoPoint>(); var addressViewModel = new Fixture().Build <AddressViewModel>().Create(); var postalAddress = new Fixture().Build <PostalAddress>().With(a => a.GeoPoint, geopoint).Create(); var postalAddress2 = new Fixture().Build <PostalAddress>().With(a => a.GeoPoint, geopoint2).Create(); MockGeocodeService.Setup(gs => gs.GetGeoPointFor(It.IsAny <PostalAddress>())).Returns(geopoint); var locationSearchViewModel = new LocationSearchViewModel { EmployerId = EmployerId, ProviderSiteId = ProviderSiteId, EmployerEdsUrn = EdsUrn, Addresses = new List <VacancyLocationAddressViewModel> { new VacancyLocationAddressViewModel { Address = addressViewModel }, new VacancyLocationAddressViewModel { Address = addressViewModel } } }; var vacancyLocations = new List <VacancyLocation> { new VacancyLocation { Address = postalAddress }, new VacancyLocation { Address = postalAddress2 } }; MockMapper.Setup(m => m.Map <VacancyLocationAddressViewModel, VacancyLocation>(locationSearchViewModel.Addresses[0])).Returns(vacancyLocations[0]); MockMapper.Setup(m => m.Map <VacancyLocationAddressViewModel, VacancyLocation>(locationSearchViewModel.Addresses[1])).Returns(vacancyLocations[1]); MockVacancyPostingService.Setup(v => v.CreateVacancy(It.IsAny <Vacancy>())) .Returns(new Vacancy()); var vacancy = new Fixture().Create <Vacancy>(); MockVacancyPostingService.Setup(s => s.GetVacancyByReferenceNumber(It.IsAny <int>())) .Returns(vacancy); MockProviderService.Setup(s => s.GetProvider(Ukprn, true)).Returns(new Provider()); var provider = GetVacancyPostingProvider(); // Act. provider.AddLocations(locationSearchViewModel); // Assert. MockVacancyPostingService.Verify(m => m.UpdateVacancy(It.IsAny <Vacancy>()), Times.Once); MockLocalAuthorityLookupService.Verify(m => m.GetLocalAuthorityCode(It.IsAny <string>()), Times.Exactly(2)); MockVacancyPostingService.Verify(m => m.DeleteVacancyLocationsFor(vacancy.VacancyId)); MockVacancyPostingService.Verify(m => m.CreateVacancyLocations(It.IsAny <List <VacancyLocation> >()), Times.Once); }
public ActionResult ShowLocations(LocationSearchViewModel viewModel) { viewModel.Addresses = (List <VacancyLocationAddressViewModel>)TempData["AlreadyAddedLocations"]; ModelState.Clear(); return(View("Locations", viewModel)); }
private static LocationSearchViewModel GetLocationSearchViewModelWithOneLocationDifferentFromEmployerAddress(int vacancyReferenceNumber, int numberOfPositions) { var locationSearchViewModel = new LocationSearchViewModel { IsEmployerLocationMainApprenticeshipLocation = false, VacancyReferenceNumber = vacancyReferenceNumber, Addresses = new List <VacancyLocationAddressViewModel> { new VacancyLocationAddressViewModel { Address = new AddressViewModel { AddressLine4 = "address line 4 - 1", AddressLine3 = "address line 3 - 1", AddressLine2 = "address line 2 - 1", AddressLine1 = "address line 1 - 1", Postcode = "postcode", Uprn = "uprn" }, NumberOfPositions = numberOfPositions } } }; return(locationSearchViewModel); }
private void AddPostcodeSearchErrorToModelState(LocationSearchViewModel viewModel) { ModelState.AddModelError("PostcodeSearch", LocationSearchViewModelMessages.PostCodeSearch.ErrorText); //To work around an issue with MVC: SetModelValue must be called if AddModelError is called. ModelState.SetModelValue("PostcodeSearch", new ValueProviderResult(viewModel.PostcodeSearch ?? "", (viewModel.PostcodeSearch ?? ""), CultureInfo.CurrentCulture)); }
public void ShouldAssignLocalAuthorityCodeOnUpdatingVacancyLocationsWithSingleAddressDifferentToEmployer() { // Arrange. const string localAuthorityCode = "ABCD"; var geopoint = new Fixture().Create <GeoPoint>(); var addressViewModel = new Fixture().Build <AddressViewModel>().Create(); var postalAddress = new Fixture().Build <PostalAddress>().With(a => a.GeoPoint, geopoint).Create(); MockGeocodeService.Setup(gs => gs.GetGeoPointFor(It.IsAny <PostalAddress>())).Returns(geopoint); var locationSearchViewModel = new LocationSearchViewModel { EmployerId = EmployerId, ProviderSiteId = ProviderSiteId, EmployerEdsUrn = EdsUrn, Addresses = new List <VacancyLocationAddressViewModel>() { new VacancyLocationAddressViewModel() { Address = addressViewModel } } }; MockMapper.Setup( m => m.Map <VacancyLocationAddressViewModel, VacancyLocation>(It.IsAny <VacancyLocationAddressViewModel>())) .Returns(new VacancyLocation { Address = postalAddress }); MockMapper.Setup(m => m.Map <AddressViewModel, PostalAddress>(addressViewModel)).Returns(postalAddress); var geoPointViewModel = new Fixture().Create <GeoPointViewModel>(); MockMapper.Setup(m => m.Map <GeoPoint, GeoPointViewModel>(geopoint)) .Returns(geoPointViewModel); MockMapper.Setup(m => m.Map <GeoPointViewModel, GeoPoint>(geoPointViewModel)).Returns(geopoint); MockLocalAuthorityLookupService.Setup(m => m.GetLocalAuthorityCode(It.IsAny <string>())) .Returns(localAuthorityCode); var vacancy = new Fixture().Create <Vacancy>(); MockVacancyPostingService.Setup(s => s.GetVacancyByReferenceNumber(It.IsAny <int>())) .Returns(vacancy); MockProviderService.Setup(s => s.GetProvider(Ukprn, true)).Returns(new Provider()); var provider = GetVacancyPostingProvider(); // Act. provider.AddLocations(locationSearchViewModel); // Assert. MockLocalAuthorityLookupService.Verify(m => m.GetLocalAuthorityCode(It.IsAny <string>()), Times.Once); MockVacancyPostingService.Verify(m => m.UpdateVacancy(It.Is <Vacancy>(av => av.LocalAuthorityCode == localAuthorityCode))); MockVacancyPostingService.Verify(m => m.UpdateVacancy(It.IsAny <Vacancy>()), Times.Once); }
private static LocationSearchViewModel GetLocationSearchViewModel(string aNewAdditionalLocationInformation, string aNewAdditionalLocationInformationComment, int vacancyReferenceNumber, string aNewLocationAddressesComment) { var locationSearchViewModel = new LocationSearchViewModel { AdditionalLocationInformation = aNewAdditionalLocationInformation, AdditionalLocationInformationComment = aNewAdditionalLocationInformationComment, IsEmployerLocationMainApprenticeshipLocation = false, VacancyReferenceNumber = vacancyReferenceNumber, Addresses = new List <VacancyLocationAddressViewModel> { new VacancyLocationAddressViewModel { Address = new AddressViewModel { AddressLine4 = "address line 4 - 1", AddressLine3 = "address line 3 - 1", AddressLine2 = "address line 2 - 1", AddressLine1 = "address line 1 - 1", Postcode = "postcode", Uprn = "uprn" }, NumberOfPositions = 1 }, new VacancyLocationAddressViewModel { Address = new AddressViewModel { AddressLine4 = "address line 4 - 2", AddressLine3 = "address line 3 - 2", AddressLine2 = "address line 2 - 2", AddressLine1 = "address line 1 - 2", Postcode = "postcode", Uprn = "uprn" }, NumberOfPositions = 1 }, new VacancyLocationAddressViewModel { Address = new AddressViewModel { AddressLine4 = "address line 4 - 3", AddressLine3 = "address line 3 - 3", AddressLine2 = "address line 2 - 3", AddressLine1 = "address line 1 - 3", Postcode = "postcode", Uprn = "uprn" }, NumberOfPositions = 1 } }, LocationAddressesComment = aNewLocationAddressesComment }; return(locationSearchViewModel); }
public MediatorResponse <LocationSearchViewModel> RemoveLocation(LocationSearchViewModel viewModel, int locationIndex) { viewModel.Addresses.RemoveAt(locationIndex); viewModel.SearchResultAddresses = new PageableViewModel <VacancyLocationAddressViewModel>(); viewModel.PostcodeSearch = string.Empty; viewModel.CurrentPage = 1; viewModel.TotalNumberOfPages = 1; return(GetMediatorResponse(VacancyMediatorCodes.RemoveLocation.Ok, viewModel)); }
public LocationSearchViewModel GetAddressesFor(LocationSearchViewModel viewModel) { var pageSize = int.MaxValue; // TODO: maybe we can remove the pageable propery. We'll keep it until the design is confirmed. var resultsPage = _addressSearchService.GetAddressesFor(viewModel.PostcodeSearch, viewModel.CurrentPage, pageSize); var resultsViewModelPage = resultsPage.ToViewModel(resultsPage.Page.Select(ConvertToViewModel)); viewModel.SearchResultAddresses = resultsViewModelPage; return(viewModel); }
public void AddLocationsShouldStoreLocationsInDB() { const string providerSiteErn = "101282923"; const string edsUrn = "100608868"; const string additionalLocationInformation = "additional location information"; var numberOfPositions = 5; var address1 = new VacancyLocationAddressViewModel { Address = { Postcode = "HA0 1TW", AddressLine1 = "Abbeydale Road", AddressLine4 = "Wembley" }, NumberOfPositions = numberOfPositions }; var vacancyGuid = Guid.NewGuid(); var viewModel = new LocationSearchViewModel { ProviderSiteEdsUrn = providerSiteErn, EmployerEdsUrn = edsUrn, AdditionalLocationInformation = additionalLocationInformation, Addresses = new List <VacancyLocationAddressViewModel> { address1 }, VacancyGuid = vacancyGuid }; var savedVacancy = new MongoVacancy { VacancyGuid = vacancyGuid }; Collection.Save(savedVacancy); var vacancyPostingController = Container.GetInstance <VacancyPostingController>(); var result = vacancyPostingController.Locations(viewModel); result.Should().BeOfType <RedirectToRouteResult>(); var redirection = result as RedirectToRouteResult; redirection.RouteName.Should().Be("CreateVacancy"); var vacancy = Collection.FindOneById(vacancyGuid); /*vacancy.LocationAddresses.Should().HaveCount(1); * vacancy.LocationAddresses[0].Address.AddressLine1.Should().Be(address1.Address.AddressLine1); * vacancy.LocationAddresses[0].Address.AddressLine2.Should().Be(address1.Address.AddressLine2); * vacancy.LocationAddresses[0].Address.AddressLine3.Should().Be(address1.Address.AddressLine3); * vacancy.LocationAddresses[0].Address.AddressLine4.Should().Be(address1.Address.AddressLine4); * vacancy.LocationAddresses[0].Address.Postcode.Should().Be(address1.Address.Postcode); * vacancy.LocationAddresses[0].NumberOfPositions.Should().Be(numberOfPositions); * vacancy.AdditionalLocationInformation.Should().Be(additionalLocationInformation);*/ }
public ActionResult SearchLocations(LocationSearchViewModel viewModel) { TempData["AlreadyAddedLocations"] = viewModel.Addresses; return(RedirectToRoute(ManagementRouteNames.SearchAddresses, new { PostcodeSearch = viewModel.PostcodeSearch, VacancyGuid = viewModel.VacancyGuid, AdditionalLocationInformation = viewModel.AdditionalLocationInformation, VacancyReferenceNumber = viewModel.VacancyReferenceNumber })); }
public void OnGet() { if (LocationSearch == null) { LocationSearch = new LocationSearchViewModel() { Postcode = "CV1 2HJ", //Default post code SearchRadius = 25m //Default search radius }; } //return Page(); }
public ActionResult RemoveLocation(LocationSearchViewModel viewModel, int locationIndex) { var response = _vacancyMediator.RemoveLocation(viewModel, locationIndex); switch (response.Code) { case VacancyMediatorCodes.RemoveLocation.Ok: return(RedirectToShowLocations(viewModel)); default: throw new InvalidMediatorCodeException(response.Code); } }
public MediatorResponse <LocationSearchViewModel> AddLocations(LocationSearchViewModel viewModel) { var validationResult = _locationSearchViewModelServerValidator.Validate(viewModel); if (!validationResult.IsValid) { return(GetMediatorResponse(VacancyMediatorCodes.AddLocations.FailedValidation, viewModel, validationResult)); } var locationSearchViewModel = _vacancyQaProvider.AddLocations(viewModel); return(GetMediatorResponse(VacancyMediatorCodes.AddLocations.Ok, locationSearchViewModel)); }
private void AddAlreadyAddedLocations(LocationSearchViewModel viewModel, List <VacancyLocationAddressViewModel> alreadyAddedLocations) { var existingVacancy = _vacancyQaProvider.GetVacancy(viewModel.VacancyGuid); if (existingVacancy != null) { viewModel.Addresses = existingVacancy.LocationAddresses; } if (alreadyAddedLocations != null && alreadyAddedLocations.Any()) { viewModel.Addresses = alreadyAddedLocations; } }
public JsonResult Search(LocationSearchViewModel model) { Response response; try { List <Location> list; int dataCount; using (var db = new KiaGalleryContext()) { var query = db.Location.Select(x => x); if (!string.IsNullOrEmpty(model.term)) { query = query.Where(x => x.Name.Contains(model.term) || x.EnglishName.Contains(model.term) || x.Name.Contains(model.term.Trim().Replace("ی", "ي").Replace("ک", "ك")) || x.EnglishName.Contains(model.term.Trim().Replace("ی", "ي").Replace("ک", "ك"))); } dataCount = query.Count(); query = query.OrderByDescending(x => x.Id).Skip(model.page * model.count).Take(model.count); list = query.ToList(); } response = new Response() { status = 200, data = new { list = list.Select(item => new { id = item.Id, name = item.Name, englishName = item.EnglishName, order = item.Order }), pageCount = Math.Ceiling((double)dataCount / model.count), count = dataCount, page = model.page + 1 } }; } catch (Exception ex) { response = Core.GetExceptionResponse(ex); } return(Json(response, JsonRequestBehavior.AllowGet)); }
private async Task <ILocationSearchViewModel> PoulateDropDownListAsync(ILocationSearchViewModel model, CancellationToken cancellationToken) { if (model == null) { model = new LocationSearchViewModel(); } model.DDLCountry = await _ddlDal.GetCountryListAsync(userId, cancellationToken); model.DDLLocation = await _ddlDal.GetLocationListAsync(userId, 0, cancellationToken, true); model.DDLSearch = await _ddlDal.GetLocationSearchListAsync(userId, cancellationToken); model.DDLCountry[0].Identifier = "DDLCountry"; model.DDLLocation[0].Identifier = "ddlLocation"; return(model); }
public ActionResult SearchAddresses(LocationSearchViewModel viewModel) { var response = _vacancyMediator.SearchLocations(viewModel, (List <VacancyLocationAddressViewModel>)TempData["AlreadyAddedLocations"]); ModelState.Clear(); switch (response.Code) { case VacancyMediatorCodes.SearchLocations.Ok: return(View("Locations", response.ViewModel)); case VacancyMediatorCodes.SearchLocations.NotFullPostcode: AddPostcodeSearchErrorToModelState(viewModel); return(View("Locations", response.ViewModel)); default: throw new InvalidMediatorCodeException(response.Code); } }
public ActionResult Locations(LocationSearchViewModel viewModel) { var response = _vacancyMediator.AddLocations(viewModel); ModelState.Clear(); switch (response.Code) { case VacancyMediatorCodes.AddLocations.Ok: return(RedirectToRoute(ManagementRouteNames.ReviewVacancy, new { vacancyReferenceNumber = response.ViewModel.VacancyReferenceNumber })); case VacancyMediatorCodes.AddLocations.FailedValidation: response.ValidationResult.AddToModelState(ModelState, string.Empty); return(View(response.ViewModel)); default: throw new InvalidMediatorCodeException(response.Code); } }
public MediatorResponse <LocationSearchViewModel> SearchLocations(LocationSearchViewModel viewModel, List <VacancyLocationAddressViewModel> alreadyAddedLocations) { if (string.IsNullOrWhiteSpace(viewModel.PostcodeSearch)) { AddAlreadyAddedLocations(viewModel, alreadyAddedLocations); return(GetMediatorResponse(VacancyMediatorCodes.SearchLocations.NotFullPostcode, viewModel)); } try { viewModel = _locationsProvider.GetAddressesFor(viewModel); AddAlreadyAddedLocations(viewModel, alreadyAddedLocations); return(GetMediatorResponse(VacancyMediatorCodes.SearchLocations.Ok, viewModel)); } catch (CustomException) { return(GetMediatorResponse(VacancyMediatorCodes.SearchLocations.NotFullPostcode, viewModel)); } }
public MediatorResponse <LocationSearchViewModel> UseLocation(LocationSearchViewModel viewModel, int locationIndex, string postCodeSearch) { viewModel.PostcodeSearch = postCodeSearch; var searchResult = SearchLocations(viewModel, viewModel.Addresses); if (searchResult.ViewModel.SearchResultAddresses?.Page != null && searchResult.ViewModel.SearchResultAddresses.Page.Count() > locationIndex) { var addressToAdd = searchResult.ViewModel.SearchResultAddresses.Page.ToList()[locationIndex]; var isNewAddress = viewModel.Addresses.TrueForAll(v => !v.Address.Equals(addressToAdd.Address)); if (isNewAddress) { viewModel.Addresses.Add(addressToAdd); } } viewModel.SearchResultAddresses = new PageableViewModel <VacancyLocationAddressViewModel>(); viewModel.CurrentPage = 1; viewModel.TotalNumberOfPages = 1; viewModel.PostcodeSearch = string.Empty; return(GetMediatorResponse(VacancyMediatorCodes.UseLocation.Ok, viewModel)); }
public void Search_Location_Provisioning_Service_Throws_Exeption() { using (ShimsContext.Create()) { //Arrange var myContext = new SIMPLTestContext(); var fakeUserDto = myContext.GetFakeUserDtoObject(); ShimCurrentUser.AsUserDto = () => fakeUserDto; //search criteria var locationSearchViewModel = new LocationSearchViewModel { SubscriberID = "370001704986" }; //expected search results var expectedResult = new { status = "error", isModal = false, errorMessage = "Provisioning Service Error" }.ToJSON(); ShimRosettianClient.AllInstances.SearchLocationsSearchFieldsDtoUserDto = delegate { throw new Exception("Provisioning Service Error"); }; var actionResult = SearchControllerForTests.SearchLocation(locationSearchViewModel) as JsonResult; Assert.IsNotNull(actionResult, "SearchSubscribers returned null"); var actualJsonResult = actionResult.Data.ToJSON(); Assert.AreEqual(expectedResult, actualJsonResult); } }
public void Search_Location_By_SubscriberID() { using (ShimsContext.Create()) { //Arrange var myContext = new SIMPLTestContext(); var fakeUserDto = myContext.GetFakeUserDtoObject(); ShimCurrentUser.AsUserDto = () => fakeUserDto; //search criteria var locationSearchViewModel = new LocationSearchViewModel { SubscriberID = "370001704986" }; //expected search results var record = new[] { new { ID = "9999999", AddressLine1 = "123 Fake St.", AddressLine2 = "Apt 2", CityName = "Fake City", StateName = null as object, ZipCode =null as object, ZipPlusFourCode = null as object, IsBillingAddress = false, HeadendCode = "01", HasSubscriber = true, FacilityList = new Provisioning.FacilityDto[] {}, CustomFields = new CustomFieldDto[] {}, RateCenterName = "1234", MaximumBandwidth =null as object, NetworkLocationCode = null as object } }; var expectedSearchResults = new { status = "valid", isModal = false, searchResults = record }.ToJSON(); var fakeLocationDto = myContext.GetFakeLocationDtoObject(); var fakeLocationCollectionDto = new LocationCollectionDto() { fakeLocationDto }; ShimRosettianClient.AllInstances.SearchLocationsSearchFieldsDtoUserDto = delegate { return fakeLocationCollectionDto; }; var actionResult = SearchControllerForTests.SearchLocation(locationSearchViewModel) as JsonResult; Assert.IsNotNull(actionResult, "SearchSubscribers returned null"); var actualJsonResult = actionResult.Data.ToJSON(); Assert.AreEqual(expectedSearchResults, actualJsonResult); } }