예제 #1
0
        public void TestAjaxMinCombinedFail()
        {
            // create the task
            var task = new AjaxMin();

            // common settings
            task.JsKnownGlobalNames = "jQuery,$";
            task.JsEvalTreatment    = "MakeImmediateSafe";
            task.Switches           = "-rename:none -reorder:N";

            // set up the JS files
            task.JsSourceFiles = new[] {
                new TaskItem()
                {
                    ItemSpec = @"Dll\Input\AjaxMinTask\file1.js"
                },
                new TaskItem()
                {
                    ItemSpec = @"Dll\Input\AjaxMinTask\fail.js"
                },
            };

            // set up the CSS files
            task.CssSourceFiles = new[] {
                new TaskItem()
                {
                    ItemSpec = @"Dll\Input\AjaxMinTask\test1.css"
                },
                new TaskItem()
                {
                    ItemSpec = @"Dll\Input\AjaxMinTask\fail.css"
                },
            };

            // our mockup build engine
            task.BuildEngine = new TestBuildEngine()
            {
                MockProjectPath = Path.Combine(testContextInstance.DeploymentDirectory, "mock.csproj")
            };

            // set up the combined file outputs
            task.JsCombinedFileName  = @"Dll\Output\AjaxMinTask\CombinedFail.min.js";
            task.CssCombinedFileName = @"Dll\Output\AjaxMinTask\CombinedFail.min.css";

            var success = ExecuteAndReport(task);

            // check overall success
            Assert.IsFalse(success, "expected the task to fail");

            // make sure all the files we expect were created
            Assert.IsFalse(File.Exists(Path.Combine(s_outputFolder, "CombinedFail.min.js")), "CombinedFail.min.js should not exist");
            Assert.IsFalse(File.Exists(Path.Combine(s_outputFolder, "CombinedFail.min.css")), "CombinedFail.min.css should not exist");
        }
예제 #2
0
        private bool ExecuteAndReport(AjaxMin task)
        {
            var success = task.Execute();

            Trace.Write("TASK RESULT: ");
            Trace.WriteLine(success);

            Trace.WriteLine(string.Empty);
            Trace.WriteLine("BUILD MESSAGES:");
            foreach (var logMessage in ((TestBuildEngine)task.BuildEngine).LogMessages)
            {
                Trace.WriteLine(logMessage);
            }

            return(success);
        }
예제 #3
0
        private AjaxMin CreateTaskWithInputs()
        {
            // create the task, set it up, and execute it
            var task = new AjaxMin();

            // common settings
            task.JsKnownGlobalNames = "jQuery,$";
            task.JsEvalTreatment    = "MakeImmediateSafe";
            task.Switches           = "-rename:none -reorder:N";

            // set up the JS files
            task.JsSourceFiles = new[] {
                new TaskItem()
                {
                    ItemSpec = @"Dll\Input\AjaxMinTask\file1.js"
                },
                new TaskItem()
                {
                    ItemSpec = @"Dll\Input\AjaxMinTask\file2.js"
                },
            };

            // set up the CSS files
            task.CssSourceFiles = new[] {
                new TaskItem()
                {
                    ItemSpec = @"Dll\Input\AjaxMinTask\test1.css"
                },
                new TaskItem()
                {
                    ItemSpec = @"Dll\Input\AjaxMinTask\test2.css"
                },
            };

            // our mockup build engine
            task.BuildEngine = new TestBuildEngine()
            {
                MockProjectPath = Path.Combine(testContextInstance.DeploymentDirectory, "mock.csproj")
            };

            return(task);
        }
예제 #4
0
        protected override void MinifyCss(string cssFile, string outputMinifiedCssFile)
        {
            var ajaxMinTask = new AjaxMin();

            ajaxMinTask.TreatWarningsAsErrors = true;
            ajaxMinTask.BuildEngine           = this.Task.BuildEngine;
            ajaxMinTask.CssSourceFiles        = new ITaskItem[] { new TaskItem(cssFile) };
            ajaxMinTask.CssCombinedFileName   = outputMinifiedCssFile;
            if (ajaxMinTask.Execute())
            {
                // IF success
                // THEN do nothing
            }
            else
            {
                // ELSE failure
                // THEN raise an error

                throw new ApplicationException(string.Format("An error occurred trying to minify css file. Css File: {0}", cssFile));
            }
        }
예제 #5
0
        protected override void MinifyJavaScript(string javaScriptFile, string outputMinifiedJavaScriptFile)
        {
            var ajaxMinTask = new AjaxMin();
            ajaxMinTask.TreatWarningsAsErrors = true;
            ajaxMinTask.BuildEngine = this.Task.BuildEngine;
            ajaxMinTask.JsSourceFiles = new ITaskItem[] { new TaskItem(javaScriptFile) };
            ajaxMinTask.JsCombinedFileName = outputMinifiedJavaScriptFile;
            if (ajaxMinTask.Execute())
            {
                // IF success
                // THEN do nothing
            }
            else
            {
                // ELSE failure
                // THEN raise an error

                throw new ApplicationException(string.Format("An error occurred trying to minify JavaScript file. JavaScript File: {0}", javaScriptFile, outputMinifiedJavaScriptFile));
            }
        }