Пример #1
0
        public void ShouldDetermineZipFileCanBeCreated()
        {
            // setup
            var folderTozipPath = Support.Fixture.FirstFolderToZipPath;
            var destinationPath = Support.Fixture.OutputFolder;

            // run
            var SUT       = new ZipValidator(folderTozipPath, destinationPath);
            var canCreate = SUT.ZipFileCanBeCreated();

            // assert
            Assert.That(canCreate, Is.True);
        }
Пример #2
0
        public void ShouldGetExpectedZipFilePath()
        {
            // setup
            var folderTozipPath = Support.Fixture.FirstFolderToZipPath;
            var destinationPath = Support.Fixture.OutputFolder;

            var expectedZipFilePath = Support.FileSystem.GetZipFilePathFrom(folderTozipPath, destinationPath);

            // run
            var SUT = new ZipValidator(folderTozipPath, destinationPath);
            var actualZipFilePath = SUT.GetZipFilePath();

            // assert
            Assert.That(actualZipFilePath, Is.EqualTo(expectedZipFilePath));
        }
Пример #3
0
        public static IValidator CreateValidator(ValidationRequest request)
        {
            IValidator validator;

            switch (Path.GetExtension(request.FileName).ToLower())
            {
            case ".zip":
                validator = new ZipValidator(request);
                break;

            case ".pdf":
                validator = new PdfValidator(request);
                break;

            case ".xml":
                validator = new XmlValidator(request);
                break;

            case ".doc":
            case ".docx":
                validator = new WordValidator(request);
                break;

            case ".json":
                validator = new JsonValidator(request);
                break;

            case ".txt":
                validator = new TextValidator(request);
                break;

            case ".csv":
                validator = new CsvValidator(request);
                break;

            case ".html":
            case ".htm":
                validator = new HtmlValidator(request);
                break;

            default:
                validator = new UnknownValidator(request);
                break;
            }

            return(validator);
        }
Пример #4
0
        public void ShouldDetermineZipFileCanNotBeCreated_SinceItAlreadyExists()
        {
            // setup
            var folderTozipPath = Support.Fixture.FirstFolderToZipPath;
            var destinationPath = Support.Fixture.OutputFolder;

            var zipFilePath = Path.Combine(destinationPath, $"{new DirectoryInfo(folderTozipPath).Name}.zip");

            Support.FileSystem.CreateZipOutput(zipFilePath);

            // run
            var SUT       = new ZipValidator(folderTozipPath, destinationPath);
            var canCreate = SUT.ZipFileCanBeCreated();

            // assert
            Assert.That(canCreate, Is.False);
        }
Пример #5
0
        private bool ZipSubFolder(string subFolderPath, string destinationPath, CancellationToken token)
        {
            if (!Directory.Exists(subFolderPath))
            {
                return(false);
            }

            var zipValidator = new ZipValidator(subFolderPath, destinationPath);
            var zipPath      = zipValidator.GetZipFilePath();

            if (!zipValidator.ZipFileCanBeCreated())
            {
                return(false);
            }

            new Zipper(subFolderPath, zipPath).ZipFolder(token);
            return(true);
        }