<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Unit testing and objects equality</title>
	<atom:link href="http://sirmike.org/2009/02/16/unit-testing-and-objects-equality/feed/" rel="self" type="application/rss+xml" />
	<link>http://sirmike.org/2009/02/16/unit-testing-and-objects-equality/</link>
	<description>C++, C#, ASP.NET, OpenGL, DirectX, Game developing</description>
	<lastBuildDate>Sun, 01 Aug 2010 19:45:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: SirMike</title>
		<link>http://sirmike.org/2009/02/16/unit-testing-and-objects-equality/comment-page-1/#comment-1133</link>
		<dc:creator>SirMike</dc:creator>
		<pubDate>Sat, 21 Feb 2009 13:49:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.sirmike.org/?p=232#comment-1133</guid>
		<description>I think you&#039;re right :) No remorse to the bad code!</description>
		<content:encoded><![CDATA[<p>I think you&#8217;re right <img src='http://sirmike.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  No remorse to the bad code!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: moozzyk</title>
		<link>http://sirmike.org/2009/02/16/unit-testing-and-objects-equality/comment-page-1/#comment-1132</link>
		<dc:creator>moozzyk</dc:creator>
		<pubDate>Sat, 21 Feb 2009 04:13:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.sirmike.org/?p=232#comment-1132</guid>
		<description>Well, I don&#039;t think the test needs to be fixed here - the test is good. It found a bug in your code. I think this is the code that needs to be fixed so that the result of both of the calls 
(
Console.WriteLine(one.Equals(two));
Console.WriteLine(objOne.Equals(objTwo));
) 
is the same. Otherwise it will hit you sooner or later (or I would say sooner than later)

moozzyk</description>
		<content:encoded><![CDATA[<p>Well, I don&#8217;t think the test needs to be fixed here &#8211; the test is good. It found a bug in your code. I think this is the code that needs to be fixed so that the result of both of the calls<br />
(<br />
Console.WriteLine(one.Equals(two));<br />
Console.WriteLine(objOne.Equals(objTwo));<br />
)<br />
is the same. Otherwise it will hit you sooner or later (or I would say sooner than later)</p>
<p>moozzyk</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SirMike</title>
		<link>http://sirmike.org/2009/02/16/unit-testing-and-objects-equality/comment-page-1/#comment-1131</link>
		<dc:creator>SirMike</dc:creator>
		<pubDate>Fri, 20 Feb 2009 21:15:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.sirmike.org/?p=232#comment-1131</guid>
		<description>Thanks for a comprehensive comment. Yes, AreSame in this example is really stupid :)
Finally I had created an Assert exactly the same way like you proposed:

Assert.IsTrue(one.Equals(two));

:)</description>
		<content:encoded><![CDATA[<p>Thanks for a comprehensive comment. Yes, AreSame in this example is really stupid <img src='http://sirmike.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
Finally I had created an Assert exactly the same way like you proposed:</p>
<p>Assert.IsTrue(one.Equals(two));</p>
<p> <img src='http://sirmike.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: moozzyk</title>
		<link>http://sirmike.org/2009/02/16/unit-testing-and-objects-equality/comment-page-1/#comment-1130</link>
		<dc:creator>moozzyk</dc:creator>
		<pubDate>Fri, 20 Feb 2009 06:16:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.sirmike.org/?p=232#comment-1130</guid>
		<description>AreSame should not return true ever. Just use reflector and you will find it is implemented as follows:
if (!object.ReferenceEquals(expected, actual))

AreEqual - again if you use reflector you will see what is happening. Then you will probably write a test like this:
            Foo one = new Foo();
            one.Variable = 5;
            Foo two = new Foo();
            two.Variable = 5;

            object objOne = one;
            object objTwo = two;

            Console.WriteLine(one.Equals(two));
            Console.WriteLine(objOne.Equals(objTwo));

Here is the output:
True
False

This is &quot;kinda&quot; puzzling unless you go to msdn (http://msdn.microsoft.com/en-us/library/ms131190.aspx) and read:

Notes to Implementers: 
If you implement Equals, you should also override the base class implementations of Object..::.Equals(Object) and GetHashCode so that their behavior is consistent with that of the IEquatable&lt;(Of )&gt;)..::.Equals method. If you do override Object..::.Equals(Object), your overridden implementation is also called in calls to the static Equals(System.Object, System.Object) method on your class. This ensures that all invocations of the Equals method return consistent results (...)

So you basically have a bug in your Foo class and your UnitTest found the bug - this is a damn good test :) 

moozzyk

P.S. I hate details like this since they are showing how much I still don&#039;t know. I also don&#039;t think I would find this bug if I reviewed your code...</description>
		<content:encoded><![CDATA[<p>AreSame should not return true ever. Just use reflector and you will find it is implemented as follows:<br />
if (!object.ReferenceEquals(expected, actual))</p>
<p>AreEqual &#8211; again if you use reflector you will see what is happening. Then you will probably write a test like this:<br />
            Foo one = new Foo();<br />
            one.Variable = 5;<br />
            Foo two = new Foo();<br />
            two.Variable = 5;</p>
<p>            object objOne = one;<br />
            object objTwo = two;</p>
<p>            Console.WriteLine(one.Equals(two));<br />
            Console.WriteLine(objOne.Equals(objTwo));</p>
<p>Here is the output:<br />
True<br />
False</p>
<p>This is &#8220;kinda&#8221; puzzling unless you go to msdn (<a href="http://msdn.microsoft.com/en-us/library/ms131190.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms131190.aspx</a>) and read:</p>
<p>Notes to Implementers:<br />
If you implement Equals, you should also override the base class implementations of Object..::.Equals(Object) and GetHashCode so that their behavior is consistent with that of the IEquatable&lt;(Of )&gt;)..::.Equals method. If you do override Object..::.Equals(Object), your overridden implementation is also called in calls to the static Equals(System.Object, System.Object) method on your class. This ensures that all invocations of the Equals method return consistent results (&#8230;)</p>
<p>So you basically have a bug in your Foo class and your UnitTest found the bug &#8211; this is a damn good test <img src='http://sirmike.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
<p>moozzyk</p>
<p>P.S. I hate details like this since they are showing how much I still don&#8217;t know. I also don&#8217;t think I would find this bug if I reviewed your code&#8230;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
