diff --git a/src/Testura.Mutation.Application/Commands/Project/OpenProject/Handlers/OpenProjectGitFilterHandler.cs b/src/Testura.Mutation.Application/Commands/Project/OpenProject/Handlers/OpenProjectGitFilterHandler.cs index e83fd32..bc542a2 100644 --- a/src/Testura.Mutation.Application/Commands/Project/OpenProject/Handlers/OpenProjectGitFilterHandler.cs +++ b/src/Testura.Mutation.Application/Commands/Project/OpenProject/Handlers/OpenProjectGitFilterHandler.cs @@ -1,7 +1,6 @@ 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; @@ -9,7 +8,7 @@ namespace Testura.Mutation.Application.Commands.Project.OpenProject.Handlers { - public class OpenProjectGitFilterHandler : OpenProjectHandler + public class OpenProjectGitFilterHandler { private readonly MutationDocumentFilterItemGitDiffCreator _diffCreator; @@ -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(); @@ -35,8 +34,6 @@ public OpenProjectGitFilterHandler(MutationDocumentFilterItemGitDiffCreator diff applicationConfig.Filter.FilterItems.AddRange(filterItems); } - - return base.HandleAsync(fileConfig, applicationConfig, cancellationToken); } } } diff --git a/src/Testura.Mutation.Application/Commands/Project/OpenProject/Handlers/OpenProjectHandler.cs b/src/Testura.Mutation.Application/Commands/Project/OpenProject/Handlers/OpenProjectHandler.cs deleted file mode 100644 index b6bc83d..0000000 --- a/src/Testura.Mutation.Application/Commands/Project/OpenProject/Handlers/OpenProjectHandler.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Threading; -using System.Threading.Tasks; -using Testura.Mutation.Application.Models; -using Testura.Mutation.Core.Config; - -namespace Testura.Mutation.Application.Commands.Project.OpenProject.Handlers -{ - public abstract class OpenProjectHandler - { - public OpenProjectHandler Next { get; set; } - - public virtual Task HandleAsync(MutationFileConfig fileConfig, MutationConfig applicationConfig, CancellationToken cancellationToken = default(CancellationToken)) - { - return Next?.HandleAsync(fileConfig, applicationConfig, cancellationToken) ?? Task.CompletedTask; - } - - public OpenProjectHandler SetNext(OpenProjectHandler handler) - { - Next = handler; - return Next; - } - } -} diff --git a/src/Testura.Mutation.Application/Commands/Project/OpenProject/Handlers/OpenProjectMutatorsHandler.cs b/src/Testura.Mutation.Application/Commands/Project/OpenProject/Handlers/OpenProjectMutatorsHandler.cs index 2652f19..7e458f1 100644 --- a/src/Testura.Mutation.Application/Commands/Project/OpenProject/Handlers/OpenProjectMutatorsHandler.cs +++ b/src/Testura.Mutation.Application/Commands/Project/OpenProject/Handlers/OpenProjectMutatorsHandler.cs @@ -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; @@ -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(); @@ -29,8 +28,6 @@ public class OpenProjectMutatorsHandler : OpenProjectHandler { LoadCustomMutatorList(fileConfig, applicationConfig); } - - return base.HandleAsync(fileConfig, applicationConfig, cancellationToken); } private void LoadCustomMutatorList(MutationFileConfig fileConfig, MutationConfig applicationConfig) diff --git a/src/Testura.Mutation.Application/Commands/Project/OpenProject/Handlers/OpenProjectExistHandler.cs b/src/Testura.Mutation.Application/Commands/Project/OpenProject/Handlers/OpenProjectSolutionExistHandler.cs similarity index 74% rename from src/Testura.Mutation.Application/Commands/Project/OpenProject/Handlers/OpenProjectExistHandler.cs rename to src/Testura.Mutation.Application/Commands/Project/OpenProject/Handlers/OpenProjectSolutionExistHandler.cs index 733cc56..952d30d 100644 --- a/src/Testura.Mutation.Application/Commands/Project/OpenProject/Handlers/OpenProjectExistHandler.cs +++ b/src/Testura.Mutation.Application/Commands/Project/OpenProject/Handlers/OpenProjectSolutionExistHandler.cs @@ -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(); @@ -39,8 +38,6 @@ await _gitCloner.CloneSolutionAsync( fileConfig.Git.Password, fileConfig.Git.LocalPath); } - - await base.HandleAsync(fileConfig, applicationConfig, cancellationToken); } } } diff --git a/src/Testura.Mutation.Application/Commands/Project/OpenProject/Handlers/OpenProjectWorkspaceHandler.cs b/src/Testura.Mutation.Application/Commands/Project/OpenProject/Handlers/OpenProjectWorkspaceHandler.cs index be48c2c..f98e123 100644 --- a/src/Testura.Mutation.Application/Commands/Project/OpenProject/Handlers/OpenProjectWorkspaceHandler.cs +++ b/src/Testura.Mutation.Application/Commands/Project/OpenProject/Handlers/OpenProjectWorkspaceHandler.cs @@ -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; @@ -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(); @@ -40,8 +40,6 @@ public OpenProjectWorkspaceHandler(BaselineCreator baselineCreator, ISolutionOpe { applicationConfig.BaselineInfos = new List(await _baselineCreator.CreateBaselineAsync(applicationConfig, cancellationToken)); } - - await base.HandleAsync(fileConfig, applicationConfig, cancellationToken); } private void InitializeMutationProjects(MutationFileConfig fileConfig, MutationConfig config) diff --git a/src/Testura.Mutation.Application/Commands/Project/OpenProject/OpenProjectCommandHandler.cs b/src/Testura.Mutation.Application/Commands/Project/OpenProject/OpenProjectCommandHandler.cs index 73555ad..e4f0f6b 100644 --- a/src/Testura.Mutation.Application/Commands/Project/OpenProject/OpenProjectCommandHandler.cs +++ b/src/Testura.Mutation.Application/Commands/Project/OpenProject/OpenProjectCommandHandler.cs @@ -14,20 +14,21 @@ namespace Testura.Mutation.Application.Commands.Project.OpenProject { public class OpenProjectCommandHandler : IRequestHandler { - 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 Handle(OpenProjectCommand command, CancellationToken cancellationToken) @@ -42,7 +43,12 @@ public async Task 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; diff --git a/src/Testura.Mutation.Application/Testura.Mutation.Application.csproj b/src/Testura.Mutation.Application/Testura.Mutation.Application.csproj index 815a417..fe13699 100644 --- a/src/Testura.Mutation.Application/Testura.Mutation.Application.csproj +++ b/src/Testura.Mutation.Application/Testura.Mutation.Application.csproj @@ -411,8 +411,7 @@ - - + diff --git a/src/Testura.Mutation.Core/Baseline/BaselineCreator.cs b/src/Testura.Mutation.Core/Baseline/BaselineCreator.cs index 80f97f0..1036d65 100644 --- a/src/Testura.Mutation.Core/Baseline/BaselineCreator.cs +++ b/src/Testura.Mutation.Core/Baseline/BaselineCreator.cs @@ -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"); @@ -39,8 +39,10 @@ public BaselineCreator( try { - var baselineInfos = new List(); - 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; diff --git a/src/Testura.Mutation.Core/Baseline/Handlers/BaselineCreatorCompileMutationProjectsHandler.cs b/src/Testura.Mutation.Core/Baseline/Handlers/BaselineCreatorCompileMutationProjectsHandler.cs index cebf8a7..4bca73d 100644 --- a/src/Testura.Mutation.Core/Baseline/Handlers/BaselineCreatorCompileMutationProjectsHandler.cs +++ b/src/Testura.Mutation.Core/Baseline/Handlers/BaselineCreatorCompileMutationProjectsHandler.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using System.Linq; +using System.Linq; using System.Threading; using System.Threading.Tasks; using Anotar.Log4Net; @@ -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; @@ -21,12 +20,14 @@ public BaselineCreatorCompileMutationProjectsHandler(IProjectCompiler projectCom _directoryHandler = directoryHandler; } - public override async Task HandleAsync(MutationConfig config, string baselineDirectoryPath, IList 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); @@ -44,8 +45,6 @@ public BaselineCreatorCompileMutationProjectsHandler(IProjectCompiler projectCom new CompilationException(result.Errors.Select(e => e.Message))); } } - - await base.HandleAsync(config, baselineDirectoryPath, baselineInfos, cancellationToken); } } } diff --git a/src/Testura.Mutation.Core/Baseline/Handlers/BaselineCreatorHandler.cs b/src/Testura.Mutation.Core/Baseline/Handlers/BaselineCreatorHandler.cs deleted file mode 100644 index 8eb5e60..0000000 --- a/src/Testura.Mutation.Core/Baseline/Handlers/BaselineCreatorHandler.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -using Testura.Mutation.Core.Config; - -namespace Testura.Mutation.Core.Baseline.Handlers -{ - public abstract class BaselineCreatorHandler - { - public BaselineCreatorHandler Next { get; set; } - - public virtual Task HandleAsync(MutationConfig config, string baselineDirectoryPath, IList baselineInfos, CancellationToken cancellationToken = default(CancellationToken)) - { - return Next?.HandleAsync(config, baselineDirectoryPath, baselineInfos, cancellationToken) ?? Task.CompletedTask; - } - - public BaselineCreatorHandler SetNext(BaselineCreatorHandler handler) - { - Next = handler; - return Next; - } - } -} diff --git a/src/Testura.Mutation.Core/Baseline/Handlers/BaselineCreatorLogSummaryHandler.cs b/src/Testura.Mutation.Core/Baseline/Handlers/BaselineCreatorLogSummaryHandler.cs index e46db18..b907cbb 100644 --- a/src/Testura.Mutation.Core/Baseline/Handlers/BaselineCreatorLogSummaryHandler.cs +++ b/src/Testura.Mutation.Core/Baseline/Handlers/BaselineCreatorLogSummaryHandler.cs @@ -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 baselineInfos, CancellationToken cancellationToken = default(CancellationToken)) + public void ShowBaselineSummary(IList baselineInfos) { var table = new ConsoleTable("Project", "Execution time"); foreach (var configBaselineInfo in baselineInfos) @@ -18,8 +15,6 @@ public class BaselineCreatorLogSummaryHandler : BaselineCreatorHandler } LogTo.Info($"\n{table.ToStringAlternative()}"); - - return base.HandleAsync(config, baselineDirectoryPath, baselineInfos, cancellationToken); } } } diff --git a/src/Testura.Mutation.Core/Baseline/Handlers/BaselineCreatorRunUnittestsHandler.cs b/src/Testura.Mutation.Core/Baseline/Handlers/BaselineCreatorRunUnittestsHandler.cs index 36389eb..5525e48 100644 --- a/src/Testura.Mutation.Core/Baseline/Handlers/BaselineCreatorRunUnittestsHandler.cs +++ b/src/Testura.Mutation.Core/Baseline/Handlers/BaselineCreatorRunUnittestsHandler.cs @@ -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; @@ -31,9 +31,9 @@ public BaselineCreatorRunUnitTestsHandler( _testRunnerDependencyFilesHandler = testRunnerDependencyFilesHandler; } - public override async Task HandleAsync(MutationConfig config, string baselineDirectoryPath, IList baselineInfos, CancellationToken cancellationToken = default(CancellationToken)) + public async Task> RunUnitTests(MutationConfig config, string baselineDirectoryPath, CancellationToken cancellationToken = default(CancellationToken)) { - cancellationToken.ThrowIfCancellationRequested(); + var baselineInfos = new List(); foreach (var testProject in config.TestProjects) { @@ -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 RunTestAsync( diff --git a/src/Testura.Mutation.Core/Testura.Mutation.Core.csproj b/src/Testura.Mutation.Core/Testura.Mutation.Core.csproj index d727445..dec8aba 100644 --- a/src/Testura.Mutation.Core/Testura.Mutation.Core.csproj +++ b/src/Testura.Mutation.Core/Testura.Mutation.Core.csproj @@ -50,7 +50,6 @@ -