public void BuilderShouldReturnPublicMethodsOnly() {
     var builder = new CommandHandlerDescriptorBuilder();
     var descriptor = builder.Build(typeof(PublicMethodsOnly));
     Assert.That(descriptor, Is.Not.Null);
     Assert.That(descriptor.Commands.Count(), Is.EqualTo(1));
     Assert.That(descriptor.Commands.Single(d => d.Name == "Method"), Is.Not.Null);
 }
Example #2
0
        protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration) {

            if (!registration.Services.Contains(new TypedService(typeof(ICommandHandler))))
                return;

            var builder = new CommandHandlerDescriptorBuilder();
            var descriptor = builder.Build(registration.Activator.LimitType);
            registration.Metadata.Add(typeof(CommandHandlerDescriptor).FullName, descriptor);
        }
        protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration)
        {
            if (!registration.Services.Contains(new TypedService(typeof(ICommandHandler))))
            {
                return;
            }

            var builder    = new CommandHandlerDescriptorBuilder();
            var descriptor = builder.Build(registration.Activator.LimitType);

            registration.Metadata.Add(typeof(CommandHandlerDescriptor).FullName, descriptor);
        }
 public void BuilderShouldCreateDescriptor() {
     var builder = new CommandHandlerDescriptorBuilder();
     var descriptor = builder.Build(typeof(MyCommand));
     Assert.That(descriptor, Is.Not.Null);
     Assert.That(descriptor.Commands.Count(), Is.EqualTo(4));
     Assert.That(descriptor.Commands.Single(d => d.Name == "FooBar"), Is.Not.Null);
     Assert.That(descriptor.Commands.Single(d => d.Name == "FooBar").MethodInfo, Is.EqualTo(typeof(MyCommand).GetMethod("FooBar")));
     Assert.That(descriptor.Commands.Single(d => d.Name == "MyCommand"), Is.Not.Null);
     Assert.That(descriptor.Commands.Single(d => d.Name == "MyCommand").MethodInfo, Is.EqualTo(typeof(MyCommand).GetMethod("FooBar2")));
     Assert.That(descriptor.Commands.Single(d => d.Name == "Foo Bar"), Is.Not.Null);
     Assert.That(descriptor.Commands.Single(d => d.Name == "Foo Bar").MethodInfo, Is.EqualTo(typeof(MyCommand).GetMethod("Foo_Bar")));
     Assert.That(descriptor.Commands.Single(d => d.Name == "Foo_Bar"), Is.Not.Null);
     Assert.That(descriptor.Commands.Single(d => d.Name == "Foo_Bar").MethodInfo, Is.EqualTo(typeof(MyCommand).GetMethod("Foo_Bar3")));
 }
Example #5
0
        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 => string.Equals(d.Name, commandName, StringComparison.OrdinalIgnoreCase));

            return new CommandContext { 
                Command = commandName, 
                Switches = switches, 
                CommandDescriptor = commandDescriptor,
                Arguments = args,
                Input = new StringReader(string.Empty),
                Output = new StringWriter()
            };
        }