Skip to content

Commit 4fc6d8c

Browse files
Merge pull request #3207 from devlead/feature/gh-2685
GH2685/2903: Integrate Cake.DotNetTool.Module
2 parents 1b6f500 + 90df47a commit 4fc6d8c

21 files changed

+1028
-2
lines changed

build/parameters.cake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ public class BuildParameters
115115
"Cake.Tool",
116116
"Cake.Frosting",
117117
"Cake.Frosting.Template",
118-
"Cake.Cli"
118+
"Cake.Cli",
119+
"Cake.DotNetTool.Module"
119120
},
120121
new [] { "cake.portable" });
121122

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<AssemblyName>Cake.DotNetTool.Module.Tests</AssemblyName>
5+
<TargetFrameworks>net461;netcoreapp2.1;netcoreapp3.1;net5.0</TargetFrameworks>
6+
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
7+
<IsCakeTestProject>true</IsCakeTestProject>
8+
</PropertyGroup>
9+
<!-- Import shared functionality -->
10+
<Import Project="..\Shared.msbuild" />
11+
<!-- Project references -->
12+
<ItemGroup>
13+
<ProjectReference Include="..\Cake.Core\Cake.Core.csproj" />
14+
<ProjectReference Include="..\Cake.DotNetTool.Module\Cake.DotNetTool.Module.csproj" />
15+
<ProjectReference Include="..\Cake.Testing\Cake.Testing.csproj" />
16+
<ProjectReference Include="..\Cake.Testing.Xunit\Cake.Testing.Xunit.csproj" />
17+
</ItemGroup>
18+
<!-- Global packages -->
19+
<ItemGroup>
20+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
21+
<PackageReference Include="xunit" Version="2.4.1" />
22+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
23+
<PrivateAssets>all</PrivateAssets>
24+
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
25+
</PackageReference>
26+
<PackageReference Include="NSubstitute" Version="4.2.2" />
27+
<PackageReference Include="Castle.Core" Version="4.4.1" />
28+
</ItemGroup>
29+
</Project>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System.Collections.Generic;
2+
using Cake.Core;
3+
using Cake.Core.Configuration;
4+
using Cake.Core.Diagnostics;
5+
using Cake.Core.IO;
6+
using Cake.Core.Packaging;
7+
using Cake.Testing;
8+
using NSubstitute;
9+
10+
namespace Cake.DotNetTool.Module.Tests
11+
{
12+
/// <summary>
13+
/// Fixture used for testing DotNetToolPackageInstaller
14+
/// </summary>
15+
internal sealed class DotNetToolPackageInstallerFixture
16+
{
17+
public ICakeEnvironment Environment { get; set; }
18+
public IFileSystem FileSystem { get; set; }
19+
public IProcessRunner ProcessRunner { get; set; }
20+
public IDotNetToolContentResolver ContentResolver { get; set; }
21+
public ICakeLog Log { get; set; }
22+
23+
public PackageReference Package { get; set; }
24+
public PackageType PackageType { get; set; }
25+
public DirectoryPath InstallPath { get; set; }
26+
27+
public ICakeConfiguration Config { get; set; }
28+
29+
/// <summary>
30+
/// Initializes a new instance of the <see cref="DotNetToolPackageInstallerFixture"/> class.
31+
/// </summary>
32+
internal DotNetToolPackageInstallerFixture()
33+
{
34+
Environment = FakeEnvironment.CreateUnixEnvironment();
35+
FileSystem = new FakeFileSystem(Environment);
36+
ProcessRunner = Substitute.For<IProcessRunner>();
37+
ContentResolver = Substitute.For<IDotNetToolContentResolver>();
38+
Log = new FakeLog();
39+
Config = Substitute.For<ICakeConfiguration>();
40+
Package = new PackageReference("dotnet:?package=windirstat");
41+
PackageType = PackageType.Addin;
42+
InstallPath = new DirectoryPath("./dotnet");
43+
}
44+
45+
/// <summary>
46+
/// Create the installer.
47+
/// </summary>
48+
/// <returns>The dotnet Tool package installer.</returns>
49+
internal DotNetToolPackageInstaller CreateInstaller()
50+
{
51+
return new DotNetToolPackageInstaller(Environment, ProcessRunner, Log, ContentResolver, Config, FileSystem);
52+
}
53+
54+
/// <summary>DotNetPackageInstallerFixture
55+
/// Installs the specified resource at the given location.
56+
/// </summary>
57+
/// <returns>The installed files.</returns>
58+
internal IReadOnlyCollection<IFile> Install()
59+
{
60+
var installer = CreateInstaller();
61+
return installer.Install(Package, PackageType, InstallPath);
62+
}
63+
64+
/// <summary>
65+
/// Determines whether this instance can install the specified resource.
66+
/// </summary>
67+
/// <returns><c>true</c> if this installer can install the specified resource; otherwise <c>false</c>.</returns>
68+
internal bool CanInstall()
69+
{
70+
var installer = CreateInstaller();
71+
return installer.CanInstall(Package, PackageType);
72+
}
73+
}
74+
}
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
using System;
2+
using Cake.Core.Packaging;
3+
using Xunit;
4+
5+
namespace Cake.DotNetTool.Module.Tests
6+
{
7+
/// <summary>
8+
/// DotNetToolPackageInstaller unit tests
9+
/// </summary>
10+
public sealed class DotNetToolPackageInstallerTests
11+
{
12+
public sealed class TheConstructor
13+
{
14+
[Fact]
15+
public void Should_Throw_If_Environment_Is_Null()
16+
{
17+
// Given
18+
var fixture = new DotNetToolPackageInstallerFixture();
19+
fixture.Environment = null;
20+
21+
// When
22+
var result = Record.Exception(() => fixture.CreateInstaller());
23+
24+
// Then
25+
Assert.IsType<ArgumentNullException>(result);
26+
Assert.Equal("environment", ((ArgumentNullException)result).ParamName);
27+
}
28+
29+
[Fact]
30+
public void Should_Throw_If_Process_Runner_Is_Null()
31+
{
32+
// Given
33+
var fixture = new DotNetToolPackageInstallerFixture();
34+
fixture.ProcessRunner = null;
35+
36+
// When
37+
var result = Record.Exception(() => fixture.CreateInstaller());
38+
39+
// Then
40+
Assert.IsType<ArgumentNullException>(result);
41+
Assert.Equal("processRunner", ((ArgumentNullException)result).ParamName);
42+
}
43+
44+
[Fact]
45+
public void Should_Throw_If_Content_Resolver_Is_Null()
46+
{
47+
// Given
48+
var fixture = new DotNetToolPackageInstallerFixture();
49+
fixture.ContentResolver = null;
50+
51+
// When
52+
var result = Record.Exception(() => fixture.CreateInstaller());
53+
54+
// Then
55+
Assert.IsType<ArgumentNullException>(result);
56+
Assert.Equal("contentResolver", ((ArgumentNullException)result).ParamName);
57+
}
58+
59+
[Fact]
60+
public void Should_Throw_If_Log_Is_Null()
61+
{
62+
// Given
63+
var fixture = new DotNetToolPackageInstallerFixture();
64+
fixture.Log = null;
65+
66+
// When
67+
var result = Record.Exception(() => fixture.CreateInstaller());
68+
69+
// Then
70+
Assert.IsType<ArgumentNullException>(result);
71+
Assert.Equal("log", ((ArgumentNullException)result).ParamName);
72+
}
73+
}
74+
75+
public sealed class TheCanInstallMethod
76+
{
77+
[Fact]
78+
public void Should_Throw_If_URI_Is_Null()
79+
{
80+
// Given
81+
var fixture = new DotNetToolPackageInstallerFixture();
82+
fixture.Package = null;
83+
84+
// When
85+
var result = Record.Exception(() => fixture.CanInstall());
86+
87+
// Then
88+
Assert.IsType<ArgumentNullException>(result);
89+
Assert.Equal("package", ((ArgumentNullException)result).ParamName);
90+
}
91+
92+
[Fact]
93+
public void Should_Be_Able_To_Install_If_Scheme_Is_Correct()
94+
{
95+
// Given
96+
var fixture = new DotNetToolPackageInstallerFixture();
97+
fixture.Package = new PackageReference("dotnet:?package=Octopus.DotNet.Cli");
98+
99+
// When
100+
var result = fixture.CanInstall();
101+
102+
// Then
103+
Assert.True(result);
104+
}
105+
106+
[Fact]
107+
public void Should_Not_Be_Able_To_Install_If_Scheme_Is_Incorrect()
108+
{
109+
// Given
110+
var fixture = new DotNetToolPackageInstallerFixture();
111+
fixture.Package = new PackageReference("homebrew:?package=windirstat");
112+
113+
// When
114+
var result = fixture.CanInstall();
115+
116+
// Then
117+
Assert.False(result);
118+
}
119+
}
120+
121+
public sealed class TheInstallMethod
122+
{
123+
[Fact]
124+
public void Should_Throw_If_Uri_Is_Null()
125+
{
126+
// Given
127+
var fixture = new DotNetToolPackageInstallerFixture();
128+
fixture.Package = null;
129+
130+
// When
131+
var result = Record.Exception(() => fixture.Install());
132+
133+
// Then
134+
Assert.IsType<ArgumentNullException>(result);
135+
Assert.Equal("package", ((ArgumentNullException)result).ParamName);
136+
}
137+
138+
[Fact]
139+
public void Should_Throw_If_Install_Path_Is_Null()
140+
{
141+
// Given
142+
var fixture = new DotNetToolPackageInstallerFixture();
143+
fixture.InstallPath = null;
144+
145+
// When
146+
var result = Record.Exception(() => fixture.Install());
147+
148+
// Then
149+
Assert.IsType<ArgumentNullException>(result);
150+
Assert.Equal("path", ((ArgumentNullException)result).ParamName);
151+
}
152+
}
153+
}
154+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<AssemblyName>Cake.DotNetTool.Module</AssemblyName>
4+
<TargetFrameworks>net461;netstandard2.0;net5.0</TargetFrameworks>
5+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
6+
<IncludeSymbols>true</IncludeSymbols>
7+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
8+
</PropertyGroup>
9+
<PropertyGroup>
10+
<CodeAnalysisRuleSet>Cake.DotNetTool.Module.ruleset</CodeAnalysisRuleSet>
11+
</PropertyGroup>
12+
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
13+
<DefineConstants>TRACE;DEBUG;NETSTANDARD</DefineConstants>
14+
</PropertyGroup>
15+
16+
<PropertyGroup>
17+
<Description>Cake Module that extends Cake with ability to install tools using dotnet cli.</Description>
18+
</PropertyGroup>
19+
20+
<!-- Import shared functionality -->
21+
<Import Project="..\Shared.msbuild" />
22+
<!-- Project references -->
23+
<ItemGroup>
24+
<ProjectReference Include="..\Cake.Core\Cake.Core.csproj" />
25+
</ItemGroup>
26+
27+
</Project>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RuleSet Name="Microsoft Managed Recommended Rules" Description="These rules focus on the most critical problems in your code, including potential security holes, application crashes, and other important logic and design errors. It is recommended to include this rule set in any custom rule set you create for your projects." ToolsVersion="10.0">
3+
<Localization ResourceAssembly="Microsoft.VisualStudio.CodeAnalysis.RuleSets.Strings.dll" ResourceBaseName="Microsoft.VisualStudio.CodeAnalysis.RuleSets.Strings.Localized">
4+
<Name Resource="MinimumRecommendedRules_Name" />
5+
<Description Resource="MinimumRecommendedRules_Description" />
6+
</Localization>
7+
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
8+
<Rule Id="CA1001" Action="Warning" />
9+
<Rule Id="CA1009" Action="Warning" />
10+
<Rule Id="CA1016" Action="Warning" />
11+
<Rule Id="CA1033" Action="Warning" />
12+
<Rule Id="CA1049" Action="Warning" />
13+
<Rule Id="CA1060" Action="Warning" />
14+
<Rule Id="CA1061" Action="Warning" />
15+
<Rule Id="CA1063" Action="Warning" />
16+
<Rule Id="CA1065" Action="Warning" />
17+
<Rule Id="CA1301" Action="Warning" />
18+
<Rule Id="CA1400" Action="Warning" />
19+
<Rule Id="CA1401" Action="Warning" />
20+
<Rule Id="CA1403" Action="Warning" />
21+
<Rule Id="CA1404" Action="Warning" />
22+
<Rule Id="CA1405" Action="Warning" />
23+
<Rule Id="CA1410" Action="Warning" />
24+
<Rule Id="CA1415" Action="Warning" />
25+
<Rule Id="CA1821" Action="Warning" />
26+
<Rule Id="CA1900" Action="Warning" />
27+
<Rule Id="CA1901" Action="Warning" />
28+
<Rule Id="CA2002" Action="Warning" />
29+
<Rule Id="CA2100" Action="Warning" />
30+
<Rule Id="CA2101" Action="Warning" />
31+
<Rule Id="CA2108" Action="Warning" />
32+
<Rule Id="CA2111" Action="Warning" />
33+
<Rule Id="CA2112" Action="Warning" />
34+
<Rule Id="CA2114" Action="Warning" />
35+
<Rule Id="CA2116" Action="Warning" />
36+
<Rule Id="CA2117" Action="Warning" />
37+
<Rule Id="CA2122" Action="Warning" />
38+
<Rule Id="CA2123" Action="Warning" />
39+
<Rule Id="CA2124" Action="Warning" />
40+
<Rule Id="CA2126" Action="Warning" />
41+
<Rule Id="CA2131" Action="Warning" />
42+
<Rule Id="CA2132" Action="Warning" />
43+
<Rule Id="CA2133" Action="Warning" />
44+
<Rule Id="CA2134" Action="Warning" />
45+
<Rule Id="CA2137" Action="Warning" />
46+
<Rule Id="CA2138" Action="Warning" />
47+
<Rule Id="CA2140" Action="Warning" />
48+
<Rule Id="CA2141" Action="Warning" />
49+
<Rule Id="CA2146" Action="Warning" />
50+
<Rule Id="CA2147" Action="Warning" />
51+
<Rule Id="CA2149" Action="Warning" />
52+
<Rule Id="CA2200" Action="Warning" />
53+
<Rule Id="CA2202" Action="Warning" />
54+
<Rule Id="CA2207" Action="Warning" />
55+
<Rule Id="CA2212" Action="Warning" />
56+
<Rule Id="CA2213" Action="Warning" />
57+
<Rule Id="CA2214" Action="Warning" />
58+
<Rule Id="CA2216" Action="Warning" />
59+
<Rule Id="CA2220" Action="Warning" />
60+
<Rule Id="CA2229" Action="Warning" />
61+
<Rule Id="CA2231" Action="Warning" />
62+
<Rule Id="CA2232" Action="Warning" />
63+
<Rule Id="CA2235" Action="Warning" />
64+
<Rule Id="CA2236" Action="Warning" />
65+
<Rule Id="CA2237" Action="Warning" />
66+
<Rule Id="CA2238" Action="Warning" />
67+
<Rule Id="CA2240" Action="Warning" />
68+
<Rule Id="CA2241" Action="Warning" />
69+
<Rule Id="CA2242" Action="Warning" />
70+
</Rules>
71+
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
72+
<Rule Id="SA1200" Action="None" />
73+
<Rule Id="SA1101" Action="None" />
74+
<Rule Id="SA1309" Action="None" />
75+
<Rule Id="SA1633" Action="None" />
76+
<Rule Id="SA1600" Action="Warning" />
77+
</Rules>
78+
</RuleSet>

0 commit comments

Comments
 (0)