<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Engine.DataTypes;
using Engine.Drivers.Context;
using Engine.Drivers.Rules;
using Couchbase;
using Tweek.Drivers.CouchbaseDriver;
using Engine.Drivers.Rules.Git;
using System.IO;
using Couchbase.Core;

namespace Engine.Tests.TestDrivers
{
    class CouchbaseTestDriver : ITestDriver
    {
        readonly Cluster _cluster;
        readonly CouchBaseDriver _driver;
        
        public IContextDriver Context => _driver;
        public Func<Task> cleanup = async ()=> {};

        public CouchbaseTestDriver(Cluster cluster, string bucket)
        {
            _cluster = cluster;
            _driver = new CouchBaseDriver(cluster, bucket);
        }

        async Task InsertRuleData(GitDriver driver, Dictionary<string, RuleDefinition> rules)
        {
            await
                Task.WhenAll(
                    rules.Select(
                        x => driver.CommitRuleset(x.Key, x.Value, "tweekintegrationtests", "<EMAIL>", DateTimeOffset.UtcNow)));
        }


        async Task InsertContextRows(Dictionary<Identity, Dictionary<string, string>> contexts)
        {
            cleanup = () => Task.WhenAll(contexts.Select(x => x.Key).Select(_driver.RemoveIdentityContext));

            await Task.WhenAll(
                contexts.Map(x => _driver.AppendContext(x.Key, x.Value)
                ));
        }

       
        async Task Flush()
        {
            await cleanup();
            _driver.Dispose();
        }

        public TestScope SetTestEnviornment(Dictionary<Identity, Dictionary<string, string>> contexts, string[] keys, Dictionary<string, RuleDefinition> rules)
        {
            var gitDriver = new GitDriver(Path.Combine(Environment.CurrentDirectory, "tweek-rules-tests" + Guid.NewGuid()));

            return new TestScope(rules: gitDriver, context: Context, 
                init: () => Task.WhenAll(InsertContextRows(contexts), InsertRuleData(gitDriver, rules)),
                dispose: Flush);
        }
    }
}<commit_msg>fix integraion tests execution folder<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Engine.DataTypes;
using Engine.Drivers.Context;
using Engine.Drivers.Rules;
using Couchbase;
using Tweek.Drivers.CouchbaseDriver;
using Engine.Drivers.Rules.Git;
using System.IO;
using Couchbase.Core;

namespace Engine.Tests.TestDrivers
{
    class CouchbaseTestDriver : ITestDriver
    {
        readonly Cluster _cluster;
        readonly CouchBaseDriver _driver;
        
        public IContextDriver Context => _driver;
        public Func<Task> cleanup = async ()=> {};

        public CouchbaseTestDriver(Cluster cluster, string bucket)
        {
            _cluster = cluster;
            _driver = new CouchBaseDriver(cluster, bucket);
        }

        async Task InsertRuleData(GitDriver driver, Dictionary<string, RuleDefinition> rules)
        {
            await
                Task.WhenAll(
                    rules.Select(
                        x => driver.CommitRuleset(x.Key, x.Value, "tweekintegrationtests", "<EMAIL>", DateTimeOffset.UtcNow)));
        }


        async Task InsertContextRows(Dictionary<Identity, Dictionary<string, string>> contexts)
        {
            cleanup = () => Task.WhenAll(contexts.Select(x => x.Key).Select(_driver.RemoveIdentityContext));

            await Task.WhenAll(
                contexts.Map(x => _driver.AppendContext(x.Key, x.Value)
                ));
        }

       
        async Task Flush()
        {
            await cleanup();
            _driver.Dispose();
        }

        public TestScope SetTestEnviornment(Dictionary<Identity, Dictionary<string, string>> contexts, string[] keys, Dictionary<string, RuleDefinition> rules)
        {
            var gitDriver = new GitDriver(Path.Combine(Path.GetTempPath(), "tweek-rules-tests" + Guid.NewGuid()));

            return new TestScope(rules: gitDriver, context: Context, 
                init: () => Task.WhenAll(InsertContextRows(contexts), InsertRuleData(gitDriver, rules)),
                dispose: Flush);
        }
    }
}
{'fraction_non_alphanumeric': 0.10103383458646617, 'fraction_numerical': 0.0, 'mean_word_length': 2.4302981466559226, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 33, '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': '5928438', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1124, 'n_words': 246}