Ejemplo n.º 1
0
        public override IContext CreateContext(string contextName, ContextSchema schema)
        {
            if (string.IsNullOrEmpty(contextName))
            {
                throw new ArgumentNullException("contextName");
            }
            if (schema == null)
            {
                throw new ArgumentNullException("schema");
            }

            IContext context;

            lock (padlock) {
                if (ContextsContains(contextName))
                {
                    throw new ContextAlreadyExistsException("A context with the name [" + contextName + "] already exists.");
                }
                using (var transaction = TransactionFactory.BeginTransaction(CurrentDB)) {
                    CurrentDB.ExecuteNonQuery("dbo.USER_CreateContext",
                                              transaction,
                                              CurrentDB.CreateStringInputParameter("@chvContext", DbType.AnsiString, contextName));
                    foreach (var s in schema)
                    {
                        AddSchemaToContext(s, contextName, transaction);
                    }
                    context = new Context(contextName);
                    transaction.Commit();
                }

                contexts.Add(context);
            }

            return(context);
        }
Ejemplo n.º 2
0
 public override void SaveUser(IUser user)
 {
     using (var transaction = TransactionFactory.BeginTransaction(CurrentDB)) {
         SaveUser(user, transaction);
         transaction.Commit();
     }
 }
Ejemplo n.º 3
0
 public override void SaveProperties(IUser user, IPropertyCollection propertyCollection)
 {
     using (var transaction = TransactionFactory.BeginTransaction(CurrentDB)) {
         SaveProperties(user, propertyCollection, transaction);
         transaction.Commit();
     }
 }
Ejemplo n.º 4
0
        public void BeginTransaction_ReturnTransactionWithIsolationLeverlReadUncommitted_TestSoTransactionWithRightIsolationLevelIsStarted()
        {
            var dataSource = A.Fake <IDataSource>();
            var connection = A.Fake <IDbConnection>();

            A.CallTo(() => dataSource.OpenConnection()).Returns(connection);
            using (TransactionFactory.BeginTransaction(dataSource, IsolationLevel.ReadUncommitted)) {
                A.CallTo(() => dataSource.OpenConnection()).MustHaveHappened(Repeated.Exactly.Once);
                A.CallTo(() => connection.BeginTransaction(IsolationLevel.ReadUncommitted)).MustHaveHappened(Repeated.Exactly.Once);
            }
        }
Ejemplo n.º 5
0
        public void Constructor_CreatesConnection_ReturnsCommandWithCorrectTransaction()
        {
            var dataSource    = A.Fake <IDataSource>();
            var dbCommand     = A.Fake <IDbCommand>();
            var dbTransaction = TransactionFactory.BeginTransaction(dataSource);
            var command       = new Command(dbCommand, dbTransaction, null);

            Assert.AreEqual(dbTransaction, command.Transaction);
            Assert.AreEqual(dbTransaction.Connection, dbCommand.Connection);
            Assert.AreEqual(dbTransaction.DbTransaction, dbCommand.Transaction);
        }
        public void BeginTransaction()
        {
            ITransactionFactory transactionFactory = new TransactionFactory();
            IConnectionFactory  connectionFactory  = new SqliteConnectionFactory();

            using (var connection = connectionFactory.Open(_connectionString))
                using (var transaction = transactionFactory.BeginTransaction(connection))
                {
                    Assert.IsNotNull(transaction);
                    Assert.AreEqual(connection, transaction.Connection);
                    Assert.AreEqual(IsolationLevel.Serializable, transaction.IsolationLevel);
                    transaction.Rollback();
                }
        }
        public void BeginTransaction_WithIsolationLevel()
        {
            ITransactionFactory transactionFactory = new TransactionFactory();
            IConnectionFactory  connectionFactory  = new SqlServerConnectionFactory();

            using (var connection = connectionFactory.Open(AppState.ConnectionString))
                using (var transaction = transactionFactory.BeginTransaction(connection, IsolationLevel.Snapshot))
                {
                    Assert.IsNotNull(transaction);
                    Assert.AreEqual(connection, transaction.Connection);
                    Assert.AreEqual(IsolationLevel.Snapshot, transaction.IsolationLevel);
                    transaction.Rollback();
                }
        }
Ejemplo n.º 8
0
        public override void SaveUsers(IList <IUser> users)
        {
            if (users == null)
            {
                throw new ArgumentNullException("users");
            }

            using (var transaction = TransactionFactory.BeginTransaction(CurrentDB)) {
                foreach (var user in users)
                {
                    SaveUser(user, transaction);
                }
                transaction.Commit();
            }
        }
        public void BeginTransaction_WithIsolationLevel_Failure()
        {
            // sqlite only supports IsolationLevel.Serializable
            ITransactionFactory transactionFactory = new TransactionFactory();
            IConnectionFactory  connectionFactory  = new SqliteConnectionFactory();

            using (var connection = connectionFactory.Open(_connectionString))
                using (var transaction = transactionFactory.BeginTransaction(connection, IsolationLevel.Snapshot))
                {
                    Assert.IsNotNull(transaction);
                    Assert.AreEqual(connection, transaction.Connection);
                    Assert.AreEqual(IsolationLevel.Snapshot, transaction.IsolationLevel);
                    transaction.Rollback();
                }
        }
Ejemplo n.º 10
0
        public void Rollback_RunTranactionAndRoleback_RollbackOnTheUnderlyingObjectIsCalled()
        {
            var underlyingTrans = A.Fake <IDbTransaction>();
            var connection      = new FakeConnection(underlyingTrans);
            var dataSource      = A.Fake <IDataSource>();

            A.CallTo(() => dataSource.OpenConnection()).Returns(connection);
            using (var trans = TransactionFactory.BeginTransaction(dataSource, IsolationLevel.Chaos)) {
                var myCommand = dataSource.CreateSPCommand("exec storedprocedure", trans);
                dataSource.ExecuteDataSet(myCommand);
                dataSource.ExecuteNonQuery("select * from table", CommandType.Text, trans);
                trans.Rollback();
                A.CallTo(() => underlyingTrans.Rollback()).MustHaveHappened(Repeated.Exactly.Once);
                Assert.AreEqual(IsolationLevel.Chaos, trans.IsolationLevel);
            }
        }
Ejemplo n.º 11
0
        public void BeginTransaction_ReturnTransactionThatOpenConnection_CosingConncetionWhenTransactionIsOver()
        {
            var dataSource = A.Fake <IDataSource>();
            var connection = A.Fake <IDbConnection>();

            A.CallTo(() => dataSource.OpenConnection()).Returns(connection);
            using (ITransaction transaction = TransactionFactory.BeginTransaction(dataSource)) {
                A.CallTo(() => connection.State).Returns(ConnectionState.Open);
                A.CallTo(() => dataSource.OpenConnection()).MustHaveHappened(Repeated.Exactly.Once);
                A.CallTo(() => connection.BeginTransaction(IsolationLevel.ReadCommitted)).MustHaveHappened(Repeated.Exactly.Once);
                A.CallTo(() => connection.Close()).MustNotHaveHappened();
                transaction.Commit();
            }
            A.CallTo(() => connection.State).Returns(ConnectionState.Closed);
            A.CallTo(() => connection.Close()).MustHaveHappened(Repeated.Exactly.Once);
        }
Ejemplo n.º 12
0
 public override void DeleteContext(IContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     lock (padlock) {
         using (var transaction = TransactionFactory.BeginTransaction(CurrentDB)) {
             CurrentDB.ExecuteNonQuery("dbo.USER_DeleteContext",
                                       transaction,
                                       CurrentDB.CreateStringInputParameter("@chvContext", DbType.AnsiString, context.Name, true));
             transaction.Commit();
         }
         contexts.Remove(context);
     }
 }