public void When_ContactCreateRequestIsPassed_If_HttpClientHasNullBaseAddress_Then_AnArgumentNullExceptionMustBeThrown()
        {
            // arrange
            var httpClient = new HttpClient();
            var request    = new ContactCreateRequest();

            // act and assert
            Assert.Throws <ArgumentNullException>(() => request.MapToHttpRequestMessage(httpClient));
        }
        /// <inheritdoc/>
        public async Task <BaseContactResponse> CreateContactAsync(ContactCreateRequest request, CancellationToken cancellationToken)
        {
            if (request is null)
            {
                throw new System.ArgumentNullException(nameof(request));
            }

            using (var httpRequest = request.MapToHttpRequestMessage(this.httpClient))
                using (var httpResponse = await this.httpClient.SendAndLogAsync(httpRequest, this.logger, cancellationToken))
                {
                    return(await httpResponse.MapToCreateContactResponse());
                }
        }
        public void When_ContactCreateRequestIsPassed_Then_HttpRequestContentTypeMustBeApplicationJsonWithUtf8Charset()
        {
            // arrange
            const string expectedContentType = "application/json; charset=utf-8";
            var          httpClient          = new HttpClient {
                BaseAddress = new Uri("http://localhost")
            };
            var request = new ContactCreateRequest();

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

            // assert
            Assert.Equal(expectedContentType, httpRequest.Content.Headers.GetValues("Content-Type").First());
        }
        public void When_ContactCreateRequestIsPassed_Then_HttpRequestMethodMustBePost()
        {
            // arrange
            var httpClient = new HttpClient {
                BaseAddress = new Uri("http://localhost")
            };
            var request = new ContactCreateRequest();

            // act
            using (var httpRequest = request.MapToHttpRequestMessage(httpClient))
            {
                // assert
                Assert.Equal(HttpMethod.Post, httpRequest.Method);
            }
        }
        public void When_ContactCreateRequestIsPassed_Then_HttpRequestUriMustBeCorrect()
        {
            // arrange
            const string expectedUri = "http://localhost/crm/v3/objects/contacts";
            var          httpClient  = new HttpClient {
                BaseAddress = new Uri("http://localhost")
            };
            var request = new ContactCreateRequest();

            // act
            using (var httpRequest = request.MapToHttpRequestMessage(httpClient))
            {
                // assert
                Assert.Equal(expectedUri, httpRequest.RequestUri.ToString());
            }
        }
        public void When_ContactCreateRequestIsPassed_Then_HttpRequestAcceptHeaderMustBeApplicationJson()
        {
            // arrange
            const string expectedAccept = "application/json";
            var          httpClient     = new HttpClient {
                BaseAddress = new Uri("http://localhost")
            };
            var request = new ContactCreateRequest();

            // act
            using (var httpRequest = request.MapToHttpRequestMessage(httpClient))
            {
                // assert
                Assert.Equal(expectedAccept, httpRequest.Headers.GetValues("Accept").First());
            }
        }
        public void When_ContactCreateRequestIsPassed_Then_HttpRequestBodyMustBeCorrect()
        {
            // arrange
            const string expectedBody = @"{""properties"":{""foo"":""bar""}}";
            var          httpClient   = new HttpClient {
                BaseAddress = new Uri("http://localhost")
            };
            var request = new ContactCreateRequest();

            request.Properties.Add("foo", "bar");

            // act
            using (var httpRequest = request.MapToHttpRequestMessage(httpClient))
            {
                // assert
                var body = httpRequest.Content.ReadAsStringAsync().Result;
                Assert.Equal(expectedBody, body);
            }
        }