<commit_before>﻿using System;
using System.Linq;
using DotNet.Basics.IO;
using FluentAssertions;
using NUnit.Framework;

namespace DotNet.Basics.Tests.IO
{
    [TestFixture]
    public class DirExtensionsTests
    {
        private const string _testDirRoot = @"K:\testDir";
        private const string _testDoubleDir = @"\testa\testb";
        private const string _testSingleDir = @"\testk\";

        [Test]
        public void DeleteIfExists_DirExists_DirIsDeleted()
        {
            var dir = TestContext.CurrentContext.TestDirectory.ToDir(@"DeleteIfExists_DirExists_DirIsDeleted");

            dir.CreateIfNotExists();

            dir.Exists().Should().BeTrue();

            //act
            dir.DeleteIfExists();

            dir.Exists().Should().BeFalse();
        }


        [Test]
        public void DeleteIfExists_DeleteLongNamedDir_DirIsDeleted()
        {
            //arrange
            //we set up a folder with a really long name
            const string testDirName = "DeleteIfExists_DeleteLongNamedDir_DirIsDeleted";

            var rootTestdir = TestContext.CurrentContext.TestDirectory.ToDir(testDirName);
            rootTestdir.CleanIfExists();
            var identicalSubDir = rootTestdir;
            try
            {
                //we keep adding sub folders until we reach our limit - whichever comes first
                for (var level = 0; level < 15; level++)
                {
                    identicalSubDir.CreateIfNotExists();
                    identicalSubDir = identicalSubDir.ToDir(testDirName);
                }
            }
            catch (System.IO.PathTooLongException)
            {
                identicalSubDir.CleanIfExists();
            }

            rootTestdir.Exists().Should().BeTrue();

            //act
            var deleted = rootTestdir.DeleteIfExists();

            //assert
            deleted.Should().BeTrue();
            rootTestdir.Exists().Should().BeFalse();
        }
        
        [Test]
        public void Parent_NameOnlySourceDir_PartenIsResolved()
        {
            var currentDir = TestContext.CurrentContext.TestDirectory.ToDir();
            var dir = TestContext.CurrentContext.TestDirectory.ToDir(@"Parent_NameOnlySourceDir_PartenIsResolved");

            dir.Parent.FullName.Should().Be(currentDir.FullName);
        }

        [Test]
        public void Parent_FullSourceDir_ParenItsResolved()
        {
            var parent = @"C:\Projects\dotnet.basics\DotNet.Basics.Tests\bin\Debug".ToDir();
            var dir = parent.ToDir("Parent_ParentDir_PartenIsResolved");

            dir.Parent.FullName.Should().Be(parent.FullName);
        }


        [Test]
        public void CopyTo_IncludeSubDirectories_DirIsCopied()
        {
            const int dirDepth = 3;
            var root = TestContext.CurrentContext.TestDirectory.ToDir("CopyTo_InclSubDirs_DirIsCop");
            root.DeleteIfExists();
            var currentDir = CreateIdenticalSubdirs(root, dirDepth);
            "blaaaa".WriteAllText(currentDir, "myFile.txt");

            var targetRoot = (root.Name + "Target").ToDir();
            var targetDir = targetRoot.CreateSubDir(root.Name);
            targetDir.DeleteIfExists();
            targetDir.Exists().Should().BeFalse();

            root.CopyTo(targetDir, includeSubfolders: true);

            targetDir.Exists().Should().BeTrue();
            GetHierarchyDepth(targetDir).Should().Be(dirDepth + 1);
        }

        [Test]<commit_msg>Fixed tests where test context wasn't set properly resulting in test folder being created in git root instead of test root<commit_after>﻿using System;
using System.Linq;
using DotNet.Basics.IO;
using FluentAssertions;
using NUnit.Framework;

namespace DotNet.Basics.Tests.IO
{
    [TestFixture]
    public class DirExtensionsTests
    {
        private const string _testDirRoot = @"K:\testDir";
        private const string _testDoubleDir = @"\testa\testb";
        private const string _testSingleDir = @"\testk\";

        [Test]
        public void DeleteIfExists_DirExists_DirIsDeleted()
        {
            var dir = TestContext.CurrentContext.TestDirectory.ToDir(@"DeleteIfExists_DirExists_DirIsDeleted");

            dir.CreateIfNotExists();

            dir.Exists().Should().BeTrue();

            //act
            dir.DeleteIfExists();

            dir.Exists().Should().BeFalse();
        }


        [Test]
        public void DeleteIfExists_DeleteLongNamedDir_DirIsDeleted()
        {
            //arrange
            //we set up a folder with a really long name
            const string testDirName = "DeleteIfExists_DeleteLongNamedDir_DirIsDeleted";

            var rootTestdir = TestContext.CurrentContext.TestDirectory.ToDir(testDirName);
            rootTestdir.CleanIfExists();
            var identicalSubDir = rootTestdir;
            try
            {
                //we keep adding sub folders until we reach our limit - whichever comes first
                for (var level = 0; level < 15; level++)
                {
                    identicalSubDir.CreateIfNotExists();
                    identicalSubDir = identicalSubDir.ToDir(testDirName);
                }
            }
            catch (System.IO.PathTooLongException)
            {
                identicalSubDir.CleanIfExists();
            }

            rootTestdir.Exists().Should().BeTrue();

            //act
            var deleted = rootTestdir.DeleteIfExists();

            //assert
            deleted.Should().BeTrue();
            rootTestdir.Exists().Should().BeFalse();
        }
        
        [Test]
        public void Parent_NameOnlySourceDir_PartenIsResolved()
        {
            var currentDir = TestContext.CurrentContext.TestDirectory.ToDir();
            var dir = TestContext.CurrentContext.TestDirectory.ToDir(@"Parent_NameOnlySourceDir_PartenIsResolved");

            dir.Parent.FullName.Should().Be(currentDir.FullName);
        }

        [Test]
        public void Parent_FullSourceDir_ParenItsResolved()
        {
            var parent = @"C:\Projects\dotnet.basics\DotNet.Basics.Tests\bin\Debug".ToDir();
            var dir = parent.ToDir("Parent_ParentDir_PartenIsResolved");

            dir.Parent.FullName.Should().Be(parent.FullName);
        }


        [Test]
        public void CopyTo_IncludeSubDirectories_DirIsCopied()
        {
            const int dirDepth = 3;
            var root = TestContext.CurrentContext.TestDirectory.ToDir("CopyTo_InclSubDirs_DirIsCop");
            root.DeleteIfExists();
            var currentDir = CreateIdenticalSubdirs(root, dirDepth);
            "blaaaa".WriteAllText(currentDir, "myFile.txt");

            var targetRoot = TestContext.CurrentContext.TestDirectory.ToDir(root.Name + "Target");
            var targetDir = targetRoot.CreateSubDir(root.Name);
            targetDir.DeleteIfExists();
            targetDir.Exists().Should().BeFalse();

            root.CopyTo(targetDir, includeSubfolders: true);

            targetDir.Exists().Should().BeTrue();
            GetHierarchyDepth(targetDir).Should().Be(dirDepth + 1);
        }

        [Test]
{'fraction_non_alphanumeric': 0.09878100042034468, 'fraction_numerical': 0.0014011489421325487, 'mean_word_length': 2.0517315091919626, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3620937', 'n_tokens_mistral': 1930, 'n_tokens_neox': 1862, 'n_words': 339}