public void SerializeReferenceInConvert() { JsonSerializerSettings settings = new JsonSerializerSettings(); settings.PreserveReferencesHandling = PreserveReferencesHandling.All; settings.TypeNameHandling = TypeNameHandling.All; settings.Formatting = Formatting.Indented; Container c1 = new Container(); ContentA content = new ContentA(); content.B.SomeValue = true; c1.ListA.Add(content); c1.ListB.Add(content); string s = JsonConvert.SerializeObject(c1, settings); StringAssert.AreEqual(@"{ ""$id"": ""1"", ""$type"": ""Newtonsoft.Json.Tests.Serialization.PreserveReferencesHandlingTests+Container, Newtonsoft.Json.Tests"", ""ListA"": { ""$id"": ""2"", ""$type"": """ + ReflectionUtils.GetTypeName(typeof(List <ContentA>), 0, DefaultSerializationBinder.Instance) + @""", ""$values"": [ { ""$id"": ""3"", ""$type"": ""Newtonsoft.Json.Tests.Serialization.PreserveReferencesHandlingTests+ContentB, Newtonsoft.Json.Tests"", ""SomeValue"": true } ] }, ""ListB"": { ""$id"": ""4"", ""$type"": """ + ReflectionUtils.GetTypeName(typeof(List <ContentA>), 0, DefaultSerializationBinder.Instance) + @""", ""$values"": [ { ""$ref"": ""3"" } ] } }", s); Container c2 = JsonConvert.DeserializeObject <Container>(s, settings); Assert.AreEqual(c2.ListA[0], c2.ListB[0]); Assert.AreEqual(true, c2.ListA[0].B.SomeValue); }
public void TestMethod1() { var client = new Client(); // this does NOT work due to constraints var locationId = "location"; var container = new MyContainer { Location = locationId }; var content = new ContentA(); container.Add(content); client.DoSomething<MyContainer, ContentA>(container, content); Assert.AreEqual(locationId, content.Location); }
/// <summary> /// Testing the extension method D. /// </summary> /// <param name="obj">The extension target.</param> public static void MethodD(this ContentA obj) { }
public ContentAViewModel(ContentA model) { }