public ActionResult GetNewMessages(GetNewMessagesRequestModel request) { int parentChatroomId = request.ParentChatroomId; int chatroomId = request.ChatroomId; List <int> existingIds = request.ExistingMessageIds; GetNewMessagesResponseModel response = new GetNewMessagesResponseModel(); var user = UserService.GetUser(request.UserId); if (user == null || user.Role == Models.User_Model.RoleLevel.Blocked) { response.Logout = true; } else { var messageInformationModels = ChatroomService.GetNewMessagesInformation(parentChatroomId, chatroomId, existingIds); foreach (var messageInformationModel in messageInformationModels) { if (messageInformationModel.IntendedForUserId != -1) { if (messageInformationModel.IntendedForUserId == request.UserId) { response.MessagesInformation.Add(messageInformationModel); } } else { response.MessagesInformation.Add(messageInformationModel); } } } return(Json(response)); }
public void TestComposeAndGetNewMessages() { //Necessary to create the child chatroom before requesting its information var USER = _helper.testUsers[1]; ChatroomController chatControllerTest = new ChatroomController(); ChatRequestModel model = new ChatRequestModel() { RawChatroomIdValue = "123404", UserHandle = USER.DefaultHandle, ChatroomName = "TestComposeAndGetNewMessages", User = new UserModel() { Id = USER.Id, Username = USER.Username } }; ChatResponseTestModel chatRoom = _helper.createChatroomAndAddUser(model);//for now don't do anything with the result //Right now every time we run the test another message gets added. ComposeMessageRequestModel messageModel = new ComposeMessageRequestModel() { Message = "This is a test message", ChatroomId = chatRoom.ChatroomModel.ChatroomId, UserId = USER.Id, ParentChatroomId = chatRoom.ChatroomModel.ParentChatroomId, UserHandle = USER.DefaultHandle }; var msgResult = chatControllerTest.ComposeMessage(messageModel); //Create test data model GetNewMessagesRequestModel model2 = new GetNewMessagesRequestModel() { ChatroomId = chatRoom.ChatroomModel.ChatroomId, UserId = USER.Id, ExistingMessageIds = new List <int>(), ParentChatroomId = chatRoom.ChatroomModel.ParentChatroomId, User = new UserModel() { Id = USER.Id } }; //Test that there are > 0 message results returned. var result = chatControllerTest.GetNewMessages(model2) as JsonResult; Assert.AreNotEqual(0, ((GetNewMessagesResponseModel)result.Data).MessagesInformation.Count); }