public async Task Subscribe_RaiseEvent_With_Argument_As_Variables() { // arrange var registry = new InMemoryEventRegistry(); var services = new Mock <IServiceProvider>(); services.Setup(t => t.GetService(It.IsAny <Type>())) .Returns(new Func <Type, object>(t => { if (t == typeof(IEventRegistry) || t == typeof(IEventSender)) { return(registry); } return(null); })); ISchema schema = Schema.Create(c => { c.RegisterQueryType <DummyQuery>(); c.RegisterServiceProvider(services.Object); c.RegisterMutationType <MutationType>(); c.RegisterSubscriptionType <SubscriptionType>(); }); IQueryExecutor executor = schema.MakeExecutable(); var responseStream = await executor.ExecuteAsync(QueryRequestBuilder.New() .SetQuery("subscription($a: String!) { bar(baz:$a) }") .AddVariableValue("a", "123") .Create()) as IResponseStream; // act await executor.ExecuteAsync(QueryRequestBuilder.New() .SetQuery("mutation($a: String!) { bar(baz:$a) }") .AddVariableValue("a", "123") .Create()); // assert using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30))) { await foreach (IReadOnlyQueryResult result in responseStream.WithCancellation(cts.Token)) { Assert.Equal("123", result.Data["bar"]); break; } } }
public async Task Subscribe_RaiseEvent_With_Argument() { // arrange var registry = new InMemoryEventRegistry(); var services = new Mock <IServiceProvider>(); services.Setup(t => t.GetService(It.IsAny <Type>())) .Returns(new Func <Type, object>(t => { if (t == typeof(IEventRegistry) || t == typeof(IEventSender)) { return(registry); } return(null); })); ISchema schema = Schema.Create(c => { c.RegisterQueryType <DummyQuery>(); c.RegisterServiceProvider(services.Object); c.RegisterMutationType <MutationType>(); c.RegisterSubscriptionType <SubscriptionType>(); }); IQueryExecutor executor = schema.MakeExecutable(); var responseStream = await executor.ExecuteAsync("subscription { bar(baz:\"123\") }") as IResponseStream; // act await executor.ExecuteAsync("mutation { bar(baz:\"123\") }"); // assert using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30))) { IReadOnlyQueryResult result = await responseStream.ReadAsync(cts.Token); Assert.False(responseStream.IsCompleted); Assert.Equal("123", result.Data["bar"]); } }
public async Task Subscribe_RaiseEvent_ReceiveSubscriptionResult() { // arrange var registry = new InMemoryEventRegistry(); var services = new Mock <IServiceProvider>(); services.Setup(t => t.GetService(It.IsAny <Type>())) .Returns(new Func <Type, object>(t => { if (t == typeof(IEventRegistry) || t == typeof(IEventSender)) { return(registry); } return(null); })); ISchema schema = Schema.Create(c => { c.RegisterQueryType <DummyQuery>(); c.RegisterServiceProvider(services.Object); c.RegisterMutationType <MutationType>(); c.RegisterSubscriptionType <SubscriptionType>(); }); IQueryExecutor executor = schema.MakeExecutable(); var responseStream = await executor.ExecuteAsync("subscription { foo }") as IResponseStream; // act await executor.ExecuteAsync("mutation { foo }"); // assert IReadOnlyQueryResult result = await responseStream.ReadAsync(); Assert.False(responseStream.IsCompleted); Assert.Equal("bar", result.Data["foo"]); }