public void StartFileWatcher_FileRenamed_CreatesNewDestinationFile()
        {
            var compilerMock = new Mock <ITask>();

            try
            {
                // Arrange
                InitialiseTestEnvironment();
                string _renameFileScssOldFileName = "rename.scss";
                string _renameFileScssNewFileName = "renameNew.scss";

                compilerMock.Setup(o => o.Run(It.IsAny <string>()));
                WriteScssFile(Path.Combine(_testSourcePath, _renameFileScssOldFileName));
                var watcher = new TaskFileWatcher(_testOptions, compilerMock.Object);
                watcher.StartFileWatcher();

                // Act
                var oldPath = Path.Combine(_testSourcePath, _renameFileScssOldFileName);
                var newPath = Path.Combine(_testSourcePath, _renameFileScssNewFileName);
                File.Move(oldPath, newPath);

                // Give the file system a second to catch up
                Thread.Sleep(200);

                watcher.StopFileWatcher();
            }
            finally
            {
                CleanUpTestEnvironment();
            }
            // Assert
            compilerMock.Verify(o => o.Run(It.IsAny <string>()), Times.Once);
        }
        public void StartFileWatcher_FileUpdated_UpdatesDestinationFile()
        {
            var compilerMock = new Mock <ITask>();

            try
            {
                // Arrange
                InitialiseTestEnvironment();
                string _updateContentsScssFileName = "update.scss";

                compilerMock.Setup(o => o.Run(It.IsAny <string>()));
                WriteScssFile(Path.Combine(_testSourcePath, _updateContentsScssFileName));
                var watcher = new TaskFileWatcher(_testOptions, compilerMock.Object);
                watcher.StartFileWatcher();

                // Act
                WriteScssFile(Path.Combine(_testSourcePath, _updateContentsScssFileName), @"body {  
color: blue;
}");
                // Give the file system a second to catch up
                Thread.Sleep(200);

                watcher.StopFileWatcher();
            }
            finally
            {
                CleanUpTestEnvironment();
            }
            // Assert
            compilerMock.Verify(o => o.Run(It.IsAny <string>()), Times.Once);
        }
        public void StartFileWatcher_CompileOnStartTrue_CallsICompilerCompileMethod()
        {
            // Arrange
            InitialiseTestEnvironment();
            var compilerMock = new Mock <ITask>();

            compilerMock.Setup(o => o.Run(It.IsAny <string>()));
            var options = new FileWatcherOptions {
                SourcePath = _testOptions.SourcePath, CompileOnStart = true
            };
            var sassWatcher = new TaskFileWatcher(options, compilerMock.Object);

            // Act
            sassWatcher.StartFileWatcher();
            sassWatcher.StopFileWatcher();

            CleanUpTestEnvironment();
            // Assert
            compilerMock.Verify(o => o.Run(It.IsAny <string>()), Times.Once);
        }
        public void StartFileWatcher_CompileOnStartFalse_DoesNotCallICompilerCompileMethod()
        {
            var compilerMock = new Mock <ITask>();

            try
            {
                // Arrange
                InitialiseTestEnvironment();
                compilerMock.Setup(o => o.Run(It.IsAny <string>()));
                var sassWatcher = new TaskFileWatcher(_testOptions, compilerMock.Object);

                // Act
                sassWatcher.StartFileWatcher();
                sassWatcher.StopFileWatcher();
            }
            finally
            {
                CleanUpTestEnvironment();
            }
            // Assert
            compilerMock.Verify(o => o.Run(It.IsAny <string>()), Times.Never);
        }
        public void StartFileWatcher_FileDeleted_DeletesDestinationFile()
        {
            bool fileExists = true;

            try
            {
                // Arrange
                InitialiseTestEnvironment();
                string _deleteFileScssFileName = "delete.scss";
                string _deleteFileCssFileName  = "delete.css";

                var compilerMock = new Mock <ITask>();
                compilerMock.Setup(o => o.Run(It.IsAny <string>()));
                compilerMock.Setup(o => o.IsExcluded(It.IsAny <string>()));
                var scssPath = Path.Combine(_testSourcePath, _deleteFileScssFileName);
                var cssPath  = Path.Combine(_testDestinationPath, _deleteFileCssFileName);
                WriteScssFile(scssPath);
                WriteScssFile(cssPath);
                var watcher = new TaskFileWatcher(_testOptions, compilerMock.Object);
                watcher.StartFileWatcher();

                // Act
                File.Delete(scssPath);

                // Give the file system a second to catch up
                Thread.Sleep(200);

                watcher.StopFileWatcher();
                fileExists = File.Exists(cssPath);
            }
            finally
            {
                CleanUpTestEnvironment();
            }

            // Assert
            Assert.False(fileExists);
        }