public IEnumerable <UserLightModel> GetAllMembers(TeamLightModel team) { var allMembership = this.userTeamMemberRepository.GetAll().ToList(); var allUsers = this.userRepository.GetAll().ToList(); return(findMyMembers(allMembership, allUsers, team)); }
public IEnumerable <MyRecentActivityModel> GetRecentUserActivity(UserLightModel user) { const int contributionViewedNumber = 5; var detailUser = GetDetail(user) as UserModel; List <MyRecentActivityModel> myRecentActivity = new List <MyRecentActivityModel>(); foreach (var contribution in detailUser.MyContributions.OrderByDescending(contribution => contribution.Date).Take(contributionViewedNumber)) { TeamLightModel teamAssociatedWithContribution = new TeamLightModel(); switch (contribution) { case PostLightModel post: teamAssociatedWithContribution = findAssociatedTeam(post); break; case CommentLightModel comment: teamAssociatedWithContribution = findAssociatedTeam(findAssociatedPost(comment)); break; } myRecentActivity.Add(new MyRecentActivityModel { PublicationTime = contribution.Date, Contribution = contribution, Team = teamAssociatedWithContribution }); } return(myRecentActivity); }
private void Load(TeamLightModel selectedTeam) { this.SelectedTeam = selectedTeam; TeamsMembers.Clear(); var teamMembers = facade.GetAllMembers(selectedTeam) .ToList(); TeamsMembers.AddRange(teamMembers); }
private IEnumerable <int?> getMembersIds(TeamLightModel team) { var membersIds = new List <int?>(); var detailTeam = GetDetail(team) as TeamModel; foreach (var membership in detailTeam.Members) { membersIds.Add(membership.UserId); } return(membersIds); }
public void Load(TeamLightModel team) { this.TeamWhereArentUsers = new TeamLightModel { Id = team.Id, Name = team.Name }; TeamsNonMembers.Clear(); var teamNonMembers = facade.GetAllNonMembers(team) .ToList(); TeamsNonMembers.AddRange(teamNonMembers); }
public void DeleteUserFromTeam(UserLightModel user, TeamLightModel team) { var unWantedUser = new UserTeamMemberModel { Team = team, TeamId = team.Id, User = user, UserId = user.Id }; this.userTeamMemberRepository.Remove(unWantedUser.UserId, unWantedUser.TeamId); }
public void JoinUserToTeam(UserLightModel user, TeamLightModel team) { var requestingUser = new UserTeamMemberModel { Team = team, TeamId = team.Id, User = user, UserId = user.Id }; this.userTeamMemberRepository.Add(requestingUser); }
public Team MapTeamLightModelToTeam(TeamLightModel lightModel) { if (lightModel == null) { return(null); } return(new Team { Id = lightModel.Id, Name = lightModel.Name }); }
public void IsUserAdmin_ExistingTeam_ReturnsTrue() { //Arrange var teamModel = new TeamLightModel() { Id = 1 }; var user = FacadeSUT.FindUserByEmail("*****@*****.**"); //Act var isAdmin = FacadeSUT.IsUserAdminInTeam(user, teamModel); //Assert Assert.True(isAdmin); }
public void ConvertTeamModelToTeamLightModel_WithExistingTeam() { //Arrange var teamModel = new TeamLightModel() { Id = 1 }; var existingTeam = FacadeSUT.GetDetail(teamModel) as TeamModel; //Act var existingTeamLightModel = FacadeSUT.ConvertTeamModelToTeamLightModel(existingTeam); //Assert Assert.Equal(existingTeamLightModel.Id, teamModel.Id); }
public void FindNewestNPostsInTeam_WithExistingTeam() { //Arrange var team = new TeamLightModel() { Id = 1 }; var existingTeam = FacadeSUT.GetDetail(team) as TeamModel; //Act var newestPosts = FacadeSUT.FindNewestNPostsInTeam(existingTeam, 2); var numberOfFoundPosts = newestPosts.Count(); //Assert Assert.Equal(2, numberOfFoundPosts); }
public void DelegateAdminPosition(UserLightModel user, TeamLightModel team) { var teamModel = GetDetail(team) as TeamModel; var teamWithNewAdmin = new TeamModel { Admin = user, Description = teamModel.Description, Id = teamModel.Id, Members = teamModel.Members, Name = teamModel.Name, Posts = teamModel.Posts }; this.Update(teamWithNewAdmin); }
public IEnumerable <UserLightModel> GetAllNonMembers(TeamLightModel team) { var allUsers = this.userRepository.GetAll().ToList(); var membersIds = getMembersIds(team); var nonMembers = new List <UserLightModel>(); foreach (var user in allUsers) { if (!isUserInTeam(user, membersIds)) { nonMembers.Add(user); } } return(nonMembers); }
public void SearchInTeam_PatternDoesNotExist_ReturnsContributions() { //Arrange var team = new TeamLightModel() { Id = 1 }; var existingTeam = FacadeSUT.GetDetail(team) as TeamModel; const string pattern = "bogus"; //Act var contributions = FacadeSUT.Search(pattern, existingTeam); var numberOfContributions = contributions.Count(); //Assert Assert.Equal(0, numberOfContributions); }
private void Save() { if (Model.Id == null) { Model = facade.Create(Model) as TeamModel; var lightTeam = new TeamLightModel { Id = Model.Id }; var lightUser = new UserLightModel { Id = Model.Admin.Id }; facade.JoinUserToTeam(lightUser, lightTeam); } else { facade.Update(Model); } }
public void DelegateAdminPosition_WithExistingTeamAndUser_AdminDelegated() { //Arrange var teamModel = new TeamLightModel() { Id = 1 }; var notAdmin = new UserLightModel() { Id = 3 }; //Act FacadeSUT.DelegateAdminPosition(notAdmin, teamModel); var updatedTeam = FacadeSUT.GetDetail(teamModel) as TeamModel; //Assert Debug.Assert(updatedTeam != null, nameof(updatedTeam) + " != null"); Assert.Equal(notAdmin.Id, updatedTeam.Admin.Id); }
public bool IsUserAdminInTeam(UserLightModel user, TeamLightModel team) { var teamDetail = GetDetail(team) as TeamModel; return(teamDetail.Admin.Id == user.Id); }
public void getAllPostsInIFJTeam_twoPosts_notThrow() { //Arrange var imageToUserLucas = new ProfileImageModel { Id = 810, Content = new byte[10], FileName = "Profile Lucas Picture", PictureFormat = SupportedFormatPicture.Png }; imageToUserLucas = FacadeSUT.Create(imageToUserLucas) as ProfileImageModel; var imageToUserLucasLight = new ProfileImageLightModel { Id = imageToUserLucas.Id }; var lucas = new UserModel { Id = 811, AdministratedTeams = new List <TeamLightModel>(), ContributionUserTags = new List <ContributionUserTagModel>(), Email = "*****@*****.**", FirstName = "Lucas", LastName = "Collins", MyContributions = new List <ContributionLightModel>(), Password = "******", ProfilePicture = imageToUserLucasLight, UserDescription = "Lucas school account", UserTeams = new List <UserTeamMemberModel>() }; lucas = FacadeSUT.Create(lucas) as UserModel; var lucasLight = new UserLightModel { Id = lucas.Id }; var teamIFJ = new TeamModel { Id = 812, Admin = lucasLight, Description = "Team for formal language and compilators (IFJ) project.", Name = "IFJ team", Posts = new List <PostLightModel>(), Members = new List <UserTeamMemberModel>() }; teamIFJ = FacadeSUT.Create(teamIFJ) as TeamModel; var teamLight = new TeamLightModel { Id = teamIFJ.Id }; FacadeSUT.JoinUserToTeam(lucasLight, teamLight); var lucasPostInIFJ = new PostModel { Id = 813, AssociatedFiles = new List <ContributionFileLightModel>(), Author = lucasLight, Comments = new List <CommentModel>(), Content = "Download documentation on private web.", ContributionUserTags = new List <ContributionUserTagModel>(), CorrespondingTeam = teamLight, Date = new DateTime(2019, 2, 1), Title = "Project has been released!" }; lucasPostInIFJ = FacadeSUT.Create(lucasPostInIFJ) as PostModel; teamIFJ = FacadeSUT.GetDetail(teamLight) as TeamModel; //Act var allPosts = FacadeSUT.GetAllPostsInTeam(teamIFJ).ToList(); //Assert Assert.Contains(allPosts, model => model.Id == lucasPostInIFJ.Id); }
public void findAllNonMemebrs_UserIsNotMember_UserIsInNonmembersList() { //Arrange ProfileImageModel imageToUserJames = new ProfileImageModel { Id = 670, Content = new byte[10], FileName = "Profile James Picture", PictureFormat = SupportedFormatPicture.Jpg }; var lightPic = new ProfileImageLightModel { Id = imageToUserJames.Id }; imageToUserJames = FacadeSUT.Create(imageToUserJames) as ProfileImageModel; UserModel userModel = new UserModel { Id = 671, AdministratedTeams = new List <TeamLightModel>(), ContributionUserTags = new List <ContributionUserTagModel>(), Email = "*****@*****.**", FirstName = "James", LastName = "Smith", MyContributions = new List <ContributionLightModel>(), Password = "******", ProfilePicture = new ProfileImageLightModel { Id = imageToUserJames.Id }, UserDescription = "James school account", UserTeams = new List <UserTeamMemberModel>() }; userModel = FacadeSUT.Create(userModel) as UserModel; var userLight = new UserLightModel { Id = userModel.Id }; var teamModel = new TeamModel { Id = 672, Name = "Team1", Description = "First team", Admin = new UserLightModel(), Members = new List <UserTeamMemberModel>(), Posts = new List <PostLightModel>() }; teamModel = FacadeSUT.Create(teamModel) as TeamModel; var teamLight = new TeamLightModel { Id = teamModel.Id }; //Act var allNonUsers = FacadeSUT.GetAllNonMembers(teamLight); //Assert Assert.Contains(allNonUsers, model => model.Id == userModel.Id); }
public void JoinUserToTeam_UserAndTeamExist_UserIsTeamMember() { ProfileImageModel imageToUserJames = new ProfileImageModel { Id = 620, Content = new byte[10], FileName = "Profile James Picture", PictureFormat = SupportedFormatPicture.Jpg }; var lightPic = new ProfileImageLightModel { Id = 620 }; imageToUserJames = FacadeSUT.Create(imageToUserJames) as ProfileImageModel; UserModel userModel = new UserModel { Id = 621, AdministratedTeams = new List <TeamLightModel>(), ContributionUserTags = new List <ContributionUserTagModel>(), Email = "*****@*****.**", FirstName = "James", LastName = "Smith", MyContributions = new List <ContributionLightModel>(), Password = "******", ProfilePicture = new ProfileImageLightModel { Id = imageToUserJames.Id }, UserDescription = "James school account", UserTeams = new List <UserTeamMemberModel>() }; userModel = FacadeSUT.Create(userModel) as UserModel; var userLight = new UserLightModel { Id = userModel.Id }; var teamModel = new TeamModel { Id = 622, Name = "Team1", Description = "First team", Admin = new UserLightModel(), Members = new List <UserTeamMemberModel>(), Posts = new List <PostLightModel>() }; teamModel = FacadeSUT.Create(teamModel) as TeamModel; var teamLight = new TeamLightModel { Id = teamModel.Id }; //Act FacadeSUT.JoinUserToTeam(userLight, teamLight); //Assert var teamsMembers = FacadeSUT.GetAllMembers(teamLight).ToList(); Assert.Contains(teamsMembers, member => member.Id == userLight.Id); FacadeSUT.DeleteUserFromTeam(userLight, teamLight); }
public void FindMyTeam_UserInTeams_IsInTeams() { //Arrange ProfileImageModel imageToUserJames = new ProfileImageModel { Id = 660, Content = new byte[10], FileName = "Profile James Picture", PictureFormat = SupportedFormatPicture.Jpg }; imageToUserJames = FacadeSUT.Create(imageToUserJames) as ProfileImageModel; var lightPic = new ProfileImageLightModel { Id = imageToUserJames.Id }; UserModel userModel = new UserModel { Id = 661, AdministratedTeams = new List <TeamLightModel>(), ContributionUserTags = new List <ContributionUserTagModel>(), Email = "*****@*****.**", FirstName = "James", LastName = "Smith", MyContributions = new List <ContributionLightModel>(), Password = "******", ProfilePicture = new ProfileImageLightModel { Id = imageToUserJames.Id }, UserDescription = "James school account", UserTeams = new List <UserTeamMemberModel>() }; userModel = FacadeSUT.Create(userModel) as UserModel; var userLight = new UserLightModel { Id = userModel.Id }; var teamModel = new TeamModel { Id = 662, Name = "Team1", Description = "First team", Admin = new UserLightModel(), Members = new List <UserTeamMemberModel>(), Posts = new List <PostLightModel>() }; teamModel = FacadeSUT.Create(teamModel) as TeamModel; var teamLight = new TeamLightModel { Id = teamModel.Id }; //Act FacadeSUT.JoinUserToTeam(userLight, teamLight); //Act var teams = FacadeSUT.FindMyTeams(userLight).ToList(); //Assert var teamsCount = teams.Count; Assert.Equal(1, teamsCount); }
private void MyTeamSelected(TeamLightModel myTeamLightModel) => mediator.Send(new MyTeamSelectedMessage { MyTeam = myTeamLightModel });
private void Load(TeamLightModel team) { this.ModelForMessages = team; this.Model = facade.GetDetail(team) as TeamModel; }
private IEnumerable <UserLightModel> findMyMembers(IEnumerable <UserTeamMemberModel> allMembership, IEnumerable <UserLightModel> allUsers, TeamLightModel team) { var myUsersIds = (from membership in allMembership where membership.TeamId == team.Id select membership.UserId).ToList(); var myUsers = new List <UserLightModel>(); foreach (var myUserId in myUsersIds) { myUsers.Add(allUsers.FirstOrDefault(user => myUserId == user.Id)); } return(myUsers); }