public void When_two_commands_have_the_same_names_should_pick_the_first_one()
        {
            var catalog = new CommandsCatalog();
            int value   = 0;

            catalog.AddCommand(() => value = 1).WithName("cmd");
            catalog.AddCommand(() => value = 2).WithName("cmd");

            var dispacther = new CommandDispatcher(catalog);

            dispacther.DispatchCommand("cmd");

            value.Should().Be(1);
        }
예제 #2
0
        static void Main(string[] args)
        {
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterType <Service>().SingleInstance();
            containerBuilder.RegisterType <AddValue>();

            var catalog = new CommandsCatalog();

            catalog.AddCommand <AddValue>();
            catalog.AddExitCommand();
            catalog.AddHelpCommand();

            var dispatcher = new CommandDispatcher(catalog);

            dispatcher.UseCommandContextFactory(new AutofacCommandContextFactory(containerBuilder.Build()));
            dispatcher.StartDispatchingFromUserInput();
        }