public static void ReadPrimitiveIList() { IList result = JsonSerializer.Deserialize <IList>(Encoding.UTF8.GetBytes(@"[1,2]")); int expected = 1; foreach (JsonElement i in result) { Assert.Equal(expected++, i.GetInt32()); } result = JsonSerializer.Deserialize <IList>(Encoding.UTF8.GetBytes(@"[]")); int count = 0; IEnumerator e = result.GetEnumerator(); while (e.MoveNext()) { count++; } Assert.Equal(0, count); WrapperForIList result2 = JsonSerializer.Deserialize <WrapperForIList>(@"[1,2]"); expected = 1; foreach (JsonElement i in result2) { Assert.Equal(expected++, i.GetInt32()); } }
public void Initialize() { MyIListWrapper = new WrapperForIList() { "Hello" }; MyIDictionaryWrapper = new WrapperForIDictionary() { { "key", "value" } }; MyHashtableWrapper = new HashtableWrapper(new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>("key", "value") }); MyArrayListWrapper = new ArrayListWrapper() { "Hello" }; MySortedListWrapper = new SortedListWrapper() { { "key", "value" } }; MyStackWrapper = new StackWrapper(); MyQueueWrapper = new QueueWrapper(); MyStackWrapper.Push("Hello"); MyQueueWrapper.Enqueue("Hello"); }
public async Task ReadPrimitiveIList() { IList result = await Serializer.DeserializeWrapper <IList>(@"[1,2]"); int expected = 1; foreach (JsonElement i in result) { Assert.Equal(expected++, i.GetInt32()); } result = await Serializer.DeserializeWrapper <IList>(@"[]"); int count = 0; IEnumerator e = result.GetEnumerator(); while (e.MoveNext()) { count++; } Assert.Equal(0, count); WrapperForIList result2 = await Serializer.DeserializeWrapper <WrapperForIList>(@"[1,2]"); expected = 1; foreach (JsonElement i in result2) { Assert.Equal(expected++, i.GetInt32()); } }
public async Task WriteIListOfIList() { IList input = new List <IList> { new List <int>() { 1, 2 }, new List <int>() { 3, 4 } }; string json = await Serializer.SerializeWrapper(input); Assert.Equal("[[1,2],[3,4]]", json); WrapperForIList input2 = new WrapperForIList { new List <object>() { 1, 2 }, new List <object>() { 3, 4 }, }; json = await Serializer.SerializeWrapper(input2); Assert.Equal("[[1,2],[3,4]]", json); }
public static void WriteIListOfIList() { IList input = new List <IList> { new List <int>() { 1, 2 }, new List <int>() { 3, 4 } }; string json = JsonSerializer.Serialize(input); Assert.Equal("[[1,2],[3,4]]", json); WrapperForIList input2 = new WrapperForIList { new List <object>() { 1, 2 }, new List <object>() { 3, 4 }, }; json = JsonSerializer.Serialize(input2); Assert.Equal("[[1,2],[3,4]]", json); }