public void GetDbTransaction_returns_the_DbTransaction() { var dbConnection = new FakeDbConnection(ConnectionString); var dbTransaction = new FakeDbTransaction(dbConnection); var connection = new FakeRelationalConnection( CreateOptions((FakeRelationalOptionsExtension) new FakeRelationalOptionsExtension().WithConnection(dbConnection))); var loggerFactory = new ListLoggerFactory(); var transaction = new RelationalTransaction( connection, dbTransaction, new Guid(), new DiagnosticsLogger <DbLoggerCategory.Database.Transaction>( loggerFactory, new LoggingOptions(), new DiagnosticListener("Fake"), new TestRelationalLoggingDefinitions(), new NullDbContextLogger()), false, new RelationalSqlGenerationHelper( new RelationalSqlGenerationHelperDependencies())); Assert.Equal(dbTransaction, transaction.GetDbTransaction()); }
public void GetDbTransaction_returns_the_DbTransaction() { var dbConnection = new FakeDbConnection(ConnectionString); var dbTransaction = new FakeDbTransaction(dbConnection); var connection = new FakeRelationalConnection( CreateOptions(new FakeRelationalOptionsExtension { Connection = dbConnection })); var transaction = new RelationalTransaction( connection, dbTransaction, new ListLogger(new List<Tuple<LogLevel, string>>()), false); Assert.Equal(dbTransaction, transaction.GetDbTransaction()); }
public static void ExplicitTransactionTwoSaveChanges() { CUI.MainHeadline(nameof(ExplicitTransactionTwoSaveChanges)); using (var ctx = new WWWingsContext()) { // Start transaction. Default is System.Data.IsolationLevel.ReadCommitted using (var t = ctx.Database.BeginTransaction(System.Data.IsolationLevel.ReadCommitted)) { // Print isolation level RelationalTransaction rt = t as RelationalTransaction; DbTransaction dbt = rt.GetDbTransaction(); Console.WriteLine("Transaction with Level: " + dbt.IsolationLevel); // Read data int flightNo = ctx.FlightSet.OrderBy(x => x.FlightNo).FirstOrDefault().FlightNo; var f = ctx.FlightSet.Where(x => x.FlightNo == flightNo).SingleOrDefault(); Console.WriteLine("Before: " + f.ToString()); // Change data and save f.FreeSeats--; var count1 = ctx.SaveChanges(); Console.WriteLine("Number of saved changes: " + count1); // Change data again and save f.Memo = "last changed at " + DateTime.Now.ToString(); var count2 = ctx.SaveChanges(); Console.WriteLine("Number of saved changes: " + count2); Console.WriteLine("Commit or Rollback? 1 = Commit, other = Rollback"); var eingabe = Console.ReadKey().Key; if (eingabe == ConsoleKey.D1) { t.Commit(); Console.WriteLine("Commit done!"); } else { t.Rollback(); Console.WriteLine("Rollback done!"); } Console.WriteLine("After in RAM: " + f.ToString()); ctx.Entry(f).Reload(); Console.WriteLine("After in DB: " + f.ToString()); } } }
public void GetDbTransaction_returns_the_DbTransaction() { var dbConnection = new FakeDbConnection(ConnectionString); var dbTransaction = new FakeDbTransaction(dbConnection); var connection = new FakeRelationalConnection( CreateOptions((FakeRelationalOptionsExtension) new FakeRelationalOptionsExtension().WithConnection(dbConnection))); var transaction = new RelationalTransaction( connection, dbTransaction, new InterceptingLogger <LoggerCategory.Database.Transaction>(new ListLoggerFactory(new List <Tuple <LogLevel, string> >()), new LoggingOptions()), new DiagnosticListener("Fake"), false); Assert.Equal(dbTransaction, transaction.GetDbTransaction()); }
public void GetDbTransaction_returns_the_DbTransaction() { var dbConnection = new FakeDbConnection(ConnectionString); var dbTransaction = new FakeDbTransaction(dbConnection); var connection = new FakeRelationalConnection( CreateOptions(new FakeRelationalOptionsExtension { Connection = dbConnection })); var transaction = new RelationalTransaction( connection, dbTransaction, new ListLogger(new List <Tuple <LogLevel, string> >()), false); Assert.Equal(dbTransaction, transaction.GetDbTransaction()); }