public void JoinRoom(ChatUser user, ChatRoom room, string inviteCode) { // Throw if the room is private but the user isn't allowed if (room.Private) { // First, check if the invite code is correct if (!String.IsNullOrEmpty(inviteCode) && String.Equals(inviteCode, room.InviteCode, StringComparison.OrdinalIgnoreCase)) { // It is, add the user to the allowed users so that future joins will work room.AllowedUsers.Add(user); } if (!room.IsUserAllowed(user)) { throw new HubException(String.Format(LanguageResources.Join_LockedAccessPermission, room.Name)); } } // Add this user to the room _repository.AddUserRoom(user, room); ChatUserPreferences userPreferences = user.Preferences; userPreferences.TabOrder.Add(room.Name); user.Preferences = userPreferences; // Clear the cache _cache.RemoveUserInRoom(user, room); }
public void VerifyUserRoomTest() { var user1 = new ChatUser(); // null var testRoom = new ChatRoom() { Name = "testRoom" }; // null // test HubException with empty string parameter Assert.Throws <HubException>(() => _repository.VerifyUserRoom(_cache, user1, "")); // test HubException if room = null Assert.Throws <HubException>(() => _repository.VerifyUserRoom(_cache, user1, "testRoom")); // test HubException ChatRoom returns null _repository.Add(testRoom); _repository.AddUserRoom(user1, testRoom); //repository.IsUserInRoom(cache, user, room) uses cache, FAILS -- NOT IMPLEMENTED -- Possibly DI of Repo //Assert.Throws<HubException>(() => _repository.VerifyUserRoom(_cache, user1, "testRoom")); // Clean up _repository.Remove(testRoom); _repository.RemoveUserRoom(user1, testRoom); Console.WriteLine("\tRepositoryExtensionTest.VerifyUserRoomTest: Complete"); }
public void JoinRoom(ChatUser user, ChatRoom room, string inviteCode) { // Throw if the room is private but the user isn't allowed if (room.Private) { // First, check if the invite code is correct if (!String.IsNullOrEmpty(inviteCode) && String.Equals(inviteCode, room.InviteCode, StringComparison.OrdinalIgnoreCase)) { // It is, add the user to the allowed users so that future joins will work room.AllowedUsers.Add(user); } if (!IsUserAllowed(room, user)) { throw new InvalidOperationException(String.Format("Unable to join {0}. This room is locked and you don't have permission to enter. If you have an invite code, make sure to enter it in the /join command", room.Name)); } } // Add this user to the room _repository.AddUserRoom(user, room); // Clear the cache _cache.RemoveUserInRoom(user, room); }