public async Task ExecuteAsync_does_not_call_Commit_if_existing_transaction(bool async)
        {
            using (var context = new TestContext())
            {
                var connection  = SetupConnection(context);
                var transaction = new FakeDbTransaction(connection);
                context.Database.UseTransaction(transaction);

                context.Add(
                    new Foo
                {
                    Id = "1"
                });

                if (async)
                {
                    await context.SaveChangesAsync();
                }
                else
                {
                    context.SaveChanges();
                }

                Assert.Empty(connection.DbTransactions);
                Assert.Equal(0, transaction.CommitCount);
            }
        }
        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 use_transaction_throws_on_non_relational_provider()
        {
            var transaction = new FakeDbTransaction(new FakeDbConnection("A=B"));
            var context     = InMemoryTestHelpers.Instance.CreateContext();

            Assert.Equal(
                RelationalStrings.RelationalNotInUse,
                Assert.Throws <InvalidOperationException>(
                    () => context.Database.UseTransaction(transaction)).Message);
        }
        public void Can_use_transaction()
        {
            var dbConnection = new FakeDbConnection("A=B");
            var context      = RelationalTestHelpers.Instance.CreateContext();

            ((FakeRelationalConnection)context.GetService <IRelationalConnection>()).UseConnection(dbConnection);
            var transaction = new FakeDbTransaction(dbConnection, IsolationLevel.Chaos);

            Assert.Same(transaction, context.Database.UseTransaction(transaction).GetDbTransaction());
        }
        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());
        }