/// <summary> /// Test LogProjectStarted /// </summary> private void LogProjectStartedTestHelper(string projectFile, string targetNames) { string message = string.Empty; if (!String.IsNullOrEmpty(targetNames)) { message = ResourceUtilities.FormatResourceString("ProjectStartedPrefixForTopLevelProjectWithTargetNames", Path.GetFileName(projectFile), targetNames); } else { message = ResourceUtilities.FormatResourceString("ProjectStartedPrefixForTopLevelProjectWithDefaultTargets", Path.GetFileName(projectFile)); } MockHost componentHost = new MockHost(); ProcessBuildEventHelper service = (ProcessBuildEventHelper)ProcessBuildEventHelper.CreateLoggingService(LoggerMode.Synchronous, 1, componentHost); ConfigCache cache = (ConfigCache)componentHost.GetComponent(BuildComponentType.ConfigCache); BuildRequestData data = new BuildRequestData("file", new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase), "toolsVersion", new string[0], null); BuildRequestConfiguration config = new BuildRequestConfiguration(2, data, "4.0"); cache.AddConfiguration(config); BuildEventContext context = service.LogProjectStarted(s_buildEventContext, 1, 2, s_buildEventContext, projectFile, targetNames, null, null); BuildEventContext parentBuildEventContext = s_buildEventContext; VerifyProjectStartedEventArgs(service, context.ProjectContextId, message, projectFile, targetNames, parentBuildEventContext, context); service.ResetProcessedBuildEvent(); }
/// <summary> /// Test ProjectFinishedEvent /// </summary> /// <param name="projectFile">Project File to Test</param> /// <param name="success">Success value to test</param> private void TestProjectFinishedEvent(string projectFile, bool success) { string message = ResourceUtilities.FormatResourceString((success ? "ProjectFinishedSuccess" : "ProjectFinishedFailure"), Path.GetFileName(projectFile)); MockHost componentHost = new MockHost(); ProcessBuildEventHelper service = (ProcessBuildEventHelper)ProcessBuildEventHelper.CreateLoggingService(LoggerMode.Synchronous, 1, componentHost); try { service.LogProjectFinished(s_buildEventContext, projectFile, success); } catch (InternalErrorException ex) { Assert.IsTrue(ex.Message.Contains("ContextID " + s_buildEventContext.ProjectContextId)); } finally { service.ResetProcessedBuildEvent(); } ConfigCache cache = (ConfigCache)componentHost.GetComponent(BuildComponentType.ConfigCache); BuildRequestData data = new BuildRequestData("file", new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase), "toolsVersion", new string[0], null); BuildRequestConfiguration config = new BuildRequestConfiguration(2, data, "4.0"); cache.AddConfiguration(config); // Now do it the right way -- with a matching ProjectStarted. BuildEventContext projectContext = service.LogProjectStarted ( new BuildEventContext(1, BuildEventContext.InvalidTargetId, BuildEventContext.InvalidProjectContextId, BuildEventContext.InvalidTaskId), 1, 2, s_buildEventContext, projectFile, null, null, null ); service.LogProjectFinished(projectContext, projectFile, success); VerifyProjectFinishedEvent(service, projectContext, message, projectFile, success); service.ResetProcessedBuildEvent(); }