Example #1
0
        public async Task GetApiLinksNotPermitted()
        {
            OAuth2Token oAuth2Token = new OAuth2TokenBuilder().WithAccessToken(AccessTokens.ValidAccessToken_InvalidService).Build();

            this.Fixture.MockProviderService
            .UponReceiving("a GET index request that is unauthorised to retrieve API links")
            .With(new ProviderServiceRequest
            {
                Method  = HttpVerb.Get,
                Path    = "/",
                Headers = new Dictionary <string, object>
                {
                    { "Authorization", "Bearer " + AccessTokens.ValidAccessToken_InvalidService },
                    { "Accept", $"{ResponseContentTypes.Hal}, {ResponseContentTypes.AdvertisementErrorVersion1}" },
                    { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
                }
            })
            .WillRespondWith(new ProviderServiceResponse
            {
                Status  = (int)HttpStatusCode.Unauthorized,
                Headers = new Dictionary <string, object> {
                    { "X-Request-Id", RequestId }
                }
            });

            UnauthorizedException actualException;

            using (var client = this.Fixture.GetClient(oAuth2Token))
            {
                actualException = await Assert.ThrowsAsync <UnauthorizedException>(
                    async() => await client.InitialiseIndexResource(this.Fixture.AdPostingApiServiceBaseUri));
            }

            actualException.ShouldBeEquivalentToException(
                new UnauthorizedException(RequestId, 401, $"[GET] {this.Fixture.AdPostingApiServiceBaseUri} is not authorized."));
        }
Example #2
0
        public async Task PostAdWhereAdvertiserNotRelatedToRequestor()
        {
            var oAuth2Token = new OAuth2TokenBuilder().Build();

            this.Fixture.RegisterIndexPageInteractions(oAuth2Token);

            this.Fixture.AdPostingApiService
            .UponReceiving("a POST advertisement request to create a job for an advertiser not related to the requestor's account")
            .With(
                new ProviderServiceRequest
            {
                Method  = HttpVerb.Post,
                Path    = AdvertisementLink,
                Headers = new Dictionary <string, string>
                {
                    { "Authorization", "Bearer " + oAuth2Token.AccessToken },
                    { "Content-Type", RequestContentTypes.AdvertisementVersion1 },
                    { "Accept", $"{ResponseContentTypes.AdvertisementVersion1}, {ResponseContentTypes.AdvertisementErrorVersion1}" },
                    { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
                },
                Body = new AdvertisementContentBuilder(this.MinimumFieldsInitializer)
                       .WithRequestCreationId(CreationIdForAdWithMinimumRequiredData)
                       .WithAdvertiserId("999888777")
                       .Build()
            }
                )
            .WillRespondWith(
                new ProviderServiceResponse
            {
                Status  = 403,
                Headers = new Dictionary <string, string>
                {
                    { "Content-Type", ResponseContentTypes.AdvertisementErrorVersion1 },
                    { "X-Request-Id", RequestId }
                },
                Body = new
                {
                    message = "Forbidden",
                    errors  = new[] { new { code = "RelationshipError" } }
                }
            });

            var requestModel = new AdvertisementModelBuilder(this.MinimumFieldsInitializer).WithRequestCreationId(CreationIdForAdWithMinimumRequiredData).WithAdvertiserId("999888777").Build();

            UnauthorizedException actualException;

            using (AdPostingApiClient client = this.Fixture.GetClient(oAuth2Token))
            {
                actualException = await Assert.ThrowsAsync <UnauthorizedException>(
                    async() => await client.CreateAdvertisementAsync(requestModel));
            }

            actualException.ShouldBeEquivalentToException(
                new UnauthorizedException(
                    RequestId,
                    403,
                    new AdvertisementErrorResponse
            {
                Message = "Forbidden",
                Errors  = new[] { new AdvertisementError {
                                      Code = "RelationshipError"
                                  } }
            }));
        }
Example #3
0
        public async Task PostAdWithExistingCreationId()
        {
            const string creationId      = "CreationIdOf8e2fde50-bc5f-4a12-9cfb-812e50500184";
            const string advertisementId = "8e2fde50-bc5f-4a12-9cfb-812e50500184";
            OAuth2Token  oAuth2Token     = new OAuth2TokenBuilder().Build();
            var          location        = $"http://localhost{AdvertisementLink}/{advertisementId}";

            this.Fixture.RegisterIndexPageInteractions(oAuth2Token);

            this.Fixture.AdPostingApiService
            .Given("There is a standout advertisement with maximum data")
            .UponReceiving($"a POST advertisement request to create a job ad with the same creation id '{creationId}'")
            .With(
                new ProviderServiceRequest
            {
                Method  = HttpVerb.Post,
                Path    = AdvertisementLink,
                Headers = new Dictionary <string, string>
                {
                    { "Authorization", "Bearer " + oAuth2Token.AccessToken },
                    { "Content-Type", RequestContentTypes.AdvertisementVersion1 },
                    { "Accept", $"{ResponseContentTypes.AdvertisementVersion1}, {ResponseContentTypes.AdvertisementErrorVersion1}" },
                    { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
                },
                Body = new AdvertisementContentBuilder(this.MinimumFieldsInitializer).WithRequestCreationId(creationId).Build()
            }
                )
            .WillRespondWith(
                new ProviderServiceResponse
            {
                Status  = 409,
                Headers = new Dictionary <string, string>
                {
                    { "Location", location },
                    { "Content-Type", ResponseContentTypes.AdvertisementErrorVersion1 },
                    { "X-Request-Id", RequestId }
                },
                Body = new
                {
                    message = "Conflict",
                    errors  = new[] { new { field = "creationId", code = "AlreadyExists" } }
                }
            });

            CreationIdAlreadyExistsException actualException;

            using (AdPostingApiClient client = this.Fixture.GetClient(oAuth2Token))
            {
                actualException = await Assert.ThrowsAsync <CreationIdAlreadyExistsException>(
                    async() => await client.CreateAdvertisementAsync(new AdvertisementModelBuilder(this.MinimumFieldsInitializer).WithRequestCreationId(creationId).Build()));
            }

            var expectedException = new CreationIdAlreadyExistsException(RequestId, new Uri(location),
                                                                         new AdvertisementErrorResponse
            {
                Message = "Conflict",
                Errors  = new[] { new AdvertisementError {
                                      Field = "creationId", Code = "AlreadyExists"
                                  } }
            });

            actualException.ShouldBeEquivalentToException(expectedException);
        }
Example #4
0
        public async Task PostAdWithNoCreationId()
        {
            OAuth2Token oAuth2Token = new OAuth2TokenBuilder().Build();

            this.Fixture.RegisterIndexPageInteractions(oAuth2Token);

            this.Fixture.AdPostingApiService
            .UponReceiving("a POST advertisement request to create a job ad without a creation id")
            .With(
                new ProviderServiceRequest
            {
                Method  = HttpVerb.Post,
                Path    = AdvertisementLink,
                Headers = new Dictionary <string, string>
                {
                    { "Authorization", "Bearer " + oAuth2Token.AccessToken },
                    { "Content-Type", RequestContentTypes.AdvertisementVersion1 },
                    { "Accept", $"{ResponseContentTypes.AdvertisementVersion1}, {ResponseContentTypes.AdvertisementErrorVersion1}" },
                    { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
                },
                Body = new AdvertisementContentBuilder(this.MinimumFieldsInitializer).Build()
            }
                )
            .WillRespondWith(
                new ProviderServiceResponse
            {
                Status  = 422,
                Headers = new Dictionary <string, string>
                {
                    { "Content-Type", ResponseContentTypes.AdvertisementErrorVersion1 },
                    { "X-Request-Id", RequestId }
                },
                Body = new
                {
                    message = "Validation Failure",
                    errors  = new[]
                    {
                        new { field = "creationId", code = "Required" }
                    }
                }
            });

            ValidationException exception;

            using (AdPostingApiClient client = this.Fixture.GetClient(oAuth2Token))
            {
                exception = await Assert.ThrowsAsync <ValidationException>(
                    async() => await client.CreateAdvertisementAsync(new AdvertisementModelBuilder(this.MinimumFieldsInitializer).Build()));
            }

            exception.ShouldBeEquivalentToException(
                new ValidationException(
                    RequestId,
                    HttpMethod.Post,
                    new AdvertisementErrorResponse
            {
                Message = "Validation Failure",
                Errors  = new[] { new AdvertisementError {
                                      Field = "creationId", Code = "Required"
                                  } }
            }));
        }
        public async Task ExpireAdvertisementWithPostVerb()
        {
            const string advertisementId = "8e2fde50-bc5f-4a12-9cfb-812e50500184";
            OAuth2Token  oAuth2Token     = new OAuth2TokenBuilder().Build();
            string       link            = $"{AdvertisementLink}/{advertisementId}";
            string       viewRenderedAdvertisementLink = $"{AdvertisementLink}/{advertisementId}/view";
            DateTime     expiryDate = new DateTime(2015, 10, 7, 21, 19, 00, DateTimeKind.Utc);

            this.Fixture.MockProviderService
            .Given("There is a standout advertisement with maximum data")
            .UponReceiving("a POST advertisement request to expire an advertisement")
            .With(
                new ProviderServiceRequest
            {
                Method  = HttpVerb.Post,
                Path    = link,
                Headers = new Dictionary <string, object>
                {
                    { "Authorization", "Bearer " + oAuth2Token.AccessToken },
                    { "Content-Type", RequestContentTypes.AdvertisementPatchVersion1 },
                    { "Accept", this._acceptHeader },
                    { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
                },
                Body = this._expireRequest
            }
                )
            .WillRespondWith(
                new ProviderServiceResponse
            {
                Status  = 200,
                Headers = new Dictionary <string, object>
                {
                    { "Content-Type", ResponseContentTypes.AdvertisementVersion1 },
                    { "X-Request-Id", RequestId }
                },
                Body = new AdvertisementResponseContentBuilder(this.AllFieldsInitializer)
                       .WithId(advertisementId)
                       .WithState(AdvertisementState.Expired.ToString())
                       .WithLink("self", link)
                       .WithLink("view", viewRenderedAdvertisementLink)
                       .WithExpiryDate(expiryDate)
                       .WithAgentId(null)
                       .WithAdditionalProperties(AdditionalPropertyType.ResidentsOnly.ToString(), AdditionalPropertyType.Graduate.ToString())
                       .Build()
            });

            AdvertisementResource result;
            var requestUri = new Uri(this.Fixture.AdPostingApiServiceBaseUri, link);

            using (var client = new HttpClient())
            {
                using (HttpRequestMessage request = this.CreatePatchRequest(requestUri, this._expireRequest, oAuth2Token.AccessToken, "POST"))
                {
                    using (HttpResponseMessage response = await client.SendAsync(request))
                    {
                        response.EnsureSuccessStatusCode();

                        result = JsonConvert.DeserializeObject <AdvertisementResource>(
                            await response.Content.ReadAsStringAsync(), new ResourceConverter(null, requestUri, response.Headers));
                    }
                }
            }

            AdvertisementResource expectedResult = new AdvertisementResourceBuilder(this.AllFieldsInitializer)
                                                   .WithId(new Guid(advertisementId))
                                                   .WithLinks(advertisementId)
                                                   .WithState(AdvertisementState.Expired)
                                                   .WithExpiryDate(expiryDate)
                                                   .WithAgentId(null)
                                                   .Build();

            result.ShouldBeEquivalentTo(expectedResult);
        }
        public async Task ExpireAdvertisementWhereAdvertiserNotRelatedToRequestor()
        {
            var         advertisementId = new Guid("8e2fde50-bc5f-4a12-9cfb-812e50500184");
            OAuth2Token oAuth2Token     = new OAuth2TokenBuilder().WithAccessToken(AccessTokens.OtherThirdPartyUploader).Build();
            var         link            = $"{AdvertisementLink}/{advertisementId}";

            this.Fixture.MockProviderService
            .Given("There is a standout advertisement with maximum data")
            .UponReceiving("a PATCH advertisement request to expire a job for an advertiser not related to the requestor's account")
            .With(
                new ProviderServiceRequest
            {
                Method  = HttpVerb.Patch,
                Path    = link,
                Headers = new Dictionary <string, object>
                {
                    { "Authorization", "Bearer " + oAuth2Token.AccessToken },
                    { "Content-Type", RequestContentTypes.AdvertisementPatchVersion1 },
                    { "Accept", this._acceptHeader },
                    { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
                },
                Body = new[]
                {
                    new
                    {
                        op    = "replace",
                        path  = "state",
                        value = AdvertisementState.Expired.ToString()
                    }
                }
            }
                )
            .WillRespondWith(
                new ProviderServiceResponse
            {
                Status  = 403,
                Headers = new Dictionary <string, object>
                {
                    { "Content-Type", ResponseContentTypes.AdvertisementErrorVersion1 },
                    { "X-Request-Id", RequestId }
                },
                Body = new
                {
                    message = "Forbidden",
                    errors  = new[] { new { code = "RelationshipError" } }
                }
            });

            UnauthorizedException actualException;

            using (AdPostingApiClient client = this.Fixture.GetClient(oAuth2Token))
            {
                actualException = await Assert.ThrowsAsync <UnauthorizedException>(
                    async() => await client.ExpireAdvertisementAsync(new Uri(this.Fixture.AdPostingApiServiceBaseUri, link)));
            }

            actualException.ShouldBeEquivalentToException(
                new UnauthorizedException(
                    RequestId,
                    403,
                    new AdvertisementErrorResponse
            {
                Message = "Forbidden",
                Errors  = new[] { new Error {
                                      Code = "RelationshipError"
                                  } }
            }));
        }
        public async Task GetExistingAdvertisementWithWarnings()
        {
            const string advertisementId = "8e2fde50-bc5f-4a12-9cfb-812e50500184";

            OAuth2Token oAuth2Token = new OAuth2TokenBuilder().Build();
            var         link        = $"{AdvertisementLink}/{advertisementId}";
            var         viewRenderedAdvertisementLink = $"{AdvertisementLink}/{advertisementId}/view";

            this.Fixture.MockProviderService
            .Given("There is a standout advertisement with maximum data")
            .UponReceiving("a GET advertisement request for an advertisement with warnings")
            .With(new ProviderServiceRequest
            {
                Method  = HttpVerb.Get,
                Path    = link,
                Headers = new Dictionary <string, object>
                {
                    { "Authorization", "Bearer " + oAuth2Token.AccessToken },
                    { "Accept", $"{ResponseContentTypes.AdvertisementVersion1}, {ResponseContentTypes.AdvertisementErrorVersion1}" },
                    { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
                }
            })
            .WillRespondWith(new ProviderServiceResponse
            {
                Status  = 200,
                Headers = new Dictionary <string, object>
                {
                    { "Content-Type", ResponseContentTypes.AdvertisementVersion1 },
                    { "Processing-Status", "Completed" },
                    { "X-Request-Id", RequestId }
                },
                Body = new AdvertisementResponseContentBuilder(AllFieldsInitializer)
                       .WithId(advertisementId)
                       .WithState(AdvertisementState.Open.ToString())
                       .WithLink("self", link)
                       .WithLink("view", viewRenderedAdvertisementLink)
                       .WithWarnings(
                    new { field = "standout.logoId", code = "missing" },
                    new { field = "standout.bullets", code = "missing" })
                       .WithAgentId(null)
                       .WithAdditionalProperties(AdditionalPropertyType.ResidentsOnly.ToString(), AdditionalPropertyType.Graduate.ToString())
                       .Build()
            });

            AdvertisementResource result;

            using (AdPostingApiClient client = this.Fixture.GetClient(oAuth2Token))
            {
                result = await client.GetAdvertisementAsync(new Uri(this.Fixture.AdPostingApiServiceBaseUri, link));
            }

            AdvertisementResource expectedResult = new AdvertisementResourceBuilder(this.AllFieldsInitializer)
                                                   .WithId(new Guid(advertisementId))
                                                   .WithLinks(advertisementId)
                                                   .WithProcessingStatus(ProcessingStatus.Completed)
                                                   .WithWarnings(
                new Error {
                Field = "standout.logoId", Code = "missing"
            },
                new Error {
                Field = "standout.bullets", Code = "missing"
            })
                                                   .WithAgentId(null)
                                                   .Build();

            result.ShouldBeEquivalentTo(expectedResult);
        }
        public async Task GetAllAdvertisementsByAdvertiserNextPage()
        {
            const string advertiserId     = "456";
            const string advertisementId1 = "f7302df2-704b-407c-a42a-62ff822b5461";
            const string beforeJobId      = "5";
            const string queryString      = "advertiserId=" + advertiserId + "&beforeId=" + beforeJobId;
            const string selfLink         = "/advertisement?" + queryString;
            OAuth2Token  oAuth2Token      = new OAuth2TokenBuilder().Build();

            this.Fixture.AdPostingApiService
            .Given("A page size of 3 with more than 1 page of data")
            .UponReceiving("a GET advertisements request for the second page of advertisements belonging to the advertiser")
            .With(new ProviderServiceRequest
            {
                Method  = HttpVerb.Get,
                Path    = "/advertisement",
                Query   = queryString,
                Headers = new Dictionary <string, string>
                {
                    { "Authorization", "Bearer " + oAuth2Token.AccessToken },
                    { "Accept", $"{ResponseContentTypes.AdvertisementListVersion1}, {ResponseContentTypes.AdvertisementErrorVersion1}" },
                    { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
                }
            })
            .WillRespondWith(new ProviderServiceResponse
            {
                Status  = 200,
                Headers = new Dictionary <string, string>
                {
                    { "Content-Type", ResponseContentTypes.AdvertisementListVersion1 },
                    { "X-Request-Id", RequestId }
                },
                Body = new
                {
                    _embedded = new
                    {
                        advertisements = new[]
                        {
                            new AdvertisementSummaryResponseContentBuilder()
                            .WithId(advertisementId1)
                            .WithAdvertiserId(advertiserId)
                            .WithJobTitle("Exciting Developer role in a great CBD location. Great $$")
                            .WithJobReference("JOB1111")
                            .WithResponseLink("self", this.GenerateSelfLink(advertisementId1))
                            .WithResponseLink("view", this.GenerateViewLink(advertisementId1))
                            .Build()
                        }
                    },
                    _links = new
                    {
                        self = new { href = selfLink }
                    }
                }
            });

            AdvertisementSummaryPageResource pageResource = new AdvertisementSummaryPageResource
            {
                Links = new Links(this.Fixture.AdPostingApiServiceBaseUri)
                {
                    { "self", new Link {
                          Href = "/advertisement"
                      } },
                    { "next", new Link {
                          Href = $"/advertisement?advertiserId={advertiserId}&beforeId={beforeJobId}"
                      } }
                }
            };

            var oAuthClient = Mock.Of <IOAuth2TokenClient>(c => c.GetOAuth2TokenAsync() == Task.FromResult(oAuth2Token));
            AdvertisementSummaryPageResource nextPageResource;

            using (var client = new Hal.Client(new HttpClient(new AdPostingApiMessageHandler(new OAuthMessageHandler(oAuthClient)))))
            {
                pageResource.Initialise(client);

                nextPageResource = await pageResource.NextPageAsync();
            }

            AdvertisementSummaryPageResource expectedNextPageResource = new AdvertisementSummaryPageResource
            {
                AdvertisementSummaries = new List <AdvertisementSummaryResource>
                {
                    new AdvertisementSummaryResource
                    {
                        Id           = new Guid(advertisementId1),
                        AdvertiserId = advertiserId,
                        JobReference = "JOB1111",
                        JobTitle     = "Exciting Developer role in a great CBD location. Great $$",
                        Links        = new Links(this.Fixture.AdPostingApiServiceBaseUri)
                        {
                            { "self", new Link {
                                  Href = $"/advertisement/{advertisementId1}"
                              } },
                            { "view", new Link {
                                  Href = $"/advertisement/{advertisementId1}/view"
                              } }
                        }
                    }
                },
                Links = new Links(this.Fixture.AdPostingApiServiceBaseUri)
                {
                    { "self", new Link {
                          Href = selfLink
                      } }
                },
                RequestId = RequestId
            };

            nextPageResource.ShouldBeEquivalentTo(expectedNextPageResource);
        }
Example #9
0
        public async Task UpdateExpiredAdvertisement()
        {
            OAuth2Token oAuth2Token = new OAuth2TokenBuilder().Build();
            var         link        = $"{AdvertisementLink}/c294088d-ff50-4374-bc38-7fa805790e3e";

            this.Fixture.AdPostingApiService
            .Given("There is an expired advertisement")
            .UponReceiving("a PUT advertisement request to update an expired advertisement")
            .With(
                new ProviderServiceRequest
            {
                Method  = HttpVerb.Put,
                Path    = link,
                Headers = new Dictionary <string, string>
                {
                    { "Authorization", "Bearer " + oAuth2Token.AccessToken },
                    { "Content-Type", RequestContentTypes.AdvertisementVersion1 },
                    { "Accept", $"{ResponseContentTypes.AdvertisementVersion1}, {ResponseContentTypes.AdvertisementErrorVersion1}" },
                    { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
                },
                Body = new AdvertisementContentBuilder(this.MinimumFieldsInitializer).Build()
            }
                )
            .WillRespondWith(
                new ProviderServiceResponse
            {
                Status  = 403,
                Headers = new Dictionary <string, string>
                {
                    { "Content-Type", ResponseContentTypes.AdvertisementErrorVersion1 },
                    { "X-Request-Id", RequestId }
                },
                Body = new
                {
                    message = "Forbidden",
                    errors  = new[] { new { code = "Expired" } }
                }
            });

            Advertisement         requestModel = new AdvertisementModelBuilder(this.MinimumFieldsInitializer).Build();
            UnauthorizedException actualException;

            using (AdPostingApiClient client = this.Fixture.GetClient(oAuth2Token))
            {
                actualException = await Assert.ThrowsAsync <UnauthorizedException>(
                    async() => await client.UpdateAdvertisementAsync(new Uri(this.Fixture.AdPostingApiServiceBaseUri, link), requestModel));
            }

            var expectedException =
                new UnauthorizedException(
                    RequestId,
                    403,
                    new AdvertisementErrorResponse
            {
                Message = "Forbidden",
                Errors  = new[] { new AdvertisementError {
                                      Code = "Expired"
                                  } }
            });

            actualException.ShouldBeEquivalentToException(expectedException);
        }
Example #10
0
        public async Task PostAdWithInvalidFieldValues()
        {
            OAuth2Token oAuth2Token = new OAuth2TokenBuilder().Build();

            this.Fixture.RegisterIndexPageInteractions(oAuth2Token);

            this.Fixture.AdPostingApiService
            .UponReceiving("a POST advertisement request to create a job ad with invalid field values")
            .With(
                new ProviderServiceRequest
            {
                Method  = HttpVerb.Post,
                Path    = AdvertisementLink,
                Headers = new Dictionary <string, string>
                {
                    { "Authorization", "Bearer " + oAuth2Token.AccessToken },
                    { "Content-Type", RequestContentTypes.AdvertisementVersion1 },
                    { "Accept", $"{ResponseContentTypes.AdvertisementVersion1}, {ResponseContentTypes.AdvertisementErrorVersion1}" },
                    { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
                },
                Body = new AdvertisementContentBuilder(this.MinimumFieldsInitializer)
                       .WithRequestCreationId("20150914-134527-00109")
                       .WithSalaryMinimum((decimal) - 1.0)
                       .WithSalaryMaximum((decimal)3000.0)
                       .WithSalaryCurrencyCode(1)
                       .WithApplicationEmail("klang(at)seekasia.domain")
                       .WithApplicationFormUrl("htp://ww.seekasia.domain/apply")
                       .WithJobTitle("Temporary part-time libraries North-West inter-library loan business unit administration assistant")
                       .Build()
            }
                )
            .WillRespondWith(
                new ProviderServiceResponse
            {
                Status  = 422,
                Headers = new Dictionary <string, string>
                {
                    { "Content-Type", ResponseContentTypes.AdvertisementErrorVersion1 },
                    { "X-Request-Id", RequestId }
                },
                Body = new
                {
                    message = "Validation Failure",
                    errors  = new[]
                    {
                        new { field = "applicationEmail", code = "InvalidEmailAddress" },
                        new { field = "applicationFormUrl", code = "InvalidUrl" },
                        new { field = "salary.minimum", code = "ValueOutOfRange" },
                        new { field = "jobTitle", code = "MaxLengthExceeded" },
                        new { field = "salary.display", code = "Required" }
                    }
                }
            });

            ValidationException exception;

            using (AdPostingApiClient client = this.Fixture.GetClient(oAuth2Token))
            {
                exception = await Assert.ThrowsAsync <ValidationException>(
                    async() =>
                    await client.CreateAdvertisementAsync(new AdvertisementModelBuilder(this.MinimumFieldsInitializer)
                                                          .WithRequestCreationId("20150914-134527-00109")
                                                          .WithSalaryMinimum((decimal) - 1.0)
                                                          .WithSalaryMaximum((decimal)3000.0)
                                                          .WithSalaryCurrencyCode(1)
                                                          .WithApplicationEmail("klang(at)seekasia.domain")
                                                          .WithApplicationFormUrl("htp://ww.seekasia.domain/apply")
                                                          .WithJobTitle("Temporary part-time libraries North-West inter-library loan business unit administration assistant")
                                                          .Build()));
            }

            var expectedException =
                new ValidationException(
                    RequestId,
                    HttpMethod.Post,
                    new AdvertisementErrorResponse
            {
                Message = "Validation Failure",
                Errors  = new[]
                {
                    new AdvertisementError {
                        Field = "applicationEmail", Code = "InvalidEmailAddress"
                    },
                    new AdvertisementError {
                        Field = "applicationFormUrl", Code = "InvalidUrl"
                    },
                    new AdvertisementError {
                        Field = "salary.minimum", Code = "ValueOutOfRange"
                    },
                    new AdvertisementError {
                        Field = "jobTitle", Code = "MaxLengthExceeded"
                    },
                    new AdvertisementError {
                        Field = "salary.display", Code = "Required"
                    }
                }
            });

            exception.ShouldBeEquivalentToException(expectedException);
        }
Example #11
0
        public async Task UpdateAdWhereAdvertiserNotRelatedToRequestor()
        {
            var oAuth2Token = new OAuth2TokenBuilder().WithAccessToken(AccessTokens.OtherThirdPartyUploader).Build();
            var link        = $"{AdvertisementLink}/{AdvertisementId}";

            this.Fixture.AdPostingApiService
            .Given("There is a standout advertisement with maximum data")
            .UponReceiving("a PUT advertisement request to update a job for an advertiser not related to the requestor's account")
            .With(
                new ProviderServiceRequest
            {
                Method  = HttpVerb.Put,
                Path    = link,
                Headers = new Dictionary <string, string>
                {
                    { "Authorization", "Bearer " + oAuth2Token.AccessToken },
                    { "Content-Type", RequestContentTypes.AdvertisementVersion1 },
                    { "Accept", $"{ResponseContentTypes.AdvertisementVersion1}, {ResponseContentTypes.AdvertisementErrorVersion1}" },
                    { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
                },
                Body = new AdvertisementContentBuilder(this.AllFieldsInitializer)
                       .Build()
            }
                )
            .WillRespondWith(
                new ProviderServiceResponse
            {
                Status  = 403,
                Headers = new Dictionary <string, string>
                {
                    { "Content-Type", ResponseContentTypes.AdvertisementErrorVersion1 },
                    { "X-Request-Id", RequestId }
                },
                Body = new
                {
                    message = "Forbidden",
                    errors  = new[] { new { code = "RelationshipError" } }
                }
            });

            var requestModel = new AdvertisementModelBuilder(this.AllFieldsInitializer).Build();

            UnauthorizedException actualException;

            using (AdPostingApiClient client = this.Fixture.GetClient(oAuth2Token))
            {
                actualException = await Assert.ThrowsAsync <UnauthorizedException>(
                    async() => await client.UpdateAdvertisementAsync(new Uri(this.Fixture.AdPostingApiServiceBaseUri, link), requestModel));
            }

            actualException.ShouldBeEquivalentToException(
                new UnauthorizedException(
                    RequestId,
                    403,
                    new AdvertisementErrorResponse
            {
                Message = "Forbidden",
                Errors  = new[] { new AdvertisementError {
                                      Code = "RelationshipError"
                                  } }
            }));
        }
Example #12
0
        public async Task UpdateWithInvalidAdvertisementDetailsWithCleanseJobAdDetailsOption()
        {
            OAuth2Token oAuth2Token = new OAuth2TokenBuilder().Build();
            var         link        = $"{AdvertisementLink}/{AdvertisementId}";
            var         viewRenderedAdvertisementLink = $"{AdvertisementLink}/{AdvertisementId}/view";
            var         adDetailsBeforeCleanse        = "<p style=\"text-align:justify; font-family:'Comic Sans MS', cursive, sans-serif\">Whimsical</p>";
            var         adDetailsAfterCleanse         = "<p style=\"text-align:justify\">Whimsical</p>";

            this.Fixture.AdPostingApiService
            .Given("There is a standout advertisement with maximum data")
            .UponReceiving("a PUT advertisement request for advertisement with invalid advertisement details and with 'CleanseJobAdDetails' processing option")
            .With(new ProviderServiceRequest
            {
                Method  = HttpVerb.Put,
                Path    = link,
                Headers = new Dictionary <string, string>
                {
                    { "Authorization", "Bearer " + oAuth2Token.AccessToken },
                    { "Content-Type", RequestContentTypes.AdvertisementVersion1 },
                    { "Accept", $"{ResponseContentTypes.AdvertisementVersion1}, {ResponseContentTypes.AdvertisementErrorVersion1}" },
                    { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
                },
                Body = new AdvertisementContentBuilder(this.MinimumFieldsInitializer)
                       .WithAdvertisementType(AdvertisementType.StandOut.ToString())
                       .WithAdditionalProperties(AdditionalPropertyType.Graduate.ToString())
                       .WithAdvertisementDetails(adDetailsBeforeCleanse)
                       .WithProcessingOptions(ProcessingOptionsType.CleanseAdvertisementDetails.ToString())
                       .Build()
            })
            .WillRespondWith(
                new ProviderServiceResponse
            {
                Status  = 200,
                Headers = new Dictionary <string, string>
                {
                    { "Content-Type", ResponseContentTypes.AdvertisementVersion1 },
                    { "X-Request-Id", RequestId }
                },
                Body = new AdvertisementResponseContentBuilder(this.MinimumFieldsInitializer)
                       .WithState(AdvertisementState.Open.ToString())
                       .WithId(AdvertisementId)
                       .WithLink("self", link)
                       .WithLink("view", viewRenderedAdvertisementLink)
                       .WithAdvertisementType(AdvertisementType.StandOut.ToString())
                       .WithAdditionalProperties(AdditionalPropertyType.Graduate.ToString())
                       .WithAdvertisementDetails(adDetailsAfterCleanse)
                       .Build()
            });

            AdvertisementResource result;

            using (AdPostingApiClient client = this.Fixture.GetClient(oAuth2Token))
            {
                result = await client.UpdateAdvertisementAsync(new Uri(this.Fixture.AdPostingApiServiceBaseUri, link),
                                                               new AdvertisementModelBuilder(this.MinimumFieldsInitializer)
                                                               .WithAdvertisementType(AdvertisementType.StandOut)
                                                               .WithAdditionalProperties(AdditionalPropertyType.Graduate)
                                                               .WithAdvertisementDetails(adDetailsBeforeCleanse)
                                                               .WithProcessingOptions(ProcessingOptionsType.CleanseAdvertisementDetails)
                                                               .Build());
            }

            var expectedResult = new AdvertisementResourceBuilder(this.MinimumFieldsInitializer)
                                 .WithId(new Guid(AdvertisementId))
                                 .WithLinks(AdvertisementId)
                                 .WithAdvertisementType(AdvertisementType.StandOut)
                                 .WithAdditionalProperties(AdditionalPropertyType.Graduate)
                                 .WithAdvertisementDetails(adDetailsAfterCleanse)
                                 .Build();

            result.ShouldBeEquivalentTo(expectedResult);
        }
Example #13
0
        public async Task UpdateWithInvalidAdvertisementDetails()
        {
            OAuth2Token oAuth2Token = new OAuth2TokenBuilder().Build();
            var         link        = $"{AdvertisementLink}/{AdvertisementId}";

            this.Fixture.AdPostingApiService
            .Given("There is a standout advertisement with maximum data")
            .UponReceiving("a PUT advertisement request for advertisement with invalid advertisement details")
            .With(new ProviderServiceRequest
            {
                Method  = HttpVerb.Put,
                Path    = link,
                Headers = new Dictionary <string, string>
                {
                    { "Authorization", "Bearer " + oAuth2Token.AccessToken },
                    { "Content-Type", RequestContentTypes.AdvertisementVersion1 },
                    { "Accept", $"{ResponseContentTypes.AdvertisementVersion1}, {ResponseContentTypes.AdvertisementErrorVersion1}" },
                    { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
                },
                Body = new AdvertisementContentBuilder(this.MinimumFieldsInitializer)
                       .WithAdvertisementDetails("Ad details with <a href='www.youtube.com'>a link</a> and incomplete <h2> element")
                       .Build()
            })
            .WillRespondWith(
                new ProviderServiceResponse
            {
                Status  = 422,
                Headers = new Dictionary <string, string>
                {
                    { "Content-Type", ResponseContentTypes.AdvertisementErrorVersion1 },
                    { "X-Request-Id", RequestId }
                },
                Body = new
                {
                    message = "Validation Failure",
                    errors  = new[] { new { field = "advertisementDetails", code = "InvalidFormat" } }
                }
            });

            ValidationException actualException;

            using (AdPostingApiClient client = this.Fixture.GetClient(oAuth2Token))
            {
                actualException = await Assert.ThrowsAsync <ValidationException>(
                    async() => await client.UpdateAdvertisementAsync(new Uri(this.Fixture.AdPostingApiServiceBaseUri, link),
                                                                     new AdvertisementModelBuilder(this.MinimumFieldsInitializer)
                                                                     .WithAdvertisementDetails("Ad details with <a href='www.youtube.com'>a link</a> and incomplete <h2> element")
                                                                     .Build()));
            }

            var expectedException =
                new ValidationException(
                    RequestId,
                    HttpMethod.Put,
                    new AdvertisementErrorResponse
            {
                Message = "Validation Failure",
                Errors  = new[] { new AdvertisementError {
                                      Field = "advertisementDetails", Code = "InvalidFormat"
                                  } }
            });

            actualException.ShouldBeEquivalentToException(expectedException);
        }
Example #14
0
        public async Task PostAdWithDuplicateTemplateCustomFieldNames()
        {
            OAuth2Token oAuth2Token = new OAuth2TokenBuilder().Build();

            this.Fixture.RegisterIndexPageInteractions(oAuth2Token);

            this.Fixture.AdPostingApiService
            .UponReceiving("a POST advertisement request to create a job ad with duplicated names for template custom fields")
            .With(
                new ProviderServiceRequest
            {
                Method  = HttpVerb.Post,
                Path    = AdvertisementLink,
                Headers = new Dictionary <string, string>
                {
                    { "Authorization", "Bearer " + oAuth2Token.AccessToken },
                    { "Content-Type", RequestContentTypes.AdvertisementVersion1 },
                    { "Accept", $"{ResponseContentTypes.AdvertisementVersion1}, {ResponseContentTypes.AdvertisementErrorVersion1}" },
                    { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
                },
                Body = new AdvertisementContentBuilder(this.MinimumFieldsInitializer)
                       .WithRequestCreationId(CreationIdForAdWithDuplicateTemplateCustomFields)
                       .WithTemplateItems(
                    new KeyValuePair <object, object>("FieldNameA", "Template Value 1"),
                    new KeyValuePair <object, object>("FieldNameB", "Template Value 2"),
                    new KeyValuePair <object, object>("FieldNameA", "Template Value 3"))
                       .Build()
            }
                )
            .WillRespondWith(
                new ProviderServiceResponse
            {
                Status  = 422,
                Headers = new Dictionary <string, string>
                {
                    { "Content-Type", ResponseContentTypes.AdvertisementErrorVersion1 },
                    { "X-Request-Id", RequestId }
                },
                Body = new
                {
                    message = "Validation Failure",
                    errors  = new[]
                    {
                        new { field = "template.items[0]", code = "AlreadySpecified" },
                        new { field = "template.items[2]", code = "AlreadySpecified" }
                    }
                }
            });
            ValidationException exception;

            using (AdPostingApiClient client = this.Fixture.GetClient(oAuth2Token))
            {
                exception = await Assert.ThrowsAsync <ValidationException>(
                    async() =>
                    await client.CreateAdvertisementAsync(new AdvertisementModelBuilder(this.MinimumFieldsInitializer)
                                                          .WithRequestCreationId(CreationIdForAdWithDuplicateTemplateCustomFields)
                                                          .WithTemplateItems(
                                                              new TemplateItem {
                    Name = "FieldNameA", Value = "Template Value 1"
                },
                                                              new TemplateItem {
                    Name = "FieldNameB", Value = "Template Value 2"
                },
                                                              new TemplateItem {
                    Name = "FieldNameA", Value = "Template Value 3"
                })
                                                          .Build()));
            }

            var expectedException = new ValidationException(
                RequestId,
                HttpMethod.Post,
                new AdvertisementErrorResponse
            {
                Message = "Validation Failure",
                Errors  = new[]
                {
                    new AdvertisementError {
                        Field = "template.items[0]", Code = "AlreadySpecified"
                    },
                    new AdvertisementError {
                        Field = "template.items[2]", Code = "AlreadySpecified"
                    }
                }
            });

            exception.ShouldBeEquivalentToException(expectedException);
        }
Example #15
0
        public async Task GetAllAdvertisementsNextPage()
        {
            const string advertisementId1 = "fa6939b5-c91f-4f6a-9600-1ea74963fbb2";
            const string advertisementId2 = "f7302df2-704b-407c-a42a-62ff822b5461";
            const string advertisementId3 = "3b138935-f65b-4ec7-91d8-fc250757b53d";
            const string beforeJobId      = "6";
            OAuth2Token  oAuth2Token      = new OAuth2TokenBuilder().Build();

            this.Fixture.MockProviderService
            .Given("A page size of 3 with more than 1 page of data")
            .UponReceiving("a GET advertisements request for the last page of data")
            .With(new ProviderServiceRequest
            {
                Method  = HttpVerb.Get,
                Path    = "/advertisement",
                Query   = "beforeId=" + beforeJobId,
                Headers = new Dictionary <string, object>
                {
                    { "Authorization", "Bearer " + oAuth2Token.AccessToken },
                    { "Accept", $"{ResponseContentTypes.AdvertisementListVersion1}, {ResponseContentTypes.AdvertisementErrorVersion1}" },
                    { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
                }
            })
            .WillRespondWith(new ProviderServiceResponse
            {
                Status  = 200,
                Headers = new Dictionary <string, object>
                {
                    { "Content-Type", ResponseContentTypes.AdvertisementListVersion1 },
                    { "X-Request-Id", RequestId }
                },
                Body = new
                {
                    _embedded = new
                    {
                        advertisements = new[]
                        {
                            new AdvertisementSummaryResponseContentBuilder()
                            .WithId(advertisementId3)
                            .WithAdvertiserId("456")
                            .WithJobTitle("Exciting tester role in a great CBD location. Great $$")
                            .WithJobReference("JOB2222")
                            .WithResponseLink("self", this.GenerateSelfLink(advertisementId3))
                            .WithResponseLink("view", this.GenerateViewLink(advertisementId3))
                            .Build(),
                            new AdvertisementSummaryResponseContentBuilder()
                            .WithId(advertisementId2)
                            .WithAdvertiserId("456")
                            .WithJobTitle("Exciting Developer role in a great CBD location. Great $$")
                            .WithJobReference("JOB1111")
                            .WithResponseLink("self", this.GenerateSelfLink(advertisementId2))
                            .WithResponseLink("view", this.GenerateViewLink(advertisementId2))
                            .Build(),
                            new AdvertisementSummaryResponseContentBuilder()
                            .WithId(advertisementId1)
                            .WithAdvertiserId("123")
                            .WithJobTitle("Exciting Developer role in a great CBD location. Great $$")
                            .WithJobReference("JOB1234")
                            .WithResponseLink("self", this.GenerateSelfLink(advertisementId1))
                            .WithResponseLink("view", this.GenerateViewLink(advertisementId1))
                            .Build()
                        }
                    },
                    _links = new
                    {
                        self = new { href = $"/advertisement?beforeId={beforeJobId}" }
                    }
                }
            });

            AdvertisementSummaryPageResource pageResource = new AdvertisementSummaryPageResource
            {
                Links = new Links(this.Fixture.AdPostingApiServiceBaseUri)
                {
                    { "self", new Link {
                          Href = "/advertisement"
                      } },
                    { "next", new Link {
                          Href = $"/advertisement?beforeId={beforeJobId}"
                      } }
                }
            };

            var oAuthClient = Mock.Of <IOAuth2TokenClient>(c => c.GetOAuth2TokenAsync() == Task.FromResult(oAuth2Token));
            AdvertisementSummaryPageResource nextPageResource;

            HttpMessageHandler pipeline = new HttpClientHandler()
                                          .DecorateWith(new OAuthMessageHandler(oAuthClient))
                                          .DecorateWith(new AdPostingApiMessageHandler());

            using (var client = new Hal.Client(new HttpClient(pipeline)))
            {
                pageResource.Initialise(client);

                nextPageResource = await pageResource.NextPageAsync();
            }

            AdvertisementSummaryPageResource expectedNextPageResource = new AdvertisementSummaryPageResource
            {
                AdvertisementSummaries = new List <AdvertisementSummaryResource>
                {
                    new AdvertisementSummaryResource
                    {
                        Id           = new Guid(advertisementId3),
                        AdvertiserId = "456",
                        JobReference = "JOB2222",
                        JobTitle     = "Exciting tester role in a great CBD location. Great $$",
                        Links        = new Links(this.Fixture.AdPostingApiServiceBaseUri)
                        {
                            { "self", new Link {
                                  Href = $"/advertisement/{advertisementId3}"
                              } },
                            { "view", new Link {
                                  Href = $"/advertisement/{advertisementId3}/view"
                              } }
                        }
                    },
                    new AdvertisementSummaryResource
                    {
                        Id           = new Guid(advertisementId2),
                        AdvertiserId = "456",
                        JobReference = "JOB1111",
                        JobTitle     = "Exciting Developer role in a great CBD location. Great $$",
                        Links        = new Links(this.Fixture.AdPostingApiServiceBaseUri)
                        {
                            { "self", new Link {
                                  Href = $"/advertisement/{advertisementId2}"
                              } },
                            { "view", new Link {
                                  Href = $"/advertisement/{advertisementId2}/view"
                              } }
                        }
                    },
                    new AdvertisementSummaryResource
                    {
                        Id           = new Guid(advertisementId1),
                        AdvertiserId = "123",
                        JobReference = "JOB1234",
                        JobTitle     = "Exciting Developer role in a great CBD location. Great $$",
                        Links        = new Links(this.Fixture.AdPostingApiServiceBaseUri)
                        {
                            { "self", new Link {
                                  Href = $"/advertisement/{advertisementId1}"
                              } },
                            { "view", new Link {
                                  Href = $"/advertisement/{advertisementId1}/view"
                              } }
                        }
                    }
                },
                Links = new Links(this.Fixture.AdPostingApiServiceBaseUri)
                {
                    { "self", new Link {
                          Href = $"/advertisement?beforeId={beforeJobId}"
                      } }
                },
                RequestId = RequestId
            };

            nextPageResource.ShouldBeEquivalentTo(expectedNextPageResource);
        }
Example #16
0
        public async Task PostAdWithGranularLocation()
        {
            const string advertisementId = "75b2b1fc-9050-4f45-a632-ec6b7ac2bb4a";
            OAuth2Token  oAuth2Token     = new OAuth2TokenBuilder().Build();
            var          link            = $"{AdvertisementLink}/{advertisementId}";
            var          viewRenderedAdvertisementLink = $"{AdvertisementLink}/{advertisementId}/view";
            var          location = $"http://localhost{link}";

            this.Fixture.RegisterIndexPageInteractions(oAuth2Token);

            var allFieldsWithGranularLocationInitializer = new AllFieldsInitializer(LocationType.UseGranularLocation);

            this.Fixture.AdPostingApiService
            .UponReceiving("a POST advertisement request to create a job ad with granular location")
            .With(
                new ProviderServiceRequest
            {
                Method  = HttpVerb.Post,
                Path    = AdvertisementLink,
                Headers = new Dictionary <string, string>
                {
                    { "Authorization", "Bearer " + oAuth2Token.AccessToken },
                    { "Content-Type", RequestContentTypes.AdvertisementVersion1 },
                    { "Accept", $"{ResponseContentTypes.AdvertisementVersion1}, {ResponseContentTypes.AdvertisementErrorVersion1}" },
                    { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
                },
                Body = new AdvertisementContentBuilder(allFieldsWithGranularLocationInitializer)
                       .WithRequestCreationId(CreationIdForAdWithMinimumRequiredData)
                       .Build()
            }
                )
            .WillRespondWith(
                new ProviderServiceResponse
            {
                Status  = 200,
                Headers = new Dictionary <string, string>
                {
                    { "Content-Type", ResponseContentTypes.AdvertisementVersion1 },
                    { "Location", location },
                    { "X-Request-Id", RequestId }
                },
                Body = new AdvertisementResponseContentBuilder(allFieldsWithGranularLocationInitializer)
                       .WithId(advertisementId)
                       .WithState(AdvertisementState.Open.ToString())
                       .WithLink("self", link)
                       .WithLink("view", viewRenderedAdvertisementLink)
                       .WithGranularLocationState(null)
                       .Build()
            });

            var requestModel = new AdvertisementModelBuilder(allFieldsWithGranularLocationInitializer)
                               .WithRequestCreationId(CreationIdForAdWithMinimumRequiredData)
                               .Build();

            AdvertisementResource result;

            using (AdPostingApiClient client = this.Fixture.GetClient(oAuth2Token))
            {
                result = await client.CreateAdvertisementAsync(requestModel);
            }

            AdvertisementResource expectedResult = new AdvertisementResourceBuilder(allFieldsWithGranularLocationInitializer)
                                                   .WithId(new Guid(advertisementId))
                                                   .WithLinks(advertisementId)
                                                   .WithGranularLocationState(null)
                                                   .Build();

            result.ShouldBeEquivalentTo(expectedResult);
        }
Example #17
0
        public async Task PostAdWithInvalidFieldValues()
        {
            OAuth2Token oAuth2Token = new OAuth2TokenBuilder().Build();

            this.Fixture.RegisterIndexPageInteractions(oAuth2Token);

            this.Fixture.AdPostingApiService
            .UponReceiving("a POST advertisement request to create a job ad with invalid field values")
            .With(
                new ProviderServiceRequest
            {
                Method  = HttpVerb.Post,
                Path    = AdvertisementLink,
                Headers = new Dictionary <string, string>
                {
                    { "Authorization", "Bearer " + oAuth2Token.AccessToken },
                    { "Content-Type", RequestContentTypes.AdvertisementVersion1 },
                    { "Accept", $"{ResponseContentTypes.AdvertisementVersion1}, {ResponseContentTypes.AdvertisementErrorVersion1}" },
                    { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
                },
                Body = new AdvertisementContentBuilder(this.MinimumFieldsInitializer)
                       .WithRequestCreationId("20150914-134527-00109")
                       .WithAdvertisementType(AdvertisementType.StandOut.ToString())
                       .WithSalaryMinimum(-1.0)
                       .WithStandoutBullets("new Uzi", "new Remington Model".PadRight(85, '!'), "new AK-47")
                       .WithApplicationEmail("someone(at)some.domain")
                       .WithApplicationFormUrl("htp://somecompany.domain/apply")
                       .WithTemplateItems(
                    new KeyValuePair <object, object>("Template Line 1", "Template Value 1"),
                    new KeyValuePair <object, object>("", "value2"))
                       .Build()
            }
                )
            .WillRespondWith(
                new ProviderServiceResponse
            {
                Status  = 422,
                Headers = new Dictionary <string, string>
                {
                    { "Content-Type", ResponseContentTypes.AdvertisementErrorVersion1 },
                    { "X-Request-Id", RequestId }
                },
                Body = new
                {
                    message = "Validation Failure",
                    errors  = new[]
                    {
                        new { field = "applicationEmail", code = "InvalidEmailAddress" },
                        new { field = "applicationFormUrl", code = "InvalidUrl" },
                        new { field = "salary.minimum", code = "ValueOutOfRange" },
                        new { field = "standout.bullets[1]", code = "MaxLengthExceeded" },
                        new { field = "template.items[1].name", code = "Required" }
                    }
                }
            });

            ValidationException exception;

            using (AdPostingApiClient client = this.Fixture.GetClient(oAuth2Token))
            {
                exception = await Assert.ThrowsAsync <ValidationException>(
                    async() =>
                    await client.CreateAdvertisementAsync(new AdvertisementModelBuilder(this.MinimumFieldsInitializer)
                                                          .WithRequestCreationId("20150914-134527-00109")
                                                          .WithAdvertisementType(AdvertisementType.StandOut)
                                                          .WithSalaryMinimum(-1)
                                                          .WithStandoutBullets("new Uzi", "new Remington Model".PadRight(85, '!'), "new AK-47")
                                                          .WithApplicationEmail("someone(at)some.domain")
                                                          .WithApplicationFormUrl("htp://somecompany.domain/apply")
                                                          .WithTemplateItems(
                                                              new TemplateItem {
                    Name = "Template Line 1", Value = "Template Value 1"
                },
                                                              new TemplateItem {
                    Name = "", Value = "value2"
                })
                                                          .Build()));
            }

            var expectedException =
                new ValidationException(
                    RequestId,
                    HttpMethod.Post,
                    new AdvertisementErrorResponse
            {
                Message = "Validation Failure",
                Errors  = new[]
                {
                    new AdvertisementError {
                        Field = "applicationEmail", Code = "InvalidEmailAddress"
                    },
                    new AdvertisementError {
                        Field = "applicationFormUrl", Code = "InvalidUrl"
                    },
                    new AdvertisementError {
                        Field = "salary.minimum", Code = "ValueOutOfRange"
                    },
                    new AdvertisementError {
                        Field = "standout.bullets[1]", Code = "MaxLengthExceeded"
                    },
                    new AdvertisementError {
                        Field = "template.items[1].name", Code = "Required"
                    }
                }
            });

            exception.ShouldBeEquivalentToException(expectedException);
        }
        public async Task GetAllAdvertisementsFirstPage()
        {
            const string advertisementId3        = "9141cf19-b8d7-4380-9e3f-3b5c22783bdc";
            const string advertisementId2        = "7bbe4318-fd3b-4d26-8384-d41489ff1dd0";
            const string advertisementId1        = "e6e31b9c-3c2c-4b85-b17f-babbf7da972b";
            const string advertisement3Title     = "More Exciting Senior Developer role in a great CBD location. Great $$$";
            const string advertisement2Title     = "More Exciting Senior Tester role in a great CBD location. Great $$$";
            const string advertisement1Title     = "More Exciting Senior Developer role in a great CBD location. Great $$$";
            const string advertisement3Reference = "JOB4444";
            const string advertisement2Reference = "JOB3333";
            const string advertisement1Reference = "JOB12345";
            const string beforeJobId             = "6";
            const string nextLink    = "/advertisement?beforeId=" + beforeJobId;
            const string selfLink    = "/advertisement";
            OAuth2Token  oAuth2Token = new OAuth2TokenBuilder().Build();

            this.Fixture.RegisterIndexPageInteractions(oAuth2Token);

            this.Fixture.AdPostingApiService
            .Given("A page size of 3 with more than 1 page of data")
            .UponReceiving("a GET advertisements request for first page of data")
            .With(new ProviderServiceRequest
            {
                Method  = HttpVerb.Get,
                Path    = "/advertisement",
                Headers = new Dictionary <string, string>
                {
                    { "Authorization", "Bearer " + oAuth2Token.AccessToken },
                    { "Accept", $"{ResponseContentTypes.AdvertisementListVersion1}, {ResponseContentTypes.AdvertisementErrorVersion1}" },
                    { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
                }
            })
            .WillRespondWith(new ProviderServiceResponse
            {
                Status  = 200,
                Headers = new Dictionary <string, string>
                {
                    { "Content-Type", ResponseContentTypes.AdvertisementListVersion1 },
                    { "X-Request-Id", RequestId }
                },
                Body = new
                {
                    _embedded = new
                    {
                        advertisements = new[]
                        {
                            new AdvertisementSummaryResponseContentBuilder()
                            .WithId(advertisementId3)
                            .WithAdvertiserId("456")
                            .WithJobTitle(advertisement3Title)
                            .WithJobReference(advertisement3Reference)
                            .WithResponseLink("self", this.GenerateSelfLink(advertisementId3))
                            .WithResponseLink("view", this.GenerateViewLink(advertisementId3))
                            .Build(),
                            new AdvertisementSummaryResponseContentBuilder()
                            .WithId(advertisementId2)
                            .WithAdvertiserId("456")
                            .WithJobTitle(advertisement2Title)
                            .WithJobReference(advertisement2Reference)
                            .WithResponseLink("self", this.GenerateSelfLink(advertisementId2))
                            .WithResponseLink("view", this.GenerateViewLink(advertisementId2))
                            .Build(),
                            new AdvertisementSummaryResponseContentBuilder()
                            .WithId(advertisementId1)
                            .WithAdvertiserId("345")
                            .WithJobTitle(advertisement1Title)
                            .WithJobReference(advertisement1Reference)
                            .WithResponseLink("self", this.GenerateSelfLink(advertisementId1))
                            .WithResponseLink("view", this.GenerateViewLink(advertisementId1))
                            .Build()
                        }
                    },
                    _links = new
                    {
                        self = new { href = selfLink },
                        next = new { href = nextLink }
                    }
                }
            });

            AdvertisementSummaryPageResource pageResource;

            using (AdPostingApiClient client = this.Fixture.GetClient(oAuth2Token))
            {
                pageResource = await client.GetAllAdvertisementsAsync();
            }

            AdvertisementSummaryPageResource expectedPageResource = new AdvertisementSummaryPageResource
            {
                AdvertisementSummaries = new List <AdvertisementSummaryResource>
                {
                    new AdvertisementSummaryResource
                    {
                        Id           = new Guid(advertisementId3),
                        AdvertiserId = "456",
                        JobReference = advertisement3Reference,
                        JobTitle     = advertisement3Title,
                        Links        = new Links(this.Fixture.AdPostingApiServiceBaseUri)
                        {
                            { "self", new Link {
                                  Href = $"/advertisement/{advertisementId3}"
                              } },
                            { "view", new Link {
                                  Href = $"/advertisement/{advertisementId3}/view"
                              } }
                        }
                    },
                    new AdvertisementSummaryResource
                    {
                        Id           = new Guid(advertisementId2),
                        AdvertiserId = "456",
                        JobReference = advertisement2Reference,
                        JobTitle     = advertisement2Title,
                        Links        = new Links(this.Fixture.AdPostingApiServiceBaseUri)
                        {
                            { "self", new Link {
                                  Href = $"/advertisement/{advertisementId2}"
                              } },
                            { "view", new Link {
                                  Href = $"/advertisement/{advertisementId2}/view"
                              } }
                        }
                    },
                    new AdvertisementSummaryResource
                    {
                        Id           = new Guid(advertisementId1),
                        AdvertiserId = "345",
                        JobReference = advertisement1Reference,
                        JobTitle     = advertisement1Title,
                        Links        = new Links(this.Fixture.AdPostingApiServiceBaseUri)
                        {
                            { "self", new Link {
                                  Href = $"/advertisement/{advertisementId1}"
                              } },
                            { "view", new Link {
                                  Href = $"/advertisement/{advertisementId1}/view"
                              } }
                        }
                    }
                },
                Links = new Links(this.Fixture.AdPostingApiServiceBaseUri)
                {
                    { "self", new Link {
                          Href = "/advertisement"
                      } },
                    { "next", new Link {
                          Href = "/advertisement?beforeId=" + beforeJobId
                      } }
                },
                RequestId = RequestId
            };

            pageResource.ShouldBeEquivalentTo(expectedPageResource);
        }
Example #19
0
        public async Task PostAdWithInvalidAdvertisementDetails()
        {
            OAuth2Token oAuth2Token = new OAuth2TokenBuilder().Build();

            this.Fixture.RegisterIndexPageInteractions(oAuth2Token);

            this.Fixture.AdPostingApiService
            .UponReceiving("a POST advertisement request to create a job ad with invalid advertisement details")
            .With(
                new ProviderServiceRequest
            {
                Method  = HttpVerb.Post,
                Path    = AdvertisementLink,
                Headers = new Dictionary <string, string>
                {
                    { "Authorization", "Bearer " + oAuth2Token.AccessToken },
                    { "Content-Type", RequestContentTypes.AdvertisementVersion1 },
                    { "Accept", $"{ResponseContentTypes.AdvertisementVersion1}, {ResponseContentTypes.AdvertisementErrorVersion1}" },
                    { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
                },
                Body = new AdvertisementContentBuilder(this.MinimumFieldsInitializer)
                       .WithRequestCreationId("20150914-134527-00109")
                       .WithAdvertisementDetails("Ad details with <a href='www.youtube.com'>a link</a> and incomplete <h2> element")
                       .Build()
            }
                )
            .WillRespondWith(
                new ProviderServiceResponse
            {
                Status  = 422,
                Headers = new Dictionary <string, string>
                {
                    { "Content-Type", ResponseContentTypes.AdvertisementErrorVersion1 },
                    { "X-Request-Id", RequestId }
                },
                Body = new
                {
                    message = "Validation Failure",
                    errors  = new[]
                    {
                        new { field = "advertisementDetails", code = "InvalidFormat" }
                    }
                }
            });

            ValidationException exception;

            using (AdPostingApiClient client = this.Fixture.GetClient(oAuth2Token))
            {
                exception = await Assert.ThrowsAsync <ValidationException>(
                    async() =>
                    await client.CreateAdvertisementAsync(new AdvertisementModelBuilder(this.MinimumFieldsInitializer)
                                                          .WithRequestCreationId("20150914-134527-00109")
                                                          .WithAdvertisementDetails("Ad details with <a href='www.youtube.com'>a link</a> and incomplete <h2> element")
                                                          .Build()));
            }

            var expectedException =
                new ValidationException(
                    RequestId,
                    HttpMethod.Post,
                    new AdvertisementErrorResponse
            {
                Message = "Validation Failure",
                Errors  = new[] { new AdvertisementError {
                                      Field = "advertisementDetails", Code = "InvalidFormat"
                                  } }
            });

            exception.ShouldBeEquivalentToException(expectedException);
        }
        public async Task ExpireAlreadyExpiredAdvertisement()
        {
            var         advertisementId = new Guid("c294088d-ff50-4374-bc38-7fa805790e3e");
            OAuth2Token oAuth2Token     = new OAuth2TokenBuilder().Build();
            var         link            = $"{AdvertisementLink}/{advertisementId}";

            this.Fixture.MockProviderService
            .Given("There is an expired advertisement")
            .UponReceiving("a PATCH advertisement request to expire an advertisement")
            .With(
                new ProviderServiceRequest
            {
                Method  = HttpVerb.Patch,
                Path    = link,
                Headers = new Dictionary <string, object>
                {
                    { "Authorization", "Bearer " + oAuth2Token.AccessToken },
                    { "Content-Type", RequestContentTypes.AdvertisementPatchVersion1 },
                    { "Accept", this._acceptHeader },
                    { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
                },
                Body = new[]
                {
                    new
                    {
                        op    = "replace",
                        path  = "state",
                        value = AdvertisementState.Expired.ToString()
                    }
                }
            }
                )
            .WillRespondWith(
                new ProviderServiceResponse
            {
                Status  = 403,
                Headers = new Dictionary <string, object>
                {
                    { "Content-Type", ResponseContentTypes.AdvertisementErrorVersion1 },
                    { "X-Request-Id", RequestId }
                },
                Body = new
                {
                    message = "Forbidden",
                    errors  = new[] { new { code = "Expired" } }
                }
            });

            UnauthorizedException actualException;

            using (AdPostingApiClient client = this.Fixture.GetClient(oAuth2Token))
            {
                actualException = await Assert.ThrowsAsync <UnauthorizedException>(
                    async() => await client.ExpireAdvertisementAsync(new Uri(this.Fixture.AdPostingApiServiceBaseUri, link)));
            }

            var expectedException =
                new UnauthorizedException(
                    RequestId,
                    403,
                    new AdvertisementErrorResponse
            {
                Message = "Forbidden",
                Errors  = new[] { new Error {
                                      Code = "Expired"
                                  } }
            });

            actualException.ShouldBeEquivalentToException(expectedException);
        }
Example #21
0
        public async Task PostAdWithInvalidAdvertisementDetailsWithCleanseJobAdDetailsOption()
        {
            const string advertisementId = "75b2b1fc-9050-4f45-a632-ec6b7ac2bb4a";
            OAuth2Token  oAuth2Token     = new OAuth2TokenBuilder().Build();
            var          link            = $"{AdvertisementLink}/{advertisementId}";
            var          viewRenderedAdvertisementLink = $"{AdvertisementLink}/{advertisementId}/view";
            var          location = $"http://localhost{link}";
            var          adDetailsBeforeCleanse = "<p style=\"text-align:justify; color:#FF00AA\">Colourful</p>";
            var          adDetailsAfterCleanse  = "<p style=\"text-align:justify\">Colourful</p>";

            this.Fixture.RegisterIndexPageInteractions(oAuth2Token);

            this.Fixture.AdPostingApiService
            .UponReceiving("a POST advertisement request to create a job ad with invalid advertisement details and with 'CleanseJobAdDetails' processing option")
            .With(
                new ProviderServiceRequest
            {
                Method  = HttpVerb.Post,
                Path    = AdvertisementLink,
                Headers = new Dictionary <string, string>
                {
                    { "Authorization", "Bearer " + oAuth2Token.AccessToken },
                    { "Content-Type", RequestContentTypes.AdvertisementVersion1 },
                    { "Accept", $"{ResponseContentTypes.AdvertisementVersion1}, {ResponseContentTypes.AdvertisementErrorVersion1}" },
                    { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
                },
                Body = new AdvertisementContentBuilder(this.MinimumFieldsInitializer)
                       .WithRequestCreationId(CreationIdForAdWithMinimumRequiredData)
                       .WithAdvertisementDetails(adDetailsBeforeCleanse)
                       .WithProcessingOptions(ProcessingOptionsType.CleanseAdvertisementDetails.ToString())
                       .Build()
            }
                )
            .WillRespondWith(
                new ProviderServiceResponse
            {
                Status  = 200,
                Headers = new Dictionary <string, string>
                {
                    { "Content-Type", ResponseContentTypes.AdvertisementVersion1 },
                    { "Location", location },
                    { "X-Request-Id", RequestId }
                },
                Body = new AdvertisementResponseContentBuilder(this.MinimumFieldsInitializer)
                       .WithState(AdvertisementState.Open.ToString())
                       .WithId(advertisementId)
                       .WithLink("self", link)
                       .WithLink("view", viewRenderedAdvertisementLink)
                       .WithAdvertisementDetails(adDetailsAfterCleanse)
                       .Build()
            });

            var requestModel = new AdvertisementModelBuilder(this.MinimumFieldsInitializer)
                               .WithRequestCreationId(CreationIdForAdWithMinimumRequiredData)
                               .WithAdvertisementDetails(adDetailsBeforeCleanse)
                               .WithProcessingOptions(ProcessingOptionsType.CleanseAdvertisementDetails)
                               .Build();

            AdvertisementResource result;

            using (AdPostingApiClient client = this.Fixture.GetClient(oAuth2Token))
            {
                result = await client.CreateAdvertisementAsync(requestModel);
            }

            AdvertisementResource expectedResult = new AdvertisementResourceBuilder(this.MinimumFieldsInitializer)
                                                   .WithId(new Guid(advertisementId))
                                                   .WithLinks(advertisementId)
                                                   .WithAdvertisementDetails(adDetailsAfterCleanse)
                                                   .Build();

            result.ShouldBeEquivalentTo(expectedResult);
        }
        public async Task ExpireAdvertisementUsingInvalidRequestContent()
        {
            var         advertisementId = new Guid("8e2fde50-bc5f-4a12-9cfb-812e50500184");
            OAuth2Token oAuth2Token     = new OAuth2TokenBuilder().WithAccessToken(AccessTokens.OtherThirdPartyUploader).Build();
            var         link            = $"{AdvertisementLink}/{advertisementId}";
            var         acceptHeader    = this._acceptHeader;
            var         requestBody     = new[]
            {
                new
                {
                    op    = "add",
                    path  = "state",
                    value = "open"
                }
            };

            this.Fixture.MockProviderService
            .Given("There is a standout advertisement with maximum data")
            .UponReceiving("a PATCH advertisement request to expire a job using invalid request content")
            .With(
                new ProviderServiceRequest
            {
                Method  = HttpVerb.Patch,
                Path    = link,
                Headers = new Dictionary <string, object>
                {
                    { "Authorization", "Bearer " + oAuth2Token.AccessToken },
                    { "Content-Type", RequestContentTypes.AdvertisementPatchVersion1 },
                    { "Accept", acceptHeader },
                    { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
                },
                Body = requestBody
            }
                )
            .WillRespondWith(
                new ProviderServiceResponse
            {
                Status  = 422,
                Headers = new Dictionary <string, object>
                {
                    { "Content-Type", ResponseContentTypes.AdvertisementErrorVersion1 },
                    { "X-Request-Id", RequestId }
                },
                Body = new
                {
                    message = "Validation Failure",
                    errors  = new[] { new { code = "InvalidRequestContent" } }
                }
            });

            using (var client = new HttpClient())
            {
                using (HttpRequestMessage request = this.CreatePatchRequest(
                           new Uri(this.Fixture.AdPostingApiServiceBaseUri, link), requestBody, AccessTokens.OtherThirdPartyUploader))
                {
                    using (HttpResponseMessage response = await client.SendAsync(request))
                    {
                        Assert.Equal(422, (int)response.StatusCode);
                    }
                }
            }
        }
        public async Task UpdateWithSameQuestionnaireId()
        {
            OAuth2Token oAuth2Token = new OAuth2TokenBuilder().Build();
            var         link        = $"{AdvertisementLink}/{AdvertisementId}";
            var         viewRenderedAdvertisementLink             = $"{AdvertisementLink}/{AdvertisementId}/view";
            Guid        questionnaireIdUsedForCreateAdvertisement = new Guid("77d26391-eb70-4511-ac3e-2de00c7b9e29");

            this.Fixture.MockProviderService
            .Given("There is a standout advertisement with maximum data and a questionnaire ID")
            .UponReceiving("a PUT advertisement request to update a job ad with a questionnaire ID")
            .With(new ProviderServiceRequest
            {
                Method  = HttpVerb.Put,
                Path    = link,
                Headers = new Dictionary <string, object>
                {
                    { "Authorization", "Bearer " + oAuth2Token.AccessToken },
                    { "Content-Type", RequestContentTypes.AdvertisementVersion1 },
                    { "Accept", $"{ResponseContentTypes.AdvertisementVersion1}, {ResponseContentTypes.AdvertisementErrorVersion1}" },
                    { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
                },
                Body = new AdvertisementContentBuilder(this.AllFieldsInitializer)
                       .WithQuestionnaireId(questionnaireIdUsedForCreateAdvertisement)
                       .WithScreenId(null)
                       .Build()
            })
            .WillRespondWith(
                new ProviderServiceResponse
            {
                Status  = 200,
                Headers = new Dictionary <string, object>
                {
                    { "Content-Type", ResponseContentTypes.AdvertisementVersion1 },
                    { "X-Request-Id", RequestId }
                },
                Body = new AdvertisementResponseContentBuilder(this.AllFieldsInitializer)
                       .WithId(AdvertisementId)
                       .WithState(AdvertisementState.Open.ToString())
                       .WithLink("self", link)
                       .WithLink("view", viewRenderedAdvertisementLink)
                       .WithQuestionnaireId(questionnaireIdUsedForCreateAdvertisement)
                       .WithScreenId(null)
                       .Build()
            });

            Advertisement requestModel = new AdvertisementModelBuilder(this.AllFieldsInitializer)
                                         .WithQuestionnaireId(questionnaireIdUsedForCreateAdvertisement)
                                         .WithScreenId(null)
                                         .Build();
            AdvertisementResource result;

            using (AdPostingApiClient client = this.Fixture.GetClient(oAuth2Token))
            {
                result = await client.UpdateAdvertisementAsync(new Uri(this.Fixture.AdPostingApiServiceBaseUri, link), requestModel);
            }

            AdvertisementResource expectedResult = new AdvertisementResourceBuilder(this.AllFieldsInitializer)
                                                   .WithId(new Guid(AdvertisementId))
                                                   .WithLinks(AdvertisementId)
                                                   .WithQuestionnaireId(questionnaireIdUsedForCreateAdvertisement)
                                                   .WithScreenId(null)
                                                   .WithGranularLocationState(null)
                                                   .Build();

            result.ShouldBeEquivalentTo(expectedResult);
        }