-
-
Notifications
You must be signed in to change notification settings - Fork 736
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a24178
commit a0c88b3
Showing
11 changed files
with
626 additions
and
63 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
53 changes: 53 additions & 0 deletions
53
src/Cake.Common.Tests/Fixtures/Tools/DotCover/Cover/DotCoverCovererFixture.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,53 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Cake.Common.Tools.DotCover.Cover; | ||
using Cake.Core; | ||
using Cake.Core.Diagnostics; | ||
using Cake.Core.IO; | ||
using NSubstitute; | ||
|
||
namespace Cake.Common.Tests.Fixtures.Tools.DotCover.Cover | ||
{ | ||
internal sealed class DotCoverCovererFixture : DotCoverFixture<DotCoverCoverSettings> | ||
{ | ||
public ICakeContext Context { get; set; } | ||
public Action<ICakeContext> Action { get; set; } | ||
public FilePath OutputPath { get; set; } | ||
|
||
public DotCoverCovererFixture() | ||
{ | ||
// Set the output file. | ||
OutputPath = new FilePath("./result.dcvr"); | ||
|
||
// Setup the Cake Context. | ||
Context = Substitute.For<ICakeContext>(); | ||
Context.FileSystem.Returns(FileSystem); | ||
Context.Arguments.Returns(Substitute.For<ICakeArguments>()); | ||
Context.Environment.Returns(Environment); | ||
Context.Globber.Returns(Globber); | ||
Context.Log.Returns(Substitute.For<ICakeLog>()); | ||
Context.Registry.Returns(Substitute.For<IRegistry>()); | ||
Context.ProcessRunner.Returns((IProcessRunner)null); | ||
|
||
// Set up the default action that intercepts. | ||
Action = context => | ||
{ | ||
context.ProcessRunner.Start( | ||
new FilePath("/Working/tools/Test.exe"), | ||
new ProcessSettings() | ||
{ | ||
Arguments = "-argument" | ||
}); | ||
}; | ||
} | ||
|
||
protected override void RunTool() | ||
{ | ||
var tool = new DotCoverCoverer(FileSystem, Environment, ProcessRunner, Globber); | ||
tool.Cover(Context, Action, OutputPath, Settings); | ||
} | ||
} | ||
} |
266 changes: 266 additions & 0 deletions
266
src/Cake.Common.Tests/Unit/Tools/DotCover/Cover/DotCoverCovererTests.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,266 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Cake.Common.Tests.Fixtures.Tools.DotCover; | ||
using Cake.Common.Tests.Fixtures.Tools.DotCover.Cover; | ||
using Cake.Common.Tools.DotCover; | ||
using Cake.Common.Tools.DotCover.Cover; | ||
using Cake.Common.Tools.NUnit; | ||
using Cake.Common.Tools.XUnit; | ||
using Cake.Core.IO; | ||
using Cake.Testing; | ||
using Xunit; | ||
|
||
namespace Cake.Common.Tests.Unit.Tools.DotCover.Cover | ||
{ | ||
public sealed class DotCoverCovererTests | ||
{ | ||
public sealed class TheCoverMethod | ||
{ | ||
[Fact] | ||
public void Should_Throw_If_Context_Is_Null() | ||
{ | ||
// Given | ||
var fixture = new DotCoverCovererFixture(); | ||
fixture.Context = null; | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
Assert.IsArgumentNullException(result, "context"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_Action_Is_Null() | ||
{ | ||
// Given | ||
var fixture = new DotCoverCovererFixture(); | ||
fixture.Action = null; | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
Assert.IsArgumentNullException(result, "action"); | ||
|
||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_Output_File_Is_Null() | ||
{ | ||
// Given | ||
var fixture = new DotCoverCovererFixture(); | ||
fixture.OutputPath = null; | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
Assert.IsArgumentNullException(result, "outputPath"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_Settings_Are_Null() | ||
{ | ||
// Given | ||
var fixture = new DotCoverCovererFixture(); | ||
fixture.Settings = null; | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
Assert.IsArgumentNullException(result, "settings"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_No_Tool_Was_Intercepted() | ||
{ | ||
// Given | ||
var fixture = new DotCoverCovererFixture(); | ||
fixture.Action = context => { }; | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
Assert.IsCakeException(result, "No tool was started."); | ||
} | ||
|
||
[Fact] | ||
public void Should_Capture_Tool_And_Arguments_From_Action() | ||
{ | ||
// Given | ||
var fixture = new DotCoverCovererFixture(); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("Cover /TargetExecutable=\"/Working/tools/Test.exe\" " + | ||
"/TargetArguments=\"-argument\" " + | ||
"/Output=\"/Working/result.dcvr\"", result.Args); | ||
} | ||
|
||
[Theory] | ||
[InlineData("")] | ||
[InlineData(null)] | ||
public void Should_Not_Capture_Arguments_From_Action_If_Excluded(string arguments) | ||
{ | ||
// Given | ||
var fixture = new DotCoverCovererFixture(); | ||
fixture.Action = context => | ||
{ | ||
context.ProcessRunner.Start( | ||
new FilePath("/Working/tools/Test.exe"), | ||
new ProcessSettings() | ||
{ | ||
Arguments = arguments | ||
}); | ||
}; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("Cover /TargetExecutable=\"/Working/tools/Test.exe\" " + | ||
"/Output=\"/Working/result.dcvr\"", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Append_TargetWorkingDir() | ||
{ | ||
// Given | ||
var fixture = new DotCoverCovererFixture(); | ||
fixture.Settings.TargetWorkingDir = new DirectoryPath("/Working"); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("Cover /TargetExecutable=\"/Working/tools/Test.exe\" " + | ||
"/TargetArguments=\"-argument\" " + | ||
"/Output=\"/Working/result.dcvr\" " + | ||
"/TargetWorkingDir=\"/Working\"", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Append_Scope() | ||
{ | ||
// Given | ||
var fixture = new DotCoverCovererFixture(); | ||
fixture.Settings.WithScope("/Working/*.dll") | ||
.WithScope("/Some/**/Other/*.dll"); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("Cover /TargetExecutable=\"/Working/tools/Test.exe\" " + | ||
"/TargetArguments=\"-argument\" " + | ||
"/Output=\"/Working/result.dcvr\" " + | ||
"/Scope=\"/Working/*.dll;/Some/**/Other/*.dll\"", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Append_Filters() | ||
{ | ||
// Given | ||
var fixture = new DotCoverCovererFixture(); | ||
fixture.Settings.WithFilter("+:module=Test.*") | ||
.WithFilter("-:myassembly"); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("Cover /TargetExecutable=\"/Working/tools/Test.exe\" " + | ||
"/TargetArguments=\"-argument\" " + | ||
"/Output=\"/Working/result.dcvr\" " + | ||
"/Filters=\"+:module=Test.*;-:myassembly\"", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Append_AttributeFilters() | ||
{ | ||
// Given | ||
var fixture = new DotCoverCovererFixture(); | ||
fixture.Settings.WithAttributeFilter("filter1") | ||
.WithAttributeFilter("filter2"); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("Cover /TargetExecutable=\"/Working/tools/Test.exe\" " + | ||
"/TargetArguments=\"-argument\" " + | ||
"/Output=\"/Working/result.dcvr\" " + | ||
"/AttributeFilters=\"filter1;filter2\"", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Append_DisableDefaultFilters() | ||
{ | ||
// Given | ||
var fixture = new DotCoverCovererFixture(); | ||
fixture.Settings.DisableDefaultFilters = true; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("Cover /TargetExecutable=\"/Working/tools/Test.exe\" " + | ||
"/TargetArguments=\"-argument\" " + | ||
"/Output=\"/Working/result.dcvr\" " + | ||
"/DisableDefaultFilters", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Capture_XUnit() | ||
{ | ||
// Given | ||
var fixture = new DotCoverCovererFixture(); | ||
fixture.FileSystem.CreateFile("/Working/tools/xunit.console.exe"); | ||
fixture.Action = context => | ||
{ | ||
context.XUnit2( | ||
new FilePath[] { "./Test.dll" }, | ||
new XUnit2Settings { ShadowCopy = false }); | ||
}; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("Cover /TargetExecutable=\"/Working/tools/xunit.console.exe\" " + | ||
"/TargetArguments=\"\\\"/Working/Test.dll\\\" -noshadow\" " + | ||
"/Output=\"/Working/result.dcvr\"", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Capture_NUnit() | ||
{ | ||
// Given | ||
var fixture = new DotCoverCovererFixture(); | ||
fixture.FileSystem.CreateFile("/Working/tools/nunit-console.exe"); | ||
fixture.Action = context => | ||
{ | ||
context.NUnit( | ||
new FilePath[] { "./Test.dll" }, | ||
new NUnitSettings { ShadowCopy = false }); | ||
}; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("Cover /TargetExecutable=\"/Working/tools/nunit-console.exe\" " + | ||
"/TargetArguments=\"\\\"/Working/Test.dll\\\" -noshadow\" " + | ||
"/Output=\"/Working/result.dcvr\"", result.Args); | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.