public static void AssemblyInitialize(TestContext testContext) { var sender = new Ping(); var reply = sender.Send(Settings.Server); if (reply.Status != IPStatus.Success) { Assert.Fail("Ping responded with" + reply.Status.ToString()); } Impersonator.ExecuteAction(() => { var coreService = new ServiceController("PRTGCoreService", Settings.Server); var probeService = new ServiceController("PRTGProbeService", Settings.Server); if (coreService.Status != ServiceControllerStatus.Running) { Assert.Fail("Core Service is not running"); } if (probeService.Status != ServiceControllerStatus.Running) { Assert.Fail("Probe Service is not running"); } if (Settings.ResetAfterTests) { File.Copy(PrtgConfig, PrtgConfigBackup); } }); new BasePrtgClientTest().client.RefreshObject(Settings.Device); }
public void Initialize() { Initialized = false; PingServer(); Logger.Log("Connecting to local server"); Impersonator.ExecuteAction(RemoteInit); Logger.Log("Refreshing CI device"); try { Client.RefreshObject(Settings.Device); WaitForObjects(); } catch (Exception ex) { Logger.Log($"Exception occurred while refreshing device: {ex.Message}", true); Cleanup(); throw; } Logger.Log("Ready for tests"); }
public static void ExecuteAction(Action action) { using (var impersonator = new Impersonator(Settings.Server, Settings.WindowsUsername, Settings.WindowsPassword)) { action(); } }
public static T ExecuteAction <T>(Func <T> action) { using (var impersonator = new Impersonator(Settings.Server, Settings.WindowsUserName, Settings.WindowsPassword)) { return(action()); } }
private void Logic_Client_RetryRequestInternal(Action <PrtgClient> action, bool isAsync) { var initialThread = Thread.CurrentThread.ManagedThreadId; Impersonator.ExecuteAction(() => { var retriesMade = 0; var retriesToMake = 3; var coreService = new ServiceController("PRTGCoreService", Settings.Server); var localClient = new PrtgClient(Settings.ServerWithProto, Settings.UserName, Settings.Password); localClient.RetryRequest += (sender, args) => { Logger.LogTestDetail($"Handling retry {retriesMade + 1}"); if (!isAsync) { AssertEx.AreEqual(initialThread, Thread.CurrentThread.ManagedThreadId, "Event was not handled on initial thread"); } retriesMade++; }; localClient.RetryCount = retriesToMake; Logger.LogTestDetail("Stopping PRTG Service"); coreService.Stop(); coreService.WaitForStatus(ServiceControllerStatus.Stopped); try { action(localClient); } catch (AggregateException ex) { if (ex.InnerException != null && ex.InnerException.GetType() == typeof(AssertFailedException)) { throw ex.InnerException; } } catch (WebException) { } finally { Logger.LogTestDetail("Starting PRTG Service"); coreService.Start(); coreService.WaitForStatus(ServiceControllerStatus.Running); Logger.LogTestDetail("Sleeping for 20 seconds"); Thread.Sleep(20000); Logger.LogTestDetail("Refreshing and sleeping for 20 seconds"); localClient.RefreshObject(Settings.Device); Thread.Sleep(20000); } AssertEx.AreEqual(retriesToMake, retriesMade, "An incorrect number of retries were made."); }); }
public void RepairConfig() { Logger.Log("Repairing config"); Impersonator.ExecuteAction(() => RemoteCleanup(false)); Logger.Log("Sleeping for 60 seconds while service starts up"); Thread.Sleep(60 * 1000); }
public void Cleanup() { if (!Initialized) { Logger.Log("Did not initialize properly; not cleaning up"); return; } Logger.Log("Cleaning up after tests"); if (Settings.ResetAfterTests) { Logger.Log("Connecting to server"); Impersonator.ExecuteAction(() => RemoteCleanup(true)); } }
public void StartServices() { Impersonator.ExecuteAction(() => { var coreService = GetCoreService(); var probeService = GetProbeService(); if (coreService.Status != ServiceControllerStatus.Running) { StartService(coreService, "Core Service"); } if (probeService.Status != ServiceControllerStatus.Running) { StartService(probeService, "Probe Service"); } }); }
[AssemblyCleanup] public static void AssemblyCleanup() { if (Settings.ResetAfterTests) { Impersonator.ExecuteAction(() => { var controller = new ServiceController("PRTGCoreService", Settings.Server); controller.Stop(); controller.WaitForStatus(ServiceControllerStatus.Stopped); File.Copy(PrtgConfigBackup, PrtgConfig, true); File.Delete(PrtgConfigBackup); controller.Start(); controller.WaitForStatus(ServiceControllerStatus.Running); }); } }