<commit_before>﻿using System;
using System.Threading.Tasks;

namespace Azi.Amazon.CloudDrive.Tests
{
    public abstract class AmazonTestsBase : ITokenUpdateListener, IDisposable
    {
        protected AmazonDrive Amazon;

        protected AmazonTestsBase()
        {
            Amazon = Authenticate().Result;
            var rootId = Amazon.Nodes.GetRoot().Result.id;
            var node = Amazon.Nodes.GetChild(rootId, TestDir).Result;
            if (node == null)
            {
                node = Amazon.Nodes.CreateFolder(rootId, TestDir).Result;
            }
            TestDirId = node.id;
        }

        protected async Task<AmazonDrive> Authenticate()
        {
            var settings = Properties.Settings.Default;
            var amazon = new AmazonDrive(AmazonSecret.ClientId, AmazonSecret.ClientSecret);
            amazon.OnTokenUpdate = this;

            if (!string.IsNullOrWhiteSpace(settings.AuthRenewToken))
            {
                if (await amazon.AuthenticationByTokens(
                    settings.AuthToken,
                    settings.AuthRenewToken,
                    settings.AuthTokenExpiration))
                {
                    return amazon;
                }
            }

            if (await amazon.AuthenticationByExternalBrowser(CloudDriveScopes.ReadAll | CloudDriveScopes.Write, TimeSpan.FromMinutes(10)))
            {
                return amazon;
            }

            return null;
        }

        protected const string TestDir = "ACDDokanNetTest";

        protected string TestDirId;

        public void OnTokenUpdated(string access_token, string refresh_token, DateTime expires_in)
        {
            var settings = Properties.Settings.Default;

            settings.AuthToken = access_token;
            settings.AuthRenewToken = refresh_token;
            settings.AuthTokenExpiration = expires_in;
            settings.Save();
        }

        public void Dispose()
        {
            if (Amazon == null || TestDirId == null) return;
            Amazon.Nodes.Trash(TestDirId).Wait();
        }
    }
}<commit_msg>Unit testn AmazonSecret comment<commit_after>﻿using System;
using System.Threading.Tasks;

namespace Azi.Amazon.CloudDrive.Tests
{
    public abstract class AmazonTestsBase : ITokenUpdateListener, IDisposable
    {
        protected AmazonDrive Amazon;

        protected AmazonTestsBase()
        {
            Amazon = Authenticate().Result;
            var rootId = Amazon.Nodes.GetRoot().Result.id;
            var node = Amazon.Nodes.GetChild(rootId, TestDir).Result;
            if (node == null)
            {
                node = Amazon.Nodes.CreateFolder(rootId, TestDir).Result;
            }
            TestDirId = node.id;
        }

        protected async Task<AmazonDrive> Authenticate()
        {
            var settings = Properties.Settings.Default;

            // AmazonSecret is in git ignore because Amazon App info should not be public. 
            // So to run tests you need to create your own class with your App Id and Secret.
            var amazon = new AmazonDrive(AmazonSecret.ClientId, AmazonSecret.ClientSecret);
            amazon.OnTokenUpdate = this;

            if (!string.IsNullOrWhiteSpace(settings.AuthRenewToken))
            {
                if (await amazon.AuthenticationByTokens(
                    settings.AuthToken,
                    settings.AuthRenewToken,
                    settings.AuthTokenExpiration))
                {
                    return amazon;
                }
            }

            if (await amazon.AuthenticationByExternalBrowser(CloudDriveScopes.ReadAll | CloudDriveScopes.Write, TimeSpan.FromMinutes(10)))
            {
                return amazon;
            }

            return null;
        }

        protected const string TestDir = "ACDDokanNetTest";

        protected string TestDirId;

        public void OnTokenUpdated(string access_token, string refresh_token, DateTime expires_in)
        {
            var settings = Properties.Settings.Default;

            settings.AuthToken = access_token;
            settings.AuthRenewToken = refresh_token;
            settings.AuthTokenExpiration = expires_in;
            settings.Save();
        }

        public void Dispose()
        {
            if (Amazon == null || TestDirId == null) return;
            Amazon.Nodes.Trash(TestDirId).Wait();
        }
    }
}
{'fraction_non_alphanumeric': 0.07676676450666065, 'fraction_numerical': 0.0009031384059607134, 'mean_word_length': 1.744733581164808, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2878714', 'n_tokens_mistral': 1139, 'n_tokens_neox': 1071, 'n_words': 239}