Merge pull request #1410 from alesliehughes/master
[mono.git] / mcs / nunit24 / ClientUtilities / util / TestResultItem.cs
1 // ****************************************************************\r
2 // This is free software licensed under the NUnit license. You\r
3 // may obtain a copy of the license as well as information regarding\r
4 // copyright ownership at http://nunit.org/?p=license&r=2.4.\r
5 // ****************************************************************\r
6 \r
7 using System;\r
8 \r
9 namespace NUnit.Util\r
10 {\r
11         using NUnit.Core;\r
12 \r
13         /// <summary>\r
14         /// Summary description for TestResultItem.\r
15         /// </summary>\r
16         public class TestResultItem\r
17         {\r
18                 private string testName;\r
19                 private string message;\r
20                 private string stackTrace;\r
21 \r
22                 public TestResultItem(TestResult result )\r
23                 {\r
24                         testName = result.Test.TestName.FullName;\r
25                         message = result.Message;\r
26                         stackTrace = result.StackTrace;\r
27 \r
28                         if ( result.Test.IsSuite && result.FailureSite == FailureSite.SetUp )\r
29                                 testName += " (TestFixtureSetUp)";\r
30                 }\r
31 \r
32                 public TestResultItem( string testName, string message, string stackTrace )\r
33                 {\r
34                         this.testName = testName;\r
35                         this.message = message;\r
36                         this.stackTrace = stackTrace;\r
37                 }\r
38 \r
39                 public override string ToString()\r
40                 {\r
41                         if ( message.Length > 64000 )\r
42                                 return string.Format( "{0}:{1}{2}", testName, Environment.NewLine, message.Substring( 0, 64000 ) );\r
43 \r
44                         return GetMessage();\r
45                 }\r
46 \r
47                 public string GetMessage()\r
48                 {\r
49                         return String.Format("{0}:{1}{2}", testName, Environment.NewLine, message);\r
50                 }\r
51 \r
52         public string GetToolTipMessage()   //NRG 05/28/03 - Substitute spaces for tab characters\r
53         {\r
54             return (ReplaceTabs(GetMessage(), 8)); // Change each tab to 8 space characters\r
55         }\r
56 \r
57         public string ReplaceTabs(string strOriginal, int nSpaces)  //NRG 05/28/03\r
58         {\r
59             string strSpaces = string.Empty;\r
60             strSpaces = strSpaces.PadRight(nSpaces, ' ');\r
61             return(strOriginal.Replace("\t", strSpaces));\r
62         }\r
63 \r
64                 public string StackTrace\r
65                 {\r
66                         get \r
67                         {\r
68                                 string trace = "No stack trace is available";\r
69                                 if(stackTrace != null)\r
70                                         trace = StackTraceFilter.Filter(stackTrace);\r
71 \r
72                                 return trace;\r
73                         }\r
74                 }\r
75         }\r
76 }\r