public void ShouldAddGames() { using (var db = new JUGContext()) { var teamDataService = new BaseDataService <TeamDAO>(); var gameDataService = new GameDataService(); Assert.Empty(teamDataService.GetAll(db)); Assert.Empty(gameDataService.GetAll(db)); DbHelper.AddSomeTeams(10, db); var game = new GameDAO(); game.Home = teamDataService.GetAll(db).Where(t => t.Name == "Team 1").FirstOrDefault(); game.Away = teamDataService.GetAll(db).Where(t => t.Name == "Team 6").FirstOrDefault(); game.AwayScore = 5; game.HomeScore = 6; game.IsComplete = true; game.IsStarted = true; game.CanTie = true; gameDataService.Create(game, db); Assert.Single(db.Games.Local); } }
//should over write the basic create method public IGameViewModel Create(long homeId, long awayId) { var homeTeam = TeamService.GetDomainObjectById(homeId); var awayTeam = TeamService.GetDomainObjectById(awayId); var mostRecentGameNumber = GameDataService.MostRecentGameNumber(); var gameNo = mostRecentGameNumber + 1; //need a way to get this var day = 1; //need a way to get this var year = 1; //need a way to get this var canTie = true; //need a way to get this var maxOverTimePeriods = 1; //need a way to get this var minPeriods = 3; //need a way to get this var game = new Game(null, gameNo, day, year, 1, homeTeam, new GameTeamStats(0, 0), awayTeam, new GameTeamStats(0, 0), false, false, canTie, minPeriods, maxOverTimePeriods); //map the model var gameDAO = Mapper.DomainToDAO(game); using (var db = new JUGContext()) { //when creating we need to make sure we populate the child objects with registered data objects gameDAO.Home = TeamDataService.GetById(homeId, db); gameDAO.Away = TeamDataService.GetById(awayId, db); GameDataService.Create(gameDAO, db); GameDataService.SaveChanges(db); } game.Id = gameDAO.Id; return(Mapper.DomainToViewModel(game)); }