Ejemplo n.º 1
0
        public async Task ExpireNonExistentAdvertisment()
        {
            var         advertisementId = new Guid("9b650105-7434-473f-8293-4e23b7e0e064");
            OAuth2Token oAuth2Token     = new OAuth2TokenBuilder().Build();
            var         link            = $"{AdvertisementLink}/{advertisementId}";

            this.Fixture.MockProviderService
            .UponReceiving("a PATCH advertisement request to expire a non-existent 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  = 404,
                Headers = new Dictionary <string, object> {
                    { "X-Request-Id", RequestId }
                }
            });

            AdvertisementNotFoundException actualException;

            using (AdPostingApiClient client = this.Fixture.GetClient(oAuth2Token))
            {
                actualException = await Assert.ThrowsAsync <AdvertisementNotFoundException>(
                    async() => await client.ExpireAdvertisementAsync(new Uri(this.Fixture.AdPostingApiServiceBaseUri, link)));
            }

            actualException.ShouldBeEquivalentToException(new AdvertisementNotFoundException(RequestId));
        }
Ejemplo n.º 2
0
        public async Task ExpireAdvertisementUsingHalSelfLink()
        {
            const string advertisementId = "8e2fde50-bc5f-4a12-9cfb-812e50500184";
            OAuth2Token  oAuth2Token     = new OAuth2TokenBuilder().Build();
            string       link            = $"{AdvertisementLink}/{advertisementId}";
            string       viewRenderedAdvertisementLink = $"{AdvertisementLink}/{advertisementId}/view";
            DateTime     expiryDate = new DateTime(2015, 10, 7, 21, 19, 00, DateTimeKind.Utc);

            this.SetupPactForExpiringExistingAdvertisement(link, oAuth2Token, advertisementId, viewRenderedAdvertisementLink, expiryDate);

            AdvertisementResource result;

            using (AdPostingApiClient client = this.Fixture.GetClient(oAuth2Token))
            {
                result = await client.ExpireAdvertisementAsync(new Uri(this.Fixture.AdPostingApiServiceBaseUri, link));
            }

            this.AssertReturnedAdvertisementMatchesExpectedExpiredAdvertisement(advertisementId, expiryDate, result);
        }
Ejemplo n.º 3
0
        public async Task ExpireAdvertisementWhereAdvertiserNotRelatedToRequestor()
        {
            var         advertisementId = new Guid("8e2fde50-bc5f-4a12-9cfb-812e50500184");
            OAuth2Token oAuth2Token     = new OAuth2TokenBuilder().WithAccessToken(AccessTokens.OtherThirdPartyUploader).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 for an advertiser not related to the requestor's 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 = "RelationshipError" } }
                }
            });

            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 = "RelationshipError"
                                  } }
            }));
        }
Ejemplo n.º 4
0
        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);
        }