public async Task Handle_Stop_Subscription()
        {
            // arrange
            var connection = new SocketConnectionMock();

            IRequestExecutor executor = await new ServiceCollection()
                                        .AddGraphQL()
                                        .AddStarWarsTypes()
                                        .AddStarWarsRepositories()
                                        .AddInMemorySubscriptions()
                                        .Services
                                        .BuildServiceProvider()
                                        .GetRequiredService <IRequestExecutorResolver>()
                                        .GetRequestExecutorAsync();

            var stream =
                (IResponseStream)await executor.ExecuteAsync(
                    "subscription { onReview(episode: NEW_HOPE) { stars } }");

            var subscription = new Subscription(connection, stream, "123");

            connection.Subscriptions.Register(subscription);

            var handler = new DataStopMessageHandler();
            var message = new DataStopMessage("123");

            // act
            await handler.HandleAsync(
                connection,
                message,
                CancellationToken.None);

            // assert
            Assert.Empty(connection.Subscriptions);
        }
        public void CanHandle_DataStartMessage_True()
        {
            // arrange
            var handler = new DataStopMessageHandler();
            var message = new DataStopMessage("123");

            // act
            var result = handler.CanHandle(message);

            // assert
            Assert.True(result);
        }
示例#3
0
        public async Task Handle_Stop_Subscription()
        {
            // arrange
            var connection = new SocketConnectionMock();

            var services = new ServiceCollection();

            services.AddInMemorySubscriptionProvider();
            services.AddStarWarsRepositories();

            IQueryExecutor executor = SchemaBuilder.New()
                                      .AddServices(services.BuildServiceProvider())
                                      .AddStarWarsTypes()
                                      .Create()
                                      .MakeExecutable();

            DocumentNode query = Utf8GraphQLParser.Parse(
                "subscription { onReview(episode: NEWHOPE) { stars } }");

            IResponseStream stream =
                (IResponseStream)await executor.ExecuteAsync(
                    "subscription { onReview(episode: NEWHOPE) { stars } }");

            var subscription = new Subscription(connection, stream, "123");

            connection.Subscriptions.Register(subscription);

            var handler = new DataStopMessageHandler();
            var message = new DataStopMessage("123");

            // act
            await handler.HandleAsync(
                connection,
                message,
                CancellationToken.None);

            // assert
            Assert.Empty(connection.Subscriptions);
        }