Esempio n. 1
0
        public void GetResolvedRuleSetPath_FullPath_Existent()
        {
            MockEngine mockEngine           = new MockEngine();
            ResolveCodeAnalysisRuleSet task = new ResolveCodeAnalysisRuleSet();

            task.BuildEngine = mockEngine;

            string codeAnalysisRuleSet = Path.Combine(Path.GetTempPath(), @"CodeAnalysis.ruleset");

            task.CodeAnalysisRuleSet            = codeAnalysisRuleSet;
            task.MSBuildProjectDirectory        = null;
            task.CodeAnalysisRuleSetDirectories = null;

            using (new TemporaryFile(codeAnalysisRuleSet, "foo"))
            {
                bool   result          = task.Execute();
                string resolvedRuleSet = task.ResolvedCodeAnalysisRuleSet;

                Assert.True(result);
                Assert.Equal(expected: codeAnalysisRuleSet, actual: resolvedRuleSet);
                mockEngine.AssertLogDoesntContain("MSB3884");
            }
        }
Esempio n. 2
0
        public void ToolPath()
        {
            ResGen t = new ResGen();
            string badParameterValue  = @"C:\Program Files\Microsoft Visual Studio 10.0\My Fake SDK Path";
            string goodParameterValue = Path.GetTempPath();

            ITaskItem[] throwawayInput = { new TaskItem("hello.resx") };

            // Without any inputs, the task just passes
            t.InputFiles = throwawayInput;

            Assert.Null(t.ToolPath); // "ToolPath should be null by default"
            ExecuteTaskAndVerifyLogContainsErrorFromResource(t, "ResGen.SdkOrToolPathNotSpecifiedOrInvalid", t.SdkToolsPath, t.ToolPath);

            t.ToolPath = badParameterValue;
            Assert.Equal(badParameterValue, t.ToolPath); // "New ToolPath value should be set"
            ExecuteTaskAndVerifyLogContainsErrorFromResource(t, "ResGen.SdkOrToolPathNotSpecifiedOrInvalid", t.SdkToolsPath, t.ToolPath);

            MockEngine e = new MockEngine();

            t.BuildEngine = e;
            t.ToolPath    = goodParameterValue;

            Assert.Equal(goodParameterValue, t.ToolPath); // "New ToolPath value should be set"

            bool taskPassed = t.Execute();

            Assert.False(taskPassed); // "Task should still fail -- there are other things wrong with it."

            // but that particular error shouldn't be there anymore.
            string toolPathMessage = t.Log.FormatResourceString("ResGen.SdkOrToolPathNotSpecifiedOrInvalid", t.SdkToolsPath, t.ToolPath);
            string messageWithNoCode;
            string toolPathCode = t.Log.ExtractMessageCode(toolPathMessage, out messageWithNoCode);

            e.AssertLogDoesntContain(toolPathCode);
        }
Esempio n. 3
0
        /// <summary>
        /// Given a log and a resource string, acquires the text of that resource string and
        /// compares it to the log.  Assert fails if the log contain the desired string.
        /// </summary>
        /// <param name="e">The MockEngine that contains the log we're checking</param>
        /// <param name="log">The TaskLoggingHelper that we use to load the string resource</param>
        /// <param name="errorResource">The name of the resource string to check the log for</param>
        /// <param name="args">Arguments needed to format the resource string properly</param>
        private void VerifyLogDoesNotContainResource(MockEngine e, TaskLoggingHelper log, string messageResource, params object[] args)
        {
            string message = log.FormatResourceString(messageResource, args);

            e.AssertLogDoesntContain(message);
        }