public void WhenLocalDirectoryTreeDepthIsEqualToMaxDepthValidationResultIsSuccess()
        {
            // Prepare
            int                        maxDepth      = 4;
            IConfiguration             configuration = MockFactory.ConfigurationWithMaximumDepthOf(maxDepth);
            MaximumTreeDepthValidation validation    = new MaximumTreeDepthValidation(configuration);
            string                     path          = @"C:\first\second\third\fourth";
            IDirectoryInfo             directory     = MockFactory.DirectoryWithPath(path);

            // Exercise
            IValidationResult validationResult = validation.Validate(directory);

            // Verify
            AssertExtension.ValidationResultIsSuccess(validationResult, "Local file with depth equal to max depth triggers an error.");
        }
Example #2
0
        public void WhenLocalFileDepthIsEqualToMaxDepthValidationResultIsSuccess()
        {
            // Prepare
            int                        maxDepth      = 4;
            IConfiguration             configuration = MockFactory.ConfigurationWithMaximumDepthOf(maxDepth);
            MaximumTreeDepthValidation validation    = new MaximumTreeDepthValidation(configuration);
            var                        path          = Path.Combine(@"C:\", "first", "second", "third", "fourth");
            IFileInfo                  file          = MockFactory.FileWithPath(path);

            // Exercise
            IValidationResult validationResult = validation.Validate(file);

            // Verify
            AssertExtension.ValidationResultIsSuccess(validationResult, "Local file with depth equal to max depth triggers an error.");
        }
        public void WhenLocalFileIsDeeperThanMaxDepthValidationResultIsError()
        {
            // Prepare
            int                        maxDepth      = 3;
            IConfiguration             configuration = MockFactory.ConfigurationWithMaximumDepthOf(maxDepth);
            MaximumTreeDepthValidation validation    = new MaximumTreeDepthValidation(configuration);
            string                     tooDeepFile   = @"C:\first\second\third\fourth";
            IFileInfo                  file          = MockFactory.FileWithPath(tooDeepFile);

            // Exercise
            IValidationResult validationResult = validation.Validate(file);

            // Verify
            AssertExtension.ValidationResultIsError(validationResult, "Too deep local file does not trigger an error.");
        }
Example #4
0
        public void WhenDirectoryNameIsTooLongValidationResultIsError()
        {
            // Prepare
            int            maxFilenameLength           = 3;
            IConfiguration configuration               = MockFactory.ConfigurationWithMaximumFilenameLength(maxFilenameLength);
            MaximumFilenameLengthValidation validation = new MaximumFilenameLengthValidation(configuration);
            string         tooLongName = "abcd";
            IDirectoryInfo directory   = MockFactory.DirectoryWithName(tooLongName);

            // Exercise
            IValidationResult validationResult = validation.Validate(directory);

            // Verify
            AssertExtension.ValidationResultIsError(validationResult, "File with too long name does not trigger an error.");
        }
Example #5
0
        public void WhenDirectoryNameLengthIsEqualToMaxLengthValidationResultIsSuccess()
        {
            // Prepare
            int            maxFilenameLength           = 3;
            IConfiguration configuration               = MockFactory.ConfigurationWithMaximumFilenameLength(maxFilenameLength);
            MaximumFilenameLengthValidation validation = new MaximumFilenameLengthValidation(configuration);
            string         dirName   = "abc";
            IDirectoryInfo directory = MockFactory.DirectoryWithName(dirName);

            // Exercise
            IValidationResult validationResult = validation.Validate(directory);

            // Verify
            AssertExtension.ValidationResultIsSuccess(validationResult, "File with name of length equal to max length triggers an error.");
        }
        public void WhenUNCPathRelativePartIsEqualToMaximumPathLengthValidationResultIsSuccess()
        {
            // Prepare
            int            maxPathLength           = 5;
            IConfiguration configuration           = MockFactory.ConfigurationWithMaximumPathLengthOf(maxPathLength);
            MaximumPathLengthValidation validation = new MaximumPathLengthValidation(configuration);
            string    path = "\\\\servername\\share$\\asdf";
            IFileInfo file = MockFactory.FileWithPath(path);

            // Exercise
            IValidationResult validationResult = validation.Validate(file);

            // Verify
            AssertExtension.ValidationResultIsSuccess(validationResult, "File with UNC path relative parth length equal to max path length triggers an error.");
        }
Example #7
0
        public void WhenFilenameLengthIsLessThanMaxLengthValidationResultIsSuccess()
        {
            // Prepare
            int            maxFilenameLength           = 3;
            IConfiguration configuration               = MockFactory.ConfigurationWithMaximumFilenameLength(maxFilenameLength);
            MaximumFilenameLengthValidation validation = new MaximumFilenameLengthValidation(configuration);
            string    filename = "ac";
            IFileInfo file     = MockFactory.FileWithName(filename);

            // Exercise
            IValidationResult validationResult = validation.Validate(file);

            // Verify
            AssertExtension.ValidationResultIsSuccess(validationResult, "File with name of length less than max length triggers an error.");
        }
        public void WhenLocalFilePathIsEqualToMaxPathLengthValidationResultIsSuccess()
        {
            // Prepare
            int            maxPathLength           = 20;
            IConfiguration configuration           = MockFactory.ConfigurationWithMaximumPathLengthOf(maxPathLength);
            MaximumPathLengthValidation validation = new MaximumPathLengthValidation(configuration);
            string    path = "C:/asdfasdf/asdfasdf";
            IFileInfo file = MockFactory.FileWithPath(path);

            // Exercise
            IValidationResult validationResult = validation.Validate(file);

            // Verify
            AssertExtension.ValidationResultIsSuccess(validationResult, "File with path length equal to max path length triggers an error.");
        }
        public void WhenUNCPathIsTooLongValidationResultIsError()
        {
            // Prepare
            int            maxPathLength           = 3;
            IConfiguration configuration           = MockFactory.ConfigurationWithMaximumPathLengthOf(maxPathLength);
            MaximumPathLengthValidation validation = new MaximumPathLengthValidation(configuration);
            string    path = "\\\\servername\\share$\\asdfasdf\\asdfasdf";
            IFileInfo file = MockFactory.FileWithPath(path);

            // Exercise
            IValidationResult validationResult = validation.Validate(file);

            // Verify
            AssertExtension.ValidationResultIsError(validationResult, "File with path length longer than max path length does not trigger an error.");
        }
        public void WhenUNCFileDepthIsEqualToMaxDepthValidationResultIsSuccess()
        {
            // Prepare
            int                        maxDepth      = 4;
            IConfiguration             configuration = MockFactory.ConfigurationWithMaximumDepthOf(maxDepth);
            MaximumTreeDepthValidation validation    = new MaximumTreeDepthValidation(configuration);
            string                     path          = @"\\server\share$\first\second\third\fourth";
            IFileInfo                  file          = MockFactory.FileWithPath(path);

            // Exercise
            IValidationResult validationResult = validation.Validate(file);

            // Verify
            AssertExtension.ValidationResultIsSuccess(validationResult, "UNC file with depth equal to max depth triggers an error.");
        }
        public void WhenLocalDirectoryPathIsTooLongValidationResultIsError()
        {
            // Prepare
            int            maxPathLength           = 20;
            IConfiguration configuration           = MockFactory.ConfigurationWithMaximumPathLengthOf(maxPathLength);
            MaximumPathLengthValidation validation = new MaximumPathLengthValidation(configuration);
            string         tooLongPath             = "C:/asdfasdf/asdfasdf/asdfasdf";
            IDirectoryInfo directory = MockFactory.DirectoryWithPath(tooLongPath);

            // Exercise
            IValidationResult validationResult = validation.Validate(directory);

            // Verify
            AssertExtension.ValidationResultIsError(validationResult, "Directory with too long path does not trigger an error.");
        }
Example #12
0
        public void WhenUNCFileIsDeeperThanMaxDepthValidationResultIsError()
        {
            // Prepare
            int                        maxDepth      = 3;
            IConfiguration             configuration = MockFactory.ConfigurationWithMaximumDepthOf(maxDepth);
            MaximumTreeDepthValidation validation    = new MaximumTreeDepthValidation(configuration);
            var                        tooDeepFile   = Path.Combine(@"\\server", "share$", "first", "second", "third", "fourth");
            IFileInfo                  file          = MockFactory.FileWithPath(tooDeepFile);

            // Exercise
            IValidationResult validationResult = validation.Validate(file);

            // Verify
            AssertExtension.ValidationResultIsError(validationResult, "Too deep local file does not trigger an error.");
        }
        public void WhenFileIsSizeIsLessThanMaxSizeValidationResultIsSuccess()
        {
            // Prepare
            int                       maxFileSize     = 10;
            IConfiguration            configuration   = MockFactory.ConfigurationWithMaximumFileSizeOf(maxFileSize);
            MaximumFileSizeValidation validation      = new MaximumFileSizeValidation(configuration);
            int                       lessThanMaxSize = maxFileSize - 1;
            IFileInfo                 file            = MockFactory.FileWithSizeOf(lessThanMaxSize);

            // Exercise
            IValidationResult validationResult = validation.Validate(file);

            // Verify
            AssertExtension.ValidationResultIsSuccess(validationResult, "A file with size less than maximum file size triggers an error.");
        }
        public void WhenFileIsTooBigValidationResultIsError()
        {
            // Prepare
            int                       maxFileSize   = 10;
            IConfiguration            configuration = MockFactory.ConfigurationWithMaximumFileSizeOf(maxFileSize);
            MaximumFileSizeValidation validation    = new MaximumFileSizeValidation(configuration);
            int                       tooBigSize    = maxFileSize + 1;
            IFileInfo                 tooBigFile    = MockFactory.FileWithSizeOf(tooBigSize);

            // Exercise
            IValidationResult validationResult = validation.Validate(tooBigFile);

            // Verify
            AssertExtension.ValidationResultIsError(validationResult, "A file bigger than maximum file size does not trigger an error.");
        }
        public void WhenDirectoryNameIsValidValidationResultIsSuccess()
        {
            // Prepare
            string        invalidFilename  = "invalid_filename";
            List <string> invalidFilenames = new List <string>
            {
                invalidFilename
            };
            IConfiguration            configuration = MockFactory.ConfigurationWithInvalidFilenames(invalidFilenames);
            InvalidFilenameValidation validation    = new InvalidFilenameValidation(configuration);
            IDirectoryInfo            file          = MockFactory.DirectoryWithName("valid_name");

            // Exercise
            IValidationResult validationResult = validation.Validate(file);

            // Verify
            Assert.StrictEqual <Result>(Result.Success, validationResult.Result);
        }
        public void WhenFileFilenameIsInvalidValidationResultIsError()
        {
            // Prepare
            string        invalidFilename  = "invalid_filename";
            List <string> invalidFilenames = new List <string>
            {
                invalidFilename
            };
            IConfiguration            configuration = MockFactory.ConfigurationWithInvalidFilenames(invalidFilenames);
            InvalidFilenameValidation validation    = new InvalidFilenameValidation(configuration);
            IFileInfo file = MockFactory.FileWithName(invalidFilename);

            // Exercise
            IValidationResult validationResult = validation.Validate(file);

            // Verify
            Assert.StrictEqual <Result>(Result.Fail, validationResult.Result);
        }
        public void EnumerationTotals()
        {
            var           nsEnumerator              = new NamespaceEnumerator();
            int           depth                     = 3;
            int           numberOfSubdirs           = 5;
            int           numberOfFilesPerDirectory = 3;
            int           totalBytes                = 1024 * 1024;
            NamespaceInfo nsInfo                    = nsEnumerator.Run(MockFactory.DirectoryWithGivenParameters(
                                                                           root: "c:",
                                                                           depth: depth,
                                                                           numberOfDirectories: numberOfSubdirs,
                                                                           numberOfFilesPerDirectory: numberOfFilesPerDirectory,
                                                                           totalSize: totalBytes));

            Assert.True(nsInfo != null, "namespace information was returned");
            Assert.True(nsInfo.IsComplete, "namespace scan is complete");

            int totalDirs  = ((int)Math.Pow(numberOfSubdirs, depth + 1) - 1) / (numberOfSubdirs - 1);
            int totalFiles = totalDirs * numberOfFilesPerDirectory;

            Assert.True(nsInfo.NumberOfDirectories == totalDirs, "number of directories is as expected");
            Assert.True(nsInfo.NumberOfFiles == totalFiles, "number of files is as expected");
            Assert.True(nsInfo.TotalFileSizeInBytes == totalBytes, "size is as expected");
        }