public static void ValidStateTransitionTest_Created_Entered(TransactionContextAffinity affinity)
		{
			using (var context = new TransactionContext(affinity))
			{
				Assert.AreEqual(TransactionContextState.Entered, context.State);
			}
		}
Beispiel #2
0
 public static void ValidStateTransitionTest_Created_Entered(TransactionContextAffinity affinity)
 {
     using (var context = new TransactionContext(affinity))
     {
         Assert.AreEqual(TransactionContextState.Entered, context.State);
     }
 }
Beispiel #3
0
 public static void ValidStateTransitionTest_Entered_ToBeCommitted(TransactionContextAffinity affinity)
 {
     using (var context = new TransactionContext(affinity))
     {
         context.VoteCommit();
         Assert.AreEqual(TransactionContextState.ToBeCommitted, context.State);
     }
 }
		public static void ValidStateTransitionTest_Entered_ToBeCommitted(TransactionContextAffinity affinity)
		{
			using (var context = new TransactionContext(affinity))
			{
				context.VoteCommit();
				Assert.AreEqual(TransactionContextState.ToBeCommitted, context.State);
			}
		}
		public void CreateTransactionContextTest(TransactionContextAffinity affinity)
		{
			using (var context = new TransactionContext(affinity))
			{
				Assert.AreEqual(affinity, context.Affinity);
				Assert.AreEqual(TransactionContextState.Entered, context.State);
				Assert.AreEqual(IsolationLevel.ReadCommitted, context.IsolationLevel);
			}
		}
Beispiel #6
0
 public void CreateTransactionContextTest(TransactionContextAffinity affinity)
 {
     using (var context = new TransactionContext(affinity))
     {
         Assert.AreEqual(affinity, context.Affinity);
         Assert.AreEqual(TransactionContextState.Entered, context.State);
         Assert.AreEqual(IsolationLevel.ReadCommitted, context.IsolationLevel);
     }
 }
Beispiel #7
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);
            }
        }
Beispiel #8
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();
                }
            });
        }
Beispiel #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TransactionContext"/> class.
        /// </summary>
        /// <param name="affinity">The transaction context affinity.</param>
        public TransactionContext(TransactionContextAffinity affinity)
        {
#if DEBUG
            _allocStackTrace = new StackTrace();
#endif

            TransactionManager.EnsureInitialize();

            this.Affinity          = affinity;
            this.State             = TransactionContextState.Created;
            this.StateFromChildren = TransactionContextState.ToBeCommitted;
            this.IsolationLevel    = IsolationLevel.ReadCommitted;

            Created?.Invoke(this, new TransactionContextCreatedEventArgs(this));

            this.Enter();
        }
Beispiel #10
0
		/// <summary>
		/// Initializes a new instance of the <see cref="TransactionContext"/> class.
		/// </summary>
		/// <param name="affinity">The transaction context affinity.</param>
		public TransactionContext(TransactionContextAffinity affinity)
		{
#if DEBUG
			_allocStackTrace = new StackTrace();
#endif

			TransactionManager.EnsureInitialize();

			this.Affinity = affinity;
			this.State = TransactionContextState.Created;
			this.StateFromChildren = TransactionContextState.ToBeCommitted;
			this.IsolationLevel = IsolationLevel.ReadCommitted;

			Created?.Invoke(this, new TransactionContextCreatedEventArgs(this));

			this.Enter();
		}
		public static void ValidStateTransitionTest_ToBeCommitted_ToBeCommitted(TransactionContextAffinity affinity)
		{
			using (var context = new TransactionContext(affinity))
			{
				context.VoteCommit();
				Assert.AreEqual(TransactionContextState.ToBeCommitted, context.State);

				context.StateChanged +=
					(sender, e) =>
					{
						if (e.NewState == TransactionContextState.ToBeCommitted)
							Assert.Fail("Changed event should not be raised again");
					};

				context.VoteCommit();
				Assert.AreEqual(TransactionContextState.ToBeCommitted, context.State);
			}
		}
Beispiel #12
0
        public static void ValidStateTransitionTest_ToBeRollbacked_ToBeRollbacked(TransactionContextAffinity affinity)
        {
            using (var context = new TransactionContext(affinity))
            {
                context.VoteRollback();
                Assert.AreEqual(TransactionContextState.ToBeRollbacked, context.State);

                context.StateChanged +=
                    (sender, e) =>
                {
                    if (e.NewState == TransactionContextState.ToBeCommitted)
                    {
                        Assert.Fail("Changed event should not be raised again");
                    }
                };

                context.VoteRollback();
                Assert.AreEqual(TransactionContextState.ToBeRollbacked, context.State);
            }
        }
Beispiel #13
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);
            }
        }
		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 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);
			}
		}