diff --git a/ArchUnit.sln.DotSettings b/ArchUnit.sln.DotSettings
index f430f615e..7a18ebc4f 100644
--- a/ArchUnit.sln.DotSettings
+++ b/ArchUnit.sln.DotSettings
@@ -4,12 +4,13 @@
Required
Required
Copyright 2019 Florian Gather <florian.gather@tngtech.com>
- Copyright 2019 Paula Ruiz <paularuiz22@gmail.com>
Copyright 2019 Fritz Brandhuber <fritz.brandhuber@tngtech.com>
+ Copyright 2020 Pavel Fischer <rubbiroid@gmail.com>
SPDX-License-Identifier: Apache-2.0
False
+
True
True
True
diff --git a/ArchUnitNET.NUnit/ArchRuleAssert.cs b/ArchUnitNET.NUnit/ArchRuleAssert.cs
index dcae9c895..45ba19840 100644
--- a/ArchUnitNET.NUnit/ArchRuleAssert.cs
+++ b/ArchUnitNET.NUnit/ArchRuleAssert.cs
@@ -20,9 +20,9 @@ public static class ArchRuleAssert
/// The rule to test the architecture with
public static void FulfilsRule(Architecture architecture, IArchRule archRule)
{
- if (!architecture.FulfilsRule(archRule))
+ if (!archRule.HasNoViolations(architecture))
{
- Assert.Fail(architecture.EvaluateRule(archRule).ToErrorMessage());
+ Assert.Fail(archRule.Evaluate(architecture).ToErrorMessage());
}
}
}
diff --git a/ArchUnitNET.NUnitTests/RuleEvaluationTests.cs b/ArchUnitNET.NUnitTests/RuleEvaluationTests.cs
index 257d2b09e..2379d2fc7 100644
--- a/ArchUnitNET.NUnitTests/RuleEvaluationTests.cs
+++ b/ArchUnitNET.NUnitTests/RuleEvaluationTests.cs
@@ -4,10 +4,10 @@
//
// SPDX-License-Identifier: Apache-2.0
-using ArchUnitNET.Core;
using ArchUnitNET.Domain;
using ArchUnitNET.Fluent;
using ArchUnitNET.Fluent.Extensions;
+using ArchUnitNET.Loader;
using ArchUnitNET.NUnit;
using NUnit.Framework;
using static ArchUnitNET.Fluent.ArchRuleDefinition;
diff --git a/ArchUnitNET.xUnit/Asserts/ArchRuleAsserts.cs b/ArchUnitNET.xUnit/Asserts/ArchRuleAsserts.cs
index 91a2893a9..8769fa318 100644
--- a/ArchUnitNET.xUnit/Asserts/ArchRuleAsserts.cs
+++ b/ArchUnitNET.xUnit/Asserts/ArchRuleAsserts.cs
@@ -22,7 +22,7 @@ partial class Assert
/// Thrown if the rule is violated
public static void ArchRule(Architecture architecture, IArchRule archRule)
{
- if (!architecture.FulfilsRule(archRule))
+ if (!archRule.HasNoViolations(architecture))
{
throw new FailedArchRuleException(architecture, archRule);
}
diff --git a/ArchUnitNET.xUnit/Asserts/Sdk/Exceptions/FailedArchRuleException.cs b/ArchUnitNET.xUnit/Asserts/Sdk/Exceptions/FailedArchRuleException.cs
index c7e1959c0..02c4fca35 100644
--- a/ArchUnitNET.xUnit/Asserts/Sdk/Exceptions/FailedArchRuleException.cs
+++ b/ArchUnitNET.xUnit/Asserts/Sdk/Exceptions/FailedArchRuleException.cs
@@ -20,7 +20,7 @@ public class FailedArchRuleException : XunitException
/// The architecture which was tested
/// The archrule that failed
public FailedArchRuleException(Architecture architecture, IArchRule archRule)
- : this(architecture.EvaluateRule(archRule))
+ : this(archRule.Evaluate(architecture))
{
}
diff --git a/ArchUnitNET/ArchUnitNET.csproj b/ArchUnitNET/ArchUnitNET.csproj
index a02db2cce..4cf525ee2 100644
--- a/ArchUnitNET/ArchUnitNET.csproj
+++ b/ArchUnitNET/ArchUnitNET.csproj
@@ -6,7 +6,7 @@
ArchUnitNET
TngTech.ArchUnitNET
ArchUnit C#
- Florian Gather, Paula Ruiz, Fritz Brandhuber
+ Florian Gather, Paula Ruiz, Fritz Brandhuber, Pavel Fischer
TNG Technology Consulting GmbH
C# Version of ArchUnit (see: archunit.org)
https://apache.org/licenses/LICENSE-2.0
diff --git a/ArchUnitNET/ArchitectureExceptions/ArchitectureException.cs b/ArchUnitNET/ArchitectureExceptions/ArchitectureException.cs
deleted file mode 100644
index 9ab43bb72..000000000
--- a/ArchUnitNET/ArchitectureExceptions/ArchitectureException.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2019 Florian Gather
-// Copyright 2019 Paula Ruiz
-// Copyright 2019 Fritz Brandhuber
-//
-// SPDX-License-Identifier: Apache-2.0
-
-using System;
-
-namespace ArchUnitNET.ArchitectureExceptions
-{
- public class ArchitectureException : Exception
- {
- public ArchitectureException(string firstFullName) : base(firstFullName)
- {
- }
- }
-}
\ No newline at end of file
diff --git a/ArchUnitNET/Domain/Architecture.cs b/ArchUnitNET/Domain/Architecture.cs
index a3b9b6be0..1f5ea465f 100644
--- a/ArchUnitNET/Domain/Architecture.cs
+++ b/ArchUnitNET/Domain/Architecture.cs
@@ -26,11 +26,8 @@ public Architecture(IEnumerable allAssemblies, IEnumerable
}
public IEnumerable Assemblies => _allAssemblies.Where(assembly => !assembly.IsOnlyReferenced);
-
public IEnumerable Namespaces { get; }
-
public IEnumerable Types { get; }
-
public IEnumerable Classes => Types.OfType();
public IEnumerable Interfaces => Types.OfType();
public IEnumerable Attributes => Types.OfType();
@@ -39,22 +36,12 @@ public Architecture(IEnumerable allAssemblies, IEnumerable
public IEnumerable MethodMembers => Members.OfType();
public IEnumerable Members => Types.SelectMany(type => type.Members);
- public bool FulfilsRule(IArchRule archRule)
- {
- return archRule.HasNoViolations(this);
- }
-
public IEnumerable GetOrCreateObjects(IObjectProvider objectProvider,
Func> providingFunction) where T : ICanBeAnalyzed
{
return _objectProviderCache.GetOrCreateObjects(objectProvider, providingFunction);
}
- public IEnumerable EvaluateRule(IArchRule archRule)
- {
- return archRule.Evaluate(this);
- }
-
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
diff --git a/ArchUnitNET/Domain/ArchitectureCacheKey.cs b/ArchUnitNET/Domain/ArchitectureCacheKey.cs
index efe48109c..9acfae4d2 100644
--- a/ArchUnitNET/Domain/ArchitectureCacheKey.cs
+++ b/ArchUnitNET/Domain/ArchitectureCacheKey.cs
@@ -7,7 +7,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using ArchUnitNET.Fluent.Extensions;
+using ArchUnitNET.Domain.Extensions;
namespace ArchUnitNET.Domain
{
diff --git a/ArchUnitNET/Domain/Class.cs b/ArchUnitNET/Domain/Class.cs
index 6542f02bb..0b17f2a44 100644
--- a/ArchUnitNET/Domain/Class.cs
+++ b/ArchUnitNET/Domain/Class.cs
@@ -6,8 +6,8 @@
using System.Collections.Generic;
using System.Linq;
-using ArchUnitNET.Domain.Dependencies.Types;
-using ArchUnitNET.Fluent.Extensions;
+using ArchUnitNET.Domain.Dependencies;
+using ArchUnitNET.Domain.Extensions;
using JetBrains.Annotations;
namespace ArchUnitNET.Domain
@@ -101,7 +101,7 @@ public bool IsAssignableTo(IType assignableToType)
public bool IsAssignableTo(string pattern, bool useRegularExpressions = false)
{
return pattern != null && this.GetAssignableTypes()
- .Any(type => type.FullNameMatches(pattern, useRegularExpressions));
+ .Any(type => type.FullNameMatches(pattern, useRegularExpressions));
}
public override string ToString()
diff --git a/ArchUnitNET/Domain/Dependencies/Members/AttributeMemberDependency.cs b/ArchUnitNET/Domain/Dependencies/AttributeMemberDependency.cs
similarity index 97%
rename from ArchUnitNET/Domain/Dependencies/Members/AttributeMemberDependency.cs
rename to ArchUnitNET/Domain/Dependencies/AttributeMemberDependency.cs
index 9f4a4fbd3..99e8736be 100644
--- a/ArchUnitNET/Domain/Dependencies/Members/AttributeMemberDependency.cs
+++ b/ArchUnitNET/Domain/Dependencies/AttributeMemberDependency.cs
@@ -6,7 +6,7 @@
using Equ;
-namespace ArchUnitNET.Domain.Dependencies.Members
+namespace ArchUnitNET.Domain.Dependencies
{
public class AttributeMemberDependency : MemberwiseEquatable, IMemberTypeDependency
{
diff --git a/ArchUnitNET/Domain/Dependencies/Types/AttributeTypeDependency.cs b/ArchUnitNET/Domain/Dependencies/AttributeTypeDependency.cs
similarity index 92%
rename from ArchUnitNET/Domain/Dependencies/Types/AttributeTypeDependency.cs
rename to ArchUnitNET/Domain/Dependencies/AttributeTypeDependency.cs
index e8f70e84a..f117f1c9a 100644
--- a/ArchUnitNET/Domain/Dependencies/Types/AttributeTypeDependency.cs
+++ b/ArchUnitNET/Domain/Dependencies/AttributeTypeDependency.cs
@@ -6,7 +6,7 @@
using Equ;
-namespace ArchUnitNET.Domain.Dependencies.Types
+namespace ArchUnitNET.Domain.Dependencies
{
public class AttributeTypeDependency : MemberwiseEquatable, ITypeDependency
{
diff --git a/ArchUnitNET/Domain/Dependencies/Members/BodyTypeMemberDependency.cs b/ArchUnitNET/Domain/Dependencies/BodyTypeMemberDependency.cs
similarity index 97%
rename from ArchUnitNET/Domain/Dependencies/Members/BodyTypeMemberDependency.cs
rename to ArchUnitNET/Domain/Dependencies/BodyTypeMemberDependency.cs
index 05bc396aa..58282c801 100644
--- a/ArchUnitNET/Domain/Dependencies/Members/BodyTypeMemberDependency.cs
+++ b/ArchUnitNET/Domain/Dependencies/BodyTypeMemberDependency.cs
@@ -6,7 +6,7 @@
using Equ;
-namespace ArchUnitNET.Domain.Dependencies.Members
+namespace ArchUnitNET.Domain.Dependencies
{
public class BodyTypeMemberDependency : MemberwiseEquatable,
IMemberTypeDependency
diff --git a/ArchUnitNET/Domain/Dependencies/Members/FieldTypeDependency.cs b/ArchUnitNET/Domain/Dependencies/FieldTypeDependency.cs
similarity index 97%
rename from ArchUnitNET/Domain/Dependencies/Members/FieldTypeDependency.cs
rename to ArchUnitNET/Domain/Dependencies/FieldTypeDependency.cs
index 971af02ac..fe0927285 100644
--- a/ArchUnitNET/Domain/Dependencies/Members/FieldTypeDependency.cs
+++ b/ArchUnitNET/Domain/Dependencies/FieldTypeDependency.cs
@@ -6,7 +6,7 @@
using Equ;
-namespace ArchUnitNET.Domain.Dependencies.Members
+namespace ArchUnitNET.Domain.Dependencies
{
public class FieldTypeDependency : MemberwiseEquatable, IMemberTypeDependency
{
diff --git a/ArchUnitNET/Domain/Dependencies/Members/IMemberMemberDependency.cs b/ArchUnitNET/Domain/Dependencies/IMemberMemberDependency.cs
similarity index 87%
rename from ArchUnitNET/Domain/Dependencies/Members/IMemberMemberDependency.cs
rename to ArchUnitNET/Domain/Dependencies/IMemberMemberDependency.cs
index 530bfae84..cb0bf2ece 100644
--- a/ArchUnitNET/Domain/Dependencies/Members/IMemberMemberDependency.cs
+++ b/ArchUnitNET/Domain/Dependencies/IMemberMemberDependency.cs
@@ -4,7 +4,7 @@
//
// SPDX-License-Identifier: Apache-2.0
-namespace ArchUnitNET.Domain.Dependencies.Members
+namespace ArchUnitNET.Domain.Dependencies
{
public interface IMemberMemberDependency : IMemberTypeDependency
{
diff --git a/ArchUnitNET/Domain/Dependencies/Members/IMemberTypeDependency.cs b/ArchUnitNET/Domain/Dependencies/IMemberTypeDependency.cs
similarity index 78%
rename from ArchUnitNET/Domain/Dependencies/Members/IMemberTypeDependency.cs
rename to ArchUnitNET/Domain/Dependencies/IMemberTypeDependency.cs
index b6d8e8047..95f770753 100644
--- a/ArchUnitNET/Domain/Dependencies/Members/IMemberTypeDependency.cs
+++ b/ArchUnitNET/Domain/Dependencies/IMemberTypeDependency.cs
@@ -4,9 +4,7 @@
//
// SPDX-License-Identifier: Apache-2.0
-using ArchUnitNET.Domain.Dependencies.Types;
-
-namespace ArchUnitNET.Domain.Dependencies.Members
+namespace ArchUnitNET.Domain.Dependencies
{
public interface IMemberTypeDependency : ITypeDependency
{
diff --git a/ArchUnitNET/Domain/Dependencies/Types/ITypeDependency.cs b/ArchUnitNET/Domain/Dependencies/ITypeDependency.cs
similarity index 87%
rename from ArchUnitNET/Domain/Dependencies/Types/ITypeDependency.cs
rename to ArchUnitNET/Domain/Dependencies/ITypeDependency.cs
index 28e14b2e2..a1d22a9d9 100644
--- a/ArchUnitNET/Domain/Dependencies/Types/ITypeDependency.cs
+++ b/ArchUnitNET/Domain/Dependencies/ITypeDependency.cs
@@ -4,7 +4,7 @@
//
// SPDX-License-Identifier: Apache-2.0
-namespace ArchUnitNET.Domain.Dependencies.Types
+namespace ArchUnitNET.Domain.Dependencies
{
public interface ITypeDependency
{
diff --git a/ArchUnitNET/Domain/Dependencies/Types/ImplementsInterfaceDependency.cs b/ArchUnitNET/Domain/Dependencies/ImplementsInterfaceDependency.cs
similarity index 92%
rename from ArchUnitNET/Domain/Dependencies/Types/ImplementsInterfaceDependency.cs
rename to ArchUnitNET/Domain/Dependencies/ImplementsInterfaceDependency.cs
index dccdb5a32..c76243607 100644
--- a/ArchUnitNET/Domain/Dependencies/Types/ImplementsInterfaceDependency.cs
+++ b/ArchUnitNET/Domain/Dependencies/ImplementsInterfaceDependency.cs
@@ -6,7 +6,7 @@
using Equ;
-namespace ArchUnitNET.Domain.Dependencies.Types
+namespace ArchUnitNET.Domain.Dependencies
{
public class ImplementsInterfaceDependency : MemberwiseEquatable, ITypeDependency
{
diff --git a/ArchUnitNET/Domain/Dependencies/Types/InheritsBaseClassDependency.cs b/ArchUnitNET/Domain/Dependencies/InheritsBaseClassDependency.cs
similarity index 92%
rename from ArchUnitNET/Domain/Dependencies/Types/InheritsBaseClassDependency.cs
rename to ArchUnitNET/Domain/Dependencies/InheritsBaseClassDependency.cs
index 7869590c0..8c6c52c66 100644
--- a/ArchUnitNET/Domain/Dependencies/Types/InheritsBaseClassDependency.cs
+++ b/ArchUnitNET/Domain/Dependencies/InheritsBaseClassDependency.cs
@@ -6,7 +6,7 @@
using Equ;
-namespace ArchUnitNET.Domain.Dependencies.Types
+namespace ArchUnitNET.Domain.Dependencies
{
public class InheritsBaseClassDependency : MemberwiseEquatable, ITypeDependency
{
diff --git a/ArchUnitNET/Domain/Dependencies/Members/MethodCallDependency.cs b/ArchUnitNET/Domain/Dependencies/MethodCallDependency.cs
similarity index 96%
rename from ArchUnitNET/Domain/Dependencies/Members/MethodCallDependency.cs
rename to ArchUnitNET/Domain/Dependencies/MethodCallDependency.cs
index a332d9753..bc41be84a 100644
--- a/ArchUnitNET/Domain/Dependencies/Members/MethodCallDependency.cs
+++ b/ArchUnitNET/Domain/Dependencies/MethodCallDependency.cs
@@ -4,7 +4,7 @@
//
// SPDX-License-Identifier: Apache-2.0
-namespace ArchUnitNET.Domain.Dependencies.Members
+namespace ArchUnitNET.Domain.Dependencies
{
public class MethodCallDependency : IMemberMemberDependency
{
diff --git a/ArchUnitNET/Domain/Dependencies/Members/MethodSignatureDependency.cs b/ArchUnitNET/Domain/Dependencies/MethodSignatureDependency.cs
similarity index 97%
rename from ArchUnitNET/Domain/Dependencies/Members/MethodSignatureDependency.cs
rename to ArchUnitNET/Domain/Dependencies/MethodSignatureDependency.cs
index 474611537..023fe27e9 100644
--- a/ArchUnitNET/Domain/Dependencies/Members/MethodSignatureDependency.cs
+++ b/ArchUnitNET/Domain/Dependencies/MethodSignatureDependency.cs
@@ -6,7 +6,7 @@
using Equ;
-namespace ArchUnitNET.Domain.Dependencies.Members
+namespace ArchUnitNET.Domain.Dependencies
{
public class MethodSignatureDependency : MemberwiseEquatable,
IMemberTypeDependency
diff --git a/ArchUnitNET/Domain/Dependencies/Members/PropertyTypeDependency.cs b/ArchUnitNET/Domain/Dependencies/PropertyTypeDependency.cs
similarity index 97%
rename from ArchUnitNET/Domain/Dependencies/Members/PropertyTypeDependency.cs
rename to ArchUnitNET/Domain/Dependencies/PropertyTypeDependency.cs
index 27539403b..3d8ae5da0 100644
--- a/ArchUnitNET/Domain/Dependencies/Members/PropertyTypeDependency.cs
+++ b/ArchUnitNET/Domain/Dependencies/PropertyTypeDependency.cs
@@ -6,7 +6,7 @@
using Equ;
-namespace ArchUnitNET.Domain.Dependencies.Members
+namespace ArchUnitNET.Domain.Dependencies
{
public class PropertyTypeDependency : MemberwiseEquatable, IMemberTypeDependency
{
diff --git a/ArchUnitNET/Domain/Dependencies/Types/TypeReferenceDependency.cs b/ArchUnitNET/Domain/Dependencies/TypeReferenceDependency.cs
similarity index 92%
rename from ArchUnitNET/Domain/Dependencies/Types/TypeReferenceDependency.cs
rename to ArchUnitNET/Domain/Dependencies/TypeReferenceDependency.cs
index 7971ea459..ed35839f5 100644
--- a/ArchUnitNET/Domain/Dependencies/Types/TypeReferenceDependency.cs
+++ b/ArchUnitNET/Domain/Dependencies/TypeReferenceDependency.cs
@@ -6,7 +6,7 @@
using Equ;
-namespace ArchUnitNET.Domain.Dependencies.Types
+namespace ArchUnitNET.Domain.Dependencies
{
public class TypeReferenceDependency : MemberwiseEquatable, ITypeDependency
{
diff --git a/ArchUnitNET/Domain/Dependencies/Types/AttributeAssemblyDependency.cs b/ArchUnitNET/Domain/Dependencies/Types/AttributeAssemblyDependency.cs
deleted file mode 100644
index 95b9b7112..000000000
--- a/ArchUnitNET/Domain/Dependencies/Types/AttributeAssemblyDependency.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2019 Florian Gather
-// Copyright 2019 Paula Ruiz
-// Copyright 2019 Fritz Brandhuber
-//
-// SPDX-License-Identifier: Apache-2.0
-
-using Equ;
-
-namespace ArchUnitNET.Domain.Dependencies.Types
-{
- public class AttributeAssemblyDependency : MemberwiseEquatable
- {
-// public AttributeAssemblyDependency(Attribute origin, Assembly target)
-// {
-// Origin = origin;
-// Target = target;
-// }
-// public Attribute Origin { get; }
-//
-// //what should the type of Target be to include assemblies and modules?
-// public IType Target { get; }
- }
-}
\ No newline at end of file
diff --git a/ArchUnitNET/ArchitectureExceptions/AssemblyDoesNotExistInArchitecture.cs b/ArchUnitNET/Domain/Exceptions/AssemblyDoesNotExistInArchitecture.cs
similarity index 67%
rename from ArchUnitNET/ArchitectureExceptions/AssemblyDoesNotExistInArchitecture.cs
rename to ArchUnitNET/Domain/Exceptions/AssemblyDoesNotExistInArchitecture.cs
index 201746e58..2e1d71335 100644
--- a/ArchUnitNET/ArchitectureExceptions/AssemblyDoesNotExistInArchitecture.cs
+++ b/ArchUnitNET/Domain/Exceptions/AssemblyDoesNotExistInArchitecture.cs
@@ -6,17 +6,12 @@
using System;
-namespace ArchUnitNET.ArchitectureExceptions
+namespace ArchUnitNET.Domain.Exceptions
{
public class AssemblyDoesNotExistInArchitecture : Exception
{
public AssemblyDoesNotExistInArchitecture(string message) : base(message)
{
}
-
- public AssemblyDoesNotExistInArchitecture(string message, Exception innerException) : base(message,
- innerException)
- {
- }
}
}
\ No newline at end of file
diff --git a/ArchUnitNET/ArchitectureExceptions/InvalidStateException.cs b/ArchUnitNET/Domain/Exceptions/InvalidStateException.cs
similarity index 89%
rename from ArchUnitNET/ArchitectureExceptions/InvalidStateException.cs
rename to ArchUnitNET/Domain/Exceptions/InvalidStateException.cs
index 00b3c33e8..fb856f72f 100644
--- a/ArchUnitNET/ArchitectureExceptions/InvalidStateException.cs
+++ b/ArchUnitNET/Domain/Exceptions/InvalidStateException.cs
@@ -6,7 +6,7 @@
using System;
-namespace ArchUnitNET.ArchitectureExceptions
+namespace ArchUnitNET.Domain.Exceptions
{
public class InvalidStateException : Exception
{
diff --git a/ArchUnitNET/ArchitectureExceptions/MultipleOccurrencesInSequenceException.cs b/ArchUnitNET/Domain/Exceptions/MultipleOccurrencesInSequenceException.cs
similarity index 67%
rename from ArchUnitNET/ArchitectureExceptions/MultipleOccurrencesInSequenceException.cs
rename to ArchUnitNET/Domain/Exceptions/MultipleOccurrencesInSequenceException.cs
index 78ea31114..f3c9f36ad 100644
--- a/ArchUnitNET/ArchitectureExceptions/MultipleOccurrencesInSequenceException.cs
+++ b/ArchUnitNET/Domain/Exceptions/MultipleOccurrencesInSequenceException.cs
@@ -6,17 +6,12 @@
using System;
-namespace ArchUnitNET.ArchitectureExceptions
+namespace ArchUnitNET.Domain.Exceptions
{
public class MultipleOccurrencesInSequenceException : Exception
{
public MultipleOccurrencesInSequenceException(string message) : base(message)
{
}
-
- public MultipleOccurrencesInSequenceException(string message, Exception innerException) : base(message,
- innerException)
- {
- }
}
}
\ No newline at end of file
diff --git a/ArchUnitNET/ArchitectureExceptions/TypeDoesNotExistInArchitecture.cs b/ArchUnitNET/Domain/Exceptions/TypeDoesNotExistInArchitecture.cs
similarity index 69%
rename from ArchUnitNET/ArchitectureExceptions/TypeDoesNotExistInArchitecture.cs
rename to ArchUnitNET/Domain/Exceptions/TypeDoesNotExistInArchitecture.cs
index 28315ea82..ca1be47c1 100644
--- a/ArchUnitNET/ArchitectureExceptions/TypeDoesNotExistInArchitecture.cs
+++ b/ArchUnitNET/Domain/Exceptions/TypeDoesNotExistInArchitecture.cs
@@ -6,16 +6,12 @@
using System;
-namespace ArchUnitNET.ArchitectureExceptions
+namespace ArchUnitNET.Domain.Exceptions
{
public class TypeDoesNotExistInArchitecture : Exception
{
public TypeDoesNotExistInArchitecture(string message) : base(message)
{
}
-
- public TypeDoesNotExistInArchitecture(string message, Exception innerException) : base(message, innerException)
- {
- }
}
}
\ No newline at end of file
diff --git a/ArchUnitNET/Fluent/Extensions/ArchitectureExtensions.cs b/ArchUnitNET/Domain/Extensions/ArchitectureExtensions.cs
similarity index 96%
rename from ArchUnitNET/Fluent/Extensions/ArchitectureExtensions.cs
rename to ArchUnitNET/Domain/Extensions/ArchitectureExtensions.cs
index 4d502fd1f..be9729e5e 100644
--- a/ArchUnitNET/Fluent/Extensions/ArchitectureExtensions.cs
+++ b/ArchUnitNET/Domain/Extensions/ArchitectureExtensions.cs
@@ -5,12 +5,10 @@
// SPDX-License-Identifier: Apache-2.0
using System;
-using ArchUnitNET.ArchitectureExceptions;
-using ArchUnitNET.Domain;
+using ArchUnitNET.Domain.Exceptions;
using JetBrains.Annotations;
-using Attribute = ArchUnitNET.Domain.Attribute;
-namespace ArchUnitNET.Fluent.Extensions
+namespace ArchUnitNET.Domain.Extensions
{
public static class ArchitectureExtensions
{
diff --git a/ArchUnitNET/Domain/Extensions/AttributeExtensions.cs b/ArchUnitNET/Domain/Extensions/AttributeExtensions.cs
new file mode 100644
index 000000000..cde988ae3
--- /dev/null
+++ b/ArchUnitNET/Domain/Extensions/AttributeExtensions.cs
@@ -0,0 +1,25 @@
+// Copyright 2019 Florian Gather
+// Copyright 2019 Fritz Brandhuber
+// Copyright 2020 Pavel Fischer
+//
+// SPDX-License-Identifier: Apache-2.0
+//
+
+using System.Linq;
+
+namespace ArchUnitNET.Domain.Extensions
+{
+ public static class AttributeExtensions
+ {
+ public static bool HasAttribute(this IHasAttributes a, string pattern, bool useRegularExpressions = false)
+ {
+ return a.Attributes.Any(attribute => attribute.FullNameMatches(pattern, useRegularExpressions));
+ }
+
+ public static bool OnlyHasAttributes(this IHasAttributes a, string pattern, bool useRegularExpressions = false)
+ {
+ return a.Attributes.IsNullOrEmpty() ||
+ a.Attributes.All(attribute => attribute.FullNameMatches(pattern, useRegularExpressions));
+ }
+ }
+}
\ No newline at end of file
diff --git a/ArchUnitNET/Domain/Extensions/DependencyExtensions.cs b/ArchUnitNET/Domain/Extensions/DependencyExtensions.cs
new file mode 100644
index 000000000..6a6f03967
--- /dev/null
+++ b/ArchUnitNET/Domain/Extensions/DependencyExtensions.cs
@@ -0,0 +1,56 @@
+// Copyright 2019 Florian Gather
+// Copyright 2019 Fritz Brandhuber
+// Copyright 2020 Pavel Fischer
+//
+// SPDX-License-Identifier: Apache-2.0
+//
+
+using System.Collections.Generic;
+using System.Linq;
+using ArchUnitNET.Domain.Dependencies;
+
+namespace ArchUnitNET.Domain.Extensions
+{
+ public static class DependencyExtensions
+ {
+ public static bool CallsMethod(this IHasDependencies type, string pattern, bool useRegularExpressions = false)
+ {
+ return type.GetCalledMethods().Any(member => member.FullNameMatches(pattern, useRegularExpressions));
+ }
+
+ public static IEnumerable GetCalledMethods(this IHasDependencies type)
+ {
+ return type.Dependencies.OfType()
+ .Select(dependency => (MethodMember) dependency.TargetMember);
+ }
+
+ public static bool DependsOn(this IHasDependencies c, string pattern, bool useRegularExpressions = false)
+ {
+ return c.GetTypeDependencies().Any(d => d.FullNameMatches(pattern, useRegularExpressions));
+ }
+
+
+ public static bool OnlyDependsOn(this IHasDependencies c, string pattern, bool useRegularExpressions = false)
+ {
+ return c.GetTypeDependencies().All(d => d.FullNameMatches(pattern, useRegularExpressions));
+ }
+
+ public static IEnumerable GetTypeDependencies(this IHasDependencies c)
+ {
+ return c.Dependencies.Select(dependency => dependency.Target);
+ }
+
+ public static IEnumerable GetTypeDependencies(this IHasDependencies c, Architecture architecture)
+ {
+ return c.Dependencies.Select(dependency => dependency.Target).Intersect(architecture.Types);
+ }
+
+ public static IEnumerable GetFieldTypeDependencies(this IHasDependencies type,
+ bool getBackwardsDependencies = false)
+ {
+ return getBackwardsDependencies
+ ? type.BackwardsDependencies.OfType()
+ : type.Dependencies.OfType();
+ }
+ }
+}
\ No newline at end of file
diff --git a/ArchUnitNET/Domain/Extensions/EnumerableExtensions.cs b/ArchUnitNET/Domain/Extensions/EnumerableExtensions.cs
new file mode 100644
index 000000000..3f28d866a
--- /dev/null
+++ b/ArchUnitNET/Domain/Extensions/EnumerableExtensions.cs
@@ -0,0 +1,28 @@
+// Copyright 2019 Florian Gather
+// Copyright 2019 Paula Ruiz
+// Copyright 2019 Fritz Brandhuber
+//
+// SPDX-License-Identifier: Apache-2.0
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace ArchUnitNET.Domain.Extensions
+{
+ public static class EnumerableExtensions
+ {
+ public static void ForEach(this IEnumerable source, Action action)
+ {
+ foreach (var element in source)
+ {
+ action(element);
+ }
+ }
+
+ public static bool IsNullOrEmpty(this IEnumerable source)
+ {
+ return source == null || !source.Any();
+ }
+ }
+}
\ No newline at end of file
diff --git a/ArchUnitNET/Fluent/Extensions/MemberExtensions.cs b/ArchUnitNET/Domain/Extensions/MemberExtensions.cs
similarity index 83%
rename from ArchUnitNET/Fluent/Extensions/MemberExtensions.cs
rename to ArchUnitNET/Domain/Extensions/MemberExtensions.cs
index 35bbbade9..ceebd354c 100644
--- a/ArchUnitNET/Fluent/Extensions/MemberExtensions.cs
+++ b/ArchUnitNET/Domain/Extensions/MemberExtensions.cs
@@ -6,11 +6,9 @@
using System.Collections.Generic;
using System.Linq;
-using ArchUnitNET.Domain;
-using ArchUnitNET.Domain.Dependencies.Members;
-using ArchUnitNET.Domain.Dependencies.Types;
+using ArchUnitNET.Domain.Dependencies;
-namespace ArchUnitNET.Fluent.Extensions
+namespace ArchUnitNET.Domain.Extensions
{
public static class MemberExtensions
{
@@ -69,14 +67,6 @@ public static bool HasDependencyInMethodBodyTo(this MethodMember member, string
dependency.Target.FullNameMatches(pattern, useRegularExpressions));
}
- public static IEnumerable GetFieldTypeDependencies(this IHasDependencies type,
- bool getBackwardsDependencies = false)
- {
- return getBackwardsDependencies
- ? type.BackwardsDependencies.OfType()
- : type.Dependencies.OfType();
- }
-
public static bool HasFieldTypeDependencies(this IMember member, bool getBackwardsDependencies = false)
{
return member.GetFieldTypeDependencies(getBackwardsDependencies).Any();
@@ -87,14 +77,6 @@ public static Attribute GetAttributeFromMember(this IMember member, Class attrib
return member.Attributes.Find(attribute => attribute.FullName.Equals(attributeClass.FullName));
}
- public static IEnumerable GetAttributeMemberDependencies(
- this IHasDependencies member, bool getBackwardsDependencies = false)
- {
- return getBackwardsDependencies
- ? member.BackwardsDependencies.OfType()
- : member.Dependencies.OfType();
- }
-
public static bool HasMethodSignatureDependency(this IMember member,
MethodSignatureDependency methodSignatureDependency, bool getBackwardsDependencies = false)
{
diff --git a/ArchUnitNET/Domain/Extensions/NamingExtensions.cs b/ArchUnitNET/Domain/Extensions/NamingExtensions.cs
new file mode 100644
index 000000000..110eecc8c
--- /dev/null
+++ b/ArchUnitNET/Domain/Extensions/NamingExtensions.cs
@@ -0,0 +1,81 @@
+// Copyright 2019 Florian Gather
+// Copyright 2019 Fritz Brandhuber
+// Copyright 2020 Pavel Fischer
+//
+// SPDX-License-Identifier: Apache-2.0
+//
+
+using System.Collections.Generic;
+using System.Linq;
+using System.Text.RegularExpressions;
+using ArchUnitNET.Domain.Exceptions;
+using JetBrains.Annotations;
+
+namespace ArchUnitNET.Domain.Extensions
+{
+ public static class NamingExtensions
+ {
+ public static bool NameEndsWith(this IHasName cls, string pattern)
+ {
+ return cls.Name.ToLower().EndsWith(pattern.ToLower());
+ }
+
+ public static bool NameStartsWith(this IHasName cls, string pattern)
+ {
+ return cls.Name.ToLower().StartsWith(pattern.ToLower());
+ }
+
+ public static bool NameContains(this IHasName cls, string pattern)
+ {
+ return pattern != null && cls.Name.ToLower().Contains(pattern.ToLower());
+ }
+
+ public static bool NameMatches(this IHasName cls, string pattern, bool useRegularExpressions = false)
+ {
+ if (useRegularExpressions)
+ {
+ return pattern != null && Regex.IsMatch(cls.Name, pattern);
+ }
+
+ return cls.NameContains(pattern);
+ }
+
+ public static bool FullNameMatches(this IHasName cls, string pattern, bool useRegularExpressions = false)
+ {
+ if (useRegularExpressions)
+ {
+ return pattern != null && Regex.IsMatch(cls.FullName, pattern);
+ }
+
+ return cls.FullNameContains(pattern);
+ }
+
+ public static bool FullNameContains(this IHasName cls, string pattern)
+ {
+ return pattern != null && cls.FullName.ToLower().Contains(pattern.ToLower());
+ }
+
+ [NotNull]
+ public static IEnumerable WhereNameIs(this IEnumerable source, string name)
+ where TType : IHasName
+ {
+ return source.Where(hasName => hasName.Name == name);
+ }
+
+ [CanBeNull]
+ public static TType WhereFullNameIs(this IEnumerable source, string fullName)
+ where TType : IHasName
+ {
+ var withFullName = source.Where(type => type.FullName == fullName).ToList();
+
+ if (withFullName.Count > 1)
+ {
+ 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.");
+ }
+
+ return withFullName.FirstOrDefault();
+ }
+ }
+}
\ No newline at end of file
diff --git a/ArchUnitNET/Fluent/Extensions/NullableExtensions.cs b/ArchUnitNET/Domain/Extensions/NullableExtensions.cs
similarity index 86%
rename from ArchUnitNET/Fluent/Extensions/NullableExtensions.cs
rename to ArchUnitNET/Domain/Extensions/NullableExtensions.cs
index 48234e8b7..b582f67d2 100644
--- a/ArchUnitNET/Fluent/Extensions/NullableExtensions.cs
+++ b/ArchUnitNET/Domain/Extensions/NullableExtensions.cs
@@ -4,9 +4,9 @@
//
// SPDX-License-Identifier: Apache-2.0
-using ArchUnitNET.ArchitectureExceptions;
+using ArchUnitNET.Domain.Exceptions;
-namespace ArchUnitNET.Fluent.Extensions
+namespace ArchUnitNET.Domain.Extensions
{
public static class NullableExtensions
{
diff --git a/ArchUnitNET/Domain/Extensions/TypeExtensions.cs b/ArchUnitNET/Domain/Extensions/TypeExtensions.cs
new file mode 100644
index 000000000..df73463f5
--- /dev/null
+++ b/ArchUnitNET/Domain/Extensions/TypeExtensions.cs
@@ -0,0 +1,189 @@
+// Copyright 2019 Florian Gather
+// Copyright 2019 Paula Ruiz
+// Copyright 2019 Fritz Brandhuber
+//
+// SPDX-License-Identifier: Apache-2.0
+
+using System.Collections.Generic;
+using System.Linq;
+using ArchUnitNET.Domain.Dependencies;
+
+namespace ArchUnitNET.Domain.Extensions
+{
+ public static class TypeExtensions
+ {
+ public static IEnumerable> SlicedBy(this IEnumerable source, string fullName)
+ {
+ return source.GroupBy(type => type.FullName)
+ .Select(sliceItems => new Slice(sliceItems.Key, sliceItems.ToList()));
+ }
+
+ public static IEnumerable GetAssignableTypes(this IType type)
+ {
+ switch (type)
+ {
+ case Interface intf:
+ return intf.ImplementedInterfaces.Append(intf);
+ case Class cls:
+ return cls.InheritedClasses.Append(cls).Concat(cls.ImplementedInterfaces);
+ default:
+ return Enumerable.Empty();
+ }
+ }
+
+ public static IEnumerable GetPropertyMembersWithName(this IType type, string name)
+ {
+ return type.GetPropertyMembers().WhereNameIs(name);
+ }
+
+ public static bool HasPropertyMemberWithName(this IType type, string name)
+ {
+ return !type.GetPropertyMembersWithName(name).IsNullOrEmpty();
+ }
+
+ public static IEnumerable GetFieldMembersWithName(this IType type, string name)
+ {
+ return type.GetFieldMembers().WhereNameIs(name);
+ }
+
+ public static bool HasFieldMemberWithName(this IType type, string name)
+ {
+ return !type.GetFieldMembersWithName(name).IsNullOrEmpty();
+ }
+
+ public static IEnumerable GetMethodMembersWithName(this IType type, string name)
+ {
+ return type.GetMethodMembers().WhereNameIs(name);
+ }
+
+ public static bool HasMethodMemberWithName(this IType type, string name)
+ {
+ return !type.GetMethodMembersWithName(name).IsNullOrEmpty();
+ }
+
+ public static IEnumerable GetMembersWithName(this IType type, string name)
+ {
+ return type.Members.WhereNameIs(name);
+ }
+
+ public static bool HasMemberWithName(this IType type, string name)
+ {
+ return !type.GetMembersWithName(name).IsNullOrEmpty();
+ }
+
+ public static PropertyMember GetPropertyMemberWithFullName(this IType type, string fullName)
+ {
+ return type.GetPropertyMembers().WhereFullNameIs(fullName);
+ }
+
+ public static bool HasPropertyMemberWithFullName(this IType type, string fullname)
+ {
+ return type.GetPropertyMemberWithFullName(fullname) != null;
+ }
+
+ public static MethodMember GetMethodMemberWithFullName(this IType type, string fullName)
+ {
+ return type.GetMethodMembers().WhereFullNameIs(fullName);
+ }
+
+ public static bool HasMethodMemberWithFullName(this IType type, string fullname)
+ {
+ return type.GetMethodMemberWithFullName(fullname) != null;
+ }
+
+ public static FieldMember GetFieldMemberWithFullName(this IType type, string fullName)
+ {
+ return type.GetFieldMembers().WhereFullNameIs(fullName);
+ }
+
+ public static bool HasFieldMemberWithFullName(this IType type, string fullname)
+ {
+ return type.GetFieldMemberWithFullName(fullname) != null;
+ }
+
+ public static IMember GetMemberWithFullName(this IType type, string fullName)
+ {
+ return type.Members.WhereFullNameIs(fullName);
+ }
+
+ public static bool HasMemberWithFullName(this IType type, string fullname)
+ {
+ return type.GetMemberWithFullName(fullname) != null;
+ }
+
+ public static Attribute GetAttributeOfType(this IType type, Class attributeClass)
+ {
+ return type.Attributes.Find(attribute => attribute.FullName.Equals(attributeClass.FullName));
+ }
+
+ public static bool ResidesInNamespace(this IType e, string pattern, bool useRegularExpressions = false)
+ {
+ return e.Namespace.FullNameMatches(pattern, useRegularExpressions);
+ }
+
+ public static bool ResidesInAssembly(this IType e, string pattern, bool useRegularExpressions = false)
+ {
+ return e.Assembly.FullNameMatches(pattern, useRegularExpressions);
+ }
+
+ public static bool IsDeclaredAsFieldIn(this IType type, string pattern, bool useRegularExpressions = false)
+ {
+ return type.GetFieldTypeDependencies(true).Any(dependency =>
+ dependency.Target.FullNameMatches(pattern, useRegularExpressions));
+ }
+
+ public static bool HasDependency(this IType type, ITypeDependency dependency)
+ {
+ return type.Dependencies.Contains(dependency);
+ }
+
+ public static bool HasDependencies(this IType type, IEnumerable dependencies)
+ {
+ return dependencies.All(dependency => type.Dependencies.Contains(dependency));
+ }
+
+ public static IEnumerable GetPropertyMembers(this IType type)
+ {
+ return type.Members.OfType();
+ }
+
+ public static IEnumerable GetFieldMembers(this IType type)
+ {
+ return type.Members.OfType();
+ }
+
+ public static IEnumerable GetMethodMembers(this IType type)
+ {
+ return type.Members.OfType();
+ }
+
+ public static IEnumerable GetConstructors(this IType type)
+ {
+ return type.GetMethodMembers().Where(method => method.IsConstructor());
+ }
+
+ public static IEnumerable GetAttributeTypeDependencies(this IType type,
+ bool getBackwardsDependencies = false)
+ {
+ return getBackwardsDependencies
+ ? type.BackwardsDependencies.OfType()
+ : type.Dependencies.OfType();
+ }
+
+ public static IEnumerable GetImplementsInterfaceDependencies(this IType type,
+ bool getBackwardsDependencies = false)
+ {
+ return getBackwardsDependencies
+ ? type.BackwardsDependencies.OfType()
+ : type.Dependencies.OfType();
+ }
+
+ public static IEnumerable GetInheritsBaseClassDependencies(this IType type,
+ bool getBackwardsDependencies = false)
+ {
+ return getBackwardsDependencies
+ ? type.BackwardsDependencies.OfType()
+ : type.Dependencies.OfType();
+ }
+ }
+}
\ No newline at end of file
diff --git a/ArchUnitNET/Domain/FieldMember.cs b/ArchUnitNET/Domain/FieldMember.cs
index 2ad9e63ff..144f5018e 100644
--- a/ArchUnitNET/Domain/FieldMember.cs
+++ b/ArchUnitNET/Domain/FieldMember.cs
@@ -5,8 +5,7 @@
// SPDX-License-Identifier: Apache-2.0
using System.Collections.Generic;
-using ArchUnitNET.Domain.Dependencies.Members;
-using ArchUnitNET.Domain.Dependencies.Types;
+using ArchUnitNET.Domain.Dependencies;
namespace ArchUnitNET.Domain
{
diff --git a/ArchUnitNET/Domain/IHasDependencies.cs b/ArchUnitNET/Domain/IHasDependencies.cs
index 195d4cb55..29fa98b34 100644
--- a/ArchUnitNET/Domain/IHasDependencies.cs
+++ b/ArchUnitNET/Domain/IHasDependencies.cs
@@ -5,7 +5,7 @@
// SPDX-License-Identifier: Apache-2.0
using System.Collections.Generic;
-using ArchUnitNET.Domain.Dependencies.Types;
+using ArchUnitNET.Domain.Dependencies;
namespace ArchUnitNET.Domain
{
diff --git a/ArchUnitNET/Domain/IMember.cs b/ArchUnitNET/Domain/IMember.cs
index e79351722..f497db8cc 100644
--- a/ArchUnitNET/Domain/IMember.cs
+++ b/ArchUnitNET/Domain/IMember.cs
@@ -5,7 +5,7 @@
// SPDX-License-Identifier: Apache-2.0
using System.Collections.Generic;
-using ArchUnitNET.Domain.Dependencies.Members;
+using ArchUnitNET.Domain.Dependencies;
namespace ArchUnitNET.Domain
{
diff --git a/ArchUnitNET/Domain/Interface.cs b/ArchUnitNET/Domain/Interface.cs
index 67f526a3e..b2128bd8f 100644
--- a/ArchUnitNET/Domain/Interface.cs
+++ b/ArchUnitNET/Domain/Interface.cs
@@ -5,8 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
using System.Collections.Generic;
-using ArchUnitNET.Domain.Dependencies.Types;
-using ArchUnitNET.Fluent.Extensions;
+using ArchUnitNET.Domain.Dependencies;
+using ArchUnitNET.Domain.Extensions;
namespace ArchUnitNET.Domain
{
diff --git a/ArchUnitNET/Domain/MemberList.cs b/ArchUnitNET/Domain/MemberList.cs
index 894c85686..90745c802 100644
--- a/ArchUnitNET/Domain/MemberList.cs
+++ b/ArchUnitNET/Domain/MemberList.cs
@@ -7,7 +7,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
-using ArchUnitNET.Fluent.Extensions;
+using ArchUnitNET.Domain.Extensions;
using Equ;
namespace ArchUnitNET.Domain
diff --git a/ArchUnitNET/Domain/MethodMember.cs b/ArchUnitNET/Domain/MethodMember.cs
index 41ab5e0d2..7f3c2ae7b 100644
--- a/ArchUnitNET/Domain/MethodMember.cs
+++ b/ArchUnitNET/Domain/MethodMember.cs
@@ -5,8 +5,7 @@
// SPDX-License-Identifier: Apache-2.0
using System.Collections.Generic;
-using ArchUnitNET.Domain.Dependencies.Members;
-using ArchUnitNET.Domain.Dependencies.Types;
+using ArchUnitNET.Domain.Dependencies;
namespace ArchUnitNET.Domain
{
diff --git a/ArchUnitNET/Domain/PropertyMember.cs b/ArchUnitNET/Domain/PropertyMember.cs
index 05aa95e61..3913242d3 100644
--- a/ArchUnitNET/Domain/PropertyMember.cs
+++ b/ArchUnitNET/Domain/PropertyMember.cs
@@ -5,8 +5,7 @@
// SPDX-License-Identifier: Apache-2.0
using System.Collections.Generic;
-using ArchUnitNET.Domain.Dependencies.Members;
-using ArchUnitNET.Domain.Dependencies.Types;
+using ArchUnitNET.Domain.Dependencies;
using Equ;
using JetBrains.Annotations;
using static ArchUnitNET.Domain.Visibility;
@@ -32,8 +31,12 @@ public PropertyMember(IType declaringType, string name, string fullName, IType t
public Visibility SetterVisibility => Setter?.Visibility ?? NotAccessible;
public Visibility GetterVisibility => Getter?.Visibility ?? NotAccessible;
- [CanBeNull] public MethodMember Getter { get; }
- [CanBeNull] public MethodMember Setter { get; }
+ [CanBeNull]
+ public MethodMember Getter { get; }
+
+ [CanBeNull]
+ public MethodMember Setter { get; }
+
public FieldMember BackingField { get; internal set; }
public Visibility Visibility => GetterVisibility < SetterVisibility ? GetterVisibility : SetterVisibility;
diff --git a/ArchUnitNET/Domain/Slice.cs b/ArchUnitNET/Domain/Slice.cs
index cac95a640..6dffb3e66 100644
--- a/ArchUnitNET/Domain/Slice.cs
+++ b/ArchUnitNET/Domain/Slice.cs
@@ -6,7 +6,7 @@
using System.Collections.Generic;
using System.Linq;
-using ArchUnitNET.Domain.Dependencies.Types;
+using ArchUnitNET.Domain.Dependencies;
using Equ;
namespace ArchUnitNET.Domain
diff --git a/ArchUnitNET/Fluent/Extensions/StaticConstants.cs b/ArchUnitNET/Domain/StaticConstants.cs
similarity index 55%
rename from ArchUnitNET/Fluent/Extensions/StaticConstants.cs
rename to ArchUnitNET/Domain/StaticConstants.cs
index 63ad9fa7f..b4c614628 100644
--- a/ArchUnitNET/Fluent/Extensions/StaticConstants.cs
+++ b/ArchUnitNET/Domain/StaticConstants.cs
@@ -6,19 +6,12 @@
// ReSharper disable InconsistentNaming
-namespace ArchUnitNET.Fluent.Extensions
+namespace ArchUnitNET.Domain
{
public static class StaticConstants
{
public const string BackingField = "k__BackingField";
public const string ConstructorNameBase = ".ctor";
- public const string ArchUnitNETTestsFluentNamespace = "ArchUnitNETTests.Fluent";
-
- public const string ArchUnitNETTestsDependenciesAttributesNamespace =
- "ArchUnitNETTests.Dependencies.Attributes";
-
public const string SystemNamespace = "System";
- public const string GuidClassName = "Guid";
- public const string SystemGuidFullName = SystemNamespace + "." + GuidClassName;
}
}
\ No newline at end of file
diff --git a/ArchUnitNET/Domain/TypeDependencyComparer.cs b/ArchUnitNET/Domain/TypeDependencyComparer.cs
index 983fe29e5..e73e3d248 100644
--- a/ArchUnitNET/Domain/TypeDependencyComparer.cs
+++ b/ArchUnitNET/Domain/TypeDependencyComparer.cs
@@ -6,7 +6,7 @@
//
using System.Collections.Generic;
-using ArchUnitNET.Domain.Dependencies.Types;
+using ArchUnitNET.Domain.Dependencies;
namespace ArchUnitNET.Domain
{
diff --git a/ArchUnitNET/Domain/TypeList.cs b/ArchUnitNET/Domain/TypeList.cs
deleted file mode 100644
index 9cc58545b..000000000
--- a/ArchUnitNET/Domain/TypeList.cs
+++ /dev/null
@@ -1,387 +0,0 @@
-// Copyright 2019 Florian Gather
-// Copyright 2019 Paula Ruiz
-// Copyright 2019 Fritz Brandhuber
-//
-// SPDX-License-Identifier: Apache-2.0
-
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Linq;
-using ArchUnitNET.Fluent;
-using ArchUnitNET.Fluent.Extensions;
-using Equ;
-using JetBrains.Annotations;
-
-namespace ArchUnitNET.Domain
-{
- public class TypeList : MemberwiseEquatable, IList>, IObjectProvider
- {
- private readonly IList> _typeProviderList;
- [CanBeNull] private string _customDescription;
-
- public TypeList()
- {
- _typeProviderList = new List>();
- }
-
- public TypeList(IList> typeProviderList, string description = null)
- {
- _typeProviderList = typeProviderList;
- _customDescription = description;
- }
-
- public TypeList(Type firstType, params Type[] moreTypes) : this()
- {
- Add(firstType, moreTypes);
- }
-
- public TypeList(IEnumerable types) : this()
- {
- Add(types);
- }
-
- public TypeList(IType firstType, params IType[] moreTypes) : this()
- {
- Add(firstType, moreTypes);
- }
-
- public TypeList(IEnumerable types) : this()
- {
- Add(types);
- }
-
- public TypeList(IEnumerable patterns, bool useRegularExpressions = false) : this()
- {
- Add(patterns, useRegularExpressions);
- }
-
- public TypeList(string pattern, bool useRegularExpressions = false) : this()
- {
- Add(pattern, useRegularExpressions);
- }
-
- public TypeList(string pattern, params string[] morePatterns) : this()
- {
- Add(pattern, morePatterns);
- }
-
- public void Add(IObjectProvider typeProvider)
- {
- _typeProviderList.Add(typeProvider);
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return _typeProviderList.GetEnumerator();
- }
-
- public IEnumerator> GetEnumerator()
- {
- return _typeProviderList.GetEnumerator();
- }
-
- public void Clear()
- {
- _typeProviderList.Clear();
- }
-
- public bool Contains(IObjectProvider item)
- {
- return _typeProviderList.Contains(item);
- }
-
- public void CopyTo(IObjectProvider[] array, int arrayIndex)
- {
- _typeProviderList.CopyTo(array, arrayIndex);
- }
-
- public bool Remove(IObjectProvider item)
- {
- return _typeProviderList.Remove(item);
- }
-
- public int Count => _typeProviderList.Count;
- public bool IsReadOnly => _typeProviderList.IsReadOnly;
-
- public int IndexOf(IObjectProvider item)
- {
- return _typeProviderList.IndexOf(item);
- }
-
- public void Insert(int index, IObjectProvider item)
- {
- _typeProviderList.Insert(index, item);
- }
-
- public void RemoveAt(int index)
- {
- _typeProviderList.RemoveAt(index);
- }
-
- public IObjectProvider this[int index]
- {
- get => _typeProviderList[index];
- set => _typeProviderList[index] = value;
- }
-
- public string Description => _customDescription ?? _typeProviderList
- .Aggregate("",
- (current, typeProvider) => current + "\r\n" + typeProvider.Description)
- .Remove(0, 2);
-
- public IEnumerable GetObjects(Architecture architecture)
- {
- return architecture.GetOrCreateObjects(this,
- arch => _typeProviderList.SelectMany(provider => provider.GetObjects(arch)).Distinct());
- }
-
- public TypeList As(string description)
- {
- _customDescription = description;
- return this;
- }
-
- public void Add(Type firstType, params Type[] moreTypes)
- {
- Add(new TypeCollection(firstType, moreTypes));
- }
-
- public void Add(IEnumerable types)
- {
- Add(new TypeCollection(types));
- }
-
- public void Add(IType firstType, params IType[] moreTypes)
- {
- Add(new ArchTypeCollection(firstType, moreTypes));
- }
-
- public void Add(IEnumerable types)
- {
- Add(new ArchTypeCollection(types));
- }
-
- public void Add(IEnumerable patterns, bool useRegularExpressions = false)
- {
- Add(new PatternCollection(patterns, useRegularExpressions));
- }
-
- public void Add(string pattern, params string[] morePatterns)
- {
- Add(new PatternCollection(pattern, morePatterns));
- }
-
- public void Add(string pattern, bool useRegularExpressions = false)
- {
- Add(new PatternCollection(pattern, useRegularExpressions));
- }
-
- private new bool Equals(TypeList other)
- {
- if (ReferenceEquals(null, other))
- {
- return false;
- }
-
- if (ReferenceEquals(this, other))
- {
- return true;
- }
-
- return base.Equals(other) &&
- _typeProviderList.SequenceEqual(other._typeProviderList) &&
- _customDescription == other._customDescription;
- }
-
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(null, obj))
- {
- return false;
- }
-
- if (ReferenceEquals(this, obj))
- {
- return true;
- }
-
- return obj.GetType() == GetType() && Equals((TypeList) obj);
- }
-
- public override int GetHashCode()
- {
- unchecked
- {
- var hashCode = base.GetHashCode();
- hashCode = (hashCode * 397) ^ (_customDescription != null ? _customDescription.GetHashCode() : 0);
- _typeProviderList.Aggregate(hashCode,
- (current, predicateElement) =>
- (current * 397) ^ (predicateElement != null ? predicateElement.GetHashCode() : 0));
- return hashCode;
- }
- }
-
- private abstract class Collection : IObjectProvider
- {
- protected readonly List Items;
-
- protected Collection(IEnumerable item)
- {
- Items = item.ToList();
- }
-
- protected Collection(T firstItem, params T[] moreItems)
- {
- Items = new List {firstItem};
- Items.AddRange(moreItems);
- }
-
- public abstract string Description { get; }
- public abstract IEnumerable GetObjects(Architecture architecture);
-
- public override string ToString()
- {
- return Description;
- }
-
- protected bool Equals(Collection other)
- {
- return Items.SequenceEqual(other.Items);
- }
-
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(null, obj))
- {
- return false;
- }
-
- if (ReferenceEquals(this, obj))
- {
- return true;
- }
-
- return obj.GetType() == GetType() && Equals((Collection) obj);
- }
-
- public override int GetHashCode()
- {
- unchecked
- {
- return Items != null
- ? Items.Aggregate(397,
- (current, item) => (current * 397) ^ (item != null ? item.GetHashCode() : 0))
- : 0;
- }
- }
- }
-
- private class TypeCollection : Collection
- {
- public TypeCollection(IEnumerable types) : base(types)
- {
- }
-
- public TypeCollection(Type firstType, params Type[] moreTypes) : base(firstType, moreTypes)
- {
- }
-
- public override string Description => Items
- .Aggregate("", (current, type) => current + ", " + type.Name).Remove(0, 2);
-
- public override IEnumerable GetObjects(Architecture architecture)
- {
- return architecture.GetOrCreateObjects(this, arch => Items.Select(arch.GetITypeOfType).Distinct());
- }
- }
-
- private class ArchTypeCollection : Collection
- {
- public ArchTypeCollection(IEnumerable types) : base(types)
- {
- }
-
- public ArchTypeCollection(IType firstType, params IType[] moreTypes) : base(firstType, moreTypes)
- {
- }
-
- public override string Description => Items
- .Aggregate("", (current, type) => current + ", " + type.Name).Remove(0, 2);
-
- public override IEnumerable GetObjects(Architecture architecture)
- {
- return Items.Distinct();
- }
- }
-
- private class PatternCollection : Collection
- {
- private readonly bool _useRegularExpressions;
-
- public PatternCollection(IEnumerable patterns, bool useRegularExpressions = false) : base(patterns)
- {
- _useRegularExpressions = useRegularExpressions;
- }
-
- public PatternCollection(string pattern, params string[] morePatterns) : base(pattern, morePatterns)
- {
- _useRegularExpressions = false;
- }
-
- public PatternCollection(string pattern, bool useRegularExpressions = false) : base(pattern)
- {
- _useRegularExpressions = useRegularExpressions;
- }
-
-
- public override string Description => Items
- .Aggregate("", (current, pattern) => current + ", \"" + pattern + "\"").Remove(0, 2);
-
- public override IEnumerable GetObjects(Architecture architecture)
- {
- IEnumerable CreateFunction(Architecture arch)
- {
- var types = new List();
- foreach (var pattern in Items)
- {
- types.AddRange(arch.Types.Where(type =>
- type.FullNameMatches(pattern, _useRegularExpressions)));
- }
-
- return types.Distinct();
- }
-
- return architecture.GetOrCreateObjects(this, CreateFunction);
- }
-
- private bool Equals(PatternCollection other)
- {
- return base.Equals(other) && _useRegularExpressions == other._useRegularExpressions;
- }
-
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(null, obj))
- {
- return false;
- }
-
- if (ReferenceEquals(this, obj))
- {
- return true;
- }
-
- return obj.GetType() == GetType() && Equals((PatternCollection) obj);
- }
-
- public override int GetHashCode()
- {
- unchecked
- {
- return (base.GetHashCode() * 397) ^ _useRegularExpressions.GetHashCode();
- }
- }
- }
- }
-}
\ No newline at end of file
diff --git a/ArchUnitNET/Fluent/ArchRuleCreator.ConditionManager.cs b/ArchUnitNET/Fluent/ArchRuleCreator.ConditionManager.cs
deleted file mode 100644
index 4a1e325b6..000000000
--- a/ArchUnitNET/Fluent/ArchRuleCreator.ConditionManager.cs
+++ /dev/null
@@ -1,311 +0,0 @@
-// Copyright 2019 Florian Gather
-// Copyright 2019 Paula Ruiz
-// Copyright 2019 Fritz Brandhuber
-//
-// SPDX-License-Identifier: Apache-2.0
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using ArchUnitNET.Domain;
-using ArchUnitNET.Fluent.Conditions;
-using ArchUnitNET.Fluent.Extensions;
-using ArchUnitNET.Fluent.Predicates;
-using JetBrains.Annotations;
-
-namespace ArchUnitNET.Fluent
-{
- public partial class ArchRuleCreator
- {
- private class ConditionManager : IHasDescription where T : ICanBeAnalyzed
- {
- private readonly List> _conditionElements;
- private Type _referenceTypeTemp;
- private object _relatedObjectsTemp;
- private object _relationConditionTemp;
-
- public ConditionManager()
- {
- _conditionElements = new List>
- {
- new ConditionElement(LogicalConjunctionDefinition.ForwardSecondValue)
- };
- }
-
- public string Description => _conditionElements
- .Aggregate("", (current, conditionElement) => current + " " + conditionElement.Description).Trim();
-
- public void BeginComplexCondition(IObjectProvider relatedObjects,
- RelationCondition relationCondition)
- where TRelatedType : ICanBeAnalyzed
- {
- _relatedObjectsTemp = relatedObjects;
- _relationConditionTemp = relationCondition;
- _referenceTypeTemp = typeof(TRelatedType);
- }
-
- public void ContinueComplexCondition(IPredicate filter)
- where TRelatedType : ICanBeAnalyzed
- {
- if (typeof(TRelatedType) == _referenceTypeTemp)
- {
- AddCondition(
- new ComplexCondition((IObjectProvider) _relatedObjectsTemp,
- (RelationCondition) _relationConditionTemp, filter));
- }
- else
- {
- throw new InvalidCastException(
- "ContinueComplexCondition() has to be called with the same generic type argument that was used for BeginComplexCondition().");
- }
- }
-
- public void AddCondition(ICondition condition)
- {
- _conditionElements.Last().SetCondition(condition);
- }
-
- public void AddReason(string reason)
- {
- _conditionElements.Last().AddReason(reason);
- }
-
- public void SetCustomDescription(string description)
- {
- _conditionElements.ForEach(conditionElement => conditionElement.SetCustomDescription(""));
- _conditionElements.Last().SetCustomDescription(description);
- }
-
- public void SetNextLogicalConjunction(LogicalConjunction logicalConjunction)
- {
- _conditionElements.Add(new ConditionElement(logicalConjunction));
- }
-
- private bool CheckEmpty()
- {
- return _conditionElements.Aggregate(true,
- (currentResult, conditionElement) => conditionElement.CheckEmpty(currentResult));
- }
-
- public IEnumerable EvaluateConditions(IEnumerable filteredObjects,
- Architecture architecture, ICanBeEvaluated archRuleCreator)
- {
- var filteredObjectsList = filteredObjects.ToList();
- if (filteredObjectsList.IsNullOrEmpty())
- {
- yield return new EvaluationResult(null, CheckEmpty(), "There are no objects matching the criteria",
- archRuleCreator, architecture);
- yield break;
- }
-
- var conditionResults = _conditionElements.Select(conditionElement =>
- conditionElement.Check(filteredObjectsList, architecture).ToList()).ToList();
-
- for (var i = 0; i < filteredObjectsList.Count; i++)
- {
- yield return CreateEvaluationResult(conditionResults.Select(results => results[i]), architecture,
- archRuleCreator);
- }
- }
-
- private static EvaluationResult CreateEvaluationResult(
- IEnumerable conditionElementResults,
- Architecture architecture, ICanBeEvaluated archRuleCreator)
- {
- var conditionElementResultsList = conditionElementResults.ToList();
- var analyzedObject = conditionElementResultsList.First().ConditionResult.AnalyzedObject;
- var passRule = conditionElementResultsList.Aggregate(true,
- (currentResult, conditionElementResult) =>
- conditionElementResult.LogicalConjunction.Evaluate(currentResult,
- conditionElementResult.ConditionResult.Pass));
- var description = analyzedObject.FullName;
- if (passRule)
- {
- description += " passed";
- }
- else
- {
- var first = true;
- var failDescriptionCache =
- new List(); //Prevent failDescriptions like "... failed because ... is public and is public"
- foreach (var conditionResult in conditionElementResultsList.Select(result => result.ConditionResult)
- .Where(condResult =>
- !condResult.Pass && !failDescriptionCache.Contains(condResult.FailDescription)))
- {
- if (!first)
- {
- description += " and";
- }
-
- description += " " + conditionResult.FailDescription;
- failDescriptionCache.Add(conditionResult.FailDescription);
- first = false;
- }
- }
-
- return new EvaluationResult(analyzedObject, passRule, description, archRuleCreator, architecture);
- }
-
- public override string ToString()
- {
- return Description;
- }
-
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(null, obj))
- {
- return false;
- }
-
- if (ReferenceEquals(this, obj))
- {
- return true;
- }
-
- return obj.GetType() == GetType() && Equals((ConditionManager) obj);
- }
-
- public override int GetHashCode()
- {
- unchecked
- {
- return _conditionElements.Aggregate(397,
- (current, conditionElement) =>
- (current * 397) ^ (conditionElement != null ? conditionElement.GetHashCode() : 0));
- }
- }
-
- private bool Equals(ConditionManager other)
- {
- return _conditionElements.SequenceEqual(other._conditionElements) &&
- _referenceTypeTemp == other._referenceTypeTemp &&
- _relationConditionTemp == other._relationConditionTemp;
- }
-
-#pragma warning disable 693
- private class ConditionElement : IHasDescription where T : ICanBeAnalyzed
- {
- private readonly LogicalConjunction _logicalConjunction;
- private ICondition _condition;
- [CanBeNull] private string _customDescription;
- private string _reason;
-
- public ConditionElement(LogicalConjunction logicalConjunction)
- {
- _condition = null;
- _logicalConjunction = logicalConjunction;
- _reason = "";
- }
-
- public string Description => _customDescription ?? (_condition == null
- ? ""
- : (_logicalConjunction.Description + " should " +
- _condition.GetShortDescription() + " " + _reason).Trim());
-
- public void AddReason(string reason)
- {
- if (_condition == null)
- {
- throw new InvalidOperationException(
- "Can't add a reason to a ConditionElement before the condition is set.");
- }
-
- if (_reason != "")
- {
- throw new InvalidOperationException(
- "Can't add a reason to a ConditionElement which already has a reason.");
- }
-
- _reason = "because " + reason;
- }
-
- public void SetCondition(ICondition condition)
- {
- _condition = condition;
- }
-
- public void SetCustomDescription(string description)
- {
- _customDescription = description;
- }
-
- public IEnumerable Check(IEnumerable objects, Architecture architecture)
- {
- if (_condition == null)
- {
- throw new InvalidOperationException(
- "Can't check a ConditionElement before the condition is set.");
- }
-
- return _condition.Check(objects, architecture)
- .Select(result => new ConditionElementResult(result, _logicalConjunction));
- }
-
- public bool CheckEmpty(bool currentResult)
- {
- if (_condition == null)
- {
- throw new InvalidOperationException(
- "Can't check a ConditionElement before the condition is set.");
- }
-
- return _logicalConjunction.Evaluate(currentResult, _condition.CheckEmpty());
- }
-
- public override string ToString()
- {
- return Description;
- }
-
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(null, obj))
- {
- return false;
- }
-
- if (ReferenceEquals(this, obj))
- {
- return true;
- }
-
- return obj.GetType() == GetType() && Equals((ConditionElement) obj);
- }
-
- private bool Equals(ConditionElement other)
- {
- return Equals(_logicalConjunction, other._logicalConjunction) &&
- Equals(_condition, other._condition) &&
- _customDescription == other._customDescription &&
- _reason == other._reason;
- }
-
- public override int GetHashCode()
- {
- unchecked
- {
- var hashCode = _logicalConjunction != null ? _logicalConjunction.GetHashCode() : 0;
- hashCode = (hashCode * 397) ^ (_condition != null ? _condition.GetHashCode() : 0);
- hashCode = (hashCode * 397) ^
- (_customDescription != null ? _customDescription.GetHashCode() : 0);
- hashCode = (hashCode * 397) ^ (_reason != null ? _reason.GetHashCode() : 0);
- return hashCode;
- }
- }
- }
-
- private class ConditionElementResult
- {
- public readonly ConditionResult ConditionResult;
- public readonly LogicalConjunction LogicalConjunction;
-
- public ConditionElementResult(ConditionResult conditionResult, LogicalConjunction logicalConjunction)
- {
- ConditionResult = conditionResult;
- LogicalConjunction = logicalConjunction;
- }
- }
- }
- }
-}
\ No newline at end of file
diff --git a/ArchUnitNET/Fluent/ArchRuleCreator.PredicateManager.cs b/ArchUnitNET/Fluent/ArchRuleCreator.PredicateManager.cs
deleted file mode 100644
index ac1135fe1..000000000
--- a/ArchUnitNET/Fluent/ArchRuleCreator.PredicateManager.cs
+++ /dev/null
@@ -1,216 +0,0 @@
-// Copyright 2019 Florian Gather
-// Copyright 2019 Paula Ruiz
-// Copyright 2019 Fritz Brandhuber
-//
-// SPDX-License-Identifier: Apache-2.0
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using ArchUnitNET.Domain;
-using ArchUnitNET.Fluent.Extensions;
-using ArchUnitNET.Fluent.Predicates;
-using JetBrains.Annotations;
-
-namespace ArchUnitNET.Fluent
-{
- public partial class ArchRuleCreator
- {
- private class PredicateManager : IHasDescription where T : ICanBeAnalyzed
- {
- private const string NotSet = "not set";
- private readonly BasicObjectProvider _basicObjectProvider;
- private readonly List> _predicateElements;
- private bool _hasCustomDescription;
-
- public PredicateManager(BasicObjectProvider basicObjectProvider)
- {
- _basicObjectProvider = basicObjectProvider;
- _predicateElements = new List>
- {
- new PredicateElement(LogicalConjunctionDefinition.ForwardSecondValue,
- new SimplePredicate(t => true, NotSet))
- };
- _hasCustomDescription = false;
- }
-
- public string Description => _hasCustomDescription
- ? _predicateElements.Aggregate("",
- (current, objectFilterElement) => current + " " + objectFilterElement.Description)
- : _predicateElements.First().Description == NotSet
- ? _basicObjectProvider.Description
- : _basicObjectProvider.Description + " that" + _predicateElements.Aggregate("",
- (current, objectFilterElement) => current + " " + objectFilterElement.Description);
-
- public IEnumerable GetObjects(Architecture architecture)
- {
- var objects = _basicObjectProvider.GetObjects(architecture).ToList();
- IEnumerable filteredObjects = new List();
- return _predicateElements.Aggregate(filteredObjects,
- (current, predicateElement) => predicateElement.CheckPredicate(current, objects, architecture));
- }
-
- public void AddPredicate(IPredicate predicate)
- {
- _predicateElements.Last().SetPredicate(predicate);
- }
-
- public void AddReason(string reason)
- {
- _predicateElements.Last().AddReason(reason);
- }
-
- public void SetCustomDescription(string description)
- {
- _hasCustomDescription = true;
- _predicateElements.ForEach(predicateElement => predicateElement.SetCustomDescription(""));
- _predicateElements.Last().SetCustomDescription(description);
- }
-
- public void SetNextLogicalConjunction(LogicalConjunction logicalConjunction)
- {
- _predicateElements.Add(new PredicateElement(logicalConjunction));
- }
-
- public override string ToString()
- {
- return Description;
- }
-
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(null, obj))
- {
- return false;
- }
-
- if (ReferenceEquals(this, obj))
- {
- return true;
- }
-
- return obj.GetType() == GetType() && Equals((PredicateManager) obj);
- }
-
- private bool Equals(PredicateManager other)
- {
- return Equals(_basicObjectProvider, other._basicObjectProvider) &&
- _predicateElements.SequenceEqual(other._predicateElements) &&
- _hasCustomDescription == other._hasCustomDescription;
- }
-
- public override int GetHashCode()
- {
- unchecked
- {
- var hashCode = _basicObjectProvider != null ? _basicObjectProvider.GetHashCode() : 0;
- return _predicateElements.Aggregate(hashCode,
- (current, predicateElement) =>
- (current * 397) ^ (predicateElement != null ? predicateElement.GetHashCode() : 0));
- }
- }
-
-#pragma warning disable 693
- private class PredicateElement : IHasDescription where T : ICanBeAnalyzed
- {
- private readonly LogicalConjunction _logicalConjunction;
- [CanBeNull] private string _customDescription;
- private IPredicate _predicate;
- private string _reason;
-
- public PredicateElement(LogicalConjunction logicalConjunction, IPredicate predicate = null)
- {
- _predicate = predicate;
- _logicalConjunction = logicalConjunction;
- _reason = "";
- }
-
- public string Description => _customDescription ?? (_predicate == null
- ? _logicalConjunction.Description
- : (_logicalConjunction.Description + " " +
- _predicate.GetShortDescription() + " " + _reason).Trim());
-
- public void AddReason(string reason)
- {
- if (_predicate == null)
- {
- throw new InvalidOperationException(
- "Can't add a reason to a PredicateElement before the predicate is set.");
- }
-
- if (_reason != "")
- {
- throw new InvalidOperationException(
- "Can't add a reason to a PredicateElement which already has a reason.");
- }
-
- _reason = "because " + reason;
- }
-
- public void SetCustomDescription(string description)
- {
- _customDescription = description;
- }
-
- public void SetPredicate(IPredicate predicate)
- {
- _predicate = predicate;
- }
-
- public IEnumerable CheckPredicate(IEnumerable currentObjects, IEnumerable allObjects,
- Architecture architecture)
- {
- if (_predicate == null)
- {
- throw new InvalidOperationException(
- "Can't check a PredicateElement before the predicate is set.");
- }
-
- return _logicalConjunction.Evaluate(currentObjects,
- _predicate.GetMatchingObjects(allObjects, architecture));
- }
-
- public override string ToString()
- {
- return Description;
- }
-
- private bool Equals(PredicateElement other)
- {
- return Equals(_logicalConjunction, other._logicalConjunction) &&
- _customDescription == other._customDescription &&
- Equals(_predicate, other._predicate) &&
- _reason == other._reason;
- }
-
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(null, obj))
- {
- return false;
- }
-
- if (ReferenceEquals(this, obj))
- {
- return true;
- }
-
- return obj.GetType() == GetType() && Equals((PredicateElement) obj);
- }
-
- public override int GetHashCode()
- {
- unchecked
- {
- var hashCode = _logicalConjunction != null ? _logicalConjunction.GetHashCode() : 0;
- hashCode = (hashCode * 397) ^
- (_customDescription != null ? _customDescription.GetHashCode() : 0);
- hashCode = (hashCode * 397) ^ (_predicate != null ? _predicate.GetHashCode() : 0);
- hashCode = (hashCode * 397) ^ (_reason != null ? _reason.GetHashCode() : 0);
- return hashCode;
- }
- }
- }
- }
- }
-}
\ No newline at end of file
diff --git a/ArchUnitNET/Fluent/ArchRuleCreator.cs b/ArchUnitNET/Fluent/ArchRuleCreator.cs
index f481db4e3..17a73da11 100644
--- a/ArchUnitNET/Fluent/ArchRuleCreator.cs
+++ b/ArchUnitNET/Fluent/ArchRuleCreator.cs
@@ -12,7 +12,7 @@
namespace ArchUnitNET.Fluent
{
- public partial class ArchRuleCreator : IArchRuleCreator where TRuleType : ICanBeAnalyzed
+ public class ArchRuleCreator : IArchRuleCreator where TRuleType : ICanBeAnalyzed
{
private readonly ConditionManager _conditionManager;
private readonly PredicateManager _predicateManager;
diff --git a/ArchUnitNET/Fluent/ConditionManager.cs b/ArchUnitNET/Fluent/ConditionManager.cs
new file mode 100644
index 000000000..120d34150
--- /dev/null
+++ b/ArchUnitNET/Fluent/ConditionManager.cs
@@ -0,0 +1,313 @@
+// Copyright 2019 Florian Gather
+// Copyright 2019 Paula Ruiz
+// Copyright 2019 Fritz Brandhuber
+//
+// SPDX-License-Identifier: Apache-2.0
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using ArchUnitNET.Domain;
+using ArchUnitNET.Domain.Extensions;
+using ArchUnitNET.Fluent.Conditions;
+using ArchUnitNET.Fluent.Extensions;
+using ArchUnitNET.Fluent.Predicates;
+using JetBrains.Annotations;
+
+namespace ArchUnitNET.Fluent
+{
+ internal class ConditionManager : IHasDescription where T : ICanBeAnalyzed
+ {
+ private readonly List> _conditionElements;
+ private Type _referenceTypeTemp;
+ private object _relatedObjectsTemp;
+ private object _relationConditionTemp;
+
+ public ConditionManager()
+ {
+ _conditionElements = new List>
+ {
+ new ConditionElement(LogicalConjunctionDefinition.ForwardSecondValue)
+ };
+ }
+
+ public string Description => _conditionElements
+ .Aggregate("", (current, conditionElement) => current + " " + conditionElement.Description).Trim();
+
+ public void BeginComplexCondition(IObjectProvider relatedObjects,
+ RelationCondition relationCondition)
+ where TRelatedType : ICanBeAnalyzed
+ {
+ _relatedObjectsTemp = relatedObjects;
+ _relationConditionTemp = relationCondition;
+ _referenceTypeTemp = typeof(TRelatedType);
+ }
+
+ public void ContinueComplexCondition(IPredicate filter)
+ where TRelatedType : ICanBeAnalyzed
+ {
+ if (typeof(TRelatedType) == _referenceTypeTemp)
+ {
+ AddCondition(
+ new ComplexCondition((IObjectProvider) _relatedObjectsTemp,
+ (RelationCondition) _relationConditionTemp, filter));
+ }
+ else
+ {
+ throw new InvalidCastException(
+ "ContinueComplexCondition() has to be called with the same generic type argument that was used for BeginComplexCondition().");
+ }
+ }
+
+ public void AddCondition(ICondition condition)
+ {
+ _conditionElements.Last().SetCondition(condition);
+ }
+
+ public void AddReason(string reason)
+ {
+ _conditionElements.Last().AddReason(reason);
+ }
+
+ public void SetCustomDescription(string description)
+ {
+ _conditionElements.ForEach(conditionElement => conditionElement.SetCustomDescription(""));
+ _conditionElements.Last().SetCustomDescription(description);
+ }
+
+ public void SetNextLogicalConjunction(LogicalConjunction logicalConjunction)
+ {
+ _conditionElements.Add(new ConditionElement(logicalConjunction));
+ }
+
+ private bool CheckEmpty()
+ {
+ return _conditionElements.Aggregate(true,
+ (currentResult, conditionElement) => conditionElement.CheckEmpty(currentResult));
+ }
+
+ public IEnumerable EvaluateConditions(IEnumerable filteredObjects,
+ Architecture architecture, ICanBeEvaluated archRuleCreator)
+ {
+ var filteredObjectsList = filteredObjects.ToList();
+ if (filteredObjectsList.IsNullOrEmpty())
+ {
+ yield return new EvaluationResult(null, CheckEmpty(), "There are no objects matching the criteria",
+ archRuleCreator, architecture);
+ yield break;
+ }
+
+ var conditionResults = _conditionElements.Select(conditionElement =>
+ conditionElement.Check(filteredObjectsList, architecture).ToList()).ToList();
+
+ for (var i = 0; i < filteredObjectsList.Count; i++)
+ {
+ var index = i;
+ yield return CreateEvaluationResult(conditionResults.Select(results => results[index]), architecture,
+ archRuleCreator);
+ }
+ }
+
+ private static EvaluationResult CreateEvaluationResult(
+ IEnumerable conditionElementResults,
+ Architecture architecture, ICanBeEvaluated archRuleCreator)
+ {
+ var conditionElementResultsList = conditionElementResults.ToList();
+ var analyzedObject = conditionElementResultsList.First().ConditionResult.AnalyzedObject;
+ var passRule = conditionElementResultsList.Aggregate(true,
+ (currentResult, conditionElementResult) =>
+ conditionElementResult.LogicalConjunction.Evaluate(currentResult,
+ conditionElementResult.ConditionResult.Pass));
+ var description = analyzedObject.FullName;
+ if (passRule)
+ {
+ description += " passed";
+ }
+ else
+ {
+ var first = true;
+ var failDescriptionCache =
+ new List(); //Prevent failDescriptions like "... failed because ... is public and is public"
+ foreach (var conditionResult in conditionElementResultsList.Select(result => result.ConditionResult)
+ .Where(condResult =>
+ !condResult.Pass && !failDescriptionCache.Contains(condResult.FailDescription)))
+ {
+ if (!first)
+ {
+ description += " and";
+ }
+
+ description += " " + conditionResult.FailDescription;
+ failDescriptionCache.Add(conditionResult.FailDescription);
+ first = false;
+ }
+ }
+
+ return new EvaluationResult(analyzedObject, passRule, description, archRuleCreator, architecture);
+ }
+
+ public override string ToString()
+ {
+ return Description;
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj))
+ {
+ return false;
+ }
+
+ if (ReferenceEquals(this, obj))
+ {
+ return true;
+ }
+
+ return obj.GetType() == GetType() && Equals((ConditionManager) obj);
+ }
+
+ public override int GetHashCode()
+ {
+ unchecked
+ {
+ return _conditionElements.Aggregate(397,
+ (current, conditionElement) =>
+ (current * 397) ^ (conditionElement != null ? conditionElement.GetHashCode() : 0));
+ }
+ }
+
+ private bool Equals(ConditionManager other)
+ {
+ return _conditionElements.SequenceEqual(other._conditionElements) &&
+ _referenceTypeTemp == other._referenceTypeTemp &&
+ _relationConditionTemp == other._relationConditionTemp;
+ }
+
+#pragma warning disable 693
+ private class ConditionElement : IHasDescription where T : ICanBeAnalyzed
+ {
+ private readonly LogicalConjunction _logicalConjunction;
+ private ICondition _condition;
+
+ [CanBeNull]
+ private string _customDescription;
+
+ private string _reason;
+
+ public ConditionElement(LogicalConjunction logicalConjunction)
+ {
+ _condition = null;
+ _logicalConjunction = logicalConjunction;
+ _reason = "";
+ }
+
+ public string Description => _customDescription ?? (_condition == null
+ ? ""
+ : (_logicalConjunction.Description + " should " +
+ _condition.GetShortDescription() + " " + _reason).Trim());
+
+ public void AddReason(string reason)
+ {
+ if (_condition == null)
+ {
+ throw new InvalidOperationException(
+ "Can't add a reason to a ConditionElement before the condition is set.");
+ }
+
+ if (_reason != "")
+ {
+ throw new InvalidOperationException(
+ "Can't add a reason to a ConditionElement which already has a reason.");
+ }
+
+ _reason = "because " + reason;
+ }
+
+ public void SetCondition(ICondition condition)
+ {
+ _condition = condition;
+ }
+
+ public void SetCustomDescription(string description)
+ {
+ _customDescription = description;
+ }
+
+ public IEnumerable Check(IEnumerable objects, Architecture architecture)
+ {
+ if (_condition == null)
+ {
+ throw new InvalidOperationException(
+ "Can't check a ConditionElement before the condition is set.");
+ }
+
+ return _condition.Check(objects, architecture)
+ .Select(result => new ConditionElementResult(result, _logicalConjunction));
+ }
+
+ public bool CheckEmpty(bool currentResult)
+ {
+ if (_condition == null)
+ {
+ throw new InvalidOperationException(
+ "Can't check a ConditionElement before the condition is set.");
+ }
+
+ return _logicalConjunction.Evaluate(currentResult, _condition.CheckEmpty());
+ }
+
+ public override string ToString()
+ {
+ return Description;
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj))
+ {
+ return false;
+ }
+
+ if (ReferenceEquals(this, obj))
+ {
+ return true;
+ }
+
+ return obj.GetType() == GetType() && Equals((ConditionElement) obj);
+ }
+
+ private bool Equals(ConditionElement other)
+ {
+ return Equals(_logicalConjunction, other._logicalConjunction) &&
+ Equals(_condition, other._condition) &&
+ _customDescription == other._customDescription &&
+ _reason == other._reason;
+ }
+
+ public override int GetHashCode()
+ {
+ unchecked
+ {
+ var hashCode = _logicalConjunction != null ? _logicalConjunction.GetHashCode() : 0;
+ hashCode = (hashCode * 397) ^ (_condition != null ? _condition.GetHashCode() : 0);
+ hashCode = (hashCode * 397) ^
+ (_customDescription != null ? _customDescription.GetHashCode() : 0);
+ hashCode = (hashCode * 397) ^ (_reason != null ? _reason.GetHashCode() : 0);
+ return hashCode;
+ }
+ }
+ }
+
+ private class ConditionElementResult
+ {
+ public readonly ConditionResult ConditionResult;
+ public readonly LogicalConjunction LogicalConjunction;
+
+ public ConditionElementResult(ConditionResult conditionResult, LogicalConjunction logicalConjunction)
+ {
+ ConditionResult = conditionResult;
+ LogicalConjunction = logicalConjunction;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ArchUnitNET/Fluent/Extensions/EnumerableExtensions.cs b/ArchUnitNET/Fluent/Extensions/EnumerableExtensions.cs
deleted file mode 100644
index ae9331ee7..000000000
--- a/ArchUnitNET/Fluent/Extensions/EnumerableExtensions.cs
+++ /dev/null
@@ -1,90 +0,0 @@
-// Copyright 2019 Florian Gather
-// Copyright 2019 Paula Ruiz
-// Copyright 2019 Fritz Brandhuber
-//
-// SPDX-License-Identifier: Apache-2.0
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using ArchUnitNET.ArchitectureExceptions;
-using ArchUnitNET.Domain;
-using JetBrains.Annotations;
-
-namespace ArchUnitNET.Fluent.Extensions
-{
- public static class EnumerableExtensions
- {
- public static IEnumerable> SlicedBy(this IEnumerable source, string fullName)
- {
- return source.GroupBy(type => type.FullName)
- .Select(sliceItems => new Slice(sliceItems.Key, sliceItems.ToList()));
- }
-
- public static void ForEach(this IEnumerable source, Action action)
- {
- foreach (var element in source)
- {
- action(element);
- }
- }
-
- public static bool IsNullOrEmpty(this IEnumerable source)
- {
- return source == null || !source.Any();
- }
-
- [NotNull]
- public static IEnumerable WhereNameIs(this IEnumerable source, string name)
- where TType : IHasName
- {
- return source.Where(hasName => hasName.Name == name);
- }
-
- [CanBeNull]
- public static TType WhereFullNameIs(this IEnumerable