示例#1
0
文件: ResGen_Tests.cs 项目: 3F/IeXod
        /// <summary>
        /// Given an instance of a ResGen task, executes that task (assuming all necessary parameters
        /// have been set ahead of time), verifies that the task had the expected result, and ensures
        /// the log does not contain the string corresponding to the resource name passed in
        /// </summary>
        /// <param name="t">The task to execute and check</param>
        /// <param name="expectedResult">true if the task is expected to pass, false otherwise</param>
        /// <param name="resourceString">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 ExecuteTaskAndVerifyLogDoesNotContainResource(ResGen t, bool expectedResult, string resourceString, params object[] args)
        {
            MockEngine e = new MockEngine();

            t.BuildEngine = e;

            bool taskPassed = t.Execute();

            Assert.Equal(taskPassed, expectedResult); // "Unexpected task result"

            VerifyLogDoesNotContainResource(e, t.Log, resourceString, args);
        }
示例#2
0
文件: ResGen_Tests.cs 项目: 3F/IeXod
        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);
        }