Example #1
0
        public void TestRoomLifecycle()
        {
            const string roomName        = "Room Lifecycle {0}";
            const string roomDescription = "Description of the room lifecycle {0}";
            var          roomId          = TestCreateRoom();

            TestGetRoom(roomId);
            TestPutRoom(roomId);
            TestDeleteRoom(roomId);

            // [POST] /rooms.
            long TestCreateRoom()
            {
                var identifier = "New";
                var parameters = new NewRoomParameters
                {
                    Description        = string.Format(CultureInfo.InvariantCulture, roomDescription, identifier),
                    IconPreset         = IconPresetValue.Group,
                    Link               = false,
                    LinkCode           = "jlklqwes",
                    LinkNeedAcceptance = true,
                    MembersAdminIds    = new[] { AccountId },
                    MembersMemberIds   = MemberList,
                    MembersReadonlyIds = null,
                    Name               = string.Format(CultureInfo.InvariantCulture, roomName, identifier),
                };

                var response = Client.PostRoom(parameters);

                AssertPostRoomsResponse(response);
                return(response.Data.RoomId);
            }

            // [GET] /rooms/{room_id}.
            void TestGetRoom(long roomId)
            {
                var response = Client.GetRoom(roomId);

                AssertGetRoomResponse(response, roomId);
            }

            // [PUT] /rooms/{room_id}.
            void TestPutRoom(long roomId)
            {
                var iconPresetList = Enum.GetValues(typeof(IconPresetValue));

                foreach (IconPresetValue iconPreset in iconPresetList)
                {
                    var identifier = string.Format(
                        CultureInfo.InvariantCulture,
                        "[{0}]",
                        StringValueAttribute.GetStringValue(iconPreset));

                    var parameters = new UpdateRoomParameters
                    {
                        Description = string.Format(CultureInfo.InvariantCulture, roomDescription, identifier),
                        IconPreset  = iconPreset,
                        Name        = string.Format(CultureInfo.InvariantCulture, roomName, identifier),
                    };

                    var response = Client.PutRoom(roomId, parameters);
                    AssertPutRoomResponse(response, roomId);
                }
            }

            // [DELETE] /rooms/{room_id}.
            void TestDeleteRoom(long roomId)
            {
                var parameters = new DeleteRoomParameters
                {
                    ActionType = ActionTypeValue.Delete,
                };

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

                AssertDeleteRoomResponse(response);
            }
        }
Example #2
0
        public void TestStaticRoomLifecycleAsyncCallback()
        {
            const string roomName        = "Room Lifecycle {0}";
            const string roomDescription = "Description of the room lifecycle {0}";

            TestStaticCreateRoomAsyncCallback(
                roomId => TestStaticPutRoomAsyncCallback(
                    roomId,
                    roomId => TestStaticGetRoomAsyncCallback(
                        roomId,
                        TestStaticDeleteRoomAsyncCallback)));

            // [POST] /rooms.
            void TestStaticCreateRoomAsyncCallback(Action <long> next)
            {
                var identifier = "New";
                var parameters = new NewRoomParameters
                {
                    Description        = string.Format(CultureInfo.InvariantCulture, roomDescription, identifier),
                    IconPreset         = IconPresetValue.Group,
                    Link               = false,
                    LinkCode           = "weqxdfas",
                    LinkNeedAcceptance = true,
                    MembersAdminIds    = new[] { AccountId },
                    MembersMemberIds   = null,
                    MembersReadonlyIds = null,
                    Name               = string.Format(CultureInfo.InvariantCulture, roomName, identifier),
                };

                ChatworkClient.PostRoomAsync(
                    Token,
                    response =>
                {
                    AssertPostRoomsResponse(response);
                    next.Invoke(response.Data.RoomId);
                },
                    parameters);
            }

            // [GET] /rooms/{room_id}.
            void TestStaticGetRoomAsyncCallback(long roomId, Action <long> next)
            {
                ChatworkClient.GetRoomAsync(
                    Token,
                    response =>
                {
                    AssertGetRoomResponse(response, roomId);
                    next.Invoke(roomId);
                },
                    roomId);
            }

            // [PUT] /rooms/{room_id}.
            void TestStaticPutRoomAsyncCallback(long roomId, Action <long> next)
            {
                var iconPreset = IconPresetValue.Business;
                var identifier = StringValueAttribute.GetStringValue(iconPreset);
                var parameters = new UpdateRoomParameters
                {
                    Description = string.Format(CultureInfo.InvariantCulture, roomDescription, identifier),
                    IconPreset  = iconPreset,
                    Name        = string.Format(CultureInfo.InvariantCulture, roomName, identifier),
                };

                ChatworkClient.PutRoomAsync(
                    Token,
                    response =>
                {
                    AssertPutRoomResponse(response, roomId);
                    next.Invoke(roomId);
                },
                    roomId,
                    parameters);
            }

            // [DELETE] /rooms/{room_id}.
            void TestStaticDeleteRoomAsyncCallback(long roomId)
            {
                var parameters = new DeleteRoomParameters
                {
                    ActionType = ActionTypeValue.Leave,
                };

                ChatworkClient.DeleteRoomAsync(
                    Token,
                    response => AssertDeleteRoomResponse(response),
                    roomId,
                    parameters);
            }
        }
Example #3
0
        public async void TestRoomLifecycleAsync()
        {
            const string roomName        = "Room Lifecycle {0}";
            const string roomDescription = "Description of the room lifecycle {0}";

            var roomId = await TestCreateRoomAsync()
                         .ConfigureAwait(false);

            await TestPutRoomAsync(roomId)
            .ConfigureAwait(false);

            await TestGetRoomAsync(roomId)
            .ConfigureAwait(false);

            await TestDeleteRoomAsync(roomId)
            .ConfigureAwait(false);

            // [POST] /rooms.
            async Task <long> TestCreateRoomAsync()
            {
                var identifier = "New";
                var parameters = new NewRoomParameters
                {
                    Description        = string.Format(CultureInfo.InvariantCulture, roomDescription, identifier),
                    IconPreset         = IconPresetValue.Group,
                    Link               = false,
                    LinkCode           = "weqxdfas",
                    LinkNeedAcceptance = true,
                    MembersAdminIds    = new[] { AccountId },
                    MembersMemberIds   = null,
                    MembersReadonlyIds = MemberList,
                    Name               = string.Format(CultureInfo.InvariantCulture, roomName, identifier),
                };

                var response = await Client.PostRoomAsync(parameters)
                               .ConfigureAwait(false);

                AssertPostRoomsResponse(response);
                return(response.Data.RoomId);
            }

            // [GET] /rooms/{room_id}.
            async Task TestGetRoomAsync(long roomId)
            {
                var response = await Client.GetRoomAsync(roomId)
                               .ConfigureAwait(false);

                AssertGetRoomResponse(response, roomId);
            }

            // [PUT] /rooms/{room_id}.
            async Task TestPutRoomAsync(long roomId)
            {
                var iconPreset = IconPresetValue.Business;
                var identifier = StringValueAttribute.GetStringValue(iconPreset);
                var parameters = new UpdateRoomParameters
                {
                    Description = string.Format(CultureInfo.InvariantCulture, roomDescription, identifier),
                    IconPreset  = iconPreset,
                    Name        = string.Format(CultureInfo.InvariantCulture, roomName, identifier),
                };

                var response = await Client.PutRoomAsync(roomId, parameters)
                               .ConfigureAwait(false);

                AssertPutRoomResponse(response, roomId);
            }

            // [DELETE] /rooms/{room_id}.
            async Task TestDeleteRoomAsync(long roomId)
            {
                var parameters = new DeleteRoomParameters
                {
                    ActionType = ActionTypeValue.Leave,
                };

                var response = await Client.DeleteRoomAsync(roomId, parameters)
                               .ConfigureAwait(false);

                AssertDeleteRoomResponse(response);
            }
        }