Ejemplo n.º 1
0
        public void TestMessageLifecycle()
        {
            var roomId    = RoomList != null && RoomList.Any() ? RoomList.First() : Room;
            var messageId = TestPostRoomMessage(roomId);

            TestGetRoomMessage(roomId, messageId);
            TestPutRoomMessage(roomId, messageId);
            TestDeleteRoomMessage(roomId, messageId);

            // [POST] /rooms/{room_id}/messages.
            string TestPostRoomMessage(long roomId)
            {
                var parameters = new NewMessageParameters
                {
                    Body       = "new test message.",
                    SelfUnread = true,
                };

                var response = Client.PostRoomMessage(roomId, parameters);

                AssertPostRoomMessageResponse(response);

                return(response.Data.MessageId);
            }

            // [GET] /rooms/{room_id}/messages/{message_id}.
            void TestGetRoomMessage(long roomId, string messageId)
            {
                var response = Client.GetRoomMessage(roomId, messageId);

                AssertGetRoomMessageResponse(response, messageId);
            }

            // [PUT] /rooms/{room_id}/messages/{message_id}.
            void TestPutRoomMessage(long roomId, string messageId)
            {
                var parameters = new UpdateMessageParameters
                {
                    Body = "update test message.",
                };

                var response = Client.PutRoomMessage(roomId, messageId, parameters);

                AssertPutRoomMessageResponse(response, messageId);
            }

            // [DELETE] /rooms/{room_id}/messages/{message_id}.
            void TestDeleteRoomMessage(long roomId, string messageId)
            {
                var response = Client.DeleteRoomMessage(roomId, messageId);

                AssertDeleteRoomMessageResponse(response, messageId);
            }
        }
Ejemplo n.º 2
0
        public void TestStaticMessageLifecycleAsyncCallback()
        {
            var roomId = RoomList != null && RoomList.Any() ? RoomList.First() : Room;

            TestStaticPostRoomMessageAsyncCallback(
                roomId,
                (roomId, messageId) => TestStaticGetRoomMessageAsyncCallback(
                    roomId,
                    messageId,
                    (roomId, messageId) => TestStaticPutRoomMessageAsyncCallback(
                        roomId,
                        messageId,
                        TestStaticDeleteRoomMessageAsyncCallback)));

            // [POST] /rooms/{room_id}/messages.
            void TestStaticPostRoomMessageAsyncCallback(long roomId, Action <long, string> next)
            {
                var parameters = new NewMessageParameters
                {
                    Body       = "new test message.",
                    SelfUnread = true,
                };

                ChatworkClient.PostRoomMessageAsync(
                    Token,
                    response =>
                {
                    AssertPostRoomMessageResponse(response);
                    next.Invoke(roomId, response.Data.MessageId);
                },
                    roomId,
                    parameters);
            }

            // [GET] /rooms/{room_id}/messages/{message_id}.
            void TestStaticGetRoomMessageAsyncCallback(long roomId, string messageId, Action <long, string> next)
            {
                ChatworkClient.GetRoomMessageAsync(
                    Token,
                    response =>
                {
                    AssertGetRoomMessageResponse(response, messageId);
                    next.Invoke(roomId, messageId);
                },
                    roomId,
                    messageId);
            }

            // [PUT] /rooms/{room_id}/messages/{message_id}.
            void TestStaticPutRoomMessageAsyncCallback(long roomId, string messageId, Action <long, string> next)
            {
                var parameters = new UpdateMessageParameters
                {
                    Body = "update test message.",
                };

                ChatworkClient.PutRoomMessageAsync(
                    Token,
                    response =>
                {
                    AssertPutRoomMessageResponse(response, messageId);
                    next.Invoke(roomId, messageId);
                },
                    roomId,
                    messageId,
                    parameters);
            }

            // [DELETE] /rooms/{room_id}/messages/{message_id}.
            void TestStaticDeleteRoomMessageAsyncCallback(long roomId, string messageId)
            {
                ChatworkClient.DeleteRoomMessageAsync(
                    Token,
                    response => AssertDeleteRoomMessageResponse(response, messageId),
                    roomId,
                    messageId);
            }
        }
Ejemplo n.º 3
0
        public async void TestStaticMessageLifecycleAsync()
        {
            var roomId = RoomList != null && RoomList.Any() ? RoomList.First() : Room;

            var messageId = await TestStaticPostRoomMessageAsync(roomId)
                            .ConfigureAwait(false);

            await TestStaticGetRoomMessageAsync(roomId, messageId)
            .ConfigureAwait(false);

            await TestStaticPutRoomMessageAsync(roomId, messageId)
            .ConfigureAwait(false);

            await TestStaticDeleteRoomMessageAsync(roomId, messageId)
            .ConfigureAwait(false);

            // [POST] /rooms/{room_id}/messages.
            async Task <string> TestStaticPostRoomMessageAsync(long roomId)
            {
                var parameters = new NewMessageParameters
                {
                    Body       = "new test message.",
                    SelfUnread = true,
                };

                var response = await ChatworkClient.PostRoomMessageAsync(Token, roomId, parameters)
                               .ConfigureAwait(false);

                AssertPostRoomMessageResponse(response);
                return(response.Data.MessageId);
            }

            // [GET] /rooms/{room_id}/messages/{message_id}.
            async Task TestStaticGetRoomMessageAsync(long roomId, string messageId)
            {
                var response = await ChatworkClient.GetRoomMessageAsync(Token, roomId, messageId)
                               .ConfigureAwait(false);

                AssertGetRoomMessageResponse(response, messageId);
            }

            // [PUT] /rooms/{room_id}/messages/{message_id}.
            async Task TestStaticPutRoomMessageAsync(long roomId, string messageId)
            {
                var parameters = new UpdateMessageParameters
                {
                    Body = "update test message.",
                };

                var response = await ChatworkClient.PutRoomMessageAsync(Token, roomId, messageId, parameters)
                               .ConfigureAwait(false);

                AssertPutRoomMessageResponse(response, messageId);
            }

            // [DELETE] /rooms/{room_id}/messages/{message_id}.
            async Task TestStaticDeleteRoomMessageAsync(long roomId, string messageId)
            {
                var response = await ChatworkClient.DeleteRoomMessageAsync(Token, roomId, messageId)
                               .ConfigureAwait(false);

                AssertDeleteRoomMessageResponse(response, messageId);
            }
        }