private Score AddPossibleGameScore(Game game) { // In order to determine if the latest game change is a scoring event, we create a // weighted decision based upon the last time a score was made for the game var timeSinceLastScore = _clock.Now - game.LastScoreTimestamp; var randomSeconds = TimeSpan.FromSeconds(_random.Any(1, 10)); if ((timeSinceLastScore + randomSeconds) < TimeSpan.FromSeconds(10)) { return(null); } // Randomly choose if the home/away team is scoring var teamId = _random.AnyBoolean() ? game.HomeTeamId : game.AwayTeamId; // Get any player who made the score var player = _gameDataRepository.GetRandom <Player>(x => x.TeamId == teamId); // Determine number of points var points = _random.Any(1, 3); var score = new Score { Id = Guid.NewGuid(), GameId = game.Id, GameName = game.Name, TeamId = teamId, TeamName = null, PlayerId = player.Id, PlayerName = player.Name, PlayerPosition = player.Position, Points = points, }; // Record the last time a score was made in the game game.LastScoreTimestamp = _clock.Now; using (var writeContext = _gameDataRepository.BeginWrite()) { writeContext.Update(game); writeContext.Insert(score); } return(score); }