internal static IDevCommandsConfig AddDatabaseManager(this IDevCommandsConfig config) { config.Add("dbChanges", () => DatabaseChangeWatcher.DispatchChanges()); async Task <bool> startDatabase(bool shouldRedirect = false) { var redirect = Context.Current.Request().ToAbsoluteUri().AsUri().RemoveQueryString("Web.Test.Command").ToString(); WebTestConfig.SetRunner(); await TempDatabase.Restart(); if (shouldRedirect) { Debug.WriteLine("All done. Redirecting to: " + redirect); Context.Current.Response().Redirect(redirect); } return(shouldRedirect); } foreach (var command in new[] { "start", "run", "ran", "cancel" }) { config.Add(command, () => startDatabase()); } config.Add("restart", () => startDatabase(shouldRedirect: true), "Restart DB"); return(config); }
public static IApplicationBuilder UseWebTest(this IApplicationBuilder app, Func <Task> createReferenceData, Action <IWebTestConfig> config = null) { if (!WebTestConfig.IsActive()) { return(app); } WebTestConfig.ReferenceDataCreator = createReferenceData; var settings = new WebTestConfig(); config?.Invoke(settings); if (settings.AddDefaultHandlers) { settings.AddDatabaseManager().AddSnapshot().AddTimeInjector().AddSqlProfile(); } app.UseMiddleware <WebTestMiddleware>(); Task.Factory.RunSync(() => TempDatabase.Create(enforceRestart: false, mustRenew: false)); return(app); }
async Task <bool> ProcessAsWebCommand() { if (TempDatabase.Config?.DatabaseManager == null) { return(false); } await TempDatabase.AwaitReadiness(); var command = Context.Current.Request().Param("Web.Test.Command"); if (command.IsEmpty()) { return(false); } try { return(await WebTestConfig.Run(command)); } catch (Exception ex) { await Context.Current.Response().EndWith(ex.ToLogString().ToHtmlLines()); return(false); } }
public static async Task InitializeTempDatabase <TDatabaseManager>(this IApplicationBuilder app, Func <Task> createReferenceData) where TDatabaseManager : DatabaseManager, new() { if (!WebTestConfig.IsActive()) { return; } TempDatabase.Config.DatabaseManager = new TDatabaseManager(); WebTestConfig.ReferenceDataCreator = createReferenceData; await TempDatabase.AwaitReadiness(); }