Esempio n. 1
0
                public async Task ReturnsQueryStats_WhenNotInTransaction()
                {
                    var          response  = MockResponse.Json(200, @"{
            'results' : [ {
                'columns' : [ 'id(n)' ],
                'data' : [ {
                    'row' : [ 4 ],
                    'meta' : [ null ]
                } ],
                'stats' : {
                    'contains_updates' : true,
                    'nodes_created' : 1,
                    'nodes_deleted' : 0,
                    'properties_set' : 0,
                    'relationships_created' : 0,
                    'relationship_deleted' : 0,
                    'labels_added' : 0,
                    'labels_removed' : 0,
                    'indexes_added' : 0,
                    'indexes_removed' : 0,
                    'constraints_added' : 0,
                    'constraints_removed' : 0,
                    'contains_system_updates' : false,
                    'system_updates' : 0
                }
            } ],
            'errors' : [ ]
        }
        ");
                    const string queryText = @"MATCH (n) RETURN id(n)";

                    var cypherQuery         = new CypherQuery(queryText, null, CypherResultMode.Set, CypherResultFormat.Rest, "neo4j", includeQueryStats: true);
                    var transactionApiQuery = new CypherStatementList {
                        new CypherTransactionStatement(cypherQuery)
                    };

                    using (var testHarness = new RestTestHarness
                    {
                        { MockRequest.PostObjectAsJson("/transaction/commit", transactionApiQuery), response }
                    })
                    {
                        var graphClient = await testHarness.CreateAndConnectGraphClient();

                        var        completedRaised = false;
                        QueryStats stats           = null;
                        graphClient.OperationCompleted += (o, e) =>
                        {
                            stats           = e.QueryStats;
                            completedRaised = true;
                        };

                        var results = await graphClient.ExecuteGetCypherResultsAsync <int>(cypherQuery);

                        results.First().Should().Be(4);

                        completedRaised.Should().BeTrue();
                        stats.Should().NotBeNull();
                        stats.NodesCreated.Should().Be(1);
                    }
                }
Esempio n. 2
0
                public async Task ReturnsQueryStats_WhenInTransaction()
                {
                    var          response = MockResponse.Json(201, @"{
    'results': [
        {
            'columns': [
                'id(n)'
            ],
            'data': [
                {
                    'row': [
                        4
                    ],
                    'meta': [
                        null
                    ]
                }
            ],
            'stats': {
                'contains_updates': false,
                'nodes_created': 0,
                'nodes_deleted': 0,
                'properties_set': 0,
                'relationships_created': 0,
                'relationship_deleted': 0,
                'labels_added': 0,
                'labels_removed': 0,
                'indexes_added': 0,
                'indexes_removed': 0,
                'constraints_added': 0,
                'constraints_removed': 0,
                'contains_system_updates': false,
                'system_updates': 0
            }
        }
    ],
    'errors': [],
    'commit': 'http://*****:*****@"{
  'statements': [
    {
      'statement': 'MATCH (n)\r\nRETURN id(n)',
      'resultDataContents': [],
      'parameters': {},
      'includeStats': true
    }
  ]
}");
                    var          rollbackTransactionRequest = MockRequest.Delete($"/db/{database}/tx/1");

                    using (var testHarness = new RestTestHarness(false, "http://*****:*****@"{'results':[], 'errors':[] }") }
                    })
                    {
                        var graphClient = await testHarness.CreateAndConnectTransactionalGraphClient(RestTestHarness.Neo4jVersion.Neo40);

                        var        completedRaised = false;
                        QueryStats stats           = null;
                        graphClient.OperationCompleted += (o, e) =>
                        {
                            stats           = e.QueryStats;
                            completedRaised = true;
                        };

                        using (var tx = graphClient.BeginTransaction())
                        {
                            var query = graphClient.Cypher.WithQueryStats.Match("(n)").Return(n => n.Id());
                            query.Query.IncludeQueryStats.Should().BeTrue();

                            await query.ExecuteWithoutResultsAsync();

                            completedRaised.Should().BeTrue();
                            stats.Should().NotBeNull();
                        }
                    }
                }