private static void AddCommandRunnerServices(IServiceCollection services) { var assembly = typeof(VersionCommand).Assembly; Guard.Operation(assembly != null, "Command assembly not found."); var apiClients = from t in assembly.GetTypes() where t.Name == nameof(VersionCommand.CommandRunner) select t; foreach (var client in apiClients) { services.AddTransient(client); } }
private static RootCommand ConfigureCommands() { var rootCommand = new RootCommand("Canopy CLI"); var entryAssembly = Assembly.GetEntryAssembly(); Guard.Operation(entryAssembly != null, "Entry assembly not found."); var commands = from t in entryAssembly.GetTypes() where typeof(CanopyCommandBase).IsAssignableFrom(t) && t != typeof(CanopyCommandBase) select(CanopyCommandBase?) Activator.CreateInstance(t); foreach (var command in commands.Where(v => v != null)) { rootCommand.Add(command.Create()); } return(rootCommand); }
public void WhenOperationTestFails_ItShouldThrowWithMessage() { Assert.Throws <InvalidOperationException>( () => Guard.Operation(false)); string?message = null; try { Guard.Operation(false, "Hello {0}", "World"); Assert.False(true, "This should not run."); } catch (InvalidOperationException t) { message = t.Message; } Assert.Equal("Hello World", message); }
private static void AddApiClientServices(IServiceCollection services) { var assembly = typeof(IAuthenticationManager).Assembly; Guard.Operation(assembly != null, "API Client assembly not found."); var apiClients = from t in assembly.GetTypes() where typeof(CanopyApiClient).IsAssignableFrom(t) && t != typeof(CanopyApiClient) select(Class: t, Interface: t.GetInterface($"I{t.Name}")); foreach (var client in apiClients) { if (client.Interface == typeof(ITokenClient)) { continue; } services.AddTransient(client.Interface, client.Class); } // The TokenClient is used for authentication by the AuthenticationManager, so we inject a special configuration object // which contains a dummy AuthenticationManager instead. services.AddTransient <ITokenClient, TokenClient>(s => new TokenClient(s.GetService <ICanopyTokenApiConfiguration>())); }
public void WhenOperationTestPasses_ItShouldNotThrow() { Guard.Operation(true); Guard.Operation(true, "Hello {0}", "World"); }