public void Equals() { ApplicationDirectory ad1 = new ApplicationDirectory("mono"); Assert.IsFalse(ad1.Equals(null), "Equals(null)"); Assert.IsFalse(ad1.Equals(String.Empty), "Equals(String.Empty)"); Assert.IsFalse(ad1.Equals("mono"), "Equals(mono)"); Assert.IsTrue(ad1.Equals(ad1), "Equals(self)"); ApplicationDirectory ad2 = new ApplicationDirectory(ad1.Directory); Assert.IsTrue(ad1.Equals(ad2), "Equals(ad2)"); Assert.IsTrue(ad2.Equals(ad1), "Equals(ad2)"); ApplicationDirectory ad3 = new ApplicationDirectory(".."); Assert.IsFalse(ad2.Equals(ad3), "Equals(ad3)"); }
public static void ApplicationDirectoryCallMethods() { ApplicationDirectory ad = new ApplicationDirectory("test"); object obj = ad.Copy(); bool check = ad.Equals(new object()); int hash = ad.GetHashCode(); string str = ad.ToString(); }
public void Copy() { ApplicationDirectory ad = new ApplicationDirectory("novell"); Assert.AreEqual("novell", ad.Directory, "Directory"); ApplicationDirectory copy = (ApplicationDirectory)ad.Copy(); Assert.IsTrue(ad.Equals(copy), "ad.Equals(copy)"); Assert.IsTrue(copy.Equals(ad), "copy.Equals(ad)"); Assert.IsFalse(Object.ReferenceEquals(ad, copy), "Copy"); Assert.AreEqual(ad.GetHashCode(), copy.GetHashCode(), "GetHashCode"); Assert.AreEqual(ad.ToString(), copy.ToString(), "ToString"); }
public void Equals_Invalid() { // funny one string appdir = Invalid(true); // constructor is ok with an invalid path... ApplicationDirectory ad = new ApplicationDirectory(appdir); // we can copy it... ApplicationDirectory copy = (ApplicationDirectory)ad.Copy(); // we can't get it's hash code Assert.AreEqual(appdir.GetHashCode(), ad.GetHashCode(), "GetHashCode"); // we can convert it to string... Assert.IsTrue(ad.ToString().IndexOf(appdir) > 0, "ToString"); // ... but it throws in Equals - with self! Assert.IsTrue(ad.Equals(ad), "Equals(self)"); }