PageRenderTime 64ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Solutions/Wolfpack.Core.Testing/Domains/SystemDomainBase.cs

#
C# | 127 lines | 100 code | 23 blank | 4 comment | 5 complexity | 913099bd2cba9b01a27e6f2f55a5f8d1 MD5 | raw file
Possible License(s): Apache-2.0, BSD-2-Clause, BSD-3-Clause, GPL-2.0, MIT
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using Wolfpack.Core.Artifacts;
  6. using Wolfpack.Core.Artifacts.Formats;
  7. using Wolfpack.Core.Interfaces;
  8. using Wolfpack.Core.Interfaces.Entities;
  9. using Wolfpack.Core.Notification.Filters.Request;
  10. using Wolfpack.Core.Testing.Bdd;
  11. using Wolfpack.Core.Testing.Drivers;
  12. using FluentAssertions;
  13. namespace Wolfpack.Core.Testing.Domains
  14. {
  15. /// <summary>
  16. /// This provides a base class that exposes the core wolfpack system
  17. /// </summary>
  18. public abstract class SystemDomainBase : BddTestDomain
  19. {
  20. public const string ArtifactBaseFolder = "_artifacts";
  21. protected readonly IList<IArtifactFormatter> _formatters;
  22. protected AutomationProfile Agent { get { return _automatedAgent; } }
  23. private readonly AutomationProfile _automatedAgent;
  24. private IArtifactManager _artifactManager;
  25. private IConfigurationManager _configurationManager;
  26. protected SystemDomainBase()
  27. {
  28. _automatedAgent = AutomationProfile.Configure();
  29. _formatters = new List<IArtifactFormatter>();
  30. }
  31. public override void Dispose()
  32. {
  33. // override this to perform something at the end of the test
  34. TheAgentIsStopped();
  35. }
  36. public void ThereShouldBe_SessionMessagesPublished(int expected)
  37. {
  38. Agent.NotificationEvents.Count(ne => ne.EventType == NotificationEventAgentStart.EventTypeName).Should().Be(expected);
  39. }
  40. public void ThereShouldBe_HealthCheckNotificationsReceived(int expected)
  41. {
  42. Agent.NotificationEvents.Count(ne => ne.EventType == NotificationEventHealthCheck.EventTypeName).Should().Be(expected);
  43. }
  44. public void ThereShouldBe_NotificationRequestMessagesOfType_Published(int expected, string type)
  45. {
  46. Agent.NotificationRequests.Count(m => m.Notification.EventType.Equals(type, StringComparison.OrdinalIgnoreCase))
  47. .Should().Be(expected);
  48. }
  49. public void TheNotificationRequestAtIndex_ShouldHaveResult_(int index, bool expected)
  50. {
  51. Agent.NotificationRequests[index].Notification.Result.Should().Be(expected);
  52. }
  53. public void TheNotificationRecievedAtIndex_ShouldHaveResult_(int index, bool expected)
  54. {
  55. Agent.NotificationEvents[index].Result.Should().Be(expected);
  56. }
  57. public void TheNotificationReceivedAtIndex_ShouldHaveResultCount_(int index, double expected)
  58. {
  59. Agent.NotificationEvents[index].ResultCount.Value.Should().BeInRange(expected, expected);
  60. }
  61. public void TheDefaultNotificationFiltersAreLoaded()
  62. {
  63. Agent.Run(new FailureOnlyNotificationFilter(),
  64. new StateChangeNagFailNotificationFilter(),
  65. new StateChangeNotificationFilter(),
  66. new SuccessOnlyNotificationFilter());
  67. }
  68. public void TheAgentIsStarted()
  69. {
  70. if (_artifactManager == null)
  71. TheDefaultArtifactManagerIsLoaded();
  72. Agent.Start();
  73. }
  74. public void TheAgentIsStopped()
  75. {
  76. Agent.Stop();
  77. }
  78. public void TheCheckArtifactsArePurged(string checkName)
  79. {
  80. var path = Path.Combine(ArtifactBaseFolder, checkName);
  81. if (!Directory.Exists(path))
  82. return;
  83. foreach (var file in Directory.GetFiles(path))
  84. {
  85. File.Delete(file);
  86. }
  87. }
  88. public void ThereShouldBe_ArtifactFilesForCheck_(int expected, string checkName)
  89. {
  90. Directory.GetFiles(Path.Combine(ArtifactBaseFolder, checkName)).Count().Should().Be(expected);
  91. }
  92. public void TheDefaultConfigurationManagerIsLoaded()
  93. {
  94. Agent.Run(new AutomationConfigurationManager());
  95. }
  96. public void TheDefaultArtifactManagerIsLoaded()
  97. {
  98. _formatters.Add(new TabSeparatedFormatter());
  99. _formatters.Add(new JsonFormatter());
  100. _artifactManager = new FileSystemArtifactManager(ArtifactBaseFolder, _formatters);
  101. ArtifactManager.Initialise(_artifactManager);
  102. }
  103. }
  104. }