public void StructuralEqualSuccess() { // primitive "hoge".IsStructuralEqual("hoge"); (100).IsStructuralEqual(100); new[] { 1, 2, 3 }.IsStructuralEqual(new[] { 1, 2, 3 }); // complex new { Hoge = "aiueo", Huga = 100, Tako = new { k = 10 } }.IsStructuralEqual(new { Hoge = "aiueo", Huga = 100, Tako = new { k = 10 } }); new DummyStructural() { MyProperty = "aiueo" }.IsStructuralEqual(new DummyStructural() { MyProperty = "kakikukeko" }); new EmptyClass().IsStructuralEqual(new EmptyClass()); var s1 = new StructuralEqualTestClass { IntPro = 1, IntField = 10, StrField = "hoge", StrProp = "huga", IntArray = new[] { 1, 2, 3, 4, 5 }, StruStru = new Stru() { MyProperty = 1000, StrArray = new[] { "hoge", "huga", "tako" }, MP2 = new MMM() { MyProperty = 10000 } } }; var s2 = new StructuralEqualTestClass { IntPro = 1, IntField = 10, StrField = "hoge", StrProp = "huga", IntArray = new[] { 1, 2, 3, 4, 5 }, StruStru = new Stru() { MyProperty = 1000, StrArray = new[] { "hoge", "huga", "tako" }, MP2 = new MMM() { MyProperty = 10000 } } }; s1.IsStructuralEqual(s1); s1.IsStructuralEqual(s2); }
public void StructuralEqualFailed() { // type object n = null; Assert.Throws <ArgumentNullException>(() => n.IsStructuralEqual("a")); Assert.Throws <ArgumentNullException>(() => "a".IsStructuralEqual(n)); int i = 10; long l = 10; Assert.Throws <XunitException>(() => i.IsStructuralEqual(l)); // primitive Assert.Throws <XunitException>(() => "hoge".IsStructuralEqual("hage")) .Message.Contains("actual = hoge expected = hage").Is(true); Assert.Throws <XunitException>(() => (100).IsStructuralEqual(101)) .Message.Contains("actual = 100 expected = 101").Is(true); Assert.Throws <XunitException>(() => new[] { 1, 2, 3 }.IsStructuralEqual(new[] { 1, 2 })) .Message.Contains("actual = 3 expected = ").Is(true); Assert.Throws <XunitException>(() => new[] { 1, 2, 3 }.IsStructuralEqual(new[] { 1, 2, 4 })) .Message.Contains("actual = 3 expected = 4").Is(true); Assert.Throws <XunitException>(() => new[] { 1, 2, 3 }.IsStructuralEqual(new[] { 1, 2, 3, 4 })) .Message.Contains("actual = expected = 4").Is(true); Assert.Throws <XunitException>(() => new { Hoge = "aiueo", Huga = 100, Tako = new { k = 10 } }.IsStructuralEqual(new { Hoge = "aiueo", Huga = 100, Tako = new { k = 12 } })) .Message.Contains("actual = 10 expected = 12").Is(true); var s1 = new StructuralEqualTestClass { IntPro = 1, IntField = 10, StrField = "hoge", StrProp = "huga", IntArray = new[] { 1, 2, 3, 4, 5 }, StruStru = new Stru() { MyProperty = 1000, StrArray = new[] { "hoge", "huga", "tako" }, MP2 = new MMM() { MyProperty = 10000 } } }; var s2 = new StructuralEqualTestClass { IntPro = 1, IntField = 10, StrField = "hoge", StrProp = "huga", IntArray = new[] { 1, 2, 3, 4, 5, 6 }, StruStru = new Stru() { MyProperty = 1000, StrArray = new[] { "hoge", "huga", "tako" }, MP2 = new MMM() { MyProperty = 10000 } } }; var s3 = new StructuralEqualTestClass { IntPro = 1, IntField = 10, StrField = "hoge", StrProp = "huga", IntArray = new[] { 1, 2, 3, 4, 5 }, StruStru = new Stru() { MyProperty = 1000, StrArray = new[] { "hoge", "huga", "tako" }, MP2 = new MMM() { MyProperty = 13000 } } }; Assert.Throws <XunitException>(() => s1.IsStructuralEqual(s2)) .Message.Contains("StructuralEqualTestClass.IntArray.[5]").Is(true); Assert.Throws <XunitException>(() => s1.IsStructuralEqual(s3)) .Message.Contains("StructuralEqualTestClass.StruStru.MP2.MyProperty").Is(true); }