public void NotEqualNestedOneLevel3() { var l1 = new Level { Value = 1, Next = new Level { Value = 2 } }; var l2 = new Level { Value = 1, Next = new Level { Value = 3 } }; var ex1 = Assert.Throws <AssertException>(() => FieldAssert.Equal(l1, l2)); var em1 = " Found this difference between expected and actual:\r\n" + " expected.next.value: 2\r\n" + " actual.next.value: 3"; Assert.AreEqual(em1, ex1.Message); var ex2 = Assert.Throws <AssertException>(() => FieldAssert.Equal(l2, l1)); var em2 = " Found this difference between expected and actual:\r\n" + " expected.next.value: 3\r\n" + " actual.next.value: 2"; Assert.AreEqual(em2, ex2.Message); }
public void NotEqualIEnumerablesOfDummiesTwoDiffs() { var l1 = new[] { new Dummy { Value = 1 }, new Dummy { Value = 2 } }; var l2 = new[] { new Dummy { Value = 2 }, new Dummy { Value = 5 } }; var ex1 = Assert.Throws <AssertException>(() => FieldAssert.Equal(l1, l2)); var em1 = " Fields differ between expected and actual, here are the 2 differences:\r\n" + " expected[0].value: 1\r\n" + " actual[0].value: 2\r\n" + "\r\n" + " expected[1].value: 2\r\n" + " actual[1].value: 5"; Assert.AreEqual(em1, ex1.Message); var ex2 = Assert.Throws <AssertException>(() => FieldAssert.Equal(l2, l1)); var em2 = " Fields differ between expected and actual, here are the 2 differences:\r\n" + " expected[0].value: 2\r\n" + " actual[0].value: 1\r\n" + "\r\n" + " expected[1].value: 5\r\n" + " actual[1].value: 2"; Assert.AreEqual(em2, ex2.Message); }
public void RoundtripHappyPath() { var dummy = new SerializableDummy(); var roundtrip = BinaryFormatterAssert.Roundtrip(dummy); FieldAssert.Equal(dummy, roundtrip); }
public void EqualIEnumerablesOfInts() { var l1 = new[] { 1, 2 }; var l2 = new[] { 1, 2 }; FieldAssert.Equal(l1, l1); FieldAssert.Equal(l2, l1); FieldAssert.Equal(l1, l2); }
public void HappyPath() { var actual = new Dummy { Value = 2 }; var roundtrip = XmlSerializerAssert.Roundtrip(actual); Assert.AreEqual(roundtrip.Value, actual.Value); FieldAssert.Equal(actual, roundtrip); }
public void EqualXmlAttributeClass() { var actual = new XmlAttributeClass { Value = 2 }; var expectedXml = "<XmlAttributeClass Value=\"2\" />"; var roundtrip = DataContractSerializerAssert.Equal(expectedXml, actual, XmlAssertOptions.IgnoreNamespaces | XmlAssertOptions.IgnoreDeclaration); Assert.AreEqual(roundtrip.Value, actual.Value); FieldAssert.Equal(actual, roundtrip); }
public void EqualParentChildren() { var p1 = new Parent { new Child(1), new Child(2) }; var p2 = new Parent { new Child(1), new Child(2) }; FieldAssert.Equal(p1, p1); FieldAssert.Equal(p2, p1); FieldAssert.Equal(p1, p2); }
public void EqualNoDeclarationOrNamespaces() { var actual = new DataContractDummy { Value = 2 }; var expectedXml = "<DataContractDummy>\r\n" + " <Value>2</Value>\r\n" + "</DataContractDummy>"; var roundtrip = DataContractSerializerAssert.Equal(expectedXml, actual, XmlAssertOptions.IgnoreDeclaration | XmlAssertOptions.IgnoreNamespaces); Assert.AreEqual(roundtrip.Value, actual.Value); FieldAssert.Equal(actual, roundtrip); }
public void EqualDummies() { var d1 = new Dummy { Value = 1 }; var d2 = new Dummy { Value = 1 }; FieldAssert.Equal(d1, d1); FieldAssert.Equal(d2, d1); FieldAssert.Equal(d1, d2); }
public void EqualNestedOneLevel1() { var l1 = new Level { Value = 2 }; var l2 = new Level { Value = 2 }; FieldAssert.Equal(l1, l1); FieldAssert.Equal(l2, l1); FieldAssert.Equal(l1, l2); }
public void Equal() { var actual = new DataContractDummy { Value = 2 }; var expectedXml = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" + "<DataContractDummy xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.datacontract.org/2004/07/Gu.SerializationAsserts.Tests.Dtos\">\r\n" + " <Value>2</Value>\r\n" + "</DataContractDummy>"; var roundtrip = DataContractSerializerAssert.Equal(expectedXml, actual); Assert.AreEqual(roundtrip.Value, actual.Value); FieldAssert.Equal(actual, roundtrip); }
public void EqualWithAttributeAndDeclaration() { var actual = new Dummy { Value = 2 }; var expectedXml = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" + "<Dummy xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n" + " <Value>2</Value>\r\n" + "</Dummy>"; var roundtrip = XmlSerializerAssert.Equal(expectedXml, actual); Assert.AreEqual(roundtrip.Value, actual.Value); FieldAssert.Equal(actual, roundtrip); }
/// <summary> /// 1. Places <paramref name="item"/> in a ContainerClass{T} container1 /// 2. Serializes container1 /// 3. Deserializes the containerJson to container2 and does FieldAssert.Equal(container1, container2); /// 4. Serializes container2 /// 5. Checks JsonAssert.Equal(containerJson1, containerJson2, JsonAssertOptions.Verbatim); /// </summary> /// <typeparam name="T">The type of <paramref name="item"/></typeparam> /// <param name="item">The instance to roundtrip</param> /// <returns>The serialized and deserialized instance (container2.Other)</returns> public static T Roundtrip <T>(T item) { Roundtripper.Simple(item, nameof(item), ToJson, FromJson <T>); var roundtripped = Roundtripper.InContainer( item, nameof(item), ToJson, FromJson <ContainerClass <T> >, (e, a) => JsonAssert.Equal(e, a, JsonAssertOptions.Verbatim)); FieldAssert.Equal(item, roundtripped); return(roundtripped); }
/// <summary> /// 1. Places <paramref name="item"/> in a ContainerClass{T} container1 /// 2. Serializes container1 /// 3. Deserializes the containerJson to container2 and does FieldAssert.Equal(container1, container2); /// 4. Serializes container2 /// 5. Checks JsonAssert.Equal(containerJson1, containerJson2, JsonAssertOptions.Verbatim); /// </summary> /// <typeparam name="T">The type of <paramref name="item"/></typeparam> /// <param name="item">The instance to roundtrip</param> /// <param name="settings">The settings to use when serializing and deserializing.</param> /// <returns>The serialized and deserialized instance (container2.Other)</returns> public static T Roundtrip <T>(T item, JsonSerializerSettings settings) { Roundtripper.Simple(item, nameof(item), x => ToJson(x, settings), x => FromJson <T>(x, settings)); var roundtripped = Roundtripper.InContainer( item, nameof(item), x => ToJson(x, settings), x => FromJson <ContainerClass <T> >(x, settings), (e, a) => JsonAssert.Equal(e, a, JsonAssertOptions.Verbatim)); FieldAssert.Equal(item, roundtripped); return(roundtripped); }
public void EqualIEnumerablesOfDummies() { var l1 = new[] { new Dummy { Value = 1 }, new Dummy { Value = 2 } }; var l2 = new[] { new Dummy { Value = 1 }, new Dummy { Value = 2 } }; FieldAssert.Equal(l1, l1); FieldAssert.Equal(l2, l1); FieldAssert.Equal(l1, l2); }
public void NotEqualIEnumerablesOfIntsLength() { var l1 = new[] { 1, 2 }; var l2 = new[] { 1, 2, 3 }; var ex1 = Assert.Throws <AssertException>(() => FieldAssert.Equal(l1, l2)); var em1 = " Found this difference between expected and actual:\r\n" + " expected.Count: 2\r\n" + " actual.Count: 3"; Assert.AreEqual(em1, ex1.Message); var ex2 = Assert.Throws <AssertException>(() => FieldAssert.Equal(l2, l1)); var em2 = " Found this difference between expected and actual:\r\n" + " expected.Count: 3\r\n" + " actual.Count: 2"; Assert.AreEqual(em2, ex2.Message); }
public void NotEqualParentChildren() { var p1 = new Parent { new Child(1), new Child(2) }; var p2 = new Parent { new Child(1), new Child(5) }; var ex1 = Assert.Throws <AssertException>(() => FieldAssert.Equal(p1, p2)); var em1 = " Found this difference between expected and actual:\r\n" + " expected[1].value: 2\r\n" + " actual[1].value: 5"; Assert.AreEqual(em1, ex1.Message); var ex2 = Assert.Throws <AssertException>(() => FieldAssert.Equal(p2, p1)); var em2 = " Found this difference between expected and actual:\r\n" + " expected[1].value: 5\r\n" + " actual[1].value: 2"; Assert.AreEqual(em2, ex2.Message); }
public void NotEqualNestedOneLevel2() { var l1 = new Level { Value = 2, Next = null }; var l2 = new Level { Value = 2, Next = new Level() }; var ex1 = Assert.Throws <AssertException>(() => FieldAssert.Equal(l1, l2)); var em1 = " Found this difference between expected and actual:\r\n" + " expected.next: null\r\n" + " actual.next: Gu.SerializationAsserts.Tests.Dtos.Level"; Assert.AreEqual(em1, ex1.Message); var ex2 = Assert.Throws <AssertException>(() => FieldAssert.Equal(l2, l1)); var em2 = " Found this difference between expected and actual:\r\n" + " expected.next: Gu.SerializationAsserts.Tests.Dtos.Level\r\n" + " actual.next: null"; Assert.AreEqual(em2, ex2.Message); }
public void NotEqualDummies() { var d1 = new Dummy { Value = 1 }; var d2 = new Dummy { Value = 2 }; var ex1 = Assert.Throws <AssertException>(() => FieldAssert.Equal(d1, d2)); var em1 = " Found this difference between expected and actual:\r\n" + " expected.value: 1\r\n" + " actual.value: 2"; Assert.AreEqual(em1, ex1.Message); var ex2 = Assert.Throws <AssertException>(() => FieldAssert.Equal(d2, d1)); var em2 = " Found this difference between expected and actual:\r\n" + " expected.value: 2\r\n" + " actual.value: 1"; Assert.AreEqual(em2, ex2.Message); }