PageRenderTime 48ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/Solutions/Wolfpack.Contrib.Tests/Publishers/Deployment/NUnitDeploymentPublisherDomain.cs

#
C# | 167 lines | 135 code | 32 blank | 0 comment | 1 complexity | 318e79f5bc9b26f55942f5a033fdff90 MD5 | raw file
Possible License(s): BSD-2-Clause, Apache-2.0, GPL-2.0
  1. using System.Diagnostics;
  2. using System.Linq;
  3. using FakeItEasy;
  4. using FluentAssertions;
  5. using Wolfpack.Contrib.Deployment;
  6. using Wolfpack.Contrib.Deployment.Exe;
  7. using Wolfpack.Contrib.Deployment.NUnit;
  8. using Wolfpack.Core.Interfaces.Entities;
  9. namespace Wolfpack.Contrib.Tests.Publishers.Deployment
  10. {
  11. public class NUnitDeploymentPublisherDomain : DeploymentPublisherDomainBase<NUnitDeploymentConfig>
  12. {
  13. public const string ExpectedXmlResultsFile = @"c:\testing\results\testresults.xml";
  14. private readonly IProcessLauncher _launcher;
  15. private ProcessStartInfo _actualLauncherProcessArg;
  16. private int _launcherResult;
  17. private NUnitResult _testResult;
  18. private string _actualTestResultFile;
  19. private INUnitResultFileParser _parser;
  20. public NUnitDeploymentPublisherDomain()
  21. {
  22. SetDeploymentBaseConfig(_config = new NUnitDeploymentConfig
  23. {
  24. ResultsFile = ExpectedXmlResultsFile,
  25. Command = @"nunit-console-x86.exe UnderTest\Wolfpack.Contrib.nunit /xml=UnderTest\wolfpack.contrib.results.xml"
  26. });
  27. _testResult = new NUnitResult();
  28. _launcher = A.Fake<IProcessLauncher>();
  29. }
  30. public void TheUnitTestResultContainsNoFailuresErrorsOrInvalidTests()
  31. {
  32. _testResult.Errors = 0;
  33. _testResult.Failures = 0;
  34. _testResult.Invalid = 0;
  35. }
  36. public void TheDataMessageShouldContainTheTestResultAsProperties()
  37. {
  38. var msg = Agent.NotificationEvents.First(n => n.EventType == NotificationEventHealthCheck.EventTypeName);
  39. typeof(NUnitResult).GetProperties().ToList()
  40. .ForEach(pi => msg.Properties.ContainsKey(pi.Name).Should().BeTrue());
  41. }
  42. public void TheFilenameTheParserIsCalledWithIsTheSameAsTheConfig()
  43. {
  44. _actualTestResultFile.Should().Be(ExpectedXmlResultsFile);
  45. }
  46. public void TheUnitTestResultFailuresIsSetTo_(int count)
  47. {
  48. _testResult.Failures = count;
  49. }
  50. public void TheUnitTestResultErrorsIsSetTo_(int count)
  51. {
  52. _testResult.Errors = count;
  53. }
  54. public void TheXmlFileParserWithResultFile(string filename)
  55. {
  56. _parser = new NUnitXmlResultFileParser();
  57. _actualTestResultFile = filename;
  58. }
  59. public void TheParserIsInvoked()
  60. {
  61. _testResult = _parser.Parse(_actualTestResultFile);
  62. }
  63. public void TheUnitResultShouldBeValid()
  64. {
  65. _testResult.Should().NotBeNull();
  66. }
  67. public void TheUnitTestResultShouldHave_Errors(int expected)
  68. {
  69. _testResult.Errors.Should().Be(expected);
  70. }
  71. public void TheUnitTestResultShouldHave_Failures(int expected)
  72. {
  73. _testResult.Failures.Should().Be(expected);
  74. }
  75. public void TheUnitTestResultShouldHave_NotRun(int expected)
  76. {
  77. _testResult.NotRun.Should().Be(expected);
  78. }
  79. public void TheUnitTestResultShouldHave_Inconclusive(int expected)
  80. {
  81. _testResult.Inconclusive.Should().Be(expected);
  82. }
  83. public void TheUnitTestResultShouldHave_Ignored(int expected)
  84. {
  85. _testResult.Ignored.Should().Be(expected);
  86. }
  87. public void TheUnitTestResultShouldHave_Skipped(int expected)
  88. {
  89. _testResult.Skipped.Should().Be(expected);
  90. }
  91. public void TheUnitTestResultShouldHave_Invalid(int expected)
  92. {
  93. _testResult.Invalid.Should().Be(expected);
  94. }
  95. public void TheUnitTestResultShouldHave_Total(int expected)
  96. {
  97. _testResult.Total.Should().Be(expected);
  98. }
  99. public void ThePublisherIsCalled()
  100. {
  101. A.CallTo(() => _launcher.Launch(A<ProcessStartInfo>.Ignored))
  102. .Invokes(call =>
  103. {
  104. _actualLauncherProcessArg = (ProcessStartInfo)call.Arguments[0];
  105. })
  106. .Returns(_launcherResult);
  107. var fakeParser = A.Fake<INUnitResultFileParser>();
  108. A.CallTo(() => fakeParser.Parse(A<string>.Ignored))
  109. .Invokes(call =>
  110. {
  111. _actualTestResultFile = call.Arguments[0].ToString();
  112. })
  113. .Returns(_testResult);
  114. var sut = new NUnitDeploymentPublisher(_config)
  115. {
  116. Launcher = _launcher,
  117. Updater = _updater,
  118. ResultParser = fakeParser
  119. };
  120. sut.Consume(_triggerNotification);
  121. }
  122. public void TheCommandLine_(string cmd)
  123. {
  124. _config.Command = cmd;
  125. }
  126. public void TheLauncherIndicatesSuccess()
  127. {
  128. _launcherResult = 0;
  129. }
  130. public void TheLauncherReturnsErrorCode_(int errorCode)
  131. {
  132. _launcherResult = errorCode;
  133. }
  134. }
  135. }