public static void InitiateTempDatabase(bool enforceRestart, bool mustRenew) { if (!IsTddExecutionMode()) { return; } if (Config.Get("PredictableGuidEnabled", defaultValue: false)) { PredictableGuidGenerator.Reset("Default"); GuidEntity.NewGuidGenerator = PredictableGuidGenerator.Generate; } IsDatabaseBeingCreated = true; try { DataAccessor.Current.ClearAllPools(); AutomatedTask.DeleteExecutionStatusHistory(); if (enforceRestart) { TempDatabaseInitiated = null; } if (TempDatabaseInitiated.HasValue) { return; } var generator = TestDatabaseGenerator.Current.Initialize(isTempDatabaseOptional: true, mustRenew: mustRenew); TempDatabaseInitiated = generator.Process(); Database.Refresh(); DataAccessor.Current.ClearAllPools(); } finally { IsDatabaseBeingCreated = false; } }
public static void ProcessCommand(string command) { if (command.IsEmpty()) { return; } if (!IsTddExecutionMode()) { throw new Exception("Invalid command in non TDD mode."); } var request = HttpContext.Current.Request; var response = HttpContext.Current.Response; var isShared = request["mode"] == "shared"; if (command == "snap") { new Snapshot(request["name"], isShared).Create(HttpContext.Current); } else if (command == "restore") { new Snapshot(request["name"], isShared).Restore(HttpContext.Current); } else if (command == "remove_snapshots") { Snapshot.RemoveSnapshots(); } else if (command == "snapshots_list") { response.EndWith(JsonConvert.SerializeObject(Snapshot.GetList(isShared))); } else if (command == "snapExists") { if (new Snapshot(request["name"], isShared).Exists()) { response.EndWith("true"); } else { response.EndWith("false"); } } else if (command.IsAnyOf("start", "run", "ran", "cancel", "restart")) { InitiateTempDatabase(enforceRestart: true, mustRenew: true); DatabaseChangeWatcher.Restart(); if (request.Has("runner")) { CurrentRunner = request["runner"]; } } else if (command == "testContext") { PredictableGuidGenerator.Reset(request["name"]); } else if (command == "testEmail") { new EmailTestService(request, response).Process(); } else if (command == "dbChanges") { DatabaseChangeWatcher.DispatchChanges(); } else if (command == "dbRefresh") { Database.Refresh(); } else if (command == "runChanges") { DatabaseChangeWatcher.RunChanges(); } else if (command == "tasks") { DispatchTasksList(); } else if (command == "setLocalDate") { if (request["date"] == "now") { // reset to normal LocalTime.RedefineNow(overriddenNow: null); response.EndWith(LocalTime.Now.ToString("yyyy-MM-dd @ HH:mm:ss")); } var time = LocalTime.Now.TimeOfDay; if (request.Has("time")) { time = TimeSpan.Parse(request["time"]); } var date = LocalTime.Today; if (request.Has("date")) { date = request["date"].To <DateTime>(); } date = date.Add(time); var trueOrigin = DateTime.Now; LocalTime.RedefineNow(() => { return(date.Add(DateTime.Now.Subtract(trueOrigin))); }); response.Clear(); response.EndWith(date.ToString("yyyy-MM-dd @ HH:mm:ss")); } else if (command == "remove_snapshot") { Snapshot.RemoveSnapshot(request["name"]); } else if (command == "inject.service.response") { var serviceType = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(a => a.GetTypes()) .Where(x => x.InhritsFrom(typeof(IntegrationService))) .SingleOrDefault(x => x.Name == request["service"]); if (serviceType == null) { throw new Exception("Cannot find a class named " + request["service"] + " in the currently loaded assemblies, which inherits from IntegrationService<,>."); } new Thread(new ThreadStart(() => IntegrationTestInjector.Inject(serviceType, request["request"], request["response"]))) { IsBackground = true } .Start(); } }