Skip to content

Commit

Permalink
Merge pull request #10 from brandhuf/feature/fluent
Browse files Browse the repository at this point in the history
Added support for different input parameters for ImplementInterface(), AreCalledBy() and HaveDependencyInMethodBodyTo()
  • Loading branch information
fgather authored Feb 16, 2020
2 parents 9c6cbdd + 8832dbb commit 7a565e8
Show file tree
Hide file tree
Showing 20 changed files with 1,895 additions and 6 deletions.
4 changes: 2 additions & 2 deletions ArchUnitNET/Core/Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Type(string fullname, string name, Assembly assembly, Namespace namespc,
.OfType<ImplementsInterfaceDependency>()
.Select(dependency => dependency.Target);

public bool ImplementsInterface(IType intf)
public bool ImplementsInterface(Interface intf)
{
return ImplementedInterfaces.Any(implementedInterface =>
Equals(implementedInterface, intf) || Equals(implementedInterface.GenericType, intf));
Expand Down Expand Up @@ -84,7 +84,7 @@ public bool IsAssignableTo(IType assignableToType)
return true;
}

return assignableToType is Interface && ImplementsInterface(assignableToType);
return assignableToType is Interface && ImplementsInterface((Interface) assignableToType);
}

public bool IsAssignableTo(string pattern, bool useRegularExpressions = false)
Expand Down
2 changes: 1 addition & 1 deletion ArchUnitNET/Domain/Class.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public bool? IsStruct
public IType GenericType => Type.GenericType;
public List<IType> GenericTypeArguments => Type.GenericTypeArguments;

public bool ImplementsInterface(IType intf)
public bool ImplementsInterface(Interface intf)
{
return Type.ImplementsInterface(intf);
}
Expand Down
2 changes: 1 addition & 1 deletion ArchUnitNET/Domain/IType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface IType : ICanBeAnalyzed
[CanBeNull] IType GenericType { get; }
bool IsNested { get; }
IEnumerable<IType> ImplementedInterfaces { get; }
bool ImplementsInterface(IType intf);
bool ImplementsInterface(Interface intf);
bool ImplementsInterface(string pattern, bool useRegularExpressions = false);
bool IsAssignableTo(IType assignableToType);
bool IsAssignableTo(string pattern, bool useRegularExpressions = false);
Expand Down
2 changes: 1 addition & 1 deletion ArchUnitNET/Domain/Interface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Interface(IType type)
public IType GenericType => Type.GenericType;
public List<IType> GenericTypeArguments => Type.GenericTypeArguments;

public bool ImplementsInterface(IType intf)
public bool ImplementsInterface(Interface intf)
{
return Type.ImplementsInterface(intf);
}
Expand Down
6 changes: 6 additions & 0 deletions ArchUnitNET/Fluent/Extensions/MemberExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public static bool IsCalledBy(this MethodMember member, string pattern, bool use
dependency.Origin.FullNameMatches(pattern, useRegularExpressions));
}

public static IEnumerable<IType> GetCallingTypes(this MethodMember member)
{
return member.MemberBackwardsDependencies.OfType<MethodCallDependency>()
.Select(dependency => dependency.Origin).Distinct();
}

public static bool HasDependencyInMethodBodyTo(this MethodMember member, string pattern,
bool useRegularExpressions = false)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//
// SPDX-License-Identifier: Apache-2.0

using System;
using System.Collections.Generic;
using ArchUnitNET.Domain;

namespace ArchUnitNET.Fluent.Syntax.Elements.Members.MethodMembers
Expand Down Expand Up @@ -33,6 +35,43 @@ public GivenMethodMembersConjunction AreCalledBy(string pattern, bool useRegular
return new GivenMethodMembersConjunction(_ruleCreator);
}

public GivenMethodMembersConjunction AreCalledBy(IEnumerable<string> patterns,
bool useRegularExpressions = false)
{
_ruleCreator.AddPredicate(MethodMemberPredicatesDefinition.AreCalledBy(patterns, useRegularExpressions));
return new GivenMethodMembersConjunction(_ruleCreator);
}

public GivenMethodMembersConjunction AreCalledBy(IType firstType, params IType[] moreTypes)
{
_ruleCreator.AddPredicate(MethodMemberPredicatesDefinition.AreCalledBy(firstType, moreTypes));
return new GivenMethodMembersConjunction(_ruleCreator);
}

public GivenMethodMembersConjunction AreCalledBy(Type type, params Type[] moreTypes)
{
_ruleCreator.AddPredicate(MethodMemberPredicatesDefinition.AreCalledBy(type, moreTypes));
return new GivenMethodMembersConjunction(_ruleCreator);
}

public GivenMethodMembersConjunction AreCalledBy(IObjectProvider<IType> types)
{
_ruleCreator.AddPredicate(MethodMemberPredicatesDefinition.AreCalledBy(types));
return new GivenMethodMembersConjunction(_ruleCreator);
}

public GivenMethodMembersConjunction AreCalledBy(IEnumerable<IType> types)
{
_ruleCreator.AddPredicate(MethodMemberPredicatesDefinition.AreCalledBy(types));
return new GivenMethodMembersConjunction(_ruleCreator);
}

public GivenMethodMembersConjunction AreCalledBy(IEnumerable<Type> types)
{
_ruleCreator.AddPredicate(MethodMemberPredicatesDefinition.AreCalledBy(types));
return new GivenMethodMembersConjunction(_ruleCreator);
}

public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo(string pattern,
bool useRegularExpressions = false)
{
Expand All @@ -41,6 +80,49 @@ public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo(string pattern
return new GivenMethodMembersConjunction(_ruleCreator);
}

public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo(IEnumerable<string> patterns,
bool useRegularExpressions = false)
{
_ruleCreator.AddPredicate(
MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(patterns, useRegularExpressions));
return new GivenMethodMembersConjunction(_ruleCreator);
}

public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo(IType firstType, params IType[] moreTypes)
{
_ruleCreator.AddPredicate(
MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(firstType, moreTypes));
return new GivenMethodMembersConjunction(_ruleCreator);
}

public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo(Type type, params Type[] moreTypes)
{
_ruleCreator.AddPredicate(
MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(type, moreTypes));
return new GivenMethodMembersConjunction(_ruleCreator);
}

public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo(IObjectProvider<IType> types)
{
_ruleCreator.AddPredicate(
MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(types));
return new GivenMethodMembersConjunction(_ruleCreator);
}

public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo(IEnumerable<IType> types)
{
_ruleCreator.AddPredicate(
MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(types));
return new GivenMethodMembersConjunction(_ruleCreator);
}

public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo(IEnumerable<Type> types)
{
_ruleCreator.AddPredicate(
MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(types));
return new GivenMethodMembersConjunction(_ruleCreator);
}

//Negations


Expand All @@ -62,12 +144,93 @@ public GivenMethodMembersConjunction AreNotCalledBy(string pattern, bool useRegu
return new GivenMethodMembersConjunction(_ruleCreator);
}

public GivenMethodMembersConjunction AreNotCalledBy(IEnumerable<string> patterns,
bool useRegularExpressions = false)
{
_ruleCreator.AddPredicate(MethodMemberPredicatesDefinition.AreNotCalledBy(patterns, useRegularExpressions));
return new GivenMethodMembersConjunction(_ruleCreator);
}

public GivenMethodMembersConjunction AreNotCalledBy(IType firstType, params IType[] moreTypes)
{
_ruleCreator.AddPredicate(MethodMemberPredicatesDefinition.AreNotCalledBy(firstType, moreTypes));
return new GivenMethodMembersConjunction(_ruleCreator);
}

public GivenMethodMembersConjunction AreNotCalledBy(Type type, params Type[] moreTypes)
{
_ruleCreator.AddPredicate(MethodMemberPredicatesDefinition.AreNotCalledBy(type, moreTypes));
return new GivenMethodMembersConjunction(_ruleCreator);
}

public GivenMethodMembersConjunction AreNotCalledBy(IObjectProvider<IType> types)
{
_ruleCreator.AddPredicate(MethodMemberPredicatesDefinition.AreNotCalledBy(types));
return new GivenMethodMembersConjunction(_ruleCreator);
}

public GivenMethodMembersConjunction AreNotCalledBy(IEnumerable<IType> types)
{
_ruleCreator.AddPredicate(MethodMemberPredicatesDefinition.AreNotCalledBy(types));
return new GivenMethodMembersConjunction(_ruleCreator);
}

public GivenMethodMembersConjunction AreNotCalledBy(IEnumerable<Type> types)
{
_ruleCreator.AddPredicate(MethodMemberPredicatesDefinition.AreNotCalledBy(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<string> patterns,
bool useRegularExpressions = false)
{
_ruleCreator.AddPredicate(
MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(patterns, useRegularExpressions));
return new GivenMethodMembersConjunction(_ruleCreator);
}

public GivenMethodMembersConjunction DoNotHaveDependencyInMethodBodyTo(IType firstType,
params IType[] moreTypes)
{
_ruleCreator.AddPredicate(
MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(firstType, moreTypes));
return new GivenMethodMembersConjunction(_ruleCreator);
}

public GivenMethodMembersConjunction DoNotHaveDependencyInMethodBodyTo(Type type, params Type[] moreTypes)
{
_ruleCreator.AddPredicate(
MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(type, moreTypes));
return new GivenMethodMembersConjunction(_ruleCreator);
}

public GivenMethodMembersConjunction DoNotHaveDependencyInMethodBodyTo(IObjectProvider<IType> types)
{
_ruleCreator.AddPredicate(
MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(types));
return new GivenMethodMembersConjunction(_ruleCreator);
}

public GivenMethodMembersConjunction DoNotHaveDependencyInMethodBodyTo(IEnumerable<IType> types)
{
_ruleCreator.AddPredicate(
MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(types));
return new GivenMethodMembersConjunction(_ruleCreator);
}

public GivenMethodMembersConjunction DoNotHaveDependencyInMethodBodyTo(IEnumerable<Type> types)
{
_ruleCreator.AddPredicate(
MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(types));
return new GivenMethodMembersConjunction(_ruleCreator);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,30 @@
//
// SPDX-License-Identifier: Apache-2.0

using System;
using System.Collections.Generic;
using ArchUnitNET.Domain;

namespace ArchUnitNET.Fluent.Syntax.Elements.Members.MethodMembers
{
public interface IMethodMemberConditions<out TReturnType> : IMemberConditions<TReturnType>
{
TReturnType BeConstructor();
TReturnType BeVirtual();
TReturnType BeCalledBy(string pattern, bool useRegularExpressions = false);
TReturnType BeCalledBy(IEnumerable<string> patterns, bool useRegularExpressions = false);
TReturnType BeCalledBy(IType firstType, params IType[] moreTypes);
TReturnType BeCalledBy(Type type, params Type[] moreTypes);
TReturnType BeCalledBy(IObjectProvider<IType> types);
TReturnType BeCalledBy(IEnumerable<IType> types);
TReturnType BeCalledBy(IEnumerable<Type> types);
TReturnType HaveDependencyInMethodBodyTo(string pattern, bool useRegularExpressions = false);
TReturnType HaveDependencyInMethodBodyTo(IEnumerable<string> patterns, bool useRegularExpressions = false);
TReturnType HaveDependencyInMethodBodyTo(IType firstType, params IType[] moreTypes);
TReturnType HaveDependencyInMethodBodyTo(Type type, params Type[] moreTypes);
TReturnType HaveDependencyInMethodBodyTo(IObjectProvider<IType> types);
TReturnType HaveDependencyInMethodBodyTo(IEnumerable<IType> types);
TReturnType HaveDependencyInMethodBodyTo(IEnumerable<Type> types);


//Negations
Expand All @@ -20,6 +36,18 @@ public interface IMethodMemberConditions<out TReturnType> : IMemberConditions<TR
TReturnType BeNoConstructor();
TReturnType NotBeVirtual();
TReturnType NotBeCalledBy(string pattern, bool useRegularExpressions = false);
TReturnType NotBeCalledBy(IEnumerable<string> patterns, bool useRegularExpressions = false);
TReturnType NotBeCalledBy(IType firstType, params IType[] moreTypes);
TReturnType NotBeCalledBy(Type type, params Type[] moreTypes);
TReturnType NotBeCalledBy(IObjectProvider<IType> types);
TReturnType NotBeCalledBy(IEnumerable<IType> types);
TReturnType NotBeCalledBy(IEnumerable<Type> types);
TReturnType NotHaveDependencyInMethodBodyTo(string pattern, bool useRegularExpressions = false);
TReturnType NotHaveDependencyInMethodBodyTo(IEnumerable<string> patterns, bool useRegularExpressions = false);
TReturnType NotHaveDependencyInMethodBodyTo(IType firstType, params IType[] moreTypes);
TReturnType NotHaveDependencyInMethodBodyTo(Type type, params Type[] moreTypes);
TReturnType NotHaveDependencyInMethodBodyTo(IObjectProvider<IType> types);
TReturnType NotHaveDependencyInMethodBodyTo(IEnumerable<IType> types);
TReturnType NotHaveDependencyInMethodBodyTo(IEnumerable<Type> types);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,56 @@
//
// SPDX-License-Identifier: Apache-2.0

using System;
using System.Collections.Generic;
using ArchUnitNET.Domain;

namespace ArchUnitNET.Fluent.Syntax.Elements.Members.MethodMembers
{
public interface IMethodMemberPredicates<out TRuleTypeConjunction> : IMemberPredicates<TRuleTypeConjunction>
{
TRuleTypeConjunction AreConstructors();
TRuleTypeConjunction AreVirtual();
TRuleTypeConjunction AreCalledBy(string pattern, bool useRegularExpressions = false);
TRuleTypeConjunction AreCalledBy(IEnumerable<string> patterns, bool useRegularExpressions = false);
TRuleTypeConjunction AreCalledBy(IType firstType, params IType[] moreTypes);
TRuleTypeConjunction AreCalledBy(Type type, params Type[] moreTypes);
TRuleTypeConjunction AreCalledBy(IObjectProvider<IType> types);
TRuleTypeConjunction AreCalledBy(IEnumerable<IType> types);
TRuleTypeConjunction AreCalledBy(IEnumerable<Type> types);
TRuleTypeConjunction HaveDependencyInMethodBodyTo(string pattern, bool useRegularExpressions = false);

TRuleTypeConjunction HaveDependencyInMethodBodyTo(IEnumerable<string> patterns,
bool useRegularExpressions = false);

TRuleTypeConjunction HaveDependencyInMethodBodyTo(IType firstType, params IType[] moreTypes);
TRuleTypeConjunction HaveDependencyInMethodBodyTo(Type type, params Type[] moreTypes);
TRuleTypeConjunction HaveDependencyInMethodBodyTo(IObjectProvider<IType> types);
TRuleTypeConjunction HaveDependencyInMethodBodyTo(IEnumerable<IType> types);
TRuleTypeConjunction HaveDependencyInMethodBodyTo(IEnumerable<Type> types);


//Negations


TRuleTypeConjunction AreNoConstructors();
TRuleTypeConjunction AreNotVirtual();
TRuleTypeConjunction AreNotCalledBy(string pattern, bool useRegularExpressions = false);
TRuleTypeConjunction AreNotCalledBy(IEnumerable<string> patterns, bool useRegularExpressions = false);
TRuleTypeConjunction AreNotCalledBy(IType firstType, params IType[] moreTypes);
TRuleTypeConjunction AreNotCalledBy(Type type, params Type[] moreTypes);
TRuleTypeConjunction AreNotCalledBy(IObjectProvider<IType> types);
TRuleTypeConjunction AreNotCalledBy(IEnumerable<IType> types);
TRuleTypeConjunction AreNotCalledBy(IEnumerable<Type> types);
TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo(string pattern, bool useRegularExpressions = false);

TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo(IEnumerable<string> patterns,
bool useRegularExpressions = false);

TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo(IType firstType, params IType[] moreTypes);
TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo(Type type, params Type[] moreTypes);
TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo(IObjectProvider<IType> types);
TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo(IEnumerable<IType> types);
TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo(IEnumerable<Type> types);
}
}
Loading

0 comments on commit 7a565e8

Please sign in to comment.