public void GetShouldSucceedInSuppressedMode() { var nodeReference = new NodeReference <TestNode>(1); var requests = new List <KeyValuePair <MockRequest, MockResponse> > { new KeyValuePair <MockRequest, MockResponse>( MockRequest.Get("/node/1"), MockResponse.Json(HttpStatusCode.OK, @"{ 'self': 'http://foo/db/data/node/456', 'data': { 'Foo': 'foo' }, 'create_relationship': 'http://foo/db/data/node/1/relationships', 'all_relationships': 'http://foo/db/data/node/1/relationships/all', 'all_typed relationships': 'http://foo/db/data/node/1/relationships/all/{-list|&|types}', 'incoming_relationships': 'http://foo/db/data/node/1/relationships/in', 'incoming_typed relationships': 'http://foo/db/data/node/1/relationships/in/{-list|&|types}', 'outgoing_relationships': 'http://foo/db/data/node/1/relationships/out', 'outgoing_typed relationships': 'http://foo/db/data/node/1/relationships/out/{-list|&|types}', 'properties': 'http://foo/db/data/node/1/properties', 'property': 'http://foo/db/data/node/1/property/{key}', 'traverse': 'http://foo/db/data/node/1/traverse/{returnType}' }") ) }; ExecuteRestMethodUnderTransaction( client => client.Get(nodeReference), TransactionScopeOption.Suppress, requests); }
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.Equal(21484836470, node.Reference.Id); Assert.Equal("foo", node.Data.Foo); Assert.Equal("bar", node.Data.Bar); Assert.Equal("baz", node.Data.Baz); } }
public void ShouldReturnNodeDataAndDeserialzedJsonDatesForDateTimeOffsetNullableType() { using (var testHarness = new RestTestHarness { { MockRequest.Get("/node/456"), MockResponse.Json(HttpStatusCode.OK, @"{ 'self': 'http://foo/db/data/node/456', 'data': { 'DateOffSet': '/Date(1309421746929+0000)/' }, '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 <TestNode>((NodeReference)456); Assert.NotNull(node.Data.DateOffSet); Assert.Equal("2011-06-30 08:15:46Z", node.Data.DateOffSet.Value.ToString("u")); } }
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.Equal(456, node.Reference.Id); Assert.Equal("foo", node.Data.Foo); Assert.Equal(TestEnum.Value1, node.Data.Status); } }
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.False(requestMessage.Headers.Any(h => h.Key == "max-execution-time")); } }
public async Task DoesntSetMaxExecutionTime_WhenNotSet() { const string queryText = "MATCH n SET n.Value = 'value'"; var cypherQuery = new CypherQuery(queryText, new Dictionary <string, object>(), CypherResultMode.Set, "neo4j"); var transactionApiQuery = new CypherStatementList { new CypherTransactionStatement(cypherQuery) }; using (var testHarness = new RestTestHarness { { MockRequest.Get(""), MockResponse.NeoRoot20() }, { MockRequest.PostObjectAsJson("/transaction/commit", transactionApiQuery), MockResponse.Http((int)HttpStatusCode.OK) } }) { var httpClient = testHarness.GenerateHttpClient(testHarness.BaseUri); var graphClient = new GraphClient(new Uri(testHarness.BaseUri), httpClient); await graphClient.ConnectAsync(); httpClient.ClearReceivedCalls(); await((IRawGraphClient)graphClient).ExecuteCypherAsync(cypherQuery); var call = httpClient.ReceivedCalls().Single(); var requestMessage = (HttpRequestMessage)call.GetArguments()[0]; Assert.False(requestMessage.Headers.Any(h => h.Key == "max-execution-time")); } }
private void Request(Dictionary <string, dynamic> headers, Action <MockResponse> responseAction = null) { if (responseAction != null) { responseAction(_request.Get("/", headers)); } }
public void ShouldReturnNodeWithReferenceBackToClient() { using (var testHarness = new RestTestHarness { { MockRequest.Get("/node/456"), MockResponse.Json(HttpStatusCode.OK, @"{ 'self': 'http://foo/db/data/node/456', 'data': { 'Foo': 'foo', 'Bar': 'bar', 'Baz': 'baz' }, '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 <TestNode>((NodeReference)456); Assert.Equal(graphClient, ((IGremlinQuery)node.Reference).Client); } }
public void SendsCommandWithCorrectTimeout() { const string queryText = "MATCH n SET n.Value = 'value'"; const int expectedMaxExecutionTime = 100; var cypherQuery = new CypherQuery(queryText, new Dictionary <string, object>(), CypherResultMode.Set, CypherResultFormat.DependsOnEnvironment, maxExecutionTime: expectedMaxExecutionTime); 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.Equal(expectedMaxExecutionTime.ToString(CultureInfo.InvariantCulture), maxExecutionTimeHeader.Value.Single()); } }
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.Equal(expectedMaxExecutionTime.ToString(CultureInfo.InvariantCulture), maxExecutionTimeHeader.Value.Single()); } }
public async Task 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, "neo4j"); var cypherApiQuery = new CypherStatementList { new CypherTransactionStatement(cypherQuery) }; using (var testHarness = new RestTestHarness { { MockRequest.Get(""), MockResponse.NeoRoot20() }, { MockRequest.PostObjectAsJson("/transaction/commit", 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); await graphClient.ConnectAsync(); httpClient.ClearReceivedCalls(); await((IRawGraphClient)graphClient).ExecuteGetCypherResultsAsync <object>(cypherQuery); var call = httpClient.ReceivedCalls().Single(); var requestMessage = (HttpRequestMessage)call.GetArguments()[0]; Assert.False(requestMessage.Headers.Any(h => h.Key == "max-execution-time")); } }
public void ShouldParse15M02Version() { using (var testHarness = new RestTestHarness { { MockRequest.Get(""), MockResponse.NeoRoot() } }) { var graphClient = (GraphClient)testHarness.CreateAndConnectGraphClient(); Assert.Equal("1.5.0.2", graphClient.ServerVersion.ToString()); } }
public void ShouldRunDelegateForChanges() { var nodeToUpdate = new TestNode { Id = 1, Foo = "foo", Bar = "bar", Baz = "baz" }; using (var testHarness = new RestTestHarness { { MockRequest.Get("/node/456"), MockResponse.Json(HttpStatusCode.OK, @"{ 'self': 'http://foo/db/data/node/456', 'data': { 'Foo': 'foo', 'Bar': 'bar', 'Baz': 'baz' }, '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}' }") }, { MockRequest.PutObjectAsJson("/node/456/properties", nodeToUpdate), MockResponse.Http((int)HttpStatusCode.NoContent) } }) { var graphClient = testHarness.CreateAndConnectGraphClient(); //Act var hasChanged = false; var pocoReference = new NodeReference <TestNode>(456); graphClient.Update( pocoReference, nodeFromDb => { nodeFromDb.Foo = "fooUpdated"; nodeFromDb.Baz = "bazUpdated"; nodeToUpdate = nodeFromDb; }, null, diff => { hasChanged = diff.Any(); } ); Assert.IsTrue(hasChanged); } }
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://*****:*****@foo/db/data"), httpClient); graphClient.Connect(); Assert.Equal("/node", graphClient.RootApiResponse.Node); } }
public void ShouldThrowConnectionExceptionFor500Response() { using (var testHarness = new RestTestHarness { { MockRequest.Get(""), MockResponse.Http(500) } }) { testHarness.CreateAndConnectGraphClient(); } }
public void Should_Route_Root_Apps_Correctly() { var mapping = new KeyValuePair <string, object> [2]; mapping[0] = GetMapForRootRouteTest("/", "root"); mapping[1] = GetMapForRootRouteTest("/foo", "foo"); var mappingDictionary = mapping.ToDictionary(pair => pair.Key, pair => pair.Value); var map = new UrlMap(mappingDictionary); var mock = new MockRequest(map); var res = mock.Get("/foo/bar"); Assert.AreEqual(200, res.Status); Assert.AreEqual("foo", res["X-Position"]); Assert.AreEqual("/bar", res["X-PathInfo"]); Assert.AreEqual("/foo", res["X-ScriptName"]); res = mock.Get("/foo"); Assert.AreEqual(200, res.Status); Assert.AreEqual("foo", res["X-Position"]); Assert.AreEqual(string.Empty, res["X-PathInfo"]); Assert.AreEqual("/foo", res["X-ScriptName"]); res = mock.Get("/bar"); Assert.AreEqual(200, res.Status); Assert.AreEqual("root", res["X-Position"]); Assert.AreEqual("/bar", res["X-PathInfo"]); Assert.AreEqual(string.Empty, res["X-ScriptName"]); res = mock.Get(string.Empty); Assert.AreEqual(200, res.Status); Assert.AreEqual("root", res["X-Position"]); Assert.AreEqual("/", res["X-PathInfo"]); Assert.AreEqual(string.Empty, res["X-ScriptName"]); }
public void ShouldReturnNodeAfterUpdating() { var nodeToUpdate = new TestNode { Foo = "foo", Bar = "bar", Baz = "baz" }; using (var testHarness = new RestTestHarness { { MockRequest.Get("/node/456"), MockResponse.Json(HttpStatusCode.OK, @"{ 'self': 'http://foo/db/data/node/456', 'data': { 'Foo': 'foo', 'Bar': 'bar', 'Baz': 'baz' }, '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}' }") }, { MockRequest.PutObjectAsJson("/node/456/properties", nodeToUpdate), MockResponse.Http((int)HttpStatusCode.NoContent) } }) { var graphClient = testHarness.CreateAndConnectGraphClient(); //Act var pocoReference = new NodeReference <TestNode>(456); var updatedNode = graphClient.Update( pocoReference, nodeFromDb => { nodeFromDb.Foo = "fooUpdated"; nodeFromDb.Baz = "bazUpdated"; }); Assert.AreEqual(pocoReference, updatedNode.Reference); Assert.AreEqual("fooUpdated", updatedNode.Data.Foo); Assert.AreEqual("bazUpdated", updatedNode.Data.Baz); Assert.AreEqual("bar", updatedNode.Data.Bar); } }
public void Should_Catch_Exceptions() { dynamic res = null; var req = new MockRequest(new ShowExceptions(DetachedApplication.Create( env => { throw new InvalidOperationException(); }))); Assert.DoesNotThrow(delegate { res = req.Get("/"); }); Assert.AreEqual(500, res.Status); Assert.IsTrue(res.Body.ToString().Contains("InvalidOperationException")); Assert.IsTrue(res.Body.ToString().Contains("ShowExceptions")); }
public void ShouldThrowConnectionExceptionFor500Response() { using (var testHarness = new RestTestHarness { { MockRequest.Get(""), MockResponse.Http(500) } }) { var ex = Assert.Throws <Exception>(() => testHarness.CreateAndConnectGraphClient()); Assert.Equal("Received an unexpected HTTP status when executing the request.\r\n\r\nThe response status was: 500 InternalServerError", ex.Message); } }
public void ShouldReturnCypher19CapabilitiesForVersion20() { using (var testHarness = new RestTestHarness { { MockRequest.Get(""), MockResponse.NeoRoot20() } }) { var graphClient = testHarness.CreateAndConnectGraphClient(); Assert.Equal(CypherCapabilities.Cypher20, graphClient.CypherCapabilities); } }
public void ShouldNotThrowANotSupportedExceptionForPre15M02DatabaseWhenThereAreNoIndexEntries() { var testNode = new TestNode { Foo = "foo", Bar = "bar", Baz = "baz" }; var batch = new List <BatchStep>(); batch.Add(HttpMethod.Post, "/node", testNode); var testHarness = new RestTestHarness { { MockRequest.Get(""), MockResponse.NeoRootPre15M02() }, { MockRequest.PostObjectAsJson("/batch", batch), MockResponse.Json(HttpStatusCode.OK, @"[{'id':0,'location':'http://foo/db/data/node/760','body':{ 'outgoing_relationships' : 'http://foo/db/data/node/760/relationships/out', 'data' : { 'Foo' : 'foo', 'Bar' : 'bar', 'Baz' : 'baz' }, 'traverse' : 'http://foo/db/data/node/760/traverse/{returnType}', 'all_typed_relationships' : 'http://foo/db/data/node/760/relationships/all/{-list|&|types}', 'self' : 'http://foo/db/data/node/760', 'property' : 'http://foo/db/data/node/760/properties/{key}', 'outgoing_typed_relationships' : 'http://foo/db/data/node/760/relationships/out/{-list|&|types}', 'properties' : 'http://foo/db/data/node/760/properties', 'incoming_relationships' : 'http://foo/db/data/node/760/relationships/in', 'extensions' : { }, 'create_relationship' : 'http://foo/db/data/node/760/relationships', 'paged_traverse' : 'http://foo/db/data/node/760/paged/traverse/{returnType}{?pageSize,leaseTime}', 'all_relationships' : 'http://foo/db/data/node/760/relationships/all', 'incoming_typed_relationships' : 'http://foo/db/data/node/760/relationships/in/{-list|&|types}' },'from':'/node'}]" ) } }; var graphClient = testHarness.CreateAndConnectGraphClient(); graphClient.Create(testNode, null, null); testHarness.AssertRequestConstraintsAreMet(); }
public void ShouldReturnEmptyDictionaryOfIndexesForHttpResponse204() { using (var testHarness = new RestTestHarness { { MockRequest.Get("/index/node"), MockResponse.Http(204) } }) { var graphClient = testHarness.CreateAndConnectGraphClient(); var indexes = graphClient.GetIndexes(IndexFor.Node); Assert.False(indexes.Any()); } }
public void ShouldReturnNullWhenNodeDoesntExist() { using (var testHarness = new RestTestHarness { { MockRequest.Get("/node/456"), MockResponse.Http(404) } }) { var graphClient = testHarness.CreateAndConnectGraphClient(); var node = graphClient.Get <TestNode>((NodeReference)456); Assert.Null(node); } }
public void ShouldFailGracefullyWhenGremlinIsNotAvailable() { using (var testHarness = new RestTestHarness { { MockRequest.Get(""), MockResponse.NeoRoot20() } }) { var graphClient = (GraphClient)testHarness.CreateAndConnectGraphClient(); var ex = Assert.Throws <Exception>( () => graphClient.ExecuteScalarGremlin("foo bar query", null)); Assert.AreEqual(GraphClient.GremlinPluginUnavailable, ex.Message); } }
public bool ShouldReturnIfIndexIsFound( IndexFor indexFor, string indexPath, HttpStatusCode httpStatusCode) { using (var testHarness = new RestTestHarness { { MockRequest.Get(indexPath), MockResponse.Json(httpStatusCode, "") } }) { var graphClient = testHarness.CreateAndConnectGraphClient(); return(graphClient.CheckIndexExists("MyIndex", indexFor)); } }
public void ShouldReturnNodeIndexes() { using (var testHarness = new RestTestHarness { { MockRequest.Get("/index/node"), MockResponse.Json(HttpStatusCode.OK, @"{ 'agency24871-clients' : { 'to_lower_case' : 'true', 'template' : 'http://localhost:5102/db/data/index/node/agency24871-clients/{key}/{value}', '_blueprints:type' : 'MANUAL', 'provider' : 'lucene', 'type' : 'fulltext' }, 'agency36681-clients' : { 'to_lower_case' : 'false', 'template' : 'http://localhost:5102/db/data/index/node/agency36681-clients/{key}/{value}', '_blueprints:type' : 'MANUAL', 'provider' : 'lucene', 'type' : 'exact' } }") } }) { var graphClient = testHarness.CreateAndConnectGraphClient(); var indexes = graphClient.GetIndexes(IndexFor.Node); Assert.Equal(2, indexes.Count()); var index = indexes.ElementAt(0); Assert.Equal("agency24871-clients", index.Key); Assert.Equal(true, index.Value.ToLowerCase); Assert.Equal("http://localhost:5102/db/data/index/node/agency24871-clients/{key}/{value}", index.Value.Template); Assert.Equal("lucene", index.Value.Provider); Assert.Equal("fulltext", index.Value.Type); index = indexes.ElementAt(1); Assert.Equal("agency36681-clients", index.Key); Assert.Equal(false, index.Value.ToLowerCase); Assert.Equal("http://localhost:5102/db/data/index/node/agency36681-clients/{key}/{value}", index.Value.Template); Assert.Equal("lucene", index.Value.Provider); Assert.Equal("exact", index.Value.Type); } }
public void ShouldDeleteAllRelationshipsFirst() { using (var testHarness = new RestTestHarness { { MockRequest.Get("/node/456/relationships/all"), MockResponse.Json(HttpStatusCode.OK, @"[ { 'self': 'http://foo/db/data/relationship/56', 'start': 'http://foo/db/data/node/123', 'end': 'http://foo/db/data/node/456', 'type': 'KNOWS', 'properties': 'http://foo/db/data/relationship/56/properties', 'property': 'http://foo/db/data/relationship/56/properties/{key}', 'data': { 'date': 1270559208258 } }, { 'self': 'http://foo/db/data/relationship/78', 'start': 'http://foo/db/data/node/456', 'end': 'http://foo/db/data/node/789', 'type': 'KNOWS', 'properties': 'http://foo/db/data/relationship/78/properties', 'property': 'http://foo/db/data/relationship/78/properties/{key}', 'data': { 'date': 1270559208258 } } ]") }, { MockRequest.Delete("/relationship/56"), MockResponse.Http(204) }, { MockRequest.Delete("/relationship/78"), MockResponse.Http(204) }, { MockRequest.Delete("/node/456"), MockResponse.Http(204) } }) { var graphClient = testHarness.CreateAndConnectGraphClient(); graphClient.Delete(456, DeleteMode.NodeAndRelationships); } }
public async Task 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, "neo4j", maxExecutionTime: expectedMaxExecutionTime, customHeaders: customHeaders); var transactionApiQuery = new CypherStatementList { new CypherTransactionStatement(cypherQuery) }; using (var testHarness = new RestTestHarness { { MockRequest.Get(""), MockResponse.NeoRoot20() }, { MockRequest.PostObjectAsJson("/transaction/commit", transactionApiQuery), MockResponse.Http((int)HttpStatusCode.OK) } }) { var httpClient = testHarness.GenerateHttpClient(testHarness.BaseUri); var graphClient = new GraphClient(new Uri(testHarness.BaseUri), httpClient); await graphClient.ConnectAsync(); httpClient.ClearReceivedCalls(); await((IRawGraphClient)graphClient).ExecuteCypherAsync(cypherQuery); var call = httpClient.ReceivedCalls().Single(); var requestMessage = (HttpRequestMessage)call.GetArguments()[0]; var maxExecutionTimeHeader = requestMessage.Headers.Single(h => h.Key == "max-execution-time"); Assert.Equal(expectedMaxExecutionTime.ToString(CultureInfo.InvariantCulture), maxExecutionTimeHeader.Value.Single()); var customHeader = requestMessage.Headers.Single(h => h.Key == headerName); Assert.NotNull(customHeader); Assert.Equal(headerValue, customHeader.Value.Single()); } }
public async Task 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 = $"Neo4jClient/{typeof(NeoServerConfiguration).Assembly.GetName().Version}", UseJsonStreaming = true, JsonConverters = GraphClient.DefaultJsonConverters }; await Assert.ThrowsAsync <InvalidOperationException>(async() => await NeoServerConfiguration.GetConfigurationAsync(new Uri(testHarness.BaseUri), null, null, null, null, executeConfiguration)); } }
public void RootNode_ShouldReturnNullReferenceNode_WhenNoReferenceNodeDefined() { using (var testHarness = new RestTestHarness { { MockRequest.Get(""), MockResponse.Json(HttpStatusCode.OK, @"{ 'batch' : 'http://foo/db/data/batch', 'node' : 'http://foo/db/data/node', 'node_index' : 'http://foo/db/data/index/node', 'relationship_index' : 'http://foo/db/data/index/relationship', 'extensions_info' : 'http://foo/db/data/ext', 'extensions' : { } }") } }) { var graphClient = testHarness.CreateAndConnectGraphClient(); Assert.Null(graphClient.RootNode); } }