Inheritance: ICompilerConfiguration
Ejemplo n.º 1
0
        public void CompileFile_NoCompilerForMinification_ThrowsException()
        {
            var compiler = new DefaultSourceCompiler(true, ".js");

            var config = new CompilerConfiguration().CompilerFor(".js", new PassthroughCompiler());

            compiler.CompileFile(new FileInfo("blah.js"), config);
        }
        public void CompileFile_NoCompilerForMinification_ThrowsException()
        {
            var compiler = new DefaultSourceCompiler(true, ".js");

            var config = new CompilerConfiguration().CompilerFor(".js", new PassthroughCompiler()) as CompilerConfiguration;

            Assert.ThrowsAsync(typeof(InvalidOperationException), async () =>
            {
                await compiler.CompileFile(new FileInfo("blah.js"), config).ConfigureAwait(false);
            });
        }
        public void FindDestinationPile_WithRealPile_ReturnsCorrectSetOfFiles()
        {
            var pile = GetWorkingPile(true);
            var compiler = new CompilerConfiguration();
            _sourceCompiler.CompileFile(Arg.Any<FileInfo>(), compiler).Returns(Task.Factory.StartNew(() => new CompileResult { Output = "Saved" }));
            _manager.SetPileAsSource(pile, compiler).Wait();

            var dest = _manager.FindDestinationPile();

            Assert.That(dest.FindFiles("global").Count(), Is.EqualTo(2));
            Assert.That(dest.FindFiles("global").Any(f => f.Name == "exampleCoffee1.js"));
        }
        public void FindDestinationPile_WithRealPileCombined_ReturnsCorrectSetOfFiles()
        {
            var manager = new DefaultSourceManager(true, ".js", "testCompile", _sourceCompiler);
            var pile = GetWorkingPile(true);
            var compiler = new CompilerConfiguration();
            _sourceCompiler.CompileFile(Arg.Any<FileInfo>(), compiler).Returns(Task.Factory.StartNew(() => new CompileResult { Output = "Saved" }));
            manager.SetPileAsSource(pile, compiler).Wait();

            var dest = manager.FindDestinationPile();

            Assert.That(dest.FindFiles("global").Count(), Is.EqualTo(1));
            Assert.That(dest.FindFiles("global").Single().Name, Is.EqualTo("global.js"));
        }
        public void CompileFile_ValidFileWithDoesNotCompile_ReturnsErrorInString()
        {
            var compiler = new DefaultSourceCompiler(false, ".js");

            var file = new FileInfo(TestContext.CurrentContext.TestDirectory + "/../../Data/emptyJS.js");

            var jsCompiler = Substitute.For<ICompiler>();
            jsCompiler.Compile(";", file).Returns<CompileResult>(info => { throw new CompileException("Error"); });

            var config = new CompilerConfiguration().CompilerFor(".js", jsCompiler).CompilerFor(".other", null) as CompilerConfiguration;

            var result = compiler.CompileFile(file, config).Result.Output;

            jsCompiler.Received().Compile(";", file);
            Assert.AreEqual("An error occurred during initial compilation: \r\nError", result);
        }
        public void CompileFile_ValidFileWithDoesNotCompile_MinificationReturnsErrorInString()
        {
            var compiler = new DefaultSourceCompiler(true, ".js");

            var file = new FileInfo(TestContext.CurrentContext.TestDirectory + "/../../Data/emptyJS.js");

            var minCompiler = Substitute.For<ICompiler>();
            minCompiler.Compile(";", null).Returns<CompileResult>(info => { throw new CompileException("Error"); });

            var config = new CompilerConfiguration().CompilerFor(".js", new PassthroughCompiler()).CompilerFor(".js.min", minCompiler) as CompilerConfiguration;

            var result = compiler.CompileFile(file, config).Result.Output;

            minCompiler.Received().Compile(";", null);
            Assert.AreEqual("An error occurred during minification: \r\nError", result);
        }
        public void CompileFile_ValidFile_MinificationPicksCorrectCompiler()
        {
            var compiler = new DefaultSourceCompiler(true, ".js");

            var file = new FileInfo(TestContext.CurrentContext.TestDirectory + "/../../Data/emptyJS.js");

            var minCompiler = Substitute.For<ICompiler>();
            minCompiler.Compile(";", null).Returns(Task.Factory.StartNew(() => new CompileResult { Output = ";" }));

            var config = new CompilerConfiguration().CompilerFor(".js", new PassthroughCompiler()).CompilerFor(".js.min", minCompiler) as CompilerConfiguration;

            var result = compiler.CompileFile(file, config).Result.Output;

            minCompiler.Received().Compile(";", null);
            Assert.AreEqual(";", result);
        }
        public void CompileFile_ValidMinJsFile_IgnoresMinificationStep()
        {
            var compiler = new DefaultSourceCompiler(true, ".js");

            var file = new FileInfo(TestContext.CurrentContext.TestDirectory + "/../../Data/emptyJS.min.js");

            var rightCompiler = Substitute.For<ICompiler>();
            rightCompiler.Compile(";", null).Returns(Task.Factory.StartNew(() => new CompileResult { Output = "Right" }));

            var wrongCompiler = Substitute.For<ICompiler>();
            wrongCompiler.Compile(";", null).Returns(Task.Factory.StartNew(() => new CompileResult { Output = "Wrong" }));

            var config = new CompilerConfiguration()
                .CompilerFor(".js", new PassthroughCompiler())
                .CompilerFor(".min.js.min", rightCompiler)
                .CompilerFor(".js.min", wrongCompiler) as CompilerConfiguration;

            var result = compiler.CompileFile(file, config).Result.Output;

            Assert.AreEqual("Right", result);
        }
        public void CompileFile_ValidFile_PicksCorrectCompiler()
        {
            var compiler = new DefaultSourceCompiler(false, ".js");

            var file = new FileInfo(TestContext.CurrentContext.TestDirectory + "/../../Data/emptyJS.js");

            var jsCompiler = Substitute.For<ICompiler>();
            jsCompiler.Compile(";", file).Returns(Task.Factory.StartNew(() => new CompileResult { Output = ";" }));

            var config = new CompilerConfiguration().CompilerFor(".js", jsCompiler).CompilerFor(".other", null) as CompilerConfiguration;

            var result = compiler.CompileFile(file, config).Result.Output;

            jsCompiler.Received().Compile(";", file);
            Assert.AreEqual(";", result);
        }
 public void Init()
 {
     _config = new CompilerConfiguration();
     _comp1 = new JsMinifyCompiler();
     _comp2 = new PassthroughCompiler();
 }
        public void SetPileAsSource_AddPile_DoesInitialCompile()
        {
            var pile = GetWorkingPile(false);
            var compiler = new CompilerConfiguration();
            _sourceCompiler.CompileFile(Arg.Any<FileInfo>(), compiler).Returns(Task.Factory.StartNew(() => new CompileResult { Output = string.Empty }));

            _manager.SetPileAsSource(pile, compiler).Wait();

            _sourceCompiler.Received(2).CompileFile(Arg.Any<FileInfo>(), compiler);
        }
        public void SetPileSource_AddPile_CominationWorks()
        {
            var manager = new DefaultSourceManager(true, ".js", "testCompile", _sourceCompiler);
            var pile = GetWorkingPile(true);
            var compiler = new CompilerConfiguration();
            _sourceCompiler.CompileFile(Arg.Any<FileInfo>(), compiler).Returns(Task.Factory.StartNew(() => new CompileResult { Output = "Saved" }));

            manager.SetPileAsSource(pile, compiler).Wait();

            Assert.That(File.ReadAllText("testCompile/global.js"), Is.EqualTo("SavedSaved"));
        }
        public void SetPileAsSource_AddPile_SavesResultOfCompile()
        {
            var pile = GetWorkingPile(false);
            var compiler = new CompilerConfiguration();
            _sourceCompiler.CompileFile(Arg.Any<FileInfo>(), compiler).Returns(Task.Factory.StartNew(() => new CompileResult { Output = "Saved" }));

            _manager.SetPileAsSource(pile, compiler).Wait();

            Assert.That(File.ReadAllText("testCompile/global/normalJavascript0.js"), Is.EqualTo("Saved"));
            Assert.That(File.ReadAllText("testCompile/coffee/exampleCoffee0.js"), Is.EqualTo("Saved"));
        }