本文整理汇总了C#中RestTestHarness.Add方法的典型用法代码示例。如果您正苦于以下问题:C# RestTestHarness.Add方法的具体用法?C# RestTestHarness.Add怎么用?C# RestTestHarness.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RestTestHarness
的用法示例。
在下文中一共展示了RestTestHarness.Add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
}
示例2: 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());
}
}
}