public JsonResult SendMessage(long userId) { long userID = Convert.ToInt64(Session["UserId"]); //ChatDetailListModel model = new ChatDetailListModel() //{ // SenderUserId = userID, // RecieverUserId = userId, // UserMessage = text, // UserMessageTime = DateTime.Now.ToString("hh:mm tt"), // IsSender = true, // TimeStamp=timestamp //}; ChatRequestModel m = new ChatRequestModel() { FromUserId = userID, ToUserId = userId }; propertyService.AddChatRequest(m); //var status = await FirebaseHelper.AddChatMessage(model); wsBase wsBase = new wsBase(); wsBase.status = true; return(Json(wsBase, JsonRequestBehavior.AllowGet)); }
public async Task TestIfGetAllChatRequestsWorksAccordingly() { var context = PCHUBDbContextInMemoryInitializer.InitializeContext(); var chatRequests = new RequestChatServices(context); var modelOne = new ChatRequestModel(); modelOne.Email = "*****@*****.**"; modelOne.ConnectionId = "connectionId"; modelOne.IsAuthenticated = true; modelOne.Subject = "Help me select laptop"; await chatRequests.AddToQueueAsync(modelOne); var modelTwo = new ChatRequestModel(); modelOne.Email = "*****@*****.**"; modelOne.ConnectionId = "connectionIdrandom"; modelOne.IsAuthenticated = true; modelOne.Subject = "Help me select random laptop"; await chatRequests.AddToQueueAsync(modelOne); var result = await chatRequests.GetAllChatRequestsAsync(); Assert.NotEmpty(result); Assert.Equal(2, result.Count); }
public void TestGetChatroomInformation() { //Necessary to create the chatroom before requesting its information var USER = _helper.testUsers[1]; ChatroomController chatControllerTest = new ChatroomController(); ChatRequestModel model = new ChatRequestModel() { RawChatroomIdValue = "123400", UserHandle = USER.DefaultHandle, ChatroomName = "TestGetChatroomInformation", User = new UserModel() { Id = USER.Id, Username = USER.Username } }; ChatResponseTestModel chatRoom = _helper.createChatroomAndAddUser(model);//for now don't do anything with the result //Create test data model GetChatroomInformationRequestModel model2 = 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(model2) 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); }
public async Task TestIfConnectionIdExistsReturnsTrue() { var context = PCHUBDbContextInMemoryInitializer.InitializeContext(); var chatRequests = new RequestChatServices(context); var modelOne = new ChatRequestModel(); modelOne.Email = "*****@*****.**"; modelOne.ConnectionId = "connectionId"; modelOne.IsAuthenticated = true; modelOne.Subject = "Help me select laptop"; await chatRequests.AddToQueueAsync(modelOne); var modelTwo = new ChatRequestModel(); modelOne.Email = "*****@*****.**"; modelOne.ConnectionId = "connectionIdrandom"; modelOne.IsAuthenticated = true; modelOne.Subject = "Help me select random laptop"; await chatRequests.AddToQueueAsync(modelOne); Assert.True(await chatRequests.ConnectionIdExistsAsync("connectionId")); Assert.True(await chatRequests.ConnectionIdExistsAsync("connectionIdrandom")); }
public void TestJoinChatroom() { //Necessary to create the child chatroom before requesting its information var USER = _helper.testUsers[1]; var JOINING_USER = _helper.testUsers[0]; ChatroomController chatControllerTest = new ChatroomController(); ChatRequestModel model = new ChatRequestModel() { RawChatroomIdValue = "123402", UserHandle = USER.DefaultHandle, ChatroomName = "TestJoinChatroom", 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 - with all options possible since without them is easier. Do hard mode xD JoinChatroomRequestModel model2 = new JoinChatroomRequestModel() { UserId = JOINING_USER.Id, ChatroomId = chatRoom.ChatroomModel.ChatroomId, ParentChatroomId = chatRoom.ChatroomModel.ParentChatroomId, CurrentChatroomId = -1, UserHandle = JOINING_USER.DefaultHandle, Password = "", User = new UserModel() { Id = JOINING_USER.Id } }; //Test joining a chatroom success result = chatControllerTest.JoinChatroom(model2) as JsonResult; //Post-sanity check NOW there will be two users in the chatroom xD result = chatControllerTest.GetChatroomInformation(modelInfo) as JsonResult; Assert.AreEqual(2, ((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); Assert.AreEqual(JOINING_USER.Id, ((GetChatroomInformationResponseModel)result.Data).UsersInformation[1].Id); Assert.AreEqual(JOINING_USER.Username, ((GetChatroomInformationResponseModel)result.Data).UsersInformation[1].Username); }
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 ActionResult Chat(ChatRequestModel request) { var response = new PartialViewModel(); var user = UserService.GetUser(request.User.Id); if (user == null || user.Role == Models.User_Model.RoleLevel.Blocked) { response.Logout = true; return(Json(response)); } int chatroomId = 0; if (request.RawChatroomIdValue != null) { chatroomId = request.RawChatroomIdValue.GetHashCode(); } int parentChatroomId = chatroomId; //temporary during initial testing string chatroomName = request.ChatroomName; if (!ChatroomService.DoesChatroomExist(chatroomId)) { ChatroomService.CreateChatroom(chatroomId, chatroomName); } var joinErrors = SecurityService.CanUserJoinChatroom(request); response.Errors.AddRange(joinErrors); if (joinErrors.Count == 0) { if (!ChatroomService.AddUserToChatroom(chatroomId, parentChatroomId, request.User.Id, request.UserHandle)) { response.AddError("Error adding user into chatroom."); } } var chatroomModel = new ChatroomModel() { ChatroomId = chatroomId, ChatroomName = chatroomName, ParentChatroomId = parentChatroomId, UserHandle = request.UserHandle, UserId = request.User.Id }; //response.Data = PartialView("~/Views/Chatroom/_Chat.cshtml", chatroomModel); response.Data = RenderPartialViewToString(this.ControllerContext, "~/Views/Chatroom/_Chat.cshtml", chatroomModel); return(Json(response)); }
public async Task RequestChat(string subject) { if (!await this.service.ConnectionIdExistsAsync(this.Context.User.Identity.Name)) { var userInformation = await this.userProfileService.GetUserProfileInformationAsync(this.Context.User.Identity.Name); var chatRequest = new ChatRequestModel { IsAuthenticated = true, Email = userInformation.UserName, Subject = subject, ConnectionId = this.Context.User.Identity.Name }; await this.service.AddToQueueAsync(chatRequest); await this.Clients.Group("Technicians").SendAsync("RequestChat", chatRequest); } }
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); }
public async Task AddToQueueAsync(ChatRequestModel request) { if (!await this.ConnectionIdExistsAsync(request.ConnectionId)) { await this.context.ChatRequests.AddAsync(new ChatRequest { CreatedOn = DateTime.UtcNow, ModificationDate = DateTime.UtcNow, ConnetctionId = request.ConnectionId, Email = request.Email, IsAuthenticated = request.IsAuthenticated, Subject = request.Subject, }); await this.context.SaveChangesAsync(); } }
public IHttpActionResult AddChatRequest(ChatRequestModel model) { if (model == null) { return(this.Ok(new { status = false, message = Resource.fill_required_records, })); } var status = propertyService.AddChatRequest(model); return(this.Ok(new { status = status, message = propertyService.message, })); }
//Helper method for creating a chatroom since MVC uses controller contexts to route the user to the chat partial view page/ //We don't need that routing here, all we need is the logic or 99% above that line so just replicate it here and //This will create a chatroom and add the user to it //The chatrrom only exists in memory while the tests are run. Each new build refreshes public ChatResponseTestModel createChatroomAndAddUser(ChatRequestModel request) { var response = new ChatResponseTestModel(); int chatroomId = 0; if (request.RawChatroomIdValue != null) { chatroomId = request.RawChatroomIdValue.GetHashCode(); } int parentChatroomId = chatroomId; //temporary during initial testing string chatroomName = request.ChatroomName; if (!ChatroomService.DoesChatroomExist(chatroomId)) { ChatroomService.CreateChatroom(chatroomId, chatroomName); } var joinErrors = SecurityService.CanUserJoinChatroom(request); response.Errors.AddRange(joinErrors); if (joinErrors.Count == 0) { if (!ChatroomService.AddUserToChatroom(chatroomId, parentChatroomId, request.User.Id, request.UserHandle)) { response.AddError("Error adding user into chatroom."); } } var chatroomModel = new ChatroomModel() { ChatroomId = chatroomId, ChatroomName = chatroomName, ParentChatroomId = parentChatroomId, UserHandle = request.UserHandle, UserId = request.User.Id }; response.ChatroomModel = chatroomModel; return(response); }
public void TestCreateChatroom() { //Necessary to create the child chatroom before requesting its information var USER = _helper.testUsers[1]; ChatroomController chatControllerTest = new ChatroomController(); ChatRequestModel model = new ChatRequestModel() { RawChatroomIdValue = "123401", UserHandle = USER.DefaultHandle, ChatroomName = "TestCreateChatroom", User = new UserModel() { Id = USER.Id, Username = USER.Username } }; ChatResponseTestModel chatRoom = _helper.createChatroomAndAddUser(model);//for now don't do anything with the result //Create test data model - with all options possible since without them is easier. Do hard mode xD CreateChatroomRequestModel model2 = new CreateChatroomRequestModel() { ChatroomName = ("PRIVATE" + chatRoom.ChatroomModel.ChatroomName), ParentChatroomId = chatRoom.ChatroomModel.ChatroomId, Blacklist = "test1,test2", Password = "******", Capacity = 30, User = new UserModel() { Id = USER.Id } }; //Test creating a private chatroom success var result = chatControllerTest.CreateChatroom(model2) as JsonResult; Assert.AreEqual(0, ((CreateChatroomResponseModel)result.Data).Errors.Count); Assert.AreEqual(("PRIVATE" + chatRoom.ChatroomModel.ChatroomName), ((CreateChatroomResponseModel)result.Data).ChatroomName); Assert.AreEqual(chatRoom.ChatroomModel.ChatroomId, ((CreateChatroomResponseModel)result.Data).ParentChatroomId); Assert.AreEqual(USER.Id, ((CreateChatroomResponseModel)result.Data).UserId); //Test trying to create duplicate named private chatroom fail result = chatControllerTest.CreateChatroom(model2) as JsonResult; Assert.AreNotEqual(0, ((CreateChatroomResponseModel)result.Data).Errors.Count); Assert.AreEqual("A private chatroom with this name already exists.", ((CreateChatroomResponseModel)result.Data).Errors[0].ErrorMessage); }
public JsonResult SendMessage(long userId) { if (userId != 0) { long userID = Convert.ToInt64(Session["UserId"]); ChatRequestModel m = new ChatRequestModel() { FromUserId = userID, ToUserId = userId }; propertyService.AddChatRequest(m); wsBase wsBase = new wsBase(); wsBase.status = true; return(Json(wsBase, JsonRequestBehavior.AllowGet)); } else { return(Json("Session Expired", JsonRequestBehavior.AllowGet)); } }
public static List <ErrorModel> CanUserJoinChatroom(ChatRequestModel request) { var model = new JoinChatroomRequestModel(); if (request.RawChatroomIdValue == null) { model.ChatroomId = 0; model.ParentChatroomId = 0; } else { model.ChatroomId = request.RawChatroomIdValue.GetHashCode(); model.ParentChatroomId = request.RawChatroomIdValue.GetHashCode(); } model.Password = null; model.UserHandle = request.UserHandle; model.User = request.User; return(CanUserJoinChatroom(model)); }
public async Task TestIfRemoveChatRequestWorksAccordingly(string connectionOne, string connectionTwo) { var context = PCHUBDbContextInMemoryInitializer.InitializeContext(); var chatRequests = new RequestChatServices(context); var modelOne = new ChatRequestModel(); modelOne.Email = "*****@*****.**"; modelOne.ConnectionId = connectionOne; modelOne.IsAuthenticated = true; modelOne.Subject = "Help me select laptop"; await chatRequests.AddToQueueAsync(modelOne); var modelTwo = new ChatRequestModel(); modelOne.Email = "*****@*****.**"; modelOne.ConnectionId = connectionTwo; modelOne.IsAuthenticated = true; modelOne.Subject = "Help me select random laptop"; await chatRequests.AddToQueueAsync(modelOne); await chatRequests.RemoveChatRequestAsync(connectionOne); var resultOne = await chatRequests.GetAllChatRequestsAsync(); Assert.NotEmpty(resultOne); Assert.Single(resultOne); await chatRequests.RemoveChatRequestAsync(connectionTwo); var resultTwo = await chatRequests.GetAllChatRequestsAsync(); Assert.Empty(resultTwo); }
public async Task TestIfAddToQueueWorksAccordingly() { var context = PCHUBDbContextInMemoryInitializer.InitializeContext(); var chatRequests = new RequestChatServices(context); var model = new ChatRequestModel(); model.Email = "*****@*****.**"; model.ConnectionId = "connectionId"; model.IsAuthenticated = true; model.Subject = "Help me select laptop"; await chatRequests.AddToQueueAsync(model); var result = await context.ChatRequests.FirstOrDefaultAsync(x => x.Email == "*****@*****.**"); Assert.NotNull(result); Assert.Equal("connectionId", result.ConnetctionId); Assert.True(result.IsAuthenticated); Assert.Equal("Help me select laptop", result.Subject); }