@@ -77,6 +77,53 @@ public void ResultsShouldSendNotifications()
7777 }
7878 }
7979
80+ [ Test ]
81+ public void Results_WhenEmbeddedObjectIsModified_Notifies ( )
82+ {
83+ var query = _realm . All < TestNotificationObject > ( ) ;
84+ var actualChanges = new List < ChangeSet ? > ( ) ;
85+ void OnNotification ( IRealmCollection < TestNotificationObject > collection , ChangeSet ? changes ) => actualChanges . Add ( changes ) ;
86+
87+ Assert . That ( query . Count , Is . EqualTo ( 0 ) ) ;
88+
89+ using ( query . SubscribeForNotifications ( OnNotification ) )
90+ {
91+ _realm . Refresh ( ) ;
92+
93+ // Notification from subscribing.
94+ Assert . That ( actualChanges . Count , Is . EqualTo ( 1 ) ) ;
95+
96+ var testObject = _realm . Write ( ( ) => _realm . Add ( new TestNotificationObject ( ) ) ) ;
97+
98+ _realm . Refresh ( ) ;
99+ Assert . That ( actualChanges . Count , Is . EqualTo ( 2 ) ) ;
100+ Assert . That ( actualChanges [ 1 ] , Is . Not . Null ) ;
101+ Assert . That ( actualChanges [ 1 ] ! . InsertedIndices , Is . EquivalentTo ( new [ ] { 0 } ) ) ;
102+
103+ _realm . Write ( ( ) =>
104+ {
105+ testObject . EmbeddedObject = new EmbeddedIntPropertyObject { Int = 1 } ;
106+ } ) ;
107+
108+ _realm . Refresh ( ) ;
109+ Assert . That ( actualChanges . Count , Is . EqualTo ( 3 ) ) ;
110+ Assert . That ( actualChanges [ 2 ] , Is . Not . Null ) ;
111+ Assert . That ( actualChanges [ 2 ] ! . NewModifiedIndices , Is . EquivalentTo ( new [ ] { 0 } ) ) ;
112+ Assert . That ( actualChanges [ 2 ] ! . ModifiedIndices , Is . EquivalentTo ( new [ ] { 0 } ) ) ;
113+
114+ _realm . Write ( ( ) =>
115+ {
116+ testObject . EmbeddedObject ! . Int ++ ;
117+ } ) ;
118+
119+ _realm . Refresh ( ) ;
120+ Assert . That ( actualChanges . Count , Is . EqualTo ( 4 ) ) ;
121+ Assert . That ( actualChanges [ 3 ] , Is . Not . Null ) ;
122+ Assert . That ( actualChanges [ 3 ] ! . NewModifiedIndices , Is . EquivalentTo ( new [ ] { 0 } ) ) ;
123+ Assert . That ( actualChanges [ 3 ] ! . ModifiedIndices , Is . EquivalentTo ( new [ ] { 0 } ) ) ;
124+ }
125+ }
126+
80127 [ Test ]
81128 public void ListShouldSendNotifications ( )
82129 {
0 commit comments