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
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
20 public class TestID : ICloneable
\r
24 /// The int key that distinguishes this test from all others created
\r
25 /// by the same runner.
\r
30 /// Static value to seed ids. It's started at 1000 so any
\r
31 /// uninitialized ids will stand out.
\r
33 private static int nextID = 1000;
\r
37 #region Construction
\r
39 /// Construct a new TestID
\r
43 this.id = unchecked( nextID++ );
\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
52 /// <param name="id"></param>
\r
53 public TestID( int id )
\r
59 #region Static Methods
\r
61 /// Parse a TestID from it's string representation
\r
63 /// <param name="s"></param>
\r
64 /// <returns></returns>
\r
65 public static TestID Parse( string s )
\r
67 int id = Int32.Parse( s );
\r
68 return new TestID( id );
\r
72 #region Object Overrides
\r
74 /// Override of Equals method to allow comparison of TestIDs
\r
76 /// <param name="obj"></param>
\r
77 /// <returns></returns>
\r
78 public override bool Equals(object obj)
\r
80 TestID other = obj as TestID;
\r
81 if ( other != null )
\r
82 return this.id == other.id;
\r
84 return base.Equals (obj);
\r
88 /// Override of GetHashCode for TestIDs
\r
90 /// <returns></returns>
\r
91 public override int GetHashCode()
\r
93 return id.GetHashCode();
\r
97 /// Override ToString() to display the int id
\r
99 /// <returns></returns>
\r
100 public override string ToString()
\r
102 return id.ToString();
\r
106 #region Operator Overrides
\r
108 /// Operator == override
\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
115 if ( Object.Equals( id1, null ) )
\r
116 return Object.Equals( id2, null );
\r
118 return id1.Equals( id2 );
\r
122 /// Operator != override
\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
129 return id1 == id2 ? false : true;
\r
133 #region ICloneable Implementation
\r
135 /// Clone this TestID
\r
137 /// <returns>An identical TestID</returns>
\r
138 public object Clone()
\r
140 return this.MemberwiseClone();
\r