public async Task Subscribe()
        {
            /* Given */
            var addedMessage = new Message
            {
                Content = "test",
                From    = new MessageFrom()
                {
                    DisplayName = "test",
                    Id          = "1"
                },
                SentAt = DateTime.Now
            };
            var chat   = new Chat();
            var schema = new ChatSchema(chat);

            /* When */
            var result = await SubscribeAsync(new ExecutionOptions
            {
                Query  = "subscription MessageAdded { messageAdded { from { id displayName } content sentAt } }",
                Schema = schema
            });

            chat.AddMessage(addedMessage);

            /* Then */
            var stream  = result.Streams.Values.FirstOrDefault();
            var message = await stream.FirstOrDefaultAsync();

            message.ShouldNotBeNull();
            message.ShouldBeOfType <ExecutionResult>();
            message.Data.ShouldNotBeNull();
            message.Data.ShouldNotBeAssignableTo <Task>();
        }
        public async Task OnError()
        {
            /* Given */
            var chat   = new Chat();
            var schema = new ChatSchema(chat);

            /* When */
            var result = await SubscribeAsync(new ExecutionOptions
            {
                Query  = "subscription MessageAdded { messageAdded { from { id displayName } content sentAt } }",
                Schema = schema
            });

            chat.AddError(new Exception("test"));

            /* Then */
            var stream  = result.Streams.Values.FirstOrDefault();
            var message = await stream.FirstOrDefaultAsync();

            message.ShouldNotBeNull();
            message.ShouldBeOfType <ExecutionResult>();
            message.Data.ShouldBeNull();
            var error = message.Errors.Single();

            error.InnerException.Message.ShouldBe("test");
            error.Path.ShouldBe(new[] { "messageAdded" });
        }
        public async Task SubscribeWithArgument()
        {
            /* Given */
            var addedMessage = new Message
            {
                Content = "test",
                From    = new MessageFrom()
                {
                    DisplayName = "test",
                    Id          = "1"
                },
                SentAt = DateTime.Now
            };
            var chat   = new Chat();
            var schema = new ChatSchema(chat);
            var sut    = new SubscriptionExecuter();

            /* When */
            var result = await sut.SubscribeAsync(new ExecutionOptions
            {
                Query  = "subscription MessageAddedByUser($id:String!) { messageAddedByUser(id: $id) { from { id displayName } content sentAt } }",
                Schema = schema,
                Inputs = new Inputs(new Dictionary <string, object>()
                {
                    ["id"] = "1"
                })
            });

            chat.AddMessage(addedMessage);

            /* Then */
            var stream  = result.Streams.Values.FirstOrDefault();
            var message = await stream.FirstOrDefaultAsync();

            message.ShouldNotBeNull();
            message.ShouldBeOfType <ExecutionResult>();
            message.Data.ShouldNotBeNull();
        }
Esempio n. 4
0
        public async Task SubscribeToContent()
        {
            /* Given */
            var addedMessage = new Message
            {
                Content = "test",
                From    = new MessageFrom
                {
                    DisplayName = "test",
                    Id          = "1"
                },
                SentAt = DateTime.Now.Date
            };

            var chat   = new Chat();
            var schema = new ChatSchema(chat);

            /* When */
            var result = await ExecuteSubscribeAsync(new ExecutionOptions
            {
                Query  = "subscription newMessageContent { newMessageContent }",
                Schema = schema
            });

            chat.AddMessage(addedMessage);

            /* Then */
            var stream  = result.Streams.Values.FirstOrDefault();
            var message = await stream.FirstOrDefaultAsync();

            message.ShouldNotBeNull();
            var data = (Dictionary <string, object>)message.Data;

            data.ShouldNotBeNull();
            data["newMessageContent"].ShouldNotBeNull();
            data["newMessageContent"].ToString().ShouldBe("test");
        }
        public async Task SubscribeGetAll()
        {
            /* Given */
            var addedMessage = new Message
            {
                Content = "test",
                From    = new MessageFrom
                {
                    DisplayName = "test",
                    Id          = "1"
                },
                SentAt = DateTime.Now.Date
            };

            var chat   = new Chat();
            var schema = new ChatSchema(chat);

            /* When */
            var result = await ExecuteSubscribeAsync(new ExecutionOptions
            {
                Query  = "subscription messageGetAll { messageGetAll { from { id displayName } content sentAt } }",
                Schema = schema
            });

            chat.AddMessageGetAll(addedMessage);

            /* Then */
            var stream  = result.Streams.Values.FirstOrDefault();
            var message = await stream.FirstOrDefaultAsync();

            message.ShouldNotBeNull();
            var data = message.Data.ToDict();

            data.ShouldNotBeNull();
            data["messageGetAll"].ShouldNotBeNull();
        }