public async Task GetApiLinksWithInvalidAccessTokenTriggersTokenRenewal() { this.Fixture.AdPostingApiService .UponReceiving("a GET index request to retrieve API links with an invalid access token") .With(new ProviderServiceRequest { Method = HttpVerb.Get, Path = "/", Headers = new Dictionary<string, string> { { "Authorization", "Bearer " + AccessTokens.InvalidAccessToken }, { "Accept", $"{ResponseContentTypes.Hal}, {ResponseContentTypes.AdvertisementErrorVersion1}" }, { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue } } }) .WillRespondWith(new ProviderServiceResponse { Status = (int)HttpStatusCode.Unauthorized, Headers = new Dictionary<string, string> { { "WWW-Authenticate", "Bearer error=\"Invalid request\"" } } }); this.Fixture.RegisterIndexPageInteractions(new OAuth2TokenBuilder().Build()); using (var fakeOAuth2Client = new FakeOAuth2Client()) { using (var client = new AdPostingApiClient(this.Fixture.AdPostingApiServiceBaseUri, fakeOAuth2Client)) { await client.InitialiseIndexResource(this.Fixture.AdPostingApiServiceBaseUri); } } }
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" } } })); }
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); }
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 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 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); }
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); }
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); }
public async Task GetAllTemplatesForPartnerMultipleTemplatesReturned() { this.Fixture.MockProviderService .Given("There are multiple templates for multiple advertisers related to the requestor") .UponReceiving("a GET templates request to retrieve all templates") .With(new ProviderServiceRequest { Method = HttpVerb.Get, Path = AdPostingTemplateApiFixture.TemplateApiBasePath, Headers = new Dictionary <string, object> { { "Authorization", "Bearer " + this._oAuth2TokenRequestorA.AccessToken }, { "Accept", $"{ResponseContentTypes.TemplateListVersion1}, {ResponseContentTypes.TemplateErrorVersion1}" }, { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue } } }) .WillRespondWith(new ProviderServiceResponse { Status = 200, Headers = new Dictionary <string, object> { { "Content-Type", ResponseContentTypes.TemplateListVersion1 }, { "X-Request-Id", RequestId } }, Body = new { _embedded = new { // sorted by WriteSequence templates = new[] { this._template4.Build(), this._template2.Build(), this._template1.Build(), this._template5.Build(), this._template3.Build() } }, _links = new { self = new { href = AdPostingTemplateApiFixture.TemplateApiBasePath }, next = new { href = AdPostingTemplateApiFixture.TemplateApiBasePath + $"?after={TemplateWriteSequence3}" } } } }); TemplateSummaryListResource templatesSummary; using (AdPostingApiClient client = this.Fixture.GetClient(this._oAuth2TokenRequestorA)) { templatesSummary = await client.GetAllTemplatesAsync(); } TemplateSummaryListResource expectedTemplates = new TemplateSummaryListResource { Templates = new List <TemplateSummaryResource> { // sorted by WriteSequence this._expectedTemplateResource4, this._expectedTemplateResource2, this._expectedTemplateResource1, this._expectedTemplateResource5, this._expectedTemplateResource3 }, Links = new Links(this.Fixture.AdPostingApiServiceBaseUri) { { "self", new Link { Href = AdPostingTemplateApiFixture.TemplateApiBasePath } }, { "next", new Link { Href = AdPostingTemplateApiFixture.TemplateApiBasePath + $"?after={TemplateWriteSequence3}" } } }, RequestId = RequestId }; templatesSummary.ShouldBeEquivalentTo(expectedTemplates); }
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); }
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 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); }
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" } } })); }
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); }
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); }
public async Task GetAllTemplatesForAdvertiserAndAfterSequenceIdentifierNoTemplatesReturned() { string queryString = "advertiserId=" + AdvertiserId2 + "&after=" + TemplateWriteSequence3; this.Fixture.MockProviderService .Given("There are no templates after given sequence identifier for all advertisers related to the requestor") .UponReceiving("a GET templates request to retrieve all templates for an advertiser after given sequence identifier") .With(new ProviderServiceRequest { Method = HttpVerb.Get, Path = AdPostingTemplateApiFixture.TemplateApiBasePath, Query = queryString, Headers = new Dictionary <string, object> { { "Authorization", "Bearer " + this._oAuth2TokenRequestorA.AccessToken }, { "Accept", $"{ResponseContentTypes.TemplateListVersion1}, {ResponseContentTypes.TemplateErrorVersion1}" }, { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue } } }) .WillRespondWith(new ProviderServiceResponse { Status = 200, Headers = new Dictionary <string, object> { { "Content-Type", ResponseContentTypes.TemplateListVersion1 }, { "X-Request-Id", RequestId } }, Body = new { _embedded = new { templates = new object[0] }, _links = new { self = new { href = $"{AdPostingTemplateApiFixture.TemplateApiBasePath}?{queryString}" } } } }); TemplateSummaryListResource templateSummary; using (AdPostingApiClient client = this.Fixture.GetClient(this._oAuth2TokenRequestorA)) { templateSummary = await client.GetAllTemplatesAsync(AdvertiserId2, TemplateWriteSequence3); } TemplateSummaryListResource expectedTemplates = new TemplateSummaryListResource { Templates = new List <TemplateSummaryResource>(), Links = new Links(this.Fixture.AdPostingApiServiceBaseUri) { { "self", new Link { Href = $"{AdPostingTemplateApiFixture.TemplateApiBasePath}?{queryString}" } } }, RequestId = RequestId }; templateSummary.ShouldBeEquivalentTo(expectedTemplates); }
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); }
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 GetAllLogosForAdvertiserMultipleLogosReturned() { string queryString = "advertiserId=" + AdvertiserId1; this.Fixture.MockProviderService .Given("There are multiple logos for multiple advertisers related to the requestor") .UponReceiving("a GET logos request to retrieve all logos for an advertiser") .With(new ProviderServiceRequest { Method = HttpVerb.Get, Path = AdPostingLogoApiFixture.LogoApiBasePath, Query = queryString, Headers = new Dictionary <string, object> { { "Authorization", "Bearer " + this._oAuth2TokenRequestorA.AccessToken }, { "Accept", $"{ResponseContentTypes.LogoListVersion1}, {ResponseContentTypes.LogoErrorVersion1}" }, { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue } } }) .WillRespondWith(new ProviderServiceResponse { Status = 200, Headers = new Dictionary <string, object> { { "Content-Type", ResponseContentTypes.LogoListVersion1 }, { "X-Request-Id", RequestId } }, Body = new { _embedded = new { logos = new[] { this._logo1.Build(), this._logo2.Build(), this._logo3.Build() } }, _links = new { self = new { href = $"{AdPostingLogoApiFixture.LogoApiBasePath}?{queryString}" } } } }); LogoSummaryListResource logosSummary; using (AdPostingApiClient client = this.Fixture.GetClient(this._oAuth2TokenRequestorA)) { logosSummary = await client.GetAllLogosAsync(AdvertiserId1); } LogoSummaryListResource expectedLogos = new LogoSummaryListResource { Logos = new List <LogoSummaryResource> { this._expectedLogoResource1, this._expectedLogoResource2, this._expectedLogoResource3 }, Links = new Links(this.Fixture.AdPostingApiServiceBaseUri) { { "self", new Link { Href = $"{AdPostingLogoApiFixture.LogoApiBasePath}?{queryString}" } } }, RequestId = RequestId }; logosSummary.ShouldBeEquivalentTo(expectedLogos); }
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 ExpireAdvertisementUsingDisabledRequestorAccount() { var advertisementId = new Guid("8e2fde50-bc5f-4a12-9cfb-812e50500184"); OAuth2Token oAuth2Token = new OAuth2TokenBuilder().WithAccessToken(AccessTokens.ValidAccessToken_Disabled).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 using a disabled requestor 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 = "AccountError" } } } }); 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 = "AccountError" } } })); }
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); }