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);
        }
Esempio n. 2
0
 public NewSeasonProcessService(ILogger <FixturesController> logger,
                                GameService gameService,
                                TeamsService teamsService,
                                FixturesService fixturesService,
                                StandingsService standingsService)
 {
     _logger           = logger;
     _gameService      = gameService;
     _teamsService     = teamsService;
     _fixturesService  = fixturesService;
     _standingsService = standingsService;
 }
 public ChampionshipWeekProcessService(ILogger <FixturesController> logger,
                                       GameService gameService,
                                       FixturesService fixturesService,
                                       StandingsService standingsService,
                                       TeamsService teamsService)
 {
     _logger           = logger;
     _gameService      = gameService;
     _fixturesService  = fixturesService;
     _standingsService = standingsService;
     _teamsService     = teamsService;
 }
        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);
        }
        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 GetFixtureByNameShouldReturnCorrectFixture()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetFixtureByName_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 fixtureId = dbContext.Fixtures.FirstOrDefault(n => n.Name == "Matchday 1").Id;
            var fixture   = fixturesService.GetFixtureById <FixtureViewModel>(fixtureId);

            var expectedFixtureName = "Matchday 1";

            Assert.AreEqual(expectedFixtureName, fixture.Name);
        }
        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);
        }
Esempio n. 9
0
 public FixturesController(ILogger <FixturesController> logger, FixturesService fixturesService)
 {
     _logger          = logger;
     _fixturesService = fixturesService;
 }