Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Sort out test projects
Browse files Browse the repository at this point in the history
  • Loading branch information
caesay committed Dec 15, 2023
1 parent 2be55fb commit 37c5f67
Show file tree
Hide file tree
Showing 40 changed files with 2,730 additions and 2,965 deletions.
12 changes: 6 additions & 6 deletions Squirrel.sln
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squirrel.Packaging.OSX", "s
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squirrel.Deployment", "src\Squirrel.Deployment\Squirrel.Deployment.csproj", "{D19EA72C-E7AE-4A7B-924A-E7550901A49C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squirrel.Integration.Tests", "test\Squirrel.Integration.Tests\Squirrel.Integration.Tests.csproj", "{1A20C135-05FA-4FBA-BC53-5E6E75E136B0}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Squirrel.Packaging.Tests", "test\Squirrel.Packaging.Tests\Squirrel.Packaging.Tests.csproj", "{175B06A5-5C09-4DAB-A6AF-C8A2257BD1B6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -72,18 +72,18 @@ Global
{D19EA72C-E7AE-4A7B-924A-E7550901A49C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D19EA72C-E7AE-4A7B-924A-E7550901A49C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D19EA72C-E7AE-4A7B-924A-E7550901A49C}.Release|Any CPU.Build.0 = Release|Any CPU
{1A20C135-05FA-4FBA-BC53-5E6E75E136B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1A20C135-05FA-4FBA-BC53-5E6E75E136B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1A20C135-05FA-4FBA-BC53-5E6E75E136B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1A20C135-05FA-4FBA-BC53-5E6E75E136B0}.Release|Any CPU.Build.0 = Release|Any CPU
{175B06A5-5C09-4DAB-A6AF-C8A2257BD1B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{175B06A5-5C09-4DAB-A6AF-C8A2257BD1B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{175B06A5-5C09-4DAB-A6AF-C8A2257BD1B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{175B06A5-5C09-4DAB-A6AF-C8A2257BD1B6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{98AEB048-E27D-42F4-9440-505B7F78BAFD} = {7AC3A776-B582-4B65-9D03-BD52332B5CA3}
{519EAB50-47B8-425F-8B20-AB9548F220B4} = {7AC3A776-B582-4B65-9D03-BD52332B5CA3}
{1A20C135-05FA-4FBA-BC53-5E6E75E136B0} = {7AC3A776-B582-4B65-9D03-BD52332B5CA3}
{175B06A5-5C09-4DAB-A6AF-C8A2257BD1B6} = {7AC3A776-B582-4B65-9D03-BD52332B5CA3}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {68CA987A-9BAB-4C75-8EEB-4596BA6BBD07}
Expand Down
2 changes: 1 addition & 1 deletion src/Squirrel/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[assembly: ComVisible(false)]
[assembly: InternalsVisibleTo("Squirrel.Tests, PublicKey=" + SNK.SHA1)]
[assembly: InternalsVisibleTo("Squirrel.Integration.Tests, PublicKey=" + SNK.SHA1)]
[assembly: InternalsVisibleTo("Squirrel.Packaging.Tests, PublicKey=" + SNK.SHA1)]
[assembly: InternalsVisibleTo("Squirrel, PublicKey=" + SNK.SHA1)]
[assembly: InternalsVisibleTo("Squirrel.Deployment, PublicKey=" + SNK.SHA1)]
[assembly: InternalsVisibleTo("Squirrel.Packaging, PublicKey=" + SNK.SHA1)]
Expand Down
36 changes: 16 additions & 20 deletions test/Squirrel.CommandLine.Tests/BaseCommandTests.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
using Squirrel.CommandLine.Commands;
using Xunit;
namespace Squirrel.CommandLine.Tests;

namespace Squirrel.CommandLine.Tests
public abstract class BaseCommandTests<T> : TempFileTestBase
where T : BaseCommand, new()
{
public abstract class BaseCommandTests<T> : TempFileTestBase
where T : BaseCommand, new()
{
public virtual bool ShouldBeNonEmptyReleaseDir => false;

[Fact]
public void ReleaseDirectory_WithDirectory_ParsesValue()
{
var releaseDirectory = CreateTempDirectory();
public virtual bool ShouldBeNonEmptyReleaseDir => false;

if (ShouldBeNonEmptyReleaseDir)
CreateTempFile(releaseDirectory, "anything");
[Fact]
public void ReleaseDirectory_WithDirectory_ParsesValue()
{
var releaseDirectory = CreateTempDirectory();

BaseCommand command = new T();
if (ShouldBeNonEmptyReleaseDir)
CreateTempFile(releaseDirectory, "anything");

var cli = GetRequiredDefaultOptions() + $"--outputDir \"{releaseDirectory.FullName}\"";
var parseResult = command.ParseAndApply(cli);
BaseCommand command = new T();

Assert.Equal(releaseDirectory.FullName, command.ReleaseDirectory);
}
var cli = GetRequiredDefaultOptions() + $"--outputDir \"{releaseDirectory.FullName}\"";
var parseResult = command.ParseAndApply(cli);

protected virtual string GetRequiredDefaultOptions() => "";
Assert.Equal(releaseDirectory.FullName, command.ReleaseDirectory);
}

protected virtual string GetRequiredDefaultOptions() => "";
}
139 changes: 67 additions & 72 deletions test/Squirrel.CommandLine.Tests/Commands/GitHubCommandTests.cs
Original file line number Diff line number Diff line change
@@ -1,102 +1,97 @@
using System.CommandLine.Parsing;
using Squirrel.CommandLine.Commands;
using Xunit;
namespace Squirrel.CommandLine.Tests.Commands;

namespace Squirrel.CommandLine.Tests.Commands
public abstract class GitHubCommandTests<T> : BaseCommandTests<T>
where T : GitHubBaseCommand, new()
{
public abstract class GitHubCommandTests<T> : BaseCommandTests<T>
where T : GitHubBaseCommand, new()
[Fact]
public void RepoUrl_WithUrl_ParsesValue()
{
[Fact]
public void RepoUrl_WithUrl_ParsesValue()
{
GitHubBaseCommand command = new T();
GitHubBaseCommand command = new T();

ParseResult parseResult = command.ParseAndApply($"--repoUrl \"http://clowd.squirrel.com\"");
ParseResult parseResult = command.ParseAndApply($"--repoUrl \"http://clowd.squirrel.com\"");

Assert.Empty(parseResult.Errors);
Assert.Equal("http://clowd.squirrel.com/", command.RepoUrl);
}
Assert.Empty(parseResult.Errors);
Assert.Equal("http://clowd.squirrel.com/", command.RepoUrl);
}

[Fact]
public void RepoUrl_WithNonHttpValue_ShowsError()
{
GitHubBaseCommand command = new T();
[Fact]
public void RepoUrl_WithNonHttpValue_ShowsError()
{
GitHubBaseCommand command = new T();

ParseResult parseResult = command.ParseAndApply($"--repoUrl \"file://clowd.squirrel.com\"");
ParseResult parseResult = command.ParseAndApply($"--repoUrl \"file://clowd.squirrel.com\"");

Assert.Equal(1, parseResult.Errors.Count);
//Assert.Equal(command.RepoUrl, parseResult.Errors[0].SymbolResult?.Symbol);
Assert.StartsWith("--repoUrl must contain a Uri with one of the following schems: http, https.", parseResult.Errors[0].Message);
}
Assert.Equal(1, parseResult.Errors.Count);
//Assert.Equal(command.RepoUrl, parseResult.Errors[0].SymbolResult?.Symbol);
Assert.StartsWith("--repoUrl must contain a Uri with one of the following schems: http, https.", parseResult.Errors[0].Message);
}

[Fact]
public void RepoUrl_WithRelativeUrl_ShowsError()
{
GitHubBaseCommand command = new T();
[Fact]
public void RepoUrl_WithRelativeUrl_ShowsError()
{
GitHubBaseCommand command = new T();

ParseResult parseResult = command.ParseAndApply($"--repoUrl \"clowd.squirrel.com\"");
ParseResult parseResult = command.ParseAndApply($"--repoUrl \"clowd.squirrel.com\"");

Assert.Equal(1, parseResult.Errors.Count);
//Assert.Equal(command.RepoUrl, parseResult.Errors[0].SymbolResult?.Symbol);
Assert.StartsWith("--repoUrl must contain an absolute Uri.", parseResult.Errors[0].Message);
}
Assert.Equal(1, parseResult.Errors.Count);
//Assert.Equal(command.RepoUrl, parseResult.Errors[0].SymbolResult?.Symbol);
Assert.StartsWith("--repoUrl must contain an absolute Uri.", parseResult.Errors[0].Message);
}

[Fact]
public void Token_WithValue_ParsesValue()
{
GitHubBaseCommand command = new T();
[Fact]
public void Token_WithValue_ParsesValue()
{
GitHubBaseCommand command = new T();

string cli = GetRequiredDefaultOptions() + $"--token \"abc\"";
ParseResult parseResult = command.ParseAndApply(cli);
string cli = GetRequiredDefaultOptions() + $"--token \"abc\"";
ParseResult parseResult = command.ParseAndApply(cli);

Assert.Equal("abc", command.Token);
}
Assert.Equal("abc", command.Token);
}

protected override string GetRequiredDefaultOptions()
{
return $"--repoUrl \"https://clowd.squirrel.com\" ";
}
protected override string GetRequiredDefaultOptions()
{
return $"--repoUrl \"https://clowd.squirrel.com\" ";
}
}

public class GitHubDownloadCommandTests : GitHubCommandTests<GitHubDownloadCommand>
public class GitHubDownloadCommandTests : GitHubCommandTests<GitHubDownloadCommand>
{
[Fact]
public void Pre_BareOption_SetsFlag()
{
[Fact]
public void Pre_BareOption_SetsFlag()
{
var command = new GitHubDownloadCommand();
var command = new GitHubDownloadCommand();

string cli = GetRequiredDefaultOptions() + "--pre";
ParseResult parseResult = command.ParseAndApply(cli);
string cli = GetRequiredDefaultOptions() + "--pre";
ParseResult parseResult = command.ParseAndApply(cli);

Assert.True(command.Pre);
}
Assert.True(command.Pre);
}
}

public class GitHubUploadCommandTests : GitHubCommandTests<GitHubUploadCommand>
{
public override bool ShouldBeNonEmptyReleaseDir => true;
public class GitHubUploadCommandTests : GitHubCommandTests<GitHubUploadCommand>
{
public override bool ShouldBeNonEmptyReleaseDir => true;

[Fact]
public void Publish_BareOption_SetsFlag()
{
var command = new GitHubUploadCommand();
[Fact]
public void Publish_BareOption_SetsFlag()
{
var command = new GitHubUploadCommand();

string cli = GetRequiredDefaultOptions() + "--publish";
ParseResult parseResult = command.ParseAndApply(cli);
string cli = GetRequiredDefaultOptions() + "--publish";
ParseResult parseResult = command.ParseAndApply(cli);

Assert.True(command.Publish);
}
Assert.True(command.Publish);
}

[Fact]
public void ReleaseName_WithName_ParsesValue()
{
var command = new GitHubUploadCommand();
[Fact]
public void ReleaseName_WithName_ParsesValue()
{
var command = new GitHubUploadCommand();

string cli = GetRequiredDefaultOptions() + $"--releaseName \"my release\"";
ParseResult parseResult = command.ParseAndApply(cli);
string cli = GetRequiredDefaultOptions() + $"--releaseName \"my release\"";
ParseResult parseResult = command.ParseAndApply(cli);

Assert.Equal("my release", command.ReleaseName);
}
Assert.Equal("my release", command.ReleaseName);
}
}
Original file line number Diff line number Diff line change
@@ -1,49 +1,45 @@
using System.CommandLine.Parsing;
using Squirrel.CommandLine.Commands;
using Xunit;

namespace Squirrel.CommandLine.Tests.Commands;

namespace Squirrel.CommandLine.Tests.Commands
public class HttpDownloadCommandTests : BaseCommandTests<HttpDownloadCommand>
{
public class HttpDownloadCommandTests : BaseCommandTests<HttpDownloadCommand>
[Fact]
public void Url_WithUrl_ParsesValue()
{
[Fact]
public void Url_WithUrl_ParsesValue()
{
var command = new HttpDownloadCommand();
var command = new HttpDownloadCommand();

ParseResult parseResult = command.ParseAndApply($"--url \"http://clowd.squirrel.com\"");
ParseResult parseResult = command.ParseAndApply($"--url \"http://clowd.squirrel.com\"");

Assert.Empty(parseResult.Errors);
Assert.Equal("http://clowd.squirrel.com/", command.Url);
}
Assert.Empty(parseResult.Errors);
Assert.Equal("http://clowd.squirrel.com/", command.Url);
}

[Fact]
public void Url_WithNonHttpValue_ShowsError()
{
var command = new HttpDownloadCommand();
[Fact]
public void Url_WithNonHttpValue_ShowsError()
{
var command = new HttpDownloadCommand();

ParseResult parseResult = command.ParseAndApply($"--url \"file://clowd.squirrel.com\"");
ParseResult parseResult = command.ParseAndApply($"--url \"file://clowd.squirrel.com\"");

Assert.Equal(1, parseResult.Errors.Count);
//Assert.Equal(command.Url, parseResult.Errors[0].SymbolResult?.Symbol);
Assert.StartsWith("--url must contain a Uri with one of the following schems: http, https.", parseResult.Errors[0].Message);
}
Assert.Equal(1, parseResult.Errors.Count);
//Assert.Equal(command.Url, parseResult.Errors[0].SymbolResult?.Symbol);
Assert.StartsWith("--url must contain a Uri with one of the following schems: http, https.", parseResult.Errors[0].Message);
}

[Fact]
public void Url_WithRelativeUrl_ShowsError()
{
var command = new HttpDownloadCommand();
[Fact]
public void Url_WithRelativeUrl_ShowsError()
{
var command = new HttpDownloadCommand();

ParseResult parseResult = command.ParseAndApply($"--url \"clowd.squirrel.com\"");
ParseResult parseResult = command.ParseAndApply($"--url \"clowd.squirrel.com\"");

Assert.Equal(1, parseResult.Errors.Count);
//Assert.Equal(command.Url, parseResult.Errors[0].SymbolResult?.Symbol);
Assert.StartsWith("--url must contain an absolute Uri.", parseResult.Errors[0].Message);
}
Assert.Equal(1, parseResult.Errors.Count);
//Assert.Equal(command.Url, parseResult.Errors[0].SymbolResult?.Symbol);
Assert.StartsWith("--url must contain an absolute Uri.", parseResult.Errors[0].Message);
}

protected override string GetRequiredDefaultOptions()
{
return $"--url \"https://clowd.squirrel.com\" ";
}
protected override string GetRequiredDefaultOptions()
{
return $"--url \"https://clowd.squirrel.com\" ";
}
}
Loading

0 comments on commit 37c5f67

Please sign in to comment.