Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .csharpierignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ArchUnitNETTests/Fluent/Syntax/Elements/ObjectSyntaxElementsTests.cs
ArchUnitNETTests/Fluent/Syntax/Elements/TypeSyntaxElementsTests.cs
ArchUnitNETTests/Fluent/Syntax/Elements/ObjectSyntaxElementsTests.cs
7 changes: 7 additions & 0 deletions ArchUnit.sln
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArchUnitNET.TUnit", "ArchUn
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArchUnitNET.TUnitTests", "ArchUnitNET.TUnitTests\ArchUnitNET.TUnitTests.csproj", "{C54143CE-3256-4313-B991-0706705EEA1D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InterfaceAssembly", "TestAssemblies\InterfaceAssembly\InterfaceAssembly.csproj", "{076E223C-32D3-4672-8B00-925CDBC1383E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -130,6 +132,10 @@ Global
{C54143CE-3256-4313-B991-0706705EEA1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C54143CE-3256-4313-B991-0706705EEA1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C54143CE-3256-4313-B991-0706705EEA1D}.Release|Any CPU.Build.0 = Release|Any CPU
{076E223C-32D3-4672-8B00-925CDBC1383E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{076E223C-32D3-4672-8B00-925CDBC1383E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{076E223C-32D3-4672-8B00-925CDBC1383E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{076E223C-32D3-4672-8B00-925CDBC1383E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -141,5 +147,6 @@ Global
{0243F2D4-AC89-4561-A936-D647B6BB821F} = {B1191F18-91CB-4387-B775-A5EB64D3AC30}
{5A24529B-1794-4080-ADCC-77440BA0A0B3} = {B1191F18-91CB-4387-B775-A5EB64D3AC30}
{E6CB8C69-25F5-4C94-8EA3-D56E444EB46B} = {B1191F18-91CB-4387-B775-A5EB64D3AC30}
{076E223C-32D3-4672-8B00-925CDBC1383E} = {B1191F18-91CB-4387-B775-A5EB64D3AC30}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion ArchUnitNET/Fluent/Conditions/RelationCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ string failDescription

public ICondition<TRuleType> GetCondition(IEnumerable<TRelatedType> objects)
{
return _relation(new ListObjectProvider<TRelatedType>(objects.ToList()));
return _relation(new ObjectProvider<TRelatedType>(objects.ToList()));
}

private bool Equals(RelationCondition<TRuleType, TRelatedType> other)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@

namespace ArchUnitNET.Fluent
{
public class ListObjectProvider<T> : ISizedObjectProvider<T>
public class ObjectProvider<T> : ISizedObjectProvider<T>
where T : ICanBeAnalyzed
{
private readonly IEnumerable<T> _objects;
private readonly List<T> _objects;

public ListObjectProvider(List<T> objects)
public ObjectProvider()
: this(new List<T>()) { }

public ObjectProvider(IEnumerable<T> objects)
{
_objects = objects;
Description = string.Join(" or ", objects.Select(obj => $"\"{obj.FullName}\""));
_objects = objects.ToList();
Description = string.Join(" or ", _objects.Select(obj => $"\"{obj.FullName}\""));
}

public string Description { get; }
Expand All @@ -24,7 +27,7 @@ public IEnumerable<T> GetObjects(Architecture architecture)
return _objects;
}

private bool Equals(ListObjectProvider<T> other)
private bool Equals(ObjectProvider<T> other)
{
return string.Equals(Description, other.Description);
}
Expand All @@ -41,7 +44,7 @@ public override bool Equals(object obj)
return true;
}

return obj.GetType() == GetType() && Equals((ListObjectProvider<T>)obj);
return obj.GetType() == GetType() && Equals((ObjectProvider<T>)obj);
}

public override int GetHashCode()
Expand Down
29 changes: 29 additions & 0 deletions ArchUnitNET/Fluent/Syntax/DescriptionHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using ArchUnitNET.Domain;

namespace ArchUnitNET.Fluent.Syntax
{
public static class DescriptionHelpers
{
public static string SelectDescription<T>(
string emptyDescription,
string singleDescription,
string multipleDescription,
IObjectProvider<T> objectProvider
)
{
if (!(objectProvider is ISizedObjectProvider<T> sizedObjectProvider))
{
return $"{multipleDescription} {objectProvider.Description}";
}

switch (sizedObjectProvider.Count)
{
case 0:
return emptyDescription;
case 1:
return $"{singleDescription} {objectProvider.Description}";
}
return $"{multipleDescription} {objectProvider.Description}";
}
}
}
64 changes: 32 additions & 32 deletions ArchUnitNET/Fluent/Syntax/Elements/ObjectsShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ params ICanBeAnalyzed[] moreObjects
objectList.AddRange(moreObjects);
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.Be(
new ListObjectProvider<ICanBeAnalyzed>(objectList)
new ObjectProvider<ICanBeAnalyzed>(objectList)
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand All @@ -72,7 +72,7 @@ public TRuleTypeShouldConjunction Be(IEnumerable<ICanBeAnalyzed> objects)
{
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.Be(
new ListObjectProvider<ICanBeAnalyzed>(objects.ToList())
new ObjectProvider<ICanBeAnalyzed>(objects.ToList())
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand Down Expand Up @@ -121,7 +121,7 @@ params MethodMember[] moreMethods
methodList.AddRange(moreMethods);
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.CallAny(
new ListObjectProvider<MethodMember>(methodList)
new ObjectProvider<MethodMember>(methodList)
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand All @@ -131,7 +131,7 @@ public TRuleTypeShouldConjunction CallAny(IEnumerable<MethodMember> methods)
{
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.CallAny(
new ListObjectProvider<MethodMember>(methods.ToList())
new ObjectProvider<MethodMember>(methods.ToList())
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand Down Expand Up @@ -177,7 +177,7 @@ public TRuleTypeShouldConjunction DependOnAny(IType firstType, params IType[] mo
typeList.AddRange(moreTypes);
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.DependOnAny(
new ListObjectProvider<IType>(typeList)
new ObjectProvider<IType>(typeList)
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand All @@ -189,7 +189,7 @@ public TRuleTypeShouldConjunction DependOnAny(Type firstType, params Type[] more
typeList.AddRange(moreTypes);
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.DependOnAny(
new SystemTypeListObjectProvider<IType>(typeList)
new SystemTypeObjectProvider<IType>(typeList)
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand All @@ -205,7 +205,7 @@ public TRuleTypeShouldConjunction DependOnAny(IEnumerable<IType> types)
{
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.DependOnAny(
new ListObjectProvider<IType>(types.ToList())
new ObjectProvider<IType>(types.ToList())
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand All @@ -215,7 +215,7 @@ public TRuleTypeShouldConjunction DependOnAny(IEnumerable<Type> types)
{
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.DependOnAny(
new SystemTypeListObjectProvider<IType>(types.ToList())
new SystemTypeObjectProvider<IType>(types.ToList())
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand Down Expand Up @@ -288,7 +288,7 @@ public TRuleTypeShouldConjunction OnlyDependOn(IType firstType, params IType[] m
typeList.AddRange(moreTypes);
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.OnlyDependOn(
new ListObjectProvider<IType>(typeList)
new ObjectProvider<IType>(typeList)
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand All @@ -300,7 +300,7 @@ public TRuleTypeShouldConjunction OnlyDependOn(Type firstType, params Type[] mor
typeList.AddRange(moreTypes);
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.OnlyDependOn(
new SystemTypeListObjectProvider<IType>(typeList)
new SystemTypeObjectProvider<IType>(typeList)
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand All @@ -316,7 +316,7 @@ public TRuleTypeShouldConjunction OnlyDependOn(IEnumerable<IType> types)
{
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.OnlyDependOn(
new ListObjectProvider<IType>(types.ToList())
new ObjectProvider<IType>(types.ToList())
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand All @@ -326,7 +326,7 @@ public TRuleTypeShouldConjunction OnlyDependOn(IEnumerable<Type> types)
{
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.OnlyDependOn(
new SystemTypeListObjectProvider<IType>(types.ToList())
new SystemTypeObjectProvider<IType>(types.ToList())
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand Down Expand Up @@ -375,7 +375,7 @@ params Attribute[] moreAttributes
attributeList.AddRange(moreAttributes);
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.HaveAnyAttributes(
new ListObjectProvider<Attribute>(attributeList)
new ObjectProvider<Attribute>(attributeList)
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand All @@ -390,7 +390,7 @@ params Type[] moreAttributes
attributeList.AddRange(moreAttributes);
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.HaveAnyAttributes(
new SystemTypeListObjectProvider<Attribute>(attributeList)
new SystemTypeObjectProvider<Attribute>(attributeList)
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand All @@ -408,7 +408,7 @@ public TRuleTypeShouldConjunction HaveAnyAttributes(IEnumerable<Attribute> attri
{
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.HaveAnyAttributes(
new ListObjectProvider<Attribute>(attributes.ToList())
new ObjectProvider<Attribute>(attributes.ToList())
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand All @@ -418,7 +418,7 @@ public TRuleTypeShouldConjunction HaveAnyAttributes(IEnumerable<Type> attributes
{
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.HaveAnyAttributes(
new SystemTypeListObjectProvider<Attribute>(attributes.ToList())
new SystemTypeObjectProvider<Attribute>(attributes.ToList())
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand Down Expand Up @@ -467,7 +467,7 @@ params Attribute[] moreAttributes
attributeList.AddRange(moreAttributes);
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.OnlyHaveAttributes(
new ListObjectProvider<Attribute>(attributeList)
new ObjectProvider<Attribute>(attributeList)
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand All @@ -482,7 +482,7 @@ params Type[] moreAttributes
attributeList.AddRange(moreAttributes);
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.OnlyHaveAttributes(
new SystemTypeListObjectProvider<Attribute>(attributeList)
new SystemTypeObjectProvider<Attribute>(attributeList)
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand All @@ -500,7 +500,7 @@ public TRuleTypeShouldConjunction OnlyHaveAttributes(IEnumerable<Attribute> attr
{
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.OnlyHaveAttributes(
new ListObjectProvider<Attribute>(attributes.ToList())
new ObjectProvider<Attribute>(attributes.ToList())
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand All @@ -510,7 +510,7 @@ public TRuleTypeShouldConjunction OnlyHaveAttributes(IEnumerable<Type> attribute
{
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.OnlyHaveAttributes(
new SystemTypeListObjectProvider<Attribute>(attributes.ToList())
new SystemTypeObjectProvider<Attribute>(attributes.ToList())
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand Down Expand Up @@ -979,7 +979,7 @@ params ICanBeAnalyzed[] moreObjects
objectList.AddRange(moreObjects);
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.NotBe(
new ListObjectProvider<ICanBeAnalyzed>(objectList)
new ObjectProvider<ICanBeAnalyzed>(objectList)
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand All @@ -989,7 +989,7 @@ public TRuleTypeShouldConjunction NotBe(IEnumerable<ICanBeAnalyzed> objects)
{
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.NotBe(
new ListObjectProvider<ICanBeAnalyzed>(objects.ToList())
new ObjectProvider<ICanBeAnalyzed>(objects.ToList())
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand Down Expand Up @@ -1038,7 +1038,7 @@ params MethodMember[] moreMethods
methods.AddRange(moreMethods);
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.NotCallAny(
new ListObjectProvider<MethodMember>(methods)
new ObjectProvider<MethodMember>(methods)
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand All @@ -1049,7 +1049,7 @@ public TRuleTypeShouldConjunction NotCallAny(IEnumerable<MethodMember> methods)
var methodList = methods.ToList();
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.NotCallAny(
new ListObjectProvider<MethodMember>(methodList)
new ObjectProvider<MethodMember>(methodList)
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand Down Expand Up @@ -1098,7 +1098,7 @@ public TRuleTypeShouldConjunction NotDependOnAny(IType firstType, params IType[]
typeList.AddRange(moreTypes);
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.NotDependOnAny(
new ListObjectProvider<IType>(typeList)
new ObjectProvider<IType>(typeList)
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand All @@ -1110,7 +1110,7 @@ public TRuleTypeShouldConjunction NotDependOnAny(Type firstType, params Type[] m
typeList.AddRange(moreTypes);
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.NotDependOnAny(
new SystemTypeListObjectProvider<IType>(typeList)
new SystemTypeObjectProvider<IType>(typeList)
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand All @@ -1126,7 +1126,7 @@ public TRuleTypeShouldConjunction NotDependOnAny(IEnumerable<IType> types)
{
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.NotDependOnAny(
new ListObjectProvider<IType>(types.ToList())
new ObjectProvider<IType>(types.ToList())
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand All @@ -1136,7 +1136,7 @@ public TRuleTypeShouldConjunction NotDependOnAny(IEnumerable<Type> types)
{
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.NotDependOnAny(
new SystemTypeListObjectProvider<IType>(types.ToList())
new SystemTypeObjectProvider<IType>(types.ToList())
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand Down Expand Up @@ -1185,7 +1185,7 @@ params Attribute[] moreAttributes
attributeList.AddRange(moreAttributes);
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.NotHaveAnyAttributes(
new ListObjectProvider<Attribute>(attributeList)
new ObjectProvider<Attribute>(attributeList)
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand All @@ -1200,7 +1200,7 @@ params Type[] moreAttributes
attributeList.AddRange(moreAttributes);
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.NotHaveAnyAttributes(
new SystemTypeListObjectProvider<Attribute>(attributeList)
new SystemTypeObjectProvider<Attribute>(attributeList)
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand All @@ -1220,7 +1220,7 @@ public TRuleTypeShouldConjunction NotHaveAnyAttributes(IEnumerable<Attribute> at
{
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.NotHaveAnyAttributes(
new ListObjectProvider<Attribute>(attributes.ToList())
new ObjectProvider<Attribute>(attributes.ToList())
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand All @@ -1230,7 +1230,7 @@ public TRuleTypeShouldConjunction NotHaveAnyAttributes(IEnumerable<Type> attribu
{
_ruleCreator.AddCondition(
ObjectConditionsDefinition<TRuleType>.NotHaveAnyAttributes(
new SystemTypeListObjectProvider<Attribute>(attributes.ToList())
new SystemTypeObjectProvider<Attribute>(attributes.ToList())
)
);
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
Expand Down
Loading
Loading