public async Task EstateController_POST_CreateEstate_CreateEstateResponseIsReturned()
        {
            HttpClient client = this.WebApplicationFactory.CreateClient();


            CreateEstateRequest createEstateRequest = TestData.CreateEstateRequestDTO;
            String        uri     = "api/estates/";
            StringContent content = Helpers.CreateStringContent(createEstateRequest);

            client.DefaultRequestHeaders.Add("api-version", "1.0");
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "eyJhbGciOiJSUzI1NiIsImtpZCI6Il9JbGpYLXU5M0FnV3FrUjl2eEZIU0EiLCJ0eXAiOiJhdCtqd3QifQ.eyJuYmYiOjE1NzYzNTIwMTQsImV4cCI6MTU3NjM1NTYxNCwiaXNzIjoiaHR0cDovLzE5Mi4xNjguMS4xMzM6NTAwMSIsImF1ZCI6WyJlc3RhdGVNYW5hZ2VtZW50IiwidHJhbnNhY3Rpb25Qcm9jZXNzb3IiLCJ0cmFuc2FjdGlvblByb2Nlc3NvckFDTCJdLCJjbGllbnRfaWQiOiJzZXJ2aWNlQ2xpZW50Iiwic2NvcGUiOlsiZXN0YXRlTWFuYWdlbWVudCIsInRyYW5zYWN0aW9uUHJvY2Vzc29yIiwidHJhbnNhY3Rpb25Qcm9jZXNzb3JBQ0wiXX0.dqwKXApOl5DTEp7wz-PAWoEy_43gquzuA1o7H7MF-tBgdTmlmbzfHD5Sez6y1F0tJHTPN0ZIbGJa1aiLs0m4YVfdvpLuIE8pEI5KUpTPuXr-olJkuRxZ7lAkstMFYvxsjd1d_Q-Y1fAIQFg_zq1So9c3eAbfdYC0-KF13Iwpp8fJpNN8Z5OVqrs3aUYtldJUkBt5o6toXFxdsJx-qS4ewnkLfDTLv1VJD1mg5lMJgTFLzvWQesB3Emia2XiwY-vq2CrXdu83Ez9guKvrmAbWDQa-WZoGeIMFjVC3ug8CVyxYYi6rZtmpbN9D8u-PRuo7jALiPef27QwzY9MLTIcPJg");

            // 2. Act
            HttpResponseMessage response = await client.PostAsync(uri, content, CancellationToken.None);

            // 3. Assert
            response.StatusCode.ShouldBe(HttpStatusCode.Created);

            String responseAsJson = await response.Content.ReadAsStringAsync();

            responseAsJson.ShouldNotBeNullOrEmpty();

            CreateEstateResponse responseObject = JsonConvert.DeserializeObject <CreateEstateResponse>(responseAsJson);

            responseObject.ShouldNotBeNull();
            responseObject.EstateId.ShouldNotBe(Guid.Empty);
        }
Пример #2
0
        public void CreateEstateRequest_CanBeCreated_IsCreated()
        {
            CreateEstateRequest createEstateRequest = CreateEstateRequest.Create(TestData.EstateId, TestData.EstateName);

            createEstateRequest.ShouldNotBeNull();
            createEstateRequest.EstateId.ShouldBe(TestData.EstateId);
            createEstateRequest.Name.ShouldBe(TestData.EstateName);
        }
Пример #3
0
        public async Task WhenICreateTheFollowingEstates(Table table)
        {
            foreach (TableRow tableRow in table.Rows)
            {
                String estateName = SpecflowTableHelper.GetStringRowValue(tableRow, "EstateName");

                CreateEstateRequest createEstateRequest = new CreateEstateRequest
                {
                    EstateId   = Guid.NewGuid(),
                    EstateName = estateName
                };

                CreateEstateResponse response = null;
                try
                {
                    response = await this.TestingContext.DockerHelper.EstateClient
                               .CreateEstate(this.TestingContext.AccessToken, createEstateRequest, CancellationToken.None)
                               .ConfigureAwait(false);
                }
                catch (Exception e)
                {
                    this.TestingContext.DockerHelper.Logger.LogInformation(e.Message);
                    if (e.InnerException != null)
                    {
                        this.TestingContext.DockerHelper.Logger.LogInformation(e.InnerException.Message);
                        if (e.InnerException.InnerException != null)
                        {
                            this.TestingContext.DockerHelper.Logger.LogInformation(e.InnerException.InnerException.Message);
                        }
                    }
                }

                response.ShouldNotBeNull();
                response.EstateId.ShouldNotBe(Guid.Empty);

                // Cache the estate id
                this.TestingContext.AddEstateDetails(response.EstateId, estateName);

                //this.TestingContext.Logger.LogInformation($"Estate {estateName} created with Id {response.EstateId}");
            }

            foreach (TableRow tableRow in table.Rows)
            {
                EstateDetails  estateDetails = this.TestingContext.GetEstateDetails(tableRow);
                EstateResponse estate        = null;
                await Retry.For(async() =>
                {
                    estate = await this.TestingContext.DockerHelper.EstateClient
                             .GetEstate(this.TestingContext.AccessToken, estateDetails.EstateId, CancellationToken.None).ConfigureAwait(false);
                });

                estate.ShouldNotBeNull();
                estate.EstateName.ShouldBe(estateDetails.EstateName);
            }
        }
        public void EstateRequestHandler_CreateEstateRequest_IsHandled()
        {
            Mock <IEstateDomainService> estateDomainService = new Mock <IEstateDomainService>();
            EstateRequestHandler        handler             = new EstateRequestHandler(estateDomainService.Object);

            CreateEstateRequest request = TestData.CreateEstateRequest;

            Should.NotThrow(async() =>
            {
                await handler.Handle(request, CancellationToken.None);
            });
        }
        public async Task WhenICreateTheFollowingEstates(Table table)
        {
            foreach (TableRow tableRow in table.Rows)
            {
                String estateName = SpecflowTableHelper.GetStringRowValue(tableRow, "EstateName");
                // Setup the subscriptions for the estate
                await Retry.For(async() => { await this.TestingContext.DockerHelper.PopulateSubscriptionServiceConfiguration(estateName).ConfigureAwait(false); },
                                retryFor : TimeSpan.FromMinutes(2),
                                retryInterval : TimeSpan.FromSeconds(30));
            }

            foreach (TableRow tableRow in table.Rows)
            {
                String estateName = SpecflowTableHelper.GetStringRowValue(tableRow, "EstateName");

                CreateEstateRequest createEstateRequest = new CreateEstateRequest
                {
                    EstateId   = Guid.NewGuid(),
                    EstateName = estateName
                };
                CreateEstateResponse response = null;
                await Retry.For(async() =>
                {
                    response = await this.TestingContext.DockerHelper.EstateClient
                               .CreateEstate(this.TestingContext.AccessToken, createEstateRequest, CancellationToken.None)
                               .ConfigureAwait(false);

                    response.ShouldNotBeNull();
                    response.EstateId.ShouldNotBe(Guid.Empty);
                }, retryFor : TimeSpan.FromMinutes(1),
                                retryInterval : TimeSpan.FromSeconds(30));


                this.TestingContext.Logger.LogInformation($"Estate {estateName} created with Id {response.EstateId}");

                EstateResponse estate = null;
                await Retry.For(async() =>
                {
                    estate = await this.TestingContext.DockerHelper.EstateClient
                             .GetEstate(this.TestingContext.AccessToken, response.EstateId, CancellationToken.None).ConfigureAwait(false);
                    estate.ShouldNotBeNull();

                    // Cache the estate id
                    this.TestingContext.AddEstateDetails(estate.EstateId, estate.EstateName);
                },
                                TimeSpan.FromMinutes(3),
                                TimeSpan.FromSeconds(30)).ConfigureAwait(false);

                estate.EstateName.ShouldBe(estateName);
            }
        }
Пример #6
0
        /// <summary>
        /// Creates the estate.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        /// <param name="createEstateRequest">The create estate request.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public async Task <CreateEstateResponse> CreateEstate(String accessToken,
                                                              CreateEstateRequest createEstateRequest,
                                                              CancellationToken cancellationToken)
        {
            CreateEstateResponse response = null;

            String requestUri = this.BuildRequestUrl("/api/estates/");

            try
            {
                String requestSerialised = JsonConvert.SerializeObject(createEstateRequest);

                StringContent httpContent = new StringContent(requestSerialised, Encoding.UTF8, "application/json");

                // Add the access token to the client headers
                this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

                // Make the Http Call here
                HttpResponseMessage httpResponse = await this.HttpClient.PostAsync(requestUri, httpContent, cancellationToken);

                // Process the response
                String content = await this.HandleResponse(httpResponse, cancellationToken);

                // call was successful so now deserialise the body to the response object
                response = JsonConvert.DeserializeObject <CreateEstateResponse>(content);
            }
            catch (Exception ex)
            {
                // An exception has occurred, add some additional information to the message
                Exception exception = new Exception($"Error creating new estate {createEstateRequest.EstateName}.", ex);

                throw exception;
            }

            return(response);
        }