public async Task ExecutePersistedQuery_NotFound() { // arrange var queryId = Guid.NewGuid().ToString("N"); var storage = new RedisQueryStorage(_database); await storage.WriteQueryAsync(queryId, new QuerySourceText("{ __typename }")); IRequestExecutor executor = await new ServiceCollection() .AddGraphQL() .AddQueryType(c => c.Name("Query").Field("a").Resolve("b")) .AddRedisQueryStorage(s => _database) .UseRequest(n => async c => { await n(c); if (c.IsPersistedDocument && c.Result is IQueryResult r) { c.Result = QueryResultBuilder .FromResult(r) .SetExtension("persistedDocument", true) .Create(); } }) .UsePersistedQueryPipeline() .BuildRequestExecutorAsync(); // act IExecutionResult result = await executor.ExecuteAsync(new QueryRequest(queryId : "does_not_exist")); // assert result.MatchSnapshot(); }
public Task Read_Query_QueryId_Invalid(string queryId) { return(TryTest(async() => { var storage = new RedisQueryStorage(_database); // act Task Action() => storage.TryReadQueryAsync(queryId); // assert await Assert.ThrowsAsync <ArgumentNullException>(Action); })); }
public Task Write_Query_Query_Is_Null() { return(TryTest(async() => { var storage = new RedisQueryStorage(_database); var queryId = Guid.NewGuid().ToString("N"); // act Task Action() => storage.WriteQueryAsync(queryId, null !); // assert await Assert.ThrowsAsync <ArgumentNullException>(Action); })); }
public Task Write_Query_QueryId_Invalid(string queryId) { return(TryTest(async() => { var storage = new RedisQueryStorage(_database); var query = new QuerySourceText("{ foo }"); // act Task Action() => storage.WriteQueryAsync(queryId, query); // assert await Assert.ThrowsAsync <ArgumentNullException>(Action); })); }
public Task Read_Query_QueryId_Invalid(string queryId) { SnapshotFullName snapshotName = Snapshot.FullName(); return(TryTest(async() => { var storage = new RedisQueryStorage(_database); // act Func <Task> action = () => storage.TryReadQueryAsync(queryId); // assert await Assert.ThrowsAsync <ArgumentNullException>(action); })); }
public Task Write_Query_Query_Is_Null() { SnapshotFullName snapshotName = Snapshot.FullName(); return(TryTest(async() => { var storage = new RedisQueryStorage(_database); var queryId = Guid.NewGuid().ToString("N"); // act Func <Task> action = () => storage.WriteQueryAsync(queryId, null); // assert await Assert.ThrowsAsync <ArgumentNullException>(action); })); }
public Task Write_Query_QueryId_Invalid(string queryId) { SnapshotFullName snapshotName = Snapshot.FullName(); return(TryTest(async() => { var storage = new RedisQueryStorage(_database); var query = new QuerySourceText("{ foo }"); // act Func <Task> action = () => storage.WriteQueryAsync(queryId, query); // assert await Assert.ThrowsAsync <ArgumentNullException>(action); })); }
public Task Write_Query_To_Storage() { SnapshotFullName snapshotName = Snapshot.FullName(); var queryId = Guid.NewGuid().ToString("N"); return(TryTest(async() => { // arrange var storage = new RedisQueryStorage(_database); var query = new QuerySourceText("{ foo }"); // act await storage.WriteQueryAsync(queryId, query); // assert var buffer = (byte[])await _database.StringGetAsync(queryId); Utf8GraphQLParser.Parse(buffer).Print().MatchSnapshot(snapshotName); }, () => _database.KeyDeleteAsync(queryId))); }
public Task Read_Query_From_Storage() { SnapshotFullName snapshotName = Snapshot.FullName(); var queryId = Guid.NewGuid().ToString("N"); return(TryTest(async() => { // arrange var storage = new RedisQueryStorage(_database); var buffer = Encoding.UTF8.GetBytes("{ foo }"); await _database.StringSetAsync(queryId, buffer); // act QueryDocument query = await storage.TryReadQueryAsync(queryId); // assert Assert.NotNull(query); query.Document.Print().MatchSnapshot(snapshotName); }, () => _database.KeyDeleteAsync(queryId))); }
public async Task ExecutePersistedQuery_ApplicationDI_Default() { // arrange var queryId = Guid.NewGuid().ToString("N"); var storage = new RedisQueryStorage(_database); await storage.WriteQueryAsync(queryId, new QuerySourceText("{ __typename }")); IRequestExecutor executor = await new ServiceCollection() // we register the multiplexer on the application services .AddSingleton(_multiplexer) .AddGraphQL() .AddQueryType(c => c.Name("Query").Field("a").Resolve("b")) // and in the redis storage setup refer to that instance. .AddRedisQueryStorage() .UseRequest(n => async c => { await n(c); if (c.IsPersistedDocument && c.Result is IQueryResult r) { c.Result = QueryResultBuilder .FromResult(r) .SetExtension("persistedDocument", true) .Create(); } }) .UsePersistedQueryPipeline() .BuildRequestExecutorAsync(); // act IExecutionResult result = await executor.ExecuteAsync(new QueryRequest(queryId : queryId)); // assert result.MatchSnapshot(); }