public static void ReadHashSetTOfHashSetT() { HashSet <HashSet <int> > result = JsonSerializer.Deserialize <HashSet <HashSet <int> > >(Encoding.UTF8.GetBytes(@"[[1,2],[3,4]]")); int expected = 1; foreach (HashSet <int> hs in result) { foreach (int i in hs) { Assert.Equal(expected++, i); } } GenericHashSetWrapper <StringHashSetWrapper> result2 = JsonSerializer.Deserialize <GenericHashSetWrapper <StringHashSetWrapper> >(@"[[""1"",""2""],[""3"",""4""]]"); expected = 1; foreach (StringHashSetWrapper hs in result2) { foreach (string str in hs) { Assert.Equal($"{expected++}", str); } } }
public async Task ReadHashSetTOfHashSetT() { HashSet <HashSet <int> > result = await Serializer.DeserializeWrapper <HashSet <HashSet <int> > >(@"[[1,2],[3,4]]"); int expected = 1; foreach (HashSet <int> hs in result) { foreach (int i in hs) { Assert.Equal(expected++, i); } } GenericHashSetWrapper <StringHashSetWrapper> result2 = await Serializer.DeserializeWrapper <GenericHashSetWrapper <StringHashSetWrapper> >(@"[[""1"",""2""],[""3"",""4""]]"); expected = 1; foreach (StringHashSetWrapper hs in result2) { foreach (string str in hs) { Assert.Equal($"{expected++}", str); } } }
public static void WriteHashSetTOfHashSetT() { HashSet <HashSet <int> > input = new HashSet <HashSet <int> >(new List <HashSet <int> > { new HashSet <int>(new List <int>() { 1, 2 }), new HashSet <int>(new List <int>() { 3, 4 }) }); string json = JsonSerializer.Serialize(input); // Because order isn't guaranteed, roundtrip data to ensure write was accurate. input = JsonSerializer.Deserialize <HashSet <HashSet <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()); } GenericHashSetWrapper <StringHashSetWrapper> input2 = new GenericHashSetWrapper <StringHashSetWrapper>(new List <StringHashSetWrapper> { new StringHashSetWrapper(new List <string>() { "1", "2" }), new StringHashSetWrapper(new List <string>() { "3", "4" }) }); json = JsonSerializer.Serialize(input2); // Because order isn't guaranteed, roundtrip data to ensure write was accurate. input2 = JsonSerializer.Deserialize <GenericHashSetWrapper <StringHashSetWrapper> >(json); if (input2.First().Contains("1")) { Assert.Equal(new StringHashSetWrapper(new List <string> { "1", "2" }), input2.First()); Assert.Equal(new StringHashSetWrapper(new List <string> { "3", "4" }), input2.Last()); } else { Assert.Equal(new StringHashSetWrapper(new List <string> { "3", "4" }), input2.First()); Assert.Equal(new StringHashSetWrapper(new List <string> { "1", "2" }), input2.Last()); } }