Beispiel #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 });
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
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.");
        }
Beispiel #5
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);
        }
Beispiel #6
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.""}]}");
        }