public void Handle(TestCaseResult message) { if (message == null) throw new ArgumentNullException("message"); switch (message.ResultType) { case ResultType.Ignored: "I".WrapConsoleMessageWithColor(_settings.ConsoleColorInformation, false); break; case ResultType.Passed: ".".WrapConsoleMessageWithColor(_settings.ConsoleColorInformation, false); break; case ResultType.Failed: case ResultType.SystemGeneratedFailure: System.Console.WriteLine(""); "------------------ ".WrapConsoleMessageWithColor(_settings.ConsoleColorError, false); "Test ".WrapConsoleMessageWithColor(_settings.ConsoleColorError, false); "Failed".WrapConsoleMessageWithColor(_settings.ConsoleColorError, false); " ------------------".WrapConsoleMessageWithColor(_settings.ConsoleColorError, true); "Test Namespace: ".WrapConsoleMessageWithColor(_settings.ConsoleColorInformation, false); message.NamespaceName.WrapConsoleMessageWithColor(_settings.ConsoleColorError, true); "Test Class: ".WrapConsoleMessageWithColor(_settings.ConsoleColorInformation, false); message.ClassName.WrapConsoleMessageWithColor(_settings.ConsoleColorError, true); "Test Method: ".WrapConsoleMessageWithColor(_settings.ConsoleColorInformation, false); message.MethodName.WrapConsoleMessageWithColor(_settings.ConsoleColorError, true); if (!string.IsNullOrEmpty(message.OtherInfo)) { "Other Info: ".WrapConsoleMessageWithColor(_settings.ConsoleColorInformation, false); message.OtherInfo.WrapConsoleMessageWithColor(_settings.ConsoleColorError, true); } foreach (var metaData in message.Metadata) { "{0,-19}".FormatWith(metaData.Classification + ": ").WrapConsoleMessageWithColor(_settings.ConsoleColorInformation, false); (metaData.Name + " - ").WrapConsoleMessageWithColor(_settings.ConsoleColorInformation, false); metaData.Value.WrapConsoleMessageWithColor(_settings.ConsoleColorError, true); } WriteExceptionInfo(message.ExceptionInfo); "-------------------------------------------------" .WrapConsoleMessageWithColor(ConsoleColor.DarkRed, true); break; default: "Unknown TestCaseResult (to StatLight) - {0}".FormatWith(message.ResultType) .WrapConsoleMessageWithColor(_settings.ConsoleColorError, true); break; } }
public void Handle(TestCaseResult message) { if (message == null) throw new ArgumentNullException("message"); switch (message.ResultType) { case ResultType.Ignored: "I".WrapConsoleMessageWithColor(_settings.ConsoleColorInformatoin, false); break; case ResultType.Passed: ".".WrapConsoleMessageWithColor(_settings.ConsoleColorInformatoin, false); break; case ResultType.Failed: case ResultType.SystemGeneratedFailure: System.Console.WriteLine(""); "------------------ ".WrapConsoleMessageWithColor(_settings.ConsoleColorError, false); "Test ".WrapConsoleMessageWithColor(_settings.ConsoleColorError, false); "Failed".WrapConsoleMessageWithColor(_settings.ConsoleColorError, false); " ------------------".WrapConsoleMessageWithColor(_settings.ConsoleColorError, true); "Test Namespace: ".WrapConsoleMessageWithColor(_settings.ConsoleColorInformatoin, false); message.NamespaceName.WrapConsoleMessageWithColor(_settings.ConsoleColorError, true); "Test Class: ".WrapConsoleMessageWithColor(_settings.ConsoleColorInformatoin, false); message.ClassName.WrapConsoleMessageWithColor(_settings.ConsoleColorError, true); "Test Method: ".WrapConsoleMessageWithColor(_settings.ConsoleColorInformatoin, false); message.MethodName.WrapConsoleMessageWithColor(_settings.ConsoleColorError, true); if (!string.IsNullOrEmpty(message.OtherInfo)) { "Other Info: ".WrapConsoleMessageWithColor(_settings.ConsoleColorInformatoin, false); message.OtherInfo.WrapConsoleMessageWithColor(_settings.ConsoleColorError, true); } if (message.ExceptionInfo != null) { //TODO: print to the console - the exception info in a more readable/visually parsable format "Exception Message: ".WrapConsoleMessageWithColor(_settings.ConsoleColorInformatoin, true); message.ExceptionInfo.FullMessage.WrapConsoleMessageWithColor(_settings.ConsoleColorError, true); } "-------------------------------------------------" .WrapConsoleMessageWithColor(ConsoleColor.DarkRed, true); break; default: "Unknown TestCaseResult (to StatLight) - {0}".FormatWith(message.ResultType) .WrapConsoleMessageWithColor(_settings.ConsoleColorError, true); break; } }
private static string GetErrorMessage(TestCaseResult result) { var sb = new StringBuilder(); if (result.ExceptionInfo != null) sb.Append(result.ExceptionInfo.FullMessage); if (!string.IsNullOrEmpty(result.OtherInfo)) { sb.Append(Environment.NewLine); sb.Append(result.OtherInfo); } var rtn = sb.ToString(); return string.IsNullOrEmpty(rtn) ? null : rtn; }
public void Handle(TestCaseResult message) { if (message == null) throw new ArgumentNullException("message"); var name = message.FullMethodName(); var durationMilliseconds = message.TimeToComplete.Milliseconds; switch (message.ResultType) { case ResultType.Ignored: WrapTestWithStartAndEnd(CommandFactory.TestIgnored(message.MethodName, string.Empty), message.MethodName, 0); break; case ResultType.Passed: WrapTestWithStartAndEnd(() => { }, name, durationMilliseconds); break; case ResultType.Failed: WrapTestWithStartAndEnd(() => _messageWriter.Write( CommandFactory.TestFailed( name, message.ExceptionInfo.FullMessage, message.ExceptionInfo.FullMessage)), name, durationMilliseconds); break; case ResultType.SystemGeneratedFailure: WrapTestWithStartAndEnd(() => _messageWriter.Write( CommandFactory.TestFailed( name, "StatLight generated test failure", message.OtherInfo)), name, durationMilliseconds); break; default: "Unknown TestCaseResult (to StatLight) - {0}".FormatWith(message.ResultType) .WrapConsoleMessageWithColor(Settings.Default.ConsoleColorError, true); break; } }
public TestReport AddResult(TestCaseResult result) { SetLastMessageReceivedTime(); _testCaseResults.Add(result); return this; }
private static XElement GetResult(TestCaseResult result) { Func<TestCaseResult, string> formatName = resultX => resultX.FullMethodName(); XElement otherInfoElement = null; if (!string.IsNullOrEmpty(result.OtherInfo)) { otherInfoElement = new XElement("otherInfo", result.OtherInfo); } XElement exceptionInfoElement = null; if (result.ExceptionInfo != null) { exceptionInfoElement = FormatExceptionInfoElement(result.ExceptionInfo); } return new XElement("test", new XAttribute("name", formatName(result)), new XAttribute("resulttype", result.ResultType), new XAttribute("timeToComplete", result.TimeToComplete.ToString()), exceptionInfoElement, otherInfoElement ); }
private Guid GetTestId(TestCaseResult testCaseResult) { return GetGuidForItem(testCaseResult, HashType.TestId); }
private Guid GetGuidForItem(TestCaseResult testCaseResult, HashType hashType) { IDictionary<TestCaseResult, Guid> hash; switch (hashType) { case HashType.ExecutionId: hash = _executionIdHash; break; case HashType.TestId: hash = _testIdHash; break; default: throw new NotImplementedException(); } Guid newGuid; if (hash.ContainsKey(testCaseResult)) newGuid = hash[testCaseResult]; else { newGuid = _guidSequenceGenerator.GetNext(); hash.Add(testCaseResult, newGuid); } return newGuid; }
private Guid GetExecutionId(TestCaseResult testCaseResult) { return GetGuidForItem(testCaseResult, HashType.ExecutionId); }
private static XElement GetTestOwner(TestCaseResult test, XNamespace ns) { var owners = test.Metadata.Where(i => i.Value == "Owner"); var items = new List<XElement>(); foreach (var owner in owners) { items.Add(new XElement(ns + "Owner", new XAttribute("name", owner.Name))); } if (items.Count > 0) return new XElement(ns + "Owners", items); return null; }
internal bool TryFindByFullName(string fullName, out TestCaseResult testCaseResult) { testCaseResult = _testCaseResults.Where(w => w.FullMethodName() == fullName).SingleOrDefault(); return testCaseResult != null; }
public void Handle(TestCaseResult message) { Console.WriteLine("Hello From Class1"); }
public void Handle(TestCaseResult message) { if (message == null) throw new ArgumentNullException("message"); var name = message.FullMethodName(); var durationMilliseconds = message.TimeToComplete.Milliseconds; switch (message.ResultType) { case ResultType.Ignored: WrapTestWithStartAndEnd(CommandFactory.TestIgnored(message.MethodName, string.Empty), message.MethodName, 0); break; case ResultType.Passed: WrapTestWithStartAndEnd(() => { }, name, durationMilliseconds); break; case ResultType.Failed: var sb = new StringBuilder(); sb.Append("Test Namespace: "); sb.AppendLine(message.NamespaceName); sb.Append("Test Class: "); sb.AppendLine(message.ClassName); sb.Append("Test Method: "); sb.AppendLine(message.MethodName); if (!string.IsNullOrEmpty(message.OtherInfo)) { sb.Append("Other Info: "); sb.AppendLine(message.OtherInfo); } foreach (var metaData in message.Metadata) { sb.Append("{0,-17}".FormatWith(metaData.Classification + ": ")); sb.Append(metaData.Name + " - "); sb.AppendLine(metaData.Value); } sb.AppendLine(message.ExceptionInfo.FullMessage); var msg = sb.ToString(); WrapTestWithStartAndEnd(() => _messageWriter.Write( CommandFactory.TestFailed( name, message.ExceptionInfo.FullMessage, msg)), name, durationMilliseconds); break; case ResultType.SystemGeneratedFailure: WrapTestWithStartAndEnd(() => _messageWriter.Write( CommandFactory.TestFailed( name, "StatLight generated test failure", message.OtherInfo)), name, durationMilliseconds); break; default: "Unknown TestCaseResult (to StatLight) - {0}".FormatWith(message.ResultType) .WrapConsoleMessageWithColor(Settings.Default.ConsoleColorError, true); break; } }
private static XElement GetResult(TestCaseResult result) { Func<TestCaseResult, string> formatName = resultX => resultX.FullMethodName(); XElement otherInfoElement = null; if (!string.IsNullOrEmpty(result.OtherInfo)) { otherInfoElement = new XElement("otherInfo", result.OtherInfo); } XElement exceptionInfoElement = null; if (result.ExceptionInfo != null) { exceptionInfoElement = FormatExceptionInfoElement(result.ExceptionInfo); } XElement metaData = null; if (result.Metadata.Any()) { metaData = new XElement("metaDataItems", from md in result.Metadata select new XElement("metaData", new XAttribute("classification", md.Classification), new XAttribute("name", md.Name), md.Value)); } return new XElement("test", new XAttribute("name", formatName(result)), new XAttribute("resulttype", result.ResultType), new XAttribute("timeToComplete", result.TimeToComplete.ToString()), exceptionInfoElement, otherInfoElement, metaData ); }