Skip to content

Commit

Permalink
Changed structure on handlers (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
MilleBo authored Feb 21, 2020
1 parent 5da746e commit d81aa63
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 109 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Anotar.Log4Net;
using Testura.Mutation.Application.Models;
using Testura.Mutation.Core.Config;
using Testura.Mutation.Core.Creator.Filter;

namespace Testura.Mutation.Application.Commands.Project.OpenProject.Handlers
{
public class OpenProjectGitFilterHandler : OpenProjectHandler
public class OpenProjectGitFilterHandler
{
private readonly MutationDocumentFilterItemGitDiffCreator _diffCreator;

Expand All @@ -18,7 +17,7 @@ public OpenProjectGitFilterHandler(MutationDocumentFilterItemGitDiffCreator diff
_diffCreator = diffCreator;
}

public override Task HandleAsync(MutationFileConfig fileConfig, MutationConfig applicationConfig, CancellationToken cancellationToken = default(CancellationToken))
public void InitializeGitFilter(MutationFileConfig fileConfig, MutationConfig applicationConfig, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();

Expand All @@ -35,8 +34,6 @@ public OpenProjectGitFilterHandler(MutationDocumentFilterItemGitDiffCreator diff

applicationConfig.Filter.FilterItems.AddRange(filterItems);
}

return base.HandleAsync(fileConfig, applicationConfig, cancellationToken);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Anotar.Log4Net;
using Testura.Mutation.Application.Exceptions;
using Testura.Mutation.Application.Models;
Expand All @@ -13,9 +12,9 @@

namespace Testura.Mutation.Application.Commands.Project.OpenProject.Handlers
{
public class OpenProjectMutatorsHandler : OpenProjectHandler
public class OpenProjectMutatorsHandler
{
public override Task HandleAsync(MutationFileConfig fileConfig, MutationConfig applicationConfig, CancellationToken cancellationToken = default(CancellationToken))
public void InitializeMutators(MutationFileConfig fileConfig, MutationConfig applicationConfig, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();

Expand All @@ -29,8 +28,6 @@ public class OpenProjectMutatorsHandler : OpenProjectHandler
{
LoadCustomMutatorList(fileConfig, applicationConfig);
}

return base.HandleAsync(fileConfig, applicationConfig, cancellationToken);
}

private void LoadCustomMutatorList(MutationFileConfig fileConfig, MutationConfig applicationConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@
using Anotar.Log4Net;
using Testura.Mutation.Application.Exceptions;
using Testura.Mutation.Application.Models;
using Testura.Mutation.Core.Config;
using Testura.Mutation.Core.Git;

namespace Testura.Mutation.Application.Commands.Project.OpenProject.Handlers
{
public class OpenProjectExistHandler : OpenProjectHandler
public class OpenProjectSolutionExistHandler
{
private readonly IGitCloner _gitCloner;

public OpenProjectExistHandler(IGitCloner gitCloner)
public OpenProjectSolutionExistHandler(IGitCloner gitCloner)
{
_gitCloner = gitCloner;
}

public override async Task HandleAsync(MutationFileConfig fileConfig, MutationConfig applicationConfig, CancellationToken cancellationToken = default(CancellationToken))
public async Task VerifySolutionExistAsync(MutationFileConfig fileConfig, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();

Expand All @@ -39,8 +38,6 @@ await _gitCloner.CloneSolutionAsync(
fileConfig.Git.Password,
fileConfig.Git.LocalPath);
}

await base.HandleAsync(fileConfig, applicationConfig, cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace Testura.Mutation.Application.Commands.Project.OpenProject.Handlers
{
public class OpenProjectWorkspaceHandler : OpenProjectHandler
public class OpenProjectWorkspaceHandler
{
private readonly BaselineCreator _baselineCreator;
private readonly ISolutionOpener _solutionOpener;
Expand All @@ -27,7 +27,7 @@ public OpenProjectWorkspaceHandler(BaselineCreator baselineCreator, ISolutionOpe
_solutionOpener = solutionOpener;
}

public override async Task HandleAsync(MutationFileConfig fileConfig, MutationConfig applicationConfig, CancellationToken cancellationToken = default(CancellationToken))
public async Task InitializeProjectAsync(MutationFileConfig fileConfig, MutationConfig applicationConfig, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();

Expand All @@ -40,8 +40,6 @@ public OpenProjectWorkspaceHandler(BaselineCreator baselineCreator, ISolutionOpe
{
applicationConfig.BaselineInfos = new List<BaselineInfo>(await _baselineCreator.CreateBaselineAsync(applicationConfig, cancellationToken));
}

await base.HandleAsync(fileConfig, applicationConfig, cancellationToken);
}

private void InitializeMutationProjects(MutationFileConfig fileConfig, MutationConfig config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@ namespace Testura.Mutation.Application.Commands.Project.OpenProject
{
public class OpenProjectCommandHandler : IRequestHandler<OpenProjectCommand, MutationConfig>
{
private readonly OpenProjectHandler _handler;
private readonly OpenProjectSolutionExistHandler _solutionExistHandler;
private readonly OpenProjectMutatorsHandler _mutatorsHandler;
private readonly OpenProjectGitFilterHandler _gitFilterHandler;
private readonly OpenProjectWorkspaceHandler _workspaceHandler;

public OpenProjectCommandHandler(
OpenProjectExistHandler openProjectExistHandler,
OpenProjectMutatorsHandler openProjectMutatorsHandler,
OpenProjectGitFilterHandler openProjectGitFilterHandler,
OpenProjectWorkspaceHandler openProjectWorkspaceHandler)
OpenProjectSolutionExistHandler solutionExistHandler,
OpenProjectMutatorsHandler mutatorsHandler,
OpenProjectGitFilterHandler gitFilterHandler,
OpenProjectWorkspaceHandler workspaceHandler)
{
_handler = openProjectExistHandler;

_handler
.SetNext(openProjectMutatorsHandler)
.SetNext(openProjectGitFilterHandler)
.SetNext(openProjectWorkspaceHandler);
_solutionExistHandler = solutionExistHandler;
_mutatorsHandler = mutatorsHandler;
_gitFilterHandler = gitFilterHandler;
_workspaceHandler = workspaceHandler;
}

public async Task<MutationConfig> Handle(OpenProjectCommand command, CancellationToken cancellationToken)
Expand All @@ -42,7 +43,12 @@ public async Task<MutationConfig> Handle(OpenProjectCommand command, Cancellatio
{
(fileConfig, applicationConfig) = LoadConfigs(path, command.Config);

await _handler.HandleAsync(fileConfig, applicationConfig, cancellationToken);
await _solutionExistHandler.VerifySolutionExistAsync(fileConfig, cancellationToken);

_mutatorsHandler.InitializeMutators(fileConfig, applicationConfig, cancellationToken);
_gitFilterHandler.InitializeGitFilter(fileConfig, applicationConfig, cancellationToken);

await _workspaceHandler.InitializeProjectAsync(fileConfig, applicationConfig, cancellationToken);

LogTo.Info("Opening project finished.");
return applicationConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,7 @@
<Compile Include="Commands\Project\History\GetProjectHistory\GetProjectHistoryCommand.cs" />
<Compile Include="Commands\Project\History\GetProjectHistory\GetProjectHistoryCommandHandler.cs" />
<Compile Include="Commands\Project\History\GetProjectHistory\GetProjectHistoryCommandValidator.cs" />
<Compile Include="Commands\Project\OpenProject\Handlers\OpenProjectHandler.cs" />
<Compile Include="Commands\Project\OpenProject\Handlers\OpenProjectExistHandler.cs" />
<Compile Include="Commands\Project\OpenProject\Handlers\OpenProjectSolutionExistHandler.cs" />
<Compile Include="Commands\Project\OpenProject\Handlers\OpenProjectGitFilterHandler.cs" />
<Compile Include="Commands\Project\OpenProject\Handlers\OpenProjectMutatorsHandler.cs" />
<Compile Include="Commands\Project\OpenProject\Handlers\OpenProjectWorkspaceHandler.cs" />
Expand Down
24 changes: 13 additions & 11 deletions src/Testura.Mutation.Core/Baseline/BaselineCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ namespace Testura.Mutation.Core.Baseline
public class BaselineCreator
{
private readonly IDirectoryHandler _directoryHandler;
private readonly BaselineCreatorHandler _handler;
private readonly BaselineCreatorCompileMutationProjectsHandler _compileMutationProjectsHandler;
private readonly BaselineCreatorRunUnitTestsHandler _runUnitTestHandler;
private readonly BaselineCreatorLogSummaryHandler _logSummaryHandler;

public BaselineCreator(
IDirectoryHandler directoryHandler,
BaselineCreatorCompileMutationProjectsHandler baselineCreatorCompileMutationProjectsHandler,
BaselineCreatorRunUnitTestsHandler baselineCreatorRunUnitTestsHandler,
BaselineCreatorLogSummaryHandler baselineCreatorLogSummaryHandler)
BaselineCreatorCompileMutationProjectsHandler compileMutationProjectsHandler,
BaselineCreatorRunUnitTestsHandler runUnitTestHandler,
BaselineCreatorLogSummaryHandler logSummaryHandler)
{
_directoryHandler = directoryHandler;
_handler = baselineCreatorCompileMutationProjectsHandler;

_handler
.SetNext(baselineCreatorRunUnitTestsHandler)
.SetNext(baselineCreatorLogSummaryHandler);
_compileMutationProjectsHandler = compileMutationProjectsHandler;
_runUnitTestHandler = runUnitTestHandler;
_logSummaryHandler = logSummaryHandler;
}

private string BaselineDirectoryPath => Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TestRun", "Baseline");
Expand All @@ -39,8 +39,10 @@ public BaselineCreator(

try
{
var baselineInfos = new List<BaselineInfo>();
await _handler.HandleAsync(config, BaselineDirectoryPath, baselineInfos, cancellationToken);
await _compileMutationProjectsHandler.CompileMutationProjects(config, BaselineDirectoryPath, cancellationToken);
var baselineInfos = await _runUnitTestHandler.RunUnitTests(config, BaselineDirectoryPath, cancellationToken);

_logSummaryHandler.ShowBaselineSummary(baselineInfos);

LogTo.Info("Baseline completed.");
return baselineInfos;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Anotar.Log4Net;
Expand All @@ -10,7 +9,7 @@

namespace Testura.Mutation.Core.Baseline.Handlers
{
public class BaselineCreatorCompileMutationProjectsHandler : BaselineCreatorHandler
public class BaselineCreatorCompileMutationProjectsHandler
{
private readonly IProjectCompiler _projectCompiler;
private readonly IDirectoryHandler _directoryHandler;
Expand All @@ -21,12 +20,14 @@ public BaselineCreatorCompileMutationProjectsHandler(IProjectCompiler projectCom
_directoryHandler = directoryHandler;
}

public override async Task HandleAsync(MutationConfig config, string baselineDirectoryPath, IList<BaselineInfo> baselineInfos, CancellationToken cancellationToken = default(CancellationToken))
public async Task CompileMutationProjects(MutationConfig config, string baselineDirectoryPath, CancellationToken cancellationToken = default(CancellationToken))
{
_directoryHandler.CreateDirectory(baselineDirectoryPath);

foreach (var mutationProject in config.MutationProjects)
{
cancellationToken.ThrowIfCancellationRequested();

LogTo.Info($"Compiling {mutationProject.Project.Name}..");

var project = config.Solution.Projects.FirstOrDefault(p => p.Name == mutationProject.Project.Name);
Expand All @@ -44,8 +45,6 @@ public BaselineCreatorCompileMutationProjectsHandler(IProjectCompiler projectCom
new CompilationException(result.Errors.Select(e => e.Message)));
}
}

await base.HandleAsync(config, baselineDirectoryPath, baselineInfos, cancellationToken);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Anotar.Log4Net;
using ConsoleTables;
using Testura.Mutation.Core.Config;

namespace Testura.Mutation.Core.Baseline.Handlers
{
public class BaselineCreatorLogSummaryHandler : BaselineCreatorHandler
public class BaselineCreatorLogSummaryHandler
{
public override Task HandleAsync(MutationConfig config, string baselineDirectoryPath, IList<BaselineInfo> baselineInfos, CancellationToken cancellationToken = default(CancellationToken))
public void ShowBaselineSummary(IList<BaselineInfo> baselineInfos)
{
var table = new ConsoleTable("Project", "Execution time");
foreach (var configBaselineInfo in baselineInfos)
Expand All @@ -18,8 +15,6 @@ public class BaselineCreatorLogSummaryHandler : BaselineCreatorHandler
}

LogTo.Info($"\n{table.ToStringAlternative()}");

return base.HandleAsync(config, baselineDirectoryPath, baselineInfos, cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace Testura.Mutation.Core.Baseline.Handlers
{
public class BaselineCreatorRunUnitTestsHandler : BaselineCreatorHandler
public class BaselineCreatorRunUnitTestsHandler
{
private readonly IDirectoryHandler _directoryHandler;
private readonly ITestRunnerClient _testRunnerClient;
Expand All @@ -31,9 +31,9 @@ public BaselineCreatorRunUnitTestsHandler(
_testRunnerDependencyFilesHandler = testRunnerDependencyFilesHandler;
}

public override async Task HandleAsync(MutationConfig config, string baselineDirectoryPath, IList<BaselineInfo> baselineInfos, CancellationToken cancellationToken = default(CancellationToken))
public async Task<IList<BaselineInfo>> RunUnitTests(MutationConfig config, string baselineDirectoryPath, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
var baselineInfos = new List<BaselineInfo>();

foreach (var testProject in config.TestProjects)
{
Expand All @@ -59,7 +59,7 @@ public BaselineCreatorRunUnitTestsHandler(
baselineInfos.Add(new BaselineInfo(testProject.Project.Name, result.ExecutionTime));
}

await base.HandleAsync(config, baselineDirectoryPath, baselineInfos, cancellationToken);
return baselineInfos;
}

private async Task<TestSuiteResult> RunTestAsync(
Expand Down
1 change: 0 additions & 1 deletion src/Testura.Mutation.Core/Testura.Mutation.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
<Compile Include="Baseline\BaselineCreator.cs" />
<Compile Include="Baseline\BaselineInfo.cs" />
<Compile Include="Baseline\Handlers\BaselineCreatorCompileMutationProjectsHandler.cs" />
<Compile Include="Baseline\Handlers\BaselineCreatorHandler.cs" />
<Compile Include="Baseline\Handlers\BaselineCreatorLogSummaryHandler.cs" />
<Compile Include="Baseline\Handlers\BaselineCreatorRunUnitTestsHandler.cs" />
<Compile Include="Config\MutationProject.cs" />
Expand Down

0 comments on commit d81aa63

Please sign in to comment.