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_KeepAliveMessage_False()
        {
            // arrange
            var handler = new DataStopMessageHandler();
            KeepConnectionAliveMessage message = KeepConnectionAliveMessage.Default;

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

            // assert
            Assert.False(result);
        }
        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);
        }
Ejemplo n.º 4
0
        public void CanHandle_KeepAliveMessage_False()
        {
            // arrange
            IQueryExecutor executor = SchemaBuilder.New()
                                      .AddStarWarsTypes()
                                      .Create()
                                      .MakeExecutable();

            var handler = new DataStopMessageHandler();
            var message = KeepConnectionAliveMessage.Default;

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

            // assert
            Assert.False(result);
        }
Ejemplo n.º 5
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);
        }