-
Notifications
You must be signed in to change notification settings - Fork 903
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3134 from AdmiringWorm/PROJ-595/update-rule-engine
(maint) Add ability to get rules from the registered rules.
- Loading branch information
Showing
19 changed files
with
233 additions
and
34 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
73 changes: 73 additions & 0 deletions
73
src/chocolatey.tests/infrastructure.app/services/RulesServiceSpecs.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,73 @@ | ||
// Copyright © 2017 - 2021 Chocolatey Software, Inc | ||
// Copyright © 2011 - 2017 RealDimensions Software, LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
namespace chocolatey.tests.infrastructure.app.services | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using chocolatey.infrastructure.app.rules; | ||
using chocolatey.infrastructure.app.services; | ||
using chocolatey.infrastructure.rules; | ||
using chocolatey.infrastructure.services; | ||
using Should; | ||
|
||
public class RulesServiceSpecs : TinySpec | ||
{ | ||
private RuleService _service; | ||
private IReadOnlyList<ImmutableRule> _detectedRules; | ||
// We can't reference RuleIdentifiers directly as it's Internal. We should either get these from there, or do something different... | ||
private const string EmptyRequiredElement = "CHCR0001"; | ||
private const string InvalidTypeElement = "CHCU0001"; | ||
private const string MissingElementOnRequiringLicenseAcceptance = "CHCR0002"; | ||
private const string UnsupportedElementUsed = "CHCU0002"; | ||
|
||
public override void Context() | ||
{ | ||
Type[] availableRules = typeof(IRuleService).Assembly | ||
.GetTypes() | ||
.Where(t => !t.IsInterface && !t.IsAbstract && typeof(IMetadataRule).IsAssignableFrom(t)) | ||
.ToArray(); | ||
var rules = new List<IMetadataRule>(); | ||
|
||
foreach (Type availableRule in availableRules) | ||
{ | ||
// We do first here as we want it to fail if the constructor can't be found. | ||
var rule = availableRule.GetConstructors().First().Invoke(new object[] { }); | ||
rules.Add((MetadataRuleBase)rule); | ||
} | ||
|
||
_service = new RuleService(rules.ToArray()); | ||
} | ||
|
||
public override void Because() | ||
{ | ||
_detectedRules = _service.GetAllAvailableRules(); | ||
} | ||
|
||
[Fact] | ||
public void GetsRulesFromService() | ||
{ | ||
_detectedRules.Count().ShouldEqual(4); | ||
IEnumerable<string> ruleIds = _detectedRules.Select(t => t.Id); | ||
ruleIds.ShouldContain(UnsupportedElementUsed); | ||
ruleIds.ShouldContain(EmptyRequiredElement); | ||
ruleIds.ShouldContain(InvalidTypeElement); | ||
ruleIds.ShouldContain(MissingElementOnRequiringLicenseAcceptance); | ||
} | ||
} | ||
} |
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
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
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
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
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.