11using System . Data ;
2- using System . Data . Common ;
32using NHibernate . Cfg ;
43using NHibernate . Dialect ;
54using NUnit . Framework ;
5+ using NUnit . Framework . Constraints ;
66
77namespace NHibernate . Test . NHSpecificTest . NH1553 . MsSQL
88{
@@ -64,18 +64,15 @@ public void UpdateConflictDetectedByNH()
6464 p2 . IdentificationNumber += 2 ;
6565
6666 SavePerson ( p1 ) ;
67- Assert . AreEqual ( person . Version + 1 , p1 . Version ) ;
68- try
69- {
70- SavePerson ( p2 ) ;
71- Assert . Fail ( "Expecting stale object state exception" ) ;
72- }
73- catch ( StaleObjectStateException sose )
74- {
75- Assert . AreEqual ( typeof ( Person ) . FullName , sose . EntityName ) ;
76- Assert . AreEqual ( p2 . Id , sose . Identifier ) ;
77- // as expected.
78- }
67+ Assert . That ( p1 . Version , Is . EqualTo ( person . Version + 1 ) ) ;
68+
69+ var expectedException = sessions . Settings . IsBatchVersionedDataEnabled
70+ ? ( IResolveConstraint ) Throws . InstanceOf < StaleStateException > ( )
71+ : Throws . InstanceOf < StaleObjectStateException > ( )
72+ . And . Property ( "EntityName" ) . EqualTo ( typeof ( Person ) . FullName )
73+ . And . Property ( "Identifier" ) . EqualTo ( p2 . Id ) ;
74+
75+ Assert . That ( ( ) => SavePerson ( p2 ) , expectedException ) ;
7976 }
8077
8178 /// <summary>
@@ -89,46 +86,43 @@ public void UpdateConflictDetectedBySQLServer()
8986
9087 p1 . IdentificationNumber ++ ;
9188
92- using ( ISession session1 = OpenSession ( ) )
89+ using ( var session1 = OpenSession ( ) )
90+ using ( var tr1 = BeginTransaction ( session1 ) )
9391 {
94- using ( ITransaction tr1 = BeginTransaction ( session1 ) )
92+ session1 . SaveOrUpdate ( p1 ) ;
93+ session1 . Flush ( ) ;
94+
95+ using ( var session2 = OpenSession ( ) )
96+ using ( var tr2 = BeginTransaction ( session2 ) )
9597 {
96- session1 . SaveOrUpdate ( p1 ) ;
97- session1 . Flush ( ) ;
98+ var p2 = session2 . Get < Person > ( person . Id ) ;
99+ p2 . IdentificationNumber += 2 ;
100+
101+ tr1 . Commit ( ) ;
102+ Assert . That ( p1 . Version , Is . EqualTo ( person . Version + 1 ) ) ;
103+
104+ session2 . SaveOrUpdate ( p2 ) ;
105+
106+ var expectedException = sessions . Settings . IsBatchVersionedDataEnabled
107+ ? ( IConstraint ) Throws . InstanceOf < StaleStateException > ( )
108+ : Throws . InstanceOf < StaleObjectStateException > ( )
109+ . And . Property ( "EntityName" ) . EqualTo ( typeof ( Person ) . FullName )
110+ . And . Property ( "Identifier" ) . EqualTo ( p2 . Id ) ;
98111
99- using ( ISession session2 = OpenSession ( ) )
100- {
101- using ( ITransaction tr2 = BeginTransaction ( session2 ) )
112+ Assert . That (
113+ ( ) =>
102114 {
103- var p2 = session2 . Get < Person > ( person . Id ) ;
104- p2 . IdentificationNumber += 2 ;
105-
106- tr1 . Commit ( ) ;
107- Assert . AreEqual ( person . Version + 1 , p1 . Version ) ;
108-
109- try
110- {
111- session2 . SaveOrUpdate ( p2 ) ;
112- session2 . Flush ( ) ;
113-
114- tr2 . Commit ( ) ;
115- Assert . Fail ( "StaleObjectStateException expected" ) ;
116- }
117- catch ( StaleObjectStateException sose )
118- {
119- Assert . AreEqual ( typeof ( Person ) . FullName , sose . EntityName ) ;
120- Assert . AreEqual ( p2 . Id , sose . Identifier ) ;
121- // as expected
122- }
123- }
124- }
115+ session2 . Flush ( ) ;
116+ tr2 . Commit ( ) ;
117+ } ,
118+ expectedException ) ;
125119 }
126120 }
127121 }
128122
129123 protected override bool AppliesTo ( Dialect . Dialect dialect )
130124 {
131- return dialect is MsSql2005Dialect || dialect is MsSql2008Dialect ;
125+ return dialect is MsSql2005Dialect ;
132126 }
133127
134128 private void SetAllowSnapshotIsolation ( bool on )
0 commit comments