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); }
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); }
public MockDataReader(MockDataCommand command, CommandBehavior behavior) : base() { if (command == null) throw new ArgumentNullException(nameof(command)); this.Command = command; this.CommandBehavior = behavior; }
void IMockDataCommandOwner.RegisterExpectation(MockDataCommand cmd, int expectedCalls) { List <MockDataCommand> cmds; if (!_expectations.TryGetValue(cmd.Signature, out cmds)) { cmds = new List <MockDataCommand>(); _expectations.Add(cmd.Signature, cmds); } for (int i = 0; i < expectedCalls; i++) { cmds.Add(cmd); } }
MockDataCommand IMockDataCommandOwner.GetExpectation(MockDataCommand cmd) { List <MockDataCommand> cmds; if (!_expectations.TryGetValue(cmd.Signature, out cmds)) { throw new AssertionException(string.Format("cannot find an expectation for query with signature: {0}", cmd.Signature)); } var expectation = cmds[0]; cmds.RemoveAt(0); if (cmds.Count == 0) { _expectations.Remove(cmd.Signature); } return(expectation); }
/// <summary> /// Create a new mock command to intercept a specific <see cref="IDataCatalog.NewQuery(string,bool)"/> call. /// </summary> /// <param name="query">Sql query string.</param> /// <param name="readonly"><see langword="True"/> if the query is readonly.</param> /// <param name="expectedCalls">Number of times this call is expected to occur.</param> /// <returns>New mock command.</returns> public MockDataCommand ExpectNewQuery(string query, bool @readonly, int expectedCalls) { var cmd = new MockDataCommand(this, expectedCalls, @readonly ? "READONLY-" : "" + query); return(cmd); }