Skip to content

Add ResideInNamespaceOrBelow and Its Negated Variants - #511

Open
StefanGreve wants to merge 1 commit into
TNG:mainfrom
StefanGreve:feat/add-reside-in-namespace-starting-with
Open

StefanGreve wants to merge 1 commit into
TNG:mainfrom
StefanGreve:feat/add-reside-in-namespace-starting-with

Conversation

@StefanGreve

Copy link
Copy Markdown

Motivation

In one of my projects, an architecture test restricts the visibility of everything in a Model namespace and its sub-namespaces. With the current API, the rule has to name each namespace (MyProject.Model and MyProject.Model.Options, joined by Or), so a sub-namespace added later escapes the rule silently instead of failing it. ResideInNamespaceMatching can work around this with a regular expression, but at the cost of the readability a fluent API normally provides.

Feature Description

Add ResideInNamespaceOrBelow and NotResideInNamespaceOrBelow to TypeConditionsDefinition, ResideInNamespaceOrBelow and DoNotResideInNamespaceOrBelow to TypePredicatesDefinition, and the matching methods in AddTypeCondition/AddTypePredicate, mirroring ResideInNamespace and NotResideInNamespace/DoNotResideInNamespace.

A namespace matches when its full name equals the given name or starts with it followed by a dot, compared case-insensitively like ResideInNamespace, so Foo.Bar matches Foo.Bar and Foo.Bar.Baz but not Foo.BarBaz:

Types().That().ResideInNamespaceOrBelow("Foo.Bar").Should().NotBePublic()

ResideInNamespace matches one namespace by full name and
ResideInNamespaceMatching takes an unanchored regex, so a rule over a
namespace and all of its sub-namespaces either lists each one, silently
missing any added later, or needs a pattern like ^Foo\.Bar(\.|$) to
avoid also matching Foo.BarBaz. Add ResideInNamespaceOrBelow and
NotResideInNamespaceOrBelow to TypeConditionsDefinition,
ResideInNamespaceOrBelow and DoNotResideInNamespaceOrBelow to
TypePredicatesDefinition, and the matching methods in
AddTypeCondition/AddTypePredicate, mirroring ResideInNamespace and
NotResideInNamespace/DoNotResideInNamespace.

A namespace matches when its full name equals the given name or starts
with it followed by a dot, compared case-insensitively like
ResideInNamespace, so "Foo.Bar" matches Foo.Bar and Foo.Bar.Baz but not
Foo.BarBaz.

Signed-off-by: StefanGreve <stefan.ohlsen.greve@gmail.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.55%. Comparing base (dc9f1a9) to head (7e96181).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #511      +/-   ##
==========================================
+ Coverage   86.51%   86.55%   +0.04%     
==========================================
  Files         261      261              
  Lines       12610    12648      +38     
  Branches     1233     1236       +3     
==========================================
+ Hits        10909    10947      +38     
  Misses       1359     1359              
  Partials      342      342              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants