public void RosterInitializerIntializesRoster() { var teamRosters = new List <TeamRoster> { new TeamRoster(new team(), new string[] { "test", "another player" }) }; var leaguePlayers = new List <player> { new player { name = "test", playeryeardatas = new List <playeryeardata> { new playeryeardata { year = new year { value = 2014 }, finishingHandicap = 10, startingHandicap = 7, week0Score = 43 } } } }; RosterInitializer ri = new RosterInitializer(teamRosters, leaguePlayers, new year { value = 2015 }); Assert.IsTrue(ri.NewPlayerYearDatas.Count() == 1); Assert.IsTrue(ri.NewPlayers.Count() == 1); Assert.AreEqual("test", ri.NewPlayerYearDatas.First().player.name); Assert.IsTrue(ri.NewPlayerYearDatas.First().player.playeryeardatas.Any(x => x.year.value == 2015)); var pyd = ri.NewPlayerYearDatas.First().player.playeryeardatas.First(x => x.year.value == 2015); Assert.IsTrue(pyd.week0Score == 46); // defined as finishing handicap from previous year + 36 Assert.IsTrue(pyd.startingHandicap == 10); }
// TODO: maybe move this in to golf year stuff? This is nastyyyy private async Task <IEnumerable <string> > SaveRoster(string roster, IEnumerable <team> teams, year yearToSave) { if (string.IsNullOrEmpty(roster)) { return(new LinkedList <string>()); } using (RosterReader rosterReader = new RosterReader(new MemoryStream(Encoding.UTF8.GetBytes(roster)))) { var rosters = rosterReader.GetRoster(teams); // This fetches all players from the previous two years, as they may be in the league again this year. RosterInitializer rosterInitializer = new RosterInitializer(rosters, await this.Db.players.Where(x => x.playeryeardatas.Any(y => y.year.value > yearToSave.value - 4)).ToListAsync(), yearToSave); rosterInitializer.PersistRosters(this.Db); return(rosterInitializer.NewPlayers); } }