public void GetAll_MultipleUsersRoleArgGuest_ReturnsAllUsers() { var users = new List <User>() { new User() { Email = "*****@*****.**", FirstName = "Gomez", LastName = "", Role = Role.ADMIN }, new User() { Email = "*****@*****.**", FirstName = "Diego", LastName = "", Role = Role.USER }, new User() { Email = "*****@*****.**", FirstName = "Bezi", LastName = "Mienny", Role = Role.GUEST } }; var(context, userService) = CreateTestTools(nameof(GetAll_MultipleUsersRoleArgGuest_ReturnsAllUsers)); foreach (var user in users) { UserDataManager.CreateUser(context, user); } var allUsers = userService.GetAll(Role.GUEST).ToList(); users.Sort((u1, u2) => string.CompareOrdinal(u1.Email, u2.Email)); allUsers.Sort((u1, u2) => string.CompareOrdinal(u1.Email, u2.Email)); Assert.Equal(users, allUsers); }
public void ConfirmPlayerName() { SetPlayerNameWindow.SetActive(false); dataManager.SetUserName(curPlayerName); dataManager.CreateUser(slotInd); loginManager.RefreshPlayerList(); }
public void GetGroup_UserAuthorizedGroupAdmin_ReturnsRequiredGroupDetails() { var(context, controller) = CreateTestTools( nameof(GetGroup_UserAuthorizedGroupAdmin_ReturnsRequiredGroupDetails) ); var user = UserDataManager.AuthorizeControllerUser(controller, context); var member1 = UserDataManager.CreateUser(context, "*****@*****.**"); var member2 = UserDataManager.CreateUser(context, "*****@*****.**"); var notMember = UserDataManager.CreateUser(context, "*****@*****.**"); var group = GroupDataManager.CreateGroup( context, "Test group", user, new List <Database.POCO.User> { member1, member2 } ); var result = controller.GetGroup(group.Id) as JsonResult; Assert.NotNull(result); var groupDetails = result.Value as GroupDetails; Assert.NotNull(groupDetails); AssertUserListsEqual(group.Users.ToList(), groupDetails.GroupMembers); AssertUserListsEqual( new List <User> { new User(notMember), new User(user) }, groupDetails.UserGlobalList ); }
public void SetReadByIdAsync_SetReadByBcc_MessageStateChangedForRightUserOnly() { var(context, messageService) = CreateTestTools( nameof(SetReadByIdAsync_SetReadByBcc_MessageStateChangedForRightUserOnly) ); var sender = UserDataManager.CreateTestUser(context); var receiver = UserDataManager.CreateUser(context, "*****@*****.**"); var ccUser = UserDataManager.CreateUser(context, "*****@*****.**"); var bccUser = UserDataManager.CreateUser(context, "*****@*****.**"); var otherBcc = UserDataManager.CreateUser(context, "*****@*****.**"); var message = MessageDataManager.CreateMessage( context, "Test", "Test", sender, new List <Database.POCO.User> { receiver }, new List <Database.POCO.User> { ccUser }, new List <Database.POCO.User> { bccUser, otherBcc } ); Assert.False(message.MessagesBCCs.First(b => b.User.Equals(bccUser)).IsRead); bool receiverRead = message.MessagesReceivers.First(r => r.User.Equals(receiver)).IsRead; bool ccRead = message.MessagesCCs.First(c => c.User.Equals(ccUser)).IsRead; bool otherRead = message.MessagesBCCs.First(b => b.User.Equals(otherBcc)).IsRead; messageService.SetReadByIdAsync(message.MessageId, new User(bccUser), true).Wait(); var updated = context.Messages.Find(message.MessageId); Assert.True(updated.MessagesBCCs.First(b => b.User.Equals(bccUser)).IsRead); Assert.Equal(receiverRead, message.MessagesReceivers.First(r => r.User.Equals(receiver)).IsRead); Assert.Equal(ccRead, message.MessagesCCs.First(c => c.User.Equals(ccUser)).IsRead); Assert.Equal(otherRead, message.MessagesBCCs.First(b => b.User.Equals(otherBcc)).IsRead); }
public void UpdateAsync_AddingReceivers_UpdatesMessageInDatabase() { var(context, messageService) = CreateTestTools( nameof(UpdateAsync_AddingReceivers_UpdatesMessageInDatabase) ); var testUser = UserDataManager.CreateTestUser(context); var otherUser = UserDataManager.CreateUser(context, "*****@*****.**"); var msgEntity = MessageDataManager.CreateMessage( context, "Test", "Test", testUser, new List <Database.POCO.User> { otherUser }, new List <Database.POCO.User>(), new List <Database.POCO.User>() ); var message = new Message(msgEntity, new User(msgEntity.Sender)); message.Receivers = msgEntity.Receivers.Select(r => new User(r)).ToList(); message.AddReceiver(new User(testUser)); var task = messageService.UpdateAsync(message); task.Wait(); msgEntity.Receivers.Add(testUser); var updatedEntity = context.Messages.Find(msgEntity.MessageId); Assert.Equal(msgEntity, updatedEntity); }
public void DisableUser_UserNotAuthorized_ReturnsNotFound() { var(context, controller) = CreateTestTools(nameof(DisableUser_UserNotAuthorized_ReturnsNotFound)); var targetUser = UserDataManager.CreateUser(context, "*****@*****.**"); var result = controller.DisableUser(targetUser.Email).Result; Assert.IsType <NotFoundResult>(result); }
public void AcceptUser_UserAuthorizedNotAdmin_ReturnsNotFound() { var(context, controller) = CreateTestTools(nameof(AcceptUser_UserAuthorizedNotAdmin_ReturnsNotFound)); UserDataManager.AuthorizeControllerUser(controller, context); var targetUser = UserDataManager.CreateUser(context, "*****@*****.**"); var result = controller.AcceptUser(targetUser.Email).Result; Assert.IsType <NotFoundResult>(result); }
public void DisableUser_AdminAuthorizedTargetUserIsAdmin_ReturnsNoContent() { var(context, controller) = CreateTestTools( nameof(DisableUser_AdminAuthorizedTargetUserIsAdmin_ReturnsNoContent) ); UserDataManager.AuthorizeControllerUser(controller, context, Role.ADMIN); var targetUser = UserDataManager.CreateUser(context, "*****@*****.**", Role.ADMIN); var result = controller.DisableUser(targetUser.Email).Result; Assert.IsType <NoContentResult>(result); }
public void Get_SingleUser_ReturnsUserWithGivenEmail() { const string email = "*****@*****.**"; var(context, userService) = CreateTestTools(nameof(Get_SingleUser_ReturnsUserWithGivenEmail)); UserDataManager.CreateUser(context, email); var user = userService.Get(email); Assert.Equal(email, user.Email); }
private void DisplayNewUserFields() { EditorGUILayout.Space(); EditorGUILayout.LabelField("New User:"******"Create User")) { source.CreateUser(source.Users.Count); sourceRef.Update(); } EditorGUILayout.Space(); }
public void GetAllToUser_MultipleMessages_ReturnsOnlySentToGivenUser() { var(context, messageService) = CreateTestTools( nameof(GetAllToUser_MultipleMessages_ReturnsOnlySentToGivenUser) ); var sender = UserDataManager.CreateTestUser(context); var receiver = UserDataManager.CreateUser(context, "*****@*****.**"); var otherReceiver = UserDataManager.CreateUser(context, "*****@*****.**"); var recv1 = MessageDataManager.CreateMessage( context, "Test 1", "Test", sender, new List <Database.POCO.User> { receiver }, new List <Database.POCO.User>(), new List <Database.POCO.User>() ); var recv2 = MessageDataManager.CreateMessage( context, "Test 2", "Test", sender, new List <Database.POCO.User> { receiver, otherReceiver }, new List <Database.POCO.User>(), new List <Database.POCO.User>() ); var recv3 = MessageDataManager.CreateMessage( context, "Test 3", "Test", sender, new List <Database.POCO.User> { otherReceiver }, new List <Database.POCO.User> { receiver }, new List <Database.POCO.User>() ); var recv4 = MessageDataManager.CreateMessage( context, "Test 4", "Test", sender, new List <Database.POCO.User> { otherReceiver }, new List <Database.POCO.User>(), new List <Database.POCO.User> { receiver } ); var notRecv1 = MessageDataManager.CreateMessage( context, "Test 5", "Test", sender, new List <Database.POCO.User> { otherReceiver }, new List <Database.POCO.User>(), new List <Database.POCO.User>() ); var ids = messageService.GetAllToUser(new User(receiver)).Select(m => m.Id).ToList(); Assert.Contains(recv3.MessageId, ids); Assert.Contains(recv4.MessageId, ids); Assert.Contains(recv1.MessageId, ids); Assert.Contains(recv2.MessageId, ids); Assert.DoesNotContain(notRecv1.MessageId, ids); }
public void GetGroup_UserAuthorizedNotGroupAdmin_ReturnsNotFound() { var(context, controller) = CreateTestTools( nameof(GetGroup_UserAuthorizedNotGroupAdmin_ReturnsNotFound) ); UserDataManager.AuthorizeControllerUser(controller, context); var otherUser = UserDataManager.CreateUser(context, "*****@*****.**"); var group = GroupDataManager.CreateGroup(context, "Test group", otherUser); var result = controller.GetGroup(group.Id); Assert.IsType <NotFoundResult>(result); }
public void DisableUser_AdminAuthorizedTargetUserIsAdmin_TargetUserRemainsUnchanged() { var(context, controller) = CreateTestTools( nameof(DisableUser_AdminAuthorizedTargetUserIsAdmin_TargetUserRemainsUnchanged) ); UserDataManager.AuthorizeControllerUser(controller, context, Role.ADMIN); var targetUser = UserDataManager.CreateUser(context, "*****@*****.**", Role.ADMIN); controller.DisableUser(targetUser.Email).Wait(); var disabledUser = context.Users.First(u => u.Email.Equals(targetUser.Email)); Assert.Equal(Role.ADMIN, disabledUser.Role); }
public void AcceptUser_AdminAuthorizedTargetUserNotAdmin_TargetUserDisabled() { var(context, controller) = CreateTestTools( nameof(AcceptUser_AdminAuthorizedTargetUserNotAdmin_TargetUserDisabled) ); UserDataManager.AuthorizeControllerUser(controller, context, Role.ADMIN); var targetUser = UserDataManager.CreateUser(context, "*****@*****.**"); controller.AcceptUser(targetUser.Email).Wait(); var acceptedUser = context.Users.First(u => u.Email.Equals(targetUser.Email)); Assert.Equal(Role.USER, acceptedUser.Role); }
public void UpdateAsync_ChangingUserRole_ReturnsUpdatedUser() { var user = new User() { Email = "*****@*****.**", FirstName = "Mariusz", LastName = "Tester", Role = Role.GUEST }; var(context, userService) = CreateTestTools(nameof(UpdateAsync_ChangingUserRole_ReturnsUpdatedUser)); UserDataManager.CreateUser(context, user); user.Role = Role.USER; var updated = userService.UpdateAsync(user).Result; Assert.Equal(user, updated); }
public void DisableUser_AdminAuthorizedTargetUserNotAdmin_ReturnsDisabledUser() { var(context, controller) = CreateTestTools( nameof(DisableUser_AdminAuthorizedTargetUserNotAdmin_ReturnsDisabledUser) ); UserDataManager.AuthorizeControllerUser(controller, context, Role.ADMIN); var targetUser = UserDataManager.CreateUser(context, "*****@*****.**"); var result = controller.DisableUser(targetUser.Email).Result as JsonResult; Assert.NotNull(result); var disabledUser = result.Value as User; Assert.NotNull(disabledUser); Assert.Equal(disabledUser.Email, targetUser.Email); Assert.Equal(Role.GUEST, disabledUser.Role); }
public void GetOrCreateAsync_ExistingUser_ReturnsUserWithGivenEmail() { var(context, userService) = CreateTestTools( nameof(GetOrCreateAsync_ExistingUser_ReturnsUserWithGivenEmail) ); const string email = "*****@*****.**"; UserDataManager.CreateUser(context, email); var claims = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim("emails", email), }, "mock")); var user = userService.GetOrCreateAsync(claims).Result; Assert.Equal(email, user.Email); }
public void GetAll_MultipleUsersRoleArgUser_ReturnsOnlyUsersAndAdmins() { var admin = new User() { Email = "*****@*****.**", FirstName = "Gomez", LastName = "", Role = Role.ADMIN }; var user = new User() { Email = "*****@*****.**", FirstName = "Diego", LastName = "", Role = Role.USER }; var guest = new User() { Email = "*****@*****.**", FirstName = "Bezi", LastName = "Mienny", Role = Role.GUEST }; var users = new List <User>() { admin, user, guest }; var(context, userService) = CreateTestTools( nameof(GetAll_MultipleUsersRoleArgUser_ReturnsOnlyUsersAndAdmins) ); foreach (var u in users) { UserDataManager.CreateUser(context, u); } var allUsers = userService.GetAll(); Assert.Contains(admin, allUsers); Assert.Contains(user, allUsers); Assert.DoesNotContain(guest, allUsers); }
public void AddUsersToGroup_UserAuthorizedGroupAdmin_AddsUserToGroupInDatabase() { var(context, controller) = CreateTestTools( nameof(AddUsersToGroup_UserAuthorizedGroupAdmin_AddsUserToGroupInDatabase) ); var user = UserDataManager.AuthorizeControllerUser(controller, context); var member1 = UserDataManager.CreateUser(context, "*****@*****.**"); var member2 = UserDataManager.CreateUser(context, "*****@*****.**"); var members = new List <User> { new User(member1), new User(member2) }; var group = GroupDataManager.CreateGroup(context, "Test group", user); controller.AddUsersToGroup(group.Id, members).Wait(); var groupEntity = context.Groups.First(g => g.Admin.Email.Equals(user.Email)); AssertUserListsEqual(members, groupEntity.Users.Select(u => new User(u)).ToList()); }
public void SetReadByIdAsync_SetReadByReceiver_ReturnsUpdatedMessage() { var(context, messageService) = CreateTestTools( nameof(SetReadByIdAsync_SetReadByReceiver_ReturnsUpdatedMessage) ); var sender = UserDataManager.CreateTestUser(context); var receiver = UserDataManager.CreateUser(context, "*****@*****.**"); var message = MessageDataManager.CreateMessage( context, "Test", "Test", sender, new List <Database.POCO.User> { receiver }, new List <Database.POCO.User>(), new List <Database.POCO.User>() ); var updated = messageService.SetReadByIdAsync(message.MessageId, new User(receiver), true).Result; AssertMessagesEqual(updated, message); Assert.True(updated.IsReadBy(new User(receiver))); }
public void UpdateAsync_AddingReceivers_ReturnsUpdatedMessage() { var(context, messageService) = CreateTestTools(nameof(UpdateAsync_AddingReceivers_ReturnsUpdatedMessage)); var testUser = UserDataManager.CreateTestUser(context); var otherUser = UserDataManager.CreateUser(context, "*****@*****.**"); var msgEntity = MessageDataManager.CreateMessage( context, "Test", "Test", testUser, new List <Database.POCO.User> { otherUser }, new List <Database.POCO.User>(), new List <Database.POCO.User>() ); var message = new Message(context.Messages.Find(msgEntity.MessageId), new User(msgEntity.Sender)); message.AddReceiver(new User(testUser)); var updated = messageService.UpdateAsync(message).Result; AssertMessagesEqual(message, updated); }
public void MarkRead_UserAuthorized_UpdatesMessageInDatabase() { var(context, controller) = CreateTestTools(nameof(MarkRead_UserAuthorized_UpdatesMessageInDatabase)); var userEntity = UserDataManager.AuthorizeControllerUser(controller, context); var user = new User(userEntity); var otherUser = UserDataManager.CreateUser(context, "*****@*****.**"); var message = MessageDataManager.CreateMessage( context, "Test", "Test", otherUser, new List <Database.POCO.User> { userEntity }, new List <Database.POCO.User>(), new List <Database.POCO.User>() ); controller.MarkRead(message.MessageId, user).Wait(); var updatedMessage = context.Messages.Find(message.MessageId); Assert.True(updatedMessage.MessagesReceivers.First(r => r.User.Email.Equals(user.Email)).IsRead); }
public void GetNewerThan_MultipleOlderMultipleNewer_ReturnsAllNewer() { var(context, messageService) = CreateTestTools( nameof(GetNewerThan_MultipleOlderMultipleNewer_ReturnsAllNewer) ); var testUser = UserDataManager.CreateTestUser(context); var otherUser = UserDataManager.CreateUser(context, "*****@*****.**"); var timeSpan = TimeSpan.FromSeconds(10); var older1 = MessageDataManager.CreateMessage( context, "Test 1", "Old message", testUser, new List <Database.POCO.User> { otherUser }, new List <Database.POCO.User>(), new List <Database.POCO.User>(), DateTime.Now - 2 * timeSpan ); var older2 = MessageDataManager.CreateMessage( context, "Test 2", "Old message", testUser, new List <Database.POCO.User> { otherUser }, new List <Database.POCO.User>(), new List <Database.POCO.User>(), DateTime.Now - 2 * timeSpan ); var newer1 = MessageDataManager.CreateMessage( context, "Test 3", "New message", testUser, new List <Database.POCO.User> { otherUser }, new List <Database.POCO.User>(), new List <Database.POCO.User>() ); var newer2 = MessageDataManager.CreateMessage( context, "Test 4", "New message", testUser, new List <Database.POCO.User> { otherUser }, new List <Database.POCO.User>(), new List <Database.POCO.User>() ); var ids = messageService.GetNewerThan(DateTime.Now - timeSpan).Select(m => m.Id).ToList(); Assert.DoesNotContain(older1.MessageId, ids); Assert.DoesNotContain(older2.MessageId, ids); Assert.Contains(newer1.MessageId, ids); Assert.Contains(newer2.MessageId, ids); }
public void UpdateAsync_ChangingUserRole_UpdatesUserInDatabase() { var user = new User() { Email = "*****@*****.**", FirstName = "Mariusz", LastName = "Tester", Role = Role.GUEST }; var(context, userService) = CreateTestTools(nameof(UpdateAsync_ChangingUserRole_UpdatesUserInDatabase)); UserDataManager.CreateUser(context, user); user.Role = Role.USER; var task = userService.UpdateAsync(user); task.Wait(); var userEntity = context.Users.First(u => u.Email.Equals(user.Email)); Assert.Equal(user.Role, userEntity.Role); }
public void RemoveUserFromGroup_UserAuthorizedGroupAdmin_RemovesUserFromGroupInDatabase() { var(context, controller) = CreateTestTools( nameof(RemoveUserFromGroup_UserAuthorizedGroupAdmin_RemovesUserFromGroupInDatabase) ); var user = UserDataManager.AuthorizeControllerUser(controller, context); var member1 = UserDataManager.CreateUser(context, "*****@*****.**"); var member2 = UserDataManager.CreateUser(context, "*****@*****.**"); var members = new List <Database.POCO.User> { member1, member2 }; var group = GroupDataManager.CreateGroup(context, "Test group", user, members); controller.RemoveUserFromGroup(group.Id, member1.Email).Wait(); var groupEntity = context.Groups.First(g => g.Admin.Email.Equals(user.Email)); var emails = groupEntity.Users.Select(u => u.Email).ToList(); Assert.DoesNotContain(member1.Email, emails); Assert.Contains(member2.Email, emails); }
public void AddUsersToGroup_UserAuthorizedGroupAdmin_ReturnsAddedUsers() { var(context, controller) = CreateTestTools( nameof(AddUsersToGroup_UserAuthorizedGroupAdmin_ReturnsAddedUsers) ); var user = UserDataManager.AuthorizeControllerUser(controller, context); var member1 = UserDataManager.CreateUser(context, "*****@*****.**"); var member2 = UserDataManager.CreateUser(context, "*****@*****.**"); var members = new List <User> { new User(member1), new User(member2) }; var group = GroupDataManager.CreateGroup(context, "Test group", user); var result = controller.AddUsersToGroup(group.Id, members).Result as JsonResult; Assert.NotNull(result); var users = result.Value as List <User>; Assert.NotNull(users); AssertUserListsEqual(members, users); }
public void RemoveUserFromGroup_UserAuthorizedGroupAdmin_ReturnsRemovedUser() { var(context, controller) = CreateTestTools( nameof(RemoveUserFromGroup_UserAuthorizedGroupAdmin_ReturnsRemovedUser) ); var user = UserDataManager.AuthorizeControllerUser(controller, context); var member = UserDataManager.CreateUser(context, "*****@*****.**"); var group = GroupDataManager.CreateGroup( context, "Test group", user, new List <Database.POCO.User> { member } ); var result = controller.RemoveUserFromGroup(group.Id, member.Email).Result as JsonResult; Assert.NotNull(result); var removedUser = result.Value as User; Assert.NotNull(removedUser); Assert.Equal(member.Email, removedUser.Email); }
public void Index_AdminAuthorized_ReturnsViewWithAllUsers() { var(context, controller) = CreateTestTools(nameof(Index_AdminAuthorized_ReturnsViewWithAllUsers)); var testUser = UserDataManager.AuthorizeControllerUser(controller, context, Role.ADMIN); var guest = UserDataManager.CreateUser(context, "*****@*****.**", Role.GUEST); var user = UserDataManager.CreateUser(context, "*****@*****.**", Role.USER); var admin = UserDataManager.CreateUser(context, "*****@*****.**", Role.ADMIN); var result = controller.Index().Result as ViewResult; Assert.NotNull(result); var users = (List <User>)result.ViewData.Model; Assert.NotNull(users); var emails = users.Select(u => u.Email).ToList(); Assert.DoesNotContain(guest.Email, emails); Assert.Contains(user.Email, emails); Assert.Contains(admin.Email, emails); Assert.Contains(testUser.Email, emails); }
public void GetGroups_UserAuthorizedMultipleGroups_ReturnsAdministeredGroups() { var(context, controller) = CreateTestTools( nameof(GetGroups_UserAuthorizedMultipleGroups_ReturnsAdministeredGroups) ); var user = UserDataManager.AuthorizeControllerUser(controller, context); var otherUser = UserDataManager.CreateUser(context, "*****@*****.**"); var group1 = GroupDataManager.CreateGroup(context, "Test group 1", user); var group2 = GroupDataManager.CreateGroup(context, "Test group 2", user); var group3 = GroupDataManager.CreateGroup(context, "Test group 3", otherUser); var result = controller.GetGroups().Result as JsonResult; Assert.NotNull(result); var groups = result.Value as List <Group>; Assert.NotNull(groups); Assert.DoesNotContain(group3, groups); Assert.Contains(group1, groups); Assert.Contains(group2, groups); }
public void MarkUnread_UserAuthorized_ReturnsUpdatedMessage() { var(context, controller) = CreateTestTools(nameof(MarkUnread_UserAuthorized_ReturnsUpdatedMessage)); var userEntity = UserDataManager.AuthorizeControllerUser(controller, context); var user = new User(userEntity); var otherUser = UserDataManager.CreateUser(context, "*****@*****.**"); var message = MessageDataManager.CreateMessage( context, "Test", "Test", otherUser, new List <Database.POCO.User> { userEntity }, new List <Database.POCO.User>(), new List <Database.POCO.User>() ); var result = controller.MarkUnread(message.MessageId, user).Result as JsonResult; Assert.NotNull(result); var updatedMessage = result.Value as Message; Assert.NotNull(updatedMessage); Assert.Equal(message.MessageId, updatedMessage.Id); Assert.False(updatedMessage.IsReadBy(user)); }