Beispiel #1
0
            public void FoundWithLongOrAlternateName(string optionName)
            {
                // Arrange
                var testCommandType = new ClassBasedCommandType(typeof(TestCommand),
                                                                new List <IConverter> {
                    new StringConverter(), new GuidConverter(), new Int32Converter()
                }, new List <IPropertyOptionAlternateNameGenerator>());
                var serviceProviderMock = new Mock <IServiceProvider>();

                serviceProviderMock.Setup(_ => _.GetService(typeof(IClassBasedCommandActivator)))
                .Returns(ClassBasedBasicCommandActivator.Instance);
                var classBasedCommandObjectBuilder =
                    (ClassBasedCommandObjectBuilder)testCommandType.CreateCommandObjectBuilder(serviceProviderMock.Object);
                var testCommand = (TestCommand)((IClassBasedCommandObject)classBasedCommandObjectBuilder.GenerateCommandObject()).Command;

                // Act
                var actual = classBasedCommandObjectBuilder.FindOptionByShortName(optionName);

                // Assert
                Assert.NotNull(actual);
                Assert.NotNull(testCommand);
                Assert.True(actual.ShouldProvideValue);
                actual.AssignValue("42");
                Assert.Single(testCommand.PropertyList);
                Assert.Equal(42, testCommand.PropertyList.First());
            }
            public void PropertyWithNoConverterException()
            {
                // Arrange
                var testCommandType = new ClassBasedCommandType(typeof(TestBadConverterCommand),
                                                                new List <IConverter>
                {
                    new StringConverter(),
                    new GuidConverter(),
                    new Int32Converter(),
                    new BooleanConverter()
                }, new List <IPropertyOptionAlternateNameGenerator>());
                var serviceProviderMock = new Mock <IServiceProvider>();

                serviceProviderMock.Setup(_ => _.GetService(typeof(IClassBasedCommandActivator)))
                .Returns(ClassBasedBasicCommandActivator.Instance);
                var optionName = nameof(TestBadConverterCommand.PropertySimpleWithBadConverter);
                var expectedMessageException =
                    Constants.ExceptionMessages.ParserSpecifiedConverterNotValid(optionName,
                                                                                 testCommandType.Metadata.Name, typeof(int), typeof(bool));

                // Act
                var actualException =
                    Assert.Throws <CommandLineParserException>(
                        () => testCommandType.CreateCommandObjectBuilder(serviceProviderMock.Object));

                // Assert
                Assert.Equal(expectedMessageException, actualException.Message);
            }