@@ -1326,6 +1326,52 @@ public async Task SetAddAsync(bool initialize)
1326
1326
}
1327
1327
}
1328
1328
1329
+ [ Test ]
1330
+ public async Task SetAddWithOverrideEqualsAsync ( )
1331
+ {
1332
+ User gavin ;
1333
+ User robert ;
1334
+ User tom ;
1335
+
1336
+ using ( var s = OpenSession ( ) )
1337
+ using ( var t = s . BeginTransaction ( ) )
1338
+ {
1339
+ gavin = new User ( "gavin" , "secret" ) ;
1340
+ robert = new User ( "robert" , "secret" ) ;
1341
+ tom = new User ( "tom" , "secret" ) ;
1342
+ await ( s . PersistAsync ( gavin ) ) ;
1343
+ await ( s . PersistAsync ( robert ) ) ;
1344
+ await ( s . PersistAsync ( tom ) ) ;
1345
+
1346
+ gavin . Followers . Add ( new UserFollower ( gavin , robert ) ) ;
1347
+ gavin . Followers . Add ( new UserFollower ( gavin , tom ) ) ;
1348
+ robert . Followers . Add ( new UserFollower ( robert , tom ) ) ;
1349
+
1350
+ Assert . That ( gavin . Followers . Count , Is . EqualTo ( 2 ) , "Gavin's documents count after adding 2" ) ;
1351
+ Assert . That ( robert . Followers . Count , Is . EqualTo ( 1 ) , "Robert's followers count after adding one" ) ;
1352
+
1353
+ await ( t . CommitAsync ( ) ) ;
1354
+ }
1355
+
1356
+ using ( var s = OpenSession ( ) )
1357
+ using ( var t = s . BeginTransaction ( ) )
1358
+ {
1359
+ gavin = await ( s . GetAsync < User > ( "gavin" ) ) ;
1360
+ robert = await ( s . GetAsync < User > ( "robert" ) ) ;
1361
+ tom = await ( s . GetAsync < User > ( "tom" ) ) ;
1362
+
1363
+ // Re-add
1364
+ Assert . That ( gavin . Followers . Add ( new UserFollower ( gavin , robert ) ) , Is . False , "Re-adding element" ) ;
1365
+ Assert . That ( NHibernateUtil . IsInitialized ( gavin . Followers ) , Is . True , "Documents initialization status after re-adding" ) ;
1366
+ Assert . That ( gavin . Followers , Has . Count . EqualTo ( 2 ) , "Gavin's followers count after re-adding" ) ;
1367
+
1368
+ // Add new
1369
+ Assert . That ( robert . Followers . Add ( new UserFollower ( robert , gavin ) ) , Is . True , "Adding element" ) ;
1370
+ Assert . That ( NHibernateUtil . IsInitialized ( gavin . Followers ) , Is . True , "Documents initialization status after adding" ) ;
1371
+ Assert . That ( gavin . Followers , Has . Count . EqualTo ( 2 ) , "Robert's followers count after re-adding" ) ;
1372
+ }
1373
+ }
1374
+
1329
1375
[ TestCase ( false , false ) ]
1330
1376
[ TestCase ( false , true ) ]
1331
1377
[ TestCase ( true , false ) ]
0 commit comments