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


C# RestTestHarness.GenerateHttpClient方法代码示例

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


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

示例1: 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

示例2: ShouldThrowExceptionIfRootApiIsNotDefined

        public void ShouldThrowExceptionIfRootApiIsNotDefined()
        {
            using (var testHarness = new RestTestHarness
            {
                { MockRequest.Get("/"), 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
                };

                NeoServerConfiguration.GetConfiguration(new Uri(testHarness.BaseUri), null, null, executeConfiguration);
            }
        }
开发者ID:albumprinter,项目名称:Neo4jClient,代码行数:21,代码来源:FactoryTests.cs

示例3: ShouldParseRootApiResponseFromAuthenticatedConnection

 public void ShouldParseRootApiResponseFromAuthenticatedConnection()
 {
     using (var testHarness = new RestTestHarness()
     {
         { MockRequest.Get(""), MockResponse.NeoRoot() }
     })
     {
         var httpClient = testHarness.GenerateHttpClient("http://foo/db/data");
         var graphClient = new GraphClient(new Uri("http://username:[email protected]/db/data"), httpClient);
         graphClient.Connect();
         Assert.AreEqual("/node", graphClient.RootApiResponse.Node);
     }
 }
开发者ID:neildobson71,项目名称:Neo4jClient,代码行数:13,代码来源:ConnectTests.cs

示例4: ExecuteMultipleStatementInOneRequestHttpRequest

        public void ExecuteMultipleStatementInOneRequestHttpRequest()
        {
            const string headerName = "MyTestHeader";
            const string headerValue = "myTestHeaderValue";
            var customHeaders = new NameValueCollection { {headerName, headerValue} };
            

            var initTransactionRequest = MockRequest.PostJson("/transaction", @"{
                'statements': [{'statement': 'MATCH n\r\nRETURN count(n)', 'resultDataContents':[], 'parameters': {}}, {'statement': 'MATCH t\r\nRETURN count(t)', 'resultDataContents':[], 'parameters': {}}]}");
            var commitRequest = MockRequest.PostJson("/transaction/1/commit", @"{'statements': []}");
            using (var testHarness = new RestTestHarness
            {
                {
                    initTransactionRequest,
                    MockResponse.Json(201, TransactionRestResponseHelper.GenerateInitTransactionResponse(1), "http://foo/db/data/transaction/1")
                },
                {
                    commitRequest, MockResponse.Json(200, @"{'results':[], 'errors':[] }")
                }
            })
            {
                var response = MockResponse.NeoRoot20();
                testHarness.Add(MockRequest.Get(""), response);
                var httpClient = testHarness.GenerateHttpClient("http://foo/db/data");
                testHarness.CreateAndConnectTransactionalGraphClient();
                ITransactionalGraphClient client = new GraphClient(new Uri("http://foo/db/data"), httpClient);
                client.Connect();
                using (var transaction = client.BeginTransaction())
                {
                    // dummy query to generate request
                    var rawClient = client as IRawGraphClient;
                    if (rawClient == null)
                    {
                        Assert.Fail("ITransactionalGraphClient is not IRawGraphClient");
                    }

                    var queries = new List<CypherQuery>()
                    {
                        client.Cypher
                            .Match("n")
                            .Return(n => n.Count())
                            .Query,
                        client.Cypher
                            .Match("t")
                            .Return(t => t.Count())
                            .Query
                    };
                    httpClient.ClearReceivedCalls();
                    rawClient.ExecuteMultipleCypherQueriesInTransaction(queries, customHeaders);
                    transaction.Commit();

                    var calls = httpClient.ReceivedCalls().ToList();
                    Assert.IsNotEmpty(calls);

                    HttpRequestMessage requestMessage = null;

                    foreach (var call in calls)
                    {
                        if (call.GetArguments().Single().GetType() == typeof (HttpRequestMessage))
                        {
                            requestMessage = (HttpRequestMessage) call.GetArguments().Single();
                        }
                    }

                    Assert.IsNotNull(requestMessage);

                    var customHeader = requestMessage.Headers.Single(h => h.Key == headerName);
                    Assert.IsNotNull(customHeader);
                    Assert.AreEqual(headerValue, customHeader.Value.Single());
                }
            }
        }
开发者ID:meshr-net,项目名称:Neo4jClient,代码行数:72,代码来源:QueriesInTransactionTests.cs

示例5: DoesntSetHeaders_WhenNotSet

        public void DoesntSetHeaders_WhenNotSet()
        {
            const string queryText = "MATCH n SET n.Value = 'value'";

            var cypherQuery = new CypherQuery(queryText, new Dictionary<string, object>(), CypherResultMode.Set);
            var cypherApiQuery = new CypherApiQuery(cypherQuery);

            using (var testHarness = new RestTestHarness
            {
                {
                    MockRequest.Get(""),
                    MockResponse.NeoRoot()
                },
                {
                    MockRequest.PostObjectAsJson("/cypher", cypherApiQuery),
                    MockResponse.Http((int) HttpStatusCode.OK)
                }
            })
            {
                var httpClient = testHarness.GenerateHttpClient(testHarness.BaseUri);
                var graphClient = new GraphClient(new Uri(testHarness.BaseUri), httpClient);
                graphClient.Connect();

                httpClient.ClearReceivedCalls();
                ((IRawGraphClient)graphClient).ExecuteCypher(cypherQuery);

                var call = httpClient.ReceivedCalls().Single();
                var requestMessage = (HttpRequestMessage)call.GetArguments()[0];
                Assert.IsFalse(requestMessage.Headers.Any(h => h.Key == "max-execution-time"));
            }
        }
开发者ID:albumprinter,项目名称:Neo4jClient,代码行数:31,代码来源:ExecuteCypherTests.cs

示例6: SendsCommandWithCustomHeaders

        public void SendsCommandWithCustomHeaders()
        {
            const string queryText = "MATCH n SET n.Value = 'value'";
            const int expectedMaxExecutionTime = 100;
            const string headerName = "MyTestHeader";
            const string headerValue = "myTestHeaderValue";
            var customHeaders = new NameValueCollection();
            customHeaders.Add(headerName, headerValue);

            var cypherQuery = new CypherQuery(queryText, new Dictionary<string, object>(), CypherResultMode.Set, CypherResultFormat.DependsOnEnvironment, maxExecutionTime: expectedMaxExecutionTime, customHeaders: customHeaders);
            
            var cypherApiQuery = new CypherApiQuery(cypherQuery);

            using (var testHarness = new RestTestHarness
            {
                {
                    MockRequest.Get(""),
                    MockResponse.NeoRoot()
                },
                {
                    MockRequest.PostObjectAsJson("/cypher", cypherApiQuery),
                    MockResponse.Http((int) HttpStatusCode.OK)
                }
            })
            {
                var httpClient = testHarness.GenerateHttpClient(testHarness.BaseUri);
                var graphClient = new GraphClient(new Uri(testHarness.BaseUri), httpClient);
                graphClient.Connect();

                httpClient.ClearReceivedCalls();
                ((IRawGraphClient)graphClient).ExecuteCypher(cypherQuery);

                var call = httpClient.ReceivedCalls().Single();
                var requestMessage = (HttpRequestMessage)call.GetArguments()[0];
                var maxExecutionTimeHeader = requestMessage.Headers.Single(h => h.Key == "max-execution-time");
                Assert.AreEqual(expectedMaxExecutionTime.ToString(CultureInfo.InvariantCulture), maxExecutionTimeHeader.Value.Single());
                var customHeader = requestMessage.Headers.Single(h => h.Key == headerName);
                Assert.IsNotNull(customHeader);
                Assert.AreEqual(headerValue, customHeader.Value.Single());
            }
        }
开发者ID:albumprinter,项目名称:Neo4jClient,代码行数:41,代码来源:ExecuteCypherTests.cs

示例7: DoesntSendMaxExecutionTime_WhenNotAddedToQuery

        public void DoesntSendMaxExecutionTime_WhenNotAddedToQuery()
        {
            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);
            var cypherApiQuery = new CypherApiQuery(cypherQuery);

            using (var testHarness = new RestTestHarness
            {
                {
                    MockRequest.Get(""),
                    MockResponse.NeoRoot()
                },
                {
                    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 httpClient = testHarness.GenerateHttpClient(testHarness.BaseUri);
                var graphClient = new GraphClient(new Uri(testHarness.BaseUri), httpClient);
                graphClient.Connect();

                httpClient.ClearReceivedCalls();
                ((IRawGraphClient)graphClient).ExecuteGetCypherResults<object>(cypherQuery);

                var call = httpClient.ReceivedCalls().Single();
                var requestMessage = (HttpRequestMessage)call.GetArguments()[0];
                Assert.IsFalse(requestMessage.Headers.Any(h => h.Key == "max-execution-time"));
            }
        }
开发者ID:albumprinter,项目名称:Neo4jClient,代码行数:55,代码来源:ExecuteGetCypherResultsTests.cs

示例8: SendsCommandWithCorrectTimeout

        public void SendsCommandWithCorrectTimeout()
        {
            const int expectedMaxExecutionTime = 100;

            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.Transactional ,maxExecutionTime: expectedMaxExecutionTime);
            var cypherApiQuery = new CypherApiQuery(cypherQuery);

            using (var testHarness = new RestTestHarness
            {
                {
                    MockRequest.Get(""),
                    MockResponse.NeoRoot()
                },
                {
                    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 httpClient = testHarness.GenerateHttpClient(testHarness.BaseUri);
                var graphClient = new GraphClient(new Uri(testHarness.BaseUri), httpClient);
                graphClient.Connect();

                httpClient.ClearReceivedCalls();
                ((IRawGraphClient)graphClient).ExecuteGetCypherResults<object>(cypherQuery);

                var call = httpClient.ReceivedCalls().Single();
                var requestMessage = (HttpRequestMessage)call.GetArguments()[0];
                var maxExecutionTimeHeader = requestMessage.Headers.Single(h => h.Key == "max-execution-time");
                Assert.AreEqual(expectedMaxExecutionTime.ToString(CultureInfo.InvariantCulture), maxExecutionTimeHeader.Value.Single());
            }
        }
开发者ID:albumprinter,项目名称:Neo4jClient,代码行数:59,代码来源:ExecuteGetCypherResultsTests.cs


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