public async Task EmptyCollectionOnContext_YieldsNothingPublished()
        {
            var nextCalled = false;

            Task CallNext(GraphQueryExecutionContext context, CancellationToken token)
            {
                nextCalled = true;
                return(Task.CompletedTask);
            }

            var next      = new GraphMiddlewareInvocationDelegate <GraphQueryExecutionContext>(CallNext);
            var queue     = new SubscriptionEventQueue();
            var publisher = new PublishRaisedSubscriptionEventsMiddleware <GraphSchema>(queue);

            var server = new TestServerBuilder()
                         .Build();

            var context = server.CreateQueryContextBuilder()
                          .Build();

            var col = context.Items.GetOrAdd(
                SubscriptionConstants.RAISED_EVENTS_COLLECTION_KEY, (_) => new List <SubscriptionEventProxy>());

            await publisher.InvokeAsync(context, next, default);

            Assert.IsTrue(nextCalled);
            Assert.AreEqual(0, queue.Count);
        }
        public void CollectionKeyIsNotACollection_ThrowsException()
        {
            Task CallNext(GraphQueryExecutionContext context, CancellationToken token)
            {
                return(Task.CompletedTask);
            }

            var next      = new GraphMiddlewareInvocationDelegate <GraphQueryExecutionContext>(CallNext);
            var queue     = new SubscriptionEventQueue();
            var publisher = new PublishRaisedSubscriptionEventsMiddleware <GraphSchema>(queue);

            var server = new TestServerBuilder()
                         .Build();

            var context = server.CreateQueryContextBuilder()
                          .Build();

            var col = context.Items.GetOrAdd(
                SubscriptionConstants.RAISED_EVENTS_COLLECTION_KEY, (_) => new object());

            Assert.ThrowsAsync <GraphExecutionException>(async() =>
            {
                await publisher.InvokeAsync(context, next, default);
            });
        }
        public async Task NoItemsOnContext_YieldsNothingPublished()
        {
            var nextCalled = false;

            Task CallNext(GraphQueryExecutionContext context, CancellationToken token)
            {
                nextCalled = true;
                return(Task.CompletedTask);
            }

            var next      = new GraphMiddlewareInvocationDelegate <GraphQueryExecutionContext>(CallNext);
            var queue     = new SubscriptionEventQueue();
            var publisher = new PublishRaisedSubscriptionEventsMiddleware <GraphSchema>(queue);

            var server = new TestServerBuilder()
                         .Build();

            var context = server.CreateQueryContextBuilder()
                          .Build();

            await publisher.InvokeAsync(context, next, default);

            Assert.IsTrue(nextCalled);
            Assert.AreEqual(0, queue.Count);
        }