public Game GameFromArray(string[] line)
        {
            // set up a new game
            Game game = new Game();
            // set up the teams
            using (var repository = new TeamRepository())
            {
                var teams = (repository.GetAll().Where(t => t.Name == line[iHome])).ToList();
                if (teams.Count > 0)
                {
                    game.HomeTeamId = teams[0].Id;
                }
                else
                {
                    var home = new Team() { Name = line[iHome] };
                    home.Id = repository.Add(home);
                    game.HomeTeamId = home.Id;
                }
                teams = (repository.GetAll().Where(t => t.Name == line[iAway])).ToList();
                if (teams.Count > 0)
                {
                    game.AwayTeamId = teams[0].Id;
                }
                else
                {
                    var away = new Team() { Name = line[iAway] };
                    away.Id = repository.Add(away);
                    game.AwayTeamId = away.Id;
                }
            }

            // get the start time
            DateTime start = DateTime.Parse(line[iDate]);
            TimeSpan time = TimeSpan.Parse(line[iTime]);

            game.Start = start + time;

            // get the score
            string score = line[iScore];
            var scores = Regex.Matches(score, @"\d");
            game.HomeGoals = Int32.Parse(scores[0].Value);
            game.AwayGoals = Int32.Parse(scores[1].Value);

            // set the status of the tweet mining
            game.TweetsRetrieved = RetrievalStatus.NONE;

            return game;
        }
        public void BuildQueryTest()
        {
            string expected = "#chelsea OR #cfc OR #coys OR #thfc OR #CFCTHFC";
            // Set up teams
            Team chelsea = new Team()
            {
                Name = "Chelsea",
                ShortName = "CFC",
                Hashtags = new List<Hashtag>()
            };
            foreach (var tag in new List<string>() { "#chelsea", "#cfc" })
                chelsea.Hashtags.Add(new Hashtag() { Value = tag });
            Team spurs = new Team()
            {
                Name = "Tottenham Hotspur",
                ShortName = "THFC",
                Hashtags = new List<Hashtag>()
            };
            foreach (var tag in new List<string>() { "#coys", "#thfc" })
                chelsea.Hashtags.Add(new Hashtag() { Value = tag });
            // Set up the Game
            Game game = new Game()
            {
                HomeTeam = chelsea,
                AwayTeam = spurs,
                Start = new DateTime(2014, 3, 8, 17, 30, 0),
            };
            TweetMiner miner = new TweetMiner();

            // Execute
            string actual = miner.BuildQuery(game);

            // Validate
            Assert.IsNotNull(actual);
            Assert.AreEqual(expected, actual);
        }
        /// <summary>
        /// From the timeline data scraped identify what game it corresponds.
        /// returns null if the game is not found
        /// </summary>
        /// <param name="data">the scraped timeline data</param>
        /// <returns>the corresponding game object</returns>
        public Game GetGameFromDetailsData(string data)
        {
            Game game = new Game();
            var allJson = JsonConvert.DeserializeObject<JObject>(data);
            string homeStr = allJson["Data"]["HomeTeam"].ToString();
            JsonTeam homeTeam = JsonConvert.DeserializeObject<JsonTeam>(homeStr);

            string awayStr = allJson["Data"]["AwayTeam"].ToString();
            JsonTeam awayTeam = JsonConvert.DeserializeObject<JsonTeam>(awayStr);

            string startStr = allJson["Data"]["DateTime"].ToString();
            DateTime start = Convert.ToDateTime(startStr);
            game.Start = start;

            if (homeTeam == null || awayTeam == null ||
                homeTeam.Name == null || awayTeam.Name == null)
            {
                return null;
            }

            // set up the teams
            using (var repository = new TeamRepository())
            {
                // home team
                var teams = (repository.GetAll().Where(t => t.ShortName == homeTeam.Code)).ToList();
                if (teams.Count > 0)
                {
                    game.HomeTeamId = teams[0].Id;
                }
                else
                {
                    var home = new Team() { Name = homeTeam.Name };
                    home.Id = repository.Add(home);
                    game.HomeTeamId = home.Id;
                    game.HomeTeam = home;
                }
                // away team
                teams = (repository.GetAll().Where(t => t.ShortName == awayTeam.Code)).ToList();
                if (teams.Count > 0)
                {
                    game.AwayTeamId = teams[0].Id;
                }
                else
                {
                    var away = new Team() { Name = awayTeam.Name };
                    away.Id = repository.Add(away);
                    game.AwayTeamId = away.Id;
                }
            }

            // get the score
            game.HomeGoals = homeTeam.Score;
            game.AwayGoals = awayTeam.Score;

            // set the status of the tweet mining
            game.TweetsRetrieved = RetrievalStatus.NONE;

            return game;
        }