public static void ReadGenericISetOfGenericISet() { ISet <ISet <int> > result = JsonSerializer.Deserialize <ISet <ISet <int> > >(Encoding.UTF8.GetBytes(@"[[1,2],[3,4]]")); if (result.First().Contains(1)) { Assert.Equal(new HashSet <int> { 1, 2 }, result.First()); Assert.Equal(new HashSet <int> { 3, 4 }, result.Last()); } else { Assert.Equal(new HashSet <int> { 3, 4 }, result.First()); Assert.Equal(new HashSet <int> { 1, 2 }, result.Last()); } GenericISetWrapper <StringISetWrapper> result2 = JsonSerializer.Deserialize <GenericISetWrapper <StringISetWrapper> >(@"[[""1"",""2""],[""3"",""4""]]"); if (result2.First().Contains("1")) { Assert.Equal(new HashSet <string> { "1", "2" }, (ISet <string>)result2.First()); Assert.Equal(new HashSet <string> { "3", "4" }, (ISet <string>)result2.Last()); } else { Assert.Equal(new HashSet <string> { "3", "4" }, (ISet <string>)result.First()); Assert.Equal(new HashSet <string> { "1", "2" }, (ISet <string>)result.Last()); } }
public async Task ReadGenericISetOfGenericISet() { ISet <ISet <int> > result = await Serializer.DeserializeWrapper <ISet <ISet <int> > >(@"[[1,2],[3,4]]"); if (result.First().Contains(1)) { Assert.Equal(new HashSet <int> { 1, 2 }, result.First()); Assert.Equal(new HashSet <int> { 3, 4 }, result.Last()); } else { Assert.Equal(new HashSet <int> { 3, 4 }, result.First()); Assert.Equal(new HashSet <int> { 1, 2 }, result.Last()); } GenericISetWrapper <StringISetWrapper> result2 = await Serializer.DeserializeWrapper <GenericISetWrapper <StringISetWrapper> >(@"[[""1"",""2""],[""3"",""4""]]"); if (result2.First().Contains("1")) { Assert.Equal(new HashSet <string> { "1", "2" }, (ISet <string>)result2.First()); Assert.Equal(new HashSet <string> { "3", "4" }, (ISet <string>)result2.Last()); } else { Assert.Equal(new HashSet <string> { "3", "4" }, (ISet <string>)result.First()); Assert.Equal(new HashSet <string> { "1", "2" }, (ISet <string>)result.Last()); } }
public static void WriteISetTOfISetT() { ISet <ISet <int> > input = new HashSet <ISet <int> > { new HashSet <int>() { 1, 2 }, new HashSet <int>() { 3, 4 } }; string json = JsonSerializer.Serialize(input); // Because order isn't guaranteed, roundtrip data to ensure write was accurate. input = JsonSerializer.Deserialize <ISet <ISet <int> > >(json); if (input.First().Contains(1)) { Assert.Equal(new HashSet <int> { 1, 2 }, input.First()); Assert.Equal(new HashSet <int> { 3, 4 }, input.Last()); } else { Assert.Equal(new HashSet <int> { 3, 4 }, input.First()); Assert.Equal(new HashSet <int> { 1, 2 }, input.Last()); } GenericISetWrapper <StringISetWrapper> input2 = new GenericISetWrapper <StringISetWrapper> { new StringISetWrapper() { "1", "2" }, new StringISetWrapper() { "3", "4" }, }; json = JsonSerializer.Serialize(input2); // Because order isn't guaranteed, roundtrip data to ensure write was accurate. input2 = JsonSerializer.Deserialize <GenericISetWrapper <StringISetWrapper> >(json); if (input2.First().Contains("1")) { Assert.Equal(new StringISetWrapper() { "1", "2" }, input2.First()); Assert.Equal(new StringISetWrapper() { "3", "4" }, input2.Last()); } else { Assert.Equal(new StringISetWrapper() { "3", "4" }, input2.First()); Assert.Equal(new StringISetWrapper() { "1", "2" }, input2.Last()); } }