/// <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); }