public void Update_MissingRequiredFieldLocation_DoesNotCallUpdateTeam()
        {
            sut.ModelState.AddModelError("", "Location field is required");
            var viewModel = new TeamViewModel
            {
                TeamId     = TeamId,
                Name       = "Test",
                Division   = "Western",
                Conference = "Madeup"
            };

            sut.Edit(viewModel, "submit");

            _teamService.DidNotReceive().UpdateTeam(Arg.Any <DbTeam>());
        }
Example #2
0
        public async Task Test_Edit_Edits_Team()
        {
            var team = new Team {
                Name = "Newcastle United"
            };

            await controller.Edit(team);

            context.MockContext.Verify(x => x.SetModified(It.Is <object>(t => t == team)));
        }
Example #3
0
        public void EditCupReturnsViewResultWithCupModel()
        {
            Team _team = new Team();

            _team.Name     = "Barcelona";
            _team.TeamId   = 1;
            _team.Password = "******";
            _team.Mail     = "*****@*****.**";

            Team new_team = _team;

            new_team.Name = "New";
            new_team.Mail = "*****@*****.**";

            Player player = new Player();

            player.Name     = "Messi";
            player.PlayerId = 1;
            player.Born     = new DateTime(1987, 12, 23);
            player.Position = "Middle Attacker";
            player.Surname  = "Lionel";
            player.TeamId   = 1;

            Reward reward = new Reward();

            reward.Name   = "Reward";
            reward.Date   = "1987-01-23";
            reward.TeamId = 1;

            // Arrange
            var mockHighService = new Mock <IHighLevelSoccerManagerService>();
            var mockLowService  = new Mock <ILowLevelSoccerManagmentService>();

            mockHighService.Setup(service => service.GetAllTeam()).Returns(new List <Team>()
            {
                _team
            });
            mockHighService.Setup(service => service.UpdateTeam(It.IsAny <int>(), It.IsAny <Team>()))
            .Callback(() =>
            {
                _team = new_team;
            });
            mockLowService.Setup(service => service.GetAllPlayers()).Returns(new List <Player>()
            {
                player
            });
            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
            ViewResult result = (ViewResult)controller.Edit(new WebApplication1.Models.ViewModels.TeamModels.EditTeamModel()
            {
                Team = new_team, File = null
            }).Result;

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.Equal(new_team, ((TeamMainInfo)viewResult?.Model).Team);
        }