Skip to content

Commit

Permalink
fluent implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Fritz Brandhuber <[email protected]>
  • Loading branch information
brandhuf committed Aug 23, 2021
1 parent 3e3c694 commit 2f2040a
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembersThat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public TGivenRuleTypeConjunction AreDeclaredIn(IEnumerable<Type> types)
return Create<TGivenRuleTypeConjunction, TRuleType>(_ruleCreator);
}

public TGivenRuleTypeConjunction AreStatic()
{
_ruleCreator.AddPredicate(MemberPredicatesDefinition<TRuleType>.AreStatic());
return Create<TGivenRuleTypeConjunction, TRuleType>(_ruleCreator);
}

//Negations


Expand Down Expand Up @@ -112,5 +118,11 @@ public TGivenRuleTypeConjunction AreNotDeclaredIn(IEnumerable<Type> types)
_ruleCreator.AddPredicate(MemberPredicatesDefinition<TRuleType>.AreNotDeclaredIn(types));
return Create<TGivenRuleTypeConjunction, TRuleType>(_ruleCreator);
}

public TGivenRuleTypeConjunction AreNotStatic()
{
_ruleCreator.AddPredicate(MemberPredicatesDefinition<TRuleType>.AreNotStatic());
return Create<TGivenRuleTypeConjunction, TRuleType>(_ruleCreator);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public interface IMemberConditions<out TReturnType, out TRuleType> : IObjectCond
TReturnType BeDeclaredIn(IObjectProvider<IType> types);
TReturnType BeDeclaredIn(IEnumerable<IType> types);
TReturnType BeDeclaredIn(IEnumerable<Type> types);
TReturnType BeStatic();


//Negations
Expand All @@ -31,5 +32,6 @@ public interface IMemberConditions<out TReturnType, out TRuleType> : IObjectCond
TReturnType NotBeDeclaredIn(IObjectProvider<IType> types);
TReturnType NotBeDeclaredIn(IEnumerable<IType> types);
TReturnType NotBeDeclaredIn(IEnumerable<Type> types);
TReturnType NotBeStatic();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public interface
TRuleTypeConjunction AreDeclaredIn(IObjectProvider<IType> types);
TRuleTypeConjunction AreDeclaredIn(IEnumerable<IType> types);
TRuleTypeConjunction AreDeclaredIn(IEnumerable<Type> types);
TRuleTypeConjunction AreStatic();

//Negations

Expand All @@ -32,5 +33,6 @@ public interface
TRuleTypeConjunction AreNotDeclaredIn(IObjectProvider<IType> types);
TRuleTypeConjunction AreNotDeclaredIn(IEnumerable<IType> types);
TRuleTypeConjunction AreNotDeclaredIn(IEnumerable<Type> types);
TRuleTypeConjunction AreNotStatic();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ IEnumerable<ConditionResult> Condition(IEnumerable<TRuleType> methods, Architect
return new ArchitectureCondition<TRuleType>(Condition, description);
}

public static ICondition<TRuleType> BeStatic()
{
return new SimpleCondition<TRuleType>(member => !member.IsStatic.HasValue || member.IsStatic.Value,
"be static", "is not static");
}


//Relation Conditions

Expand Down Expand Up @@ -321,6 +327,12 @@ IEnumerable<ConditionResult> Condition(IEnumerable<TRuleType> methods, Architect
return new ArchitectureCondition<TRuleType>(Condition, description);
}

public static ICondition<TRuleType> NotBeStatic()
{
return new SimpleCondition<TRuleType>(member => !member.IsStatic.HasValue || !member.IsStatic.Value,
"not be static", "is static");
}


//Relation Condition Negations

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ IEnumerable<T> Condition(IEnumerable<T> members, Architecture architecture)
return new ArchitecturePredicate<T>(Condition, description);
}

public static IPredicate<T> AreStatic()
{
return new SimplePredicate<T>(member => member.IsStatic.HasValue && member.IsStatic.Value, "are static");
}


//Negations

Expand Down Expand Up @@ -260,5 +265,11 @@ IEnumerable<T> Condition(IEnumerable<T> members, Architecture architecture)

return new ArchitecturePredicate<T>(Condition, description);
}

public static IPredicate<T> AreNotStatic()
{
return new SimplePredicate<T>(member => member.IsStatic.HasValue && !member.IsStatic.Value,
"are not static");
}
}
}
12 changes: 12 additions & 0 deletions ArchUnitNET/Fluent/Syntax/Elements/Members/MembersShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ public TRuleTypeShouldConjunction BeDeclaredIn(IEnumerable<Type> types)
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
}

public TRuleTypeShouldConjunction BeStatic()
{
_ruleCreator.AddCondition(MemberConditionsDefinition<TRuleType>.BeStatic());
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
}

//Relation Conditions

public ShouldRelateToTypesThat<TRuleTypeShouldConjunction, IType, TRuleType> BeDeclaredInTypesThat()
Expand Down Expand Up @@ -126,6 +132,12 @@ public TRuleTypeShouldConjunction NotBeDeclaredIn(IEnumerable<Type> types)
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
}

public TRuleTypeShouldConjunction NotBeStatic()
{
_ruleCreator.AddCondition(MemberConditionsDefinition<TRuleType>.NotBeStatic());
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
}

//Relation Condition Negations

public ShouldRelateToTypesThat<TRuleTypeShouldConjunction, IType, TRuleType> NotBeDeclaredInTypesThat()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ public TRuleTypeShouldConjunction AreDeclaredIn(IEnumerable<Type> types)
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
}

public TRuleTypeShouldConjunction AreStatic()
{
_ruleCreator.ContinueComplexCondition(MemberPredicatesDefinition<TReferenceType>.AreStatic());
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
}


//Negations

Expand Down Expand Up @@ -119,5 +125,11 @@ public TRuleTypeShouldConjunction AreNotDeclaredIn(IEnumerable<Type> types)
_ruleCreator.ContinueComplexCondition(MemberPredicatesDefinition<TReferenceType>.AreNotDeclaredIn(types));
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
}

public TRuleTypeShouldConjunction AreNotStatic()
{
_ruleCreator.ContinueComplexCondition(MemberPredicatesDefinition<TReferenceType>.AreNotStatic());
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
}
}
}

0 comments on commit 2f2040a

Please sign in to comment.