public void SimpleDispatching()
        {
            var commandHandlers = new List <ICommandHandler <ChangeUsersNameCommand> > {
                new CommandHandler()
            };
            var commandPreconditions = new List <ICommandPrecondition <ChangeUsersNameCommand> > {
                new CommandPrecondition()
            };

            var services = new ServiceCollection();

            services.AddScoped <ICommandHandler <ChangeUsersNameCommand>, CommandHandler>();
            services.AddScoped <ICommandPrecondition <ChangeUsersNameCommand>, CommandPrecondition>();

            var serviceProvider = services.BuildServiceProvider();

            var logger        = new Mock <ILogger>();
            var loggerFactory = new Mock <ILoggerFactory>();

            loggerFactory
            .Setup(x => x.CreateLogger(It.IsAny <String>()))
            .Returns(logger.Object);

            var sut = new CommandDispatcher(loggerFactory.Object, serviceProvider);

            sut.DispatchCommand(new ChangeUsersNameCommand
            {
                UserId = Guid.NewGuid(),
                Name   = "Juergen"
            });
        }
Пример #2
0
 static void Main(string[] args)
 {
     using (var container = new UnityContainer())
     {
         ContainerBootstraper.RegisterComponents(container);
         CommandDispatcher.DispatchCommand(args, container, Console.Out, Console.Error);
     }
 }
Пример #3
0
        public void OverridingCommand_ShouldWork()
        {
            var command = new OverridingCommand();
            var output  = new StringWriter();

            CommandDispatcher.DispatchCommand(command, new[] { "/n", "123" }, output).Should().Be(123);
            output.ToString().Should().BeNullOrEmpty();
        }
        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);
        }
Пример #5
0
        private void login_Btn(object sender, RoutedEventArgs e)
        {
            var username = this.username.Text;
            var password = this.password.Password;
            var command  = "Login";
            CommandDispatcher dispatcher = new CommandDispatcher();

            dispatcher.DispatchCommand(new string[]
            {
                command,
                username,
                password
            });
            var user = LoginUser.User.Credentials.Email;

            Switcher.Switch(new TestPage());
        }
Пример #6
0
        private static void Main(string[] args)
        {
            var manager = new TaskManager();
            var catalog = new CommandsCatalog();

            catalog.AddCommandsFrom(manager);
            catalog.AddHelpCommand().WithGroup("todo");
            catalog.AddExitCommand().WithGroup("todo");

            var dispatcher = new CommandDispatcher(catalog);

            catalog.AddCommandsFrom(new DebugCommands(dispatcher));

            dispatcher.DispatchCommand("\"check example app\" -c -t CommandFramework -t Example");

            dispatcher.StartDispatchingFromUserInput();
        }
Пример #7
0
        public void CommandDispatch_WithoutRequiredParameter_ShouldShowFriendlyErrorInfo()
        {
            var output = new StringWriter();

            CommandDispatcher.DispatchCommand(new SomeCommandWithAParameter(), new[] { "some", "/a" }, output);

            var outputMessage = output.ToString().ToLower();

            outputMessage.AssertContainsInOrder(new []
            {
                "missing required value for option '/a'",
                "expected usage:",
            });

            outputMessage.Contains("ndesk.options").Should().BeFalse();
            outputMessage.Contains("exception").Should().BeFalse();
        }
Пример #8
0
        public void CommandDispatch_ShouldWriteExpectedTrace()
        {
            var expected = @"
Executing thecommand (One-line description):
    FieldA : abc
    PropertyB : def
    PropertyC : null
    PropertyD : 1, 2, 3

";

            var output = new StringWriter();

            CommandDispatcher.DispatchCommand(new SomeCommand(), new[] { "thecommand" }, output);

            output.ToString().Should().Be(expected);
        }
        public void MultipleDispatch_ShouldNotInterferWithEachOther()
        {
            var trace = new StringWriter();
            var expectedTraceParts = new []
            {
                "You walk to 1, 2 and find a maze of twisty little passages, all alike.",
                "You walk to 3, 0 and find a maze of twisty little passages, all alike.",
                "You walk to 0, 4 and find a maze of twisty little passages, all alike.",
                "You walk to 0, 0 and find a maze of twisty little passages, all alike.",
            };

            CommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move", "-x", "1", "-y", "2" }, new StringWriter());
            CommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move", "-x", "3" }, new StringWriter());
            CommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move", "-y", "4" }, new StringWriter());
            CommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move" }, new StringWriter());

            trace.ToString().AssertContainsInOrder(expectedTraceParts);
        }
        public void DispatchCommand_BackupAndUpdate_BackupHappensFirst()
        {
            var backupFlag     = "-bak";
            var backupFile     = "backupTo";
            var updateFlag     = "-u";
            var mockRepository = new MockRepository();
            var service        = mockRepository.DynamicMock <IMigrationsService>();
            var dispatcher     = new CommandDispatcher(service);

            using (mockRepository.Ordered())
            {
                service.Expect(g => g.BackupDatabase(backupFile));
                service.Expect(g => g.UpdateDatabase());
            }
            mockRepository.Replay(service);

            dispatcher.DispatchCommand(new[] { "-d", DatabaseName, updateFlag, backupFlag, backupFile });

            mockRepository.Verify(service);
        }
 public void TestStaticMethodInvocation()
 {
     _dispatcher.DispatchCommand("static -intP 10 -stringP test -dateP 2015-01-01 -boolP -colP 2 -colP 3 -colP 4");
 }