public async void Tests_that_batch_downloads_over_multiple_days_are_processed_in_expected_order() { // Assemble: test state var downloadedBatches = new List <IksWriteArgs>(); // Assemble: other object var logger = new IksDownloaderLoggingExtensions(new TestLogger <IksDownloaderLoggingExtensions>()); var now = DateTime.UtcNow; var dtp = new Mock <IUtcDateTimeProvider>(); dtp.Setup(_ => _.Snapshot).Returns(now); var writer = new Mock <IIksWriterCommand>(); writer.Setup(_ => _.Execute(It.IsAny <IksWriteArgs>())) .Callback((IksWriteArgs args) => downloadedBatches.Add(args)); // Assemble: configure receiver to return batches for the FIRST day var responses = new List <HttpGetIksSuccessResult>() { new HttpGetIksSuccessResult { BatchTag = "1", Content = new byte[] { 0x0, 0x0 }, NextBatchTag = "2" }, new HttpGetIksSuccessResult { BatchTag = "2", Content = new byte[] { 0x0, 0x0 }, NextBatchTag = null }, }; var receiver = FixedResultHttpGetIksCommand.Create(responses, now.AddDays(-1)); // Assemble: create the job to be tested IksPollingBatchJob sut = new IksPollingBatchJob(dtp.Object, () => receiver, () => writer.Object, _IksInDbProvider.CreateNew(), new EfgsConfig(), logger); // Act - process files for FIRST day await sut.ExecuteAsync(); // Assert Assert.Equal(2, downloadedBatches.Count); // Assemble: add the batches for the SECOND day to the receiver receiver.AddItem(new HttpGetIksSuccessResult { BatchTag = "3", Content = new byte[] { 0x0, 0x0 }, NextBatchTag = "4" }, now); receiver.AddItem(new HttpGetIksSuccessResult { BatchTag = "4", Content = new byte[] { 0x0, 0x0 }, NextBatchTag = null }, now); // Act - process files for SECOND day await sut.ExecuteAsync(); // Assert Assert.Equal(4, downloadedBatches.Count); Assert.Equal("1", downloadedBatches[0].BatchTag); Assert.Equal("2", downloadedBatches[1].BatchTag); Assert.Equal("3", downloadedBatches[2].BatchTag); Assert.Equal("4", downloadedBatches[3].BatchTag); }
public async void Tests_that_batches_added_between_calls_are_downloaded() { // Assemble: test state var downloadedBatches = new List <IksWriteArgs>(); // Assemble: other object var logger = new IksDownloaderLoggingExtensions(new TestLogger <IksDownloaderLoggingExtensions>()); var now = DateTime.UtcNow; var dtp = new Mock <IUtcDateTimeProvider>(); dtp.Setup(_ => _.Snapshot).Returns(now); var writer = new Mock <IIksWriterCommand>(); writer.Setup(_ => _.Execute(It.IsAny <IksWriteArgs>())) .Callback((IksWriteArgs args) => downloadedBatches.Add(args)); var datePart = dtp.Object.Snapshot.Date.ToString("yyyyMMdd"); // Assemble: configure the receiver to return the first sequence of files var responses = new List <HttpGetIksSuccessResult> { new HttpGetIksSuccessResult { BatchTag = $"{datePart}-1", Content = new byte[] { 0x0, 0x0 }, NextBatchTag = null } }; var receiver = FixedResultHttpGetIksCommand.Create(responses); // Assemble: create the job to be tested var sut = new IksPollingBatchJob(dtp.Object, () => receiver, () => writer.Object, _iksInDbProvider.CreateNew(), new EfgsConfigMock(), logger); // Act await sut.ExecuteAsync(); // Assert Assert.Single(downloadedBatches); // Assemble: add another batch receiver.AddItem(new HttpGetIksSuccessResult { BatchTag = $"{datePart}-2", Content = new byte[] { 0x0, 0x0 }, NextBatchTag = null }); // Act await sut.ExecuteAsync(); // Assert Assert.Equal(2, downloadedBatches.Count); Assert.Equal($"{datePart}-1", downloadedBatches[0].BatchTag); Assert.Equal($"{datePart}-2", downloadedBatches[1].BatchTag); }
public async void Tests_that_entire_sequence_of_batches_are_downloaded() { // Assemble: test state var downloadedBatches = new List <IksWriteArgs>(); // Assemble: other object var logger = new IksDownloaderLoggingExtensions(new TestLogger <IksDownloaderLoggingExtensions>()); var now = DateTime.UtcNow; var dtp = new Mock <IUtcDateTimeProvider>(); dtp.Setup(_ => _.Snapshot).Returns(now); var writer = new Mock <IIksWriterCommand>(); writer.Setup(_ => _.Execute(It.IsAny <IksWriteArgs>())) .Callback((IksWriteArgs args) => downloadedBatches.Add(args)); // Assemble: configure the receiver to return the first sequence of files var responses = new List <HttpGetIksSuccessResult> { new HttpGetIksSuccessResult { BatchTag = "1", Content = new byte[] { 0x0, 0x0 }, NextBatchTag = "2" }, new HttpGetIksSuccessResult { BatchTag = "2", Content = new byte[] { 0x0, 0x0 }, NextBatchTag = "3" }, new HttpGetIksSuccessResult { BatchTag = "3", Content = new byte[] { 0x0, 0x0 }, NextBatchTag = null } }; var receiver = FixedResultHttpGetIksCommand.Create(responses); // Assemble: create the job to be tested IksPollingBatchJob sut = new IksPollingBatchJob(dtp.Object, () => receiver, () => writer.Object, _IksInDbProvider.CreateNew(), new EfgsConfig(), logger); // Act await sut.ExecuteAsync(); // Assert Assert.Equal(3, downloadedBatches.Count); Assert.Equal("1", downloadedBatches[0].BatchTag); Assert.Equal("2", downloadedBatches[1].BatchTag); Assert.Equal("3", downloadedBatches[2].BatchTag); }