Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public async Task And_SecurityException_Then_Returns_Forbidden(
            string accountId,
            SearchVacancyRequest request,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] VacancyController controller)
        {
            var accountIdentifier = $"Employer-{accountId}-product";

            mockMediator
            .Setup(mediator => mediator.Send(
                       It.IsAny <GetVacanciesQuery>(),
                       It.IsAny <CancellationToken>()))
            .ThrowsAsync(new SecurityException());

            var controllerResult = await controller.GetVacancies(accountIdentifier, request) as StatusCodeResult;

            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.Forbidden);
        }
Ejemplo n.º 3
0
        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);
        }