public async Task OnPublishSchema()
        {
            // arrange
            var serializer = new IdSerializer();

            var schema = new Schema("abc", "def");
            await SchemaRepository.AddSchemaAsync(schema);

            var environment = new Environment("abc", "def");
            await EnvironmentRepository.AddEnvironmentAsync(environment);

            string sessionId = await SessionCreator.CreateSessionAsync();

            await PublishSchemaEventSender.SendAsync(
                new PublishDocumentEvent(
                    sessionId,
                    new Issue("foo", "file.graphql", new Location(0, 0, 1, 1),
                              IssueType.Information)));

            await PublishSchemaEventSender.SendAsync(
                PublishDocumentEvent.Completed(sessionId));

            // act
            var responseStream = (IResponseStream)await Executor.ExecuteAsync(
                QueryRequestBuilder.New()
                .SetQuery(
                    @"subscription(
                            $sessionId: String!) {
                            onPublishSchema(sessionId: $sessionId) {
                                sessionId
                                isCompleted
                            }
                        }")
                .SetVariableValue("sessionId", sessionId)
                .Create());

            // assert
            var results = new List <IReadOnlyQueryResult>();

            await foreach (IReadOnlyQueryResult result in responseStream)
            {
                results.Add(result);
            }

            results.MatchSnapshot(matchOptions =>
                                  matchOptions.Assert(fieldOption =>
                                                      Assert.Collection(
                                                          fieldOption.Fields <string>("[*].Data.onPublishSchema.sessionId"),
                                                          t => Assert.Equal(sessionId, t),
                                                          t => Assert.Equal(sessionId, t))));
        }
Beispiel #2
0
        public async Task Send_And_Receive_Message()
        {
            // arrange
            var test    = new MessageQueue <PublishDocumentEvent>();
            var message = new PublishDocumentEvent(
                "abc",
                new Issue("def", "file", new Location(0, 0, 0, 0), IssueType.Error));

            // act
            await test.SendAsync(message);

            // assert
            await foreach (PublishDocumentEvent m in await test.SubscribeAsync())
            {
                Assert.Equal(message, m);
                break;
            }
        }
Beispiel #3
0
        public async Task Unsubscribe_On_Complete_Message()
        {
            // arrange
            var sessionManager = new SessionManager();
            var test           = new SessionMessageQueue <PublishDocumentEvent>(sessionManager);

            string sessionId = await sessionManager.CreateSessionAsync();

            var message = new PublishDocumentEvent(
                sessionId,
                new Issue("def", "foo", new Location(0, 0, 0, 0),
                          IssueType.Error));
            var completeMessage = PublishDocumentEvent.Completed(sessionId);
            var received        = new List <PublishDocumentEvent>();

            await test.SendAsync(message);

            Task sendCompleteMessage = Task.Run(async() =>
            {
                await Task.Delay(250);
                await test.SendAsync(completeMessage);
            });

            // act
            await foreach (PublishDocumentEvent m in await test.SubscribeAsync(message.SessionId))
            {
                received.Add(m);

                if (received.Count == 1)
                {
                    await sendCompleteMessage;
                }
            }

            // assert
            Assert.Collection(received,
                              t => Assert.Equal(message, t),
                              t => Assert.Equal(completeMessage, t));
        }
Beispiel #4
0
        public async Task Send_And_Receive_Message()
        {
            // arrange
            var sessionManager = new SessionManager();
            var test           = new SessionMessageQueue <PublishDocumentEvent>(sessionManager);

            string sessionId = await sessionManager.CreateSessionAsync();

            var message = new PublishDocumentEvent(
                sessionId,
                new Issue("def", "foo", new Location(0, 0, 0, 0),
                          IssueType.Error));

            // act
            await test.SendAsync(message);

            // assert
            await foreach (PublishDocumentEvent m in await test.SubscribeAsync(message.SessionId))
            {
                Assert.Equal(message, m);
                break;
            }
        }