Beispiel #1
0
        public void Extracter_Extract_Default()
        {
            var format = new FormatObject("test", DateTime.Now, TimeZoneInfo.Utc);

            var source = new Mock <ISourceSpecification>();

            source.Setup(x => x.GetUpperBoundExclusive(It.IsAny <FormatObject>())).Returns <FormatObject>(y => y.DateTime.AddDays(1));

            var downloader = new Mock <IDownloader>();

            downloader.Setup(x => x.TryDownload(default(FormatObject))).Returns(default(TryDownloadResult));
            downloader.SetupAllProperties();

            var formatIterator = new Mock <IFormatIterator>();

            formatIterator.Setup(x => x.GetNextCandidates(It.IsAny <FormatObject>()))
            .Returns <FormatObject>(y =>
            {
                if (y.DateTime == default(FormatObject).DateTime)
                {
                    return(new[] { format });
                }
                else
                {
                    var ret = y;
                    ret.DateTime.AddDays(1);
                    return(new[] { ret });
                }
            });

            var downloadAggregator = new DownloadAggregator()
            {
                NumberOfFilesToAggregate = 2,
                Source         = source.Object,
                Downloader     = downloader.Object,
                FormatIterator = formatIterator.Object
            };

            downloadAggregator.Initialize();

            var target = new Extracter()
            {
                Source = source.Object,
                TempDownloadLocation = TempLocation,
                Aggregator           = downloadAggregator
            };

            var expected = new FileNameExtractionResult[] { };

            var actual = target.Extract(default(FormatObject));

            AreEqual(expected, actual.Cast <FileNameExtractionResult>());

            formatIterator.Verify(x => x.GetNextCandidates(default(FormatObject)), Times.Exactly(1));
            downloader.Verify(x => x.TryDownload(format), Times.Exactly(1));
        }
        public void DownloadAggregator_DownloadFirst_Two_Incomplete()
        {
            var numDaysToAggregate = 2;

            var format = new FormatObject(
                sourceName: "test",
                dateTime: new DateTimeOffset(new DateTime(2001, 1, 1), TimeSpan.FromHours(0)),
                localTimeZone: TimeZoneInfo.Utc);

            var file = new FileInfo(@"d:\temp\test1.test");


            var downloader = new Mock <IDownloader>();

            downloader.Setup(x => x.TryDownload(format)).Returns(new TryDownloadResult()
            {
                DestinationFile = file,
                IsSuccess       = true
            });


            var formatIterator = new Mock <IFormatIterator>();

            formatIterator.Setup(x => x.GetNextCandidates(default(FormatObject))).Returns(new[] { format });

            var source = new Mock <ISourceSpecification>();

            source.SetupGet(x => x.NumberOfFilesToAggregate).Returns(numDaysToAggregate);

            var target = new DownloadAggregator()
            {
                NumberOfFilesToAggregate = numDaysToAggregate,
                Source         = source.Object,
                Downloader     = downloader.Object,
                FormatIterator = formatIterator.Object
            };

            target.Initialize();

            var expected = new DownloadAggregatorResult()
            {
                CurrentPosition = format,
            };

            var actual = target.DownloadFirst(format);

            AreEqual(expected, actual);
            Assert.AreEqual(1, target.CurrentAggregatedFiles.Count());
            Assert.IsTrue(target.CurrentAggregatedFiles.SequenceEqual(new[] { Tuple.Create(format, file) }));
            downloader.Verify(x => x.TryDownload(format), Times.Once());
        }
        public void DownloadAggregator_DownloadNext_DownloadFailure()
        {
            var numDaysToAggregate = 1;

            var format1 = new FormatObject(
                sourceName: "test",
                dateTime: new DateTimeOffset(new DateTime(2001, 1, 1), TimeSpan.FromHours(0)),
                localTimeZone: TimeZoneInfo.Utc);

            var format2 = new FormatObject(
                sourceName: "test",
                dateTime: new DateTimeOffset(new DateTime(2001, 1, 2), TimeSpan.FromHours(0)),
                localTimeZone: TimeZoneInfo.Utc);

            var downloader = new Mock <IDownloader>();

            downloader.Setup(x => x.TryDownload(It.IsAny <FormatObject>())).Returns(new TryDownloadResult()
            {
                IsSuccess = false
            });

            var formatIterator = new Mock <IFormatIterator>();

            formatIterator.Setup(x => x.GetNextCandidates(It.Is <FormatObject>(y => y.DateTime == format1.DateTime))).Returns(new [] { format2 });

            var source = new Mock <ISourceSpecification>();

            source.SetupGet(x => x.NumberOfFilesToAggregate).Returns(numDaysToAggregate);

            var target = new DownloadAggregator()
            {
                NumberOfFilesToAggregate = numDaysToAggregate,
                Source         = source.Object,
                Downloader     = downloader.Object,
                FormatIterator = formatIterator.Object
            };

            target.Initialize();

            var expected = new DownloadAggregatorResult()
            {
                CurrentPosition = format2,
            };

            var actual = target.DownloadNext(format1);

            Assert.AreEqual(expected, actual);
            Assert.AreEqual(0, target.CurrentAggregatedFiles.Count());
            formatIterator.Verify(x => x.GetNextCandidates(format1), Times.Once());
            downloader.Verify(x => x.TryDownload(format2), Times.Once());
        }
        public void DownloadAggregator_DownloadFirst_One()
        {
            var numDaysToAggregate = 1;

            var format = new FormatObject(
                sourceName: "test",
                dateTime: new DateTimeOffset(new DateTime(2001, 1, 1), TimeSpan.FromHours(0)),
                localTimeZone: TimeZoneInfo.Utc);

            var file = new FileInfo(@"d:\temp\test1.test");

            var downloader = new Mock <IDownloader>();

            downloader.Setup(x => x.TryDownload(format)).Returns(new TryDownloadResult()
            {
                DestinationFile = file,
                IsSuccess       = true
            });


            var formatIterator = new Mock <IFormatIterator>();

            var source = new Mock <ISourceSpecification>();

            var target = new DownloadAggregator()
            {
                NumberOfFilesToAggregate = numDaysToAggregate,
                Source         = source.Object,
                Downloader     = downloader.Object,
                FormatIterator = formatIterator.Object
            };

            target.Initialize();

            var expected = new DownloadAggregatorResult()
            {
                IsSuccess        = true,
                CurrentPosition  = format,
                DestinationFiles = new[] { file },
            };

            var actual = target.DownloadFirst(format);

            AreEqual(expected, actual);
            Assert.AreEqual(0, target.CurrentAggregatedFiles.Count());
            downloader.Verify(x => x.TryDownload(format), Times.Once());
        }
        public void DownloadAggregator_DownloadFirst_Default()
        {
            var downloader     = new Mock <IDownloader>();
            var formatIterator = new Mock <IFormatIterator>();
            var source         = new Mock <ISourceSpecification>();

            var target = new DownloadAggregator()
            {
                Source         = source.Object,
                Downloader     = downloader.Object,
                FormatIterator = formatIterator.Object
            };

            var expected = default(DownloadAggregatorResult);

            var actual = target.DownloadFirst(default(FormatObject));

            Assert.AreEqual(expected, actual);
            Assert.AreEqual(0, target.CurrentAggregatedFiles.Count());
        }
        public void DownloadAggregator_DownloadFirst_DownloadFailure()
        {
            var numDaysToAggregate = 1;

            var format = new FormatObject(
                sourceName: "test",
                dateTime: new DateTimeOffset(new DateTime(2001, 1, 1), TimeSpan.FromHours(0)),
                localTimeZone: TimeZoneInfo.Utc);

            var downloader     = new Mock <IDownloader>();
            var formatIterator = new Mock <IFormatIterator>();

            var source = new Mock <ISourceSpecification>();

            source.SetupGet(x => x.NumberOfFilesToAggregate).Returns(numDaysToAggregate);

            var target = new DownloadAggregator()
            {
                NumberOfFilesToAggregate = numDaysToAggregate,
                Source         = source.Object,
                Downloader     = downloader.Object,
                FormatIterator = formatIterator.Object
            };

            target.Initialize();

            var expected = new DownloadAggregatorResult()
            {
                CurrentPosition = format,
            };

            var actual = target.DownloadFirst(format);

            Assert.AreEqual(expected, actual);
            Assert.AreEqual(0, target.CurrentAggregatedFiles.Count());
            downloader.Verify(x => x.TryDownload(format), Times.Once());
        }
Beispiel #7
0
        public void Extracter_Extract_OnlyStopsWhenCurrentDateNotOnDownloadFail()
        {
            var source = new Mock <ISourceSpecification>();

            source.Setup(x => x.GetUpperBoundExclusive(It.IsAny <FormatObject>())).Returns <FormatObject>((x) => x.DateTime.AddDays(1));

            var formatObject1 = new FormatObject("test", DateTime.Now.AddDays(-2), TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time"));
            var formatObject2 = new FormatObject("test", DateTime.Now.AddDays(-1), TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time"));
            var formatObject3 = new FormatObject("test", DateTime.Now.AddDays(0), TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time"));
            var formatObject4 = new FormatObject("test", DateTime.Now.AddDays(1), TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time"));

            var downloader = new Mock <IDownloader>();

            downloader.Setup(x => x.TryDownload(default(FormatObject))).Returns(
                new TryDownloadResult()
            {
                IsSuccess       = false,
                DestinationFile = new FileInfo(@"d:\test.test"),
            });

            downloader.Setup(x => x.TryDownload(It.Is <FormatObject>(y => y.DateTime == formatObject1.DateTime))).Returns(
                new TryDownloadResult()
            {
                IsSuccess       = false,
                DestinationFile = new FileInfo(@"d:\test.test"),
            });

            downloader.Setup(x => x.TryDownload(It.Is <FormatObject>(y => y.DateTime == formatObject2.DateTime))).Returns(
                new TryDownloadResult()
            {
                IsSuccess       = false,
                DestinationFile = new FileInfo(@"d:\test.test"),
            });

            downloader.Setup(x => x.TryDownload(It.Is <FormatObject>(y => y.DateTime == formatObject3.DateTime))).Returns(
                new TryDownloadResult()
            {
                IsSuccess       = false,
                DestinationFile = new FileInfo(@"d:\test.test"),
            });

            downloader.Setup(x => x.TryDownload(It.Is <FormatObject>(y => y.DateTime == formatObject4.DateTime))).Returns(
                new TryDownloadResult()
            {
                IsSuccess       = false,
                DestinationFile = new FileInfo(@"d:\test.test"),
            });

            var formatIterator = new Mock <IFormatIterator>();

            formatIterator.Setup(x => x.GetNextCandidates(default(FormatObject))).Returns(new[] { formatObject1 });
            formatIterator.Setup(x => x.GetNextCandidates(It.Is <FormatObject>(y => y.DateTime == formatObject1.DateTime))).Returns(new[] { formatObject2 });
            formatIterator.Setup(x => x.GetNextCandidates(It.Is <FormatObject>(y => y.DateTime == formatObject2.DateTime))).Returns(new[] { formatObject3 });
            formatIterator.Setup(x => x.GetNextCandidates(It.Is <FormatObject>(y => y.DateTime == formatObject3.DateTime))).Returns(new[] { formatObject4 });

            var downloadAggregator = new DownloadAggregator()
            {
                NumberOfFilesToAggregate = 2,
                Source         = source.Object,
                Downloader     = downloader.Object,
                FormatIterator = formatIterator.Object
            };

            downloadAggregator.Initialize();

            var target = new Extracter()
            {
                Source = source.Object,
                TempDownloadLocation = TempLocation,
                Aggregator           = downloadAggregator
            };

            var expected = new FileNameExtractionResult[] { };

            var actual = target.Extract(default(FormatObject));

            AreEqual(expected, actual.Cast <FileNameExtractionResult>());

            downloader.Verify(x => x.TryDownload(default(FormatObject)), Times.Exactly(0));
            downloader.Verify(x => x.TryDownload(formatObject1), Times.Exactly(1));
            downloader.Verify(x => x.TryDownload(formatObject2), Times.Exactly(1));
            downloader.Verify(x => x.TryDownload(formatObject3), Times.Exactly(1));
            downloader.Verify(x => x.TryDownload(formatObject4), Times.Exactly(0));
        }
        public void DownloadAggregator_Sequence()
        {
            var numDaysToAggregate = 2;

            var firstDate = new DateTimeOffset(new DateTime(2001, 1, 1), TimeSpan.FromHours(0));

            var format1 = new FormatObject("test", DateTime.Now.AddDays(-2), TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time"));
            var format2 = new FormatObject("test", DateTime.Now.AddDays(-1), TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time"));
            var format3 = new FormatObject("test", DateTime.Now.AddDays(0), TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time"));
            var format4 = new FormatObject("test", DateTime.Now.AddDays(1), TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time"));

            var source = new Mock <ISourceSpecification>();

            source.Setup(x => x.GetUpperBoundExclusive(It.IsAny <FormatObject>())).Returns <FormatObject>(y => y.DateTime.AddDays(1));
            source.SetupGet(x => x.FirstDateTimeOffset).Returns(firstDate);
            source.Setup(x => x.GetPossibleFormatObjects(firstDate)).Returns(new[] { format1 });

            var formatIterator = new Mock <IFormatIterator>();

            formatIterator.Setup(x => x.GetNextCandidates(It.Is <FormatObject>(y => y.DateTime == format1.DateTime))).Returns(new[] { format2 });
            formatIterator.Setup(x => x.GetNextCandidates(It.Is <FormatObject>(y => y.DateTime == format2.DateTime))).Returns(new[] { format3 });
            formatIterator.Setup(x => x.GetNextCandidates(It.Is <FormatObject>(y => y.DateTime == format3.DateTime))).Returns(new[] { format4 });

            var file1 = new FileInfo(@"d:\temp\test1.test");
            var file2 = new FileInfo(@"d:\temp\test2.test");
            var file3 = new FileInfo(@"d:\temp\test3.test");
            var file4 = new FileInfo(@"d:\temp\test4.test");

            var downloader = new Mock <IDownloader>();

            downloader.Setup(x => x.TryDownload(It.Is <FormatObject>(y => y.DateTime == format1.DateTime))).Returns(
                new TryDownloadResult()
            {
                IsSuccess       = true,
                DestinationFile = file1,
            });

            downloader.Setup(x => x.TryDownload(It.Is <FormatObject>(y => y.DateTime == format2.DateTime))).Returns(
                new TryDownloadResult()
            {
                IsSuccess       = true,
                DestinationFile = file2,
            });

            downloader.Setup(x => x.TryDownload(It.Is <FormatObject>(y => y.DateTime == format3.DateTime))).Returns(
                new TryDownloadResult()
            {
                IsSuccess       = true,
                DestinationFile = file3,
            });

            downloader.Setup(x => x.TryDownload(It.Is <FormatObject>(y => y.DateTime == format4.DateTime))).Returns(
                new TryDownloadResult()
            {
                IsSuccess       = true,
                DestinationFile = file4,
            });


            var target = new DownloadAggregator()
            {
                NumberOfFilesToAggregate = numDaysToAggregate,
                Source         = source.Object,
                Downloader     = downloader.Object,
                FormatIterator = formatIterator.Object
            };

            target.Initialize();

            var expected = new DownloadAggregatorResult()
            {
                IsSuccess        = true,
                CurrentPosition  = format3,
                DestinationFiles = new[] { file2, file3 },
            };

            var actual = target.DownloadNext(target.DownloadNext(target.DownloadFirst(format1).CurrentPosition).CurrentPosition);

            AreEqual(expected, actual);
            Assert.AreEqual(1, target.CurrentAggregatedFiles.Count());
            Assert.IsTrue(target.CurrentAggregatedFiles.SequenceEqual(new[] { Tuple.Create(format3, file3) }));
            downloader.Verify(x => x.TryDownload(default(FormatObject)), Times.Exactly(0));
            downloader.Verify(x => x.TryDownload(format1), Times.Exactly(1));
            downloader.Verify(x => x.TryDownload(format2), Times.Exactly(1));
            downloader.Verify(x => x.TryDownload(format3), Times.Exactly(1));
            downloader.Verify(x => x.TryDownload(format4), Times.Exactly(0));
        }
        public void DownloadAggregator_DownloadNext_Two_IgnoresSameFile()
        {
            var numDaysToAggregate = 2;

            var format1 = new FormatObject(
                sourceName: "test",
                dateTime: new DateTimeOffset(new DateTime(2001, 1, 1), TimeSpan.FromHours(0)),
                localTimeZone: TimeZoneInfo.Utc);

            var format2 = new FormatObject(
                sourceName: "test",
                dateTime: new DateTimeOffset(new DateTime(2001, 1, 2), TimeSpan.FromHours(0)),
                localTimeZone: TimeZoneInfo.Utc);

            var format3 = new FormatObject(
                sourceName: "test",
                dateTime: new DateTimeOffset(new DateTime(2001, 1, 3), TimeSpan.FromHours(0)),
                localTimeZone: TimeZoneInfo.Utc);

            var file1 = new FileInfo(@"d:\temp\test1.test");
            var file2 = new FileInfo(@"d:\temp\test2.test");

            var downloader = new Mock <IDownloader>();

            downloader.Setup(x => x.TryDownload(It.Is <FormatObject>(y => y.DateTime == format1.DateTime))).Returns(new TryDownloadResult()
            {
                DestinationFile = file1,
                IsSuccess       = true
            });
            downloader.Setup(x => x.TryDownload(It.Is <FormatObject>(y => y.DateTime == format2.DateTime))).Returns(new TryDownloadResult()
            {
                DestinationFile = file1,
                IsSuccess       = true
            });
            downloader.Setup(x => x.TryDownload(It.Is <FormatObject>(y => y.DateTime == format3.DateTime))).Returns(new TryDownloadResult()
            {
                DestinationFile = file2,
                IsSuccess       = true
            });


            var formatIterator = new Mock <IFormatIterator>();

            formatIterator.Setup(x => x.GetNextCandidates(default(FormatObject))).Returns(new[] { format1 });
            formatIterator.Setup(x => x.GetNextCandidates(It.Is <FormatObject>(y => y.DateTime == format1.DateTime))).Returns(new[] { format2 });
            formatIterator.Setup(x => x.GetNextCandidates(It.Is <FormatObject>(y => y.DateTime == format2.DateTime))).Returns(new[] { format3 });

            var source = new Mock <ISourceSpecification>();

            var target = new DownloadAggregator()
            {
                NumberOfFilesToAggregate = numDaysToAggregate,
                Source         = source.Object,
                Downloader     = downloader.Object,
                FormatIterator = formatIterator.Object
            };

            target.Initialize();

            var expected = new DownloadAggregatorResult()
            {
                IsSuccess        = true,
                CurrentPosition  = format3,
                DestinationFiles = new[] { file1, file2 },
            };

            var actual = target.DownloadNext(target.DownloadNext(target.DownloadNext(default(FormatObject)).CurrentPosition).CurrentPosition);

            AreEqual(expected, actual);
            Assert.AreEqual(1, target.CurrentAggregatedFiles.Count());
            Assert.IsTrue(target.CurrentAggregatedFiles.SequenceEqual(new[] { Tuple.Create(format3, file2) }));
            formatIterator.Verify(x => x.GetNextCandidates(default(FormatObject)), Times.Exactly(1));
            formatIterator.Verify(x => x.GetNextCandidates(format1), Times.Exactly(1));
            formatIterator.Verify(x => x.GetNextCandidates(format2), Times.Exactly(1));
            downloader.Verify(x => x.TryDownload(format1), Times.Once());
            downloader.Verify(x => x.TryDownload(format2), Times.Once());
            downloader.Verify(x => x.TryDownload(format3), Times.Once());
        }