- is it a breaking change in the .Net framework
- is it a different behavior of Nunit (I upgraded Nunit also to the latest version to be able to test .Net 4.5)
- something else ...
[Test] public void NotAvailableNotEvenEqualToItself() { Assert.AreNotEqual(ConditionalGetFingerprint.NOT_AVAILABLE, ConditionalGetFingerprint.NOT_AVAILABLE); Assert.AreSame(ConditionalGetFingerprint.NOT_AVAILABLE, ConditionalGetFingerprint.NOT_AVAILABLE); }As said before that one works in .Net 3.5, but not in .Net 4.5
I've updated the test to the following and still the same bold line breaks.
[Test] public void NotAvailableNotEvenEqualToItself() { Assert.IsTrue(ConditionalGetFingerprint.NOT_AVAILABLE == ConditionalGetFingerprint.NOT_AVAILABLE); Assert.IsTrue(ConditionalGetFingerprint.Equals(ConditionalGetFingerprint.NOT_AVAILABLE, ConditionalGetFingerprint.NOT_AVAILABLE)); Assert.AreNotEqual(ConditionalGetFingerprint.NOT_AVAILABLE, ConditionalGetFingerprint.NOT_AVAILABLE); Assert.AreSame(ConditionalGetFingerprint.NOT_AVAILABLE, ConditionalGetFingerprint.NOT_AVAILABLE); }The same test with the added asserts is still green in .Net 3.5 (with both versions of NUnit).
The code in CCNet uses statements like : (if fingerprint1 == fingerprint2) as far as I could see, so I would guess that the functionality stays the same, but I'm not 100% sure :-(
I understand the difference between the == and the .equals operator- == tests for object equivalence
- .Equals() test that objects represent the same 'value', they may represent different objects but the value of these are considered the same.
And now something really weird : If I change the test to just the breaking assert
[Test] public void NotAvailableNotEvenEqualToItself() { Assert.AreNotEqual(ConditionalGetFingerprint.NOT_AVAILABLE, ConditionalGetFingerprint.NOT_AVAILABLE); }and I change that override equals of the ConditionalGetFingerprint into the following :
public override bool Equals(object obj) { Console.WriteLine("Equals method"); return false; }Result :
- In .Net framework 3.5 it passes, and I see the string "Equals method" in the output.
- In .Net framework 4.5 it does not pass, and I do NOT see the string "Equals method" in the output
--> this leads me to the believe that this is change in the .Net framework or it's compiler. I've found a blog, and at the bottom it says :
In C# 4.0, if the operands to == are "dynamic" then we will do the usual compile-time analysis at runtime based on the runtime types, which effectively does give you something like double-virtual dispatch, at the cost of running the compiler at runtime. We will cache the results of the analysis, so the second time you hit the call site, it should be reasonably efficient.
so does this indeed imply a change in .Net? Any help, guidance, tips are really appreciated !
You can find the source of CCNet in the links below :
This comment has been removed by a blog administrator.
ReplyDeleteHi.
ReplyDeleteThat CCNet 1.9 works fine for .NET framework 4.5 really?
I need urgent.