public static void ReadGenericICollectionOfGenericICollection() { ICollection <ICollection <int> > result = JsonSerializer.Deserialize <ICollection <ICollection <int> > >(Encoding.UTF8.GetBytes(@"[[1,2],[3,4]]")); int expected = 1; foreach (ICollection <int> ie in result) { foreach (int i in ie) { Assert.Equal(expected++, i); } } GenericICollectionWrapper <StringICollectionWrapper> result2 = JsonSerializer.Deserialize <GenericICollectionWrapper <StringICollectionWrapper> >(@"[[""1"",""2""],[""3"",""4""]]"); expected = 1; foreach (StringICollectionWrapper ic in result2) { foreach (string str in ic) { Assert.Equal($"{expected++}", str); } } }
public static void WriteGenericICollectionOfGenericICollection() { ICollection <ICollection <int> > input = new List <ICollection <int> > { new List <int>() { 1, 2 }, new List <int>() { 3, 4 } }; string json = JsonSerializer.Serialize(input); Assert.Equal("[[1,2],[3,4]]", json); GenericICollectionWrapper <GenericICollectionWrapper <string> > input2 = new GenericICollectionWrapper <GenericICollectionWrapper <string> > { new GenericICollectionWrapper <string>() { "1", "2" }, new GenericICollectionWrapper <string>() { "3", "4" } }; json = JsonSerializer.Serialize(input2); Assert.Equal(@"[[""1"",""2""],[""3"",""4""]]", json); }
public static void ReadGenericICollectionOfArray() { ICollection <int[]> result = JsonSerializer.Deserialize <ICollection <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); } } GenericICollectionWrapper <string[]> result2 = JsonSerializer.Deserialize <GenericICollectionWrapper <string[]> >(@"[[""1"",""2""],[""3"",""4""]]"); expected = 1; foreach (string[] arr in result2) { foreach (string str in arr) { Assert.Equal($"{expected++}", str); } } }
public async Task WriteGenericICollectionOfICollection() { ICollection <ICollection> input = new List <ICollection> { new List <int>() { 1, 2 }, new List <int>() { 3, 4 } }; string json = await Serializer.SerializeWrapper(input); Assert.Equal("[[1,2],[3,4]]", json); GenericICollectionWrapper <WrapperForICollection> input2 = new GenericICollectionWrapper <WrapperForICollection> { new WrapperForICollection(new List <object> { 1, 2 }), new WrapperForICollection(new List <object> { 3, 4 }), }; json = await Serializer.SerializeWrapper(input2); Assert.Equal("[[1,2],[3,4]]", json); }
public static void ReadSimpleGenericICollection() { ICollection <int> result = JsonSerializer.Deserialize <ICollection <int> >(Encoding.UTF8.GetBytes(@"[1,2]")); int expected = 1; foreach (int i in result) { Assert.Equal(expected++, i); } result = JsonSerializer.Deserialize <ICollection <int> >(Encoding.UTF8.GetBytes(@"[]")); Assert.Equal(0, result.Count()); GenericICollectionWrapper <string> result2 = JsonSerializer.Deserialize <GenericICollectionWrapper <string> >(@"[""1"",""2""]"); expected = 1; foreach (string str in result2) { Assert.Equal($"{expected++}", str); } result2 = JsonSerializer.Deserialize <GenericICollectionWrapper <string> >(Encoding.UTF8.GetBytes(@"[]")); Assert.Equal(0, result2.Count()); }
public async Task ReadSimpleGenericICollection() { ICollection <int> result = await Serializer.DeserializeWrapper <ICollection <int> >(@"[1,2]"); int expected = 1; foreach (int i in result) { Assert.Equal(expected++, i); } result = await Serializer.DeserializeWrapper <ICollection <int> >(@"[]"); Assert.Equal(0, result.Count()); GenericICollectionWrapper <string> result2 = await Serializer.DeserializeWrapper <GenericICollectionWrapper <string> >(@"[""1"",""2""]"); expected = 1; foreach (string str in result2) { Assert.Equal($"{expected++}", str); } result2 = await Serializer.DeserializeWrapper <GenericICollectionWrapper <string> >(@"[]"); Assert.Equal(0, result2.Count()); }
public async Task ReadGenericICollectionOfArray() { ICollection <int[]> result = await Serializer.DeserializeWrapper <ICollection <int[]> >(@"[[1,2],[3,4]]"); int expected = 1; foreach (int[] arr in result) { foreach (int i in arr) { Assert.Equal(expected++, i); } } GenericICollectionWrapper <string[]> result2 = await Serializer.DeserializeWrapper <GenericICollectionWrapper <string[]> >(@"[[""1"",""2""],[""3"",""4""]]"); expected = 1; foreach (string[] arr in result2) { foreach (string str in arr) { Assert.Equal($"{expected++}", str); } } }
public async Task WriteGenericICollectionOfGenericICollection() { ICollection <ICollection <int> > input = new List <ICollection <int> > { new List <int>() { 1, 2 }, new List <int>() { 3, 4 } }; string json = await JsonSerializerWrapperForString.SerializeWrapper(input); Assert.Equal("[[1,2],[3,4]]", json); GenericICollectionWrapper <GenericICollectionWrapper <string> > input2 = new GenericICollectionWrapper <GenericICollectionWrapper <string> > { new GenericICollectionWrapper <string>() { "1", "2" }, new GenericICollectionWrapper <string>() { "3", "4" } }; json = await JsonSerializerWrapperForString.SerializeWrapper(input2); Assert.Equal(@"[[""1"",""2""],[""3"",""4""]]", json); }
public void Initialize() { MyStringICollectionWrapper = new GenericICollectionWrapper <string>() { "Hello" }; MyStringIListWrapper = new StringIListWrapper() { "Hello" }; MyStringISetWrapper = new StringISetWrapper() { "Hello" }; MyStringToStringIDictionaryWrapper = new GenericIDictionaryWrapper <string, string>() { { "key", "value" } }; MyStringListWrapper = new StringListWrapper() { "Hello" }; MyStringStackWrapper = new StringStackWrapper(new List <string> { "Hello" }); MyStringQueueWrapper = new StringQueueWrapper(new List <string> { "Hello" }); MyStringHashSetWrapper = new StringHashSetWrapper() { "Hello" }; MyStringLinkedListWrapper = new StringLinkedListWrapper(new List <string> { "Hello" }); MyStringSortedSetWrapper = new StringSortedSetWrapper() { "Hello" }; MyStringToStringDictionaryWrapper = new StringToStringDictionaryWrapper() { { "key", "value" } }; MyStringToStringSortedDictionaryWrapper = new StringToStringSortedDictionaryWrapper() { { "key", "value" } }; MyStringToGenericDictionaryWrapper = new StringToGenericDictionaryWrapper <StringToGenericDictionaryWrapper <string> >() { { "key", new StringToGenericDictionaryWrapper <string>() { { "key", "value" } } } }; }