public void When_ContactUpdateRequestIsPassed_If_HttpClientHasNullBaseAddress_Then_AnArgumentNullExceptionMustBeThrown()
        {
            // arrange
            var httpClient = new HttpClient();
            var request    = new ContactUpdateRequest();

            // act and assert
            Assert.Throws <ArgumentNullException>(() => request.MapToHttpRequestMessage(httpClient));
        }
        public void When_ContactUpdateRequestIsPassed_Then_HttpRequestContentTypeMustBeApplicationJsonWithUtf8Charset()
        {
            // arrange
            const string expectedContentType = "application/json; charset=utf-8";
            var          httpClient          = new HttpClient {
                BaseAddress = new Uri("http://localhost")
            };
            var request = new ContactUpdateRequest();

            // act
            var httpRequest = request.MapToHttpRequestMessage(httpClient);

            // assert
            Assert.Equal(expectedContentType, httpRequest.Content.Headers.GetValues("Content-Type").First());
        }
        public void When_ContactUpdateRequestIsPassed_Then_HttpRequestAcceptHeaderMustBeApplicationJson()
        {
            // arrange
            const string expectedAccept = "application/json";
            var          httpClient     = new HttpClient {
                BaseAddress = new Uri("http://localhost")
            };
            var request = new ContactUpdateRequest();

            // act
            using (var httpRequest = request.MapToHttpRequestMessage(httpClient))
            {
                // assert
                Assert.Equal(expectedAccept, httpRequest.Headers.GetValues("Accept").First());
            }
        }
        public void When_ContactUpdateRequestIsPassed_Then_HttpRequestMethodMustBePatch()
        {
            // arrange
            var httpClient = new HttpClient {
                BaseAddress = new Uri("http://localhost")
            };
            var request = new ContactUpdateRequest {
                Id = "someid"
            };

            // act
            using (var httpRequest = request.MapToHttpRequestMessage(httpClient))
            {
                // assert
                Assert.Equal(new HttpMethod("PATCH"), httpRequest.Method);
            }
        }
        /// <inheritdoc/>
        public async Task <BaseContactResponse> UpdateContactAsync(ContactUpdateRequest request, CancellationToken cancellationToken)
        {
            if (request is null)
            {
                throw new System.ArgumentNullException(nameof(request));
            }

            if (string.IsNullOrWhiteSpace(request.Id))
            {
                throw new System.ArgumentNullException(nameof(request.Id));
            }

            using (var httpRequest = request.MapToHttpRequestMessage(this.httpClient))
                using (var httpResponse = await this.httpClient.SendAndLogAsync(httpRequest, this.logger, cancellationToken))
                {
                    return(await httpResponse.MapToUpdateContactResponse());
                }
        }
        public void When_ContactUpdateRequestIsPassed_Then_HttpRequestBodyMustBeCorrect()
        {
            // arrange
            var expectedBody = @"{""properties"":{}}";
            var httpClient   = new HttpClient {
                BaseAddress = new Uri("http://localhost")
            };
            var request = new ContactUpdateRequest {
                Id = "someid"
            };

            // act
            using (var httpRequest = request.MapToHttpRequestMessage(httpClient))
            {
                // assert
                var body = httpRequest.Content.ReadAsStringAsync().Result;
                Assert.Equal(expectedBody, body);
            }
        }
        public void When_ContactUpdateRequestIsPassed_Then_HttpRequestUriMustBeCorrect()
        {
            // arrange
            const string expectedId  = "someid";
            var          expectedUri = $"http://localhost/crm/v3/objects/contacts/{expectedId}";
            var          httpClient  = new HttpClient {
                BaseAddress = new Uri("http://localhost")
            };
            var request = new ContactUpdateRequest {
                Id = expectedId
            };

            // act
            using (var httpRequest = request.MapToHttpRequestMessage(httpClient))
            {
                // assert
                Assert.Equal(expectedUri, httpRequest.RequestUri.ToString());
            }
        }