public void Cannot_Delete_Nonexistent_Player()
 {
     Mock<IPlayerRepository> mock = new Mock<IPlayerRepository>();
     mock.Setup(p => p.Players).Returns(new Player[] {
             new Player { PlayerId = 1, Name = "Player1"},
             new Player { PlayerId = 2, Name = "Player2" },
             new Player { PlayerId = 3, Name = "Player3"}
     }.AsQueryable());
     AdminController targ = new AdminController(mock.Object, null, null, null, null);
     targ.Delete(100);
     mock.Verify(p => p.DeletePlayer(It.IsAny<Player>()), Times.Never());
 }
        public void Cannot_Edit_Nonexistent_Player()
        {
            Mock<IPlayerRepository> mockPlayers = new Mock<IPlayerRepository>();
            mockPlayers.Setup(p => p.Players).Returns(new Player[] {
                    new Player { PlayerId = 1, Name = "Player1"},
                    new Player { PlayerId = 2, Name = "Player2"},
                    new Player { PlayerId = 3, Name = "Player3"}
            }.AsQueryable());

            AdminController targ = new AdminController(mockPlayers.Object, null, null, null, null);
            Player result = targ.Edit(4).ViewData.Model as Player;
            Assert.IsNull(result);
        }
        public void Cannot_Save_Invalid_Changes()
        {
            Mock<IPlayerRepository> mockPlayer = new Mock<IPlayerRepository>();
            Mock<IClubRepository> mockClubs = new Mock<IClubRepository>();
            Mock<IPositionRepository> mockPositions = new Mock<IPositionRepository>();
            Mock<IStatRepository> mockStats = new Mock<IStatRepository>();

            Player player = new Player { Name = "Player1" };

            mockClubs.Setup(p => p.Clubs).Returns(new Club[] {
                    new Club { ClubId = 1, Name = "Club1" }
            }.AsQueryable());
            mockPositions.Setup(p => p.Positions).Returns(new Position[] {
                    new Position { PositionId = 1, Name = "Вратарь" }
            }.AsQueryable());

            AdminController targ = new AdminController(
                    mockPlayer.Object,
                    mockClubs.Object,
                    mockPositions.Object,
                    mockStats.Object,
                    null);

            FormCollection form = new FormCollection   {
                {"PlayerId", "1"},
                {"Name", "Player1"},
                {"ClubsList", "1"},
                {"PositionsList", "1"},
                {"Price", "5"},
                { "StatId1", "1" },
                { "Score", "0" },
                { "Concede", "0" },
                { "PenaltyScore", "0" },
                { "PenaltyMiss", "0" },
                { "PenaltySave", "0" },
                { "OwnGoal", "0" },
                { "YellowCard", "0" },
                { "RedCard", "0" },
                { "Minutes", "0" },
                { "Points", "0" },
            };
            ActionResult result = targ.Edit(player, form);
            //mockPlayer.Verify(m => m.SavePlayer(It.IsAny<Player>()), Times.Never());
            Assert.IsNotInstanceOfType(result, typeof(ViewResult));
        }
 public void Can_Change_TransfersStatus()
 {
     Mock<IAppDataRepository> mock = new Mock<IAppDataRepository>();
     mock.Setup(p => p.AppData).Returns(new AppData[] {
             new AppData { Id = 1, TransfersStatus = false }}.AsQueryable());
     AdminController targ = new AdminController(null, null, null, null, mock.Object);
     targ.Transfers();
     Assert.IsTrue(mock.Object.AppData.FirstOrDefault().TransfersStatus);
     targ.Transfers();
     Assert.IsFalse(mock.Object.AppData.FirstOrDefault().TransfersStatus);
 }
        public void Can_List_All_Players()
        {
            Mock<IPlayerRepository> mockPlayers = new Mock<IPlayerRepository>();
            Mock<IClubRepository> mockClubs = new Mock<IClubRepository>();
            Mock<IPositionRepository> mockPositions = new Mock<IPositionRepository>();
            Mock<IAppDataRepository> mockAppData = new Mock<IAppDataRepository>();
            mockPlayers.Setup(p => p.Players).Returns(new Player[] {
                    new Player { PlayerId = 1, Name = "Player1", ClubId = 1 },
                    new Player { PlayerId = 2, Name = "Player2", ClubId = 3 },
                    new Player { PlayerId = 3, Name = "Player3", ClubId = 2 }
            }.AsQueryable());
            mockClubs.Setup(p => p.Clubs).Returns(new Club[] {
                    new Club { ClubId = 1, Name = "Club1" },
                    new Club { ClubId = 2, Name = "Club2" },
                    new Club { ClubId = 3, Name = "Club3" }
            }.AsQueryable());
            mockPositions.Setup(p => p.Positions).Returns(new Position[] {
                    new Position { PositionId = 1, Name = "Вратарь" },
                    new Position { PositionId = 2, Name = "Защитник" },
                    new Position { PositionId = 3, Name = "Полузащитник" },
                    new Position { PositionId = 4, Name = "Нападающий" }
            }.AsQueryable());
            mockAppData.Setup(p => p.AppData).Returns(new AppData[] {
                new AppData {Id = 1, Week = 2, TransfersStatus = false }
            }.AsQueryable());

            AdminController targ = new AdminController(mockPlayers.Object, mockClubs.Object, mockPositions.Object, null, mockAppData.Object);

            ListPlayersViewModel result = targ.Index().ViewData.Model as ListPlayersViewModel;

            Player[] players = result.Players.ToArray();
            Club[] clubs = result.Clubs.ToArray();
            Position[] positions = result.Positions.ToArray();

            Assert.AreEqual(3, result.Players.Count());
            Assert.AreEqual(3, result.Clubs.Count());
            Assert.AreEqual(4, result.Positions.Count());
            Assert.AreEqual("Player1", players[0].Name);
            Assert.AreEqual("Player2", players[1].Name);
            Assert.AreEqual("Player3", players[2].Name);
            Assert.AreEqual(1, players[0].ClubId);
            Assert.AreEqual(3, players[1].ClubId);
            Assert.AreEqual(2, players[2].ClubId);
            Assert.AreEqual("Club1", clubs[0].Name);
            Assert.AreEqual("Club2", clubs[1].Name);
            Assert.AreEqual("Club3", clubs[2].Name);
            Assert.AreEqual("Вратарь", positions[0].Name);
            Assert.AreEqual("Защитник", positions[1].Name);
            Assert.AreEqual("Полузащитник", positions[2].Name);
            Assert.AreEqual("Нападающий", positions[3].Name);
        }
        public void Can_Edit_Player()
        {
            Mock<IPlayerRepository> mockPlayers = new Mock<IPlayerRepository>();
            Mock<IClubRepository> mockClubs = new Mock<IClubRepository>();
            Mock<IPositionRepository> mockPositions = new Mock<IPositionRepository>();
            Mock<IStatRepository> mockStats = new Mock<IStatRepository>();

            List<Stat> stats1 = new List<Stat> {
                    new Stat { StatId = 1, Week = 1, Score = 2, PenaltyScore = 1},
                    new Stat { StatId = 2, Week = 2, Score = 1, PenaltyScore = 3}
            };
            List<Stat> stats2 = new List<Stat> {
                    new Stat { StatId = 3, Week = 1, Score = 5, PenaltyScore = 2},
                    new Stat { StatId = 4, Week = 2, Score = 6, PenaltyScore = 1}
            };

            mockPlayers.Setup(p => p.Players).Returns(new Player[] {
                    new Player { PlayerId = 1, Name = "Player1", PositionId = 3, ClubId = 1, Stats = stats1 },
                    new Player { PlayerId = 2, Name = "Player2", PositionId = 1, ClubId = 3, Stats = stats2 },
                    new Player { PlayerId = 3, Name = "Player3", PositionId = 2, ClubId = 2, Stats = stats1 }
            }.AsQueryable());
            mockClubs.Setup(p => p.Clubs).Returns(new Club[] {
                    new Club { ClubId = 1, Name = "Club1" },
                    new Club { ClubId = 2, Name = "Club2" },
                    new Club { ClubId = 3, Name = "Club3" }
            }.AsQueryable());
            mockPositions.Setup(p => p.Positions).Returns(new Position[] {
                    new Position { PositionId = 1, Name = "Вратарь" },
                    new Position { PositionId = 2, Name = "Защитник" },
                    new Position { PositionId = 3, Name = "Полузащитник" },
                    new Position { PositionId = 4, Name = "Нападающий" }
            }.AsQueryable());

            AdminController targ = new AdminController(
                    mockPlayers.Object,
                    mockClubs.Object,
                    mockPositions.Object,
                    mockStats.Object,
                    null
            );
            SelectList clubsList1 = targ.Edit(1).ViewData["Clubs"] as SelectList;
            SelectList clubsList2 = targ.Edit(2).ViewData["Clubs"] as SelectList;
            SelectList clubsList3 = targ.Edit(3).ViewData["Clubs"] as SelectList;

            SelectList posList1 = targ.Edit(1).ViewData["Positions"] as SelectList;
            SelectList posList2 = targ.Edit(2).ViewData["Positions"] as SelectList;
            SelectList posList3 = targ.Edit(3).ViewData["Positions"] as SelectList;

            Player player1 = targ.Edit(1).ViewData.Model as Player;
            Player player2 = targ.Edit(2).ViewData.Model as Player;
            Player player3 = targ.Edit(3).ViewData.Model as Player;

            Assert.AreEqual(1, player1.PlayerId);
            Assert.AreEqual(2, player2.PlayerId);
            Assert.AreEqual(3, player3.PlayerId);

            Assert.AreEqual(2, player1.Stats.FirstOrDefault(p => p.Week == 1).Score);
            Assert.AreEqual(3, player1.Stats.FirstOrDefault(p => p.Week == 2).PenaltyScore);
            Assert.AreEqual(5, player2.Stats.FirstOrDefault(p => p.Week == 1).Score);
            Assert.AreEqual(1, player2.Stats.FirstOrDefault(p => p.Week == 2).PenaltyScore);

            Assert.AreEqual(1, clubsList1.SelectedValue);
            Assert.AreEqual(3, clubsList2.SelectedValue);
            Assert.AreEqual(2, clubsList3.SelectedValue);

            Assert.AreEqual(3, posList1.SelectedValue);
            Assert.AreEqual(1, posList2.SelectedValue);
            Assert.AreEqual(2, posList3.SelectedValue);
        }
 public void Can_Delete_Valid_Player()
 {
     Player player = new Player { PlayerId = 2, Name = "Pl2" };
     Mock<IPlayerRepository> mock = new Mock<IPlayerRepository>();
     mock.Setup(p => p.Players).Returns(new Player[] {
             new Player { PlayerId = 1, Name = "Player1"},
             player,
             new Player { PlayerId = 3, Name = "Player3"}
     }.AsQueryable());
     AdminController targ = new AdminController(mock.Object, null, null, null, null);
     targ.Delete(player.PlayerId);
     mock.Verify(p => p.DeletePlayer(player));
 }