public static void ValidStateTransitionTest_Entered_Exited(TransactionContextAffinity affinity) { using (var context = new TransactionContext(affinity)) { context.StateChanged += (sender, e) => { if (e.OldState == TransactionContextState.Entered) { Assert.AreEqual(TransactionContextState.ToBeRollbacked, context.State); Assert.AreEqual(TransactionContextState.ToBeRollbacked, e.NewState); } else { Assert.AreEqual(TransactionContextState.Exited, context.State); Assert.AreEqual(TransactionContextState.ToBeRollbacked, e.OldState); Assert.AreEqual(TransactionContextState.Exited, e.NewState); } }; context.Exit(); Assert.AreEqual(TransactionContextState.Exited, context.State); } }
public static void ValidValidStateTransitionTest_Exited_Exited(TransactionContextAffinity affinity) { using (var context = new TransactionContext(affinity)) { context.Exit(); Assert.AreEqual(TransactionContextState.Exited, context.State); context.StateChanged += (sender, e) => { if (e.NewState == TransactionContextState.Exited) Assert.Fail("Changed event should not be raised again"); }; context.Exit(); Assert.AreEqual(TransactionContextState.Exited, context.State); } }
public static void InvalidStateTransitionTest_Exited_ToBeRollbacked(TransactionContextAffinity affinity) { var ex = Assert.Throws<InvalidOperationException>( () => { using (var context = new TransactionContext(affinity)) { context.Exit(); Assert.AreEqual(TransactionContextState.Exited, context.State); context.VoteRollback(); } }); }
public static void ValidStateTransitionTest_ToBeRollbacked_Exited(TransactionContextAffinity affinity) { using (var context = new TransactionContext(affinity)) { context.VoteRollback(); Assert.AreEqual(TransactionContextState.ToBeRollbacked, context.State); context.Exit(); Assert.AreEqual(TransactionContextState.Exited, context.State); } }