<commit_before>﻿using System.Net.Http.Headers;
using System.Threading.Tasks;
using Xunit;

namespace Octokit.Tests.Integration.Clients
{
    public class StatisticsClientTests
    {
        readonly IGitHubClient _client;
        readonly ICommitsClient _fixture;

        public StatisticsClientTests()
        {
            _client = new GitHubClient(new ProductHeaderValue("OctokitTests"))
            {
                Credentials = Helper.Credentials
            };
            _fixture = _client.GitDatabase.Commit;
        }

        [IntegrationTest]
        public async Task CanCreateAndRetrieveCommit()
        {
            var repository = await CreateRepository();
            await CommitToRepository(repository);
            var contributors = await _client.Statistics.GetContributors(repository.Owner, repository.Name);
            Assert.NotNull(contributors);
        }

        [IntegrationTest]
        public async Task CanGetCommitActivityForTheLastYear()
        {
            var repository = await CreateRepository();
            await CommitToRepository(repository);
            var contributors = await _client.Statistics.GetCommitActivityForTheLastYear(repository.Owner, repository.Name);
            Assert.NotNull(contributors);
        }

        async Task<RepositorySummary> CreateRepository()
        {
            var repoName = Helper.MakeNameWithTimestamp("public-repo");
            var repository = await _client.Repository.Create(new NewRepository { Name = repoName, AutoInit = true });
            return new RepositorySummary
            {
                Owner = repository.Owner.Login,
                Name = repoName
            };
        }

        async Task<Commit> CommitToRepository(RepositorySummary repositorySummary)
        {
            var owner = repositorySummary.Owner;
            var repository = repositorySummary.Name;
            var blob = new NewBlob
            {
                Content = "Hello World!",
                Encoding = EncodingType.Utf8<commit_msg>Extra asserts for contributors intergration tests<commit_after>﻿using System.Linq;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Xunit;

namespace Octokit.Tests.Integration.Clients
{
    public class StatisticsClientTests
    {
        readonly IGitHubClient _client;
        readonly ICommitsClient _fixture;

        public StatisticsClientTests()
        {
            _client = new GitHubClient(new ProductHeaderValue("OctokitTests"))
            {
                Credentials = Helper.Credentials
            };
            _fixture = _client.GitDatabase.Commit;
        }

        [IntegrationTest]
        public async Task CanCreateAndRetrieveCommit()
        {
            var repository = await CreateRepository();
            await CommitToRepository(repository);
            var contributors = await _client.Statistics.GetContributors(repository.Owner, repository.Name);

            Assert.NotNull(contributors);
            Assert.True(contributors.Count() == 1);

            var soleContributor = contributors.First();
            Assert.NotNull(soleContributor.Author);
            Assert.True(soleContributor.Author.Login == repository.Owner);

            Assert.True(soleContributor.Weeks.Count() == 1);
            Assert.True(soleContributor.Total == 1);
        }

        [IntegrationTest]
        public async Task CanGetCommitActivityForTheLastYear()
        {
            var repository = await CreateRepository();
            await CommitToRepository(repository);
            var contributors = await _client.Statistics.GetCommitActivityForTheLastYear(repository.Owner, repository.Name);
            Assert.NotNull(contributors);
        }

        async Task<RepositorySummary> CreateRepository()
        {
            var repoName = Helper.MakeNameWithTimestamp("public-repo");
            var repository = await _client.Repository.Create(new NewRepository { Name = repoName, AutoInit = true });
            return new RepositorySummary
            {
                Owner = repository.Owner.Login,
                Name = repoName
            };
        }

        async Task<Commit> CommitToRepository(RepositorySummary repositorySummary)
        {
            var owner = repositorySummary.Owner;
            var repository = repositorySummary.Name;
            var blob = new NewBlob
            {
                Content = "Hello World!",
                Encoding = EncodingType.Utf8
{'fraction_non_alphanumeric': 0.07496084135153278, 'fraction_numerical': 0.0011188185276348177, 'mean_word_length': 2.128061581525542, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1887007', 'n_tokens_mistral': 1064, 'n_tokens_neox': 1031, 'n_words': 222}