예제 #1
0
        public async Task UpdateWithGranularLocationData()
        {
            OAuth2Token oAuth2Token = new OAuth2TokenBuilder().Build();
            var         link        = $"{AdvertisementLink}/{AdvertisementId}";
            var         viewRenderedAdvertisementLink = $"{AdvertisementLink}/{AdvertisementId}/view";

            var allFieldsWithGranularLocationInitializer = new AllFieldsInitializer(LocationType.UseGranularLocation);

            this.Fixture.AdPostingApiService
            .Given("There is a standout advertisement with maximum data")
            .UponReceiving("a PUT advertisement request to update granular location")
            .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(allFieldsWithGranularLocationInitializer)
                       .Build()
            })
            .WillRespondWith(
                new ProviderServiceResponse
            {
                Status  = 200,
                Headers = new Dictionary <string, string>
                {
                    { "Content-Type", ResponseContentTypes.AdvertisementVersion1 },
                    { "X-Request-Id", RequestId }
                },
                Body = new AdvertisementResponseContentBuilder(allFieldsWithGranularLocationInitializer)
                       .WithId(AdvertisementId)
                       .WithState(AdvertisementState.Open.ToString())
                       .WithLink("self", link)
                       .WithLink("view", viewRenderedAdvertisementLink)
                       .WithGranularLocationState(null)
                       .Build()
            });

            Advertisement requestModel = new AdvertisementModelBuilder(allFieldsWithGranularLocationInitializer)
                                         .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(allFieldsWithGranularLocationInitializer)
                                                   .WithId(new Guid(AdvertisementId))
                                                   .WithLinks(AdvertisementId)
                                                   .WithGranularLocationState(null)
                                                   .Build();

            result.ShouldBeEquivalentTo(expectedResult);
        }
 private AdvertisementModelBuilder <TAdvertisement> SetupModelForExistingAdvertisement <TAdvertisement>(
     AdvertisementModelBuilder <TAdvertisement> builder) where TAdvertisement : Advertisement, new()
 {
     return(builder
            .WithJobTitle("Exciting Senior Developer role in a great CBD location. Great $$$ - updated")
            .WithApplicationFormUrl("http://FakeATS.com.au")
            .WithStandOutBullet("new Uzi", "new Remington Model", "new AK-47"));
 }
예제 #3
0
 private AdvertisementModelBuilder <TAdvertisement> SetupModelForExistingAdvertisement <TAdvertisement>(
     AdvertisementModelBuilder <TAdvertisement> builder) where TAdvertisement : Advertisement, new()
 {
     return(builder
            .WithAgentId(null)
            .WithAgentJobReference(null)
            .WithJobTitle("Exciting Senior Developer role in a great CBD location. Great $$$ - updated")
            .WithVideoUrl("https://www.youtube.com/embed/dVDk7PXNXB8")
            .WithApplicationFormUrl("http://FakeATS.com.au")
            .WithEndApplicationUrl("http://endform.com/updated")
            .WithStandoutBullets("new Uzi", "new Remington Model", "new AK-47"));
 }
        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 = 202,
                        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);
        }
        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" } }
                    }));
        }
예제 #6
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);
        }
예제 #7
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"
                                  } }
            }));
        }
예제 #8
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);
        }
예제 #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);
        }
예제 #10
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"
                                  } }
            }));
        }