コード例 #1
0
        public void IsValidDirectoryPath_NullInput_ThrowsNullArgumentException()
        {
            // Arrange
            string directoryPath = null;

            // Act
            TestDelegate action = () => MultiPurposeValidator.IsValidDirectoryPath(directoryPath);

            // Assert
            Assert.Throws <ArgumentNullException>(action);
        }
コード例 #2
0
        public void IsValidFileName_NullInput_ThrowsNullArgumentException()
        {
            // Arrange
            string fileName = null;

            // Act
            TestDelegate action = () => MultiPurposeValidator.IsValidFileName(fileName);

            // Assert
            Assert.Throws <ArgumentNullException>(action);
        }
コード例 #3
0
        public ScreenshotCommand(string fileName, string directoryPath)
        {
            _fileName      = fileName ?? throw new ArgumentNullException(nameof(fileName));
            _directoryPath = directoryPath ?? throw new ArgumentNullException(nameof(directoryPath));

            if (!MultiPurposeValidator.IsValidFileName(fileName))
            {
                throw new ArgumentException($"Invalid file name: {fileName}");
            }
            if (!MultiPurposeValidator.IsValidDirectoryPath(directoryPath))
            {
                throw new ArgumentException($"Invalid directory: {directoryPath}");
            }
        }
コード例 #4
0
        public void IsValidDirectoryPath_InvalidInput_DoesNotThrowException()
        {
            // Arrange

            // Act
            TestDelegate[] actions =
            {
                () => MultiPurposeValidator.IsValidFileName(""),
                () => MultiPurposeValidator.IsValidFileName("  "),
                () => MultiPurposeValidator.IsValidFileName("directory*path"),
                () => MultiPurposeValidator.IsValidFileName("<?>")
            };

            // Assert
            AssertMultiple.DoesNotThrow(actions);
        }
コード例 #5
0
        public void IsValidFileName_ValidInput_ReturnsTrue()
        {
            // Arrange

            // Act
            Func <bool>[] actions =
            {
                () => MultiPurposeValidator.IsValidFileName("image.jpg"),
                () => MultiPurposeValidator.IsValidFileName("image.unkown"),
                () => MultiPurposeValidator.IsValidFileName("directory/filename.png"),
                () => MultiPurposeValidator.IsValidFileName("filename_noext")
            };

            // Assert
            AssertMultiple.Returns(actions, true);
        }
コード例 #6
0
        public void IsValidFileName_InvalidInput_ReturnsFalse()
        {
            // Arrange

            // Act
            Func <bool>[] actions =
            {
                () => MultiPurposeValidator.IsValidFileName(""),
                () => MultiPurposeValidator.IsValidFileName("  "),
                () => MultiPurposeValidator.IsValidFileName("file*name"),
                () => MultiPurposeValidator.IsValidFileName("<?>")
            };

            // Assert
            AssertMultiple.Returns(actions, false);
        }
コード例 #7
0
        public void IsValidDirectoryPath_ValidInput_ReturnsTrue()
        {
            // Arrange

            // Act
            Func <bool>[] actions =
            {
                () => MultiPurposeValidator.IsValidFileName("sub/sub/sub\\sap\\sap\\sap"),
                () => MultiPurposeValidator.IsValidFileName("%TEMP%"),
                () => MultiPurposeValidator.IsValidFileName("C://Windows/System32"),
                () => MultiPurposeValidator.IsValidFileName("folder_only")
            };

            // Assert
            AssertMultiple.Returns(actions, true);
        }