Exit() public method

Exits the transaction context. Its commit or rollback status becomes final.
/// The requested transaction context state change is invalid. ///
public Exit ( ) : void
return void
コード例 #1
0
		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);
			}
		}
コード例 #2
0
		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);
			}
		}
コード例 #3
0
		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();
					}
				});
		}
コード例 #4
0
		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);
			}
		}