public void WhenAsyncCommandFails_ShouldNotRaiseCompleted() { // 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.Throws() } }) { var graphClient = testHarness.CreateAndConnectGraphClient(); bool raisedEvent = false; graphClient.OperationCompleted += (sender, e) => { raisedEvent = true; }; //Act var task = graphClient.ExecuteCypherAsync(cypherQuery) .ContinueWith(t => { Assert.True(t.IsFaulted); Assert.IsAssignableFrom <MockResponseThrowsException>(t.Exception.Flatten().InnerException); }); task.Wait(); Assert.False(raisedEvent, "Raised OperationCompleted"); } }
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"; } ); } }
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.True(raisedEvent, "Raised OperationCompleted"); } }
public void EmptyCollectionShouldDeserializeCorrectly() { const string queryText = @"RETURN [] AS p"; var cypherQuery = new CypherQuery(queryText, new Dictionary <string, object>(), CypherResultMode.Set, CypherResultFormat.Rest); var cypherApiQuery = new CypherApiQuery(cypherQuery); using (var testHarness = new RestTestHarness { { MockRequest.PostObjectAsJson("/cypher", cypherApiQuery), MockResponse.Json(HttpStatusCode.OK, @"{'columns' : [ 'p' ], 'data' : [[ ]]}") } }) { var graphClient = testHarness.CreateAndConnectGraphClient(); var results = graphClient .ExecuteGetCypherResults <PathsResult>(cypherQuery) .ToArray(); Assert.Empty(results); } }
public async Task EmptyCollectionShouldDeserializeCorrectly() { const string queryText = @"RETURN [] AS p"; var cypherQuery = new CypherQuery(queryText, new Dictionary <string, object>(), CypherResultMode.Set, CypherResultFormat.Rest, "neo4j"); var cypherApiQuery = new CypherStatementList { new CypherTransactionStatement(cypherQuery) }; using (var testHarness = new RestTestHarness { { MockRequest.PostObjectAsJson("/transaction/commit", cypherApiQuery), MockResponse.Json(HttpStatusCode.OK, @"{'results': [{'columns' : [ 'p' ], 'data' : []}]}") } }) { var graphClient = await testHarness.CreateAndConnectGraphClient(); var results = (await graphClient .ExecuteGetCypherResultsAsync <PathsResult>(cypherQuery)) .ToArray(); Assert.Empty(results); } }
public void ShouldThrowExceptionIfHttpCodeIsNot201( IndexFor indexFor, IndexProvider indexProvider, IndexType indexType, string createEndpoint, string createJson) { //Arrange using (var testHarness = new RestTestHarness { { MockRequest.PostJson(createEndpoint, createJson), MockResponse.Http(500) } }) { var graphClient = testHarness.CreateAndConnectGraphClient(); var indexConfiguration = new IndexConfiguration { Provider = indexProvider, Type = indexType }; Assert.Throws <Exception>(() => graphClient.CreateIndex("foo", indexConfiguration, indexFor)); } }
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 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"; } ); } }
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, CypherResultFormat.Rest); 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); } }
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"); } }
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); } }
public void ShouldReturnAttachedRelationshipReference() { using (var testHarness = new RestTestHarness { { MockRequest.PostJson("/node/81/relationships", @"{ 'to': 'http://foo/db/data/node/81', 'type': 'TEST_RELATIONSHIP' }"), MockResponse.Json(HttpStatusCode.Created, @"{ 'extensions' : { }, 'start' : 'http://foo/db/data/node/81', 'property' : 'http://foo/db/data/relationship/38/properties/{key}', 'self' : 'http://foo/db/data/relationship/38', 'properties' : 'http://foo/db/data/relationship/38/properties', 'type' : 'TEST_RELATIONSHIP', 'end' : 'http://foo/db/data/node/80', 'data' : { } }") } }) { var graphClient = testHarness.CreateAndConnectGraphClient(); var testRelationship = new TestRelationship(81); var relationshipReference = graphClient.CreateRelationship(new NodeReference <TestNode>(81), testRelationship); Assert.AreEqual(graphClient, ((IAttachedReference)relationshipReference).Client); } }
public async Task 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, CypherResultFormat.Rest, "neo4j"); var transactionApiQuery = new CypherStatementList { new CypherTransactionStatement(cypherQuery) }; using (var testHarness = new RestTestHarness { { MockRequest.PostObjectAsJson("/transaction/commit", transactionApiQuery), MockResponse.Http((int)HttpStatusCode.OK) } }) { var graphClient = await testHarness.CreateAndConnectGraphClient(); //Act await graphClient.ExecuteCypherAsync(cypherQuery); } }
public async Task WhenExecuteCypherFails_ShouldRaiseCompletedWithException() { // Arrange const string queryText = @"bad cypher"; var parameters = new Dictionary <string, object>(); var cypherQuery = new CypherQuery(queryText, parameters, CypherResultMode.Set, "neo4j"); var transactionApiQuery = new CypherStatementList { new CypherTransactionStatement(cypherQuery) }; using (var testHarness = new RestTestHarness { { MockRequest.PostObjectAsJson("/transaction/commit", transactionApiQuery), MockResponse.Throws() } }) { var graphClient = await testHarness.CreateAndConnectGraphClient(); OperationCompletedEventArgs eventArgs = null; graphClient.OperationCompleted += (sender, e) => { eventArgs = e; }; //Act await Assert.ThrowsAsync <MockResponseThrowsException>(async() => { await graphClient.ExecuteCypherAsync(cypherQuery); }); Assert.NotNull(eventArgs); Assert.True(eventArgs.HasException); Assert.Equal(typeof(MockResponseThrowsException), eventArgs.Exception.GetType()); Assert.Equal(-1, eventArgs.ResourcesReturned); } }
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()); } }
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); } }
public void WhenExecuteGetCypherResultsFails_ShouldRaiseCompletedWithException() { // 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.Throws() } }) { var graphClient = testHarness.CreateAndConnectGraphClient(); OperationCompletedEventArgs eventArgs = null; graphClient.OperationCompleted += (sender, e) => { eventArgs = e; }; //Act Assert.Throws <MockResponseThrowsException>(() => { graphClient.ExecuteGetCypherResults <ExecuteGetCypherResultsTests.SimpleResultDto>(cypherQuery); }, "We should expect an exception"); Assert.IsNotNull(eventArgs, "but we should also have received the completion event"); Assert.IsTrue(eventArgs.HasException); Assert.AreEqual(typeof(MockResponseThrowsException), eventArgs.Exception.GetType()); Assert.AreEqual(-1, eventArgs.ResourcesReturned); } }
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 ShouldReturnNodeData() { 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.AreEqual(456, node.Reference.Id); Assert.AreEqual("foo", node.Data.Foo); Assert.AreEqual("bar", node.Data.Bar); Assert.AreEqual("baz", node.Data.Baz); } }
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 async Task ThrowsClientException_WhenGettingErrorResponse() { const string queryText = @"return 1"; var parameters = new Dictionary <string, object>(); var cypherQuery = new CypherQuery(queryText, parameters, CypherResultMode.Set, "neo4j"); var transactionApiQuery = new CypherStatementList { new CypherTransactionStatement(cypherQuery) }; using (var testHarness = new RestTestHarness { { MockRequest.PostObjectAsJson("/transaction/commit", transactionApiQuery), EmptyErrorResponse } }) { var graphClient = await testHarness.CreateAndConnectGraphClient(); //Act var ex = await Assert.ThrowsAsync <ClientException>(async() => await graphClient.ExecuteCypherAsync(cypherQuery)); ex.Code.Should().Be("Error 1"); ex.Message.Should().Be("Unable to do Cypher"); } }
public void WhenExecuteCypherFails_ShouldRaiseCompletedWithException() { // Arrange const string queryText = @"bad cypher"; 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.Throws() } }) { var graphClient = testHarness.CreateAndConnectGraphClient(); OperationCompletedEventArgs eventArgs = null; graphClient.OperationCompleted += (sender, e) => { eventArgs = e; }; //Act Assert.Throws <MockResponseThrowsException>(() => { graphClient.ExecuteCypher(cypherQuery); }); Assert.NotNull(eventArgs); Assert.True(eventArgs.HasException); Assert.Equal(typeof(MockResponseThrowsException), eventArgs.Exception.GetType()); Assert.Equal(-1, eventArgs.ResourcesReturned); } }
public async Task ShouldDeserializeSimpleTableStructure() { // Arrange const string queryText = @" START x = node($p0) MATCH x-[r]->n RETURN type(r) AS RelationshipType, n.Name? AS Name, n.UniqueId? AS UniqueId LIMIT 3"; var cypherQuery = new CypherQuery( queryText, new Dictionary <string, object> { { "p0", 123 } }, CypherResultMode.Projection, CypherResultFormat.Rest, "neo4j"); var cypherApiQuery = new CypherStatementList { new CypherTransactionStatement(cypherQuery) }; using (var testHarness = new RestTestHarness { { MockRequest.PostObjectAsJson("/transaction/commit", cypherApiQuery), MockResponse.Json(HttpStatusCode.OK, @"{ 'data' : [ [ 'HOSTS', 'foo', 44321 ], [ 'LIKES', 'bar', 44311 ], [ 'HOSTS', 'baz', 42586 ] ], 'columns' : [ 'RelationshipType', 'Name', 'UniqueId' ] }") } }) { var graphClient = await testHarness.CreateAndConnectGraphClient(); //Act var results = await graphClient.ExecuteGetCypherResultsAsync <SimpleResultDto>(cypherQuery); //Assert Assert.IsAssignableFrom <IEnumerable <SimpleResultDto> >(results); var resultsArray = results.ToArray(); Assert.Equal(3, resultsArray.Count()); var firstResult = resultsArray[0]; Assert.Equal("HOSTS", firstResult.RelationshipType); Assert.Equal("foo", firstResult.Name); Assert.Equal(44321, firstResult.UniqueId); var secondResult = resultsArray[1]; Assert.Equal("LIKES", secondResult.RelationshipType); Assert.Equal("bar", secondResult.Name); Assert.Equal(44311, secondResult.UniqueId); var thirdResult = resultsArray[2]; Assert.Equal("HOSTS", thirdResult.RelationshipType); Assert.Equal("baz", thirdResult.Name); Assert.Equal(42586, thirdResult.UniqueId); } }
public async Task 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, "neo4j"); var cypherApiQuery = new CypherStatementList { new CypherTransactionStatement(cypherQuery) }; using (var testHarness = new RestTestHarness { { 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 graphClient = await testHarness.CreateAndConnectGraphClient(); //Act var results = (await graphClient .ExecuteGetCypherResultsAsync <PathsResult>(cypherQuery)) .ToArray(); //Assert Assert.IsAssignableFrom <IEnumerable <PathsResult> >(results); Assert.Equal(results.First().Length, 2); Assert.Equal(results.First().Start, "http://foo/db/data/node/215"); Assert.Equal(results.First().End, "http://foo/db/data/node/219"); Assert.Equal(results.Skip(1).First().Length, 2); Assert.Equal(results.Skip(1).First().Start, "http://foo/db/data/node/215"); Assert.Equal(results.Skip(1).First().End, "http://foo/db/data/node/219"); } }
public void ShouldReturnCypher19CapabilitiesForPre20Version() { using (var testHarness = new RestTestHarness()) { var graphClient = testHarness.CreateAndConnectGraphClient(); Assert.Equal(CypherCapabilities.Cypher19, graphClient.CypherCapabilities); } }
public void ShouldSetCypher22CapabilitiesForPost22Version() { using (var testHarness = new RestTestHarness()) { var graphClient = testHarness.CreateAndConnectGraphClient(RestTestHarness.Neo4jVersion.Neo22); Assert.Equal(CypherCapabilities.Cypher22, graphClient.CypherCapabilities); } }
[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"); } }
public void RootNodeShouldHaveReferenceBackToClient() { using (var testHarness = new RestTestHarness()) { var client = testHarness.CreateAndConnectGraphClient(); var rootNode = client.RootNode; Assert.AreEqual(client, ((IGremlinQuery) rootNode).Client); } }
public void RootNodeShouldHaveReferenceBackToClient() { using (var testHarness = new RestTestHarness()) { var client = testHarness.CreateAndConnectGraphClient(); var rootNode = client.RootNode; Assert.Equal(client, ((IGremlinQuery)rootNode).Client); } }
public void ShouldParse15M02Version() { using (var testHarness = new RestTestHarness()) { var graphClient = (GraphClient)testHarness.CreateAndConnectGraphClient(); Assert.Equal("1.5.0.2", graphClient.RootApiResponse.Version.ToString()); } }
[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); 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"); } }
public void RootNodeShouldSupportGremlinQueries() { using (var testHarness = new RestTestHarness()) { var client = testHarness.CreateAndConnectGraphClient(); var rootNode = client.RootNode; Assert.AreEqual("g.v(p0)", ((IGremlinQuery) rootNode).QueryText); Assert.AreEqual(123, ((IGremlinQuery) rootNode).QueryParameters["p0"]); } }
public void RootNode_ShouldReturnReferenceNode() { using (var testHarness = new RestTestHarness()) { var graphClient = testHarness.CreateAndConnectGraphClient(); Assert.NotNull(graphClient.RootNode); Assert.Equal(123, graphClient.RootNode.Id); } }
public void RootNodeShouldSupportGremlinQueries() { using (var testHarness = new RestTestHarness()) { var client = testHarness.CreateAndConnectGraphClient(); var rootNode = client.RootNode; Assert.Equal("g.v(p0)", ((IGremlinQuery)rootNode).QueryText); Assert.Equal(123L, ((IGremlinQuery)rootNode).QueryParameters["p0"]); } }
public void RootNode_ShouldReturnReferenceNode() { using (var testHarness = new RestTestHarness()) { var graphClient = testHarness.CreateAndConnectGraphClient(); Assert.IsNotNull(graphClient.RootNode); Assert.AreEqual(123, graphClient.RootNode.Id); } }
public void ShouldThrowNotSupportedExceptionForIncomingRelationship() { using (var testHarness = new RestTestHarness()) { var client = testHarness.CreateAndConnectGraphClient(); client.CreateRelationship(new NodeReference <TestNode>(5), new TestRelationship(10) { Direction = RelationshipDirection.Incoming }); } }
public void ShouldRetrieveApiEndpoints() { using (var testHarness = new RestTestHarness()) { var graphClient = (GraphClient)testHarness.CreateAndConnectGraphClient(); Assert.AreEqual("/node", graphClient.RootApiResponse.Node); Assert.AreEqual("/index/node", graphClient.RootApiResponse.NodeIndex); Assert.AreEqual("/index/relationship", graphClient.RootApiResponse.RelationshipIndex); Assert.AreEqual("http://foo/db/data/node/123", graphClient.RootApiResponse.ReferenceNode); Assert.AreEqual("/ext", graphClient.RootApiResponse.ExtensionsInfo); } }
public void ShouldParse15M02Version() { using (var testHarness = new RestTestHarness { { MockRequest.Get(""), MockResponse.NeoRoot() } }) { var graphClient = (GraphClient)testHarness.CreateAndConnectGraphClient(); Assert.AreEqual("1.5.0.2", graphClient.ServerVersion.ToString()); } }
public void ShouldRetrieveApiEndpoints() { using (var testHarness = new RestTestHarness()) { var graphClient = (GraphClient)testHarness.CreateAndConnectGraphClient(); Assert.Equal("/node", graphClient.RootApiResponse.Node); Assert.Equal("/index/node", graphClient.RootApiResponse.NodeIndex); Assert.Equal("/index/relationship", graphClient.RootApiResponse.RelationshipIndex); Assert.Equal("http://foo/db/data/node/123", graphClient.RootApiResponse.ReferenceNode); Assert.Equal("/ext", graphClient.RootApiResponse.ExtensionsInfo); } }
public void ShouldThrowConnectionExceptionFor500Response() { using (var testHarness = new RestTestHarness { { MockRequest.Get(""), MockResponse.Http(500) } }) { testHarness.CreateAndConnectGraphClient(); } }
public void ShouldDeleteNodeOnly() { using (var testHarness = new RestTestHarness { { MockRequest.Delete("/node/456"), MockResponse.Http(204) } }) { var graphClient = testHarness.CreateAndConnectGraphClient(); graphClient.Delete(456, DeleteMode.NodeOnly); } }
public void ShouldThrowApplicationExceptionWhenDeleteFails() { using (var testHarness = new RestTestHarness { { MockRequest.Delete("/relationship/456"), MockResponse.Http(404) } }) { var graphClient = testHarness.CreateAndConnectGraphClient(); graphClient.DeleteRelationship(456); } }
public void ShouldDeleteRelationship() { using (var testHarness = new RestTestHarness { { MockRequest.Delete("/relationship/456"), MockResponse.Http(204) } }) { var graphClient = testHarness.CreateAndConnectGraphClient(); graphClient.DeleteRelationship(456); } }
public void ShouldUpdateNode() { 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); graphClient.Update( pocoReference, nodeFromDb => { nodeFromDb.Foo = "fooUpdated"; nodeFromDb.Baz = "bazUpdated"; nodeToUpdate = nodeFromDb; } ); Assert.AreEqual("fooUpdated", nodeToUpdate.Foo); Assert.AreEqual("bazUpdated", nodeToUpdate.Baz); Assert.AreEqual("bar", nodeToUpdate.Bar); } }
public void ShouldThrowExceptionWhenDeleteFails() { using (var testHarness = new RestTestHarness { { MockRequest.Delete("/relationship/456"), MockResponse.Http(404) } }) { var graphClient = testHarness.CreateAndConnectGraphClient(); var ex = Assert.Throws<Exception>(() => graphClient.DeleteRelationship(456)); ex.Message.Should().Be("Unable to delete the relationship. The response status was: 404 NotFound"); } }
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.IsFalse(indexes.Any()); } }
public void ShouldExecuteSilentlyForSuccessfulDelete() { using (var testHarness = new RestTestHarness { { MockRequest.Delete("/index/node/MyIndex"), MockResponse.Http(204) } }) { var graphClient = testHarness.CreateAndConnectGraphClient(); //Act graphClient.DeleteIndex("MyIndex", IndexFor.Node); } }
public void ShouldFailGracefullyWhenGremlinIsNotAvailable() { using (var testHarness = new RestTestHarness { { MockRequest.Get(""), MockResponse.NeoRoot20() } }) { var graphClient = (GraphClient)testHarness.CreateAndConnectGraphClient(); var ex = Assert.Throws<ApplicationException>( () => 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.AreEqual(2, indexes.Count()); var index = indexes.ElementAt(0); Assert.AreEqual("agency24871-clients", index.Key); Assert.AreEqual(true, index.Value.ToLowerCase); Assert.AreEqual("http://localhost:5102/db/data/index/node/agency24871-clients/{key}/{value}", index.Value.Template); Assert.AreEqual("lucene", index.Value.Provider); Assert.AreEqual("fulltext", index.Value.Type); index = indexes.ElementAt(1); Assert.AreEqual("agency36681-clients", index.Key); Assert.AreEqual(false, index.Value.ToLowerCase); Assert.AreEqual("http://localhost:5102/db/data/index/node/agency36681-clients/{key}/{value}", index.Value.Template); Assert.AreEqual("lucene", index.Value.Provider); Assert.AreEqual("exact", index.Value.Type); } }
public void ShouldAcceptQuestionMarkInRelationshipIndexValue() { //Arrange var indexKeyValues = new Dictionary<string, object> { {"BarKey", "foo?bar"} }; var indexEntries = new List<IndexEntry> { new IndexEntry { Name = "my_relationships", KeyValues = indexKeyValues, } }; using (var testHarness = new RestTestHarness { { MockRequest.PostObjectAsJson("/index/relationship/my_relationships", new { key = "BarKey", value = "foo?bar", uri = "http://foo/db/data/relationship/1234" }), MockResponse.Json(HttpStatusCode.Created, @"Location: http://foo/db/data/index/relationship/my_relationships/BarKey/%3f/1234") }, { MockRequest.Delete("/index/relationship/my_relationships/1234"), MockResponse.Http((int) HttpStatusCode.NoContent) } }) { var graphClient = testHarness.CreateAndConnectGraphClient(); //Act var relReference = new RelationshipReference(1234); graphClient.ReIndex(relReference, indexEntries); // Assert Assert.Pass("Success."); } }
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 void ShouldReindexNodeWithIndexEntryContainingSpace() { //Arrange var indexEntries = new List<IndexEntry> { new IndexEntry { Name = "my_nodes", KeyValues = new Dictionary<string, object> { {"FooKey", "the_value with space"} }, } }; using (var testHarness = new RestTestHarness { { MockRequest.PostObjectAsJson("/index/node/my_nodes", new { key = "FooKey", value = "the_value with space", uri = "http://foo/db/data/node/123" }), MockResponse.Json(HttpStatusCode.Created, @"Location: http://foo/db/data/index/node/my_nodes/FooKey/the_value%20with%20space/123") }, { MockRequest.Delete("/index/node/my_nodes/123"), MockResponse.Http((int) HttpStatusCode.NoContent) } }) { var graphClient = testHarness.CreateAndConnectGraphClient(); //Act graphClient.ReIndex((NodeReference)123, indexEntries); // Assert Assert.Pass("Success."); } }
public void ShouldReplaceNode() { var newData = new TestNode { Foo = "foo", Bar = "bar", Baz = "baz" }; using (var testHarness = new RestTestHarness { { MockRequest.PutObjectAsJson("/node/456/properties", newData), MockResponse.Http((int)HttpStatusCode.NoContent) } }) { var graphClient = testHarness.CreateAndConnectGraphClient(); //Act var pocoReference = new NodeReference<TestNode>(456); graphClient.Update(pocoReference, newData); } }
public void SendingNullParametersShouldNotRaiseExceptionWhenExecutingCypher() { 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.PostObjectAsJson("/cypher", cypherApiQuery), MockResponse.Http((int)HttpStatusCode.OK) } }) { var graphClient = testHarness.CreateAndConnectGraphClient(); // execute cypher with "null" parameters graphClient.ExecuteCypher(cypherQuery); } }
public void ShouldReturnListOfRelationshipInstances() { //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, @"[ { 'start' : 'http://127.0.0.1:5118/db/data/node/123', 'data' : { }, 'self' : 'http://127.0.0.1:5118/db/data/relationship/456', 'property' : 'http://127.0.0.1:5118/db/data/relationship/456/properties/{key}', 'properties' : 'http://127.0.0.1:5118/db/data/relationship/456/properties', 'type' : 'KNOWS', 'extensions' : { }, 'end' : 'http://127.0.0.1:5118/db/data/node/789' } ]") } }) { var graphClient = (GraphClient)testHarness.CreateAndConnectGraphClient(); //Act var relationships = graphClient .ExecuteGetAllRelationshipsGremlin(gremlinQueryExpected, null) .ToList(); //Assert Assert.AreEqual(1, relationships.Count()); Assert.AreEqual(456, relationships.ElementAt(0).Reference.Id); Assert.AreEqual(123, relationships.ElementAt(0).StartNodeReference.Id); Assert.AreEqual(789, relationships.ElementAt(0).EndNodeReference.Id); Assert.AreEqual("KNOWS", relationships.ElementAt(0).TypeKey); } }
public void ShouldReturnScalarValue() { //Arrange using (var testHarness = new RestTestHarness { { MockRequest.PostJson( "/ext/GremlinPlugin/graphdb/execute_script", @"{ 'script': 'foo bar query', 'params': {} }"), MockResponse.Json(HttpStatusCode.OK, @"1") } }) { var graphClient = testHarness.CreateAndConnectGraphClient(); //Act var node = graphClient.ExecuteScalarGremlin("foo bar query", null); //Assert Assert.AreEqual(1, int.Parse(node)); } }