Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        /// <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 checks
        /// the log for 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 ExecuteTaskAndVerifyLogContainsResource(ResGen t, bool expectedResult, string resourceString, params object[] args)
        {
            MockEngine e = new MockEngine();

            t.BuildEngine = e;

            bool taskPassed = t.Execute();

            Assert.IsTrue(taskPassed == expectedResult, "Unexpected task result");

            VerifyLogContainsResource(e, t.Log, resourceString, args);
        }
Esempio n. 3
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. 4
0
        /// <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.IsTrue(taskPassed == expectedResult, "Unexpected task result");

            VerifyLogDoesNotContainResource(e, t.Log, resourceString, args);
        }
Esempio n. 5
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.IsNull(t.ToolPath, "ToolPath should be null by default");
            ExecuteTaskAndVerifyLogContainsErrorFromResource(t, "ResGen.SdkOrToolPathNotSpecifiedOrInvalid", t.SdkToolsPath, t.ToolPath);

            t.ToolPath = badParameterValue;
            Assert.AreEqual(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.AreEqual(goodParameterValue, t.ToolPath, "New ToolPath value should be set");

            bool taskPassed = t.Execute();
            Assert.IsFalse(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. 6
0
        /// <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 checks 
        /// the log for 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 ExecuteTaskAndVerifyLogContainsResource(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"

            VerifyLogContainsResource(e, t.Log, resourceString, args);
        }