Skip to content

Commit

Permalink
Merge pull request #245 from corgibytes/bom-dispatches-compute-libyear
Browse files Browse the repository at this point in the history
BillOfMaterialsGeneratedEvent dispatch ComputeLibYearActivity
  • Loading branch information
mscottford authored Sep 13, 2022
2 parents de7d42c + 1b39f91 commit 59b1dd9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using Corgibytes.Freshli.Cli.Functionality;
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.Git;

public class BillOfMaterialsGeneratedEventTest
{
[Fact]
public void CorrectlyDispatchesComputeLibYearActivity()
{
var serviceProvider = new Mock<IServiceProvider>();
var calculateLibYearFromFile = new Mock<ICalculateLibYearFromFile>();
var analysisLocation = new AnalysisLocation("/cache/directory", "2dbc2fd2358e1ea1b7a6bc08ea647b9a337ac92d",
"da39a3ee5e6b4b0d3255bfef95601890afd80709");
var pathToBoM = "/path/to/bom";

var billOfMaterialsGeneratedEvent = new BillOfMaterialsGeneratedEvent(analysisLocation, pathToBoM);

serviceProvider.Setup(mock => mock.GetService(typeof(ICalculateLibYearFromFile)))
.Returns(calculateLibYearFromFile.Object);

var engine = new Mock<IApplicationActivityEngine>();
engine.Setup(mock => mock.ServiceProvider).Returns(serviceProvider.Object);

billOfMaterialsGeneratedEvent.Handle(engine.Object);

engine.Verify(mock => mock.Dispatch(It.Is<ComputeLibYearActivity>(value =>
value.AnalysisLocation == analysisLocation &&
value.PathToBoM == pathToBoM
)));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Corgibytes.Freshli.Cli.Functionality.Analysis;
using Corgibytes.Freshli.Cli.Functionality.Engine;
using Corgibytes.Freshli.Cli.Services;
using Microsoft.Extensions.DependencyInjection;

namespace Corgibytes.Freshli.Cli.Functionality.BillOfMaterials;

Expand All @@ -15,5 +16,10 @@ public BillOfMaterialsGeneratedEvent(IAnalysisLocation analysisLocation, string
public IAnalysisLocation AnalysisLocation { get; }
public string PathToBillOfMaterials { get; }

public void Handle(IApplicationActivityEngine eventClient) => throw new NotImplementedException();
public void Handle(IApplicationActivityEngine eventClient) => eventClient.Dispatch(
new ComputeLibYearActivity(
eventClient.ServiceProvider.GetRequiredService<ICalculateLibYearFromFile>(),
PathToBillOfMaterials,
AnalysisLocation
));
}
15 changes: 7 additions & 8 deletions Corgibytes.Freshli.Cli/Functionality/ComputeLibYearActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@ namespace Corgibytes.Freshli.Cli.Functionality;

public class ComputeLibYearActivity : IApplicationActivity
{
[JsonProperty] private readonly AnalysisLocation _analysisLocation;
public readonly IAnalysisLocation AnalysisLocation;
[JsonProperty] private readonly ICalculateLibYearFromFile _calculateLibYearFromFile;

[JsonProperty] private readonly string _pathToBoM;
public readonly string PathToBoM;

public ComputeLibYearActivity(ICalculateLibYearFromFile calculateLibYearFromFile, string pathToBoM,
AnalysisLocation analysisLocation)
IAnalysisLocation analysisLocation)
{
_calculateLibYearFromFile = calculateLibYearFromFile;
_pathToBoM = pathToBoM;
_analysisLocation = analysisLocation;
PathToBoM = pathToBoM;
AnalysisLocation = analysisLocation;
}

public void Handle(IApplicationEventEngine eventClient)
{
var libYearPackages = _calculateLibYearFromFile.AsList(_pathToBoM);
var libYearPackages = _calculateLibYearFromFile.AsList(PathToBoM);
eventClient.Fire(new LibYearComputedEvent
{
LibYearPackages = libYearPackages,
AnalysisLocation = _analysisLocation
AnalysisLocation = AnalysisLocation
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Corgibytes.Freshli.Cli.Functionality;
public class LibYearComputedEvent : IApplicationEvent
{
public IList<PackageLibYear>? LibYearPackages { get; init; }
public AnalysisLocation? AnalysisLocation { get; init; }
public IAnalysisLocation? AnalysisLocation { get; init; }

public void Handle(IApplicationActivityEngine eventClient)
{
Expand Down

0 comments on commit 59b1dd9

Please sign in to comment.