Exemplo n.º 1
0
        public void Commit_Tests()
        {
            {
                using (var connection = new TestDbConnection(new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True"), new TestProfiler()))
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        transaction.Rollback();

                        Assert.Throws <NullReferenceException>(() => transaction.Commit());

                        Assert.True(connection.TestProfiler.PassedEvents.Contains(nameof(IAdoNetProfiler.OnCommitting)));
                        Assert.False(connection.TestProfiler.PassedEvents.Contains(nameof(IAdoNetProfiler.OnCommitted)));
                    }
                }
            }

            {
                using (var connection = new TestDbConnection(new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True"), new TestProfiler()))
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        transaction.Commit();

                        Assert.Null(((AdoNetProfilerDbTransaction)transaction).WrappedTransaction);
                        Assert.True(connection.TestProfiler.PassedEvents.Contains(nameof(IAdoNetProfiler.OnCommitting)));
                        Assert.True(connection.TestProfiler.PassedEvents.Contains(nameof(IAdoNetProfiler.OnCommitted)));
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void BeginTransaction_Tests()
        {
            {
                using (var connection = new TestDbConnection(new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True"), new TestProfiler()))
                {
                    Assert.Throws <InvalidOperationException>(() => connection.BeginTransaction());

                    Assert.True(connection.TestProfiler.PassedEvents.Contains(nameof(IAdoNetProfiler.OnStartingTransaction)));
                    Assert.False(connection.TestProfiler.PassedEvents.Contains(nameof(IAdoNetProfiler.OnStartedTransaction)));
                }
            }

            {
                using (var connection = new TestDbConnection(new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True"), new TestProfiler()))
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        Assert.NotNull(transaction);
                        Assert.Equal(typeof(SqlTransaction), ((AdoNetProfilerDbTransaction)transaction).WrappedTransaction.GetType());
                        Assert.True(connection.TestProfiler.PassedEvents.Contains(nameof(IAdoNetProfiler.OnStartingTransaction)));
                        Assert.True(connection.TestProfiler.PassedEvents.Contains(nameof(IAdoNetProfiler.OnStartedTransaction)));
                    }
                }
            }
        }