public void SetUp() { LoggingServiceFactory loggingFactory = new LoggingServiceFactory(LoggerMode.Synchronous, 1); _loggingService = loggingFactory.CreateInstance(BuildComponentType.LoggingService) as LoggingService; _customLogger = new MyCustomLogger(); _mockHost = new MockHost(); _mockHost.LoggingService = _loggingService; _loggingService.RegisterLogger(_customLogger); _elementLocation = ElementLocation.Create("MockFile", 5, 5); BuildRequest buildRequest = new BuildRequest(1 /* submissionId */, 1, 1, new List<string>(), null, BuildEventContext.Invalid, null); BuildRequestConfiguration configuration = new BuildRequestConfiguration(1, new BuildRequestData("Nothing", new Dictionary<string, string>(), "4.0", new string[0], null), "2.0"); configuration.Project = new ProjectInstance(ProjectRootElement.Create()); BuildRequestEntry entry = new BuildRequestEntry(buildRequest, configuration); BuildResult buildResult = new BuildResult(buildRequest, false); buildResult.AddResultsForTarget("Build", new TargetResult(new TaskItem[] { new TaskItem("IamSuper", configuration.ProjectFullPath) }, TestUtilities.GetSkippedResult())); _mockRequestCallback = new MockIRequestBuilderCallback(new BuildResult[] { buildResult }); entry.Builder = (IRequestBuilder)_mockRequestCallback; _taskHost = new TaskHost(_mockHost, entry, _elementLocation, null /*Dont care about the callback either unless doing a build*/); _taskHost.LoggingContext = new TaskLoggingContext(_loggingService, BuildEventContext.Invalid); }
public void TestLogErrorEvent() { MyCustomLogger myLogger = new MyCustomLogger(); engine.RegisterLogger(myLogger); engineProxy.UpdateContinueOnError(false); // Log the custom event args. (Pretend that the task actually did this.) engineProxy.LogErrorEvent(new BuildErrorEventArgs("SubCategory", "code", null, 0, 1, 2, 3, "message", "Help", "Sender")); engine.LoggingServices.ProcessPostedLoggingEvents(); // Make sure our custom logger received the actual custom event and not some fake. Assertion.Assert("Expected Error Event", myLogger.lastError is BuildErrorEventArgs); Assertion.Assert("Expected line number to be 0", myLogger.lastError.LineNumber == 0); engineProxy.UpdateContinueOnError(true); // Log the custom event args. (Pretend that the task actually did this.) engineProxy.LogErrorEvent(new BuildErrorEventArgs("SubCategory", "code", null, 0, 1, 2, 3, "message", "Help", "Sender")); engine.LoggingServices.ProcessPostedLoggingEvents(); // Make sure our custom logger received the actual custom event and not some fake. Assertion.Assert("Expected Warning Event", myLogger.lastWarning is BuildWarningEventArgs); Assertion.Assert("Expected line number to be 0", myLogger.lastWarning.LineNumber == 0); }
/// <summary> /// Set up and initialize before each test is run /// </summary> public TaskHost_Tests() { LoggingServiceFactory loggingFactory = new LoggingServiceFactory(LoggerMode.Synchronous, 1); _loggingService = loggingFactory.CreateInstance(BuildComponentType.LoggingService) as LoggingService; _customLogger = new MyCustomLogger(); _mockHost = new MockHost(); _mockHost.LoggingService = _loggingService; _loggingService.RegisterLogger(_customLogger); _elementLocation = ElementLocation.Create("MockFile", 5, 5); BuildRequest buildRequest = new BuildRequest(1 /* submissionId */, 1, 1, new List <string>(), null, BuildEventContext.Invalid, null); BuildRequestConfiguration configuration = new BuildRequestConfiguration(1, new BuildRequestData("Nothing", new Dictionary <string, string>(), "4.0", new string[0], null), "2.0"); configuration.Project = new ProjectInstance(ProjectRootElement.Create()); BuildRequestEntry entry = new BuildRequestEntry(buildRequest, configuration); BuildResult buildResult = new BuildResult(buildRequest, false); buildResult.AddResultsForTarget("Build", new TargetResult(new TaskItem[] { new TaskItem("IamSuper", configuration.ProjectFullPath) }, TestUtilities.GetSkippedResult())); _mockRequestCallback = new MockIRequestBuilderCallback(new BuildResult[] { buildResult }); entry.Builder = (IRequestBuilder)_mockRequestCallback; _taskHost = new TaskHost(_mockHost, entry, _elementLocation, null /*Don't care about the callback either unless doing a build*/); _taskHost.LoggingContext = new TaskLoggingContext(_loggingService, BuildEventContext.Invalid); }
public void TestLogErrorEventNull2() { MyCustomLogger myLogger = new MyCustomLogger(); engine.RegisterLogger(myLogger); engineProxy.UpdateContinueOnError(false); engineProxy.LogErrorEvent(null); engine.LoggingServices.ProcessPostedLoggingEvents(); }
public void BuildProjectFile() { string[] targets; MyCustomLogger myLogger = new MyCustomLogger(); engine.RegisterLogger(myLogger); Dictionary <string, string> globalProperties = new Dictionary <string, string>(); targets = new string[1]; targets[0] = "Build"; Assert.IsTrue(engineProxy.BuildProjectFile(project1, targets, null, new Dictionary <object, object>()), "Expected Build 2 to work"); }
public void TestLogMessageEvent() { MyCustomLogger myLogger = new MyCustomLogger(); engine.RegisterLogger(myLogger); // Log the custom event args. (Pretend that the task actually did this.) engineProxy.LogMessageEvent(new BuildMessageEventArgs("message", "HelpKeyword", "senderName", MessageImportance.High)); engine.LoggingServices.ProcessPostedLoggingEvents(); // Make sure our custom logger received the actual custom event and not some fake. Assertion.Assert("Expected Message Event", myLogger.lastMessage is BuildMessageEventArgs); Assertion.Assert("Expected Message importance to be high", myLogger.lastMessage.Importance == MessageImportance.High); }
public void TestLogCustomEvent() { MyCustomLogger myLogger = new MyCustomLogger(); engine.RegisterLogger(myLogger); // Log the custom event args. (Pretend that the task actually did this.) engineProxy.LogCustomEvent(new MyCustomBuildEventArgs("testCustomBuildEvent")); engine.LoggingServices.ProcessPostedLoggingEvents(); // Make sure our custom logger received the actual custom event and not some fake. Assertion.Assert("Expected custom build Event", myLogger.lastCustom is CustomBuildEventArgs); Assertion.AssertEquals("testCustomBuildEvent", myLogger.lastCustom.Message); }
public static void Main() { var myLogger = new MyCustomLogger(); myLogger.LogInfo("Server starting..."); RequestResponseServer requestResponseServer = new RequestResponseServer(); requestResponseServer.Init(new SimpleRequestHandlerFactory(), myLogger); requestResponseServer.Run(SERVER_URL); myLogger.LogInfo("Server is shutting down..."); Console.ReadKey(); }
public void TestCustomWarningEventException() { MyCustomLogger myLogger = new MyCustomLogger(); engine.RegisterLogger(myLogger); engineProxy2.LogWarningEvent(new CustomWarningEvent()); engine.LoggingServices.ProcessPostedLoggingEvents(); Assertion.AssertNotNull("Expected WarningEvent Not to be null", myLogger.lastWarning); Assertion.AssertEquals(1, myLogger.numberOfWarning); myLogger = null; myLogger = new MyCustomLogger(); engine.RegisterLogger(myLogger); engineProxy.LogWarningEvent(new CustomWarningEvent()); engine.LoggingServices.ProcessPostedLoggingEvents(); Assertion.AssertNotNull("Expected WarningEvent Not to be null", myLogger.lastWarning); Assertion.AssertEquals(1, myLogger.numberOfWarning); myLogger = null; }
public void CustomLoggerIsNotifiedForStartSectionAndEndSection() { var customLogger = new MyCustomLogger(); Logger.Initialize(customLogger); using (Logger.StartSection("Section1")) { Assert.AreEqual(nameof(customLogger.StartSection), customLogger.LastMethodCalled); Logger.WriteLine("Something"); Assert.AreEqual(nameof(customLogger.WriteLine), customLogger.LastMethodCalled); using (Logger.StartSection("Nested section")) { Assert.AreEqual(nameof(customLogger.StartSection), customLogger.LastMethodCalled); } Assert.AreEqual(nameof(customLogger.EndSection), customLogger.LastMethodCalled); } Assert.AreEqual(nameof(customLogger.EndSection), customLogger.LastMethodCalled); }
public void CustomLoggerGetsTimestampAndMessage() { var customLogger = new MyCustomLogger(); Logger.Initialize(customLogger); var timeBeforeWrite = DateTime.Now; Logger.WriteLine("Hello"); var timeAfterWrite = DateTime.Now; Assert.IsTrue(timeBeforeWrite <= customLogger.Timestamp && customLogger.Timestamp <= timeAfterWrite, $"timestamp={customLogger.Timestamp} should be between {timeBeforeWrite} and {timeAfterWrite}"); Assert.AreEqual("Hello", customLogger.Text); Thread.Sleep(100); timeBeforeWrite = DateTime.Now; Logger.WriteLine("World"); timeAfterWrite = DateTime.Now; Assert.IsTrue(timeBeforeWrite <= customLogger.Timestamp && customLogger.Timestamp <= timeAfterWrite); Assert.AreEqual("World", customLogger.Text); }
public void CustomBuildErrorEventIsPreserved() { MyCustomLogger myLogger = new MyCustomLogger(); engine.RegisterLogger(myLogger); // Create a custom build event args that derives from MSBuild's BuildErrorEventArgs. // Set a custom field on this event (FXCopRule). MyCustomBuildErrorEventArgs fxcopError = new MyCustomBuildErrorEventArgs("Your code is lame."); fxcopError.FXCopRule = "CodeLamenessViolation"; // Log the custom event args. (Pretend that the task actually did this.) engineProxy.LogErrorEvent(fxcopError); engine.LoggingServices.ProcessPostedLoggingEvents(); // Make sure our custom logger received the actual custom event and not some fake. Assertion.Assert("Expected Custom Error Event", myLogger.lastError is MyCustomBuildErrorEventArgs); // Make sure the special fields in the custom event match what we originally logged. fxcopError = myLogger.lastError as MyCustomBuildErrorEventArgs; Assertion.AssertEquals("Your code is lame.", fxcopError.Message); Assertion.AssertEquals("CodeLamenessViolation", fxcopError.FXCopRule); }
public void TestLogWarningEvent() { MyCustomLogger myLogger = new MyCustomLogger(); engine.RegisterLogger(myLogger); // Log the custom event args. (Pretend that the task actually did this.) engineProxy.LogWarningEvent(new BuildWarningEventArgs("SubCategory", "code", null, 0, 1, 2, 3, "message", "Help", "Sender")); engine.LoggingServices.ProcessPostedLoggingEvents(); // Make sure our custom logger received the actual custom event and not some fake. Assertion.Assert("Expected Warning Event", myLogger.lastWarning is BuildWarningEventArgs); Assertion.Assert("Expected line number to be 0", myLogger.lastWarning.LineNumber == 0); }
public void TestLogMessageEvent() { MyCustomLogger myLogger = new MyCustomLogger(); engine.RegisterLogger(myLogger); // Log the custom event args. (Pretend that the task actually did this.) engineProxy.LogMessageEvent(new BuildMessageEventArgs("message", "HelpKeyword", "senderName", MessageImportance.High)); engine.LoggingServices.ProcessPostedLoggingEvents(); // Make sure our custom logger received the actual custom event and not some fake. Assertion.Assert("Expected Message Event", myLogger.lastMessage is BuildMessageEventArgs); Assertion.Assert("Expected Message importance to be high", myLogger.lastMessage.Importance == MessageImportance.High); }
public void TestLogErrorEventNull2() { MyCustomLogger myLogger = new MyCustomLogger(); engine.RegisterLogger(myLogger); engineProxy.UpdateContinueOnError(false); engineProxy.LogErrorEvent(null); engine.LoggingServices.ProcessPostedLoggingEvents(); }
public void TestLogCustomEvent() { MyCustomLogger myLogger = new MyCustomLogger(); engine.RegisterLogger(myLogger); // Log the custom event args. (Pretend that the task actually did this.) engineProxy.LogCustomEvent(new MyCustomBuildEventArgs("testCustomBuildEvent")); engine.LoggingServices.ProcessPostedLoggingEvents(); // Make sure our custom logger received the actual custom event and not some fake. Assertion.Assert("Expected custom build Event", myLogger.lastCustom is CustomBuildEventArgs); Assertion.AssertEquals("testCustomBuildEvent", myLogger.lastCustom.Message); }
public void BuildProjectFile() { string[] targets; MyCustomLogger myLogger = new MyCustomLogger(); engine.RegisterLogger(myLogger); Dictionary<string, string> globalProperties = new Dictionary<string, string>(); targets = new string[1]; targets[0] = "Build"; Assert.IsTrue(engineProxy.BuildProjectFile(project1, targets, null, new Dictionary<object, object>()), "Expected Build 2 to work"); }
public void TestCustomMessageEventException() { MyCustomLogger myLogger = new MyCustomLogger(); engine.RegisterLogger(myLogger); engineProxy2.LogMessageEvent(new CustomMessageEvent()); engine.LoggingServices.ProcessPostedLoggingEvents(); Assertion.AssertNull("Expected customMessageEvent to be null", myLogger.lastMessage); Assertion.AssertNotNull("Expected WarningEvent Not to be null", myLogger.lastWarning); Assertion.AssertEquals(0, myLogger.numberOfMessage); Assertion.AssertEquals(1, myLogger.numberOfWarning); myLogger = null; myLogger = new MyCustomLogger(); engine.RegisterLogger(myLogger); engineProxy.LogMessageEvent(new CustomMessageEvent()); engine.LoggingServices.ProcessPostedLoggingEvents(); Assertion.AssertNotNull("Expected customMessageEvent to not be null", myLogger.lastMessage); Assertion.AssertNull("Expected WarningEvent to be null", myLogger.lastWarning); Assertion.AssertEquals(1, myLogger.numberOfMessage); Assertion.AssertEquals(0, myLogger.numberOfWarning); myLogger = null; }
public void TearDown() { _customLogger = null; _mockHost = null; _elementLocation = null; _taskHost = null; }
public void CustomBuildErrorEventIsPreserved() { MyCustomLogger myLogger = new MyCustomLogger(); engine.RegisterLogger(myLogger); // Create a custom build event args that derives from MSBuild's BuildErrorEventArgs. // Set a custom field on this event (FXCopRule). MyCustomBuildErrorEventArgs fxcopError = new MyCustomBuildErrorEventArgs("Your code is lame."); fxcopError.FXCopRule = "CodeLamenessViolation"; // Log the custom event args. (Pretend that the task actually did this.) engineProxy.LogErrorEvent(fxcopError); engine.LoggingServices.ProcessPostedLoggingEvents(); // Make sure our custom logger received the actual custom event and not some fake. Assertion.Assert("Expected Custom Error Event", myLogger.lastError is MyCustomBuildErrorEventArgs); // Make sure the special fields in the custom event match what we originally logged. fxcopError = myLogger.lastError as MyCustomBuildErrorEventArgs; Assertion.AssertEquals("Your code is lame.", fxcopError.Message); Assertion.AssertEquals("CodeLamenessViolation", fxcopError.FXCopRule); }