public static async Task Run([TimerTrigger("0 45 17 * * *")] TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"[BEGIN] StandingsImporter: {DateTime.Now}");
            var serviceProvider   = new ServiceCollection().AddHttpClient().BuildServiceProvider();
            var httpClientFactory = serviceProvider.GetService <IHttpClientFactory>();

            var settings = AppSettings.Configure();

            using (var sqlConnection = new SqlConnection(settings.Database.ConnectionString))
            {
                sqlConnection.Open();
                var databaseConnection = new DatabaseConnection(sqlConnection);

                var standingsMapper     = new StandingsMapper();
                var topEuroCompetitions = new CompetitionDatabase(databaseConnection, new[] { 524, 565, 581, 582, 764, 770, 525, 526, 573, 574, 988, 754, 755, 771, 775, 776, 891, 902, 656, 766, 1264, 432, 577, 576, 357, 566, 571, 787, 1312, 1310 });
                var standingsProvider   = new ApiFootballStandingProvider(httpClientFactory, settings.Api.AuthToken, standingsMapper, topEuroCompetitions, new ApiFootballThrottler());
                var standings           = await StandingsCollection.RetrieveFrom(standingsProvider);

                var teamDb        = new TeamDatabase(databaseConnection);
                var competitionDb = new CompetitionDatabase(databaseConnection);
                var standingsDb   = new StandingsDatabase(databaseConnection, teamDb, competitionDb);

                log.LogInformation($"Retrieved {standings.Count()} league standings");
                await standings.SaveTo(standingsDb, competitionDb, teamDb);
            }

            log.LogInformation($"[COMPLETE] StandingsImporter: {DateTime.Now}");
        }
Ejemplo n.º 2
0
        public StandingsMapperTests()
        {
            var autoFixture = new AutoFixture.Fixture();

            autoFixture.Customize <Standing>(x => x.With(s => s.Stage, "REGULAR_SEASON"));
            _source = autoFixture.Create <StandingResponse>();

            var rnd   = new Random();
            var index = rnd.Next(_source.Standings.Length);

            _source.Standings[index].Type = "TOTAL";

            var mapper = new StandingsMapper();

            _result = mapper.MapAsync(_source).Result;
        }