From 13a5e06eb8c4cae3a634e2f848ceb7917fda2bef Mon Sep 17 00:00:00 2001 From: Edwin Kortman Date: Mon, 12 Sep 2022 13:39:02 +0200 Subject: [PATCH] ManifestDetectedEvent dispatches GenerateBillOfMaterialsActivity --- .../Analysis/ManifestDetectedEventTest.cs | 37 +++++++++++++++++++ .../GenerateBillOfMaterialsActivityTest.cs | 6 +-- .../Analysis/ManifestDetectedEvent.cs | 8 +++- .../GenerateBillOfMaterialsActivity.cs | 23 +++++------- 4 files changed, 53 insertions(+), 21 deletions(-) create mode 100644 Corgibytes.Freshli.Cli.Test/Functionality/Analysis/ManifestDetectedEventTest.cs diff --git a/Corgibytes.Freshli.Cli.Test/Functionality/Analysis/ManifestDetectedEventTest.cs b/Corgibytes.Freshli.Cli.Test/Functionality/Analysis/ManifestDetectedEventTest.cs new file mode 100644 index 000000000..72803e307 --- /dev/null +++ b/Corgibytes.Freshli.Cli.Test/Functionality/Analysis/ManifestDetectedEventTest.cs @@ -0,0 +1,37 @@ +using System; +using Corgibytes.Freshli.Cli.Functionality.Analysis; +using Corgibytes.Freshli.Cli.Functionality.BillOfMaterials; +using Corgibytes.Freshli.Cli.Functionality.Engine; +using Corgibytes.Freshli.Cli.Services; +using Moq; +using Xunit; + +namespace Corgibytes.Freshli.Cli.Test.Functionality.Analysis; + +[UnitTest] +public class ManifestDetectedEventTest +{ + [Fact] + public void CorrectlyDispatchesGenerateBillOfMaterialsActivity() + { + var manifestPath = "/path/to/manifest"; + var billOfMaterialsPath = "/path/to/bom"; + var analysisLocation = new AnalysisLocation("/cache/directory", "2dbc2fd2358e1ea1b7a6bc08ea647b9a337ac92d", + "da39a3ee5e6b4b0d3255bfef95601890afd80709"); + + var javaAgentReader = new Mock(); + + javaAgentReader.Setup(mock => mock.ProcessManifest(manifestPath, It.IsAny())).Returns(billOfMaterialsPath); + + var engine = new Mock(); + + var manifestEvent = new ManifestDetectedEvent(analysisLocation, javaAgentReader.Object, manifestPath); + manifestEvent.Handle(engine.Object); + + engine.Verify(mock => mock.Dispatch(It.Is(value => + value.AnalysisLocation == analysisLocation && + value.ManifestPath == manifestPath && + value.AgentReader == javaAgentReader.Object + ))); + } +} diff --git a/Corgibytes.Freshli.Cli.Test/Functionality/BillOfMaterials/GenerateBillOfMaterialsActivityTest.cs b/Corgibytes.Freshli.Cli.Test/Functionality/BillOfMaterials/GenerateBillOfMaterialsActivityTest.cs index 64ffe3280..21a83dade 100644 --- a/Corgibytes.Freshli.Cli.Test/Functionality/BillOfMaterials/GenerateBillOfMaterialsActivityTest.cs +++ b/Corgibytes.Freshli.Cli.Test/Functionality/BillOfMaterials/GenerateBillOfMaterialsActivityTest.cs @@ -14,19 +14,15 @@ public class GenerateBillOfMaterialsActivityTest public void Handle() { // Arrange - var agentManager = new Mock(); var javaAgentReader = new Mock(); var eventEngine = new Mock(); var analysisLocation = new Mock(); - agentManager.Setup(mock => mock.GetReader("/usr/local/bin/freshli-agent-java")).Returns(javaAgentReader.Object); javaAgentReader.Setup(mock => mock.ProcessManifest("/path/to/manifest", It.IsAny())) .Returns("/path/to/bill-of-materials"); // Act - var activity = new GenerateBillOfMaterialsActivity( - agentManager.Object, analysisLocation.Object, "/path/to/manifest", "/usr/local/bin/freshli-agent-java" - ); + var activity = new GenerateBillOfMaterialsActivity(javaAgentReader.Object, analysisLocation.Object, "/path/to/manifest"); activity.Handle(eventEngine.Object); // Assert diff --git a/Corgibytes.Freshli.Cli/Functionality/Analysis/ManifestDetectedEvent.cs b/Corgibytes.Freshli.Cli/Functionality/Analysis/ManifestDetectedEvent.cs index 553cd336c..bb73cc47f 100644 --- a/Corgibytes.Freshli.Cli/Functionality/Analysis/ManifestDetectedEvent.cs +++ b/Corgibytes.Freshli.Cli/Functionality/Analysis/ManifestDetectedEvent.cs @@ -1,4 +1,4 @@ -using System; +using Corgibytes.Freshli.Cli.Functionality.BillOfMaterials; using Corgibytes.Freshli.Cli.Functionality.Engine; using Corgibytes.Freshli.Cli.Services; @@ -17,5 +17,9 @@ public ManifestDetectedEvent(IAnalysisLocation analysisLocation, IAgentReader ag public IAgentReader AgentReader { get; } public string ManifestPath { get; } - public void Handle(IApplicationActivityEngine eventClient) => throw new NotImplementedException(); + public void Handle(IApplicationActivityEngine eventClient) => eventClient.Dispatch(new GenerateBillOfMaterialsActivity( + AgentReader, + AnalysisLocation, + ManifestPath + )); } diff --git a/Corgibytes.Freshli.Cli/Functionality/BillOfMaterials/GenerateBillOfMaterialsActivity.cs b/Corgibytes.Freshli.Cli/Functionality/BillOfMaterials/GenerateBillOfMaterialsActivity.cs index cf2977883..0f1084840 100644 --- a/Corgibytes.Freshli.Cli/Functionality/BillOfMaterials/GenerateBillOfMaterialsActivity.cs +++ b/Corgibytes.Freshli.Cli/Functionality/BillOfMaterials/GenerateBillOfMaterialsActivity.cs @@ -7,27 +7,22 @@ namespace Corgibytes.Freshli.Cli.Functionality.BillOfMaterials; public class GenerateBillOfMaterialsActivity : IApplicationActivity { - private readonly IAgentManager _agentManager; - private readonly string _agentPath; - private readonly IAnalysisLocation _analysisLocation; - private readonly string _manifestPath; + public readonly IAgentReader AgentReader; + public readonly IAnalysisLocation AnalysisLocation; + public readonly string ManifestPath; - public GenerateBillOfMaterialsActivity( - IAgentManager agentManager, IAnalysisLocation analysisLocation, string manifestPath, string agentPath - ) + public GenerateBillOfMaterialsActivity(IAgentReader agentReader, IAnalysisLocation analysisLocation, string manifestPath) { - _agentManager = agentManager; - _analysisLocation = analysisLocation; - _manifestPath = manifestPath; - _agentPath = agentPath; + AgentReader = agentReader; + AnalysisLocation = analysisLocation; + ManifestPath = manifestPath; } public void Handle(IApplicationEventEngine eventClient) { - var agent = _agentManager.GetReader(_agentPath); var asOfDate = DateTime.Now; - var pathToBillOfMaterials = agent.ProcessManifest(_manifestPath, asOfDate); + var pathToBillOfMaterials = AgentReader.ProcessManifest(ManifestPath, asOfDate); - eventClient.Fire(new BillOfMaterialsGeneratedEvent(_analysisLocation, pathToBillOfMaterials)); + eventClient.Fire(new BillOfMaterialsGeneratedEvent(AnalysisLocation, pathToBillOfMaterials)); } }