Esempio n. 1
0
        public void AttemptToLoadDataWithFilesInForLoading_AgreementBetweenForLoadingAndCache()
        {
            var tempDirPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            var tempDir     = Directory.CreateDirectory(tempDirPath);

            try
            {
                // File in cache is the same file as in ForLoading (20160101.zip)
                var loadDirectory  = LoadDirectory.CreateDirectoryStructure(tempDir, "CachedFileRetriever");
                var cachedFilePath = Path.Combine(loadDirectory.Cache.FullName, "2016-01-01.zip");
                File.WriteAllText(cachedFilePath, "");
                File.WriteAllText(Path.Combine(loadDirectory.ForLoading.FullName, "2016-01-01.zip"), "");


                // Set up retriever
                var cacheLayout = new ZipCacheLayoutOnePerDay(loadDirectory.Cache, new NoSubdirectoriesCachePathResolver());

                var retriever = new TestCachedFileRetriever()
                {
                    ExtractFilesFromArchive = false,
                    LoadProgress            = _lpMock,
                    Layout = cacheLayout
                };

                // Set up job
                var job = CreateTestJob(loadDirectory);
                job.DatesToRetrieve = new List <DateTime>
                {
                    new DateTime(2016, 01, 01)
                };

                // Should complete successfully, the file in ForLoading matches the job specification
                retriever.Fetch(job, new GracefulCancellationToken());

                // And ForLoading should still have the file in it (i.e. it hasn't mysteriously disappeared)
                Assert.IsTrue(File.Exists(Path.Combine(loadDirectory.ForLoading.FullName, "2016-01-01.zip")));
            }
            finally
            {
                tempDir.Delete(true);
            }
        }
Esempio n. 2
0
        public void AttemptToLoadDataWithoutFilesInForLoading()
        {
            var tempDirPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            var tempDir     = Directory.CreateDirectory(tempDirPath);

            try
            {
                // File in cache only, no files in ForLoading
                var loadDirectory  = LoadDirectory.CreateDirectoryStructure(tempDir, "CachedFileRetriever");
                var cachedFilePath = Path.Combine(loadDirectory.Cache.FullName, "2016-01-01.zip");
                File.WriteAllText(cachedFilePath, "");


                // Set up retriever
                var cacheLayout = new ZipCacheLayoutOnePerDay(loadDirectory.Cache, new NoSubdirectoriesCachePathResolver());

                var retriever = new TestCachedFileRetriever()
                {
                    ExtractFilesFromArchive = false,
                    LoadProgress            = _lpMock,
                    Layout = cacheLayout
                };

                // Set up job
                var job = CreateTestJob(loadDirectory);
                job.DatesToRetrieve = new List <DateTime>
                {
                    new DateTime(2016, 01, 01)
                };

                // Should complete successfully, there are no files in ForLoading to worry about
                retriever.Fetch(job, new GracefulCancellationToken());

                // And the retriever should have copied the cached archive file into ForLoading
                Assert.IsTrue(File.Exists(Path.Combine(loadDirectory.ForLoading.FullName, "2016-01-01.zip")));
            }
            finally
            {
                tempDir.Delete(true);
            }
        }
Esempio n. 3
0
        public void AttemptToLoadDataWithFilesInForLoading_DisagreementBetweenCacheAndForLoading()
        {
            var tempDirPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            var tempDir     = Directory.CreateDirectory(tempDirPath);

            try
            {
                // Different file in ForLoading than exists in cache
                var loadDirectory  = LoadDirectory.CreateDirectoryStructure(tempDir, "CachedFileRetriever");
                var cachedFilePath = Path.Combine(loadDirectory.Cache.FullName, "2016-01-02.zip");
                File.WriteAllText(cachedFilePath, "");
                File.WriteAllText(Path.Combine(loadDirectory.ForLoading.FullName, "2016-01-01.zip"), "");

                // Set up retriever
                var cacheLayout = new ZipCacheLayoutOnePerDay(loadDirectory.Cache, new NoSubdirectoriesCachePathResolver());

                var retriever = new TestCachedFileRetriever()
                {
                    ExtractFilesFromArchive = false,
                    LoadProgress            = _lpMock,
                    Layout = cacheLayout
                };

                // Set up job
                var job = CreateTestJob(loadDirectory);
                job.DatesToRetrieve = new List <DateTime>
                {
                    new DateTime(2016, 01, 02)
                };

                // Should fail after determining that the files in ForLoading do not match the job specification
                var ex = Assert.Throws <InvalidOperationException>(() => retriever.Fetch(job, new GracefulCancellationToken()));
                Assert.IsTrue(ex.Message.StartsWith("The files in ForLoading do not match what this job expects to be loading from the cache."), ex.Message + Environment.NewLine + Environment.NewLine + ex.StackTrace);
            }
            finally
            {
                tempDir.Delete(true);
            }
        }