示例#1
0
        public async Task Then_The_Request_Is_Handled_And_Response_Returned_And_Type_Set_For_Provider(
            int ukprn,
            Guid id,
            CreateVacancyCommandResponse mediatorResponse,
            CreateVacancyRequest request,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] VacancyController controller)
        {
            var accountIdentifier = $"Provider-{ukprn}-product";

            mockMediator.Setup(x =>
                               x.Send(It.Is <CreateVacancyCommand>(c =>
                                                                   c.Id.Equals(id) &&
                                                                   c.AccountIdentifier.AccountType == AccountType.Provider &&
                                                                   c.AccountIdentifier.Ukprn == ukprn &&
                                                                   c.AccountIdentifier.AccountHashedId == null &&
                                                                   c.PostVacancyRequestData.Title.Equals(request.Title) &&
                                                                   c.PostVacancyRequestData.User.Ukprn.Equals(ukprn) &&
                                                                   c.PostVacancyRequestData.OwnerType.Equals(OwnerType.Provider) &&
                                                                   c.PostVacancyRequestData.ProviderContact.Name.Equals(request.SubmitterContactDetails.Name) &&
                                                                   c.PostVacancyRequestData.ProviderContact.Phone.Equals(request.SubmitterContactDetails.Phone) &&
                                                                   c.PostVacancyRequestData.ProviderContact.Email.Equals(request.SubmitterContactDetails.Email) &&
                                                                   c.IsSandbox.Equals(false)
                                                                   ), CancellationToken.None))
            .ReturnsAsync(mediatorResponse);

            var controllerResult = await controller.CreateVacancy(accountIdentifier, id, request) as CreatedResult;

            controllerResult !.StatusCode.Should().Be((int)HttpStatusCode.Created);
            controllerResult.Value.Should().BeEquivalentTo(new { mediatorResponse.VacancyReference });
        }
        public async void GetUserCVsSummary_ReturnsOk()
        {
            //arrange
            var vacanciesPreview = new VacancySummaryDTO[]
            {
                new VacancySummaryDTO()
                {
                    Id = new Guid("11111111-1111-1111-1111-111111111111")
                },
                new VacancySummaryDTO()
                {
                    Id = new Guid("11111111-1111-1111-1111-111111111112")
                }
            };
            var mock = new Mock <IVacancyService>();

            mock.Setup(v => v.GetVacancyPreviewAsync(It.IsAny <Guid>(), It.IsAny <Int32>(), It.IsAny <Int32>()))
            .ReturnsAsync(vacanciesPreview);
            VacancyController vacancyController = new VacancyController(mock.Object, null, _mapper, null);
            //act
            ObjectResult actual = vacancyController.GetVacancySummary(
                new Guid("11111111-1111-1111-1111-111111111110"), 1, 1).Result as ObjectResult;
            var actualVacancies = actual.Value as IEnumerable <VacancySummaryDTO>;

            //assert
            Assert.Equal(200, actual.StatusCode);
            Assert.Equal(vacanciesPreview, actualVacancies);
        }
示例#3
0
        public async Task Sandbox_Special_Case_Guids(
            string guid,
            bool isSandbox,
            HttpStatusCode expectedStatusCode,
            CreateVacancyCommandResponse mediatorResponse,
            CreateVacancyRequest request,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] VacancyController controller)
        {
            var id                = Guid.Parse(guid);
            var accountId         = "ABC123";
            var accountIdentifier = $"Employer-{accountId}-Product";

            mockMediator.Setup(x =>
                               x.Send(It.Is <CreateVacancyCommand>(c =>
                                                                   c.Id.Equals(id) &&
                                                                   c.PostVacancyRequestData.Title.Equals(request.Title) &&
                                                                   c.PostVacancyRequestData.EmployerAccountId.Equals(accountId.ToUpper()) &&
                                                                   c.IsSandbox.Equals(isSandbox)
                                                                   ), CancellationToken.None))
            .ReturnsAsync(mediatorResponse);

            var controllerResult = await controller.CreateVacancy(accountIdentifier, id, request, isSandbox) as IStatusCodeActionResult;

            controllerResult.StatusCode.Should().Be((int)expectedStatusCode);
        }
示例#4
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);
        }
示例#5
0
        public async Task Then_If_The_Format_Is_Not_Correct_For_The_AccountIdentifier_Then_Forbidden_Returned(
            long accountIdentifier,
            Guid id,
            CreateVacancyRequest request,
            [Greedy] VacancyController controller)
        {
            var controllerResult = await controller.CreateVacancy(accountIdentifier.ToString(), id, request) as StatusCodeResult;

            controllerResult !.StatusCode.Should().Be((int)HttpStatusCode.Forbidden);
        }
示例#6
0
        public async Task Then_If_The_Ukprn_Is_Not_Correct_For_The_AccountIdentifier_Then_Forbidden_Returned(
            Guid id,
            CreateVacancyRequest request,
            [Greedy] VacancyController controller)
        {
            var ukprn             = "ABC123";
            var accountIdentifier = $"Provider-{ukprn}-product";

            var controllerResult = await controller.CreateVacancy(accountIdentifier, id, request) as BadRequestObjectResult;

            controllerResult !.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
            controllerResult.Value.Should().BeEquivalentTo("Account Identifier is not in the correct format.");
        }
        public async Task Then_If_Error_Then_Internal_Server_Error_Returned(
            string vacancyReference,
            GetVacancyQueryResult queryResult,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] VacancyController controller)
        {
            mockMediator.Setup(x => x.Send(It.IsAny <GetVacancyQuery>(),
                                           CancellationToken.None)).ThrowsAsync(new Exception());

            var controllerResult = await controller.GetVacancy(vacancyReference) as StatusCodeResult;

            Assert.IsNotNull(controllerResult);
            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.InternalServerError);
        }
示例#8
0
        public void TestEmptyVacancies()
        {
            var optionsBuilder = new DbContextOptionsBuilder <HomeMyDayDbContext>();

            optionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            HomeMyDayDbContext context    = new HomeMyDayDbContext(optionsBuilder.Options);
            IVacancyRepository repository = new EFVacancyRepository(context);
            IVacancyManager    manager    = new VacancyManager(repository);

            VacancyController target = new VacancyController(manager);

            var result = target.Index() as ViewResult;
            var model  = result.Model as Vacancy;

            Assert.Null(model);
        }
        public async Task Then_If_No_Result_Then_Not_Found_Result_Returned(
            string vacancyReference,
            GetVacancyQueryResult queryResult,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] VacancyController controller)
        {
            queryResult.Vacancy = null;
            mockMediator.Setup(x => x.Send(It.Is <GetVacancyQuery>(c =>
                                                                   c.VacancyReference.Equals(vacancyReference)),
                                           CancellationToken.None)).ReturnsAsync(queryResult);

            var controllerResult = await controller.GetVacancy(vacancyReference) as NotFoundResult;

            Assert.IsNotNull(controllerResult);
            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.NotFound);
        }
示例#10
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);
        }
示例#11
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);
        }
        public async Task Then_The_Handler_Is_Called_And_Data_Returned(
            string vacancyReference,
            GetVacancyQueryResult queryResult,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] VacancyController controller)
        {
            mockMediator.Setup(x => x.Send(It.Is <GetVacancyQuery>(c =>
                                                                   c.VacancyReference.Equals(vacancyReference)),
                                           CancellationToken.None)).ReturnsAsync(queryResult);

            var controllerResult = await controller.GetVacancy(vacancyReference) as ObjectResult;

            Assert.IsNotNull(controllerResult);
            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.OK);
            var model = controllerResult.Value as GetVacancyResponse;

            Assert.IsNotNull(model);
            model.Should().BeEquivalentTo((GetVacancyResponse)queryResult);
        }
示例#13
0
        public async Task Then_If_Exception_Internal_Server_Error_Is_Returned(
            Guid id,
            string errorContent,
            CreateVacancyRequest request,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] VacancyController controller)
        {
            var accountId         = "ABC123";
            var accountIdentifier = $"Employer-{accountId}-product";

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

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

            controllerResult !.StatusCode.Should().Be((int)HttpStatusCode.InternalServerError);
        }
示例#14
0
        public async Task Then_If_ContentException_Bad_Request_Is_Returned_And_Error_Keys_Mapped(
            Guid id,
            string errorContent,
            CreateVacancyRequest request,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] VacancyController controller)
        {
            var accountId         = "ABC123";
            var accountIdentifier = $"Employer-{accountId}-product";

            mockMediator
            .Setup(mediator => mediator.Send(
                       It.IsAny <CreateVacancyCommand>(),
                       It.IsAny <CancellationToken>()))
            .ThrowsAsync(new HttpRequestContentException("Error", HttpStatusCode.BadRequest, @"{""errors"":[{""field"":""ProgrammeId"",""message"":""Training programme a does not exist.""},{""field"":""employerName"",""message"":""Employer name is not in the correct format.""},{""field"":""employerNameOption"",""message"":""Invalid employer name option.""}]}"));

            var controllerResult = await controller.CreateVacancy(accountIdentifier, id, request) as ObjectResult;

            controllerResult !.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
            controllerResult.Value.Should().Be(@"{""errors"":[{""field"":""standardLarsCode"",""message"":""Training programme a does not exist.""},{""field"":""alternativeEmployerName"",""message"":""Employer name is not in the correct format.""},{""field"":""employerNameOption"",""message"":""Invalid employer name option.""}]}");
        }