Esempio n. 1
0
        public void CreateArchiveWithNoFiles_ShouldThrow()
        {
            var directoryHelper = new TestDirectoryHelper(GetType());

            directoryHelper.SetUp();

            var testDir = directoryHelper.Directory.CreateSubdirectory("CreateArchiveWithNoFiles_ShouldThrow");

            var archiveFiles  = new ArchiveFiles(new HICLoadConfigurationFlags());
            var loadDirectory = LoadDirectory.CreateDirectoryStructure(testDir, "dataset");

            var job = Mock.Of <IDataLoadJob>(j => j.DataLoadInfo == Mock.Of <IDataLoadInfo>());

            job.LoadDirectory = loadDirectory;

            try
            {
                archiveFiles.Run(job, new GracefulCancellationToken());

                foreach (FileInfo fileInfo in loadDirectory.ForArchiving.GetFiles("*.zip"))
                {
                    Console.WriteLine("About to throw SetUp because of zip file:" + fileInfo.FullName);
                }

                Assert.IsFalse(loadDirectory.ForArchiving.GetFiles("*.zip").Any(), "There should not be any zip files in the archive directory!");
            }
            finally
            {
                directoryHelper.TearDown();
            }
        }
Esempio n. 2
0
        public void TestAllFilesAreArchived()
        {
            var directoryHelper = new TestDirectoryHelper(GetType());

            directoryHelper.SetUp();

            var forArchiving = directoryHelper.Directory.CreateSubdirectory("forArchiving");
            var forLoading   = directoryHelper.Directory.CreateSubdirectory("forLoading");

            File.WriteAllText(Path.Combine(forLoading.FullName, "test.txt"), "test data");
            var subDir = forLoading.CreateSubdirectory("subdir");

            File.WriteAllText(Path.Combine(subDir.FullName, "subdir.txt"), "test data in subdir");

            // test the hidden dir which the archiver should ignore
            var hiddenDir = forLoading.CreateSubdirectory(ArchiveFiles.HiddenFromArchiver);

            File.WriteAllText(Path.Combine(hiddenDir.FullName, "hidden.txt"), "I should not appear in the archive");

            var archiveComponent = new ArchiveFiles(new HICLoadConfigurationFlags());

            var dataLoadInfo = Mock.Of <IDataLoadInfo>(info => info.ID == 1);

            var LoadDirectory = Mock.Of <ILoadDirectory>(d => d.ForArchiving == forArchiving && d.ForLoading == forLoading);

            var job = Mock.Of <IDataLoadJob>(j => j.DataLoadInfo == dataLoadInfo);

            job.LoadDirectory = LoadDirectory;

            try
            {
                archiveComponent.Run(job, new GracefulCancellationToken());

                // first we expect a file in forArchiving called 1.zip
                var zipFilename = Path.Combine(forArchiving.FullName, "1.zip");
                Assert.True(File.Exists(zipFilename));

                // there should be two entries
                using (var archive = ZipFile.Open(zipFilename, ZipArchiveMode.Read))
                {
                    Assert.AreEqual(2, archive.Entries.Count, "There should be two entries in this archive: one from the root and one from the subdirectory");
                    Assert.IsTrue(archive.Entries.Any(entry => entry.FullName.Equals(@"subdir/subdir.txt")));
                    Assert.IsTrue(archive.Entries.Any(entry => entry.FullName.Equals(@"test.txt")));
                }
            }
            finally
            {
                directoryHelper.TearDown();
            }
        }
Esempio n. 3
0
        protected override void OneTimeSetUp()
        {
            base.OneTimeSetUp();

            try
            {
                _directoryHelper = new TestDirectoryHelper(GetType());

                _directoryHelper.SetUp();

                Random random = new Random();

                //delete all catalogues with duplicate names
                Catalogue[] catalogues = CatalogueRepository.GetAllObjects <Catalogue>().ToArray();

                foreach (var cata in catalogues)
                {
                    if (catalogues.Count(c => c.Name.Equals(cata.Name)) > 1)
                    {
                        Console.WriteLine("Deleteing Catalogue Called " + cata.Name + " (because there are multiple Catalogues with this name) in database at end of ConnectionString:" + CatalogueRepository.ConnectionString);
                        cata.DeleteInDatabase();
                    }
                }

                //make sure all Catalogues have acroynms, if they dont then assign them a super random one
                foreach (Catalogue cata in CatalogueRepository.GetAllObjects <Catalogue>())
                {
                    if (string.IsNullOrWhiteSpace(cata.Acronym))
                    {
                        cata.Acronym = "RANDOMACRONYM_" + random.Next(10000);
                        cata.SaveToDatabase();
                    }
                }
            }
            catch (Exception e)
            {
                _setupException = e;
            }
        }