Ejemplo n.º 1
0
        public void AsValid_Should_Return_Correctly()
        {
            // ACT
            var response = ValidateResponse.AsValid();

            // ASSERT
            response.Valid.Should().BeTrue();
            response.Message.Should().BeNull();
        }
Ejemplo n.º 2
0
        public static ValidateResponse Validate(this Parameters parameters)
        {
            var isFileNameBlank = string.IsNullOrWhiteSpace(parameters.FileName);

            if (isFileNameBlank)
            {
                return(ValidateResponse.AsInvalid("FileName is required."));
            }

            var fileName          = Path.GetFileName(parameters.FileName);
            var isFileNameInvalid = Path.GetInvalidFileNameChars().Any(c => fileName.Contains(c));
            var directoryName     = Path.GetDirectoryName(parameters.FileName);
            var isPathInvalid     = Path.GetInvalidPathChars().Any(c => directoryName.Contains(c));

            if (isFileNameInvalid || isPathInvalid)
            {
                return(ValidateResponse.AsInvalid("Invalid FileName."));
            }

            var isDirectoryValid = string.IsNullOrWhiteSpace(directoryName) ? true : Directory.Exists(directoryName);

            if (!isDirectoryValid)
            {
                return(ValidateResponse.AsInvalid("Directory does not exist."));
            }
            ;

            // even though Default is part of ContentFillType it is still considered an invalid value
            //   because this should have been updated when parsing the received arguments
            var isContentFillDefault = parameters.ContentFill == ContentFillType.Default;

            if (isContentFillDefault)
            {
                return(ValidateResponse.AsInvalid("Invalid --FILL value."));
            }

            // ContentTemplate is required unless ContentFill is ContentFillType.Null
            var isContentTemplateBlank  = string.IsNullOrWhiteSpace(parameters.ContentTemplate);
            var isContentTemplateNeeded = parameters.ContentFill != ContentFillType.Null && isContentTemplateBlank;

            if (isContentTemplateNeeded)
            {
                return(ValidateResponse.AsInvalid("Invalid --CONTENT value."));
            }

            return(ValidateResponse.AsValid());
        }