Ejemplo n.º 1
0
        public async Task GetAllTemplatesForPartnerNoTemplatesReturned()
        {
            this.Fixture.MockProviderService
            .Given("There are no templates for any advertiser 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._oAuth2TokenRequestorB.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 List <TemplateSummaryResource>() },
                    _links    = new { self = new { href = "/template" } }
                }
            });

            TemplateSummaryListResource templatesSummary;

            using (AdPostingApiClient client = this.Fixture.GetClient(this._oAuth2TokenRequestorB))
            {
                templatesSummary = await client.GetAllTemplatesAsync();
            }

            TemplateSummaryListResource expectedTemplates = new TemplateSummaryListResource
            {
                Links = new Links(this.Fixture.AdPostingApiServiceBaseUri)
                {
                    { "self", new Link {
                          Href = "/template"
                      } }
                },
                Templates = new List <TemplateSummaryResource>(),
                RequestId = RequestId
            };

            templatesSummary.ShouldBeEquivalentTo(expectedTemplates);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public async Task GetAllTemplatesForAdvertiserReturnsRelationshipError()
        {
            string queryString = "advertiserId=" + AdvertiserId1;

            this.Fixture.MockProviderService
            .UponReceiving("a GET templates request to retrieve all templates for an advertiser not related to requestor")
            .With(new ProviderServiceRequest
            {
                Method  = HttpVerb.Get,
                Path    = AdPostingTemplateApiFixture.TemplateApiBasePath,
                Query   = queryString,
                Headers = new Dictionary <string, object>
                {
                    { "Authorization", "Bearer " + this._oAuth2TokenRequestorB.AccessToken },
                    { "Accept", $"{ResponseContentTypes.TemplateListVersion1}, {ResponseContentTypes.TemplateErrorVersion1}" },
                    { "User-Agent", AdPostingApiFixture.UserAgentHeaderValue }
                }
            })
            .WillRespondWith(new ProviderServiceResponse
            {
                Status  = 403,
                Headers = new Dictionary <string, object>
                {
                    { "Content-Type", ResponseContentTypes.TemplateErrorVersion1 },
                    { "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.GetAllTemplatesAsync(AdvertiserId1));
            }

            actualException.ShouldBeEquivalentToException(
                new UnauthorizedException(
                    RequestId,
                    403,
                    new TemplateErrorResponse
            {
                Message = "Forbidden",
                Errors  = new[] { new Error {
                                      Code = "RelationshipError"
                                  } }
            }));
        }
Ejemplo n.º 4
0
        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);
        }