public async Task Then_Gets_Vacancies_From_Mediator_As_Provider_And_Uses_Request_Ukprn_If_FilterBySubscription_Is_false( SearchVacancyRequest request, int ukprn, GetVacanciesQueryResult mediatorResult, [Frozen] Mock <IMediator> mockMediator, [Greedy] VacancyController controller) { request.FilterBySubscription = false; var accountIdentifier = $"Provider-{ukprn}-product"; mockMediator .Setup(mediator => mediator.Send( It.Is <GetVacanciesQuery>( c => c.Ukprn.Equals(request.Ukprn) && c.AccountIdentifier.AccountType == AccountType.Provider && c.AccountIdentifier.AccountHashedId == null && c.AccountIdentifier.Ukprn == ukprn && c.PageNumber.Equals(request.PageNumber) && c.AccountPublicHashedId == null && c.AccountLegalEntityPublicHashedId.Equals(request.AccountLegalEntityPublicHashedId) && c.PageSize.Equals(request.PageSize)), It.IsAny <CancellationToken>())) .ReturnsAsync(mediatorResult); var controllerResult = await controller.GetVacancies(accountIdentifier, request) as ObjectResult; Assert.IsNotNull(controllerResult); controllerResult.StatusCode.Should().Be((int)HttpStatusCode.OK); var model = controllerResult.Value as GetVacanciesListResponse; Assert.IsNotNull(model); model.Should().BeEquivalentTo((GetVacanciesListResponse)mediatorResult); }
public void And_IsEmployerAnonymous_Then_Anon_Values_Used(GetVacanciesQueryResult source) { //arrange var sourceVacancies = source.Vacancies.ToList(); foreach (var getVacanciesItem in sourceVacancies) { getVacanciesItem.IsEmployerAnonymous = true; getVacanciesItem.VacancyLocationType = "nAtiONal"; } //act var actual = (GetVacanciesListResponse)source; //assert actual.Vacancies.Should().BeEquivalentTo(sourceVacancies, options => options .ExcludingMissingMembers() .Excluding(item => item.EmployerName) .Excluding(item => item.CourseTitle) .Excluding(item => item.CourseLevel) .Excluding(item => item.Location)); actual.Vacancies.TrueForAll(c => c.IsNationalVacancy).Should().BeTrue(); for (var i = 0; i < actual.Vacancies.Count; i++) { actual.Vacancies[i].EmployerName.Should().Be(sourceVacancies[i].AnonymousEmployerName); actual.Vacancies[i].Course.Title.Should().Be($"{sourceVacancies[i].CourseTitle} (level {sourceVacancies[i].CourseLevel})"); actual.Vacancies[i].Course.Level.Should().Be(sourceVacancies[i].CourseLevel); actual.Vacancies[i].Course.Route.Should().Be(sourceVacancies[i].Route); actual.Vacancies[i].Course.LarsCode.Should().Be(sourceVacancies[i].StandardLarsCode); actual.Vacancies[i].Location.Lat.Should().Be(sourceVacancies[i].Location.Lat); actual.Vacancies[i].Location.Lon.Should().Be(sourceVacancies[i].Location.Lon); } }
public void Then_The_Values_Are_Mapped(GetVacanciesQueryResult source) { //Arrange source.Location.Country = "Scotland"; SetVacancyUrl(source); //Act var actual = (SearchResultsViewModel)source; actual.TotalResults.Should().Be(source.TotalFound); actual.Location.Latitude.Should().Be(source.Location.GeoPoint.First()); actual.Location.Longitude.Should().Be(source.Location.GeoPoint.Last()); Enum.TryParse <Country>(source.Location.Country, out var country); actual.Country.Should().Be(country); actual.CountryName.Should().Be(source.Location.Country); actual.Routes.Should().BeEquivalentTo(source.Routes.Select(c => c.Name).ToList()); actual.Results.Should().BeEquivalentTo(source.Vacancies, options => options .Excluding(c => c.Location) .Excluding(c => c.VacancyUrl) ); foreach (var result in actual.Results) { result.Location.Latitude.Should().Be(source.Vacancies .Single(c => c.VacancyReference.Equals(result.VacancyReference)).Location.Lat); result.Location.Longitude.Should().Be(source.Vacancies .Single(c => c.VacancyReference.Equals(result.VacancyReference)).Location.Lon); result.VacancyUrl.Should().BeEquivalentTo(new Uri(source.Vacancies .Single(c => c.VacancyReference.Equals(result.VacancyReference)).VacancyUrl)); } }
public void Then_If_No_Location_Then_Set_To_Null(GetVacanciesQueryResult source) { //Arrange SetVacancyUrl(source, true); //Act var actual = (SearchResultsViewModel)source; //Assert actual.Results.ToList().TrueForAll(c => c.Location == null).Should().BeTrue(); }
private static void SetVacancyUrl(GetVacanciesQueryResult source, bool setEmptyLocation = false) { foreach (var vacancy in source.Vacancies) { vacancy.VacancyUrl = $"https://{vacancy.VacancyUrl}"; if (setEmptyLocation) { vacancy.Location = null; } } }
public void Then_The_Fields_Are_Mapped(GetVacanciesQueryResult source) { var actual = (GetVacanciesListResponse)source; actual.Vacancies.Should().BeEquivalentTo(source.Vacancies, options => options.ExcludingMissingMembers().Excluding(c => c.EmployerName)); actual.Total.Should().Be(source.Total); actual.TotalFiltered.Should().Be(source.TotalFiltered); actual.TotalPages.Should().Be(source.TotalPages); foreach (var vacancy in actual.Vacancies) { var expectedVacancy = source.Vacancies.Single(c => c.VacancyReference.Equals(vacancy.VacancyReference)); vacancy.Location.Lat.Should().Be(expectedVacancy.Location.Lat); vacancy.Location.Lon.Should().Be(expectedVacancy.Location.Lon); } }
public async Task Then_Gets_Vacancies_From_Mediator_As_Employer_With_No_AccountId_Filter_When_FilterBySubscription_Is_False( SearchVacancyRequest request, GetVacanciesQueryResult mediatorResult, [Frozen] Mock <IMediator> mockMediator, [Greedy] VacancyController controller) { var accountId = "ABC123"; var accountIdentifier = $"Employer-{accountId}-product"; request.FilterBySubscription = false; request.Sort = VacancySort.ExpectedStartDateAsc; mockMediator .Setup(mediator => mediator.Send( It.Is <GetVacanciesQuery>( c => c.Ukprn.Equals(request.Ukprn) && c.AccountIdentifier.AccountType == AccountType.Employer && c.AccountIdentifier.AccountHashedId == accountId && c.AccountIdentifier.Ukprn == null && c.PageNumber.Equals(request.PageNumber) && c.AccountPublicHashedId == null && c.AccountLegalEntityPublicHashedId.Equals(request.AccountLegalEntityPublicHashedId) && c.PageSize.Equals(request.PageSize) && c.Lat.Equals(request.Lat) && c.Lon.Equals(request.Lon) && c.Routes.Equals(request.Routes) && c.Sort.Equals(request.Sort.ToString()) && c.DistanceInMiles.Equals(request.DistanceInMiles) && c.NationWideOnly.Equals(request.NationWideOnly) && c.StandardLarsCode.Equals(request.StandardLarsCode) && c.PostedInLastNumberOfDays.Equals(request.PostedInLastNumberOfDays) ), It.IsAny <CancellationToken>())) .ReturnsAsync(mediatorResult); var controllerResult = await controller.GetVacancies(accountIdentifier, request) as ObjectResult; Assert.IsNotNull(controllerResult); controllerResult.StatusCode.Should().Be((int)HttpStatusCode.OK); var model = controllerResult.Value as GetVacanciesListResponse; Assert.IsNotNull(model); model.Should().BeEquivalentTo((GetVacanciesListResponse)mediatorResult); }
public void Then_If_No_Results_No_Data_Mapped(List <Route> routes) { //Arrange var source = new GetVacanciesQueryResult { Location = null, Vacancies = new List <Vacancy>(), Routes = routes, TotalFound = 0 }; //Act var actual = (SearchResultsViewModel)source; //Assert actual.TotalResults.Should().Be(0); actual.Location.Should().BeNull(); actual.Results.Should().BeEmpty(); actual.Routes.Should().BeEquivalentTo(source.Routes.Select(c => c.Name).ToList()); actual.Country.Should().Be(Country.England); }
public void Then_The_Apprentice_Country_Url_Is_Mapped(string country, string expectedUrl, Country expectedCountry, GetVacanciesQueryResult source) { //Arrange source.Location.Country = country; SetVacancyUrl(source); //Act var actual = (SearchResultsViewModel)source; //Assert actual.CountryUrl.Should().Be(expectedUrl); actual.Country.Should().Be(expectedCountry); actual.CountryName.Should().Be(country); }