Ejemplo n.º 1
0
        private async Task SeedReferees(FooteoDbContext dbContext, UserManager <FooteoUser> userManager)
        {
            for (int i = 1; i <= 20; i++)
            {
                var user = new FooteoUser
                {
                    Age          = new Random().Next(20, 30),
                    Email        = $"footeoReferee{i}@mail.bg",
                    FirstName    = "Footeo",
                    LastName     = "Referee",
                    UserName     = $"footeoReferee{i}",
                    Town         = dbContext.Towns.FirstOrDefault(t => t.Name == "Sofia"),
                    PasswordHash = "123123",
                    Referee      = new Referee
                    {
                        FullName = $"Footeo Referee{i}"
                    }
                };

                var result = await userManager.CreateAsync(user, "123123");

                if (result.Succeeded)
                {
                    await userManager.AddToRoleAsync(user, GlobalConstants.RefereeRoleName);
                }
            }
        }
Ejemplo n.º 2
0
        public void SetLeagueStatusToCompletedAndReturnAllCompletedLeagues()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "CompletedLeagues_Leagues_DB")
                          .Options;

            var dbContext = new FooteoDbContext(options);

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

            for (int i = 1; i <= 5; i++)
            {
                leaguesService.CreateLeague($"League{i}", $"Description{i}", DateTime.UtcNow.AddDays(i), DateTime.UtcNow.AddDays(i * i), "Sofia");
            }

            var leagues = dbContext.Leagues.ToList();

            foreach (var league in leagues)
            {
                leaguesService.SetLeagueStatusToCompleted(league.Id);
            }

            var completedLeagues = leaguesService.AllCompletedLeagues <CompletedLeagueViewModel>().ToList();

            var completedLeaguesCount = completedLeagues.Count;

            var expectedCompletedLeaguesCount = 5;

            Assert.AreEqual(expectedCompletedLeaguesCount, completedLeaguesCount);
        }
 public MatchesService(FooteoDbContext dbContext,
                       IFixturesService fixturesService, ITeamsService teamsService)
 {
     this.dbContext       = dbContext;
     this.fixturesService = fixturesService;
     this.teamsService    = teamsService;
 }
        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);
        }
Ejemplo n.º 5
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);
        }
        public void AllFixturesByLeagueIdShouldReturnCorrectCount()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "AllFixturesByLeague_Fixtures_DB")
                          .Options;

            var dbContext       = new FooteoDbContext(options);
            var townsService    = new TownsService(dbContext);
            var leaguesService  = new LeaguesService(dbContext, townsService);
            var fixturesService = new FixturesService(dbContext, leaguesService);

            leaguesService.CreateLeague("League2", "Desc", DateTime.UtcNow, DateTime.UtcNow.AddMonths(2), "Varna");

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

            for (int i = 1; i <= 20; i++)
            {
                fixturesService.CreateFixture($"Matchday {i}", DateTime.UtcNow.AddDays(i + 7), league.Id);
            }

            var fixtures = fixturesService.AllFixtures <FixtureViewModel>(league.Id).ToList();

            var expectedFixtures = 20;

            Assert.AreEqual(expectedFixtures, fixtures.Count);
        }
        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);
        }
Ejemplo n.º 8
0
 public PlayersService(FooteoDbContext dbContext,
                       UserManager <FooteoUser> userManager, RoleManager <IdentityRole> roleManager,
                       ITeamsService teamsService)
 {
     this.dbContext    = dbContext;
     this.userManager  = userManager;
     this.roleManager  = roleManager;
     this.teamsService = teamsService;
 }
Ejemplo n.º 9
0
 public TeamsService(FooteoDbContext dbContext,
                     ITownsService townsService, ILeaguesService leaguesService,
                     UserManager <FooteoUser> userManager, RoleManager <IdentityRole> roleManager)
 {
     this.dbContext      = dbContext;
     this.townsService   = townsService;
     this.leaguesService = leaguesService;
     this.userManager    = userManager;
     this.roleManager    = roleManager;
 }
        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);
        }
Ejemplo n.º 12
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 GetTownByNameShouldReturnNull()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetTownByName_Towns_DB")
                          .Options;

            var dbContext = new FooteoDbContext(options);

            var townsService = new TownsService(dbContext);

            townsService.CreateTown("Sofia");

            var town = townsService.GetTownByName <Town>("Burgas");

            Assert.Null(town);
        }
        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);
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
0
        public void GetLeagueByIdShouldReturnNull()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetLeagueByName_Leagues_DB")
                          .Options;

            var dbContext = new FooteoDbContext(options);

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

            leaguesService.CreateLeague("League", "Description", DateTime.UtcNow, DateTime.UtcNow.AddMonths(2), "Sofia");

            var invalidLeagueId = 2;
            var league          = leaguesService.GetLeagueById <League>(invalidLeagueId);

            Assert.Null(league);
        }
Ejemplo n.º 17
0
        public void LeagueExistsByNameShouldReturnTrue()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "LeagueExistsByName_Leagues_DB")
                          .Options;

            var dbContext = new FooteoDbContext(options);

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

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

            var leagueExists = leaguesService.LeagueExistsByName(league.Name);

            Assert.True(leagueExists);
        }
        public void FieldExistsByNameShouldReturnFalse()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "FieldExists_Fields_DB")
                          .Options;

            var dbContext = new FooteoDbContext(options);

            var townsService  = new TownsService(dbContext);
            var fieldsService = new FieldsService(dbContext, townsService);

            fieldsService.CreateField("Field", "Address", true, "Burgas");

            var fieldNameForTest = "Field1";
            var fieldExists      = fieldsService.FieldExistsByName(fieldNameForTest);

            Assert.False(fieldExists);
        }
Ejemplo n.º 19
0
        public async Task InvokeAsync(HttpContext context, FooteoDbContext dbContext,
                                      UserManager <FooteoUser> userManager, RoleManager <IdentityRole> roleManager)
        {
            if (!dbContext.Roles.Any())
            {
                await this.SeedRoles(userManager, roleManager);
            }

            if (!dbContext.Referees.Any())
            {
                await this.SeedReferees(dbContext, userManager);
            }

            if (!dbContext.Fields.Any())
            {
                this.SeedFields(dbContext);
            }

            await this.next(context);
        }
        public void CreateTownShouldReturnCorrectTownsCount()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "CreateTown_Towns_DB")
                          .Options;

            var dbContext = new FooteoDbContext(options);

            var townsService = new TownsService(dbContext);

            for (int i = 1; i <= 50; i++)
            {
                townsService.CreateTown($"Town{i}");
            }

            var townsCount         = dbContext.Towns.CountAsync().Result;
            var expectedTownsCount = 50;

            Assert.AreEqual(expectedTownsCount, townsCount);
        }
Ejemplo n.º 21
0
        public void SetLeagueStatusShouldReturnCompletedStatus()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "SetCompletedStatus_Leagues_DB")
                          .Options;

            var dbContext = new FooteoDbContext(options);

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

            leaguesService.CreateLeague($"LeagueC", $"Description", DateTime.UtcNow.AddDays(3), DateTime.UtcNow.AddMonths(3), "Varna");

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

            leaguesService.SetLeagueStatusToCompleted(league.Id);

            var expectedLeagueStatus = "Completed";

            Assert.AreEqual(expectedLeagueStatus, league.Status.ToString());
        }
Ejemplo n.º 22
0
        public void CreateLeagueShouldReturnCorrectCountOfLeagues()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "CreateLeague_Leagues_DB")
                          .Options;

            var dbContext = new FooteoDbContext(options);

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

            for (int i = 1; i <= 5; i++)
            {
                leaguesService.CreateLeague($"League{i}", $"Description{i}", DateTime.UtcNow.AddDays(i), DateTime.UtcNow.AddDays(i * i), "Sofia");
            }

            var leaguesCount         = dbContext.Leagues.CountAsync().Result;
            var expectedLeaguesCount = 5;

            Assert.AreEqual(expectedLeaguesCount, leaguesCount);
        }
        public void CreateFieldShouldReturnCorrectCountOfFields()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "CreateField_Fields_DB")
                          .Options;

            var dbContext = new FooteoDbContext(options);

            var townsService  = new TownsService(dbContext);
            var fieldsService = new FieldsService(dbContext, townsService);

            for (int i = 1; i <= 20; i++)
            {
                fieldsService.CreateField($"Field{i}", $"Address{i}", false, "Sofia");
            }

            var fieldsCount         = dbContext.Fields.CountAsync().Result;
            var expectedFieldsCount = 20;

            Assert.AreEqual(expectedFieldsCount, fieldsCount);
        }
        public void CreateFixtureShouldNotReturnNull()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "CreateFixture_Fixtures_DB")
                          .Options;

            var dbContext       = new FooteoDbContext(options);
            var townsService    = new TownsService(dbContext);
            var leaguesService  = new LeaguesService(dbContext, townsService);
            var fixturesService = new FixturesService(dbContext, leaguesService);

            leaguesService.CreateLeague("League", "Desc", DateTime.UtcNow, DateTime.UtcNow.AddMonths(2), "Sofia");

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

            fixturesService.CreateFixture("Matchday 1", DateTime.UtcNow, league.Id);

            var fixture = dbContext.Fixtures.FirstOrDefault(n => n.Name == "Matchday 1");

            Assert.NotNull(fixture);
        }
        public void GetLeagueForFixtureShouldReturnCorrectLeague()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetLeagueForFixture_Fixtures_DB")
                          .Options;

            var dbContext       = new FooteoDbContext(options);
            var townsService    = new TownsService(dbContext);
            var leaguesService  = new LeaguesService(dbContext, townsService);
            var fixturesService = new FixturesService(dbContext, leaguesService);

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

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

            var leagueForFixture = fixturesService.GetLeagueForFixture(fixture.Id);

            Assert.AreEqual(league, leagueForFixture);
        }
Ejemplo n.º 26
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 AllFieldsShouldReturnCorrectFieldsCount()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "AllFields_Fields_DB")
                          .Options;

            var dbContext = new FooteoDbContext(options);

            var townsService  = new TownsService(dbContext);
            var fieldsService = new FieldsService(dbContext, townsService);

            for (int i = 1; i <= 10; i++)
            {
                fieldsService.CreateField($"Field{i}", $"Address{i}", false, "Sofia");
            }

            var fields = fieldsService.AllFields <FieldViewModel>().ToList();

            var expectedFieldsCount = 10;

            Assert.AreEqual(expectedFieldsCount, fields.Count);
        }
Ejemplo n.º 28
0
        public void AllPendingLeaguesShouldReturnCorrectCount()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "PendingLeagues_Leagues_DB")
                          .Options;

            var dbContext = new FooteoDbContext(options);

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

            for (int i = 1; i <= 3; i++)
            {
                leaguesService.CreateLeague($"League{i}", $"Description{i}", DateTime.UtcNow.AddDays(i), DateTime.UtcNow.AddDays(i * i), "Sofia");
            }

            var pendingLeagues      = leaguesService.AllPendingLeagues <PendingLeagueViewModel>().ToList();
            var pendingLeaguesCount = pendingLeagues.Count;

            var expectedPendingLeaguesCount = 3;

            Assert.AreEqual(expectedPendingLeaguesCount, pendingLeaguesCount);
        }
        public void FixtureExistsByIdShouldReturnTrue()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "FixtureExistsByIdTrue_Fixtures_DB")
                          .Options;

            var dbContext       = new FooteoDbContext(options);
            var townsService    = new TownsService(dbContext);
            var leaguesService  = new LeaguesService(dbContext, townsService);
            var fixturesService = new FixturesService(dbContext, leaguesService);

            leaguesService.CreateLeague("League1", "Desc", DateTime.UtcNow, DateTime.UtcNow.AddMonths(2), "Sofia");

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

            fixturesService.CreateFixture("Matchday 2", DateTime.UtcNow, league.Id);

            var fixtureId = dbContext.Fixtures.FirstOrDefault(n => n.Name == "Matchday 2").Id;

            var fixtureExists = fixturesService.FixtureExistsById(fixtureId);

            Assert.True(fixtureExists);
        }
        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);
        }