[msvc] Update csproj files (#4074)
[mono.git] / mcs / nunit24 / NUnitCore / interfaces / TestID.cs
1 // ****************************************************************\r
2 // Copyright 2007, Charlie Poole\r
3 // This is free software licensed under the NUnit license. You may\r
4 // obtain a copy of the license at http://nunit.org/?p=license&r=2.4\r
5 // ****************************************************************\r
6 using System;\r
7 \r
8 namespace NUnit.Core\r
9 {\r
10         /// <summary>\r
11         /// TestID encapsulates a unique identifier for tests. As\r
12         /// currently implemented, this is an integer and is unique\r
13         /// within the AppDomain. TestID is one component of a \r
14         /// TestName. We use this object, rather than a raw int,\r
15         /// for two reasons: (1) to hide the implementation so\r
16         /// it may be changed later if necessary and (2) so that the\r
17         /// id may be null in a "weak" TestName.\r
18         /// </summary>\r
19         [Serializable]\r
20         public class TestID : ICloneable\r
21         {\r
22                 #region Fields\r
23                         /// <summary>\r
24                         /// The int key that distinguishes this test from all others created\r
25                         /// by the same runner.\r
26                         /// </summary>\r
27                         private int id;\r
28                 \r
29                 /// <summary>\r
30                 /// Static value to seed ids. It's started at 1000 so any\r
31                 /// uninitialized ids will stand out.\r
32                 /// </summary>\r
33                 private static int nextID = 1000;\r
34 \r
35                 #endregion\r
36 \r
37                 #region Construction\r
38                 /// <summary>\r
39                 /// Construct a new TestID\r
40                 /// </summary>\r
41                 public TestID()\r
42                 {\r
43                         this.id = unchecked( nextID++ );\r
44                 }\r
45 \r
46                 /// <summary>\r
47                 /// Construct a TestID with a given value.\r
48                 /// Used in parsing test names and in order\r
49                 /// to construct an artificial test node for\r
50                 /// aggregating multiple test runners.\r
51                 /// </summary>\r
52                 /// <param name="id"></param>\r
53                 public TestID( int id )\r
54                 {\r
55                         this.id = id;\r
56                 }\r
57                 #endregion\r
58 \r
59                 #region Static Methods\r
60                 /// <summary>\r
61                 /// Parse a TestID from it's string representation\r
62                 /// </summary>\r
63                 /// <param name="s"></param>\r
64                 /// <returns></returns>\r
65                 public static TestID Parse( string s )\r
66                 {\r
67                         int id = Int32.Parse( s );\r
68                         return new TestID( id );\r
69                 }\r
70                 #endregion\r
71 \r
72                 #region Object Overrides\r
73                 /// <summary>\r
74                 /// Override of Equals method to allow comparison of TestIDs\r
75                 /// </summary>\r
76                 /// <param name="obj"></param>\r
77                 /// <returns></returns>\r
78                 public override bool Equals(object obj)\r
79                 {\r
80                         TestID other = obj as TestID;\r
81                         if ( other != null )\r
82                                 return this.id == other.id;\r
83 \r
84                         return base.Equals (obj);\r
85                 }\r
86 \r
87                 /// <summary>\r
88                 /// Override of GetHashCode for TestIDs\r
89                 /// </summary>\r
90                 /// <returns></returns>\r
91                 public override int GetHashCode()\r
92                 {\r
93                         return id.GetHashCode();\r
94                 }\r
95 \r
96                 /// <summary>\r
97                 /// Override ToString() to display the int id\r
98                 /// </summary>\r
99                 /// <returns></returns>\r
100                 public override string ToString()\r
101                 {\r
102                         return id.ToString();\r
103                 }\r
104                 #endregion\r
105 \r
106                 #region Operator Overrides\r
107         /// <summary>\r
108         /// Operator == override\r
109         /// </summary>\r
110         /// <param name="id1"></param>\r
111         /// <param name="id2"></param>\r
112         /// <returns></returns>\r
113                 public static bool operator ==( TestID id1, TestID id2 )\r
114                 {\r
115                         if ( Object.Equals( id1, null ) )\r
116                                 return Object.Equals( id2, null );\r
117 \r
118                         return id1.Equals( id2 );\r
119                 }\r
120 \r
121         /// <summary>\r
122         /// Operator != override\r
123         /// </summary>\r
124         /// <param name="id1"></param>\r
125         /// <param name="id2"></param>\r
126         /// <returns></returns>\r
127                 public static bool operator !=( TestID id1, TestID id2 )\r
128                 {\r
129                         return id1 == id2 ? false : true;\r
130                 }\r
131                 #endregion\r
132 \r
133                 #region ICloneable Implementation\r
134         /// <summary>\r
135         /// Clone this TestID\r
136         /// </summary>\r
137         /// <returns>An identical TestID</returns>\r
138                 public object Clone()\r
139                 {\r
140                         return this.MemberwiseClone();\r
141                 }\r
142                 #endregion\r
143         }\r
144 }\r