From f8839201ca9d9d2f7c5138390d69f5bee119f419 Mon Sep 17 00:00:00 2001 From: Fritz Brandhuber Date: Fri, 7 Feb 2025 17:10:20 +0100 Subject: [PATCH 1/7] Remove overloads with string parameters from most methods in the Fluent API. Instead, an IObjectProvider should be used (e.g. Types().That().HaveFullNameMatching(...)), since this allows for more flexiblity and is much clearer, what you are matching against. Added TODOs to split the methods for matching names with string into separate methods for regex and string equality. Signed-off-by: Fritz Brandhuber --- .../Syntax/Elements/GivenObjectsThat.cs | 364 +---- .../Syntax/Elements/IObjectConditions.cs | 58 +- .../Syntax/Elements/IObjectPredicates.cs | 77 +- .../Elements/Members/GivenMembersThat.cs | 55 +- .../Elements/Members/IMemberConditions.cs | 8 - .../Elements/Members/IMemberPredicates.cs | 12 - .../Members/MemberConditionsDefinition.cs | 121 +- .../Members/MemberPredicatesDefinition.cs | 107 -- .../Syntax/Elements/Members/MembersShould.cs | 53 +- .../MethodMembers/GivenMethodMembersThat.cs | 147 -- .../MethodMembers/IMethodMemberConditions.cs | 30 - .../MethodMembers/IMethodMemberPredicates.cs | 44 - .../MethodMemberConditionsDefinition.cs | 431 ------ .../MethodMemberPredicatesDefinition.cs | 289 +--- .../MethodMembers/MethodMembersShould.cs | 144 -- .../ShouldRelateToMethodMembersThat.cs | 149 +- .../Members/ShouldRelateToMembersThat.cs | 57 - .../Elements/ObjectConditionsDefinition.cs | 1206 +---------------- .../Elements/ObjectPredicatesDefinition.cs | 561 +------- .../Fluent/Syntax/Elements/ObjectsShould.cs | 365 +---- .../Elements/ShouldRelateToObjectsThat.cs | 393 +----- .../Syntax/Elements/Types/GivenTypesThat.cs | 86 +- .../Syntax/Elements/Types/ITypeConditions.cs | 20 +- .../Syntax/Elements/Types/ITypePredicates.cs | 20 +- .../Elements/Types/ShouldRelateToTypesThat.cs | 94 +- .../Types/TypeConditionsDefinition.cs | 204 +-- .../Types/TypePredicatesDefinition.cs | 152 +-- .../Syntax/Elements/Types/TypesShould.cs | 88 +- .../ArchUnitArchitectureTests.cs | 8 +- .../Dependencies/ExternalDependenciesTests.cs | 24 - .../Elements/MemberSyntaxElementsTests.cs | 78 +- .../MethodMemberSyntaxElementsTests.cs | 84 +- .../Elements/ObjectSyntaxElementsTests.cs | 123 +- .../Syntax/Elements/ObjectsShouldTests.cs | 600 +------- .../Elements/TypeSyntaxElementsTests.cs | 87 +- ExampleTest/ExampleArchUnitTest.cs | 4 +- 36 files changed, 205 insertions(+), 6138 deletions(-) diff --git a/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsThat.cs index 9b8fbbb58..c4ce3fee0 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsThat.cs @@ -21,25 +21,6 @@ public abstract class GivenObjectsThat protected GivenObjectsThat(IArchRuleCreator ruleCreator) : base(ruleCreator) { } - public TGivenRuleTypeConjunction Are(string pattern, bool useRegularExpressions = false) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.Are(pattern, useRegularExpressions) - ); - return Create(_ruleCreator); - } - - public TGivenRuleTypeConjunction Are( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.Are(patterns, useRegularExpressions) - ); - return Create(_ruleCreator); - } - public TGivenRuleTypeConjunction Are( ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects @@ -63,25 +44,6 @@ public TGivenRuleTypeConjunction Are(IObjectProvider objects) return Create(_ruleCreator); } - public TGivenRuleTypeConjunction CallAny(string pattern, bool useRegularExpressions = false) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.CallAny(pattern, useRegularExpressions) - ); - return Create(_ruleCreator); - } - - public TGivenRuleTypeConjunction CallAny( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.CallAny(patterns, useRegularExpressions) - ); - return Create(_ruleCreator); - } - public TGivenRuleTypeConjunction CallAny( MethodMember method, params MethodMember[] moreMethods @@ -105,28 +67,6 @@ public TGivenRuleTypeConjunction CallAny(IObjectProvider methods) return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DependOnAny( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.DependOnAny(pattern, useRegularExpressions) - ); - return Create(_ruleCreator); - } - - public TGivenRuleTypeConjunction DependOnAny( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.DependOnAny(patterns, useRegularExpressions) - ); - return Create(_ruleCreator); - } - public TGivenRuleTypeConjunction DependOnAny(Type firstType, params Type[] moreTypes) { _ruleCreator.AddPredicate( @@ -178,28 +118,6 @@ string description return Create(_ruleCreator); } - public TGivenRuleTypeConjunction OnlyDependOn( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.OnlyDependOn(pattern, useRegularExpressions) - ); - return Create(_ruleCreator); - } - - public TGivenRuleTypeConjunction OnlyDependOn( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.OnlyDependOn(patterns, useRegularExpressions) - ); - return Create(_ruleCreator); - } - public TGivenRuleTypeConjunction OnlyDependOn(Type firstType, params Type[] moreTypes) { _ruleCreator.AddPredicate( @@ -234,34 +152,6 @@ public TGivenRuleTypeConjunction OnlyDependOn(IEnumerable types) return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveAnyAttributes( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.HaveAnyAttributes( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - - public TGivenRuleTypeConjunction HaveAnyAttributes( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.HaveAnyAttributes( - patterns, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TGivenRuleTypeConjunction HaveAnyAttributes( Type firstAttribute, params Type[] moreAttributes @@ -314,34 +204,6 @@ public TGivenRuleTypeConjunction HaveAnyAttributes(IEnumerable attributes) return Create(_ruleCreator); } - public TGivenRuleTypeConjunction OnlyHaveAttributes( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.OnlyHaveAttributes( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - - public TGivenRuleTypeConjunction OnlyHaveAttributes( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.OnlyHaveAttributes( - patterns, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TGivenRuleTypeConjunction OnlyHaveAttributes( Type firstAttribute, params Type[] moreAttributes @@ -418,36 +280,6 @@ params object[] moreArgumentValues return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveAttributeWithArguments( - string attribute, - IEnumerable argumentValues - ) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.HaveAttributeWithArguments( - attribute, - argumentValues - ) - ); - return Create(_ruleCreator); - } - - public TGivenRuleTypeConjunction HaveAttributeWithArguments( - string attribute, - object firstArgumentValue, - params object[] moreArgumentValues - ) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.HaveAttributeWithArguments( - attribute, - firstArgumentValue, - moreArgumentValues - ) - ); - return Create(_ruleCreator); - } - public TGivenRuleTypeConjunction HaveAttributeWithArguments( Attribute attribute, IEnumerable argumentValues @@ -534,36 +366,6 @@ public TGivenRuleTypeConjunction HaveAnyAttributesWithNamedArguments( return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveAttributeWithNamedArguments( - string attribute, - IEnumerable<(string, object)> attributeArguments - ) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.HaveAttributeWithNamedArguments( - attribute, - attributeArguments - ) - ); - return Create(_ruleCreator); - } - - public TGivenRuleTypeConjunction HaveAttributeWithNamedArguments( - string attribute, - (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments - ) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.HaveAttributeWithNamedArguments( - attribute, - firstAttributeArgument, - moreAttributeArguments - ) - ); - return Create(_ruleCreator); - } - public TGivenRuleTypeConjunction HaveAttributeWithNamedArguments( Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -627,7 +429,7 @@ public TGivenRuleTypeConjunction HaveAttributeWithNamedArguments( public TGivenRuleTypeConjunction HaveName( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { _ruleCreator.AddPredicate( ObjectPredicatesDefinition.HaveName(pattern, useRegularExpressions) @@ -638,7 +440,7 @@ public TGivenRuleTypeConjunction HaveName( public TGivenRuleTypeConjunction HaveFullName( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { _ruleCreator.AddPredicate( ObjectPredicatesDefinition.HaveFullName(pattern, useRegularExpressions) @@ -716,26 +518,6 @@ public TGivenRuleTypeConjunction ArePrivateProtected() //Negations - - public TGivenRuleTypeConjunction AreNot(string pattern, bool useRegularExpressions = false) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.AreNot(pattern, useRegularExpressions) - ); - return Create(_ruleCreator); - } - - public TGivenRuleTypeConjunction AreNot( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.AreNot(patterns, useRegularExpressions) - ); - return Create(_ruleCreator); - } - public TGivenRuleTypeConjunction AreNot( ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects @@ -759,28 +541,6 @@ public TGivenRuleTypeConjunction AreNot(IObjectProvider objects) return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotCallAny( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.DoNotCallAny(pattern, useRegularExpressions) - ); - return Create(_ruleCreator); - } - - public TGivenRuleTypeConjunction DoNotCallAny( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.DoNotCallAny(patterns, useRegularExpressions) - ); - return Create(_ruleCreator); - } - public TGivenRuleTypeConjunction DoNotCallAny( MethodMember method, params MethodMember[] moreMethods @@ -804,34 +564,6 @@ public TGivenRuleTypeConjunction DoNotCallAny(IObjectProvider meth return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotDependOnAny( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.DoNotDependOnAny( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - - public TGivenRuleTypeConjunction DoNotDependOnAny( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.DoNotDependOnAny( - patterns, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TGivenRuleTypeConjunction DoNotDependOnAny(Type firstType, params Type[] moreTypes) { _ruleCreator.AddPredicate( @@ -872,34 +604,6 @@ public TGivenRuleTypeConjunction DoNotDependOnAny(IEnumerable types) return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveAnyAttributes( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.DoNotHaveAnyAttributes( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - - public TGivenRuleTypeConjunction DoNotHaveAnyAttributes( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.DoNotHaveAnyAttributes( - patterns, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TGivenRuleTypeConjunction DoNotHaveAnyAttributes( Type firstAttribute, params Type[] moreAttributes @@ -980,66 +684,6 @@ params object[] moreArgumentValues return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveAttributeWithArguments( - string attribute, - IEnumerable argumentValues - ) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments( - attribute, - argumentValues - ) - ); - return Create(_ruleCreator); - } - - public TGivenRuleTypeConjunction DoNotHaveAttributeWithArguments( - string attribute, - object firstArgumentValue, - params object[] moreArgumentValues - ) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments( - attribute, - firstArgumentValue, - moreArgumentValues - ) - ); - return Create(_ruleCreator); - } - - public TGivenRuleTypeConjunction DoNotHaveAttributeWithNamedArguments( - string attribute, - IEnumerable<(string, object)> attributeArguments - ) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments( - attribute, - attributeArguments - ) - ); - return Create(_ruleCreator); - } - - public TGivenRuleTypeConjunction DoNotHaveAttributeWithNamedArguments( - string attribute, - (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments - ) - { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments( - attribute, - firstAttributeArgument, - moreAttributeArguments - ) - ); - return Create(_ruleCreator); - } - public TGivenRuleTypeConjunction DoNotHaveAttributeWithArguments( Attribute attribute, IEnumerable argumentValues @@ -1189,7 +833,7 @@ public TGivenRuleTypeConjunction DoNotHaveAttributeWithNamedArguments( public TGivenRuleTypeConjunction DoNotHaveName( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { _ruleCreator.AddPredicate( ObjectPredicatesDefinition.DoNotHaveName(pattern, useRegularExpressions) @@ -1200,7 +844,7 @@ public TGivenRuleTypeConjunction DoNotHaveName( public TGivenRuleTypeConjunction DoNotHaveFullName( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { _ruleCreator.AddPredicate( ObjectPredicatesDefinition.DoNotHaveFullName( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/IObjectConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/IObjectConditions.cs index 01738d28b..6804b928a 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/IObjectConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/IObjectConditions.cs @@ -16,18 +16,12 @@ public interface IObjectConditions where TRuleType : ICanBeAnalyzed { TReturnType Exist(); - TReturnType Be(string pattern, bool useRegularExpressions = false); - TReturnType Be(IEnumerable patterns, bool useRegularExpressions = false); TReturnType Be(ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects); TReturnType Be(IEnumerable objects); TReturnType Be(IObjectProvider objects); - TReturnType CallAny(string pattern, bool useRegularExpressions = false); - TReturnType CallAny(IEnumerable patterns, bool useRegularExpressions = false); TReturnType CallAny(MethodMember method, params MethodMember[] moreMethods); TReturnType CallAny(IEnumerable methods); TReturnType CallAny(IObjectProvider methods); - TReturnType DependOnAny(string pattern, bool useRegularExpressions = false); - TReturnType DependOnAny(IEnumerable patterns, bool useRegularExpressions = false); TReturnType DependOnAny(IType firstType, params IType[] moreTypes); TReturnType DependOnAny(Type firstType, params Type[] moreTypes); TReturnType DependOnAny(IObjectProvider types); @@ -43,28 +37,16 @@ TReturnType FollowCustomCondition( string description, string failDescription ); - TReturnType OnlyDependOn(string pattern, bool useRegularExpressions = false); - TReturnType OnlyDependOn(IEnumerable patterns, bool useRegularExpressions = false); TReturnType OnlyDependOn(IType firstType, params IType[] moreTypes); TReturnType OnlyDependOn(Type firstType, params Type[] moreTypes); TReturnType OnlyDependOn(IObjectProvider types); TReturnType OnlyDependOn(IEnumerable types); TReturnType OnlyDependOn(IEnumerable types); - TReturnType HaveAnyAttributes(string pattern, bool useRegularExpressions = false); - TReturnType HaveAnyAttributes( - IEnumerable patterns, - bool useRegularExpressions = false - ); TReturnType HaveAnyAttributes(Attribute firstAttribute, params Attribute[] moreAttributes); TReturnType HaveAnyAttributes(Type firstAttribute, params Type[] moreAttributes); TReturnType HaveAnyAttributes(IObjectProvider attributes); TReturnType HaveAnyAttributes(IEnumerable attributes); TReturnType HaveAnyAttributes(IEnumerable attributes); - TReturnType OnlyHaveAttributes(string pattern, bool useRegularExpressions = false); - TReturnType OnlyHaveAttributes( - IEnumerable patterns, - bool useRegularExpressions = false - ); TReturnType OnlyHaveAttributes(Attribute firstAttribute, params Attribute[] moreAttributes); TReturnType OnlyHaveAttributes(Type firstAttribute, params Type[] moreAttributes); TReturnType OnlyHaveAttributes(IObjectProvider attributes); @@ -75,15 +57,6 @@ TReturnType HaveAnyAttributesWithArguments( object firstArgumentValue, params object[] moreArgumentValues ); - TReturnType HaveAttributeWithArguments( - string attribute, - IEnumerable argumentValues - ); - TReturnType HaveAttributeWithArguments( - string attribute, - object firstArgumentValue, - params object[] moreArgumentValues - ); TReturnType HaveAttributeWithArguments( Attribute attribute, IEnumerable argumentValues @@ -106,15 +79,6 @@ TReturnType HaveAnyAttributesWithNamedArguments( (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments ); - TReturnType HaveAttributeWithNamedArguments( - string attribute, - IEnumerable<(string, object)> attributeArguments - ); - TReturnType HaveAttributeWithNamedArguments( - string attribute, - (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments - ); TReturnType HaveAttributeWithNamedArguments( Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -133,8 +97,8 @@ TReturnType HaveAttributeWithNamedArguments( (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments ); - TReturnType HaveName(string pattern, bool useRegularExpressions = false); - TReturnType HaveFullName(string pattern, bool useRegularExpressions = false); + TReturnType HaveName(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations + TReturnType HaveFullName(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations TReturnType HaveNameStartingWith(string pattern); TReturnType HaveNameEndingWith(string pattern); TReturnType HaveNameContaining(string pattern); @@ -150,31 +114,17 @@ TReturnType HaveAttributeWithNamedArguments( TReturnType NotExist(); - TReturnType NotBe(string pattern, bool useRegularExpressions = false); - TReturnType NotBe(IEnumerable patterns, bool useRegularExpressions = false); TReturnType NotBe(ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects); TReturnType NotBe(IEnumerable objects); TReturnType NotBe(IObjectProvider objects); - TReturnType NotCallAny(string pattern, bool useRegularExpressions = false); - TReturnType NotCallAny(IEnumerable patterns, bool useRegularExpressions = false); TReturnType NotCallAny(MethodMember method, params MethodMember[] moreMethods); TReturnType NotCallAny(IEnumerable methods); TReturnType NotCallAny(IObjectProvider methods); - TReturnType NotDependOnAny(string pattern, bool useRegularExpressions = false); - TReturnType NotDependOnAny( - IEnumerable patterns, - bool useRegularExpressions = false - ); TReturnType NotDependOnAny(IType firstType, params IType[] moreTypes); TReturnType NotDependOnAny(Type firstType, params Type[] moreTypes); TReturnType NotDependOnAny(IObjectProvider types); TReturnType NotDependOnAny(IEnumerable types); TReturnType NotDependOnAny(IEnumerable types); - TReturnType NotHaveAnyAttributes(string pattern, bool useRegularExpressions = false); - TReturnType NotHaveAnyAttributes( - IEnumerable patterns, - bool useRegularExpressions = false - ); TReturnType NotHaveAnyAttributes( Attribute firstAttribute, params Attribute[] moreAttributes @@ -231,8 +181,8 @@ TReturnType NotHaveAttributeWithNamedArguments( (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments ); - TReturnType NotHaveName(string pattern, bool useRegularExpressions = false); - TReturnType NotHaveFullName(string pattern, bool useRegularExpressions = false); + TReturnType NotHaveName(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations + TReturnType NotHaveFullName(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations TReturnType NotHaveNameStartingWith(string pattern); TReturnType NotHaveNameEndingWith(string pattern); TReturnType NotHaveNameContaining(string pattern); diff --git a/ArchUnitNET/Fluent/Syntax/Elements/IObjectPredicates.cs b/ArchUnitNET/Fluent/Syntax/Elements/IObjectPredicates.cs index ac382780e..a2b139aa2 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/IObjectPredicates.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/IObjectPredicates.cs @@ -15,18 +15,12 @@ namespace ArchUnitNET.Fluent.Syntax.Elements public interface IObjectPredicates where TRuleType : ICanBeAnalyzed { - TReturnType Are(string pattern, bool useRegularExpressions = false); - TReturnType Are(IEnumerable patterns, bool useRegularExpressions = false); TReturnType Are(ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects); TReturnType Are(IEnumerable objects); TReturnType Are(IObjectProvider objects); - TReturnType CallAny(string pattern, bool useRegularExpressions = false); - TReturnType CallAny(IEnumerable patterns, bool useRegularExpressions = false); TReturnType CallAny(MethodMember method, params MethodMember[] moreMethods); TReturnType CallAny(IEnumerable methods); TReturnType CallAny(IObjectProvider methods); - TReturnType DependOnAny(string pattern, bool useRegularExpressions = false); - TReturnType DependOnAny(IEnumerable patterns, bool useRegularExpressions = false); TReturnType DependOnAny(Type firstType, params Type[] moreTypes); TReturnType DependOnAny(IType firstType, params IType[] moreTypes); TReturnType DependOnAny(IObjectProvider types); @@ -34,28 +28,16 @@ public interface IObjectPredicates TReturnType DependOnAny(IEnumerable types); TReturnType FollowCustomPredicate(IPredicate predicate); TReturnType FollowCustomPredicate(Func predicate, string description); - TReturnType OnlyDependOn(string pattern, bool useRegularExpressions = false); - TReturnType OnlyDependOn(IEnumerable patterns, bool useRegularExpressions = false); TReturnType OnlyDependOn(Type firstType, params Type[] moreTypes); TReturnType OnlyDependOn(IType firstType, params IType[] moreTypes); TReturnType OnlyDependOn(IObjectProvider types); TReturnType OnlyDependOn(IEnumerable types); TReturnType OnlyDependOn(IEnumerable types); - TReturnType HaveAnyAttributes(string pattern, bool useRegularExpressions = false); - TReturnType HaveAnyAttributes( - IEnumerable patterns, - bool useRegularExpressions = false - ); TReturnType HaveAnyAttributes(Attribute firstAttribute, params Attribute[] moreAttributes); TReturnType HaveAnyAttributes(Type firstAttribute, params Type[] moreAttributes); TReturnType HaveAnyAttributes(IObjectProvider attributes); TReturnType HaveAnyAttributes(IEnumerable attributes); TReturnType HaveAnyAttributes(IEnumerable attributes); - TReturnType OnlyHaveAttributes(string pattern, bool useRegularExpressions = false); - TReturnType OnlyHaveAttributes( - IEnumerable patterns, - bool useRegularExpressions = false - ); TReturnType OnlyHaveAttributes(Attribute firstAttribute, params Attribute[] moreAttributes); TReturnType OnlyHaveAttributes(Type firstAttribute, params Type[] moreAttributes); TReturnType OnlyHaveAttributes(IObjectProvider attributes); @@ -66,15 +48,6 @@ TReturnType HaveAnyAttributesWithArguments( object firstArgumentValue, params object[] moreArgumentValues ); - TReturnType HaveAttributeWithArguments( - string attribute, - IEnumerable argumentValues - ); - TReturnType HaveAttributeWithArguments( - string attribute, - object firstArgumentValue, - params object[] moreArgumentValues - ); TReturnType HaveAttributeWithArguments( Attribute attribute, IEnumerable argumentValues @@ -97,15 +70,6 @@ TReturnType HaveAnyAttributesWithNamedArguments( (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments ); - TReturnType HaveAttributeWithNamedArguments( - string attribute, - IEnumerable<(string, object)> attributeArguments - ); - TReturnType HaveAttributeWithNamedArguments( - string attribute, - (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments - ); TReturnType HaveAttributeWithNamedArguments( Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -124,8 +88,8 @@ TReturnType HaveAttributeWithNamedArguments( (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments ); - TReturnType HaveName(string pattern, bool useRegularExpressions = false); - TReturnType HaveFullName(string pattern, bool useRegularExpressions = false); + TReturnType HaveName(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations + TReturnType HaveFullName(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations TReturnType HaveNameStartingWith(string pattern); TReturnType HaveNameEndingWith(string pattern); TReturnType HaveNameContaining(string pattern); @@ -139,32 +103,17 @@ TReturnType HaveAttributeWithNamedArguments( //Negations - - TReturnType AreNot(string pattern, bool useRegularExpressions = false); - TReturnType AreNot(IEnumerable patterns, bool useRegularExpressions = false); TReturnType AreNot(ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects); TReturnType AreNot(IEnumerable objects); TReturnType AreNot(IObjectProvider objects); - TReturnType DoNotCallAny(string pattern, bool useRegularExpressions = false); - TReturnType DoNotCallAny(IEnumerable patterns, bool useRegularExpressions = false); TReturnType DoNotCallAny(MethodMember method, params MethodMember[] moreMethods); TReturnType DoNotCallAny(IEnumerable methods); TReturnType DoNotCallAny(IObjectProvider methods); - TReturnType DoNotDependOnAny(string pattern, bool useRegularExpressions = false); - TReturnType DoNotDependOnAny( - IEnumerable patterns, - bool useRegularExpressions = false - ); TReturnType DoNotDependOnAny(Type firstType, params Type[] moreTypes); TReturnType DoNotDependOnAny(IType firstType, params IType[] moreTypes); TReturnType DoNotDependOnAny(IObjectProvider types); TReturnType DoNotDependOnAny(IEnumerable types); TReturnType DoNotDependOnAny(IEnumerable types); - TReturnType DoNotHaveAnyAttributes(string pattern, bool useRegularExpressions = false); - TReturnType DoNotHaveAnyAttributes( - IEnumerable patterns, - bool useRegularExpressions = false - ); TReturnType DoNotHaveAnyAttributes( Attribute firstAttribute, params Attribute[] moreAttributes @@ -178,15 +127,6 @@ TReturnType DoNotHaveAnyAttributesWithArguments( object firstArgumentValue, params object[] moreArgumentValues ); - TReturnType DoNotHaveAttributeWithArguments( - string attribute, - IEnumerable argumentValues - ); - TReturnType DoNotHaveAttributeWithArguments( - string attribute, - object firstArgumentValue, - params object[] moreArgumentValues - ); TReturnType DoNotHaveAttributeWithArguments( Attribute attribute, IEnumerable argumentValues @@ -212,15 +152,6 @@ TReturnType DoNotHaveAnyAttributesWithNamedArguments( (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments ); - TReturnType DoNotHaveAttributeWithNamedArguments( - string attribute, - IEnumerable<(string, object)> attributeArguments - ); - TReturnType DoNotHaveAttributeWithNamedArguments( - string attribute, - (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments - ); TReturnType DoNotHaveAttributeWithNamedArguments( Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -239,8 +170,8 @@ TReturnType DoNotHaveAttributeWithNamedArguments( (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments ); - TReturnType DoNotHaveName(string pattern, bool useRegularExpressions = false); - TReturnType DoNotHaveFullName(string pattern, bool useRegularExpressions = false); + TReturnType DoNotHaveName(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations + TReturnType DoNotHaveFullName(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations TReturnType DoNotHaveNameStartingWith(string pattern); TReturnType DoNotHaveNameEndingWith(string pattern); TReturnType DoNotHaveNameContaining(string pattern); diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembersThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembersThat.cs index d8737365e..073a5d5f2 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembersThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembersThat.cs @@ -20,29 +20,7 @@ public class GivenMembersThat // ReSharper disable once MemberCanBeProtected.Global public GivenMembersThat(IArchRuleCreator ruleCreator) : base(ruleCreator) { } - - public TGivenRuleTypeConjunction AreDeclaredIn( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - MemberPredicatesDefinition.AreDeclaredIn(pattern, useRegularExpressions) - ); - return Create(_ruleCreator); - } - - public TGivenRuleTypeConjunction AreDeclaredIn( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - MemberPredicatesDefinition.AreDeclaredIn(patterns, useRegularExpressions) - ); - return Create(_ruleCreator); - } - + public TGivenRuleTypeConjunction AreDeclaredIn(IType firstType, params IType[] moreTypes) { _ruleCreator.AddPredicate( @@ -96,36 +74,7 @@ public TGivenRuleTypeConjunction AreImmutable() } //Negations - - - public TGivenRuleTypeConjunction AreNotDeclaredIn( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - MemberPredicatesDefinition.AreNotDeclaredIn( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - - public TGivenRuleTypeConjunction AreNotDeclaredIn( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - MemberPredicatesDefinition.AreNotDeclaredIn( - patterns, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - + public TGivenRuleTypeConjunction AreNotDeclaredIn(IType firstType, params IType[] moreTypes) { _ruleCreator.AddPredicate( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/IMemberConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/IMemberConditions.cs index 563673905..71b03e596 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/IMemberConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/IMemberConditions.cs @@ -14,8 +14,6 @@ public interface IMemberConditions : IObjectConditions where TRuleType : ICanBeAnalyzed { - TReturnType BeDeclaredIn(string pattern, bool useRegularExpressions = false); - TReturnType BeDeclaredIn(IEnumerable patterns, bool useRegularExpressions = false); TReturnType BeDeclaredIn(IType firstType, params IType[] moreTypes); TReturnType BeDeclaredIn(Type firstType, params Type[] moreTypes); TReturnType BeDeclaredIn(IObjectProvider types); @@ -25,12 +23,6 @@ public interface IMemberConditions TReturnType BeImmutable(); //Negations - - TReturnType NotBeDeclaredIn(string pattern, bool useRegularExpressions = false); - TReturnType NotBeDeclaredIn( - IEnumerable patterns, - bool useRegularExpressions = false - ); TReturnType NotBeDeclaredIn(IType firstType, params IType[] moreTypes); TReturnType NotBeDeclaredIn(Type firstType, params Type[] moreTypes); TReturnType NotBeDeclaredIn(IObjectProvider types); diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/IMemberPredicates.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/IMemberPredicates.cs index 2369a5b03..f425d0926 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/IMemberPredicates.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/IMemberPredicates.cs @@ -14,11 +14,6 @@ public interface IMemberPredicates : IObjectPredicates where TRuleType : ICanBeAnalyzed { - TRuleTypeConjunction AreDeclaredIn(string pattern, bool useRegularExpressions = false); - TRuleTypeConjunction AreDeclaredIn( - IEnumerable patterns, - bool useRegularExpressions = false - ); TRuleTypeConjunction AreDeclaredIn(IType firstType, params IType[] moreTypes); TRuleTypeConjunction AreDeclaredIn(Type firstType, params Type[] moreTypes); TRuleTypeConjunction AreDeclaredIn(IObjectProvider types); @@ -28,13 +23,6 @@ TRuleTypeConjunction AreDeclaredIn( TRuleTypeConjunction AreImmutable(); //Negations - - - TRuleTypeConjunction AreNotDeclaredIn(string pattern, bool useRegularExpressions = false); - TRuleTypeConjunction AreNotDeclaredIn( - IEnumerable patterns, - bool useRegularExpressions = false - ); TRuleTypeConjunction AreNotDeclaredIn(IType firstType, params IType[] moreTypes); TRuleTypeConjunction AreNotDeclaredIn(Type firstType, params Type[] moreTypes); TRuleTypeConjunction AreNotDeclaredIn(IObjectProvider types); diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberConditionsDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberConditionsDefinition.cs index 090dfa88e..15c69a58b 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberConditionsDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberConditionsDefinition.cs @@ -17,64 +17,6 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Members public static class MemberConditionsDefinition where TRuleType : IMember { - public static ICondition BeDeclaredIn( - string pattern, - bool useRegularExpressions = false - ) - { - return new SimpleCondition( - member => member.IsDeclaredIn(pattern, useRegularExpressions), - member => "is declared in " + member.DeclaringType.FullName, - "be declared in types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static ICondition BeDeclaredIn( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Condition(TRuleType ruleType) - { - return patternList.Any(pattern => - ruleType.IsDeclaredIn(pattern, useRegularExpressions) - ); - } - - string description; - if (patternList.IsNullOrEmpty()) - { - description = "be declared in no type (always false)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(obj => !obj.Equals(firstPattern)) - .Distinct() - .Aggregate( - "be declared in types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimpleCondition( - Condition, - member => "is declared in " + member.DeclaringType.FullName, - description - ); - } - public static ICondition BeDeclaredIn(IType firstType, params IType[] moreTypes) { var types = new List { firstType }; @@ -258,66 +200,6 @@ public static RelationCondition BeDeclaredInTypesThat() } //Negations - - - public static ICondition NotBeDeclaredIn( - string pattern, - bool useRegularExpressions = false - ) - { - return new SimpleCondition( - member => !member.IsDeclaredIn(pattern, useRegularExpressions), - member => "is declared in " + member.DeclaringType.FullName, - "not be declared in types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static ICondition NotBeDeclaredIn( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Condition(TRuleType ruleType) - { - return patternList.All(pattern => - !ruleType.IsDeclaredIn(pattern, useRegularExpressions) - ); - } - - string description; - if (patternList.IsNullOrEmpty()) - { - description = "not be declared in no type (always true)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(obj => !obj.Equals(firstPattern)) - .Distinct() - .Aggregate( - "not be declared in types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimpleCondition( - Condition, - member => "is declared in " + member.DeclaringType.FullName, - description - ); - } - public static ICondition NotBeDeclaredIn( IType firstType, params IType[] moreTypes @@ -492,8 +374,7 @@ public static ICondition NotBeImmutable() } //Relation Condition Negations - - + public static RelationCondition NotBeDeclaredInTypesThat() { return new RelationCondition( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberPredicatesDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberPredicatesDefinition.cs index 6c1257f7b..73675f420 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberPredicatesDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberPredicatesDefinition.cs @@ -17,59 +17,6 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Members public static class MemberPredicatesDefinition where T : IMember { - public static IPredicate AreDeclaredIn( - string pattern, - bool useRegularExpressions = false - ) - { - return new SimplePredicate( - member => member.IsDeclaredIn(pattern, useRegularExpressions), - "are declared in types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static IPredicate AreDeclaredIn( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Condition(T ruleType) - { - return patternList.Any(pattern => - ruleType.IsDeclaredIn(pattern, useRegularExpressions) - ); - } - - string description; - if (patternList.IsNullOrEmpty()) - { - description = "are declared in no type (always false)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(obj => !obj.Equals(firstPattern)) - .Distinct() - .Aggregate( - "are declared in types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimplePredicate(Condition, description); - } - public static IPredicate AreDeclaredIn(IType firstType, params IType[] moreTypes) { var types = new List { firstType }; @@ -195,60 +142,6 @@ public static IPredicate AreImmutable() //Negations - - public static IPredicate AreNotDeclaredIn( - string pattern, - bool useRegularExpressions = false - ) - { - return new SimplePredicate( - member => !member.IsDeclaredIn(pattern, useRegularExpressions), - "are not declared in types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static IPredicate AreNotDeclaredIn( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Condition(T ruleType) - { - return patternList.All(pattern => - !ruleType.IsDeclaredIn(pattern, useRegularExpressions) - ); - } - - string description; - if (patternList.IsNullOrEmpty()) - { - description = "are not declared in no type (always true)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(obj => !obj.Equals(firstPattern)) - .Distinct() - .Aggregate( - "are not declared in types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimplePredicate(Condition, description); - } - public static IPredicate AreNotDeclaredIn(IType firstType, params IType[] moreTypes) { var types = new List { firstType }; diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MembersShould.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MembersShould.cs index 6ce322882..3486d75ed 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MembersShould.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MembersShould.cs @@ -21,29 +21,7 @@ public class MembersShould // ReSharper disable once MemberCanBeProtected.Global public MembersShould(IArchRuleCreator ruleCreator) : base(ruleCreator) { } - - public TRuleTypeShouldConjunction BeDeclaredIn( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - MemberConditionsDefinition.BeDeclaredIn(pattern, useRegularExpressions) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction BeDeclaredIn( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - MemberConditionsDefinition.BeDeclaredIn(patterns, useRegularExpressions) - ); - return Create(_ruleCreator); - } - + public TRuleTypeShouldConjunction BeDeclaredIn(IType firstType, params IType[] moreTypes) { _ruleCreator.AddCondition( @@ -115,35 +93,6 @@ public ShouldRelateToTypesThat< //Negations - - public TRuleTypeShouldConjunction NotBeDeclaredIn( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - MemberConditionsDefinition.NotBeDeclaredIn( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction NotBeDeclaredIn( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - MemberConditionsDefinition.NotBeDeclaredIn( - patterns, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction NotBeDeclaredIn(IType firstType, params IType[] moreTypes) { _ruleCreator.AddCondition( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/GivenMethodMembersThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/GivenMethodMembersThat.cs index bfd76c9c5..ad3d7e23b 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/GivenMethodMembersThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/GivenMethodMembersThat.cs @@ -29,28 +29,6 @@ public GivenMethodMembersConjunction AreVirtual() return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction AreCalledBy( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.AreCalledBy(pattern, useRegularExpressions) - ); - return new GivenMethodMembersConjunction(_ruleCreator); - } - - public GivenMethodMembersConjunction AreCalledBy( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.AreCalledBy(patterns, useRegularExpressions) - ); - return new GivenMethodMembersConjunction(_ruleCreator); - } - public GivenMethodMembersConjunction AreCalledBy(IType firstType, params IType[] moreTypes) { _ruleCreator.AddPredicate( @@ -85,34 +63,6 @@ public GivenMethodMembersConjunction AreCalledBy(IEnumerable types) return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo( - pattern, - useRegularExpressions - ) - ); - return new GivenMethodMembersConjunction(_ruleCreator); - } - - public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo( - patterns, - useRegularExpressions - ) - ); - return new GivenMethodMembersConjunction(_ruleCreator); - } - public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo( IType firstType, params IType[] moreTypes @@ -161,28 +111,6 @@ public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo(IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.HaveReturnType(patterns, useRegularExpressions) - ); - return new GivenMethodMembersConjunction(_ruleCreator); - } - public GivenMethodMembersConjunction HaveReturnType( IType firstType, params IType[] moreTypes @@ -235,28 +163,6 @@ public GivenMethodMembersConjunction AreNotVirtual() return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction AreNotCalledBy( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.AreNotCalledBy(pattern, useRegularExpressions) - ); - return new GivenMethodMembersConjunction(_ruleCreator); - } - - public GivenMethodMembersConjunction AreNotCalledBy( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.AreNotCalledBy(patterns, useRegularExpressions) - ); - return new GivenMethodMembersConjunction(_ruleCreator); - } - public GivenMethodMembersConjunction AreNotCalledBy( IType firstType, params IType[] moreTypes @@ -294,34 +200,6 @@ public GivenMethodMembersConjunction AreNotCalledBy(IEnumerable types) return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction DoNotHaveDependencyInMethodBodyTo( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo( - pattern, - useRegularExpressions - ) - ); - return new GivenMethodMembersConjunction(_ruleCreator); - } - - public GivenMethodMembersConjunction DoNotHaveDependencyInMethodBodyTo( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo( - patterns, - useRegularExpressions - ) - ); - return new GivenMethodMembersConjunction(_ruleCreator); - } - public GivenMethodMembersConjunction DoNotHaveDependencyInMethodBodyTo( IType firstType, params IType[] moreTypes @@ -377,31 +255,6 @@ IEnumerable types return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction DoNotHaveReturnType( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.DoNotHaveReturnType(pattern, useRegularExpressions) - ); - return new GivenMethodMembersConjunction(_ruleCreator); - } - - public GivenMethodMembersConjunction DoNotHaveReturnType( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.DoNotHaveReturnType( - patterns, - useRegularExpressions - ) - ); - return new GivenMethodMembersConjunction(_ruleCreator); - } - public GivenMethodMembersConjunction DoNotHaveReturnType( IType firstType, params IType[] moreTypes diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IMethodMemberConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IMethodMemberConditions.cs index 4620039a1..9886ff23f 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IMethodMemberConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IMethodMemberConditions.cs @@ -16,31 +16,16 @@ public interface IMethodMemberConditions { TReturnType BeConstructor(); TReturnType BeVirtual(); - TReturnType BeCalledBy(string pattern, bool useRegularExpressions = false); - TReturnType BeCalledBy(IEnumerable patterns, bool useRegularExpressions = false); TReturnType BeCalledBy(IType firstType, params IType[] moreTypes); TReturnType BeCalledBy(Type type, params Type[] moreTypes); TReturnType BeCalledBy(IObjectProvider types); TReturnType BeCalledBy(IEnumerable types); TReturnType BeCalledBy(IEnumerable types); - TReturnType HaveDependencyInMethodBodyTo( - string pattern, - bool useRegularExpressions = false - ); - TReturnType HaveDependencyInMethodBodyTo( - IEnumerable patterns, - bool useRegularExpressions = false - ); TReturnType HaveDependencyInMethodBodyTo(IType firstType, params IType[] moreTypes); TReturnType HaveDependencyInMethodBodyTo(Type type, params Type[] moreTypes); TReturnType HaveDependencyInMethodBodyTo(IObjectProvider types); TReturnType HaveDependencyInMethodBodyTo(IEnumerable types); TReturnType HaveDependencyInMethodBodyTo(IEnumerable types); - TReturnType HaveReturnType(string pattern, bool useRegularExpressions = false); - TReturnType HaveReturnType( - IEnumerable patterns, - bool useRegularExpressions = false - ); TReturnType HaveReturnType(IType firstType, params IType[] moreTypes); TReturnType HaveReturnType(IEnumerable types); TReturnType HaveReturnType(IObjectProvider types); @@ -52,31 +37,16 @@ TReturnType HaveReturnType( TReturnType BeNoConstructor(); TReturnType NotBeVirtual(); - TReturnType NotBeCalledBy(string pattern, bool useRegularExpressions = false); - TReturnType NotBeCalledBy(IEnumerable patterns, bool useRegularExpressions = false); TReturnType NotBeCalledBy(IType firstType, params IType[] moreTypes); TReturnType NotBeCalledBy(Type type, params Type[] moreTypes); TReturnType NotBeCalledBy(IObjectProvider types); TReturnType NotBeCalledBy(IEnumerable types); TReturnType NotBeCalledBy(IEnumerable types); - TReturnType NotHaveDependencyInMethodBodyTo( - string pattern, - bool useRegularExpressions = false - ); - TReturnType NotHaveDependencyInMethodBodyTo( - IEnumerable patterns, - bool useRegularExpressions = false - ); TReturnType NotHaveDependencyInMethodBodyTo(IType firstType, params IType[] moreTypes); TReturnType NotHaveDependencyInMethodBodyTo(Type type, params Type[] moreTypes); TReturnType NotHaveDependencyInMethodBodyTo(IObjectProvider types); TReturnType NotHaveDependencyInMethodBodyTo(IEnumerable types); TReturnType NotHaveDependencyInMethodBodyTo(IEnumerable types); - TReturnType NotHaveReturnType(string pattern, bool useRegularExpressions = false); - TReturnType NotHaveReturnType( - IEnumerable patterns, - bool useRegularExpressions = false - ); TReturnType NotHaveReturnType(IType firstType, params IType[] moreTypes); TReturnType NotHaveReturnType(IEnumerable types); TReturnType NotHaveReturnType(IObjectProvider types); diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IMethodMemberPredicates.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IMethodMemberPredicates.cs index d4cfcbf36..29abc991f 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IMethodMemberPredicates.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IMethodMemberPredicates.cs @@ -16,26 +16,11 @@ public interface IMethodMemberPredicates { TRuleTypeConjunction AreConstructors(); TRuleTypeConjunction AreVirtual(); - TRuleTypeConjunction AreCalledBy(string pattern, bool useRegularExpressions = false); - TRuleTypeConjunction AreCalledBy( - IEnumerable patterns, - bool useRegularExpressions = false - ); TRuleTypeConjunction AreCalledBy(IType firstType, params IType[] moreTypes); TRuleTypeConjunction AreCalledBy(Type type, params Type[] moreTypes); TRuleTypeConjunction AreCalledBy(IObjectProvider types); TRuleTypeConjunction AreCalledBy(IEnumerable types); TRuleTypeConjunction AreCalledBy(IEnumerable types); - TRuleTypeConjunction HaveDependencyInMethodBodyTo( - string pattern, - bool useRegularExpressions = false - ); - - TRuleTypeConjunction HaveDependencyInMethodBodyTo( - IEnumerable patterns, - bool useRegularExpressions = false - ); - TRuleTypeConjunction HaveDependencyInMethodBodyTo( IType firstType, params IType[] moreTypes @@ -44,11 +29,6 @@ params IType[] moreTypes TRuleTypeConjunction HaveDependencyInMethodBodyTo(IObjectProvider types); TRuleTypeConjunction HaveDependencyInMethodBodyTo(IEnumerable types); TRuleTypeConjunction HaveDependencyInMethodBodyTo(IEnumerable types); - TRuleTypeConjunction HaveReturnType(string pattern, bool useRegularExpressions = false); - TRuleTypeConjunction HaveReturnType( - IEnumerable patterns, - bool useRegularExpressions = false - ); TRuleTypeConjunction HaveReturnType(IType firstType, params IType[] moreTypes); TRuleTypeConjunction HaveReturnType(IEnumerable types); TRuleTypeConjunction HaveReturnType(IObjectProvider types); @@ -60,26 +40,11 @@ TRuleTypeConjunction HaveReturnType( TRuleTypeConjunction AreNoConstructors(); TRuleTypeConjunction AreNotVirtual(); - TRuleTypeConjunction AreNotCalledBy(string pattern, bool useRegularExpressions = false); - TRuleTypeConjunction AreNotCalledBy( - IEnumerable patterns, - bool useRegularExpressions = false - ); TRuleTypeConjunction AreNotCalledBy(IType firstType, params IType[] moreTypes); TRuleTypeConjunction AreNotCalledBy(Type type, params Type[] moreTypes); TRuleTypeConjunction AreNotCalledBy(IObjectProvider types); TRuleTypeConjunction AreNotCalledBy(IEnumerable types); TRuleTypeConjunction AreNotCalledBy(IEnumerable types); - TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo( - string pattern, - bool useRegularExpressions = false - ); - - TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo( - IEnumerable patterns, - bool useRegularExpressions = false - ); - TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo( IType firstType, params IType[] moreTypes @@ -88,15 +53,6 @@ params IType[] moreTypes TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo(IObjectProvider types); TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo(IEnumerable types); TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo(IEnumerable types); - - TRuleTypeConjunction DoNotHaveReturnType( - string pattern, - bool useRegularExpressions = false - ); - TRuleTypeConjunction DoNotHaveReturnType( - IEnumerable patterns, - bool useRegularExpressions = false - ); TRuleTypeConjunction DoNotHaveReturnType(IType firstType, params IType[] moreTypes); TRuleTypeConjunction DoNotHaveReturnType(IEnumerable types); TRuleTypeConjunction DoNotHaveReturnType(IObjectProvider types); diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberConditionsDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberConditionsDefinition.cs index 2afd38a9f..e0beab35f 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberConditionsDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberConditionsDefinition.cs @@ -34,77 +34,6 @@ public static ICondition BeVirtual() ); } - public static ICondition BeCalledBy( - string pattern, - bool useRegularExpressions = false - ) - { - return new SimpleCondition( - member => member.IsCalledBy(pattern, useRegularExpressions), - "be called by types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"", - "is called by a type with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static ICondition BeCalledBy( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Condition(MethodMember ruleType) - { - return patternList.Any(pattern => - ruleType.IsCalledBy(pattern, useRegularExpressions) - ); - } - - string description; - string failDescription; - if (patternList.IsNullOrEmpty()) - { - description = "be called by one of no types (always false)"; - failDescription = "is not called by one of no types (always true)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(type => !type.Equals(firstPattern)) - .Distinct() - .Aggregate( - "be called by types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - failDescription = patternList - .Where(type => !type.Equals(firstPattern)) - .Distinct() - .Aggregate( - "is not called by types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimpleCondition(Condition, description, failDescription); - } - public static ICondition BeCalledBy(IType firstType, params IType[] moreTypes) { var types = new List { firstType }; @@ -279,78 +208,6 @@ Architecture architecture return new ArchitectureCondition(Condition, description); } - public static ICondition HaveDependencyInMethodBodyTo( - string pattern, - bool useRegularExpressions = false - ) - { - return new SimpleCondition( - member => member.HasDependencyInMethodBodyTo(pattern, useRegularExpressions), - "have dependencies in method body to types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"", - "does not have dependencies in method body to a type with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static ICondition HaveDependencyInMethodBodyTo( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Condition(MethodMember ruleType) - { - return patternList.Any(pattern => - ruleType.HasDependencyInMethodBodyTo(pattern, useRegularExpressions) - ); - } - - string description; - string failDescription; - if (patternList.IsNullOrEmpty()) - { - description = "have dependency in method body to one of no types (always false)"; - failDescription = - "does not have dependencies in method body to one of no types (always true)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(type => !type.Equals(firstPattern)) - .Distinct() - .Aggregate( - "have dependencies in method body to types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - failDescription = patternList - .Where(type => !type.Equals(firstPattern)) - .Distinct() - .Aggregate( - "does not have dependencies in method body to types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimpleCondition(Condition, description, failDescription); - } - public static ICondition HaveDependencyInMethodBodyTo( IType firstType, params IType[] moreTypes @@ -558,62 +415,6 @@ Architecture architecture return new ArchitectureCondition(Condition, description); } - public static ICondition HaveReturnType( - string pattern, - bool useRegularExpressions = false - ) - { - var description = - "have return type with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\""; - - var failDescription = - "does not have return type with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\""; - - return new SimpleCondition( - member => member.ReturnType.FullNameMatches(pattern, useRegularExpressions), - description, - failDescription - ); - } - - public static ICondition HaveReturnType( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternsArray = patterns.ToArray(); - var description = - "have return type with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + string.Join("\" or \"", patternsArray) - + "\""; - - var failDescription = - "does not have return type with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + string.Join("\" or \"", patternsArray) - + "\""; - - bool Condition(MethodMember member) - { - return patternsArray.Any(pattern => - member.ReturnType.FullNameMatches(pattern, useRegularExpressions) - ); - } - - return new SimpleCondition(Condition, description, failDescription); - } - public static ICondition HaveReturnType( IType firstType, params IType[] moreTypes @@ -726,93 +527,6 @@ public static ICondition NotBeVirtual() ); } - public static ICondition NotBeCalledBy( - string pattern, - bool useRegularExpressions = false - ) - { - ConditionResult Condition(MethodMember member) - { - var pass = true; - var description = "is called by"; - foreach ( - var type in member - .GetMethodCallDependencies(true) - .Select(dependency => dependency.Origin) - .Distinct() - ) - { - if (type.FullNameMatches(pattern, useRegularExpressions)) - { - description += (pass ? " " : " and ") + type.FullName; - pass = false; - } - } - - return new ConditionResult(member, pass, description); - } - - return new SimpleCondition( - Condition, - "not be called by types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static ICondition NotBeCalledBy( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Condition(MethodMember ruleType) - { - return !patternList.Any(pattern => - ruleType.IsCalledBy(pattern, useRegularExpressions) - ); - } - - string description; - string failDescription; - if (patternList.IsNullOrEmpty()) - { - description = "not be called by one of no types (always true)"; - failDescription = "is called by one of no types (always false)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(type => !type.Equals(firstPattern)) - .Distinct() - .Aggregate( - "not be called by types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - failDescription = patternList - .Where(type => !type.Equals(firstPattern)) - .Distinct() - .Aggregate( - "is called by types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimpleCondition(Condition, description, failDescription); - } - public static ICondition NotBeCalledBy( IType firstType, params IType[] moreTypes @@ -993,95 +707,6 @@ Architecture architecture return new ArchitectureCondition(Condition, description); } - public static ICondition NotHaveDependencyInMethodBodyTo( - string pattern, - bool useRegularExpressions = false - ) - { - ConditionResult Condition(MethodMember member) - { - var pass = true; - var description = "does have dependencies in method body to"; - foreach ( - var type in member - .GetBodyTypeMemberDependencies() - .Select(dependency => dependency.Target) - .Distinct() - ) - { - if (type.FullNameMatches(pattern, useRegularExpressions)) - { - description += (pass ? " " : " and ") + type.FullName; - pass = false; - } - } - - return new ConditionResult(member, pass, description); - } - - return new SimpleCondition( - Condition, - "not have dependencies in method body to types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static ICondition NotHaveDependencyInMethodBodyTo( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Condition(MethodMember ruleType) - { - return !patternList.Any(pattern => - ruleType.HasDependencyInMethodBodyTo(pattern, useRegularExpressions) - ); - } - - string description; - string failDescription; - if (patternList.IsNullOrEmpty()) - { - description = - "not have dependencies in method body to one of no types (always true)"; - failDescription = - "does have dependencies in method body to one of no types (always false)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(type => !type.Equals(firstPattern)) - .Distinct() - .Aggregate( - "not have dependencies in method body to types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - failDescription = patternList - .Where(type => !type.Equals(firstPattern)) - .Distinct() - .Aggregate( - "does have dependencies in method body to types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimpleCondition(Condition, description, failDescription); - } - public static ICondition NotHaveDependencyInMethodBodyTo( IType firstType, params IType[] moreTypes @@ -1293,62 +918,6 @@ Architecture architecture return new ArchitectureCondition(Condition, description); } - public static ICondition NotHaveReturnType( - string pattern, - bool useRegularExpressions = false - ) - { - var description = - "not have return type with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\""; - - var failDescription = - "does have return type with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\""; - - return new SimpleCondition( - member => !member.ReturnType.FullNameMatches(pattern, useRegularExpressions), - description, - failDescription - ); - } - - public static ICondition NotHaveReturnType( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternsArray = patterns.ToArray(); - var description = - "not have return type with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + string.Join("\" or \"", patternsArray) - + "\""; - - var failDescription = - "does have return type with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + string.Join("\" or \"", patternsArray) - + "\""; - - bool Condition(MethodMember member) - { - return patternsArray.All(pattern => - !member.ReturnType.FullNameMatches(pattern, useRegularExpressions) - ); - } - - return new SimpleCondition(Condition, description, failDescription); - } - public static ICondition NotHaveReturnType( IType firstType, params IType[] moreTypes diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberPredicatesDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberPredicatesDefinition.cs index 8d6047544..cc673e801 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberPredicatesDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberPredicatesDefinition.cs @@ -29,59 +29,6 @@ public static IPredicate AreVirtual() return new SimplePredicate(member => member.IsVirtual, "are virtual"); } - public static IPredicate AreCalledBy( - string pattern, - bool useRegularExpressions = false - ) - { - return new SimplePredicate( - member => member.IsCalledBy(pattern, useRegularExpressions), - "are called by types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static IPredicate AreCalledBy( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Condition(MethodMember ruleType) - { - return patternList.Any(pattern => - ruleType.IsCalledBy(pattern, useRegularExpressions) - ); - } - - string description; - if (patternList.IsNullOrEmpty()) - { - description = "are called by one of no types (always false)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(type => !type.Equals(firstPattern)) - .Distinct() - .Aggregate( - "are called by types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimplePredicate(Condition, description); - } - public static IPredicate AreCalledBy( IType firstType, params IType[] moreTypes @@ -190,59 +137,6 @@ Architecture architecture return new ArchitecturePredicate(Condition, description); } - public static IPredicate HaveDependencyInMethodBodyTo( - string pattern, - bool useRegularExpressions = false - ) - { - return new SimplePredicate( - member => member.HasDependencyInMethodBodyTo(pattern, useRegularExpressions), - "have dependencies in method body to types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static IPredicate HaveDependencyInMethodBodyTo( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Condition(MethodMember ruleType) - { - return patternList.Any(pattern => - ruleType.HasDependencyInMethodBodyTo(pattern, useRegularExpressions) - ); - } - - string description; - if (patternList.IsNullOrEmpty()) - { - description = "have dependencies in method body to one of no types (always false)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(type => !type.Equals(firstPattern)) - .Distinct() - .Aggregate( - "have dependencies in method body to types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimplePredicate(Condition, description); - } - public static IPredicate HaveDependencyInMethodBodyTo( IType firstType, params IType[] moreTypes @@ -371,43 +265,6 @@ Architecture architecture return new ArchitecturePredicate(Condition, description); } - public static IPredicate HaveReturnType( - string pattern, - bool useRegularExpressions = false - ) - { - return new SimplePredicate( - member => member.ReturnType.FullNameMatches(pattern, useRegularExpressions), - "have return type with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static IPredicate HaveReturnType( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternsArray = patterns.ToArray(); - var description = - "have return type with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + string.Join("\" or \"", patternsArray) - + "\""; - - return new SimplePredicate( - member => - patternsArray.Any(pattern => - member.ReturnType.FullNameMatches(pattern, useRegularExpressions) - ), - description - ); - } - public static IPredicate HaveReturnType( IType firstType, params IType[] moreTypes @@ -491,59 +348,6 @@ public static IPredicate AreNotVirtual() ); } - public static IPredicate AreNotCalledBy( - string pattern, - bool useRegularExpressions = false - ) - { - return new SimplePredicate( - member => !member.IsCalledBy(pattern, useRegularExpressions), - "are not called by types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static IPredicate AreNotCalledBy( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Condition(MethodMember ruleType) - { - return !patternList.Any(pattern => - ruleType.IsCalledBy(pattern, useRegularExpressions) - ); - } - - string description; - if (patternList.IsNullOrEmpty()) - { - description = "are not called by one of no types (always true)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(type => !type.Equals(firstPattern)) - .Distinct() - .Aggregate( - "are not called by types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimplePredicate(Condition, description); - } - public static IPredicate AreNotCalledBy( IType firstType, params IType[] moreTypes @@ -654,61 +458,7 @@ Architecture architecture return new ArchitecturePredicate(Condition, description); } - - public static IPredicate DoNotHaveDependencyInMethodBodyTo( - string pattern, - bool useRegularExpressions = false - ) - { - return new SimplePredicate( - member => !member.HasDependencyInMethodBodyTo(pattern, useRegularExpressions), - "do not have dependencies in method body to types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static IPredicate DoNotHaveDependencyInMethodBodyTo( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Condition(MethodMember ruleType) - { - return !patternList.Any(pattern => - ruleType.HasDependencyInMethodBodyTo(pattern, useRegularExpressions) - ); - } - - string description; - if (patternList.IsNullOrEmpty()) - { - description = - "do not have dependencies in method body to one of no types (always true)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(type => !type.Equals(firstPattern)) - .Distinct() - .Aggregate( - "do not have dependencies in method body to types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimplePredicate(Condition, description); - } - + public static IPredicate DoNotHaveDependencyInMethodBodyTo( IType firstType, params IType[] moreTypes @@ -842,43 +592,6 @@ Architecture architecture return new ArchitecturePredicate(Condition, description); } - public static IPredicate DoNotHaveReturnType( - string pattern, - bool useRegularExpressions = false - ) - { - return new SimplePredicate( - member => !member.ReturnType.FullNameMatches(pattern, useRegularExpressions), - "do not have return type with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static IPredicate DoNotHaveReturnType( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternsArray = patterns.ToArray(); - var description = - "do not have return type with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + string.Join("\" or \"", patternsArray) - + "\""; - - return new SimplePredicate( - member => - patternsArray.All(pattern => - !member.ReturnType.FullNameMatches(pattern, useRegularExpressions) - ), - description - ); - } - public static IPredicate DoNotHaveReturnType( IType firstType, params IType[] moreTypes diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMembersShould.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMembersShould.cs index 318eea920..785d2994c 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMembersShould.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMembersShould.cs @@ -29,28 +29,6 @@ public MethodMembersShouldConjunction BeVirtual() return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction BeCalledBy( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.BeCalledBy(pattern, useRegularExpressions) - ); - return new MethodMembersShouldConjunction(_ruleCreator); - } - - public MethodMembersShouldConjunction BeCalledBy( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.BeCalledBy(patterns, useRegularExpressions) - ); - return new MethodMembersShouldConjunction(_ruleCreator); - } - public MethodMembersShouldConjunction BeCalledBy(IType firstType, params IType[] moreTypes) { _ruleCreator.AddCondition( @@ -83,34 +61,6 @@ public MethodMembersShouldConjunction BeCalledBy(IEnumerable types) return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction HaveDependencyInMethodBodyTo( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.HaveDependencyInMethodBodyTo( - pattern, - useRegularExpressions - ) - ); - return new MethodMembersShouldConjunction(_ruleCreator); - } - - public MethodMembersShouldConjunction HaveDependencyInMethodBodyTo( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.HaveDependencyInMethodBodyTo( - patterns, - useRegularExpressions - ) - ); - return new MethodMembersShouldConjunction(_ruleCreator); - } - public MethodMembersShouldConjunction HaveDependencyInMethodBodyTo( IType firstType, params IType[] moreTypes @@ -159,28 +109,6 @@ public MethodMembersShouldConjunction HaveDependencyInMethodBodyTo(IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.HaveReturnType(patterns, useRegularExpressions) - ); - return new MethodMembersShouldConjunction(_ruleCreator); - } - public MethodMembersShouldConjunction HaveReturnType( IType firstType, params IType[] moreTypes @@ -233,28 +161,6 @@ public MethodMembersShouldConjunction NotBeVirtual() return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction NotBeCalledBy( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.NotBeCalledBy(pattern, useRegularExpressions) - ); - return new MethodMembersShouldConjunction(_ruleCreator); - } - - public MethodMembersShouldConjunction NotBeCalledBy( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.NotBeCalledBy(patterns, useRegularExpressions) - ); - return new MethodMembersShouldConjunction(_ruleCreator); - } - public MethodMembersShouldConjunction NotBeCalledBy( IType firstType, params IType[] moreTypes @@ -292,34 +198,6 @@ public MethodMembersShouldConjunction NotBeCalledBy(IEnumerable types) return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction NotHaveDependencyInMethodBodyTo( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.NotHaveDependencyInMethodBodyTo( - pattern, - useRegularExpressions - ) - ); - return new MethodMembersShouldConjunction(_ruleCreator); - } - - public MethodMembersShouldConjunction NotHaveDependencyInMethodBodyTo( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.NotHaveDependencyInMethodBodyTo( - patterns, - useRegularExpressions - ) - ); - return new MethodMembersShouldConjunction(_ruleCreator); - } - public MethodMembersShouldConjunction NotHaveDependencyInMethodBodyTo( IType firstType, params IType[] moreTypes @@ -375,28 +253,6 @@ IEnumerable types return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction NotHaveReturnType( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.NotHaveReturnType(pattern, useRegularExpressions) - ); - return new MethodMembersShouldConjunction(_ruleCreator); - } - - public MethodMembersShouldConjunction NotHaveReturnType( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.NotHaveReturnType(patterns, useRegularExpressions) - ); - return new MethodMembersShouldConjunction(_ruleCreator); - } - public MethodMembersShouldConjunction NotHaveReturnType( IType firstType, params IType[] moreTypes diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/ShouldRelateToMethodMembersThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/ShouldRelateToMethodMembersThat.cs index 78236f36d..2d36973c5 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/ShouldRelateToMethodMembersThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/ShouldRelateToMethodMembersThat.cs @@ -34,28 +34,6 @@ public TRuleTypeShouldConjunction AreVirtual() return Create(_ruleCreator); } - public TRuleTypeShouldConjunction AreCalledBy( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.AreCalledBy(pattern, useRegularExpressions) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction AreCalledBy( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.AreCalledBy(patterns, useRegularExpressions) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction AreCalledBy(IType firstType, params IType[] moreTypes) { _ruleCreator.ContinueComplexCondition( @@ -96,34 +74,6 @@ public TRuleTypeShouldConjunction AreCalledBy(IEnumerable types) return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveDependencyInMethodBodyTo( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction HaveDependencyInMethodBodyTo( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo( - patterns, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction HaveDependencyInMethodBodyTo( IType firstType, params IType[] moreTypes @@ -169,29 +119,7 @@ public TRuleTypeShouldConjunction HaveDependencyInMethodBodyTo(IEnumerable ); return Create(_ruleCreator); } - - public TRuleTypeShouldConjunction HaveReturnType( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.HaveReturnType(pattern, useRegularExpressions) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction HaveReturnType( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.HaveReturnType(patterns, useRegularExpressions) - ); - return Create(_ruleCreator); - } - + public TRuleTypeShouldConjunction HaveReturnType(IType firstType, params IType[] moreTypes) { _ruleCreator.ContinueComplexCondition( @@ -249,28 +177,6 @@ public TRuleTypeShouldConjunction AreNotVirtual() return Create(_ruleCreator); } - public TRuleTypeShouldConjunction AreNotCalledBy( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.AreNotCalledBy(pattern, useRegularExpressions) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction AreNotCalledBy( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.AreNotCalledBy(patterns, useRegularExpressions) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction AreNotCalledBy(IType firstType, params IType[] moreTypes) { _ruleCreator.ContinueComplexCondition( @@ -311,34 +217,6 @@ public TRuleTypeShouldConjunction AreNotCalledBy(IEnumerable types) return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveDependencyInMethodBodyTo( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction DoNotHaveDependencyInMethodBodyTo( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo( - patterns, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction DoNotHaveDependencyInMethodBodyTo( IType firstType, params IType[] moreTypes @@ -392,31 +270,6 @@ public TRuleTypeShouldConjunction DoNotHaveDependencyInMethodBodyTo(IEnumerable< return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveReturnType( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.DoNotHaveReturnType(pattern, useRegularExpressions) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction DoNotHaveReturnType( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.DoNotHaveReturnType( - patterns, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction DoNotHaveReturnType( IType firstType, params IType[] moreTypes diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/ShouldRelateToMembersThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/ShouldRelateToMembersThat.cs index 186175ee5..33f66449e 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/ShouldRelateToMembersThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/ShouldRelateToMembersThat.cs @@ -21,34 +21,6 @@ public class ShouldRelateToMembersThat ruleCreator) : base(ruleCreator) { } - public TRuleTypeShouldConjunction AreDeclaredIn( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - MemberPredicatesDefinition.AreDeclaredIn( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction AreDeclaredIn( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - MemberPredicatesDefinition.AreDeclaredIn( - patterns, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction AreDeclaredIn(IType firstType, params IType[] moreTypes) { _ruleCreator.ContinueComplexCondition( @@ -115,35 +87,6 @@ public TRuleTypeShouldConjunction AreImmutable() //Negations - - public TRuleTypeShouldConjunction AreNotDeclaredIn( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - MemberPredicatesDefinition.AreNotDeclaredIn( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction AreNotDeclaredIn( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - MemberPredicatesDefinition.AreNotDeclaredIn( - patterns, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction AreNotDeclaredIn( IType firstType, params IType[] moreTypes diff --git a/ArchUnitNET/Fluent/Syntax/Elements/ObjectConditionsDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/ObjectConditionsDefinition.cs index acf152b39..9107e9b30 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/ObjectConditionsDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/ObjectConditionsDefinition.cs @@ -25,71 +25,6 @@ public static ICondition Exist() return new ExistsCondition(true); } - public static ICondition Be(string pattern, bool useRegularExpressions = false) - { - return new SimpleCondition( - obj => obj.FullNameMatches(pattern, useRegularExpressions), - "have full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"", - "does not have full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static ICondition Be( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - string description; - string failDescription; - if (patternList.IsNullOrEmpty()) - { - description = "not exist"; - failDescription = "does exist"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(pattern => !pattern.Equals(firstPattern)) - .Distinct() - .Aggregate( - "have full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - failDescription = patternList - .Where(pattern => !pattern.Equals(firstPattern)) - .Distinct() - .Aggregate( - "does not have full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimpleCondition( - obj => - patternList.Any(pattern => obj.FullNameMatches(pattern, useRegularExpressions)), - description, - failDescription - ); - } - public static ICondition Be( ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects @@ -178,78 +113,7 @@ Architecture architecture "be " + objectProvider.Description ); } - - public static ICondition CallAny( - string pattern, - bool useRegularExpressions = false - ) - { - return new SimpleCondition( - obj => obj.CallsMethod(pattern, useRegularExpressions), - "calls any method with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"", - "does not call any method with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static ICondition CallAny( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Condition(TRuleType ruleType) - { - return patternList.Any(pattern => - ruleType.CallsMethod(pattern, useRegularExpressions) - ); - } - - string description; - string failDescription; - if (patternList.IsNullOrEmpty()) - { - description = "call one of no methods (impossible)"; - failDescription = "does not call one of no methods (always true)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(pattern => !pattern.Equals(firstPattern)) - .Distinct() - .Aggregate( - "calls any method with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - failDescription = patternList - .Where(pattern => !pattern.Equals(firstPattern)) - .Distinct() - .Aggregate( - "does not call any methods with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimpleCondition(Condition, description, failDescription); - } - + public static ICondition CallAny( MethodMember method, params MethodMember[] moreMethods @@ -348,81 +212,6 @@ IEnumerable Condition(IEnumerable ruleTypes) return new EnumerableCondition(Condition, description); } - public static ICondition DependOnAny( - string pattern, - bool useRegularExpressions = false - ) - { - return new SimpleCondition( - obj => obj.DependsOn(pattern, useRegularExpressions), - "depend on any types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"", - "does not depend on any type with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static ICondition DependOnAny( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - bool Condition(TRuleType ruleType, Architecture architecture) - { - return !ruleType.GetTypeDependencies(architecture).IsNullOrEmpty() - && ruleType - .GetTypeDependencies(architecture) - .Any(target => - patternList.Any(pattern => - target.FullNameMatches(pattern, useRegularExpressions) - ) - ); - } - - string description; - string failDescription; - if (patternList.IsNullOrEmpty()) - { - description = "depend on one of no types (impossible)"; - failDescription = "does not depend on no types (always true)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(pattern => !pattern.Equals(firstPattern)) - .Distinct() - .Aggregate( - "depend on any types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - failDescription = patternList - .Where(pattern => !pattern.Equals(firstPattern)) - .Distinct() - .Aggregate( - "does not depend any types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new ArchitectureCondition(Condition, description, failDescription); - } - public static ICondition DependOnAny(IType firstType, params IType[] moreTypes) { var types = new List { firstType }; @@ -612,92 +401,6 @@ string failDescription return new SimpleCondition(condition, description, failDescription); } - public static ICondition OnlyDependOn( - string pattern, - bool useRegularExpressions = false - ) - { - ConditionResult Condition(TRuleType ruleType) - { - var pass = true; - var dynamicFailDescription = "does depend on"; - foreach (var dependency in ruleType.GetTypeDependencies()) - { - if (!dependency.FullNameMatches(pattern, useRegularExpressions)) - { - dynamicFailDescription += pass - ? " " + dependency.FullName - : " and " + dependency.FullName; - pass = false; - } - } - - return new ConditionResult(ruleType, pass, dynamicFailDescription); - } - - return new SimpleCondition( - Condition, - "only depend on types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static ICondition OnlyDependOn( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - ConditionResult Condition(TRuleType ruleType) - { - var pass = true; - var dynamicFailDescription = "does depend on"; - foreach (var dependency in ruleType.GetTypeDependencies()) - { - if ( - !patternList.Any(pattern => - dependency.FullNameMatches(pattern, useRegularExpressions) - ) - ) - { - dynamicFailDescription += pass - ? " " + dependency.FullName - : " and " + dependency.FullName; - pass = false; - } - } - - return new ConditionResult(ruleType, pass, dynamicFailDescription); - } - - string description; - if (patternList.IsNullOrEmpty()) - { - description = "have no dependencies"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(pattern => !pattern.Equals(firstPattern)) - .Distinct() - .Aggregate( - "only depend on types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimpleCondition(Condition, description); - } - public static ICondition OnlyDependOn(IType firstType, params IType[] moreTypes) { var types = new List { firstType }; @@ -875,79 +578,6 @@ var type in failedObject.GetTypeDependencies().Except(archUnitTypeList) return new ArchitectureCondition(Condition, description); } - public static ICondition HaveAnyAttributes( - string pattern, - bool useRegularExpressions = false - ) - { - return new SimpleCondition( - obj => obj.HasAttribute(pattern, useRegularExpressions), - "have any attribute with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"", - "does not have any attribute with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static ICondition HaveAnyAttributes( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Condition(TRuleType ruleType) - { - return ruleType.Attributes.Any(attribute => - patternList.Any(pattern => - attribute.FullNameMatches(pattern, useRegularExpressions) - ) - ); - } - - string description; - string failDescription; - if (patternList.IsNullOrEmpty()) - { - description = "have one of no attributes (impossible)"; - failDescription = "does not have one of no attributes (always true)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(pattern => !pattern.Equals(firstPattern)) - .Distinct() - .Aggregate( - "have any attribute with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - failDescription = patternList - .Where(pattern => !pattern.Equals(firstPattern)) - .Distinct() - .Aggregate( - "does not have any attribute with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimpleCondition(Condition, description, failDescription); - } - public static ICondition HaveAnyAttributes( Attribute firstAttribute, params Attribute[] moreAttributes @@ -1107,80 +737,6 @@ Architecture architecture return new ArchitectureCondition(Condition, description); } - public static ICondition OnlyHaveAttributes( - string pattern, - bool useRegularExpressions = false - ) - { - return new SimpleCondition( - obj => obj.OnlyHasAttributes(pattern, useRegularExpressions), - "only have attributes with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"", - "does not only have attributes with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static ICondition OnlyHaveAttributes( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Condition(TRuleType ruleType) - { - return ruleType.Attributes.IsNullOrEmpty() - || ruleType.Attributes.All(attribute => - patternList.Any(pattern => - attribute.FullNameMatches(pattern, useRegularExpressions) - ) - ); - } - - string description; - string failDescription; - if (patternList.IsNullOrEmpty()) - { - description = "have no attributes"; - failDescription = "does have attributes"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(pattern => !pattern.Equals(firstPattern)) - .Distinct() - .Aggregate( - "only have attributes with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " and \"" + pattern + "\"" - ); - failDescription = patternList - .Where(pattern => !pattern.Equals(firstPattern)) - .Distinct() - .Aggregate( - "does not only have attributes with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimpleCondition(Condition, description, failDescription); - } - public static ICondition OnlyHaveAttributes( Attribute firstAttribute, params Attribute[] moreAttributes @@ -1368,18 +924,7 @@ params object[] moreArgumentValues argumentValues.AddRange(moreArgumentValues); return HaveAnyAttributesWithArguments(argumentValues); } - - public static ICondition HaveAttributeWithArguments( - string attribute, - object firstArgumentValue, - params object[] moreArgumentValues - ) - { - var argumentValues = new List { firstArgumentValue }; - argumentValues.AddRange(moreArgumentValues); - return HaveAttributeWithArguments(attribute, argumentValues); - } - + public static ICondition HaveAttributeWithArguments( Attribute attribute, object firstArgumentValue, @@ -1412,17 +957,6 @@ public static ICondition HaveAnyAttributesWithNamedArguments( return HaveAnyAttributesWithNamedArguments(attributeArguments); } - public static ICondition HaveAttributeWithNamedArguments( - string attribute, - (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments - ) - { - var attributeArguments = new List<(string, object)> { firstAttributeArgument }; - attributeArguments.AddRange(moreAttributeArguments); - return HaveAttributeWithNamedArguments(attribute, attributeArguments); - } - public static ICondition HaveAttributeWithNamedArguments( Attribute attribute, (string, object) firstAttributeArgument, @@ -1513,97 +1047,16 @@ bool Condition(TRuleType obj, Architecture architecture) } else if (!attributeArguments.Contains(arg)) { - return false; - } - } - - return true; - } - - return new ArchitectureCondition(Condition, failDescription, description); - } - - public static ICondition HaveAttributeWithArguments( - [NotNull] string attribute, - IEnumerable argumentValues - ) - { - string description, - failDescription; - var argumentValueList = argumentValues?.ToList() ?? new List { null }; - if (argumentValueList.IsNullOrEmpty()) - { - description = "have attribute \"" + attribute + "\""; - failDescription = "does not have attribute \"" + attribute + "\""; - } - else - { - var firstArgument = argumentValueList.First(); - description = argumentValueList - .Where(att => att != firstArgument) - .Aggregate( - "have attribute \"" - + attribute - + "\" with arguments \"" - + firstArgument - + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\"" - ); - failDescription = argumentValueList - .Where(att => att != firstArgument) - .Aggregate( - "does not have attribute \"" - + attribute - + "\" with arguments \"" - + firstArgument - + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\"" - ); - } - - bool Condition(TRuleType obj, Architecture architecture) - { - foreach (var attributeInstance in obj.AttributeInstances) - { - if (!attributeInstance.Type.FullNameMatches(attribute)) - { - goto NextAttribute; - } - - var attributeArguments = attributeInstance - .AttributeArguments.Select(arg => arg.Value) - .ToList(); - var typeAttributeArguments = attributeArguments - .OfType>() - .Select(t => t.Type) - .Union(attributeArguments.OfType()) - .ToList(); - foreach (var arg in argumentValueList) - { - if (arg is Type argType) - { - if (typeAttributeArguments.All(t => t.FullName != argType.FullName)) - { - goto NextAttribute; - } - } - else if (!attributeArguments.Contains(arg)) - { - goto NextAttribute; - } + return false; } - - return true; - NextAttribute: - ; } - return false; + return true; } - return new ArchitectureCondition(Condition, description, failDescription); + return new ArchitectureCondition(Condition, failDescription, description); } - + public static ICondition HaveAttributeWithArguments( [NotNull] Attribute attribute, IEnumerable argumentValues @@ -1867,98 +1320,7 @@ bool Condition(TRuleType obj, Architecture architecture) return new ArchitectureCondition(Condition, failDescription, description); } - - public static ICondition HaveAttributeWithNamedArguments( - [NotNull] string attribute, - IEnumerable<(string, object)> attributeArguments - ) - { - string description, - failDescription; - var argumentList = attributeArguments.ToList(); - if (argumentList.IsNullOrEmpty()) - { - description = "have attribute \"" + attribute + "\""; - failDescription = "does not have attribute \"" + attribute + "\""; - } - else - { - var firstArgument = argumentList.First(); - description = argumentList - .Where(att => att != firstArgument) - .Aggregate( - "have attribute \"" - + attribute - + "\" with named arguments \"" - + firstArgument.Item1 - + "=" - + firstArgument.Item2 - + "\"", - (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" - ); - failDescription = argumentList - .Where(att => att != firstArgument) - .Aggregate( - "does not have attribute \"" - + attribute - + "\" with named arguments \"" - + firstArgument.Item1 - + "=" - + firstArgument.Item2 - + "\"", - (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" - ); - } - - bool Condition(TRuleType obj, Architecture architecture) - { - foreach (var attributeInstance in obj.AttributeInstances) - { - if (!attributeInstance.Type.FullNameMatches(attribute)) - { - goto NextAttribute; - } - - var attributeArgs = attributeInstance - .AttributeArguments.OfType() - .Select(arg => (arg.Name, arg.Value)) - .ToList(); - var typeAttributeArguments = attributeArgs - .Where(arg => arg.Value is ITypeInstance || arg.Value is IType) - .ToList(); - foreach (var arg in argumentList) - { - if (arg.Item2 is Type argType) - { - if ( - typeAttributeArguments.All(t => - t.Name != arg.Item1 - || t.Value is ITypeInstance typeInstance - && typeInstance.Type.FullName != argType.FullName - || t.Value is IType type && type.FullName != argType.FullName - ) - ) - { - goto NextAttribute; - } - } - else if (!attributeArgs.Contains(arg)) - { - goto NextAttribute; - } - } - - return true; - NextAttribute: - ; - } - - return false; - } - - return new ArchitectureCondition(Condition, description, failDescription); - } - + public static ICondition HaveAttributeWithNamedArguments( [NotNull] Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -2155,7 +1517,7 @@ bool Condition(TRuleType obj, Architecture architecture) public static ICondition HaveName( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { return new SimpleCondition( obj => obj.NameMatches(pattern, useRegularExpressions), @@ -2171,7 +1533,7 @@ public static ICondition HaveName( public static ICondition HaveFullName( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { return new SimpleCondition( obj => obj.FullNameMatches(pattern, useRegularExpressions), @@ -2321,59 +1683,6 @@ public static ICondition NotExist() return new ExistsCondition(false); } - public static ICondition NotBe( - string pattern, - bool useRegularExpressions = false - ) - { - return new SimpleCondition( - obj => !obj.FullNameMatches(pattern, useRegularExpressions), - obj => "is " + obj.FullName, - "not have full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static ICondition NotBe( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - string description; - if (patternList.IsNullOrEmpty()) - { - description = "exist"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(pattern => !pattern.Equals(firstPattern)) - .Distinct() - .Aggregate( - "not have full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimpleCondition( - obj => - patternList.All(pattern => - !obj.FullNameMatches(pattern, useRegularExpressions) - ), - obj => "is " + obj.FullName, - description - ); - } - public static ICondition NotBe( ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects @@ -2457,93 +1766,7 @@ Architecture architecture "not be " + objectProvider.Description ); } - - public static ICondition NotCallAny( - string pattern, - bool useRegularExpressions = false - ) - { - ConditionResult Condition(TRuleType ruleType) - { - var pass = true; - var dynamicFailDescription = "does call"; - foreach (var dependency in ruleType.GetCalledMethods()) - { - if (dependency.FullNameMatches(pattern, useRegularExpressions)) - { - dynamicFailDescription += pass - ? " " + dependency.FullName - : " and " + dependency.FullName; - pass = false; - } - } - - return new ConditionResult(ruleType, pass, dynamicFailDescription); - } - - return new SimpleCondition( - Condition, - "not call any method with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static ICondition NotCallAny( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - ConditionResult Condition(TRuleType ruleType) - { - var pass = true; - var dynamicFailDescription = "does call"; - foreach (var dependency in ruleType.GetCalledMethods()) - { - if ( - patternList.Any(pattern => - dependency.FullNameMatches(pattern, useRegularExpressions) - ) - ) - { - dynamicFailDescription += pass - ? " " + dependency.FullName - : " and " + dependency.FullName; - pass = false; - } - } - - return new ConditionResult(ruleType, pass, dynamicFailDescription); - } - - string description; - if (patternList.IsNullOrEmpty()) - { - description = "not call no methods (always true)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(pattern => !pattern.Equals(firstPattern)) - .Distinct() - .Aggregate( - "not call methods with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimpleCondition(Condition, description); - } - + public static ICondition NotCallAny( MethodMember method, params MethodMember[] moreMethods @@ -2599,135 +1822,49 @@ IEnumerable Condition(IEnumerable ruleTypes) { var typeList = ruleTypes.ToList(); var failedObjects = typeList - .Where(type => type.GetCalledMethods().Intersect(methodList).Any()) - .ToList(); - foreach (var failedObject in failedObjects) - { - var dynamicFailDescription = "does call"; - var first = true; - foreach (var method in failedObject.GetCalledMethods().Intersect(methodList)) - { - dynamicFailDescription += first - ? " " + method.FullName - : " and " + method.FullName; - first = false; - } - - yield return new ConditionResult(failedObject, false, dynamicFailDescription); - } - - foreach (var passedObject in typeList.Except(failedObjects)) - { - yield return new ConditionResult(passedObject, true); - } - } - - string description; - if (methodList.IsNullOrEmpty()) - { - description = "not call no methods (always true)"; - } - else - { - var firstMethod = methodList.First(); - description = methodList - .Where(obj => !obj.Equals(firstMethod)) - .Distinct() - .Aggregate( - "not call \"" + firstMethod.FullName + "\"", - (current, obj) => current + " or \"" + obj.FullName + "\"" - ); - } - - return new EnumerableCondition(Condition, description); - } - - public static ICondition NotDependOnAny( - string pattern, - bool useRegularExpressions = false - ) - { - ConditionResult Condition(TRuleType ruleType) - { - var pass = true; - var dynamicFailDescription = "does depend on"; - foreach (var dependency in ruleType.GetTypeDependencies()) - { - if (dependency.FullNameMatches(pattern, useRegularExpressions)) - { - dynamicFailDescription += pass - ? " " + dependency.FullName - : " and " + dependency.FullName; - pass = false; - } - } - - return new ConditionResult(ruleType, pass, dynamicFailDescription); - } - - return new SimpleCondition( - Condition, - "not depend on any types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static ICondition NotDependOnAny( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - ConditionResult Condition(TRuleType ruleType) - { - var pass = true; - var dynamicFailDescription = "does depend on"; - foreach (var dependency in ruleType.GetTypeDependencies()) + .Where(type => type.GetCalledMethods().Intersect(methodList).Any()) + .ToList(); + foreach (var failedObject in failedObjects) { - if ( - patternList.Any(pattern => - dependency.FullNameMatches(pattern, useRegularExpressions) - ) - ) + var dynamicFailDescription = "does call"; + var first = true; + foreach (var method in failedObject.GetCalledMethods().Intersect(methodList)) { - dynamicFailDescription += pass - ? " " + dependency.FullName - : " and " + dependency.FullName; - pass = false; + dynamicFailDescription += first + ? " " + method.FullName + : " and " + method.FullName; + first = false; } + + yield return new ConditionResult(failedObject, false, dynamicFailDescription); } - return new ConditionResult(ruleType, pass, dynamicFailDescription); + foreach (var passedObject in typeList.Except(failedObjects)) + { + yield return new ConditionResult(passedObject, true); + } } string description; - if (patternList.IsNullOrEmpty()) + if (methodList.IsNullOrEmpty()) { - description = "not depend on no types (always true)"; + description = "not call no methods (always true)"; } else { - var firstPattern = patternList.First(); - description = patternList - .Where(pattern => !pattern.Equals(firstPattern)) + var firstMethod = methodList.First(); + description = methodList + .Where(obj => !obj.Equals(firstMethod)) .Distinct() .Aggregate( - "not depend on types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" + "not call \"" + firstMethod.FullName + "\"", + (current, obj) => current + " or \"" + obj.FullName + "\"" ); } - return new SimpleCondition(Condition, description); + return new EnumerableCondition(Condition, description); } - + public static ICondition NotDependOnAny( IType firstType, params IType[] moreTypes @@ -2903,79 +2040,6 @@ var type in failedObject.GetTypeDependencies().Intersect(archUnitTypeList) return new ArchitectureCondition(Condition, description); } - public static ICondition NotHaveAnyAttributes( - string pattern, - bool useRegularExpressions = false - ) - { - return new SimpleCondition( - obj => !obj.HasAttribute(pattern, useRegularExpressions), - "not have any attribute with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"", - "does have any attribute with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static ICondition NotHaveAnyAttributes( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Condition(TRuleType ruleType) - { - return !ruleType.Attributes.Any(attribute => - patternList.Any(pattern => - attribute.FullNameMatches(pattern, useRegularExpressions) - ) - ); - } - - string description; - string failDescription; - if (patternList.IsNullOrEmpty()) - { - description = "not have one of no attributes (always true)"; - failDescription = "does have one of no attributes (impossible)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(pattern => !pattern.Equals(firstPattern)) - .Distinct() - .Aggregate( - "not have any attribute with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - failDescription = patternList - .Where(pattern => !pattern.Equals(firstPattern)) - .Distinct() - .Aggregate( - "does have any attribute with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimpleCondition(Condition, description, failDescription); - } - public static ICondition NotHaveAnyAttributes( Attribute firstAttribute, params Attribute[] moreAttributes @@ -3166,17 +2230,6 @@ params object[] moreArgumentValues return NotHaveAnyAttributesWithArguments(argumentValues); } - public static ICondition NotHaveAttributeWithArguments( - string attribute, - object firstArgumentValue, - params object[] moreArgumentValues - ) - { - var argumentValues = new List { firstArgumentValue }; - argumentValues.AddRange(moreArgumentValues); - return NotHaveAttributeWithArguments(attribute, argumentValues); - } - public static ICondition NotHaveAttributeWithArguments( Attribute attribute, object firstArgumentValue, @@ -3209,17 +2262,6 @@ public static ICondition NotHaveAnyAttributesWithNamedArguments( return NotHaveAnyAttributesWithNamedArguments(attributeArguments); } - public static ICondition NotHaveAttributeWithNamedArguments( - string attribute, - (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments - ) - { - var attributeArguments = new List<(string, object)> { firstAttributeArgument }; - attributeArguments.AddRange(moreAttributeArguments); - return NotHaveAttributeWithNamedArguments(attribute, attributeArguments); - } - public static ICondition NotHaveAttributeWithNamedArguments( Attribute attribute, (string, object) firstAttributeArgument, @@ -3320,87 +2362,6 @@ bool Condition(TRuleType obj, Architecture architecture) return new ArchitectureCondition(Condition, failDescription, description); } - public static ICondition NotHaveAttributeWithArguments( - [NotNull] string attribute, - IEnumerable argumentValues - ) - { - string description, - failDescription; - var argumentValueList = argumentValues?.ToList() ?? new List { null }; - if (argumentValueList.IsNullOrEmpty()) - { - description = "not have attribute \"" + attribute + "\""; - failDescription = "does have attribute \"" + attribute + "\""; - } - else - { - var firstArgument = argumentValueList.First(); - description = argumentValueList - .Where(att => att != firstArgument) - .Aggregate( - "not have attribute \"" - + attribute - + "\" with arguments \"" - + firstArgument - + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\"" - ); - failDescription = argumentValueList - .Where(att => att != firstArgument) - .Aggregate( - "does have attribute \"" - + attribute - + "\" with arguments \"" - + firstArgument - + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\"" - ); - } - - bool Condition(TRuleType obj, Architecture architecture) - { - foreach (var attributeInstance in obj.AttributeInstances) - { - if (!attributeInstance.Type.FullNameMatches(attribute)) - { - goto NextAttribute; - } - - var attributeArguments = attributeInstance - .AttributeArguments.Select(arg => arg.Value) - .ToList(); - var typeAttributeArguments = attributeArguments - .OfType>() - .Select(t => t.Type) - .Union(attributeArguments.OfType()) - .ToList(); - foreach (var arg in argumentValueList) - { - if (arg is Type argType) - { - if (typeAttributeArguments.All(t => t.FullName != argType.FullName)) - { - goto NextAttribute; - } - } - else if (!attributeArguments.Contains(arg)) - { - goto NextAttribute; - } - } - - return false; - NextAttribute: - ; - } - - return true; - } - - return new ArchitectureCondition(Condition, description, failDescription); - } - public static ICondition NotHaveAttributeWithArguments( [NotNull] Attribute attribute, IEnumerable argumentValues @@ -3666,98 +2627,7 @@ t.Value is ITypeInstance typeInstance return new ArchitectureCondition(Condition, failDescription, description); } - - public static ICondition NotHaveAttributeWithNamedArguments( - [NotNull] string attribute, - IEnumerable<(string, object)> attributeArguments - ) - { - string description, - failDescription; - var argumentList = attributeArguments.ToList(); - if (argumentList.IsNullOrEmpty()) - { - description = "not have attribute \"" + attribute + "\""; - failDescription = "does have attribute \"" + attribute + "\""; - } - else - { - var firstArgument = argumentList.First(); - description = argumentList - .Where(att => att != firstArgument) - .Aggregate( - "not have attribute \"" - + attribute - + "\" with named arguments \"" - + firstArgument.Item1 - + "=" - + firstArgument.Item2 - + "\"", - (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" - ); - failDescription = argumentList - .Where(att => att != firstArgument) - .Aggregate( - "does have attribute \"" - + attribute - + "\" with named arguments \"" - + firstArgument.Item1 - + "=" - + firstArgument.Item2 - + "\"", - (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" - ); - } - - bool Condition(TRuleType obj, Architecture architecture) - { - foreach (var attributeInstance in obj.AttributeInstances) - { - if (!attributeInstance.Type.FullNameMatches(attribute)) - { - goto NextAttribute; - } - - var attributeArgs = attributeInstance - .AttributeArguments.OfType() - .Select(arg => (arg.Name, arg.Value)) - .ToList(); - var typeAttributeArguments = attributeArgs - .Where(arg => arg.Value is ITypeInstance || arg.Value is IType) - .ToList(); - foreach (var arg in argumentList) - { - if (arg.Item2 is Type argType) - { - if ( - typeAttributeArguments.All(t => - t.Name != arg.Item1 - || t.Value is ITypeInstance typeInstance - && typeInstance.Type.FullName != argType.FullName - || t.Value is IType type && type.FullName != argType.FullName - ) - ) - { - goto NextAttribute; - } - } - else if (!attributeArgs.Contains(arg)) - { - goto NextAttribute; - } - } - - return false; - NextAttribute: - ; - } - - return true; - } - - return new ArchitectureCondition(Condition, failDescription, description); - } - + public static ICondition NotHaveAttributeWithNamedArguments( [NotNull] Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -3954,7 +2824,7 @@ bool Condition(TRuleType obj, Architecture architecture) public static ICondition NotHaveName( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { return new SimpleCondition( obj => !obj.NameMatches(pattern, useRegularExpressions), @@ -3970,7 +2840,7 @@ public static ICondition NotHaveName( public static ICondition NotHaveFullName( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { return new SimpleCondition( obj => !obj.FullNameMatches(pattern, useRegularExpressions), diff --git a/ArchUnitNET/Fluent/Syntax/Elements/ObjectPredicatesDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/ObjectPredicatesDefinition.cs index 6929d284d..08a75cbc0 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/ObjectPredicatesDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/ObjectPredicatesDefinition.cs @@ -847,17 +847,6 @@ params object[] moreArgumentValues return HaveAnyAttributesWithArguments(argumentValues); } - public static IPredicate HaveAttributeWithArguments( - string attribute, - object firstArgumentValue, - params object[] moreArgumentValues - ) - { - var argumentValues = new List { firstArgumentValue }; - argumentValues.AddRange(moreArgumentValues); - return HaveAttributeWithArguments(attribute, argumentValues); - } - public static IPredicate HaveAttributeWithArguments( Attribute attribute, object firstArgumentValue, @@ -890,17 +879,6 @@ public static IPredicate HaveAnyAttributesWithNamedArguments( return HaveAnyAttributesWithNamedArguments(attributeArguments); } - public static IPredicate HaveAttributeWithNamedArguments( - string attribute, - (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments - ) - { - var attributeArguments = new List<(string, object)> { firstAttributeArgument }; - attributeArguments.AddRange(moreAttributeArguments); - return HaveAttributeWithNamedArguments(attribute, attributeArguments); - } - public static IPredicate HaveAttributeWithNamedArguments( Attribute attribute, (string, object) firstAttributeArgument, @@ -976,76 +954,7 @@ bool Predicate(T obj, Architecture architecture) return new ArchitecturePredicate(Predicate, description); } - - public static IPredicate HaveAttributeWithArguments( - [NotNull] string attribute, - IEnumerable argumentValues - ) - { - string description; - var argumentValueList = argumentValues?.ToList() ?? new List { null }; - if (argumentValueList.IsNullOrEmpty()) - { - description = "have attribute \"" + attribute + "\""; - } - else - { - var firstArgument = argumentValueList.First(); - description = argumentValueList - .Where(att => att != firstArgument) - .Aggregate( - "have attribute \"" - + attribute - + "\" with arguments \"" - + firstArgument - + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\"" - ); - } - - bool Predicate(T obj, Architecture architecture) - { - foreach (var attributeInstance in obj.AttributeInstances) - { - if (!attributeInstance.Type.FullNameMatches(attribute)) - { - goto NextAttribute; - } - - var attributeArguments = attributeInstance - .AttributeArguments.Select(arg => arg.Value) - .ToList(); - var typeAttributeArguments = attributeArguments - .OfType>() - .Select(t => t.Type) - .Union(attributeArguments.OfType()) - .ToList(); - foreach (var arg in argumentValueList) - { - if (arg is Type argType) - { - if (typeAttributeArguments.All(t => t.FullName != argType.FullName)) - { - goto NextAttribute; - } - } - else if (!attributeArguments.Contains(arg)) - { - goto NextAttribute; - } - } - - return true; - NextAttribute: - ; - } - - return false; - } - - return new ArchitecturePredicate(Predicate, description); - } - + public static IPredicate HaveAttributeWithArguments( [NotNull] Attribute attribute, IEnumerable argumentValues @@ -1260,83 +1169,6 @@ bool Predicate(T obj, Architecture architecture) return new ArchitecturePredicate(Predicate, description); } - public static IPredicate HaveAttributeWithNamedArguments( - [NotNull] string attribute, - IEnumerable<(string, object)> attributeArguments - ) - { - string description; - var argumentList = attributeArguments.ToList(); - if (argumentList.IsNullOrEmpty()) - { - description = "have attribute \"" + attribute + "\""; - } - else - { - var firstArgument = argumentList.First(); - description = argumentList - .Where(att => att != firstArgument) - .Aggregate( - "have attribute \"" - + attribute - + "\" with named arguments \"" - + firstArgument.Item1 - + "=" - + firstArgument.Item2 - + "\"", - (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" - ); - } - - bool Predicate(T obj, Architecture architecture) - { - foreach (var attributeInstance in obj.AttributeInstances) - { - if (!attributeInstance.Type.FullNameMatches(attribute)) - { - goto NextAttribute; - } - - var attributeArgs = attributeInstance - .AttributeArguments.OfType() - .Select(arg => (arg.Name, arg.Value)) - .ToList(); - var typeAttributeArguments = attributeArgs - .Where(arg => arg.Value is ITypeInstance || arg.Value is IType) - .ToList(); - foreach (var arg in argumentList) - { - if (arg.Item2 is Type argType) - { - if ( - typeAttributeArguments.All(t => - t.Name != arg.Item1 - || t.Value is ITypeInstance typeInstance - && typeInstance.Type.FullName != argType.FullName - || t.Value is IType type && type.FullName != argType.FullName - ) - ) - { - goto NextAttribute; - } - } - else if (!argumentList.Contains(arg)) - { - goto NextAttribute; - } - } - - return true; - NextAttribute: - ; - } - - return false; - } - - return new ArchitecturePredicate(Predicate, description); - } - public static IPredicate HaveAttributeWithNamedArguments( [NotNull] Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -1502,7 +1334,7 @@ bool Predicate(T obj, Architecture architecture) return new ArchitecturePredicate(Predicate, description); } - public static IPredicate HaveName(string pattern, bool useRegularExpressions = false) + public static IPredicate HaveName(string pattern, bool useRegularExpressions = false) //TODO split into multiple implementations { return new SimplePredicate( obj => obj.NameMatches(pattern, useRegularExpressions), @@ -1510,7 +1342,7 @@ public static IPredicate HaveName(string pattern, bool useRegularExpressions ); } - public static IPredicate HaveFullName(string pattern, bool useRegularExpressions = false) + public static IPredicate HaveFullName(string pattern, bool useRegularExpressions = false) //TODO split into multiple implementations { return new SimplePredicate( obj => obj.FullNameMatches(pattern, useRegularExpressions), @@ -1592,55 +1424,6 @@ public static IPredicate ArePrivateProtected() //Negations - - public static IPredicate AreNot(string pattern, bool useRegularExpressions = false) - { - return new SimplePredicate( - obj => !obj.FullNameMatches(pattern, useRegularExpressions), - "do not have full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static IPredicate AreNot( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - string description; - if (patternList.IsNullOrEmpty()) - { - description = "exist (always true)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(pattern => !pattern.Equals(firstPattern)) - .Distinct() - .Aggregate( - "do not have full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimplePredicate( - obj => - patternList.All(pattern => - !obj.FullNameMatches(pattern, useRegularExpressions) - ), - description - ); - } - public static IPredicate AreNot( ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects @@ -1689,56 +1472,6 @@ IEnumerable Filter(IEnumerable objects, Architecture architecture) return new ArchitecturePredicate(Filter, "are not " + objectProvider.Description); } - public static IPredicate DoNotCallAny(string pattern, bool useRegularExpressions = false) - { - return new SimplePredicate( - obj => !obj.CallsMethod(pattern, useRegularExpressions), - "do not call any methods with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static IPredicate DoNotCallAny( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Filter(T type) - { - return patternList.All(pattern => - !type.CallsMethod(pattern, useRegularExpressions) - ); - } - - string description; - if (patternList.IsNullOrEmpty()) - { - description = "do not call one of no methods (always true)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(pattern => !pattern.Equals(firstPattern)) - .Distinct() - .Aggregate( - "do not call any methods with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimplePredicate(Filter, description); - } - public static IPredicate DoNotCallAny( MethodMember method, params MethodMember[] moreMethods @@ -1790,62 +1523,6 @@ IEnumerable Filter(IEnumerable objects) return new EnumerablePredicate(Filter, description); } - public static IPredicate DoNotDependOnAny( - string pattern, - bool useRegularExpressions = false - ) - { - return new SimplePredicate( - obj => !obj.DependsOn(pattern, useRegularExpressions), - "do not depend on any types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static IPredicate DoNotDependOnAny( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Filter(T type) - { - return type.GetTypeDependencies() - .All(target => - patternList.All(pattern => - target.FullNameMatches(pattern, useRegularExpressions) - ) - ); - } - - string description; - if (patternList.IsNullOrEmpty()) - { - description = "do not depend on no types (always true)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(pattern => !pattern.Equals(firstPattern)) - .Distinct() - .Aggregate( - "do not depend on any types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimplePredicate(Filter, description); - } - public static IPredicate DoNotDependOnAny(IType firstType, params IType[] moreTypes) { var types = new List { firstType }; @@ -1946,61 +1623,6 @@ IEnumerable Filter(IEnumerable objects, Architecture architecture) return new ArchitecturePredicate(Filter, description); } - public static IPredicate DoNotHaveAnyAttributes( - string pattern, - bool useRegularExpressions = false - ) - { - return new SimplePredicate( - obj => !obj.HasAttribute(pattern, useRegularExpressions), - "do not have any attribute with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static IPredicate DoNotHaveAnyAttributes( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Filter(T type) - { - return !type.Attributes.Any(attribute => - patternList.Any(pattern => - attribute.FullNameMatches(pattern, useRegularExpressions) - ) - ); - } - - string description; - if (patternList.IsNullOrEmpty()) - { - description = "do not have one of no attributes (always true)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(pattern => !pattern.Equals(firstPattern)) - .Distinct() - .Aggregate( - "do not have any attribute with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimplePredicate(Filter, description); - } - public static IPredicate DoNotHaveAnyAttributes( Attribute firstAttribute, params Attribute[] moreAttributes @@ -2116,17 +1738,7 @@ params object[] moreArgumentValues argumentValues.AddRange(moreArgumentValues); return DoNotHaveAnyAttributesWithArguments(argumentValues); } - - public static IPredicate DoNotHaveAttributeWithArguments( - string attribute, - object firstArgumentValue, - params object[] moreArgumentValues - ) - { - var argumentValues = new List { firstArgumentValue }; - argumentValues.AddRange(moreArgumentValues); - return DoNotHaveAttributeWithArguments(attribute, argumentValues); - } + public static IPredicate DoNotHaveAttributeWithArguments( Attribute attribute, @@ -2160,17 +1772,6 @@ public static IPredicate DoNotHaveAnyAttributesWithNamedArguments( return DoNotHaveAnyAttributesWithNamedArguments(attributeArguments); } - public static IPredicate DoNotHaveAttributeWithNamedArguments( - string attribute, - (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments - ) - { - var attributeArguments = new List<(string, object)> { firstAttributeArgument }; - attributeArguments.AddRange(moreAttributeArguments); - return DoNotHaveAttributeWithNamedArguments(attribute, attributeArguments); - } - public static IPredicate DoNotHaveAttributeWithNamedArguments( Attribute attribute, (string, object) firstAttributeArgument, @@ -2246,76 +1847,7 @@ bool Predicate(T obj, Architecture architecture) return new ArchitecturePredicate(Predicate, description); } - - public static IPredicate DoNotHaveAttributeWithArguments( - [NotNull] string attribute, - IEnumerable argumentValues - ) - { - string description; - var argumentValueList = argumentValues?.ToList() ?? new List { null }; - if (argumentValueList.IsNullOrEmpty()) - { - description = "do not have attribute \"" + attribute + "\""; - } - else - { - var firstArgument = argumentValueList.First(); - description = argumentValueList - .Where(att => att != firstArgument) - .Aggregate( - "do not have attribute \"" - + attribute - + "\" with arguments \"" - + firstArgument - + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\"" - ); - } - - bool Predicate(T obj, Architecture architecture) - { - foreach (var attributeInstance in obj.AttributeInstances) - { - if (!attributeInstance.Type.FullNameMatches(attribute)) - { - goto NextAttribute; - } - - var attributeArguments = attributeInstance - .AttributeArguments.Select(arg => arg.Value) - .ToList(); - var typeAttributeArguments = attributeArguments - .OfType>() - .Select(t => t.Type) - .Union(attributeArguments.OfType()) - .ToList(); - foreach (var arg in argumentValueList) - { - if (arg is Type argType) - { - if (typeAttributeArguments.All(t => t.FullName != argType.FullName)) - { - goto NextAttribute; - } - } - else if (!attributeArguments.Contains(arg)) - { - goto NextAttribute; - } - } - - return false; - NextAttribute: - ; - } - - return true; - } - - return new ArchitecturePredicate(Predicate, description); - } - + public static IPredicate DoNotHaveAttributeWithArguments( [NotNull] Attribute attribute, IEnumerable argumentValues @@ -2531,84 +2063,7 @@ t.Value is ITypeInstance typeInstance return new ArchitecturePredicate(Condition, description); } - - public static IPredicate DoNotHaveAttributeWithNamedArguments( - [NotNull] string attribute, - IEnumerable<(string, object)> attributeArguments - ) - { - string description; - var argumentList = attributeArguments.ToList(); - if (argumentList.IsNullOrEmpty()) - { - description = "do not have attribute \"" + attribute + "\""; - } - else - { - var firstArgument = argumentList.First(); - description = argumentList - .Where(att => att != firstArgument) - .Aggregate( - "do not have attribute \"" - + attribute - + "\" with named arguments \"" - + firstArgument.Item1 - + "=" - + firstArgument.Item2 - + "\"", - (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" - ); - } - - bool Predicate(T obj, Architecture architecture) - { - foreach (var attributeInstance in obj.AttributeInstances) - { - if (!attributeInstance.Type.FullNameMatches(attribute)) - { - goto NextAttribute; - } - - var attributeArgs = attributeInstance - .AttributeArguments.OfType() - .Select(arg => (arg.Name, arg.Value)) - .ToList(); - var typeAttributeArguments = attributeArgs - .Where(arg => arg.Value is ITypeInstance || arg.Value is IType) - .ToList(); - foreach (var arg in argumentList) - { - if (arg.Item2 is Type argType) - { - if ( - typeAttributeArguments.All(t => - t.Name != arg.Item1 - || t.Value is ITypeInstance typeInstance - && typeInstance.Type.FullName != argType.FullName - || t.Value is IType type && type.FullName != argType.FullName - ) - ) - { - goto NextAttribute; - } - } - else if (!argumentList.Contains(arg)) - { - goto NextAttribute; - } - } - - return false; - NextAttribute: - ; - } - - return true; - } - - return new ArchitecturePredicate(Predicate, description); - } - + public static IPredicate DoNotHaveAttributeWithNamedArguments( [NotNull] Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -2777,7 +2232,7 @@ bool Predicate(T obj, Architecture architecture) public static IPredicate DoNotHaveName( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { return new SimplePredicate( obj => !obj.NameMatches(pattern, useRegularExpressions), @@ -2792,7 +2247,7 @@ public static IPredicate DoNotHaveName( public static IPredicate DoNotHaveFullName( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { return new SimplePredicate( obj => !obj.FullNameMatches(pattern, useRegularExpressions), diff --git a/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShould.cs b/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShould.cs index c90b142f9..70d3a384d 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShould.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShould.cs @@ -32,25 +32,6 @@ public TRuleTypeShouldConjunction Exist() return Create(_ruleCreator); } - public TRuleTypeShouldConjunction Be(string pattern, bool useRegularExpressions = false) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.Be(pattern, useRegularExpressions) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction Be( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.Be(patterns, useRegularExpressions) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction Be( ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects @@ -74,28 +55,6 @@ public TRuleTypeShouldConjunction Be(IObjectProvider objects) return Create(_ruleCreator); } - public TRuleTypeShouldConjunction CallAny( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.CallAny(pattern, useRegularExpressions) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction CallAny( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.CallAny(patterns, useRegularExpressions) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction CallAny( MethodMember method, params MethodMember[] moreMethods @@ -119,28 +78,6 @@ public TRuleTypeShouldConjunction CallAny(IObjectProvider methods) return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DependOnAny( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.DependOnAny(pattern, useRegularExpressions) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction DependOnAny( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.DependOnAny(patterns, useRegularExpressions) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction DependOnAny(IType firstType, params IType[] moreTypes) { _ruleCreator.AddCondition( @@ -208,28 +145,6 @@ string failDescription return Create(_ruleCreator); } - public TRuleTypeShouldConjunction OnlyDependOn( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.OnlyDependOn(pattern, useRegularExpressions) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction OnlyDependOn( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.OnlyDependOn(patterns, useRegularExpressions) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction OnlyDependOn(IType firstType, params IType[] moreTypes) { _ruleCreator.AddCondition( @@ -264,34 +179,6 @@ public TRuleTypeShouldConjunction OnlyDependOn(IEnumerable types) return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAnyAttributes( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveAnyAttributes( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction HaveAnyAttributes( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveAnyAttributes( - patterns, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction HaveAnyAttributes( Attribute firstAttribute, params Attribute[] moreAttributes @@ -344,34 +231,6 @@ public TRuleTypeShouldConjunction HaveAnyAttributes(IEnumerable attributes return Create(_ruleCreator); } - public TRuleTypeShouldConjunction OnlyHaveAttributes( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.OnlyHaveAttributes( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction OnlyHaveAttributes( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.OnlyHaveAttributes( - patterns, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction OnlyHaveAttributes( Attribute firstAttribute, params Attribute[] moreAttributes @@ -448,36 +307,6 @@ params object[] moreArgumentValues return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAttributeWithArguments( - string attribute, - IEnumerable argumentValues - ) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveAttributeWithArguments( - attribute, - argumentValues - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction HaveAttributeWithArguments( - string attribute, - object firstArgumentValue, - params object[] moreArgumentValues - ) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveAttributeWithArguments( - attribute, - firstArgumentValue, - moreArgumentValues - ) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction HaveAttributeWithArguments( Attribute attribute, IEnumerable argumentValues @@ -564,36 +393,6 @@ public TRuleTypeShouldConjunction HaveAnyAttributesWithNamedArguments( return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( - string attribute, - IEnumerable<(string, object)> attributeArguments - ) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveAttributeWithNamedArguments( - attribute, - attributeArguments - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( - string attribute, - (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments - ) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveAttributeWithNamedArguments( - attribute, - firstAttributeArgument, - moreAttributeArguments - ) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -657,7 +456,7 @@ public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( public TRuleTypeShouldConjunction HaveName( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { _ruleCreator.AddCondition( ObjectConditionsDefinition.HaveName(pattern, useRegularExpressions) @@ -668,7 +467,7 @@ public TRuleTypeShouldConjunction HaveName( public TRuleTypeShouldConjunction HaveFullName( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { _ruleCreator.AddCondition( ObjectConditionsDefinition.HaveFullName(pattern, useRegularExpressions) @@ -814,25 +613,6 @@ public TRuleTypeShouldConjunction NotExist() return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotBe(string pattern, bool useRegularExpressions = false) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotBe(pattern, useRegularExpressions) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction NotBe( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotBe(patterns, useRegularExpressions) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction NotBe( ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects @@ -855,29 +635,7 @@ public TRuleTypeShouldConjunction NotBe(IObjectProvider objects) _ruleCreator.AddCondition(ObjectConditionsDefinition.NotBe(objects)); return Create(_ruleCreator); } - - public TRuleTypeShouldConjunction NotCallAny( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotCallAny(pattern, useRegularExpressions) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction NotCallAny( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotCallAny(patterns, useRegularExpressions) - ); - return Create(_ruleCreator); - } - + public TRuleTypeShouldConjunction NotCallAny( MethodMember method, params MethodMember[] moreMethods @@ -901,31 +659,6 @@ public TRuleTypeShouldConjunction NotCallAny(IObjectProvider metho return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotDependOnAny( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotDependOnAny(pattern, useRegularExpressions) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction NotDependOnAny( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotDependOnAny( - patterns, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction NotDependOnAny(IType firstType, params IType[] moreTypes) { _ruleCreator.AddCondition( @@ -960,34 +693,6 @@ public TRuleTypeShouldConjunction NotDependOnAny(IEnumerable types) return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotHaveAnyAttributes( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveAnyAttributes( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction NotHaveAnyAttributes( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveAnyAttributes( - patterns, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction NotHaveAnyAttributes( Attribute firstAttribute, params Attribute[] moreAttributes @@ -1068,36 +773,6 @@ params object[] moreArgumentValues return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotHaveAttributeWithArguments( - string attribute, - IEnumerable argumentValues - ) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveAttributeWithArguments( - attribute, - argumentValues - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction NotHaveAttributeWithArguments( - string attribute, - object firstArgumentValue, - params object[] moreArgumentValues - ) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveAttributeWithArguments( - attribute, - firstArgumentValue, - moreArgumentValues - ) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction NotHaveAttributeWithArguments( Attribute attribute, IEnumerable argumentValues @@ -1184,36 +859,6 @@ public TRuleTypeShouldConjunction NotHaveAnyAttributesWithNamedArguments( return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotHaveAttributeWithNamedArguments( - string attribute, - IEnumerable<(string, object)> attributeArguments - ) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveAttributeWithNamedArguments( - attribute, - attributeArguments - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction NotHaveAttributeWithNamedArguments( - string attribute, - (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments - ) - { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveAttributeWithNamedArguments( - attribute, - firstAttributeArgument, - moreAttributeArguments - ) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction NotHaveAttributeWithNamedArguments( Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -1277,7 +922,7 @@ public TRuleTypeShouldConjunction NotHaveAttributeWithNamedArguments( public TRuleTypeShouldConjunction NotHaveName( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { _ruleCreator.AddCondition( ObjectConditionsDefinition.NotHaveName(pattern, useRegularExpressions) @@ -1288,7 +933,7 @@ public TRuleTypeShouldConjunction NotHaveName( public TRuleTypeShouldConjunction NotHaveFullName( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { _ruleCreator.AddCondition( ObjectConditionsDefinition.NotHaveFullName( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/ShouldRelateToObjectsThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/ShouldRelateToObjectsThat.cs index b73207081..2e0cfc1f1 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/ShouldRelateToObjectsThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/ShouldRelateToObjectsThat.cs @@ -22,25 +22,6 @@ public class ShouldRelateToObjectsThat ruleCreator) : base(ruleCreator) { } - public TRuleTypeShouldConjunction Are(string pattern, bool useRegularExpressions = false) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.Are(pattern, useRegularExpressions) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction Are( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.Are(patterns, useRegularExpressions) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction Are( ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects @@ -67,29 +48,7 @@ public TRuleTypeShouldConjunction Are(IObjectProvider objects) ); return Create(_ruleCreator); } - - public TRuleTypeShouldConjunction CallAny( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.CallAny(pattern, useRegularExpressions) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction CallAny( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.CallAny(patterns, useRegularExpressions) - ); - return Create(_ruleCreator); - } - + public TRuleTypeShouldConjunction CallAny( MethodMember method, params MethodMember[] moreMethods @@ -116,35 +75,7 @@ public TRuleTypeShouldConjunction CallAny(IObjectProvider methods) ); return Create(_ruleCreator); } - - public TRuleTypeShouldConjunction DependOnAny( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DependOnAny( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction DependOnAny( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DependOnAny( - patterns, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - + public TRuleTypeShouldConjunction DependOnAny(Type firstType, params Type[] moreTypes) { _ruleCreator.ContinueComplexCondition( @@ -207,34 +138,6 @@ string description return Create(_ruleCreator); } - public TRuleTypeShouldConjunction OnlyDependOn( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.OnlyDependOn( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction OnlyDependOn( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.OnlyDependOn( - patterns, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction OnlyDependOn(Type firstType, params Type[] moreTypes) { _ruleCreator.ContinueComplexCondition( @@ -275,34 +178,6 @@ public TRuleTypeShouldConjunction OnlyDependOn(IEnumerable types) return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAnyAttributes( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAnyAttributes( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction HaveAnyAttributes( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAnyAttributes( - patterns, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction HaveAnyAttributes( Type firstAttribute, params Type[] moreAttributes @@ -355,34 +230,6 @@ public TRuleTypeShouldConjunction HaveAnyAttributes(IEnumerable attributes return Create(_ruleCreator); } - public TRuleTypeShouldConjunction OnlyHaveAttributes( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.OnlyHaveAttributes( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction OnlyHaveAttributes( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.OnlyHaveAttributes( - patterns, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction OnlyHaveAttributes( Type firstAttribute, params Type[] moreAttributes @@ -460,37 +307,7 @@ params object[] moreArgumentValues ); return Create(_ruleCreator); } - - public TRuleTypeShouldConjunction HaveAttributeWithArguments( - string attribute, - IEnumerable argumentValues - ) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAttributeWithArguments( - attribute, - argumentValues - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction HaveAttributeWithArguments( - string attribute, - object firstArgumentValue, - params object[] moreArgumentValues - ) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAttributeWithArguments( - attribute, - firstArgumentValue, - moreArgumentValues - ) - ); - return Create(_ruleCreator); - } - + public TRuleTypeShouldConjunction HaveAttributeWithArguments( Attribute attribute, IEnumerable argumentValues @@ -576,37 +393,7 @@ public TRuleTypeShouldConjunction HaveAnyAttributesWithNamedArguments( ); return Create(_ruleCreator); } - - public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( - string attribute, - IEnumerable<(string, object)> attributeArguments - ) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAttributeWithNamedArguments( - attribute, - attributeArguments - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( - string attribute, - (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments - ) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAttributeWithNamedArguments( - attribute, - firstAttributeArgument, - moreAttributeArguments - ) - ); - return Create(_ruleCreator); - } - + public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -670,7 +457,7 @@ public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( public TRuleTypeShouldConjunction HaveName( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { _ruleCreator.ContinueComplexCondition( ObjectPredicatesDefinition.HaveName(pattern, useRegularExpressions) @@ -681,7 +468,7 @@ public TRuleTypeShouldConjunction HaveName( public TRuleTypeShouldConjunction HaveFullName( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { _ruleCreator.ContinueComplexCondition( ObjectPredicatesDefinition.HaveFullName( @@ -774,26 +561,6 @@ public TRuleTypeShouldConjunction ArePrivateProtected() //Negations - - public TRuleTypeShouldConjunction AreNot(string pattern, bool useRegularExpressions = false) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.AreNot(pattern, useRegularExpressions) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction AreNot( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.AreNot(patterns, useRegularExpressions) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction AreNot( ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects @@ -821,34 +588,6 @@ public TRuleTypeShouldConjunction AreNot(IObjectProvider objects return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotCallAny( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotCallAny( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction DoNotCallAny( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotCallAny( - patterns, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction DoNotCallAny( MethodMember method, params MethodMember[] moreMethods @@ -876,34 +615,6 @@ public TRuleTypeShouldConjunction DoNotCallAny(IObjectProvider met return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotDependOnAny( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotDependOnAny( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction DoNotDependOnAny( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotDependOnAny( - patterns, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction DoNotDependOnAny(Type firstType, params Type[] moreTypes) { _ruleCreator.ContinueComplexCondition( @@ -947,34 +658,6 @@ public TRuleTypeShouldConjunction DoNotDependOnAny(IEnumerable types) return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveAnyAttributes( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAnyAttributes( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction DoNotHaveAnyAttributes( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAnyAttributes( - patterns, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction DoNotHaveAnyAttributes( Type firstAttribute, params Type[] moreAttributes @@ -1141,66 +824,6 @@ public TRuleTypeShouldConjunction DoNotHaveAnyAttributesWithNamedArguments( return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveAttributeWithArguments( - string attribute, - IEnumerable argumentValues - ) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments( - attribute, - argumentValues - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction DoNotHaveAttributeWithArguments( - string attribute, - object firstArgumentValue, - params object[] moreArgumentValues - ) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments( - attribute, - firstArgumentValue, - moreArgumentValues - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction DoNotHaveAttributeWithNamedArguments( - string attribute, - IEnumerable<(string, object)> attributeArguments - ) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments( - attribute, - attributeArguments - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction DoNotHaveAttributeWithNamedArguments( - string attribute, - (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments - ) - { - _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments( - attribute, - firstAttributeArgument, - moreAttributeArguments - ) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction DoNotHaveAttributeWithNamedArguments( Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -1264,7 +887,7 @@ public TRuleTypeShouldConjunction DoNotHaveAttributeWithNamedArguments( public TRuleTypeShouldConjunction DoNotHaveName( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { _ruleCreator.ContinueComplexCondition( ObjectPredicatesDefinition.DoNotHaveName( @@ -1273,7 +896,7 @@ public TRuleTypeShouldConjunction DoNotHaveName( ) ); return Create(_ruleCreator); - } + } //TODO split into multiple implementations public TRuleTypeShouldConjunction DoNotHaveFullName( string pattern, diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesThat.cs index ec0035f00..c2a385640 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesThat.cs @@ -35,28 +35,6 @@ public TGivenRuleTypeConjunction Are(IEnumerable types) return Create(_ruleCreator); } - public TGivenRuleTypeConjunction AreAssignableTo( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - TypePredicatesDefinition.AreAssignableTo(pattern, useRegularExpressions) - ); - return Create(_ruleCreator); - } - - public TGivenRuleTypeConjunction AreAssignableTo( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - TypePredicatesDefinition.AreAssignableTo(patterns, useRegularExpressions) - ); - return Create(_ruleCreator); - } - public TGivenRuleTypeConjunction AreAssignableTo(IType firstType, params IType[] moreTypes) { _ruleCreator.AddPredicate( @@ -143,20 +121,6 @@ public TGivenRuleTypeConjunction AreStructs() return Create(_ruleCreator); } - public TGivenRuleTypeConjunction ImplementInterface( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - TypePredicatesDefinition.ImplementInterface( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TGivenRuleTypeConjunction ImplementInterface(Interface intf) { _ruleCreator.AddPredicate(TypePredicatesDefinition.ImplementInterface(intf)); @@ -172,7 +136,7 @@ public TGivenRuleTypeConjunction ImplementInterface(Type intf) public TGivenRuleTypeConjunction ResideInNamespace( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { _ruleCreator.AddPredicate( TypePredicatesDefinition.ResideInNamespace( @@ -186,7 +150,7 @@ public TGivenRuleTypeConjunction ResideInNamespace( public TGivenRuleTypeConjunction ResideInAssembly( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { _ruleCreator.AddPredicate( TypePredicatesDefinition.ResideInAssembly(pattern, useRegularExpressions) @@ -269,34 +233,6 @@ public TGivenRuleTypeConjunction AreNot(IEnumerable types) return Create(_ruleCreator); } - public TGivenRuleTypeConjunction AreNotAssignableTo( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - TypePredicatesDefinition.AreNotAssignableTo( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - - public TGivenRuleTypeConjunction AreNotAssignableTo( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - TypePredicatesDefinition.AreNotAssignableTo( - patterns, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TGivenRuleTypeConjunction AreNotAssignableTo( IType firstType, params IType[] moreTypes @@ -358,20 +294,6 @@ public TGivenRuleTypeConjunction AreNotStructs() return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotImplementInterface( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddPredicate( - TypePredicatesDefinition.DoNotImplementInterface( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TGivenRuleTypeConjunction DoNotImplementInterface(Interface intf) { _ruleCreator.AddPredicate( @@ -391,7 +313,7 @@ public TGivenRuleTypeConjunction DoNotImplementInterface(Type intf) public TGivenRuleTypeConjunction DoNotResideInNamespace( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { _ruleCreator.AddPredicate( TypePredicatesDefinition.DoNotResideInNamespace( @@ -405,7 +327,7 @@ public TGivenRuleTypeConjunction DoNotResideInNamespace( public TGivenRuleTypeConjunction DoNotResideInAssembly( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { _ruleCreator.AddPredicate( TypePredicatesDefinition.DoNotResideInAssembly( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypeConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypeConditions.cs index b201630c8..6595cc07c 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypeConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypeConditions.cs @@ -17,11 +17,6 @@ public interface ITypeConditions { TReturnType Be(Type firstType, params Type[] moreTypes); TReturnType Be(IEnumerable types); - TReturnType BeAssignableTo(string pattern, bool useRegularExpressions = false); - TReturnType BeAssignableTo( - IEnumerable patterns, - bool useRegularExpressions = false - ); TReturnType BeAssignableTo(IType firstType, params IType[] moreTypes); TReturnType BeAssignableTo(Type type, params Type[] moreTypes); TReturnType BeAssignableTo(IObjectProvider types); @@ -30,11 +25,10 @@ TReturnType BeAssignableTo( TReturnType BeValueTypes(); TReturnType BeEnums(); TReturnType BeStructs(); - TReturnType ImplementInterface(string pattern, bool useRegularExpressions = false); TReturnType ImplementInterface(Interface intf); TReturnType ImplementInterface(Type intf); - TReturnType ResideInNamespace(string pattern, bool useRegularExpressions = false); - TReturnType ResideInAssembly(string pattern, bool useRegularExpressions = false); + TReturnType ResideInNamespace(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations + TReturnType ResideInAssembly(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations TReturnType ResideInAssembly(Assembly assembly, params Assembly[] moreAssemblies); TReturnType ResideInAssembly( Domain.Assembly assembly, @@ -51,11 +45,6 @@ params Domain.Assembly[] moreAssemblies TReturnType NotBe(Type firstType, params Type[] moreTypes); TReturnType NotBe(IEnumerable types); - TReturnType NotBeAssignableTo(string pattern, bool useRegularExpressions = false); - TReturnType NotBeAssignableTo( - IEnumerable patterns, - bool useRegularExpressions = false - ); TReturnType NotBeAssignableTo(IType type, params IType[] moreTypes); TReturnType NotBeAssignableTo(Type type, params Type[] moreTypes); TReturnType NotBeAssignableTo(IObjectProvider types); @@ -64,11 +53,10 @@ TReturnType NotBeAssignableTo( TReturnType NotBeValueTypes(); TReturnType NotBeEnums(); TReturnType NotBeStructs(); - TReturnType NotImplementInterface(string pattern, bool useRegularExpressions = false); TReturnType NotImplementInterface(Interface intf); TReturnType NotImplementInterface(Type intf); - TReturnType NotResideInNamespace(string pattern, bool useRegularExpressions = false); - TReturnType NotResideInAssembly(string pattern, bool useRegularExpressions = false); + TReturnType NotResideInNamespace(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations + TReturnType NotResideInAssembly(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations TReturnType NotResideInAssembly(Assembly assembly, params Assembly[] moreAssemblies); TReturnType NotResideInAssembly( Domain.Assembly assembly, diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypePredicates.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypePredicates.cs index e585222cb..30157fa90 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypePredicates.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypePredicates.cs @@ -17,11 +17,6 @@ public interface ITypePredicates { TReturnType Are(Type firstType, params Type[] moreTypes); TReturnType Are(IEnumerable types); - TReturnType AreAssignableTo(string pattern, bool useRegularExpressions = false); - TReturnType AreAssignableTo( - IEnumerable patterns, - bool useRegularExpressions = false - ); TReturnType AreAssignableTo(IType firstType, params IType[] moreTypes); TReturnType AreAssignableTo(Type type, params Type[] moreTypes); TReturnType AreAssignableTo(IObjectProvider types); @@ -30,11 +25,10 @@ TReturnType AreAssignableTo( TReturnType AreValueTypes(); TReturnType AreEnums(); TReturnType AreStructs(); - TReturnType ImplementInterface(string pattern, bool useRegularExpressions = false); TReturnType ImplementInterface(Interface intf); TReturnType ImplementInterface(Type intf); - TReturnType ResideInNamespace(string pattern, bool useRegularExpressions = false); - TReturnType ResideInAssembly(string pattern, bool useRegularExpressions = false); + TReturnType ResideInNamespace(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations + TReturnType ResideInAssembly(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations TReturnType ResideInAssembly(Assembly assembly, params Assembly[] moreAssemblies); TReturnType ResideInAssembly( Domain.Assembly assembly, @@ -51,11 +45,6 @@ params Domain.Assembly[] moreAssemblies TReturnType AreNot(Type firstType, params Type[] moreTypes); TReturnType AreNot(IEnumerable types); - TReturnType AreNotAssignableTo(string pattern, bool useRegularExpressions = false); - TReturnType AreNotAssignableTo( - IEnumerable patterns, - bool useRegularExpressions = false - ); TReturnType AreNotAssignableTo(IType type, params IType[] moreTypes); TReturnType AreNotAssignableTo(Type type, params Type[] moreTypes); TReturnType AreNotAssignableTo(IObjectProvider types); @@ -64,11 +53,10 @@ TReturnType AreNotAssignableTo( TReturnType AreNotValueTypes(); TReturnType AreNotEnums(); TReturnType AreNotStructs(); - TReturnType DoNotImplementInterface(string pattern, bool useRegularExpressions = false); TReturnType DoNotImplementInterface(Interface intf); TReturnType DoNotImplementInterface(Type intf); - TReturnType DoNotResideInNamespace(string pattern, bool useRegularExpressions = false); - TReturnType DoNotResideInAssembly(string pattern, bool useRegularExpressions = false); + TReturnType DoNotResideInNamespace(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations + TReturnType DoNotResideInAssembly(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations TReturnType DoNotResideInAssembly(Assembly assembly, params Assembly[] moreAssemblies); TReturnType DoNotResideInAssembly( Domain.Assembly assembly, diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/ShouldRelateToTypesThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/ShouldRelateToTypesThat.cs index aa4a668ee..7777fec20 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/ShouldRelateToTypesThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/ShouldRelateToTypesThat.cs @@ -38,34 +38,6 @@ public TRuleTypeShouldConjunction Are(IEnumerable types) return Create(_ruleCreator); } - public TRuleTypeShouldConjunction AreAssignableTo( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.AreAssignableTo( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction AreAssignableTo( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.AreAssignableTo( - patterns, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction AreAssignableTo(IType firstType, params IType[] moreTypes) { _ruleCreator.ContinueComplexCondition( @@ -170,20 +142,6 @@ public TRuleTypeShouldConjunction AreStructs() return Create(_ruleCreator); } - public TRuleTypeShouldConjunction ImplementInterface( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.ImplementInterface( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction ImplementInterface(Interface intf) { _ruleCreator.ContinueComplexCondition( @@ -203,7 +161,7 @@ public TRuleTypeShouldConjunction ImplementInterface(Type intf) public TRuleTypeShouldConjunction ResideInNamespace( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { _ruleCreator.ContinueComplexCondition( TypePredicatesDefinition.ResideInNamespace( @@ -217,7 +175,7 @@ public TRuleTypeShouldConjunction ResideInNamespace( public TRuleTypeShouldConjunction ResideInAssembly( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { _ruleCreator.ContinueComplexCondition( TypePredicatesDefinition.ResideInAssembly( @@ -308,35 +266,7 @@ public TRuleTypeShouldConjunction AreNot(IEnumerable types) ); return Create(_ruleCreator); } - - public TRuleTypeShouldConjunction AreNotAssignableTo( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.AreNotAssignableTo( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction AreNotAssignableTo( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.AreNotAssignableTo( - patterns, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - + public TRuleTypeShouldConjunction AreNotAssignableTo( IType firstType, params IType[] moreTypes @@ -407,20 +337,6 @@ public TRuleTypeShouldConjunction AreNotStructs() return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotImplementInterface( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.DoNotImplementInterface( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction DoNotImplementInterface(Interface intf) { _ruleCreator.ContinueComplexCondition( @@ -440,7 +356,7 @@ public TRuleTypeShouldConjunction DoNotImplementInterface(Type intf) public TRuleTypeShouldConjunction DoNotResideInNamespace( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { _ruleCreator.ContinueComplexCondition( TypePredicatesDefinition.DoNotResideInNamespace( @@ -454,7 +370,7 @@ public TRuleTypeShouldConjunction DoNotResideInNamespace( public TRuleTypeShouldConjunction DoNotResideInAssembly( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { _ruleCreator.ContinueComplexCondition( TypePredicatesDefinition.DoNotResideInAssembly( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypeConditionsDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypeConditionsDefinition.cs index 24988dae9..1b7f8e604 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypeConditionsDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypeConditionsDefinition.cs @@ -90,81 +90,6 @@ Architecture architecture return new ArchitectureCondition(Condition, description); } - public static ICondition BeAssignableTo( - string pattern, - bool useRegularExpressions = false - ) - { - var description = - "be assignable to types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\""; - var failDescription = - "is not assignable to a type with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\""; - return new SimpleCondition( - type => type.IsAssignableTo(pattern, useRegularExpressions), - description, - failDescription - ); - } - - public static ICondition BeAssignableTo( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Condition(TRuleType ruleType) - { - return patternList.Any(pattern => - ruleType.IsAssignableTo(pattern, useRegularExpressions) - ); - } - - string description; - string failDescription; - if (patternList.IsNullOrEmpty()) - { - description = "be assignable to no types (always false)"; - failDescription = "is assignable to any type (always true)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(type => !type.Equals(firstPattern)) - .Distinct() - .Aggregate( - "be assignable to types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - failDescription = patternList - .Where(type => !type.Equals(firstPattern)) - .Distinct() - .Aggregate( - "is not assignable to types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimpleCondition(Condition, description, failDescription); - } - public static ICondition BeAssignableTo( IType firstType, params IType[] moreTypes @@ -535,26 +460,6 @@ public static ICondition BeStructs() ); } - public static ICondition ImplementInterface( - string pattern, - bool useRegularExpressions = false - ) - { - return new SimpleCondition( - type => type.ImplementsInterface(pattern, useRegularExpressions), - "implement interface with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"", - "does not implement interface with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - public static ICondition ImplementInterface(Interface intf) { return new SimpleCondition( @@ -626,7 +531,7 @@ Architecture architecture public static ICondition ResideInNamespace( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { return new SimpleCondition( type => type.ResidesInNamespace(pattern, useRegularExpressions), @@ -642,7 +547,7 @@ public static ICondition ResideInNamespace( public static ICondition ResideInAssembly( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { return new SimpleCondition( type => type.ResidesInAssembly(pattern, useRegularExpressions), @@ -896,87 +801,6 @@ Architecture architecture return new ArchitectureCondition(Condition, description); } - public static ICondition NotBeAssignableTo( - string pattern, - bool useRegularExpressions = false - ) - { - ConditionResult Condition(TRuleType ruleType) - { - var pass = true; - var dynamicFailDescription = "is assignable to"; - foreach (var type in ruleType.GetAssignableTypes()) - { - if (type.FullNameMatches(pattern, useRegularExpressions)) - { - dynamicFailDescription += (pass ? " " : " and ") + type.FullName; - pass = false; - } - } - - return new ConditionResult(ruleType, pass, dynamicFailDescription); - } - - var description = - "not be assignable to types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\""; - return new SimpleCondition(Condition, description); - } - - public static ICondition NotBeAssignableTo( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - ConditionResult Condition(TRuleType ruleType) - { - var pass = true; - var dynamicFailDescription = "is assignable to"; - foreach (var type in ruleType.GetAssignableTypes()) - { - if ( - patternList.Any(pattern => - type.FullNameMatches(pattern, useRegularExpressions) - ) - ) - { - dynamicFailDescription += (pass ? " " : " and ") + type.FullName; - pass = false; - } - } - - return new ConditionResult(ruleType, pass, dynamicFailDescription); - } - - string description; - if (patternList.IsNullOrEmpty()) - { - description = "not be assignable to no types (always true)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(type => !type.Equals(firstPattern)) - .Distinct() - .Aggregate( - "not be assignable to types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimpleCondition(Condition, description); - } - public static ICondition NotBeAssignableTo( IType firstType, params IType[] moreTypes @@ -1215,26 +1039,6 @@ public static ICondition NotBeStructs() ); } - public static ICondition NotImplementInterface( - string pattern, - bool useRegularExpressions = false - ) - { - return new SimpleCondition( - type => !type.ImplementsInterface(pattern, useRegularExpressions), - "not implement interface with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"", - "does implement interface with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - public static ICondition NotImplementInterface(Interface intf) { return new SimpleCondition( @@ -1302,7 +1106,7 @@ Architecture architecture public static ICondition NotResideInNamespace( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { return new SimpleCondition( type => !type.ResidesInNamespace(pattern, useRegularExpressions), @@ -1318,7 +1122,7 @@ public static ICondition NotResideInNamespace( public static ICondition NotResideInAssembly( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { return new SimpleCondition( type => !type.ResidesInAssembly(pattern, useRegularExpressions), diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypePredicatesDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypePredicatesDefinition.cs index 54958ea0a..b4c98c960 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypePredicatesDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypePredicatesDefinition.cs @@ -69,61 +69,6 @@ IEnumerable Filter(IEnumerable ruleTypes, Architecture architecture) return new ArchitecturePredicate(Filter, description); } - public static IPredicate AreAssignableTo( - string pattern, - bool useRegularExpressions = false - ) - { - var description = - "are assignable to types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\""; - return new SimplePredicate( - type => type.IsAssignableTo(pattern, useRegularExpressions), - description - ); - } - - public static IPredicate AreAssignableTo( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Condition(T ruleType) - { - return patternList.Any(pattern => - ruleType.IsAssignableTo(pattern, useRegularExpressions) - ); - } - - string description; - if (patternList.IsNullOrEmpty()) - { - description = "are assignable to no types (always false)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(type => !type.Equals(firstPattern)) - .Distinct() - .Aggregate( - "are assignable to types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimplePredicate(Condition, description); - } - public static IPredicate AreAssignableTo(IType firstType, params IType[] moreTypes) { IEnumerable Condition(IEnumerable ruleTypes) @@ -369,22 +314,7 @@ public static IPredicate AreStructs() { return new SimplePredicate(type => type is Struct, "are structs"); } - - public static IPredicate ImplementInterface( - string pattern, - bool useRegularExpressions = false - ) - { - return new SimplePredicate( - type => type.ImplementsInterface(pattern, useRegularExpressions), - "implement interface with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - + public static IPredicate ImplementInterface(Interface intf) { return new SimplePredicate( @@ -420,7 +350,7 @@ IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) public static IPredicate ResideInNamespace( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { return new SimplePredicate( type => type.ResidesInNamespace(pattern, useRegularExpressions), @@ -435,7 +365,7 @@ public static IPredicate ResideInNamespace( public static IPredicate ResideInAssembly( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { return new SimplePredicate( type => type.ResidesInAssembly(pattern, useRegularExpressions), @@ -575,61 +505,6 @@ IEnumerable Filter(IEnumerable ruleTypes, Architecture architecture) return new ArchitecturePredicate(Filter, description); } - public static IPredicate AreNotAssignableTo( - string pattern, - bool useRegularExpressions = false - ) - { - var description = - "are not assignable to types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\""; - return new SimplePredicate( - type => !type.IsAssignableTo(pattern, useRegularExpressions), - description - ); - } - - public static IPredicate AreNotAssignableTo( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Condition(T ruleType) - { - return patternList.All(pattern => - !ruleType.IsAssignableTo(pattern, useRegularExpressions) - ); - } - - string description; - if (patternList.IsNullOrEmpty()) - { - description = "are not assignable to no types (always true)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(type => !type.Equals(firstPattern)) - .Distinct() - .Aggregate( - "are not assignable to types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimplePredicate(Condition, description); - } - public static IPredicate AreNotAssignableTo(IType firstType, params IType[] moreTypes) { IEnumerable Condition(IEnumerable ruleTypes) @@ -767,22 +642,7 @@ public static IPredicate AreNotStructs() { return new SimplePredicate(cls => !(cls is Struct), "are not structs"); } - - public static IPredicate DoNotImplementInterface( - string pattern, - bool useRegularExpressions = false - ) - { - return new SimplePredicate( - type => !type.ImplementsInterface(pattern, useRegularExpressions), - "do not implement interface with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - + public static IPredicate DoNotImplementInterface(Interface intf) { return new SimplePredicate( @@ -818,7 +678,7 @@ IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) public static IPredicate DoNotResideInNamespace( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { return new SimplePredicate( type => !type.ResidesInNamespace(pattern, useRegularExpressions), @@ -833,7 +693,7 @@ public static IPredicate DoNotResideInNamespace( public static IPredicate DoNotResideInAssembly( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { return new SimplePredicate( type => !type.ResidesInAssembly(pattern, useRegularExpressions), diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShould.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShould.cs index 20267d115..8e2db3d3d 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShould.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShould.cs @@ -35,28 +35,6 @@ public TRuleTypeShouldConjunction Be(IEnumerable types) return Create(_ruleCreator); } - public TRuleTypeShouldConjunction BeAssignableTo( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - TypeConditionsDefinition.BeAssignableTo(pattern, useRegularExpressions) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction BeAssignableTo( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - TypeConditionsDefinition.BeAssignableTo(patterns, useRegularExpressions) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction BeAssignableTo(IType firstType, params IType[] moreTypes) { _ruleCreator.AddCondition( @@ -143,20 +121,6 @@ public TRuleTypeShouldConjunction BeStructs() return Create(_ruleCreator); } - public TRuleTypeShouldConjunction ImplementInterface( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - TypeConditionsDefinition.ImplementInterface( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction ImplementInterface(Interface intf) { _ruleCreator.AddCondition(TypeConditionsDefinition.ImplementInterface(intf)); @@ -172,7 +136,7 @@ public TRuleTypeShouldConjunction ImplementInterface(Type intf) public TRuleTypeShouldConjunction ResideInNamespace( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { _ruleCreator.AddCondition( TypeConditionsDefinition.ResideInNamespace( @@ -186,7 +150,7 @@ public TRuleTypeShouldConjunction ResideInNamespace( public TRuleTypeShouldConjunction ResideInAssembly( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { _ruleCreator.AddCondition( TypeConditionsDefinition.ResideInAssembly(pattern, useRegularExpressions) @@ -285,35 +249,7 @@ public TRuleTypeShouldConjunction NotBe(IEnumerable types) _ruleCreator.AddCondition(TypeConditionsDefinition.NotBe(types)); return Create(_ruleCreator); } - - public TRuleTypeShouldConjunction NotBeAssignableTo( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - TypeConditionsDefinition.NotBeAssignableTo( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - - public TRuleTypeShouldConjunction NotBeAssignableTo( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - TypeConditionsDefinition.NotBeAssignableTo( - patterns, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - + public TRuleTypeShouldConjunction NotBeAssignableTo( IType firstType, params IType[] moreTypes @@ -369,20 +305,6 @@ public TRuleTypeShouldConjunction NotBeStructs() return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotImplementInterface( - string pattern, - bool useRegularExpressions = false - ) - { - _ruleCreator.AddCondition( - TypeConditionsDefinition.NotImplementInterface( - pattern, - useRegularExpressions - ) - ); - return Create(_ruleCreator); - } - public TRuleTypeShouldConjunction NotImplementInterface(Interface intf) { _ruleCreator.AddCondition( @@ -402,7 +324,7 @@ public TRuleTypeShouldConjunction NotImplementInterface(Type intf) public TRuleTypeShouldConjunction NotResideInNamespace( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { _ruleCreator.AddCondition( TypeConditionsDefinition.NotResideInNamespace( @@ -416,7 +338,7 @@ public TRuleTypeShouldConjunction NotResideInNamespace( public TRuleTypeShouldConjunction NotResideInAssembly( string pattern, bool useRegularExpressions = false - ) + ) //TODO split into multiple implementations { _ruleCreator.AddCondition( TypeConditionsDefinition.NotResideInAssembly( diff --git a/ArchUnitNETTests/ArchitectureTests/ArchUnitArchitectureTests.cs b/ArchUnitNETTests/ArchitectureTests/ArchUnitArchitectureTests.cs index 0214565ed..5d25552f5 100644 --- a/ArchUnitNETTests/ArchitectureTests/ArchUnitArchitectureTests.cs +++ b/ArchUnitNETTests/ArchitectureTests/ArchUnitArchitectureTests.cs @@ -32,7 +32,7 @@ public void DomainHasNoDependencyOnFluent() .That() .ResideInNamespace(DomainNamespace) .Should() - .NotDependOnAny(FluentNamespace) + .NotDependOnAny(Types().That().ResideInNamespace(FluentNamespace)) .Check(_architecture); } @@ -43,7 +43,7 @@ public void DomainHasNoDependencyOnLoader() .That() .ResideInNamespace(DomainNamespace) .Should() - .NotDependOnAny(LoaderNamespace) + .NotDependOnAny(Types().That().ResideInNamespace(LoaderNamespace)) .Check(_architecture); } @@ -54,7 +54,7 @@ public void LoaderHasNoDependencyOnFluent() .That() .ResideInNamespace(LoaderNamespace) .Should() - .NotDependOnAny(FluentNamespace) + .NotDependOnAny(Types().That().ResideInNamespace(FluentNamespace)) .Check(_architecture); } @@ -65,7 +65,7 @@ public void FluentHasNoDependencyOnLoader() .That() .ResideInNamespace(FluentNamespace) .Should() - .NotDependOnAny(LoaderNamespace) + .NotDependOnAny(Types().That().ResideInNamespace(LoaderNamespace)) .Check(_architecture); } } diff --git a/ArchUnitNETTests/Dependencies/ExternalDependenciesTests.cs b/ArchUnitNETTests/Dependencies/ExternalDependenciesTests.cs index f58882536..d6e36a089 100644 --- a/ArchUnitNETTests/Dependencies/ExternalDependenciesTests.cs +++ b/ArchUnitNETTests/Dependencies/ExternalDependenciesTests.cs @@ -38,13 +38,7 @@ public void PropertyDependencyTest() .HaveFullName(typeof(PropertyDependency).FullName) .Should() .NotDependOnAny(typeof(Class2)); - var notDependOnAnyRuleString = Classes() - .That() - .HaveFullName(typeof(PropertyDependency).FullName) - .Should() - .NotDependOnAny(typeof(Class2).FullName); Assert.False(notDependOnAnyRuleClass.HasNoViolations(Architecture)); //Class2 does not exist in Architecture - Assert.False(notDependOnAnyRuleString.HasNoViolations(Architecture)); Assert.False(notDependOnAnyRuleClass.HasNoViolations(ArchitectureExternalDependency)); } @@ -56,13 +50,7 @@ public void MethodBodyDependencyTest() .HaveFullName(typeof(MethodBodyDependency).FullName) .Should() .NotDependOnAny(typeof(Class3)); - var notDependOnAnyRuleString = Classes() - .That() - .HaveFullName(typeof(MethodBodyDependency).FullName) - .Should() - .NotDependOnAny(typeof(Class3).FullName); Assert.False(notDependOnAnyRuleClass.HasNoViolations(Architecture)); //Class3 does not exist in Architecture - Assert.False(notDependOnAnyRuleString.HasNoViolations(Architecture)); Assert.False(notDependOnAnyRuleClass.HasNoViolations(ArchitectureBothAssemblies)); } @@ -74,13 +62,7 @@ public void MethodArgumentDependencyTest() .HaveFullName(typeof(MethodArgumentDependency).FullName) .Should() .NotDependOnAny(typeof(Class2)); - var notDependOnAnyRuleString = Classes() - .That() - .HaveFullName(typeof(MethodArgumentDependency).FullName) - .Should() - .NotDependOnAny(typeof(Class2).FullName); Assert.False(notDependOnAnyRuleClass.HasNoViolations(Architecture)); //Class3 does not exist in Architecture - Assert.False(notDependOnAnyRuleString.HasNoViolations(Architecture)); } [Fact] @@ -91,13 +73,7 @@ public void FieldDependencyTest() .HaveFullName(typeof(FieldDependency).FullName) .Should() .NotDependOnAny(typeof(Class2)); - var notDependOnAnyRuleString = Classes() - .That() - .HaveFullName(typeof(FieldDependency).FullName) - .Should() - .NotDependOnAny(typeof(Class2).FullName); Assert.False(notDependOnAnyRuleClass.HasNoViolations(Architecture)); //Class3 does not exist in Architecture - Assert.False(notDependOnAnyRuleString.HasNoViolations(Architecture)); } } diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/MemberSyntaxElementsTests.cs b/ArchUnitNETTests/Fluent/Syntax/Elements/MemberSyntaxElementsTests.cs index 3b267ab30..f1d52c5fe 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/MemberSyntaxElementsTests.cs +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/MemberSyntaxElementsTests.cs @@ -38,22 +38,12 @@ public MemberSyntaxElementsTests() typeof(InternalTestClass), }; - private readonly List _falseTypesPattern = new List - { - StaticTestTypes.PublicTestClass.FullName, - StaticTestTypes.InternalTestClass.FullName, - }; - - private readonly List _falseTypeConstructors = new List - { - PublicTestClassConstructor, - InternalTestClassConstructor, - }; + private static readonly IObjectProvider FalseTypeConstructors = MethodMembers().That() + .HaveFullName("System.Void ArchUnitNETTests.Domain.PublicTestClass::.ctor()").Or() + .HaveFullName("System.Void ArchUnitNETTests.Domain.InternalTestClass::.ctor()"); - private const string PublicTestClassConstructor = - "System.Void ArchUnitNETTests.Domain.PublicTestClass::.ctor()"; - private const string InternalTestClassConstructor = - "System.Void ArchUnitNETTests.Domain.InternalTestClass::.ctor()"; + private static readonly IObjectProvider PublicTestClassConstructor = + MethodMembers().That().HaveFullName("System.Void ArchUnitNETTests.Domain.PublicTestClass::.ctor()"); [Fact] public void DeclaredInTest() @@ -126,42 +116,28 @@ public void DeclaredInTest() .Should() .BeDeclaredIn(_falseTypes1) .AndShould() - .NotBe(_falseTypeConstructors); + .NotBe(FalseTypeConstructors); var notDeclaredInOtherTypeMultiple1 = Members() .That() .Are(member) .Should() .NotBeDeclaredIn(_falseTypes1) .OrShould() - .Be(_falseTypeConstructors); + .Be(FalseTypeConstructors); var declaredInOtherTypeMultiple2 = Members() .That() .Are(member) .Should() .BeDeclaredIn(_falseTypes2) .AndShould() - .NotBe(_falseTypeConstructors); + .NotBe(FalseTypeConstructors); var notDeclaredInOtherTypeMultiple2 = Members() .That() .Are(member) .Should() .NotBeDeclaredIn(_falseTypes2) .OrShould() - .Be(_falseTypeConstructors); - var declaredInOtherTypeMultiplePattern = Members() - .That() - .Are(member) - .Should() - .BeDeclaredIn(_falseTypesPattern) - .AndShould() - .NotBe(_falseTypeConstructors); - var notDeclaredInOtherTypeMultiplePattern = Members() - .That() - .Are(member) - .Should() - .NotBeDeclaredIn(_falseTypesPattern) - .OrShould() - .Be(_falseTypeConstructors); + .Be(FalseTypeConstructors); Assert.True(declaredInRightTypeFluent.HasNoViolations(Architecture)); Assert.False(notDeclaredInRightTypeFluent.HasNoViolations(Architecture)); @@ -169,8 +145,6 @@ public void DeclaredInTest() Assert.True(notDeclaredInOtherTypeMultiple1.HasNoViolations(Architecture)); Assert.False(declaredInOtherTypeMultiple2.HasNoViolations(Architecture)); Assert.True(notDeclaredInOtherTypeMultiple2.HasNoViolations(Architecture)); - Assert.False(declaredInOtherTypeMultiplePattern.HasNoViolations(Architecture)); - Assert.True(notDeclaredInOtherTypeMultiplePattern.HasNoViolations(Architecture)); } foreach (var type in _types) @@ -204,11 +178,6 @@ public void DeclaredInTest() .AreDeclaredIn(StaticTestTypes.PublicTestClass) .Should() .Be(PublicTestClassConstructor); - var emptyTypeHasOnlyConstructorPattern = Members() - .That() - .AreDeclaredIn(typeof(PublicTestClass).FullName) - .Should() - .Be(PublicTestClassConstructor); var allMembersAreNotDeclaredInEmptyType1 = Members() .That() .AreNotDeclaredIn(typeof(PublicTestClass)) @@ -219,18 +188,11 @@ public void DeclaredInTest() .AreNotDeclaredIn(StaticTestTypes.PublicTestClass) .Should() .Be(Members().That().AreNot(PublicTestClassConstructor)); - var allMembersAreNotDeclaredInEmptyTypePattern = Members() - .That() - .AreNotDeclaredIn(typeof(PublicTestClass).FullName) - .Should() - .Be(Members().That().AreNot(PublicTestClassConstructor)); Assert.True(emptyTypeHasOnlyConstructor1.HasNoViolations(Architecture)); Assert.True(emptyTypeHasOnlyConstructor2.HasNoViolations(Architecture)); - Assert.True(emptyTypeHasOnlyConstructorPattern.HasNoViolations(Architecture)); Assert.True(allMembersAreNotDeclaredInEmptyType1.HasNoViolations(Architecture)); Assert.True(allMembersAreNotDeclaredInEmptyType2.HasNoViolations(Architecture)); - Assert.True(allMembersAreNotDeclaredInEmptyTypePattern.HasNoViolations(Architecture)); //Multiple Arguments @@ -238,41 +200,27 @@ public void DeclaredInTest() .That() .AreDeclaredIn(_falseTypes1) .Should() - .Be(_falseTypeConstructors); + .Be(FalseTypeConstructors); var emptyTypeHasOnlyConstructorMultiple2 = Members() .That() .AreDeclaredIn(_falseTypes2) .Should() - .Be(_falseTypeConstructors); - var emptyTypeHasOnlyConstructorMultiplePattern = Members() - .That() - .AreDeclaredIn(_falseTypesPattern) - .Should() - .Be(_falseTypeConstructors); + .Be(FalseTypeConstructors); var allMembersAreNotDeclaredInEmptyTypeMultiple1 = Members() .That() .AreNotDeclaredIn(_falseTypes1) .Should() - .Be(Members().That().AreNot(_falseTypeConstructors)); + .Be(Members().That().AreNot(FalseTypeConstructors)); var allMembersAreNotDeclaredInEmptyTypeMultiple2 = Members() .That() .AreNotDeclaredIn(_falseTypes2) .Should() - .Be(Members().That().AreNot(_falseTypeConstructors)); - var allMembersAreNotDeclaredInEmptyTypeMultiplePattern = Members() - .That() - .AreNotDeclaredIn(_falseTypesPattern) - .Should() - .Be(Members().That().AreNot(_falseTypeConstructors)); + .Be(Members().That().AreNot(FalseTypeConstructors)); Assert.True(emptyTypeHasOnlyConstructorMultiple1.HasNoViolations(Architecture)); Assert.True(emptyTypeHasOnlyConstructorMultiple2.HasNoViolations(Architecture)); - Assert.True(emptyTypeHasOnlyConstructorMultiplePattern.HasNoViolations(Architecture)); Assert.True(allMembersAreNotDeclaredInEmptyTypeMultiple1.HasNoViolations(Architecture)); Assert.True(allMembersAreNotDeclaredInEmptyTypeMultiple2.HasNoViolations(Architecture)); - Assert.True( - allMembersAreNotDeclaredInEmptyTypeMultiplePattern.HasNoViolations(Architecture) - ); } [Fact] diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/MethodMemberSyntaxElementsTests.cs b/ArchUnitNETTests/Fluent/Syntax/Elements/MethodMemberSyntaxElementsTests.cs index e69148972..4d7a289fa 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/MethodMemberSyntaxElementsTests.cs +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/MethodMemberSyntaxElementsTests.cs @@ -196,7 +196,7 @@ public void CalledByTest() foreach ( var callingType in methodMember .GetMethodCallDependencies(true) - .Select(dependency => dependency.Origin.FullName) + .Select(dependency => dependency.Origin) ) { var methodIsCalledByRightType = MethodMembers() @@ -218,12 +218,12 @@ var callingType in methodMember .That() .Are(methodMember) .Should() - .BeCalledBy(typeof(PublicTestClass).FullName); + .BeCalledBy(typeof(PublicTestClass)); var methodIsNotCalledByFalseType = MethodMembers() .That() .Are(methodMember) .Should() - .NotBeCalledBy(typeof(PublicTestClass).FullName); + .NotBeCalledBy(typeof(PublicTestClass)); Assert.False(methodIsCalledByFalseType.HasNoViolations(Architecture)); Assert.True(methodIsNotCalledByFalseType.HasNoViolations(Architecture)); @@ -233,15 +233,15 @@ var callingType in methodMember { var calledMethodsShouldBeCalled = MethodMembers() .That() - .AreCalledBy(type.FullName) + .AreCalledBy(type) .Should() - .BeCalledBy(type.FullName) + .BeCalledBy(type) .WithoutRequiringPositiveResults(); var notCalledMethodsShouldNotBeCalled = MethodMembers() .That() - .AreNotCalledBy(type.FullName) + .AreNotCalledBy(type) .Should() - .NotBeCalledBy(type.FullName); + .NotBeCalledBy(type); Assert.True(calledMethodsShouldBeCalled.HasNoViolations(Architecture)); Assert.True(notCalledMethodsShouldNotBeCalled.HasNoViolations(Architecture)); @@ -249,12 +249,12 @@ var callingType in methodMember var emptyTypeCallsNoMethods = MethodMembers() .That() - .AreCalledBy(typeof(PublicTestClass).FullName) + .AreCalledBy(typeof(PublicTestClass)) .Should() .NotExist(); var methodsNotCalledByEmptyTypeShouldExist = MethodMembers() .That() - .AreNotCalledBy(typeof(PublicTestClass).FullName) + .AreNotCalledBy(typeof(PublicTestClass)) .Should() .Exist(); @@ -270,7 +270,7 @@ public void HaveDependencyInMethodBodyTest() foreach ( var dependency in methodMember .GetBodyTypeMemberDependencies() - .Select(dependency => dependency.Target.FullName) + .Select(dependency => dependency.Target) ) { var hasRightDependency = MethodMembers() @@ -293,15 +293,15 @@ var dependency in methodMember { var dependentMethodsShouldBeDependent = MethodMembers() .That() - .HaveDependencyInMethodBodyTo(type.FullName) + .HaveDependencyInMethodBodyTo(type) .Should() - .HaveDependencyInMethodBodyTo(type.FullName) + .HaveDependencyInMethodBodyTo(type) .WithoutRequiringPositiveResults(); var notDependentMethodsShouldNotBeDependent = MethodMembers() .That() - .DoNotHaveDependencyInMethodBodyTo(type.FullName) + .DoNotHaveDependencyInMethodBodyTo(type) .Should() - .NotHaveDependencyInMethodBodyTo(type.FullName); + .NotHaveDependencyInMethodBodyTo(type); Assert.True(dependentMethodsShouldBeDependent.HasNoViolations(Architecture)); Assert.True(notDependentMethodsShouldNotBeDependent.HasNoViolations(Architecture)); @@ -311,21 +311,6 @@ var dependency in methodMember [Fact] public void HaveReturnTypeConditionTest() { - var stringReturnTypes = new List { "Void", "String", "ReturnTypeClass" }; - var retTypeWithString = MethodMembers() - .That() - .HaveFullNameContaining("ReturnTypeMethod") - .Should() - .HaveReturnType(stringReturnTypes, true); - var retTypeWithStringFail = MethodMembers() - .That() - .HaveFullNameContaining("ReturnTypeMethod") - .Should() - .HaveReturnType("bool", true); - - Assert.True(retTypeWithString.HasNoViolations(Architecture)); - Assert.False(retTypeWithStringFail.HasNoViolations(Architecture)); - var retTypeWithType = MethodMembers() .That() .HaveFullNameContaining("ReturnTypeMethod") @@ -373,21 +358,6 @@ public void HaveReturnTypeConditionTest() [Fact] public void NotHaveReturnTypeConditionTest() { - var stringReturnTypes = new List { "Void", "String", "ReturnTypeClass" }; - var retTypeWithString = MethodMembers() - .That() - .HaveFullNameContaining("ReturnTypeMethod") - .Should() - .NotHaveReturnType("bool", true); - var retTypeWithStringFail = MethodMembers() - .That() - .HaveFullNameContaining("ReturnTypeMethod") - .Should() - .NotHaveReturnType(stringReturnTypes, true); - - Assert.True(retTypeWithString.HasNoViolations(Architecture)); - Assert.False(retTypeWithStringFail.HasNoViolations(Architecture)); - var retTypeWithType = MethodMembers() .That() .HaveFullNameContaining("ReturnTypeMethod") @@ -435,28 +405,6 @@ public void NotHaveReturnTypeConditionTest() [Fact] public void HaveReturnTypePredicateTest() { - var stringReturnTypes = new List { "void", "string" }; - var retTypeWithString = MethodMembers() - .That() - .HaveFullNameContaining("ReturnTypeMethod") - .And() - .HaveReturnType(stringReturnTypes, true) - .Should() - .HaveFullNameContaining("Void") - .OrShould() - .HaveFullNameContaining("String") - .WithoutRequiringPositiveResults(); - var retTypeWithStringNegate = MethodMembers() - .That() - .DoNotHaveReturnType("String", true) - .And() - .HaveFullNameContaining("ReturnTypeMethod") - .Should() - .NotHaveFullNameContaining("String"); - - Assert.True(retTypeWithString.HasNoViolations(Architecture)); - Assert.True(retTypeWithStringNegate.HasNoViolations(Architecture)); - var retTypeWithType = MethodMembers() .That() .HaveFullNameContaining("ReturnTypeMethod") @@ -478,12 +426,12 @@ public void HaveReturnTypePredicateTest() var objectProviderClass = Classes().That().HaveFullNameContaining("ReturnTypeClass"); var retTypeWithObjectProvider = MethodMembers() .That() - .HaveReturnType("ReturnTypeClass", true) + .HaveReturnType(objectProviderClass) .Should() .HaveFullNameContaining("ReturnTypeMethodClass"); var retTypeWithObjectProviderFail = MethodMembers() .That() - .DoNotHaveReturnType("ReturnTypeClass", true) + .DoNotHaveReturnType(objectProviderClass) .And() .HaveFullNameContaining("ReturnTypeMethod") .Should() diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectSyntaxElementsTests.cs b/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectSyntaxElementsTests.cs index bf9fd665e..ee590b8fd 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectSyntaxElementsTests.cs +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectSyntaxElementsTests.cs @@ -46,24 +46,24 @@ public void AreTest() var typeIsItselfPattern = Types() .That() - .Are(type.FullName) + .Are(type) .Should() - .Be(type.FullName); + .Be(type); var typeIsNotItselfPattern = Types() .That() - .Are(type.FullName) + .Are(type) .Should() - .NotBe(type.FullName); + .NotBe(type); var otherTypesAreNotThisTypePattern = Types() .That() - .AreNot(type.FullName) + .AreNot(type) .Should() - .NotBe(type.FullName); + .NotBe(type); var otherTypesAreThisTypePattern = Types() .That() - .AreNot(type.FullName) + .AreNot(type) .Should() - .Be(type.FullName); + .Be(type); Assert.True(typeIsItself.HasNoViolations(Architecture)); Assert.False(typeIsNotItself.HasNoViolations(Architecture)); @@ -97,40 +97,13 @@ public void AreTest() .Should() .NotBe(StaticTestTypes.PublicTestClass); - var publicTestClassIsPublicPattern = Types() - .That() - .Are(StaticTestTypes.PublicTestClass.FullName) - .Should() - .BePublic(); - var publicTestClassIsNotPublicPattern = Types() - .That() - .Are(StaticTestTypes.PublicTestClass.FullName) - .Should() - .NotBePublic(); - var notPublicTypesAreNotPublicTestClassPattern = Types() - .That() - .AreNotPublic() - .Should() - .NotBe(StaticTestTypes.PublicTestClass.FullName); - var publicTypesAreNotPublicTestClassPattern = Types() - .That() - .ArePublic() - .Should() - .NotBe(StaticTestTypes.PublicTestClass.FullName); - Assert.True(publicTestClassIsPublic.HasNoViolations(Architecture)); Assert.False(publicTestClassIsNotPublic.HasNoViolations(Architecture)); Assert.True(notPublicTypesAreNotPublicTestClass.HasNoViolations(Architecture)); Assert.False(publicTypesAreNotPublicTestClass.HasNoViolations(Architecture)); - Assert.True(publicTestClassIsPublicPattern.HasNoViolations(Architecture)); - Assert.False(publicTestClassIsNotPublicPattern.HasNoViolations(Architecture)); - Assert.True(notPublicTypesAreNotPublicTestClassPattern.HasNoViolations(Architecture)); - Assert.False(publicTypesAreNotPublicTestClassPattern.HasNoViolations(Architecture)); - //Tests with multiple arguments - - + var publicTestClassAndInternalTestClassIsPublicOrInternal = Types() .That() .Are(StaticTestTypes.PublicTestClass, StaticTestTypes.InternalTestClass) @@ -200,32 +173,7 @@ public void AreTest() .AreInternal() .Should() .NotBe(list); - - var patternList = new List - { - StaticTestTypes.PublicTestClass.FullName, - StaticTestTypes.InternalTestClass.FullName, - }; - var publicTestClassAndInternalTestClassIsPublicOrInternalPattern = Types() - .That() - .Are(patternList) - .Should() - .BePublic() - .OrShould() - .BeInternal(); - var publicTestClassAndInternalTestClassIsPublicPattern = Types() - .That() - .Are(patternList) - .Should() - .BePublic(); - var notPublicAndNotInternalClassesAreNotPublicTestClassOrInternalTestClassPattern = - Types().That().AreNotPublic().And().AreNotInternal().Should().NotBe(patternList); - var internalTypesAreNotPublicTestClassOrInternalTestClassPattern = Types() - .That() - .AreInternal() - .Should() - .NotBe(patternList); - + Assert.True( listPublicTestClassAndInternalTestClassIsPublicOrInternal.HasNoViolations( Architecture @@ -244,25 +192,6 @@ public void AreTest() Architecture ) ); - - Assert.True( - publicTestClassAndInternalTestClassIsPublicOrInternalPattern.HasNoViolations( - Architecture - ) - ); - Assert.False( - publicTestClassAndInternalTestClassIsPublicPattern.HasNoViolations(Architecture) - ); - Assert.True( - notPublicAndNotInternalClassesAreNotPublicTestClassOrInternalTestClassPattern.HasNoViolations( - Architecture - ) - ); - Assert.False( - internalTypesAreNotPublicTestClassOrInternalTestClassPattern.HasNoViolations( - Architecture - ) - ); } [Fact] @@ -270,57 +199,37 @@ public void DependOnPatternTest() { foreach (var type in _types) { - //One Argument - var typesDependOnOwnDependencies = Types() .That() - .DependOnAny(type.FullName) + .DependOnAny(type) .Should() - .DependOnAny(type.FullName) + .DependOnAny(type) .WithoutRequiringPositiveResults(); var typeDoesNotDependOnFalseDependency = Types() .That() .Are(type) .Should() - .NotDependOnAny(NoTypeName); + .NotDependOnAny(Types().That().HaveFullName(NoTypeName)); var typeDependsOnFalseDependency = Types() .That() .Are(type) .Should() - .DependOnAny(NoTypeName) + .DependOnAny(Types().That().HaveFullName(NoTypeName)) .WithoutRequiringPositiveResults(); Assert.True(typesDependOnOwnDependencies.HasNoViolations(Architecture)); Assert.True(typeDoesNotDependOnFalseDependency.HasNoViolations(Architecture)); Assert.False(typeDependsOnFalseDependency.HasNoViolations(Architecture)); - - //Multiple Arguments - - var patternList = new List { type.FullName, NoTypeName }; - var typesDependOnOwnDependenciesMultiple = Types() - .That() - .DependOnAny(patternList) - .Should() - .DependOnAny(patternList) - .WithoutRequiringPositiveResults(); - var typeDependsOnFalseDependencyMultiple = Types() - .That() - .Are(patternList) - .Should() - .DependOnAny(NoTypeName); - - Assert.True(typesDependOnOwnDependenciesMultiple.HasNoViolations(Architecture)); - Assert.False(typeDependsOnFalseDependencyMultiple.HasNoViolations(Architecture)); } var noTypeDependsOnFalseDependency = Types() .That() - .DependOnAny(NoTypeName) + .DependOnAny(Types().That().HaveFullName(NoTypeName)) .Should() .NotExist(); var typesDoNotDependsOnFalseDependency = Types() .That() - .DoNotDependOnAny(NoTypeName) + .DoNotDependOnAny(Types().That().HaveFullName(NoTypeName)) .Should() .Exist(); diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectsShouldTests.cs b/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectsShouldTests.cs index d11a8b2bf..cec013093 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectsShouldTests.cs +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectsShouldTests.cs @@ -18,10 +18,6 @@ public async Task BeTest() var helper = new DependencyAssemblyTestHelper(); helper.AddSnapshotHeader("No violations"); var should = Types().That().Are(helper.ChildClass).Should(); - should.Be(helper.ChildClass.FullName).AssertNoViolations(helper); - should.Be("^.*\\.ChildClass$", true).AssertNoViolations(helper); - should.Be([helper.ChildClass.FullName]).AssertNoViolations(helper); - should.Be(["^.*\\.ChildClass$"], true).AssertNoViolations(helper); should.Be(helper.ChildClass).AssertNoViolations(helper); should.Be(helper.ChildClassSystemType).AssertNoViolations(helper); should.Be(Classes().That().Are(helper.ChildClass)).AssertNoViolations(helper); @@ -30,10 +26,6 @@ public async Task BeTest() helper.AddSnapshotHeader("Violations"); should = Types().That().Are(helper.ChildClass).Should(); - should.Be(helper.ClassWithoutDependencies.FullName).AssertOnlyViolations(helper); - should.Be("^.*\\.ClassWithoutDependencies$", true).AssertOnlyViolations(helper); - should.Be([helper.ClassWithoutDependencies.FullName]).AssertOnlyViolations(helper); - should.Be(["^.*\\.ClassWithoutDependencies$"], true).AssertOnlyViolations(helper); should.Be(helper.ClassWithoutDependencies).AssertOnlyViolations(helper); should.Be(helper.ClassWithoutDependenciesSystemType).AssertOnlyViolations(helper); should @@ -42,23 +34,14 @@ public async Task BeTest() should.Be([helper.ClassWithoutDependencies]).AssertOnlyViolations(helper); should.Be([helper.ClassWithoutDependenciesSystemType]).AssertOnlyViolations(helper); - helper.AddSnapshotHeader("Non-existent type"); - should = Types().That().Are(helper.BaseClass).Should(); - should.Be(helper.NonExistentObjectName).AssertOnlyViolations(helper); - should.Be([helper.NonExistentObjectName]).AssertOnlyViolations(helper); - helper.AddSnapshotHeader("Empty arguments"); should = Types().That().Are(helper.BaseClass).Should(); - should.Be(new List()).AssertOnlyViolations(helper); should.Be(new List()).AssertOnlyViolations(helper); should.Be(new List()).AssertOnlyViolations(helper); - should.Be(Classes().That().Are(helper.NonExistentObjectName)).AssertOnlyViolations(helper); + should.Be(Classes().That().HaveFullName(helper.NonExistentObjectName)).AssertOnlyViolations(helper); helper.AddSnapshotHeader("Multiple arguments"); should = Types().That().Are(helper.ChildClass).Should(); - should - .Be([helper.ClassWithoutDependencies.FullName, helper.BaseClass.FullName]) - .AssertOnlyViolations(helper); should.Be(helper.ClassWithoutDependencies, helper.BaseClass).AssertOnlyViolations(helper); should.Be([helper.ClassWithoutDependencies, helper.BaseClass]).AssertOnlyViolations(helper); should @@ -483,47 +466,27 @@ public async Task CallAnyTest() var helper = new DependencyAssemblyTestHelper(); helper.AddSnapshotHeader("No violations"); var should = MethodMembers().That().Are(helper.MethodWithSingleDependency).Should(); - should.CallAny(helper.CalledMethod.FullName).AssertNoViolations(helper); - should.CallAny("^.*::CalledMethod\\(\\)$", true).AssertNoViolations(helper); - should.CallAny([helper.CalledMethod.FullName]).AssertNoViolations(helper); - should.CallAny(["^.*::CalledMethod\\(\\)$"], true).AssertNoViolations(helper); should.CallAny(helper.CalledMethod).AssertNoViolations(helper); should.CallAny([helper.CalledMethod]).AssertNoViolations(helper); should.CallAny(MethodMembers().That().Are(helper.CalledMethod)).AssertNoViolations(helper); helper.AddSnapshotHeader("Violations"); should = MethodMembers().That().Are(helper.MethodWithSingleDependency).Should(); - should.CallAny(helper.MethodWithoutDependencies.FullName).AssertOnlyViolations(helper); - should.CallAny([helper.MethodWithoutDependencies.FullName]).AssertOnlyViolations(helper); should.CallAny(helper.MethodWithoutDependencies).AssertOnlyViolations(helper); should.CallAny([helper.MethodWithoutDependencies]).AssertOnlyViolations(helper); should .CallAny(MethodMembers().That().Are(helper.MethodWithoutDependencies)) .AssertOnlyViolations(helper); - helper.AddSnapshotHeader("Non-existent method member"); - should = MethodMembers().That().Are(helper.MethodWithSingleDependency).Should(); - should.CallAny(helper.NonExistentObjectName).AssertOnlyViolations(helper); - should.CallAny([helper.NonExistentObjectName]).AssertOnlyViolations(helper); - helper.AddSnapshotHeader("Empty arguments"); should = MethodMembers().That().Are(helper.MethodWithSingleDependency).Should(); - should.CallAny(new List()).AssertOnlyViolations(helper); should.CallAny(new List()).AssertOnlyViolations(helper); should - .CallAny(MethodMembers().That().Are(helper.NonExistentObjectName)) + .CallAny(MethodMembers().That().HaveFullName(helper.NonExistentObjectName)) .AssertOnlyViolations(helper); helper.AddSnapshotHeader("Multiple arguments"); should = MethodMembers().That().Are(helper.MethodWithMultipleDependencies).Should(); - should - .CallAny( - [ - helper.MethodWithoutDependencies.FullName, - helper.MethodWithMultipleDependencies.FullName, - ] - ) - .AssertOnlyViolations(helper); should .CallAny(helper.MethodWithoutDependencies, helper.MethodWithMultipleDependencies) .AssertOnlyViolations(helper); @@ -560,10 +523,6 @@ public async Task DependOnAnyTest() var helper = new DependencyAssemblyTestHelper(); helper.AddSnapshotHeader("No violations"); var should = Types().That().Are(helper.ChildClass).Should(); - should.DependOnAny(helper.BaseClass.FullName).AssertNoViolations(helper); - should.DependOnAny("^.*\\.BaseClass$", true).AssertNoViolations(helper); - should.DependOnAny([helper.BaseClass.FullName]).AssertNoViolations(helper); - should.DependOnAny(["^.*\\.BaseClass$"], true).AssertNoViolations(helper); should.DependOnAny(helper.BaseClass).AssertNoViolations(helper); should.DependOnAny(helper.BaseClassSystemType).AssertNoViolations(helper); should.DependOnAny(Classes().That().Are(helper.BaseClass)).AssertNoViolations(helper); @@ -571,9 +530,7 @@ public async Task DependOnAnyTest() should.DependOnAny([helper.BaseClassSystemType]).AssertNoViolations(helper); helper.AddSnapshotHeader("Violations"); - should = Types().That().Are(helper.ClassWithMultipleDependencies.FullName).Should(); - should.DependOnAny(helper.ClassWithoutDependencies.FullName).AssertOnlyViolations(helper); - should.DependOnAny([helper.ClassWithoutDependencies.FullName]).AssertOnlyViolations(helper); + should = Types().That().HaveFullName(helper.ClassWithMultipleDependencies.FullName).Should(); should.DependOnAny(helper.ClassWithoutDependencies).AssertOnlyViolations(helper); should.DependOnAny(helper.ClassWithoutDependenciesSystemType).AssertOnlyViolations(helper); should @@ -583,32 +540,23 @@ public async Task DependOnAnyTest() should .DependOnAny([helper.ClassWithoutDependenciesSystemType]) .AssertOnlyViolations(helper); - - helper.AddSnapshotHeader("Non-existent type"); - should = Types().That().Are(helper.ClassWithMultipleDependencies.FullName).Should(); - should.DependOnAny(helper.NonExistentObjectName).AssertOnlyViolations(helper); - should.DependOnAny([helper.NonExistentObjectName]).AssertOnlyViolations(helper); - + helper.AddSnapshotHeader("Type outside of architecture"); - should = Types().That().Are(helper.ClassWithMultipleDependencies.FullName).Should(); + should = Types().That().Are(helper.ClassWithMultipleDependencies).Should(); should .DependOnAny(typeof(AttributeNamespace.ClassWithoutAttributes)) .AssertOnlyViolations(helper); helper.AddSnapshotHeader("Empty arguments"); - should = Types().That().Are(helper.ClassWithMultipleDependencies.FullName).Should(); - should.DependOnAny(new List()).AssertOnlyViolations(helper); + should = Types().That().Are(helper.ClassWithMultipleDependencies).Should(); should.DependOnAny(new List()).AssertOnlyViolations(helper); should.DependOnAny(new List()).AssertOnlyViolations(helper); should - .DependOnAny(Classes().That().Are(helper.NonExistentObjectName)) + .DependOnAny(Classes().That().HaveFullName(helper.NonExistentObjectName)) .AssertOnlyViolations(helper); helper.AddSnapshotHeader("Multiple arguments"); - should = Types().That().Are(helper.ClassWithMultipleDependencies.FullName).Should(); - should - .DependOnAny([helper.ClassWithoutDependencies.FullName, helper.BaseClass.FullName]) - .AssertOnlyViolations(helper); + should = Types().That().Are(helper.ClassWithMultipleDependencies).Should(); should .DependOnAny(helper.ClassWithoutDependencies, helper.BaseClass) .AssertOnlyViolations(helper); @@ -625,7 +573,7 @@ public async Task DependOnAnyTest() helper.AddSnapshotHeader("Input without dependencies"); should = Types().That().Are(helper.ClassWithoutDependencies).Should(); should - .DependOnAny([helper.BaseClass.FullName, helper.ChildClass.FullName]) + .DependOnAny([helper.BaseClass, helper.ChildClass]) .AssertOnlyViolations(helper); helper.AddSnapshotHeader("Multiple inputs"); @@ -679,7 +627,7 @@ public async Task ExistTest() helper.AddSnapshotHeader("Violations"); Types() .That() - .Are(helper.NonExistentObjectName) + .HaveFullName(helper.NonExistentObjectName) .Should() .Exist() .AssertOnlyViolations(helper); @@ -762,10 +710,6 @@ public async Task HaveAnyAttributesTest() var helper = new AttributeAssemblyTestHelpers(); helper.AddSnapshotHeader("No violations"); var should = Types().That().Are(helper.ClassWithAttributes).Should(); - should.HaveAnyAttributes(helper.Attribute1.FullName).AssertNoViolations(helper); - should.HaveAnyAttributes("^.*\\.Attribute1$", true).AssertNoViolations(helper); - should.HaveAnyAttributes([helper.Attribute1.FullName]).AssertNoViolations(helper); - should.HaveAnyAttributes(["^.*\\.Attribute1$"], true).AssertNoViolations(helper); should.HaveAnyAttributes(helper.Attribute1).AssertNoViolations(helper); should.HaveAnyAttributes([helper.Attribute1]).AssertNoViolations(helper); should.HaveAnyAttributes(helper.Attribute1SystemType).AssertNoViolations(helper); @@ -776,8 +720,6 @@ public async Task HaveAnyAttributesTest() helper.AddSnapshotHeader("Violations"); should = Types().That().Are(helper.ClassWithAttributes).Should(); - should.HaveAnyAttributes(helper.UnusedAttribute.FullName).AssertOnlyViolations(helper); - should.HaveAnyAttributes([helper.UnusedAttribute.FullName]).AssertOnlyViolations(helper); should.HaveAnyAttributes(helper.UnusedAttribute).AssertOnlyViolations(helper); should.HaveAnyAttributes([helper.UnusedAttribute]).AssertOnlyViolations(helper); should.HaveAnyAttributes(helper.UnusedAttributeSystemType).AssertOnlyViolations(helper); @@ -786,25 +728,16 @@ public async Task HaveAnyAttributesTest() .HaveAnyAttributes(Attributes().That().Are(helper.UnusedAttribute)) .AssertOnlyViolations(helper); - helper.AddSnapshotHeader("Non-existent attribute"); - should = Types().That().Are(helper.ClassWithAttributes).Should(); - should.HaveAnyAttributes(helper.NonExistentObjectName).AssertOnlyViolations(helper); - should.HaveAnyAttributes([helper.NonExistentObjectName]).AssertOnlyViolations(helper); - helper.AddSnapshotHeader("Empty arguments"); should = Types().That().Are(helper.ClassWithAttributes).Should(); - should.HaveAnyAttributes(new List()).AssertOnlyViolations(helper); should.HaveAnyAttributes(new List()).AssertOnlyViolations(helper); should.HaveAnyAttributes(new List()).AssertOnlyViolations(helper); should - .HaveAnyAttributes(Attributes().That().Are(helper.NonExistentObjectName)) + .HaveAnyAttributes(Attributes().That().HaveFullName(helper.NonExistentObjectName)) .AssertOnlyViolations(helper); helper.AddSnapshotHeader("Multiple arguments"); should = Types().That().Are(helper.ClassWithAttributes).Should(); - should - .HaveAnyAttributes([helper.Attribute1.FullName, helper.UnusedAttribute.FullName]) - .AssertNoViolations(helper); should .HaveAnyAttributes(helper.Attribute1, helper.UnusedAttribute) .AssertNoViolations(helper); @@ -1041,18 +974,6 @@ public async Task HaveAttributeWithArgumentsTest() var helper = new AttributeAssemblyTestHelpers(); helper.AddSnapshotHeader("No violations with type arguments"); var should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .HaveAttributeWithArguments( - helper.Attribute1.FullName, - helper.Attribute1Parameter3Value - ) - .AssertNoViolations(helper); - should - .HaveAttributeWithArguments( - helper.Attribute1.FullName, - [helper.Attribute1Parameter3Value] - ) - .AssertNoViolations(helper); should .HaveAttributeWithArguments(helper.Attribute1, helper.Attribute1Parameter3Value) .AssertNoViolations(helper); @@ -1074,18 +995,6 @@ public async Task HaveAttributeWithArgumentsTest() helper.AddSnapshotHeader("No violations with value arguments"); should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .HaveAttributeWithArguments( - helper.Attribute1.FullName, - helper.Attribute1Parameter1Value - ) - .AssertNoViolations(helper); - should - .HaveAttributeWithArguments( - helper.Attribute1.FullName, - [helper.Attribute1Parameter1Value] - ) - .AssertNoViolations(helper); should .HaveAttributeWithArguments(helper.Attribute1, helper.Attribute1Parameter1Value) .AssertNoViolations(helper); @@ -1107,18 +1016,6 @@ public async Task HaveAttributeWithArgumentsTest() helper.AddSnapshotHeader("Violations with type arguments"); should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .HaveAttributeWithArguments( - helper.Attribute1.FullName, - helper.Attribute1Parameter3InvalidValue - ) - .AssertOnlyViolations(helper); - should - .HaveAttributeWithArguments( - helper.Attribute1.FullName, - [helper.Attribute1Parameter3InvalidValue] - ) - .AssertOnlyViolations(helper); should .HaveAttributeWithArguments(helper.Attribute1, helper.Attribute1Parameter3InvalidValue) .AssertOnlyViolations(helper); @@ -1143,18 +1040,6 @@ public async Task HaveAttributeWithArgumentsTest() helper.AddSnapshotHeader("Violations with value arguments"); should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .HaveAttributeWithArguments( - helper.Attribute1.FullName, - helper.Attribute2Parameter2Value - ) - .AssertOnlyViolations(helper); - should - .HaveAttributeWithArguments( - helper.Attribute1.FullName, - [helper.Attribute2Parameter2Value] - ) - .AssertOnlyViolations(helper); should .HaveAttributeWithArguments(helper.Attribute1, helper.Attribute2Parameter2Value) .AssertOnlyViolations(helper); @@ -1174,15 +1059,6 @@ public async Task HaveAttributeWithArgumentsTest() ) .AssertOnlyViolations(helper); - helper.AddSnapshotHeader("Non-existent attribute"); - should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .HaveAttributeWithArguments( - helper.NonExistentObjectName, - helper.Attribute1Parameter1Value - ) - .AssertOnlyViolations(helper); - helper.AddSnapshotHeader("Type outside of architecture"); should = Types().That().Are(helper.ClassWithArguments).Should(); should @@ -1194,9 +1070,6 @@ public async Task HaveAttributeWithArgumentsTest() helper.AddSnapshotHeader("Null argument"); should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .HaveAttributeWithArguments(helper.Attribute1.FullName, null) - .AssertOnlyViolations(helper); should.HaveAttributeWithArguments(helper.Attribute1, null).AssertOnlyViolations(helper); should .HaveAttributeWithArguments(helper.Attribute1SystemType, null) @@ -1204,9 +1077,6 @@ public async Task HaveAttributeWithArgumentsTest() helper.AddSnapshotHeader("Empty arguments"); should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .HaveAttributeWithArguments(helper.Attribute1.FullName, new List()) - .AssertNoViolations(helper); should .HaveAttributeWithArguments(helper.Attribute1, new List()) .AssertNoViolations(helper); @@ -1216,12 +1086,6 @@ public async Task HaveAttributeWithArgumentsTest() helper.AddSnapshotHeader("Multiple arguments"); should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .HaveAttributeWithArguments( - helper.Attribute1.FullName, - [helper.Attribute1Parameter1Value, helper.Attribute1Parameter2Value] - ) - .AssertNoViolations(helper); should .HaveAttributeWithArguments( helper.Attribute1, @@ -1271,18 +1135,6 @@ public async Task HaveAttributeWithNamedArguments() var helper = new AttributeAssemblyTestHelpers(); helper.AddSnapshotHeader("No violations with type arguments"); var should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .HaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - helper.Attribute1NamedParameter1Pair - ) - .AssertNoViolations(helper); - should - .HaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - [helper.Attribute1NamedParameter1Pair] - ) - .AssertNoViolations(helper); should .HaveAttributeWithNamedArguments( helper.Attribute1, @@ -1310,18 +1162,6 @@ public async Task HaveAttributeWithNamedArguments() helper.AddSnapshotHeader("No violations with value arguments"); should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .HaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - helper.Attribute1NamedParameter2Pair - ) - .AssertNoViolations(helper); - should - .HaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - [helper.Attribute1NamedParameter2Pair] - ) - .AssertNoViolations(helper); should .HaveAttributeWithNamedArguments( helper.Attribute1, @@ -1349,18 +1189,6 @@ public async Task HaveAttributeWithNamedArguments() helper.AddSnapshotHeader("Violations with type arguments"); should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .HaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - helper.Attribute1NamedParameter1InvalidNamePair - ) - .AssertOnlyViolations(helper); - should - .HaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - [helper.Attribute1NamedParameter1InvalidNamePair] - ) - .AssertOnlyViolations(helper); should .HaveAttributeWithNamedArguments( helper.Attribute1, @@ -1385,18 +1213,6 @@ public async Task HaveAttributeWithNamedArguments() [helper.Attribute1NamedParameter1InvalidNamePair] ) .AssertOnlyViolations(helper); - should - .HaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - helper.Attribute1NamedParameter1InvalidValuePair - ) - .AssertOnlyViolations(helper); - should - .HaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - [helper.Attribute1NamedParameter1InvalidValuePair] - ) - .AssertOnlyViolations(helper); should .HaveAttributeWithNamedArguments( helper.Attribute1, @@ -1424,18 +1240,6 @@ public async Task HaveAttributeWithNamedArguments() helper.AddSnapshotHeader("Violations with value arguments"); should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .HaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - helper.Attribute1NamedParameter2InvalidNamePair - ) - .AssertOnlyViolations(helper); - should - .HaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - [helper.Attribute1NamedParameter2InvalidNamePair] - ) - .AssertOnlyViolations(helper); should .HaveAttributeWithNamedArguments( helper.Attribute1, @@ -1460,18 +1264,6 @@ public async Task HaveAttributeWithNamedArguments() [helper.Attribute1NamedParameter2InvalidNamePair] ) .AssertOnlyViolations(helper); - should - .HaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - helper.Attribute1NamedParameter2InvalidValuePair - ) - .AssertOnlyViolations(helper); - should - .HaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - [helper.Attribute1NamedParameter2InvalidValuePair] - ) - .AssertOnlyViolations(helper); should .HaveAttributeWithNamedArguments( helper.Attribute1, @@ -1499,18 +1291,6 @@ public async Task HaveAttributeWithNamedArguments() helper.AddSnapshotHeader("Unused attribute"); should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .HaveAttributeWithNamedArguments( - helper.UnusedAttribute.FullName, - helper.Attribute1NamedParameter1Pair - ) - .AssertOnlyViolations(helper); - should - .HaveAttributeWithNamedArguments( - helper.UnusedAttribute.FullName, - [helper.Attribute1NamedParameter1Pair] - ) - .AssertOnlyViolations(helper); should .HaveAttributeWithNamedArguments( helper.UnusedAttribute, @@ -1547,9 +1327,6 @@ public async Task HaveAttributeWithNamedArguments() helper.AddSnapshotHeader("Emtpy arguments"); should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .HaveAttributeWithNamedArguments(helper.Attribute1.FullName, []) - .AssertNoViolations(helper); should.HaveAttributeWithNamedArguments(helper.Attribute1, []).AssertNoViolations(helper); should .HaveAttributeWithNamedArguments(helper.Attribute1SystemType, []) @@ -1557,19 +1334,6 @@ public async Task HaveAttributeWithNamedArguments() helper.AddSnapshotHeader("Multiple arguments"); should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .HaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - helper.Attribute1NamedParameter1Pair, - helper.Attribute2NamedParameter2Pair - ) - .AssertOnlyViolations(helper); - should - .HaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - [helper.Attribute1NamedParameter1Pair, helper.Attribute2NamedParameter2Pair] - ) - .AssertOnlyViolations(helper); should .HaveAttributeWithNamedArguments( helper.Attribute1, @@ -1599,18 +1363,6 @@ public async Task HaveAttributeWithNamedArguments() helper.AddSnapshotHeader("Multiple inputs"); should = Types().That().Are(helper.ClassWithArguments, helper.ClassWithAttributes).Should(); - should - .HaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - helper.Attribute1NamedParameter1Pair - ) - .AssertAnyViolations(helper); - should - .HaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - [helper.Attribute1NamedParameter1Pair] - ) - .AssertAnyViolations(helper); should .HaveAttributeWithNamedArguments( helper.Attribute1, @@ -1671,11 +1423,7 @@ public async Task NotBeTest() { var helper = new DependencyAssemblyTestHelper(); helper.AddSnapshotHeader("No violations"); - var should = Types().That().DependOnAny(helper.BaseClass.FullName).Should(); - should.NotBe(helper.ClassWithoutDependencies.FullName).AssertNoViolations(helper); - should.NotBe("^.*\\.ClassWithoutDependencies$", true).AssertNoViolations(helper); - should.NotBe([helper.ClassWithoutDependencies.FullName]).AssertNoViolations(helper); - should.NotBe("^.*\\.ClassWithoutDependencies$", true).AssertNoViolations(helper); + var should = Types().That().DependOnAny(helper.BaseClass).Should(); should.NotBe(helper.ClassWithoutDependencies).AssertNoViolations(helper); should.NotBe(helper.ClassWithoutDependenciesSystemType).AssertNoViolations(helper); should @@ -1685,32 +1433,21 @@ public async Task NotBeTest() should.NotBe([helper.ClassWithoutDependenciesSystemType]).AssertNoViolations(helper); helper.AddSnapshotHeader("Violations"); - should = Types().That().DependOnAny(helper.BaseClass.FullName).Should(); - should.NotBe(helper.ChildClass.FullName).AssertAnyViolations(helper); - should.NotBe([helper.ChildClass.FullName]).AssertAnyViolations(helper); + should = Types().That().DependOnAny(helper.BaseClass).Should(); should.NotBe(helper.ChildClass).AssertAnyViolations(helper); should.NotBe(helper.ChildClassSystemType).AssertAnyViolations(helper); should.NotBe(Classes().That().Are(helper.ChildClass)).AssertAnyViolations(helper); should.NotBe([helper.ChildClass]).AssertAnyViolations(helper); should.NotBe([helper.ChildClassSystemType]).AssertAnyViolations(helper); - helper.AddSnapshotHeader("Non-existent type"); - should = Types().That().DependOnAny(helper.BaseClass.FullName).Should(); - should.NotBe(helper.NonExistentObjectName).AssertNoViolations(helper); - should.NotBe([helper.NonExistentObjectName]).AssertNoViolations(helper); - helper.AddSnapshotHeader("Empty arguments"); - should = Types().That().DependOnAny(helper.BaseClass.FullName).Should(); - should.NotBe(new List()).AssertNoViolations(helper); + should = Types().That().DependOnAny(helper.BaseClass).Should(); should.NotBe(new List()).AssertNoViolations(helper); should.NotBe(new List()).AssertNoViolations(helper); - should.NotBe(Classes().That().Are(helper.NonExistentObjectName)).AssertNoViolations(helper); + should.NotBe(Classes().That().HaveFullName(helper.NonExistentObjectName)).AssertNoViolations(helper); helper.AddSnapshotHeader("Multiple arguments"); - should = Types().That().DependOnAny(helper.BaseClass.FullName).Should(); - should - .NotBe([helper.ClassWithoutDependencies.FullName, helper.BaseClass.FullName]) - .AssertNoViolations(helper); + should = Types().That().DependOnAny(helper.BaseClass).Should(); should.NotBe(helper.ClassWithoutDependencies, helper.BaseClass).AssertNoViolations(helper); should .NotBe([helper.ClassWithoutDependencies, helper.BaseClass]) @@ -1730,10 +1467,6 @@ public async Task NotCallAnyTest() var helper = new DependencyAssemblyTestHelper(); helper.AddSnapshotHeader("No violations"); var should = MethodMembers().That().Are(helper.MethodWithSingleDependency).Should(); - should.NotCallAny(helper.MethodWithoutDependencies.FullName).AssertNoViolations(helper); - should.NotCallAny("^.*\\.MethodWithoutDependencies$", true).AssertNoViolations(helper); - should.NotCallAny([helper.MethodWithoutDependencies.FullName]).AssertNoViolations(helper); - should.NotCallAny("^.*\\.MethodWithoutDependencies$", true).AssertNoViolations(helper); should.NotCallAny(helper.MethodWithoutDependencies).AssertNoViolations(helper); should.NotCallAny([helper.MethodWithoutDependencies]).AssertNoViolations(helper); should @@ -1742,41 +1475,18 @@ public async Task NotCallAnyTest() helper.AddSnapshotHeader("Violations"); should = MethodMembers().That().Are(helper.MethodWithSingleDependency).Should(); - should.NotCallAny(helper.CalledMethod.FullName).AssertOnlyViolations(helper); - should.NotCallAny([helper.CalledMethod.FullName]).AssertOnlyViolations(helper); should.NotCallAny(helper.CalledMethod).AssertOnlyViolations(helper); should.NotCallAny([helper.CalledMethod]).AssertOnlyViolations(helper); should .NotCallAny(MethodMembers().That().Are(helper.CalledMethod)) .AssertOnlyViolations(helper); - helper.AddSnapshotHeader("Non-existent method member"); - should = MethodMembers().That().Are(helper.MethodWithSingleDependency).Should(); - should.NotCallAny(helper.NonExistentObjectName).AssertNoViolations(helper); - should.NotCallAny([helper.NonExistentObjectName]).AssertNoViolations(helper); - helper.AddSnapshotHeader("Empty arguments"); should = MethodMembers().That().Are(helper.MethodWithSingleDependency).Should(); - should.NotCallAny(new List()).AssertNoViolations(helper); should.NotCallAny(new List()).AssertNoViolations(helper); - should - .NotCallAny(MethodMembers().That().Are(helper.NonExistentObjectName)) - .AssertNoViolations(helper); helper.AddSnapshotHeader("Multiple arguments"); should = MethodMembers().That().Are(helper.MethodWithMultipleDependencies).Should(); - should - .NotCallAny("^.*::(MethodWithoutDependencies|CalledMethod[0-9])\\(\\)$", true) - .AssertOnlyViolations(helper); - should - .NotCallAny( - [ - helper.MethodWithoutDependencies.FullName, - helper.CalledMethod1.FullName, - helper.CalledMethod2.FullName, - ] - ) - .AssertOnlyViolations(helper); should .NotCallAny( helper.MethodWithoutDependencies, @@ -1847,12 +1557,6 @@ public async Task NotDependOnAnyTest() var helper = new DependencyAssemblyTestHelper(); helper.AddSnapshotHeader("No violations"); var should = Types().That().Are(helper.ChildClass).Should(); - should.NotDependOnAny(helper.ClassWithoutDependencies.FullName).AssertNoViolations(helper); - should.NotDependOnAny("^.*\\.ClassWithoutDependencies$", true).AssertNoViolations(helper); - should - .NotDependOnAny([helper.ClassWithoutDependencies.FullName]) - .AssertNoViolations(helper); - should.NotDependOnAny("^.*\\.ClassWithoutDependencies$", true).AssertNoViolations(helper); should.NotDependOnAny(helper.ClassWithoutDependencies).AssertNoViolations(helper); should.NotDependOnAny(helper.ClassWithoutDependenciesSystemType).AssertNoViolations(helper); should @@ -1865,19 +1569,12 @@ public async Task NotDependOnAnyTest() helper.AddSnapshotHeader("Violations"); should = Types().That().Are(helper.ChildClass).Should(); - should.NotDependOnAny(helper.BaseClass.FullName).AssertOnlyViolations(helper); - should.NotDependOnAny([helper.BaseClass.FullName]).AssertOnlyViolations(helper); should.NotDependOnAny(helper.BaseClass).AssertOnlyViolations(helper); should.NotDependOnAny(helper.BaseClassSystemType).AssertOnlyViolations(helper); should.NotDependOnAny(Classes().That().Are(helper.BaseClass)).AssertOnlyViolations(helper); should.NotDependOnAny([helper.BaseClass]).AssertOnlyViolations(helper); should.NotDependOnAny([helper.BaseClassSystemType]).AssertOnlyViolations(helper); - helper.AddSnapshotHeader("Non-existent type"); - should = Types().That().Are(helper.ChildClass).Should(); - should.NotDependOnAny(helper.NonExistentObjectName).AssertNoViolations(helper); - should.NotDependOnAny([helper.NonExistentObjectName]).AssertNoViolations(helper); - helper.AddSnapshotHeader("Type outside of architecture"); should = Types().That().Are(helper.ChildClass).Should(); should @@ -1886,18 +1583,11 @@ public async Task NotDependOnAnyTest() helper.AddSnapshotHeader("Empty arguments"); should = Types().That().Are(helper.ChildClass).Should(); - should.NotDependOnAny(new List()).AssertNoViolations(helper); should.NotDependOnAny(new List()).AssertNoViolations(helper); should.NotDependOnAny(new List()).AssertNoViolations(helper); - should - .NotDependOnAny(Classes().That().Are(helper.NonExistentObjectName)) - .AssertNoViolations(helper); helper.AddSnapshotHeader("Multiple arguments"); should = Types().That().Are(helper.ChildClass).Should(); - should - .NotDependOnAny([helper.ClassWithoutDependencies.FullName, helper.BaseClass.FullName]) - .AssertOnlyViolations(helper); should .NotDependOnAny(helper.ClassWithoutDependencies, helper.BaseClass) .AssertOnlyViolations(helper); @@ -1913,12 +1603,6 @@ public async Task NotDependOnAnyTest() helper.AddSnapshotHeader("Input with multiple dependencies"); should = Types().That().Are(helper.ClassWithMultipleDependencies).Should(); - should - .NotDependOnAny("^.*\\.(BaseClassWithMember|OtherBaseClass)$", true) - .AssertOnlyViolations(helper); - should - .NotDependOnAny([helper.BaseClassWithMember.FullName, helper.OtherBaseClass.FullName]) - .AssertOnlyViolations(helper); should .NotDependOnAny(helper.BaseClassWithMember, helper.OtherBaseClass) .AssertOnlyViolations(helper); @@ -1958,10 +1642,6 @@ public async Task NotHaveAnyAttributesTest() var helper = new AttributeAssemblyTestHelpers(); helper.AddSnapshotHeader("No violations"); var should = Types().That().Are(helper.ClassWithSingleAttribute).Should(); - should.NotHaveAnyAttributes(helper.UnusedAttribute.FullName).AssertNoViolations(helper); - should.NotHaveAnyAttributes("^.*\\.UnusedAttribute$", true).AssertNoViolations(helper); - should.NotHaveAnyAttributes([helper.UnusedAttribute.FullName]).AssertNoViolations(helper); - should.NotHaveAnyAttributes("^.*\\.UnusedAttribute$", true).AssertNoViolations(helper); should.NotHaveAnyAttributes(helper.UnusedAttribute).AssertNoViolations(helper); should.NotHaveAnyAttributes([helper.UnusedAttribute]).AssertNoViolations(helper); should.NotHaveAnyAttributes(helper.UnusedAttributeSystemType).AssertNoViolations(helper); @@ -1972,8 +1652,6 @@ public async Task NotHaveAnyAttributesTest() helper.AddSnapshotHeader("Violations"); should = Types().That().Are(helper.ClassWithSingleAttribute).Should(); - should.NotHaveAnyAttributes(helper.Attribute1.FullName).AssertOnlyViolations(helper); - should.NotHaveAnyAttributes([helper.Attribute1.FullName]).AssertOnlyViolations(helper); should.NotHaveAnyAttributes(helper.Attribute1).AssertOnlyViolations(helper); should.NotHaveAnyAttributes([helper.Attribute1]).AssertOnlyViolations(helper); should.NotHaveAnyAttributes(helper.Attribute1SystemType).AssertOnlyViolations(helper); @@ -1982,11 +1660,6 @@ public async Task NotHaveAnyAttributesTest() .NotHaveAnyAttributes(Attributes().That().Are(helper.Attribute1)) .AssertOnlyViolations(helper); - helper.AddSnapshotHeader("Non-existent attribute"); - should = Types().That().Are(helper.ClassWithoutAttributes).Should(); - should.NotHaveAnyAttributes(helper.NonExistentObjectName).AssertNoViolations(helper); - should.NotHaveAnyAttributes([helper.NonExistentObjectName]).AssertNoViolations(helper); - helper.AddSnapshotHeader("Type outside of architecture"); should = Types().That().Are(helper.ClassWithAttributes).Should(); should @@ -1995,17 +1668,12 @@ public async Task NotHaveAnyAttributesTest() helper.AddSnapshotHeader("Empty arguments"); should = Types().That().Are(helper.ClassWithoutAttributes).Should(); - should.NotHaveAnyAttributes(new List()).AssertNoViolations(helper); should.NotHaveAnyAttributes(new List()).AssertNoViolations(helper); should.NotHaveAnyAttributes(new List()).AssertNoViolations(helper); should - .NotHaveAnyAttributes(Attributes().That().Are(helper.NonExistentObjectName)) - .AssertNoViolations(helper); - should = Types().That().Are(helper.NonExistentObjectName).Should(); - should - .NotHaveAnyAttributes(new List()) - .WithoutRequiringPositiveResults() + .NotHaveAnyAttributes(Attributes().That().HaveFullName(helper.NonExistentObjectName)) .AssertNoViolations(helper); + should = Types().That().HaveFullName(helper.NonExistentObjectName).Should(); should .NotHaveAnyAttributes(new List()) .WithoutRequiringPositiveResults() @@ -2015,15 +1683,12 @@ public async Task NotHaveAnyAttributesTest() .WithoutRequiringPositiveResults() .AssertNoViolations(helper); should - .NotHaveAnyAttributes(Attributes().That().Are(helper.NonExistentObjectName)) + .NotHaveAnyAttributes(Attributes().That().HaveFullName(helper.NonExistentObjectName)) .WithoutRequiringPositiveResults() .AssertNoViolations(helper); helper.AddSnapshotHeader("Multiple arguments"); should = Types().That().Are(helper.ClassWithAttributes).Should(); - should - .NotHaveAnyAttributes([helper.Attribute1.FullName, helper.Attribute2.FullName]) - .AssertOnlyViolations(helper); should .NotHaveAnyAttributes(helper.Attribute1, helper.Attribute2) .AssertOnlyViolations(helper); @@ -2248,18 +1913,6 @@ public async Task NotHaveAttributeWithArgumentsTest() var helper = new AttributeAssemblyTestHelpers(); helper.AddSnapshotHeader("No violations with type arguments"); var should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .NotHaveAttributeWithArguments( - helper.Attribute1.FullName, - helper.Attribute2Parameter1Value - ) - .AssertNoViolations(helper); - should - .NotHaveAttributeWithArguments( - helper.Attribute1.FullName, - [helper.Attribute2Parameter1Value] - ) - .AssertNoViolations(helper); should .NotHaveAttributeWithArguments(helper.Attribute1, helper.Attribute2Parameter1Value) .AssertNoViolations(helper); @@ -2281,18 +1934,6 @@ public async Task NotHaveAttributeWithArgumentsTest() helper.AddSnapshotHeader("No violations with value arguments"); should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .NotHaveAttributeWithArguments( - helper.Attribute1.FullName, - helper.Attribute2Parameter1Value - ) - .AssertNoViolations(helper); - should - .NotHaveAttributeWithArguments( - helper.Attribute1.FullName, - [helper.Attribute2Parameter1Value] - ) - .AssertNoViolations(helper); should .NotHaveAttributeWithArguments(helper.Attribute1, helper.Attribute2Parameter1Value) .AssertNoViolations(helper); @@ -2314,18 +1955,6 @@ public async Task NotHaveAttributeWithArgumentsTest() helper.AddSnapshotHeader("Violations with type arguments"); should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .NotHaveAttributeWithArguments( - helper.Attribute1.FullName, - helper.Attribute1Parameter1Value - ) - .AssertOnlyViolations(helper); - should - .NotHaveAttributeWithArguments( - helper.Attribute1.FullName, - [helper.Attribute1Parameter1Value] - ) - .AssertOnlyViolations(helper); should .NotHaveAttributeWithArguments(helper.Attribute1, helper.Attribute1Parameter1Value) .AssertOnlyViolations(helper); @@ -2347,18 +1976,6 @@ public async Task NotHaveAttributeWithArgumentsTest() helper.AddSnapshotHeader("Violations with value arguments"); should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .NotHaveAttributeWithArguments( - helper.Attribute1.FullName, - helper.Attribute1Parameter2Value - ) - .AssertOnlyViolations(helper); - should - .NotHaveAttributeWithArguments( - helper.Attribute1.FullName, - [helper.Attribute1Parameter2Value] - ) - .AssertOnlyViolations(helper); should .NotHaveAttributeWithArguments(helper.Attribute1, helper.Attribute1Parameter2Value) .AssertOnlyViolations(helper); @@ -2380,18 +1997,6 @@ public async Task NotHaveAttributeWithArgumentsTest() helper.AddSnapshotHeader("Unused attribute"); should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .NotHaveAttributeWithArguments( - helper.UnusedAttribute.FullName, - helper.Attribute1Parameter1Value - ) - .AssertNoViolations(helper); - should - .NotHaveAttributeWithArguments( - helper.UnusedAttribute.FullName, - [helper.Attribute1Parameter1Value] - ) - .AssertNoViolations(helper); should .NotHaveAttributeWithArguments(helper.UnusedAttribute, helper.Attribute1Parameter1Value) .AssertNoViolations(helper); @@ -2422,9 +2027,6 @@ public async Task NotHaveAttributeWithArgumentsTest() helper.AddSnapshotHeader("Null argument"); should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .NotHaveAttributeWithArguments(helper.UnusedAttribute.FullName, null) - .AssertNoViolations(helper); should .NotHaveAttributeWithArguments(helper.UnusedAttribute, null) .AssertNoViolations(helper); @@ -2434,9 +2036,6 @@ public async Task NotHaveAttributeWithArgumentsTest() helper.AddSnapshotHeader("Empty arguments"); should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .NotHaveAttributeWithArguments(helper.Attribute1.FullName, []) - .AssertOnlyViolations(helper); should.NotHaveAttributeWithArguments(helper.Attribute1, []).AssertOnlyViolations(helper); should .NotHaveAttributeWithArguments(helper.Attribute1SystemType, []) @@ -2444,19 +2043,6 @@ public async Task NotHaveAttributeWithArgumentsTest() helper.AddSnapshotHeader("Multiple arguments"); should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .NotHaveAttributeWithArguments( - helper.Attribute1.FullName, - helper.Attribute1Parameter3Value, - helper.Attribute1Parameter2Value - ) - .AssertOnlyViolations(helper); - should - .NotHaveAttributeWithArguments( - helper.Attribute1.FullName, - [helper.Attribute1Parameter3Value, helper.Attribute1Parameter2Value] - ) - .AssertOnlyViolations(helper); should .NotHaveAttributeWithArguments( helper.Attribute1, @@ -2486,18 +2072,6 @@ public async Task NotHaveAttributeWithArgumentsTest() helper.AddSnapshotHeader("Multiple inputs"); should = Types().That().Are(helper.ClassWithArguments, helper.ClassWithAttributes).Should(); - should - .NotHaveAttributeWithArguments( - helper.Attribute1.FullName, - helper.Attribute1Parameter1Value - ) - .AssertAnyViolations(helper); - should - .NotHaveAttributeWithArguments( - helper.Attribute1.FullName, - [helper.Attribute1Parameter1Value] - ) - .AssertAnyViolations(helper); should .NotHaveAttributeWithArguments(helper.Attribute1, helper.Attribute1Parameter1Value) .AssertAnyViolations(helper); @@ -2526,18 +2100,6 @@ public async Task NotHaveAttributeWithNamedArgumentsTest() var helper = new AttributeAssemblyTestHelpers(); helper.AddSnapshotHeader("No violations with type arguments"); var should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .NotHaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - helper.Attribute2NamedParameter1Pair - ) - .AssertNoViolations(helper); - should - .NotHaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - [helper.Attribute2NamedParameter1Pair] - ) - .AssertNoViolations(helper); should .NotHaveAttributeWithNamedArguments( helper.Attribute1, @@ -2565,18 +2127,6 @@ public async Task NotHaveAttributeWithNamedArgumentsTest() helper.AddSnapshotHeader("No violations with value arguments"); should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .NotHaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - helper.Attribute2NamedParameter1Pair - ) - .AssertNoViolations(helper); - should - .NotHaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - [helper.Attribute2NamedParameter1Pair] - ) - .AssertNoViolations(helper); should .NotHaveAttributeWithNamedArguments( helper.Attribute1, @@ -2604,18 +2154,6 @@ public async Task NotHaveAttributeWithNamedArgumentsTest() helper.AddSnapshotHeader("Violations with type arguments"); should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .NotHaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - helper.Attribute1NamedParameter1Pair - ) - .AssertOnlyViolations(helper); - should - .NotHaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - [helper.Attribute1NamedParameter1Pair] - ) - .AssertOnlyViolations(helper); should .NotHaveAttributeWithNamedArguments( helper.Attribute1, @@ -2643,18 +2181,6 @@ public async Task NotHaveAttributeWithNamedArgumentsTest() helper.AddSnapshotHeader("Violations with value arguments"); should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .NotHaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - helper.Attribute1NamedParameter2Pair - ) - .AssertOnlyViolations(helper); - should - .NotHaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - [helper.Attribute1NamedParameter2Pair] - ) - .AssertOnlyViolations(helper); should .NotHaveAttributeWithNamedArguments( helper.Attribute1, @@ -2682,18 +2208,6 @@ public async Task NotHaveAttributeWithNamedArgumentsTest() helper.AddSnapshotHeader("Unused attribute"); should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .NotHaveAttributeWithNamedArguments( - helper.UnusedAttribute.FullName, - helper.Attribute1NamedParameter1Pair - ) - .AssertNoViolations(helper); - should - .NotHaveAttributeWithNamedArguments( - helper.UnusedAttribute.FullName, - [helper.Attribute1NamedParameter1Pair] - ) - .AssertNoViolations(helper); should .NotHaveAttributeWithNamedArguments( helper.UnusedAttribute, @@ -2730,9 +2244,6 @@ public async Task NotHaveAttributeWithNamedArgumentsTest() helper.AddSnapshotHeader("Empty arguments"); should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .NotHaveAttributeWithNamedArguments(helper.Attribute1.FullName, []) - .AssertOnlyViolations(helper); should .NotHaveAttributeWithNamedArguments(helper.Attribute1, []) .AssertOnlyViolations(helper); @@ -2742,19 +2253,6 @@ public async Task NotHaveAttributeWithNamedArgumentsTest() helper.AddSnapshotHeader("Multiple arguments"); should = Types().That().Are(helper.ClassWithArguments).Should(); - should - .NotHaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - helper.Attribute1NamedParameter1Pair, - helper.Attribute1NamedParameter2Pair - ) - .AssertOnlyViolations(helper); - should - .NotHaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - [helper.Attribute1NamedParameter1Pair, helper.Attribute1NamedParameter2Pair] - ) - .AssertOnlyViolations(helper); should .NotHaveAttributeWithNamedArguments( helper.Attribute1, @@ -2784,18 +2282,6 @@ public async Task NotHaveAttributeWithNamedArgumentsTest() helper.AddSnapshotHeader("Multiple inputs"); should = Types().That().Are(helper.ClassWithArguments, helper.ClassWithAttributes).Should(); - should - .NotHaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - helper.Attribute1NamedParameter1Pair - ) - .AssertAnyViolations(helper); - should - .NotHaveAttributeWithNamedArguments( - helper.Attribute1.FullName, - [helper.Attribute1NamedParameter1Pair] - ) - .AssertAnyViolations(helper); should .NotHaveAttributeWithNamedArguments( helper.Attribute1, @@ -2861,10 +2347,6 @@ public async Task OnlyDependOnTest() var helper = new DependencyAssemblyTestHelper(); helper.AddSnapshotHeader("No violations"); var should = Types().That().Are(helper.ChildClass).Should(); - should.OnlyDependOn(helper.BaseClass.FullName).AssertNoViolations(helper); - should.OnlyDependOn("^.*\\.BaseClass$", true).AssertNoViolations(helper); - should.OnlyDependOn([helper.BaseClass.FullName]).AssertNoViolations(helper); - should.OnlyDependOn(["^.*\\.BaseClass$"], true).AssertNoViolations(helper); should.OnlyDependOn(helper.BaseClass).AssertNoViolations(helper); should.OnlyDependOn(helper.BaseClassSystemType).AssertNoViolations(helper); should.OnlyDependOn(Classes().That().Are(helper.BaseClass)).AssertNoViolations(helper); @@ -2873,19 +2355,12 @@ public async Task OnlyDependOnTest() helper.AddSnapshotHeader("Violations"); should = Types().That().Are(helper.ClassWithMultipleDependencies).Should(); - should.OnlyDependOn(helper.BaseClass.FullName).AssertOnlyViolations(helper); - should.OnlyDependOn([helper.BaseClass.FullName]).AssertOnlyViolations(helper); should.OnlyDependOn(helper.BaseClass).AssertOnlyViolations(helper); should.OnlyDependOn(helper.BaseClassSystemType).AssertOnlyViolations(helper); should.OnlyDependOn(Classes().That().Are(helper.BaseClass)).AssertOnlyViolations(helper); should.OnlyDependOn([helper.BaseClass]).AssertOnlyViolations(helper); should.OnlyDependOn([helper.BaseClassSystemType]).AssertOnlyViolations(helper); - helper.AddSnapshotHeader("Non-existent type"); - should = Types().That().Are(helper.ClassWithMultipleDependencies).Should(); - should.OnlyDependOn(helper.NonExistentObjectName).AssertOnlyViolations(helper); - should.OnlyDependOn([helper.NonExistentObjectName]).AssertOnlyViolations(helper); - helper.AddSnapshotHeader("Type outside of architecture"); should = Types().That().Are(helper.ClassWithMultipleDependencies).Should(); should @@ -2894,18 +2369,14 @@ public async Task OnlyDependOnTest() helper.AddSnapshotHeader("Empty arguments"); should = Types().That().Are(helper.ClassWithMultipleDependencies).Should(); - should.OnlyDependOn(new List()).AssertOnlyViolations(helper); should.OnlyDependOn(new List()).AssertOnlyViolations(helper); should.OnlyDependOn(new List()).AssertOnlyViolations(helper); should - .OnlyDependOn(Classes().That().Are(helper.NonExistentObjectName)) + .OnlyDependOn(Classes().That().HaveFullName(helper.NonExistentObjectName)) .AssertOnlyViolations(helper); helper.AddSnapshotHeader("Multiple arguments"); should = Types().That().Are(helper.ClassWithMultipleDependencies).Should(); - should - .OnlyDependOn([helper.BaseClass.FullName, helper.OtherBaseClass.FullName]) - .AssertOnlyViolations(helper); should.OnlyDependOn(helper.BaseClass, helper.OtherBaseClass).AssertOnlyViolations(helper); should.OnlyDependOn([helper.BaseClass, helper.OtherBaseClass]).AssertOnlyViolations(helper); should @@ -2926,11 +2397,11 @@ public async Task OnlyDependOnTypesThatTest() var helper = new DependencyAssemblyTestHelper(); helper.AddSnapshotHeader("No violations"); var should = Types().That().Are(helper.ChildClass).Should(); - should.OnlyDependOnTypesThat().Are(helper.BaseClass.FullName).AssertNoViolations(helper); + should.OnlyDependOnTypesThat().Are(helper.BaseClass).AssertNoViolations(helper); helper.AddSnapshotHeader("Violations"); should = Types().That().Are(helper.ClassWithMultipleDependencies).Should(); - should.OnlyDependOnTypesThat().Are(helper.BaseClass.FullName).AssertOnlyViolations(helper); + should.OnlyDependOnTypesThat().Are(helper.BaseClass).AssertOnlyViolations(helper); await helper.AssertSnapshotMatches(); } @@ -2940,10 +2411,6 @@ public async Task OnlyHaveAttributesTest() var helper = new AttributeAssemblyTestHelpers(); helper.AddSnapshotHeader("No violations"); var should = Types().That().Are(helper.ClassWithSingleAttribute).Should(); - should.OnlyHaveAttributes(helper.Attribute1.FullName).AssertNoViolations(helper); - should.OnlyHaveAttributes("^.*\\.Attribute1$", true).AssertNoViolations(helper); - should.OnlyHaveAttributes([helper.Attribute1.FullName]).AssertNoViolations(helper); - should.OnlyHaveAttributes(["^.*\\.Attribute1$"], true).AssertNoViolations(helper); should.OnlyHaveAttributes(helper.Attribute1).AssertNoViolations(helper); should.OnlyHaveAttributes([helper.Attribute1]).AssertNoViolations(helper); should.OnlyHaveAttributes(helper.Attribute1SystemType).AssertNoViolations(helper); @@ -2954,8 +2421,6 @@ public async Task OnlyHaveAttributesTest() helper.AddSnapshotHeader("Violations"); should = Types().That().Are(helper.ClassWithSingleAttribute).Should(); - should.OnlyHaveAttributes(helper.UnusedAttribute.FullName).AssertOnlyViolations(helper); - should.OnlyHaveAttributes([helper.UnusedAttribute.FullName]).AssertOnlyViolations(helper); should.OnlyHaveAttributes(helper.UnusedAttribute).AssertOnlyViolations(helper); should.OnlyHaveAttributes([helper.UnusedAttribute]).AssertOnlyViolations(helper); should.OnlyHaveAttributes(helper.UnusedAttributeSystemType).AssertOnlyViolations(helper); @@ -2964,11 +2429,6 @@ public async Task OnlyHaveAttributesTest() .OnlyHaveAttributes(Attributes().That().Are(helper.UnusedAttribute)) .AssertOnlyViolations(helper); - helper.AddSnapshotHeader("Non-existent attribute"); - should = Types().That().Are(helper.ClassWithSingleAttribute).Should(); - should.OnlyHaveAttributes(helper.NonExistentObjectName).AssertOnlyViolations(helper); - should.OnlyHaveAttributes([helper.NonExistentObjectName]).AssertOnlyViolations(helper); - helper.AddSnapshotHeader("Attribute outside of architecture"); should = Types().That().Are(helper.ClassWithSingleAttribute).Should(); should @@ -2977,25 +2437,17 @@ public async Task OnlyHaveAttributesTest() helper.AddSnapshotHeader("Empty arguments"); should = Types().That().Are(helper.ClassWithSingleAttribute).Should(); - should.OnlyHaveAttributes(new List()).AssertOnlyViolations(helper); should.OnlyHaveAttributes(new List()).AssertOnlyViolations(helper); should.OnlyHaveAttributes(new List()).AssertOnlyViolations(helper); should - .OnlyHaveAttributes(Attributes().That().Are(helper.NonExistentObjectName)) + .OnlyHaveAttributes(Attributes().That().HaveFullName(helper.NonExistentObjectName)) .AssertOnlyViolations(helper); should = Types().That().Are(helper.ClassWithoutAttributes).Should(); - should.OnlyHaveAttributes(new List()).AssertNoViolations(helper); should.OnlyHaveAttributes(new List()).AssertNoViolations(helper); should.OnlyHaveAttributes(new List()).AssertNoViolations(helper); - should - .OnlyHaveAttributes(Attributes().That().Are(helper.NonExistentObjectName)) - .AssertNoViolations(helper); helper.AddSnapshotHeader("Multiple arguments"); should = Types().That().Are(helper.ClassWithAttributes).Should(); - should - .OnlyHaveAttributes([helper.Attribute1.FullName, helper.Attribute2.FullName]) - .AssertNoViolations(helper); should.OnlyHaveAttributes(helper.Attribute1, helper.Attribute2).AssertNoViolations(helper); should .OnlyHaveAttributes([helper.Attribute1, helper.Attribute2]) @@ -3015,8 +2467,6 @@ public async Task OnlyHaveAttributesTest() .That() .Are(helper.ClassWithAttributes, helper.OtherClassWithAttributes) .Should(); - should.OnlyHaveAttributes(helper.UnusedAttribute.FullName).AssertOnlyViolations(helper); - should.OnlyHaveAttributes([helper.UnusedAttribute.FullName]).AssertOnlyViolations(helper); should.OnlyHaveAttributes(helper.UnusedAttribute).AssertOnlyViolations(helper); should.OnlyHaveAttributes([helper.UnusedAttribute]).AssertOnlyViolations(helper); should.OnlyHaveAttributes(helper.UnusedAttributeSystemType).AssertOnlyViolations(helper); @@ -3033,13 +2483,13 @@ public async Task OnlyHaveAttributesThatTest() var helper = new AttributeAssemblyTestHelpers(); helper.AddSnapshotHeader("No violations"); var should = Types().That().Are(helper.ClassWithSingleAttribute).Should(); - should.OnlyHaveAttributesThat().Are(helper.Attribute1.FullName).AssertNoViolations(helper); + should.OnlyHaveAttributesThat().Are(helper.Attribute1).AssertNoViolations(helper); helper.AddSnapshotHeader("Violations"); should = Types().That().Are(helper.ClassWithSingleAttribute).Should(); should .OnlyHaveAttributesThat() - .Are(helper.UnusedAttribute.FullName) + .Are(helper.UnusedAttribute) .AssertOnlyViolations(helper); await helper.AssertSnapshotMatches(); } diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/TypeSyntaxElementsTests.cs b/ArchUnitNETTests/Fluent/Syntax/Elements/TypeSyntaxElementsTests.cs index a2bc5db90..8f10f1036 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/TypeSyntaxElementsTests.cs +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/TypeSyntaxElementsTests.cs @@ -165,21 +165,11 @@ public void AssignableToTest() .Are(type) .Should() .BeAssignableTo(type); - var typeIsAssignableToItselfPattern = Types() - .That() - .Are(type) - .Should() - .BeAssignableTo(type.FullName); var typeIsNotAssignableToItself = Types() .That() .Are(type) .Should() .NotBeAssignableTo(type); - var typeIsNotAssignableToItselfPattern = Types() - .That() - .Are(type) - .Should() - .NotBeAssignableTo(type.FullName); var typeIsNotAssignableToFalseType1 = Types() .That() .Are(type) @@ -194,13 +184,6 @@ public void AssignableToTest() .NotBeAssignableTo(StaticTestTypes.PublicTestClass) .OrShould() .Be(typeof(PublicTestClass)); - var typeIsNotAssignableToFalseTypePattern = Types() - .That() - .Are(type) - .Should() - .NotBeAssignableTo(StaticTestTypes.PublicTestClass.FullName) - .OrShould() - .Be(typeof(PublicTestClass)); var typeIsAssignableToFalseType1 = Types() .That() .Are(type) @@ -215,25 +198,13 @@ public void AssignableToTest() .BeAssignableTo(StaticTestTypes.PublicTestClass) .AndShould() .NotBe(typeof(PublicTestClass)); - var typeIsAssignableToFalseTypePattern = Types() - .That() - .Are(type) - .Should() - .BeAssignableTo(StaticTestTypes.PublicTestClass.FullName) - .AndShould() - .NotBe(typeof(PublicTestClass)); Assert.True(typeIsAssignableToItself.HasNoViolations(Architecture)); - Assert.True(typeIsAssignableToItselfPattern.HasNoViolations(Architecture)); Assert.False(typeIsNotAssignableToItself.HasNoViolations(Architecture)); - Assert.False(typeIsNotAssignableToItselfPattern.HasNoViolations(Architecture)); Assert.True(typeIsNotAssignableToFalseType1.HasNoViolations(Architecture)); Assert.True(typeIsNotAssignableToFalseType2.HasNoViolations(Architecture)); - Assert.True(typeIsNotAssignableToFalseTypePattern.HasNoViolations(Architecture)); Assert.False(typeIsAssignableToFalseType1.HasNoViolations(Architecture)); Assert.False(typeIsAssignableToFalseType2.HasNoViolations(Architecture)); - Assert.False(typeIsAssignableToFalseTypePattern.HasNoViolations(Architecture)); - //Multiple Arguments var typeIsAssignableToItselfFluent = Types() @@ -260,13 +231,6 @@ public void AssignableToTest() .NotBeAssignableTo(falseTypeList2) .OrShould() .Be(falseTypeList1); - var typeIsNotAssignableToFalseTypeMultiplePattern = Types() - .That() - .Are(type) - .Should() - .NotBeAssignableTo(falseTypeListPattern) - .OrShould() - .Be(falseTypeList1); var typeIsAssignableToFalseTypeMultiple1 = Types() .That() .Are(type) @@ -281,26 +245,13 @@ public void AssignableToTest() .BeAssignableTo(falseTypeList2) .AndShould() .NotBe(falseTypeList1); - var typeIsAssignableToFalseTypeMultiplePattern = Types() - .That() - .Are(type) - .Should() - .BeAssignableTo(falseTypeListPattern) - .AndShould() - .NotBe(falseTypeList1); Assert.True(typeIsAssignableToItselfFluent.HasNoViolations(Architecture)); Assert.False(typeIsNotAssignableToItselfFluent.HasNoViolations(Architecture)); Assert.True(typeIsNotAssignableToFalseTypeMultiple1.HasNoViolations(Architecture)); Assert.True(typeIsNotAssignableToFalseTypeMultiple2.HasNoViolations(Architecture)); - Assert.True( - typeIsNotAssignableToFalseTypeMultiplePattern.HasNoViolations(Architecture) - ); Assert.False(typeIsAssignableToFalseTypeMultiple1.HasNoViolations(Architecture)); Assert.False(typeIsAssignableToFalseTypeMultiple2.HasNoViolations(Architecture)); - Assert.False( - typeIsAssignableToFalseTypeMultiplePattern.HasNoViolations(Architecture) - ); } } @@ -606,42 +557,42 @@ public void ImplementInterfaceTest() { var typesThatImplementInterfaceImplementInterface = Types() .That() - .ImplementInterface(intf.FullName) + .ImplementInterface(intf) .Should() - .ImplementInterface(intf.FullName) + .ImplementInterface(intf) .WithoutRequiringPositiveResults(); var typesThatImplementInterfaceDoNotImplementInterface = Types() .That() - .ImplementInterface(intf.FullName) + .ImplementInterface(intf) .Should() - .NotImplementInterface(intf.FullName) + .NotImplementInterface(intf) .AndShould() .Exist(); var typesThatDoNotImplementInterfaceImplementInterface = Types() .That() - .DoNotImplementInterface(intf.FullName) + .DoNotImplementInterface(intf) .Should() - .ImplementInterface(intf.FullName) + .ImplementInterface(intf) .AndShould() .Exist(); var typesThatDoNotImplementInterfaceDoNotImplementInterface = Types() .That() - .DoNotImplementInterface(intf.FullName) + .DoNotImplementInterface(intf) .Should() - .NotImplementInterface(intf.FullName); + .NotImplementInterface(intf); var implementInterfaceIsEqualToAssignableTo = Types() .That() - .ImplementInterface(intf.FullName) + .ImplementInterface(intf) .Should() - .BeAssignableTo(intf.FullName) + .BeAssignableTo(intf) .And() .Types() .That() - .AreAssignableTo(intf.FullName) + .AreAssignableTo(intf) .Should() - .ImplementInterface(intf.FullName) + .ImplementInterface(intf) .OrShould() - .Be(intf.FullName); + .Be(intf); Assert.True( typesThatImplementInterfaceImplementInterface.HasNoViolations(Architecture) @@ -664,30 +615,30 @@ public void ImplementInterfaceTest() .That() .Are(StaticTestTypes.InheritedType) .Should() - .ImplementInterface(InheritedTestInterface.FullName); + .ImplementInterface(InheritedTestInterface); var testClassThatImplementsOtherInterfaceImplementsInterfaces = Types() .That() .Are(StaticTestTypes.InheritedType) .Should() - .ImplementInterface(InheritedTestInterface.FullName) + .ImplementInterface(InheritedTestInterface) .AndShould() - .ImplementInterface(InheritingInterface.FullName); + .ImplementInterface(InheritingInterface); var testInterfaceThatImplementsInterfaceImplementsInterface = Interfaces() .That() .Are(InheritingInterface) .Should() - .ImplementInterface(InheritedTestInterface.FullName); + .ImplementInterface(InheritedTestInterface); var testClassThatImplementsNoInterfaceDoesNotImplementInterface = Interfaces() .That() .Are(StaticTestTypes.PublicTestClass) .Should() - .NotImplementInterface(InheritedTestInterface.FullName) + .NotImplementInterface(InheritedTestInterface) .WithoutRequiringPositiveResults(); var testClassThatImplementsNoInterfaceImplementsInterface = Interfaces() .That() .Are(StaticTestTypes.PublicTestClass) .Should() - .ImplementInterface(InheritedTestInterface.FullName) + .ImplementInterface(InheritedTestInterface) .AndShould() .Exist(); diff --git a/ExampleTest/ExampleArchUnitTest.cs b/ExampleTest/ExampleArchUnitTest.cs index 4bdacc97f..0d562b0b1 100644 --- a/ExampleTest/ExampleArchUnitTest.cs +++ b/ExampleTest/ExampleArchUnitTest.cs @@ -35,7 +35,7 @@ public class ExampleArchUnitTest private readonly IObjectProvider ExampleClasses = Classes() .That() - .ImplementInterface("IExampleInterface") + .ImplementInterface(typeof(IExampleInterface)) .As("Example Classes"); private readonly IObjectProvider ForbiddenLayer = Types() @@ -161,3 +161,5 @@ public void ExampleClassesShouldNotCallForbiddenMethods() internal class ExampleClass { } internal class ForbiddenClass { } + +internal interface IExampleInterface { } \ No newline at end of file From 07b8e6f7559b3f864f381a1d145a08b60cfb6ea9 Mon Sep 17 00:00:00 2001 From: Fritz Brandhuber Date: Fri, 7 Feb 2025 17:23:25 +0100 Subject: [PATCH 2/7] Updated outdated test snapshots, since tests for removed string overloads of fluent methods were removed Signed-off-by: Fritz Brandhuber --- .../ObjectsShouldTests.BeTest.verified.txt | 98 ----------- ...bjectsShouldTests.CallAnyTest.verified.txt | 80 --------- ...tsShouldTests.DependOnAnyTest.verified.txt | 120 +++---------- ...ldTests.HaveAnyAttributesTest.verified.txt | 77 --------- ...aveAttributeWithArgumentsTest.verified.txt | 92 ---------- ...veAttributeWithNamedArguments.verified.txt | 160 ------------------ .../ObjectsShouldTests.NotBeTest.verified.txt | 132 +++------------ ...ctsShouldTests.NotCallAnyTest.verified.txt | 86 ---------- ...houldTests.NotDependOnAnyTest.verified.txt | 95 ----------- ...ests.NotHaveAnyAttributesTest.verified.txt | 75 -------- ...aveAttributeWithArgumentsTest.verified.txt | 127 -------------- ...tributeWithNamedArgumentsTest.verified.txt | 121 ------------- ...sShouldTests.OnlyDependOnTest.verified.txt | 80 --------- ...sts.OnlyDependOnTypesThatTest.verified.txt | 6 +- ...dTests.OnlyHaveAttributesTest.verified.txt | 113 ------------- ...ts.OnlyHaveAttributesThatTest.verified.txt | 6 +- 16 files changed, 48 insertions(+), 1420 deletions(-) diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.BeTest.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.BeTest.verified.txt index 3499fd96b..be5d74f70 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.BeTest.verified.txt +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.BeTest.verified.txt @@ -1,29 +1,5 @@ ===== No violations ===== -Query: Types that are "TypeDependencyNamespace.ChildClass" should have full name "TypeDependencyNamespace.ChildClass" -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Message: -All Evaluations passed - -Query: Types that are "TypeDependencyNamespace.ChildClass" should have full name matching "^.*\.ChildClass$" -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Message: -All Evaluations passed - -Query: Types that are "TypeDependencyNamespace.ChildClass" should have full name "TypeDependencyNamespace.ChildClass" -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Message: -All Evaluations passed - -Query: Types that are "TypeDependencyNamespace.ChildClass" should have full name matching "^.*\.ChildClass$" -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Message: -All Evaluations passed - Query: Types that are "TypeDependencyNamespace.ChildClass" should be "TypeDependencyNamespace.ChildClass" Result: True Description: TypeDependencyNamespace.ChildClass passed @@ -56,42 +32,6 @@ All Evaluations passed ===== Violations ===== -Query: Types that are "TypeDependencyNamespace.ChildClass" should have full name "TypeDependencyNamespace.ClassWithoutDependencies" -Result: False -Description: TypeDependencyNamespace.ChildClass does not have full name "TypeDependencyNamespace.ClassWithoutDependencies" -Message: -"Types that are "TypeDependencyNamespace.ChildClass" should have full name "TypeDependencyNamespace.ClassWithoutDependencies"" failed: - TypeDependencyNamespace.ChildClass does not have full name "TypeDependencyNamespace.ClassWithoutDependencies" - - - -Query: Types that are "TypeDependencyNamespace.ChildClass" should have full name matching "^.*\.ClassWithoutDependencies$" -Result: False -Description: TypeDependencyNamespace.ChildClass does not have full name matching "^.*\.ClassWithoutDependencies$" -Message: -"Types that are "TypeDependencyNamespace.ChildClass" should have full name matching "^.*\.ClassWithoutDependencies$"" failed: - TypeDependencyNamespace.ChildClass does not have full name matching "^.*\.ClassWithoutDependencies$" - - - -Query: Types that are "TypeDependencyNamespace.ChildClass" should have full name "TypeDependencyNamespace.ClassWithoutDependencies" -Result: False -Description: TypeDependencyNamespace.ChildClass does not have full name "TypeDependencyNamespace.ClassWithoutDependencies" -Message: -"Types that are "TypeDependencyNamespace.ChildClass" should have full name "TypeDependencyNamespace.ClassWithoutDependencies"" failed: - TypeDependencyNamespace.ChildClass does not have full name "TypeDependencyNamespace.ClassWithoutDependencies" - - - -Query: Types that are "TypeDependencyNamespace.ChildClass" should have full name matching "^.*\.ClassWithoutDependencies$" -Result: False -Description: TypeDependencyNamespace.ChildClass does not have full name matching "^.*\.ClassWithoutDependencies$" -Message: -"Types that are "TypeDependencyNamespace.ChildClass" should have full name matching "^.*\.ClassWithoutDependencies$"" failed: - TypeDependencyNamespace.ChildClass does not have full name matching "^.*\.ClassWithoutDependencies$" - - - Query: Types that are "TypeDependencyNamespace.ChildClass" should be "TypeDependencyNamespace.ClassWithoutDependencies" Result: False Description: TypeDependencyNamespace.ChildClass is not "TypeDependencyNamespace.ClassWithoutDependencies" @@ -137,26 +77,6 @@ Message: -===== Non-existent type ===== - -Query: Types that are "TypeDependencyNamespace.BaseClass" should have full name "NotTheNameOfAnyObject" -Result: False -Description: TypeDependencyNamespace.BaseClass does not have full name "NotTheNameOfAnyObject" -Message: -"Types that are "TypeDependencyNamespace.BaseClass" should have full name "NotTheNameOfAnyObject"" failed: - TypeDependencyNamespace.BaseClass does not have full name "NotTheNameOfAnyObject" - - - -Query: Types that are "TypeDependencyNamespace.BaseClass" should have full name "NotTheNameOfAnyObject" -Result: False -Description: TypeDependencyNamespace.BaseClass does not have full name "NotTheNameOfAnyObject" -Message: -"Types that are "TypeDependencyNamespace.BaseClass" should have full name "NotTheNameOfAnyObject"" failed: - TypeDependencyNamespace.BaseClass does not have full name "NotTheNameOfAnyObject" - - - ===== Empty arguments ===== Query: Types that are "TypeDependencyNamespace.BaseClass" should not exist @@ -168,15 +88,6 @@ Message: -Query: Types that are "TypeDependencyNamespace.BaseClass" should not exist -Result: False -Description: TypeDependencyNamespace.BaseClass does exist -Message: -"Types that are "TypeDependencyNamespace.BaseClass" should not exist" failed: - TypeDependencyNamespace.BaseClass does exist - - - Query: Types that are "TypeDependencyNamespace.BaseClass" should not exist Result: False Description: TypeDependencyNamespace.BaseClass is TypeDependencyNamespace.BaseClass @@ -197,15 +108,6 @@ Message: ===== Multiple arguments ===== -Query: Types that are "TypeDependencyNamespace.ChildClass" should have full name "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" -Result: False -Description: TypeDependencyNamespace.ChildClass does not have full name "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" -Message: -"Types that are "TypeDependencyNamespace.ChildClass" should have full name "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass"" failed: - TypeDependencyNamespace.ChildClass does not have full name "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" - - - Query: Types that are "TypeDependencyNamespace.ChildClass" should be "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" Result: False Description: TypeDependencyNamespace.ChildClass is not "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.CallAnyTest.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.CallAnyTest.verified.txt index 3470ce9af..7befa3ffe 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.CallAnyTest.verified.txt +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.CallAnyTest.verified.txt @@ -1,29 +1,5 @@ ===== No violations ===== -Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should calls any method with full name "System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod()" -Result: True -Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() passed -Message: -All Evaluations passed - -Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should calls any method with full name matching "^.*::CalledMethod\(\)$" -Result: True -Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() passed -Message: -All Evaluations passed - -Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should calls any method with full name "System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod()" -Result: True -Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() passed -Message: -All Evaluations passed - -Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should calls any method with full name matching "^.*::CalledMethod\(\)$" -Result: True -Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() passed -Message: -All Evaluations passed - Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should call "System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod()" Result: True Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() passed @@ -44,24 +20,6 @@ All Evaluations passed ===== Violations ===== -Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should calls any method with full name "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithoutDependencies()" -Result: False -Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() does not call any method with full name "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithoutDependencies()" -Message: -"Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should calls any method with full name "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithoutDependencies()"" failed: - System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() does not call any method with full name "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithoutDependencies()" - - - -Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should calls any method with full name "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithoutDependencies()" -Result: False -Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() does not call any methods with full name "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithoutDependencies()" -Message: -"Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should calls any method with full name "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithoutDependencies()"" failed: - System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() does not call any methods with full name "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithoutDependencies()" - - - Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should call "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithoutDependencies()" Result: False Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() does call System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod() @@ -89,37 +47,8 @@ Message: -===== Non-existent method member ===== - -Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should calls any method with full name "NotTheNameOfAnyObject" -Result: False -Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() does not call any method with full name "NotTheNameOfAnyObject" -Message: -"Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should calls any method with full name "NotTheNameOfAnyObject"" failed: - System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() does not call any method with full name "NotTheNameOfAnyObject" - - - -Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should calls any method with full name "NotTheNameOfAnyObject" -Result: False -Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() does not call any methods with full name "NotTheNameOfAnyObject" -Message: -"Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should calls any method with full name "NotTheNameOfAnyObject"" failed: - System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() does not call any methods with full name "NotTheNameOfAnyObject" - - - ===== Empty arguments ===== -Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should call one of no methods (impossible) -Result: False -Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() does not call one of no methods (always true) -Message: -"Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should call one of no methods (impossible)" failed: - System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() does not call one of no methods (always true) - - - Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should call one of no methods (impossible) Result: False Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() does call System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod() @@ -140,15 +69,6 @@ Message: ===== Multiple arguments ===== -Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithMultipleDependencies()" should calls any method with full name "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithoutDependencies()" or "System.Void MethodDe... -Result: False -Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithMultipleDependencies() does not call any methods with full name "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithoutDependencies()" or "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithMultipleDependencies()" -Message: -"Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithMultipleDependencies()" should calls any method with full name "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithoutDependencies()" or "System.Void MethodDe..." failed: - System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithMultipleDependencies() does not call any methods with full name "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithoutDependencies()" or "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithMultipleDependencies()" - - - Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithMultipleDependencies()" should call "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithoutDependencies()" or "System.Void MethodDependencyNamespace.MethodDep... Result: False Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithMultipleDependencies() does call System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod1() and System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod2() and System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod3() diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.DependOnAnyTest.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.DependOnAnyTest.verified.txt index 129c319bf..7b4463556 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.DependOnAnyTest.verified.txt +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.DependOnAnyTest.verified.txt @@ -1,29 +1,5 @@ ===== No violations ===== -Query: Types that are "TypeDependencyNamespace.ChildClass" should depend on any types with full name "TypeDependencyNamespace.BaseClass" -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Message: -All Evaluations passed - -Query: Types that are "TypeDependencyNamespace.ChildClass" should depend on any types with full name matching "^.*\.BaseClass$" -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Message: -All Evaluations passed - -Query: Types that are "TypeDependencyNamespace.ChildClass" should depend on any types with full name "TypeDependencyNamespace.BaseClass" -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Message: -All Evaluations passed - -Query: Types that are "TypeDependencyNamespace.ChildClass" should depend on any types with full name matching "^.*\.BaseClass$" -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Message: -All Evaluations passed - Query: Types that are "TypeDependencyNamespace.ChildClass" should depend on "TypeDependencyNamespace.BaseClass" Result: True Description: TypeDependencyNamespace.ChildClass passed @@ -56,24 +32,6 @@ All Evaluations passed ===== Violations ===== -Query: Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on any types with full name "TypeDependencyNamespace.ClassWithoutDependencies" -Result: False -Description: TypeDependencyNamespace.ClassWithMultipleDependencies does not depend on any type with full name "TypeDependencyNamespace.ClassWithoutDependencies" -Message: -"Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on any types with full name "TypeDependencyNamespace.ClassWithoutDependencies"" failed: - TypeDependencyNamespace.ClassWithMultipleDependencies does not depend on any type with full name "TypeDependencyNamespace.ClassWithoutDependencies" - - - -Query: Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on any types with full name "TypeDependencyNamespace.ClassWithoutDependencies" -Result: False -Description: TypeDependencyNamespace.ClassWithMultipleDependencies does not depend any types with full name "TypeDependencyNamespace.ClassWithoutDependencies" -Message: -"Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on any types with full name "TypeDependencyNamespace.ClassWithoutDependencies"" failed: - TypeDependencyNamespace.ClassWithMultipleDependencies does not depend any types with full name "TypeDependencyNamespace.ClassWithoutDependencies" - - - Query: Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on "TypeDependencyNamespace.ClassWithoutDependencies" Result: False Description: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass @@ -119,130 +77,92 @@ Message: -===== Non-existent type ===== - -Query: Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on any types with full name "NotTheNameOfAnyObject" -Result: False -Description: TypeDependencyNamespace.ClassWithMultipleDependencies does not depend on any type with full name "NotTheNameOfAnyObject" -Message: -"Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on any types with full name "NotTheNameOfAnyObject"" failed: - TypeDependencyNamespace.ClassWithMultipleDependencies does not depend on any type with full name "NotTheNameOfAnyObject" - - - -Query: Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on any types with full name "NotTheNameOfAnyObject" -Result: False -Description: TypeDependencyNamespace.ClassWithMultipleDependencies does not depend any types with full name "NotTheNameOfAnyObject" -Message: -"Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on any types with full name "NotTheNameOfAnyObject"" failed: - TypeDependencyNamespace.ClassWithMultipleDependencies does not depend any types with full name "NotTheNameOfAnyObject" - - - ===== Type outside of architecture ===== -Query: Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on "AttributeNamespace.ClassWithoutAttributes" +Query: Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on "AttributeNamespace.ClassWithoutAttributes" Result: False Description: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass Message: -"Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on "AttributeNamespace.ClassWithoutAttributes"" failed: +"Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on "AttributeNamespace.ClassWithoutAttributes"" failed: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass ===== Empty arguments ===== -Query: Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on one of no types (impossible) -Result: False -Description: TypeDependencyNamespace.ClassWithMultipleDependencies does not depend on no types (always true) -Message: -"Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on one of no types (impossible)" failed: - TypeDependencyNamespace.ClassWithMultipleDependencies does not depend on no types (always true) - - - -Query: Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on one of no types (impossible) +Query: Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on one of no types (impossible) Result: False Description: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass Message: -"Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on one of no types (impossible)" failed: +"Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on one of no types (impossible)" failed: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass -Query: Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on one of no types (impossible) +Query: Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on one of no types (impossible) Result: False Description: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass Message: -"Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on one of no types (impossible)" failed: +"Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on one of no types (impossible)" failed: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass -Query: Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on any Classes that have full name "NotTheNameOfAnyObject" +Query: Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on any Classes that have full name "NotTheNameOfAnyObject" Result: False Description: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass Message: -"Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on any Classes that have full name "NotTheNameOfAnyObject"" failed: +"Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on any Classes that have full name "NotTheNameOfAnyObject"" failed: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass ===== Multiple arguments ===== -Query: Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on any types with full name "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" -Result: False -Description: TypeDependencyNamespace.ClassWithMultipleDependencies does not depend any types with full name "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" -Message: -"Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on any types with full name "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass"" failed: - TypeDependencyNamespace.ClassWithMultipleDependencies does not depend any types with full name "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" - - - -Query: Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" +Query: Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" Result: False Description: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass Message: -"Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass"" failed: +"Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass"" failed: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass -Query: Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" +Query: Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" Result: False Description: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass Message: -"Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass"" failed: +"Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass"" failed: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass -Query: Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" +Query: Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" Result: False Description: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass Message: -"Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass"" failed: +"Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass"" failed: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass -Query: Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" +Query: Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" Result: False Description: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass Message: -"Types that have full name "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass"" failed: +"Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should depend on "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass"" failed: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass ===== Input without dependencies ===== -Query: Types that are "TypeDependencyNamespace.ClassWithoutDependencies" should depend on any types with full name "TypeDependencyNamespace.BaseClass" or "TypeDependencyNamespace.ChildClass" +Query: Types that are "TypeDependencyNamespace.ClassWithoutDependencies" should depend on "TypeDependencyNamespace.BaseClass" or "TypeDependencyNamespace.ChildClass" Result: False -Description: TypeDependencyNamespace.ClassWithoutDependencies does not depend any types with full name "TypeDependencyNamespace.BaseClass" or "TypeDependencyNamespace.ChildClass" +Description: TypeDependencyNamespace.ClassWithoutDependencies does depend on System.Object Message: -"Types that are "TypeDependencyNamespace.ClassWithoutDependencies" should depend on any types with full name "TypeDependencyNamespace.BaseClass" or "TypeDependencyNamespace.ChildClass"" failed: - TypeDependencyNamespace.ClassWithoutDependencies does not depend any types with full name "TypeDependencyNamespace.BaseClass" or "TypeDependencyNamespace.ChildClass" +"Types that are "TypeDependencyNamespace.ClassWithoutDependencies" should depend on "TypeDependencyNamespace.BaseClass" or "TypeDependencyNamespace.ChildClass"" failed: + TypeDependencyNamespace.ClassWithoutDependencies does depend on System.Object diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.HaveAnyAttributesTest.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.HaveAnyAttributesTest.verified.txt index a8a00b944..b41d686f8 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.HaveAnyAttributesTest.verified.txt +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.HaveAnyAttributesTest.verified.txt @@ -1,29 +1,5 @@ ===== No violations ===== -Query: Types that are "AttributeNamespace.ClassWithAttributes" should have any attribute with full name "AttributeNamespace.Attribute1" -Result: True -Description: AttributeNamespace.ClassWithAttributes passed -Message: -All Evaluations passed - -Query: Types that are "AttributeNamespace.ClassWithAttributes" should have any attribute with full name matching "^.*\.Attribute1$" -Result: True -Description: AttributeNamespace.ClassWithAttributes passed -Message: -All Evaluations passed - -Query: Types that are "AttributeNamespace.ClassWithAttributes" should have any attribute with full name "AttributeNamespace.Attribute1" -Result: True -Description: AttributeNamespace.ClassWithAttributes passed -Message: -All Evaluations passed - -Query: Types that are "AttributeNamespace.ClassWithAttributes" should have any attribute with full name matching "^.*\.Attribute1$" -Result: True -Description: AttributeNamespace.ClassWithAttributes passed -Message: -All Evaluations passed - Query: Types that are "AttributeNamespace.ClassWithAttributes" should have attribute "AttributeNamespace.Attribute1" Result: True Description: AttributeNamespace.ClassWithAttributes passed @@ -56,24 +32,6 @@ All Evaluations passed ===== Violations ===== -Query: Types that are "AttributeNamespace.ClassWithAttributes" should have any attribute with full name "AttributeNamespace.UnusedAttribute" -Result: False -Description: AttributeNamespace.ClassWithAttributes does not have any attribute with full name "AttributeNamespace.UnusedAttribute" -Message: -"Types that are "AttributeNamespace.ClassWithAttributes" should have any attribute with full name "AttributeNamespace.UnusedAttribute"" failed: - AttributeNamespace.ClassWithAttributes does not have any attribute with full name "AttributeNamespace.UnusedAttribute" - - - -Query: Types that are "AttributeNamespace.ClassWithAttributes" should have any attribute with full name "AttributeNamespace.UnusedAttribute" -Result: False -Description: AttributeNamespace.ClassWithAttributes does not have any attribute with full name "AttributeNamespace.UnusedAttribute" -Message: -"Types that are "AttributeNamespace.ClassWithAttributes" should have any attribute with full name "AttributeNamespace.UnusedAttribute"" failed: - AttributeNamespace.ClassWithAttributes does not have any attribute with full name "AttributeNamespace.UnusedAttribute" - - - Query: Types that are "AttributeNamespace.ClassWithAttributes" should have attribute "AttributeNamespace.UnusedAttribute" Result: False Description: AttributeNamespace.ClassWithAttributes does not have attribute "AttributeNamespace.UnusedAttribute" @@ -119,26 +77,6 @@ Message: -===== Non-existent attribute ===== - -Query: Types that are "AttributeNamespace.ClassWithAttributes" should have any attribute with full name "NotTheNameOfAnyObject" -Result: False -Description: AttributeNamespace.ClassWithAttributes does not have any attribute with full name "NotTheNameOfAnyObject" -Message: -"Types that are "AttributeNamespace.ClassWithAttributes" should have any attribute with full name "NotTheNameOfAnyObject"" failed: - AttributeNamespace.ClassWithAttributes does not have any attribute with full name "NotTheNameOfAnyObject" - - - -Query: Types that are "AttributeNamespace.ClassWithAttributes" should have any attribute with full name "NotTheNameOfAnyObject" -Result: False -Description: AttributeNamespace.ClassWithAttributes does not have any attribute with full name "NotTheNameOfAnyObject" -Message: -"Types that are "AttributeNamespace.ClassWithAttributes" should have any attribute with full name "NotTheNameOfAnyObject"" failed: - AttributeNamespace.ClassWithAttributes does not have any attribute with full name "NotTheNameOfAnyObject" - - - ===== Empty arguments ===== Query: Types that are "AttributeNamespace.ClassWithAttributes" should have one of no attributes (impossible) @@ -159,15 +97,6 @@ Message: -Query: Types that are "AttributeNamespace.ClassWithAttributes" should have one of no attributes (impossible) -Result: False -Description: AttributeNamespace.ClassWithAttributes does not have one of no attributes (always true) -Message: -"Types that are "AttributeNamespace.ClassWithAttributes" should have one of no attributes (impossible)" failed: - AttributeNamespace.ClassWithAttributes does not have one of no attributes (always true) - - - Query: Types that are "AttributeNamespace.ClassWithAttributes" should have any Attributes that have full name "NotTheNameOfAnyObject" Result: False Description: AttributeNamespace.ClassWithAttributes does not have any Attributes that have full name "NotTheNameOfAnyObject" @@ -179,12 +108,6 @@ Message: ===== Multiple arguments ===== -Query: Types that are "AttributeNamespace.ClassWithAttributes" should have any attribute with full name "AttributeNamespace.Attribute1" or "AttributeNamespace.UnusedAttribute" -Result: True -Description: AttributeNamespace.ClassWithAttributes passed -Message: -All Evaluations passed - Query: Types that are "AttributeNamespace.ClassWithAttributes" should have attribute "AttributeNamespace.Attribute1" or "AttributeNamespace.UnusedAttribute" Result: True Description: AttributeNamespace.ClassWithAttributes passed diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.HaveAttributeWithArgumentsTest.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.HaveAttributeWithArgumentsTest.verified.txt index fe6f034af..fc6d2b161 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.HaveAttributeWithArgumentsTest.verified.txt +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.HaveAttributeWithArgumentsTest.verified.txt @@ -24,18 +24,6 @@ Description: AttributeNamespace.ClassWithArguments passed Message: All Evaluations passed -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.TypeArgument" -Result: True -Description: AttributeNamespace.ClassWithArguments passed -Message: -All Evaluations passed - -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.TypeArgument" -Result: True -Description: AttributeNamespace.ClassWithArguments passed -Message: -All Evaluations passed - ===== No violations with value arguments ===== Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with arguments "Argument" @@ -62,18 +50,6 @@ Description: AttributeNamespace.ClassWithArguments passed Message: All Evaluations passed -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with arguments "Argument" -Result: True -Description: AttributeNamespace.ClassWithArguments passed -Message: -All Evaluations passed - -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with arguments "Argument" -Result: True -Description: AttributeNamespace.ClassWithArguments passed -Message: -All Evaluations passed - ===== Violations with type arguments ===== Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.OtherTypeArgument" @@ -112,24 +88,6 @@ Message: -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.OtherTypeArgument" -Result: False -Description: AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.OtherTypeArgument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.OtherTypeArgument"" failed: - AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.OtherTypeArgument" - - - -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.OtherTypeArgument" -Result: False -Description: AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.OtherTypeArgument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.OtherTypeArgument"" failed: - AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.OtherTypeArgument" - - - ===== Violations with value arguments ===== Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with arguments "OtherArgument" @@ -168,35 +126,6 @@ Message: -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with arguments "OtherArgument" -Result: False -Description: AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with arguments "OtherArgument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with arguments "OtherArgument"" failed: - AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with arguments "OtherArgument" - - - -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with arguments "OtherArgument" -Result: False -Description: AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with arguments "OtherArgument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with arguments "OtherArgument"" failed: - AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with arguments "OtherArgument" - - - -===== Non-existent attribute ===== - -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "NotTheNameOfAnyObject" with arguments "Argument" -Result: False -Description: AttributeNamespace.ClassWithArguments does not have attribute "NotTheNameOfAnyObject" with arguments "Argument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should have attribute "NotTheNameOfAnyObject" with arguments "Argument"" failed: - AttributeNamespace.ClassWithArguments does not have attribute "NotTheNameOfAnyObject" with arguments "Argument" - - - ===== Type outside of architecture ===== Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "TypeDependencyNamespace.BaseClass" with arguments "Argument" @@ -228,15 +157,6 @@ Message: -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with arguments "" -Result: False -Description: AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with arguments "" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with arguments """ failed: - AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with arguments "" - - - ===== Empty arguments ===== Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" @@ -251,12 +171,6 @@ Description: AttributeNamespace.ClassWithArguments passed Message: All Evaluations passed -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" -Result: True -Description: AttributeNamespace.ClassWithArguments passed -Message: -All Evaluations passed - ===== Multiple arguments ===== Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with arguments "Argument" and "0" @@ -283,12 +197,6 @@ Description: AttributeNamespace.ClassWithArguments passed Message: All Evaluations passed -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with arguments "Argument" and "0" -Result: True -Description: AttributeNamespace.ClassWithArguments passed -Message: -All Evaluations passed - ===== Multiple inputs ===== Query: Types that are "AttributeNamespace.ClassWithArguments" or "AttributeNamespace.OtherClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with arguments "Argument" diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.HaveAttributeWithNamedArguments.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.HaveAttributeWithNamedArguments.verified.txt index d3befb95c..4c6f0dbda 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.HaveAttributeWithNamedArguments.verified.txt +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.HaveAttributeWithNamedArguments.verified.txt @@ -24,18 +24,6 @@ Description: AttributeNamespace.ClassWithArguments passed Message: All Evaluations passed -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" -Result: True -Description: AttributeNamespace.ClassWithArguments passed -Message: -All Evaluations passed - -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" -Result: True -Description: AttributeNamespace.ClassWithArguments passed -Message: -All Evaluations passed - ===== No violations with value arguments ===== Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter2=NamedArgument" @@ -62,18 +50,6 @@ Description: AttributeNamespace.ClassWithArguments passed Message: All Evaluations passed -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter2=NamedArgument" -Result: True -Description: AttributeNamespace.ClassWithArguments passed -Message: -All Evaluations passed - -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter2=NamedArgument" -Result: True -Description: AttributeNamespace.ClassWithArguments passed -Message: -All Evaluations passed - ===== Violations with type arguments ===== Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "OtherNamedParameter1=AttributeNamespace.NamedTypeArgument" @@ -112,42 +88,6 @@ Message: -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "OtherNamedParameter1=AttributeNamespace.NamedTypeArgument" -Result: False -Description: AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with named arguments "OtherNamedParameter1=AttributeNamespace.NamedTypeArgument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "OtherNamedParameter1=AttributeNamespace.NamedTypeArgument"" failed: - AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with named arguments "OtherNamedParameter1=AttributeNamespace.NamedTypeArgument" - - - -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "OtherNamedParameter1=AttributeNamespace.NamedTypeArgument" -Result: False -Description: AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with named arguments "OtherNamedParameter1=AttributeNamespace.NamedTypeArgument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "OtherNamedParameter1=AttributeNamespace.NamedTypeArgument"" failed: - AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with named arguments "OtherNamedParameter1=AttributeNamespace.NamedTypeArgument" - - - -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.OtherNamedTypeArgument" -Result: False -Description: AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.OtherNamedTypeArgument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.OtherNamedTypeArgument"" failed: - AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.OtherNamedTypeArgument" - - - -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.OtherNamedTypeArgument" -Result: False -Description: AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.OtherNamedTypeArgument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.OtherNamedTypeArgument"" failed: - AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.OtherNamedTypeArgument" - - - Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.OtherNamedTypeArgument" Result: False Description: AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.OtherNamedTypeArgument" @@ -222,42 +162,6 @@ Message: -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "OtherNamedParameter2=NamedArgument" -Result: False -Description: AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with named arguments "OtherNamedParameter2=NamedArgument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "OtherNamedParameter2=NamedArgument"" failed: - AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with named arguments "OtherNamedParameter2=NamedArgument" - - - -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "OtherNamedParameter2=NamedArgument" -Result: False -Description: AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with named arguments "OtherNamedParameter2=NamedArgument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "OtherNamedParameter2=NamedArgument"" failed: - AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with named arguments "OtherNamedParameter2=NamedArgument" - - - -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter2=OtherNamedArgument" -Result: False -Description: AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter2=OtherNamedArgument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter2=OtherNamedArgument"" failed: - AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter2=OtherNamedArgument" - - - -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter2=OtherNamedArgument" -Result: False -Description: AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter2=OtherNamedArgument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter2=OtherNamedArgument"" failed: - AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter2=OtherNamedArgument" - - - Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter2=OtherNamedArgument" Result: False Description: AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter2=OtherNamedArgument" @@ -332,24 +236,6 @@ Message: -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.UnusedAttribute" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" -Result: False -Description: AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.UnusedAttribute" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.UnusedAttribute" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument"" failed: - AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.UnusedAttribute" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" - - - -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.UnusedAttribute" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" -Result: False -Description: AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.UnusedAttribute" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.UnusedAttribute" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument"" failed: - AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.UnusedAttribute" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" - - - ===== Type outside of architecture ===== Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "TypeDependencyNamespace.BaseClass" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" @@ -375,12 +261,6 @@ Description: AttributeNamespace.ClassWithArguments passed Message: All Evaluations passed -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" -Result: True -Description: AttributeNamespace.ClassWithArguments passed -Message: -All Evaluations passed - ===== Multiple arguments ===== Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" and "OtherNamedParameter... @@ -419,24 +299,6 @@ Message: -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" and "OtherNamedParameter... -Result: False -Description: AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" and "OtherNamedParameter2=3" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" and "OtherNamedParameter..." failed: - AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" and "OtherNamedParameter2=3" - - - -Query: Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" and "OtherNamedParameter... -Result: False -Description: AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" and "OtherNamedParameter2=3" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" and "OtherNamedParameter..." failed: - AttributeNamespace.ClassWithArguments does not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" and "OtherNamedParameter2=3" - - - ===== Multiple inputs ===== Query: Types that are "AttributeNamespace.ClassWithArguments" or "AttributeNamespace.ClassWithAttributes" should have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" @@ -483,25 +345,3 @@ Message: -Query: Types that are "AttributeNamespace.ClassWithArguments" or "AttributeNamespace.ClassWithAttributes" should have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" -Result: False -Description: AttributeNamespace.ClassWithAttributes does not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" -Result: True -Description: AttributeNamespace.ClassWithArguments passed -Message: -"Types that are "AttributeNamespace.ClassWithArguments" or "AttributeNamespace.ClassWithAttributes" should have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument"" failed: - AttributeNamespace.ClassWithAttributes does not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" - - - -Query: Types that are "AttributeNamespace.ClassWithArguments" or "AttributeNamespace.ClassWithAttributes" should have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" -Result: False -Description: AttributeNamespace.ClassWithAttributes does not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" -Result: True -Description: AttributeNamespace.ClassWithArguments passed -Message: -"Types that are "AttributeNamespace.ClassWithArguments" or "AttributeNamespace.ClassWithAttributes" should have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument"" failed: - AttributeNamespace.ClassWithAttributes does not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" - - - diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.NotBeTest.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.NotBeTest.verified.txt index 50ece354b..ab6d20fdd 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.NotBeTest.verified.txt +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.NotBeTest.verified.txt @@ -1,6 +1,6 @@ ===== No violations ===== -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not have full name "TypeDependencyNamespace.ClassWithoutDependencies" +Query: Types that depend on "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ClassWithoutDependencies" Result: True Description: TypeDependencyNamespace.ChildClass passed Result: True @@ -8,7 +8,7 @@ Description: TypeDependencyNamespace.OtherChildClass passed Message: All Evaluations passed -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not have full name matching "^.*\.ClassWithoutDependencies$" +Query: Types that depend on "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ClassWithoutDependencies" Result: True Description: TypeDependencyNamespace.ChildClass passed Result: True @@ -16,7 +16,7 @@ Description: TypeDependencyNamespace.OtherChildClass passed Message: All Evaluations passed -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not have full name "TypeDependencyNamespace.ClassWithoutDependencies" +Query: Types that depend on "TypeDependencyNamespace.BaseClass" should not be Classes that are "TypeDependencyNamespace.ClassWithoutDependencies" Result: True Description: TypeDependencyNamespace.ChildClass passed Result: True @@ -24,7 +24,7 @@ Description: TypeDependencyNamespace.OtherChildClass passed Message: All Evaluations passed -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not have full name matching "^.*\.ClassWithoutDependencies$" +Query: Types that depend on "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ClassWithoutDependencies" Result: True Description: TypeDependencyNamespace.ChildClass passed Result: True @@ -32,39 +32,7 @@ Description: TypeDependencyNamespace.OtherChildClass passed Message: All Evaluations passed -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ClassWithoutDependencies" -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Result: True -Description: TypeDependencyNamespace.OtherChildClass passed -Message: -All Evaluations passed - -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ClassWithoutDependencies" -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Result: True -Description: TypeDependencyNamespace.OtherChildClass passed -Message: -All Evaluations passed - -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not be Classes that are "TypeDependencyNamespace.ClassWithoutDependencies" -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Result: True -Description: TypeDependencyNamespace.OtherChildClass passed -Message: -All Evaluations passed - -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ClassWithoutDependencies" -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Result: True -Description: TypeDependencyNamespace.OtherChildClass passed -Message: -All Evaluations passed - -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ClassWithoutDependencies" +Query: Types that depend on "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ClassWithoutDependencies" Result: True Description: TypeDependencyNamespace.ChildClass passed Result: True @@ -74,112 +42,64 @@ All Evaluations passed ===== Violations ===== -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not have full name "TypeDependencyNamespace.ChildClass" +Query: Types that depend on "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ChildClass" Result: False Description: TypeDependencyNamespace.ChildClass is TypeDependencyNamespace.ChildClass Result: True Description: TypeDependencyNamespace.OtherChildClass passed Message: -"Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not have full name "TypeDependencyNamespace.ChildClass"" failed: +"Types that depend on "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ChildClass"" failed: TypeDependencyNamespace.ChildClass is TypeDependencyNamespace.ChildClass -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not have full name "TypeDependencyNamespace.ChildClass" +Query: Types that depend on "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ChildClass" Result: False Description: TypeDependencyNamespace.ChildClass is TypeDependencyNamespace.ChildClass Result: True Description: TypeDependencyNamespace.OtherChildClass passed Message: -"Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not have full name "TypeDependencyNamespace.ChildClass"" failed: +"Types that depend on "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ChildClass"" failed: TypeDependencyNamespace.ChildClass is TypeDependencyNamespace.ChildClass -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ChildClass" -Result: False -Description: TypeDependencyNamespace.ChildClass is TypeDependencyNamespace.ChildClass -Result: True -Description: TypeDependencyNamespace.OtherChildClass passed -Message: -"Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ChildClass"" failed: - TypeDependencyNamespace.ChildClass is TypeDependencyNamespace.ChildClass - - - -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ChildClass" -Result: False -Description: TypeDependencyNamespace.ChildClass is TypeDependencyNamespace.ChildClass -Result: True -Description: TypeDependencyNamespace.OtherChildClass passed -Message: -"Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ChildClass"" failed: - TypeDependencyNamespace.ChildClass is TypeDependencyNamespace.ChildClass - - - -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not be Classes that are "TypeDependencyNamespace.ChildClass" +Query: Types that depend on "TypeDependencyNamespace.BaseClass" should not be Classes that are "TypeDependencyNamespace.ChildClass" Result: False Description: TypeDependencyNamespace.ChildClass is Classes that are "TypeDependencyNamespace.ChildClass" Result: True Description: TypeDependencyNamespace.OtherChildClass passed Message: -"Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not be Classes that are "TypeDependencyNamespace.ChildClass"" failed: +"Types that depend on "TypeDependencyNamespace.BaseClass" should not be Classes that are "TypeDependencyNamespace.ChildClass"" failed: TypeDependencyNamespace.ChildClass is Classes that are "TypeDependencyNamespace.ChildClass" -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ChildClass" +Query: Types that depend on "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ChildClass" Result: False Description: TypeDependencyNamespace.ChildClass is TypeDependencyNamespace.ChildClass Result: True Description: TypeDependencyNamespace.OtherChildClass passed Message: -"Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ChildClass"" failed: +"Types that depend on "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ChildClass"" failed: TypeDependencyNamespace.ChildClass is TypeDependencyNamespace.ChildClass -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ChildClass" +Query: Types that depend on "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ChildClass" Result: False Description: TypeDependencyNamespace.ChildClass is TypeDependencyNamespace.ChildClass Result: True Description: TypeDependencyNamespace.OtherChildClass passed Message: -"Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ChildClass"" failed: +"Types that depend on "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ChildClass"" failed: TypeDependencyNamespace.ChildClass is TypeDependencyNamespace.ChildClass -===== Non-existent type ===== - -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not have full name "NotTheNameOfAnyObject" -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Result: True -Description: TypeDependencyNamespace.OtherChildClass passed -Message: -All Evaluations passed - -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not have full name "NotTheNameOfAnyObject" -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Result: True -Description: TypeDependencyNamespace.OtherChildClass passed -Message: -All Evaluations passed - ===== Empty arguments ===== -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should exist -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Result: True -Description: TypeDependencyNamespace.OtherChildClass passed -Message: -All Evaluations passed - -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should exist +Query: Types that depend on "TypeDependencyNamespace.BaseClass" should exist Result: True Description: TypeDependencyNamespace.ChildClass passed Result: True @@ -187,7 +107,7 @@ Description: TypeDependencyNamespace.OtherChildClass passed Message: All Evaluations passed -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not be no type (always true) +Query: Types that depend on "TypeDependencyNamespace.BaseClass" should not be no type (always true) Result: True Description: TypeDependencyNamespace.ChildClass passed Result: True @@ -195,7 +115,7 @@ Description: TypeDependencyNamespace.OtherChildClass passed Message: All Evaluations passed -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not be Classes that have full name "NotTheNameOfAnyObject" +Query: Types that depend on "TypeDependencyNamespace.BaseClass" should not be Classes that have full name "NotTheNameOfAnyObject" Result: True Description: TypeDependencyNamespace.ChildClass passed Result: True @@ -205,15 +125,7 @@ All Evaluations passed ===== Multiple arguments ===== -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not have full name "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Result: True -Description: TypeDependencyNamespace.OtherChildClass passed -Message: -All Evaluations passed - -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" +Query: Types that depend on "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" Result: True Description: TypeDependencyNamespace.ChildClass passed Result: True @@ -221,7 +133,7 @@ Description: TypeDependencyNamespace.OtherChildClass passed Message: All Evaluations passed -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" +Query: Types that depend on "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" Result: True Description: TypeDependencyNamespace.ChildClass passed Result: True @@ -229,7 +141,7 @@ Description: TypeDependencyNamespace.OtherChildClass passed Message: All Evaluations passed -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" +Query: Types that depend on "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" Result: True Description: TypeDependencyNamespace.ChildClass passed Result: True @@ -237,7 +149,7 @@ Description: TypeDependencyNamespace.OtherChildClass passed Message: All Evaluations passed -Query: Types that depend on any types with full name "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" +Query: Types that depend on "TypeDependencyNamespace.BaseClass" should not be "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" Result: True Description: TypeDependencyNamespace.ChildClass passed Result: True diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.NotCallAnyTest.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.NotCallAnyTest.verified.txt index 61e80e420..c75d45b68 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.NotCallAnyTest.verified.txt +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.NotCallAnyTest.verified.txt @@ -1,29 +1,5 @@ ===== No violations ===== -Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should not call any method with full name "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithoutDependencies()" -Result: True -Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() passed -Message: -All Evaluations passed - -Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should not call any method with full name matching "^.*\.MethodWithoutDependencies$" -Result: True -Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() passed -Message: -All Evaluations passed - -Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should not call methods with full name "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithoutDependencies()" -Result: True -Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() passed -Message: -All Evaluations passed - -Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should not call any method with full name matching "^.*\.MethodWithoutDependencies$" -Result: True -Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() passed -Message: -All Evaluations passed - Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should not call "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithoutDependencies()" Result: True Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() passed @@ -44,24 +20,6 @@ All Evaluations passed ===== Violations ===== -Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should not call any method with full name "System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod()" -Result: False -Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() does call System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod() -Message: -"Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should not call any method with full name "System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod()"" failed: - System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() does call System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod() - - - -Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should not call methods with full name "System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod()" -Result: False -Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() does call System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod() -Message: -"Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should not call methods with full name "System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod()"" failed: - System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() does call System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod() - - - Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should not call "System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod()" Result: False Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() does call System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod() @@ -89,20 +47,6 @@ Message: -===== Non-existent method member ===== - -Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should not call any method with full name "NotTheNameOfAnyObject" -Result: True -Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() passed -Message: -All Evaluations passed - -Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should not call methods with full name "NotTheNameOfAnyObject" -Result: True -Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() passed -Message: -All Evaluations passed - ===== Empty arguments ===== Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should not call no methods (always true) @@ -111,38 +55,8 @@ Description: System.Void MethodDependencyNamespace.MethodDependencyClass::Method Message: All Evaluations passed -Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should not call no methods (always true) -Result: True -Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() passed -Message: -All Evaluations passed - -Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency()" should not call Method members that have full name "NotTheNameOfAnyObject" -Result: True -Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithSingleDependency() passed -Message: -All Evaluations passed - ===== Multiple arguments ===== -Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithMultipleDependencies()" should not call any method with full name matching "^.*::(MethodWithoutDependencies|CalledMethod[0-9])\(\)$" -Result: False -Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithMultipleDependencies() does call System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod1() and System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod2() and System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod3() -Message: -"Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithMultipleDependencies()" should not call any method with full name matching "^.*::(MethodWithoutDependencies|CalledMethod[0-9])\(\)$"" failed: - System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithMultipleDependencies() does call System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod1() and System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod2() and System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod3() - - - -Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithMultipleDependencies()" should not call methods with full name "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithoutDependencies()" or "System.Void MethodDe... -Result: False -Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithMultipleDependencies() does call System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod1() and System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod2() -Message: -"Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithMultipleDependencies()" should not call methods with full name "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithoutDependencies()" or "System.Void MethodDe..." failed: - System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithMultipleDependencies() does call System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod1() and System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod2() - - - Query: Method members that are "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithMultipleDependencies()" should not call "System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithoutDependencies()" or "System.Void MethodDependencyNamespace.Metho... Result: False Description: System.Void MethodDependencyNamespace.MethodDependencyClass::MethodWithMultipleDependencies() does call System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod1() and System.Void MethodDependencyNamespace.MethodDependencyClass::CalledMethod2() diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.NotDependOnAnyTest.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.NotDependOnAnyTest.verified.txt index 570c9d677..bac227e89 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.NotDependOnAnyTest.verified.txt +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.NotDependOnAnyTest.verified.txt @@ -1,29 +1,5 @@ ===== No violations ===== -Query: Types that are "TypeDependencyNamespace.ChildClass" should not depend on any types with full name "TypeDependencyNamespace.ClassWithoutDependencies" -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Message: -All Evaluations passed - -Query: Types that are "TypeDependencyNamespace.ChildClass" should not depend on any types with full name matching "^.*\.ClassWithoutDependencies$" -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Message: -All Evaluations passed - -Query: Types that are "TypeDependencyNamespace.ChildClass" should not depend on types with full name "TypeDependencyNamespace.ClassWithoutDependencies" -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Message: -All Evaluations passed - -Query: Types that are "TypeDependencyNamespace.ChildClass" should not depend on any types with full name matching "^.*\.ClassWithoutDependencies$" -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Message: -All Evaluations passed - Query: Types that are "TypeDependencyNamespace.ChildClass" should not depend on "TypeDependencyNamespace.ClassWithoutDependencies" Result: True Description: TypeDependencyNamespace.ChildClass passed @@ -56,24 +32,6 @@ All Evaluations passed ===== Violations ===== -Query: Types that are "TypeDependencyNamespace.ChildClass" should not depend on any types with full name "TypeDependencyNamespace.BaseClass" -Result: False -Description: TypeDependencyNamespace.ChildClass does depend on TypeDependencyNamespace.BaseClass and TypeDependencyNamespace.BaseClass -Message: -"Types that are "TypeDependencyNamespace.ChildClass" should not depend on any types with full name "TypeDependencyNamespace.BaseClass"" failed: - TypeDependencyNamespace.ChildClass does depend on TypeDependencyNamespace.BaseClass and TypeDependencyNamespace.BaseClass - - - -Query: Types that are "TypeDependencyNamespace.ChildClass" should not depend on types with full name "TypeDependencyNamespace.BaseClass" -Result: False -Description: TypeDependencyNamespace.ChildClass does depend on TypeDependencyNamespace.BaseClass and TypeDependencyNamespace.BaseClass -Message: -"Types that are "TypeDependencyNamespace.ChildClass" should not depend on types with full name "TypeDependencyNamespace.BaseClass"" failed: - TypeDependencyNamespace.ChildClass does depend on TypeDependencyNamespace.BaseClass and TypeDependencyNamespace.BaseClass - - - Query: Types that are "TypeDependencyNamespace.ChildClass" should not depend on "TypeDependencyNamespace.BaseClass" Result: False Description: TypeDependencyNamespace.ChildClass does depend on TypeDependencyNamespace.BaseClass @@ -119,20 +77,6 @@ Message: -===== Non-existent type ===== - -Query: Types that are "TypeDependencyNamespace.ChildClass" should not depend on any types with full name "NotTheNameOfAnyObject" -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Message: -All Evaluations passed - -Query: Types that are "TypeDependencyNamespace.ChildClass" should not depend on types with full name "NotTheNameOfAnyObject" -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Message: -All Evaluations passed - ===== Type outside of architecture ===== Query: Types that are "TypeDependencyNamespace.ChildClass" should not depend on "AttributeNamespace.ClassWithoutAttributes" @@ -155,29 +99,8 @@ Description: TypeDependencyNamespace.ChildClass passed Message: All Evaluations passed -Query: Types that are "TypeDependencyNamespace.ChildClass" should not depend on no types (always true) -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Message: -All Evaluations passed - -Query: Types that are "TypeDependencyNamespace.ChildClass" should not depend on Classes that have full name "NotTheNameOfAnyObject" -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Message: -All Evaluations passed - ===== Multiple arguments ===== -Query: Types that are "TypeDependencyNamespace.ChildClass" should not depend on types with full name "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" -Result: False -Description: TypeDependencyNamespace.ChildClass does depend on TypeDependencyNamespace.BaseClass and TypeDependencyNamespace.BaseClass -Message: -"Types that are "TypeDependencyNamespace.ChildClass" should not depend on types with full name "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass"" failed: - TypeDependencyNamespace.ChildClass does depend on TypeDependencyNamespace.BaseClass and TypeDependencyNamespace.BaseClass - - - Query: Types that are "TypeDependencyNamespace.ChildClass" should not depend on "TypeDependencyNamespace.ClassWithoutDependencies" or "TypeDependencyNamespace.BaseClass" Result: False Description: TypeDependencyNamespace.ChildClass does depend on TypeDependencyNamespace.BaseClass @@ -216,24 +139,6 @@ Message: ===== Input with multiple dependencies ===== -Query: Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should not depend on any types with full name matching "^.*\.(BaseClassWithMember|OtherBaseClass)$" -Result: False -Description: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass -Message: -"Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should not depend on any types with full name matching "^.*\.(BaseClassWithMember|OtherBaseClass)$"" failed: - TypeDependencyNamespace.ClassWithMultipleDependencies does depend on TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass - - - -Query: Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should not depend on types with full name "TypeDependencyNamespace.BaseClassWithMember" or "TypeDependencyNamespace.OtherBaseClass" -Result: False -Description: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass -Message: -"Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should not depend on types with full name "TypeDependencyNamespace.BaseClassWithMember" or "TypeDependencyNamespace.OtherBaseClass"" failed: - TypeDependencyNamespace.ClassWithMultipleDependencies does depend on TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass - - - Query: Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should not depend on "TypeDependencyNamespace.BaseClassWithMember" or "TypeDependencyNamespace.OtherBaseClass" Result: False Description: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.NotHaveAnyAttributesTest.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.NotHaveAnyAttributesTest.verified.txt index 1129315d2..40aaee752 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.NotHaveAnyAttributesTest.verified.txt +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.NotHaveAnyAttributesTest.verified.txt @@ -1,29 +1,5 @@ ===== No violations ===== -Query: Types that are "AttributeNamespace.ClassWithSingleAttribute" should not have any attribute with full name "AttributeNamespace.UnusedAttribute" -Result: True -Description: AttributeNamespace.ClassWithSingleAttribute passed -Message: -All Evaluations passed - -Query: Types that are "AttributeNamespace.ClassWithSingleAttribute" should not have any attribute with full name matching "^.*\.UnusedAttribute$" -Result: True -Description: AttributeNamespace.ClassWithSingleAttribute passed -Message: -All Evaluations passed - -Query: Types that are "AttributeNamespace.ClassWithSingleAttribute" should not have any attribute with full name "AttributeNamespace.UnusedAttribute" -Result: True -Description: AttributeNamespace.ClassWithSingleAttribute passed -Message: -All Evaluations passed - -Query: Types that are "AttributeNamespace.ClassWithSingleAttribute" should not have any attribute with full name matching "^.*\.UnusedAttribute$" -Result: True -Description: AttributeNamespace.ClassWithSingleAttribute passed -Message: -All Evaluations passed - Query: Types that are "AttributeNamespace.ClassWithSingleAttribute" should not have attribute "AttributeNamespace.UnusedAttribute" Result: True Description: AttributeNamespace.ClassWithSingleAttribute passed @@ -56,24 +32,6 @@ All Evaluations passed ===== Violations ===== -Query: Types that are "AttributeNamespace.ClassWithSingleAttribute" should not have any attribute with full name "AttributeNamespace.Attribute1" -Result: False -Description: AttributeNamespace.ClassWithSingleAttribute does have any attribute with full name "AttributeNamespace.Attribute1" -Message: -"Types that are "AttributeNamespace.ClassWithSingleAttribute" should not have any attribute with full name "AttributeNamespace.Attribute1"" failed: - AttributeNamespace.ClassWithSingleAttribute does have any attribute with full name "AttributeNamespace.Attribute1" - - - -Query: Types that are "AttributeNamespace.ClassWithSingleAttribute" should not have any attribute with full name "AttributeNamespace.Attribute1" -Result: False -Description: AttributeNamespace.ClassWithSingleAttribute does have any attribute with full name "AttributeNamespace.Attribute1" -Message: -"Types that are "AttributeNamespace.ClassWithSingleAttribute" should not have any attribute with full name "AttributeNamespace.Attribute1"" failed: - AttributeNamespace.ClassWithSingleAttribute does have any attribute with full name "AttributeNamespace.Attribute1" - - - Query: Types that are "AttributeNamespace.ClassWithSingleAttribute" should not have attribute "AttributeNamespace.Attribute1" Result: False Description: AttributeNamespace.ClassWithSingleAttribute does have attribute AttributeNamespace.Attribute1 @@ -119,20 +77,6 @@ Message: -===== Non-existent attribute ===== - -Query: Types that are "AttributeNamespace.ClassWithoutAttributes" should not have any attribute with full name "NotTheNameOfAnyObject" -Result: True -Description: AttributeNamespace.ClassWithoutAttributes passed -Message: -All Evaluations passed - -Query: Types that are "AttributeNamespace.ClassWithoutAttributes" should not have any attribute with full name "NotTheNameOfAnyObject" -Result: True -Description: AttributeNamespace.ClassWithoutAttributes passed -Message: -All Evaluations passed - ===== Type outside of architecture ===== Query: Types that are "AttributeNamespace.ClassWithAttributes" should not have attribute "TypeDependencyNamespace.BaseClass" @@ -155,12 +99,6 @@ Description: AttributeNamespace.ClassWithoutAttributes passed Message: All Evaluations passed -Query: Types that are "AttributeNamespace.ClassWithoutAttributes" should not have one of no attributes (always true) -Result: True -Description: AttributeNamespace.ClassWithoutAttributes passed -Message: -All Evaluations passed - Query: Types that are "AttributeNamespace.ClassWithoutAttributes" should not have any Attributes that have full name "NotTheNameOfAnyObject" Result: True Description: AttributeNamespace.ClassWithoutAttributes passed @@ -175,25 +113,12 @@ Query: Types that have full name "NotTheNameOfAnyObject" should not have one of Message: All Evaluations passed -Query: Types that have full name "NotTheNameOfAnyObject" should not have one of no attributes (always true) -Message: -All Evaluations passed - Query: Types that have full name "NotTheNameOfAnyObject" should not have any Attributes that have full name "NotTheNameOfAnyObject" Message: All Evaluations passed ===== Multiple arguments ===== -Query: Types that are "AttributeNamespace.ClassWithAttributes" should not have any attribute with full name "AttributeNamespace.Attribute1" or "AttributeNamespace.Attribute2" -Result: False -Description: AttributeNamespace.ClassWithAttributes does have any attribute with full name "AttributeNamespace.Attribute1" or "AttributeNamespace.Attribute2" -Message: -"Types that are "AttributeNamespace.ClassWithAttributes" should not have any attribute with full name "AttributeNamespace.Attribute1" or "AttributeNamespace.Attribute2"" failed: - AttributeNamespace.ClassWithAttributes does have any attribute with full name "AttributeNamespace.Attribute1" or "AttributeNamespace.Attribute2" - - - Query: Types that are "AttributeNamespace.ClassWithAttributes" should not have attribute "AttributeNamespace.Attribute1" or "AttributeNamespace.Attribute2" Result: False Description: AttributeNamespace.ClassWithAttributes does have attribute AttributeNamespace.Attribute1 and AttributeNamespace.Attribute2 diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.NotHaveAttributeWithArgumentsTest.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.NotHaveAttributeWithArgumentsTest.verified.txt index 6abd90820..79a4cf958 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.NotHaveAttributeWithArgumentsTest.verified.txt +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.NotHaveAttributeWithArgumentsTest.verified.txt @@ -1,17 +1,5 @@ ===== No violations with type arguments ===== -Query: Types that are "AttributeNamespace.ClassWithArguments" should not have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.OtherTypeArgument" -Result: True -Description: AttributeNamespace.ClassWithArguments passed -Message: -All Evaluations passed - -Query: Types that are "AttributeNamespace.ClassWithArguments" should not have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.OtherTypeArgument" -Result: True -Description: AttributeNamespace.ClassWithArguments passed -Message: -All Evaluations passed - Query: Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.OtherTypeArgument" Result: True Description: AttributeNamespace.ClassWithArguments passed @@ -38,18 +26,6 @@ All Evaluations passed ===== No violations with value arguments ===== -Query: Types that are "AttributeNamespace.ClassWithArguments" should not have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.OtherTypeArgument" -Result: True -Description: AttributeNamespace.ClassWithArguments passed -Message: -All Evaluations passed - -Query: Types that are "AttributeNamespace.ClassWithArguments" should not have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.OtherTypeArgument" -Result: True -Description: AttributeNamespace.ClassWithArguments passed -Message: -All Evaluations passed - Query: Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.OtherTypeArgument" Result: True Description: AttributeNamespace.ClassWithArguments passed @@ -76,24 +52,6 @@ All Evaluations passed ===== Violations with type arguments ===== -Query: Types that are "AttributeNamespace.ClassWithArguments" should not have attribute "AttributeNamespace.Attribute1" with arguments "Argument" -Result: False -Description: AttributeNamespace.ClassWithArguments does have attribute "AttributeNamespace.Attribute1" with arguments "Argument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should not have attribute "AttributeNamespace.Attribute1" with arguments "Argument"" failed: - AttributeNamespace.ClassWithArguments does have attribute "AttributeNamespace.Attribute1" with arguments "Argument" - - - -Query: Types that are "AttributeNamespace.ClassWithArguments" should not have attribute "AttributeNamespace.Attribute1" with arguments "Argument" -Result: False -Description: AttributeNamespace.ClassWithArguments does have attribute "AttributeNamespace.Attribute1" with arguments "Argument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should not have attribute "AttributeNamespace.Attribute1" with arguments "Argument"" failed: - AttributeNamespace.ClassWithArguments does have attribute "AttributeNamespace.Attribute1" with arguments "Argument" - - - Query: Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" with arguments "Argument" Result: False Description: AttributeNamespace.ClassWithArguments not have attribute "AttributeNamespace.Attribute1" with arguments "Argument" @@ -132,24 +90,6 @@ Message: ===== Violations with value arguments ===== -Query: Types that are "AttributeNamespace.ClassWithArguments" should not have attribute "AttributeNamespace.Attribute1" with arguments "0" -Result: False -Description: AttributeNamespace.ClassWithArguments does have attribute "AttributeNamespace.Attribute1" with arguments "0" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should not have attribute "AttributeNamespace.Attribute1" with arguments "0"" failed: - AttributeNamespace.ClassWithArguments does have attribute "AttributeNamespace.Attribute1" with arguments "0" - - - -Query: Types that are "AttributeNamespace.ClassWithArguments" should not have attribute "AttributeNamespace.Attribute1" with arguments "0" -Result: False -Description: AttributeNamespace.ClassWithArguments does have attribute "AttributeNamespace.Attribute1" with arguments "0" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should not have attribute "AttributeNamespace.Attribute1" with arguments "0"" failed: - AttributeNamespace.ClassWithArguments does have attribute "AttributeNamespace.Attribute1" with arguments "0" - - - Query: Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" with arguments "0" Result: False Description: AttributeNamespace.ClassWithArguments not have attribute "AttributeNamespace.Attribute1" with arguments "0" @@ -188,18 +128,6 @@ Message: ===== Unused attribute ===== -Query: Types that are "AttributeNamespace.ClassWithArguments" should not have attribute "AttributeNamespace.UnusedAttribute" with arguments "Argument" -Result: True -Description: AttributeNamespace.ClassWithArguments passed -Message: -All Evaluations passed - -Query: Types that are "AttributeNamespace.ClassWithArguments" should not have attribute "AttributeNamespace.UnusedAttribute" with arguments "Argument" -Result: True -Description: AttributeNamespace.ClassWithArguments passed -Message: -All Evaluations passed - Query: Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.UnusedAttribute" with arguments "Argument" Result: True Description: AttributeNamespace.ClassWithArguments passed @@ -234,12 +162,6 @@ All Evaluations passed ===== Null argument ===== -Query: Types that are "AttributeNamespace.ClassWithArguments" should not have attribute "AttributeNamespace.UnusedAttribute" with arguments "" -Result: True -Description: AttributeNamespace.ClassWithArguments passed -Message: -All Evaluations passed - Query: Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.UnusedAttribute" with arguments "" Result: True Description: AttributeNamespace.ClassWithArguments passed @@ -254,15 +176,6 @@ All Evaluations passed ===== Empty arguments ===== -Query: Types that are "AttributeNamespace.ClassWithArguments" should not have attribute "AttributeNamespace.Attribute1" -Result: False -Description: AttributeNamespace.ClassWithArguments does have attribute "AttributeNamespace.Attribute1" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should not have attribute "AttributeNamespace.Attribute1"" failed: - AttributeNamespace.ClassWithArguments does have attribute "AttributeNamespace.Attribute1" - - - Query: Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" Result: False Description: AttributeNamespace.ClassWithArguments not have attribute "AttributeNamespace.Attribute1" @@ -283,24 +196,6 @@ Message: ===== Multiple arguments ===== -Query: Types that are "AttributeNamespace.ClassWithArguments" should not have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.TypeArgument" and "0" -Result: False -Description: AttributeNamespace.ClassWithArguments does have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.TypeArgument" and "0" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should not have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.TypeArgument" and "0"" failed: - AttributeNamespace.ClassWithArguments does have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.TypeArgument" and "0" - - - -Query: Types that are "AttributeNamespace.ClassWithArguments" should not have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.TypeArgument" and "0" -Result: False -Description: AttributeNamespace.ClassWithArguments does have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.TypeArgument" and "0" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should not have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.TypeArgument" and "0"" failed: - AttributeNamespace.ClassWithArguments does have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.TypeArgument" and "0" - - - Query: Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.TypeArgument" and "0" Result: False Description: AttributeNamespace.ClassWithArguments not have attribute "AttributeNamespace.Attribute1" with arguments "AttributeNamespace.TypeArgument" and "0" @@ -339,28 +234,6 @@ Message: ===== Multiple inputs ===== -Query: Types that are "AttributeNamespace.ClassWithArguments" or "AttributeNamespace.ClassWithAttributes" should not have attribute "AttributeNamespace.Attribute1" with arguments "Argument" -Result: True -Description: AttributeNamespace.ClassWithAttributes passed -Result: False -Description: AttributeNamespace.ClassWithArguments does have attribute "AttributeNamespace.Attribute1" with arguments "Argument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" or "AttributeNamespace.ClassWithAttributes" should not have attribute "AttributeNamespace.Attribute1" with arguments "Argument"" failed: - AttributeNamespace.ClassWithArguments does have attribute "AttributeNamespace.Attribute1" with arguments "Argument" - - - -Query: Types that are "AttributeNamespace.ClassWithArguments" or "AttributeNamespace.ClassWithAttributes" should not have attribute "AttributeNamespace.Attribute1" with arguments "Argument" -Result: True -Description: AttributeNamespace.ClassWithAttributes passed -Result: False -Description: AttributeNamespace.ClassWithArguments does have attribute "AttributeNamespace.Attribute1" with arguments "Argument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" or "AttributeNamespace.ClassWithAttributes" should not have attribute "AttributeNamespace.Attribute1" with arguments "Argument"" failed: - AttributeNamespace.ClassWithArguments does have attribute "AttributeNamespace.Attribute1" with arguments "Argument" - - - Query: Types that are "AttributeNamespace.ClassWithArguments" or "AttributeNamespace.ClassWithAttributes" should does have attribute "AttributeNamespace.Attribute1" with arguments "Argument" Result: True Description: AttributeNamespace.ClassWithAttributes passed diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.NotHaveAttributeWithNamedArgumentsTest.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.NotHaveAttributeWithNamedArgumentsTest.verified.txt index 05c29aa54..fd8df0b63 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.NotHaveAttributeWithNamedArgumentsTest.verified.txt +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.NotHaveAttributeWithNamedArgumentsTest.verified.txt @@ -24,18 +24,6 @@ Description: AttributeNamespace.ClassWithArguments passed Message: All Evaluations passed -Query: Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" with named arguments "OtherNamedParameter1=OtherNamedArgument" -Result: True -Description: AttributeNamespace.ClassWithArguments passed -Message: -All Evaluations passed - -Query: Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" with named arguments "OtherNamedParameter1=OtherNamedArgument" -Result: True -Description: AttributeNamespace.ClassWithArguments passed -Message: -All Evaluations passed - ===== No violations with value arguments ===== Query: Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" with named arguments "OtherNamedParameter1=OtherNamedArgument" @@ -62,18 +50,6 @@ Description: AttributeNamespace.ClassWithArguments passed Message: All Evaluations passed -Query: Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" with named arguments "OtherNamedParameter1=OtherNamedArgument" -Result: True -Description: AttributeNamespace.ClassWithArguments passed -Message: -All Evaluations passed - -Query: Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" with named arguments "OtherNamedParameter1=OtherNamedArgument" -Result: True -Description: AttributeNamespace.ClassWithArguments passed -Message: -All Evaluations passed - ===== Violations with type arguments ===== Query: Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" @@ -112,24 +88,6 @@ Message: -Query: Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" -Result: False -Description: AttributeNamespace.ClassWithArguments not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument"" failed: - AttributeNamespace.ClassWithArguments not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" - - - -Query: Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" -Result: False -Description: AttributeNamespace.ClassWithArguments not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument"" failed: - AttributeNamespace.ClassWithArguments not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" - - - ===== Violations with value arguments ===== Query: Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter2=NamedArgument" @@ -168,24 +126,6 @@ Message: -Query: Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter2=NamedArgument" -Result: False -Description: AttributeNamespace.ClassWithArguments not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter2=NamedArgument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter2=NamedArgument"" failed: - AttributeNamespace.ClassWithArguments not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter2=NamedArgument" - - - -Query: Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter2=NamedArgument" -Result: False -Description: AttributeNamespace.ClassWithArguments not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter2=NamedArgument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter2=NamedArgument"" failed: - AttributeNamespace.ClassWithArguments not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter2=NamedArgument" - - - ===== Unused attribute ===== Query: Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.UnusedAttribute" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" @@ -212,18 +152,6 @@ Description: AttributeNamespace.ClassWithArguments passed Message: All Evaluations passed -Query: Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.UnusedAttribute" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" -Result: True -Description: AttributeNamespace.ClassWithArguments passed -Message: -All Evaluations passed - -Query: Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.UnusedAttribute" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" -Result: True -Description: AttributeNamespace.ClassWithArguments passed -Message: -All Evaluations passed - ===== Type outside of architecture ===== Query: Types that are "AttributeNamespace.ClassWithAttributes" should does have attribute "TypeDependencyNamespace.BaseClass" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" @@ -252,15 +180,6 @@ Message: -Query: Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" -Result: False -Description: AttributeNamespace.ClassWithArguments not have attribute "AttributeNamespace.Attribute1" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1"" failed: - AttributeNamespace.ClassWithArguments not have attribute "AttributeNamespace.Attribute1" - - - ===== Multiple arguments ===== Query: Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" and "NamedParameter... @@ -299,24 +218,6 @@ Message: -Query: Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" and "NamedParameter... -Result: False -Description: AttributeNamespace.ClassWithArguments not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" and "NamedParameter2=NamedArgument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" and "NamedParameter..." failed: - AttributeNamespace.ClassWithArguments not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" and "NamedParameter2=NamedArgument" - - - -Query: Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" and "NamedParameter... -Result: False -Description: AttributeNamespace.ClassWithArguments not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" and "NamedParameter2=NamedArgument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" should does have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" and "NamedParameter..." failed: - AttributeNamespace.ClassWithArguments not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" and "NamedParameter2=NamedArgument" - - - ===== Multiple inputs ===== Query: Types that are "AttributeNamespace.ClassWithArguments" or "AttributeNamespace.ClassWithAttributes" should does have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" @@ -363,25 +264,3 @@ Message: -Query: Types that are "AttributeNamespace.ClassWithArguments" or "AttributeNamespace.ClassWithAttributes" should does have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" -Result: True -Description: AttributeNamespace.ClassWithAttributes passed -Result: False -Description: AttributeNamespace.ClassWithArguments not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" or "AttributeNamespace.ClassWithAttributes" should does have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument"" failed: - AttributeNamespace.ClassWithArguments not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" - - - -Query: Types that are "AttributeNamespace.ClassWithArguments" or "AttributeNamespace.ClassWithAttributes" should does have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" -Result: True -Description: AttributeNamespace.ClassWithAttributes passed -Result: False -Description: AttributeNamespace.ClassWithArguments not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" -Message: -"Types that are "AttributeNamespace.ClassWithArguments" or "AttributeNamespace.ClassWithAttributes" should does have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument"" failed: - AttributeNamespace.ClassWithArguments not have attribute "AttributeNamespace.Attribute1" with named arguments "NamedParameter1=AttributeNamespace.NamedTypeArgument" - - - diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.OnlyDependOnTest.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.OnlyDependOnTest.verified.txt index 7863ac402..da5f6370b 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.OnlyDependOnTest.verified.txt +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.OnlyDependOnTest.verified.txt @@ -1,29 +1,5 @@ ===== No violations ===== -Query: Types that are "TypeDependencyNamespace.ChildClass" should only depend on types with full name "TypeDependencyNamespace.BaseClass" -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Message: -All Evaluations passed - -Query: Types that are "TypeDependencyNamespace.ChildClass" should only depend on types with full name matching "^.*\.BaseClass$" -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Message: -All Evaluations passed - -Query: Types that are "TypeDependencyNamespace.ChildClass" should only depend on types with full name "TypeDependencyNamespace.BaseClass" -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Message: -All Evaluations passed - -Query: Types that are "TypeDependencyNamespace.ChildClass" should only depend on types with full name matching "^.*\.BaseClass$" -Result: True -Description: TypeDependencyNamespace.ChildClass passed -Message: -All Evaluations passed - Query: Types that are "TypeDependencyNamespace.ChildClass" should only depend on "TypeDependencyNamespace.BaseClass" Result: True Description: TypeDependencyNamespace.ChildClass passed @@ -56,24 +32,6 @@ All Evaluations passed ===== Violations ===== -Query: Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should only depend on types with full name "TypeDependencyNamespace.BaseClass" -Result: False -Description: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass and System.Object -Message: -"Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should only depend on types with full name "TypeDependencyNamespace.BaseClass"" failed: - TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass and System.Object - - - -Query: Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should only depend on types with full name "TypeDependencyNamespace.BaseClass" -Result: False -Description: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass and System.Object -Message: -"Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should only depend on types with full name "TypeDependencyNamespace.BaseClass"" failed: - TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass and System.Object - - - Query: Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should only depend on "TypeDependencyNamespace.BaseClass" Result: False Description: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass @@ -119,26 +77,6 @@ Message: -===== Non-existent type ===== - -Query: Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should only depend on types with full name "NotTheNameOfAnyObject" -Result: False -Description: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass and System.Object -Message: -"Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should only depend on types with full name "NotTheNameOfAnyObject"" failed: - TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass and System.Object - - - -Query: Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should only depend on types with full name "NotTheNameOfAnyObject" -Result: False -Description: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass and System.Object -Message: -"Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should only depend on types with full name "NotTheNameOfAnyObject"" failed: - TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass and System.Object - - - ===== Type outside of architecture ===== Query: Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should only depend on "AttributeNamespace.ClassWithoutAttributes" @@ -152,15 +90,6 @@ Message: ===== Empty arguments ===== -Query: Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should have no dependencies -Result: False -Description: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass and System.Object -Message: -"Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should have no dependencies" failed: - TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass and System.Object - - - Query: Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should have no dependencies Result: False Description: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass @@ -190,15 +119,6 @@ Message: ===== Multiple arguments ===== -Query: Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should only depend on types with full name "TypeDependencyNamespace.BaseClass" or "TypeDependencyNamespace.OtherBaseClass" -Result: False -Description: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and System.Object -Message: -"Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should only depend on types with full name "TypeDependencyNamespace.BaseClass" or "TypeDependencyNamespace.OtherBaseClass"" failed: - TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and System.Object - - - Query: Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should only depend on "TypeDependencyNamespace.BaseClass" or "TypeDependencyNamespace.OtherBaseClass" Result: False Description: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.OnlyDependOnTypesThatTest.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.OnlyDependOnTypesThatTest.verified.txt index 37fe19ee0..638bcd557 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.OnlyDependOnTypesThatTest.verified.txt +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.OnlyDependOnTypesThatTest.verified.txt @@ -1,6 +1,6 @@ ===== No violations ===== -Query: Types that are "TypeDependencyNamespace.ChildClass" should only depend on types that have full name "TypeDependencyNamespace.BaseClass" +Query: Types that are "TypeDependencyNamespace.ChildClass" should only depend on types that are "TypeDependencyNamespace.BaseClass" Result: True Description: TypeDependencyNamespace.ChildClass passed Message: @@ -8,11 +8,11 @@ All Evaluations passed ===== Violations ===== -Query: Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should only depend on types that have full name "TypeDependencyNamespace.BaseClass" +Query: Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should only depend on types that are "TypeDependencyNamespace.BaseClass" Result: False Description: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass Message: -"Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should only depend on types that have full name "TypeDependencyNamespace.BaseClass"" failed: +"Types that are "TypeDependencyNamespace.ClassWithMultipleDependencies" should only depend on types that are "TypeDependencyNamespace.BaseClass"" failed: TypeDependencyNamespace.ClassWithMultipleDependencies does depend on System.Object and TypeDependencyNamespace.BaseClassWithMember and TypeDependencyNamespace.OtherBaseClass diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.OnlyHaveAttributesTest.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.OnlyHaveAttributesTest.verified.txt index 715a7f169..278ee85bd 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.OnlyHaveAttributesTest.verified.txt +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.OnlyHaveAttributesTest.verified.txt @@ -1,29 +1,5 @@ ===== No violations ===== -Query: Types that are "AttributeNamespace.ClassWithSingleAttribute" should only have attributes with full name "AttributeNamespace.Attribute1" -Result: True -Description: AttributeNamespace.ClassWithSingleAttribute passed -Message: -All Evaluations passed - -Query: Types that are "AttributeNamespace.ClassWithSingleAttribute" should only have attributes with full name matching "^.*\.Attribute1$" -Result: True -Description: AttributeNamespace.ClassWithSingleAttribute passed -Message: -All Evaluations passed - -Query: Types that are "AttributeNamespace.ClassWithSingleAttribute" should only have attributes with full name "AttributeNamespace.Attribute1" -Result: True -Description: AttributeNamespace.ClassWithSingleAttribute passed -Message: -All Evaluations passed - -Query: Types that are "AttributeNamespace.ClassWithSingleAttribute" should only have attributes with full name matching "^.*\.Attribute1$" -Result: True -Description: AttributeNamespace.ClassWithSingleAttribute passed -Message: -All Evaluations passed - Query: Types that are "AttributeNamespace.ClassWithSingleAttribute" should only have attributes "AttributeNamespace.Attribute1" Result: True Description: AttributeNamespace.ClassWithSingleAttribute passed @@ -56,24 +32,6 @@ All Evaluations passed ===== Violations ===== -Query: Types that are "AttributeNamespace.ClassWithSingleAttribute" should only have attributes with full name "AttributeNamespace.UnusedAttribute" -Result: False -Description: AttributeNamespace.ClassWithSingleAttribute does not only have attributes with full name "AttributeNamespace.UnusedAttribute" -Message: -"Types that are "AttributeNamespace.ClassWithSingleAttribute" should only have attributes with full name "AttributeNamespace.UnusedAttribute"" failed: - AttributeNamespace.ClassWithSingleAttribute does not only have attributes with full name "AttributeNamespace.UnusedAttribute" - - - -Query: Types that are "AttributeNamespace.ClassWithSingleAttribute" should only have attributes with full name "AttributeNamespace.UnusedAttribute" -Result: False -Description: AttributeNamespace.ClassWithSingleAttribute does not only have attributes with full name "AttributeNamespace.UnusedAttribute" -Message: -"Types that are "AttributeNamespace.ClassWithSingleAttribute" should only have attributes with full name "AttributeNamespace.UnusedAttribute"" failed: - AttributeNamespace.ClassWithSingleAttribute does not only have attributes with full name "AttributeNamespace.UnusedAttribute" - - - Query: Types that are "AttributeNamespace.ClassWithSingleAttribute" should only have attributes "AttributeNamespace.UnusedAttribute" Result: False Description: AttributeNamespace.ClassWithSingleAttribute does have attribute AttributeNamespace.Attribute1 @@ -119,26 +77,6 @@ Message: -===== Non-existent attribute ===== - -Query: Types that are "AttributeNamespace.ClassWithSingleAttribute" should only have attributes with full name "NotTheNameOfAnyObject" -Result: False -Description: AttributeNamespace.ClassWithSingleAttribute does not only have attributes with full name "NotTheNameOfAnyObject" -Message: -"Types that are "AttributeNamespace.ClassWithSingleAttribute" should only have attributes with full name "NotTheNameOfAnyObject"" failed: - AttributeNamespace.ClassWithSingleAttribute does not only have attributes with full name "NotTheNameOfAnyObject" - - - -Query: Types that are "AttributeNamespace.ClassWithSingleAttribute" should only have attributes with full name "NotTheNameOfAnyObject" -Result: False -Description: AttributeNamespace.ClassWithSingleAttribute does not only have attributes with full name "NotTheNameOfAnyObject" -Message: -"Types that are "AttributeNamespace.ClassWithSingleAttribute" should only have attributes with full name "NotTheNameOfAnyObject"" failed: - AttributeNamespace.ClassWithSingleAttribute does not only have attributes with full name "NotTheNameOfAnyObject" - - - ===== Attribute outside of architecture ===== Query: Types that are "AttributeNamespace.ClassWithSingleAttribute" should only have attributes "TypeDependencyNamespace.BaseClass" @@ -152,15 +90,6 @@ Message: ===== Empty arguments ===== -Query: Types that are "AttributeNamespace.ClassWithSingleAttribute" should have no attributes -Result: False -Description: AttributeNamespace.ClassWithSingleAttribute does have attributes -Message: -"Types that are "AttributeNamespace.ClassWithSingleAttribute" should have no attributes" failed: - AttributeNamespace.ClassWithSingleAttribute does have attributes - - - Query: Types that are "AttributeNamespace.ClassWithSingleAttribute" should have no attributes Result: False Description: AttributeNamespace.ClassWithSingleAttribute does have attribute AttributeNamespace.Attribute1 @@ -200,26 +129,8 @@ Description: AttributeNamespace.ClassWithoutAttributes passed Message: All Evaluations passed -Query: Types that are "AttributeNamespace.ClassWithoutAttributes" should have no attributes -Result: True -Description: AttributeNamespace.ClassWithoutAttributes passed -Message: -All Evaluations passed - -Query: Types that are "AttributeNamespace.ClassWithoutAttributes" should does only have Attributes that have full name "NotTheNameOfAnyObject" -Result: True -Description: AttributeNamespace.ClassWithoutAttributes passed -Message: -All Evaluations passed - ===== Multiple arguments ===== -Query: Types that are "AttributeNamespace.ClassWithAttributes" should only have attributes with full name "AttributeNamespace.Attribute1" and "AttributeNamespace.Attribute2" -Result: True -Description: AttributeNamespace.ClassWithAttributes passed -Message: -All Evaluations passed - Query: Types that are "AttributeNamespace.ClassWithAttributes" should only have attributes "AttributeNamespace.Attribute1" and "AttributeNamespace.Attribute2" Result: True Description: AttributeNamespace.ClassWithAttributes passed @@ -252,30 +163,6 @@ All Evaluations passed ===== Multiple inputs ===== -Query: Types that are "AttributeNamespace.ClassWithAttributes" or "AttributeNamespace.OtherClassWithAttributes" should only have attributes with full name "AttributeNamespace.UnusedAttribute" -Result: False -Description: AttributeNamespace.ClassWithAttributes does not only have attributes with full name "AttributeNamespace.UnusedAttribute" -Result: False -Description: AttributeNamespace.OtherClassWithAttributes does not only have attributes with full name "AttributeNamespace.UnusedAttribute" -Message: -"Types that are "AttributeNamespace.ClassWithAttributes" or "AttributeNamespace.OtherClassWithAttributes" should only have attributes with full name "AttributeNamespace.UnusedAttribute"" failed: - AttributeNamespace.ClassWithAttributes does not only have attributes with full name "AttributeNamespace.UnusedAttribute" - AttributeNamespace.OtherClassWithAttributes does not only have attributes with full name "AttributeNamespace.UnusedAttribute" - - - -Query: Types that are "AttributeNamespace.ClassWithAttributes" or "AttributeNamespace.OtherClassWithAttributes" should only have attributes with full name "AttributeNamespace.UnusedAttribute" -Result: False -Description: AttributeNamespace.ClassWithAttributes does not only have attributes with full name "AttributeNamespace.UnusedAttribute" -Result: False -Description: AttributeNamespace.OtherClassWithAttributes does not only have attributes with full name "AttributeNamespace.UnusedAttribute" -Message: -"Types that are "AttributeNamespace.ClassWithAttributes" or "AttributeNamespace.OtherClassWithAttributes" should only have attributes with full name "AttributeNamespace.UnusedAttribute"" failed: - AttributeNamespace.ClassWithAttributes does not only have attributes with full name "AttributeNamespace.UnusedAttribute" - AttributeNamespace.OtherClassWithAttributes does not only have attributes with full name "AttributeNamespace.UnusedAttribute" - - - Query: Types that are "AttributeNamespace.ClassWithAttributes" or "AttributeNamespace.OtherClassWithAttributes" should only have attributes "AttributeNamespace.UnusedAttribute" Result: False Description: AttributeNamespace.ClassWithAttributes does have attribute AttributeNamespace.Attribute1 and AttributeNamespace.Attribute2 diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.OnlyHaveAttributesThatTest.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.OnlyHaveAttributesThatTest.verified.txt index dc972841d..4643ef533 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.OnlyHaveAttributesThatTest.verified.txt +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.OnlyHaveAttributesThatTest.verified.txt @@ -1,6 +1,6 @@ ===== No violations ===== -Query: Types that are "AttributeNamespace.ClassWithSingleAttribute" should only have attributes that have full name "AttributeNamespace.Attribute1" +Query: Types that are "AttributeNamespace.ClassWithSingleAttribute" should only have attributes that are "AttributeNamespace.Attribute1" Result: True Description: AttributeNamespace.ClassWithSingleAttribute passed Message: @@ -8,11 +8,11 @@ All Evaluations passed ===== Violations ===== -Query: Types that are "AttributeNamespace.ClassWithSingleAttribute" should only have attributes that have full name "AttributeNamespace.UnusedAttribute" +Query: Types that are "AttributeNamespace.ClassWithSingleAttribute" should only have attributes that are "AttributeNamespace.UnusedAttribute" Result: False Description: AttributeNamespace.ClassWithSingleAttribute does have attribute AttributeNamespace.Attribute1 Message: -"Types that are "AttributeNamespace.ClassWithSingleAttribute" should only have attributes that have full name "AttributeNamespace.UnusedAttribute"" failed: +"Types that are "AttributeNamespace.ClassWithSingleAttribute" should only have attributes that are "AttributeNamespace.UnusedAttribute"" failed: AttributeNamespace.ClassWithSingleAttribute does have attribute AttributeNamespace.Attribute1 From 9740af71f2dd79a40578ce6b3ea0000ff0cf9801 Mon Sep 17 00:00:00 2001 From: Fritz Brandhuber Date: Fri, 7 Feb 2025 17:56:25 +0100 Subject: [PATCH 3/7] fix wrong implementation of NotHaveDependencyInMethodBodyTo(IEnumerable types), which was equal to HaveDependencyInMethodBodyTo(IEnumerable types) Signed-off-by: Fritz Brandhuber --- .../MethodMemberConditionsDefinition.cs | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberConditionsDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberConditionsDefinition.cs index e0beab35f..7a606f650 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberConditionsDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberConditionsDefinition.cs @@ -775,7 +775,7 @@ IEnumerable types IEnumerable Condition(IEnumerable methodMembers) { var methodMemberList = methodMembers.ToList(); - var passedObjects = methodMemberList + var failedObjects = methodMemberList .Where(methodMember => methodMember .GetBodyTypeMemberDependencies() @@ -788,27 +788,27 @@ IEnumerable Condition(IEnumerable methodMembers) if (typeList.IsNullOrEmpty()) { failDescription = - "does not have dependencies in method body to one of no types (always true)"; + "does have dependencies in method body to one of no types (always false)"; } else { failDescription = typeList - .Where(type => !type.Equals(firstType)) + .Where(type => !Equals(type, firstType)) .Distinct() .Aggregate( - "does not have dependencies in method body to \"" - + firstType.FullName - + "\"", + "does have dependencies in method body to \"" + + firstType.FullName + + "\"", (current, type) => current + " or \"" + type.FullName + "\"" ); } - foreach (var failedObject in methodMemberList.Except(passedObjects)) + foreach (var failedObject in failedObjects) { yield return new ConditionResult(failedObject, false, failDescription); } - foreach (var passedObject in passedObjects) + foreach (var passedObject in methodMemberList.Except(failedObjects)) { yield return new ConditionResult(passedObject, true); } @@ -817,15 +817,16 @@ IEnumerable Condition(IEnumerable methodMembers) string description; if (typeList.IsNullOrEmpty()) { - description = "have dependencies in method body to one of no types (always false)"; + description = + "not have dependencies in method body to one of no types (always true)"; } else { description = typeList - .Where(type => !type.Equals(firstType)) + .Where(type => !Equals(type, firstType)) .Distinct() .Aggregate( - "have dependencies in method body to \"" + firstType.FullName + "\"", + "not have dependencies in method body to \"" + firstType.FullName + "\"", (current, type) => current + " or \"" + type.FullName + "\"" ); } From 2654588b6832b0e95cfe3ad478ec11ad5be5907c Mon Sep 17 00:00:00 2001 From: Fritz Brandhuber Date: Mon, 10 Mar 2025 22:07:28 +0100 Subject: [PATCH 4/7] Replaced all occurences where useRegularExpressions was used as a method parameter to change between string equality checks and regex matching by two separate methods. Removed some more redundant methods in the Fluent API with strings as arguments, that can be replaced by equivalent expressions by invoking the method with an IObjectProvider created by the fluent syntax. Signed-off-by: Fritz Brandhuber --- .../Domain/Extensions/AttributeExtensions.cs | 37 +- .../Domain/Extensions/DependencyExtensions.cs | 46 ++- .../Domain/Extensions/MemberExtensions.cs | 51 ++- .../Domain/Extensions/NamingExtensions.cs | 38 +- .../Domain/Extensions/TypeExtensions.cs | 86 +++- .../PlantUml/Export/DependencyFilters.cs | 26 -- .../Import/ClassDiagramAssociation.cs | 2 +- .../Syntax/Elements/GivenObjectsThat.cs | 63 +-- .../Syntax/Elements/IObjectConditions.cs | 12 +- .../Syntax/Elements/IObjectPredicates.cs | 12 +- .../MethodMemberConditionsDefinition.cs | 8 +- .../MethodMemberPredicatesDefinition.cs | 8 +- .../Elements/ObjectConditionsDefinition.cs | 87 ++-- .../Elements/ObjectPredicatesDefinition.cs | 389 ++---------------- .../Fluent/Syntax/Elements/ObjectsShould.cs | 71 ++-- .../Elements/ShouldRelateToObjectsThat.cs | 67 +-- .../Syntax/Elements/Types/GivenTypesThat.cs | 73 ++-- .../Syntax/Elements/Types/ITypeConditions.cs | 12 +- .../Syntax/Elements/Types/ITypePredicates.cs | 12 +- .../Elements/Types/ShouldRelateToTypesThat.cs | 70 ++-- .../Types/TypeConditionsDefinition.cs | 87 ++-- .../Types/TypePredicatesDefinition.cs | 80 ++-- .../Syntax/Elements/Types/TypesShould.cs | 66 +-- .../Dependencies/StringDependenciesTests.cs | 2 + .../Attributes/AttributeDependencyTests.cs | 6 +- .../Domain/Extensions/TypeExtensionTests.cs | 38 +- .../Syntax/Elements/ObjectsShouldTests.cs | 16 +- ArchUnitNETTests/Loader/TypeTests.cs | 3 +- 28 files changed, 685 insertions(+), 783 deletions(-) diff --git a/ArchUnitNET/Domain/Extensions/AttributeExtensions.cs b/ArchUnitNET/Domain/Extensions/AttributeExtensions.cs index 88df21bf6..f2329ca36 100644 --- a/ArchUnitNET/Domain/Extensions/AttributeExtensions.cs +++ b/ArchUnitNET/Domain/Extensions/AttributeExtensions.cs @@ -13,25 +13,44 @@ public static class AttributeExtensions { public static bool HasAttribute( this IHasAttributes a, - string pattern, - bool useRegularExpressions = false + string fullName ) { return a.Attributes.Any(attribute => - attribute.FullNameMatches(pattern, useRegularExpressions) + attribute.FullNameEquals(fullName) + ); + } + + public static bool HasAttributeMatching( + this IHasAttributes a, + string pattern + ) + { + return a.Attributes.Any(attribute => + attribute.FullNameMatches(pattern) ); } public static bool OnlyHasAttributes( this IHasAttributes a, - string pattern, - bool useRegularExpressions = false + string name + ) + { + return a.Attributes.IsNullOrEmpty() + || a.Attributes.All(attribute => + attribute.FullNameEquals(name) + ); + } + + public static bool OnlyHasAttributesMatching( + this IHasAttributes a, + string pattern ) { return a.Attributes.IsNullOrEmpty() - || a.Attributes.All(attribute => - attribute.FullNameMatches(pattern, useRegularExpressions) - ); + || a.Attributes.All(attribute => + attribute.FullNameMatches(pattern) + ); } } -} +} \ No newline at end of file diff --git a/ArchUnitNET/Domain/Extensions/DependencyExtensions.cs b/ArchUnitNET/Domain/Extensions/DependencyExtensions.cs index 565bd218a..c07e91d3c 100644 --- a/ArchUnitNET/Domain/Extensions/DependencyExtensions.cs +++ b/ArchUnitNET/Domain/Extensions/DependencyExtensions.cs @@ -15,12 +15,20 @@ public static class DependencyExtensions { public static bool CallsMethod( this IHasDependencies type, - string pattern, - bool useRegularExpressions = false + string fullName ) { return type.GetCalledMethods() - .Any(member => member.FullNameMatches(pattern, useRegularExpressions)); + .Any(member => member.FullNameEquals(fullName)); + } + + public static bool CallsMethodMatching( + this IHasDependencies type, + string pattern + ) + { + return type.GetCalledMethods() + .Any(member => member.FullNameMatches(pattern)); } public static IEnumerable GetCalledMethods(this IHasDependencies type) @@ -37,24 +45,40 @@ public static IEnumerable GetAccessedFieldMembers(this IHasDependen .Select(dependency => (FieldMember)dependency.TargetMember); } - public static bool DependsOn( + public static bool DependsOnType( + this IHasDependencies c, + string fullName + ) + { + return c.GetTypeDependencies() + .Any(d => d.FullNameEquals(fullName)); + } + + public static bool DependsOnTypeMatching( this IHasDependencies c, - string pattern, - bool useRegularExpressions = false + string pattern ) { return c.GetTypeDependencies() - .Any(d => d.FullNameMatches(pattern, useRegularExpressions)); + .Any(d => d.FullNameMatches(pattern)); } - public static bool OnlyDependsOn( + + public static bool OnlyDependsOnType( + this IHasDependencies c, + string fullName + ) + { + return c.GetTypeDependencies() + .All(d => d.FullNameEquals(fullName)); + } + public static bool OnlyDependsOnTypesMatching( this IHasDependencies c, - string pattern, - bool useRegularExpressions = false + string pattern ) { return c.GetTypeDependencies() - .All(d => d.FullNameMatches(pattern, useRegularExpressions)); + .All(d => d.FullNameMatches(pattern)); } public static IEnumerable GetTypeDependencies(this IHasDependencies c) diff --git a/ArchUnitNET/Domain/Extensions/MemberExtensions.cs b/ArchUnitNET/Domain/Extensions/MemberExtensions.cs index 854eaa0e9..383e827d0 100644 --- a/ArchUnitNET/Domain/Extensions/MemberExtensions.cs +++ b/ArchUnitNET/Domain/Extensions/MemberExtensions.cs @@ -14,11 +14,18 @@ public static class MemberExtensions { public static bool IsDeclaredIn( this IMember member, - string pattern, - bool useRegularExpressions = false + string fullName ) { - return member.DeclaringType.FullNameMatches(pattern, useRegularExpressions); + return member.DeclaringType.FullNameEquals(fullName); + } + + public static bool IsDeclaredInTypeMatching( + this IMember member, + string pattern + ) + { + return member.DeclaringType.FullNameMatches(pattern); } public static bool IsDeclaredIn(this IMember member, IType type) @@ -62,16 +69,27 @@ public static bool HasMethodCallDependencies( return member.GetMethodCallDependencies(getBackwardsDependencies).Any(); } - public static bool IsCalledBy( + public static bool IsCalledByType( + this MethodMember member, + string fullName + ) + { + return member + .GetMethodCallDependencies(true) + .Any(dependency => + dependency.Origin.FullNameEquals(fullName) + ); + } + + public static bool IsCalledByTypeMatching( this MethodMember member, - string pattern, - bool useRegularExpressions = false + string pattern ) { return member .GetMethodCallDependencies(true) .Any(dependency => - dependency.Origin.FullNameMatches(pattern, useRegularExpressions) + dependency.Origin.FullNameMatches(pattern) ); } @@ -83,16 +101,27 @@ public static IEnumerable GetCallingTypes(this MethodMember member) .Distinct(); } - public static bool HasDependencyInMethodBodyTo( + public static bool HasDependencyInMethodBodyToType( + this MethodMember member, + string fullName + ) + { + return member + .GetBodyTypeMemberDependencies() + .Any(dependency => + dependency.Target.FullNameEquals(fullName) + ); + } + + public static bool HasDependencyInMethodBodyToTypeMatching( this MethodMember member, - string pattern, - bool useRegularExpressions = false + string pattern ) { return member .GetBodyTypeMemberDependencies() .Any(dependency => - dependency.Target.FullNameMatches(pattern, useRegularExpressions) + dependency.Target.FullNameMatches(pattern) ); } diff --git a/ArchUnitNET/Domain/Extensions/NamingExtensions.cs b/ArchUnitNET/Domain/Extensions/NamingExtensions.cs index a3d55d4e5..d7cde5f95 100644 --- a/ArchUnitNET/Domain/Extensions/NamingExtensions.cs +++ b/ArchUnitNET/Domain/Extensions/NamingExtensions.cs @@ -43,32 +43,24 @@ public static bool NameContains( return cls.Name.IndexOf(pattern, stringComparison) >= 0; } - public static bool NameMatches( - this IHasName cls, - string pattern, - bool useRegularExpressions = false - ) + public static bool NameEquals(this IHasName cls, string name) { - if (useRegularExpressions) - { - return pattern != null && Regex.IsMatch(cls.Name, pattern); - } - - return string.Equals(cls.Name, pattern, StringComparison.OrdinalIgnoreCase); + return string.Equals(cls.Name, name, StringComparison.OrdinalIgnoreCase); } - public static bool FullNameMatches( - this IHasName cls, - string pattern, - bool useRegularExpressions = false - ) + public static bool NameMatches(this IHasName cls, string pattern) { - if (useRegularExpressions) - { - return pattern != null && Regex.IsMatch(cls.FullName, pattern); - } + return pattern != null && Regex.IsMatch(cls.Name, pattern); + } - return string.Equals(cls.FullName, pattern, StringComparison.OrdinalIgnoreCase); + public static bool FullNameEquals(this IHasName cls, string fullName) + { + return string.Equals(cls.FullName, fullName, StringComparison.OrdinalIgnoreCase); + } + + public static bool FullNameMatches(this IHasName cls, string pattern) + { + return pattern != null && Regex.IsMatch(cls.FullName, pattern); } public static bool FullNameContains(this IHasName cls, string pattern) @@ -96,7 +88,7 @@ public static TType WhereFullNameIs(this IEnumerable source, strin { throw new MultipleOccurrencesInSequenceException( $"Full name {fullName} found multiple times in provided types. Please use extern " - + "alias to reference assemblies that have the same fully-qualified type names." + + "alias to reference assemblies that have the same fully-qualified type names." ); } @@ -115,4 +107,4 @@ string assemblyQualifiedName ); } } -} +} \ No newline at end of file diff --git a/ArchUnitNET/Domain/Extensions/TypeExtensions.cs b/ArchUnitNET/Domain/Extensions/TypeExtensions.cs index 32e2b1f64..07a9c8d6c 100644 --- a/ArchUnitNET/Domain/Extensions/TypeExtensions.cs +++ b/ArchUnitNET/Domain/Extensions/TypeExtensions.cs @@ -27,8 +27,7 @@ public static bool ImplementsInterface(this IType type, Interface intf) public static bool ImplementsInterface( this IType type, - string pattern, - bool useRegularExpressions = false + string fullName ) { if (type is GenericParameter) @@ -37,7 +36,22 @@ public static bool ImplementsInterface( } return type.ImplementedInterfaces.Any(implementedInterface => - implementedInterface.FullNameMatches(pattern, useRegularExpressions) + implementedInterface.FullNameEquals(fullName) + ); + } + + public static bool ImplementsInterfaceMatching( + this IType type, + string pattern + ) + { + if (type is GenericParameter) + { + return false; + } + + return type.ImplementedInterfaces.Any(implementedInterface => + implementedInterface.FullNameMatches(pattern) ); } @@ -55,19 +69,34 @@ public static bool IsAssignableTo(this IType type, IType assignableToType) public static bool IsAssignableTo( this IType type, - string pattern, - bool useRegularExpressions = false + string fullName + ) + { + if (type is GenericParameter genericParameter) + { + return genericParameter.TypeConstraints.All(t => + t.IsAssignableTo(fullName) + ); + } + + return type.GetAssignableTypes() + .Any(t => t.FullNameEquals(fullName)); + } + + public static bool IsAssignableToTypeMatching( + this IType type, + string pattern ) { if (type is GenericParameter genericParameter) { return genericParameter.TypeConstraints.All(t => - t.IsAssignableTo(pattern, useRegularExpressions) + t.IsAssignableTo(pattern) ); } return type.GetAssignableTypes() - .Any(t => t.FullNameMatches(pattern, useRegularExpressions)); + .Any(t => t.FullNameMatches(pattern)); } public static bool IsNestedIn(this IType type, IType assignableToType) @@ -233,34 +262,57 @@ public static Attribute GetAttributeOfType(this IType type, Class attributeClass attribute.FullName.Equals(attributeClass.FullName) ); } - + public static bool ResidesInNamespace( this IType e, - string pattern, - bool useRegularExpressions = false + string fullName + ) + { + return e.Namespace.FullNameEquals(fullName); + } + + public static bool ResidesInNamespaceMatching( + this IType e, + string pattern ) { - return e.Namespace.FullNameMatches(pattern, useRegularExpressions); + return e.Namespace.FullNameMatches(pattern); } public static bool ResidesInAssembly( this IType e, - string pattern, - bool useRegularExpressions = false + string fullName ) { - return e.Assembly.FullNameMatches(pattern, useRegularExpressions); + return e.Assembly.FullNameEquals(fullName); + } + public static bool ResidesInAssemblyMatching( + this IType e, + string pattern + ) + { + return e.Assembly.FullNameMatches(pattern); } public static bool IsDeclaredAsFieldIn( this IType type, - string pattern, - bool useRegularExpressions = false + string fullName + ) + { + return type.GetFieldTypeDependencies(true) + .Any(dependency => + dependency.Target.FullNameEquals(fullName) + ); + } + + public static bool IsDeclaredAsFieldInTypeMatching( + this IType type, + string pattern ) { return type.GetFieldTypeDependencies(true) .Any(dependency => - dependency.Target.FullNameMatches(pattern, useRegularExpressions) + dependency.Target.FullNameMatches(pattern) ); } diff --git a/ArchUnitNET/Domain/PlantUml/Export/DependencyFilters.cs b/ArchUnitNET/Domain/PlantUml/Export/DependencyFilters.cs index 139110fa1..cb4bd24d9 100644 --- a/ArchUnitNET/Domain/PlantUml/Export/DependencyFilters.cs +++ b/ArchUnitNET/Domain/PlantUml/Export/DependencyFilters.cs @@ -57,16 +57,6 @@ public static Func FocusOn(IEnumerable types) }; } - public static Func FocusOn( - string pattern, - bool useRegularExpressions = false - ) - { - return dependency => - dependency.Target.FullNameMatches(pattern, useRegularExpressions) - ^ dependency.Origin.FullNameMatches(pattern, useRegularExpressions); - } - public static Func HasOrigin(IType type) { return dependency => dependency.Origin.Equals(type); @@ -77,14 +67,6 @@ public static Func HasOrigin(IEnumerable types) return dependency => types.Contains(dependency.Origin); } - public static Func HasOrigin( - string pattern, - bool useRegularExpressions = false - ) - { - return dependency => dependency.Origin.FullNameMatches(pattern, useRegularExpressions); - } - public static Func HasTarget(IType type) { return dependency => dependency.Target.Equals(type); @@ -94,13 +76,5 @@ public static Func HasTarget(IEnumerable types) { return dependency => types.Contains(dependency.Target); } - - public static Func HasTarget( - string pattern, - bool useRegularExpressions = false - ) - { - return dependency => dependency.Target.FullNameMatches(pattern, useRegularExpressions); - } } } diff --git a/ArchUnitNET/Domain/PlantUml/Import/ClassDiagramAssociation.cs b/ArchUnitNET/Domain/PlantUml/Import/ClassDiagramAssociation.cs index 44f949564..178994f5c 100644 --- a/ArchUnitNET/Domain/PlantUml/Import/ClassDiagramAssociation.cs +++ b/ArchUnitNET/Domain/PlantUml/Import/ClassDiagramAssociation.cs @@ -145,7 +145,7 @@ public bool Contains(IType clazz) { foreach (Stereotype stereotype in _component.Stereotypes) { - if (clazz.ResidesInNamespace(stereotype.AsString(), true)) + if (clazz.ResidesInNamespaceMatching(stereotype.AsString())) { return true; } diff --git a/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsThat.cs index c4ce3fee0..8f0f022d8 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsThat.cs @@ -426,24 +426,34 @@ public TGivenRuleTypeConjunction HaveAttributeWithNamedArguments( return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveName( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public TGivenRuleTypeConjunction HaveName(string name) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.HaveName(pattern, useRegularExpressions) + ObjectPredicatesDefinition.HaveName(name) + ); + return Create(_ruleCreator); + } + + public TGivenRuleTypeConjunction HaveNameMatching(string pattern) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveNameMatching(pattern) ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveFullName( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public TGivenRuleTypeConjunction HaveFullName(string fullName) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.HaveFullName(pattern, useRegularExpressions) + ObjectPredicatesDefinition.HaveFullName(fullName) + ); + return Create(_ruleCreator); + } + + public TGivenRuleTypeConjunction HaveFullNameMatching(string pattern) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveFullNameMatching(pattern) ); return Create(_ruleCreator); } @@ -830,27 +840,34 @@ public TGivenRuleTypeConjunction DoNotHaveAttributeWithNamedArguments( return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveName( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public TGivenRuleTypeConjunction DoNotHaveName(string name) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.DoNotHaveName(pattern, useRegularExpressions) + ObjectPredicatesDefinition.DoNotHaveName(name) + ); + return Create(_ruleCreator); + } + + public TGivenRuleTypeConjunction DoNotHaveNameMatching(string pattern) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveNameMatching(pattern) ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveFullName( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public TGivenRuleTypeConjunction DoNotHaveFullName(string fullName) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.DoNotHaveFullName( - pattern, - useRegularExpressions - ) + ObjectPredicatesDefinition.DoNotHaveFullName(fullName) + ); + return Create(_ruleCreator); + } + + public TGivenRuleTypeConjunction DoNotHaveFullNameMatching(string pattern) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveFullNameMatching(pattern) ); return Create(_ruleCreator); } diff --git a/ArchUnitNET/Fluent/Syntax/Elements/IObjectConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/IObjectConditions.cs index 6804b928a..a449c8154 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/IObjectConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/IObjectConditions.cs @@ -97,8 +97,10 @@ TReturnType HaveAttributeWithNamedArguments( (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments ); - TReturnType HaveName(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations - TReturnType HaveFullName(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations + TReturnType HaveName(string name); + TReturnType HaveNameMatching(string pattern); + TReturnType HaveFullName(string fullName); + TReturnType HaveFullNameMatching(string pattern); TReturnType HaveNameStartingWith(string pattern); TReturnType HaveNameEndingWith(string pattern); TReturnType HaveNameContaining(string pattern); @@ -181,8 +183,10 @@ TReturnType NotHaveAttributeWithNamedArguments( (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments ); - TReturnType NotHaveName(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations - TReturnType NotHaveFullName(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations + TReturnType NotHaveName(string name); + TReturnType NotHaveNameMatching(string pattern); + TReturnType NotHaveFullName(string fullName); + TReturnType NotHaveFullNameMatching(string pattern); TReturnType NotHaveNameStartingWith(string pattern); TReturnType NotHaveNameEndingWith(string pattern); TReturnType NotHaveNameContaining(string pattern); diff --git a/ArchUnitNET/Fluent/Syntax/Elements/IObjectPredicates.cs b/ArchUnitNET/Fluent/Syntax/Elements/IObjectPredicates.cs index a2b139aa2..ada65d2c8 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/IObjectPredicates.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/IObjectPredicates.cs @@ -88,8 +88,10 @@ TReturnType HaveAttributeWithNamedArguments( (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments ); - TReturnType HaveName(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations - TReturnType HaveFullName(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations + TReturnType HaveName(string name); + TReturnType HaveNameMatching(string pattern); + TReturnType HaveFullName(string fullName); + TReturnType HaveFullNameMatching(string pattern); TReturnType HaveNameStartingWith(string pattern); TReturnType HaveNameEndingWith(string pattern); TReturnType HaveNameContaining(string pattern); @@ -170,8 +172,10 @@ TReturnType DoNotHaveAttributeWithNamedArguments( (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments ); - TReturnType DoNotHaveName(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations - TReturnType DoNotHaveFullName(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations + TReturnType DoNotHaveName(string name); + TReturnType DoNotHaveNameMatching(string pattern); + TReturnType DoNotHaveFullName(string fullName); + TReturnType DoNotHaveFullNameMatching(string pattern); TReturnType DoNotHaveNameStartingWith(string pattern); TReturnType DoNotHaveNameEndingWith(string pattern); TReturnType DoNotHaveNameContaining(string pattern); diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberConditionsDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberConditionsDefinition.cs index 7a606f650..f25640819 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberConditionsDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberConditionsDefinition.cs @@ -434,7 +434,7 @@ public static ICondition HaveReturnType(IEnumerable types) bool Condition(MethodMember member) { - return typeList.Any(type => member.ReturnType.FullNameMatches(type.FullName)); + return typeList.Any(type => member.ReturnType.FullNameEquals(type.FullName)); } return new SimpleCondition( @@ -455,7 +455,7 @@ Architecture architecture var methodMemberList = methodMembers.ToList(); var passedObjects = methodMemberList .Where(methodMember => - typeList.Any(type => methodMember.ReturnType.FullNameMatches(type.FullName)) + typeList.Any(type => methodMember.ReturnType.FullNameEquals(type.FullName)) ) .ToList(); foreach (var failedObject in methodMemberList.Except(passedObjects)) @@ -938,7 +938,7 @@ public static ICondition NotHaveReturnType(IEnumerable type bool Condition(MethodMember member) { - return typeList.All(type => !member.ReturnType.FullNameMatches(type.FullName)); + return typeList.All(type => !member.ReturnType.FullNameEquals(type.FullName)); } return new SimpleCondition( @@ -960,7 +960,7 @@ Architecture architecture var passedObjects = methodMemberList .Where(methodMember => typeList.All(type => - !methodMember.ReturnType.FullNameMatches(type.FullName) + !methodMember.ReturnType.FullNameEquals(type.FullName) ) ) .ToList(); diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberPredicatesDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberPredicatesDefinition.cs index cc673e801..498e1f6e6 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberPredicatesDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberPredicatesDefinition.cs @@ -283,7 +283,7 @@ public static IPredicate HaveReturnType(IEnumerable types) "have return type \"" + string.Join("\" or \"", typeStringList) + "\""; return new SimplePredicate( - member => typeList.Any(type => member.ReturnType.FullNameMatches(type.FullName)), + member => typeList.Any(type => member.ReturnType.FullNameEquals(type.FullName)), description ); } @@ -298,7 +298,7 @@ Architecture architecture var typeList = types.GetObjects(architecture).ToList(); var methodMemberList = methodMembers.ToList(); return methodMemberList.Where(methodMember => - typeList.Any(type => methodMember.ReturnType.FullNameMatches(type.FullName)) + typeList.Any(type => methodMember.ReturnType.FullNameEquals(type.FullName)) ); } @@ -610,7 +610,7 @@ public static IPredicate DoNotHaveReturnType(IEnumerable ty "do not have return type \"" + string.Join("\" or \"", typeStringList) + "\""; return new SimplePredicate( - member => typeList.Any(type => !member.ReturnType.FullNameMatches(type.FullName)), + member => typeList.Any(type => !member.ReturnType.FullNameEquals(type.FullName)), description ); } @@ -625,7 +625,7 @@ Architecture architecture var typeList = types.GetObjects(architecture).ToList(); var methodMemberList = methodMembers.ToList(); return methodMemberList.Where(methodMember => - typeList.All(type => !methodMember.ReturnType.FullNameMatches(type.FullName)) + typeList.All(type => !methodMember.ReturnType.FullNameEquals(type.FullName)) ); } diff --git a/ArchUnitNET/Fluent/Syntax/Elements/ObjectConditionsDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/ObjectConditionsDefinition.cs index 9107e9b30..28cb5abe2 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/ObjectConditionsDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/ObjectConditionsDefinition.cs @@ -1514,35 +1514,36 @@ bool Condition(TRuleType obj, Architecture architecture) return new ArchitectureCondition(Condition, description, failDescription); } - public static ICondition HaveName( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public static ICondition HaveName(string name) { return new SimpleCondition( - obj => obj.NameMatches(pattern, useRegularExpressions), + obj => obj.NameEquals(name), obj => "does have name " + obj.Name, - "have full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); + $"have name \"{name}\""); + } + + public static ICondition HaveNameMatching(string pattern) + { + return new SimpleCondition( + obj => obj.NameMatches(pattern), + obj => "does have name " + obj.Name, + $"have name matching \"{pattern}\""); } - public static ICondition HaveFullName( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public static ICondition HaveFullName(string name) { return new SimpleCondition( - obj => obj.FullNameMatches(pattern, useRegularExpressions), + obj => obj.FullNameEquals(name), obj => "does have full name " + obj.FullName, - "have full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" + "have full name \"" + name + "\"" + ); + } + public static ICondition HaveFullNameMatching(string pattern) + { + return new SimpleCondition( + obj => obj.FullNameMatches(pattern), + obj => "does have full name " + obj.FullName, + "have full name matching \"" + pattern + "\"" ); } @@ -2821,35 +2822,41 @@ bool Condition(TRuleType obj, Architecture architecture) return new ArchitectureCondition(Condition, failDescription, description); } - public static ICondition NotHaveName( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public static ICondition NotHaveName(string name) { return new SimpleCondition( - obj => !obj.NameMatches(pattern, useRegularExpressions), + obj => !obj.NameEquals(name), obj => "does have name " + obj.Name, - "not have name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" + $"not have name \"{name}\"" + ); + } + public static ICondition NotHaveNameMatching(string pattern) + { + return new SimpleCondition( + obj => !obj.NameMatches(pattern), + obj => "does have name " + obj.Name, + $"not have name matching \"{pattern}\"" ); } public static ICondition NotHaveFullName( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + string fullName + ) + { + return new SimpleCondition( + obj => !obj.FullNameEquals(fullName), + obj => "does have full name " + obj.FullName, + "not have full name \"" + fullName + "\"" + ); + } + public static ICondition NotHaveFullNameMatching( + string pattern + ) { return new SimpleCondition( - obj => !obj.FullNameMatches(pattern, useRegularExpressions), + obj => !obj.FullNameMatches(pattern), obj => "does have full name " + obj.FullName, - "not have full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" + "not have full name matching \"" + pattern + "\"" ); } diff --git a/ArchUnitNET/Fluent/Syntax/Elements/ObjectPredicatesDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/ObjectPredicatesDefinition.cs index 08a75cbc0..11bfc823a 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/ObjectPredicatesDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/ObjectPredicatesDefinition.cs @@ -20,52 +20,6 @@ namespace ArchUnitNET.Fluent.Syntax.Elements public static class ObjectPredicatesDefinition where T : ICanBeAnalyzed { - public static IPredicate Are(string pattern, bool useRegularExpressions = false) - { - return new SimplePredicate( - obj => obj.FullNameMatches(pattern, useRegularExpressions), - "have full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static IPredicate Are( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - string description; - if (patternList.IsNullOrEmpty()) - { - description = "not exist (impossible)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(pattern => !pattern.Equals(firstPattern)) - .Distinct() - .Aggregate( - "have full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimplePredicate( - obj => - patternList.Any(pattern => obj.FullNameMatches(pattern, useRegularExpressions)), - description - ); - } - public static IPredicate Are( ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects @@ -117,54 +71,6 @@ IEnumerable Filter(IEnumerable objects, Architecture architecture) return new ArchitecturePredicate(Filter, "are " + objectProvider.Description); } - public static IPredicate CallAny(string pattern, bool useRegularExpressions = false) - { - return new SimplePredicate( - obj => obj.CallsMethod(pattern, useRegularExpressions), - "calls any method with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static IPredicate CallAny( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Filter(T type) - { - return patternList.Any(method => type.CallsMethod(method)); - } - - string description; - if (patternList.IsNullOrEmpty()) - { - description = "call one of no methods (impossible)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(pattern => !pattern.Equals(firstPattern)) - .Distinct() - .Aggregate( - "call any method with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimplePredicate(Filter, description); - } - public static IPredicate CallAny(MethodMember method, params MethodMember[] moreMethods) { var methods = new List { method }; @@ -212,60 +118,7 @@ IEnumerable Filter(IEnumerable objects) return new EnumerablePredicate(Filter, description); } - - public static IPredicate DependOnAny(string pattern, bool useRegularExpressions = false) - { - return new SimplePredicate( - obj => obj.DependsOn(pattern, useRegularExpressions), - "depend on any types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static IPredicate DependOnAny( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Filter(T type) - { - return type.GetTypeDependencies() - .Any(target => - patternList.Any(pattern => - target.FullNameMatches(pattern, useRegularExpressions) - ) - ); - } - - string description; - if (patternList.IsNullOrEmpty()) - { - description = "have no dependencies"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(pattern => !pattern.Equals(firstPattern)) - .Distinct() - .Aggregate( - "depend on any types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimplePredicate(Filter, description); - } - + public static IPredicate DependOnAny(IType firstType, params IType[] moreTypes) { var types = new List { firstType }; @@ -373,60 +226,7 @@ string description { return new SimplePredicate(predicate, description); } - - public static IPredicate OnlyDependOn(string pattern, bool useRegularExpressions = false) - { - return new SimplePredicate( - obj => obj.OnlyDependsOn(pattern, useRegularExpressions), - "only depend on types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static IPredicate OnlyDependOn( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Filter(T type) - { - return type.GetTypeDependencies() - .All(target => - patternList.Any(pattern => - target.FullNameMatches(pattern, useRegularExpressions) - ) - ); - } - - string description; - if (patternList.IsNullOrEmpty()) - { - description = "have no dependencies"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(pattern => !pattern.Equals(firstPattern)) - .Distinct() - .Aggregate( - "only depend on types with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimplePredicate(Filter, description); - } - + public static IPredicate OnlyDependOn(IType firstType, params IType[] moreTypes) { var types = new List { firstType }; @@ -530,62 +330,7 @@ IEnumerable Filter(IEnumerable objects, Architecture architecture) return new ArchitecturePredicate(Filter, description); } - - public static IPredicate HaveAnyAttributes( - string pattern, - bool useRegularExpressions = false - ) - { - return new SimplePredicate( - obj => obj.HasAttribute(pattern, useRegularExpressions), - "have any attribute with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static IPredicate HaveAnyAttributes( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Filter(T type) - { - return type.Attributes.Any(attribute => - patternList.Any(pattern => - attribute.FullNameMatches(pattern, useRegularExpressions) - ) - ); - } - - string description; - if (patternList.IsNullOrEmpty()) - { - description = "have one of no attributes (impossible)"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(pattern => !pattern.Equals(firstPattern)) - .Distinct() - .Aggregate( - "have any attribute with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimplePredicate(Filter, description); - } - + public static IPredicate HaveAnyAttributes( Attribute firstAttribute, params Attribute[] moreAttributes @@ -677,62 +422,6 @@ IEnumerable Filter(IEnumerable objects, Architecture architecture) return new ArchitecturePredicate(Filter, description); } - public static IPredicate OnlyHaveAttributes( - string pattern, - bool useRegularExpressions = false - ) - { - return new SimplePredicate( - obj => obj.OnlyHasAttributes(pattern, useRegularExpressions), - "only have attributes with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" - ); - } - - public static IPredicate OnlyHaveAttributes( - IEnumerable patterns, - bool useRegularExpressions = false - ) - { - var patternList = patterns.ToList(); - - bool Filter(T type) - { - return type.Attributes.IsNullOrEmpty() - || type.Attributes.All(attribute => - patternList.Any(pattern => - attribute.FullNameMatches(pattern, useRegularExpressions) - ) - ); - } - - string description; - if (patternList.IsNullOrEmpty()) - { - description = "have no attributes"; - } - else - { - var firstPattern = patternList.First(); - description = patternList - .Where(pattern => !pattern.Equals(firstPattern)) - .Distinct() - .Aggregate( - "only have attributes with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + firstPattern - + "\"", - (current, pattern) => current + " or \"" + pattern + "\"" - ); - } - - return new SimplePredicate(Filter, description); - } - public static IPredicate OnlyHaveAttributes( Attribute firstAttribute, params Attribute[] moreAttributes @@ -1334,23 +1023,33 @@ bool Predicate(T obj, Architecture architecture) return new ArchitecturePredicate(Predicate, description); } - public static IPredicate HaveName(string pattern, bool useRegularExpressions = false) //TODO split into multiple implementations + public static IPredicate HaveName(string name) + { + return new SimplePredicate( + obj => obj.NameEquals(name), + "have name \"" + name + "\"" + ); + } + public static IPredicate HaveNameMatching(string pattern) { return new SimplePredicate( - obj => obj.NameMatches(pattern, useRegularExpressions), - "have name " + (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\"" + obj => obj.NameMatches(pattern), + "have name matching \"" + pattern + "\"" ); } - public static IPredicate HaveFullName(string pattern, bool useRegularExpressions = false) //TODO split into multiple implementations + public static IPredicate HaveFullName(string fullName) { return new SimplePredicate( - obj => obj.FullNameMatches(pattern, useRegularExpressions), - "have full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" + obj => obj.FullNameEquals(fullName), + "have full name \"" + fullName + "\"" + ); + } + public static IPredicate HaveFullNameMatching(string pattern) + { + return new SimplePredicate( + obj => obj.FullNameMatches(pattern), + "have full name matching \"" + pattern + "\"" ); } @@ -2229,36 +1928,38 @@ bool Predicate(T obj, Architecture architecture) return new ArchitecturePredicate(Predicate, description); } - public static IPredicate DoNotHaveName( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public static IPredicate DoNotHaveName(string name) + { + return new SimplePredicate( + obj => !obj.NameEquals(name), + $"do not have name \"{name}\"" + ); + } + + public static IPredicate DoNotHaveNameMatching(string pattern) { return new SimplePredicate( - obj => !obj.NameMatches(pattern, useRegularExpressions), - "do not have name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" + obj => !obj.NameMatches(pattern), + $"do not have name matching \"{pattern}\"" ); } - public static IPredicate DoNotHaveFullName( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public static IPredicate DoNotHaveFullName(string fullName) { return new SimplePredicate( - obj => !obj.FullNameMatches(pattern, useRegularExpressions), - "do not have full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" + obj => !obj.FullNameEquals(fullName), + "do not have full name \"" + fullName + "\"" ); } + public static IPredicate DoNotHaveFullNameMatching(string pattern) + { + return new SimplePredicate( + obj => !obj.FullNameMatches(pattern), + "do not have full name matching \"" + pattern + "\"" + ); + } + public static IPredicate DoNotHaveNameStartingWith(string pattern) { return new SimplePredicate( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShould.cs b/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShould.cs index 70d3a384d..cd2af7150 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShould.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShould.cs @@ -23,7 +23,9 @@ public abstract class ObjectsShould where TRuleTypeShouldConjunction : SyntaxElement { protected ObjectsShould(IArchRuleCreator ruleCreator) - : base(ruleCreator) { } + : base(ruleCreator) + { + } public TRuleTypeShouldConjunction Exist() { @@ -453,24 +455,34 @@ public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveName( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public TRuleTypeShouldConjunction HaveName(string name) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.HaveName(name) + ); + return Create(_ruleCreator); + } + + public TRuleTypeShouldConjunction HaveNameMatching(string pattern) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.HaveNameMatching(pattern) + ); + return Create(_ruleCreator); + } + + public TRuleTypeShouldConjunction HaveFullName(string fullName) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveName(pattern, useRegularExpressions) + ObjectConditionsDefinition.HaveFullName(fullName) ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveFullName( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public TRuleTypeShouldConjunction HaveFullNameMatching(string pattern) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveFullName(pattern, useRegularExpressions) + ObjectConditionsDefinition.HaveFullNameMatching(pattern) ); return Create(_ruleCreator); } @@ -635,7 +647,7 @@ public TRuleTypeShouldConjunction NotBe(IObjectProvider objects) _ruleCreator.AddCondition(ObjectConditionsDefinition.NotBe(objects)); return Create(_ruleCreator); } - + public TRuleTypeShouldConjunction NotCallAny( MethodMember method, params MethodMember[] moreMethods @@ -919,27 +931,34 @@ public TRuleTypeShouldConjunction NotHaveAttributeWithNamedArguments( return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotHaveName( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public TRuleTypeShouldConjunction NotHaveName(string name) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveName(pattern, useRegularExpressions) + ObjectConditionsDefinition.NotHaveName(name) ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotHaveFullName( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public TRuleTypeShouldConjunction NotHaveNameMatching(string pattern) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveFullName( - pattern, - useRegularExpressions - ) + ObjectConditionsDefinition.NotHaveNameMatching(pattern) + ); + return Create(_ruleCreator); + } + + public TRuleTypeShouldConjunction NotHaveFullName(string fullName) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotHaveFullName(fullName) + ); + return Create(_ruleCreator); + } + + public TRuleTypeShouldConjunction NotHaveFullNameMatching(string pattern) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotHaveFullNameMatching(pattern) ); return Create(_ruleCreator); } @@ -1047,4 +1066,4 @@ public ShouldRelateToAttributesThat< ); } } -} +} \ No newline at end of file diff --git a/ArchUnitNET/Fluent/Syntax/Elements/ShouldRelateToObjectsThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/ShouldRelateToObjectsThat.cs index 2e0cfc1f1..4e84c4f16 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/ShouldRelateToObjectsThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/ShouldRelateToObjectsThat.cs @@ -454,27 +454,32 @@ public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveName( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public TRuleTypeShouldConjunction HaveName(string name) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveName(pattern, useRegularExpressions) + ObjectPredicatesDefinition.HaveName(name) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction HaveNameMatching(string pattern) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.HaveNameMatching(pattern) ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveFullName( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public TRuleTypeShouldConjunction HaveFullName(string fullName) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveFullName( - pattern, - useRegularExpressions - ) + ObjectPredicatesDefinition.HaveFullName(fullName) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction HaveFullNameMatching(string pattern) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.HaveFullNameMatching(pattern) ); return Create(_ruleCreator); } @@ -884,30 +889,32 @@ public TRuleTypeShouldConjunction DoNotHaveAttributeWithNamedArguments( return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveName( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public TRuleTypeShouldConjunction DoNotHaveName(string name) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveName( - pattern, - useRegularExpressions - ) + ObjectPredicatesDefinition.DoNotHaveName(name) ); return Create(_ruleCreator); - } //TODO split into multiple implementations + } + public TRuleTypeShouldConjunction DoNotHaveNameMatching(string pattern) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.DoNotHaveName(pattern) + ); + return Create(_ruleCreator); + } - public TRuleTypeShouldConjunction DoNotHaveFullName( - string pattern, - bool useRegularExpressions = false - ) + public TRuleTypeShouldConjunction DoNotHaveFullName(string fullName) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveFullName( - pattern, - useRegularExpressions - ) + ObjectPredicatesDefinition.DoNotHaveFullName(fullName) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction DoNotHaveFullNameMatching(string pattern) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.DoNotHaveFullNameMatching(pattern) ); return Create(_ruleCreator); } diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesThat.cs index c2a385640..debbdca3f 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesThat.cs @@ -19,7 +19,9 @@ public class GivenTypesThat { // ReSharper disable once MemberCanBeProtected.Global public GivenTypesThat(IArchRuleCreator ruleCreator) - : base(ruleCreator) { } + : base(ruleCreator) + { + } public TGivenRuleTypeConjunction Are(Type firstType, params Type[] moreTypes) { @@ -133,27 +135,34 @@ public TGivenRuleTypeConjunction ImplementInterface(Type intf) return Create(_ruleCreator); } - public TGivenRuleTypeConjunction ResideInNamespace( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public TGivenRuleTypeConjunction ResideInNamespace(string fullName) { _ruleCreator.AddPredicate( - TypePredicatesDefinition.ResideInNamespace( - pattern, - useRegularExpressions - ) + TypePredicatesDefinition.ResideInNamespace(fullName) ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction ResideInAssembly( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public TGivenRuleTypeConjunction ResideInNamespaceMatching(string pattern) + { + _ruleCreator.AddPredicate( + TypePredicatesDefinition.ResideInNamespace(pattern) + ); + return Create(_ruleCreator); + } + + public TGivenRuleTypeConjunction ResideInAssembly(string fullName) + { + _ruleCreator.AddPredicate( + TypePredicatesDefinition.ResideInAssembly(fullName) + ); + return Create(_ruleCreator); + } + + public TGivenRuleTypeConjunction ResideInAssemblyMatching(string pattern) { _ruleCreator.AddPredicate( - TypePredicatesDefinition.ResideInAssembly(pattern, useRegularExpressions) + TypePredicatesDefinition.ResideInAssemblyMatching(pattern) ); return Create(_ruleCreator); } @@ -310,30 +319,32 @@ public TGivenRuleTypeConjunction DoNotImplementInterface(Type intf) return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotResideInNamespace( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public TGivenRuleTypeConjunction DoNotResideInNamespace(string fullName) + { + _ruleCreator.AddPredicate( + TypePredicatesDefinition.DoNotResideInNamespace(fullName) + ); + return Create(_ruleCreator); + } + + public TGivenRuleTypeConjunction DoNotResideInNamespaceMatching(string pattern) { _ruleCreator.AddPredicate( - TypePredicatesDefinition.DoNotResideInNamespace( - pattern, - useRegularExpressions - ) + TypePredicatesDefinition.DoNotResideInNamespaceMatching(pattern) ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotResideInAssembly( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public TGivenRuleTypeConjunction DoNotResideInAssembly(string fullName) { _ruleCreator.AddPredicate( - TypePredicatesDefinition.DoNotResideInAssembly( - pattern, - useRegularExpressions - ) + TypePredicatesDefinition.DoNotResideInAssembly(fullName) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction DoNotResideInAssemblyMatching(string pattern){ + _ruleCreator.AddPredicate( + TypePredicatesDefinition.DoNotResideInAssemblyMatching(pattern) ); return Create(_ruleCreator); } @@ -398,4 +409,4 @@ public TGivenRuleTypeConjunction AreNotNested() return Create(_ruleCreator); } } -} +} \ No newline at end of file diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypeConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypeConditions.cs index 6595cc07c..840e9160b 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypeConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypeConditions.cs @@ -27,8 +27,10 @@ public interface ITypeConditions TReturnType BeStructs(); TReturnType ImplementInterface(Interface intf); TReturnType ImplementInterface(Type intf); - TReturnType ResideInNamespace(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations - TReturnType ResideInAssembly(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations + TReturnType ResideInNamespace(string fullName); + TReturnType ResideInNamespaceMatching(string pattern); + TReturnType ResideInAssembly(string fullName); + TReturnType ResideInAssemblyMatching(string pattern); TReturnType ResideInAssembly(Assembly assembly, params Assembly[] moreAssemblies); TReturnType ResideInAssembly( Domain.Assembly assembly, @@ -55,8 +57,10 @@ params Domain.Assembly[] moreAssemblies TReturnType NotBeStructs(); TReturnType NotImplementInterface(Interface intf); TReturnType NotImplementInterface(Type intf); - TReturnType NotResideInNamespace(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations - TReturnType NotResideInAssembly(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations + TReturnType NotResideInNamespace(string fullName); + TReturnType NotResideInNamespaceMatching(string pattern); + TReturnType NotResideInAssembly(string fullName); + TReturnType NotResideInAssemblyMatching(string pattern); TReturnType NotResideInAssembly(Assembly assembly, params Assembly[] moreAssemblies); TReturnType NotResideInAssembly( Domain.Assembly assembly, diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypePredicates.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypePredicates.cs index 30157fa90..6eed12213 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypePredicates.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypePredicates.cs @@ -27,8 +27,10 @@ public interface ITypePredicates TReturnType AreStructs(); TReturnType ImplementInterface(Interface intf); TReturnType ImplementInterface(Type intf); - TReturnType ResideInNamespace(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations - TReturnType ResideInAssembly(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations + TReturnType ResideInNamespace(string fullName); + TReturnType ResideInNamespaceMatching(string pattern); + TReturnType ResideInAssembly(string fullName); + TReturnType ResideInAssemblyMatching(string pattern); TReturnType ResideInAssembly(Assembly assembly, params Assembly[] moreAssemblies); TReturnType ResideInAssembly( Domain.Assembly assembly, @@ -55,8 +57,10 @@ params Domain.Assembly[] moreAssemblies TReturnType AreNotStructs(); TReturnType DoNotImplementInterface(Interface intf); TReturnType DoNotImplementInterface(Type intf); - TReturnType DoNotResideInNamespace(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations - TReturnType DoNotResideInAssembly(string pattern, bool useRegularExpressions = false); //TODO split into multiple implementations + TReturnType DoNotResideInNamespace(string fullName); + TReturnType DoNotResideInNamespaceMatching(string pattern); + TReturnType DoNotResideInAssembly(string fullName); + TReturnType DoNotResideInAssemblyMatching(string pattern); TReturnType DoNotResideInAssembly(Assembly assembly, params Assembly[] moreAssemblies); TReturnType DoNotResideInAssembly( Domain.Assembly assembly, diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/ShouldRelateToTypesThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/ShouldRelateToTypesThat.cs index 7777fec20..b3ddb95a5 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/ShouldRelateToTypesThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/ShouldRelateToTypesThat.cs @@ -158,33 +158,37 @@ public TRuleTypeShouldConjunction ImplementInterface(Type intf) return Create(_ruleCreator); } - public TRuleTypeShouldConjunction ResideInNamespace( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public TRuleTypeShouldConjunction ResideInNamespace(string fullName) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.ResideInNamespace( - pattern, - useRegularExpressions - ) + TypePredicatesDefinition.ResideInNamespace(fullName) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction ResideInNamespaceMatching(string pattern) + { + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.ResideInNamespaceMatching(pattern) ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction ResideInAssembly( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public TRuleTypeShouldConjunction ResideInAssembly(string fullName) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.ResideInAssembly( - pattern, - useRegularExpressions - ) + TypePredicatesDefinition.ResideInAssembly(fullName) ); return Create(_ruleCreator); } + + public TRuleTypeShouldConjunction ResideInAssemblyMatching(string pattern) + { + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.ResideInAssemblyMatching(pattern) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction ResideInAssembly( Assembly assembly, @@ -353,30 +357,32 @@ public TRuleTypeShouldConjunction DoNotImplementInterface(Type intf) return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotResideInNamespace( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public TRuleTypeShouldConjunction DoNotResideInNamespace(string fullName) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.DoNotResideInNamespace( - pattern, - useRegularExpressions - ) + TypePredicatesDefinition.DoNotResideInNamespace(fullName) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction DoNotResideInNamespaceMatching(string pattern) + { + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.DoNotResideInNamespaceMatching(pattern) ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotResideInAssembly( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public TRuleTypeShouldConjunction DoNotResideInAssembly(string fullName) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.DoNotResideInAssembly( - pattern, - useRegularExpressions - ) + TypePredicatesDefinition.DoNotResideInAssembly(fullName) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction DoNotResideInAssemblyMatching(string pattern) + { + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.DoNotResideInAssemblyMatching(pattern) ); return Create(_ruleCreator); } diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypeConditionsDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypeConditionsDefinition.cs index 1b7f8e604..8126f5b28 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypeConditionsDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypeConditionsDefinition.cs @@ -528,37 +528,39 @@ Architecture architecture ); } - public static ICondition ResideInNamespace( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public static ICondition ResideInNamespace(string fullName) { return new SimpleCondition( - type => type.ResidesInNamespace(pattern, useRegularExpressions), + type => type.ResidesInNamespace(fullName), obj => "does reside in " + obj.Namespace.FullName, - "reside in namespace with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" + "reside in namespace with full name \"" + fullName + "\"" + ); + } + public static ICondition ResideInNamespaceMatching(string pattern) + { + return new SimpleCondition( + type => type.ResidesInNamespace(pattern), + obj => "does reside in " + obj.Namespace.FullName, + "reside in namespace with full name matching \"" + pattern + "\"" ); } - public static ICondition ResideInAssembly( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public static ICondition ResideInAssembly(string fullName) { return new SimpleCondition( - type => type.ResidesInAssembly(pattern, useRegularExpressions), + type => type.ResidesInAssembly(fullName), obj => "does reside in " + obj.Assembly.FullName, - "reside in assembly with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" + "reside in assembly with full name \"" + fullName + "\"" ); } + public static ICondition ResideInAssemblyMatching(string pattern) + { + return new SimpleCondition( + type => type.ResidesInAssemblyMatching(pattern), + obj => "does reside in " + obj.Assembly.FullName, + "reside in assembly with full name matching \"" + pattern + "\"" + ); + } public static ICondition ResideInAssembly( System.Reflection.Assembly assembly, @@ -662,7 +664,7 @@ ConditionResult Condition(TRuleType ruleType) if ( classDiagramAssociation.Contains(dependency) && !allAllowedTargets.Any(pattern => - dependency.FullNameMatches(pattern, true) + dependency.FullNameMatches(pattern) ) ) { @@ -1103,35 +1105,38 @@ Architecture architecture ); } - public static ICondition NotResideInNamespace( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public static ICondition NotResideInNamespace(string fullName) { return new SimpleCondition( - type => !type.ResidesInNamespace(pattern, useRegularExpressions), + type => !type.ResidesInNamespace(fullName), obj => "does reside in " + obj.Namespace.FullName, - "not reside in namespace with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" + "not reside in namespace with full name \"" + fullName + "\"" ); } - public static ICondition NotResideInAssembly( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public static ICondition NotResideInNamespaceMatching(string pattern) + { + return new SimpleCondition( + type => !type.ResidesInNamespaceMatching(pattern), + obj => "does reside in " + obj.Namespace.FullName, + "not reside in namespace with full name matching \"" + pattern + "\"" + ); + } + + public static ICondition NotResideInAssembly(string fullName) + { + return new SimpleCondition( + type => !type.ResidesInAssembly(fullName), + obj => "does reside in " + obj.Assembly.FullName, + "not reside in assembly with full name \"" + fullName + "\"" + ); + } + public static ICondition NotResideInAssemblyMatching(string pattern) { return new SimpleCondition( - type => !type.ResidesInAssembly(pattern, useRegularExpressions), + type => !type.ResidesInAssemblyMatching(pattern), obj => "does reside in " + obj.Assembly.FullName, - "not reside in assembly with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" + "not reside in assembly with full name matching \"" + pattern + "\"" ); } diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypePredicatesDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypePredicatesDefinition.cs index b4c98c960..8e364cd7a 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypePredicatesDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypePredicatesDefinition.cs @@ -347,33 +347,33 @@ IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) ); } - public static IPredicate ResideInNamespace( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public static IPredicate ResideInNamespace(string fullName) { return new SimplePredicate( - type => type.ResidesInNamespace(pattern, useRegularExpressions), - "reside in namespace with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" + type => type.ResidesInNamespace(fullName), + "reside in namespace with full name \"" + fullName + "\"" + ); + } + public static IPredicate ResideInNamespaceMatching(string pattern) + { + return new SimplePredicate( + type => type.ResidesInNamespaceMatching(pattern), + "reside in namespace with full name matching \"" + pattern + "\"" ); } - public static IPredicate ResideInAssembly( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public static IPredicate ResideInAssembly(string fullName) + { + return new SimplePredicate( + type => type.ResidesInAssembly(fullName), + "reside in assembly with full name \"" + fullName + "\"" + ); + } + public static IPredicate ResideInAssemblyMatching(string pattern) { return new SimplePredicate( - type => type.ResidesInAssembly(pattern, useRegularExpressions), - "reside in assembly with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" + type => type.ResidesInAssembly(pattern), + "reside in assembly with full name matching \"" + pattern + "\"" ); } @@ -675,33 +675,33 @@ IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) ); } - public static IPredicate DoNotResideInNamespace( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public static IPredicate DoNotResideInNamespace(string fullName) { return new SimplePredicate( - type => !type.ResidesInNamespace(pattern, useRegularExpressions), - "do not reside in namespace with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" + type => !type.ResidesInNamespace(fullName), + "do not reside in namespace with full name \"" + fullName + "\"" + ); + } + public static IPredicate DoNotResideInNamespaceMatching(string pattern) + { + return new SimplePredicate( + type => !type.ResidesInNamespace(pattern), + "do not reside in namespace with full name matching \"" + pattern + "\"" ); } - public static IPredicate DoNotResideInAssembly( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public static IPredicate DoNotResideInAssembly(string fullName) + { + return new SimplePredicate( + type => !type.ResidesInAssembly(fullName), + "do not reside in assembly with full name \"" + fullName + "\"" + ); + } + public static IPredicate DoNotResideInAssemblyMatching(string pattern) { return new SimplePredicate( - type => !type.ResidesInAssembly(pattern, useRegularExpressions), - "do not reside in assembly with full name " - + (useRegularExpressions ? "matching " : "") - + "\"" - + pattern - + "\"" + type => !type.ResidesInAssembly(pattern), + "do not reside in assembly with full name matching \"" + pattern + "\"" ); } diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShould.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShould.cs index 8e2db3d3d..a87f17ebb 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShould.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShould.cs @@ -133,27 +133,33 @@ public TRuleTypeShouldConjunction ImplementInterface(Type intf) return Create(_ruleCreator); } - public TRuleTypeShouldConjunction ResideInNamespace( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public TRuleTypeShouldConjunction ResideInNamespace(string fullName) { _ruleCreator.AddCondition( - TypeConditionsDefinition.ResideInNamespace( - pattern, - useRegularExpressions - ) + TypeConditionsDefinition.ResideInNamespace(fullName) ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction ResideInAssembly( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public TRuleTypeShouldConjunction ResideInNamespaceMatching(string pattern) + { + _ruleCreator.AddCondition( + TypeConditionsDefinition.ResideInNamespaceMatching(pattern) + ); + return Create(_ruleCreator); + } + + public TRuleTypeShouldConjunction ResideInAssembly(string fullName) + { + _ruleCreator.AddCondition( + TypeConditionsDefinition.ResideInAssembly(fullName) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction ResideInAssemblyMatching(string pattern) { _ruleCreator.AddCondition( - TypeConditionsDefinition.ResideInAssembly(pattern, useRegularExpressions) + TypeConditionsDefinition.ResideInAssemblyMatching(pattern) ); return Create(_ruleCreator); } @@ -321,30 +327,32 @@ public TRuleTypeShouldConjunction NotImplementInterface(Type intf) return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotResideInNamespace( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public TRuleTypeShouldConjunction NotResideInNamespace(string fullName) { _ruleCreator.AddCondition( - TypeConditionsDefinition.NotResideInNamespace( - pattern, - useRegularExpressions - ) + TypeConditionsDefinition.NotResideInNamespace(fullName) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction NotResideInNamespaceMatching(string pattern) + { + _ruleCreator.AddCondition( + TypeConditionsDefinition.NotResideInNamespaceMatching(pattern) ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotResideInAssembly( - string pattern, - bool useRegularExpressions = false - ) //TODO split into multiple implementations + public TRuleTypeShouldConjunction NotResideInAssembly(string fullName) + { + _ruleCreator.AddCondition( + TypeConditionsDefinition.NotResideInAssembly(fullName) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction NotResideInAssemblyMatching(string pattern) { _ruleCreator.AddCondition( - TypeConditionsDefinition.NotResideInAssembly( - pattern, - useRegularExpressions - ) + TypeConditionsDefinition.NotResideInAssemblyMatching(pattern) ); return Create(_ruleCreator); } diff --git a/ArchUnitNETTests/Dependencies/StringDependenciesTests.cs b/ArchUnitNETTests/Dependencies/StringDependenciesTests.cs index f8f7845e9..fd7fe37f2 100644 --- a/ArchUnitNETTests/Dependencies/StringDependenciesTests.cs +++ b/ArchUnitNETTests/Dependencies/StringDependenciesTests.cs @@ -72,6 +72,8 @@ public void PropertyStringDependencyFound() ); } } +#pragma warning disable CS0219 // Variable is assigned but its value is never used +#pragma warning disable CS0414 // Field is assigned but its value is never used internal class ClassWithStringField { diff --git a/ArchUnitNETTests/Domain/Dependencies/Attributes/AttributeDependencyTests.cs b/ArchUnitNETTests/Domain/Dependencies/Attributes/AttributeDependencyTests.cs index f3af00762..5be09a4b3 100644 --- a/ArchUnitNETTests/Domain/Dependencies/Attributes/AttributeDependencyTests.cs +++ b/ArchUnitNETTests/Domain/Dependencies/Attributes/AttributeDependencyTests.cs @@ -78,7 +78,7 @@ public void ClassAttributeInnerDependencyAssignedToOriginClass() //Assert Assert.All( expectedClassTargets, - targetClass => Assert.True(_originClass.DependsOn(targetClass.FullName)) + targetClass => Assert.True(_originClass.DependsOnType(targetClass.FullName)) ); } @@ -87,7 +87,7 @@ public void ForbidAttributeForClass() { Assert.All( _eventHandlerImplementClasses, - cls => Assert.False(cls.DependsOn("forbidden")) + cls => Assert.False(cls.DependsOnTypeMatching("forbidden")) ); } @@ -106,7 +106,7 @@ public void MemberAttributeInnerDependencyAssignedToOriginClass() //Assert Assert.All( expectedClassTargets, - targetClass => Assert.True(_originClass.DependsOn(targetClass.FullName)) + targetClass => Assert.True(_originClass.DependsOnType(targetClass.FullName)) ); } diff --git a/ArchUnitNETTests/Domain/Extensions/TypeExtensionTests.cs b/ArchUnitNETTests/Domain/Extensions/TypeExtensionTests.cs index dca9dbbe4..bc117b3d9 100644 --- a/ArchUnitNETTests/Domain/Extensions/TypeExtensionTests.cs +++ b/ArchUnitNETTests/Domain/Extensions/TypeExtensionTests.cs @@ -74,14 +74,20 @@ public void FullNameContainsTest() [Fact] public void FullNameMatchesTest() { - Assert.True(_fieldMember.FullNameMatches("(?i)ieLda", true)); - Assert.True(_propertyOriginClass.FullNameMatches("(?i)sswITH", true)); - Assert.False(_methodOriginClass.FullNameMatches("ClassMethod")); - Assert.False(_methodMember.FullNameMatches("")); - Assert.True(_methodMember.FullNameMatches(_methodMember.FullName)); - Assert.True(_methodMember.FullNameMatches(_methodMember.FullName.ToLower())); + Assert.True(_fieldMember.FullNameMatches("(?i)ieLda")); + Assert.True(_propertyOriginClass.FullNameMatches("(?i)sswITH")); Assert.False(_exampleAttribute.FullNameMatches(null)); } + + [Fact] + public void FullNameEqualsTest() + { + Assert.False(_methodOriginClass.FullNameEquals("ClassMethod")); + Assert.False(_methodMember.FullNameEquals("")); + Assert.True(_methodMember.FullNameEquals(_methodMember.FullName)); + Assert.True(_methodMember.FullNameEquals(_methodMember.FullName.ToLower())); + Assert.False(_exampleAttribute.FullNameEquals(null)); + } [Fact] public void HasMembersWithFullNameTest() @@ -199,21 +205,27 @@ public void NameEndsWithTest() [Fact] public void NameMatchesTest() { - Assert.True(_fieldMember.NameMatches("(?i)ieLda", true)); - Assert.True(_propertyOriginClass.NameMatches("(?i)sswITH", true)); - Assert.False(_methodOriginClass.NameMatches("ClassMethod")); - Assert.False(_methodMember.NameMatches("")); - Assert.True(_methodMember.NameMatches(_methodMember.Name)); - Assert.True(_methodMember.NameMatches(_methodMember.Name.ToLower())); + Assert.True(_fieldMember.NameMatches("(?i)ieLda")); + Assert.True(_propertyOriginClass.NameMatches("(?i)sswITH")); Assert.False(_exampleAttribute.NameMatches(null)); } + + [Fact] + public void NameEqualsTest() + { + Assert.False(_methodOriginClass.NameEquals("ClassMethod")); + Assert.False(_methodMember.NameEquals("")); + Assert.True(_methodMember.NameEquals(_methodMember.Name)); + Assert.True(_methodMember.NameEquals(_methodMember.Name.ToLower())); + Assert.False(_exampleAttribute.NameEquals(null)); + } [Fact] public void NamespaceMatchAsExpected() { Assert.True(_exampleAttribute.ResidesInNamespace(ExpectedAttributeNamespace)); Assert.False(_exampleAttribute.ResidesInNamespace(ParentAttributeNamespace)); - Assert.True(_exampleAttribute.ResidesInNamespace(ParentAttributeNamespace, true)); + Assert.True(_exampleAttribute.ResidesInNamespaceMatching(ParentAttributeNamespace)); Assert.True(_regexUtilsTests.ResidesInNamespace(ExpectedRegexUtilsTestNamespace)); Assert.False(_exampleAttribute.ResidesInNamespace(string.Empty)); } diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectsShouldTests.cs b/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectsShouldTests.cs index cec013093..4d0b5027f 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectsShouldTests.cs +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectsShouldTests.cs @@ -1397,9 +1397,9 @@ public async Task HaveNameTest() helper.AddSnapshotHeader("No violations"); var should = Types().That().Are(helper.BaseClass).Should(); should.HaveName(helper.BaseClass.Name).AssertNoViolations(helper); - should.HaveName("^Base.*$", true).AssertNoViolations(helper); + should.HaveNameMatching("^Base.*$").AssertNoViolations(helper); should.HaveFullName(helper.BaseClass.FullName).AssertNoViolations(helper); - should.HaveFullName("^.*\\.Base.*$", true).AssertNoViolations(helper); + should.HaveFullNameMatching("^.*\\.Base.*$").AssertNoViolations(helper); should.HaveNameContaining("Base").AssertNoViolations(helper); should.HaveFullNameContaining(helper.BaseClass.Namespace.Name).AssertNoViolations(helper); should.HaveNameStartingWith("Base").AssertNoViolations(helper); @@ -1408,9 +1408,9 @@ public async Task HaveNameTest() helper.AddSnapshotHeader("Violations"); should = Types().That().Are(helper.BaseClass).Should(); should.HaveName(helper.BaseClass.FullName).AssertOnlyViolations(helper); - should.HaveName("^.*\\.Base.*$", false).AssertOnlyViolations(helper); + should.HaveName("^.*\\.Base.*$").AssertOnlyViolations(helper); should.HaveFullName(helper.BaseClass.Name).AssertOnlyViolations(helper); - should.HaveFullName("^Base.*$", false).AssertOnlyViolations(helper); + should.HaveFullName("^Base.*$").AssertOnlyViolations(helper); should.HaveNameContaining(helper.BaseClass.Namespace.Name).AssertOnlyViolations(helper); should.HaveFullNameContaining(helper.NonExistentObjectName).AssertOnlyViolations(helper); should.HaveNameStartingWith(helper.BaseClass.Namespace.Name).AssertOnlyViolations(helper); @@ -2318,9 +2318,9 @@ public async Task NotHaveNameTest() helper.AddSnapshotHeader("No violations"); var should = Types().That().Are(helper.BaseClass).Should(); should.NotHaveName(helper.BaseClass.FullName).AssertNoViolations(helper); - should.NotHaveName("^.*\\.Base.*$", true).AssertNoViolations(helper); + should.NotHaveNameMatching("^.*\\.Base.*$").AssertNoViolations(helper); should.NotHaveFullName(helper.BaseClass.Name).AssertNoViolations(helper); - should.NotHaveFullName("^Base.*$", true).AssertNoViolations(helper); + should.NotHaveFullNameMatching("^Base.*$").AssertNoViolations(helper); should.NotHaveNameContaining(helper.BaseClass.Namespace.Name).AssertNoViolations(helper); should.NotHaveFullNameContaining(helper.NonExistentObjectName).AssertNoViolations(helper); should.NotHaveNameStartingWith(helper.BaseClass.Namespace.Name).AssertNoViolations(helper); @@ -2329,9 +2329,9 @@ public async Task NotHaveNameTest() helper.AddSnapshotHeader("Violations"); should = Types().That().Are(helper.BaseClass).Should(); should.NotHaveName(helper.BaseClass.Name).AssertOnlyViolations(helper); - should.NotHaveName("^Base.*$", true).AssertOnlyViolations(helper); + should.NotHaveNameMatching("^Base.*$").AssertOnlyViolations(helper); should.NotHaveFullName(helper.BaseClass.FullName).AssertOnlyViolations(helper); - should.NotHaveFullName("^.*\\.Base.*$", true).AssertOnlyViolations(helper); + should.NotHaveFullNameMatching("^.*\\.Base.*$").AssertOnlyViolations(helper); should.NotHaveNameContaining("Base").AssertOnlyViolations(helper); should .NotHaveFullNameContaining(helper.BaseClass.Namespace.Name) diff --git a/ArchUnitNETTests/Loader/TypeTests.cs b/ArchUnitNETTests/Loader/TypeTests.cs index 6b818b15d..c205bdb2b 100644 --- a/ArchUnitNETTests/Loader/TypeTests.cs +++ b/ArchUnitNETTests/Loader/TypeTests.cs @@ -121,7 +121,8 @@ public void AccessAttributes() [Fact] public void NotAssignableToNull() { - Assert.False(_type.IsAssignableTo(null)); + Assert.False(_type.IsAssignableTo((IType)null)); + Assert.False(_type.IsAssignableTo((string)null)); } [Fact] From 6ff10e9117e12763dc59276a97358adcd1df5b3b Mon Sep 17 00:00:00 2001 From: Fritz Brandhuber Date: Mon, 10 Mar 2025 22:14:52 +0100 Subject: [PATCH 5/7] Fix wrong rule description of HaveName() and HaveNameMatching() in expected test output Signed-off-by: Fritz Brandhuber --- .../ObjectsShouldTests.HaveNameTest.verified.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.HaveNameTest.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.HaveNameTest.verified.txt index 3bb7c59e6..06d62f034 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.HaveNameTest.verified.txt +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/ObjectsShouldTests.HaveNameTest.verified.txt @@ -1,12 +1,12 @@ ===== No violations ===== -Query: Types that are "TypeDependencyNamespace.BaseClass" should have full name "BaseClass" +Query: Types that are "TypeDependencyNamespace.BaseClass" should have name "BaseClass" Result: True Description: TypeDependencyNamespace.BaseClass passed Message: All Evaluations passed -Query: Types that are "TypeDependencyNamespace.BaseClass" should have full name matching "^Base.*$" +Query: Types that are "TypeDependencyNamespace.BaseClass" should have name matching "^Base.*$" Result: True Description: TypeDependencyNamespace.BaseClass passed Message: @@ -50,20 +50,20 @@ All Evaluations passed ===== Violations ===== -Query: Types that are "TypeDependencyNamespace.BaseClass" should have full name "TypeDependencyNamespace.BaseClass" +Query: Types that are "TypeDependencyNamespace.BaseClass" should have name "TypeDependencyNamespace.BaseClass" Result: False Description: TypeDependencyNamespace.BaseClass does have name BaseClass Message: -"Types that are "TypeDependencyNamespace.BaseClass" should have full name "TypeDependencyNamespace.BaseClass"" failed: +"Types that are "TypeDependencyNamespace.BaseClass" should have name "TypeDependencyNamespace.BaseClass"" failed: TypeDependencyNamespace.BaseClass does have name BaseClass -Query: Types that are "TypeDependencyNamespace.BaseClass" should have full name "^.*\.Base.*$" +Query: Types that are "TypeDependencyNamespace.BaseClass" should have name "^.*\.Base.*$" Result: False Description: TypeDependencyNamespace.BaseClass does have name BaseClass Message: -"Types that are "TypeDependencyNamespace.BaseClass" should have full name "^.*\.Base.*$"" failed: +"Types that are "TypeDependencyNamespace.BaseClass" should have name "^.*\.Base.*$"" failed: TypeDependencyNamespace.BaseClass does have name BaseClass From 0ef3e63481245064d33f2b0cc8dfdbe30a9de349 Mon Sep 17 00:00:00 2001 From: Fritz Brandhuber Date: Tue, 11 Mar 2025 08:46:16 +0100 Subject: [PATCH 6/7] fix code format Signed-off-by: Fritz Brandhuber --- .../Domain/Extensions/AttributeExtensions.cs | 38 +++------ .../Domain/Extensions/DependencyExtensions.cs | 54 ++++--------- .../Domain/Extensions/MemberExtensions.cs | 42 +++------- .../Domain/Extensions/NamingExtensions.cs | 6 +- .../Domain/Extensions/TypeExtensions.cs | 81 +++++-------------- .../Syntax/Elements/GivenObjectsThat.cs | 20 ++--- .../Elements/Members/GivenMembersThat.cs | 4 +- .../Members/MemberConditionsDefinition.cs | 2 +- .../Syntax/Elements/Members/MembersShould.cs | 2 +- .../MethodMemberConditionsDefinition.cs | 8 +- .../MethodMemberPredicatesDefinition.cs | 2 +- .../ShouldRelateToMethodMembersThat.cs | 2 +- .../Elements/ObjectConditionsDefinition.cs | 33 ++++---- .../Elements/ObjectPredicatesDefinition.cs | 17 ++-- .../Fluent/Syntax/Elements/ObjectsShould.cs | 18 ++--- .../Elements/ShouldRelateToObjectsThat.cs | 12 ++- .../Syntax/Elements/Types/GivenTypesThat.cs | 14 ++-- .../Elements/Types/ShouldRelateToTypesThat.cs | 8 +- .../Types/TypeConditionsDefinition.cs | 9 ++- .../Types/TypePredicatesDefinition.cs | 8 +- .../Syntax/Elements/Types/TypesShould.cs | 5 +- .../Domain/Extensions/TypeExtensionTests.cs | 4 +- .../Elements/MemberSyntaxElementsTests.cs | 13 ++- .../Elements/ObjectSyntaxElementsTests.cs | 22 ++--- .../Syntax/Elements/ObjectsShouldTests.cs | 24 +++--- ExampleTest/ExampleArchUnitTest.cs | 2 +- 26 files changed, 171 insertions(+), 279 deletions(-) diff --git a/ArchUnitNET/Domain/Extensions/AttributeExtensions.cs b/ArchUnitNET/Domain/Extensions/AttributeExtensions.cs index f2329ca36..85c2f69c0 100644 --- a/ArchUnitNET/Domain/Extensions/AttributeExtensions.cs +++ b/ArchUnitNET/Domain/Extensions/AttributeExtensions.cs @@ -11,46 +11,26 @@ namespace ArchUnitNET.Domain.Extensions { public static class AttributeExtensions { - public static bool HasAttribute( - this IHasAttributes a, - string fullName - ) + public static bool HasAttribute(this IHasAttributes a, string fullName) { - return a.Attributes.Any(attribute => - attribute.FullNameEquals(fullName) - ); + return a.Attributes.Any(attribute => attribute.FullNameEquals(fullName)); } - public static bool HasAttributeMatching( - this IHasAttributes a, - string pattern - ) + public static bool HasAttributeMatching(this IHasAttributes a, string pattern) { - return a.Attributes.Any(attribute => - attribute.FullNameMatches(pattern) - ); + return a.Attributes.Any(attribute => attribute.FullNameMatches(pattern)); } - public static bool OnlyHasAttributes( - this IHasAttributes a, - string name - ) + public static bool OnlyHasAttributes(this IHasAttributes a, string name) { return a.Attributes.IsNullOrEmpty() - || a.Attributes.All(attribute => - attribute.FullNameEquals(name) - ); + || a.Attributes.All(attribute => attribute.FullNameEquals(name)); } - public static bool OnlyHasAttributesMatching( - this IHasAttributes a, - string pattern - ) + public static bool OnlyHasAttributesMatching(this IHasAttributes a, string pattern) { return a.Attributes.IsNullOrEmpty() - || a.Attributes.All(attribute => - attribute.FullNameMatches(pattern) - ); + || a.Attributes.All(attribute => attribute.FullNameMatches(pattern)); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Extensions/DependencyExtensions.cs b/ArchUnitNET/Domain/Extensions/DependencyExtensions.cs index c07e91d3c..a27548fae 100644 --- a/ArchUnitNET/Domain/Extensions/DependencyExtensions.cs +++ b/ArchUnitNET/Domain/Extensions/DependencyExtensions.cs @@ -13,22 +13,14 @@ namespace ArchUnitNET.Domain.Extensions { public static class DependencyExtensions { - public static bool CallsMethod( - this IHasDependencies type, - string fullName - ) + public static bool CallsMethod(this IHasDependencies type, string fullName) { - return type.GetCalledMethods() - .Any(member => member.FullNameEquals(fullName)); + return type.GetCalledMethods().Any(member => member.FullNameEquals(fullName)); } - - public static bool CallsMethodMatching( - this IHasDependencies type, - string pattern - ) + + public static bool CallsMethodMatching(this IHasDependencies type, string pattern) { - return type.GetCalledMethods() - .Any(member => member.FullNameMatches(pattern)); + return type.GetCalledMethods().Any(member => member.FullNameMatches(pattern)); } public static IEnumerable GetCalledMethods(this IHasDependencies type) @@ -45,40 +37,24 @@ public static IEnumerable GetAccessedFieldMembers(this IHasDependen .Select(dependency => (FieldMember)dependency.TargetMember); } - public static bool DependsOnType( - this IHasDependencies c, - string fullName - ) + public static bool DependsOnType(this IHasDependencies c, string fullName) { - return c.GetTypeDependencies() - .Any(d => d.FullNameEquals(fullName)); + return c.GetTypeDependencies().Any(d => d.FullNameEquals(fullName)); } - - public static bool DependsOnTypeMatching( - this IHasDependencies c, - string pattern - ) + + public static bool DependsOnTypeMatching(this IHasDependencies c, string pattern) { - return c.GetTypeDependencies() - .Any(d => d.FullNameMatches(pattern)); + return c.GetTypeDependencies().Any(d => d.FullNameMatches(pattern)); } - - public static bool OnlyDependsOnType( - this IHasDependencies c, - string fullName - ) + public static bool OnlyDependsOnType(this IHasDependencies c, string fullName) { - return c.GetTypeDependencies() - .All(d => d.FullNameEquals(fullName)); + return c.GetTypeDependencies().All(d => d.FullNameEquals(fullName)); } - public static bool OnlyDependsOnTypesMatching( - this IHasDependencies c, - string pattern - ) + + public static bool OnlyDependsOnTypesMatching(this IHasDependencies c, string pattern) { - return c.GetTypeDependencies() - .All(d => d.FullNameMatches(pattern)); + return c.GetTypeDependencies().All(d => d.FullNameMatches(pattern)); } public static IEnumerable GetTypeDependencies(this IHasDependencies c) diff --git a/ArchUnitNET/Domain/Extensions/MemberExtensions.cs b/ArchUnitNET/Domain/Extensions/MemberExtensions.cs index 383e827d0..1142cea09 100644 --- a/ArchUnitNET/Domain/Extensions/MemberExtensions.cs +++ b/ArchUnitNET/Domain/Extensions/MemberExtensions.cs @@ -12,18 +12,12 @@ namespace ArchUnitNET.Domain.Extensions { public static class MemberExtensions { - public static bool IsDeclaredIn( - this IMember member, - string fullName - ) + public static bool IsDeclaredIn(this IMember member, string fullName) { return member.DeclaringType.FullNameEquals(fullName); } - - public static bool IsDeclaredInTypeMatching( - this IMember member, - string pattern - ) + + public static bool IsDeclaredInTypeMatching(this IMember member, string pattern) { return member.DeclaringType.FullNameMatches(pattern); } @@ -69,28 +63,18 @@ public static bool HasMethodCallDependencies( return member.GetMethodCallDependencies(getBackwardsDependencies).Any(); } - public static bool IsCalledByType( - this MethodMember member, - string fullName - ) + public static bool IsCalledByType(this MethodMember member, string fullName) { return member .GetMethodCallDependencies(true) - .Any(dependency => - dependency.Origin.FullNameEquals(fullName) - ); + .Any(dependency => dependency.Origin.FullNameEquals(fullName)); } - - public static bool IsCalledByTypeMatching( - this MethodMember member, - string pattern - ) + + public static bool IsCalledByTypeMatching(this MethodMember member, string pattern) { return member .GetMethodCallDependencies(true) - .Any(dependency => - dependency.Origin.FullNameMatches(pattern) - ); + .Any(dependency => dependency.Origin.FullNameMatches(pattern)); } public static IEnumerable GetCallingTypes(this MethodMember member) @@ -108,11 +92,9 @@ string fullName { return member .GetBodyTypeMemberDependencies() - .Any(dependency => - dependency.Target.FullNameEquals(fullName) - ); + .Any(dependency => dependency.Target.FullNameEquals(fullName)); } - + public static bool HasDependencyInMethodBodyToTypeMatching( this MethodMember member, string pattern @@ -120,9 +102,7 @@ string pattern { return member .GetBodyTypeMemberDependencies() - .Any(dependency => - dependency.Target.FullNameMatches(pattern) - ); + .Any(dependency => dependency.Target.FullNameMatches(pattern)); } public static bool HasFieldTypeDependencies( diff --git a/ArchUnitNET/Domain/Extensions/NamingExtensions.cs b/ArchUnitNET/Domain/Extensions/NamingExtensions.cs index d7cde5f95..9055489a7 100644 --- a/ArchUnitNET/Domain/Extensions/NamingExtensions.cs +++ b/ArchUnitNET/Domain/Extensions/NamingExtensions.cs @@ -57,7 +57,7 @@ public static bool FullNameEquals(this IHasName cls, string fullName) { return string.Equals(cls.FullName, fullName, StringComparison.OrdinalIgnoreCase); } - + public static bool FullNameMatches(this IHasName cls, string pattern) { return pattern != null && Regex.IsMatch(cls.FullName, pattern); @@ -88,7 +88,7 @@ public static TType WhereFullNameIs(this IEnumerable source, strin { throw new MultipleOccurrencesInSequenceException( $"Full name {fullName} found multiple times in provided types. Please use extern " - + "alias to reference assemblies that have the same fully-qualified type names." + + "alias to reference assemblies that have the same fully-qualified type names." ); } @@ -107,4 +107,4 @@ string assemblyQualifiedName ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Extensions/TypeExtensions.cs b/ArchUnitNET/Domain/Extensions/TypeExtensions.cs index 07a9c8d6c..cf247c70e 100644 --- a/ArchUnitNET/Domain/Extensions/TypeExtensions.cs +++ b/ArchUnitNET/Domain/Extensions/TypeExtensions.cs @@ -25,10 +25,7 @@ public static bool ImplementsInterface(this IType type, Interface intf) ); } - public static bool ImplementsInterface( - this IType type, - string fullName - ) + public static bool ImplementsInterface(this IType type, string fullName) { if (type is GenericParameter) { @@ -39,11 +36,8 @@ string fullName implementedInterface.FullNameEquals(fullName) ); } - - public static bool ImplementsInterfaceMatching( - this IType type, - string pattern - ) + + public static bool ImplementsInterfaceMatching(this IType type, string pattern) { if (type is GenericParameter) { @@ -67,36 +61,24 @@ public static bool IsAssignableTo(this IType type, IType assignableToType) return type.GetAssignableTypes().Contains(assignableToType); } - public static bool IsAssignableTo( - this IType type, - string fullName - ) + public static bool IsAssignableTo(this IType type, string fullName) { if (type is GenericParameter genericParameter) { - return genericParameter.TypeConstraints.All(t => - t.IsAssignableTo(fullName) - ); + return genericParameter.TypeConstraints.All(t => t.IsAssignableTo(fullName)); } - return type.GetAssignableTypes() - .Any(t => t.FullNameEquals(fullName)); + return type.GetAssignableTypes().Any(t => t.FullNameEquals(fullName)); } - - public static bool IsAssignableToTypeMatching( - this IType type, - string pattern - ) + + public static bool IsAssignableToTypeMatching(this IType type, string pattern) { if (type is GenericParameter genericParameter) { - return genericParameter.TypeConstraints.All(t => - t.IsAssignableTo(pattern) - ); + return genericParameter.TypeConstraints.All(t => t.IsAssignableTo(pattern)); } - return type.GetAssignableTypes() - .Any(t => t.FullNameMatches(pattern)); + return type.GetAssignableTypes().Any(t => t.FullNameMatches(pattern)); } public static bool IsNestedIn(this IType type, IType assignableToType) @@ -262,58 +244,37 @@ public static Attribute GetAttributeOfType(this IType type, Class attributeClass attribute.FullName.Equals(attributeClass.FullName) ); } - - public static bool ResidesInNamespace( - this IType e, - string fullName - ) + + public static bool ResidesInNamespace(this IType e, string fullName) { return e.Namespace.FullNameEquals(fullName); } - public static bool ResidesInNamespaceMatching( - this IType e, - string pattern - ) + public static bool ResidesInNamespaceMatching(this IType e, string pattern) { return e.Namespace.FullNameMatches(pattern); } - public static bool ResidesInAssembly( - this IType e, - string fullName - ) + public static bool ResidesInAssembly(this IType e, string fullName) { return e.Assembly.FullNameEquals(fullName); } - public static bool ResidesInAssemblyMatching( - this IType e, - string pattern - ) + + public static bool ResidesInAssemblyMatching(this IType e, string pattern) { return e.Assembly.FullNameMatches(pattern); } - public static bool IsDeclaredAsFieldIn( - this IType type, - string fullName - ) + public static bool IsDeclaredAsFieldIn(this IType type, string fullName) { return type.GetFieldTypeDependencies(true) - .Any(dependency => - dependency.Target.FullNameEquals(fullName) - ); + .Any(dependency => dependency.Target.FullNameEquals(fullName)); } - - public static bool IsDeclaredAsFieldInTypeMatching( - this IType type, - string pattern - ) + + public static bool IsDeclaredAsFieldInTypeMatching(this IType type, string pattern) { return type.GetFieldTypeDependencies(true) - .Any(dependency => - dependency.Target.FullNameMatches(pattern) - ); + .Any(dependency => dependency.Target.FullNameMatches(pattern)); } public static bool HasDependency(this IType type, ITypeDependency dependency) diff --git a/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsThat.cs index 8f0f022d8..bd8d2fdde 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsThat.cs @@ -428,12 +428,10 @@ public TGivenRuleTypeConjunction HaveAttributeWithNamedArguments( public TGivenRuleTypeConjunction HaveName(string name) { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.HaveName(name) - ); + _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveName(name)); return Create(_ruleCreator); } - + public TGivenRuleTypeConjunction HaveNameMatching(string pattern) { _ruleCreator.AddPredicate( @@ -444,12 +442,10 @@ public TGivenRuleTypeConjunction HaveNameMatching(string pattern) public TGivenRuleTypeConjunction HaveFullName(string fullName) { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.HaveFullName(fullName) - ); + _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveFullName(fullName)); return Create(_ruleCreator); } - + public TGivenRuleTypeConjunction HaveFullNameMatching(string pattern) { _ruleCreator.AddPredicate( @@ -842,12 +838,10 @@ public TGivenRuleTypeConjunction DoNotHaveAttributeWithNamedArguments( public TGivenRuleTypeConjunction DoNotHaveName(string name) { - _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.DoNotHaveName(name) - ); + _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveName(name)); return Create(_ruleCreator); } - + public TGivenRuleTypeConjunction DoNotHaveNameMatching(string pattern) { _ruleCreator.AddPredicate( @@ -863,7 +857,7 @@ public TGivenRuleTypeConjunction DoNotHaveFullName(string fullName) ); return Create(_ruleCreator); } - + public TGivenRuleTypeConjunction DoNotHaveFullNameMatching(string pattern) { _ruleCreator.AddPredicate( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembersThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembersThat.cs index 073a5d5f2..cb7d149b7 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembersThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembersThat.cs @@ -20,7 +20,7 @@ public class GivenMembersThat // ReSharper disable once MemberCanBeProtected.Global public GivenMembersThat(IArchRuleCreator ruleCreator) : base(ruleCreator) { } - + public TGivenRuleTypeConjunction AreDeclaredIn(IType firstType, params IType[] moreTypes) { _ruleCreator.AddPredicate( @@ -74,7 +74,7 @@ public TGivenRuleTypeConjunction AreImmutable() } //Negations - + public TGivenRuleTypeConjunction AreNotDeclaredIn(IType firstType, params IType[] moreTypes) { _ruleCreator.AddPredicate( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberConditionsDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberConditionsDefinition.cs index 15c69a58b..8907fcdc5 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberConditionsDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberConditionsDefinition.cs @@ -374,7 +374,7 @@ public static ICondition NotBeImmutable() } //Relation Condition Negations - + public static RelationCondition NotBeDeclaredInTypesThat() { return new RelationCondition( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MembersShould.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MembersShould.cs index 3486d75ed..2205e0713 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MembersShould.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MembersShould.cs @@ -21,7 +21,7 @@ public class MembersShould // ReSharper disable once MemberCanBeProtected.Global public MembersShould(IArchRuleCreator ruleCreator) : base(ruleCreator) { } - + public TRuleTypeShouldConjunction BeDeclaredIn(IType firstType, params IType[] moreTypes) { _ruleCreator.AddCondition( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberConditionsDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberConditionsDefinition.cs index f25640819..f6ae01e1c 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberConditionsDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberConditionsDefinition.cs @@ -797,8 +797,8 @@ IEnumerable Condition(IEnumerable methodMembers) .Distinct() .Aggregate( "does have dependencies in method body to \"" - + firstType.FullName - + "\"", + + firstType.FullName + + "\"", (current, type) => current + " or \"" + type.FullName + "\"" ); } @@ -959,9 +959,7 @@ Architecture architecture var methodMemberList = methodMembers.ToList(); var passedObjects = methodMemberList .Where(methodMember => - typeList.All(type => - !methodMember.ReturnType.FullNameEquals(type.FullName) - ) + typeList.All(type => !methodMember.ReturnType.FullNameEquals(type.FullName)) ) .ToList(); foreach (var failedObject in methodMemberList.Except(passedObjects)) diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberPredicatesDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberPredicatesDefinition.cs index 498e1f6e6..ad168564a 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberPredicatesDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberPredicatesDefinition.cs @@ -458,7 +458,7 @@ Architecture architecture return new ArchitecturePredicate(Condition, description); } - + public static IPredicate DoNotHaveDependencyInMethodBodyTo( IType firstType, params IType[] moreTypes diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/ShouldRelateToMethodMembersThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/ShouldRelateToMethodMembersThat.cs index 2d36973c5..b08083a56 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/ShouldRelateToMethodMembersThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/ShouldRelateToMethodMembersThat.cs @@ -119,7 +119,7 @@ public TRuleTypeShouldConjunction HaveDependencyInMethodBodyTo(IEnumerable ); return Create(_ruleCreator); } - + public TRuleTypeShouldConjunction HaveReturnType(IType firstType, params IType[] moreTypes) { _ruleCreator.ContinueComplexCondition( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/ObjectConditionsDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/ObjectConditionsDefinition.cs index 28cb5abe2..2b1aed624 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/ObjectConditionsDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/ObjectConditionsDefinition.cs @@ -113,7 +113,7 @@ Architecture architecture "be " + objectProvider.Description ); } - + public static ICondition CallAny( MethodMember method, params MethodMember[] moreMethods @@ -924,7 +924,7 @@ params object[] moreArgumentValues argumentValues.AddRange(moreArgumentValues); return HaveAnyAttributesWithArguments(argumentValues); } - + public static ICondition HaveAttributeWithArguments( Attribute attribute, object firstArgumentValue, @@ -1056,7 +1056,7 @@ bool Condition(TRuleType obj, Architecture architecture) return new ArchitectureCondition(Condition, failDescription, description); } - + public static ICondition HaveAttributeWithArguments( [NotNull] Attribute attribute, IEnumerable argumentValues @@ -1320,7 +1320,7 @@ bool Condition(TRuleType obj, Architecture architecture) return new ArchitectureCondition(Condition, failDescription, description); } - + public static ICondition HaveAttributeWithNamedArguments( [NotNull] Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -1519,15 +1519,17 @@ public static ICondition HaveName(string name) return new SimpleCondition( obj => obj.NameEquals(name), obj => "does have name " + obj.Name, - $"have name \"{name}\""); + $"have name \"{name}\"" + ); } - + public static ICondition HaveNameMatching(string pattern) { return new SimpleCondition( obj => obj.NameMatches(pattern), obj => "does have name " + obj.Name, - $"have name matching \"{pattern}\""); + $"have name matching \"{pattern}\"" + ); } public static ICondition HaveFullName(string name) @@ -1538,6 +1540,7 @@ public static ICondition HaveFullName(string name) "have full name \"" + name + "\"" ); } + public static ICondition HaveFullNameMatching(string pattern) { return new SimpleCondition( @@ -1767,7 +1770,7 @@ Architecture architecture "not be " + objectProvider.Description ); } - + public static ICondition NotCallAny( MethodMember method, params MethodMember[] moreMethods @@ -1865,7 +1868,7 @@ IEnumerable Condition(IEnumerable ruleTypes) return new EnumerableCondition(Condition, description); } - + public static ICondition NotDependOnAny( IType firstType, params IType[] moreTypes @@ -2628,7 +2631,7 @@ t.Value is ITypeInstance typeInstance return new ArchitectureCondition(Condition, failDescription, description); } - + public static ICondition NotHaveAttributeWithNamedArguments( [NotNull] Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -2830,6 +2833,7 @@ public static ICondition NotHaveName(string name) $"not have name \"{name}\"" ); } + public static ICondition NotHaveNameMatching(string pattern) { return new SimpleCondition( @@ -2839,9 +2843,7 @@ public static ICondition NotHaveNameMatching(string pattern) ); } - public static ICondition NotHaveFullName( - string fullName - ) + public static ICondition NotHaveFullName(string fullName) { return new SimpleCondition( obj => !obj.FullNameEquals(fullName), @@ -2849,9 +2851,8 @@ string fullName "not have full name \"" + fullName + "\"" ); } - public static ICondition NotHaveFullNameMatching( - string pattern - ) + + public static ICondition NotHaveFullNameMatching(string pattern) { return new SimpleCondition( obj => !obj.FullNameMatches(pattern), diff --git a/ArchUnitNET/Fluent/Syntax/Elements/ObjectPredicatesDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/ObjectPredicatesDefinition.cs index 11bfc823a..131f72649 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/ObjectPredicatesDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/ObjectPredicatesDefinition.cs @@ -118,7 +118,7 @@ IEnumerable Filter(IEnumerable objects) return new EnumerablePredicate(Filter, description); } - + public static IPredicate DependOnAny(IType firstType, params IType[] moreTypes) { var types = new List { firstType }; @@ -226,7 +226,7 @@ string description { return new SimplePredicate(predicate, description); } - + public static IPredicate OnlyDependOn(IType firstType, params IType[] moreTypes) { var types = new List { firstType }; @@ -330,7 +330,7 @@ IEnumerable Filter(IEnumerable objects, Architecture architecture) return new ArchitecturePredicate(Filter, description); } - + public static IPredicate HaveAnyAttributes( Attribute firstAttribute, params Attribute[] moreAttributes @@ -643,7 +643,7 @@ bool Predicate(T obj, Architecture architecture) return new ArchitecturePredicate(Predicate, description); } - + public static IPredicate HaveAttributeWithArguments( [NotNull] Attribute attribute, IEnumerable argumentValues @@ -1030,6 +1030,7 @@ public static IPredicate HaveName(string name) "have name \"" + name + "\"" ); } + public static IPredicate HaveNameMatching(string pattern) { return new SimplePredicate( @@ -1045,6 +1046,7 @@ public static IPredicate HaveFullName(string fullName) "have full name \"" + fullName + "\"" ); } + public static IPredicate HaveFullNameMatching(string pattern) { return new SimplePredicate( @@ -1437,7 +1439,6 @@ params object[] moreArgumentValues argumentValues.AddRange(moreArgumentValues); return DoNotHaveAnyAttributesWithArguments(argumentValues); } - public static IPredicate DoNotHaveAttributeWithArguments( Attribute attribute, @@ -1546,7 +1547,7 @@ bool Predicate(T obj, Architecture architecture) return new ArchitecturePredicate(Predicate, description); } - + public static IPredicate DoNotHaveAttributeWithArguments( [NotNull] Attribute attribute, IEnumerable argumentValues @@ -1762,7 +1763,7 @@ t.Value is ITypeInstance typeInstance return new ArchitecturePredicate(Condition, description); } - + public static IPredicate DoNotHaveAttributeWithNamedArguments( [NotNull] Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -1959,7 +1960,7 @@ public static IPredicate DoNotHaveFullNameMatching(string pattern) "do not have full name matching \"" + pattern + "\"" ); } - + public static IPredicate DoNotHaveNameStartingWith(string pattern) { return new SimplePredicate( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShould.cs b/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShould.cs index cd2af7150..b4f263364 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShould.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShould.cs @@ -23,9 +23,7 @@ public abstract class ObjectsShould where TRuleTypeShouldConjunction : SyntaxElement { protected ObjectsShould(IArchRuleCreator ruleCreator) - : base(ruleCreator) - { - } + : base(ruleCreator) { } public TRuleTypeShouldConjunction Exist() { @@ -457,9 +455,7 @@ public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( public TRuleTypeShouldConjunction HaveName(string name) { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveName(name) - ); + _ruleCreator.AddCondition(ObjectConditionsDefinition.HaveName(name)); return Create(_ruleCreator); } @@ -473,9 +469,7 @@ public TRuleTypeShouldConjunction HaveNameMatching(string pattern) public TRuleTypeShouldConjunction HaveFullName(string fullName) { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveFullName(fullName) - ); + _ruleCreator.AddCondition(ObjectConditionsDefinition.HaveFullName(fullName)); return Create(_ruleCreator); } @@ -933,9 +927,7 @@ public TRuleTypeShouldConjunction NotHaveAttributeWithNamedArguments( public TRuleTypeShouldConjunction NotHaveName(string name) { - _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveName(name) - ); + _ruleCreator.AddCondition(ObjectConditionsDefinition.NotHaveName(name)); return Create(_ruleCreator); } @@ -1066,4 +1058,4 @@ public ShouldRelateToAttributesThat< ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/ShouldRelateToObjectsThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/ShouldRelateToObjectsThat.cs index 4e84c4f16..4db158be5 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/ShouldRelateToObjectsThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/ShouldRelateToObjectsThat.cs @@ -48,7 +48,7 @@ public TRuleTypeShouldConjunction Are(IObjectProvider objects) ); return Create(_ruleCreator); } - + public TRuleTypeShouldConjunction CallAny( MethodMember method, params MethodMember[] moreMethods @@ -75,7 +75,7 @@ public TRuleTypeShouldConjunction CallAny(IObjectProvider methods) ); return Create(_ruleCreator); } - + public TRuleTypeShouldConjunction DependOnAny(Type firstType, params Type[] moreTypes) { _ruleCreator.ContinueComplexCondition( @@ -307,7 +307,7 @@ params object[] moreArgumentValues ); return Create(_ruleCreator); } - + public TRuleTypeShouldConjunction HaveAttributeWithArguments( Attribute attribute, IEnumerable argumentValues @@ -393,7 +393,7 @@ public TRuleTypeShouldConjunction HaveAnyAttributesWithNamedArguments( ); return Create(_ruleCreator); } - + public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -461,6 +461,7 @@ public TRuleTypeShouldConjunction HaveName(string name) ); return Create(_ruleCreator); } + public TRuleTypeShouldConjunction HaveNameMatching(string pattern) { _ruleCreator.ContinueComplexCondition( @@ -476,6 +477,7 @@ public TRuleTypeShouldConjunction HaveFullName(string fullName) ); return Create(_ruleCreator); } + public TRuleTypeShouldConjunction HaveFullNameMatching(string pattern) { _ruleCreator.ContinueComplexCondition( @@ -896,6 +898,7 @@ public TRuleTypeShouldConjunction DoNotHaveName(string name) ); return Create(_ruleCreator); } + public TRuleTypeShouldConjunction DoNotHaveNameMatching(string pattern) { _ruleCreator.ContinueComplexCondition( @@ -911,6 +914,7 @@ public TRuleTypeShouldConjunction DoNotHaveFullName(string fullName) ); return Create(_ruleCreator); } + public TRuleTypeShouldConjunction DoNotHaveFullNameMatching(string pattern) { _ruleCreator.ContinueComplexCondition( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesThat.cs index debbdca3f..c7a592f4d 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesThat.cs @@ -19,9 +19,7 @@ public class GivenTypesThat { // ReSharper disable once MemberCanBeProtected.Global public GivenTypesThat(IArchRuleCreator ruleCreator) - : base(ruleCreator) - { - } + : base(ruleCreator) { } public TGivenRuleTypeConjunction Are(Type firstType, params Type[] moreTypes) { @@ -158,7 +156,7 @@ public TGivenRuleTypeConjunction ResideInAssembly(string fullName) ); return Create(_ruleCreator); } - + public TGivenRuleTypeConjunction ResideInAssemblyMatching(string pattern) { _ruleCreator.AddPredicate( @@ -326,7 +324,7 @@ public TGivenRuleTypeConjunction DoNotResideInNamespace(string fullName) ); return Create(_ruleCreator); } - + public TGivenRuleTypeConjunction DoNotResideInNamespaceMatching(string pattern) { _ruleCreator.AddPredicate( @@ -342,7 +340,9 @@ public TGivenRuleTypeConjunction DoNotResideInAssembly(string fullName) ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotResideInAssemblyMatching(string pattern){ + + public TGivenRuleTypeConjunction DoNotResideInAssemblyMatching(string pattern) + { _ruleCreator.AddPredicate( TypePredicatesDefinition.DoNotResideInAssemblyMatching(pattern) ); @@ -409,4 +409,4 @@ public TGivenRuleTypeConjunction AreNotNested() return Create(_ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/ShouldRelateToTypesThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/ShouldRelateToTypesThat.cs index b3ddb95a5..786fa8800 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/ShouldRelateToTypesThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/ShouldRelateToTypesThat.cs @@ -165,6 +165,7 @@ public TRuleTypeShouldConjunction ResideInNamespace(string fullName) ); return Create(_ruleCreator); } + public TRuleTypeShouldConjunction ResideInNamespaceMatching(string pattern) { _ruleCreator.ContinueComplexCondition( @@ -180,7 +181,7 @@ public TRuleTypeShouldConjunction ResideInAssembly(string fullName) ); return Create(_ruleCreator); } - + public TRuleTypeShouldConjunction ResideInAssemblyMatching(string pattern) { _ruleCreator.ContinueComplexCondition( @@ -189,7 +190,6 @@ public TRuleTypeShouldConjunction ResideInAssemblyMatching(string pattern) return Create(_ruleCreator); } - public TRuleTypeShouldConjunction ResideInAssembly( Assembly assembly, params Assembly[] moreAssemblies @@ -270,7 +270,7 @@ public TRuleTypeShouldConjunction AreNot(IEnumerable types) ); return Create(_ruleCreator); } - + public TRuleTypeShouldConjunction AreNotAssignableTo( IType firstType, params IType[] moreTypes @@ -364,6 +364,7 @@ public TRuleTypeShouldConjunction DoNotResideInNamespace(string fullName) ); return Create(_ruleCreator); } + public TRuleTypeShouldConjunction DoNotResideInNamespaceMatching(string pattern) { _ruleCreator.ContinueComplexCondition( @@ -379,6 +380,7 @@ public TRuleTypeShouldConjunction DoNotResideInAssembly(string fullName) ); return Create(_ruleCreator); } + public TRuleTypeShouldConjunction DoNotResideInAssemblyMatching(string pattern) { _ruleCreator.ContinueComplexCondition( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypeConditionsDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypeConditionsDefinition.cs index 8126f5b28..2f9fb3e0f 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypeConditionsDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypeConditionsDefinition.cs @@ -536,6 +536,7 @@ public static ICondition ResideInNamespace(string fullName) "reside in namespace with full name \"" + fullName + "\"" ); } + public static ICondition ResideInNamespaceMatching(string pattern) { return new SimpleCondition( @@ -553,6 +554,7 @@ public static ICondition ResideInAssembly(string fullName) "reside in assembly with full name \"" + fullName + "\"" ); } + public static ICondition ResideInAssemblyMatching(string pattern) { return new SimpleCondition( @@ -560,7 +562,7 @@ public static ICondition ResideInAssemblyMatching(string pattern) obj => "does reside in " + obj.Assembly.FullName, "reside in assembly with full name matching \"" + pattern + "\"" ); - } + } public static ICondition ResideInAssembly( System.Reflection.Assembly assembly, @@ -663,9 +665,7 @@ ConditionResult Condition(TRuleType ruleType) { if ( classDiagramAssociation.Contains(dependency) - && !allAllowedTargets.Any(pattern => - dependency.FullNameMatches(pattern) - ) + && !allAllowedTargets.Any(pattern => dependency.FullNameMatches(pattern)) ) { dynamicFailDescription += pass @@ -1131,6 +1131,7 @@ public static ICondition NotResideInAssembly(string fullName) "not reside in assembly with full name \"" + fullName + "\"" ); } + public static ICondition NotResideInAssemblyMatching(string pattern) { return new SimpleCondition( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypePredicatesDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypePredicatesDefinition.cs index 8e364cd7a..2beff1e71 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypePredicatesDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypePredicatesDefinition.cs @@ -314,7 +314,7 @@ public static IPredicate AreStructs() { return new SimplePredicate(type => type is Struct, "are structs"); } - + public static IPredicate ImplementInterface(Interface intf) { return new SimplePredicate( @@ -354,6 +354,7 @@ public static IPredicate ResideInNamespace(string fullName) "reside in namespace with full name \"" + fullName + "\"" ); } + public static IPredicate ResideInNamespaceMatching(string pattern) { return new SimplePredicate( @@ -369,6 +370,7 @@ public static IPredicate ResideInAssembly(string fullName) "reside in assembly with full name \"" + fullName + "\"" ); } + public static IPredicate ResideInAssemblyMatching(string pattern) { return new SimplePredicate( @@ -642,7 +644,7 @@ public static IPredicate AreNotStructs() { return new SimplePredicate(cls => !(cls is Struct), "are not structs"); } - + public static IPredicate DoNotImplementInterface(Interface intf) { return new SimplePredicate( @@ -682,6 +684,7 @@ public static IPredicate DoNotResideInNamespace(string fullName) "do not reside in namespace with full name \"" + fullName + "\"" ); } + public static IPredicate DoNotResideInNamespaceMatching(string pattern) { return new SimplePredicate( @@ -697,6 +700,7 @@ public static IPredicate DoNotResideInAssembly(string fullName) "do not reside in assembly with full name \"" + fullName + "\"" ); } + public static IPredicate DoNotResideInAssemblyMatching(string pattern) { return new SimplePredicate( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShould.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShould.cs index a87f17ebb..3eaa17f83 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShould.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShould.cs @@ -156,6 +156,7 @@ public TRuleTypeShouldConjunction ResideInAssembly(string fullName) ); return Create(_ruleCreator); } + public TRuleTypeShouldConjunction ResideInAssemblyMatching(string pattern) { _ruleCreator.AddCondition( @@ -255,7 +256,7 @@ public TRuleTypeShouldConjunction NotBe(IEnumerable types) _ruleCreator.AddCondition(TypeConditionsDefinition.NotBe(types)); return Create(_ruleCreator); } - + public TRuleTypeShouldConjunction NotBeAssignableTo( IType firstType, params IType[] moreTypes @@ -334,6 +335,7 @@ public TRuleTypeShouldConjunction NotResideInNamespace(string fullName) ); return Create(_ruleCreator); } + public TRuleTypeShouldConjunction NotResideInNamespaceMatching(string pattern) { _ruleCreator.AddCondition( @@ -349,6 +351,7 @@ public TRuleTypeShouldConjunction NotResideInAssembly(string fullName) ); return Create(_ruleCreator); } + public TRuleTypeShouldConjunction NotResideInAssemblyMatching(string pattern) { _ruleCreator.AddCondition( diff --git a/ArchUnitNETTests/Domain/Extensions/TypeExtensionTests.cs b/ArchUnitNETTests/Domain/Extensions/TypeExtensionTests.cs index bc117b3d9..b9ef9faf9 100644 --- a/ArchUnitNETTests/Domain/Extensions/TypeExtensionTests.cs +++ b/ArchUnitNETTests/Domain/Extensions/TypeExtensionTests.cs @@ -78,7 +78,7 @@ public void FullNameMatchesTest() Assert.True(_propertyOriginClass.FullNameMatches("(?i)sswITH")); Assert.False(_exampleAttribute.FullNameMatches(null)); } - + [Fact] public void FullNameEqualsTest() { @@ -209,7 +209,7 @@ public void NameMatchesTest() Assert.True(_propertyOriginClass.NameMatches("(?i)sswITH")); Assert.False(_exampleAttribute.NameMatches(null)); } - + [Fact] public void NameEqualsTest() { diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/MemberSyntaxElementsTests.cs b/ArchUnitNETTests/Fluent/Syntax/Elements/MemberSyntaxElementsTests.cs index f1d52c5fe..6adc5ee68 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/MemberSyntaxElementsTests.cs +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/MemberSyntaxElementsTests.cs @@ -38,12 +38,17 @@ public MemberSyntaxElementsTests() typeof(InternalTestClass), }; - private static readonly IObjectProvider FalseTypeConstructors = MethodMembers().That() - .HaveFullName("System.Void ArchUnitNETTests.Domain.PublicTestClass::.ctor()").Or() - .HaveFullName("System.Void ArchUnitNETTests.Domain.InternalTestClass::.ctor()"); + private static readonly IObjectProvider FalseTypeConstructors = + MethodMembers() + .That() + .HaveFullName("System.Void ArchUnitNETTests.Domain.PublicTestClass::.ctor()") + .Or() + .HaveFullName("System.Void ArchUnitNETTests.Domain.InternalTestClass::.ctor()"); private static readonly IObjectProvider PublicTestClassConstructor = - MethodMembers().That().HaveFullName("System.Void ArchUnitNETTests.Domain.PublicTestClass::.ctor()"); + MethodMembers() + .That() + .HaveFullName("System.Void ArchUnitNETTests.Domain.PublicTestClass::.ctor()"); [Fact] public void DeclaredInTest() diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectSyntaxElementsTests.cs b/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectSyntaxElementsTests.cs index ee590b8fd..74afd8234 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectSyntaxElementsTests.cs +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectSyntaxElementsTests.cs @@ -44,26 +44,14 @@ public void AreTest() var otherTypesAreNotThisType = Types().That().AreNot(type).Should().NotBe(type); var otherTypesAreThisType = Types().That().AreNot(type).Should().Be(type); - var typeIsItselfPattern = Types() - .That() - .Are(type) - .Should() - .Be(type); - var typeIsNotItselfPattern = Types() - .That() - .Are(type) - .Should() - .NotBe(type); + var typeIsItselfPattern = Types().That().Are(type).Should().Be(type); + var typeIsNotItselfPattern = Types().That().Are(type).Should().NotBe(type); var otherTypesAreNotThisTypePattern = Types() .That() .AreNot(type) .Should() .NotBe(type); - var otherTypesAreThisTypePattern = Types() - .That() - .AreNot(type) - .Should() - .Be(type); + var otherTypesAreThisTypePattern = Types().That().AreNot(type).Should().Be(type); Assert.True(typeIsItself.HasNoViolations(Architecture)); Assert.False(typeIsNotItself.HasNoViolations(Architecture)); @@ -103,7 +91,7 @@ public void AreTest() Assert.False(publicTypesAreNotPublicTestClass.HasNoViolations(Architecture)); //Tests with multiple arguments - + var publicTestClassAndInternalTestClassIsPublicOrInternal = Types() .That() .Are(StaticTestTypes.PublicTestClass, StaticTestTypes.InternalTestClass) @@ -173,7 +161,7 @@ public void AreTest() .AreInternal() .Should() .NotBe(list); - + Assert.True( listPublicTestClassAndInternalTestClassIsPublicOrInternal.HasNoViolations( Architecture diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectsShouldTests.cs b/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectsShouldTests.cs index 4d0b5027f..33136092c 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectsShouldTests.cs +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectsShouldTests.cs @@ -38,7 +38,9 @@ public async Task BeTest() should = Types().That().Are(helper.BaseClass).Should(); should.Be(new List()).AssertOnlyViolations(helper); should.Be(new List()).AssertOnlyViolations(helper); - should.Be(Classes().That().HaveFullName(helper.NonExistentObjectName)).AssertOnlyViolations(helper); + should + .Be(Classes().That().HaveFullName(helper.NonExistentObjectName)) + .AssertOnlyViolations(helper); helper.AddSnapshotHeader("Multiple arguments"); should = Types().That().Are(helper.ChildClass).Should(); @@ -530,7 +532,10 @@ public async Task DependOnAnyTest() should.DependOnAny([helper.BaseClassSystemType]).AssertNoViolations(helper); helper.AddSnapshotHeader("Violations"); - should = Types().That().HaveFullName(helper.ClassWithMultipleDependencies.FullName).Should(); + should = Types() + .That() + .HaveFullName(helper.ClassWithMultipleDependencies.FullName) + .Should(); should.DependOnAny(helper.ClassWithoutDependencies).AssertOnlyViolations(helper); should.DependOnAny(helper.ClassWithoutDependenciesSystemType).AssertOnlyViolations(helper); should @@ -540,7 +545,7 @@ public async Task DependOnAnyTest() should .DependOnAny([helper.ClassWithoutDependenciesSystemType]) .AssertOnlyViolations(helper); - + helper.AddSnapshotHeader("Type outside of architecture"); should = Types().That().Are(helper.ClassWithMultipleDependencies).Should(); should @@ -572,9 +577,7 @@ public async Task DependOnAnyTest() helper.AddSnapshotHeader("Input without dependencies"); should = Types().That().Are(helper.ClassWithoutDependencies).Should(); - should - .DependOnAny([helper.BaseClass, helper.ChildClass]) - .AssertOnlyViolations(helper); + should.DependOnAny([helper.BaseClass, helper.ChildClass]).AssertOnlyViolations(helper); helper.AddSnapshotHeader("Multiple inputs"); Types() @@ -1444,7 +1447,9 @@ public async Task NotBeTest() should = Types().That().DependOnAny(helper.BaseClass).Should(); should.NotBe(new List()).AssertNoViolations(helper); should.NotBe(new List()).AssertNoViolations(helper); - should.NotBe(Classes().That().HaveFullName(helper.NonExistentObjectName)).AssertNoViolations(helper); + should + .NotBe(Classes().That().HaveFullName(helper.NonExistentObjectName)) + .AssertNoViolations(helper); helper.AddSnapshotHeader("Multiple arguments"); should = Types().That().DependOnAny(helper.BaseClass).Should(); @@ -2487,10 +2492,7 @@ public async Task OnlyHaveAttributesThatTest() helper.AddSnapshotHeader("Violations"); should = Types().That().Are(helper.ClassWithSingleAttribute).Should(); - should - .OnlyHaveAttributesThat() - .Are(helper.UnusedAttribute) - .AssertOnlyViolations(helper); + should.OnlyHaveAttributesThat().Are(helper.UnusedAttribute).AssertOnlyViolations(helper); await helper.AssertSnapshotMatches(); } diff --git a/ExampleTest/ExampleArchUnitTest.cs b/ExampleTest/ExampleArchUnitTest.cs index 0d562b0b1..df8e1b3b5 100644 --- a/ExampleTest/ExampleArchUnitTest.cs +++ b/ExampleTest/ExampleArchUnitTest.cs @@ -162,4 +162,4 @@ internal class ExampleClass { } internal class ForbiddenClass { } -internal interface IExampleInterface { } \ No newline at end of file +internal interface IExampleInterface { } From a45fe03aba4083f05b0ed98c6557974cee2f6cd0 Mon Sep 17 00:00:00 2001 From: Fritz Brandhuber Date: Fri, 4 Apr 2025 17:54:31 +0200 Subject: [PATCH 7/7] Re-add methods with string and useRegularExpressions parameters and mark them as obsolete Signed-off-by: Fritz Brandhuber --- .../Domain/Extensions/AttributeExtensions.cs | 30 + .../Domain/Extensions/DependencyExtensions.cs | 40 + .../Domain/Extensions/MemberExtensions.cs | 45 + .../Domain/Extensions/NamingExtensions.cs | 34 + .../Domain/Extensions/TypeExtensions.cs | 78 + .../PlantUml/Export/DependencyFilters.cs | 35 + .../Syntax/Elements/GivenObjectsThat.cs | 489 ++++++ .../Syntax/Elements/IObjectConditions.cs | 166 ++ .../Syntax/Elements/IObjectPredicates.cs | 198 +++ .../Elements/Members/GivenMembersThat.cs | 62 + .../Elements/Members/IMemberConditions.cs | 21 + .../Elements/Members/IMemberPredicates.cs | 26 + .../Members/MemberConditionsDefinition.cs | 129 ++ .../Members/MemberPredicatesDefinition.cs | 118 ++ .../Syntax/Elements/Members/MembersShould.cs | 62 + .../MethodMembers/GivenMethodMembersThat.cs | 183 +++ .../MethodMembers/IMethodMemberConditions.cs | 78 + .../MethodMembers/IMethodMemberPredicates.cs | 89 ++ .../MethodMemberConditionsDefinition.cs | 467 ++++++ .../MethodMemberPredicatesDefinition.cs | 323 ++++ .../MethodMembers/MethodMembersShould.cs | 180 +++ .../ShouldRelateToMethodMembersThat.cs | 183 +++ .../Members/ShouldRelateToMembersThat.cs | 68 + .../Elements/ObjectConditionsDefinition.cs | 1371 ++++++++++++++++- .../Elements/ObjectPredicatesDefinition.cs | 1008 +++++++++++- .../Fluent/Syntax/Elements/ObjectsShould.cs | 489 ++++++ .../Elements/ShouldRelateToObjectsThat.cs | 516 +++++++ .../Syntax/Elements/Types/GivenTypesThat.cs | 161 ++ .../Syntax/Elements/Types/ITypeConditions.cs | 56 + .../Syntax/Elements/Types/ITypePredicates.cs | 57 +- .../Elements/Types/ShouldRelateToTypesThat.cs | 170 ++ .../Types/TypeConditionsDefinition.cs | 290 ++++ .../Types/TypePredicatesDefinition.cs | 224 +++ .../Syntax/Elements/Types/TypesShould.cs | 161 ++ 34 files changed, 7555 insertions(+), 52 deletions(-) diff --git a/ArchUnitNET/Domain/Extensions/AttributeExtensions.cs b/ArchUnitNET/Domain/Extensions/AttributeExtensions.cs index 85c2f69c0..e4d7867c2 100644 --- a/ArchUnitNET/Domain/Extensions/AttributeExtensions.cs +++ b/ArchUnitNET/Domain/Extensions/AttributeExtensions.cs @@ -5,17 +5,47 @@ // SPDX-License-Identifier: Apache-2.0 // +using System; using System.Linq; namespace ArchUnitNET.Domain.Extensions { public static class AttributeExtensions { + [Obsolete( + "Either HasAttribute() without the useRegularExpressions parameter or HasAttributeMatching() should be used" + )] + public static bool HasAttribute( + this IHasAttributes a, + string pattern, + bool useRegularExpressions + ) + { + return a.Attributes.Any(attribute => + attribute.FullNameMatches(pattern, useRegularExpressions) + ); + } + public static bool HasAttribute(this IHasAttributes a, string fullName) { return a.Attributes.Any(attribute => attribute.FullNameEquals(fullName)); } + [Obsolete( + "Either OnlyHasAttributes() without the useRegularExpressions parameter or OnlyHasAttributesMatching() should be used" + )] + public static bool OnlyHasAttributes( + this IHasAttributes a, + string pattern, + bool useRegularExpressions + ) + { + return a.Attributes.IsNullOrEmpty() + || a.Attributes.All(attribute => + attribute.FullNameMatches(pattern, useRegularExpressions) + ); + } + public static bool HasAttributeMatching(this IHasAttributes a, string pattern) { return a.Attributes.Any(attribute => attribute.FullNameMatches(pattern)); diff --git a/ArchUnitNET/Domain/Extensions/DependencyExtensions.cs b/ArchUnitNET/Domain/Extensions/DependencyExtensions.cs index a27548fae..217071351 100644 --- a/ArchUnitNET/Domain/Extensions/DependencyExtensions.cs +++ b/ArchUnitNET/Domain/Extensions/DependencyExtensions.cs @@ -5,6 +5,7 @@ // SPDX-License-Identifier: Apache-2.0 // +using System; using System.Collections.Generic; using System.Linq; using ArchUnitNET.Domain.Dependencies; @@ -13,6 +14,19 @@ namespace ArchUnitNET.Domain.Extensions { public static class DependencyExtensions { + [Obsolete( + "Either CallsMethod() without the useRegularExpressions parameter or CallsMethodMatching() should be used" + )] + public static bool CallsMethod( + this IHasDependencies type, + string pattern, + bool useRegularExpressions + ) + { + return type.GetCalledMethods() + .Any(member => member.FullNameMatches(pattern, useRegularExpressions)); + } + public static bool CallsMethod(this IHasDependencies type, string fullName) { return type.GetCalledMethods().Any(member => member.FullNameEquals(fullName)); @@ -37,6 +51,19 @@ public static IEnumerable GetAccessedFieldMembers(this IHasDependen .Select(dependency => (FieldMember)dependency.TargetMember); } + [Obsolete( + "Either DependsOnType() without the useRegularExpressions parameter or DependsOnTypeMatching() should be used" + )] + public static bool DependsOn( + this IHasDependencies c, + string pattern, + bool useRegularExpressions = false + ) + { + return c.GetTypeDependencies() + .Any(d => d.FullNameMatches(pattern, useRegularExpressions)); + } + public static bool DependsOnType(this IHasDependencies c, string fullName) { return c.GetTypeDependencies().Any(d => d.FullNameEquals(fullName)); @@ -47,6 +74,19 @@ public static bool DependsOnTypeMatching(this IHasDependencies c, string pattern return c.GetTypeDependencies().Any(d => d.FullNameMatches(pattern)); } + [Obsolete( + "Either OnlyDependsOnType() without the useRegularExpressions parameter or OnlyDependsOnTypesMatching() should be used" + )] + public static bool OnlyDependsOn( + this IHasDependencies c, + string pattern, + bool useRegularExpressions = false + ) + { + return c.GetTypeDependencies() + .All(d => d.FullNameMatches(pattern, useRegularExpressions)); + } + public static bool OnlyDependsOnType(this IHasDependencies c, string fullName) { return c.GetTypeDependencies().All(d => d.FullNameEquals(fullName)); diff --git a/ArchUnitNET/Domain/Extensions/MemberExtensions.cs b/ArchUnitNET/Domain/Extensions/MemberExtensions.cs index 1142cea09..9578bbf62 100644 --- a/ArchUnitNET/Domain/Extensions/MemberExtensions.cs +++ b/ArchUnitNET/Domain/Extensions/MemberExtensions.cs @@ -4,6 +4,7 @@ // // SPDX-License-Identifier: Apache-2.0 +using System; using System.Collections.Generic; using System.Linq; using ArchUnitNET.Domain.Dependencies; @@ -12,6 +13,18 @@ namespace ArchUnitNET.Domain.Extensions { public static class MemberExtensions { + [Obsolete( + "Either IsDeclaredIn() without the useRegularExpressions parameter or IsDeclaredInTypeMatching() should be used" + )] + public static bool IsDeclaredIn( + this IMember member, + string pattern, + bool useRegularExpressions + ) + { + return member.DeclaringType.FullNameMatches(pattern, useRegularExpressions); + } + public static bool IsDeclaredIn(this IMember member, string fullName) { return member.DeclaringType.FullNameEquals(fullName); @@ -63,6 +76,22 @@ public static bool HasMethodCallDependencies( return member.GetMethodCallDependencies(getBackwardsDependencies).Any(); } + [Obsolete( + "Either IsCalledByType() without the useRegularExpressions parameter or IsCalledByTypeMatching() should be used" + )] + public static bool IsCalledBy( + this MethodMember member, + string pattern, + bool useRegularExpressions = false + ) + { + return member + .GetMethodCallDependencies(true) + .Any(dependency => + dependency.Origin.FullNameMatches(pattern, useRegularExpressions) + ); + } + public static bool IsCalledByType(this MethodMember member, string fullName) { return member @@ -85,6 +114,22 @@ public static IEnumerable GetCallingTypes(this MethodMember member) .Distinct(); } + [Obsolete( + "Either HasDependencyInMethodBodyToType() without the useRegularExpressions parameter or HasDependencyInMethodBodyToTypeMatching() should be used" + )] + public static bool HasDependencyInMethodBodyTo( + this MethodMember member, + string pattern, + bool useRegularExpressions = false + ) + { + return member + .GetBodyTypeMemberDependencies() + .Any(dependency => + dependency.Target.FullNameMatches(pattern, useRegularExpressions) + ); + } + public static bool HasDependencyInMethodBodyToType( this MethodMember member, string fullName diff --git a/ArchUnitNET/Domain/Extensions/NamingExtensions.cs b/ArchUnitNET/Domain/Extensions/NamingExtensions.cs index 9055489a7..f1b5f684b 100644 --- a/ArchUnitNET/Domain/Extensions/NamingExtensions.cs +++ b/ArchUnitNET/Domain/Extensions/NamingExtensions.cs @@ -43,6 +43,23 @@ public static bool NameContains( return cls.Name.IndexOf(pattern, stringComparison) >= 0; } + [Obsolete( + "Either NameEquals() or NameMatches() without the useRegularExpressions parameter should be used" + )] + public static bool NameMatches( + this IHasName cls, + string pattern, + bool useRegularExpressions + ) + { + if (useRegularExpressions) + { + return pattern != null && Regex.IsMatch(cls.Name, pattern); + } + + return string.Equals(cls.Name, pattern, StringComparison.OrdinalIgnoreCase); + } + public static bool NameEquals(this IHasName cls, string name) { return string.Equals(cls.Name, name, StringComparison.OrdinalIgnoreCase); @@ -53,6 +70,23 @@ public static bool NameMatches(this IHasName cls, string pattern) return pattern != null && Regex.IsMatch(cls.Name, pattern); } + [Obsolete( + "Either FullNameEquals() or FullNameMatches() without the useRegularExpressions parameter should be used" + )] + public static bool FullNameMatches( + this IHasName cls, + string pattern, + bool useRegularExpressions + ) + { + if (useRegularExpressions) + { + return pattern != null && Regex.IsMatch(cls.FullName, pattern); + } + + return string.Equals(cls.FullName, pattern, StringComparison.OrdinalIgnoreCase); + } + public static bool FullNameEquals(this IHasName cls, string fullName) { return string.Equals(cls.FullName, fullName, StringComparison.OrdinalIgnoreCase); diff --git a/ArchUnitNET/Domain/Extensions/TypeExtensions.cs b/ArchUnitNET/Domain/Extensions/TypeExtensions.cs index cf247c70e..305dfd540 100644 --- a/ArchUnitNET/Domain/Extensions/TypeExtensions.cs +++ b/ArchUnitNET/Domain/Extensions/TypeExtensions.cs @@ -25,6 +25,25 @@ public static bool ImplementsInterface(this IType type, Interface intf) ); } + [Obsolete( + "Either ImplementsInterface() without the useRegularExpressions parameter or ImplementsInterfaceMatching() should be used" + )] + public static bool ImplementsInterface( + this IType type, + string pattern, + bool useRegularExpressions + ) + { + if (type is GenericParameter) + { + return false; + } + + return type.ImplementedInterfaces.Any(implementedInterface => + implementedInterface.FullNameMatches(pattern, useRegularExpressions) + ); + } + public static bool ImplementsInterface(this IType type, string fullName) { if (type is GenericParameter) @@ -61,6 +80,26 @@ public static bool IsAssignableTo(this IType type, IType assignableToType) return type.GetAssignableTypes().Contains(assignableToType); } + [Obsolete( + "Either IsAssignableTo() without the useRegularExpressions parameter or IsAssignableToTypeMatching() should be used" + )] + public static bool IsAssignableTo( + this IType type, + string pattern, + bool useRegularExpressions + ) + { + if (type is GenericParameter genericParameter) + { + return genericParameter.TypeConstraints.All(t => + t.IsAssignableTo(pattern, useRegularExpressions) + ); + } + + return type.GetAssignableTypes() + .Any(t => t.FullNameMatches(pattern, useRegularExpressions)); + } + public static bool IsAssignableTo(this IType type, string fullName) { if (type is GenericParameter genericParameter) @@ -245,6 +284,18 @@ public static Attribute GetAttributeOfType(this IType type, Class attributeClass ); } + [Obsolete( + "Either ResidesInNamespace() without the useRegularExpressions parameter or ResidesInNamespaceMatching() should be used" + )] + public static bool ResidesInNamespace( + this IType e, + string pattern, + bool useRegularExpressions + ) + { + return e.Namespace.FullNameMatches(pattern, useRegularExpressions); + } + public static bool ResidesInNamespace(this IType e, string fullName) { return e.Namespace.FullNameEquals(fullName); @@ -255,6 +306,18 @@ public static bool ResidesInNamespaceMatching(this IType e, string pattern) return e.Namespace.FullNameMatches(pattern); } + [Obsolete( + "Either ResidesInAssembly() without the useRegularExpressions parameter or ResidesInAssemblyMatching() should be used" + )] + public static bool ResidesInAssembly( + this IType e, + string pattern, + bool useRegularExpressions + ) + { + return e.Assembly.FullNameMatches(pattern, useRegularExpressions); + } + public static bool ResidesInAssembly(this IType e, string fullName) { return e.Assembly.FullNameEquals(fullName); @@ -265,6 +328,21 @@ public static bool ResidesInAssemblyMatching(this IType e, string pattern) return e.Assembly.FullNameMatches(pattern); } + [Obsolete( + "Either IsDeclaredAsFieldIn() without the useRegularExpressions parameter or IsDeclaredAsFieldInTypeMatching() should be used" + )] + public static bool IsDeclaredAsFieldIn( + this IType type, + string pattern, + bool useRegularExpressions + ) + { + return type.GetFieldTypeDependencies(true) + .Any(dependency => + dependency.Target.FullNameMatches(pattern, useRegularExpressions) + ); + } + public static bool IsDeclaredAsFieldIn(this IType type, string fullName) { return type.GetFieldTypeDependencies(true) diff --git a/ArchUnitNET/Domain/PlantUml/Export/DependencyFilters.cs b/ArchUnitNET/Domain/PlantUml/Export/DependencyFilters.cs index cb4bd24d9..dbba6c55a 100644 --- a/ArchUnitNET/Domain/PlantUml/Export/DependencyFilters.cs +++ b/ArchUnitNET/Domain/PlantUml/Export/DependencyFilters.cs @@ -57,6 +57,19 @@ public static Func FocusOn(IEnumerable types) }; } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public static Func FocusOn( + string pattern, + bool useRegularExpressions = false + ) + { + return dependency => + dependency.Target.FullNameMatches(pattern, useRegularExpressions) + ^ dependency.Origin.FullNameMatches(pattern, useRegularExpressions); + } + public static Func HasOrigin(IType type) { return dependency => dependency.Origin.Equals(type); @@ -67,6 +80,17 @@ public static Func HasOrigin(IEnumerable types) return dependency => types.Contains(dependency.Origin); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public static Func HasOrigin( + string pattern, + bool useRegularExpressions = false + ) + { + return dependency => dependency.Origin.FullNameMatches(pattern, useRegularExpressions); + } + public static Func HasTarget(IType type) { return dependency => dependency.Target.Equals(type); @@ -76,5 +100,16 @@ public static Func HasTarget(IEnumerable types) { return dependency => types.Contains(dependency.Target); } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public static Func HasTarget( + string pattern, + bool useRegularExpressions = false + ) + { + return dependency => dependency.Target.FullNameMatches(pattern, useRegularExpressions); + } } } diff --git a/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsThat.cs index bd8d2fdde..a00aacaa2 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsThat.cs @@ -21,6 +21,31 @@ public abstract class GivenObjectsThat protected GivenObjectsThat(IArchRuleCreator ruleCreator) : base(ruleCreator) { } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use Are(Types().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction Are(string pattern, bool useRegularExpressions = false) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.Are(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use Are(Types().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction Are( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.Are(patterns, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction Are( ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects @@ -44,6 +69,31 @@ public TGivenRuleTypeConjunction Are(IObjectProvider objects) return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use CallAny(MethodMembers().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction CallAny(string pattern, bool useRegularExpressions = false) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.CallAny(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use CallAny(MethodMembers().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction CallAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.CallAny(patterns, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction CallAny( MethodMember method, params MethodMember[] moreMethods @@ -67,6 +117,34 @@ public TGivenRuleTypeConjunction CallAny(IObjectProvider methods) return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DependOnAny(Types().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction DependOnAny( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DependOnAny(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DependOnAny(Types().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction DependOnAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DependOnAny(patterns, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction DependOnAny(Type firstType, params Type[] moreTypes) { _ruleCreator.AddPredicate( @@ -118,6 +196,34 @@ string description return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyDependOn(Types().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction OnlyDependOn( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.OnlyDependOn(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyDependOn(Types().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction OnlyDependOn( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.OnlyDependOn(patterns, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction OnlyDependOn(Type firstType, params Type[] moreTypes) { _ruleCreator.AddPredicate( @@ -152,6 +258,40 @@ public TGivenRuleTypeConjunction OnlyDependOn(IEnumerable types) return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveAnyAttributes(Attributes().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction HaveAnyAttributes( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveAnyAttributes( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveAnyAttributes(Attributes().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction HaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveAnyAttributes( + patterns, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction HaveAnyAttributes( Type firstAttribute, params Type[] moreAttributes @@ -204,6 +344,40 @@ public TGivenRuleTypeConjunction HaveAnyAttributes(IEnumerable attributes) return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyHaveAttributes(Attributes().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction OnlyHaveAttributes( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.OnlyHaveAttributes( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyHaveAttributes(Attributes().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction OnlyHaveAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.OnlyHaveAttributes( + patterns, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction OnlyHaveAttributes( Type firstAttribute, params Type[] moreAttributes @@ -280,6 +454,42 @@ params object[] moreArgumentValues return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TGivenRuleTypeConjunction HaveAttributeWithArguments( + string attribute, + IEnumerable argumentValues + ) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveAttributeWithArguments( + attribute, + argumentValues + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TGivenRuleTypeConjunction HaveAttributeWithArguments( + string attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveAttributeWithArguments( + attribute, + firstArgumentValue, + moreArgumentValues + ) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction HaveAttributeWithArguments( Attribute attribute, IEnumerable argumentValues @@ -366,6 +576,42 @@ public TGivenRuleTypeConjunction HaveAnyAttributesWithNamedArguments( return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TGivenRuleTypeConjunction HaveAttributeWithNamedArguments( + string attribute, + IEnumerable<(string, object)> attributeArguments + ) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveAttributeWithNamedArguments( + attribute, + attributeArguments + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TGivenRuleTypeConjunction HaveAttributeWithNamedArguments( + string attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveAttributeWithNamedArguments( + attribute, + firstAttributeArgument, + moreAttributeArguments + ) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction HaveAttributeWithNamedArguments( Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -426,6 +672,17 @@ public TGivenRuleTypeConjunction HaveAttributeWithNamedArguments( return Create(_ruleCreator); } + [Obsolete( + "Either HaveName() without the useRegularExpressions parameter or HaveNameMatching() should be used" + )] + public TGivenRuleTypeConjunction HaveName(string pattern, bool useRegularExpressions) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveName(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction HaveName(string name) { _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveName(name)); @@ -440,6 +697,17 @@ public TGivenRuleTypeConjunction HaveNameMatching(string pattern) return Create(_ruleCreator); } + [Obsolete( + "Either HaveFullName() without the useRegularExpressions parameter or HaveFullNameMatching() should be used" + )] + public TGivenRuleTypeConjunction HaveFullName(string pattern, bool useRegularExpressions) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveFullName(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction HaveFullName(string fullName) { _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveFullName(fullName)); @@ -524,6 +792,31 @@ public TGivenRuleTypeConjunction ArePrivateProtected() //Negations + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNot(Types().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction AreNot(string pattern, bool useRegularExpressions = false) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.AreNot(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNot(Types().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction AreNot( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.AreNot(patterns, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction AreNot( ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects @@ -547,6 +840,34 @@ public TGivenRuleTypeConjunction AreNot(IObjectProvider objects) return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotCallAny(MethodMembers().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction DoNotCallAny( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotCallAny(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotCallAny(MethodMembers().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction DoNotCallAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotCallAny(patterns, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction DoNotCallAny( MethodMember method, params MethodMember[] moreMethods @@ -570,6 +891,40 @@ public TGivenRuleTypeConjunction DoNotCallAny(IObjectProvider meth return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotDependOnAny(Types().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction DoNotDependOnAny( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotDependOnAny( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotDependOnAny(Types().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction DoNotDependOnAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotDependOnAny( + patterns, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction DoNotDependOnAny(Type firstType, params Type[] moreTypes) { _ruleCreator.AddPredicate( @@ -610,6 +965,40 @@ public TGivenRuleTypeConjunction DoNotDependOnAny(IEnumerable types) return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotHaveAnyAttributes(Attributes().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction DoNotHaveAnyAttributes( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveAnyAttributes( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotHaveAnyAttributes(Attributes().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction DoNotHaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveAnyAttributes( + patterns, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction DoNotHaveAnyAttributes( Type firstAttribute, params Type[] moreAttributes @@ -690,6 +1079,78 @@ params object[] moreArgumentValues return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TGivenRuleTypeConjunction DoNotHaveAttributeWithArguments( + string attribute, + IEnumerable argumentValues + ) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments( + attribute, + argumentValues + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TGivenRuleTypeConjunction DoNotHaveAttributeWithArguments( + string attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments( + attribute, + firstArgumentValue, + moreArgumentValues + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TGivenRuleTypeConjunction DoNotHaveAttributeWithNamedArguments( + string attribute, + IEnumerable<(string, object)> attributeArguments + ) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments( + attribute, + attributeArguments + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TGivenRuleTypeConjunction DoNotHaveAttributeWithNamedArguments( + string attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments( + attribute, + firstAttributeArgument, + moreAttributeArguments + ) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction DoNotHaveAttributeWithArguments( Attribute attribute, IEnumerable argumentValues @@ -836,6 +1297,17 @@ public TGivenRuleTypeConjunction DoNotHaveAttributeWithNamedArguments( return Create(_ruleCreator); } + [Obsolete( + "Either DoNotHaveName() without the useRegularExpressions parameter or DoNotHaveNameMatching() should be used" + )] + public TGivenRuleTypeConjunction DoNotHaveName(string pattern, bool useRegularExpressions) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveName(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction DoNotHaveName(string name) { _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveName(name)); @@ -850,6 +1322,23 @@ public TGivenRuleTypeConjunction DoNotHaveNameMatching(string pattern) return Create(_ruleCreator); } + [Obsolete( + "Either DoNotHaveFullName() without the useRegularExpressions parameter or DoNotHaveFullNameMatching() should be used" + )] + public TGivenRuleTypeConjunction DoNotHaveFullName( + string pattern, + bool useRegularExpressions + ) + { + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveFullName( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction DoNotHaveFullName(string fullName) { _ruleCreator.AddPredicate( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/IObjectConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/IObjectConditions.cs index a449c8154..d87578212 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/IObjectConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/IObjectConditions.cs @@ -16,12 +16,42 @@ public interface IObjectConditions where TRuleType : ICanBeAnalyzed { TReturnType Exist(); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use Be(Types().That().HaveFullName()) instead" + )] + TReturnType Be(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use Be(Types().That().HaveFullName()) instead" + )] + TReturnType Be(IEnumerable patterns, bool useRegularExpressions = false); TReturnType Be(ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects); TReturnType Be(IEnumerable objects); TReturnType Be(IObjectProvider objects); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use CallAny(MethodMembers().That().HaveFullName()) instead" + )] + TReturnType CallAny(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use CallAny(MethodMembers().That().HaveFullName()) instead" + )] + TReturnType CallAny(IEnumerable patterns, bool useRegularExpressions = false); TReturnType CallAny(MethodMember method, params MethodMember[] moreMethods); TReturnType CallAny(IEnumerable methods); TReturnType CallAny(IObjectProvider methods); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DependOnAny(Types().That().HaveFullName()) instead" + )] + TReturnType DependOnAny(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DependOnAny(Types().That().HaveFullName()) instead" + )] + TReturnType DependOnAny(IEnumerable patterns, bool useRegularExpressions = false); TReturnType DependOnAny(IType firstType, params IType[] moreTypes); TReturnType DependOnAny(Type firstType, params Type[] moreTypes); TReturnType DependOnAny(IObjectProvider types); @@ -37,16 +67,52 @@ TReturnType FollowCustomCondition( string description, string failDescription ); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyDependOn(Types().That().HaveFullName()) instead" + )] + TReturnType OnlyDependOn(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyDependOn(Types().That().HaveFullName()) instead" + )] + TReturnType OnlyDependOn(IEnumerable patterns, bool useRegularExpressions = false); TReturnType OnlyDependOn(IType firstType, params IType[] moreTypes); TReturnType OnlyDependOn(Type firstType, params Type[] moreTypes); TReturnType OnlyDependOn(IObjectProvider types); TReturnType OnlyDependOn(IEnumerable types); TReturnType OnlyDependOn(IEnumerable types); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveAnyAttributes(Attributes().That().HaveFullName()) instead" + )] + TReturnType HaveAnyAttributes(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveAnyAttributes(Attributes().That().HaveFullName()) instead" + )] + TReturnType HaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType HaveAnyAttributes(Attribute firstAttribute, params Attribute[] moreAttributes); TReturnType HaveAnyAttributes(Type firstAttribute, params Type[] moreAttributes); TReturnType HaveAnyAttributes(IObjectProvider attributes); TReturnType HaveAnyAttributes(IEnumerable attributes); TReturnType HaveAnyAttributes(IEnumerable attributes); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyHaveAttributes(Attributes().That().HaveFullName()) instead" + )] + TReturnType OnlyHaveAttributes(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyHaveAttributes(Attributes().That().HaveFullName()) instead" + )] + TReturnType OnlyHaveAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType OnlyHaveAttributes(Attribute firstAttribute, params Attribute[] moreAttributes); TReturnType OnlyHaveAttributes(Type firstAttribute, params Type[] moreAttributes); TReturnType OnlyHaveAttributes(IObjectProvider attributes); @@ -57,6 +123,23 @@ TReturnType HaveAnyAttributesWithArguments( object firstArgumentValue, params object[] moreArgumentValues ); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + TReturnType HaveAttributeWithArguments( + string attribute, + IEnumerable argumentValues + ); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + TReturnType HaveAttributeWithArguments( + string attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ); TReturnType HaveAttributeWithArguments( Attribute attribute, IEnumerable argumentValues @@ -79,6 +162,23 @@ TReturnType HaveAnyAttributesWithNamedArguments( (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments ); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + TReturnType HaveAttributeWithNamedArguments( + string attribute, + IEnumerable<(string, object)> attributeArguments + ); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + TReturnType HaveAttributeWithNamedArguments( + string attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ); TReturnType HaveAttributeWithNamedArguments( Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -97,8 +197,18 @@ TReturnType HaveAttributeWithNamedArguments( (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments ); + + [Obsolete( + "Either HaveName() without the useRegularExpressions parameter or HaveNameMatching() should be used" + )] + TReturnType HaveName(string pattern, bool useRegularExpressions); TReturnType HaveName(string name); TReturnType HaveNameMatching(string pattern); + + [Obsolete( + "Either HaveFullName() without the useRegularExpressions parameter or HaveFullNameMatching() should be used" + )] + TReturnType HaveFullName(string pattern, bool useRegularExpressions); TReturnType HaveFullName(string fullName); TReturnType HaveFullNameMatching(string pattern); TReturnType HaveNameStartingWith(string pattern); @@ -116,17 +226,63 @@ TReturnType HaveAttributeWithNamedArguments( TReturnType NotExist(); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotBe(Types().That().HaveFullName()) instead" + )] + TReturnType NotBe(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotBe(Types().That().HaveFullName()) instead" + )] + TReturnType NotBe(IEnumerable patterns, bool useRegularExpressions = false); TReturnType NotBe(ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects); TReturnType NotBe(IEnumerable objects); TReturnType NotBe(IObjectProvider objects); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotCallAny(MethodMembers().That().HaveFullName()) instead" + )] + TReturnType NotCallAny(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotCallAny(MethodMembers().That().HaveFullName()) instead" + )] + TReturnType NotCallAny(IEnumerable patterns, bool useRegularExpressions = false); TReturnType NotCallAny(MethodMember method, params MethodMember[] moreMethods); TReturnType NotCallAny(IEnumerable methods); TReturnType NotCallAny(IObjectProvider methods); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotDependOnAny(Types().That().HaveFullName()) instead" + )] + TReturnType NotDependOnAny(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotDependOnAny(Types().That().HaveFullName()) instead" + )] + TReturnType NotDependOnAny( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType NotDependOnAny(IType firstType, params IType[] moreTypes); TReturnType NotDependOnAny(Type firstType, params Type[] moreTypes); TReturnType NotDependOnAny(IObjectProvider types); TReturnType NotDependOnAny(IEnumerable types); TReturnType NotDependOnAny(IEnumerable types); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotHaveAnyAttributes(Attributes().That().HaveFullName()) instead" + )] + TReturnType NotHaveAnyAttributes(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotHaveAnyAttributes(Attributes().That().HaveFullName()) instead" + )] + TReturnType NotHaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType NotHaveAnyAttributes( Attribute firstAttribute, params Attribute[] moreAttributes @@ -183,8 +339,18 @@ TReturnType NotHaveAttributeWithNamedArguments( (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments ); + + [Obsolete( + "Either NotHaveName() without the useRegularExpressions parameter or NotHaveNameMatching() should be used" + )] + TReturnType NotHaveName(string pattern, bool useRegularExpressions); TReturnType NotHaveName(string name); TReturnType NotHaveNameMatching(string pattern); + + [Obsolete( + "Either NotHaveFullName() without the useRegularExpressions parameter or NotHaveFullNameMatching() should be used" + )] + TReturnType NotHaveFullName(string pattern, bool useRegularExpressions); TReturnType NotHaveFullName(string fullName); TReturnType NotHaveFullNameMatching(string pattern); TReturnType NotHaveNameStartingWith(string pattern); diff --git a/ArchUnitNET/Fluent/Syntax/Elements/IObjectPredicates.cs b/ArchUnitNET/Fluent/Syntax/Elements/IObjectPredicates.cs index ada65d2c8..938efb432 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/IObjectPredicates.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/IObjectPredicates.cs @@ -15,12 +15,41 @@ namespace ArchUnitNET.Fluent.Syntax.Elements public interface IObjectPredicates where TRuleType : ICanBeAnalyzed { + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use Are(Types().That().HaveFullName()) instead" + )] + TReturnType Are(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use Are(Types().That().HaveFullName()) instead" + )] + TReturnType Are(IEnumerable patterns, bool useRegularExpressions = false); TReturnType Are(ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects); TReturnType Are(IEnumerable objects); TReturnType Are(IObjectProvider objects); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use CallAny(MethodMembers().That().HaveFullName()) instead" + )] + TReturnType CallAny(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use CallAny(MethodMembers().That().HaveFullName()) instead" + )] + TReturnType CallAny(IEnumerable patterns, bool useRegularExpressions = false); TReturnType CallAny(MethodMember method, params MethodMember[] moreMethods); TReturnType CallAny(IEnumerable methods); TReturnType CallAny(IObjectProvider methods); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DependOnAny(Types().That().HaveFullName()) instead" + )] + TReturnType DependOnAny(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DependOnAny(Types().That().HaveFullName()) instead" + )] + TReturnType DependOnAny(IEnumerable patterns, bool useRegularExpressions = false); TReturnType DependOnAny(Type firstType, params Type[] moreTypes); TReturnType DependOnAny(IType firstType, params IType[] moreTypes); TReturnType DependOnAny(IObjectProvider types); @@ -28,16 +57,52 @@ public interface IObjectPredicates TReturnType DependOnAny(IEnumerable types); TReturnType FollowCustomPredicate(IPredicate predicate); TReturnType FollowCustomPredicate(Func predicate, string description); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyDependOn(Types().That().HaveFullName()) instead" + )] + TReturnType OnlyDependOn(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyDependOn(Types().That().HaveFullName()) instead" + )] + TReturnType OnlyDependOn(IEnumerable patterns, bool useRegularExpressions = false); TReturnType OnlyDependOn(Type firstType, params Type[] moreTypes); TReturnType OnlyDependOn(IType firstType, params IType[] moreTypes); TReturnType OnlyDependOn(IObjectProvider types); TReturnType OnlyDependOn(IEnumerable types); TReturnType OnlyDependOn(IEnumerable types); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveAnyAttributes(Attributes().That().HaveFullName()) instead" + )] + TReturnType HaveAnyAttributes(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveAnyAttributes(Attributes().That().HaveFullName()) instead" + )] + TReturnType HaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType HaveAnyAttributes(Attribute firstAttribute, params Attribute[] moreAttributes); TReturnType HaveAnyAttributes(Type firstAttribute, params Type[] moreAttributes); TReturnType HaveAnyAttributes(IObjectProvider attributes); TReturnType HaveAnyAttributes(IEnumerable attributes); TReturnType HaveAnyAttributes(IEnumerable attributes); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyHaveAttributes(Attributes().That().HaveFullName()) instead" + )] + TReturnType OnlyHaveAttributes(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyHaveAttributes(Attributes().That().HaveFullName()) instead" + )] + TReturnType OnlyHaveAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType OnlyHaveAttributes(Attribute firstAttribute, params Attribute[] moreAttributes); TReturnType OnlyHaveAttributes(Type firstAttribute, params Type[] moreAttributes); TReturnType OnlyHaveAttributes(IObjectProvider attributes); @@ -48,6 +113,23 @@ TReturnType HaveAnyAttributesWithArguments( object firstArgumentValue, params object[] moreArgumentValues ); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + TReturnType HaveAttributeWithArguments( + string attribute, + IEnumerable argumentValues + ); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + TReturnType HaveAttributeWithArguments( + string attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ); TReturnType HaveAttributeWithArguments( Attribute attribute, IEnumerable argumentValues @@ -70,6 +152,23 @@ TReturnType HaveAnyAttributesWithNamedArguments( (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments ); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + TReturnType HaveAttributeWithNamedArguments( + string attribute, + IEnumerable<(string, object)> attributeArguments + ); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + TReturnType HaveAttributeWithNamedArguments( + string attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ); TReturnType HaveAttributeWithNamedArguments( Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -88,8 +187,18 @@ TReturnType HaveAttributeWithNamedArguments( (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments ); + + [Obsolete( + "Either HaveName() without the useRegularExpressions parameter or HaveNameMatching() should be used" + )] + TReturnType HaveName(string pattern, bool useRegularExpressions); TReturnType HaveName(string name); TReturnType HaveNameMatching(string pattern); + + [Obsolete( + "Either HaveFullName() without the useRegularExpressions parameter or HaveFullNameMatching() should be used" + )] + TReturnType HaveFullName(string pattern, bool useRegularExpressions); TReturnType HaveFullName(string fullName); TReturnType HaveFullNameMatching(string pattern); TReturnType HaveNameStartingWith(string pattern); @@ -105,17 +214,62 @@ TReturnType HaveAttributeWithNamedArguments( //Negations + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNot(Types().That().HaveFullName()) instead" + )] + TReturnType AreNot(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNot(Types().That().HaveFullName()) instead" + )] + TReturnType AreNot(IEnumerable patterns, bool useRegularExpressions = false); TReturnType AreNot(ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects); TReturnType AreNot(IEnumerable objects); TReturnType AreNot(IObjectProvider objects); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotCallAny(MethodMembers().That().HaveFullName()) instead" + )] + TReturnType DoNotCallAny(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotCallAny(MethodMembers().That().HaveFullName()) instead" + )] + TReturnType DoNotCallAny(IEnumerable patterns, bool useRegularExpressions = false); TReturnType DoNotCallAny(MethodMember method, params MethodMember[] moreMethods); TReturnType DoNotCallAny(IEnumerable methods); TReturnType DoNotCallAny(IObjectProvider methods); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotDependOnAny(Types().That().HaveFullName()) instead" + )] + TReturnType DoNotDependOnAny(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotDependOnAny(Types().That().HaveFullName()) instead" + )] + TReturnType DoNotDependOnAny( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType DoNotDependOnAny(Type firstType, params Type[] moreTypes); TReturnType DoNotDependOnAny(IType firstType, params IType[] moreTypes); TReturnType DoNotDependOnAny(IObjectProvider types); TReturnType DoNotDependOnAny(IEnumerable types); TReturnType DoNotDependOnAny(IEnumerable types); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotHaveAnyAttributes(Attributes().That().HaveFullName()) instead" + )] + TReturnType DoNotHaveAnyAttributes(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotHaveAnyAttributes(Attributes().That().HaveFullName()) instead" + )] + TReturnType DoNotHaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType DoNotHaveAnyAttributes( Attribute firstAttribute, params Attribute[] moreAttributes @@ -129,6 +283,23 @@ TReturnType DoNotHaveAnyAttributesWithArguments( object firstArgumentValue, params object[] moreArgumentValues ); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + TReturnType DoNotHaveAttributeWithArguments( + string attribute, + IEnumerable argumentValues + ); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + TReturnType DoNotHaveAttributeWithArguments( + string attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ); TReturnType DoNotHaveAttributeWithArguments( Attribute attribute, IEnumerable argumentValues @@ -154,6 +325,23 @@ TReturnType DoNotHaveAnyAttributesWithNamedArguments( (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments ); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + TReturnType DoNotHaveAttributeWithNamedArguments( + string attribute, + IEnumerable<(string, object)> attributeArguments + ); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + TReturnType DoNotHaveAttributeWithNamedArguments( + string attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ); TReturnType DoNotHaveAttributeWithNamedArguments( Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -172,8 +360,18 @@ TReturnType DoNotHaveAttributeWithNamedArguments( (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments ); + + [Obsolete( + "Either DoNotHaveName() without the useRegularExpressions parameter or DoNotHaveNameMatching() should be used" + )] + TReturnType DoNotHaveName(string pattern, bool useRegularExpressions); TReturnType DoNotHaveName(string name); TReturnType DoNotHaveNameMatching(string pattern); + + [Obsolete( + "Either DoNotHaveFullName() without the useRegularExpressions parameter or DoNotHaveFullNameMatching() should be used" + )] + TReturnType DoNotHaveFullName(string pattern, bool useRegularExpressions); TReturnType DoNotHaveFullName(string fullName); TReturnType DoNotHaveFullNameMatching(string pattern); TReturnType DoNotHaveNameStartingWith(string pattern); diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembersThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembersThat.cs index cb7d149b7..1252fb90b 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembersThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembersThat.cs @@ -21,6 +21,34 @@ public class GivenMembersThat public GivenMembersThat(IArchRuleCreator ruleCreator) : base(ruleCreator) { } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreDeclaredIn(Types().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction AreDeclaredIn( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + MemberPredicatesDefinition.AreDeclaredIn(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreDeclaredIn(Types().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction AreDeclaredIn( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + MemberPredicatesDefinition.AreDeclaredIn(patterns, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction AreDeclaredIn(IType firstType, params IType[] moreTypes) { _ruleCreator.AddPredicate( @@ -75,6 +103,40 @@ public TGivenRuleTypeConjunction AreImmutable() //Negations + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNotDeclaredIn(Types().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction AreNotDeclaredIn( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + MemberPredicatesDefinition.AreNotDeclaredIn( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNotDeclaredIn(Types().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction AreNotDeclaredIn( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + MemberPredicatesDefinition.AreNotDeclaredIn( + patterns, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction AreNotDeclaredIn(IType firstType, params IType[] moreTypes) { _ruleCreator.AddPredicate( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/IMemberConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/IMemberConditions.cs index 71b03e596..771823eb6 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/IMemberConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/IMemberConditions.cs @@ -14,6 +14,15 @@ public interface IMemberConditions : IObjectConditions where TRuleType : ICanBeAnalyzed { + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use BeDeclaredIn(Types().That().HaveFullName()) instead" + )] + TReturnType BeDeclaredIn(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use BeDeclaredIn(Types().That().HaveFullName()) instead" + )] + TReturnType BeDeclaredIn(IEnumerable patterns, bool useRegularExpressions = false); TReturnType BeDeclaredIn(IType firstType, params IType[] moreTypes); TReturnType BeDeclaredIn(Type firstType, params Type[] moreTypes); TReturnType BeDeclaredIn(IObjectProvider types); @@ -23,6 +32,18 @@ public interface IMemberConditions TReturnType BeImmutable(); //Negations + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotBeDeclaredIn(Types().That().HaveFullName()) instead" + )] + TReturnType NotBeDeclaredIn(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotBeDeclaredIn(Types().That().HaveFullName()) instead" + )] + TReturnType NotBeDeclaredIn( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType NotBeDeclaredIn(IType firstType, params IType[] moreTypes); TReturnType NotBeDeclaredIn(Type firstType, params Type[] moreTypes); TReturnType NotBeDeclaredIn(IObjectProvider types); diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/IMemberPredicates.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/IMemberPredicates.cs index f425d0926..c1269e14a 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/IMemberPredicates.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/IMemberPredicates.cs @@ -14,6 +14,18 @@ public interface IMemberPredicates : IObjectPredicates where TRuleType : ICanBeAnalyzed { + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreDeclaredIn(Types().That().HaveFullName()) instead" + )] + TRuleTypeConjunction AreDeclaredIn(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreDeclaredIn(Types().That().HaveFullName()) instead" + )] + TRuleTypeConjunction AreDeclaredIn( + IEnumerable patterns, + bool useRegularExpressions = false + ); TRuleTypeConjunction AreDeclaredIn(IType firstType, params IType[] moreTypes); TRuleTypeConjunction AreDeclaredIn(Type firstType, params Type[] moreTypes); TRuleTypeConjunction AreDeclaredIn(IObjectProvider types); @@ -23,6 +35,20 @@ public interface IMemberPredicates TRuleTypeConjunction AreImmutable(); //Negations + + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNotDeclaredIn(Types().That().HaveFullName()) instead" + )] + TRuleTypeConjunction AreNotDeclaredIn(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNotDeclaredIn(Types().That().HaveFullName()) instead" + )] + TRuleTypeConjunction AreNotDeclaredIn( + IEnumerable patterns, + bool useRegularExpressions = false + ); TRuleTypeConjunction AreNotDeclaredIn(IType firstType, params IType[] moreTypes); TRuleTypeConjunction AreNotDeclaredIn(Type firstType, params Type[] moreTypes); TRuleTypeConjunction AreNotDeclaredIn(IObjectProvider types); diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberConditionsDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberConditionsDefinition.cs index 8907fcdc5..6e567ecc1 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberConditionsDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberConditionsDefinition.cs @@ -17,6 +17,70 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Members public static class MemberConditionsDefinition where TRuleType : IMember { + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use BeDeclaredIn(Types().That().HaveFullName()) instead" + )] + public static ICondition BeDeclaredIn( + string pattern, + bool useRegularExpressions = false + ) + { + return new SimpleCondition( + member => member.IsDeclaredIn(pattern, useRegularExpressions), + member => "is declared in " + member.DeclaringType.FullName, + "be declared in types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use BeDeclaredIn(Types().That().HaveFullName()) instead" + )] + public static ICondition BeDeclaredIn( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Condition(TRuleType ruleType) + { + return patternList.Any(pattern => + ruleType.IsDeclaredIn(pattern, useRegularExpressions) + ); + } + + string description; + if (patternList.IsNullOrEmpty()) + { + description = "be declared in no type (always false)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(obj => !obj.Equals(firstPattern)) + .Distinct() + .Aggregate( + "be declared in types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimpleCondition( + Condition, + member => "is declared in " + member.DeclaringType.FullName, + description + ); + } + public static ICondition BeDeclaredIn(IType firstType, params IType[] moreTypes) { var types = new List { firstType }; @@ -200,6 +264,71 @@ public static RelationCondition BeDeclaredInTypesThat() } //Negations + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotBeDeclaredIn(Types().That().HaveFullName()) instead" + )] + public static ICondition NotBeDeclaredIn( + string pattern, + bool useRegularExpressions = false + ) + { + return new SimpleCondition( + member => !member.IsDeclaredIn(pattern, useRegularExpressions), + member => "is declared in " + member.DeclaringType.FullName, + "not be declared in types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotBeDeclaredIn(Types().That().HaveFullName()) instead" + )] + public static ICondition NotBeDeclaredIn( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Condition(TRuleType ruleType) + { + return patternList.All(pattern => + !ruleType.IsDeclaredIn(pattern, useRegularExpressions) + ); + } + + string description; + if (patternList.IsNullOrEmpty()) + { + description = "not be declared in no type (always true)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(obj => !obj.Equals(firstPattern)) + .Distinct() + .Aggregate( + "not be declared in types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimpleCondition( + Condition, + member => "is declared in " + member.DeclaringType.FullName, + description + ); + } + public static ICondition NotBeDeclaredIn( IType firstType, params IType[] moreTypes diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberPredicatesDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberPredicatesDefinition.cs index 73675f420..75f2fe1d5 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberPredicatesDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberPredicatesDefinition.cs @@ -17,6 +17,65 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Members public static class MemberPredicatesDefinition where T : IMember { + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreDeclaredIn(Types().That().HaveFullName()) instead" + )] + public static IPredicate AreDeclaredIn( + string pattern, + bool useRegularExpressions = false + ) + { + return new SimplePredicate( + member => member.IsDeclaredIn(pattern, useRegularExpressions), + "are declared in types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreDeclaredIn(Types().That().HaveFullName()) instead" + )] + public static IPredicate AreDeclaredIn( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Condition(T ruleType) + { + return patternList.Any(pattern => + ruleType.IsDeclaredIn(pattern, useRegularExpressions) + ); + } + + string description; + if (patternList.IsNullOrEmpty()) + { + description = "are declared in no type (always false)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(obj => !obj.Equals(firstPattern)) + .Distinct() + .Aggregate( + "are declared in types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimplePredicate(Condition, description); + } + public static IPredicate AreDeclaredIn(IType firstType, params IType[] moreTypes) { var types = new List { firstType }; @@ -142,6 +201,65 @@ public static IPredicate AreImmutable() //Negations + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNotDeclaredIn(Types().That().HaveFullName()) instead" + )] + public static IPredicate AreNotDeclaredIn( + string pattern, + bool useRegularExpressions = false + ) + { + return new SimplePredicate( + member => !member.IsDeclaredIn(pattern, useRegularExpressions), + "are not declared in types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNotDeclaredIn(Types().That().HaveFullName()) instead" + )] + public static IPredicate AreNotDeclaredIn( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Condition(T ruleType) + { + return patternList.All(pattern => + !ruleType.IsDeclaredIn(pattern, useRegularExpressions) + ); + } + + string description; + if (patternList.IsNullOrEmpty()) + { + description = "are not declared in no type (always true)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(obj => !obj.Equals(firstPattern)) + .Distinct() + .Aggregate( + "are not declared in types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimplePredicate(Condition, description); + } + public static IPredicate AreNotDeclaredIn(IType firstType, params IType[] moreTypes) { var types = new List { firstType }; diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MembersShould.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MembersShould.cs index 2205e0713..5e912e2e0 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MembersShould.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MembersShould.cs @@ -22,6 +22,34 @@ public class MembersShould public MembersShould(IArchRuleCreator ruleCreator) : base(ruleCreator) { } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use BeDeclaredIn(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction BeDeclaredIn( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + MemberConditionsDefinition.BeDeclaredIn(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use BeDeclaredIn(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction BeDeclaredIn( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + MemberConditionsDefinition.BeDeclaredIn(patterns, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction BeDeclaredIn(IType firstType, params IType[] moreTypes) { _ruleCreator.AddCondition( @@ -93,6 +121,40 @@ public ShouldRelateToTypesThat< //Negations + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotBeDeclaredIn(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction NotBeDeclaredIn( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + MemberConditionsDefinition.NotBeDeclaredIn( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotBeDeclaredIn(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction NotBeDeclaredIn( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + MemberConditionsDefinition.NotBeDeclaredIn( + patterns, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction NotBeDeclaredIn(IType firstType, params IType[] moreTypes) { _ruleCreator.AddCondition( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/GivenMethodMembersThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/GivenMethodMembersThat.cs index ad3d7e23b..31c1471cf 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/GivenMethodMembersThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/GivenMethodMembersThat.cs @@ -29,6 +29,34 @@ public GivenMethodMembersConjunction AreVirtual() return new GivenMethodMembersConjunction(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreCalledBy(Types().That().HaveFullName()) instead" + )] + public GivenMethodMembersConjunction AreCalledBy( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + MethodMemberPredicatesDefinition.AreCalledBy(pattern, useRegularExpressions) + ); + return new GivenMethodMembersConjunction(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreCalledBy(Types().That().HaveFullName()) instead" + )] + public GivenMethodMembersConjunction AreCalledBy( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + MethodMemberPredicatesDefinition.AreCalledBy(patterns, useRegularExpressions) + ); + return new GivenMethodMembersConjunction(_ruleCreator); + } + public GivenMethodMembersConjunction AreCalledBy(IType firstType, params IType[] moreTypes) { _ruleCreator.AddPredicate( @@ -63,6 +91,40 @@ public GivenMethodMembersConjunction AreCalledBy(IEnumerable types) return new GivenMethodMembersConjunction(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo( + pattern, + useRegularExpressions + ) + ); + return new GivenMethodMembersConjunction(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo( + patterns, + useRegularExpressions + ) + ); + return new GivenMethodMembersConjunction(_ruleCreator); + } + public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo( IType firstType, params IType[] moreTypes @@ -111,6 +173,34 @@ public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo(IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + MethodMemberPredicatesDefinition.HaveReturnType(patterns, useRegularExpressions) + ); + return new GivenMethodMembersConjunction(_ruleCreator); + } + public GivenMethodMembersConjunction HaveReturnType( IType firstType, params IType[] moreTypes @@ -163,6 +253,34 @@ public GivenMethodMembersConjunction AreNotVirtual() return new GivenMethodMembersConjunction(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNotCalledBy(Types().That().HaveFullName()) instead" + )] + public GivenMethodMembersConjunction AreNotCalledBy( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + MethodMemberPredicatesDefinition.AreNotCalledBy(pattern, useRegularExpressions) + ); + return new GivenMethodMembersConjunction(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNotCalledBy(Types().That().HaveFullName()) instead" + )] + public GivenMethodMembersConjunction AreNotCalledBy( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + MethodMemberPredicatesDefinition.AreNotCalledBy(patterns, useRegularExpressions) + ); + return new GivenMethodMembersConjunction(_ruleCreator); + } + public GivenMethodMembersConjunction AreNotCalledBy( IType firstType, params IType[] moreTypes @@ -200,6 +318,40 @@ public GivenMethodMembersConjunction AreNotCalledBy(IEnumerable types) return new GivenMethodMembersConjunction(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotHaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + public GivenMethodMembersConjunction DoNotHaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo( + pattern, + useRegularExpressions + ) + ); + return new GivenMethodMembersConjunction(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotHaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + public GivenMethodMembersConjunction DoNotHaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo( + patterns, + useRegularExpressions + ) + ); + return new GivenMethodMembersConjunction(_ruleCreator); + } + public GivenMethodMembersConjunction DoNotHaveDependencyInMethodBodyTo( IType firstType, params IType[] moreTypes @@ -255,6 +407,37 @@ IEnumerable types return new GivenMethodMembersConjunction(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotHaveReturnType(Types().That().HaveFullName()) instead" + )] + public GivenMethodMembersConjunction DoNotHaveReturnType( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + MethodMemberPredicatesDefinition.DoNotHaveReturnType(pattern, useRegularExpressions) + ); + return new GivenMethodMembersConjunction(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotHaveReturnType(Types().That().HaveFullName()) instead" + )] + public GivenMethodMembersConjunction DoNotHaveReturnType( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + MethodMemberPredicatesDefinition.DoNotHaveReturnType( + patterns, + useRegularExpressions + ) + ); + return new GivenMethodMembersConjunction(_ruleCreator); + } + public GivenMethodMembersConjunction DoNotHaveReturnType( IType firstType, params IType[] moreTypes diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IMethodMemberConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IMethodMemberConditions.cs index 9886ff23f..982ca6ccb 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IMethodMemberConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IMethodMemberConditions.cs @@ -16,16 +16,55 @@ public interface IMethodMemberConditions { TReturnType BeConstructor(); TReturnType BeVirtual(); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use BeCalledBy(Types().That().HaveFullName()) instead" + )] + TReturnType BeCalledBy(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use BeCalledBy(Types().That().HaveFullName()) instead" + )] + TReturnType BeCalledBy(IEnumerable patterns, bool useRegularExpressions = false); TReturnType BeCalledBy(IType firstType, params IType[] moreTypes); TReturnType BeCalledBy(Type type, params Type[] moreTypes); TReturnType BeCalledBy(IObjectProvider types); TReturnType BeCalledBy(IEnumerable types); TReturnType BeCalledBy(IEnumerable types); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + TReturnType HaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + TReturnType HaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType HaveDependencyInMethodBodyTo(IType firstType, params IType[] moreTypes); TReturnType HaveDependencyInMethodBodyTo(Type type, params Type[] moreTypes); TReturnType HaveDependencyInMethodBodyTo(IObjectProvider types); TReturnType HaveDependencyInMethodBodyTo(IEnumerable types); TReturnType HaveDependencyInMethodBodyTo(IEnumerable types); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveReturnType(Types().That().HaveFullName()) instead" + )] + TReturnType HaveReturnType(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveReturnType(Types().That().HaveFullName()) instead" + )] + TReturnType HaveReturnType( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType HaveReturnType(IType firstType, params IType[] moreTypes); TReturnType HaveReturnType(IEnumerable types); TReturnType HaveReturnType(IObjectProvider types); @@ -37,16 +76,55 @@ public interface IMethodMemberConditions TReturnType BeNoConstructor(); TReturnType NotBeVirtual(); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotBeCalledBy(Types().That().HaveFullName()) instead" + )] + TReturnType NotBeCalledBy(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotBeCalledBy(Types().That().HaveFullName()) instead" + )] + TReturnType NotBeCalledBy(IEnumerable patterns, bool useRegularExpressions = false); TReturnType NotBeCalledBy(IType firstType, params IType[] moreTypes); TReturnType NotBeCalledBy(Type type, params Type[] moreTypes); TReturnType NotBeCalledBy(IObjectProvider types); TReturnType NotBeCalledBy(IEnumerable types); TReturnType NotBeCalledBy(IEnumerable types); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotHaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + TReturnType NotHaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotHaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + TReturnType NotHaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType NotHaveDependencyInMethodBodyTo(IType firstType, params IType[] moreTypes); TReturnType NotHaveDependencyInMethodBodyTo(Type type, params Type[] moreTypes); TReturnType NotHaveDependencyInMethodBodyTo(IObjectProvider types); TReturnType NotHaveDependencyInMethodBodyTo(IEnumerable types); TReturnType NotHaveDependencyInMethodBodyTo(IEnumerable types); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotHaveReturnType(Types().That().HaveFullName()) instead" + )] + TReturnType NotHaveReturnType(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotHaveReturnType(Types().That().HaveFullName()) instead" + )] + TReturnType NotHaveReturnType( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType NotHaveReturnType(IType firstType, params IType[] moreTypes); TReturnType NotHaveReturnType(IEnumerable types); TReturnType NotHaveReturnType(IObjectProvider types); diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IMethodMemberPredicates.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IMethodMemberPredicates.cs index 29abc991f..417d330bb 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IMethodMemberPredicates.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IMethodMemberPredicates.cs @@ -16,11 +16,41 @@ public interface IMethodMemberPredicates { TRuleTypeConjunction AreConstructors(); TRuleTypeConjunction AreVirtual(); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreCalledBy(Types().That().HaveFullName()) instead" + )] + TRuleTypeConjunction AreCalledBy(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreCalledBy(Types().That().HaveFullName()) instead" + )] + TRuleTypeConjunction AreCalledBy( + IEnumerable patterns, + bool useRegularExpressions = false + ); TRuleTypeConjunction AreCalledBy(IType firstType, params IType[] moreTypes); TRuleTypeConjunction AreCalledBy(Type type, params Type[] moreTypes); TRuleTypeConjunction AreCalledBy(IObjectProvider types); TRuleTypeConjunction AreCalledBy(IEnumerable types); TRuleTypeConjunction AreCalledBy(IEnumerable types); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + TRuleTypeConjunction HaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + TRuleTypeConjunction HaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ); + TRuleTypeConjunction HaveDependencyInMethodBodyTo( IType firstType, params IType[] moreTypes @@ -29,6 +59,19 @@ params IType[] moreTypes TRuleTypeConjunction HaveDependencyInMethodBodyTo(IObjectProvider types); TRuleTypeConjunction HaveDependencyInMethodBodyTo(IEnumerable types); TRuleTypeConjunction HaveDependencyInMethodBodyTo(IEnumerable types); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveReturnType(Types().That().HaveFullName()) instead" + )] + TRuleTypeConjunction HaveReturnType(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveReturnType(Types().That().HaveFullName()) instead" + )] + TRuleTypeConjunction HaveReturnType( + IEnumerable patterns, + bool useRegularExpressions = false + ); TRuleTypeConjunction HaveReturnType(IType firstType, params IType[] moreTypes); TRuleTypeConjunction HaveReturnType(IEnumerable types); TRuleTypeConjunction HaveReturnType(IObjectProvider types); @@ -40,11 +83,41 @@ params IType[] moreTypes TRuleTypeConjunction AreNoConstructors(); TRuleTypeConjunction AreNotVirtual(); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNotCalledBy(Types().That().HaveFullName()) instead" + )] + TRuleTypeConjunction AreNotCalledBy(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNotCalledBy(Types().That().HaveFullName()) instead" + )] + TRuleTypeConjunction AreNotCalledBy( + IEnumerable patterns, + bool useRegularExpressions = false + ); TRuleTypeConjunction AreNotCalledBy(IType firstType, params IType[] moreTypes); TRuleTypeConjunction AreNotCalledBy(Type type, params Type[] moreTypes); TRuleTypeConjunction AreNotCalledBy(IObjectProvider types); TRuleTypeConjunction AreNotCalledBy(IEnumerable types); TRuleTypeConjunction AreNotCalledBy(IEnumerable types); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotHaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotHaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ); + TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo( IType firstType, params IType[] moreTypes @@ -53,6 +126,22 @@ params IType[] moreTypes TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo(IObjectProvider types); TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo(IEnumerable types); TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo(IEnumerable types); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotHaveReturnType(Types().That().HaveFullName()) instead" + )] + TRuleTypeConjunction DoNotHaveReturnType( + string pattern, + bool useRegularExpressions = false + ); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotHaveReturnType(Types().That().HaveFullName()) instead" + )] + TRuleTypeConjunction DoNotHaveReturnType( + IEnumerable patterns, + bool useRegularExpressions = false + ); TRuleTypeConjunction DoNotHaveReturnType(IType firstType, params IType[] moreTypes); TRuleTypeConjunction DoNotHaveReturnType(IEnumerable types); TRuleTypeConjunction DoNotHaveReturnType(IObjectProvider types); diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberConditionsDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberConditionsDefinition.cs index f6ae01e1c..6d3c1ebad 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberConditionsDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberConditionsDefinition.cs @@ -34,6 +34,83 @@ public static ICondition BeVirtual() ); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use BeCalledBy(Types().That().HaveFullName()) instead" + )] + public static ICondition BeCalledBy( + string pattern, + bool useRegularExpressions = false + ) + { + return new SimpleCondition( + member => member.IsCalledBy(pattern, useRegularExpressions), + "be called by types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"", + "is called by a type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use BeCalledBy(Types().That().HaveFullName()) instead" + )] + public static ICondition BeCalledBy( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Condition(MethodMember ruleType) + { + return patternList.Any(pattern => + ruleType.IsCalledBy(pattern, useRegularExpressions) + ); + } + + string description; + string failDescription; + if (patternList.IsNullOrEmpty()) + { + description = "be called by one of no types (always false)"; + failDescription = "is not called by one of no types (always true)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "be called by types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + failDescription = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "is not called by types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimpleCondition(Condition, description, failDescription); + } + public static ICondition BeCalledBy(IType firstType, params IType[] moreTypes) { var types = new List { firstType }; @@ -208,6 +285,84 @@ Architecture architecture return new ArchitectureCondition(Condition, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + public static ICondition HaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ) + { + return new SimpleCondition( + member => member.HasDependencyInMethodBodyTo(pattern, useRegularExpressions), + "have dependencies in method body to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"", + "does not have dependencies in method body to a type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + public static ICondition HaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Condition(MethodMember ruleType) + { + return patternList.Any(pattern => + ruleType.HasDependencyInMethodBodyTo(pattern, useRegularExpressions) + ); + } + + string description; + string failDescription; + if (patternList.IsNullOrEmpty()) + { + description = "have dependency in method body to one of no types (always false)"; + failDescription = + "does not have dependencies in method body to one of no types (always true)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "have dependencies in method body to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + failDescription = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "does not have dependencies in method body to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimpleCondition(Condition, description, failDescription); + } + public static ICondition HaveDependencyInMethodBodyTo( IType firstType, params IType[] moreTypes @@ -415,6 +570,68 @@ Architecture architecture return new ArchitectureCondition(Condition, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveReturnType(Types().That().HaveFullName()) instead" + )] + public static ICondition HaveReturnType( + string pattern, + bool useRegularExpressions = false + ) + { + var description = + "have return type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\""; + + var failDescription = + "does not have return type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\""; + + return new SimpleCondition( + member => member.ReturnType.FullNameMatches(pattern, useRegularExpressions), + description, + failDescription + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveReturnType(Types().That().HaveFullName()) instead" + )] + public static ICondition HaveReturnType( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternsArray = patterns.ToArray(); + var description = + "have return type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + string.Join("\" or \"", patternsArray) + + "\""; + + var failDescription = + "does not have return type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + string.Join("\" or \"", patternsArray) + + "\""; + + bool Condition(MethodMember member) + { + return patternsArray.Any(pattern => + member.ReturnType.FullNameMatches(pattern, useRegularExpressions) + ); + } + + return new SimpleCondition(Condition, description, failDescription); + } + public static ICondition HaveReturnType( IType firstType, params IType[] moreTypes @@ -527,6 +744,99 @@ public static ICondition NotBeVirtual() ); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotBeCalledBy(Types().That().HaveFullName()) instead" + )] + public static ICondition NotBeCalledBy( + string pattern, + bool useRegularExpressions = false + ) + { + ConditionResult Condition(MethodMember member) + { + var pass = true; + var description = "is called by"; + foreach ( + var type in member + .GetMethodCallDependencies(true) + .Select(dependency => dependency.Origin) + .Distinct() + ) + { + if (type.FullNameMatches(pattern, useRegularExpressions)) + { + description += (pass ? " " : " and ") + type.FullName; + pass = false; + } + } + + return new ConditionResult(member, pass, description); + } + + return new SimpleCondition( + Condition, + "not be called by types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotBeCalledBy(Types().That().HaveFullName()) instead" + )] + public static ICondition NotBeCalledBy( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Condition(MethodMember ruleType) + { + return !patternList.Any(pattern => + ruleType.IsCalledBy(pattern, useRegularExpressions) + ); + } + + string description; + string failDescription; + if (patternList.IsNullOrEmpty()) + { + description = "not be called by one of no types (always true)"; + failDescription = "is called by one of no types (always false)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "not be called by types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + failDescription = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "is called by types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimpleCondition(Condition, description, failDescription); + } + public static ICondition NotBeCalledBy( IType firstType, params IType[] moreTypes @@ -707,6 +1017,101 @@ Architecture architecture return new ArchitectureCondition(Condition, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotHaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + public static ICondition NotHaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ) + { + ConditionResult Condition(MethodMember member) + { + var pass = true; + var description = "does have dependencies in method body to"; + foreach ( + var type in member + .GetBodyTypeMemberDependencies() + .Select(dependency => dependency.Target) + .Distinct() + ) + { + if (type.FullNameMatches(pattern, useRegularExpressions)) + { + description += (pass ? " " : " and ") + type.FullName; + pass = false; + } + } + + return new ConditionResult(member, pass, description); + } + + return new SimpleCondition( + Condition, + "not have dependencies in method body to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotHaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + public static ICondition NotHaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Condition(MethodMember ruleType) + { + return !patternList.Any(pattern => + ruleType.HasDependencyInMethodBodyTo(pattern, useRegularExpressions) + ); + } + + string description; + string failDescription; + if (patternList.IsNullOrEmpty()) + { + description = + "not have dependencies in method body to one of no types (always true)"; + failDescription = + "does have dependencies in method body to one of no types (always false)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "not have dependencies in method body to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + failDescription = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "does have dependencies in method body to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimpleCondition(Condition, description, failDescription); + } + public static ICondition NotHaveDependencyInMethodBodyTo( IType firstType, params IType[] moreTypes @@ -919,6 +1324,68 @@ Architecture architecture return new ArchitectureCondition(Condition, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotHaveReturnType(Types().That().HaveFullName()) instead" + )] + public static ICondition NotHaveReturnType( + string pattern, + bool useRegularExpressions = false + ) + { + var description = + "not have return type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\""; + + var failDescription = + "does have return type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\""; + + return new SimpleCondition( + member => !member.ReturnType.FullNameMatches(pattern, useRegularExpressions), + description, + failDescription + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotHaveReturnType(Types().That().HaveFullName()) instead" + )] + public static ICondition NotHaveReturnType( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternsArray = patterns.ToArray(); + var description = + "not have return type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + string.Join("\" or \"", patternsArray) + + "\""; + + var failDescription = + "does have return type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + string.Join("\" or \"", patternsArray) + + "\""; + + bool Condition(MethodMember member) + { + return patternsArray.All(pattern => + !member.ReturnType.FullNameMatches(pattern, useRegularExpressions) + ); + } + + return new SimpleCondition(Condition, description, failDescription); + } + public static ICondition NotHaveReturnType( IType firstType, params IType[] moreTypes diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberPredicatesDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberPredicatesDefinition.cs index ad168564a..9451554b9 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberPredicatesDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberPredicatesDefinition.cs @@ -29,6 +29,65 @@ public static IPredicate AreVirtual() return new SimplePredicate(member => member.IsVirtual, "are virtual"); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreCalledBy(Types().That().HaveFullName()) instead" + )] + public static IPredicate AreCalledBy( + string pattern, + bool useRegularExpressions = false + ) + { + return new SimplePredicate( + member => member.IsCalledBy(pattern, useRegularExpressions), + "are called by types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreCalledBy(Types().That().HaveFullName()) instead" + )] + public static IPredicate AreCalledBy( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Condition(MethodMember ruleType) + { + return patternList.Any(pattern => + ruleType.IsCalledBy(pattern, useRegularExpressions) + ); + } + + string description; + if (patternList.IsNullOrEmpty()) + { + description = "are called by one of no types (always false)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "are called by types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimplePredicate(Condition, description); + } + public static IPredicate AreCalledBy( IType firstType, params IType[] moreTypes @@ -137,6 +196,65 @@ Architecture architecture return new ArchitecturePredicate(Condition, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + public static IPredicate HaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ) + { + return new SimplePredicate( + member => member.HasDependencyInMethodBodyTo(pattern, useRegularExpressions), + "have dependencies in method body to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + public static IPredicate HaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Condition(MethodMember ruleType) + { + return patternList.Any(pattern => + ruleType.HasDependencyInMethodBodyTo(pattern, useRegularExpressions) + ); + } + + string description; + if (patternList.IsNullOrEmpty()) + { + description = "have dependencies in method body to one of no types (always false)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "have dependencies in method body to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimplePredicate(Condition, description); + } + public static IPredicate HaveDependencyInMethodBodyTo( IType firstType, params IType[] moreTypes @@ -265,6 +383,49 @@ Architecture architecture return new ArchitecturePredicate(Condition, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveReturnType(Types().That().HaveFullName()) instead" + )] + public static IPredicate HaveReturnType( + string pattern, + bool useRegularExpressions = false + ) + { + return new SimplePredicate( + member => member.ReturnType.FullNameMatches(pattern, useRegularExpressions), + "have return type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveReturnType(Types().That().HaveFullName()) instead" + )] + public static IPredicate HaveReturnType( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternsArray = patterns.ToArray(); + var description = + "have return type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + string.Join("\" or \"", patternsArray) + + "\""; + + return new SimplePredicate( + member => + patternsArray.Any(pattern => + member.ReturnType.FullNameMatches(pattern, useRegularExpressions) + ), + description + ); + } + public static IPredicate HaveReturnType( IType firstType, params IType[] moreTypes @@ -348,6 +509,65 @@ public static IPredicate AreNotVirtual() ); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNotCalledBy(Types().That().HaveFullName()) instead" + )] + public static IPredicate AreNotCalledBy( + string pattern, + bool useRegularExpressions = false + ) + { + return new SimplePredicate( + member => !member.IsCalledBy(pattern, useRegularExpressions), + "are not called by types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNotCalledBy(Types().That().HaveFullName()) instead" + )] + public static IPredicate AreNotCalledBy( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Condition(MethodMember ruleType) + { + return !patternList.Any(pattern => + ruleType.IsCalledBy(pattern, useRegularExpressions) + ); + } + + string description; + if (patternList.IsNullOrEmpty()) + { + description = "are not called by one of no types (always true)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "are not called by types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimplePredicate(Condition, description); + } + public static IPredicate AreNotCalledBy( IType firstType, params IType[] moreTypes @@ -459,6 +679,66 @@ Architecture architecture return new ArchitecturePredicate(Condition, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotHaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + public static IPredicate DoNotHaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ) + { + return new SimplePredicate( + member => !member.HasDependencyInMethodBodyTo(pattern, useRegularExpressions), + "do not have dependencies in method body to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotHaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + public static IPredicate DoNotHaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Condition(MethodMember ruleType) + { + return !patternList.Any(pattern => + ruleType.HasDependencyInMethodBodyTo(pattern, useRegularExpressions) + ); + } + + string description; + if (patternList.IsNullOrEmpty()) + { + description = + "do not have dependencies in method body to one of no types (always true)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "do not have dependencies in method body to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimplePredicate(Condition, description); + } + public static IPredicate DoNotHaveDependencyInMethodBodyTo( IType firstType, params IType[] moreTypes @@ -592,6 +872,49 @@ Architecture architecture return new ArchitecturePredicate(Condition, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotHaveReturnType(Types().That().HaveFullName()) instead" + )] + public static IPredicate DoNotHaveReturnType( + string pattern, + bool useRegularExpressions = false + ) + { + return new SimplePredicate( + member => !member.ReturnType.FullNameMatches(pattern, useRegularExpressions), + "do not have return type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotHaveReturnType(Types().That().HaveFullName()) instead" + )] + public static IPredicate DoNotHaveReturnType( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternsArray = patterns.ToArray(); + var description = + "do not have return type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + string.Join("\" or \"", patternsArray) + + "\""; + + return new SimplePredicate( + member => + patternsArray.All(pattern => + !member.ReturnType.FullNameMatches(pattern, useRegularExpressions) + ), + description + ); + } + public static IPredicate DoNotHaveReturnType( IType firstType, params IType[] moreTypes diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMembersShould.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMembersShould.cs index 785d2994c..c84d0dd91 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMembersShould.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMembersShould.cs @@ -29,6 +29,34 @@ public MethodMembersShouldConjunction BeVirtual() return new MethodMembersShouldConjunction(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use BeCalledBy(Types().That().HaveFullName()) instead" + )] + public MethodMembersShouldConjunction BeCalledBy( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + MethodMemberConditionsDefinition.BeCalledBy(pattern, useRegularExpressions) + ); + return new MethodMembersShouldConjunction(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use BeCalledBy(Types().That().HaveFullName()) instead" + )] + public MethodMembersShouldConjunction BeCalledBy( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + MethodMemberConditionsDefinition.BeCalledBy(patterns, useRegularExpressions) + ); + return new MethodMembersShouldConjunction(_ruleCreator); + } + public MethodMembersShouldConjunction BeCalledBy(IType firstType, params IType[] moreTypes) { _ruleCreator.AddCondition( @@ -61,6 +89,40 @@ public MethodMembersShouldConjunction BeCalledBy(IEnumerable types) return new MethodMembersShouldConjunction(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + public MethodMembersShouldConjunction HaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + MethodMemberConditionsDefinition.HaveDependencyInMethodBodyTo( + pattern, + useRegularExpressions + ) + ); + return new MethodMembersShouldConjunction(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + public MethodMembersShouldConjunction HaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + MethodMemberConditionsDefinition.HaveDependencyInMethodBodyTo( + patterns, + useRegularExpressions + ) + ); + return new MethodMembersShouldConjunction(_ruleCreator); + } + public MethodMembersShouldConjunction HaveDependencyInMethodBodyTo( IType firstType, params IType[] moreTypes @@ -109,6 +171,34 @@ public MethodMembersShouldConjunction HaveDependencyInMethodBodyTo(IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + MethodMemberConditionsDefinition.HaveReturnType(patterns, useRegularExpressions) + ); + return new MethodMembersShouldConjunction(_ruleCreator); + } + public MethodMembersShouldConjunction HaveReturnType( IType firstType, params IType[] moreTypes @@ -161,6 +251,34 @@ public MethodMembersShouldConjunction NotBeVirtual() return new MethodMembersShouldConjunction(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotBeCalledBy(Types().That().HaveFullName()) instead" + )] + public MethodMembersShouldConjunction NotBeCalledBy( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + MethodMemberConditionsDefinition.NotBeCalledBy(pattern, useRegularExpressions) + ); + return new MethodMembersShouldConjunction(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotBeCalledBy(Types().That().HaveFullName()) instead" + )] + public MethodMembersShouldConjunction NotBeCalledBy( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + MethodMemberConditionsDefinition.NotBeCalledBy(patterns, useRegularExpressions) + ); + return new MethodMembersShouldConjunction(_ruleCreator); + } + public MethodMembersShouldConjunction NotBeCalledBy( IType firstType, params IType[] moreTypes @@ -198,6 +316,40 @@ public MethodMembersShouldConjunction NotBeCalledBy(IEnumerable types) return new MethodMembersShouldConjunction(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotHaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + public MethodMembersShouldConjunction NotHaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + MethodMemberConditionsDefinition.NotHaveDependencyInMethodBodyTo( + pattern, + useRegularExpressions + ) + ); + return new MethodMembersShouldConjunction(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotHaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + public MethodMembersShouldConjunction NotHaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + MethodMemberConditionsDefinition.NotHaveDependencyInMethodBodyTo( + patterns, + useRegularExpressions + ) + ); + return new MethodMembersShouldConjunction(_ruleCreator); + } + public MethodMembersShouldConjunction NotHaveDependencyInMethodBodyTo( IType firstType, params IType[] moreTypes @@ -253,6 +405,34 @@ IEnumerable types return new MethodMembersShouldConjunction(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotHaveReturnType(Types().That().HaveFullName()) instead" + )] + public MethodMembersShouldConjunction NotHaveReturnType( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + MethodMemberConditionsDefinition.NotHaveReturnType(pattern, useRegularExpressions) + ); + return new MethodMembersShouldConjunction(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotHaveReturnType(Types().That().HaveFullName()) instead" + )] + public MethodMembersShouldConjunction NotHaveReturnType( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + MethodMemberConditionsDefinition.NotHaveReturnType(patterns, useRegularExpressions) + ); + return new MethodMembersShouldConjunction(_ruleCreator); + } + public MethodMembersShouldConjunction NotHaveReturnType( IType firstType, params IType[] moreTypes diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/ShouldRelateToMethodMembersThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/ShouldRelateToMethodMembersThat.cs index b08083a56..179b99d2f 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/ShouldRelateToMethodMembersThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/ShouldRelateToMethodMembersThat.cs @@ -34,6 +34,34 @@ public TRuleTypeShouldConjunction AreVirtual() return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreCalledBy(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction AreCalledBy( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + MethodMemberPredicatesDefinition.AreCalledBy(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreCalledBy(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction AreCalledBy( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + MethodMemberPredicatesDefinition.AreCalledBy(patterns, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction AreCalledBy(IType firstType, params IType[] moreTypes) { _ruleCreator.ContinueComplexCondition( @@ -74,6 +102,40 @@ public TRuleTypeShouldConjunction AreCalledBy(IEnumerable types) return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction HaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction HaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo( + patterns, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction HaveDependencyInMethodBodyTo( IType firstType, params IType[] moreTypes @@ -120,6 +182,34 @@ public TRuleTypeShouldConjunction HaveDependencyInMethodBodyTo(IEnumerable return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveReturnType(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction HaveReturnType( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + MethodMemberPredicatesDefinition.HaveReturnType(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveReturnType(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction HaveReturnType( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + MethodMemberPredicatesDefinition.HaveReturnType(patterns, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction HaveReturnType(IType firstType, params IType[] moreTypes) { _ruleCreator.ContinueComplexCondition( @@ -177,6 +267,34 @@ public TRuleTypeShouldConjunction AreNotVirtual() return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNotCalledBy(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction AreNotCalledBy( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + MethodMemberPredicatesDefinition.AreNotCalledBy(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNotCalledBy(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction AreNotCalledBy( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + MethodMemberPredicatesDefinition.AreNotCalledBy(patterns, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction AreNotCalledBy(IType firstType, params IType[] moreTypes) { _ruleCreator.ContinueComplexCondition( @@ -217,6 +335,40 @@ public TRuleTypeShouldConjunction AreNotCalledBy(IEnumerable types) return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotHaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction DoNotHaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotHaveDependencyInMethodBodyTo(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction DoNotHaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo( + patterns, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction DoNotHaveDependencyInMethodBodyTo( IType firstType, params IType[] moreTypes @@ -270,6 +422,37 @@ public TRuleTypeShouldConjunction DoNotHaveDependencyInMethodBodyTo(IEnumerable< return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotHaveReturnType(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction DoNotHaveReturnType( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + MethodMemberPredicatesDefinition.DoNotHaveReturnType(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotHaveReturnType(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction DoNotHaveReturnType( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + MethodMemberPredicatesDefinition.DoNotHaveReturnType( + patterns, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction DoNotHaveReturnType( IType firstType, params IType[] moreTypes diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/ShouldRelateToMembersThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/ShouldRelateToMembersThat.cs index 33f66449e..d43cea138 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/ShouldRelateToMembersThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/ShouldRelateToMembersThat.cs @@ -21,6 +21,40 @@ public class ShouldRelateToMembersThat ruleCreator) : base(ruleCreator) { } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreDeclaredIn(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction AreDeclaredIn( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + MemberPredicatesDefinition.AreDeclaredIn( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreDeclaredIn(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction AreDeclaredIn( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + MemberPredicatesDefinition.AreDeclaredIn( + patterns, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction AreDeclaredIn(IType firstType, params IType[] moreTypes) { _ruleCreator.ContinueComplexCondition( @@ -87,6 +121,40 @@ public TRuleTypeShouldConjunction AreImmutable() //Negations + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNotDeclaredIn(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction AreNotDeclaredIn( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + MemberPredicatesDefinition.AreNotDeclaredIn( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNotDeclaredIn(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction AreNotDeclaredIn( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + MemberPredicatesDefinition.AreNotDeclaredIn( + patterns, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction AreNotDeclaredIn( IType firstType, params IType[] moreTypes diff --git a/ArchUnitNET/Fluent/Syntax/Elements/ObjectConditionsDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/ObjectConditionsDefinition.cs index 2b1aed624..46c595f86 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/ObjectConditionsDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/ObjectConditionsDefinition.cs @@ -25,6 +25,77 @@ public static ICondition Exist() return new ExistsCondition(true); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use Be(Types().That().HaveFullName()) instead" + )] + public static ICondition Be(string pattern, bool useRegularExpressions = false) + { + return new SimpleCondition( + obj => obj.FullNameMatches(pattern, useRegularExpressions), + "have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"", + "does not have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use Be(Types().That().HaveFullName()) instead" + )] + public static ICondition Be( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + string description; + string failDescription; + if (patternList.IsNullOrEmpty()) + { + description = "not exist"; + failDescription = "does exist"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + failDescription = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "does not have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimpleCondition( + obj => + patternList.Any(pattern => obj.FullNameMatches(pattern, useRegularExpressions)), + description, + failDescription + ); + } + public static ICondition Be( ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects @@ -114,6 +185,83 @@ Architecture architecture ); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use CallAny(MethodMembers().That().HaveFullName()) instead" + )] + public static ICondition CallAny( + string pattern, + bool useRegularExpressions = false + ) + { + return new SimpleCondition( + obj => obj.CallsMethod(pattern, useRegularExpressions), + "calls any method with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"", + "does not call any method with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use CallAny(MethodMembers().That().HaveFullName()) instead" + )] + public static ICondition CallAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Condition(TRuleType ruleType) + { + return patternList.Any(pattern => + ruleType.CallsMethod(pattern, useRegularExpressions) + ); + } + + string description; + string failDescription; + if (patternList.IsNullOrEmpty()) + { + description = "call one of no methods (impossible)"; + failDescription = "does not call one of no methods (always true)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "calls any method with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + failDescription = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "does not call any methods with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimpleCondition(Condition, description, failDescription); + } + public static ICondition CallAny( MethodMember method, params MethodMember[] moreMethods @@ -212,6 +360,87 @@ IEnumerable Condition(IEnumerable ruleTypes) return new EnumerableCondition(Condition, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DependOnAny(Types().That().HaveFullName()) instead" + )] + public static ICondition DependOnAny( + string pattern, + bool useRegularExpressions = false + ) + { + return new SimpleCondition( + obj => obj.DependsOn(pattern, useRegularExpressions), + "depend on any types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"", + "does not depend on any type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DependOnAny(Types().That().HaveFullName()) instead" + )] + public static ICondition DependOnAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + bool Condition(TRuleType ruleType, Architecture architecture) + { + return !ruleType.GetTypeDependencies(architecture).IsNullOrEmpty() + && ruleType + .GetTypeDependencies(architecture) + .Any(target => + patternList.Any(pattern => + target.FullNameMatches(pattern, useRegularExpressions) + ) + ); + } + + string description; + string failDescription; + if (patternList.IsNullOrEmpty()) + { + description = "depend on one of no types (impossible)"; + failDescription = "does not depend on no types (always true)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "depend on any types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + failDescription = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "does not depend any types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new ArchitectureCondition(Condition, description, failDescription); + } + public static ICondition DependOnAny(IType firstType, params IType[] moreTypes) { var types = new List { firstType }; @@ -401,6 +630,98 @@ string failDescription return new SimpleCondition(condition, description, failDescription); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyDependOn(Types().That().HaveFullName()) instead" + )] + public static ICondition OnlyDependOn( + string pattern, + bool useRegularExpressions = false + ) + { + ConditionResult Condition(TRuleType ruleType) + { + var pass = true; + var dynamicFailDescription = "does depend on"; + foreach (var dependency in ruleType.GetTypeDependencies()) + { + if (!dependency.FullNameMatches(pattern, useRegularExpressions)) + { + dynamicFailDescription += pass + ? " " + dependency.FullName + : " and " + dependency.FullName; + pass = false; + } + } + + return new ConditionResult(ruleType, pass, dynamicFailDescription); + } + + return new SimpleCondition( + Condition, + "only depend on types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyDependOn(Types().That().HaveFullName()) instead" + )] + public static ICondition OnlyDependOn( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + ConditionResult Condition(TRuleType ruleType) + { + var pass = true; + var dynamicFailDescription = "does depend on"; + foreach (var dependency in ruleType.GetTypeDependencies()) + { + if ( + !patternList.Any(pattern => + dependency.FullNameMatches(pattern, useRegularExpressions) + ) + ) + { + dynamicFailDescription += pass + ? " " + dependency.FullName + : " and " + dependency.FullName; + pass = false; + } + } + + return new ConditionResult(ruleType, pass, dynamicFailDescription); + } + + string description; + if (patternList.IsNullOrEmpty()) + { + description = "have no dependencies"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "only depend on types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimpleCondition(Condition, description); + } + public static ICondition OnlyDependOn(IType firstType, params IType[] moreTypes) { var types = new List { firstType }; @@ -578,6 +899,85 @@ var type in failedObject.GetTypeDependencies().Except(archUnitTypeList) return new ArchitectureCondition(Condition, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveAnyAttributes(Attributes().That().HaveFullName()) instead" + )] + public static ICondition HaveAnyAttributes( + string pattern, + bool useRegularExpressions = false + ) + { + return new SimpleCondition( + obj => obj.HasAttribute(pattern, useRegularExpressions), + "have any attribute with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"", + "does not have any attribute with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveAnyAttributes(Attributes().That().HaveFullName()) instead" + )] + public static ICondition HaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Condition(TRuleType ruleType) + { + return ruleType.Attributes.Any(attribute => + patternList.Any(pattern => + attribute.FullNameMatches(pattern, useRegularExpressions) + ) + ); + } + + string description; + string failDescription; + if (patternList.IsNullOrEmpty()) + { + description = "have one of no attributes (impossible)"; + failDescription = "does not have one of no attributes (always true)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "have any attribute with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + failDescription = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "does not have any attribute with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimpleCondition(Condition, description, failDescription); + } + public static ICondition HaveAnyAttributes( Attribute firstAttribute, params Attribute[] moreAttributes @@ -737,6 +1137,86 @@ Architecture architecture return new ArchitectureCondition(Condition, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyHaveAttributes(Attributes().That().HaveFullName()) instead" + )] + public static ICondition OnlyHaveAttributes( + string pattern, + bool useRegularExpressions = false + ) + { + return new SimpleCondition( + obj => obj.OnlyHasAttributes(pattern, useRegularExpressions), + "only have attributes with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"", + "does not only have attributes with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyHaveAttributes(Attributes().That().HaveFullName()) instead" + )] + public static ICondition OnlyHaveAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Condition(TRuleType ruleType) + { + return ruleType.Attributes.IsNullOrEmpty() + || ruleType.Attributes.All(attribute => + patternList.Any(pattern => + attribute.FullNameMatches(pattern, useRegularExpressions) + ) + ); + } + + string description; + string failDescription; + if (patternList.IsNullOrEmpty()) + { + description = "have no attributes"; + failDescription = "does have attributes"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "only have attributes with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " and \"" + pattern + "\"" + ); + failDescription = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "does not only have attributes with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimpleCondition(Condition, description, failDescription); + } + public static ICondition OnlyHaveAttributes( Attribute firstAttribute, params Attribute[] moreAttributes @@ -925,6 +1405,20 @@ params object[] moreArgumentValues return HaveAnyAttributesWithArguments(argumentValues); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public static ICondition HaveAttributeWithArguments( + string attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) + { + var argumentValues = new List { firstArgumentValue }; + argumentValues.AddRange(moreArgumentValues); + return HaveAttributeWithArguments(attribute, argumentValues); + } + public static ICondition HaveAttributeWithArguments( Attribute attribute, object firstArgumentValue, @@ -957,6 +1451,20 @@ public static ICondition HaveAnyAttributesWithNamedArguments( return HaveAnyAttributesWithNamedArguments(attributeArguments); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public static ICondition HaveAttributeWithNamedArguments( + string attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) + { + var attributeArguments = new List<(string, object)> { firstAttributeArgument }; + attributeArguments.AddRange(moreAttributeArguments); + return HaveAttributeWithNamedArguments(attribute, attributeArguments); + } + public static ICondition HaveAttributeWithNamedArguments( Attribute attribute, (string, object) firstAttributeArgument, @@ -1057,8 +1565,11 @@ bool Condition(TRuleType obj, Architecture architecture) return new ArchitectureCondition(Condition, failDescription, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] public static ICondition HaveAttributeWithArguments( - [NotNull] Attribute attribute, + [NotNull] string attribute, IEnumerable argumentValues ) { @@ -1067,8 +1578,8 @@ IEnumerable argumentValues var argumentValueList = argumentValues?.ToList() ?? new List { null }; if (argumentValueList.IsNullOrEmpty()) { - description = "have attribute \"" + attribute.FullName + "\""; - failDescription = "does not have attribute \"" + attribute.FullName + "\""; + description = "have attribute \"" + attribute + "\""; + failDescription = "does not have attribute \"" + attribute + "\""; } else { @@ -1077,7 +1588,7 @@ IEnumerable argumentValues .Where(att => att != firstArgument) .Aggregate( "have attribute \"" - + attribute.FullName + + attribute + "\" with arguments \"" + firstArgument + "\"", @@ -1087,7 +1598,7 @@ IEnumerable argumentValues .Where(att => att != firstArgument) .Aggregate( "does not have attribute \"" - + attribute.FullName + + attribute + "\" with arguments \"" + firstArgument + "\"", @@ -1099,7 +1610,7 @@ bool Condition(TRuleType obj, Architecture architecture) { foreach (var attributeInstance in obj.AttributeInstances) { - if (!attributeInstance.Type.Equals(attribute)) + if (!attributeInstance.Type.FullNameMatches(attribute)) { goto NextAttribute; } @@ -1139,7 +1650,7 @@ bool Condition(TRuleType obj, Architecture architecture) } public static ICondition HaveAttributeWithArguments( - [NotNull] Type attribute, + [NotNull] Attribute attribute, IEnumerable argumentValues ) { @@ -1178,20 +1689,9 @@ IEnumerable argumentValues bool Condition(TRuleType obj, Architecture architecture) { - Attribute archUnitAttribute; - try - { - archUnitAttribute = architecture.GetAttributeOfType(attribute); - } - catch (TypeDoesNotExistInArchitecture) - { - //can't have a dependency - return false; - } - foreach (var attributeInstance in obj.AttributeInstances) { - if (!attributeInstance.Type.Equals(archUnitAttribute)) + if (!attributeInstance.Type.Equals(attribute)) { goto NextAttribute; } @@ -1230,13 +1730,105 @@ bool Condition(TRuleType obj, Architecture architecture) return new ArchitectureCondition(Condition, description, failDescription); } - public static ICondition HaveAnyAttributesWithNamedArguments( - IEnumerable<(string, object)> attributeArguments + public static ICondition HaveAttributeWithArguments( + [NotNull] Type attribute, + IEnumerable argumentValues ) { - var argumentList = attributeArguments.ToList(); - string description; - Func failDescription; + string description, + failDescription; + var argumentValueList = argumentValues?.ToList() ?? new List { null }; + if (argumentValueList.IsNullOrEmpty()) + { + description = "have attribute \"" + attribute.FullName + "\""; + failDescription = "does not have attribute \"" + attribute.FullName + "\""; + } + else + { + var firstArgument = argumentValueList.First(); + description = argumentValueList + .Where(att => att != firstArgument) + .Aggregate( + "have attribute \"" + + attribute.FullName + + "\" with arguments \"" + + firstArgument + + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); + failDescription = argumentValueList + .Where(att => att != firstArgument) + .Aggregate( + "does not have attribute \"" + + attribute.FullName + + "\" with arguments \"" + + firstArgument + + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); + } + + bool Condition(TRuleType obj, Architecture architecture) + { + Attribute archUnitAttribute; + try + { + archUnitAttribute = architecture.GetAttributeOfType(attribute); + } + catch (TypeDoesNotExistInArchitecture) + { + //can't have a dependency + return false; + } + + foreach (var attributeInstance in obj.AttributeInstances) + { + if (!attributeInstance.Type.Equals(archUnitAttribute)) + { + goto NextAttribute; + } + + var attributeArguments = attributeInstance + .AttributeArguments.Select(arg => arg.Value) + .ToList(); + var typeAttributeArguments = attributeArguments + .OfType>() + .Select(t => t.Type) + .Union(attributeArguments.OfType()) + .ToList(); + foreach (var arg in argumentValueList) + { + if (arg is Type argType) + { + if (typeAttributeArguments.All(t => t.FullName != argType.FullName)) + { + goto NextAttribute; + } + } + else if (!attributeArguments.Contains(arg)) + { + goto NextAttribute; + } + } + + return true; + NextAttribute: + ; + } + + return false; + } + + return new ArchitectureCondition(Condition, description, failDescription); + } + + public static ICondition HaveAnyAttributesWithNamedArguments( + IEnumerable<(string, object)> attributeArguments + ) + { + var argumentList = attributeArguments.ToList(); + string description; + Func failDescription; if (argumentList.IsNullOrEmpty()) { description = "have no or any attributes with named arguments (always true)"; @@ -1321,6 +1913,100 @@ bool Condition(TRuleType obj, Architecture architecture) return new ArchitectureCondition(Condition, failDescription, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public static ICondition HaveAttributeWithNamedArguments( + [NotNull] string attribute, + IEnumerable<(string, object)> attributeArguments + ) + { + string description, + failDescription; + var argumentList = attributeArguments.ToList(); + if (argumentList.IsNullOrEmpty()) + { + description = "have attribute \"" + attribute + "\""; + failDescription = "does not have attribute \"" + attribute + "\""; + } + else + { + var firstArgument = argumentList.First(); + description = argumentList + .Where(att => att != firstArgument) + .Aggregate( + "have attribute \"" + + attribute + + "\" with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); + failDescription = argumentList + .Where(att => att != firstArgument) + .Aggregate( + "does not have attribute \"" + + attribute + + "\" with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); + } + + bool Condition(TRuleType obj, Architecture architecture) + { + foreach (var attributeInstance in obj.AttributeInstances) + { + if (!attributeInstance.Type.FullNameMatches(attribute)) + { + goto NextAttribute; + } + + var attributeArgs = attributeInstance + .AttributeArguments.OfType() + .Select(arg => (arg.Name, arg.Value)) + .ToList(); + var typeAttributeArguments = attributeArgs + .Where(arg => arg.Value is ITypeInstance || arg.Value is IType) + .ToList(); + foreach (var arg in argumentList) + { + if (arg.Item2 is Type argType) + { + if ( + typeAttributeArguments.All(t => + t.Name != arg.Item1 + || t.Value is ITypeInstance typeInstance + && typeInstance.Type.FullName != argType.FullName + || t.Value is IType type && type.FullName != argType.FullName + ) + ) + { + goto NextAttribute; + } + } + else if (!attributeArgs.Contains(arg)) + { + goto NextAttribute; + } + } + + return true; + NextAttribute: + ; + } + + return false; + } + + return new ArchitectureCondition(Condition, description, failDescription); + } + public static ICondition HaveAttributeWithNamedArguments( [NotNull] Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -1514,6 +2200,22 @@ bool Condition(TRuleType obj, Architecture architecture) return new ArchitectureCondition(Condition, description, failDescription); } + [Obsolete( + "Either HaveName() without the useRegularExpressions parameter or HaveNameMatching() should be used" + )] + public static ICondition HaveName(string pattern, bool useRegularExpressions) + { + return new SimpleCondition( + obj => obj.NameMatches(pattern, useRegularExpressions), + obj => "does have name " + obj.Name, + "have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + public static ICondition HaveName(string name) { return new SimpleCondition( @@ -1532,6 +2234,22 @@ public static ICondition HaveNameMatching(string pattern) ); } + [Obsolete( + "Either HaveFullName() without the useRegularExpressions parameter or HaveFullNameMatching() should be used" + )] + public static ICondition HaveFullName(string pattern, bool useRegularExpressions) + { + return new SimpleCondition( + obj => obj.FullNameMatches(pattern, useRegularExpressions), + obj => "does have full name " + obj.FullName, + "have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + public static ICondition HaveFullName(string name) { return new SimpleCondition( @@ -1687,6 +2405,65 @@ public static ICondition NotExist() return new ExistsCondition(false); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotBe(Types().That().HaveFullName()) instead" + )] + public static ICondition NotBe( + string pattern, + bool useRegularExpressions = false + ) + { + return new SimpleCondition( + obj => !obj.FullNameMatches(pattern, useRegularExpressions), + obj => "is " + obj.FullName, + "not have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotBe(Types().That().HaveFullName()) instead" + )] + public static ICondition NotBe( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + string description; + if (patternList.IsNullOrEmpty()) + { + description = "exist"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "not have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimpleCondition( + obj => + patternList.All(pattern => + !obj.FullNameMatches(pattern, useRegularExpressions) + ), + obj => "is " + obj.FullName, + description + ); + } + public static ICondition NotBe( ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects @@ -1771,6 +2548,98 @@ Architecture architecture ); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotCallAny(MethodMembers().That().HaveFullName()) instead" + )] + public static ICondition NotCallAny( + string pattern, + bool useRegularExpressions = false + ) + { + ConditionResult Condition(TRuleType ruleType) + { + var pass = true; + var dynamicFailDescription = "does call"; + foreach (var dependency in ruleType.GetCalledMethods()) + { + if (dependency.FullNameMatches(pattern, useRegularExpressions)) + { + dynamicFailDescription += pass + ? " " + dependency.FullName + : " and " + dependency.FullName; + pass = false; + } + } + + return new ConditionResult(ruleType, pass, dynamicFailDescription); + } + + return new SimpleCondition( + Condition, + "not call any method with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotCallAny(MethodMembers().That().HaveFullName()) instead" + )] + public static ICondition NotCallAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + ConditionResult Condition(TRuleType ruleType) + { + var pass = true; + var dynamicFailDescription = "does call"; + foreach (var dependency in ruleType.GetCalledMethods()) + { + if ( + patternList.Any(pattern => + dependency.FullNameMatches(pattern, useRegularExpressions) + ) + ) + { + dynamicFailDescription += pass + ? " " + dependency.FullName + : " and " + dependency.FullName; + pass = false; + } + } + + return new ConditionResult(ruleType, pass, dynamicFailDescription); + } + + string description; + if (patternList.IsNullOrEmpty()) + { + description = "not call no methods (always true)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "not call methods with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimpleCondition(Condition, description); + } + public static ICondition NotCallAny( MethodMember method, params MethodMember[] moreMethods @@ -1830,43 +2699,135 @@ IEnumerable Condition(IEnumerable ruleTypes) .ToList(); foreach (var failedObject in failedObjects) { - var dynamicFailDescription = "does call"; - var first = true; - foreach (var method in failedObject.GetCalledMethods().Intersect(methodList)) + var dynamicFailDescription = "does call"; + var first = true; + foreach (var method in failedObject.GetCalledMethods().Intersect(methodList)) + { + dynamicFailDescription += first + ? " " + method.FullName + : " and " + method.FullName; + first = false; + } + + yield return new ConditionResult(failedObject, false, dynamicFailDescription); + } + + foreach (var passedObject in typeList.Except(failedObjects)) + { + yield return new ConditionResult(passedObject, true); + } + } + + string description; + if (methodList.IsNullOrEmpty()) + { + description = "not call no methods (always true)"; + } + else + { + var firstMethod = methodList.First(); + description = methodList + .Where(obj => !obj.Equals(firstMethod)) + .Distinct() + .Aggregate( + "not call \"" + firstMethod.FullName + "\"", + (current, obj) => current + " or \"" + obj.FullName + "\"" + ); + } + + return new EnumerableCondition(Condition, description); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotDependOnAny(Types().That().HaveFullName()) instead" + )] + public static ICondition NotDependOnAny( + string pattern, + bool useRegularExpressions = false + ) + { + ConditionResult Condition(TRuleType ruleType) + { + var pass = true; + var dynamicFailDescription = "does depend on"; + foreach (var dependency in ruleType.GetTypeDependencies()) + { + if (dependency.FullNameMatches(pattern, useRegularExpressions)) + { + dynamicFailDescription += pass + ? " " + dependency.FullName + : " and " + dependency.FullName; + pass = false; + } + } + + return new ConditionResult(ruleType, pass, dynamicFailDescription); + } + + return new SimpleCondition( + Condition, + "not depend on any types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotDependOnAny(Types().That().HaveFullName()) instead" + )] + public static ICondition NotDependOnAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + ConditionResult Condition(TRuleType ruleType) + { + var pass = true; + var dynamicFailDescription = "does depend on"; + foreach (var dependency in ruleType.GetTypeDependencies()) + { + if ( + patternList.Any(pattern => + dependency.FullNameMatches(pattern, useRegularExpressions) + ) + ) { - dynamicFailDescription += first - ? " " + method.FullName - : " and " + method.FullName; - first = false; + dynamicFailDescription += pass + ? " " + dependency.FullName + : " and " + dependency.FullName; + pass = false; } - - yield return new ConditionResult(failedObject, false, dynamicFailDescription); } - foreach (var passedObject in typeList.Except(failedObjects)) - { - yield return new ConditionResult(passedObject, true); - } + return new ConditionResult(ruleType, pass, dynamicFailDescription); } string description; - if (methodList.IsNullOrEmpty()) + if (patternList.IsNullOrEmpty()) { - description = "not call no methods (always true)"; + description = "not depend on no types (always true)"; } else { - var firstMethod = methodList.First(); - description = methodList - .Where(obj => !obj.Equals(firstMethod)) + var firstPattern = patternList.First(); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) .Distinct() .Aggregate( - "not call \"" + firstMethod.FullName + "\"", - (current, obj) => current + " or \"" + obj.FullName + "\"" + "not depend on types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" ); } - return new EnumerableCondition(Condition, description); + return new SimpleCondition(Condition, description); } public static ICondition NotDependOnAny( @@ -2044,6 +3005,85 @@ var type in failedObject.GetTypeDependencies().Intersect(archUnitTypeList) return new ArchitectureCondition(Condition, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public static ICondition NotHaveAnyAttributes( + string pattern, + bool useRegularExpressions = false + ) + { + return new SimpleCondition( + obj => !obj.HasAttribute(pattern, useRegularExpressions), + "not have any attribute with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"", + "does have any attribute with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public static ICondition NotHaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Condition(TRuleType ruleType) + { + return !ruleType.Attributes.Any(attribute => + patternList.Any(pattern => + attribute.FullNameMatches(pattern, useRegularExpressions) + ) + ); + } + + string description; + string failDescription; + if (patternList.IsNullOrEmpty()) + { + description = "not have one of no attributes (always true)"; + failDescription = "does have one of no attributes (impossible)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "not have any attribute with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + failDescription = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "does have any attribute with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimpleCondition(Condition, description, failDescription); + } + public static ICondition NotHaveAnyAttributes( Attribute firstAttribute, params Attribute[] moreAttributes @@ -2234,6 +3274,20 @@ params object[] moreArgumentValues return NotHaveAnyAttributesWithArguments(argumentValues); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public static ICondition NotHaveAttributeWithArguments( + string attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) + { + var argumentValues = new List { firstArgumentValue }; + argumentValues.AddRange(moreArgumentValues); + return NotHaveAttributeWithArguments(attribute, argumentValues); + } + public static ICondition NotHaveAttributeWithArguments( Attribute attribute, object firstArgumentValue, @@ -2266,6 +3320,20 @@ public static ICondition NotHaveAnyAttributesWithNamedArguments( return NotHaveAnyAttributesWithNamedArguments(attributeArguments); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public static ICondition NotHaveAttributeWithNamedArguments( + string attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) + { + var attributeArguments = new List<(string, object)> { firstAttributeArgument }; + attributeArguments.AddRange(moreAttributeArguments); + return NotHaveAttributeWithNamedArguments(attribute, attributeArguments); + } + public static ICondition NotHaveAttributeWithNamedArguments( Attribute attribute, (string, object) firstAttributeArgument, @@ -2366,6 +3434,90 @@ bool Condition(TRuleType obj, Architecture architecture) return new ArchitectureCondition(Condition, failDescription, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public static ICondition NotHaveAttributeWithArguments( + [NotNull] string attribute, + IEnumerable argumentValues + ) + { + string description, + failDescription; + var argumentValueList = argumentValues?.ToList() ?? new List { null }; + if (argumentValueList.IsNullOrEmpty()) + { + description = "not have attribute \"" + attribute + "\""; + failDescription = "does have attribute \"" + attribute + "\""; + } + else + { + var firstArgument = argumentValueList.First(); + description = argumentValueList + .Where(att => att != firstArgument) + .Aggregate( + "not have attribute \"" + + attribute + + "\" with arguments \"" + + firstArgument + + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); + failDescription = argumentValueList + .Where(att => att != firstArgument) + .Aggregate( + "does have attribute \"" + + attribute + + "\" with arguments \"" + + firstArgument + + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); + } + + bool Condition(TRuleType obj, Architecture architecture) + { + foreach (var attributeInstance in obj.AttributeInstances) + { + if (!attributeInstance.Type.FullNameMatches(attribute)) + { + goto NextAttribute; + } + + var attributeArguments = attributeInstance + .AttributeArguments.Select(arg => arg.Value) + .ToList(); + var typeAttributeArguments = attributeArguments + .OfType>() + .Select(t => t.Type) + .Union(attributeArguments.OfType()) + .ToList(); + foreach (var arg in argumentValueList) + { + if (arg is Type argType) + { + if (typeAttributeArguments.All(t => t.FullName != argType.FullName)) + { + goto NextAttribute; + } + } + else if (!attributeArguments.Contains(arg)) + { + goto NextAttribute; + } + } + + return false; + NextAttribute: + ; + } + + return true; + } + + return new ArchitectureCondition(Condition, description, failDescription); + } + public static ICondition NotHaveAttributeWithArguments( [NotNull] Attribute attribute, IEnumerable argumentValues @@ -2632,6 +3784,100 @@ t.Value is ITypeInstance typeInstance return new ArchitectureCondition(Condition, failDescription, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public static ICondition NotHaveAttributeWithNamedArguments( + [NotNull] string attribute, + IEnumerable<(string, object)> attributeArguments + ) + { + string description, + failDescription; + var argumentList = attributeArguments.ToList(); + if (argumentList.IsNullOrEmpty()) + { + description = "not have attribute \"" + attribute + "\""; + failDescription = "does have attribute \"" + attribute + "\""; + } + else + { + var firstArgument = argumentList.First(); + description = argumentList + .Where(att => att != firstArgument) + .Aggregate( + "not have attribute \"" + + attribute + + "\" with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); + failDescription = argumentList + .Where(att => att != firstArgument) + .Aggregate( + "does have attribute \"" + + attribute + + "\" with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); + } + + bool Condition(TRuleType obj, Architecture architecture) + { + foreach (var attributeInstance in obj.AttributeInstances) + { + if (!attributeInstance.Type.FullNameMatches(attribute)) + { + goto NextAttribute; + } + + var attributeArgs = attributeInstance + .AttributeArguments.OfType() + .Select(arg => (arg.Name, arg.Value)) + .ToList(); + var typeAttributeArguments = attributeArgs + .Where(arg => arg.Value is ITypeInstance || arg.Value is IType) + .ToList(); + foreach (var arg in argumentList) + { + if (arg.Item2 is Type argType) + { + if ( + typeAttributeArguments.All(t => + t.Name != arg.Item1 + || t.Value is ITypeInstance typeInstance + && typeInstance.Type.FullName != argType.FullName + || t.Value is IType type && type.FullName != argType.FullName + ) + ) + { + goto NextAttribute; + } + } + else if (!attributeArgs.Contains(arg)) + { + goto NextAttribute; + } + } + + return false; + NextAttribute: + ; + } + + return true; + } + + return new ArchitectureCondition(Condition, failDescription, description); + } + public static ICondition NotHaveAttributeWithNamedArguments( [NotNull] Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -2825,6 +4071,22 @@ bool Condition(TRuleType obj, Architecture architecture) return new ArchitectureCondition(Condition, failDescription, description); } + [Obsolete( + "Either NotHaveName() without the useRegularExpressions parameter or NotHaveNameMatching() should be used" + )] + public static ICondition NotHaveName(string pattern, bool useRegularExpressions) + { + return new SimpleCondition( + obj => !obj.NameMatches(pattern, useRegularExpressions), + obj => "does have name " + obj.Name, + "not have name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + public static ICondition NotHaveName(string name) { return new SimpleCondition( @@ -2843,6 +4105,25 @@ public static ICondition NotHaveNameMatching(string pattern) ); } + [Obsolete( + "Either NotHaveFullName() without the useRegularExpressions parameter or NotHaveFullNameMatching() should be used" + )] + public static ICondition NotHaveFullName( + string pattern, + bool useRegularExpressions + ) + { + return new SimpleCondition( + obj => !obj.FullNameMatches(pattern, useRegularExpressions), + obj => "does have full name " + obj.FullName, + "not have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + public static ICondition NotHaveFullName(string fullName) { return new SimpleCondition( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/ObjectPredicatesDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/ObjectPredicatesDefinition.cs index 131f72649..e158f6c4d 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/ObjectPredicatesDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/ObjectPredicatesDefinition.cs @@ -20,6 +20,58 @@ namespace ArchUnitNET.Fluent.Syntax.Elements public static class ObjectPredicatesDefinition where T : ICanBeAnalyzed { + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use Are(Types().That().HaveFullName()) instead" + )] + public static IPredicate Are(string pattern, bool useRegularExpressions = false) + { + return new SimplePredicate( + obj => obj.FullNameMatches(pattern, useRegularExpressions), + "have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use Are(Types().That().HaveFullName()) instead" + )] + public static IPredicate Are( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + string description; + if (patternList.IsNullOrEmpty()) + { + description = "not exist (impossible)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimplePredicate( + obj => + patternList.Any(pattern => obj.FullNameMatches(pattern, useRegularExpressions)), + description + ); + } + public static IPredicate Are( ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects @@ -71,6 +123,60 @@ IEnumerable Filter(IEnumerable objects, Architecture architecture) return new ArchitecturePredicate(Filter, "are " + objectProvider.Description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use CallAny(MethodMembers().That().HaveFullName()) instead" + )] + public static IPredicate CallAny(string pattern, bool useRegularExpressions = false) + { + return new SimplePredicate( + obj => obj.CallsMethod(pattern, useRegularExpressions), + "calls any method with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use CallAny(MethodMembers().That().HaveFullName()) instead" + )] + public static IPredicate CallAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Filter(T type) + { + return patternList.Any(method => type.CallsMethod(method)); + } + + string description; + if (patternList.IsNullOrEmpty()) + { + description = "call one of no methods (impossible)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "call any method with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimplePredicate(Filter, description); + } + public static IPredicate CallAny(MethodMember method, params MethodMember[] moreMethods) { var methods = new List { method }; @@ -119,6 +225,65 @@ IEnumerable Filter(IEnumerable objects) return new EnumerablePredicate(Filter, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DependOnAny(Types().That().HaveFullName()) instead" + )] + public static IPredicate DependOnAny(string pattern, bool useRegularExpressions = false) + { + return new SimplePredicate( + obj => obj.DependsOn(pattern, useRegularExpressions), + "depend on any types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DependOnAny(Types().That().HaveFullName()) instead" + )] + public static IPredicate DependOnAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Filter(T type) + { + return type.GetTypeDependencies() + .Any(target => + patternList.Any(pattern => + target.FullNameMatches(pattern, useRegularExpressions) + ) + ); + } + + string description; + if (patternList.IsNullOrEmpty()) + { + description = "have no dependencies"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "depend on any types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimplePredicate(Filter, description); + } + public static IPredicate DependOnAny(IType firstType, params IType[] moreTypes) { var types = new List { firstType }; @@ -227,6 +392,65 @@ string description return new SimplePredicate(predicate, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyDependOn(Types().That().HaveFullName()) instead" + )] + public static IPredicate OnlyDependOn(string pattern, bool useRegularExpressions = false) + { + return new SimplePredicate( + obj => obj.OnlyDependsOn(pattern, useRegularExpressions), + "only depend on types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyDependOn(Types().That().HaveFullName()) instead" + )] + public static IPredicate OnlyDependOn( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Filter(T type) + { + return type.GetTypeDependencies() + .All(target => + patternList.Any(pattern => + target.FullNameMatches(pattern, useRegularExpressions) + ) + ); + } + + string description; + if (patternList.IsNullOrEmpty()) + { + description = "have no dependencies"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "only depend on types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimplePredicate(Filter, description); + } + public static IPredicate OnlyDependOn(IType firstType, params IType[] moreTypes) { var types = new List { firstType }; @@ -331,6 +555,67 @@ IEnumerable Filter(IEnumerable objects, Architecture architecture) return new ArchitecturePredicate(Filter, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveAnyAttributes(Attributes().That().HaveFullName()) instead" + )] + public static IPredicate HaveAnyAttributes( + string pattern, + bool useRegularExpressions = false + ) + { + return new SimplePredicate( + obj => obj.HasAttribute(pattern, useRegularExpressions), + "have any attribute with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveAnyAttributes(Attributes().That().HaveFullName()) instead" + )] + public static IPredicate HaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Filter(T type) + { + return type.Attributes.Any(attribute => + patternList.Any(pattern => + attribute.FullNameMatches(pattern, useRegularExpressions) + ) + ); + } + + string description; + if (patternList.IsNullOrEmpty()) + { + description = "have one of no attributes (impossible)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "have any attribute with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimplePredicate(Filter, description); + } + public static IPredicate HaveAnyAttributes( Attribute firstAttribute, params Attribute[] moreAttributes @@ -422,6 +707,68 @@ IEnumerable Filter(IEnumerable objects, Architecture architecture) return new ArchitecturePredicate(Filter, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyHaveAttributes(Attributes().That().HaveFullName()) instead" + )] + public static IPredicate OnlyHaveAttributes( + string pattern, + bool useRegularExpressions = false + ) + { + return new SimplePredicate( + obj => obj.OnlyHasAttributes(pattern, useRegularExpressions), + "only have attributes with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyHaveAttributes(Attributes().That().HaveFullName()) instead" + )] + public static IPredicate OnlyHaveAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Filter(T type) + { + return type.Attributes.IsNullOrEmpty() + || type.Attributes.All(attribute => + patternList.Any(pattern => + attribute.FullNameMatches(pattern, useRegularExpressions) + ) + ); + } + + string description; + if (patternList.IsNullOrEmpty()) + { + description = "have no attributes"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "only have attributes with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimplePredicate(Filter, description); + } + public static IPredicate OnlyHaveAttributes( Attribute firstAttribute, params Attribute[] moreAttributes @@ -536,6 +883,20 @@ params object[] moreArgumentValues return HaveAnyAttributesWithArguments(argumentValues); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public static IPredicate HaveAttributeWithArguments( + string attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) + { + var argumentValues = new List { firstArgumentValue }; + argumentValues.AddRange(moreArgumentValues); + return HaveAttributeWithArguments(attribute, argumentValues); + } + public static IPredicate HaveAttributeWithArguments( Attribute attribute, object firstArgumentValue, @@ -568,6 +929,20 @@ public static IPredicate HaveAnyAttributesWithNamedArguments( return HaveAnyAttributesWithNamedArguments(attributeArguments); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public static IPredicate HaveAttributeWithNamedArguments( + string attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) + { + var attributeArguments = new List<(string, object)> { firstAttributeArgument }; + attributeArguments.AddRange(moreAttributeArguments); + return HaveAttributeWithNamedArguments(attribute, attributeArguments); + } + public static IPredicate HaveAttributeWithNamedArguments( Attribute attribute, (string, object) firstAttributeArgument, @@ -644,6 +1019,78 @@ bool Predicate(T obj, Architecture architecture) return new ArchitecturePredicate(Predicate, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public static IPredicate HaveAttributeWithArguments( + [NotNull] string attribute, + IEnumerable argumentValues + ) + { + string description; + var argumentValueList = argumentValues?.ToList() ?? new List { null }; + if (argumentValueList.IsNullOrEmpty()) + { + description = "have attribute \"" + attribute + "\""; + } + else + { + var firstArgument = argumentValueList.First(); + description = argumentValueList + .Where(att => att != firstArgument) + .Aggregate( + "have attribute \"" + + attribute + + "\" with arguments \"" + + firstArgument + + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); + } + + bool Predicate(T obj, Architecture architecture) + { + foreach (var attributeInstance in obj.AttributeInstances) + { + if (!attributeInstance.Type.FullNameMatches(attribute)) + { + goto NextAttribute; + } + + var attributeArguments = attributeInstance + .AttributeArguments.Select(arg => arg.Value) + .ToList(); + var typeAttributeArguments = attributeArguments + .OfType>() + .Select(t => t.Type) + .Union(attributeArguments.OfType()) + .ToList(); + foreach (var arg in argumentValueList) + { + if (arg is Type argType) + { + if (typeAttributeArguments.All(t => t.FullName != argType.FullName)) + { + goto NextAttribute; + } + } + else if (!attributeArguments.Contains(arg)) + { + goto NextAttribute; + } + } + + return true; + NextAttribute: + ; + } + + return false; + } + + return new ArchitecturePredicate(Predicate, description); + } + public static IPredicate HaveAttributeWithArguments( [NotNull] Attribute attribute, IEnumerable argumentValues @@ -858,8 +1305,11 @@ bool Predicate(T obj, Architecture architecture) return new ArchitecturePredicate(Predicate, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] public static IPredicate HaveAttributeWithNamedArguments( - [NotNull] Attribute attribute, + [NotNull] string attribute, IEnumerable<(string, object)> attributeArguments ) { @@ -867,7 +1317,7 @@ public static IPredicate HaveAttributeWithNamedArguments( var argumentList = attributeArguments.ToList(); if (argumentList.IsNullOrEmpty()) { - description = "have attribute \"" + attribute.FullName + "\""; + description = "have attribute \"" + attribute + "\""; } else { @@ -876,7 +1326,7 @@ public static IPredicate HaveAttributeWithNamedArguments( .Where(att => att != firstArgument) .Aggregate( "have attribute \"" - + attribute.FullName + + attribute + "\" with named arguments \"" + firstArgument.Item1 + "=" @@ -886,11 +1336,11 @@ public static IPredicate HaveAttributeWithNamedArguments( ); } - bool Condition(T obj, Architecture architecture) + bool Predicate(T obj, Architecture architecture) { foreach (var attributeInstance in obj.AttributeInstances) { - if (!attributeInstance.Type.Equals(attribute)) + if (!attributeInstance.Type.FullNameMatches(attribute)) { goto NextAttribute; } @@ -932,7 +1382,84 @@ bool Condition(T obj, Architecture architecture) return false; } - return new ArchitecturePredicate(Condition, description); + return new ArchitecturePredicate(Predicate, description); + } + + public static IPredicate HaveAttributeWithNamedArguments( + [NotNull] Attribute attribute, + IEnumerable<(string, object)> attributeArguments + ) + { + string description; + var argumentList = attributeArguments.ToList(); + if (argumentList.IsNullOrEmpty()) + { + description = "have attribute \"" + attribute.FullName + "\""; + } + else + { + var firstArgument = argumentList.First(); + description = argumentList + .Where(att => att != firstArgument) + .Aggregate( + "have attribute \"" + + attribute.FullName + + "\" with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); + } + + bool Condition(T obj, Architecture architecture) + { + foreach (var attributeInstance in obj.AttributeInstances) + { + if (!attributeInstance.Type.Equals(attribute)) + { + goto NextAttribute; + } + + var attributeArgs = attributeInstance + .AttributeArguments.OfType() + .Select(arg => (arg.Name, arg.Value)) + .ToList(); + var typeAttributeArguments = attributeArgs + .Where(arg => arg.Value is ITypeInstance || arg.Value is IType) + .ToList(); + foreach (var arg in argumentList) + { + if (arg.Item2 is Type argType) + { + if ( + typeAttributeArguments.All(t => + t.Name != arg.Item1 + || t.Value is ITypeInstance typeInstance + && typeInstance.Type.FullName != argType.FullName + || t.Value is IType type && type.FullName != argType.FullName + ) + ) + { + goto NextAttribute; + } + } + else if (!argumentList.Contains(arg)) + { + goto NextAttribute; + } + } + + return true; + NextAttribute: + ; + } + + return false; + } + + return new ArchitecturePredicate(Condition, description); } public static IPredicate HaveAttributeWithNamedArguments( @@ -1023,6 +1550,17 @@ bool Predicate(T obj, Architecture architecture) return new ArchitecturePredicate(Predicate, description); } + [Obsolete( + "Either HaveName() without the useRegularExpressions parameter or HaveNameMatching() should be used" + )] + public static IPredicate HaveName(string pattern, bool useRegularExpressions) + { + return new SimplePredicate( + obj => obj.NameMatches(pattern, useRegularExpressions), + "have name " + (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\"" + ); + } + public static IPredicate HaveName(string name) { return new SimplePredicate( @@ -1039,6 +1577,21 @@ public static IPredicate HaveNameMatching(string pattern) ); } + [Obsolete( + "Either HaveFullName() without the useRegularExpressions parameter or HaveFullNameMatching() should be used" + )] + public static IPredicate HaveFullName(string pattern, bool useRegularExpressions) + { + return new SimplePredicate( + obj => obj.FullNameMatches(pattern, useRegularExpressions), + "have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + public static IPredicate HaveFullName(string fullName) { return new SimplePredicate( @@ -1125,6 +1678,60 @@ public static IPredicate ArePrivateProtected() //Negations + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNot(Types().That().HaveFullName()) instead" + )] + public static IPredicate AreNot(string pattern, bool useRegularExpressions = false) + { + return new SimplePredicate( + obj => !obj.FullNameMatches(pattern, useRegularExpressions), + "do not have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNot(Types().That().HaveFullName()) instead" + )] + public static IPredicate AreNot( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + string description; + if (patternList.IsNullOrEmpty()) + { + description = "exist (always true)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "do not have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimplePredicate( + obj => + patternList.All(pattern => + !obj.FullNameMatches(pattern, useRegularExpressions) + ), + description + ); + } + public static IPredicate AreNot( ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects @@ -1173,6 +1780,62 @@ IEnumerable Filter(IEnumerable objects, Architecture architecture) return new ArchitecturePredicate(Filter, "are not " + objectProvider.Description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotCallAny(MethodMembers().That().HaveFullName()) instead" + )] + public static IPredicate DoNotCallAny(string pattern, bool useRegularExpressions = false) + { + return new SimplePredicate( + obj => !obj.CallsMethod(pattern, useRegularExpressions), + "do not call any methods with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotCallAny(MethodMembers().That().HaveFullName()) instead" + )] + public static IPredicate DoNotCallAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Filter(T type) + { + return patternList.All(pattern => + !type.CallsMethod(pattern, useRegularExpressions) + ); + } + + string description; + if (patternList.IsNullOrEmpty()) + { + description = "do not call one of no methods (always true)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "do not call any methods with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimplePredicate(Filter, description); + } + public static IPredicate DoNotCallAny( MethodMember method, params MethodMember[] moreMethods @@ -1224,6 +1887,68 @@ IEnumerable Filter(IEnumerable objects) return new EnumerablePredicate(Filter, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotDependOnAny(Types().That().HaveFullName()) instead" + )] + public static IPredicate DoNotDependOnAny( + string pattern, + bool useRegularExpressions = false + ) + { + return new SimplePredicate( + obj => !obj.DependsOn(pattern, useRegularExpressions), + "do not depend on any types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotDependOnAny(Types().That().HaveFullName()) instead" + )] + public static IPredicate DoNotDependOnAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Filter(T type) + { + return type.GetTypeDependencies() + .All(target => + patternList.All(pattern => + target.FullNameMatches(pattern, useRegularExpressions) + ) + ); + } + + string description; + if (patternList.IsNullOrEmpty()) + { + description = "do not depend on no types (always true)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "do not depend on any types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimplePredicate(Filter, description); + } + public static IPredicate DoNotDependOnAny(IType firstType, params IType[] moreTypes) { var types = new List { firstType }; @@ -1324,6 +2049,67 @@ IEnumerable Filter(IEnumerable objects, Architecture architecture) return new ArchitecturePredicate(Filter, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotHaveAnyAttributes(Attributes().That().HaveFullName()) instead" + )] + public static IPredicate DoNotHaveAnyAttributes( + string pattern, + bool useRegularExpressions = false + ) + { + return new SimplePredicate( + obj => !obj.HasAttribute(pattern, useRegularExpressions), + "do not have any attribute with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotHaveAnyAttributes(Attributes().That().HaveFullName()) instead" + )] + public static IPredicate DoNotHaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Filter(T type) + { + return !type.Attributes.Any(attribute => + patternList.Any(pattern => + attribute.FullNameMatches(pattern, useRegularExpressions) + ) + ); + } + + string description; + if (patternList.IsNullOrEmpty()) + { + description = "do not have one of no attributes (always true)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "do not have any attribute with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimplePredicate(Filter, description); + } + public static IPredicate DoNotHaveAnyAttributes( Attribute firstAttribute, params Attribute[] moreAttributes @@ -1440,6 +2226,20 @@ params object[] moreArgumentValues return DoNotHaveAnyAttributesWithArguments(argumentValues); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public static IPredicate DoNotHaveAttributeWithArguments( + string attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) + { + var argumentValues = new List { firstArgumentValue }; + argumentValues.AddRange(moreArgumentValues); + return DoNotHaveAttributeWithArguments(attribute, argumentValues); + } + public static IPredicate DoNotHaveAttributeWithArguments( Attribute attribute, object firstArgumentValue, @@ -1472,6 +2272,20 @@ public static IPredicate DoNotHaveAnyAttributesWithNamedArguments( return DoNotHaveAnyAttributesWithNamedArguments(attributeArguments); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public static IPredicate DoNotHaveAttributeWithNamedArguments( + string attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) + { + var attributeArguments = new List<(string, object)> { firstAttributeArgument }; + attributeArguments.AddRange(moreAttributeArguments); + return DoNotHaveAttributeWithNamedArguments(attribute, attributeArguments); + } + public static IPredicate DoNotHaveAttributeWithNamedArguments( Attribute attribute, (string, object) firstAttributeArgument, @@ -1548,6 +2362,78 @@ bool Predicate(T obj, Architecture architecture) return new ArchitecturePredicate(Predicate, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public static IPredicate DoNotHaveAttributeWithArguments( + [NotNull] string attribute, + IEnumerable argumentValues + ) + { + string description; + var argumentValueList = argumentValues?.ToList() ?? new List { null }; + if (argumentValueList.IsNullOrEmpty()) + { + description = "do not have attribute \"" + attribute + "\""; + } + else + { + var firstArgument = argumentValueList.First(); + description = argumentValueList + .Where(att => att != firstArgument) + .Aggregate( + "do not have attribute \"" + + attribute + + "\" with arguments \"" + + firstArgument + + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); + } + + bool Predicate(T obj, Architecture architecture) + { + foreach (var attributeInstance in obj.AttributeInstances) + { + if (!attributeInstance.Type.FullNameMatches(attribute)) + { + goto NextAttribute; + } + + var attributeArguments = attributeInstance + .AttributeArguments.Select(arg => arg.Value) + .ToList(); + var typeAttributeArguments = attributeArguments + .OfType>() + .Select(t => t.Type) + .Union(attributeArguments.OfType()) + .ToList(); + foreach (var arg in argumentValueList) + { + if (arg is Type argType) + { + if (typeAttributeArguments.All(t => t.FullName != argType.FullName)) + { + goto NextAttribute; + } + } + else if (!attributeArguments.Contains(arg)) + { + goto NextAttribute; + } + } + + return false; + NextAttribute: + ; + } + + return true; + } + + return new ArchitecturePredicate(Predicate, description); + } + public static IPredicate DoNotHaveAttributeWithArguments( [NotNull] Attribute attribute, IEnumerable argumentValues @@ -1764,6 +2650,86 @@ t.Value is ITypeInstance typeInstance return new ArchitecturePredicate(Condition, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public static IPredicate DoNotHaveAttributeWithNamedArguments( + [NotNull] string attribute, + IEnumerable<(string, object)> attributeArguments + ) + { + string description; + var argumentList = attributeArguments.ToList(); + if (argumentList.IsNullOrEmpty()) + { + description = "do not have attribute \"" + attribute + "\""; + } + else + { + var firstArgument = argumentList.First(); + description = argumentList + .Where(att => att != firstArgument) + .Aggregate( + "do not have attribute \"" + + attribute + + "\" with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); + } + + bool Predicate(T obj, Architecture architecture) + { + foreach (var attributeInstance in obj.AttributeInstances) + { + if (!attributeInstance.Type.FullNameMatches(attribute)) + { + goto NextAttribute; + } + + var attributeArgs = attributeInstance + .AttributeArguments.OfType() + .Select(arg => (arg.Name, arg.Value)) + .ToList(); + var typeAttributeArguments = attributeArgs + .Where(arg => arg.Value is ITypeInstance || arg.Value is IType) + .ToList(); + foreach (var arg in argumentList) + { + if (arg.Item2 is Type argType) + { + if ( + typeAttributeArguments.All(t => + t.Name != arg.Item1 + || t.Value is ITypeInstance typeInstance + && typeInstance.Type.FullName != argType.FullName + || t.Value is IType type && type.FullName != argType.FullName + ) + ) + { + goto NextAttribute; + } + } + else if (!argumentList.Contains(arg)) + { + goto NextAttribute; + } + } + + return false; + NextAttribute: + ; + } + + return true; + } + + return new ArchitecturePredicate(Predicate, description); + } + public static IPredicate DoNotHaveAttributeWithNamedArguments( [NotNull] Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -1929,6 +2895,21 @@ bool Predicate(T obj, Architecture architecture) return new ArchitecturePredicate(Predicate, description); } + [Obsolete( + "Either DoNotHaveName() without the useRegularExpressions parameter or DoNotHaveNameMatching() should be used" + )] + public static IPredicate DoNotHaveName(string pattern, bool useRegularExpressions) + { + return new SimplePredicate( + obj => !obj.NameMatches(pattern, useRegularExpressions), + "do not have name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + public static IPredicate DoNotHaveName(string name) { return new SimplePredicate( @@ -1945,6 +2926,21 @@ public static IPredicate DoNotHaveNameMatching(string pattern) ); } + [Obsolete( + "Either DoNotHaveFullName() without the useRegularExpressions parameter or DoNotHaveFullNameMatching() should be used" + )] + public static IPredicate DoNotHaveFullName(string pattern, bool useRegularExpressions) + { + return new SimplePredicate( + obj => !obj.FullNameMatches(pattern, useRegularExpressions), + "do not have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + public static IPredicate DoNotHaveFullName(string fullName) { return new SimplePredicate( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShould.cs b/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShould.cs index b4f263364..f707a0c55 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShould.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShould.cs @@ -32,6 +32,31 @@ public TRuleTypeShouldConjunction Exist() return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use Be(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction Be(string pattern, bool useRegularExpressions = false) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.Be(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use Be(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction Be( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.Be(patterns, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction Be( ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects @@ -55,6 +80,34 @@ public TRuleTypeShouldConjunction Be(IObjectProvider objects) return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use CallAny(MethodMembers().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction CallAny( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.CallAny(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use CallAny(MethodMembers().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction CallAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.CallAny(patterns, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction CallAny( MethodMember method, params MethodMember[] moreMethods @@ -78,6 +131,34 @@ public TRuleTypeShouldConjunction CallAny(IObjectProvider methods) return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DependOnAny(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction DependOnAny( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.DependOnAny(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DependOnAny(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction DependOnAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.DependOnAny(patterns, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction DependOnAny(IType firstType, params IType[] moreTypes) { _ruleCreator.AddCondition( @@ -145,6 +226,34 @@ string failDescription return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyDependOn(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction OnlyDependOn( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.OnlyDependOn(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyDependOn(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction OnlyDependOn( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.OnlyDependOn(patterns, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction OnlyDependOn(IType firstType, params IType[] moreTypes) { _ruleCreator.AddCondition( @@ -179,6 +288,40 @@ public TRuleTypeShouldConjunction OnlyDependOn(IEnumerable types) return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveAnyAttributes(Attributes().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction HaveAnyAttributes( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.HaveAnyAttributes( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveAnyAttributes(Attributes().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction HaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.HaveAnyAttributes( + patterns, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction HaveAnyAttributes( Attribute firstAttribute, params Attribute[] moreAttributes @@ -231,6 +374,40 @@ public TRuleTypeShouldConjunction HaveAnyAttributes(IEnumerable attributes return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyHaveAttributes(Attributes().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction OnlyHaveAttributes( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.OnlyHaveAttributes( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyHaveAttributes(Attributes().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction OnlyHaveAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.OnlyHaveAttributes( + patterns, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction OnlyHaveAttributes( Attribute firstAttribute, params Attribute[] moreAttributes @@ -307,6 +484,42 @@ params object[] moreArgumentValues return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TRuleTypeShouldConjunction HaveAttributeWithArguments( + string attribute, + IEnumerable argumentValues + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.HaveAttributeWithArguments( + attribute, + argumentValues + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TRuleTypeShouldConjunction HaveAttributeWithArguments( + string attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.HaveAttributeWithArguments( + attribute, + firstArgumentValue, + moreArgumentValues + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction HaveAttributeWithArguments( Attribute attribute, IEnumerable argumentValues @@ -393,6 +606,42 @@ public TRuleTypeShouldConjunction HaveAnyAttributesWithNamedArguments( return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( + string attribute, + IEnumerable<(string, object)> attributeArguments + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.HaveAttributeWithNamedArguments( + attribute, + attributeArguments + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( + string attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.HaveAttributeWithNamedArguments( + attribute, + firstAttributeArgument, + moreAttributeArguments + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -453,6 +702,17 @@ public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( return Create(_ruleCreator); } + [Obsolete( + "Either HaveName() without the useRegularExpressions parameter or HaveNameMatching() should be used" + )] + public TRuleTypeShouldConjunction HaveName(string pattern, bool useRegularExpressions) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.HaveName(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction HaveName(string name) { _ruleCreator.AddCondition(ObjectConditionsDefinition.HaveName(name)); @@ -467,6 +727,17 @@ public TRuleTypeShouldConjunction HaveNameMatching(string pattern) return Create(_ruleCreator); } + [Obsolete( + "Either HaveFullName() without the useRegularExpressions parameter or HaveFullNameMatching() should be used" + )] + public TRuleTypeShouldConjunction HaveFullName(string pattern, bool useRegularExpressions) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.HaveFullName(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction HaveFullName(string fullName) { _ruleCreator.AddCondition(ObjectConditionsDefinition.HaveFullName(fullName)); @@ -619,6 +890,31 @@ public TRuleTypeShouldConjunction NotExist() return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotBe(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction NotBe(string pattern, bool useRegularExpressions = false) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotBe(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotBe(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction NotBe( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotBe(patterns, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction NotBe( ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects @@ -642,6 +938,34 @@ public TRuleTypeShouldConjunction NotBe(IObjectProvider objects) return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotCallAny(MethodMembers().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction NotCallAny( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotCallAny(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotCallAny(MethodMembers().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction NotCallAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotCallAny(patterns, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction NotCallAny( MethodMember method, params MethodMember[] moreMethods @@ -665,6 +989,37 @@ public TRuleTypeShouldConjunction NotCallAny(IObjectProvider metho return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotDependOnAny(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction NotDependOnAny( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotDependOnAny(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotDependOnAny(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction NotDependOnAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotDependOnAny( + patterns, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction NotDependOnAny(IType firstType, params IType[] moreTypes) { _ruleCreator.AddCondition( @@ -699,6 +1054,40 @@ public TRuleTypeShouldConjunction NotDependOnAny(IEnumerable types) return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotHaveAnyAttributes(Attributes().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction NotHaveAnyAttributes( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotHaveAnyAttributes( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotHaveAnyAttributes(Attributes().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction NotHaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotHaveAnyAttributes( + patterns, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction NotHaveAnyAttributes( Attribute firstAttribute, params Attribute[] moreAttributes @@ -779,6 +1168,42 @@ params object[] moreArgumentValues return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TRuleTypeShouldConjunction NotHaveAttributeWithArguments( + string attribute, + IEnumerable argumentValues + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotHaveAttributeWithArguments( + attribute, + argumentValues + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TRuleTypeShouldConjunction NotHaveAttributeWithArguments( + string attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotHaveAttributeWithArguments( + attribute, + firstArgumentValue, + moreArgumentValues + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction NotHaveAttributeWithArguments( Attribute attribute, IEnumerable argumentValues @@ -865,6 +1290,42 @@ public TRuleTypeShouldConjunction NotHaveAnyAttributesWithNamedArguments( return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TRuleTypeShouldConjunction NotHaveAttributeWithNamedArguments( + string attribute, + IEnumerable<(string, object)> attributeArguments + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotHaveAttributeWithNamedArguments( + attribute, + attributeArguments + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TRuleTypeShouldConjunction NotHaveAttributeWithNamedArguments( + string attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotHaveAttributeWithNamedArguments( + attribute, + firstAttributeArgument, + moreAttributeArguments + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction NotHaveAttributeWithNamedArguments( Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -925,6 +1386,17 @@ public TRuleTypeShouldConjunction NotHaveAttributeWithNamedArguments( return Create(_ruleCreator); } + [Obsolete( + "Either NotHaveName() without the useRegularExpressions parameter or NotHaveNameMatching() should be used" + )] + public TRuleTypeShouldConjunction NotHaveName(string pattern, bool useRegularExpressions) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotHaveName(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction NotHaveName(string name) { _ruleCreator.AddCondition(ObjectConditionsDefinition.NotHaveName(name)); @@ -939,6 +1411,23 @@ public TRuleTypeShouldConjunction NotHaveNameMatching(string pattern) return Create(_ruleCreator); } + [Obsolete( + "Either NotHaveFullName() without the useRegularExpressions parameter or NotHaveFullNameMatching() should be used" + )] + public TRuleTypeShouldConjunction NotHaveFullName( + string pattern, + bool useRegularExpressions + ) + { + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotHaveFullName( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction NotHaveFullName(string fullName) { _ruleCreator.AddCondition( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/ShouldRelateToObjectsThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/ShouldRelateToObjectsThat.cs index 4db158be5..65f464cc9 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/ShouldRelateToObjectsThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/ShouldRelateToObjectsThat.cs @@ -22,6 +22,31 @@ public class ShouldRelateToObjectsThat ruleCreator) : base(ruleCreator) { } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use Are(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction Are(string pattern, bool useRegularExpressions = false) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.Are(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use Are(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction Are( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.Are(patterns, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction Are( ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects @@ -49,6 +74,34 @@ public TRuleTypeShouldConjunction Are(IObjectProvider objects) return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use CallAny(MethodMembers().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction CallAny( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.CallAny(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use CallAny(MethodMembers().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction CallAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.CallAny(patterns, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction CallAny( MethodMember method, params MethodMember[] moreMethods @@ -76,6 +129,40 @@ public TRuleTypeShouldConjunction CallAny(IObjectProvider methods) return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DependOnAny(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction DependOnAny( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.DependOnAny( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DependOnAny(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction DependOnAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.DependOnAny( + patterns, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction DependOnAny(Type firstType, params Type[] moreTypes) { _ruleCreator.ContinueComplexCondition( @@ -138,6 +225,40 @@ string description return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyDependOn(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction OnlyDependOn( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.OnlyDependOn( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyDependOn(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction OnlyDependOn( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.OnlyDependOn( + patterns, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction OnlyDependOn(Type firstType, params Type[] moreTypes) { _ruleCreator.ContinueComplexCondition( @@ -178,6 +299,40 @@ public TRuleTypeShouldConjunction OnlyDependOn(IEnumerable types) return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveAnyAttributes(Attributes().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction HaveAnyAttributes( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.HaveAnyAttributes( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use HaveAnyAttributes(Attributes().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction HaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.HaveAnyAttributes( + patterns, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction HaveAnyAttributes( Type firstAttribute, params Type[] moreAttributes @@ -230,6 +385,40 @@ public TRuleTypeShouldConjunction HaveAnyAttributes(IEnumerable attributes return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyHaveAttributes(Attributes().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction OnlyHaveAttributes( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.OnlyHaveAttributes( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use OnlyHaveAttributes(Attributes().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction OnlyHaveAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.OnlyHaveAttributes( + patterns, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction OnlyHaveAttributes( Type firstAttribute, params Type[] moreAttributes @@ -308,6 +497,42 @@ params object[] moreArgumentValues return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TRuleTypeShouldConjunction HaveAttributeWithArguments( + string attribute, + IEnumerable argumentValues + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.HaveAttributeWithArguments( + attribute, + argumentValues + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TRuleTypeShouldConjunction HaveAttributeWithArguments( + string attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.HaveAttributeWithArguments( + attribute, + firstArgumentValue, + moreArgumentValues + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction HaveAttributeWithArguments( Attribute attribute, IEnumerable argumentValues @@ -394,6 +619,42 @@ public TRuleTypeShouldConjunction HaveAnyAttributesWithNamedArguments( return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( + string attribute, + IEnumerable<(string, object)> attributeArguments + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.HaveAttributeWithNamedArguments( + attribute, + attributeArguments + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( + string attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.HaveAttributeWithNamedArguments( + attribute, + firstAttributeArgument, + moreAttributeArguments + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -454,6 +715,17 @@ public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( return Create(_ruleCreator); } + [Obsolete( + "Either HaveName() without the useRegularExpressions parameter or HaveNameMatching() should be used" + )] + public TRuleTypeShouldConjunction HaveName(string pattern, bool useRegularExpressions) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.HaveName(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction HaveName(string name) { _ruleCreator.ContinueComplexCondition( @@ -470,6 +742,20 @@ public TRuleTypeShouldConjunction HaveNameMatching(string pattern) return Create(_ruleCreator); } + [Obsolete( + "Either HaveFullName() without the useRegularExpressions parameter or HaveFullNameMatching() should be used" + )] + public TRuleTypeShouldConjunction HaveFullName(string pattern, bool useRegularExpressions) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.HaveFullName( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction HaveFullName(string fullName) { _ruleCreator.ContinueComplexCondition( @@ -568,6 +854,31 @@ public TRuleTypeShouldConjunction ArePrivateProtected() //Negations + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNot(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction AreNot(string pattern, bool useRegularExpressions = false) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.AreNot(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNot(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction AreNot( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.AreNot(patterns, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction AreNot( ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects @@ -595,6 +906,40 @@ public TRuleTypeShouldConjunction AreNot(IObjectProvider objects return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotCallAny(MethodMembers().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction DoNotCallAny( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.DoNotCallAny( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotCallAny(MethodMembers().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction DoNotCallAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.DoNotCallAny( + patterns, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction DoNotCallAny( MethodMember method, params MethodMember[] moreMethods @@ -622,6 +967,40 @@ public TRuleTypeShouldConjunction DoNotCallAny(IObjectProvider met return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotDependOnAny(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction DoNotDependOnAny( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.DoNotDependOnAny( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotDependOnAny(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction DoNotDependOnAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.DoNotDependOnAny( + patterns, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction DoNotDependOnAny(Type firstType, params Type[] moreTypes) { _ruleCreator.ContinueComplexCondition( @@ -665,6 +1044,40 @@ public TRuleTypeShouldConjunction DoNotDependOnAny(IEnumerable types) return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotHaveAnyAttributes(Attributes().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction DoNotHaveAnyAttributes( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.DoNotHaveAnyAttributes( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use DoNotHaveAnyAttributes(Attributes().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction DoNotHaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.DoNotHaveAnyAttributes( + patterns, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction DoNotHaveAnyAttributes( Type firstAttribute, params Type[] moreAttributes @@ -831,6 +1244,78 @@ public TRuleTypeShouldConjunction DoNotHaveAnyAttributesWithNamedArguments( return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TRuleTypeShouldConjunction DoNotHaveAttributeWithArguments( + string attribute, + IEnumerable argumentValues + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments( + attribute, + argumentValues + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TRuleTypeShouldConjunction DoNotHaveAttributeWithArguments( + string attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments( + attribute, + firstArgumentValue, + moreArgumentValues + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TRuleTypeShouldConjunction DoNotHaveAttributeWithNamedArguments( + string attribute, + IEnumerable<(string, object)> attributeArguments + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments( + attribute, + attributeArguments + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TRuleTypeShouldConjunction DoNotHaveAttributeWithNamedArguments( + string attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments( + attribute, + firstAttributeArgument, + moreAttributeArguments + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction DoNotHaveAttributeWithNamedArguments( Attribute attribute, IEnumerable<(string, object)> attributeArguments @@ -891,6 +1376,20 @@ public TRuleTypeShouldConjunction DoNotHaveAttributeWithNamedArguments( return Create(_ruleCreator); } + [Obsolete( + "Either DoNotHaveName() without the useRegularExpressions parameter or DoNotHaveNameMatching() should be used" + )] + public TRuleTypeShouldConjunction DoNotHaveName(string pattern, bool useRegularExpressions) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.DoNotHaveName( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction DoNotHaveName(string name) { _ruleCreator.ContinueComplexCondition( @@ -907,6 +1406,23 @@ public TRuleTypeShouldConjunction DoNotHaveNameMatching(string pattern) return Create(_ruleCreator); } + [Obsolete( + "Either DoNotHaveFullName() without the useRegularExpressions parameter or DoNotHaveFullNameMatching() should be used" + )] + public TRuleTypeShouldConjunction DoNotHaveFullName( + string pattern, + bool useRegularExpressions + ) + { + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.DoNotHaveFullName( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction DoNotHaveFullName(string fullName) { _ruleCreator.ContinueComplexCondition( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesThat.cs index c7a592f4d..e945f3b55 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesThat.cs @@ -35,6 +35,34 @@ public TGivenRuleTypeConjunction Are(IEnumerable types) return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreAssignableTo(Types().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction AreAssignableTo( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + TypePredicatesDefinition.AreAssignableTo(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreAssignableTo(Types().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction AreAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + TypePredicatesDefinition.AreAssignableTo(patterns, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction AreAssignableTo(IType firstType, params IType[] moreTypes) { _ruleCreator.AddPredicate( @@ -121,6 +149,23 @@ public TGivenRuleTypeConjunction AreStructs() return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TGivenRuleTypeConjunction ImplementInterface( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + TypePredicatesDefinition.ImplementInterface( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction ImplementInterface(Interface intf) { _ruleCreator.AddPredicate(TypePredicatesDefinition.ImplementInterface(intf)); @@ -133,6 +178,23 @@ public TGivenRuleTypeConjunction ImplementInterface(Type intf) return Create(_ruleCreator); } + [Obsolete( + "Either ResideInNamespace() without the useRegularExpressions parameter or ResideInNamespaceMatching() should be used" + )] + public TGivenRuleTypeConjunction ResideInNamespace( + string pattern, + bool useRegularExpressions + ) + { + _ruleCreator.AddPredicate( + TypePredicatesDefinition.ResideInNamespace( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction ResideInNamespace(string fullName) { _ruleCreator.AddPredicate( @@ -149,6 +211,20 @@ public TGivenRuleTypeConjunction ResideInNamespaceMatching(string pattern) return Create(_ruleCreator); } + [Obsolete( + "Either ResideInAssembly() without the useRegularExpressions parameter or ResideInAssemblyMatching() should be used" + )] + public TGivenRuleTypeConjunction ResideInAssembly( + string pattern, + bool useRegularExpressions + ) + { + _ruleCreator.AddPredicate( + TypePredicatesDefinition.ResideInAssembly(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction ResideInAssembly(string fullName) { _ruleCreator.AddPredicate( @@ -240,6 +316,40 @@ public TGivenRuleTypeConjunction AreNot(IEnumerable types) return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNotAssignableTo(Types().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction AreNotAssignableTo( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + TypePredicatesDefinition.AreNotAssignableTo( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNotAssignableTo(Types().That().HaveFullName()) instead" + )] + public TGivenRuleTypeConjunction AreNotAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + TypePredicatesDefinition.AreNotAssignableTo( + patterns, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction AreNotAssignableTo( IType firstType, params IType[] moreTypes @@ -301,6 +411,23 @@ public TGivenRuleTypeConjunction AreNotStructs() return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TGivenRuleTypeConjunction DoNotImplementInterface( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddPredicate( + TypePredicatesDefinition.DoNotImplementInterface( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction DoNotImplementInterface(Interface intf) { _ruleCreator.AddPredicate( @@ -317,6 +444,23 @@ public TGivenRuleTypeConjunction DoNotImplementInterface(Type intf) return Create(_ruleCreator); } + [Obsolete( + "Either DoNotResideInNamespace() without the useRegularExpressions parameter or DoNotResideInNamespaceMatching() should be used" + )] + public TGivenRuleTypeConjunction DoNotResideInNamespace( + string pattern, + bool useRegularExpressions + ) + { + _ruleCreator.AddPredicate( + TypePredicatesDefinition.DoNotResideInNamespace( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction DoNotResideInNamespace(string fullName) { _ruleCreator.AddPredicate( @@ -333,6 +477,23 @@ public TGivenRuleTypeConjunction DoNotResideInNamespaceMatching(string pattern) return Create(_ruleCreator); } + [Obsolete( + "Either DoNotResideInAssembly() without the useRegularExpressions parameter or DoNotResideInAssemblyMatching() should be used" + )] + public TGivenRuleTypeConjunction DoNotResideInAssembly( + string pattern, + bool useRegularExpressions + ) + { + _ruleCreator.AddPredicate( + TypePredicatesDefinition.DoNotResideInAssembly( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TGivenRuleTypeConjunction DoNotResideInAssembly(string fullName) { _ruleCreator.AddPredicate( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypeConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypeConditions.cs index 840e9160b..a3f9cbd9b 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypeConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypeConditions.cs @@ -17,6 +17,19 @@ public interface ITypeConditions { TReturnType Be(Type firstType, params Type[] moreTypes); TReturnType Be(IEnumerable types); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use BeAssignableTo(Types().That().HaveFullName()) instead" + )] + TReturnType BeAssignableTo(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use BeAssignableTo(Types().That().HaveFullName()) instead" + )] + TReturnType BeAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType BeAssignableTo(IType firstType, params IType[] moreTypes); TReturnType BeAssignableTo(Type type, params Type[] moreTypes); TReturnType BeAssignableTo(IObjectProvider types); @@ -25,10 +38,25 @@ public interface ITypeConditions TReturnType BeValueTypes(); TReturnType BeEnums(); TReturnType BeStructs(); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + TReturnType ImplementInterface(string pattern, bool useRegularExpressions = false); TReturnType ImplementInterface(Interface intf); TReturnType ImplementInterface(Type intf); + + [Obsolete( + "Either ResideInNamespace() without the useRegularExpressions parameter or ResideInNamespaceMatching() should be used" + )] + TReturnType ResideInNamespace(string pattern, bool useRegularExpressions); TReturnType ResideInNamespace(string fullName); TReturnType ResideInNamespaceMatching(string pattern); + + [Obsolete( + "Either ResideInAssembly() without the useRegularExpressions parameter or ResideInAssemblyMatching() should be used" + )] + TReturnType ResideInAssembly(string pattern, bool useRegularExpressions); TReturnType ResideInAssembly(string fullName); TReturnType ResideInAssemblyMatching(string pattern); TReturnType ResideInAssembly(Assembly assembly, params Assembly[] moreAssemblies); @@ -47,6 +75,19 @@ params Domain.Assembly[] moreAssemblies TReturnType NotBe(Type firstType, params Type[] moreTypes); TReturnType NotBe(IEnumerable types); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotBeAssignableTo(Types().That().HaveFullName()) instead" + )] + TReturnType NotBeAssignableTo(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotBeAssignableTo(Types().That().HaveFullName()) instead" + )] + TReturnType NotBeAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType NotBeAssignableTo(IType type, params IType[] moreTypes); TReturnType NotBeAssignableTo(Type type, params Type[] moreTypes); TReturnType NotBeAssignableTo(IObjectProvider types); @@ -55,12 +96,27 @@ params Domain.Assembly[] moreAssemblies TReturnType NotBeValueTypes(); TReturnType NotBeEnums(); TReturnType NotBeStructs(); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + TReturnType NotImplementInterface(string pattern, bool useRegularExpressions = false); TReturnType NotImplementInterface(Interface intf); TReturnType NotImplementInterface(Type intf); + + [Obsolete( + "Either NotResideInNamespace() without the useRegularExpressions parameter or NotResideInNamespaceMatching() should be used" + )] + TReturnType NotResideInNamespace(string pattern, bool useRegularExpressions); TReturnType NotResideInNamespace(string fullName); TReturnType NotResideInNamespaceMatching(string pattern); + + [Obsolete( + "Either NotResideInAssembly() without the useRegularExpressions parameter or NotResideInAssemblyMatching() should be used" + )] TReturnType NotResideInAssembly(string fullName); TReturnType NotResideInAssemblyMatching(string pattern); + TReturnType NotResideInAssembly(string pattern, bool useRegularExpressions); TReturnType NotResideInAssembly(Assembly assembly, params Assembly[] moreAssemblies); TReturnType NotResideInAssembly( Domain.Assembly assembly, diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypePredicates.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypePredicates.cs index 6eed12213..1633b74fe 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypePredicates.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypePredicates.cs @@ -17,6 +17,19 @@ public interface ITypePredicates { TReturnType Are(Type firstType, params Type[] moreTypes); TReturnType Are(IEnumerable types); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreAssignableTo(Types().That().HaveFullName()) instead" + )] + TReturnType AreAssignableTo(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreAssignableTo(Types().That().HaveFullName()) instead" + )] + TReturnType AreAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType AreAssignableTo(IType firstType, params IType[] moreTypes); TReturnType AreAssignableTo(Type type, params Type[] moreTypes); TReturnType AreAssignableTo(IObjectProvider types); @@ -25,10 +38,25 @@ public interface ITypePredicates TReturnType AreValueTypes(); TReturnType AreEnums(); TReturnType AreStructs(); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + TReturnType ImplementInterface(string pattern, bool useRegularExpressions = false); TReturnType ImplementInterface(Interface intf); TReturnType ImplementInterface(Type intf); + + [Obsolete( + "Either ResideInNamespace() without the useRegularExpressions parameter or ResideInNamespaceMatching() should be used" + )] + TReturnType ResideInNamespace(string pattern, bool useRegularExpressions); TReturnType ResideInNamespace(string fullName); TReturnType ResideInNamespaceMatching(string pattern); + + [Obsolete( + "Either ResideInAssembly() without the useRegularExpressions parameter or ResideInAssemblyMatching() should be used" + )] + TReturnType ResideInAssembly(string pattern, bool useRegularExpressions); TReturnType ResideInAssembly(string fullName); TReturnType ResideInAssemblyMatching(string pattern); TReturnType ResideInAssembly(Assembly assembly, params Assembly[] moreAssemblies); @@ -47,6 +75,19 @@ params Domain.Assembly[] moreAssemblies TReturnType AreNot(Type firstType, params Type[] moreTypes); TReturnType AreNot(IEnumerable types); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNotAssignableTo(Types().That().HaveFullName()) instead" + )] + TReturnType AreNotAssignableTo(string pattern, bool useRegularExpressions = false); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNotAssignableTo(Types().That().HaveFullName()) instead" + )] + TReturnType AreNotAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType AreNotAssignableTo(IType type, params IType[] moreTypes); TReturnType AreNotAssignableTo(Type type, params Type[] moreTypes); TReturnType AreNotAssignableTo(IObjectProvider types); @@ -55,10 +96,24 @@ params Domain.Assembly[] moreAssemblies TReturnType AreNotValueTypes(); TReturnType AreNotEnums(); TReturnType AreNotStructs(); + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + TReturnType DoNotImplementInterface(string pattern, bool useRegularExpressions = false); TReturnType DoNotImplementInterface(Interface intf); TReturnType DoNotImplementInterface(Type intf); + + [Obsolete( + "Either DoNotResideInNamespace() without the useRegularExpressions parameter or DoNotResideInNamespaceMatching() should be used" + )] + TReturnType DoNotResideInNamespace(string pattern, bool useRegularExpressions); TReturnType DoNotResideInNamespace(string fullName); - TReturnType DoNotResideInNamespaceMatching(string pattern); + + [Obsolete( + "Either DoNotResideInAssembly() without the useRegularExpressions parameter or DoNotResideInAssemblyMatching() should be used" + )] + TReturnType DoNotResideInAssembly(string pattern, bool useRegularExpressions); TReturnType DoNotResideInAssembly(string fullName); TReturnType DoNotResideInAssemblyMatching(string pattern); TReturnType DoNotResideInAssembly(Assembly assembly, params Assembly[] moreAssemblies); diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/ShouldRelateToTypesThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/ShouldRelateToTypesThat.cs index 786fa8800..9cddd1613 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/ShouldRelateToTypesThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/ShouldRelateToTypesThat.cs @@ -38,6 +38,40 @@ public TRuleTypeShouldConjunction Are(IEnumerable types) return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreAssignableTo(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction AreAssignableTo( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.AreAssignableTo( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreAssignableTo(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction AreAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.AreAssignableTo( + patterns, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction AreAssignableTo(IType firstType, params IType[] moreTypes) { _ruleCreator.ContinueComplexCondition( @@ -142,6 +176,23 @@ public TRuleTypeShouldConjunction AreStructs() return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TRuleTypeShouldConjunction ImplementInterface( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.ImplementInterface( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction ImplementInterface(Interface intf) { _ruleCreator.ContinueComplexCondition( @@ -158,6 +209,23 @@ public TRuleTypeShouldConjunction ImplementInterface(Type intf) return Create(_ruleCreator); } + [Obsolete( + "Either ResideInNamespace() without the useRegularExpressions parameter or ResideInNamespaceMatching() should be used" + )] + public TRuleTypeShouldConjunction ResideInNamespace( + string pattern, + bool useRegularExpressions + ) + { + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.ResideInNamespace( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction ResideInNamespace(string fullName) { _ruleCreator.ContinueComplexCondition( @@ -174,6 +242,23 @@ public TRuleTypeShouldConjunction ResideInNamespaceMatching(string pattern) return Create(_ruleCreator); } + [Obsolete( + "Either ResideInAssembly() without the useRegularExpressions parameter or ResideInAssemblyMatching() should be used" + )] + public TRuleTypeShouldConjunction ResideInAssembly( + string pattern, + bool useRegularExpressions + ) + { + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.ResideInAssembly( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction ResideInAssembly(string fullName) { _ruleCreator.ContinueComplexCondition( @@ -271,6 +356,40 @@ public TRuleTypeShouldConjunction AreNot(IEnumerable types) return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNotAssignableTo(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction AreNotAssignableTo( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.AreNotAssignableTo( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNotAssignableTo(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction AreNotAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.AreNotAssignableTo( + patterns, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction AreNotAssignableTo( IType firstType, params IType[] moreTypes @@ -341,6 +460,23 @@ public TRuleTypeShouldConjunction AreNotStructs() return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TRuleTypeShouldConjunction DoNotImplementInterface( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.DoNotImplementInterface( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction DoNotImplementInterface(Interface intf) { _ruleCreator.ContinueComplexCondition( @@ -357,6 +493,23 @@ public TRuleTypeShouldConjunction DoNotImplementInterface(Type intf) return Create(_ruleCreator); } + [Obsolete( + "Either DoNotResideInNamespace() without the useRegularExpressions parameter or DoNotResideInNamespaceMatching() should be used" + )] + public TRuleTypeShouldConjunction DoNotResideInNamespace( + string pattern, + bool useRegularExpressions + ) + { + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.DoNotResideInNamespace( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction DoNotResideInNamespace(string fullName) { _ruleCreator.ContinueComplexCondition( @@ -373,6 +526,23 @@ public TRuleTypeShouldConjunction DoNotResideInNamespaceMatching(string pattern) return Create(_ruleCreator); } + [Obsolete( + "Either DoNotResideInAssembly() without the useRegularExpressions parameter or DoNotResideInAssemblyMatching() should be used" + )] + public TRuleTypeShouldConjunction DoNotResideInAssembly( + string pattern, + bool useRegularExpressions + ) + { + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.DoNotResideInAssembly( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction DoNotResideInAssembly(string fullName) { _ruleCreator.ContinueComplexCondition( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypeConditionsDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypeConditionsDefinition.cs index 2f9fb3e0f..15c6a3356 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypeConditionsDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypeConditionsDefinition.cs @@ -90,6 +90,87 @@ Architecture architecture return new ArchitectureCondition(Condition, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use BeAssignableTo(Types().That().HaveFullName()) instead" + )] + public static ICondition BeAssignableTo( + string pattern, + bool useRegularExpressions = false + ) + { + var description = + "be assignable to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\""; + var failDescription = + "is not assignable to a type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\""; + return new SimpleCondition( + type => type.IsAssignableTo(pattern, useRegularExpressions), + description, + failDescription + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use BeAssignableTo(Types().That().HaveFullName()) instead" + )] + public static ICondition BeAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Condition(TRuleType ruleType) + { + return patternList.Any(pattern => + ruleType.IsAssignableTo(pattern, useRegularExpressions) + ); + } + + string description; + string failDescription; + if (patternList.IsNullOrEmpty()) + { + description = "be assignable to no types (always false)"; + failDescription = "is assignable to any type (always true)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "be assignable to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + failDescription = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "is not assignable to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimpleCondition(Condition, description, failDescription); + } + public static ICondition BeAssignableTo( IType firstType, params IType[] moreTypes @@ -460,6 +541,29 @@ public static ICondition BeStructs() ); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public static ICondition ImplementInterface( + string pattern, + bool useRegularExpressions = false + ) + { + return new SimpleCondition( + type => type.ImplementsInterface(pattern, useRegularExpressions), + "implement interface with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"", + "does not implement interface with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + public static ICondition ImplementInterface(Interface intf) { return new SimpleCondition( @@ -528,6 +632,25 @@ Architecture architecture ); } + [Obsolete( + "Either ResideInNamespace() without the useRegularExpressions parameter or ResideInNamespaceMatching() should be used" + )] + public static ICondition ResideInNamespace( + string pattern, + bool useRegularExpressions + ) + { + return new SimpleCondition( + type => type.ResidesInNamespace(pattern, useRegularExpressions), + obj => "does reside in " + obj.Namespace.FullName, + "reside in namespace with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + public static ICondition ResideInNamespace(string fullName) { return new SimpleCondition( @@ -546,6 +669,25 @@ public static ICondition ResideInNamespaceMatching(string pattern) ); } + [Obsolete( + "Either ResideInAssembly() without the useRegularExpressions parameter or ResideInAssemblyMatching() should be used" + )] + public static ICondition ResideInAssembly( + string pattern, + bool useRegularExpressions + ) + { + return new SimpleCondition( + type => type.ResidesInAssembly(pattern, useRegularExpressions), + obj => "does reside in " + obj.Assembly.FullName, + "reside in assembly with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + public static ICondition ResideInAssembly(string fullName) { return new SimpleCondition( @@ -803,6 +945,93 @@ Architecture architecture return new ArchitectureCondition(Condition, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotBeAssignableTo(Types().That().HaveFullName()) instead" + )] + public static ICondition NotBeAssignableTo( + string pattern, + bool useRegularExpressions = false + ) + { + ConditionResult Condition(TRuleType ruleType) + { + var pass = true; + var dynamicFailDescription = "is assignable to"; + foreach (var type in ruleType.GetAssignableTypes()) + { + if (type.FullNameMatches(pattern, useRegularExpressions)) + { + dynamicFailDescription += (pass ? " " : " and ") + type.FullName; + pass = false; + } + } + + return new ConditionResult(ruleType, pass, dynamicFailDescription); + } + + var description = + "not be assignable to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\""; + return new SimpleCondition(Condition, description); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotBeAssignableTo(Types().That().HaveFullName()) instead" + )] + public static ICondition NotBeAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + ConditionResult Condition(TRuleType ruleType) + { + var pass = true; + var dynamicFailDescription = "is assignable to"; + foreach (var type in ruleType.GetAssignableTypes()) + { + if ( + patternList.Any(pattern => + type.FullNameMatches(pattern, useRegularExpressions) + ) + ) + { + dynamicFailDescription += (pass ? " " : " and ") + type.FullName; + pass = false; + } + } + + return new ConditionResult(ruleType, pass, dynamicFailDescription); + } + + string description; + if (patternList.IsNullOrEmpty()) + { + description = "not be assignable to no types (always true)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "not be assignable to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimpleCondition(Condition, description); + } + public static ICondition NotBeAssignableTo( IType firstType, params IType[] moreTypes @@ -1041,6 +1270,29 @@ public static ICondition NotBeStructs() ); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public static ICondition NotImplementInterface( + string pattern, + bool useRegularExpressions = false + ) + { + return new SimpleCondition( + type => !type.ImplementsInterface(pattern, useRegularExpressions), + "not implement interface with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"", + "does implement interface with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + public static ICondition NotImplementInterface(Interface intf) { return new SimpleCondition( @@ -1105,6 +1357,25 @@ Architecture architecture ); } + [Obsolete( + "Either NotResideInNamespace() without the useRegularExpressions parameter or NotResideInNamespaceMatching() should be used" + )] + public static ICondition NotResideInNamespace( + string pattern, + bool useRegularExpressions + ) + { + return new SimpleCondition( + type => !type.ResidesInNamespace(pattern, useRegularExpressions), + obj => "does reside in " + obj.Namespace.FullName, + "not reside in namespace with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + public static ICondition NotResideInNamespace(string fullName) { return new SimpleCondition( @@ -1123,6 +1394,25 @@ public static ICondition NotResideInNamespaceMatching(string pattern) ); } + [Obsolete( + "Either NotResideInAssembly() without the useRegularExpressions parameter or NotResideInAssemblyMatching() should be used" + )] + public static ICondition NotResideInAssembly( + string pattern, + bool useRegularExpressions + ) + { + return new SimpleCondition( + type => !type.ResidesInAssembly(pattern, useRegularExpressions), + obj => "does reside in " + obj.Assembly.FullName, + "not reside in assembly with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + public static ICondition NotResideInAssembly(string fullName) { return new SimpleCondition( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypePredicatesDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypePredicatesDefinition.cs index 2beff1e71..e0e5d9d55 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypePredicatesDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypePredicatesDefinition.cs @@ -69,6 +69,67 @@ IEnumerable Filter(IEnumerable ruleTypes, Architecture architecture) return new ArchitecturePredicate(Filter, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreAssignableTo(Types().That().HaveFullName()) instead" + )] + public static IPredicate AreAssignableTo( + string pattern, + bool useRegularExpressions = false + ) + { + var description = + "are assignable to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\""; + return new SimplePredicate( + type => type.IsAssignableTo(pattern, useRegularExpressions), + description + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreAssignableTo(Types().That().HaveFullName()) instead" + )] + public static IPredicate AreAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Condition(T ruleType) + { + return patternList.Any(pattern => + ruleType.IsAssignableTo(pattern, useRegularExpressions) + ); + } + + string description; + if (patternList.IsNullOrEmpty()) + { + description = "are assignable to no types (always false)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "are assignable to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimplePredicate(Condition, description); + } + public static IPredicate AreAssignableTo(IType firstType, params IType[] moreTypes) { IEnumerable Condition(IEnumerable ruleTypes) @@ -315,6 +376,24 @@ public static IPredicate AreStructs() return new SimplePredicate(type => type is Struct, "are structs"); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public static IPredicate ImplementInterface( + string pattern, + bool useRegularExpressions = false + ) + { + return new SimplePredicate( + type => type.ImplementsInterface(pattern, useRegularExpressions), + "implement interface with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + public static IPredicate ImplementInterface(Interface intf) { return new SimplePredicate( @@ -347,6 +426,21 @@ IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) ); } + [Obsolete( + "Either ResideInNamespace() without the useRegularExpressions parameter or ResideInNamespaceMatching() should be used" + )] + public static IPredicate ResideInNamespace(string pattern, bool useRegularExpressions) + { + return new SimplePredicate( + type => type.ResidesInNamespace(pattern, useRegularExpressions), + "reside in namespace with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + public static IPredicate ResideInNamespace(string fullName) { return new SimplePredicate( @@ -363,6 +457,21 @@ public static IPredicate ResideInNamespaceMatching(string pattern) ); } + [Obsolete( + "Either ResideInAssembly() without the useRegularExpressions parameter or ResideInAssemblyMatching() should be used" + )] + public static IPredicate ResideInAssembly(string pattern, bool useRegularExpressions) + { + return new SimplePredicate( + type => type.ResidesInAssembly(pattern, useRegularExpressions), + "reside in assembly with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + public static IPredicate ResideInAssembly(string fullName) { return new SimplePredicate( @@ -507,6 +616,67 @@ IEnumerable Filter(IEnumerable ruleTypes, Architecture architecture) return new ArchitecturePredicate(Filter, description); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNotAssignableTo(Types().That().HaveFullName()) instead" + )] + public static IPredicate AreNotAssignableTo( + string pattern, + bool useRegularExpressions = false + ) + { + var description = + "are not assignable to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\""; + return new SimplePredicate( + type => !type.IsAssignableTo(pattern, useRegularExpressions), + description + ); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use AreNotAssignableTo(Types().That().HaveFullName()) instead" + )] + public static IPredicate AreNotAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + var patternList = patterns.ToList(); + + bool Condition(T ruleType) + { + return patternList.All(pattern => + !ruleType.IsAssignableTo(pattern, useRegularExpressions) + ); + } + + string description; + if (patternList.IsNullOrEmpty()) + { + description = "are not assignable to no types (always true)"; + } + else + { + var firstPattern = patternList.First(); + description = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "are not assignable to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + } + + return new SimplePredicate(Condition, description); + } + public static IPredicate AreNotAssignableTo(IType firstType, params IType[] moreTypes) { IEnumerable Condition(IEnumerable ruleTypes) @@ -645,6 +815,24 @@ public static IPredicate AreNotStructs() return new SimplePredicate(cls => !(cls is Struct), "are not structs"); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public static IPredicate DoNotImplementInterface( + string pattern, + bool useRegularExpressions = false + ) + { + return new SimplePredicate( + type => !type.ImplementsInterface(pattern, useRegularExpressions), + "do not implement interface with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + public static IPredicate DoNotImplementInterface(Interface intf) { return new SimplePredicate( @@ -677,6 +865,24 @@ IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) ); } + [Obsolete( + "Either DoNotResideInNamespace() without the useRegularExpressions parameter or DoNotResideInNamespaceMatching() should be used" + )] + public static IPredicate DoNotResideInNamespace( + string pattern, + bool useRegularExpressions + ) + { + return new SimplePredicate( + type => !type.ResidesInNamespace(pattern, useRegularExpressions), + "do not reside in namespace with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + public static IPredicate DoNotResideInNamespace(string fullName) { return new SimplePredicate( @@ -693,6 +899,24 @@ public static IPredicate DoNotResideInNamespaceMatching(string pattern) ); } + [Obsolete( + "Either DoNotResideInAssembly() without the useRegularExpressions parameter or DoNotResideInAssemblyMatching() should be used" + )] + public static IPredicate DoNotResideInAssembly( + string pattern, + bool useRegularExpressions + ) + { + return new SimplePredicate( + type => !type.ResidesInAssembly(pattern, useRegularExpressions), + "do not reside in assembly with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + public static IPredicate DoNotResideInAssembly(string fullName) { return new SimplePredicate( diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShould.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShould.cs index 3eaa17f83..ff8c379e3 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShould.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShould.cs @@ -35,6 +35,34 @@ public TRuleTypeShouldConjunction Be(IEnumerable types) return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use BeAssignableTo(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction BeAssignableTo( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + TypeConditionsDefinition.BeAssignableTo(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use BeAssignableTo(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction BeAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + TypeConditionsDefinition.BeAssignableTo(patterns, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction BeAssignableTo(IType firstType, params IType[] moreTypes) { _ruleCreator.AddCondition( @@ -121,6 +149,23 @@ public TRuleTypeShouldConjunction BeStructs() return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TRuleTypeShouldConjunction ImplementInterface( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + TypeConditionsDefinition.ImplementInterface( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction ImplementInterface(Interface intf) { _ruleCreator.AddCondition(TypeConditionsDefinition.ImplementInterface(intf)); @@ -133,6 +178,23 @@ public TRuleTypeShouldConjunction ImplementInterface(Type intf) return Create(_ruleCreator); } + [Obsolete( + "Either ResideInNamespace() without the useRegularExpressions parameter or ResideInNamespaceMatching() should be used" + )] + public TRuleTypeShouldConjunction ResideInNamespace( + string pattern, + bool useRegularExpressions + ) + { + _ruleCreator.AddCondition( + TypeConditionsDefinition.ResideInNamespace( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction ResideInNamespace(string fullName) { _ruleCreator.AddCondition( @@ -149,6 +211,20 @@ public TRuleTypeShouldConjunction ResideInNamespaceMatching(string pattern) return Create(_ruleCreator); } + [Obsolete( + "Either ResideInAssembly() without the useRegularExpressions parameter or ResideInAssemblyMatching() should be used" + )] + public TRuleTypeShouldConjunction ResideInAssembly( + string pattern, + bool useRegularExpressions + ) + { + _ruleCreator.AddCondition( + TypeConditionsDefinition.ResideInAssembly(pattern, useRegularExpressions) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction ResideInAssembly(string fullName) { _ruleCreator.AddCondition( @@ -257,6 +333,40 @@ public TRuleTypeShouldConjunction NotBe(IEnumerable types) return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotBeAssignableTo(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction NotBeAssignableTo( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + TypeConditionsDefinition.NotBeAssignableTo( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update. You can use NotBeAssignableTo(Types().That().HaveFullName()) instead" + )] + public TRuleTypeShouldConjunction NotBeAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + TypeConditionsDefinition.NotBeAssignableTo( + patterns, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction NotBeAssignableTo( IType firstType, params IType[] moreTypes @@ -312,6 +422,23 @@ public TRuleTypeShouldConjunction NotBeStructs() return Create(_ruleCreator); } + [Obsolete( + "Another overload of this method should be used. This will be removed in a future update." + )] + public TRuleTypeShouldConjunction NotImplementInterface( + string pattern, + bool useRegularExpressions = false + ) + { + _ruleCreator.AddCondition( + TypeConditionsDefinition.NotImplementInterface( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction NotImplementInterface(Interface intf) { _ruleCreator.AddCondition( @@ -328,6 +455,23 @@ public TRuleTypeShouldConjunction NotImplementInterface(Type intf) return Create(_ruleCreator); } + [Obsolete( + "Either NotResideInNamespace() without the useRegularExpressions parameter or NotResideInNamespaceMatching() should be used" + )] + public TRuleTypeShouldConjunction NotResideInNamespace( + string pattern, + bool useRegularExpressions + ) + { + _ruleCreator.AddCondition( + TypeConditionsDefinition.NotResideInNamespace( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction NotResideInNamespace(string fullName) { _ruleCreator.AddCondition( @@ -344,6 +488,23 @@ public TRuleTypeShouldConjunction NotResideInNamespaceMatching(string pattern) return Create(_ruleCreator); } + [Obsolete( + "Either NotResideInAssembly() without the useRegularExpressions parameter or NotResideInAssemblyMatching() should be used" + )] + public TRuleTypeShouldConjunction NotResideInAssembly( + string pattern, + bool useRegularExpressions + ) + { + _ruleCreator.AddCondition( + TypeConditionsDefinition.NotResideInAssembly( + pattern, + useRegularExpressions + ) + ); + return Create(_ruleCreator); + } + public TRuleTypeShouldConjunction NotResideInAssembly(string fullName) { _ruleCreator.AddCondition(