PageRenderTime 32ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
C# | 136 lines | 107 code | 20 blank | 9 comment | 4 complexity | 0a87c98a18042508dc99c85f74ff0d3e MD5 | raw file
Possible License(s): BSD-2-Clause, Apache-2.0, GPL-2.0
  1. using System;
  2. using System.Collections.Generic;
  3. using FakeItEasy;
  4. using FluentAssertions;
  5. using Sidewinder.Core.Interfaces;
  6. using Sidewinder.Core.Interfaces.Entities;
  7. using Wolfpack.Contrib.Deployment;
  8. using Wolfpack.Core.Interfaces.Entities;
  9. using Wolfpack.Core.Notification.Filters.Request;
  10. using Wolfpack.Core.Testing;
  11. using Wolfpack.Core.Testing.Domains;
  12. using Wolfpack.Core;
  13. using System.Linq;
  14. namespace Wolfpack.Contrib.Tests.Publishers.Deployment
  15. {
  16. public abstract class DeploymentPublisherDomainBase<T> : SystemDomainBase
  17. where T: DeploymentConfig
  18. {
  19. public class BaseConfig
  20. {
  21. public const string NuGetPackageId = "TestPackage";
  22. public const string NuGetFeed = "http://some.nugetfeed.com";
  23. public const string TriggerHealthCheckId = "TriggerMessage";
  24. public const string DownloadFolder = "PackageDownload";
  25. }
  26. protected readonly NotificationEvent _triggerNotification;
  27. protected IPipelineStep<UpdaterContext> _updater;
  28. protected T _config;
  29. protected DeploymentPublisherDomainBase()
  30. {
  31. // message tag contains the name of the nuget package
  32. // property "Feed" contains the nuget feed
  33. // property "PreviousVersion" contains the existing version
  34. // property "NewVersion" contains the new version
  35. _triggerNotification = NotificationEventBuilder.From(
  36. new NotificationEventHealthCheck
  37. {
  38. CheckId = BaseConfig.TriggerHealthCheckId,
  39. Result = true,
  40. Tags = new List<string>()
  41. }).Build();
  42. _triggerNotification.Tags.AddIfMissing(BaseConfig.NuGetPackageId);
  43. TheUpdaterIndicatesUpdateAvailable();
  44. }
  45. protected void SetDeploymentBaseConfig(T config)
  46. {
  47. config.PackageId = BaseConfig.NuGetPackageId;
  48. config.Feed = BaseConfig.NuGetFeed;
  49. config.DownloadFolder = BaseConfig.DownloadFolder;
  50. config.TargetHealthCheckName = BaseConfig.TriggerHealthCheckId;
  51. if (_config == null)
  52. _config = config;
  53. }
  54. public void TheDownloadFolder(string folder)
  55. {
  56. _config.DownloadFolder = folder;
  57. }
  58. public void ThePublisherShouldOnlyPublishOnFailure()
  59. {
  60. _config.NotificationMode = FailureOnlyNotificationFilter.FilterName;
  61. }
  62. public void TheTriggerNotificationHasACriticalFailure()
  63. {
  64. _triggerNotification.CriticalFailure = true;
  65. }
  66. public void TheTriggerNotificationIndicatesFailure()
  67. {
  68. _triggerNotification.Result = false;
  69. }
  70. public void TheCheckNotificationShouldHaveProperty_WithValue_(string expectedKey, string expectedValue)
  71. {
  72. var notification = Agent.NotificationEvents.First(n => n.EventType == NotificationEventHealthCheck.EventTypeName);
  73. notification.Properties.ContainsKey(expectedKey).Should().BeTrue();
  74. notification.Properties[expectedKey].Should().Be(expectedValue);
  75. }
  76. public void TheCheckNotificationTagShouldBeTheSameAsTheTriggerMessageTag()
  77. {
  78. Agent.NotificationEvents.First(n => n.EventType == NotificationEventHealthCheck.EventTypeName)
  79. .Tags.Should().BeEquivalentTo(_triggerNotification.Tags);
  80. }
  81. //public void TheResultDataMessageShouldHaveTheDurationSet()
  82. //{
  83. // Agent.NotificationEvents.First(n => n.EventType == NotificationEventHealthCheck.EventTypeName)
  84. // .Duration > TimeSpan.Zero).Should().BeTrue();
  85. //}
  86. public void TheUpdaterIndicatesUpdateAvailable()
  87. {
  88. TheUpdaterReturns_(true);
  89. }
  90. public void TheUpdaterIndicatesNoUpdateAvailable()
  91. {
  92. TheUpdaterReturns_(false);
  93. }
  94. public void TheUpdaterShouldNotHaveBeenCalled()
  95. {
  96. A.CallTo(() => _updater.Execute(A<UpdaterContext>.Ignored)).MustNotHaveHappened();
  97. }
  98. private void TheUpdaterReturns_(bool result)
  99. {
  100. _updater = A.Fake<IPipelineStep<UpdaterContext>>();
  101. A.CallTo(() => _updater.Execute(A<UpdaterContext>.Ignored))
  102. .Invokes(call =>
  103. {
  104. var context = (UpdaterContext) call.Arguments[0];
  105. context.Updates.Add(new UpdatedPackage
  106. {
  107. Target =
  108. context.Config.TargetPackages[BaseConfig.NuGetPackageId
  109. ],
  110. NewVersion = new Version(9, 9, 9, 9)
  111. });
  112. })
  113. .Returns(result);
  114. }
  115. }
  116. }