public void DescribeParameterWithAliases_AliasesDescribed() { var parameters = CommandReflection.Describe <ArgumentWithAlias>().Arguments; ValidateParameterDescription <int>( parameters.First(), "MyProperty", 'p'); }
private CommandInfo ValidateCommandDescription <T>( string name = null) { var info = CommandReflection.Describe <T>(); info.Should().NotBeNull(); info.Type.Should().Be <T>(); info.Description.Should().BeNull(); info.Name.Should().Be(name ?? typeof(T).Name); info.Arguments.Should().BeEmpty(); return(info); }
public void DescribeCommandInvalidExecuteReturn_Exception() { try { CommandReflection.Describe <InvalidExecuteReturn>(); } catch (CommandReflectionException ex) { ex.InnerException.Should().NotBeNull(); ex.InnerException.Message.Should().Be("the Execute function must return an int."); throw ex; } }
public void DescribeCommandWithNoExecute_Exception() { try { CommandReflection.Describe <NoExecute>(); } catch (CommandReflectionException ex) { ex.InnerException.Should().NotBeNull(); ex.InnerException.Message.Should().Contain("The command must implement a public Execute function"); throw ex; } }
public void DescribeCommandInvalidExecuteParametersAsync_Exception() { try { CommandReflection.Describe <InvalidExecuteParametersAsync>(); } catch (CommandReflectionException ex) { ex.InnerException.Should().NotBeNull(); ex.InnerException.Message.Should().Contain("The Execute function must accept a CommandExecutionContext parameter"); throw ex; } }
public void DescribeCommandInvalidExecuteReturnAsync_Exception() { try { CommandReflection.Describe <InvalidExecuteReturnAsync>(); } catch (CommandReflectionException ex) { ex.InnerException.Should().NotBeNull(); ex.InnerException.Message.Should().Contain("The async Execute function must return a Task<int>"); throw ex; } }
public void RegisterCommand(Type type) { // describe command var info = CommandReflection.Describe(type); // check for duplicate command var duplicateCmd = _commands.Where(c => c.Name.Equals(info.Name, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); if (duplicateCmd != null) { throw new ArgumentException($"Cannot register command type {type.FullName} because a command with the same name is already registered :: {duplicateCmd.Type.FullName}"); } _commands.Add(info); }
public void DescribeCommandOfWrongBaseType_Exception() { CommandReflection.Describe <CommandWithWrongBase>(); }
public void DescribeWithOneParameter_ParameterDescribed() { var parameters = CommandReflection.Describe <ArgumentAttributeCmd>().Arguments; ValidateParameterDescription <int>(parameters.First(), "MyName"); }
public void DescribeWithOneEmptyParameter_ParameterDescribed() { var parameters = CommandReflection.Describe <EmptyArgumentAttribute>().Arguments; ValidateParameterDescription <string>(parameters.First(), "TestArg"); }