Example #1
0
        [InlineData("2020-08-26 00:30 +2")] //This is still the 25th in UTC.
        public async void PullKeys_FetchZipsForMultipleDays_NoErrors(string todayString)
        {
            int lastBatchNumFromHeader = 5;

            //Given there are 3 batches for day1, 3 batches for day 2, 3 batches for day3
            ExposureNotificationWebService mockedService = _helper.MockedService(new List <PullKeysMockData>
            {
                new PullKeysMockData(day1, 1).HttpStatusCode(200).WithLastBatchHeader(1).WithMoreBatchesExistHeader(true),
                new PullKeysMockData(day1, 2).HttpStatusCode(200).WithLastBatchHeader(2).WithMoreBatchesExistHeader(true),
                new PullKeysMockData(day1, 3).HttpStatusCode(200).WithLastBatchHeader(3).WithMoreBatchesExistHeader(false),
                new PullKeysMockData(day1, 4).HttpStatusCode(204),

                new PullKeysMockData(day2, 1).HttpStatusCode(200).WithLastBatchHeader(1).WithMoreBatchesExistHeader(true),
                new PullKeysMockData(day2, 2).HttpStatusCode(200).WithLastBatchHeader(2).WithMoreBatchesExistHeader(true),
                new PullKeysMockData(day2, 3).HttpStatusCode(200).WithLastBatchHeader(3).WithMoreBatchesExistHeader(false),
                new PullKeysMockData(day2, 4).HttpStatusCode(204),

                new PullKeysMockData(day3, 1).HttpStatusCode(200).WithLastBatchHeader(1).WithMoreBatchesExistHeader(true),
                new PullKeysMockData(day3, 2).HttpStatusCode(200).WithLastBatchHeader(2).WithMoreBatchesExistHeader(true),
                new PullKeysMockData(day3, 3).HttpStatusCode(200).WithLastBatchHeader(lastBatchNumFromHeader).WithMoreBatchesExistHeader(false),
                new PullKeysMockData(day3, 4).HttpStatusCode(204),
            });

            //Given today is day3
            DateTime newToday = DateTime.ParseExact(todayString, "yyyy-MM-dd HH:mm z", CultureInfo.GetCultureInfo("nn-NO"));

            SystemTime.SetDateTime(newToday);

            //Given last time we pulled was day3, batch2.
            _helper.SetLastPulledDate(day1, 2);

            //When pulling keys
            _developerTools.StartPullHistoryRecord();
            List <string> zipLocations = (await new ZipDownloader().PullNewKeys(mockedService, new CancellationToken())).ToList();

            //Then we pull the rest from day 1, all from day 2, and all from day 3
            Assert.Equal(7, zipLocations.Count);

            //The last batch number is saved from header
            Assert.Equal(lastBatchNumFromHeader, LocalPreferencesHelper.LastPullKeysBatchNumberNotSubmitted);

            //And no errors were logged
            Assert.False((await _logManager.GetLogs(10)).Any());

            //The history is stored for dev tools:
            string expected = $"Pulled the following keys (batches) at {newToday.ToUniversalTime().ToString("yyyy-MM-dd HH:mm")} UTC:\n" +
                              $"* 2020-08-23_3_no.zip: 200 OK\n" +
                              $"* 2020-08-24_1_no.zip: 200 OK\n" +
                              $"* 2020-08-24_2_no.zip: 200 OK\n" +
                              $"* 2020-08-24_3_no.zip: 200 OK\n" +
                              $"* 2020-08-25_1_no.zip: 200 OK\n" +
                              $"* 2020-08-25_2_no.zip: 200 OK\n" +
                              $"* 2020-08-25_3_no.zip: 200 OK";

            Assert.Equal(expected, _developerTools.LastPullHistory);
            Assert.Equal(expected, _developerTools.AllPullHistory);
        }