public void NullCheck() { IServiceProvider provider = CreateDependencyInjection(); Assert.Throws <ArgumentNullException>("provider", () => CommandActivator.ConstructCommand(null, typeof(NullCommand))); Assert.Throws <ArgumentNullException>("type", () => CommandActivator.ConstructCommand(provider, null)); }
public void ActivatorRequiresPublicConstructor() { IServiceProvider provider = CreateDependencyInjection(); Type type = typeof(InvalidCommand); Assert.Empty(type.GetConstructors()); Assert.Throws <InvalidOperationException>(() => CommandActivator.ConstructCommand(provider, type)); }
public void CreateCommandWithParameterlessConstructor() { IServiceProvider provider = CreateDependencyInjection(); CommandBase command = CommandActivator.ConstructCommand(provider, typeof(NullCommand)); Assert.IsType <NullCommand>(command); }
public void CreateCommandWithParameterizedConstructor() { Func <int> argument = () => 240; IServiceProvider provider = CreateDependencyInjection(argument); CommandBase command = CommandActivator.ConstructCommand(provider, typeof(DelegateCommand)); Assert.IsType <DelegateCommand>(command); }
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); }
public void ActivatorDoesNotCatchExceptionThrownInCommandConstructor() { IServiceProvider provider = CreateDependencyInjection(); Assert.Throws <NotSupportedException>(() => CommandActivator.ConstructCommand(provider, typeof(BadCommand))); }
public void TypeMustBeCommand() { IServiceProvider provider = CreateDependencyInjection(); Assert.Throws <ArgumentException>("type", () => CommandActivator.ConstructCommand(provider, typeof(CommandActivatorTests))); }