Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ArgumentRules"/> class.
        /// </summary>
        /// <param name="commandLineArguments">
        /// The command line arguments.
        /// </param>
        /// <param name="compilationLevelHelper">
        /// The compilation level helper.
        /// </param>
        public ArgumentRules(ICommandLineArguments commandLineArguments, ICompilationLevelHelper compilationLevelHelper)
        {
            Guard.ArgumentNotNull(() => commandLineArguments, commandLineArguments);
            Guard.ArgumentNotNull(() => compilationLevelHelper, compilationLevelHelper);

            // Setup validators
            var isValidJavaScriptFileName         = new IsValidJavaScriptFileName(commandLineArguments);
            var isValidCompilationLevelArgument   = new IsValidCompilationLevelArgument(commandLineArguments, compilationLevelHelper);
            var isValidWarningSuppressionArgument = new IsValidWarningSuppressionArgument(commandLineArguments);

            // Setup argument rule combos
            this.argumentRuleCombos.Add(
                new ArgumentRuleCombo(isValidJavaScriptFileName, isValidCompilationLevelArgument, isValidWarningSuppressionArgument));

            this.argumentRuleCombos.Add(
                new ArgumentRuleCombo(isValidJavaScriptFileName, isValidWarningSuppressionArgument));

            this.argumentRuleCombos.Add(
                new ArgumentRuleCombo(isValidJavaScriptFileName, isValidCompilationLevelArgument));

            this.argumentRuleCombos.Add(new ArgumentRuleCombo(isValidJavaScriptFileName));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ArgumentRules"/> class.
        /// </summary>
        /// <param name="commandLineArguments">
        /// The command line arguments.
        /// </param>
        /// <param name="compilationLevelHelper">
        /// The compilation level helper.
        /// </param>
        public ArgumentRules(ICommandLineArguments commandLineArguments, ICompilationLevelHelper compilationLevelHelper)
        {
            Guard.ArgumentNotNull(() => commandLineArguments, commandLineArguments);
            Guard.ArgumentNotNull(() => compilationLevelHelper, compilationLevelHelper);

            // Setup validators
            var isValidJavaScriptFileName = new IsValidJavaScriptFileName(commandLineArguments);
            var isValidCompilationLevelArgument = new IsValidCompilationLevelArgument(commandLineArguments, compilationLevelHelper);
            var isValidWarningSuppressionArgument = new IsValidWarningSuppressionArgument(commandLineArguments);

            // Setup argument rule combos
            this.argumentRuleCombos.Add(
                new ArgumentRuleCombo(isValidJavaScriptFileName, isValidCompilationLevelArgument, isValidWarningSuppressionArgument));

            this.argumentRuleCombos.Add(
                new ArgumentRuleCombo(isValidJavaScriptFileName, isValidWarningSuppressionArgument));

            this.argumentRuleCombos.Add(
                new ArgumentRuleCombo(isValidJavaScriptFileName, isValidCompilationLevelArgument));

            this.argumentRuleCombos.Add(new ArgumentRuleCombo(isValidJavaScriptFileName));
        }
        public void Invalid_Compilation_Switch_Directive_Is_Recognised_As_Being_Invalid()
        {
            // Arrange
            var commandLineArguments = new Mock<ICommandLineArguments>();
            var compilationLevelHelper = new Mock<ICompilationLevelHelper>();
            compilationLevelHelper.Setup(m => m.IsValid(It.Is<string>(r => r == "A"))).Returns(true);

            var rule = new IsValidCompilationLevelArgument(
                commandLineArguments.Object,
                compilationLevelHelper.Object);

            const string InvalidCompilationSwitchDirective = "/R";
            var invalidCommandLineArgument = string.Format("{0}A", InvalidCompilationSwitchDirective);

            var args = new[] { invalidCommandLineArgument };

            // Act
            var isValid = rule.IsSatisfiedBy(args);

            // Assert
            Assert.False(isValid);
            compilationLevelHelper.Verify(m => m.IsValid(It.Is<string>(r => r == "A")), Times.Never);
        }
        public void Valid_Compilation_Switch_Is_Recognised_As_Being_Valid()
        {
            // Arrange
            const string ValidCompilationSwitchAttribute = "A";
            var commandLineArguments = new Mock<ICommandLineArguments>();
            commandLineArguments.SetupSet(m => m.CompilationLevel = It.IsAny<string>()).Verifiable();

            var compilationLevelHelper = new Mock<ICompilationLevelHelper>();
            compilationLevelHelper.Setup(m => m.IsValid(It.Is<string>(r => r == ValidCompilationSwitchAttribute))).Returns(true);

            var rule = new IsValidCompilationLevelArgument(
                commandLineArguments.Object,
                compilationLevelHelper.Object);

            var args = new[] { string.Format("/C{0}", ValidCompilationSwitchAttribute) };

            // Act
            var isValid = rule.IsSatisfiedBy(args);

            // Assert
            Assert.True(isValid);
            commandLineArguments.VerifySet(m => m.CompilationLevel = ValidCompilationSwitchAttribute);
            compilationLevelHelper.Verify(m => m.IsValid(It.Is<string>(r => r == ValidCompilationSwitchAttribute)), Times.Once);
        }
 public void IsSatisfiedBy_Guards_Null_commandLineArguments()
 {
     var rule = new IsValidCompilationLevelArgument(Mock.Of<ICommandLineArguments>(), Mock.Of<ICompilationLevelHelper>());
     Assert.Throws<ArgumentNullException>(() => rule.IsSatisfiedBy(null));
 }
        public void Invalid_Compilation_Switch_No_Char_Attribute_Is_Recognised_As_Being_Invalid()
        {
            // Arrange
            var commandLineArguments = new Mock<ICommandLineArguments>();
            var compilationLevelHelper = new Mock<ICompilationLevelHelper>();
            compilationLevelHelper.Setup(m => m.IsValid(It.Is<string>(r => r == "A"))).Returns(true);

            var rule = new IsValidCompilationLevelArgument(
                commandLineArguments.Object,
                compilationLevelHelper.Object);

            var invalidCommandLineArgument = string.Format("/C");

            var args = new[] { invalidCommandLineArgument };

            // Act
            var isValid = rule.IsSatisfiedBy(args);

            // Assert
            Assert.False(isValid);
            compilationLevelHelper.Verify(m => m.IsValid(It.Is<string>(r => string.IsNullOrEmpty(r))), Times.Once);
        }