当前位置: 首页>>代码示例>>C#>>正文


C# MockEngine.AssertLogDoesntContain方法代码示例

本文整理汇总了C#中Microsoft.Build.UnitTests.MockEngine.AssertLogDoesntContain方法的典型用法代码示例。如果您正苦于以下问题:C# MockEngine.AssertLogDoesntContain方法的具体用法?C# MockEngine.AssertLogDoesntContain怎么用?C# MockEngine.AssertLogDoesntContain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Build.UnitTests.MockEngine的用法示例。


在下文中一共展示了MockEngine.AssertLogDoesntContain方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VerifyFindInvalidProjectReferences

        public void VerifyFindInvalidProjectReferences()
        {
            // Create the engine.
            MockEngine engine = new MockEngine();

            FindInvalidProjectReferences t = new FindInvalidProjectReferences();
            t.TargetPlatformVersion = "8.0";
            t.TargetPlatformIdentifier = "Windows";
            Dictionary<string, string> proj1 = new Dictionary<string, string>();
            proj1["TargetPlatformMoniker"] = "Windows, Version=7.0";

            Dictionary<string, string> proj2 = new Dictionary<string, string>();
            proj2["TargetPlatformMoniker"] = "Windows, Version=8.0";

            Dictionary<string, string> proj3 = new Dictionary<string, string>();
            proj3["TargetPlatformMoniker"] = "Windows, Version=8.1";

            Dictionary<string, string> proj4 = new Dictionary<string, string>();
            proj4["TargetPlatformMoniker"] = "Windows, Version=8.2";

            t.ProjectReferences = new TaskItem[] { new TaskItem("proj1.proj", proj1), new TaskItem("proj2.proj", proj2), new TaskItem("proj3.proj", proj3), new TaskItem("proj4.proj", proj4) };
            t.BuildEngine = engine;
            bool succeeded = t.Execute();
            Assert.True(succeeded);

            string warning1 = ResourceUtilities.FormatResourceString("FindInvalidProjectReferences.WarnWhenVersionIsIncompatible", "Windows", "8.0", "proj1.proj", "Windows, Version=7.0");
            engine.AssertLogDoesntContain(warning1);

            string warning2 = ResourceUtilities.FormatResourceString("FindInvalidProjectReferences.WarnWhenVersionIsIncompatible", "Windows", "8.0", "proj2.proj", "Windows, Version=8.0");
            engine.AssertLogDoesntContain(warning2);

            string warning3 = ResourceUtilities.FormatResourceString("FindInvalidProjectReferences.WarnWhenVersionIsIncompatible", "Windows", "8.0", "proj3.proj", "Windows, Version=8.1");
            engine.AssertLogContains(warning3);

            string warning4 = ResourceUtilities.FormatResourceString("FindInvalidProjectReferences.WarnWhenVersionIsIncompatible", "Windows", "8.0", "proj4.proj", "Windows, Version=8.2");
            engine.AssertLogContains(warning4);

            Assert.Equal(t.InvalidReferences.Length, 2);
            Assert.Equal(t.InvalidReferences[0].ItemSpec, "proj3.proj");
            Assert.Equal(t.InvalidReferences[1].ItemSpec, "proj4.proj");
        }
开发者ID:cameron314,项目名称:msbuild,代码行数:41,代码来源:FindInvalidProjectReferences_Tests.cs

示例2: TargetStopOnFirstFailureBuildInParallel

        public void TargetStopOnFirstFailureBuildInParallel()
        {
            string project1 = ObjectModelHelpers.CreateTempFileOnDisk(@"
                   <Project xmlns='msbuildnamespace' ToolsVersion='msbuilddefaulttoolsversion'>
                   <Target Name='T1'>
                          <Message Text='Proj2 T1 message'/>
                      </Target>
                    <Target Name='T2'>
                          <Message Text='Proj2 T2 message'/>
                      </Target>
                    <Target Name='T3'>
                           <Error Text='Error'/>
                      </Target>
                    </Project>
                  ");

            try
            {
                ITaskItem[] projects = new ITaskItem[]
                {
                    new TaskItem(project1)
                };
                for (int i = 0; i < 6; i++)
                {
                    // Test the case where the error is in the last target
                    MSBuild msbuildTask = new MSBuild();
                    MockEngine mockEngine = new MockEngine();
                    msbuildTask.BuildEngine = mockEngine;
                    msbuildTask.Projects = projects;
                    // Set to true as the expected result is false
                    bool success = true;
                    switch (i)
                    {
                        case 0:
                            // Test the case where the error is in the last project and RunEachTargetSeparately = true
                            msbuildTask.StopOnFirstFailure = true;
                            msbuildTask.RunEachTargetSeparately = true;
                            msbuildTask.Targets = new string[] { "T1", "T2", "T3" };
                            success = msbuildTask.Execute();
                            mockEngine.AssertLogContains("Proj2 T1 message");
                            mockEngine.AssertLogContains("Proj2 T2 message");
                            break;
                        case 1:
                            // Test the case where the error is in the second target out of 3.
                            msbuildTask.StopOnFirstFailure = true;
                            msbuildTask.RunEachTargetSeparately = true;
                            msbuildTask.Targets = new string[] { "T1", "T3", "T2" };
                            success = msbuildTask.Execute();
                            mockEngine.AssertLogContains("Proj2 T1 message");
                            mockEngine.AssertLogDoesntContain("Proj2 T2 message");
                            // The build should fail as the first project has an error
                            break;
                        case 2:
                            // Test case where error is in second last target but stopOnFirstFailure is false
                            msbuildTask.RunEachTargetSeparately = true;
                            msbuildTask.StopOnFirstFailure = false;
                            msbuildTask.Targets = new string[] { "T1", "T3", "T2" };
                            success = msbuildTask.Execute();
                            mockEngine.AssertLogContains("Proj2 T1 message");
                            mockEngine.AssertLogContains("Proj2 T2 message");
                            break;
                        // Test the cases where RunEachTargetSeparately is false. In these cases all of the targets should be submitted at once
                        case 3:
                            // Test the case where the error is in the last project and RunEachTargetSeparately = true
                            msbuildTask.StopOnFirstFailure = true;
                            msbuildTask.Targets = new string[] { "T1", "T2", "T3" };
                            success = msbuildTask.Execute();
                            mockEngine.AssertLogContains("Proj2 T1 message");
                            mockEngine.AssertLogContains("Proj2 T2 message");
                            // The build should fail as the first project has an error
                            break;
                        case 4:
                            // Test the case where the error is in the second target out of 3.
                            msbuildTask.StopOnFirstFailure = true;
                            msbuildTask.Targets = new string[] { "T1", "T3", "T2" };
                            success = msbuildTask.Execute();
                            mockEngine.AssertLogContains("Proj2 T1 message");
                            mockEngine.AssertLogDoesntContain("Proj2 T2 message");
                            // The build should fail as the first project has an error
                            break;
                        case 5:
                            // Test case where error is in second last target but stopOnFirstFailure is false
                            msbuildTask.StopOnFirstFailure = false;
                            msbuildTask.Targets = new string[] { "T1", "T3", "T2" };
                            success = msbuildTask.Execute();
                            mockEngine.AssertLogContains("Proj2 T1 message");
                            mockEngine.AssertLogDoesntContain("Proj2 T2 message");
                            break;
                    }

                    // The build should fail as the first project has an error
                    Assert.IsFalse(success, "Iteration of i:" + i + "Build Succeeded.  See 'Standard Out' tab for details.");
                }
            }
            finally
            {
                File.Delete(project1);
            }
        }
开发者ID:ChronosWS,项目名称:msbuild,代码行数:99,代码来源:MSBuild_Tests.cs

示例3: TestLogFromException

        public void TestLogFromException()
        {
            string message = "exception message";
            string stackTrace = "TaskLoggingHelperTests.TestLogFromException";

            MockEngine engine = new MockEngine();
            MockTask task = new MockTask();
            task.BuildEngine = engine;

            // need to throw and catch an exception so that its stack trace is initialized to something
            try
            {
                Exception inner = new InvalidOperationException();
                throw new Exception(message, inner);
            }
            catch (Exception e)
            {
                // log error without stack trace
                task.Log.LogErrorFromException(e);
                engine.AssertLogContains(message);
                engine.AssertLogDoesntContain(stackTrace);
                engine.AssertLogDoesntContain("InvalidOperationException");

                engine.Log = string.Empty;

                // log warning with stack trace
                task.Log.LogWarningFromException(e);
                engine.AssertLogContains(message);
                engine.AssertLogDoesntContain(stackTrace);

                engine.Log = string.Empty;

                // log error with stack trace
                task.Log.LogErrorFromException(e, true);
                engine.AssertLogContains(message);
                engine.AssertLogContains(stackTrace);
                engine.AssertLogDoesntContain("InvalidOperationException");

                engine.Log = string.Empty;

                // log warning with stack trace
                task.Log.LogWarningFromException(e, true);
                engine.AssertLogContains(message);
                engine.AssertLogContains(stackTrace);
                engine.Log = string.Empty;

                // log error with stack trace and inner exceptions
                task.Log.LogErrorFromException(e, true, true, "foo.cs");
                engine.AssertLogContains(message);
                engine.AssertLogContains(stackTrace);
                engine.AssertLogContains("InvalidOperationException");
            }
        }
开发者ID:cameron314,项目名称:msbuild,代码行数:53,代码来源:TaskLoggingHelper_Tests.cs

示例4: VerifyLogDoesNotContainResource

 /// <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);
 }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:13,代码来源:ResGen_Tests.cs

示例5: ToolPath

        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);
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:32,代码来源:ResGen_Tests.cs

示例6: GetResolvedRuleSetPath_SimpleNameAndDirectories_Existent

        public void GetResolvedRuleSetPath_SimpleNameAndDirectories_Existent()
        {
            MockEngine mockEngine = new MockEngine();
            ResolveCodeAnalysisRuleSet task = new ResolveCodeAnalysisRuleSet();
            task.BuildEngine = mockEngine;

            string codeAnalysisRuleSet = @"CodeAnalysis.ruleset";
            var directory = Path.GetTempPath();

            task.CodeAnalysisRuleSet = codeAnalysisRuleSet;
            task.MSBuildProjectDirectory = null;
            task.CodeAnalysisRuleSetDirectories = new[] { directory };

            string ruleSetFullPath = Path.Combine(directory, codeAnalysisRuleSet);

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

                Assert.Equal(expected: true, actual: result);
                Assert.Equal(expected: ruleSetFullPath, actual: resolvedRuleSet);
                mockEngine.AssertLogDoesntContain("MSB3884");
            }
        }
开发者ID:cameron314,项目名称:msbuild,代码行数:25,代码来源:ResolveCodeAnalysisRuleSet_Tests.cs

示例7: DoNotRetryWhenDestinationLockedDueToAcl

        public void DoNotRetryWhenDestinationLockedDueToAcl()
        {
            string tempDirectory = Path.Combine(Path.GetTempPath(), "DoNotRetryWhenDestinationLockedDueToAcl");
            string destinationFile = Path.Combine(tempDirectory, "DestinationFile.txt");
            string sourceFile = Path.Combine(tempDirectory, "SourceFile.txt");

            if (Directory.Exists(tempDirectory))
            {
                FileUtilities.DeleteDirectoryNoThrow(tempDirectory, true);
            }

            Directory.CreateDirectory(tempDirectory);

            File.WriteAllText(destinationFile, "Destination");
            File.WriteAllText(sourceFile, "SourceFile");

            string userAccount = string.Format(@"{0}\{1}", System.Environment.UserDomainName, System.Environment.UserName);

            FileSystemAccessRule denyFile = new FileSystemAccessRule(userAccount, FileSystemRights.Write | FileSystemRights.Delete | FileSystemRights.DeleteSubdirectoriesAndFiles | FileSystemRights.WriteData, AccessControlType.Deny);
            FileSystemAccessRule denyDirectory = new FileSystemAccessRule(userAccount, FileSystemRights.DeleteSubdirectoriesAndFiles, AccessControlType.Deny);

            FileSecurity fSecurity = File.GetAccessControl(destinationFile);
            DirectorySecurity dSecurity = Directory.GetAccessControl(tempDirectory);

            try
            {
                fSecurity.AddAccessRule(denyFile);
                File.SetAccessControl(destinationFile, fSecurity);

                dSecurity.AddAccessRule(denyDirectory);
                Directory.SetAccessControl(tempDirectory, dSecurity);

                Copy t = new Copy();
                t.RetryDelayMilliseconds = 1; // speed up tests!
                // Allow the task's default (false) to have a chance
                if (useHardLinks)
                {
                    t.UseHardlinksIfPossible = useHardLinks;
                }
                MockEngine engine = new MockEngine();
                t.BuildEngine = engine;
                t.SourceFiles = new TaskItem[] { new TaskItem(sourceFile) };
                t.DestinationFiles = new TaskItem[] { new TaskItem(destinationFile) };

                bool result = t.Execute();
                Assert.IsFalse(result);

                engine.AssertLogContains("MSB3021"); // copy failed
                engine.AssertLogDoesntContain("MSB3026"); // Didn't retry

                Assert.IsTrue(engine.Errors == 1);
                Assert.IsTrue(engine.Warnings == 0);
            }
            finally
            {
                fSecurity.RemoveAccessRule(denyFile);
                File.SetAccessControl(destinationFile, fSecurity);

                dSecurity.RemoveAccessRule(denyDirectory);
                Directory.SetAccessControl(tempDirectory, dSecurity);

                if (Directory.Exists(tempDirectory))
                {
                    FileUtilities.DeleteDirectoryNoThrow(tempDirectory, true);
                }
            }
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:67,代码来源:Copy_Tests.cs

示例8: FailureWithNoRetries

        public void FailureWithNoRetries()
        {
            Copy t = new Copy();
            t.RetryDelayMilliseconds = 1; // speed up tests!
            // Allow the task's default (false) to have a chance
            if (useHardLinks)
            {
                t.UseHardlinksIfPossible = useHardLinks;
            }
            MockEngine engine = new MockEngine(true /* log to console */);
            t.BuildEngine = engine;
            t.SourceFiles = new ITaskItem[] { new TaskItem("c:\\source") };
            t.DestinationFiles = new ITaskItem[] { new TaskItem("c:\\destination") };
            t.Retries = 0;

            CopyFunctor copyFunctor = new CopyFunctor(2, false /* do not throw on failure */);
            bool result = t.Execute(copyFunctor.Copy);

            Assert.AreEqual(false, result);
            engine.AssertLogDoesntContain("MSB3026");
            engine.AssertLogDoesntContain("MSB3027");
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:22,代码来源:Copy_Tests.cs

示例9: HandleExecutionErrorsWhenToolLogsError

        public void HandleExecutionErrorsWhenToolLogsError()
        {
            using (MyTool t = new MyTool())
            {
                MockEngine engine = new MockEngine();
                t.BuildEngine = engine;
                t.MockCommandLineCommands = "/C echo Main.cs(17,20): error CS0168: The variable 'foo' is declared but never used";

                Assert.IsFalse(t.Execute());

                // The above command logged a canonical error message.  Therefore ToolTask should
                // not log its own error beyond that.
                engine.AssertLogDoesntContain("MSB6006");
                engine.AssertLogContains("CS0168");
                engine.AssertLogContains("The variable 'foo' is declared but never used");
                Assert.AreEqual(-1, t.ExitCode);
                Assert.AreEqual(1, engine.Errors);
            }
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:19,代码来源:ToolTask_Tests.cs

示例10: ErrorFromResourcesWithInvalidArguments

        public void ErrorFromResourcesWithInvalidArguments()
        {
            MockEngine e = new MockEngine(true);
            ErrorFromResources err = new ErrorFromResources();
            err.BuildEngine = e;

            err.Resource = "Copy.Error";
            err.Arguments = new string[] { "a.txt", "b.txt" };

            bool retval = err.Execute();

            Console.WriteLine("===");
            Console.WriteLine(e.Log);
            Console.WriteLine("===");

            Assert.IsFalse(retval);

            e.AssertLogDoesntContain("a.txt");
            e.AssertLogContains("MSB3861");
            Assert.IsTrue(e.Errors == 1);
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:21,代码来源:ErrorWarningMessage_Tests.cs

示例11: DoNotRetryCopyWhenDestinationFolderIsFile

        public void DoNotRetryCopyWhenDestinationFolderIsFile()
        {
            string destinationFile = FileUtilities.GetTemporaryFile();
            string sourceFile = FileUtilities.GetTemporaryFile();

            try
            {
                using (StreamWriter sw = new StreamWriter(sourceFile, true))
                    sw.Write("This is a destination temp file.");

                ITaskItem[] sourceFiles = new ITaskItem[] { new TaskItem(sourceFile) };

                Copy t = new Copy();
                t.RetryDelayMilliseconds = 1; // speed up tests!
                // Allow the task's default (false) to have a chance
                if (useHardLinks)
                {
                    t.UseHardlinksIfPossible = useHardLinks;
                }
                MockEngine engine = new MockEngine();
                t.BuildEngine = engine;
                t.SourceFiles = sourceFiles;
                t.DestinationFolder = new TaskItem(destinationFile);
                t.SkipUnchangedFiles = true;

                bool result = t.Execute();
                Assert.False(result);

                engine.AssertLogContains("MSB3021"); // copy failed
                engine.AssertLogDoesntContain("MSB3026"); // Didn't retry

                Assert.Equal(1, engine.Errors);
                Assert.Equal(0, engine.Warnings);
            }
            finally
            {
                File.Delete(sourceFile);
            }
        }
开发者ID:cameron314,项目名称:msbuild,代码行数:39,代码来源:Copy_Tests.cs

示例12: GetResolvedRuleSetPath_FullPath_Existent

        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.AreEqual(expected: true, actual: result);
                Assert.AreEqual(expected: codeAnalysisRuleSet, actual: resolvedRuleSet);
                mockEngine.AssertLogDoesntContain("MSB3884");
            }
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:22,代码来源:ResolveCodeAnalysisRuleSet_Tests.cs

示例13: GetResolvedRuleSetPath_Null

        public void GetResolvedRuleSetPath_Null()
        {
            MockEngine mockEngine = new MockEngine();
            ResolveCodeAnalysisRuleSet task = new ResolveCodeAnalysisRuleSet();
            task.BuildEngine = mockEngine;

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

            bool result = task.Execute();
            string resolvedRuleSet = task.ResolvedCodeAnalysisRuleSet;

            Assert.AreEqual(expected: true, actual: result);
            Assert.AreEqual(expected: null, actual: resolvedRuleSet);
            mockEngine.AssertLogDoesntContain("MSB3884");
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:17,代码来源:ResolveCodeAnalysisRuleSet_Tests.cs

示例14: GetResolvedRuleSetPath_RelativePath_WithProject_Existent

        public void GetResolvedRuleSetPath_RelativePath_WithProject_Existent()
        {
            MockEngine mockEngine = new MockEngine();
            ResolveCodeAnalysisRuleSet task = new ResolveCodeAnalysisRuleSet();
            task.BuildEngine = mockEngine;

            string subdirectoryName = Path.GetRandomFileName();
            string codeAnalysisRuleSet = Path.Combine(subdirectoryName, "CodeAnalysis.ruleset");
            string projectDirectory = Path.GetTempPath();

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

            string ruleSetFullPath = Path.Combine(projectDirectory, codeAnalysisRuleSet);

            using (new TemporaryDirectory(Path.GetDirectoryName(ruleSetFullPath)))
            using (new TemporaryFile(ruleSetFullPath, "foo"))
            {
                bool result = task.Execute();
                string resolvedRuleSet = task.ResolvedCodeAnalysisRuleSet;

                Assert.AreEqual(expected: true, actual: result);
                Assert.AreEqual(expected: codeAnalysisRuleSet, actual: resolvedRuleSet);
                mockEngine.AssertLogDoesntContain("MSB3884");
            }
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:27,代码来源:ResolveCodeAnalysisRuleSet_Tests.cs

示例15: StopOnFirstFailureandBuildInParallelMultipleNode

        public void StopOnFirstFailureandBuildInParallelMultipleNode()
        {
            string project1 = ObjectModelHelpers.CreateTempFileOnDisk(@"
                  <Project xmlns='msbuildnamespace' ToolsVersion='msbuilddefaulttoolsversion'>
                      <Target Name='msbuild'>
                          <Error Text='Error'/>
                      </Target>
                  </Project>
                  ");

            string project2 = ObjectModelHelpers.CreateTempFileOnDisk(@"
                   <Project xmlns='msbuildnamespace' ToolsVersion='msbuilddefaulttoolsversion'>
                       <Target Name='msbuild'>
                           <Message Text='SecondProject'/>
                       </Target>
                    </Project>
                  ");

            try
            {
                ITaskItem[] projects = new ITaskItem[]
                {
                    new TaskItem(project1), new TaskItem(project2)
                };

                // Test the various combinations of BuildInParallel and StopOnFirstFailure when the msbuild task is told there are multiple nodes 
                // running in the system
                for (int i = 0; i < 4; i++)
                {
                    MSBuild msbuildTask = new MSBuild();
                    MockEngine mockEngine = new MockEngine();
                    mockEngine.IsRunningMultipleNodes = true;
                    msbuildTask.BuildEngine = mockEngine;
                    msbuildTask.Projects = projects;
                    msbuildTask.Targets = new string[] { "msbuild" };
                    // Make success true as the expected resultis false
                    bool success = true;
                    switch (i)
                    {
                        case 0:
                            // Verify setting BuildInParallel and StopOnFirstFailure to 
                            // true will not cause the msbuild task to set BuildInParallel to false during the execute
                            msbuildTask.BuildInParallel = true;
                            msbuildTask.StopOnFirstFailure = true;
                            success = msbuildTask.Execute();
                            // Verify build did build second project which has the message SecondProject
                            mockEngine.AssertLogContains("SecondProject");
                            // Verify the correct msbuild task messages are in the log
                            Assert.IsTrue(msbuildTask.BuildInParallel, "Iteration of 0 Expected BuildInParallel to be true");
                            break;
                        case 1:
                            // Verify setting BuildInParallel to true and StopOnFirstFailure to 
                            // false will cause no change in BuildInParallel
                            msbuildTask.BuildInParallel = true;
                            msbuildTask.StopOnFirstFailure = false;
                            success = msbuildTask.Execute();
                            // Verify build did build second project which has the message SecondProject
                            mockEngine.AssertLogContains("SecondProject");
                            // Verify the correct msbuild task messages are in the log
                            Assert.IsTrue(msbuildTask.BuildInParallel, "Iteration of 1 Expected BuildInParallel to be true");
                            break;
                        case 2:
                            // Verify setting BuildInParallel to false and StopOnFirstFailure to 
                            // true will cause no change in BuildInParallel
                            msbuildTask.BuildInParallel = false;
                            msbuildTask.StopOnFirstFailure = true;
                            success = msbuildTask.Execute();
                            // Verify build did not build second project which has the message SecondProject
                            mockEngine.AssertLogDoesntContain("SecondProject");
                            // Verify the correct msbuild task messages are in the log
                            Assert.IsFalse(msbuildTask.BuildInParallel, "Iteration of 2 Expected BuildInParallel to be false");
                            break;

                        case 3:
                            // Verify setting BuildInParallel to false and StopOnFirstFailure to 
                            // false will cause no change in BuildInParallel
                            msbuildTask.BuildInParallel = false;
                            msbuildTask.StopOnFirstFailure = false;
                            success = msbuildTask.Execute();
                            // Verify build did build second project which has the message SecondProject
                            mockEngine.AssertLogContains("SecondProject");
                            // Verify the correct msbuild task messages are in the log
                            Assert.IsFalse(msbuildTask.BuildInParallel, "Iteration of 3 Expected BuildInParallel to be false");
                            break;
                    }
                    // The build should fail as the first project has an error
                    Assert.IsFalse(success, "Iteration of i " + i + " Build Succeeded.  See 'Standard Out' tab for details.");
                }
            }
            finally
            {
                File.Delete(project1);
                File.Delete(project2);
            }
        }
开发者ID:ChronosWS,项目名称:msbuild,代码行数:95,代码来源:MSBuild_Tests.cs


注:本文中的Microsoft.Build.UnitTests.MockEngine.AssertLogDoesntContain方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。