public void TestLeaveChatroom() { //Necessary to create the child chatroom before requesting its information var USER = _helper.testUsers[1]; ChatroomController chatControllerTest = new ChatroomController(); ChatRequestModel model = new ChatRequestModel() { RawChatroomIdValue = "123403", UserHandle = USER.DefaultHandle, ChatroomName = "TestLeaveChatroom", User = new UserModel() { Id = USER.Id, Username = USER.Username } }; ChatResponseTestModel chatRoom = _helper.createChatroomAndAddUser(model);//for now don't do anything with the result //Pre-sanity check amke sure only 1 user in the room before we try ad join //Create test data model GetChatroomInformationRequestModel modelInfo = new GetChatroomInformationRequestModel() { UserId = chatRoom.ChatroomModel.UserId, ChatroomId = chatRoom.ChatroomModel.ChatroomId, ParentChatroomId = chatRoom.ChatroomModel.ParentChatroomId }; //Test getting the information from the chatroom success var result = chatControllerTest.GetChatroomInformation(modelInfo) as JsonResult; Assert.AreEqual(1, ((GetChatroomInformationResponseModel)result.Data).UsersInformation.Count); Assert.AreEqual(USER.Id, ((GetChatroomInformationResponseModel)result.Data).UsersInformation[0].Id); Assert.AreEqual(USER.Username, ((GetChatroomInformationResponseModel)result.Data).UsersInformation[0].Username); //Create test data model LeaveChatroomRequestModel model2 = new LeaveChatroomRequestModel() { ChatroomId = chatRoom.ChatroomModel.ChatroomId, ParentId = chatRoom.ChatroomModel.ParentChatroomId, UserId = USER.Id, User = new UserModel() { Id = USER.Id } }; var result2 = chatControllerTest.LeaveChatroom(model2) as EmptyResult; //nothing to assert since an empty object is returned but check below that there are no users in the room //Post-sanity check NOW there will be two users in the chatroom xD result = chatControllerTest.GetChatroomInformation(modelInfo) as JsonResult; Assert.AreEqual(0, ((GetChatroomInformationResponseModel)result.Data).UsersInformation.Count); }
public EmptyResult LeaveChatroom(LeaveChatroomRequestModel request) { ChatroomService.RemoveUserFromChatroom(request.ChatroomId, request.ParentId, request.UserId); return(new EmptyResult()); }