public void FindEntityAsync_EntityNotFoundInDataStore_ThrowsObjectNotFoundException()
        {
            // Arrange
            var repository = new LeagueSeasonRepository();

            var dbContext  = A.Fake <ProFootballEntities>();
            var leagueName = "League";
            var seasonID   = 2017;

            LeagueSeason leagueSeason = null;

            A.CallTo(() => dbContext.LeagueSeasons.FindAsync(A <string> .Ignored, A <int> .Ignored)).Returns(leagueSeason);

            // Act
            LeagueSeason result = null;

            Assert.ThrowsAsync <ObjectNotFoundException>(async() =>
            {
                result = await repository.FindEntityAsync(dbContext, leagueName, seasonID);
            });

            // Assert
            A.CallTo(() => dbContext.LeagueSeasons.FindAsync(leagueName, seasonID)).MustHaveHappenedOnceExactly();
            Assert.IsNull(result);
        }
Beispiel #2
0
        public async Task GetLeagueSeason_WhenExceptionIsCaught_ShouldReturnInternalServerError()
        {
            // Arrange
            var          leagueSeasonRepository = A.Fake <ILeagueSeasonRepository>();
            LeagueSeason?leagueSeason           = new LeagueSeason();

            A.CallTo(() => leagueSeasonRepository.GetLeagueSeasonAsync(A <int> .Ignored)).Throws <Exception>();

            var sharedRepository = A.Fake <ISharedRepository>();

            var mapper = A.Fake <IMapper>();
            LeagueSeasonModel?leagueSeasonModel = new LeagueSeasonModel();

            A.CallTo(() => mapper.Map <LeagueSeasonModel>(A <LeagueSeason> .Ignored)).Returns(leagueSeasonModel);

            var linkGenerator = A.Fake <LinkGenerator>();

            var testController = new LeagueSeasonsController(leagueSeasonRepository, sharedRepository, mapper, linkGenerator);

            int id = 1;

            // Act
            var result = await testController.GetLeagueSeason(id);

            // Assert
            result.Result.ShouldBeOfType <ObjectResult>();
            ((ObjectResult)result.Result).StatusCode.ShouldBe(StatusCodes.Status500InternalServerError);
            ((ObjectResult)result.Result).Value.ShouldBe("Database failure");
        }
        public void AddLeagueSeasons()
        {
            // Arrange
            var repository = new LeagueSeasonRepository();

            var dbContext     = A.Fake <ProFootballEntities>();
            var leagueSeasons = new List <LeagueSeason>();

            for (int i = 1; i <= 3; i++)
            {
                var leagueSeason = new LeagueSeason
                {
                    LeagueName = "League " + i,
                    SeasonID   = 2017
                };
                leagueSeasons.Add(leagueSeason);
            }
            A.CallTo(() => dbContext.LeagueSeasons.AddRange(A <IEnumerable <LeagueSeason> > .Ignored)).Returns(leagueSeasons);

            // Act
            var result = repository.AddEntities(dbContext, leagueSeasons);

            // Assert
            A.CallTo(() => dbContext.LeagueSeasons.AddRange(leagueSeasons)).MustHaveHappenedOnceExactly();
            Assert.AreSame(leagueSeasons, result);
        }
Beispiel #4
0
        public async Task DeleteLeagueSeason_WhenLeagueSeasonIsFoundAndNotDeleted_ShouldReturnBadRequest()
        {
            // Arrange
            var          leagueSeasonRepository = A.Fake <ILeagueSeasonRepository>();
            LeagueSeason?leagueSeason           = new LeagueSeason();

            A.CallTo(() => leagueSeasonRepository.GetLeagueSeasonAsync(A <int> .Ignored)).Returns(leagueSeason);

            var sharedRepository = A.Fake <ISharedRepository>();

            A.CallTo(() => sharedRepository.SaveChangesAsync()).Returns(0);

            var mapper        = A.Fake <IMapper>();
            var linkGenerator = A.Fake <LinkGenerator>();

            var testController = new LeagueSeasonsController(leagueSeasonRepository, sharedRepository, mapper, linkGenerator);

            int id = 1;

            // Act
            var result = await testController.DeleteLeagueSeason(id);

            // Assert
            A.CallTo(() => leagueSeasonRepository.GetLeagueSeasonAsync(id)).MustHaveHappenedOnceExactly();
            A.CallTo(() => sharedRepository.SaveChangesAsync()).MustHaveHappenedOnceExactly();
            result.Result.ShouldBeOfType <BadRequestResult>();
        }
        //create new season with fake start and end dates (shoul be set later automaticcally by analyzers)
        public LeagueSeason CreateAndSaveLeagueSeason(int startYear, FootballLeague league)
        {
            if (Db.Database.Connection.State == System.Data.ConnectionState.Closed)
            {
                Db.Database.Connection.Open();
            }

            var newSeason = (from n in Db.LeagueSeasons where n.StartYear == startYear && n.League.LeagueId == league.LeagueId select n).FirstOrDefault();

            if (newSeason == null)
            {
                newSeason = new LeagueSeason
                {
                    StartYear = startYear,
                    League    = league,
                    StartDate = new DateTime(startYear, 1, 1),
                    EndDate   = new DateTime(startYear + 1, 1, 1)
                };

                Db.LeagueSeasons.Add(newSeason);
                Db.SaveChanges();

                var repo = new LogRepository();
                repo.WriteLog(Database.SystemData.Severity.Information, "Insert to LeagueSeasons table new record", nameof(LeagueDataRepository),
                              "localhost", "[LeagueId = " + league.LeagueId + "] [StartYear = " + newSeason.StartYear + "]", "");
            }

            Db.Database.Connection.Close();
            return(newSeason);
        }
Beispiel #6
0
        public async Task GetLeagueSeason_WhenLeagueSeasonIsNotNull_ShouldReturnLeagueSeasonModelOfDesiredLeagueSeason()
        {
            // Arrange
            var          leagueSeasonRepository = A.Fake <ILeagueSeasonRepository>();
            LeagueSeason?leagueSeason           = new LeagueSeason();

            A.CallTo(() => leagueSeasonRepository.GetLeagueSeasonAsync(A <int> .Ignored)).Returns(leagueSeason);

            var sharedRepository = A.Fake <ISharedRepository>();

            var mapper = A.Fake <IMapper>();
            LeagueSeasonModel?leagueSeasonModel = new LeagueSeasonModel();

            A.CallTo(() => mapper.Map <LeagueSeasonModel>(A <LeagueSeason> .Ignored)).Returns(leagueSeasonModel);

            var linkGenerator = A.Fake <LinkGenerator>();

            var testController = new LeagueSeasonsController(leagueSeasonRepository, sharedRepository, mapper, linkGenerator);

            int id = 1;

            // Act
            var result = await testController.GetLeagueSeason(id);

            // Assert
            A.CallTo(() => leagueSeasonRepository.GetLeagueSeasonAsync(id)).MustHaveHappenedOnceExactly();
            A.CallTo(() => mapper.Map <LeagueSeasonModel>(leagueSeason)).MustHaveHappenedOnceExactly();
            result.Value.ShouldBeOfType <LeagueSeasonModel>();
        }
        public async Task EditPost_WhenIdEqualsLeagueSeasonIdAndModelStateIsNotValid_ShouldReturnLeagueSeasonEditView()
        {
            // Arrange
            var leagueSeasonsIndexViewModel   = A.Fake <ILeagueSeasonsIndexViewModel>();
            var leagueSeasonsDetailsViewModel = A.Fake <ILeagueSeasonsDetailsViewModel>();
            var leagueSeasonRepository        = A.Fake <ILeagueSeasonRepository>();
            var sharedRepository = A.Fake <ISharedRepository>();
            var testController   = new LeagueSeasonsController(leagueSeasonsIndexViewModel, leagueSeasonsDetailsViewModel,
                                                               leagueSeasonRepository, sharedRepository);

            int id           = 1;
            var leagueSeason = new LeagueSeason
            {
                ID = 1
            };

            testController.ModelState.AddModelError("LongName", "Please enter a long name.");

            // Act
            var result = await testController.Edit(id, leagueSeason);

            // Assert
            A.CallTo(() => leagueSeasonRepository.Update(A <LeagueSeason> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => sharedRepository.SaveChangesAsync()).MustNotHaveHappened();
            result.ShouldBeOfType <ViewResult>();
            ((ViewResult)result).Model.ShouldBe(leagueSeason);
        }
        public async Task EditPost_WhenIdEqualsLeagueSeasonIdAndModelStateIsValidAndDbUpdateConcurrencyExceptionIsCaughtAndLeagueSeasonWithIdExists_ShouldRethrowException()
        {
            // Arrange
            var leagueSeasonsIndexViewModel   = A.Fake <ILeagueSeasonsIndexViewModel>();
            var leagueSeasonsDetailsViewModel = A.Fake <ILeagueSeasonsDetailsViewModel>();

            var leagueSeasonRepository = A.Fake <ILeagueSeasonRepository>();

            A.CallTo(() => leagueSeasonRepository.Update(A <LeagueSeason> .Ignored)).Throws <DbUpdateConcurrencyException>();
            A.CallTo(() => leagueSeasonRepository.LeagueSeasonExists(A <int> .Ignored)).Returns(true);

            var sharedRepository = A.Fake <ISharedRepository>();
            var testController   = new LeagueSeasonsController(leagueSeasonsIndexViewModel, leagueSeasonsDetailsViewModel,
                                                               leagueSeasonRepository, sharedRepository);

            int id           = 1;
            var leagueSeason = new LeagueSeason
            {
                ID = 1
            };

            // Act
            var func = new Func <Task <IActionResult> >(async() => await testController.Edit(id, leagueSeason));

            // Assert
            await func.ShouldThrowAsync <DbUpdateConcurrencyException>();
        }
        public async Task Details_WhenIdIsNotNullAndLeagueSeasonFound_ShouldReturnLeagueSeasonDetailsView()
        {
            // Arrange
            var leagueSeasonsIndexViewModel   = A.Fake <ILeagueSeasonsIndexViewModel>();
            var leagueSeasonsDetailsViewModel = A.Fake <ILeagueSeasonsDetailsViewModel>();

            var          leagueSeasonRepository = A.Fake <ILeagueSeasonRepository>();
            LeagueSeason?leagueSeason           = new LeagueSeason();

            A.CallTo(() => leagueSeasonRepository.GetLeagueSeasonAsync(A <int> .Ignored)).Returns(leagueSeason);

            var sharedRepository = A.Fake <ISharedRepository>();
            var testController   = new LeagueSeasonsController(leagueSeasonsIndexViewModel, leagueSeasonsDetailsViewModel,
                                                               leagueSeasonRepository, sharedRepository);

            int?id = 0;

            // Act
            var result = await testController.Details(id);

            // Assert
            A.CallTo(() => leagueSeasonRepository.GetLeagueSeasonAsync(id.Value)).MustHaveHappenedOnceExactly();
            leagueSeasonsDetailsViewModel.LeagueSeason.ShouldBe(leagueSeason);
            result.ShouldBeOfType <ViewResult>();
            ((ViewResult)result).Model.ShouldBe(leagueSeasonsDetailsViewModel);
        }
        public async Task EditPost_WhenIdEqualsLeagueSeasonIdAndModelStateIsValidAndDbUpdateConcurrencyExceptionIsCaughtAndLeagueSeasonWithIdDoesNotExist_ShouldReturnNotFound()
        {
            // Arrange
            var leagueSeasonsIndexViewModel   = A.Fake <ILeagueSeasonsIndexViewModel>();
            var leagueSeasonsDetailsViewModel = A.Fake <ILeagueSeasonsDetailsViewModel>();

            var leagueSeasonRepository = A.Fake <ILeagueSeasonRepository>();

            A.CallTo(() => leagueSeasonRepository.Update(A <LeagueSeason> .Ignored)).Throws <DbUpdateConcurrencyException>();
            A.CallTo(() => leagueSeasonRepository.LeagueSeasonExists(A <int> .Ignored)).Returns(false);

            var sharedRepository = A.Fake <ISharedRepository>();
            var testController   = new LeagueSeasonsController(leagueSeasonsIndexViewModel, leagueSeasonsDetailsViewModel,
                                                               leagueSeasonRepository, sharedRepository);

            int id           = 1;
            var leagueSeason = new LeagueSeason
            {
                ID = 1
            };

            // Act
            var result = await testController.Edit(id, leagueSeason);

            // Assert
            result.ShouldBeOfType <NotFoundResult>();
        }
Beispiel #11
0
        public async Task PutLeagueSeason_WhenLeagueSeasonIsFoundAndSaved_ShouldReturnModelOfLeagueSeason()
        {
            // Arrange
            var          leagueSeasonRepository = A.Fake <ILeagueSeasonRepository>();
            LeagueSeason?leagueSeason           = new LeagueSeason();

            A.CallTo(() => leagueSeasonRepository.GetLeagueSeasonAsync(A <int> .Ignored)).Returns(leagueSeason);

            var sharedRepository = A.Fake <ISharedRepository>();

            A.CallTo(() => sharedRepository.SaveChangesAsync()).Returns(1);

            var mapper      = A.Fake <IMapper>();
            var returnModel = new LeagueSeasonModel();

            A.CallTo(() => mapper.Map <LeagueSeasonModel>(leagueSeason)).Returns(returnModel);

            var linkGenerator = A.Fake <LinkGenerator>();

            var testController = new LeagueSeasonsController(leagueSeasonRepository, sharedRepository, mapper, linkGenerator);

            int id    = 1;
            var model = new LeagueSeasonModel();

            // Act
            var result = await testController.PutLeagueSeason(id, model);

            // Assert
            A.CallTo(() => leagueSeasonRepository.GetLeagueSeasonAsync(id)).MustHaveHappenedOnceExactly();
            A.CallTo(() => mapper.Map(model, leagueSeason)).MustHaveHappenedOnceExactly();
            A.CallTo(() => sharedRepository.SaveChangesAsync()).MustHaveHappenedOnceExactly();
            A.CallTo(() => mapper.Map <LeagueSeasonModel>(leagueSeason)).MustHaveHappenedOnceExactly();
            result.Value.ShouldBe(returnModel);
        }
        //get football team by name or create one if doesn't exist
        public FootballTeam GetFootballTeam(string name, LeagueSeason season, string sourceId = "")
        {
            if (Db.Database.Connection.State == System.Data.ConnectionState.Closed)
            {
                Db.Database.Connection.Open();
            }

            var footballTeam = (from n in Db.FootballTeams where n.Name == name select n).FirstOrDefault();

            if (footballTeam?.ParentTeamId != null)
            {
                footballTeam = (from n in Db.FootballTeams where n.TeamId == footballTeam.ParentTeamId select n).FirstOrDefault();
            }

            if (footballTeam == null)
            {
                footballTeam = new FootballTeam
                {
                    Location   = season.League.Location,
                    LocationId = season.League.Location.LocationId,
                    Name       = name,
                    SourceId   = sourceId
                };

                Db.FootballTeams.Add(footballTeam);
                Db.SaveChanges();

                var repo = new LogRepository();
                repo.WriteLog(Database.SystemData.Severity.Information, "Insert to FootballTeams table new record", nameof(LeagueDataRepository),
                              "localhost", "[FootballTeamId = " + footballTeam.TeamId + "]", "");
            }

            Db.Database.Connection.Close();
            return(footballTeam);
        }
Beispiel #13
0
        private void AnalyzeLeagueSeason(LeagueSeason season)
        {
            var allSeasonGames = leagueRepo.GetAllSeasonGames(season.LeagueSeasonId);
            var analyzedGames  = systemRepo.GetBookmakerOddsStatsAnalyzeGames(season.LeagueSeasonId);

            var processedGames = new List <int>();

            foreach (var game in allSeasonGames)
            {
                if (game.Result == 0 || analyzedGames.FindIndex(g => g.GameId == game.GameId) >= 0)
                {
                    continue;
                }
                var gameOddsStats = new BookmakerOddsStats
                {
                    GameId = game.GameId
                };

                ComputeBookmakerOddsStats(gameOddsStats, game);

                analysisRepo.AddOrUpdateBookmakerOddsStats(gameOddsStats);
                processedGames.Add(game.GameId);
            }

            systemRepo.AddAnalyzedGames_BookmakerOddsStats(processedGames, season.LeagueSeasonId);
        }
Beispiel #14
0
        public async Task <IHttpActionResult> PutLeagueSeason(int id, LeagueSeason leagueSeason)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != leagueSeason.Id)
            {
                return(BadRequest());
            }

            db.Entry(leagueSeason).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LeagueSeasonExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task EditPost_WhenIdEqualsLeagueSeasonIdAndModelStateIsValidAndDbUpdateConcurrencyExceptionIsNotCaught_ShouldUpdateLeagueSeasonInDataStoreAndRedirectToIndexView()
        {
            // Arrange
            var leagueSeasonsIndexViewModel   = A.Fake <ILeagueSeasonsIndexViewModel>();
            var leagueSeasonsDetailsViewModel = A.Fake <ILeagueSeasonsDetailsViewModel>();
            var leagueSeasonRepository        = A.Fake <ILeagueSeasonRepository>();
            var sharedRepository = A.Fake <ISharedRepository>();
            var testController   = new LeagueSeasonsController(leagueSeasonsIndexViewModel, leagueSeasonsDetailsViewModel,
                                                               leagueSeasonRepository, sharedRepository);

            int id           = 1;
            var leagueSeason = new LeagueSeason
            {
                ID = 1
            };

            // Act
            var result = await testController.Edit(id, leagueSeason);

            // Assert
            A.CallTo(() => leagueSeasonRepository.Update(leagueSeason)).MustHaveHappenedOnceExactly();
            A.CallTo(() => sharedRepository.SaveChangesAsync()).MustHaveHappenedOnceExactly();
            result.ShouldBeOfType <RedirectToActionResult>();
            ((RedirectToActionResult)result).ActionName.ShouldBe <string>(nameof(testController.Index));
        }
        public StandingTableAnalysis GetStandingTable(LeagueSeason season)
        {
            if (Db.Database.Connection.State == System.Data.ConnectionState.Closed)
            {
                Db.Database.Connection.Open();
            }

            var standingTable = (from n in Db.StandingTableAnalysis where n.LeagueSeasonId == season.LeagueSeasonId select n).FirstOrDefault();

            if (standingTable == null)
            {
                standingTable = new StandingTableAnalysis
                {
                    AnalysisDone   = false,
                    Created        = DateTime.Now,
                    LastUpdate     = DateTime.Now,
                    LeagueSeasonId = season.LeagueSeasonId
                };

                Db.StandingTableAnalysis.Add(standingTable);
                Db.SaveChanges();

                var repo = new LogRepository();
                repo.WriteLog(Severity.Information, "Insert to StandingTableAnalysis table new record", nameof(SystemDataRepository),
                              "localhost", "[LeagueSeasonId = " + standingTable.LeagueSeasonId + "]", "");
            }

            Db.Database.Connection.Close();
            return(standingTable);
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,LeagueName,SeasonYear,TotalGames,TotalPoints,AveragePoints")] LeagueSeason leagueSeason)
        {
            if (id != leagueSeason.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _leagueSeasonRepository.Update(leagueSeason);
                    await _sharedRepository.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!await _leagueSeasonRepository.LeagueSeasonExists(leagueSeason.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }

            return(View(leagueSeason));
        }
        public async Task RunWeeklyUpdate_WhenLeagueSeasonTotalsTotalGamesAndTotalPointsAreNotNull_ShouldUpdateLeagueSeasonGamesAndPoints()
        {
            // Arrange
            var seasonRepository             = A.Fake <ISeasonRepository>();
            var gameRepository               = A.Fake <IGameRepository>();
            var leagueSeasonRepository       = A.Fake <ILeagueSeasonRepository>();
            var leagueSeasonTotalsRepository = A.Fake <ILeagueSeasonTotalsRepository>();
            var teamSeasonRepository         = A.Fake <ITeamSeasonRepository>();
            var teamSeasonScheduleRepository = A.Fake <ITeamSeasonScheduleRepository>();
            var sharedRepository             = A.Fake <ISharedRepository>();

            var service = new WeeklyUpdateService(seasonRepository, gameRepository, leagueSeasonRepository,
                                                  leagueSeasonTotalsRepository, teamSeasonRepository, teamSeasonScheduleRepository, sharedRepository);

            var leagueSeasonTotals = new LeagueSeasonTotals
            {
                TotalGames  = 0,
                TotalPoints = 0
            };

            A.CallTo(() => leagueSeasonTotalsRepository.GetLeagueSeasonTotals(A <string> .Ignored, A <int> .Ignored))
            .Returns(leagueSeasonTotals);

            var leagueSeason = new LeagueSeason();

            A.CallTo(() => leagueSeasonRepository.GetLeagueSeasonByLeagueAndSeasonAsync(A <string> .Ignored, A <int> .Ignored))
            .Returns(leagueSeason);

            var seasonYear = 1920;

            var games = new List <Game>
            {
                new Game
                {
                    SeasonYear = seasonYear,
                    Week       = 0
                }
            };

            A.CallTo(() => gameRepository.GetGamesAsync()).Returns(games);

            A.CallTo(() => seasonRepository.GetSeasonAsync(A <int> .Ignored)).Returns <Season?>(null);

            // Act
            await service.RunWeeklyUpdate(seasonYear);

            // Assert
            var leagueName = "APFA";

            A.CallTo(() => leagueSeasonTotalsRepository.GetLeagueSeasonTotals(leagueName, seasonYear))
            .MustHaveHappened();
            A.CallTo(() => leagueSeasonRepository.GetLeagueSeasonByLeagueAndSeasonAsync(leagueName, seasonYear))
            .MustHaveHappened();
            A.CallTo(() => gameRepository.GetGamesAsync()).MustHaveHappened();
            A.CallTo(() => seasonRepository.GetSeasonAsync(seasonYear)).MustHaveHappened();
            A.CallTo(() => sharedRepository.SaveChangesAsync()).MustHaveHappenedOnceExactly();
            A.CallTo(() => teamSeasonRepository.GetTeamSeasonsBySeasonAsync(A <int> .Ignored)).MustNotHaveHappened();
        }
        //get current round of season - create one or get latest (if latest has already ROUND_GAMES_NUMBER games - create new one)
        private SeasonRound GetLatestSeasonRound(LeagueSeason leagueSeason)
        {
            if (Db.Database.Connection.State == System.Data.ConnectionState.Closed)
            {
                Db.Database.Connection.Open();
            }

            var round = (from n in Db.SeasonRounds where n.LeagueSeasonId == leagueSeason.LeagueSeasonId orderby n.RoundId descending select n).FirstOrDefault();

            if (round == null) //leagueSeason doesn't have rounds yet
            {
                round = new SeasonRound
                {
                    LeagueSeason   = leagueSeason,
                    LeagueSeasonId = leagueSeason.LeagueSeasonId,
                    IsFinished     = false,
                    RoundNumber    = 1,
                    GamePlayed     = 0,
                    StartDate      = DateTime.Now,
                    EndDate        = DateTime.Now,
                    LastUpdate     = DateTime.Now
                };

                Db.SeasonRounds.Add(round);
                Db.SaveChanges();

                var repo = new LogRepository();
                repo.WriteLog(Database.SystemData.Severity.Information, "Insert to SeasonRounds table new record", nameof(LeagueDataRepository),
                              "localhost", "[RoundId = " + round.RoundId + "]", "");
            }
            else if (round.GamePlayed >= ROUND_GAMES_NUMBER) //round already has maximum number of games -> should create new round
            {
                var newRound = new SeasonRound
                {
                    LeagueSeason   = leagueSeason,
                    LeagueSeasonId = leagueSeason.LeagueSeasonId,
                    IsFinished     = false,
                    RoundNumber    = round.RoundNumber + 1,
                    GamePlayed     = 0,
                    StartDate      = DateTime.Now,
                    EndDate        = DateTime.Now,
                    LastUpdate     = DateTime.Now
                };

                Db.SeasonRounds.Add(newRound);
                Db.SaveChanges();

                round = newRound;

                var repo = new LogRepository();
                repo.WriteLog(Database.SystemData.Severity.Information, "Insert to SeasonRounds table new record", nameof(LeagueDataRepository),
                              "localhost", "[RoundId = " + round.RoundId + "]", "");
            }

            Db.Database.Connection.Close();
            return(round);
        }
Beispiel #20
0
        public async Task <IHttpActionResult> GetLeagueSeason(int id)
        {
            LeagueSeason leagueSeason = await db.LeagueSeasons.FindAsync(id);

            if (leagueSeason == null)
            {
                return(NotFound());
            }

            return(Ok(leagueSeason));
        }
        public IActionResult Index(int competitionID)
        {
            var leagueSeason = new LeagueSeason
            {
                CompetitionID = competitionID,
                Competition   = _leagueService.GetCompetition(competitionID, _hostingEnvironment.WebRootPath),
                Season        = _seasonService.GetSeason(_hostingEnvironment.WebRootPath)
            };

            return(View(leagueSeason));
        }
        public LeagueSeason Build()
        {
            if (league == null)
            {
                league = A.League.Build();
            }

            var leagueSeason = new LeagueSeason(league, A.Date, A.Date.AddMonths(9), A.Team.Repeat(18));

            return leagueSeason;
        }
Beispiel #23
0
        public async Task <IHttpActionResult> PostLeagueSeason(LeagueSeason leagueSeason)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.LeagueSeasons.Add(leagueSeason);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = leagueSeason.Id }, leagueSeason));
        }
        public void EditLeagueSeason_ExceptionCaught_LogsAndRethrowsException()
        {
            // Arrange
            var dbContext  = A.Fake <ProFootballEntities>();
            var repository = new LeagueSeasonRepository(dbContext);

            var leagueSeason = new LeagueSeason();

            A.CallTo(() => dbContext.SetModified(A <LeagueSeason> .Ignored)).Throws <Exception>();

            // Act & Assert
            Assert.Throws <Exception>(() => repository.EditEntity(leagueSeason));
        }
Beispiel #25
0
        /// <summary>
        /// Updates a <see cref="LeagueSeason"/> entity in the data store.
        /// </summary>
        /// <param name="leagueSeason">The <see cref="LeagueSeason"/> to update.</param>
        /// <returns>The updated <see cref="LeagueSeason"/> entity.</returns>
        public LeagueSeason Update(LeagueSeason leagueSeason)
        {
            if (_dbContext.LeagueSeasons is null)
            {
                return(leagueSeason);
            }

            var entity = _dbContext.LeagueSeasons.Attach(leagueSeason);

            entity.State = EntityState.Modified;

            return(leagueSeason);
        }
        public async Task <IActionResult> Create([Bind("LeagueName,SeasonYear,TotalGames,TotalPoints,AveragePoints")] LeagueSeason leagueSeason)
        {
            if (ModelState.IsValid)
            {
                await _leagueSeasonRepository.AddAsync(leagueSeason);

                await _sharedRepository.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(leagueSeason));
        }
        public void Run(BasketballDataContext dbContext)
        {
            var url     = Feeds.LeaguesFeed.GetFeedUrl();
            var rawJson = JsonUtility.GetRawJsonFromUrl(url);
            var feed    = Feeds.LeaguesFeed.FromJson(rawJson);

            // ASSUME COUNTRY ALREADY EXISTS IN COUNTRIES API ENDPOINT
            var countriesDict = dbContext.Countries.ToDictionary(x => x.ApiBasketballCountryId, y => y.CountryId);

            var existingLeagues = dbContext.Leagues.ToDictionary(x => x.ApiBasketballLeagueId, y => y);

            var orderedLeagues = feed.Leagues.OrderBy(x => x.Country.Code ?? string.Empty).ThenBy(y => y.Name).ToList();

            foreach (var apiLeague in orderedLeagues)
            {
                if (!existingLeagues.TryGetValue(apiLeague.Id, out League dbLeague))
                {
                    dbLeague = new League
                    {
                        ApiBasketballLeagueId = apiLeague.Id,
                        LeagueName            = apiLeague.Name,
                        LeagueLogo            = apiLeague.Logo,
                        CountryId             = countriesDict[apiLeague.Country.Id],
                        LeagueType            = apiLeague.Type,
                        LeagueSeasons         = new List <LeagueSeason>()
                    };

                    existingLeagues.Add(dbLeague.ApiBasketballLeagueId, dbLeague);
                    dbContext.Leagues.Add(dbLeague);
                }

                var dbLeagueSeasons  = dbContext.LeagueSeasons.Where(x => x.League.ApiBasketballLeagueId == apiLeague.Id).ToDictionary(x => x.ApiBasketballSeasonKey);
                var leagueSeasons    = dbLeague.LeagueSeasons ?? new List <LeagueSeason>();
                var apiLeagueSeasons = apiLeague.Seasons.OrderBy(x => x.Start).ToList();

                foreach (var apiSeason in apiLeagueSeasons)
                {
                    if (!dbLeagueSeasons.ContainsKey(apiSeason.Season))
                    {
                        var dbLeagueSeason = new LeagueSeason
                        {
                            ApiBasketballSeasonKey = apiSeason.Season,
                            SeasonStartUtc         = apiSeason.Start.UtcDateTime,
                            SeasonEndUtc           = apiSeason.End.UtcDateTime,
                            ApiBasketballLeagueId  = apiLeague.Id
                        };
                        dbLeague.LeagueSeasons.Add(dbLeagueSeason);
                    }
                }
            }
        }
        public void EditLeagueSeason_HappyPath()
        {
            // Arrange
            var dbContext  = A.Fake <ProFootballEntities>();
            var repository = new LeagueSeasonRepository(dbContext);

            var leagueSeason = new LeagueSeason();

            // Act
            repository.EditEntity(leagueSeason);

            // Assert
            A.CallTo(() => dbContext.SetModified(leagueSeason)).MustHaveHappenedOnceExactly();
        }
Beispiel #29
0
        public async Task <IHttpActionResult> DeleteLeagueSeason(int id)
        {
            LeagueSeason leagueSeason = await db.LeagueSeasons.FindAsync(id);

            if (leagueSeason == null)
            {
                return(NotFound());
            }

            db.LeagueSeasons.Remove(leagueSeason);
            await db.SaveChangesAsync();

            return(Ok(leagueSeason));
        }
        public void CreateLeagueSeason_ExceptionCaught_LogsAndRethrowsException()
        {
            // Arrange
            var dbContext  = A.Fake <ProFootballEntities>();
            var repository = new LeagueSeasonRepository(dbContext);

            A.CallTo(() => dbContext.LeagueSeasons.Create()).Throws <Exception>();

            // Act
            LeagueSeason result = null;

            Assert.Throws <Exception>(() => result = repository.CreateEntity());

            // Assert
            Assert.IsNull(result);
        }
        public void RemoveLeagueSeason_HappyPath()
        {
            // Arrange
            var dbContext  = A.Fake <ProFootballEntities>();
            var repository = new LeagueSeasonRepository(dbContext);

            var leagueSeason = new LeagueSeason();

            A.CallTo(() => dbContext.LeagueSeasons.Remove(A <LeagueSeason> .Ignored)).Returns(leagueSeason);

            // Act
            var result = repository.RemoveEntity(leagueSeason);

            // Assert
            A.CallTo(() => dbContext.LeagueSeasons.Remove(leagueSeason)).MustHaveHappenedOnceExactly();
            Assert.AreSame(leagueSeason, result);
        }
 private IEnumerable<Fixture> CreateLeagueSchedule(LeagueSeason leagueSeason)
 {
     return scheduler.ScheduleLeagueFixtures(leagueSeason, leagueSeason.Teams,
         leagueSeason.StartDate, leagueSeason.EndDate, leagueSeason.DayOfWeek, leagueSeason.Frequency);
 }