public void SassFileWatcher_EmptyFileNameFilters_ThrowsEmptyArrayException()
        {
            // Arrange
            var options = new FileWatcherOptions {
                SourcePath = "test", FileNameFilters = new List <string>()
            };
            var compilerMock = new Mock <ITask>();

            // Assert
            Assert.Throws <EmptyArrayException>(() => new TaskFileWatcher(options, compilerMock.Object));
        }
        public void SassFileWatcher_NullSourcePath_ThrowsEmptyStringException()
        {
            // Arrange
            var options = new FileWatcherOptions {
                SourcePath = null
            };
            var compilerMock = new Mock <ITask>();

            // Assert
            Assert.Throws <EmptyStringException>(() => new TaskFileWatcher(options, compilerMock.Object));
        }
コード例 #3
0
        public ITask GetTask(string name, FileWatcherOptions options)
        {
            if (_tasks.ContainsKey(name))
            {
                Type   type = _tasks[name];
                object?task = Activator.CreateInstance(type, options);
                if (task == null)
                {
                    throw new NullReferenceException("Activator failed to create an instance of " + nameof(type));
                }

                return((ITask)task);
            }

            throw new NoTaskRegistered(name);
        }
コード例 #4
0
        public void Compile(List <SassCompilerTaskTestData> filesToCreate, string sourceDirectory, string destinationDirectory)
        {
            bool fileExists = false;

            try
            {
                // Arrange
                foreach (var file in filesToCreate)
                {
                    WriteScssFile(file.SourceLocation, file.FileContent);
                }
                FileWatcherOptions options = new FileWatcherOptions()
                {
                    CompileOnStart = false, DestinationPath = destinationDirectory, SourcePath = sourceDirectory
                };
                ITask compiler = new SassCompilerTask(options);

                // Act
                compiler.Run(sourceDirectory);

                foreach (var file in filesToCreate)
                {
                    if (compiler.IsExcluded(Path.GetFileName(file.SourceLocation)))
                    {
                        fileExists = !File.Exists(file.DestinationLocation);
                    }
                    else
                    {
                        fileExists = File.Exists(file.DestinationLocation);
                    }

                    if (fileExists == false)
                    {
                        break;
                    }
                }
            }
            finally
            {
                CleanUpTestEnvironment();
            }
            // Assert
            Assert.True(fileExists);
        }
        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);
        }
        private void InitialiseTestEnvironment()
        {
            var tempDir = Environment.GetEnvironmentVariable("temp");

            if (string.IsNullOrEmpty(tempDir))
            {
                throw new XunitException("Unable to load the temp directory from environment variables.");
            }

            _testRootPath = Path.Combine(tempDir, _testDirectoryName);
            Directory.CreateDirectory(_testRootPath);

            _testSourcePath = Path.Combine(_testRootPath, "Source");
            Directory.CreateDirectory(_testSourcePath);

            _testDestinationPath = Path.Combine(_testRootPath, "Destination");
            Directory.CreateDirectory(_testDestinationPath);

            _testOptions = new FileWatcherOptions {
                SourcePath = _testSourcePath, DestinationPath = _testDestinationPath, CompileOnStart = false
            };
        }
コード例 #7
0
 /// <summary>
 /// Creates a new SassCompilerTask ready to be called when a file changes.
 /// </summary>
 /// <param name="options">The file watcher options. Must have the SourcePath, DestinationPath and FileNameExclusions.</param>
 public SassCompilerTask(FileWatcherOptions options)
 {
     _options = options;
 }