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 IsSatisfiedBy_Guards_Null_commandLineArguments()
 {
     var rule = new IsValidCompilationLevelArgument(Mock.Of<ICommandLineArguments>(), Mock.Of<ICompilationLevelHelper>());
     Assert.Throws<ArgumentNullException>(() => rule.IsSatisfiedBy(null));
 }
        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 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);
        }