Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 14413e7

Browse files
committed
Adding test to check if OnDeserialized doesn't throw if serialization… (#21357)
* Adding test to check if OnDeserialized doesn't throw if serialization fields aren't initialized yet. Relates to #21322 * Skipping for netfx as this only tests core impl * Update ObservableCollection_Serialization.cs
1 parent 4362253 commit 14413e7

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/System.ObjectModel/tests/ObservableCollection/ObservableCollection_Serialization.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System.Collections.Generic;
6+
using System.Reflection;
67
using System.Runtime.Serialization.Formatters.Tests;
78
using Xunit;
89

@@ -26,5 +27,17 @@ public void SerializeDeserialize_Roundtrips(ObservableCollection<int> c)
2627
Assert.NotSame(c, clone);
2728
Assert.Equal(c, clone);
2829
}
30+
31+
[Fact]
32+
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
33+
public void OnDeserialized_MonitorNotInitialized_ExpectSuccess()
34+
{
35+
var observableCollection = new ObservableCollection<int>();
36+
MethodInfo onDeserializedMethodInfo = observableCollection.GetType().GetMethod("OnDeserialized",
37+
BindingFlags.Instance | Reflection.BindingFlags.NonPublic);
38+
39+
Assert.NotNull(onDeserializedMethodInfo);
40+
onDeserializedMethodInfo.Invoke(observableCollection, new object[] { null });
41+
}
2942
}
3043
}

0 commit comments

Comments
 (0)