<commit_before>﻿// ------------------------
//    WInterop Framework
// ------------------------

// Copyright (c) <NAME>. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using FluentAssertions;
using System;
using Tests.Support;
using WInterop.DirectoryManagement;
using Xunit;

namespace Tests.DirectoryManagement
{
    public class DirectoryManagementTests
    {
        [Fact]
        public void GetCurrentDirectoryBasic()
        {
            string currentDirectory = DirectoryMethods.GetCurrentDirectory();
            currentDirectory.Should().NotBeNullOrWhiteSpace();
        }

        [Fact]
        public void SetCurrentDirectoryBasic()
        {
            string currentDirectory = DirectoryMethods.GetCurrentDirectory();

            StoreHelper.ValidateStoreGetsUnauthorizedAccess(() =>
            {
                DirectoryMethods.SetCurrentDirectory(@"C:\");
                DirectoryMethods.GetCurrentDirectory().Should().Be(@"C:\");
            });
            DirectoryMethods.SetCurrentDirectory(currentDirectory);
            DirectoryMethods.GetCurrentDirectory().Should().Be(currentDirectory);
        }

        [Fact]
        public void SetCurrentDirectoryToNonExistant()
        {
            using (var cleaner = new TestFileCleaner())
            {
                string directoryPath = cleaner.GetTestPath();
                Action action = () => DirectoryMethods.SetCurrentDirectory(directoryPath);
                action.ShouldThrow<System.IO.FileNotFoundException>();
            }
        }

        [Fact]
        public void CreateDirectoryBasic()
        {
            using (var temp = new TestFileCleaner())
            {
                string directoryPath = temp.GetTestPath();
                DirectoryMethods.CreateDirectory(directoryPath);
                using (var directory = DirectoryMethods.CreateDirectoryHandle(directoryPath))
                {
                    directory.IsInvalid.Should().BeFalse();
                }
            }
        }

        [Fact]
        public void DeleteDirectoryBasic()
        {
            using (var temp = new TestFileCleaner())
            {
                string directoryPath = temp.GetTestPath();
                DirectoryMethods.CreateDirectory(directoryPath);
                using (var directory = DirectoryMethods.CreateDirectoryHandle(directoryPath))
                {
                    directory.IsInvalid.Should().BeFalse();
                }

                DirectoryMethods.RemoveDirectory(directoryPath);

                Action action = () =>
                {
                    using (var directory = DirectoryMethods.CreateDirectoryHandle(directoryPath))
                    {
                    }
                };

                action.ShouldThrow<System.IO.FileNotFoundException>();
            }
        }
    }
}
<commit_msg>Add a test to validate set current directory 8.3 behavior.<commit_after>﻿// ------------------------
//    WInterop Framework
// ------------------------

// Copyright (c) <NAME>. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using FluentAssertions;
using System;
using Tests.Support;
using WInterop.DirectoryManagement;
using Xunit;

namespace Tests.DirectoryManagement
{
    public class DirectoryManagementTests
    {
        [Fact]
        public void GetCurrentDirectoryBasic()
        {
            string currentDirectory = DirectoryMethods.GetCurrentDirectory();
            currentDirectory.Should().NotBeNullOrWhiteSpace();
        }

        [Fact]
        public void SetCurrentDirectoryBasic()
        {
            string currentDirectory = DirectoryMethods.GetCurrentDirectory();

            try
            {
                StoreHelper.ValidateStoreGetsUnauthorizedAccess(() =>
                {
                    DirectoryMethods.SetCurrentDirectory(@"C:\");
                    DirectoryMethods.GetCurrentDirectory().Should().Be(@"C:\");
                });
            }
            finally
            {
                if (currentDirectory != DirectoryMethods.GetCurrentDirectory())
                {
                    DirectoryMethods.SetCurrentDirectory(currentDirectory);
                    DirectoryMethods.GetCurrentDirectory().Should().Be(currentDirectory);
                }
            }
        }

        [Fact]
        public void SetCurrentDirectoryShortName()
        {
            string currentDirectory = DirectoryMethods.GetCurrentDirectory();

            try
            {
                StoreHelper.ValidateStoreGetsUnauthorizedAccess(() =>
                {
                    DirectoryMethods.SetCurrentDirectory(@"C:\PROGRA~1");
                    DirectoryMethods.GetCurrentDirectory().Should().Be(@"C:\PROGRA~1");
                });
            }
            finally
            {
                if (currentDirectory != DirectoryMethods.GetCurrentDirectory())
                {
                    DirectoryMethods.SetCurrentDirectory(currentDirectory);
                    DirectoryMethods.GetCurrentDirectory().Should().Be(currentDirectory);
                }
            }
        }

        [Fact]
        public void SetCurrentDirectoryToNonExistant()
        {
            using (var cleaner = new TestFileCleaner())
            {
                string directoryPath = cleaner.GetTestPath();
                Action action = () => DirectoryMethods.SetCurrentDirectory(directoryPath);
                action.ShouldThrow<System.IO.FileNotFoundException>();
            }
        }

        [Fact]
        public void CreateDirectoryBasic()
        {
            using (var temp = new TestFileCleaner())
            {
                string directoryPath = temp.GetTestPath();
                DirectoryMethods.CreateDirectory(directoryPath);
                using (var directory = DirectoryMethods.CreateDirectoryHandle(directoryPath))
                {
                    directory.IsInvalid.Should().BeFalse();
                }
            }
        }

        [Fact]
        public void DeleteDirectoryBasic()
        {
            using (var temp = new TestFileCleaner())
            {
                string directoryPath = temp.GetTestPath();
                DirectoryMethods.CreateDirectory(directoryPath);
                using (var directory = DirectoryMethods.CreateDirectoryHandle(directoryPath))
                {
                    directory.IsInvalid.Should().BeFalse();
                }

                DirectoryMethods.RemoveDirectory(directoryPath);

                Action action = () =>
                {
                    using (var directory = DirectoryMethods.CreateDirectoryHandle(directoryPath))
                    {
                    }
                };

                action.ShouldThrow<System.IO.FileNotFoundException>();
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.09832065451413807, 'fraction_numerical': 0.0005741352088416823, 'mean_word_length': 1.5903345724907063, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 16, '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': '6648713', 'n_tokens_mistral': 1558, 'n_tokens_neox': 1428, 'n_words': 271}