public void BuilderShouldReturnPublicMethodsOnly() { var builder = new CommandHandlerDescriptorBuilder(); var descriptor = builder.Build(typeof(PublicMethodsOnly)); Assert.NotNull(descriptor); Assert.Equal(1, descriptor.Commands.Count()); Assert.NotNull(descriptor.Commands.SingleOrDefault(d => d.Name == "Method")); }
public void BuilderShouldCreateDescriptor() { var builder = new CommandHandlerDescriptorBuilder(); var descriptor = builder.Build(typeof(MyCommand)); Assert.NotNull(descriptor); Assert.Equal(4, descriptor.Commands.Count()); Assert.NotNull(descriptor.Commands.SingleOrDefault(d => d.Name == "FooBar")); Assert.Equal(typeof(MyCommand).GetMethod("FooBar"), descriptor.Commands.Single(d => d.Name == "FooBar").MethodInfo); Assert.NotNull(descriptor.Commands.SingleOrDefault(d => d.Name == "MyCommand")); Assert.Equal(typeof(MyCommand).GetMethod("FooBar2"), descriptor.Commands.Single(d => d.Name == "MyCommand").MethodInfo); Assert.NotNull(descriptor.Commands.SingleOrDefault(d => d.Name == "Foo Bar")); Assert.Equal(typeof(MyCommand).GetMethod("Foo_Bar"), descriptor.Commands.Single(d => d.Name == "Foo Bar").MethodInfo); Assert.NotNull(descriptor.Commands.SingleOrDefault(d => d.Name == "Foo_Bar")); Assert.Equal(typeof(MyCommand).GetMethod("Foo_Bar3"), descriptor.Commands.Single(d => d.Name == "Foo_Bar").MethodInfo); }
private CommandContext CreateCommandContext(string commandName, IDictionary<string, string> switches, string[] args) { var builder = new CommandHandlerDescriptorBuilder(); var descriptor = builder.Build(typeof(StubCommandHandler)); var commandDescriptor = descriptor.Commands.Single(d => d.Names.Any(x => string.Equals(x, commandName, StringComparison.OrdinalIgnoreCase))); return new CommandContext { Command = commandName, Switches = switches, CommandDescriptor = commandDescriptor, Arguments = args, Input = new StringReader(string.Empty), Output = new StringWriter() }; }