-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved base line logic to seperated classes and created a directory ha…
…ndler (#34)
- Loading branch information
Showing
11 changed files
with
273 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/Testura.Mutation.Core/Baseline/Handlers/BaselineCreatorCompileMutationProjectsHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Anotar.Log4Net; | ||
using Testura.Mutation.Core.Config; | ||
using Testura.Mutation.Core.Exceptions; | ||
using Testura.Mutation.Core.Execution.Compilation; | ||
using Testura.Mutation.Core.Util.FileSystem; | ||
|
||
namespace Testura.Mutation.Core.Baseline.Handlers | ||
{ | ||
public class BaselineCreatorCompileMutationProjectsHandler : BaselineCreatorHandler | ||
{ | ||
private readonly IProjectCompiler _projectCompiler; | ||
private readonly IDirectoryHandler _directoryHandler; | ||
|
||
public BaselineCreatorCompileMutationProjectsHandler(IProjectCompiler projectCompiler, IDirectoryHandler directoryHandler) | ||
{ | ||
_projectCompiler = projectCompiler; | ||
_directoryHandler = directoryHandler; | ||
} | ||
|
||
public override async Task HandleAsync(MutationConfig config, string baselineDirectoryPath, IList<BaselineInfo> baselineInfos, CancellationToken cancellationToken = default(CancellationToken)) | ||
{ | ||
_directoryHandler.CreateDirectory(baselineDirectoryPath); | ||
|
||
foreach (var mutationProject in config.MutationProjects) | ||
{ | ||
LogTo.Info($"Compiling {mutationProject.Project.Name}.."); | ||
|
||
var project = config.Solution.Projects.FirstOrDefault(p => p.Name == mutationProject.Project.Name); | ||
var result = await _projectCompiler.CompileAsync(baselineDirectoryPath, project); | ||
|
||
if (!result.IsSuccess) | ||
{ | ||
foreach (var compilationError in result.Errors) | ||
{ | ||
LogTo.Error($"{{ Error = \"{compilationError.Message}\", Location = \"{compilationError.Location}\""); | ||
} | ||
|
||
throw new BaselineException( | ||
$"Failed to compile {project.Name} in base line.", | ||
new CompilationException(result.Errors.Select(e => e.Message))); | ||
} | ||
} | ||
|
||
await base.HandleAsync(config, baselineDirectoryPath, baselineInfos, cancellationToken); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Testura.Mutation.Core/Baseline/Handlers/BaselineCreatorHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
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<BaselineInfo> baselineInfos, CancellationToken cancellationToken = default(CancellationToken)) | ||
{ | ||
return Next?.HandleAsync(config, baselineDirectoryPath, baselineInfos, cancellationToken) ?? Task.CompletedTask; | ||
} | ||
|
||
public BaselineCreatorHandler SetNext(BaselineCreatorHandler handler) | ||
{ | ||
Next = handler; | ||
return Next; | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Testura.Mutation.Core/Baseline/Handlers/BaselineCreatorLogSummaryHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
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 override Task HandleAsync(MutationConfig config, string baselineDirectoryPath, IList<BaselineInfo> baselineInfos, CancellationToken cancellationToken = default(CancellationToken)) | ||
{ | ||
var table = new ConsoleTable("Project", "Execution time"); | ||
foreach (var configBaselineInfo in baselineInfos) | ||
{ | ||
table.AddRow(configBaselineInfo.TestProjectName, configBaselineInfo.ExecutionTime); | ||
} | ||
|
||
LogTo.Info($"\n{table.ToStringAlternative()}"); | ||
|
||
return base.HandleAsync(config, baselineDirectoryPath, baselineInfos, cancellationToken); | ||
} | ||
} | ||
} |
Oops, something went wrong.