public void AddPlayer() { // Arrange var team = new Team(); A.CallTo(() => _teamService.GetTeamById(A <int> ._)).Returns(team); A.CallTo(() => _playerService.GetPlayerByChatId(A <string> ._)).Throws <InvalidOperationException>(); var player = new Player() { Name = "toto", ChatLogin = "******" }; // Act _target.AddPlayer(1, player); // Assert A.CallTo(() => _teamService.AddMemberToTeam(team, A <List <Player> > ._)).MustHaveHappened(); }
public void Return_View_Add_Player_Or_Redirect() { // Arrange Player player = new Player { Id = 0, Name = "Micky", Age = 33, Team = "Disney", Number = 4, Position = "Dancer" }; // Act var result = teamController.AddPlayer("Team"); // Get Action var result2 = teamController.AddPlayer(player); // Post Action // Assert Assert.IsType <ViewResult>(result); var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result2); Assert.Equal("TeamInfo", redirectToActionResult.ActionName); }
private void SetTeams() { foreach (PlayerController player in players) { if (player.transform.position.x < 0) { teamController1.AddPlayer(player); teamController2.RemovePlayer(player); } else { teamController2.AddPlayer(player); teamController1.RemovePlayer(player); } teamController1.UpdateColor(); teamController2.UpdateColor(); } }
public void AddPlayerTest() { Team _team = new Team(); _team.Name = "Barcelona"; _team.TeamId = 1; _team.Password = "******"; _team.Mail = "*****@*****.**"; Player player1 = new Player(); player1.Name = "Messi"; player1.PlayerId = 1; player1.Born = new DateTime(1987, 12, 23); player1.Position = "Middle Attacker"; player1.Surname = "Lionel"; player1.TeamId = 1; Player player2 = new Player(); player2.Name = "Neymar"; player2.PlayerId = 2; player2.Born = new DateTime(1989, 02, 13); player2.Position = "Middle Attacker"; player2.Surname = "Id"; player2.TeamId = 1; Reward reward = new Reward(); reward.Name = "Reward"; reward.Date = "1987-01-23"; reward.TeamId = 1; _team.Players = new List <Player>() { player1 }; _team.Rewards = new List <Reward>() { reward }; // Arrange var mockHighService = new Mock <IHighLevelSoccerManagerService>(); var mockLowService = new Mock <ILowLevelSoccerManagmentService>(); mockHighService.Setup(service => service.GetAllTeam()).Returns(new List <Team>() { _team }); mockLowService.Setup(service => service.GetAllPlayers()).Returns(new List <Player>() { player1 }); mockLowService.Setup(service => service.GetAllRewards()).Returns(new List <Reward>() { reward }); var store = new Mock <IUserStore <User> >(); var mockUserStore = new Mock <IUserStore <User> >(); var mockUserRoleStore = mockUserStore.As <IUserRoleStore <User> >(); var userManager = new Mock <UserManager <User> >(mockUserStore.Object, null, null, null, null, null, null, null, null); userManager.Setup(u => u.GetUserAsync(It.IsAny <ClaimsPrincipal>())).ReturnsAsync( new User() { UserName = "******", UserId = 1 }); TeamController controller = new TeamController(mockHighService.Object, mockLowService.Object, userManager.Object); controller.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, "Test") })) } }; // Act RedirectToActionResult result = (RedirectToActionResult)controller.AddPlayer(player2).Result; // Assert var viewResult = Assert.IsType <RedirectToActionResult>(result); }