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 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 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 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 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 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 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); }