Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

C# UnitTest - Assert.AreEqual() does not call Equals if the argument is null

By: a guest on Feb 26th, 2012  |  syntax: None  |  size: 0.31 KB  |  views: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2.  
  3. class TestClass
  4. {
  5.     public override bool Equals(object obj)
  6.     {
  7.         return true;
  8.     }
  9. }
  10.  
  11. [TestMethod]
  12. public void TestMethod1()
  13. {
  14.     TestClass t = new TestClass ();
  15.     Assert.AreEqual (t, null); // fails
  16.     Assert.IsTrue (t.Equals (null)); // passes
  17. }