public void IsTeamInLeagueShouldReturnTrue()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "IsTeamInLeagueTrue_Teams_DB")
                          .Options;

            var dbContext = new FooteoDbContext(options);

            var townsService   = new TownsService(dbContext);
            var leaguesService = new LeaguesService(dbContext, townsService);

            var mockUserStore = new Mock <IUserStore <FooteoUser> >();
            var userManager   = new Mock <UserManager <FooteoUser> >(mockUserStore.Object, null, null, null, null, null, null, null, null);

            var town = townsService.CreateTown("Stara Zagora");

            var user = new FooteoUser
            {
                Age          = new Random().Next(20, 30),
                Email        = $"*****@*****.**",
                FirstName    = "Footeo",
                LastName     = "Player",
                UserName     = $"footeoPlayer",
                Town         = town,
                PasswordHash = "123123",
                Player       = new Player
                {
                    FullName = "Footeo Player"
                }
            };

            dbContext.Users.Add(user);
            dbContext.SaveChanges();

            userManager.Setup(u => u.RemoveFromRoleAsync(user, "Player")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(user, "PlayerInTeam")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(user, "Captain")).Returns(Task.FromResult(IdentityResult.Success));

            var teamsService = new TeamsService(dbContext, townsService, leaguesService, userManager.Object, null);

            teamsService.CreateTeam("Team", "TTT", user.UserName);
            var team = dbContext.Teams.FirstOrDefault(n => n.Name == "Team");

            leaguesService.CreateLeague("League", "Desc", DateTime.UtcNow, DateTime.UtcNow.AddMonths(2), "Stara Zagora");
            var league = dbContext.Leagues.FirstOrDefault(n => n.Name == "League");

            var teamLeague = new TeamLeague
            {
                Team   = team,
                League = league
            };

            dbContext.TeamsLeagues.Add(teamLeague);
            dbContext.SaveChanges();

            var isTeamInLeague = teamsService.IsTeamInLeague(team.Id);

            Assert.True(isTeamInLeague);
        }
        public void CreateRefereeShouldNotReturnNull()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "CreateReferee_Referees_DB")
                          .Options;

            var dbContext    = new FooteoDbContext(options);
            var townsService = new TownsService(dbContext);
            var town         = townsService.CreateTown("Haskovo");

            var user = new FooteoUser
            {
                Age          = new Random().Next(20, 30),
                Email        = $"*****@*****.**",
                FirstName    = "Footeo",
                LastName     = "Referee",
                UserName     = $"footeoReferee",
                Town         = town,
                PasswordHash = "123123"
            };

            dbContext.Users.Add(user);
            dbContext.SaveChanges();

            var refereesService = new RefereesService(dbContext, null, null);

            var referee = new Referee
            {
                FullName = $"Footeo Referee"
            };

            refereesService.CreateReferee(user, referee);

            Assert.NotNull(user.Referee);
        }
示例#3
0
        public void CreatePlayerShouldNotReturnNull()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "CreatePlayer_Players_DB")
                          .Options;

            var dbContext    = new FooteoDbContext(options);
            var townsService = new TownsService(dbContext);
            var town         = townsService.CreateTown("Vraca");

            var user = new FooteoUser
            {
                Age          = new Random().Next(20, 30),
                Email        = "*****@*****.**",
                FirstName    = "Footeo",
                LastName     = "Player",
                UserName     = "******",
                Town         = town,
                PasswordHash = "123123"
            };

            dbContext.Users.Add(user);
            dbContext.SaveChanges();

            var playersService = new PlayersService(dbContext, null, null, null);

            var player = new Player
            {
                FullName = "Footeo Player"
            };

            playersService.CreatePlayer(user, player);

            Assert.NotNull(user.Player);
        }
示例#4
0
        public void PlayerHasATeamShouldReturnTrue()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "PlayerHasATeamTrue_Players_DB")
                          .Options;

            var dbContext    = new FooteoDbContext(options);
            var townsService = new TownsService(dbContext);
            var town         = townsService.CreateTown("Vraca");

            var user = new FooteoUser
            {
                Age          = new Random().Next(20, 30),
                Email        = "*****@*****.**",
                FirstName    = "Footeo",
                LastName     = "Player",
                UserName     = "******",
                Town         = town,
                PasswordHash = "123123"
            };

            dbContext.Users.Add(user);
            dbContext.SaveChanges();

            var playersService = new PlayersService(dbContext, null, null, null);

            var player = new Player
            {
                FullName = "Footeo Player"
            };

            playersService.CreatePlayer(user, player);

            var playerUser = dbContext.Players.FirstOrDefault(p => p.FullName == "Footeo Player");

            playerUser.Team = new Team
            {
                Name     = "Team",
                Initials = "TTT"
            };
            dbContext.SaveChanges();

            var playerHasATeam = playersService.PlayerHasATeam(user.UserName);

            Assert.True(playerHasATeam);
        }
        public void AllAwayMatchesByTeamIdShouldReturnNone()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "AllAwayMatchesNone_Teams_DB")
                          .Options;

            var dbContext = new FooteoDbContext(options);

            var townsService   = new TownsService(dbContext);
            var leaguesService = new LeaguesService(dbContext, townsService);

            var mockUserStore = new Mock <IUserStore <FooteoUser> >();
            var userManager   = new Mock <UserManager <FooteoUser> >(mockUserStore.Object, null, null, null, null, null, null, null, null);

            var town = townsService.CreateTown("Ruse");

            var user = new FooteoUser
            {
                Age          = new Random().Next(20, 30),
                Email        = $"*****@*****.**",
                FirstName    = "Footeo",
                LastName     = "Player",
                UserName     = $"footeoPlayer",
                Town         = town,
                PasswordHash = "123123",
                Player       = new Player
                {
                    FullName = "Footeo Player"
                }
            };

            dbContext.Users.Add(user);
            dbContext.SaveChanges();

            userManager.Setup(u => u.RemoveFromRoleAsync(user, "Player")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(user, "PlayerInTeam")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(user, "Captain")).Returns(Task.FromResult(IdentityResult.Success));

            var teamsService = new TeamsService(dbContext, townsService, leaguesService, userManager.Object, null);

            teamsService.CreateTeam("Team4", "TTT", user.UserName);
            var team = dbContext.Teams.FirstOrDefault(n => n.Name == "Team4");

            var allAwayMatches           = teamsService.AllAwayMatchesByTeamId(team.Id).ToList();
            var allAwayMatchesCount      = allAwayMatches.Count;
            var expectedAwayMatchesCount = 0;

            Assert.AreEqual(expectedAwayMatchesCount, allAwayMatchesCount);
        }
        public void TeamExistsByNameShouldReturnFalse()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "TeamExistsByNameFalse_Teams_DB")
                          .Options;

            var dbContext = new FooteoDbContext(options);

            var townsService   = new TownsService(dbContext);
            var leaguesService = new LeaguesService(dbContext, townsService);

            var mockUserStore = new Mock <IUserStore <FooteoUser> >();
            var userManager   = new Mock <UserManager <FooteoUser> >(mockUserStore.Object, null, null, null, null, null, null, null, null);

            var town = townsService.CreateTown("Sofia");

            var user = new FooteoUser
            {
                Age          = new Random().Next(20, 30),
                Email        = $"*****@*****.**",
                FirstName    = "Footeo",
                LastName     = "Player",
                UserName     = $"footeoPlayer",
                Town         = town,
                PasswordHash = "123123",
                Player       = new Player
                {
                    FullName = "Footeo Player"
                }
            };

            dbContext.Users.Add(user);
            dbContext.SaveChanges();

            userManager.Setup(u => u.RemoveFromRoleAsync(user, "Player")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(user, "PlayerInTeam")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(user, "Captain")).Returns(Task.FromResult(IdentityResult.Success));

            var teamsService = new TeamsService(dbContext, townsService, leaguesService, userManager.Object, null);

            teamsService.CreateTeam("Team", "TTT", user.UserName);
            var team = dbContext.Teams.FirstOrDefault(n => n.Name == "Team");

            var invalidTeamName = "Teeeeaaaam";
            var teamExists      = teamsService.TeamExistsByName(invalidTeamName);

            Assert.False(teamExists);
        }
示例#7
0
        private void SeedFields(FooteoDbContext dbContext)
        {
            for (int i = 1; i <= 20; i++)
            {
                var field = new Field
                {
                    Name      = $"Footeo Field{i}",
                    Address   = $"Addres{i}",
                    Town      = dbContext.Towns.FirstOrDefault(t => t.Name == "Sofia"),
                    IsIndoors = i % 2 == 0 ? true : false
                };

                dbContext.Fields.Add(field);
                dbContext.SaveChanges();
            }
        }
        public void GetTeamByIdShouldNotReturnNull()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetTeamById_Teams_DB")
                          .Options;

            var dbContext = new FooteoDbContext(options);

            var townsService   = new TownsService(dbContext);
            var leaguesService = new LeaguesService(dbContext, townsService);

            var mockUserStore = new Mock <IUserStore <FooteoUser> >();
            var userManager   = new Mock <UserManager <FooteoUser> >(mockUserStore.Object, null, null, null, null, null, null, null, null);

            var town = townsService.CreateTown("Plovdiv");

            var user = new FooteoUser
            {
                Age          = new Random().Next(20, 30),
                Email        = $"*****@*****.**",
                FirstName    = "Footeo",
                LastName     = "Player",
                UserName     = $"footeoPlayer",
                Town         = town,
                PasswordHash = "123123",
                Player       = new Player
                {
                    FullName = "Footeo Player"
                }
            };

            dbContext.Users.Add(user);
            dbContext.SaveChanges();

            userManager.Setup(u => u.RemoveFromRoleAsync(user, "Player")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(user, "PlayerInTeam")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(user, "Captain")).Returns(Task.FromResult(IdentityResult.Success));

            var teamsService = new TeamsService(dbContext, townsService, leaguesService, userManager.Object, null);

            teamsService.CreateTeam("Team1", "TTT", user.UserName);
            var teamId = dbContext.Teams.FirstOrDefault(n => n.Name == "Team1").Id;

            var team = teamsService.GetTeamById <TeamViewModel>(teamId);

            Assert.NotNull(team);
        }
示例#9
0
        public void SetPositionShouldReturnCorrectResult()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "SetPosition_Players_DB")
                          .Options;

            var dbContext    = new FooteoDbContext(options);
            var townsService = new TownsService(dbContext);
            var town         = townsService.CreateTown("Vraca");

            var user = new FooteoUser
            {
                Age          = new Random().Next(20, 30),
                Email        = "*****@*****.**",
                FirstName    = "Footeo",
                LastName     = "Player",
                UserName     = "******",
                Town         = town,
                PasswordHash = "123123"
            };

            dbContext.Users.Add(user);
            dbContext.SaveChanges();

            var playersService = new PlayersService(dbContext, null, null, null);

            var player = new Player
            {
                FullName = "Footeo Player"
            };

            playersService.CreatePlayer(user, player);

            playersService.SetPosition(user.UserName, PlayerPosition.Forward);

            var position         = player.Position.ToString();
            var expectedPosition = "Forward";

            Assert.AreEqual(expectedPosition, position);
        }
        public void CreateRefereeShouldReturnCorrectRefereeCount()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "RefereesCount_Referees_DB")
                          .Options;

            var dbContext = new FooteoDbContext(options);

            for (int i = 1; i <= 10; i++)
            {
                var user = new FooteoUser
                {
                    Age          = new Random().Next(20, 30),
                    Email        = $"footeoReferee{i}@mail.bg",
                    FirstName    = "Footeo",
                    LastName     = "Referee",
                    UserName     = $"footeoReferee{i}",
                    TownId       = new Random().Next(1, 20),
                    PasswordHash = "123123",
                    Referee      = new Referee
                    {
                        FullName = $"Footeo Referee{i}"
                    }
                };

                dbContext.Users.Add(user);
                dbContext.SaveChanges();
            }

            var refereesService = new RefereesService(dbContext, null, null);

            var referees = refereesService.Referees <RefereeViewModel>().ToList();

            var expectedRefereesCount = 10;

            Assert.AreEqual(expectedRefereesCount, referees.Count);
        }
        public void GetTeamLeagueWinnerShouldReturnCorrectResult()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetTeamLeagueWinner_TeamLeagues_DB")
                          .Options;

            var dbContext = new FooteoDbContext(options);

            var townsService   = new TownsService(dbContext);
            var leaguesService = new LeaguesService(dbContext, townsService);

            var mockUserStore = new Mock <IUserStore <FooteoUser> >();
            var userManager   = new Mock <UserManager <FooteoUser> >(mockUserStore.Object, null, null, null, null, null, null, null, null);

            var town = townsService.CreateTown("Sofia");

            var user = new FooteoUser
            {
                Age          = new Random().Next(20, 30),
                Email        = $"*****@*****.**",
                FirstName    = "Footeo",
                LastName     = "Player",
                UserName     = $"footeoPlayer",
                Town         = town,
                PasswordHash = "123123",
                Player       = new Player
                {
                    FullName = "Footeo Player"
                }
            };

            dbContext.Users.Add(user);
            dbContext.SaveChanges();

            userManager.Setup(u => u.RemoveFromRoleAsync(user, "Player")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(user, "PlayerInTeam")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(user, "Captain")).Returns(Task.FromResult(IdentityResult.Success));

            var user2 = new FooteoUser
            {
                Age          = new Random().Next(20, 30),
                Email        = $"*****@*****.**",
                FirstName    = "Footeo",
                LastName     = "Player",
                UserName     = $"footeo",
                Town         = town,
                PasswordHash = "123123",
                Player       = new Player
                {
                    FullName = "Footeo User"
                }
            };

            dbContext.Users.Add(user2);
            dbContext.SaveChanges();

            userManager.Setup(u => u.RemoveFromRoleAsync(user2, "Player")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(user2, "PlayerInTeam")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(user2, "Captain")).Returns(Task.FromResult(IdentityResult.Success));

            var teamsService = new TeamsService(dbContext, townsService, leaguesService, userManager.Object, null);

            teamsService.CreateTeam("Team", "TTT", user.UserName);
            teamsService.CreateTeam("Team2", "TTT", user2.UserName);
            var team  = dbContext.Teams.FirstOrDefault(n => n.Name == "Team");
            var team2 = dbContext.Teams.FirstOrDefault(n => n.Name == "Team2");

            leaguesService.CreateLeague("League", "Desc", DateTime.UtcNow.AddDays(7), DateTime.UtcNow.AddMonths(2), "Sofia");
            var league = dbContext.Leagues.FirstOrDefault(l => l.Name == "League");

            var teamLeaguesService = new TeamLeaguesService(dbContext, teamsService, leaguesService);

            teamLeaguesService.JoinLeague(user.UserName, league.Id);
            teamLeaguesService.JoinLeague(user2.UserName, league.Id);

            var teamLeague1 = dbContext.TeamsLeagues.FirstOrDefault(t => t.Team == team);
            var teamLeague2 = dbContext.TeamsLeagues.FirstOrDefault(t => t.Team == team2);

            teamLeague1.Points = 100;
            teamLeague2.Points = 50;
            dbContext.SaveChanges();

            league.Status = LeagueStatus.Completed;
            dbContext.SaveChanges();

            var winner = teamLeaguesService.GetTeamLeagueWinner(league.Id);

            Assert.AreEqual(winner.Team.Name, teamLeague1.Team.Name);
        }
示例#12
0
        public void CreateTrophyShouldNotReturnNull()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "CreateTrophy_Trophies_DB")
                          .Options;

            var dbContext = new FooteoDbContext(options);

            var townsService = new TownsService(dbContext);

            var mockUserStore = new Mock <IUserStore <FooteoUser> >();
            var userManager   = new Mock <UserManager <FooteoUser> >(mockUserStore.Object, null, null, null, null, null, null, null, null);

            var town = townsService.CreateTown("Sofia");

            var user = new FooteoUser
            {
                Age          = new Random().Next(20, 30),
                Email        = $"*****@*****.**",
                FirstName    = "Footeo",
                LastName     = "Player",
                UserName     = $"footeoPlayer",
                Town         = town,
                PasswordHash = "123123",
                Player       = new Player
                {
                    FullName = "Footeo Player"
                }
            };

            dbContext.Users.Add(user);
            dbContext.SaveChanges();

            userManager.Setup(u => u.RemoveFromRoleAsync(user, "Player")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(user, "PlayerInTeam")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(user, "Captain")).Returns(Task.FromResult(IdentityResult.Success));

            var leaguesService     = new LeaguesService(dbContext, townsService);
            var teamsService       = new TeamsService(dbContext, townsService, leaguesService, userManager.Object, null);
            var teamLeaguesService = new TeamLeaguesService(dbContext, teamsService, leaguesService);
            var trophiesService    = new TrophiesService(dbContext, teamLeaguesService);

            teamsService.CreateTeam("TeamWinner", "TWR", user.UserName);
            var team = dbContext.Teams.FirstOrDefault(t => t.Name == "TeamWinner");

            leaguesService.CreateLeague("League", "Desc", DateTime.UtcNow.AddDays(7), DateTime.UtcNow.AddMonths(2), "Sofia");
            var league = dbContext.Leagues.FirstOrDefault(l => l.Name == "League");

            leaguesService.SetLeagueStatusToCompleted(league.Id);

            var teamLeague = new TeamLeague
            {
                Team   = team,
                League = league
            };

            dbContext.TeamsLeagues.Add(teamLeague);
            dbContext.SaveChanges();

            trophiesService.CreateTrophy(league.Id);

            var hasTeamTrophy = team.Trophies.Any();

            Assert.True(hasTeamTrophy);
        }
        public void RefereeAttendToMatchShouldNotReturnNull()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "AttendToMatch_Referees_DB")
                          .Options;

            var dbContext    = new FooteoDbContext(options);
            var townsService = new TownsService(dbContext);

            var town = townsService.CreateTown("Burgas");

            var user = new FooteoUser
            {
                Age          = new Random().Next(20, 30),
                Email        = $"*****@*****.**",
                FirstName    = "Footeo",
                LastName     = "Referee",
                UserName     = $"footeoReferee",
                Town         = town,
                PasswordHash = "123123"
            };

            dbContext.Users.Add(user);
            dbContext.SaveChanges();

            var userHT = new FooteoUser
            {
                Age          = new Random().Next(20, 30),
                Email        = $"*****@*****.**",
                FirstName    = "Footeo",
                LastName     = "Player",
                UserName     = $"footeoPlayer",
                Town         = town,
                PasswordHash = "123123",
                Player       = new Player
                {
                    FullName = "Footeo Player"
                }
            };

            dbContext.Users.Add(userHT);
            dbContext.SaveChanges();

            var userAT = new FooteoUser
            {
                Age          = new Random().Next(20, 30),
                Email        = $"*****@*****.**",
                FirstName    = "Footeo",
                LastName     = "Player",
                UserName     = $"footeoPlayer2",
                Town         = town,
                PasswordHash = "123123",
                Player       = new Player
                {
                    FullName = "Footeo Player"
                }
            };

            dbContext.Users.Add(userAT);
            dbContext.SaveChanges();

            var mockUserStore = new Mock <IUserStore <FooteoUser> >();
            var userManager   = new Mock <UserManager <FooteoUser> >(mockUserStore.Object, null, null, null, null, null, null, null, null);

            userManager.Setup(u => u.RemoveFromRoleAsync(userHT, "Player")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(userHT, "PlayerInTeam")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(userHT, "Captain")).Returns(Task.FromResult(IdentityResult.Success));

            userManager.Setup(u => u.RemoveFromRoleAsync(userAT, "Player")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(userAT, "PlayerInTeam")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(userAT, "Captain")).Returns(Task.FromResult(IdentityResult.Success));

            var fieldsService      = new FieldsService(dbContext, townsService);
            var leaguesService     = new LeaguesService(dbContext, townsService);
            var teamsService       = new TeamsService(dbContext, townsService, leaguesService, userManager.Object, null);
            var teamLeaguesService = new TeamLeaguesService(dbContext, teamsService, leaguesService);
            var fixturesService    = new FixturesService(dbContext, leaguesService);
            var matchesService     = new MatchesService(dbContext, fixturesService, teamsService);
            var refereesService    = new RefereesService(dbContext, matchesService, teamLeaguesService);

            var referee = new Referee
            {
                FullName = $"Footeo Referee"
            };

            refereesService.CreateReferee(user, referee);

            townsService.CreateTown("Sofia");
            leaguesService.CreateLeague("League", "Desc", DateTime.UtcNow, DateTime.UtcNow.AddMonths(3), "Sofia");

            teamsService.CreateTeam("Home Team", "HT", userHT.UserName);
            teamsService.CreateTeam("Away Team", "AT", userAT.UserName);

            var league = dbContext.Leagues.FirstOrDefault(n => n.Name == "League");

            teamLeaguesService.JoinLeague(userHT.UserName, league.Id);
            teamLeaguesService.JoinLeague(userAT.UserName, league.Id);

            fixturesService.CreateFixture("Matchday", DateTime.UtcNow.AddDays(7), league.Id);
            var fixture = dbContext.Fixtures.FirstOrDefault(n => n.Name == "Matchday");

            fieldsService.CreateField("Field", "Address", true, "Sofia");
            var field = dbContext.Fields.FirstOrDefault(n => n.Name == "Field");

            matchesService.CreateMatch(userHT.Player.Team.Id, userAT.Player.Team.Id, field.Id, fixture.Id);
            var match = dbContext.Matches.FirstOrDefault();

            refereesService.AttendAMatch(user.UserName, match.Id);

            Assert.NotNull(match.Referee);
        }
        public void AllTrophiesByTeamShouldReturnCorrectCount()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "AllTrophiesByTeamCount_Teams_DB")
                          .Options;

            var dbContext = new FooteoDbContext(options);

            var townsService   = new TownsService(dbContext);
            var leaguesService = new LeaguesService(dbContext, townsService);

            var mockUserStore = new Mock <IUserStore <FooteoUser> >();
            var userManager   = new Mock <UserManager <FooteoUser> >(mockUserStore.Object, null, null, null, null, null, null, null, null);

            var town = townsService.CreateTown("Sofia");

            var user = new FooteoUser
            {
                Age          = new Random().Next(20, 30),
                Email        = $"*****@*****.**",
                FirstName    = "Footeo",
                LastName     = "Player",
                UserName     = $"footeoPlayer",
                Town         = town,
                PasswordHash = "123123",
                Player       = new Player
                {
                    FullName = "Footeo Player"
                }
            };

            dbContext.Users.Add(user);
            dbContext.SaveChanges();

            userManager.Setup(u => u.RemoveFromRoleAsync(user, "Player")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(user, "PlayerInTeam")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(user, "Captain")).Returns(Task.FromResult(IdentityResult.Success));

            var teamsService = new TeamsService(dbContext, townsService, leaguesService, userManager.Object, null);

            teamsService.CreateTeam("Team3", "TTT", user.UserName);
            var team = dbContext.Teams.FirstOrDefault(n => n.Name == "Team3");

            for (int i = 1; i <= 3; i++)
            {
                var trophy = new Trophy
                {
                    Name = $"Trophy{i}",
                    Team = team
                };

                dbContext.Trophies.Add(trophy);
                dbContext.SaveChanges();
            }

            var expectedTrophiesCountByTeam = 3;
            var trophiesByTeam = teamsService.AllTrophiesByTeamId <TrophyViewModel>(team.Id).ToList();
            var trophiesCount  = trophiesByTeam.Count;

            Assert.AreEqual(expectedTrophiesCountByTeam, trophiesCount);
        }
        public void AllTeamsShouldReturnCorrectTeamsCount()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "AllTeams_Teams_DB")
                          .Options;

            var dbContext = new FooteoDbContext(options);

            var townsService   = new TownsService(dbContext);
            var leaguesService = new LeaguesService(dbContext, townsService);

            var mockUserStore = new Mock <IUserStore <FooteoUser> >();
            var userManager   = new Mock <UserManager <FooteoUser> >(mockUserStore.Object, null, null, null, null, null, null, null, null);

            var town = townsService.CreateTown("Sofia");

            var user = new FooteoUser
            {
                Age          = new Random().Next(20, 30),
                Email        = $"*****@*****.**",
                FirstName    = "Footeo",
                LastName     = "Player",
                UserName     = $"footeoPlayer",
                Town         = town,
                PasswordHash = "123123",
                Player       = new Player
                {
                    FullName = "Footeo Player"
                }
            };

            dbContext.Users.Add(user);
            dbContext.SaveChanges();

            userManager.Setup(u => u.RemoveFromRoleAsync(user, "Player")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(user, "PlayerInTeam")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(user, "Captain")).Returns(Task.FromResult(IdentityResult.Success));

            var user2 = new FooteoUser
            {
                Age          = new Random().Next(20, 30),
                Email        = $"*****@*****.**",
                FirstName    = "Footeo",
                LastName     = "Player",
                UserName     = $"footeoPlayer2",
                Town         = town,
                PasswordHash = "123123",
                Player       = new Player
                {
                    FullName = "Footeo Player"
                }
            };

            dbContext.Users.Add(user2);
            dbContext.SaveChanges();

            userManager.Setup(u => u.RemoveFromRoleAsync(user2, "Player")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(user2, "PlayerInTeam")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(user2, "Captain")).Returns(Task.FromResult(IdentityResult.Success));

            var teamsService = new TeamsService(dbContext, townsService, leaguesService, userManager.Object, null);

            teamsService.CreateTeam("Team1", "TTT", user.UserName);
            teamsService.CreateTeam("Team2", "TTT", user2.UserName);

            var teams = teamsService.AllTeams <Team>().ToList();

            var expectedTeamsCount = 2;

            Assert.AreEqual(expectedTeamsCount, teams.Count);
        }
示例#16
0
        public void IsSquadNumberTakenShouldReturnTrue()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "IsSquadNumberTakenTrue_Players_DB")
                          .Options;

            var dbContext    = new FooteoDbContext(options);
            var townsService = new TownsService(dbContext);
            var town         = townsService.CreateTown("Vraca");

            var user = new FooteoUser
            {
                Age          = new Random().Next(20, 30),
                Email        = "*****@*****.**",
                FirstName    = "Footeo",
                LastName     = "Player",
                UserName     = "******",
                Town         = town,
                PasswordHash = "123123"
            };

            dbContext.Users.Add(user);
            dbContext.SaveChanges();

            var mockUserStore = new Mock <IUserStore <FooteoUser> >();
            var userManager   = new Mock <UserManager <FooteoUser> >(mockUserStore.Object, null, null, null, null, null, null, null, null);

            userManager.Setup(u => u.RemoveFromRoleAsync(user, "Player")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(user, "PlayerInTeam")).Returns(Task.FromResult(IdentityResult.Success));

            var leaguesService = new LeaguesService(dbContext, townsService);

            var player = new Player
            {
                FullName = "Footeo Player"
            };

            var playerUser = new FooteoUser
            {
                Age          = new Random().Next(20, 30),
                Email        = "*****@*****.**",
                FirstName    = "Footeo",
                LastName     = "Player",
                UserName     = "******",
                Town         = town,
                PasswordHash = "123123"
            };

            dbContext.Users.Add(playerUser);
            dbContext.SaveChanges();

            var playerTwo = new Player
            {
                FullName = "Footeo Player"
            };

            userManager.Setup(u => u.RemoveFromRoleAsync(playerUser, "Player")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(playerUser, "PlayerInTeam")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(playerUser, "Captain")).Returns(Task.FromResult(IdentityResult.Success));

            var teamsService = new TeamsService(dbContext, townsService, leaguesService, userManager.Object, null);

            var playersService = new PlayersService(dbContext, userManager.Object, null, teamsService);

            playersService.CreatePlayer(user, player);
            playersService.CreatePlayer(playerUser, playerTwo);

            teamsService.CreateTeam("Team", "TTT", playerUser.UserName);
            var team = dbContext.Teams.FirstOrDefault(t => t.Name == "Team");

            playersService.JoinTeam(team.Id, user.UserName);

            playersService.SetSquadNumber(user.UserName, 7);

            var isSquadNumberTaken = playersService.IsSquadNumberTaken(7, team.Id);

            Assert.True(isSquadNumberTaken);
        }