Handles all the queries related to transactions that could be needed in a ITransactionalGraphClient
Inheritance: ITransactionManager
        public void CurrentInternalTransaction_ReturnsNullWhenScopedTransactionsIsNull()
        {
            using (var testHarness = new RestTestHarness())
            {
                var client = testHarness.CreateAndConnectTransactionalGraphClient();
                client.Connect();

                var tm = new TransactionManager(client);
                TransactionManager.ScopedTransactions = null;

                Assert.Null(tm.CurrentInternalTransaction);
            }
        }
        public void EndTransaction_DoesntThrowAnyExceptions_WhenScopedTransactionsIsNull()
        {
            using (var testHarness = new RestTestHarness())
            {
                var client = testHarness.CreateAndConnectTransactionalGraphClient();
                client.Connect();

                var tm = new TransactionManager(client);
                TransactionManager.ScopedTransactions = null;

                tm.EndTransaction();
            }
        }
        public void CurrentInternalTransaction_ReturnsNullWhenEmpty()
        {
            using (var testHarness = new RestTestHarness())
            {
                var client = testHarness.CreateAndConnectTransactionalGraphClient();
                client.Connect();

                var tm = new TransactionManager(client);
                TransactionManager.ScopedTransactions = new ThreadContextWrapper <TransactionScopeProxy>();

                Assert.Equal(0, TransactionManager.ScopedTransactions.Count);
                Assert.Null(tm.CurrentInternalTransaction);
            }
        }
        public void EndTransaction_DoesntThrowAnyExceptions_WhenScopedTransactionsIsEmpty()
        {
            using (var testHarness = new RestTestHarness())
            {
                var client = testHarness.CreateAndConnectTransactionalGraphClient();
                client.Connect();

                var tm = new TransactionManager(client);
                TransactionManager.ScopedTransactions = new ThreadContextWrapper <TransactionScopeProxy>();

                Assert.Equal(0, TransactionManager.ScopedTransactions.Count);
                tm.EndTransaction();
            }
        }
        public void CurrentInternalTransaction_ReturnsNullWhenEmpty()
        {
            using (var testHarness = new RestTestHarness())
            {
                var client = testHarness.CreateAndConnectTransactionalGraphClient();
                client.Connect();

                var tm = new Neo4jClient.Transactions.TransactionManager(client)
                {
                    ScopedTransactions = new Stack <TransactionScopeProxy>()
                };
                Assert.AreEqual(0, tm.ScopedTransactions.Count);
                Assert.IsNull(tm.CurrentInternalTransaction);
            }
        }
        public void EndTransaction_DoesntThrowAnyExceptions_WhenScopedTransactionsIsEmpty()
        {
            using (var testHarness = new RestTestHarness())
            {
                var client = testHarness.CreateAndConnectTransactionalGraphClient();
                client.Connect();

                var tm = new Neo4jClient.Transactions.TransactionManager(client)
                {
                    ScopedTransactions = new Stack <TransactionScopeProxy>()
                };
                Assert.AreEqual(0, tm.ScopedTransactions.Count);
                tm.EndTransaction();
            }
        }
示例#7
0
        public virtual async Task ConnectAsync(NeoServerConfiguration configuration = null)
        {
            if (IsConnected)
            {
                return;
            }

            var stopwatch = Stopwatch.StartNew();
            var operationCompletedArgs = new OperationCompletedEventArgs
            {
                QueryText = "Connect",
                ResourcesReturned = 0
            };

            Action stopTimerAndNotifyCompleted = () =>
            {
                stopwatch.Stop();
                operationCompletedArgs.TimeTaken = stopwatch.Elapsed;
                OnOperationCompleted(operationCompletedArgs);
            };

            try
            {
                configuration = configuration ?? await NeoServerConfiguration.GetConfigurationAsync(
                    RootUri,
                    ExecutionConfiguration.Username,
                    ExecutionConfiguration.Password,
                    ExecutionConfiguration).ConfigureAwait(false);

                RootApiResponse = configuration.ApiConfig;

                if (!string.IsNullOrWhiteSpace(RootApiResponse.Transaction))
                {
                    transactionManager = new TransactionManager(this);
                }

                rootNode = string.IsNullOrEmpty(RootApiResponse.ReferenceNode)
                    ? null
                    : new RootNode(long.Parse(GetLastPathSegment(RootApiResponse.ReferenceNode)), this);

                // http://blog.neo4j.org/2012/04/streaming-rest-api-interview-with.html
                ExecutionConfiguration.UseJsonStreaming = ExecutionConfiguration.UseJsonStreaming &&
                                                          RootApiResponse.Version >= new Version(1, 8);

                if (RootApiResponse.Version < new Version(2, 0))
                    cypherCapabilities = CypherCapabilities.Cypher19;

                if (RootApiResponse.Version >= new Version(2, 2))
                    cypherCapabilities = CypherCapabilities.Cypher22;

                if (RootApiResponse.Version >= new Version(2, 2, 6))
                    cypherCapabilities = CypherCapabilities.Cypher226;

                if (RootApiResponse.Version >= new Version(2, 3))
                    cypherCapabilities = CypherCapabilities.Cypher23;

                if (RootApiResponse.Version >= new Version(3, 0))
                    cypherCapabilities = CypherCapabilities.Cypher30;
            }
            catch (AggregateException ex)
            {
                Exception unwrappedException;
                var wasUnwrapped = ex.TryUnwrap(out unwrappedException);
                operationCompletedArgs.Exception = wasUnwrapped ? unwrappedException : ex;

                stopTimerAndNotifyCompleted();

                if (wasUnwrapped)
                    throw unwrappedException;

                throw;
            }
            catch (Exception e)
            {
                operationCompletedArgs.Exception = e;
                stopTimerAndNotifyCompleted();
                throw;
            }

            stopTimerAndNotifyCompleted();
        }
        public void CurrentInternalTransaction_ReturnsNullWhenScopedTransactionsIsNull()
        {
            using (var testHarness = new RestTestHarness())
            {
                var client = testHarness.CreateAndConnectTransactionalGraphClient();
                client.Connect();

                var tm = new Neo4jClient.Transactions.TransactionManager(client)
                {
                    ScopedTransactions = null
                };
                Assert.IsNull(tm.CurrentInternalTransaction);
            }
        }
        public void CurrentInternalTransaction_ReturnsNullWhenEmpty()
        {
            using (var testHarness = new RestTestHarness())
            {
                var client = testHarness.CreateAndConnectTransactionalGraphClient();
                client.Connect();

                var tm = new Neo4jClient.Transactions.TransactionManager(client)
                {
                    ScopedTransactions = new Stack<TransactionScopeProxy>()
                };
                Assert.AreEqual(0, tm.ScopedTransactions.Count);
                Assert.IsNull(tm.CurrentInternalTransaction);
            }
        }
        public void EndTransaction_DoesntThrowAnyExceptions_WhenScopedTransactionsIsNull()
        {
            using (var testHarness = new RestTestHarness())
            {
                var client = testHarness.CreateAndConnectTransactionalGraphClient();
                client.Connect();

                var tm = new Neo4jClient.Transactions.TransactionManager(client)
                {
                    ScopedTransactions = null
                };
                
                tm.EndTransaction();
            }
        }
        public void EndTransaction_DoesntThrowAnyExceptions_WhenScopedTransactionsIsEmpty()
        {
            using (var testHarness = new RestTestHarness())
            {
                var client = testHarness.CreateAndConnectTransactionalGraphClient();
                client.Connect();

                var tm = new Neo4jClient.Transactions.TransactionManager(client)
                {
                    ScopedTransactions = new Stack<TransactionScopeProxy>()
                };
                Assert.AreEqual(0, tm.ScopedTransactions.Count);
                tm.EndTransaction();
            }
        }