This repository has been archived by the owner on Oct 11, 2021. It is now read-only.
(GH-50) Specs to verify Chocolatey Package Dependency #56
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
52 changes: 52 additions & 0 deletions
52
...latey.package.validator.tests/infrastructure.app/IncludesChocolateyDependencyNoteSpecs.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,52 @@ | ||
namespace chocolatey.package.validator.tests.infrastructure.app | ||
{ | ||
using System.Collections.Generic; | ||
using System.Runtime.Versioning; | ||
using chocolatey.package.validator.infrastructure.app.rules; | ||
using NuGet; | ||
using Moq; | ||
using Should; | ||
|
||
public abstract class IncludesChocolateyDependencyNoteSpecsBase : TinySpec | ||
{ | ||
protected IncludesChocolateyDependencyNote note; | ||
protected Mock<IPackage> packageWithoutChocolateyDependency = new Mock<IPackage>(); | ||
protected Mock<IPackage> packageWithChocolateyDependency = new Mock<IPackage>(); | ||
|
||
public override void Context() | ||
{ | ||
note = new IncludesChocolateyDependencyNote(); | ||
var fiddlerPackageDependency = new PackageDependency("fiddler"); | ||
var chocolateyPackageDependency = new PackageDependency("chocolatey"); | ||
var packageDependenciesWithoutChocolatey = new List<PackageDependency> { fiddlerPackageDependency }; | ||
var packageDependenciesWithChocolatey = new List<PackageDependency> { fiddlerPackageDependency, chocolateyPackageDependency }; | ||
var dependencySetWithoutChocolatey = new PackageDependencySet(new FrameworkName(".NETFramework, Version = 4.0"), packageDependenciesWithoutChocolatey); | ||
var dependencySetWithChocolatey = new PackageDependencySet(new FrameworkName(".NETFramework, Version = 4.0"), packageDependenciesWithChocolatey); | ||
var dependencySetsWithoutChocolatey = new List<PackageDependencySet> { dependencySetWithoutChocolatey }; | ||
var dependencySetsWithChocolatey = new List<PackageDependencySet> { dependencySetWithChocolatey }; | ||
packageWithoutChocolateyDependency.Setup(p => p.DependencySets).Returns(dependencySetsWithoutChocolatey); | ||
packageWithChocolateyDependency.Setup(p => p.DependencySets).Returns(dependencySetsWithChocolatey); | ||
} | ||
} | ||
|
||
public class when_inspecting_dependencies : IncludesChocolateyDependencyNoteSpecsBase | ||
{ | ||
private string result; | ||
|
||
public override void Because() | ||
{ | ||
} | ||
|
||
[Fact] | ||
public void should_return_false_with_chocolatey_as_a_dependency() | ||
{ | ||
note.inspect_dependencies_for_chocolatey(packageWithChocolateyDependency.Object).ShouldBeFalse(); | ||
} | ||
|
||
[Fact] | ||
public void should_return_true_with_chocolatey_not_as_a_dependency() | ||
{ | ||
note.inspect_dependencies_for_chocolatey(packageWithoutChocolateyDependency.Object).ShouldBeTrue(); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -23,9 +23,14 @@ public class IncludesChocolateyDependencyNote : BasePackageRule | |
{ | ||
public override string ValidationFailureMessage { get { return "Package takes a dependency on Chocolatey, which should only be required if package uses a specific Chocolatey feature. Please see [wiki article](https://github.com/chocolatey/package-validator/wiki/ChocolateyDependency) for further information and guidance."; } } | ||
|
||
protected override PackageValidationOutput is_valid(IPackage package) | ||
public bool inspect_dependencies_for_chocolatey(IPackage package) | ||
{ | ||
return package.DependencySets.All(dependencySet => dependencySet.Dependencies.All(dependency => dependency.Id.ToLower() != "chocolatey")); | ||
} | ||
|
||
protected override PackageValidationOutput is_valid(IPackage package) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shoot, this should probably be public instead of protected. |
||
{ | ||
return inspect_dependencies_for_chocolatey(package); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we leave out framework here? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. I notice that you left it in as well, so guessing there wasn't a way without it?