Beispiel #1
0
        public void Should_AddError_When_SourceDirectoryDoesNotExist()
        {
            var path             = Path.GetTempPath();
            var doesNotExistPath = Path.Combine(path, System.Guid.NewGuid().ToString());

            var validator = new SmoothValidator("year", doesNotExistPath, doesNotExistPath);
            var result    = validator.Validate();

            Assert.True(result.HasErrors);
            Assert.NotNull(result.Errors.FirstOrDefault(x => x.Contains("Source Directory")));
        }
Beispiel #2
0
        public void Should_NotError_When_SourceAndDestinationDirectoryExist()
        {
            var destinationDirectory = Path.GetTempPath();
            var sourceDirectory      = Path.Combine(Path.GetTempPath(), System.Guid.NewGuid().ToString());

            Directory.CreateDirectory(sourceDirectory);
            var validator = new SmoothValidator("year", sourceDirectory, destinationDirectory);
            var result    = validator.Validate();

            Assert.Equal(false, result.HasErrors);
        }
Beispiel #3
0
        public void Should_Error_When_DesitinationDirectoryUnderSource()
        {
            var sourceDirectory      = Path.GetTempPath();
            var destinationDirectory = Path.Combine(Path.GetTempPath(), System.Guid.NewGuid().ToString());

            Directory.CreateDirectory(destinationDirectory);
            var validator = new SmoothValidator("year", sourceDirectory, destinationDirectory);
            var result    = validator.Validate();

            Assert.Equal(true, result.HasErrors);
            Assert.NotNull(result.Errors.FirstOrDefault(x => x.Contains("Destination Directory is not allowed to be a subdirectory")));
            Directory.Delete(destinationDirectory);
        }
Beispiel #4
0
        public IValidationResult Run()
        {
            var strategy        = _app.Arguments.FirstOrDefault(x => x.Name == "sort");
            var sourceDirectory = _app.Arguments.FirstOrDefault(x => x.Name == "source");
            var rootDirectory   = _app.Arguments.FirstOrDefault(x => x.Name == "destination");

            var validator = new SmoothValidator(strategy.Value, sourceDirectory.Value, rootDirectory.Value);
            var result    = validator.Validate();

            if (!result.HasErrors)
            {
                var sorter = new Sorter(sourceDirectory.Value, rootDirectory.Value);
                sorter.RaiseFileSortEvent += HandleSortEvent;
                _watch.Start();
                sorter.Sort();
                _watch.Stop();
                string.Format("Total Time For Sorting {0} seconds", _watch.Elapsed.Seconds).Log(ConsoleColor.Yellow);
            }

            return(result);
        }