コード例 #1
0
        public void NullCheck()
        {
            IServiceProvider provider = CreateDependencyInjection();

            Assert.Throws <ArgumentNullException>("provider", () => CommandActivator.ConstructCommand(null, typeof(NullCommand)));
            Assert.Throws <ArgumentNullException>("type", () => CommandActivator.ConstructCommand(provider, null));
        }
コード例 #2
0
        public void ActivatorRequiresPublicConstructor()
        {
            IServiceProvider provider = CreateDependencyInjection();
            Type             type     = typeof(InvalidCommand);

            Assert.Empty(type.GetConstructors());
            Assert.Throws <InvalidOperationException>(() => CommandActivator.ConstructCommand(provider, type));
        }
コード例 #3
0
        public void CreateCommandWithParameterlessConstructor()
        {
            IServiceProvider provider = CreateDependencyInjection();

            CommandBase command = CommandActivator.ConstructCommand(provider, typeof(NullCommand));

            Assert.IsType <NullCommand>(command);
        }
コード例 #4
0
        public void CreateCommandWithParameterizedConstructor()
        {
            Func <int>       argument = () => 240;
            IServiceProvider provider = CreateDependencyInjection(argument);

            CommandBase command = CommandActivator.ConstructCommand(provider, typeof(DelegateCommand));

            Assert.IsType <DelegateCommand>(command);
        }
コード例 #5
0
        private static async Task <CommandResult> RunCommandPipelineAsync(ReadOnlyCollection <string> commandLineArguments, Assembly commandAssembly, IServiceProvider provider, CancellationToken stoppingToken)
        {
            CommandLineArguments args = CommandLineArgumentsParser.Parse(commandLineArguments);
            Type type = CommandSelector.SelectCommand(commandAssembly, args);

            using CommandBase instance = CommandActivator.ConstructCommand(provider, type);
            CommandArgumentsBinder.BindArguments(instance, args);
            CommandOptionsBinder.BindOptions(instance, args);

            CommandResult result = await CommandExecutor.InvokeAsync(instance, stoppingToken);

            return(result);
        }
コード例 #6
0
        public void ActivatorDoesNotCatchExceptionThrownInCommandConstructor()
        {
            IServiceProvider provider = CreateDependencyInjection();

            Assert.Throws <NotSupportedException>(() => CommandActivator.ConstructCommand(provider, typeof(BadCommand)));
        }
コード例 #7
0
        public void TypeMustBeCommand()
        {
            IServiceProvider provider = CreateDependencyInjection();

            Assert.Throws <ArgumentException>("type", () => CommandActivator.ConstructCommand(provider, typeof(CommandActivatorTests)));
        }