public void It_should_return_the_bytes_of_that_string() { var test = new TestExecutor(this); test.Assert(() => { for (var i = 0; i < _result.Length; i++) { Assert.AreEqual(_text[i], (char)_result[i]); } }); }
public static TestExecutor UseRegisterCommands(this TestExecutor executor) => executor.UseRuntime(async(context, next) => { try { if (context.Remote != null) { var commands = context.Scope.Commands.Values.Select(c => new SerializableTastyCommand { Name = c.Name, Description = c.Description, IsDefault = c.IsDefault }).ToList(); await context.Remote.RegisterCommands(commands).ConfigureAwait(false); } } finally { await next().ConfigureAwait(false); } });
public void TestRunAll() { PythonPaths.Python27_x64.AssertInstalled(); PythonPaths.Python33_x64.AssertInstalled(); var executor = new TestExecutor(); var recorder = new MockTestExecutionRecorder(); var expectedTests = TestInfo.TestAdapterATests.Concat(TestInfo.TestAdapterBTests).ToArray(); var runContext = CreateRunContext(expectedTests); executor.RunTests(expectedTests.Select(ti => ti.SourceCodeFilePath), runContext, recorder); PrintTestResults(recorder); var resultNames = recorder.Results.Select(tr => tr.TestCase.FullyQualifiedName).ToSet(); foreach (var expectedResult in expectedTests) { AssertUtil.ContainsAtLeast(resultNames, expectedResult.TestCase.FullyQualifiedName); var actualResult = recorder.Results.SingleOrDefault(tr => tr.TestCase.FullyQualifiedName == expectedResult.TestCase.FullyQualifiedName); Assert.AreEqual(expectedResult.Outcome, actualResult.Outcome, expectedResult.TestCase.FullyQualifiedName + " had incorrect result"); } }
public static TestExecutor UseTestGroupForceVisitor(this TestExecutor executor) => executor.UseGroup(async(context, next) => { try { if (context.CurrentGroup.IsForced != null) { var result = context.CurrentGroup.IsForced(); foreach (var child in context.CurrentGroup.Descendants().OfType <IForceable>()) { child.IsForced = () => result; } } await next().ConfigureAwait(false); } catch (Exception ex) { context.CurrentGroup.Exception = ex; context.CurrentGroup.TestOutcome = TestOutcome.Failed; } });
public void TestRun() { PythonPaths.Python27_x64.AssertInstalled(); PythonPaths.Python33_x64.AssertInstalled(); var executor = new TestExecutor(); var recorder = new MockTestExecutionRecorder(); var runContext = new MockRunContext(); var expectedTests = TestInfo.TestAdapterATests.Concat(TestInfo.TestAdapterBTests).ToArray(); var testCases = expectedTests.Select(tr => tr.TestCase); executor.RunTests(testCases, runContext, recorder); PrintTestResults(recorder.Results); foreach (var expectedResult in expectedTests) { var actualResult = recorder.Results.SingleOrDefault(tr => tr.TestCase.FullyQualifiedName == expectedResult.TestCase.FullyQualifiedName); Assert.IsNotNull(actualResult); Assert.AreEqual(expectedResult.Outcome, actualResult.Outcome, expectedResult.TestCase.FullyQualifiedName + " had incorrect result"); } }
public static TestExecutor UseAfterEachTest(this TestExecutor executor) => executor.Use(async(context, next) => { try { await next().ConfigureAwait(false); } finally { var hooks = context.CurrentCase.Group?.AfterEachHooks ?? context.CurrentScope.AfterEachHooks; foreach (var hook in hooks) { var hookResult = await hook.Executor.Invoke().ConfigureAwait(false); if (!hookResult) { break; } } } });
public void LinqToSqlAdvanced04() { IQueryable <Customer> custs = DB.Customers; ParameterExpression param1 = Expression.Parameter(typeof(Customer), "e"); Expression left1 = Expression.Property(param1, typeof(Customer).GetProperty("City")); Expression pred1 = Expression.Lambda(left1, param1); IQueryable <Employee> employees = DB.Employees; ParameterExpression param2 = Expression.Parameter(typeof(Employee), "c"); Expression left2 = Expression.Property(param2, typeof(Employee).GetProperty("City")); Expression pred2 = Expression.Lambda(left2, param2); Expression expr1 = Expression.Call(typeof(Queryable), "Select", new[] { typeof(Customer), typeof(string) }, Expression.Constant(custs), pred1); Expression expr2 = Expression.Call(typeof(Queryable), "Select", new[] { typeof(Employee), typeof(string) }, Expression.Constant(employees), pred2); IQueryable <string> q1 = DB.Customers.AsQueryable().Provider.CreateQuery <string> (expr1); IQueryable <string> q2 = DB.Employees.AsQueryable().Provider.CreateQuery <string> (expr2); var q3 = q1.Union(q2); TestExecutor.Execute(q3, MethodBase.GetCurrentMethod()); }
public void QueryWithStringIsNullOrEmpty() { IQueryable query = null; if (IsLinqToSqlActive) { //LinqToSQL has string.IsNullOrEmpty not implemented query = from c in DB.Customers where !(c.Region == null || c.Region == string.Empty) select c; } else if (IsRelinqSqlBackendActive) { query = from c in DB.Customers where !string.IsNullOrEmpty(c.Region) select c; } TestExecutor.Execute(query, MethodBase.GetCurrentMethod()); }
public void TestExtensionReference() { PythonPaths.Python27.AssertInstalled(); var executor = new TestExecutor(); var recorder = new MockTestExecutionRecorder(); var expectedTests = new[] { TestInfo.ExtensionReferenceTestSuccess }; var runContext = CreateRunContext(expectedTests); var testCases = expectedTests.Select(tr => tr.TestCase); executor.RunTests(testCases, runContext, recorder); PrintTestResults(recorder); var resultNames = recorder.Results.Select(tr => tr.TestCase.FullyQualifiedName).ToSet(); foreach (var expectedResult in expectedTests) { AssertUtil.ContainsAtLeast(resultNames, expectedResult.TestCase.FullyQualifiedName); var actualResult = recorder.Results.SingleOrDefault(tr => tr.TestCase.FullyQualifiedName == expectedResult.TestCase.FullyQualifiedName); Assert.AreEqual(expectedResult.Outcome, actualResult.Outcome, expectedResult.TestCase.FullyQualifiedName + " had incorrect result"); } }
private void onBeginningTestExecution(TestExecutor testExecutor, TestExecutionBeginArgs args) { // Start timers m_stopWatch = Stopwatch.StartNew(); m_executionTimer.Start(); // Set execution UI Cursor.Current = Cursors.WaitCursor; setExecutionUI(true); resetViewerAndStatusBar(); m_viewersTabControl.SelectedTab = m_traceViewerTabPage; int availableCases = 0; if (testExecutor.TestScriptObject is TestSuite) { availableCases = ((TestSuite)testExecutor.TestScriptObject).AvailableTestCases(); if (m_testTreeView.TestProfile != null) { availableCases = availableCases * m_testTreeView.TestProfile.VirtualUsers; } } else if (testExecutor.TestScriptObject is TestCase) { availableCases = 1; } m_totalAvailableStatusBarLabel.Tag = availableCases; m_totalAvailableStatusBarLabel.Text = availableCases.ToString(); m_totalAvailableStatusBarLabel.ToolTipText = string.Format(m_totalLabelFormat, getPercentageString(100, 100)); m_viewersTabControl.SelectedTab = m_traceViewerTabPage; m_traceViewer.AppendText(string.Format("Beginning execution ({0} virtual user(s)).\n\n", m_testTreeView.TestProfile != null ? m_testTreeView.TestProfile.VirtualUsers : 1)); m_traceViewer.ScrollToCaret(); }
public void PiCalculatorMethod() { var ast = TestExecutor.Parse( "r = 715237 zz=0.33333", "i = 0 A = 1664525 M = 2^32", "s = 0 C = 1013904223 F = 2^16", "r=(r*A+C)%M x=(r%F)/F r=(r*A+C)%M y=(r%F)/F", "s+=1 i+=(x*x+y*y)<1 pi=4*(i/s) goto 4" ); Console.WriteLine(ast); Console.WriteLine($"Score: {ast.ToString().Length}"); Console.WriteLine(); ast = ast.FoldConstants(); ast = ast.HoistConstants(); ast = ast.CompressConstants(); ast = ast.SimplifyVariableNames(); ast = ast.DeadPostGotoElimination(); Console.WriteLine(ast); Console.WriteLine($"Score: {ast.ToString().Length}"); }
private void onTestExecutionComplete(TestExecutor testExecutor, TestExecutionCompleteArgs args) { _isExecuting = false; // Stop timers m_stopWatch.Stop(); m_executionTimer.Stop(); // Update trace viewer var explanation = args.Explanation ?? "None"; m_traceViewer.AppendText($"Execution complete. Source: {args.TerminationSource}, Explanation: {explanation}\n\n"); m_traceViewer.ScrollToCaret(); var node = m_testTreeView.FindNode(args.TestScriptObject); m_testTreeView.SelectedNode = node; if (node.TestScriptResult != null) { m_resultsViewer.Text = node.TestScriptResult.ToString(); } }
public void TestInheritance() { // TODO: Figure out the proper fix to make this test pass. // There's a confusion between source file path and class file path. // Note that the equivalent manual test in IDE works fine. var executor = new TestExecutor(); var recorder = new MockTestExecutionRecorder(); var expectedTests = TestInfo.TestAdapterBInheritanceTests; var runContext = CreateRunContext(expectedTests, Version.InterpreterPath); var testCases = expectedTests.Select(tr => tr.TestCase); executor.RunTests(testCases, runContext, recorder); PrintTestResults(recorder); var resultNames = recorder.Results.Select(tr => tr.TestCase.FullyQualifiedName).ToSet(); foreach (var expectedResult in expectedTests) { AssertUtil.ContainsAtLeast(resultNames, expectedResult.TestCase.FullyQualifiedName); var actualResult = recorder.Results.SingleOrDefault(tr => tr.TestCase.FullyQualifiedName == expectedResult.TestCase.FullyQualifiedName); Assert.AreEqual(expectedResult.Outcome, actualResult.Outcome, expectedResult.TestCase.FullyQualifiedName + " had incorrect result"); } }
public void RoundTrip() { var ast = TestExecutor.Parse( "z = 1 :a = z z = 2 a = :a * z a /= z", "flag=a==:a if flag then goto 5 else goto 6 end", "x = \"hello\" * 4 goto \"world\" x = 2", "b*=2 flag=b>30 if flag then :b=a end", "b=b-1 goto 4", "b=b+1 goto 4" ); Console.WriteLine(ast); Console.WriteLine(); var s = new AstSerializer().Serialize(ast); Console.WriteLine(s.ToString(Formatting.None)); Console.WriteLine(); var d = new AstDeserializer().Parse(s.ToString()); Console.WriteLine(d); }
public void ZijkhalStrings() { //for (var i = 0; i < 4010; i++) var i = 3600; { try { var ms = TestExecutor.Execute($":a={i} a=\" seconds1 \"b=\" minutes1\"e=\" hours1\"f=\" days1\"g=\" years1\"q=\",1\"", "t=\" \"n=\"s1\"k=0+e-n+t l=\"0 day \"p=\" and1\"r=0+g-n+t", "y=:a s=y%60y-=s y/=60m=y%60y-=m y/=60h=y%24y-=h y/=24d=y%365y-=d", "o=a-(s>1)-n c=s>0v=m>0o=b-(m>1)-n+p-c*v-p+t+s+o y/=365c+=v", "v=h>0o=e-(h>1)-n+q-v*(c>1)-q+p-c*v-p+t+m+o c+=v v=d>0u=f-(d>1)-n", "u+=q-v*(c>1)-q+p-c*v-p+t+h+o c+=v v=y>0o=g-(y>1)-n+q-(y>0)*(c>1)-q", ":o=y+o+(p-c*(y>0)-p)+t+d+u-r-l-k-(0+b-n+t)-(0+a-n)-t:done=1goto50" ); } catch { Console.WriteLine("Index: " + i); throw; } } }
public void TestCancel() { PythonPaths.Python27_x64.AssertInstalled(); PythonPaths.Python33_x64.AssertInstalled(); var executor = new TestExecutor(); var recorder = new MockTestExecutionRecorder(); var runContext = new MockRunContext(); var expectedTests = TestInfo.TestAdapterATests.Union(TestInfo.TestAdapterBTests).ToArray(); var testCases = expectedTests.Select(tr => tr.TestCase); var thread = new System.Threading.Thread(o => { executor.RunTests(testCases, runContext, recorder); }); thread.Start(); // One of the tests being run is hard coded to take 10 secs Assert.IsTrue(thread.IsAlive); System.Threading.Thread.Sleep(100); executor.Cancel(); System.Threading.Thread.Sleep(100); // It should take less than 10 secs to cancel // Depending on which assemblies are loaded, it may take some time // to obtain the interpreters service. Assert.IsTrue(thread.Join(10000)); System.Threading.Thread.Sleep(100); Assert.IsFalse(thread.IsAlive); // Canceled test cases do not get recorded Assert.IsTrue(recorder.Results.Count < expectedTests.Length); }
public void TestLoadError() { // A load error is when unittest module fails to load the test (prior to running it) // For example, if the file where the test is defined has an unhandled ImportError. // We check that this only causes the tests that can't be loaded to fail, // all other tests in the test run which can be loaded successfully will be run. var executor = new TestExecutor(); var recorder = new MockTestExecutionRecorder(); var expectedTests = TestInfo.GetTestAdapterLoadErrorTests(ImportErrorFormat); var runContext = CreateRunContext(expectedTests, Version.InterpreterPath); var testCases = expectedTests.Select(tr => tr.TestCase); executor.RunTests(testCases, runContext, recorder); PrintTestResults(recorder); var resultNames = recorder.Results.Select(tr => tr.TestCase.FullyQualifiedName).ToSet(); foreach (var expectedResult in expectedTests) { AssertUtil.ContainsAtLeast(resultNames, expectedResult.TestCase.FullyQualifiedName); var actualResult = recorder.Results.SingleOrDefault(tr => tr.TestCase.FullyQualifiedName == expectedResult.TestCase.FullyQualifiedName); Assert.AreEqual(expectedResult.Outcome, actualResult.Outcome, expectedResult.TestCase.FullyQualifiedName + " had incorrect result"); if (expectedResult.ContainedErrorMessage != null) { Assert.IsNotNull(actualResult.ErrorMessage); Assert.IsTrue( actualResult.ErrorMessage.Contains(expectedResult.ContainedErrorMessage), string.Format("Error message did not contain expected text: {0}", expectedResult.ContainedErrorMessage) ); } else { Assert.IsNull(actualResult.ErrorMessage); } } }
private async Task RunTestsAsync( IEnumerable <string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle) { frameworkHandle.SendMessage( TestMessageLevel.Informational, string.Format("Persimmon Test Adapter {0} run tests started", version_)); try { var testExecutor = new TestExecutor(); var sink = new TestRunSink(runContext, frameworkHandle); var filteredSources = sources.Where(path => !excludeAssemblies_.Contains(Path.GetFileNameWithoutExtension(path))); // Register cancellation token. var cts = new CancellationTokenSource(); cancellationTokens_.Enqueue(cts); // Start tests. await Task.WhenAll(filteredSources.Select(targetAssemblyPath => testExecutor.RunAsync(targetAssemblyPath, new TestCase[0], sink, cts.Token))); } catch (Exception ex) { frameworkHandle.SendMessage( TestMessageLevel.Error, ex.ToString()); } finally { frameworkHandle.SendMessage( TestMessageLevel.Informational, string.Format("Persimmon Test Adapter {0} run tests finished", version_)); } }
private static void TestLoadError(string projectName) { // A load error is when unittest module fails to load the test (prior to running it) // For example, if the file where the test is defined has an unhandled ImportError. // We check that this only causes the tests that can't be loaded to fail, // all other tests in the test run which can be loaded successfully will be run. var executor = new TestExecutor(); var recorder = new MockTestExecutionRecorder(); var expectedTests = TestInfo.GetTestAdapterLoadErrorTests(projectName); var runContext = CreateRunContext(expectedTests); var testCases = expectedTests.Select(tr => tr.TestCase); executor.RunTests(testCases, runContext, recorder); PrintTestResults(recorder); var resultNames = recorder.Results.Select(tr => tr.TestCase.FullyQualifiedName).ToSet(); foreach (var expectedResult in expectedTests) { AssertUtil.ContainsAtLeast(resultNames, expectedResult.TestCase.FullyQualifiedName); var actualResult = recorder.Results.SingleOrDefault(tr => tr.TestCase.FullyQualifiedName == expectedResult.TestCase.FullyQualifiedName); Assert.AreEqual(expectedResult.Outcome, actualResult.Outcome, expectedResult.TestCase.FullyQualifiedName + " had incorrect result"); } }
public void ForcedFailureHasMessage() { // Set up a fake testing context. var framework = new MockFrameworkHandle(); // Execute all tests. TestExecutor executor = new TestExecutor(); executor.RunTests(Common.ReferenceExeList, new MockRunContext(), framework); // Map the tests by name. Dictionary <string, TestResult> resultsByName = new Dictionary <string, TestResult>(); foreach (var result in framework.Results) { resultsByName[result.TestCase.FullyQualifiedName] = result; } // Check that the test with a forced failure has the user-given message in the output. TestResult forcedFailure = resultsByName["Has forced failure"]; Assert.AreEqual(TestOutcome.Failed, forcedFailure.Outcome); Assert.IsTrue(forcedFailure.ErrorMessage.Contains("This message should be in the failure report.")); }
public static TestExecutor UseForcedTestExecutor(this TestExecutor executor) => executor.Use(async(context, next) => { try { if (context.CurrentCase.IsForced != null) { var result = context.CurrentCase.IsForced(); if (result) { await next().ConfigureAwait(false); } } else { await next().ConfigureAwait(false); } } catch (Exception exception) { context.CurrentCase.Exception = exception; context.CurrentCase.TestOutcome = TestOutcome.Failed; } });
public void GroupBy_AfterGroupBy() { var query = DB.Orders.GroupBy(o => o.Customer).GroupBy(c => c.Key.Country).Select(g => g.Key); TestExecutor.Execute(query, MethodBase.GetCurrentMethod()); }
public override void OnTestExecutionComplete(TestExecutor testExecutor, TestExecutionCompleteArgs args) { throw new NotImplementedException(); }
public async Task <ActionResult> GetIntegrationResultsAsync() { var testRunResults = await TestExecutor.ExecuteTests(typeof(BSSApiIntegrationTests)); return(Ok(testRunResults)); }
public void GroupBy_AfterDistinct() { var query = DB.Orders.Distinct().GroupBy(c => c.Customer).Select(g => g.Key.CustomerID); TestExecutor.Execute(query, MethodBase.GetCurrentMethod()); }
public void Distinct_BeforeSkipTake() { var query = DB.Orders.Select(o => o.Customer).Distinct().Skip(5).Take(2).Select(c => c.CustomerID); TestExecutor.Execute(query, MethodBase.GetCurrentMethod()); }
public async Task <ActionResult> GetDiscountResultsAsync() { var testRunResults = await TestExecutor.ComboExecuteTests <SuperStudentDiscountApiTestCase>(typeof(SuperStudentDiscountApiComboTests)); return(Ok(testRunResults)); }
public static TestExecutor UseTestGroupScope(this TestExecutor executor) => executor.UseGroup(async(context, next) => { context.CurrentScope.CurrentGroup = context.CurrentGroup; await next().ConfigureAwait(false); });
public void LinqToSqlStoredProc02() { ISingleResult <CustomersByCityResult> result = DB.CustomersByCity("London"); TestExecutor.Execute(result, MethodBase.GetCurrentMethod()); }
public void LinqToSqlStoredProc01() { int count = DB.CustomersCountByRegion("WA"); TestExecutor.Execute(count, MethodBase.GetCurrentMethod()); }
public void It_should_throw_an_ArgumentException() { var test = new TestExecutor(this); test.Assert(() => Assert.Fail("No exception has been thrown")); }
private void onBeginningTestExecution(TestExecutor testExecutor) { m_testOutputViewer.AppendText("Beginning execution\n\n"); m_testOutputViewer.ScrollToCaret(); m_executionTimer.Start(); }