Reputation: 1885
This has stumped a few of us. It's VS2013, and the code itself builds correctly as you can see from the image. We've run this test on 2 different machines with the same results.
I did copy/paste the code originally into and from MS OneNote, so possibly there is a reason there. But as you can see from Notepad++ there don't appear to be any special characters.
Ideas?
To expand on this, the following version also fails:
//Note: Why this does not pass is baffling
[TestMethod]
public void FunnyTestThatFailsForSomeReason()
{
const string expectedErrorMessage = "Web Session Not Found.";
var a = "Web Session Not Found.";
string b = "Web Session Not Found.";
Assert.AreEqual(expectedErrorMessage, a);
//Assert.AreEqual(expectedErrorMessage, b);
Assert.AreEqual(expectedErrorMessage.ToString(), b.ToString());
}
Upvotes: 0
Views: 106
Reputation: 160271
(Here for formatting purposes; the existing answer also explains what's happened. This is just the hex dump of your question's code.)
00000000: 2020 2020 7661 7220 6120 3d20 2257 6562 c2a0 5365 7373 696f : var a = "Web..Sessio
00000018: 6ec2 a04e 6f74 c2a0 466f 756e 642e 223b 0a20 2020 2020 2020 :n..Not..Found.";.
00000030: 2020 2020 2073 7472 696e 6720 6220 3d20 2257 6562 2053 6573 : string b = "Web Ses
00000048: 7369 6f6e 204e 6f74 2046 6f75 6e64 2e22 3b0a :sion Not Found.";.
The strings aren't the same.
Upvotes: 0
Reputation: 27214
You're using Assert.AreEqual(Object, Object)
which (in this case) is looking for reference equality. It's not going to work the way you want it to.
Verifies that two specified objects are equal. The assertion fails if the objects are not equal.
Use Assert.AreEqual(String, String, Boolean)
.
Verifies that two specified strings are equal, ignoring case or not as specified. The assertion fails if they are not equal.
Or, more simply, your strings are subtly different. Copy and pasting appears to have yielded different results:
Upvotes: 2