<commit_before>﻿namespace Skeleton.Web.Tests.Integration.BaseApiClient
{
    using System;
    using System.Collections.Generic;
    using System.Net.Http;
    using System.Net.Http.Headers;
    using System.Text;
    using JetBrains.Annotations;
    using Web.Integration.BaseApiClient;
    using Xunit;

    public class HttpRequestHeadersExtensionsTests
    {
        [UsedImplicitly]
        public static IEnumerable<object[]> WithBearerTokenParametersValidationTestsData;
        [UsedImplicitly]
        public static IEnumerable<object[]> WithBasicAuthParametersValidationTestsData;

        static HttpRequestHeadersExtensionsTests()
        {
            WithBearerTokenParametersValidationTestsData =
                new[]
                {
                    new object[] {null, "123"},
                    new object[] {new HttpClient().DefaultRequestHeaders, null},
                    new object[] {new HttpClient().DefaultRequestHeaders, "   "}
                };
            WithBasicAuthParametersValidationTestsData =
                new[]
                {
                    new object[] {null, "123", "123"},
                    new object[] {new HttpClient().DefaultRequestHeaders, null, "123"},
                    new object[] {new HttpClient().DefaultRequestHeaders, "   ", "123"},
                    new object[] {new HttpClient().DefaultRequestHeaders, "123", null},
                    new object[] {new HttpClient().DefaultRequestHeaders, "123", "   "}
                };
        }

        [Theory]
        [MemberData(nameof(WithBearerTokenParametersValidationTestsData))]
        public void WithBearerTokenShouldNotValidateParameters(HttpRequestHeaders headers, string token)
        {
            Assert.Throws<ArgumentNullException>(() => headers.WithBearerToken(token));
        }

        [Theory]
        [MemberData(nameof(WithBasicAuthParametersValidationTestsData))]
        public void WithBasicAuthShouldNotValidateParameters(HttpRequestHeaders headers, string login, string password)
        {
            Assert.Throws<ArgumentNullException>(() => headers.WithBasicAuth(login, password));
        }

        [Fact]
        public void ShouldPlaceSetupAuthorizationHeaderForTokenAuthentication()
        {
            // Given
            const string token = "123";
            var headers = new HttpClient().DefaultRequestHeaders;

            // When
            headers.WithBearerToken(token);

            // Then
            Assert.Equal($"Bearer {token}", headers.Authorization.ToString());
        }
<commit_msg>TheoryData was used for bearer token parameters validation testing<commit_after>﻿namespace Skeleton.Web.Tests.Integration.BaseApiClient
{
    using System;
    using System.Collections.Generic;
    using System.Net.Http;
    using System.Net.Http.Headers;
    using System.Text;
    using JetBrains.Annotations;
    using Web.Integration.BaseApiClient;
    using Xunit;

    public class HttpRequestHeadersExtensionsTests
    {
        #region TestCases

        public class BearerTokenParametersValidationTestCase
        {
            public HttpRequestHeaders Headers { get; set; }

            public string Token { get; set; }
        }

        #endregion

        [UsedImplicitly]
        public static TheoryData<BearerTokenParametersValidationTestCase> BearerTokenParametersValidationTestCases;
        [UsedImplicitly]
        public static IEnumerable<object[]> WithBasicAuthParametersValidationTestsData;

        static HttpRequestHeadersExtensionsTests()
        {
            BearerTokenParametersValidationTestCases =
                new TheoryData<BearerTokenParametersValidationTestCase>
                {
                    new BearerTokenParametersValidationTestCase {Token = "<PASSWORD>"},
                    new BearerTokenParametersValidationTestCase {Headers = new HttpClient().DefaultRequestHeaders},
                    new BearerTokenParametersValidationTestCase {Headers = new HttpClient().DefaultRequestHeaders, Token = "   "}
                };
            WithBasicAuthParametersValidationTestsData =
                new[]
                {
                    new object[] {null, "123", "123"},
                    new object[] {new HttpClient().DefaultRequestHeaders, null, "123"},
                    new object[] {new HttpClient().DefaultRequestHeaders, "   ", "123"},
                    new object[] {new HttpClient().DefaultRequestHeaders, "123", null},
                    new object[] {new HttpClient().DefaultRequestHeaders, "123", "   "}
                };
        }

        [Theory]
        [MemberData(nameof(BearerTokenParametersValidationTestCases))]
        public void ShouldValidateBearerTokenParameters(BearerTokenParametersValidationTestCase testCase)
        {
            Assert.Throws<ArgumentNullException>(() => testCase.Headers.WithBearerToken(testCase.Token));
        }

        [Theory]
        [MemberData(nameof(WithBasicAuthParametersValidationTestsData))]
        public void WithBasicAuthShouldNotValidateParameters(HttpRequestHeaders headers, string login, string password)
        {
            Assert.Throws<ArgumentNullException>(() => headers.WithBasicAuth(login, password));
        }

        [Fact]
        public void ShouldPlaceSetupAuthorizationHeaderForTokenAuthentication()
        {
            // Given
            const string token = "<PASSWORD>";
            var headers = new HttpClient().DefaultRequestHeaders;

            // When
            headers.WithBearerToken(token);

            // Then
            Assert.Equal($"Bearer {token}", headers.Authorization.ToString());
        }

{'fraction_non_alphanumeric': 0.08736487683856105, 'fraction_numerical': 0.007442849548112706, 'mean_word_length': 2.3356973995271866, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4235134', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1287, 'n_words': 263}