public Program(GraphSchemaIOConnection connectionInfo, IServiceProvider serviceProvider, TestFinder testFinder, TestExecutor testExecutor) { ConnectionInfo = connectionInfo; ServiceProvider = serviceProvider; TestFinder = testFinder; TestExecutor = testExecutor; }
// I'll need to store the GraphSchmaIO connection info to the actual // instance and creds in here public DgraphClientFactory(GraphSchemaIOConnection connectionConfig, IGraphSchemaIOClient GSioClient) { ConnectionConfig = connectionConfig; this.GSioClient = GSioClient; }
public static int Main(string[] args) { try { var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: false) .AddUserSecrets <Program>() .AddEnvironmentVariables("DGDNE2E_") .Build(); Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(config) .CreateLogger(); var services = new ServiceCollection(); var graphschemaIOconnection = new GraphSchemaIOConnection(); config.Bind(nameof(GraphSchemaIOConnection), graphschemaIOconnection); services.AddSingleton <GraphSchemaIOConnection>(graphschemaIOconnection); if (!graphschemaIOconnection.Endpoint.Equals("localhost")) { services.AddGraphSchemaIOLClient(httpClient => { httpClient.BaseAddress = new Uri(graphschemaIOconnection.Endpoint); httpClient.DefaultRequestHeaders.Add(HeaderNames.Authorization, $"X-GraphSchemaIO-ApiKey {graphschemaIOconnection.ApiKeyId}:{graphschemaIOconnection.ApiKeySecret}"); }); } else { services.AddGraphSchemaIOLClient(httpClient => { }); // only needed to make DI happy } // Inject in every possible test type so that DI will be able to // mint up these for me without me having to do anything to hydrate // the objects. Type baseTestType = typeof(GraphSchemaE2ETest); var assembly = typeof(GraphSchemaE2ETest).Assembly; IEnumerable <Type> testTypes = assembly.GetTypes().Where(t => t.IsSubclassOf(baseTestType)); foreach (var testType in testTypes) { services.AddTransient(testType); } services.AddSingleton <TestFinder>(); services.AddTransient <TestExecutor>(); services.AddScoped <DgraphClientFactory>(); var serviceProvider = services.BuildServiceProvider(); var app = new CommandLineApplication <Program>(); app.Conventions .UseDefaultConventions() .UseConstructorInjection(serviceProvider); app.Execute(args); return(0); } catch (AggregateException aggEx) { foreach (var ex in aggEx.InnerExceptions) { switch (ex) { case DgraphDotNetTestFailure testEx: Log.Error("Test Failed with reason {@Reason}", testEx.FailureReason); Log.Error(testEx, "Call Stack"); break; default: Log.Error(ex, "Unknown Exception Failure"); break; } } } catch (Exception ex) { Log.Error(ex, "Test run failed."); } finally { Log.CloseAndFlush(); } return(1); }