Inheritance: IDisposable
Esempio n. 1
0
		public static async Task SimpleTest()
		{
			const string TraceFileName = "Transactions.TransactionHandlerTest.SimpleTest.log.csv";

			try
			{
				Trace.AutoFlush = true;
				Trace.Listeners.Add(new TextWriterTraceListener(new StreamWriter(TraceFileName, false)));

				using (var dataSource = new MockDataSource("ds", "tx"))
				using (var context = new TransactionContext(TransactionContextAffinity.RequiresNew))
				{
					var command = new MockDataCommand();
					await dataSource.ExecuteNonQuery(command).ConfigureAwait(false);

					context.VoteCommit();
				}
			}
			finally
			{
				Trace.Close();
			}

			CheckTraceLog(TraceFileName);
		}
Esempio n. 2
0
		public static async Task NoContextTest()
		{
			const string TraceFileName = "Transactions.TransactionHandlerTest.NoContextTest.log.csv";

			try
			{
				Trace.AutoFlush = true;
				Trace.Listeners.Add(new TextWriterTraceListener(new StreamWriter(TraceFileName, false)));

				using (var dataSource = new MockDataSource("ds", "tx"))
				{
					try
					{
						TransactionContext.Created += NoContextTest_TransactionContextCreated;

						var command = new MockDataCommand();
						await dataSource.ExecuteNonQuery(command).ConfigureAwait(false);
					}
					finally
					{
						TransactionContext.Created -= NoContextTest_TransactionContextCreated;
					}
				}

				Assert.IsNull(TransactionContext.CurrentTransactionContext);
			}
			finally
			{
				Trace.Close();
			}

			CheckTraceLog(TraceFileName);
		}
Esempio n. 3
0
		public static IEnumerable<TestCaseData> NestedContextCaseSource()
		{
			TimeSpan maxQueryDelay = TimeSpan.FromMilliseconds(100);

			Func<TransactionContextTestNode, Task> operation =
				async node =>
				{
					using (var ds = new MockDataSource($"ds-{node.Id}", $"tx-{node.Id}", maxQueryDelay))
					{
						await ds.ExecuteNonQuery(new MockDataCommand()).ConfigureAwait(false);
					}
				};

			foreach (var parentAffinity in EnumHelper.GetValues<TransactionContextAffinity>())
				foreach (var childAffinity in EnumHelper.GetValues<TransactionContextAffinity>())
					foreach (var parentVote in EnumHelper.GetValues<VoteAction>())
						foreach (var childVote in EnumHelper.GetValues<VoteAction>())
							yield return new TestCaseData(
								new TransactionContextTestNode { Id = "parent", Affinity = parentAffinity, VoteAction = parentVote, Operation = operation }
									.AddChild(new TransactionContextTestNode { Id = "child", Affinity = childAffinity, VoteAction = childVote, Operation = operation }));
		}