Exemple #1
0
        public void CopyFiles_WhenDestinationFolderNotExists_CreateFoldersAndCopyFiles()
        {
            //Arrange
            DiskConfigurator creator = new DiskConfigurator(_fileSystem);

            var sourcePath      = Path.Combine(_userFolder, "Source");
            var destinationPath = Path.Combine(_userFolder, "Destination");

            _fileSystemMock
            .Setup(fs => fs.DirectoryExists(It.Is <string>(s => s == sourcePath)))
            .Returns(true);
            _fileSystemMock
            .Setup(fs => fs.GetFiles(sourcePath, null, SearchOption.AllDirectories))
            .Returns(new[] { "/Users/user/Source/NotExist/File1.txt" });
            _fileSystemMock
            .Setup(fs => fs.DirectoryExists(It.Is <string>(s => s.Contains("NotExist"))))
            .Returns(false);
            _fileSystemMock
            .Setup(fs => fs.GetDirectoryName(It.Is <string>(s => s.Contains("NotExist"))))
            .Returns("/Users/user/Destination/NotExist/");
            _fileSystemMock.Setup(fs => fs.CreateDirectory(It.IsAny <string>())).Verifiable();
            _fileSystemMock.Setup(fs => fs.CopyFile(It.IsAny <string>(), It.IsAny <string>(), false)).Verifiable();
            //Act
            creator.CopyFiles(sourcePath, destinationPath);
            //Assert
            _fileSystemMock.Verify(fs => fs.CreateDirectory(It.IsAny <string>()), Times.Exactly(1));
            _fileSystemMock.VerifyAll();
        }
Exemple #2
0
        public void FilterCreator_WhenCalls_ReturnFilterList(string[] expectedResult, bool ignoreSystemFiles, params string[] extension)
        {
            //Arrange
            DiskConfigurator creator = new DiskConfigurator(_fileSystem);
            //Act
            var result = creator.FilterCreator(ignoreSystemFiles, extension);

            //Assert
            Assert.Equal(expectedResult, result);
            _fileSystemMock.VerifyAll();
        }
Exemple #3
0
        public void FilterCreator_WhitoutFileSystemParameter_ReturnFilterListWithExtensions()
        {
            //Arrange
            DiskConfigurator creator = new DiskConfigurator(_fileSystem);
            //Act
            var result = creator.FilterCreator("css", "js");

            //Assert
            Assert.Equal(new string[] { @"([^\s]+(\.(?i)(css|js))$)" }, result);
            _fileSystemMock.VerifyAll();
        }
Exemple #4
0
        public void FilterCreator_WhenExtensionIsNull_ReturnsException()
        {
            //Arrange
            DiskConfigurator creator = new DiskConfigurator(_fileSystem);
            //Act
            Action result = () => creator.FilterCreator(false, null);

            //Assert
            Assert.Throws <ArgumentException>(result);
            _fileSystemMock.VerifyAll();
        }
Exemple #5
0
        public void IsFilter_WhenFileIsNull_ReturnsException()
        {
            //Arrange
            DiskConfigurator creator = new DiskConfigurator(_fileSystem);
            MethodInfo       method  = typeof(DiskConfigurator).GetMethod("IsFiltered", BindingFlags.NonPublic | BindingFlags.Instance);

            //Act
            object[] parameters = { new List <string>(new string[] { }), null };
            Action   result     = () => method.Invoke(creator, parameters);

            //Assert
            Assert.Throws <TargetInvocationException>(result);
            _fileSystemMock.VerifyAll();
        }
Exemple #6
0
        public void IsFilter_WhenFilterIsNull_ReturnsException()
        {
            //Arrange
            DiskConfigurator creator = new DiskConfigurator(_fileSystem);
            MethodInfo       method  = typeof(DiskConfigurator).GetMethod("IsFiltered", BindingFlags.NonPublic | BindingFlags.Instance);

            //Act
            object[] parameters = { null, "/Users/user/Source/Exist/File.txt" };
            var      result     = method.Invoke(creator, parameters);

            //Assert
            Assert.Equal(true, result);
            _fileSystemMock.VerifyAll();
        }
Exemple #7
0
        static void Main(string[] args)
        {
            try
            {
                _disk = new DiskConfigurator(FileSystem.Default);
                switch (OS.GetCurrent())
                {
                case "win":
                    _path = new PathsConfigurator(CommandSystem.Win, FileSystem.Default);
                    break;

                case "mac":
                    _path = new PathsConfigurator(CommandSystem.Mac, FileSystem.Default);
                    break;
                }

                _notificationSystem = NotificationSystem.Default;
                switch (OS.GetCurrent())
                {
                case "win":
                    _bridgeSystem = BridgeSystem.Bat;
                    _colorify     = new Format(Theme.Dark);
                    break;

                case "gnu":
                    _bridgeSystem = BridgeSystem.Bash;
                    _colorify     = new Format(Theme.Dark);
                    break;

                case "mac":
                    _bridgeSystem = BridgeSystem.Bash;
                    _colorify     = new Format(Theme.Light);
                    break;
                }
                _shell = new ShellConfigurator(_bridgeSystem, _notificationSystem);
                Menu();
                _colorify.ResetColor();
                _colorify.Clear();
            }
            catch (ArgumentOutOfRangeException)
            {
                MessageException("Ahh my eyes! Why this console is too small?");
            }
            catch (Exception ex)
            {
                MessageException(ex.ToString());
            }
        }
Exemple #8
0
        public void IsFiltered_WhenCalls_VerifyFileWithRules(bool expectedResult, string[] regexFilter, string filePath, string file)
        {
            //Arrange
            DiskConfigurator creator = new DiskConfigurator(_fileSystem);
            MethodInfo       method  = typeof(DiskConfigurator).GetMethod("IsFiltered", BindingFlags.NonPublic | BindingFlags.Instance);

            _fileSystemMock
            .Setup(fs => fs.GetFileName(It.Is <string>(s => s == filePath)))
            .Returns(file);
            //Act
            object[] parameters = { (regexFilter == null ? null : new List <string>(regexFilter)), filePath };
            var      result     = method.Invoke(creator, parameters);

            //Assert
            Assert.Equal(expectedResult, result);
            _fileSystemMock.VerifyAll();
        }
Exemple #9
0
        public void DeleteAll_WhenCalls_DeleteFilesAndFolders()
        {
            DiskConfigurator creator = new DiskConfigurator(_fileSystem);

            string path = Path.Combine(_userFolder, "Exist");

            _fileSystemMock
            .Setup(fs => fs.DirectoryExists(It.Is <string>(s => s == path)))
            .Returns(true);
            _fileSystemMock
            .Setup(fs => fs.DeleteDirectory(It.IsAny <string>(), true))
            .Verifiable();

            //Act
            creator.DeleteAll(path, true);
            //Assert
            _fileSystemMock.VerifyAll();
        }
Exemple #10
0
        public void CopyFiles_WhenPathNotFound_ReturnsException()
        {
            //Arrange
            DiskConfigurator creator = new DiskConfigurator(_fileSystem);

            string sourcePath      = Path.Combine(_userFolder, "NotExist");
            string destinationPath = Path.Combine(_userFolder, "NotMatters");

            _fileSystemMock
            .Setup(fs => fs.DirectoryExists(It.Is <string>(s => s == sourcePath)))
            .Returns(false);

            //Act
            Action result = () => creator.CopyFiles(sourcePath, destinationPath);

            //Assert
            Assert.Throws <DirectoryNotFoundException>(result);
            _fileSystemMock.VerifyAll();
        }
Exemple #11
0
        public void CopyDirectories_WhenDestinationExists_CopyFolders()
        {
            //Arrange
            DiskConfigurator creator = new DiskConfigurator(_fileSystem);

            var sourcePath      = Path.Combine(_userFolder, "Source");
            var destinationPath = Path.Combine(_userFolder, "Destination");

            _fileSystemMock
            .Setup(fs => fs.DirectoryExists(It.IsAny <string>()))
            .Returns(true);
            _fileSystemMock
            .Setup(fs => fs.GetDirectories(sourcePath, null, SearchOption.AllDirectories))
            .Returns(new[] { "/Users/user/Source/Exist" });
            //Act
            creator.CopyDirectories(sourcePath, destinationPath);
            //Assert
            _fileSystemMock.VerifyAll();
        }
Exemple #12
0
        public void CopyFiles_WhenSourceIsEmpty_CopyAnything()
        {
            //Arrange
            DiskConfigurator creator = new DiskConfigurator(_fileSystem);

            var sourcePath      = Path.Combine(_userFolder, "Source");
            var destinationPath = Path.Combine(_userFolder, "Destination");

            _fileSystemMock
            .Setup(fs => fs.DirectoryExists(It.Is <string>(s => s == sourcePath)))
            .Returns(true);
            _fileSystemMock
            .Setup(fs => fs.GetFiles(sourcePath, null, SearchOption.AllDirectories))
            .Returns(Enumerable.Empty <string>);
            //Act
            creator.CopyFiles(sourcePath, destinationPath);
            //Assert
            _fileSystemMock.Verify(fs => fs.DirectoryExists(It.IsAny <string>()), Times.Exactly(1));
            _fileSystemMock.VerifyAll();
        }
Exemple #13
0
        private static void Factory()
        {
            _fileSystem         = FileSystem.Default;
            _notificationSystem = new ConsoleNotificationSystem();
            _disk = new DiskConfigurator(_fileSystem, _notificationSystem);
            switch (OS.GetCurrent())
            {
            case "win":
                _path         = new PathsConfigurator(CommandSystem.Win, _fileSystem);
                _bridgeSystem = BridgeSystem.Bat;
                _colorify     = new Format(Theme.Dark);
                break;

            case "mac":
                _path         = new PathsConfigurator(CommandSystem.Mac, _fileSystem);
                _bridgeSystem = BridgeSystem.Bash;
                _colorify     = new Format(Theme.Light);
                break;
            }
            _shell     = new ShellConfigurator(_bridgeSystem, _notificationSystem);
            _logSystem = new FileLogTxt(_fileSystem, _path.Combine("~"), ".hardhat.log");
        }