Beispiel #1
0
        public async Task GetAllLogosForPartnerNoLogosReturned()
        {
            this.Fixture.MockProviderService
            .Given("There are no logos for any advertiser related to the requestor")
            .UponReceiving("a GET logos request to retrieve all logos")
            .With(new ProviderServiceRequest
            {
                Method  = HttpVerb.Get,
                Path    = AdPostingLogoApiFixture.LogoApiBasePath,
                Headers = new Dictionary <string, object>
                {
                    { "Authorization", "Bearer " + this._oAuth2TokenRequestorB.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 List <LogoSummaryResource>() },
                    _links    = new
                    {
                        self = new { href = AdPostingLogoApiFixture.LogoApiBasePath }
                    }
                }
            });

            LogoSummaryListResource logosSummary;

            using (AdPostingApiClient client = this.Fixture.GetClient(this._oAuth2TokenRequestorB))
            {
                logosSummary = await client.GetAllLogosAsync();

                var expectedLogos = new LogoSummaryListResource
                {
                    Logos = new List <LogoSummaryResource>(),
                    Links = new Links(this.Fixture.AdPostingApiServiceBaseUri)
                    {
                        { "self", new Link {
                              Href = AdPostingLogoApiFixture.LogoApiBasePath
                          } }
                    },
                    RequestId = RequestId
                };

                logosSummary.ShouldBeEquivalentTo(expectedLogos);
            }
        }
Beispiel #2
0
        public async Task GetAllLogosForAdvertiserReturnsRelationshipError()
        {
            string queryString = "advertiserId=" + AdvertiserId1;

            this.Fixture.MockProviderService
            .UponReceiving("a GET logos request to retrieve all logos for an advertiser not related to requestor")
            .With(new ProviderServiceRequest
            {
                Method  = HttpVerb.Get,
                Path    = AdPostingLogoApiFixture.LogoApiBasePath,
                Query   = queryString,
                Headers = new Dictionary <string, object>
                {
                    { "Authorization", "Bearer " + this._oAuth2TokenRequestorB.AccessToken },
                    { "Accept", $"{ResponseContentTypes.LogoListVersion1}, {ResponseContentTypes.LogoErrorVersion1}" },
                    { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
                }
            })
            .WillRespondWith(new ProviderServiceResponse
            {
                Status  = 403,
                Headers = new Dictionary <string, object>
                {
                    { "Content-Type", ResponseContentTypes.LogoErrorVersion1 },
                    { "X-Request-Id", RequestId }
                },
                Body = new
                {
                    message = "Forbidden",
                    errors  = new[] { new { code = "RelationshipError" } }
                }
            });

            UnauthorizedException actualException;

            using (AdPostingApiClient client = this.Fixture.GetClient(this._oAuth2TokenRequestorB))
            {
                actualException = await Assert.ThrowsAsync <UnauthorizedException>(async() => await client.GetAllLogosAsync(AdvertiserId1));
            }

            actualException.ShouldBeEquivalentToException(
                new UnauthorizedException(
                    RequestId,
                    403,
                    new LogoErrorResponse
            {
                Message = "Forbidden",
                Errors  = new[] { new Error {
                                      Code = "RelationshipError"
                                  } }
            }));
        }
Beispiel #3
0
        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);
        }