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());

            StringICollectionWrapper result2 = JsonSerializer.Deserialize <StringICollectionWrapper>(@"[""1"",""2""]");

            expected = 1;

            foreach (string str in result2)
            {
                Assert.Equal($"{expected++}", str);
            }

            result2 = JsonSerializer.Deserialize <StringICollectionWrapper>(Encoding.UTF8.GetBytes(@"[]"));
            Assert.Equal(0, result2.Count());
        }
Ejemplo n.º 2
0
 public void Initialize()
 {
     MyStringICollectionWrapper = new StringICollectionWrapper()
     {
         "Hello"
     };
     MyStringIListWrapper = new StringIListWrapper()
     {
         "Hello"
     };
     MyStringISetWrapper = new StringISetWrapper()
     {
         "Hello"
     };
     MyStringToStringIDictionaryWrapper = new StringToStringIDictionaryWrapper()
     {
         { "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" }
           } }
     };
 }