当前位置: 首页>>代码示例>>C#>>正文


C# RestTestHarness.CreateAndConnectTransactionalGraphClient方法代码示例

本文整理汇总了C#中RestTestHarness.CreateAndConnectTransactionalGraphClient方法的典型用法代码示例。如果您正苦于以下问题:C# RestTestHarness.CreateAndConnectTransactionalGraphClient方法的具体用法?C# RestTestHarness.CreateAndConnectTransactionalGraphClient怎么用?C# RestTestHarness.CreateAndConnectTransactionalGraphClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RestTestHarness的用法示例。


在下文中一共展示了RestTestHarness.CreateAndConnectTransactionalGraphClient方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CurrentInternalTransaction_ReturnsNullWhenEmpty

        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);
            }
        }
开发者ID:Readify,项目名称:Neo4jClient,代码行数:15,代码来源:TransactionManagementTests.cs

示例2: CannotJoinAfterClosedTransaction

        public void CannotJoinAfterClosedTransaction()
        {
            using (var testHarness = new RestTestHarness())
            {
                var client = testHarness.CreateAndConnectTransactionalGraphClient();
                using (var tran = client.BeginTransaction())
                {
                    tran.Commit();

                    Assert.IsFalse(tran.IsOpen);
                    // should fail here

                    Assert.That(() => client.BeginTransaction(), Throws.TypeOf<ClosedTransactionException>());
                }
            }
        }
开发者ID:Readify,项目名称:Neo4jClient,代码行数:16,代码来源:TransactionManagementTests.cs

示例3: CannotJoinAfterClosedTransaction

        public void CannotJoinAfterClosedTransaction()
        {
            using (var testHarness = new RestTestHarness())
            {
                var client = testHarness.CreateAndConnectTransactionalGraphClient();
                using (var tran = client.BeginTransaction())
                {
                    tran.Commit();

                    Assert.IsFalse(tran.IsOpen);
                    // should fail here
                    using (var tran2 = client.BeginTransaction())
                    {
                    }
                }
            }
        }
开发者ID:neildobson71,项目名称:Neo4jClient,代码行数:17,代码来源:TransactionManagementTests.cs

示例4: CommitInRequiresNewDoesntAffectParentScope

        public void CommitInRequiresNewDoesntAffectParentScope()
        {
            using (var testHarness = new RestTestHarness())
            {
                var client = testHarness.CreateAndConnectTransactionalGraphClient();
                using (var tran = client.BeginTransaction())
                {
                    using (var tran2 = client.BeginTransaction(TransactionScopeOption.RequiresNew))
                    {
                        tran2.Commit();
                        Assert.IsFalse(tran2.IsOpen);
                    }

                    Assert.IsTrue(tran.IsOpen);
                }
                Assert.IsFalse(client.InTransaction);
            }
        }
开发者ID:neildobson71,项目名称:Neo4jClient,代码行数:18,代码来源:TransactionManagementTests.cs

示例5: ExecuteRestMethodUnderTransaction

 private void ExecuteRestMethodUnderTransaction(
     Action<IGraphClient> restAction,
     TransactionScopeOption option = TransactionScopeOption.Join,
     IEnumerable<KeyValuePair<MockRequest, MockResponse>> requests = null)
 {
     requests = requests ?? Enumerable.Empty<KeyValuePair<MockRequest, MockResponse>>();
     using (var testHarness = new RestTestHarness())
     {
         foreach (var request in requests)
         {
             testHarness.Add(request.Key, request.Value);
         }
         var client = testHarness.CreateAndConnectTransactionalGraphClient();
         using (var transaction = client.BeginTransaction(option))
         {
             restAction(client);
         }
     }
 }
开发者ID:albumprinter,项目名称:Neo4jClient,代码行数:19,代码来源:RestCallScenarioTests.cs

示例6: CommitWithoutRequestsShouldNotGenerateMessage

 public void CommitWithoutRequestsShouldNotGenerateMessage()
 {
     var initTransactionRequest = MockRequest.PostJson("/transaction", @"{'statements': []}");
     var commitTransactionRequest = MockRequest.PostJson("/transaction/1/commit", @"{'statements': []}");
     using (var testHarness = new RestTestHarness
     {
         {
             initTransactionRequest, MockResponse.Json(201, TransactionRestResponseHelper.GenerateInitTransactionResponse(1), "http://foo/db/data/transaction/1")
         },
         {
             commitTransactionRequest, MockResponse.Json(200, @"{'results':[], 'errors':[] }")
         }
     }.ShouldNotBeCalled(initTransactionRequest, commitTransactionRequest))
     {
         var client = testHarness.CreateAndConnectTransactionalGraphClient();
         using (var transaction = client.BeginTransaction())
         {
             // no requests
             transaction.Commit();
         }
     }
 }
开发者ID:meshr-net,项目名称:Neo4jClient,代码行数:22,代码来源:QueriesInTransactionTests.cs

示例7: DeserializeResultsFromTransaction

        public void DeserializeResultsFromTransaction()
        {
            var initTransactionRequest = MockRequest.PostJson("/transaction", @"{
                'statements': [{'statement': 'MATCH n\r\nRETURN count(n)', 'resultDataContents':[], 'parameters': {}}]}");
            var deserializationRequest = MockRequest.PostJson("/transaction/1", @"{
                'statements': [{'statement': 'MATCH n\r\nRETURN count(n)', 'resultDataContents':[], 'parameters': {}}]}");
            var rollbackTransactionRequest = MockRequest.Delete("/transaction/1");
            using (var testHarness = new RestTestHarness
            {
                {
                    initTransactionRequest,
                    MockResponse.Json(201, GenerateInitTransactionResponse(1), "http://foo/db/data/transaction/1")
                },
                {
                    deserializationRequest,
                    MockResponse.Json(200, @"{'results':[{'columns': ['count(n)'], 'data': [{'row': [0]}]}]}")
                },
                {
                    rollbackTransactionRequest, MockResponse.Json(200, @"{'results':[], 'errors':[] }")
                }
            })
            {
                var client = testHarness.CreateAndConnectTransactionalGraphClient();
                using (var transaction = client.BeginTransaction())
                {
                    // dummy query to generate request
                    client.Cypher
                        .Match("n")
                        .Return(n => n.Count())
                        .ExecuteWithoutResults();

                    // this query will hit the deserializer
                    var count = client.Cypher
                        .Match("n")
                        .Return(n => n.Count())
                        .Results;

                    Assert.AreEqual(count.First(), 0);
                }
            }
        }
开发者ID:neildobson71,项目名称:Neo4jClient,代码行数:41,代码来源:QueriesInTransactionTests.cs

示例8: CommitFailsOnPendingAsyncRequests

        public void CommitFailsOnPendingAsyncRequests()
        {
            const string queryText = @"MATCH (n) RETURN count(n) as Total";
            const string resultColumn = @"{'columns':['Total'], 'data':[{'row':[1]}]}";

            var cypherQuery = new CypherQuery(queryText, new Dictionary<string, object>(), CypherResultMode.Projection);
            var cypherApiQuery = new CypherStatementList { new CypherTransactionStatement(cypherQuery, false) };

            using (var testHarness = new RestTestHarness(false)
            {
                {
                    MockRequest.PostObjectAsJson("/transaction", cypherApiQuery),
                    MockResponse.Json(201, GenerateInitTransactionResponse(1, resultColumn), "http://foo/db/data/transaction/1")
                }
            })
            {
                var client = testHarness.CreateAndConnectTransactionalGraphClient();
                var rawClient = (IRawGraphClient) client;
                using (var tran = client.BeginTransaction())
                {
                    rawClient.ExecuteGetCypherResultsAsync<DummyTotal>(cypherQuery);
                    tran.Commit();
                }

            }
        }
开发者ID:neildobson71,项目名称:Neo4jClient,代码行数:26,代码来源:QueriesInTransactionTests.cs

示例9: TestTransactionScopeWithComplexDeserialization

        public void TestTransactionScopeWithComplexDeserialization()
        {
            const string queryText = @"MATCH (dt:DummyTotal) RETURN dt";
            const string resultColumn = @"{'columns':['dt'],'data':[{'row':[{'total':1234}]}]}";
            var cypherQuery = new CypherQuery(queryText, new Dictionary<string, object>(), CypherResultMode.Projection);
            var cypherApiQuery = new CypherStatementList { new CypherTransactionStatement(cypherQuery, false) };
            var commitRequest = MockRequest.PostJson("/transaction/1/commit", @"{'statements': []}");

            using (var testHarness = new RestTestHarness
            {
                {
                    MockRequest.PostObjectAsJson("/transaction", cypherApiQuery),
                    MockResponse.Json(201, TransactionRestResponseHelper.GenerateInitTransactionResponse(1, resultColumn), "http://foo/db/data/transaction/1")
                },
                {
                    commitRequest, MockResponse.Json(200, @"{'results':[], 'errors':[] }")
                }
            })
            {
                var client = testHarness.CreateAndConnectTransactionalGraphClient();
                client.JsonContractResolver = new CamelCasePropertyNamesContractResolver();
                using (var msTransaction = new TransactionScope())
                {
                    Assert.IsTrue(client.InTransaction);

                    var results = client.Cypher.Match("(dt:DummyTotal)")
                        .Return(dt => dt.As<DummyTotal>())
                        .Results
                        .ToList();

                    Assert.AreEqual(1, results.Count());
                    Assert.AreEqual(1234, results.First().Total);

                    msTransaction.Complete();
                }

                Assert.IsFalse(client.InTransaction);
            }
        }
开发者ID:meshr-net,项目名称:Neo4jClient,代码行数:39,代码来源:QueriesInTransactionTests.cs

示例10: JoinTransactionAfterSuppressCreatesNewTransaction

 public void JoinTransactionAfterSuppressCreatesNewTransaction()
 {
     using (var testHarness = new RestTestHarness())
     {
         var client = testHarness.CreateAndConnectTransactionalGraphClient();
         using (var tran = client.BeginTransaction())
         {
             using (var tran2 = client.BeginTransaction(TransactionScopeOption.Suppress))
             {
                 Assert.AreNotSame(tran2, tran);
                 Assert.IsFalse(client.InTransaction);
                 using (var tran3 = client.BeginTransaction(TransactionScopeOption.Join))
                 {
                     Assert.AreNotSame(GetRealTransaction(tran2), GetRealTransaction(tran3));
                     Assert.AreNotSame(GetRealTransaction(tran3), GetRealTransaction(tran2));
                     Assert.IsTrue(client.InTransaction);
                 }
             }
             Assert.IsTrue(client.InTransaction);
         }
         Assert.IsFalse(client.InTransaction);
     }
 }
开发者ID:albumprinter,项目名称:Neo4jClient,代码行数:23,代码来源:TransactionManagementTests.cs

示例11: TransactionJoinedShouldBeTheSame

        public void TransactionJoinedShouldBeTheSame()
        {
            using (var testHarness = new RestTestHarness())
            {
                var client = testHarness.CreateAndConnectTransactionalGraphClient();
                using (var transaction = client.BeginTransaction())
                {

                    using (var tran2 = client.BeginTransaction())
                    {
                        Assert.AreSame(GetRealTransaction(tran2), GetRealTransaction(transaction));
                    }
                }
            }
        }
开发者ID:albumprinter,项目名称:Neo4jClient,代码行数:15,代码来源:TransactionManagementTests.cs

示例12: PromoteDurableInAmbientTransaction

        public void PromoteDurableInAmbientTransaction()
        {
            // when two durables are registered they get promoted

            // this request will be made by the ForceKeepAlive() call when PSPE registration fails for the second client
            var afterPspeFailRequest = MockRequest.PostJson("/transaction", @"{'statements': []}");
            // this request will be mode in Promote() after second durable enlistment
            var promoteRequest = MockRequest.PostJson("/transaction/1", @"{'statements': []}");
            var initTransactionRequest = MockRequest.PostJson("/transaction", @"{
                'statements': [{'statement': 'MATCH n\r\nRETURN count(n)', 'resultDataContents':[], 'parameters': {}}]}");

            var secondClientRequest = MockRequest.PostJson("/transaction/2", @"{
                'statements': [{'statement': 'MATCH n\r\nRETURN count(n)', 'resultDataContents':[], 'parameters': {}}]}");

            // there are no delete requests because those will be made in another app domain

            using (var testHarness = new RestTestHarness
            {
                {
                    initTransactionRequest,
                    MockResponse.Json(201, GenerateInitTransactionResponse(1), "http://foo/db/data/transaction/1")
                },
                {
                    secondClientRequest,
                    MockResponse.Json(200, @"{'results':[], 'errors':[] }")
                },
                {
                    afterPspeFailRequest,
                    MockResponse.Json(201, GenerateInitTransactionResponse(2), "http://foo/db/data/transaction/2")
                },
                {
                    promoteRequest,
                    MockResponse.Json(200, @"{'results':[], 'errors':[] }")
                }
            })
            {
                using (var scope = new TransactionScope())
                {
                    var client = testHarness.CreateAndConnectTransactionalGraphClient();

                    client.Cypher
                        .Match("n")
                        .Return(n => n.Count())
                        .ExecuteWithoutResults();

                    var client2 = testHarness.CreateAndConnectTransactionalGraphClient();

                    client2.Cypher
                        .Match("n")
                        .Return(n => n.Count())
                        .ExecuteWithoutResults();
                }

                // we sleep so that the app domain for the resource manager gets cleaned up
                Thread.Sleep(500);
            }
        }
开发者ID:neildobson71,项目名称:Neo4jClient,代码行数:57,代码来源:QueriesInTransactionTests.cs

示例13: NestedJoinedTransactionScope

        public void NestedJoinedTransactionScope()
        {
            var initTransactionRequest = MockRequest.PostJson("/transaction", @"{
                'statements': [{'statement': 'MATCH n\r\nRETURN count(n)', 'resultDataContents':[], 'parameters': {}}]}");
            var secondRequest = MockRequest.PostJson("/transaction/1", @"{
                'statements': [{'statement': 'MATCH n\r\nRETURN count(n)', 'resultDataContents':[], 'parameters': {}}]}");
            var deleteRequest = MockRequest.Delete("/transaction/1");
            using (var testHarness = new RestTestHarness
            {
                {
                    initTransactionRequest,
                    MockResponse.Json(201, GenerateInitTransactionResponse(1), "http://foo/db/data/transaction/1")
                },
                {
                    secondRequest,
                    MockResponse.Json(200, @"{'results':[], 'errors':[] }")
                },
                {
                    deleteRequest, MockResponse.Json(200, @"{'results':[], 'errors':[] }")
                }
            })
            {
                var client = testHarness.CreateAndConnectTransactionalGraphClient();
                using (var scope = new TransactionScope())
                {
                    using (var scope2 = new TransactionScope())
                    {
                        client.Cypher
                            .Match("n")
                            .Return(n => n.Count())
                            .ExecuteWithoutResults();

                        // this will not commit
                        scope2.Complete();
                    }

                    // this should generate a request to the known transaction ID
                    client.Cypher
                        .Match("n")
                        .Return(n => n.Count())
                        .ExecuteWithoutResults();
                }
            }
        }
开发者ID:neildobson71,项目名称:Neo4jClient,代码行数:44,代码来源:QueriesInTransactionTests.cs

示例14: TwoThreadsShouldNotHaveTheSameTransactionObject

        public void TwoThreadsShouldNotHaveTheSameTransactionObject()
        {
            // if thread support is not well implemented then the t2's BeginTransaction will fail with NotSupportedException
            ITransaction transactionFromThread1 = null;
            ITransaction transactionFromThread2 = null;
            using (var testHarness = new RestTestHarness())
            {
                var client = testHarness.CreateAndConnectTransactionalGraphClient();
                var firstTransactionSet = new EventWaitHandle(false, EventResetMode.AutoReset);
                var secondTransactionSet = new EventWaitHandle(false, EventResetMode.AutoReset);
                var t1 = new Task(() =>
                {
                    try
                    {
                        using (var transaction = client.BeginTransaction())
                        {
                            transactionFromThread1 = transaction;
                            firstTransactionSet.Set();
                            secondTransactionSet.WaitOne();
                        }
                    }
                    catch (Exception e)
                    {
                        firstTransactionSet.Set();
                        throw;
                    }
                });

                var t2 = new Task(() =>
                {
                    firstTransactionSet.WaitOne();
                    try
                    {
                        using (var transaction = client.BeginTransaction())
                        {
                            transactionFromThread2 = transaction;
                            secondTransactionSet.Set();
                        }
                    }
                    catch (Exception e)
                    {
                        secondTransactionSet.Set();
                        throw;
                    }
                });

                t1.Start();
                t2.Start();
                Task.WaitAll(t1, t2);
                Assert.IsNotNull(transactionFromThread1);
                Assert.IsNotNull(transactionFromThread2);
                Assert.AreNotEqual(transactionFromThread1, transactionFromThread2);

            }
        }
开发者ID:albumprinter,项目名称:Neo4jClient,代码行数:55,代码来源:TransactionManagementTests.cs

示例15: ShouldPromoteBadQueryResponseToNiceException

        public void ShouldPromoteBadQueryResponseToNiceException()
        {
            // Arrange
            const string queryText = @"broken query";
            var cypherQuery = new CypherQuery(queryText, new Dictionary<string, object>(), CypherResultMode.Projection);
            var cypherApiQuery = new CypherStatementList {new CypherTransactionStatement(cypherQuery, false)};

            using (var testHarness = new RestTestHarness
                {
                    {
                        MockRequest.PostObjectAsJson("/transaction", cypherApiQuery),
                        MockResponse.Json(HttpStatusCode.OK, @"{'results':[], 'errors': [{
    'code' : 'Neo.ClientError.Statement.InvalidSyntax',
    'message' : 'Invalid input b: expected SingleStatement (line 1, column 1)\nThis is not a valid Cypher Statement.\n ^'
  }]}")
                    }
                })
            {
                var graphClient = testHarness.CreateAndConnectTransactionalGraphClient();
                var rawClient = (IRawGraphClient) graphClient;

                using (graphClient.BeginTransaction())
                {

                    var ex = Assert.Throws<NeoException>(() => rawClient.ExecuteCypher(cypherQuery));
                    Assert.AreEqual("InvalidSyntax: Invalid input b: expected SingleStatement (line 1, column 1)\nThis is not a valid Cypher Statement.\n ^", ex.Message);
                    Assert.AreEqual("Invalid input b: expected SingleStatement (line 1, column 1)\nThis is not a valid Cypher Statement.\n ^", ex.NeoMessage);
                    Assert.AreEqual("InvalidSyntax", ex.NeoExceptionName);
                    Assert.AreEqual("Neo.ClientError.Statement.InvalidSyntax", ex.NeoFullName);
                    CollectionAssert.AreEqual(new String[] {}, ex.NeoStackTrace);
                }
            }
        }
开发者ID:albumprinter,项目名称:Neo4jClient,代码行数:33,代码来源:TransactionManagementTests.cs


注:本文中的RestTestHarness.CreateAndConnectTransactionalGraphClient方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。