public async Task GetAllTeams()
        {
            try
            {
                Console.WriteLine("     ----- Begin Fetch teams ----- ");
                var availableCompetitions = Competition.AvailableCompetitions;
                foreach (var availableCompetition in availableCompetitions)
                {
                    var response = await _http.GetAsync("competitions/" + availableCompetition + "/teams");

                    var responseContent = await response.Content.ReadAsStringAsync();

                    var json      = JObject.Parse(responseContent);
                    var jsonTeams = json["teams"];
                    var teams     = JsonConvert.DeserializeObject <List <Team> >(JsonConvert.SerializeObject(jsonTeams));

                    foreach (var team in teams)
                    {
                        var findTeam = _teamDao.FindTeam(team.Id).Result;
                        if (findTeam == null)
                        {
                            Console.WriteLine("Add team " + team.Id + " " + team.Name);
                            _teamDao.AddTeam(team);
                        }
                        else
                        {
                            Console.WriteLine("Replace team " + team.Id + " " + team.Name);
                            _teamDao.ReplaceTeam(findTeam.Id, team);
                        }
                    }

                    Thread.Sleep(10000);
                }

                Console.WriteLine("     ----- End Fetch teams ----- ");
            }
            catch (Exception e)
            {
                SingletonManager.Instance.EmailManager.SendWebMasterEmail(e);
                throw;
            }
        }
Example #2
0
 public void AssertThatAddTeamIsCalled()
 {
     _teamDao.AddTeam(_team);
     _collection.Received().InsertOneAsync(Arg.Any <Team>());
 }