public SeasonSummary GetForSeason(int season) { var summary = new SeasonSummary(); var cmd = new MySqlCommand(GET_BY_SEASON); cmd.Parameters.AddWithValue("@season", season); ExecuteReader(cmd, dr => summary.Weeks.Add(MapWeekSummary(dr))); return summary; }
private static void ProcessForCurrentWeek(SeasonSummary seasonSummary, DateTime today) { if (seasonSummary.Weeks == null || seasonSummary.Weeks.Count == 0) { return; } var foundCurrentWeek = false; for (var i = 1; i < seasonSummary.Weeks.Count; i++) { DateTime previousLastGamePlayed; if (i == 0) { previousLastGamePlayed = seasonSummary.Weeks[0].LastGamePlayed; } else { previousLastGamePlayed = seasonSummary.Weeks[i - 1].LastGamePlayed; } var lastGamePlayedWithPadding = seasonSummary.Weeks[i].LastGamePlayed.AddHours(12); if (today <= lastGamePlayedWithPadding && today > previousLastGamePlayed) { seasonSummary.Weeks[i].IsCurrent = true; foundCurrentWeek = true; break; } } // If we didnt set a current week, then just set the current week to the last week of the season if (!foundCurrentWeek) { if (today <= seasonSummary.Weeks.Min(week => week.LastGamePlayed)) { seasonSummary.Weeks.First().IsCurrent = true; } else { seasonSummary.Weeks.Last().IsCurrent = true; } } }
public void ParseToRecordQuery_AssignsWeekCorrectlyWhenRequestingCurrentSeason() { var seasonInfo = new SeasonSummary { Weeks = new[] { new WeekSummary { IsCurrent = false, Season = 2013, SeasonType = SeasonType.REG, Week = 1, }, new WeekSummary { IsCurrent = true, Season = 2013, SeasonType = SeasonType.REG, Week = 9, }, new WeekSummary { IsCurrent = false, Season = 2013, SeasonType = SeasonType.REG, Week = 10, } } }; _seasonManager .Setup(manager => manager.GetForSeason(2013, It.IsAny<DateTime>())) .Returns(seasonInfo); var results = _recordsManager.ParseToRecordQuery("cur/cur/cur"); Assert.Equal(9, results[0].Week); }
public void ParseToRecordQuery_SetsCurrentWeekCorrectly() { var seasonInfo = new SeasonSummary { Weeks = new[] { new WeekSummary { IsCurrent = false, Season = 2013, SeasonType = SeasonType.REG, Week = 1, }, new WeekSummary { IsCurrent = true, Season = 2013, SeasonType = SeasonType.REG, Week = 2, } } }; _seasonManager .Setup(manager => manager.GetForSeason(2013, It.IsAny<DateTime>())) .Returns(seasonInfo); var results = _recordsManager.ParseToRecordQuery("cur/cur/cur,cur,cur/cur/,cur/cur/cur,cur/cur/12"); Assert.True(results[0].CurrentWeek); Assert.False(results[1].CurrentWeek); Assert.False(results[2].CurrentWeek); Assert.True(results[3].CurrentWeek); Assert.False(results[4].CurrentWeek); }
public SeasonManagerTests() { _repository = new Mock<ISeasonRepository>(); _manager = new SeasonManager(_repository.Object); var baseDate = new DateTime(2013, 9, 1); var preWeek1 = new WeekSummary { Season = 2013, Week = 1, SeasonType = SeasonType.PRE, LastGamePlayed = baseDate // 9/1/2013 }; var preWeek2 = new WeekSummary { Season = 2013, Week = 2, SeasonType = SeasonType.PRE, LastGamePlayed = baseDate.AddDays(7) // 9/8/2013 }; var regWeek1 = new WeekSummary { Season = 2013, Week = 1, SeasonType = SeasonType.REG, LastGamePlayed = baseDate.AddDays(14) // 9/15/2013 }; var regWeek2 = new WeekSummary { Season = 2013, Week = 2, SeasonType = SeasonType.REG, LastGamePlayed = baseDate.AddDays(21) // 9/22/2013 }; var regWeek3 = new WeekSummary { Season = 2013, Week = 3, SeasonType = SeasonType.REG, LastGamePlayed = baseDate.AddDays(28) // 9/29/2013 }; var regWeek4 = new WeekSummary { Season = 2013, Week = 4, SeasonType = SeasonType.REG, LastGamePlayed = baseDate.AddDays(35) // 10/6/2013 }; _summary = new SeasonSummary { Weeks = new[] { preWeek1, preWeek2, regWeek1, regWeek2, regWeek3, regWeek4 } }; _repository .Setup(repository => repository.GetForSeason(It.IsAny<int>())) .Returns(_summary); }