Ejemplo n.º 1
0
        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 pending 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);
        }
Ejemplo n.º 2
0
        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);
        }