public void UnfollowTeamTest() { var team = new Team() { Id = 0, Name = "Team", SportId = 1 }; var teamBL = new TeamBusinessLogic(mockTeamRepo.Object, NO_BUSINESS_LOGIC); var userBL = new UserBusinessLogic(mockUserRepo.Object, teamBL, mockUTRepo.Object); mockTeamRepo.Setup(r => r.GetById(It.IsAny <int>())).Returns(team); mockUserRepo.Setup(r => r.GetById(It.IsAny <int>())).Returns(userWithAllData); var fav = new UsersTeams { TeamId = team.Id, Team = team, User = userWithAllData, UserId = userWithAllData.Id }; mockUTRepo.Setup(r => r.Get(It.IsAny <Expression <Func <UsersTeams, bool> > >(), null, "")).Returns(new List <UsersTeams>() { fav }); userBL.FollowTeam(userWithAllData.Id, team.Id); userBL.UnfollowTeam(userWithAllData.Id, team.Id); mockUserRepo.Verify(x => x.GetById(It.IsAny <int>()), Times.Exactly(2)); mockTeamRepo.Verify(x => x.GetById(It.IsAny <int>()), Times.Exactly(2)); mockUTRepo.Verify(x => x.Delete(fav), Times.Once()); }
public ActionResult UnfollowTeam([FromBody] UsersTeams userteam) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { userBusinessLogic.UnfollowTeam(userteam.UserId, userteam.TeamId); return(Ok("{\"response\": \"ok\"}")); } catch (TeamDoesNotExistsException e) { return(NotFound(e.Message)); } catch (UserDoesNotExistException e) { return(NotFound(e.Message)); } catch (UserDoesNotFollowTeamException e) { return(NotFound(e.Message)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public void AddUserToRepositoryTest() { var mockRepo = new Mock <IRepository <UsersTeams> >(); var list = new List <UsersTeams>(); var userteam = new UsersTeams() { Team = team, User = user, TeamId = team.Id, UserId = user.Id }; mockRepo.Setup(r => r.Insert(It.IsAny <UsersTeams>())).Callback <UsersTeams>(x => list.Add(userteam)); mockRepo.Object.Insert(userteam); mockRepo.Verify(x => x.Insert(userteam), Times.Once); Assert.IsTrue(list.Count == 1); }
private void LoadTeams() { using (var db = Global.GetConnection()) { var userTeams = from ut in db.Inti_Team where ut.Sys_User.GUID == Id && ut.Inti_Tournament.GUID == SessionProps.SelectedTournament.GUID select new { ut.GUID, ut.Name, ut.IsActive, ut.IsPaid }; UsersTeams.DataKeyNames = new string[] { "GUID" }; UsersTeams.DataSource = userTeams.ToList(); UsersTeams.DataBind(); } }