protected override bool Visit(ITestSkipped testSkipped) { var testCase = testCases.Single(tc => tc.DisplayName == testSkipped.TestCase.DisplayName); testCase.State = TestState.Skipped; TestFinished?.Invoke(this, TestStateEventArgs.Skipped); return(!isCancelRequested()); }
private async Task TestConnection(ConnectionData connectionData) { ReportConnectionTestStarted(); var failed = false; if (connectionData.ConnectionType == ConnectionPluginType.Build) { var buildPlugin = _pluginRepository.FindBuildPlugin(connectionData.PluginType); if (buildPlugin == null) { ReportError("ConnectionTestFailed", "NoConnectionSetup"); failed = true; } if (buildPlugin != null && connectionData.PluginConfiguration != null) { var buildResult = await buildPlugin.TestConnection(connectionData.PluginConfiguration); if (!buildResult.IsSuccess) { failed = true; ReportError("BuildConnectionTestFailed", buildResult.ErrorMessage); } } } else if (connectionData.ConnectionType == ConnectionPluginType.SourceControl) { var sourcePlugin = _pluginRepository.FindSourceControlPlugin(connectionData.PluginType); if (sourcePlugin == null) { ReportError("ConnectionTestFailed", "NoConnectionSetup"); failed = true; } if (sourcePlugin != null && connectionData.PluginConfiguration != null) { var sourceResult = await sourcePlugin.TestConnection(connectionData.PluginConfiguration); if (!sourceResult.IsSuccess) { failed = true; ReportError("SourceConnectionTestFailed", sourceResult.ErrorMessage); } } } if (!failed) { ReportSuccess(); } DispatchOnUiThread(() => { TestFinished?.Invoke(this, EventArgs.Empty); }); }
public void Run() { try { IMGAlgoritm mgAlgoritm = new CLMGAlgoritm(SettingGen); DbMap outDbMap; string message; Stopwatch stopwatch = new Stopwatch(); stopwatch.Reset(); stopwatch.Start(); bool isSuccess = mgAlgoritm.Execute(Scale, DbMap, out outDbMap, out message); stopwatch.Stop(); TestResult testResult = new TestResult { IdTestCase = Id, Time = stopwatch.ElapsedMilliseconds, IsSuccess = isSuccess }; string dirResultTests = $"{ResourceModel.DIR_TESTS}\\Test_{Id}"; if (!Directory.Exists(dirResultTests)) { Directory.CreateDirectory(dirResultTests); } // Отрисовываем исходную карту. Methods.DeleteAllElementsOnDirectry(dirResultTests); DbMap.DrawToBMP($"{dirResultTests}\\{ResourceModel.FILENAME_BEFORE_BMP}"); // Отрисовываем результирующую карту. DbMap.DrawToBMP(mgAlgoritm.Clusters, $"{dirResultTests}\\{ResourceModel.FILENAME_AFTER_BMP}"); // Сохраняем в файл результаты теста с настройкой. string distScaleInfo = $"Масштаб теста: 1:{Scale}"; string testInfo = $"{DbMap}\n{distScaleInfo}\n{SettingGen}\n{testResult}"; File.WriteAllText($"{dirResultTests}\\{ResourceModel.FILENAME_TESTINFO}", testInfo); TestFinished?.Invoke(testResult); } catch (Exception ex) { } }
public void RunTests() { var project = GetProject(FilePath); var targetPath = project.GetPropertyValue("TargetPath"); var eventListener = new TestRunnerListener( (i) => TestRunFinishedWithException.Raise(this, i), (i) => TestRunFinishedWithResult.Raise(this, i), (i, j) => TestRunStarted.Raise(this, i, j), (i) => TestSuiteFinished.Raise(this, i), (i) => TestSuiteStarted.Raise(this, i), (i) => TestFinished.Raise(this, i), (i) => TestOutput.Raise(this, i), (i) => TestStarted.Raise(this, i), (i) => TestUnhandledException.Raise(this, i)); var testRunner = new TestRunner(targetPath, eventListener); testRunner.Run(); }
protected override bool Visit(ITestFailed testFailed) { var testCase = testCases.Single(tc => tc.DisplayName == testFailed.TestCase.DisplayName); testCase.State = TestState.Failed; var resultString = new StringBuilder(testFailed.TestCase.DisplayName); resultString.AppendLine(" FAILED:"); for (int i = 0; i < testFailed.ExceptionTypes.Length; i++) { resultString.AppendLine($"\tException type: '{testFailed.ExceptionTypes[i]}', number: '{i}', parent: '{testFailed.ExceptionParentIndices[i]}'"); resultString.AppendLine($"\tException message:"); resultString.AppendLine(testFailed.Messages[i]); resultString.AppendLine($"\tException stacktrace"); resultString.AppendLine(testFailed.StackTraces[i]); } resultString.AppendLine(); TestFinished?.Invoke(this, TestStateEventArgs.Failed(resultString.ToString())); return(!isCancelRequested()); }
void OnTestCase(XElement xml) { var testResult = ParseTestResult(xml); string output = null; if (testResult.Messages.Count > 0) { output = testResult.Messages[0]; } else if (testResult.Outcome != TestOutcome.None) { output = testResult.Outcome.ToString(); } TestFinished?.Invoke(this, new TestEventArgs(testResult.Test.FullyQualifiedName, output)); if (Options.DesignTime) { _sink?.SendTestResult(testResult); } }
public bool BeforeFinished(IMessageBus messageBus, TestFinished message) { var testMethod = message.TestMethod.Method.ToRuntimeMethod(); foreach (BeforeCtorAfterDisposeAttribute beforeAfterTestCaseAttribute in _attributesStack) { try { _timer.Aggregate(() => beforeAfterTestCaseAttribute.After(testMethod)); } catch (Exception e) { _exceptions.Add(e); } } if (_exceptions.Any()) { return(messageBus.QueueMessage(new TestCleanupFailure(message.Test, new AggregateException(_exceptions)))); } return(true); }
public void OnTestEvent(string report) { XmlNode xmlNode = XmlHelper.CreateXmlNode(report); switch (xmlNode.Name) { case "start-test": TestStarting?.Invoke(new TestNodeEventArgs(TestAction.TestStarting, new TestNode(xmlNode))); break; case "start-suite": SuiteStarting?.Invoke(new TestNodeEventArgs(TestAction.SuiteStarting, new TestNode(xmlNode))); break; case "start-run": RunStarting?.Invoke(new RunStartingEventArgs(xmlNode.GetAttribute("count", -1))); break; case "test-case": ResultNode result = new ResultNode(xmlNode); _resultIndex[result.Id] = result; TestFinished?.Invoke(new TestResultEventArgs(TestAction.TestFinished, result)); break; case "test-suite": result = new ResultNode(xmlNode); _resultIndex[result.Id] = result; SuiteFinished?.Invoke(new TestResultEventArgs(TestAction.SuiteFinished, result)); break; case "test-run": result = new ResultNode(xmlNode); _resultIndex[result.Id] = result; RunFinished?.Invoke(new TestResultEventArgs(TestAction.RunFinished, result)); break; } }
protected override async Task <RunSummary> RunTestAsync() { var scenarioFactTestCase = (ScenarioFactTestCase)TestCase; var test = CreateTest(TestCase, DisplayName); var aggregatedResult = new RunSummary(); // Theories are called with required arguments. Keep track of what arguments we already tested so that we can skip those accordingly var testedArguments = new HashSet <object>(); // Each time we find a new theory argument, we will want to restart our Test so that we can collect subsequent test cases bool pendingRestart; do { // Safeguarding against abuse if (testedArguments.Count >= scenarioFactTestCase.TheoryTestCaseLimit) { pendingRestart = false; MessageBus.QueueMessage(new TestSkipped(test, "Theory tests are capped to prevent infinite loops. You can configure a different limit by setting TheoryTestCaseLimit on the Scenario attribute")); aggregatedResult.Aggregate(new RunSummary { Skipped = 1, Total = 1 }); } else { var bufferedMessageBus = new BufferedMessageBus(MessageBus); var stopwatch = Stopwatch.StartNew(); var skipAdditionalTests = false; var testRecorded = false; pendingRestart = false; // By default we dont expect a new restart object? capturedArgument = null; ScenarioContext scenarioContext = null; scenarioContext = new ScenarioContext(scenarioFactTestCase.FactName, async(ScenarioTestCaseDescriptor descriptor) => { // If we're hitting our target test if (descriptor.Name == scenarioFactTestCase.FactName) { testRecorded = true; if (skipAdditionalTests) { pendingRestart = true; // when we discovered more tests after a test completed, allow us to restart scenarioContext.EndScenarioConditionally(); return; } if (descriptor.Argument is not null) { // If we've already received this test case, don't run it again if (testedArguments.Contains(descriptor.Argument)) { return; } testedArguments.Add(descriptor.Argument); capturedArgument = descriptor.Argument; } // At this stage we found our first valid test case, any subsequent test case should issue a restart instead skipAdditionalTests = true; try { await descriptor.Invocation(); } catch (Exception) { // If we caught an exception but we're in a theory, we will want to try for additional test cases if (descriptor.Argument is not null) { pendingRestart = true; } throw; } finally { scenarioContext.IsTargetConclusive = true; } } else { // We may be hitting a shared fact, those need to be invoked as well but not recorded as our primary target if (!scenarioFactTestCase.RunInIsolation || descriptor.Flags.HasFlag(ScenarioTestCaseFlags.Shared)) { await descriptor.Invocation(); } } }); scenarioContext.AutoAbort = scenarioFactTestCase.ExecutionPolicy is ScenarioTestExecutionPolicy.EndAfterConclusion; TestMethodArguments = new object[] { scenarioContext }; RunSummary result; result = await CreateTestRunner(test, bufferedMessageBus, TestClass, ConstructorArguments, TestMethod, TestMethodArguments, SkipReason, BeforeAfterAttributes, Aggregator, CancellationTokenSource).RunAsync(); aggregatedResult.Aggregate(result); stopwatch.Stop(); var testInvocationTest = capturedArgument switch { null => CreateTest(TestCase, DisplayName), not null => CreateTest(TestCase, $"{DisplayName} ({capturedArgument})") }; var bufferedMessages = bufferedMessageBus.QueuedMessages; // We should have expected at least one test run. We probably returned before our target test was able to run if (!testRecorded && result.Failed == 0) { bufferedMessageBus.QueueMessage(new TestSkipped(test, scenarioContext.SkippedReason ?? "No applicable tests were able to run")); result = new RunSummary { Skipped = 1, Total = 1 }; } // If we skipped this test, make sure that this is reported accordingly if (scenarioContext.Skipped && !bufferedMessages.OfType <TestSkipped>().Any()) { bufferedMessages = bufferedMessages.Concat(new[] { new TestSkipped(testInvocationTest, scenarioContext.SkippedReason) }); } // If we have indeed skipped this test, make sure that we're not reporting it as passed or failed if (bufferedMessages.OfType <TestSkipped>().Any()) { bufferedMessages = bufferedMessages.Where(x => x is not TestPassed and not TestFailed); } // If we have a failure in post conditions, don't mark this test case as passed if (bufferedMessages.OfType <TestFailed>().Any()) { bufferedMessages = bufferedMessages.Where(x => x is not TestPassed); } var output = string.Join("", bufferedMessages .OfType <ITestOutput>() .Select(x => x.Output)); var duration = (decimal)stopwatch.Elapsed.TotalSeconds; foreach (var queuedMessage in bufferedMessages) { var transformedMessage = queuedMessage switch { TestStarting testStarting => new TestStarting(testInvocationTest), TestSkipped testSkipped => new TestSkipped(testInvocationTest, testSkipped.Reason), TestPassed testPassed => new TestPassed(testInvocationTest, duration, output), TestFailed testFailed => new TestFailed(testInvocationTest, duration, output, testFailed.ExceptionTypes, testFailed.Messages, testFailed.StackTraces, testFailed.ExceptionParentIndices), TestFinished testFinished => new TestFinished(testInvocationTest, duration, output), _ => queuedMessage }; if (!MessageBus.QueueMessage(transformedMessage)) { return(aggregatedResult); } } } }while (pendingRestart); return(aggregatedResult); } } }
private void OnTestFinished(object sender, System.EventArgs e) { TestFinished?.Invoke(sender, e); }
private void TestFinishedAction(TestResult testResult) { TestFinished?.Invoke(testResult); }
private void OnTestFinished(System.EventArgs e) { TestFinished?.Invoke(this, e); }
protected virtual void OnTestFinished(UnitTestResultEventArgs e) => TestFinished?.Invoke(this, e);
public async Task Start(Uri targetUri) { if (!(await IsRemoteServerAlive(targetUri))) { throw new WebException("No response from external server"); } resultDetails = new ConcurrentBag <TestResultDetail>(); processedPages = new ConcurrentDictionary <string, byte>(); result = new TestResult() { Authority = targetUri.AbsoluteUri, TestDate = DateTime.Now, Status = 1 }; RepositoryInsertRequested?.Invoke(this, new TestResultArgs(result)); CrawlConfiguration configuration = new CrawlConfiguration() { MaxPagesToCrawl = MaxPagesToCrawl, MaxCrawlDepth = MaxCrawlDepth, IsExternalPageCrawlingEnabled = IsExternalPageCrawlingEnabled, IsExternalPageLinksCrawlingEnabled = IsExternalPageLinksCrawlingEnabled, NumberOfRecurrentRequests = NumberOfRecurrentRequests, MaxConcurrentThreads = MaxConcurrentThreads }; PoliteWebCrawler crawler = new PoliteWebCrawler(configuration, crawlDecisionMaker: null, memoryManager: null, scheduler: null, hyperLinkParser: null, domainRateLimiter: null, robotsDotTextFinder: null, threadManager: null, pageRequester: new PageRequesterWithRepeats(configuration)); crawler.PageRequestSent += Crawler_PageRequestSent; crawler.PageResponseReceived += Crawler_PageResponseReceived; crawler.PageCrawlCompleted += Crawler_ProcessPageCrawlCompleted; crawler.ShouldCrawlPage((pageToCrawl, crawlContext) => { CrawlDecision decision = new CrawlDecision { Allow = true }; MatchCollection mc = Regex.Matches((pageToCrawl.Uri.AbsoluteUri), @"http[s]?:\/\/"); if (mc.Count > 1) { return new CrawlDecision { Allow = false, Reason = "Dont want to crawl external pages" } } ; return(decision); }); TestStarted?.Invoke(this, new TestResultArgs(result)); crawler.Crawl(targetUri); result.TestResultDetails = resultDetails.ToList(); result.MinResponseTime = rootMinResponseTime; result.MaxResponseTime = rootMaxResponseTime; result.MeanResponseTime = rootMeanResponseTime / numberOfPagesCrawled; result.Status = 0; TestFinished?.Invoke(this, new TestResultArgs(result)); RepositoryInsertDetailsRequested?.Invoke(this, new TestResultArgs(result)); }
public void Start(TestResult root) { using (HttpClient client = new HttpClient()) { var testBlock = new ActionBlock <TestResultDetail>(async item => { Stopwatch timer = new Stopwatch(); double mean = 0; for (int i = 1; i <= NumberOfRecurrentRequests; ++i) { timer.Start(); await client.GetAsync(item.Uri); timer.Stop(); long responseTime = timer.ElapsedMilliseconds; timer.Reset(); if (i == 1) { ProcessFirstItem(item, responseTime); } else { ProcessItem(item, responseTime); } mean += responseTime / NumberOfRecurrentRequests; } item.MeanResponseTime = mean; PageTestingCompleted?.Invoke(this, new PageTestingCompletedArgs(item)); lock (mainLock) { rootMeanResponseTime += item.MeanResponseTime; if (item.MinResponseTime < rootMinResponseTime) { rootMinResponseTime = item.MinResponseTime; } if (item.MaxResponseTime > rootMaxResponseTime) { rootMaxResponseTime = item.MaxResponseTime; } } }, new ExecutionDataflowBlockOptions() { MaxDegreeOfParallelism = MaxConcurrentThreads }); foreach (var item in root.TestResultDetails) { testBlock.Post(item); } testBlock.Complete(); root.TestDate = DateTime.Now; root.Status = 1; RepositoryUpdateRequested?.Invoke(this, new TestResultArgs(root)); TestStarted?.Invoke(this, new TestResultArgs(root)); testBlock.Completion.Wait(); } root.MinResponseTime = rootMinResponseTime; root.MaxResponseTime = rootMaxResponseTime; root.MeanResponseTime = rootMeanResponseTime / root.TestResultDetails.Count; root.Status = 0; TestFinished?.Invoke(this, new TestResultArgs(root)); RepositoryUpdateRequested?.Invoke(this, new TestResultArgs(root)); }
private void TestFinishedHandler(TestResult testResult) { TestFinished?.Invoke(testResult); }
private void OnTestFinished() { TestFinished? .Invoke(this, EventArgs.Empty); }