Skip to content

Commit

Permalink
Add tests for CallProcedure and CallProcedureAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
haysch committed Jul 27, 2023
1 parent f9b8acb commit 89c039f
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions tests/NRedisStack.Tests/Graph/GraphTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,49 @@ public void TestModulePrefixs()
Assert.NotEqual(graph1.GetHashCode(), graph2.GetHashCode());
}

[Fact]
public void TestCallProcedureDbLabels()
{
var db = redisFixture.Redis.GetDatabase();
db.Execute("FLUSHALL");

const string graphName = "social";

var graph = db.GRAPH();
// Create empty graph, otherwise call procedure will throw exception
graph.Query(graphName, "RETURN 1");

var labels0 = graph.CallProcedure(graphName, "db.labels");
Assert.Empty(labels0);

graph.Query(graphName, "CREATE (:Person { name: 'Bob' })");

var labels1 = graph.CallProcedure(graphName, "db.labels");
Assert.Single(labels1);
}

[Fact]
public void TestCallProcedureReadOnly()
{
var db = redisFixture.Redis.GetDatabase();
db.Execute("FLUSHALL");

const string graphName = "social";

var graph = db.GRAPH();
// throws RedisServerException when executing a ReadOnly procedure against non-existing graph.
Assert.Throws<RedisServerException>(() => graph.CallProcedure(graphName, "db.labels", ProcedureMode.Read));

graph.Query(graphName, "CREATE (:Person { name: 'Bob' })");
var procedureArgs = new List<string>
{
"Person",
"name"
};
// throws RedisServerException when executing a Write procedure with Read procedure mode.
Assert.Throws<RedisServerException>(() => graph.CallProcedure(graphName, "db.idx.fulltext.createNodeIndex", procedureArgs, ProcedureMode.Read));
}

#endregion

#region AsyncTests
Expand Down Expand Up @@ -1886,6 +1929,49 @@ public async Task TestModulePrefixsAsync()
Assert.NotEqual(graph1.GetHashCode(), graph2.GetHashCode());
}

[Fact]
public async Task TestCallProcedureDbLabelsAsync()
{
var db = redisFixture.Redis.GetDatabase();
db.Execute("FLUSHALL");

const string graphName = "social";

var graph = db.GRAPH();
// Create empty graph, otherwise call procedure will throw exception
await graph.QueryAsync(graphName, "RETURN 1");

var labels0 = await graph.CallProcedureAsync(graphName, "db.labels");
Assert.Empty(labels0);

await graph.QueryAsync(graphName, "CREATE (:Person { name: 'Bob' })");

var labels1 = await graph.CallProcedureAsync(graphName, "db.labels");
Assert.Single(labels1);
}

[Fact]
public async Task TestCallProcedureReadOnlyAsync()
{
var db = redisFixture.Redis.GetDatabase();
db.Execute("FLUSHALL");

const string graphName = "social";

var graph = db.GRAPH();
// throws RedisServerException when executing a ReadOnly procedure against non-existing graph.
await Assert.ThrowsAsync<RedisServerException>(() => graph.CallProcedureAsync(graphName, "db.labels", ProcedureMode.Read));

await graph.QueryAsync(graphName, "CREATE (:Person { name: 'Bob' })");
var procedureArgs = new List<string>
{
"Person",
"name"
};
// throws RedisServerException when executing a Write procedure with Read procedure mode.
await Assert.ThrowsAsync<RedisServerException>(() => graph.CallProcedureAsync(graphName, "db.idx.fulltext.createNodeIndex", procedureArgs, ProcedureMode.Read));
}

[Fact]
public void TestParseInfinity()
{
Expand Down

0 comments on commit 89c039f

Please sign in to comment.