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


C# RestTestHarness类代码示例

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


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

示例1: ReturnsThe404_WhenVersionIs_2_2_6_Plus_WhenActuallyTimingOut

 //https://github.com/Readify/Neo4jClient/issues/127
 public void ReturnsThe404_WhenVersionIs_2_2_6_Plus_WhenActuallyTimingOut([Values(RestTestHarness.Neo4jVersion.Neo226, RestTestHarness.Neo4jVersion.Neo23)] RestTestHarness.Neo4jVersion version)
 {
     var initTransactionRequest = MockRequest.PostJson("/transaction", @"{
         '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, TransactionRestResponseHelper.GenerateInitTransactionResponse(1), "http://foo/db/data/transaction/1")
         },
         {
             rollbackTransactionRequest, MockResponse.Json(404, "{\"results\":[],\"errors\":[{\"code\":\"Neo.ClientError.Transaction.UnknownId\",\"message\":\"Unrecognized transaction id. Transaction may have timed out and been rolled back.\"}]}")
         }
     })
     {
         var client = testHarness.CreateGraphClient(version);
         client.Connect();
         try
         {
             using (var transaction = client.BeginTransaction())
             {
                 client.Cypher.Match("n").Return(n => n.Count()).ExecuteWithoutResults();
             }
             Assert.Fail("Should not reach this code, as there is an expected exception.");
         }
         catch (ApplicationException ex)
         {
             Assert.That(ex.Message.Contains("404"));
         }
     }
 }
开发者ID:albumprinter,项目名称:Neo4jClient,代码行数:33,代码来源:TransactionManagementTests.cs

示例2: ShouldReturnNodeDataAndDeserializeToEnumType

        public void ShouldReturnNodeDataAndDeserializeToEnumType()
        {
            using (var testHarness = new RestTestHarness
            {
                {
                    MockRequest.Get("/node/456"),
                    MockResponse.Json(HttpStatusCode.OK,
                        @"{ 'self': 'http://foo/db/data/node/456',
                          'data': { 'Foo': 'foo',
                                    'Status': 'Value1'
                          },
                          'create_relationship': 'http://foo/db/data/node/456/relationships',
                          'all_relationships': 'http://foo/db/data/node/456/relationships/all',
                          'all_typed relationships': 'http://foo/db/data/node/456/relationships/all/{-list|&|types}',
                          'incoming_relationships': 'http://foo/db/data/node/456/relationships/in',
                          'incoming_typed relationships': 'http://foo/db/data/node/456/relationships/in/{-list|&|types}',
                          'outgoing_relationships': 'http://foo/db/data/node/456/relationships/out',
                          'outgoing_typed relationships': 'http://foo/db/data/node/456/relationships/out/{-list|&|types}',
                          'properties': 'http://foo/db/data/node/456/properties',
                          'property': 'http://foo/db/data/node/456/property/{key}',
                          'traverse': 'http://foo/db/data/node/456/traverse/{returnType}'
                        }")
                }
            })
            {
                var graphClient = testHarness.CreateAndConnectGraphClient();
                var node = graphClient.Get<TestNodeWithEnum>((NodeReference)456);

                Assert.AreEqual(456, node.Reference.Id);
                Assert.AreEqual("foo", node.Data.Foo);
                Assert.AreEqual(TestEnum.Value1, node.Data.Status);
            }
        }
开发者ID:Winsto,项目名称:Neo4jClient,代码行数:33,代码来源:GetNodeTests.cs

示例3: ShouldReturnNodeDataForLongId

        public void ShouldReturnNodeDataForLongId()
        {
            using (var testHarness = new RestTestHarness
            {
                {
                    MockRequest.Get("/node/21484836470"),
                    MockResponse.Json(HttpStatusCode.OK,
                        @"{ 'self': 'http://foo/db/data/node/21484836470',
                          'data': { 'Foo': 'foo',
                                    'Bar': 'bar',
                                    'Baz': 'baz'
                          },
                          'create_relationship': 'http://foo/db/data/node/21484836470/relationships',
                          'all_relationships': 'http://foo/db/data/node/21484836470/relationships/all',
                          'all_typed relationships': 'http://foo/db/data/node/21484836470/relationships/all/{-list|&|types}',
                          'incoming_relationships': 'http://foo/db/data/node/21484836470/relationships/in',
                          'incoming_typed relationships': 'http://foo/db/data/node/21484836470/relationships/in/{-list|&|types}',
                          'outgoing_relationships': 'http://foo/db/data/node/21484836470/relationships/out',
                          'outgoing_typed relationships': 'http://foo/db/data/node/21484836470/relationships/out/{-list|&|types}',
                          'properties': 'http://foo/db/data/node/21484836470/properties',
                          'property': 'http://foo/db/data/node/21484836470/property/{key}',
                          'traverse': 'http://foo/db/data/node/21484836470/traverse/{returnType}'
                        }")
                }
            })
            {
                var graphClient = testHarness.CreateAndConnectGraphClient();
                var node = graphClient.Get<TestNode>((NodeReference)21484836470);

                Assert.AreEqual(21484836470, node.Reference.Id);
                Assert.AreEqual("foo", node.Data.Foo);
                Assert.AreEqual("bar", node.Data.Bar);
                Assert.AreEqual("baz", node.Data.Baz);
            }
        }
开发者ID:albumprinter,项目名称:Neo4jClient,代码行数:35,代码来源:GetNodeTests.cs

示例4: GraphClientFactoryUseCase

        public void GraphClientFactoryUseCase()
        {
            const string queryText = @"MATCH (d) RETURN d";

            var cypherQuery = new CypherQuery(queryText, null, CypherResultMode.Set, CypherResultFormat.Rest);
            var cypherApiQuery = new CypherApiQuery(cypherQuery);

            using (var testHarness = new RestTestHarness
            {
                { MockRequest.Get("/"), MockResponse.NeoRoot() },
                { MockRequest.PostObjectAsJson("/cypher", cypherApiQuery), new MockResponse { StatusCode = HttpStatusCode.OK } }
            })
            {
                var httpClient = testHarness.GenerateHttpClient(testHarness.BaseUri);

                var executeConfiguration = new ExecutionConfiguration
                {
                    HttpClient = httpClient,
                    UserAgent =
                        string.Format("Neo4jClient/{0}", typeof(NeoServerConfiguration).Assembly.GetName().Version),
                    UseJsonStreaming = true,
                    JsonConverters = GraphClient.DefaultJsonConverters
                };

                var configuration = NeoServerConfiguration.GetConfiguration(new Uri(testHarness.BaseUri), null, null, executeConfiguration);

                var factory = new GraphClientFactory(configuration);

                using (var client = factory.Create(httpClient))
                {
                    client.Cypher.Match("(d)").Return<object>("d").ExecuteWithoutResults();
                }
            }
        }
开发者ID:albumprinter,项目名称:Neo4jClient,代码行数:34,代码来源:FactoryTests.cs

示例5: ShouldReturnEmptyEnumerableForNullResult

        public void ShouldReturnEmptyEnumerableForNullResult()
        {
            //Arrange
            const string gremlinQueryExpected = "foo bar query";
            var query = new GremlinApiQuery(gremlinQueryExpected, null);

            using (var testHarness = new RestTestHarness
                {
                    {
                        MockRequest.PostObjectAsJson("/ext/GremlinPlugin/graphdb/execute_script", query),
                        MockResponse.Json(HttpStatusCode.OK, @"[]")
                    }
                })
            {
                var graphClient = (GraphClient)testHarness.CreateAndConnectGraphClient();

                //Act
                var nodes = graphClient
                    .ExecuteGetAllRelationshipsGremlin(gremlinQueryExpected, null)
                    .ToList();

                //Assert
                Assert.AreEqual(0, nodes.Count());
            }
        }
开发者ID:Winsto,项目名称:Neo4jClient,代码行数:25,代码来源:ExecuteGetAllRelationshipsGremlinTests.cs

示例6: ShouldCreateIndex

        public void ShouldCreateIndex(
            IndexFor indexFor,
            IndexProvider indexProvider,
            IndexType indexType,
            string createEndpoint,
            string createJson)
        {
            //Arrange
            using (var testHarness = new RestTestHarness
            {
                {
                    MockRequest.PostJson(createEndpoint, createJson),
                    MockResponse.Http(201)
                }
            })
            {
                var graphClient = testHarness.CreateAndConnectGraphClient();

                var indexConfiguration = new IndexConfiguration
                {
                    Provider = indexProvider,
                    Type = indexType
                };
                graphClient.CreateIndex("foo", indexConfiguration, indexFor);
            }
        }
开发者ID:albumprinter,项目名称:Neo4jClient,代码行数:26,代码来源:CreateIndexTests.cs

示例7: ShouldUpdatePayload

        public void ShouldUpdatePayload()
        {
            using (var testHarness = new RestTestHarness
            {
                {
                    MockRequest.Get("/relationship/456/properties"),
                    MockResponse.Json(HttpStatusCode.OK, "{ 'Foo': 'foo', 'Bar': 'bar', 'Baz': 'baz' }")
                },
                {
                    MockRequest.PutObjectAsJson(
                        "/relationship/456/properties",
                        new TestPayload { Foo = "fooUpdated", Bar = "bar", Baz = "bazUpdated" }),
                    MockResponse.Http((int)HttpStatusCode.NoContent)
                }
            })
            {
                var graphClient = testHarness.CreateAndConnectGraphClient();

                graphClient.Update(
                    new RelationshipReference<TestPayload>(456),
                    payloadFromDb =>
                        {
                            payloadFromDb.Foo = "fooUpdated";
                            payloadFromDb.Baz = "bazUpdated";
                        }
                    );
            }
        }
开发者ID:albumprinter,项目名称:Neo4jClient,代码行数:28,代码来源:UpdateRelationshipTests.cs

示例8: ShouldSendCommandAndNotCareAboutResults

        public void ShouldSendCommandAndNotCareAboutResults()
        {
            // Arrange
            const string queryText = @"START d=node({p0}), e=node({p1}) CREATE UNIQUE d-[:foo]->e";
            var parameters = new Dictionary<string, object>
            {
                {"p0", 215},
                {"p1", 219}
            };

            var cypherQuery = new CypherQuery(queryText, parameters, CypherResultMode.Set);
            var cypherApiQuery = new CypherApiQuery(cypherQuery);

            using (var testHarness = new RestTestHarness
            {
                {
                    MockRequest.PostObjectAsJson("/cypher", cypherApiQuery),
                    MockResponse.Http((int)HttpStatusCode.OK)
                }
            })
            {
                var graphClient = testHarness.CreateAndConnectGraphClient();

                //Act
                graphClient.ExecuteCypher(cypherQuery);
            }
        }
开发者ID:Winsto,项目名称:Neo4jClient,代码行数:27,代码来源:ExecuteCypherTests.cs

示例9: ReturnsCorrectError_WhenTransactionIsAutomaticallyRolledBack_ViaNeo4j_2_2_6_Plus

 //https://github.com/Readify/Neo4jClient/issues/127
 public void ReturnsCorrectError_WhenTransactionIsAutomaticallyRolledBack_ViaNeo4j_2_2_6_Plus([Values(RestTestHarness.Neo4jVersion.Neo226/*, RestTestHarness.Neo4jVersion.Neo23*/)] RestTestHarness.Neo4jVersion version)
 {
     /* In 2.2.6 ClientErrors (Constraint Violations etc) were changed to Automatically rollback. This created a 404 error when *we* tried to rollback on an error, as the transaction no longer existed. */
     var initTransactionRequest = MockRequest.PostJson("/transaction", @"{
         '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, TransactionRestResponseHelper.GenerateCypherErrorResponse(1, "{\"code\":\"Neo.ClientError.Schema.ConstraintViolation\",\"message\":\"Node 19572 already exists with label User and property.\"}"), "http://foo/db/data/transaction/1")
         },
         {
             rollbackTransactionRequest, MockResponse.Json(404, "{\"results\":[],\"errors\":[{\"code\":\"Neo.ClientError.Transaction.UnknownId\",\"message\":\"Unrecognized transaction id. Transaction may have timed out and been rolled back.\"}]}")
         }
     })
     {
         var client = testHarness.CreateGraphClient(version);
         client.Connect();
         using (var transaction = client.BeginTransaction())
         {
             client.Cypher.Match("n").Return(n => n.Count()).ExecuteWithoutResults();
         }
     }
 }
开发者ID:albumprinter,项目名称:Neo4jClient,代码行数:26,代码来源:TransactionManagementTests.cs

示例10: ShouldSendCommandAndNotCareAboutResultsAsync

        public void ShouldSendCommandAndNotCareAboutResultsAsync()
        {
            // Arrange
            const string queryText = @"return 1";
            var parameters = new Dictionary<string, object>();

            var cypherQuery = new CypherQuery(queryText, parameters, CypherResultMode.Set);
            var cypherApiQuery = new CypherApiQuery(cypherQuery);

            using (var testHarness = new RestTestHarness
            {
                {
                    MockRequest.PostObjectAsJson("/cypher", cypherApiQuery),
                    MockResponse.Http((int)HttpStatusCode.OK)
                }
            })
            {
                var graphClient = testHarness.CreateAndConnectGraphClient();

                bool raisedEvent = false;

                graphClient.OperationCompleted += (sender, e) => { raisedEvent = true; };

                //Act
                var task = graphClient.ExecuteCypherAsync(cypherQuery);
                task.Wait();

                Assert.IsTrue(raisedEvent, "Raised OperationCompleted");
            }
        }
开发者ID:Winsto,项目名称:Neo4jClient,代码行数:30,代码来源:ExecuteCypherTests.cs

示例11: RootNodeShouldHaveReferenceBackToClient

 public void RootNodeShouldHaveReferenceBackToClient()
 {
     using (var testHarness = new RestTestHarness())
     {
         var client = testHarness.CreateAndConnectGraphClient();
         var rootNode = client.RootNode;
         Assert.AreEqual(client, ((IGremlinQuery) rootNode).Client);
     }
 }
开发者ID:Winsto,项目名称:Neo4jClient,代码行数:9,代码来源:RootNodeTests.cs

示例12: BeginTransactionShouldFailWithLower20Versions

 public void BeginTransactionShouldFailWithLower20Versions()
 {
     using (var testHarness = new RestTestHarness())
     {
         var client = testHarness.CreateGraphClient(false);
         client.Connect();
         client.BeginTransaction();
     }
 }
开发者ID:neildobson71,项目名称:Neo4jClient,代码行数:9,代码来源:TransactionManagementTests.cs

示例13: BeginTransactionShouldFailWithLower20Versions

 public void BeginTransactionShouldFailWithLower20Versions()
 {
     using (var testHarness = new RestTestHarness())
     {
         var client = testHarness.CreateGraphClient(RestTestHarness.Neo4jVersion.Neo19);
         client.Connect();
         Assert.That(() => client.BeginTransaction(), Throws.TypeOf<NotSupportedException>());
     }
 }
开发者ID:Readify,项目名称:Neo4jClient,代码行数:9,代码来源:TransactionManagementTests.cs

示例14: ShouldDeserializePathsResultAsSetBased

        [Test] public void ShouldDeserializePathsResultAsSetBased()
        {
            // Arrange
            const string queryText = @"START d=node({p0}), e=node({p1})
                                        MATCH p = allShortestPaths( d-[*..15]-e )
                                        RETURN p";

            var parameters = new Dictionary<string, object>
                {
                    {"p0", 215},
                    {"p1", 219}
                };

            var cypherQuery = new CypherQuery(queryText, parameters, CypherResultMode.Set, CypherResultFormat.Rest);
            var cypherApiQuery = new CypherApiQuery(cypherQuery);

            using (var testHarness = new RestTestHarness
                {
                    {
                    MockRequest.PostObjectAsJson("/cypher", cypherApiQuery),
                    MockResponse.Json(HttpStatusCode.OK,
                    @"{
                              'data' : [ [ {
                                'start' : 'http://foo/db/data/node/215',
                                'nodes' : [ 'http://foo/db/data/node/215', 'http://foo/db/data/node/0', 'http://foo/db/data/node/219' ],
                                'length' : 2,
                                'relationships' : [ 'http://foo/db/data/relationship/247', 'http://foo/db/data/relationship/257' ],
                                'end' : 'http://foo/db/data/node/219'
                              } ], [ {
                                'start' : 'http://foo/db/data/node/215',
                                'nodes' : [ 'http://foo/db/data/node/215', 'http://foo/db/data/node/1', 'http://foo/db/data/node/219' ],
                                'length' : 2,
                                'relationships' : [ 'http://foo/db/data/relationship/248', 'http://foo/db/data/relationship/258' ],
                                'end' : 'http://foo/db/data/node/219'
                              } ] ],
                              'columns' : [ 'p' ]
                            }")
                    }
                })
            {
                var graphClient = testHarness.CreateAndConnectGraphClient();

                //Act
                var results = graphClient
                    .ExecuteGetCypherResults<PathsResult>(cypherQuery)
                    .ToArray();

                //Assert
                Assert.IsInstanceOf<IEnumerable<PathsResult>>(results);
                Assert.AreEqual(results.First().Length, 2);
                Assert.AreEqual(results.First().Start, "http://foo/db/data/node/215");
                Assert.AreEqual(results.First().End, "http://foo/db/data/node/219");
                Assert.AreEqual(results.Skip(1).First().Length, 2);
                Assert.AreEqual(results.Skip(1).First().Start, "http://foo/db/data/node/215");
                Assert.AreEqual(results.Skip(1).First().End, "http://foo/db/data/node/219");
            }
        }
开发者ID:KodrAus,项目名称:Neo4jClient,代码行数:57,代码来源:ExecuteGetCypherResultsTests.cs

示例15: RootNode_ShouldReturnReferenceNode

        public void RootNode_ShouldReturnReferenceNode()
        {
            using (var testHarness = new RestTestHarness())
            {
                var graphClient = testHarness.CreateAndConnectGraphClient();

                Assert.IsNotNull(graphClient.RootNode);
                Assert.AreEqual(123, graphClient.RootNode.Id);
            }
        }
开发者ID:neildobson71,项目名称:Neo4jClient,代码行数:10,代码来源:ConnectTests.cs


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