public void SetupDecoratorForTest() { Engine = new Mock <ILessEngine>(); ParameterSource = new Mock <IParameterSource>(); Parameters = new Dictionary <string, string>(); ParameterSource.Setup(p => p.GetParameters()).Returns(Parameters); ParameterDecorator = new ParameterDecorator(Engine.Object, ParameterSource.Object); }
public void SetupDecoratorForTest() { Engine = new Mock<ILessEngine>(); ParameterSource = new Mock<IParameterSource>(); Parameters = new Dictionary<string, string>(); ParameterSource.Setup(p => p.GetParameters()).Returns(Parameters); ParameterDecorator = new ParameterDecorator(Engine.Object, ParameterSource.Object); }
public void NullVariableValuesProduceSensibleErrorMessage() { var parameterSourceMock = new Mock <IParameterSource>(); parameterSourceMock.Setup(s => s.GetParameters()).Returns(new Dictionary <string, string> { { "color", null } }); var decorator = new ParameterDecorator(new LessEngine(), parameterSourceMock.Object); Assert.DoesNotThrow(() => decorator.TransformToCss("", "test.less")); }
/// <inheritdoc /> protected override Task <IEnumerable <IDocument> > ExecuteContextAsync(IExecutionContext context) { DotlessConfiguration config = DotlessConfiguration.GetDefault(); // config.Logger = typeof(LessLogger); EngineFactory engineFactory = new EngineFactory(config); FileSystemReader fileSystemReader = new FileSystemReader(context.FileSystem); return(context.Inputs.ParallelSelectAsync(ProcessLessAsync)); async Task <IDocument> ProcessLessAsync(IDocument input) { context.LogDebug("Processing Less for {0}", input.ToSafeDisplayString()); // This is a hack to get to the underlying engine ParameterDecorator parameterDecorator = (ParameterDecorator)engineFactory.GetEngine(); CacheDecorator cacheDecorator = (CacheDecorator)parameterDecorator.Underlying; LessEngine engine = (LessEngine)cacheDecorator.Underlying; engine.Logger = new LessLogger(context); ((Importer)engine.Parser.Importer).FileReader = fileSystemReader; // Less conversion FilePath path = await _inputPath.GetValueAsync(input, context); if (path != null) { engine.CurrentDirectory = path.Directory.FullPath; } else { engine.CurrentDirectory = string.Empty; path = new FilePath(Path.GetRandomFileName()); context.LogWarning($"No input path found for document {input.ToSafeDisplayString()}, using {path.FileName.FullPath}"); } string content = engine.TransformToCss(await input.GetContentStringAsync(), path.FileName.FullPath); // Process the result FilePath cssPath = path.GetRelativeInputPath(context).ChangeExtension("css"); return(input.Clone( cssPath, await context.GetContentProviderAsync(content))); } }