public static void ReadGenericIListOfIList() { IList <IList> result = JsonSerializer.Deserialize <IList <IList> >(Encoding.UTF8.GetBytes(@"[[1,2],[3,4]]")); int expected = 1; foreach (IList list in result) { foreach (JsonElement i in list) { Assert.Equal(expected++, i.GetInt32()); } } GenericIListWrapper <WrapperForIList> result2 = JsonSerializer.Deserialize <GenericIListWrapper <WrapperForIList> >(@"[[1,2],[3,4]]"); expected = 1; foreach (WrapperForIList list in result2) { foreach (JsonElement i in list) { Assert.Equal(expected++, i.GetInt32()); } } }
public static void ReadGenericIListOfArray() { IList <int[]> result = JsonSerializer.Deserialize <IList <int[]> >(Encoding.UTF8.GetBytes(@"[[1,2],[3,4]]")); int expected = 1; foreach (int[] arr in result) { foreach (int i in arr) { Assert.Equal(expected++, i); } } GenericIListWrapper <string[]> result2 = JsonSerializer.Deserialize <GenericIListWrapper <string[]> >(@"[[""1"",""2""],[""3"",""4""]]"); expected = 1; foreach (string[] arr in result2) { foreach (string str in arr) { Assert.Equal($"{expected++}", str); } } }
public static void WriteGenericIListOfGenericIList() { IList <IList <int> > input = new List <IList <int> > { new List <int>() { 1, 2 }, new List <int>() { 3, 4 } }; string json = JsonSerializer.Serialize(input); Assert.Equal("[[1,2],[3,4]]", json); GenericIListWrapper <StringIListWrapper> input2 = new GenericIListWrapper <StringIListWrapper> { new StringIListWrapper() { "1", "2" }, new StringIListWrapper() { "3", "4" } }; json = JsonSerializer.Serialize(input2); Assert.Equal(@"[[""1"",""2""],[""3"",""4""]]", json); }
public static void ReadIListTOfIListT() { IList <IList <int> > result = JsonSerializer.Deserialize <IList <IList <int> > >(Encoding.UTF8.GetBytes(@"[[1,2],[3,4]]")); int expected = 1; foreach (IList <int> ie in result) { foreach (int i in ie) { Assert.Equal(expected++, i); } } GenericIListWrapper <StringIListWrapper> result2 = JsonSerializer.Deserialize <GenericIListWrapper <StringIListWrapper> >(@"[[""1"",""2""],[""3"",""4""]]"); expected = 1; foreach (StringIListWrapper il in result2) { foreach (string str in il) { Assert.Equal($"{expected++}", str); } } }
public async Task ReadGenericIListOfIList() { IList <IList> result = await Serializer.DeserializeWrapper <IList <IList> >(@"[[1,2],[3,4]]"); int expected = 1; foreach (IList list in result) { foreach (JsonElement i in list) { Assert.Equal(expected++, i.GetInt32()); } } GenericIListWrapper <WrapperForIList> result2 = await Serializer.DeserializeWrapper <GenericIListWrapper <WrapperForIList> >(@"[[1,2],[3,4]]"); expected = 1; foreach (WrapperForIList list in result2) { foreach (JsonElement i in list) { Assert.Equal(expected++, i.GetInt32()); } } }
public async Task ReadGenericIListOfArray() { IList <int[]> result = await Serializer.DeserializeWrapper <IList <int[]> >(@"[[1,2],[3,4]]"); int expected = 1; foreach (int[] arr in result) { foreach (int i in arr) { Assert.Equal(expected++, i); } } GenericIListWrapper <string[]> result2 = await Serializer.DeserializeWrapper <GenericIListWrapper <string[]> >(@"[[""1"",""2""],[""3"",""4""]]"); expected = 1; foreach (string[] arr in result2) { foreach (string str in arr) { Assert.Equal($"{expected++}", str); } } }
public async Task ReadIListTOfIListT() { IList <IList <int> > result = await Serializer.DeserializeWrapper <IList <IList <int> > >(@"[[1,2],[3,4]]"); int expected = 1; foreach (IList <int> ie in result) { foreach (int i in ie) { Assert.Equal(expected++, i); } } GenericIListWrapper <StringIListWrapper> result2 = await Serializer.DeserializeWrapper <GenericIListWrapper <StringIListWrapper> >(@"[[""1"",""2""],[""3"",""4""]]"); expected = 1; foreach (StringIListWrapper il in result2) { foreach (string str in il) { Assert.Equal($"{expected++}", str); } } }
public async Task WriteGenericIListOfGenericIList() { IList <IList <int> > input = new List <IList <int> > { new List <int>() { 1, 2 }, new List <int>() { 3, 4 } }; string json = await JsonSerializerWrapperForString.SerializeWrapper(input); Assert.Equal("[[1,2],[3,4]]", json); GenericIListWrapper <StringIListWrapper> input2 = new GenericIListWrapper <StringIListWrapper> { new StringIListWrapper() { "1", "2" }, new StringIListWrapper() { "3", "4" } }; json = await JsonSerializerWrapperForString.SerializeWrapper(input2); Assert.Equal(@"[[""1"",""2""],[""3"",""4""]]", json); }