<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using FluentAssertions;
using Xunit.Extensions;
using Moq;
using Burr.Http;

namespace Burr.Tests
{
    public class GitHubClientTests
    {
        public class TheConstructor
        {
            [Fact]
            public void CanCreateAnonymousClient()
            {
                var client = new GitHubClient();

                client.AuthenticationType.Should().Be(AuthenticationType.Anonymous);
            }

            [Fact]
            public void CanCreateBasicAuthClient()
            {
                var client = new GitHubClient { Username = "tclem", Password = "<PASSWORD>" };

                client.AuthenticationType.Should().Be(AuthenticationType.Basic);
            }

            [Fact]
            public void CanCreateOauthClient()
            {
                var client = new GitHubClient { Token = "<PASSWORD>" };

                client.AuthenticationType.Should().Be(AuthenticationType.Oauth);
            }

            [InlineData("")]
            [InlineData(" ")]
            [InlineData(null)]
            [Theory]
            public void InvalidTokenFallsBackToAnon(string t)
            {
                var client = new GitHubClient { Token = t };

                client.AuthenticationType.Should().Be(AuthenticationType.Anonymous);
            }

            [InlineData("")]
            [InlineData(" ")]
            [InlineData(null)]
            [Theory]
            public void InvalidUserNameFallsBackToAnon(string t)
            {
                var client = new GitHubClient { Username = t };

                client.AuthenticationType.Should().Be(AuthenticationType.Anonymous);
            }

            [InlineData("")]
            [InlineData(" ")]
            [InlineData(null)]
            [Theory]
            public void InvalidPasswordFallsBackToAnon(string t)
            {
                var client = new GitHubClient { Password = t };

                client.AuthenticationType.Should().Be(AuthenticationType.Anonymous);
            }
        }

        public class TheUserMethod
        {
            Func<Task<IResponse<User>>> fakeUserResponse =
                new Func<Task<IResponse<User>>>(() => new Task<IResponse<User>>(() => new Response<User> { BodyAsObject = new User() }));

            [Fact]
            public async Task GetsAuthenticatedUserWithBasic()
            {
                var endpoint = "/user";
                var c = new Mock<IConnection>();
                c.Setup(x => x.GetAsync<User>(endpoint)).Returns(fakeUserResponse);
                var client = new GitHubClient
                {
                    Username = "tclem",
                    Password = "<PASSWORD>",
                    Connection = c.Object
                };

                var user = await client.GetUserAsync();

                user.Should().NotBeNull();
                c.Verify(x => x.GetAsync<User>(endpoint));
            }

            [Fact]
            public async Task GetsAuthenticatedUserWithToken()
            {
                var endpoint = "/user";
                var c = new Mock<IConnection>();
                c.Setup(x => x.GetAsync<User>(endpoint)).Returns(fakeUserResponse);
                var client = new GitHubClient
                {
                    Token = "xyz",
                    Connection = c.Object
                };

                var user = await client.GetUserAsync();

                user.Should().NotBeNull();
                c.Verify(x => x.GetAsync<User>(endpoint));
            }

            [Fact]
            public async Task ThrowsIfNotAuthenticated()
            {
                Assert.Throws<AuthenticationException>(async () =>
                {
                    var user = await new GitHubClient().GetUserAsync();
                });
            }
        }
    }
}
<commit_msg>Assert.Throw doesn't seem to work with async<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using FluentAssertions;
using Xunit.Extensions;
using Moq;
using Burr.Http;

namespace Burr.Tests
{
    public class GitHubClientTests
    {
        public class TheConstructor
        {
            [Fact]
            public void CanCreateAnonymousClient()
            {
                var client = new GitHubClient();

                client.AuthenticationType.Should().Be(AuthenticationType.Anonymous);
            }

            [Fact]
            public void CanCreateBasicAuthClient()
            {
                var client = new GitHubClient { Username = "tclem", Password = "<PASSWORD>" };

                client.AuthenticationType.Should().Be(AuthenticationType.Basic);
            }

            [Fact]
            public void CanCreateOauthClient()
            {
                var client = new GitHubClient { Token = "<PASSWORD>" };

                client.AuthenticationType.Should().Be(AuthenticationType.Oauth);
            }

            [InlineData("")]
            [InlineData(" ")]
            [InlineData(null)]
            [Theory]
            public void InvalidTokenFallsBackToAnon(string t)
            {
                var client = new GitHubClient { Token = t };

                client.AuthenticationType.Should().Be(AuthenticationType.Anonymous);
            }

            [InlineData("")]
            [InlineData(" ")]
            [InlineData(null)]
            [Theory]
            public void InvalidUserNameFallsBackToAnon(string t)
            {
                var client = new GitHubClient { Username = t };

                client.AuthenticationType.Should().Be(AuthenticationType.Anonymous);
            }

            [InlineData("")]
            [InlineData(" ")]
            [InlineData(null)]
            [Theory]
            public void InvalidPasswordFallsBackToAnon(string t)
            {
                var client = new GitHubClient { Password = t };

                client.AuthenticationType.Should().Be(AuthenticationType.Anonymous);
            }
        }

        public class TheUserMethod
        {
            Func<Task<IResponse<User>>> fakeUserResponse =
                new Func<Task<IResponse<User>>>(() => Task.FromResult<IResponse<User>>(new Response<User> { BodyAsObject = new User() }));

            [Fact]
            public async Task GetsAuthenticatedUserWithBasic()
            {
                var endpoint = "/user";
                var c = new Mock<IConnection>();
                c.Setup(x => x.GetAsync<User>(endpoint)).Returns(fakeUserResponse);
                var client = new GitHubClient
                {
                    Username = "tclem",
                    Password = "<PASSWORD>",
                    Connection = c.Object
                };

                var user = await client.GetUserAsync();

                user.Should().NotBeNull();
                c.Verify(x => x.GetAsync<User>(endpoint));
            }

            [Fact]
            public async Task GetsAuthenticatedUserWithToken()
            {
                var endpoint = "/user";
                var c = new Mock<IConnection>();
                c.Setup(x => x.GetAsync<User>(endpoint)).Returns(fakeUserResponse);
                var client = new GitHubClient
                {
                    Token = "xyz",
                    Connection = c.Object
                };

                var user = await client.GetUserAsync();

                user.Should().NotBeNull();
                c.Verify(x => x.GetAsync<User>(endpoint));
            }

            [Fact]
            public async Task ThrowsIfNotAuthenticated()
            {
                try
                {
                    var user = await new GitHubClient().GetUserAsync();

                    Assert.True(false, "AuthenticationException was not thrown");
                }
                catch (AuthenticationException ex)
                {
                }
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.10028405582314437, 'fraction_numerical': 0.0, 'mean_word_length': 1.4296429642964297, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 52, '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': '3927527', 'n_tokens_mistral': 2019, 'n_tokens_neox': 1879, 'n_words': 394}