public void Details_AuthorizedMessageReceiver_ReturnsViewWithMessageOfGivenId() { var(context, controller) = CreateTestTools( nameof(Details_AuthorizedMessageReceiver_ReturnsViewWithMessageOfGivenId) ); var testUser = UserDataManager.AuthorizeControllerUser(controller, context); var otherUser = UserDataManager.CreateTestUser(context, Role.USER, "*****@*****.**"); var message = MessageDataManager.CreateMessage( context, "Test", "Test", otherUser, new List <User> { testUser }, new List <User>(), new List <User>() ); MessageDataManager.CreateMessage( context, "Test2", "Test2", otherUser, new List <User> { testUser }, new List <User>(), new List <User>() ); var result = controller.Details(message.MessageId).Result as ViewResult; Assert.NotNull(result); var modelMessage = result.Model as Message; Assert.NotNull(modelMessage); Assert.Equal(message.MessageId, modelMessage.Id); }
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 Index_UserAuthorized_ReturnsNotFound() { var(context, controller) = CreateTestTools(nameof(Index_UserAuthorized_ReturnsNotFound)); UserDataManager.AuthorizeControllerUser(controller, context, Role.USER); var result = controller.Index().Result; Assert.True(result is NotFoundResult); }
public void GetConfig_UserAuthorizedNotAdmin_ReturnsForbid() { var(context, controller) = CreateTestTools(nameof(GetConfig_UserAuthorizedNotAdmin_ReturnsForbid)); UserDataManager.AuthorizeControllerUser(controller, context); var result = controller.GetConfig().Result; Assert.IsType <ForbidResult>(result); }
public void Configure_UserAuthorizedNotAdmin_ReturnsForbid() { var(context, controller) = CreateTestTools(nameof(Configure_UserAuthorizedNotAdmin_ReturnsForbid)); UserDataManager.AuthorizeControllerUser(controller, context); var result = controller.Configure(new NotificationConfig()).Result; Assert.IsType <ForbidResult>(result); }
public void DisableUser_UserAuthorizedNotAdmin_ReturnsNotFound() { var(context, controller) = CreateTestTools(nameof(DisableUser_UserAuthorizedNotAdmin_ReturnsNotFound)); UserDataManager.AuthorizeControllerUser(controller, context); var targetUser = UserDataManager.CreateUser(context, "*****@*****.**"); var result = controller.DisableUser(targetUser.Email).Result; Assert.IsType <NotFoundResult>(result); }
public void GetCurrentUser_UserAuthorized_ReturnsCorrectUserObject() { var(context, controller) = CreateTestTools(nameof(GetCurrentUser_UserAuthorized_ReturnsCorrectUserObject)); var user = UserDataManager.AuthorizeControllerUser(controller, context); var result = controller.GetCurrentUser().Result as JsonResult; Assert.NotNull(result); Assert.Equal(new User(user), result.Value); }
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 GetConfig_UserAuthorizedAdmin_ReturnsNotificationConfig() { var(context, controller) = CreateTestTools( nameof(GetConfig_UserAuthorizedAdmin_ReturnsNotificationConfig) ); UserDataManager.AuthorizeControllerUser(controller, context, Role.ADMIN); var result = controller.GetConfig().Result as JsonResult; Assert.NotNull(result); Assert.IsType <NotificationConfig>(result.Value); }
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 CreateGroup_UserAuthorized_AddsGroupToDatabase() { var(context, controller) = CreateTestTools(nameof(CreateGroup_UserAuthorized_AddsGroupToDatabase)); var user = UserDataManager.AuthorizeControllerUser(controller, context); const string groupName = "Test group"; controller.CreateGroup(groupName).Wait(); var groupEntity = context.Groups.First(g => g.Admin.Email.Equals(user.Email)); Assert.Equal(groupName, groupEntity.Name); }
public void Details_ExistingUserNotGroupAdmin_ReturnsNotFound() { var(context, controller) = CreateTestTools(nameof(Details_ExistingUserNotGroupAdmin_ReturnsNotFound)); var testUser = UserDataManager.AuthorizeControllerUser(controller, context); var groupAdmin = UserDataManager.CreateTestUser(context, Role.USER, "*****@*****.**"); GroupDataManager.CreateGroup(context, "Stary obóz", groupAdmin); int id = context.Groups.First().GroupId; var result = controller.Details(id); Assert.True(result is NotFoundResult); }
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 DeleteGroup_UserAuthorizedGroupAdmin_RemovesGroupFromDatabase() { var(context, controller) = CreateTestTools( nameof(DeleteGroup_UserAuthorizedGroupAdmin_RemovesGroupFromDatabase) ); var user = UserDataManager.AuthorizeControllerUser(controller, context); var group = GroupDataManager.CreateGroup(context, "Test group", user); controller.DeleteGroup(group.Id).Wait(); var ids = context.Groups.Select(g => g.GroupId).ToList(); Assert.DoesNotContain(group.Id, ids); }
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 Index_UserAuthorized_ReturnsMessagesReceivedByUser() { var(context, controller) = CreateTestTools(nameof(Index_UserAuthorized_ReturnsMessagesReceivedByUser)); var testUser = UserDataManager.AuthorizeControllerUser(controller, context); var otherUser = UserDataManager.CreateTestUser(context, Role.USER, "*****@*****.**"); var received = MessageDataManager.CreateMessage( context, "Test", "Test", otherUser, new List <User> { testUser }, new List <User>(), new List <User>() ); var cc = MessageDataManager.CreateMessage( context, "Test", "Test", otherUser, new List <User>(), new List <User> { testUser }, new List <User>() ); var bcc = MessageDataManager.CreateMessage( context, "Test", "Test", otherUser, new List <User>(), new List <User>(), new List <User> { testUser } ); var other = MessageDataManager.CreateMessage( context, "Test", "Test", testUser, new List <User> { otherUser }, new List <User> { otherUser }, new List <User> { otherUser } ); var result = controller.Index().Result as ViewResult; Assert.NotNull(result); var model = result.Model as InboxViewModel; Assert.NotNull(model); Assert.Equal(testUser.Email, model.User.Email); var msgIds = model.Messages.Select(m => m.Id).ToList(); Assert.DoesNotContain(other.MessageId, msgIds); Assert.Contains(received.MessageId, msgIds); Assert.Contains(cc.MessageId, msgIds); Assert.Contains(bcc.MessageId, msgIds); }
public void Details_AuthorizedUserNotReceiver_ReturnsNotFound() { var(context, controller) = CreateTestTools(nameof(Details_AuthorizedUserNotReceiver_ReturnsNotFound)); var testUser = UserDataManager.AuthorizeControllerUser(controller, context); var otherUser = UserDataManager.CreateTestUser(context, Role.USER, "*****@*****.**"); var message = MessageDataManager.CreateMessage( context, "Test", "Test", testUser, new List <User> { otherUser }, new List <User>(), new List <User>() ); var result = controller.Details(message.MessageId).Result; Assert.True(result is NotFoundResult); }
public void CreateGroup_UserAuthorized_ReturnsCreatedGroup() { var(context, controller) = CreateTestTools(nameof(CreateGroup_UserAuthorized_ReturnsCreatedGroup)); var user = UserDataManager.AuthorizeControllerUser(controller, context); const string groupName = "Test group"; var result = controller.CreateGroup(groupName).Result as JsonResult; Assert.NotNull(result); var group = result.Value as Group; Assert.NotNull(group); Assert.Equal(user.Email, group.Admin.Email); Assert.Equal(groupName, group.Name); }
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 Details_ExistingUserGroupAdmin_ReturnsViewWithGroupOfGivenId() { var(context, controller) = CreateTestTools( nameof(Details_ExistingUserGroupAdmin_ReturnsViewWithGroupOfGivenId) ); var testUser = UserDataManager.AuthorizeControllerUser(controller, context); GroupDataManager.CreateGroup(context, "Stary obóz", testUser); int id = context.Groups.First().GroupId; var result = controller.Details(id) as ViewResult; Assert.NotNull(result); var group = result.Model as Group; Assert.NotNull(group); Assert.Equal(id, group.Id); }
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 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 Index_ExistingUserAuthorized_ReturnsViewWithUserGroups() { var(context, controller) = CreateTestTools(nameof(Index_ExistingUserAuthorized_ReturnsViewWithUserGroups)); var testUser = UserDataManager.AuthorizeControllerUser(controller, context); GroupDataManager.CreateGroup(context, "Stary obóz", testUser); GroupDataManager.CreateGroup(context, "Nowy obóz", testUser); var result = controller.Index().Result as ViewResult; Assert.NotNull(result); var groups = (List <Group>)result.ViewData.Model; var userGroups = context.Groups .Where(g => g.Admin.Email.Equals(testUser.Email)) .Select(g => GroupDataManager.CreateGroup(g)).ToList(); groups.Sort((g1, g2) => string.CompareOrdinal(g1.Name, g2.Name)); userGroups.Sort((g1, g2) => string.CompareOrdinal(g1.Name, g2.Name)); Assert.Equal(userGroups, groups); }
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 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 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 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)); }
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); }