public void AddRange_TypeParsers_WithValidParser_Succeeds() { var config = new CommandLineArgumentsConfiguration(); config.AddRange(new[] { new MockTypeParser() }); Assert.Contains(config.TypeParsers, p => p.GetType() == typeof(MockTypeParser)); }
public void AddRange_ArgumentValidators_WithValidValidator_Succeeds() { var config = new CommandLineArgumentsConfiguration(); config.AddRange(new[] { new MockArgumentValidator() }); Assert.Contains(config.Validators, v => v.GetType() == typeof(MockArgumentValidator)); }
public void Configuration_SetConfigWithoutHelpWriter_Throws() { var oldConfig = CommandLineArguments.Configuration; var newConfig = new CommandLineArgumentsConfiguration() { Parser = new MockParser(), HelpWriter = null }; Assert.Throws <InvalidOperationException>(() => CommandLineArguments.Configuration = newConfig); CommandLineArguments.Configuration = oldConfig; // The beauty of static, we need to restore the configuration }
public void HelpWriterConfigurationProperty_SetToNullBeforeTryParse_ThrowsInvalidOperationException() { var oldConfig = CommandLineArguments.Configuration; var config = new CommandLineArgumentsConfiguration() { Parser = new MockParser(), HelpWriter = new MockHelpWriter() }; CommandLineArguments.Configuration = config; config.HelpWriter = null; Assert.Throws <InvalidOperationException>(() => CommandLineArguments.DisplayHelp(new TestArguments())); CommandLineArguments.Configuration = oldConfig; // The beauty of static, we need to restore the configuration }
public void AddRange_ArgumentValidators_WithNull_Throws() { var config = new CommandLineArgumentsConfiguration(); Assert.Throws <ArgumentNullException>(() => config.AddRange((IEnumerable <IArgumentValidator>)null)); }
public void Add_TypeParser_WithNull_Throws() { var config = new CommandLineArgumentsConfiguration(); Assert.Throws <ArgumentNullException>(() => config.Add((ITypeParser)null)); }
public void Ctor_WithITypeParsers_Succeeds() { var c = new CommandLineArgumentsConfiguration(new[] { new MockTypeParser() }); Assert.Contains(c.TypeParsers, p => p.GetType() == typeof(MockTypeParser)); }
public void Ctor_WithIArgumentValidators_Succeeds() { var c = new CommandLineArgumentsConfiguration(new[] { new MockArgumentValidator() }); Assert.Contains(c.Validators, v => v.GetType() == typeof(MockArgumentValidator)); }
/// <summary> /// Validate the specified <see cref="CommandLineArgumentsConfiguration"/> /// </summary> /// <param name="configuration"> /// The <see cref="CommandLineArgumentsConfiguration"/> to validate /// </param> private static void ValidateConfiguration(CommandLineArgumentsConfiguration configuration) { _ = configuration ?? throw new ArgumentNullException(nameof(configuration)); _ = configuration.Parser ?? throw new InvalidOperationException("Cannot parse without a parser configured in the configuration"); _ = configuration.HelpWriter ?? throw new InvalidOperationException("Cannot display help without a help writer configured in the configuration"); }