<commit_before>﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using NFleet.Data;
using NUnit.Framework;
using Newtonsoft.Json;
using RestSharp.Deserializers;

namespace NFleet.Tests
{
    [TestFixture]
    internal class ApiTests
    {
        private Dictionary<string, Response> responses;
        private JsonDeserializer deserializer;

        [SetUp]
        public void Setup()
        {
            string url = ConfigurationManager.AppSettings["url"];
            string clientKey = ConfigurationManager.AppSettings["client-key"];
            string clientSecret = ConfigurationManager.AppSettings["client-secret"];
            string responsePath = ConfigurationManager.AppSettings["response-path"];

            Assert.IsNotNullOrEmpty(clientKey);
            Assert.IsNotNullOrEmpty(clientSecret);
            Assert.IsNotNullOrEmpty(url);
            // ReSharper disable UnusedVariable
            //##BEGIN EXAMPLE accessingapi##
            var api = new Api(url, clientKey, clientSecret);
            var tokenResponse = api.Authenticate();
            var rootLinks = api.Root;
            //##END EXAMPLE##
            // ReSharper restore UnusedVariable

            //##BEGIN EXAMPLE oauth##
            //Fail
            //##END EXAMPLE##

            responses = ResponseReader.readResponses(responsePath);
            deserializer = new JsonDeserializer();
            TestUtils.Deserializer = deserializer;
            var users = api.Navigate<UserDataSet>(rootLinks.GetLink( "list-users" ));

            foreach ( var user in users.Items )
            {
                var u = api.Navigate<UserData>( user.GetLink( "self" ) );
                api.Navigate<ResponseData>( u.GetLink( "delete-user" ) );
            } 
        }

        [Test]
        public void T00RootlinkTest()
        {
            var api = TestHelper.Authenticate();<commit_msg>Moved cleanup code to proper place.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using NFleet.Data;
using NUnit.Framework;
using Newtonsoft.Json;
using RestSharp.Deserializers;

namespace NFleet.Tests
{
    [TestFixture]
    internal class ApiTests
    {
        private Dictionary<string, Response> responses;
        private JsonDeserializer deserializer;

        [SetUp]
        public void Setup()
        {
            string url = ConfigurationManager.AppSettings["url"];
            string clientKey = ConfigurationManager.AppSettings["client-key"];
            string clientSecret = ConfigurationManager.AppSettings["client-secret"];
            string responsePath = ConfigurationManager.AppSettings["response-path"];

            Assert.IsNotNullOrEmpty(clientKey);
            Assert.IsNotNullOrEmpty(clientSecret);
            Assert.IsNotNullOrEmpty(url);
            // ReSharper disable UnusedVariable
            //##BEGIN EXAMPLE accessingapi##
            var api = new Api(url, clientKey, clientSecret);
            var tokenResponse = api.Authenticate();
            var rootLinks = api.Root;
            //##END EXAMPLE##
            // ReSharper restore UnusedVariable

            //##BEGIN EXAMPLE oauth##
            //Fail
            //##END EXAMPLE##

            responses = ResponseReader.readResponses(responsePath);
            deserializer = new JsonDeserializer();
            TestUtils.Deserializer = deserializer;
             

            
        }

        [TestFixtureTearDown]
        public void Cleanup()
        {
            string url = ConfigurationManager.AppSettings["url"];
            string clientKey = ConfigurationManager.AppSettings["client-key"];
            string clientSecret = ConfigurationManager.AppSettings["client-secret"];
            string responsePath = ConfigurationManager.AppSettings["response-path"];

            var api = new Api( url, clientKey, clientSecret );
            var tokenResponse = api.Authenticate();
            var rootLinks = api.Root;

            var users = api.Navigate<UserDataSet>( rootLinks.GetLink( "list-users" ) );

            foreach ( var user in users.Items )
            {
                var u = api.Navigate<UserData>( user.GetLink( "self" ) );
                api.Navigate<ResponseData>( u.GetLink( "delete-user" ) );
            }
        }

        [Test]
        public void T00RootlinkTest()
        {
            var api = TestHelper.Authenticate();
{'fraction_non_alphanumeric': 0.09525899912203688, 'fraction_numerical': 0.000877963125548727, 'mean_word_length': 2.1889433170048984, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '5740065', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1137, 'n_words': 258}