public static void Read_ObjectModelCollection() { Collection <bool> c = JsonSerializer.Deserialize <Collection <bool> >("[true,false]"); Assert.Equal(2, c.Count); Assert.True(c[0]); Assert.False(c[1]); // Regression test for https://github.com/dotnet/corefx/issues/40597. ObservableCollection <bool> oc = JsonSerializer.Deserialize <ObservableCollection <bool> >("[true,false]"); Assert.Equal(2, oc.Count); Assert.True(oc[0]); Assert.False(oc[1]); SimpleKeyedCollection kc = JsonSerializer.Deserialize <SimpleKeyedCollection>("[true]"); Assert.Equal(1, kc.Count); Assert.True(kc[0]); }
public async Task Read_ObjectModelCollection() { Collection <bool> c = await JsonSerializerWrapperForString.DeserializeWrapper <Collection <bool> >("[true,false]"); Assert.Equal(2, c.Count); Assert.True(c[0]); Assert.False(c[1]); // Regression test for https://github.com/dotnet/runtime/issues/30686. ObservableCollection <bool> oc = await JsonSerializerWrapperForString.DeserializeWrapper <ObservableCollection <bool> >("[true,false]"); Assert.Equal(2, oc.Count); Assert.True(oc[0]); Assert.False(oc[1]); SimpleKeyedCollection kc = await JsonSerializerWrapperForString.DeserializeWrapper <SimpleKeyedCollection>("[true]"); Assert.Equal(1, kc.Count); Assert.True(kc[0]); }
public static void Write_ObjectModelCollection() { Collection <bool> c = new Collection <bool>() { true, false }; Assert.Equal("[true,false]", JsonSerializer.Serialize(c)); ObservableCollection <bool> oc = new ObservableCollection <bool>() { true, false }; Assert.Equal("[true,false]", JsonSerializer.Serialize(oc)); SimpleKeyedCollection kc = new SimpleKeyedCollection() { true, false }; Assert.Equal("[true,false]", JsonSerializer.Serialize(kc)); Assert.Equal("[true,false]", JsonSerializer.Serialize <KeyedCollection <string, bool> >(kc)); ReadOnlyCollection <bool> roc = new ReadOnlyCollection <bool>(new List <bool> { true, false }); Assert.Equal("[true,false]", JsonSerializer.Serialize(roc)); ReadOnlyObservableCollection <bool> rooc = new ReadOnlyObservableCollection <bool>(oc); Assert.Equal("[true,false]", JsonSerializer.Serialize(rooc)); ReadOnlyDictionary <string, bool> rod = new ReadOnlyDictionary <string, bool>(new Dictionary <string, bool> { ["true"] = false }); Assert.Equal(@"{""true"":false}", JsonSerializer.Serialize(rod)); }
public async Task Write_ObjectModelCollection() { Collection <bool> c = new Collection <bool>() { true, false }; Assert.Equal("[true,false]", await Serializer.SerializeWrapper(c)); ObservableCollection <bool> oc = new ObservableCollection <bool>() { true, false }; Assert.Equal("[true,false]", await Serializer.SerializeWrapper(oc)); SimpleKeyedCollection kc = new SimpleKeyedCollection() { true, false }; Assert.Equal("[true,false]", await Serializer.SerializeWrapper(kc)); Assert.Equal("[true,false]", await Serializer.SerializeWrapper <KeyedCollection <string, bool> >(kc)); ReadOnlyCollection <bool> roc = new ReadOnlyCollection <bool>(new List <bool> { true, false }); Assert.Equal("[true,false]", await Serializer.SerializeWrapper(roc)); ReadOnlyObservableCollection <bool> rooc = new ReadOnlyObservableCollection <bool>(oc); Assert.Equal("[true,false]", await Serializer.SerializeWrapper(rooc)); ReadOnlyDictionary <string, bool> rod = new ReadOnlyDictionary <string, bool>(new Dictionary <string, bool> { ["true"] = false }); Assert.Equal(@"{""true"":false}", await Serializer.SerializeWrapper(rod)); }