internal static void RunWithTemporaryPluginFile(Gallio.Common.GallioAction <string, string> action, string pluginFileContents) { var pluginDir = SpecialPathPolicy.For <PluginLoaderTest>().GetTempDirectory().FullName; if (Directory.Exists(pluginDir)) { Directory.Delete(pluginDir, true); } var pluginFile = Path.Combine(pluginDir, "Sample.plugin"); try { Directory.CreateDirectory(pluginDir); System.IO.File.WriteAllText(pluginFile, pluginFileContents); action(pluginDir, pluginFile); } finally { if (Directory.Exists(pluginDir)) { Directory.Delete(pluginDir, true); } } }
public void ShouldWaitForAllActionsToFinishBeforeReturning( [Column(0, 1, 2, 7, 19)] int numActions) { Stopwatch stopwatch = Stopwatch.StartNew(); bool[] finished = new bool[numActions]; GallioAction[] actions = new GallioAction[numActions]; for (int i = 0; i < numActions; i++) { int actionIndex = i; actions[i] = () => { Thread.Sleep((actionIndex + 1) * 71 % 37); TestLog.WriteLine("Iteration #{0} finished after {1}ms", actionIndex + 1, stopwatch.ElapsedMilliseconds); finished[actionIndex] = true; }; } var scheduler = new WorkScheduler(() => maxThreads); scheduler.Run(actions); for (int i = 0; i < numActions; i++) { Assert.IsTrue(finished[i]); } }
private static TimeSpan Time(GallioAction action) { var stopwatch = new Stopwatch(); stopwatch.Start(); action(); stopwatch.Stop(); return(stopwatch.Elapsed); }
public void ConstructorRequiresNameAndExecuteAction() { Assert.Throws <ArgumentNullException>(() => new TestCase(null, delegate { })); Assert.Throws <ArgumentNullException>(() => new TestCase("Foo", null)); GallioAction execute = delegate { }; TestCase testCase = new TestCase("Name", execute); Assert.AreEqual("Name", testCase.Name); Assert.AreSame(execute, testCase.Execute); }
public void SetUp() { TestSuite testSuite = new TestSuite("Name"); Assert.IsNull(testSuite.SetUp); GallioAction action = delegate { }; testSuite.SetUp = action; Assert.AreSame(action, testSuite.SetUp); }
public void SuiteTearDown() { TestSuite testSuite = new TestSuite("Name"); Assert.IsNull(testSuite.SuiteTearDown); GallioAction action = delegate { }; testSuite.SuiteTearDown = action; Assert.AreSame(action, testSuite.SuiteTearDown); }
private void DoRetry(bool expectedSucceeded, Gallio.Common.GallioAction action) { AssertionFailure[] failures = Capture(action); if (expectedSucceeded) { Assert.IsEmpty(failures); } else { Assert.Count(1, failures); Assert.StartsWith(failures[0].Description, "The 'Retry.Until' operation has failed"); } }
public static AssertionFailure[] Capture(GallioAction action) { AssertionFailure[] failures = AssertionHelper.Eval(action); if (failures.Length != 0) { using (TestLog.BeginSection("Captured Assertion Failures")) { foreach (AssertionFailure failure in failures) { failure.WriteTo(TestLog.Default); } } } return(failures); }
public void BackgroundTask(Action action) { action(); }