{"id":248,"date":"2010-04-26T15:31:09","date_gmt":"2010-04-26T20:31:09","guid":{"rendered":"http:\/\/hoolihan.net\/blog-tim\/?p=248"},"modified":"2010-09-03T09:47:00","modified_gmt":"2010-09-03T14:47:00","slug":"equals-and-mstest","status":"publish","type":"post","link":"http:\/\/hoolihan.net\/blog-tim\/2010\/04\/26\/equals-and-mstest\/","title":{"rendered":"Equals, ==, and MSTest"},"content":{"rendered":"<pre>\r\n<code>    \r\n  public class SampleClass\r\n    {\r\n        public int X { get; set; }\r\n\r\n        public override bool Equals(object obj)\r\n        {\r\n            if (obj == null) return false;\r\n            if (obj.GetType() != typeof(SampleClass)) return false;\r\n            var s = obj as SampleClass;\r\n            return this.X == s.X;\r\n        }\r\n    }<\/code>\r\n<\/pre>\n<p>Tests:<\/p>\n<pre>\r\n<code>        [TestMethod()]\r\n        public void EqualsTest()\r\n        {\r\n            var sc = new SampleClass { X = 1 };\r\n            var sc_copy = sc;\r\n            var sc2 = new SampleClass { X = 1 };\r\n\r\n            Assert.IsFalse(sc.Equals(null));\r\n            Assert.IsTrue(sc.Equals(sc));\r\n            Assert.IsTrue(sc == sc_copy);\r\n            Assert.IsFalse(sc == sc2);\r\n            Assert.IsTrue(sc.Equals(sc2));\r\n            Assert.IsTrue(sc2.Equals(sc));\r\n            Assert.IsTrue(sc.Equals(sc_copy));\r\n\r\n            Assert.AreEqual(sc, sc2);\r\n            Assert.AreEqual(sc, sc_copy);\r\n            Assert.AreSame(sc, sc_copy);\r\n            Assert.AreNotSame(sc, sc2);\r\n            Assert.AreNotSame(sc_copy, sc2);\r\n        }<\/code>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>public class SampleClass { public int X { get; set; } public override bool Equals(object obj) { if (obj == null) return false; if (obj.GetType() != typeof(SampleClass)) return false; var s = obj as SampleClass; return this.X == s.X; } } Tests: [TestMethod()] public void EqualsTest() { var sc = new SampleClass { X = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34,18],"tags":[41,69,102],"class_list":["post-248","post","type-post","status-publish","format-standard","hentry","category-microsoft","category-programming","tag-net","tag-linkedin","tag-unit-test"],"_links":{"self":[{"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/posts\/248","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/comments?post=248"}],"version-history":[{"count":0,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/posts\/248\/revisions"}],"wp:attachment":[{"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/media?parent=248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/categories?post=248"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/tags?post=248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}