PageRenderTime 60ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/Tests/TechTalk.SpecFlow.Specs/StepDefinitions/ExecutionResultSteps.cs

http://github.com/techtalk/SpecFlow
C# | 115 lines | 98 code | 17 blank | 0 comment | 0 complexity | 93f9c6c73e12a70b276851be8ef50776 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using FluentAssertions;
  6. using TechTalk.SpecFlow.Assist;
  7. using TechTalk.SpecFlow.TestProjectGenerator;
  8. using TechTalk.SpecFlow.TestProjectGenerator.Driver;
  9. using TechTalk.SpecFlow.TestProjectGenerator.Helpers;
  10. namespace TechTalk.SpecFlow.Specs.StepDefinitions
  11. {
  12. [Binding]
  13. public class ExecutionResultSteps
  14. {
  15. private readonly HooksDriver _hooksDriver;
  16. private readonly VSTestExecutionDriver _vsTestExecutionDriver;
  17. private readonly TestProjectFolders _testProjectFolders;
  18. private readonly TestRunLogDriver _testRunLogDriver;
  19. public ExecutionResultSteps(HooksDriver hooksDriver, VSTestExecutionDriver vsTestExecutionDriver, TestProjectFolders testProjectFolders, TestRunLogDriver testRunLogDriver)
  20. {
  21. _hooksDriver = hooksDriver;
  22. _vsTestExecutionDriver = vsTestExecutionDriver;
  23. _testProjectFolders = testProjectFolders;
  24. _testRunLogDriver = testRunLogDriver;
  25. }
  26. [Then(@"the tests were executed successfully")]
  27. [Then(@"all tests should pass")]
  28. [Then(@"the scenario should pass")]
  29. public void ThenAllTestsShouldPass()
  30. {
  31. _vsTestExecutionDriver.LastTestExecutionResult.Should().NotBeNull();
  32. _vsTestExecutionDriver.LastTestExecutionResult.Succeeded.Should().Be(_vsTestExecutionDriver.LastTestExecutionResult.Total);
  33. }
  34. [Then(@"the execution summary should contain")]
  35. public void ThenTheExecutionSummaryShouldContain(Table expectedTestExecutionResult)
  36. {
  37. _vsTestExecutionDriver.LastTestExecutionResult.Should().NotBeNull();
  38. expectedTestExecutionResult.CompareToInstance(_vsTestExecutionDriver.LastTestExecutionResult);
  39. }
  40. [Then(@"the binding method '(.*)' is executed")]
  41. public void ThenTheBindingMethodIsExecuted(string methodName)
  42. {
  43. ThenTheBindingMethodIsExecuted(methodName, 1);
  44. }
  45. [Then(@"the binding method '(.*)' is executed (.*)")]
  46. public void ThenTheBindingMethodIsExecuted(string methodName, int times)
  47. {
  48. _vsTestExecutionDriver.CheckIsBindingMethodExecuted(methodName, times);
  49. }
  50. [Then(@"the hook '(.*)' is executed (\D.*)")]
  51. [Then(@"the hook '(.*)' is executed (\d+) times")]
  52. public void ThenTheHookIsExecuted(string methodName, int times)
  53. {
  54. _hooksDriver.CheckIsHookExecuted(methodName, times);
  55. }
  56. [Then(@"the hooks are executed in the order")]
  57. public void ThenTheHooksAreExecutedInTheOrder(Table table)
  58. {
  59. _hooksDriver.CheckIsHookExecutedInOrder(table.Rows.Select(r => r[0]));
  60. }
  61. [Then(@"the execution log should contain text '(.*)'")]
  62. public void ThenTheExecutionLogShouldContainText(string text)
  63. {
  64. _vsTestExecutionDriver.CheckAnyOutputContainsText(text);
  65. }
  66. [Then(@"the output should contain text '(.*)'")]
  67. public void ThenTheOutputShouldContainText(string text)
  68. {
  69. _vsTestExecutionDriver.CheckOutputContainsText(text);
  70. }
  71. [Then(@"the log file '(.*)' should contain text '(.*)'")]
  72. public void ThenTheLogFileShouldContainText(string logFilePath, string text)
  73. {
  74. _testRunLogDriver.CheckLogContainsText(text, logFilePath);
  75. }
  76. [Then(@"the log file '(.*)' should contain the text '(.*)' (\d+) times")]
  77. public void ThenTheLogFileShouldContainTheTextTimes(string logFilePath, string regexString, int times)
  78. {
  79. _testRunLogDriver.CheckLogMatchesRegexTimes(regexString, times, logFilePath);
  80. }
  81. private string GetPath(string logFilePath)
  82. {
  83. string filePath = Path.Combine(_testProjectFolders.ProjectFolder, logFilePath);
  84. return filePath;
  85. }
  86. [Then(@"every scenario has it's individual context id")]
  87. public void ThenEveryScenarioHasItSIndividualContextId()
  88. {
  89. var lastTestExecutionResult = _vsTestExecutionDriver.LastTestExecutionResult;
  90. foreach (var testResult in lastTestExecutionResult.TestResults)
  91. {
  92. var contextIdLines = testResult.StdOut.SplitByString(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries).Where(s => s.Contains("Context ID"));
  93. var distinctContextIdLines = contextIdLines.Distinct();
  94. distinctContextIdLines.Count().Should().Be(1);
  95. }
  96. }
  97. }
  98. }