private void SetupPactForGettingExistingAdvertisementStatus(string link, OAuth2Token oAuth2Token)
 {
     this.Fixture.AdPostingApiService
         .Given("There is a pending standout advertisement with maximum data")
         .UponReceiving("a HEAD advertisement request")
         .With(new ProviderServiceRequest
         {
             Method = HttpVerb.Head,
             Path = link,
             Headers = new Dictionary<string, string>
             {
                 {"Authorization", "Bearer " + oAuth2Token.AccessToken},
                 {"Accept", $"{ResponseContentTypes.AdvertisementVersion1}, {ResponseContentTypes.AdvertisementErrorVersion1}"},
                 { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
             }
         })
         .WillRespondWith(new ProviderServiceResponse
         {
             Status = 200,
             Headers = new Dictionary<string, string>
             {
                 {"Content-Type", ResponseContentTypes.AdvertisementVersion1},
                 {"Processing-Status", "Pending"}
             }
         });
 }
        public void RegisterIndexPageInteractions(OAuth2Token token)
        {
            const string advertisementLink = "/advertisement";

            this.AdPostingApiService
                .UponReceiving($"a GET index request to retrieve API links with Bearer {token.AccessToken}")
                .With(new ProviderServiceRequest
                {
                    Method = HttpVerb.Get,
                    Path = "/",
                    Headers = new Dictionary<string, string>
                    {
                        { "Accept", $"{ResponseContentTypes.Hal}, {ResponseContentTypes.AdvertisementErrorVersion1}" },
                        { "Authorization", $"Bearer {token.AccessToken}" },
                        { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
                    }
                })
                .WillRespondWith(new ProviderServiceResponse
                {
                    Status = 200,
                    Headers = new Dictionary<string, string>
                    {
                        { "Content-Type", $"{ResponseContentTypes.Hal}" }
                    },
                    Body = new
                    {
                        _links = new
                        {
                            advertisements = new
                            {
                                href = advertisementLink + "{?advertiserId}",
                                templated = true
                            },
                            advertisement = new
                            {
                                href = advertisementLink + "/{advertisementId}",
                                templated = true
                            }
                        }
                    }
                });
        }
 private void SetupPactForExpiringExistingAdvertisement(
     string link, OAuth2Token oAuth2Token, string advertisementId, string viewRenderedAdvertisementLink, DateTime expiryDate)
 {
     this.Fixture.AdPostingApiService
         .Given("There is a pending standout advertisement with maximum data")
         .UponReceiving("a PATCH advertisement request to expire an advertisement")
         .With(
             new ProviderServiceRequest
             {
                 Method = HttpVerb.Patch,
                 Path = link,
                 Headers = new Dictionary<string, string>
                 {
                     { "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 = 202,
                 Headers = new Dictionary<string, string>
                 {
                     {"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()
             });
 }
 private async Task<OAuth2Token> GetOAuth2TokenAsync(OAuth2Token currentOAuth2Token)
 {
     return currentOAuth2Token == this._oAuth2Token
         ? (this._oAuth2Token = await this._tokenClient.GetOAuth2TokenAsync())
         : this._oAuth2Token;
 }
Ejemplo n.º 5
0
 private void SetupPactForGettingExistingAdvertisement(string givenStatement, string link, OAuth2Token oAuth2Token, AllFieldsInitializer builderInitializer,
     string advertisementId, string viewRenderedAdvertisementLink)
 {
     this.Fixture.AdPostingApiService
         .Given(givenStatement)
         .UponReceiving("a GET advertisement request")
         .With(new ProviderServiceRequest
         {
             Method = HttpVerb.Get,
             Path = link,
             Headers = new Dictionary<string, string>
             {
                 { "Authorization", "Bearer " + oAuth2Token.AccessToken },
                 { "Accept", $"{ResponseContentTypes.AdvertisementVersion1}, {ResponseContentTypes.AdvertisementErrorVersion1}" },
                 { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
             }
         })
         .WillRespondWith(new ProviderServiceResponse
         {
             Status = 200,
             Headers = new Dictionary<string, string>
             {
                 {"Content-Type", ResponseContentTypes.AdvertisementVersion1},
                 {"Processing-Status", "Pending"},
                 {"X-Request-Id", RequestId}
             },
             Body = new AdvertisementResponseContentBuilder(builderInitializer)
                 .WithId(advertisementId)
                 .WithState(AdvertisementState.Open.ToString())
                 .WithLink("self", link)
                 .WithLink("view", viewRenderedAdvertisementLink)
                 .WithAgentId(null)
                 .WithAdditionalProperties(AdditionalPropertyType.ResidentsOnly.ToString(), AdditionalPropertyType.Graduate.ToString())
                 .Build()
         });
 }
        public AdPostingApiClient GetClient(OAuth2Token token)
        {
            var oAuthClient = Mock.Of<IOAuth2TokenClient>(c => c.GetOAuth2TokenAsync() == Task.FromResult(token));

            return new AdPostingApiClient(this.AdPostingApiServiceBaseUri, oAuthClient);
        }