diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 000000000..a4713c52b --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "csharpier": { + "version": "0.27.3", + "commands": [ + "dotnet-csharpier" + ] + } + } +} \ No newline at end of file diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 000000000..4eb2688ae --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1 @@ +60e7aa44819edda932026dc2254db2876e70ead3 \ No newline at end of file diff --git a/.gitconfig b/.gitconfig new file mode 100644 index 000000000..5226ad694 --- /dev/null +++ b/.gitconfig @@ -0,0 +1,2 @@ +[blame] + ignoreRevsFile = .git-blame-ignore-revs \ No newline at end of file diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 956f718a7..9a7b49a61 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -8,6 +8,20 @@ on: types: [opened, reopened, synchronize] jobs: + formatting: + name: Check formatting + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + - name: Setup .NET + uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4.0.0 + with: + dotnet-version: 6.0.402 + - name: Install tools + run: dotnet tool restore + - name: Check formatting + run: dotnet csharpier --check . run-tests: name: Run tests strategy: diff --git a/ArchUnitNET.MSTestV2/ArchRuleAssert.cs b/ArchUnitNET.MSTestV2/ArchRuleAssert.cs index b9be4a596..84511f83d 100644 --- a/ArchUnitNET.MSTestV2/ArchRuleAssert.cs +++ b/ArchUnitNET.MSTestV2/ArchRuleAssert.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -26,4 +26,4 @@ public static void FulfilsRule(Architecture architecture, IArchRule archRule) } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET.MSTestV2/ArchRuleExtensions.cs b/ArchUnitNET.MSTestV2/ArchRuleExtensions.cs index d9d4de0eb..eb14b3c54 100644 --- a/ArchUnitNET.MSTestV2/ArchRuleExtensions.cs +++ b/ArchUnitNET.MSTestV2/ArchRuleExtensions.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -31,4 +31,4 @@ public static void CheckRule(this Architecture architecture, IArchRule archRule) ArchRuleAssert.FulfilsRule(architecture, archRule); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET.MSTestV2Tests/RuleEvaluationTests.cs b/ArchUnitNET.MSTestV2Tests/RuleEvaluationTests.cs index a4b894179..e320fe882 100644 --- a/ArchUnitNET.MSTestV2Tests/RuleEvaluationTests.cs +++ b/ArchUnitNET.MSTestV2Tests/RuleEvaluationTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -25,7 +25,9 @@ public class RuleEvaluationTests [ClassInitialize] public static void Setup(TestContext context) { - _architecture = new ArchLoader().LoadAssemblies(System.Reflection.Assembly.Load("ArchUnitNET.MSTestV2Tests")).Build(); + _architecture = new ArchLoader() + .LoadAssemblies(System.Reflection.Assembly.Load("ArchUnitNET.MSTestV2Tests")) + .Build(); _trueRule = Classes().That().Are(typeof(RuleEvaluationTests)).Should().Exist(); _falseRule = Classes().That().Are(typeof(RuleEvaluationTests)).Should().NotExist(); _expectedErrorMessage = _falseRule.Evaluate(_architecture).ToErrorMessage(); @@ -35,9 +37,19 @@ public static void Setup(TestContext context) public void ArchRuleAssertTest() { ArchRuleAssert.FulfilsRule(_architecture, _trueRule); - Assert.ThrowsException(() => ArchRuleAssert.FulfilsRule(_architecture, _falseRule)); - Assert.AreEqual(_expectedErrorMessage, - RemoveAssertionText(Assert.ThrowsException(() => ArchRuleAssert.FulfilsRule(_architecture, _falseRule)).Message)); + Assert.ThrowsException( + () => ArchRuleAssert.FulfilsRule(_architecture, _falseRule) + ); + Assert.AreEqual( + _expectedErrorMessage, + RemoveAssertionText( + Assert + .ThrowsException( + () => ArchRuleAssert.FulfilsRule(_architecture, _falseRule) + ) + .Message + ) + ); } [TestMethod] @@ -45,16 +57,35 @@ public void ArchRuleExtensionsTest() { _architecture.CheckRule(_trueRule); _trueRule.Check(_architecture); - Assert.ThrowsException(() => _architecture.CheckRule(_falseRule)); + Assert.ThrowsException( + () => _architecture.CheckRule(_falseRule) + ); Assert.ThrowsException(() => _falseRule.Check(_architecture)); - Assert.AreEqual(_expectedErrorMessage, - RemoveAssertionText(Assert.ThrowsException(() => _architecture.CheckRule(_falseRule)).Message)); - Assert.AreEqual(_expectedErrorMessage, - RemoveAssertionText(Assert.ThrowsException(() => _falseRule.Check(_architecture)).Message)); + Assert.AreEqual( + _expectedErrorMessage, + RemoveAssertionText( + Assert + .ThrowsException( + () => _architecture.CheckRule(_falseRule) + ) + .Message + ) + ); + Assert.AreEqual( + _expectedErrorMessage, + RemoveAssertionText( + Assert + .ThrowsException( + () => _falseRule.Check(_architecture) + ) + .Message + ) + ); } - private static string RemoveAssertionText(string exceptionMessage) { - return exceptionMessage.Replace("Assert.Fail failed. ", string.Empty); + private static string RemoveAssertionText(string exceptionMessage) + { + return exceptionMessage.Replace("Assert.Fail failed. ", string.Empty); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET.NUnit/ArchRuleAssert.cs b/ArchUnitNET.NUnit/ArchRuleAssert.cs index 45ba19840..f99e4fe6e 100644 --- a/ArchUnitNET.NUnit/ArchRuleAssert.cs +++ b/ArchUnitNET.NUnit/ArchRuleAssert.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -26,4 +26,4 @@ public static void FulfilsRule(Architecture architecture, IArchRule archRule) } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET.NUnit/ArchRuleExtensions.cs b/ArchUnitNET.NUnit/ArchRuleExtensions.cs index c68456eb2..a9a6409a8 100644 --- a/ArchUnitNET.NUnit/ArchRuleExtensions.cs +++ b/ArchUnitNET.NUnit/ArchRuleExtensions.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -31,4 +31,4 @@ public static void CheckRule(this Architecture architecture, IArchRule archRule) ArchRuleAssert.FulfilsRule(architecture, archRule); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET.NUnitTests/RuleEvaluationTests.cs b/ArchUnitNET.NUnitTests/RuleEvaluationTests.cs index 811d9d6f6..3a4abc42d 100644 --- a/ArchUnitNET.NUnitTests/RuleEvaluationTests.cs +++ b/ArchUnitNET.NUnitTests/RuleEvaluationTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -24,7 +24,9 @@ public class RuleEvaluationTests [SetUp] public void Setup() { - _architecture = new ArchLoader().LoadAssemblies(System.Reflection.Assembly.Load("ArchUnitNET.NUnitTests")).Build(); + _architecture = new ArchLoader() + .LoadAssemblies(System.Reflection.Assembly.Load("ArchUnitNET.NUnitTests")) + .Build(); _trueRule = Classes().That().Are(typeof(RuleEvaluationTests)).Should().Exist(); _falseRule = Classes().That().Are(typeof(RuleEvaluationTests)).Should().NotExist(); _expectedErrorMessage = _falseRule.Evaluate(_architecture).ToErrorMessage(); @@ -34,9 +36,17 @@ public void Setup() public void ArchRuleAssertTest() { ArchRuleAssert.FulfilsRule(_architecture, _trueRule); - Assert.Throws(() => ArchRuleAssert.FulfilsRule(_architecture, _falseRule)); - Assert.AreEqual(_expectedErrorMessage, - Assert.Catch(() => ArchRuleAssert.FulfilsRule(_architecture, _falseRule)).Message); + Assert.Throws( + () => ArchRuleAssert.FulfilsRule(_architecture, _falseRule) + ); + Assert.AreEqual( + _expectedErrorMessage, + Assert + .Catch( + () => ArchRuleAssert.FulfilsRule(_architecture, _falseRule) + ) + .Message + ); } [Test] @@ -46,10 +56,14 @@ public void ArchRuleExtensionsTest() _trueRule.Check(_architecture); Assert.Throws(() => _architecture.CheckRule(_falseRule)); Assert.Throws(() => _falseRule.Check(_architecture)); - Assert.AreEqual(_expectedErrorMessage, - Assert.Catch(() => _architecture.CheckRule(_falseRule)).Message); - Assert.AreEqual(_expectedErrorMessage, - Assert.Catch(() => _falseRule.Check(_architecture)).Message); + Assert.AreEqual( + _expectedErrorMessage, + Assert.Catch(() => _architecture.CheckRule(_falseRule)).Message + ); + Assert.AreEqual( + _expectedErrorMessage, + Assert.Catch(() => _falseRule.Check(_architecture)).Message + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET.xUnit/ArchRuleAssert.cs b/ArchUnitNET.xUnit/ArchRuleAssert.cs index 4119f00a7..c2aca3d9a 100644 --- a/ArchUnitNET.xUnit/ArchRuleAssert.cs +++ b/ArchUnitNET.xUnit/ArchRuleAssert.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -26,4 +26,4 @@ public static void CheckRule(Architecture architecture, IArchRule archRule) } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET.xUnit/ArchRuleExtensions.cs b/ArchUnitNET.xUnit/ArchRuleExtensions.cs index 8febf694e..01f7a3c42 100644 --- a/ArchUnitNET.xUnit/ArchRuleExtensions.cs +++ b/ArchUnitNET.xUnit/ArchRuleExtensions.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -32,4 +32,4 @@ public static void CheckRule(this Architecture architecture, IArchRule archRule) ArchRuleAssert.CheckRule(architecture, archRule); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET.xUnit/FailedArchRuleException.cs b/ArchUnitNET.xUnit/FailedArchRuleException.cs index 04141c0f4..2d057cf68 100644 --- a/ArchUnitNET.xUnit/FailedArchRuleException.cs +++ b/ArchUnitNET.xUnit/FailedArchRuleException.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -21,17 +21,13 @@ public class FailedArchRuleException : XunitException /// The architecture which was tested /// The archrule that failed public FailedArchRuleException(Architecture architecture, IArchRule archRule) - : this(archRule.Evaluate(architecture)) - { - } + : this(archRule.Evaluate(architecture)) { } /// /// Creates a new instance of the class. /// /// The results of the evaluation of the archrule public FailedArchRuleException(IEnumerable evaluationResults) - : base(evaluationResults.ToErrorMessage()) - { - } + : base(evaluationResults.ToErrorMessage()) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Architecture.cs b/ArchUnitNET/Domain/Architecture.cs index 63e705f85..167d2eb46 100644 --- a/ArchUnitNET/Domain/Architecture.cs +++ b/ArchUnitNET/Domain/Architecture.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -15,9 +15,13 @@ public class Architecture private readonly IEnumerable _allAssemblies; private readonly ObjectProviderCache _objectProviderCache; - public Architecture(IEnumerable allAssemblies, IEnumerable namespaces, - IEnumerable types, IEnumerable genericParameters, - IEnumerable referencedTypes) + public Architecture( + IEnumerable allAssemblies, + IEnumerable namespaces, + IEnumerable types, + IEnumerable genericParameters, + IEnumerable referencedTypes + ) { _allAssemblies = allAssemblies; Namespaces = namespaces; @@ -27,7 +31,8 @@ public Architecture(IEnumerable allAssemblies, IEnumerable _objectProviderCache = new ObjectProviderCache(this); } - public IEnumerable Assemblies => _allAssemblies.Where(assembly => !assembly.IsOnlyReferenced); + public IEnumerable Assemblies => + _allAssemblies.Where(assembly => !assembly.IsOnlyReferenced); public IEnumerable Namespaces { get; } public IEnumerable Types { get; } public IEnumerable GenericParameters { get; } @@ -45,8 +50,11 @@ public Architecture(IEnumerable allAssemblies, IEnumerable public IEnumerable MethodMembers => Members.OfType(); public IEnumerable Members => Types.SelectMany(type => type.Members); - public IEnumerable GetOrCreateObjects(IObjectProvider objectProvider, - Func> providingFunction) where T : ICanBeAnalyzed + public IEnumerable GetOrCreateObjects( + IObjectProvider objectProvider, + Func> providingFunction + ) + where T : ICanBeAnalyzed { return _objectProviderCache.GetOrCreateObjects(objectProvider, providingFunction); } @@ -68,8 +76,9 @@ public override bool Equals(object obj) private bool Equals(Architecture other) { - return Assemblies.Equals(other.Assemblies) && Namespaces.Equals(other.Namespaces) && - Types.Equals(other.Types); + return Assemblies.Equals(other.Assemblies) + && Namespaces.Equals(other.Namespaces) + && Types.Equals(other.Types); } public override int GetHashCode() @@ -83,4 +92,4 @@ public override int GetHashCode() } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/ArchitectureCache.cs b/ArchUnitNET/Domain/ArchitectureCache.cs index 18b8fe919..310a75601 100644 --- a/ArchUnitNET/Domain/ArchitectureCache.cs +++ b/ArchUnitNET/Domain/ArchitectureCache.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Concurrent; @@ -13,15 +13,15 @@ public class ArchitectureCache protected readonly ConcurrentDictionary Cache = new ConcurrentDictionary(); - protected ArchitectureCache() - { - } + protected ArchitectureCache() { } public static ArchitectureCache Instance { get; } = new ArchitectureCache(); public Architecture TryGetArchitecture(ArchitectureCacheKey architectureCacheKey) { - return Cache.TryGetValue(architectureCacheKey, out var matchArchitecture) ? matchArchitecture : null; + return Cache.TryGetValue(architectureCacheKey, out var matchArchitecture) + ? matchArchitecture + : null; } public bool Add(ArchitectureCacheKey architectureCacheKey, Architecture architecture) @@ -29,4 +29,4 @@ public bool Add(ArchitectureCacheKey architectureCacheKey, Architecture architec return Cache.TryAdd(architectureCacheKey, architecture); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/ArchitectureCacheKey.cs b/ArchUnitNET/Domain/ArchitectureCacheKey.cs index 9acfae4d2..b05f162d0 100644 --- a/ArchUnitNET/Domain/ArchitectureCacheKey.cs +++ b/ArchUnitNET/Domain/ArchitectureCacheKey.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -18,7 +18,8 @@ public class ArchitectureCacheKey : IEquatable public bool Equals(ArchitectureCacheKey other) { - return other != null && _architectureCacheKey.SequenceEqual(other._architectureCacheKey); + return other != null + && _architectureCacheKey.SequenceEqual(other._architectureCacheKey); } public void Add(string moduleName, string filter) @@ -38,7 +39,7 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((ArchitectureCacheKey) obj); + return obj.GetType() == GetType() && Equals((ArchitectureCacheKey)obj); } public override int GetHashCode() @@ -46,7 +47,10 @@ public override int GetHashCode() unchecked { var hashCode = 397; - _architectureCacheKey.ForEach(tuple => { hashCode = (hashCode * 131) ^ tuple.GetHashCode(); }); + _architectureCacheKey.ForEach(tuple => + { + hashCode = (hashCode * 131) ^ tuple.GetHashCode(); + }); return hashCode; } } @@ -54,13 +58,19 @@ public override int GetHashCode() internal class ArchitectureCacheKeyComparer : IComparer<(string moduleName, string filter)> { - public int Compare((string moduleName, string filter) x, - (string moduleName, string filter) y) + public int Compare( + (string moduleName, string filter) x, + (string moduleName, string filter) y + ) { - var moduleNameComparison = string.Compare(x.moduleName, y.moduleName, StringComparison.Ordinal); + var moduleNameComparison = string.Compare( + x.moduleName, + y.moduleName, + StringComparison.Ordinal + ); return moduleNameComparison == 0 ? string.Compare(x.filter, y.filter, StringComparison.Ordinal) : moduleNameComparison; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Assembly.cs b/ArchUnitNET/Domain/Assembly.cs index cb1121119..6abcca9ae 100644 --- a/ArchUnitNET/Domain/Assembly.cs +++ b/ArchUnitNET/Domain/Assembly.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -12,7 +12,12 @@ namespace ArchUnitNET.Domain { public class Assembly : IHasName, IHasAttributes { - public Assembly(string name, string fullName, bool isOnlyReferenced , [CanBeNull] List referencedAssemblyNames) + public Assembly( + string name, + string fullName, + bool isOnlyReferenced, + [CanBeNull] List referencedAssemblyNames + ) { Name = name; FullName = fullName; @@ -24,10 +29,12 @@ public Assembly(string name, string fullName, bool isOnlyReferenced , [CanBeNull public string Name { get; } - [CanBeNull] public List ReferencedAssemblyNames { get; } + [CanBeNull] + public List ReferencedAssemblyNames { get; } public string FullName { get; } - public IEnumerable Attributes => AttributeInstances.Select(instance => instance.Type); + public IEnumerable Attributes => + AttributeInstances.Select(instance => instance.Type); public List AttributeInstances { get; } = new List(); public bool Equals(Assembly other) @@ -42,8 +49,9 @@ public bool Equals(Assembly other) return true; } - return Equals(Name, other.Name) && Equals(FullName, other.FullName) && - Equals(IsOnlyReferenced, other.IsOnlyReferenced); + return Equals(Name, other.Name) + && Equals(FullName, other.FullName) + && Equals(IsOnlyReferenced, other.IsOnlyReferenced); } public override bool Equals(object obj) @@ -63,7 +71,7 @@ public override bool Equals(object obj) return false; } - return Equals((Assembly) obj); + return Equals((Assembly)obj); } public override int GetHashCode() @@ -77,4 +85,4 @@ public override int GetHashCode() } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Attribute.cs b/ArchUnitNET/Domain/Attribute.cs index c22abeba7..28dda4cc9 100644 --- a/ArchUnitNET/Domain/Attribute.cs +++ b/ArchUnitNET/Domain/Attribute.cs @@ -1,20 +1,17 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 namespace ArchUnitNET.Domain { public class Attribute : Class { - public Attribute(IType type, bool? isAbstract, bool? isSealed) : base(type, isAbstract, - isSealed) - { - } + public Attribute(IType type, bool? isAbstract, bool? isSealed) + : base(type, isAbstract, isSealed) { } - public Attribute(Class cls) : base(cls) - { - } + public Attribute(Class cls) + : base(cls) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/AttributeArgument.cs b/ArchUnitNET/Domain/AttributeArgument.cs index 6e9708dfa..51f0dd709 100644 --- a/ArchUnitNET/Domain/AttributeArgument.cs +++ b/ArchUnitNET/Domain/AttributeArgument.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Collections.Generic; @@ -43,7 +43,7 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((AttributeArgument) obj); + return obj.GetType() == GetType() && Equals((AttributeArgument)obj); } public override int GetHashCode() @@ -56,4 +56,4 @@ public override int GetHashCode() } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/AttributeInstance.cs b/ArchUnitNET/Domain/AttributeInstance.cs index 46cc80c8c..9ca275c00 100644 --- a/ArchUnitNET/Domain/AttributeInstance.cs +++ b/ArchUnitNET/Domain/AttributeInstance.cs @@ -1,9 +1,9 @@ // 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; @@ -11,16 +11,20 @@ namespace ArchUnitNET.Domain { - public class AttributeInstance : TypeInstance + public class AttributeInstance : TypeInstance { // ReSharper disable SuggestBaseTypeForParameter - public AttributeInstance(Attribute attribute, IEnumerable attributeArguments) : - base(attribute) + public AttributeInstance( + Attribute attribute, + IEnumerable attributeArguments + ) + : base(attribute) { AttributeArguments = attributeArguments; } - public AttributeInstance(Attribute attribute) : base(attribute) + public AttributeInstance(Attribute attribute) + : base(attribute) { AttributeArguments = Enumerable.Empty(); } @@ -29,4 +33,4 @@ public AttributeInstance(Attribute attribute) : base(attribute) public bool HasAttributeArguments => AttributeArguments.Any(); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/AttributeNamedArgument.cs b/ArchUnitNET/Domain/AttributeNamedArgument.cs index f87deeaec..b22c6cb90 100644 --- a/ArchUnitNET/Domain/AttributeNamedArgument.cs +++ b/ArchUnitNET/Domain/AttributeNamedArgument.cs @@ -1,16 +1,16 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// namespace ArchUnitNET.Domain { public class AttributeNamedArgument : AttributeArgument { - public AttributeNamedArgument(string name, object value, ITypeInstance typeInstance) : base(value, - typeInstance) + public AttributeNamedArgument(string name, object value, ITypeInstance typeInstance) + : base(value, typeInstance) { Name = name; } @@ -34,7 +34,7 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((AttributeNamedArgument) obj); + return obj.GetType() == GetType() && Equals((AttributeNamedArgument)obj); } public override int GetHashCode() @@ -47,4 +47,4 @@ public override int GetHashCode() } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Class.cs b/ArchUnitNET/Domain/Class.cs index 1bf233646..95affbe3b 100644 --- a/ArchUnitNET/Domain/Class.cs +++ b/ArchUnitNET/Domain/Class.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -30,9 +30,10 @@ public Class(Class @class) IsSealed = @class.IsSealed; } - public IEnumerable DependenciesIncludingInherited => BaseClass != null - ? Type.Dependencies.Concat(BaseClass.DependenciesIncludingInherited) - : Type.Dependencies; + public IEnumerable DependenciesIncludingInherited => + BaseClass != null + ? Type.Dependencies.Concat(BaseClass.DependenciesIncludingInherited) + : Type.Dependencies; public MemberList MembersIncludingInherited => BaseClass != null @@ -41,15 +42,16 @@ public Class(Class @class) [CanBeNull] public Class BaseClass => - (Class) Dependencies.OfType().FirstOrDefault()?.Target; + (Class)Dependencies.OfType().FirstOrDefault()?.Target; public IEnumerable Constructors => Type.GetConstructors(); public bool? IsAbstract { get; } public bool? IsSealed { get; } - public IEnumerable InheritedClasses => BaseClass == null - ? Enumerable.Empty() - : BaseClass.InheritedClasses.Concat(new[] {BaseClass}); + public IEnumerable InheritedClasses => + BaseClass == null + ? Enumerable.Empty() + : BaseClass.InheritedClasses.Concat(new[] { BaseClass }); public Visibility Visibility => Type.Visibility; public bool IsNested => Type.IsNested; @@ -66,7 +68,8 @@ public Class(Class @class) public List Dependencies => Type.Dependencies; public List BackwardsDependencies => Type.BackwardsDependencies; - public IEnumerable Attributes => AttributeInstances.Select(instance => instance.Type); + public IEnumerable Attributes => + AttributeInstances.Select(instance => instance.Type); public List AttributeInstances => Type.AttributeInstances; public IEnumerable ImplementedInterfaces => Type.ImplementedInterfaces; @@ -81,8 +84,9 @@ public override string ToString() private bool Equals(Class other) { - return Equals(Type, other.Type) && Equals(IsAbstract, other.IsAbstract) && - Equals(IsSealed, other.IsSealed); + return Equals(Type, other.Type) + && Equals(IsAbstract, other.IsAbstract) + && Equals(IsSealed, other.IsSealed); } public override bool Equals(object obj) @@ -97,7 +101,7 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((Class) obj); + return obj.GetType() == GetType() && Equals((Class)obj); } public override int GetHashCode() @@ -111,4 +115,4 @@ public override int GetHashCode() } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Dependencies/AccessFieldDependency.cs b/ArchUnitNET/Domain/Dependencies/AccessFieldDependency.cs index 682523919..053b383e7 100644 --- a/ArchUnitNET/Domain/Dependencies/AccessFieldDependency.cs +++ b/ArchUnitNET/Domain/Dependencies/AccessFieldDependency.cs @@ -1,9 +1,9 @@ // 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; @@ -22,8 +22,10 @@ public AccessFieldDependency(IMember originMember, FieldMember accessedField) public IMember OriginMember { get; } public IMember TargetMember { get; } - public IEnumerable TargetGenericArguments => Enumerable.Empty(); - public IEnumerable TargetMemberGenericArguments => Enumerable.Empty(); + public IEnumerable TargetGenericArguments => + Enumerable.Empty(); + public IEnumerable TargetMemberGenericArguments => + Enumerable.Empty(); public IType Origin => OriginMember.DeclaringType; public IType Target => TargetMember.DeclaringType; @@ -43,21 +45,22 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((AccessFieldDependency) obj); + return obj.GetType() == GetType() && Equals((AccessFieldDependency)obj); } private bool Equals(IMemberMemberDependency other) { - return Equals(TargetMember, other.TargetMember) && Equals(OriginMember, other.OriginMember); + return Equals(TargetMember, other.TargetMember) + && Equals(OriginMember, other.OriginMember); } public override int GetHashCode() { unchecked { - return ((TargetMember != null ? TargetMember.GetHashCode() : 0) * 397) ^ - (OriginMember != null ? OriginMember.GetHashCode() : 0); + return ((TargetMember != null ? TargetMember.GetHashCode() : 0) * 397) + ^ (OriginMember != null ? OriginMember.GetHashCode() : 0); } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Dependencies/AttributeMemberDependency.cs b/ArchUnitNET/Domain/Dependencies/AttributeMemberDependency.cs index 587dabf45..aa500b994 100644 --- a/ArchUnitNET/Domain/Dependencies/AttributeMemberDependency.cs +++ b/ArchUnitNET/Domain/Dependencies/AttributeMemberDependency.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 namespace ArchUnitNET.Domain.Dependencies @@ -9,8 +9,6 @@ namespace ArchUnitNET.Domain.Dependencies public class AttributeMemberDependency : MemberTypeInstanceDependency { public AttributeMemberDependency(IMember member, AttributeInstance attributeInstance) - : base(member, attributeInstance) - { - } + : base(member, attributeInstance) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Dependencies/AttributeTypeDependency.cs b/ArchUnitNET/Domain/Dependencies/AttributeTypeDependency.cs index 718ab3b6b..dee91bf01 100644 --- a/ArchUnitNET/Domain/Dependencies/AttributeTypeDependency.cs +++ b/ArchUnitNET/Domain/Dependencies/AttributeTypeDependency.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 namespace ArchUnitNET.Domain.Dependencies @@ -9,8 +9,6 @@ namespace ArchUnitNET.Domain.Dependencies public class AttributeTypeDependency : TypeInstanceDependency { public AttributeTypeDependency(IType origin, AttributeInstance attributeInstance) - : base(origin, attributeInstance) - { - } + : base(origin, attributeInstance) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Dependencies/BodyTypeMemberDependency.cs b/ArchUnitNET/Domain/Dependencies/BodyTypeMemberDependency.cs index 925a794c1..e1c4e15eb 100644 --- a/ArchUnitNET/Domain/Dependencies/BodyTypeMemberDependency.cs +++ b/ArchUnitNET/Domain/Dependencies/BodyTypeMemberDependency.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 namespace ArchUnitNET.Domain.Dependencies @@ -9,9 +9,10 @@ namespace ArchUnitNET.Domain.Dependencies public class BodyTypeMemberDependency : MemberTypeInstanceDependency { // ReSharper disable once SuggestBaseTypeForParameter - public BodyTypeMemberDependency(MethodMember method, ITypeInstance targetTypeInstance) - : base(method, targetTypeInstance) - { - } + public BodyTypeMemberDependency( + MethodMember method, + ITypeInstance targetTypeInstance + ) + : base(method, targetTypeInstance) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Dependencies/CastTypeDependency.cs b/ArchUnitNET/Domain/Dependencies/CastTypeDependency.cs index 7384a68e8..c5435cb6f 100644 --- a/ArchUnitNET/Domain/Dependencies/CastTypeDependency.cs +++ b/ArchUnitNET/Domain/Dependencies/CastTypeDependency.cs @@ -1,17 +1,15 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// namespace ArchUnitNET.Domain.Dependencies { public class CastTypeDependency : MemberTypeInstanceDependency { public CastTypeDependency(IMember originMember, ITypeInstance castTypeInstance) - : base(originMember, castTypeInstance) - { - } + : base(originMember, castTypeInstance) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Dependencies/FieldTypeDependency.cs b/ArchUnitNET/Domain/Dependencies/FieldTypeDependency.cs index eacadf666..1731578dc 100644 --- a/ArchUnitNET/Domain/Dependencies/FieldTypeDependency.cs +++ b/ArchUnitNET/Domain/Dependencies/FieldTypeDependency.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 namespace ArchUnitNET.Domain.Dependencies @@ -9,8 +9,6 @@ namespace ArchUnitNET.Domain.Dependencies public class FieldTypeDependency : MemberTypeInstanceDependency { public FieldTypeDependency(FieldMember field) - : base(field, field) - { - } + : base(field, field) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Dependencies/GenericArgumentMemberDependency.cs b/ArchUnitNET/Domain/Dependencies/GenericArgumentMemberDependency.cs index 8ff27e542..801c2194b 100644 --- a/ArchUnitNET/Domain/Dependencies/GenericArgumentMemberDependency.cs +++ b/ArchUnitNET/Domain/Dependencies/GenericArgumentMemberDependency.cs @@ -1,17 +1,18 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// namespace ArchUnitNET.Domain.Dependencies { public class GenericArgumentMemberDependency : MemberTypeInstanceDependency { - public GenericArgumentMemberDependency(IMember originMember, GenericArgument genericArgument) - : base(originMember, genericArgument) - { - } + public GenericArgumentMemberDependency( + IMember originMember, + GenericArgument genericArgument + ) + : base(originMember, genericArgument) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Dependencies/GenericArgumentTypeDependency.cs b/ArchUnitNET/Domain/Dependencies/GenericArgumentTypeDependency.cs index b2e473141..fe8b88972 100644 --- a/ArchUnitNET/Domain/Dependencies/GenericArgumentTypeDependency.cs +++ b/ArchUnitNET/Domain/Dependencies/GenericArgumentTypeDependency.cs @@ -1,17 +1,15 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// namespace ArchUnitNET.Domain.Dependencies { public class GenericArgumentTypeDependency : TypeInstanceDependency { public GenericArgumentTypeDependency(IType origin, GenericArgument genericArgument) - : base(origin, genericArgument) - { - } + : base(origin, genericArgument) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Dependencies/IMemberMemberDependency.cs b/ArchUnitNET/Domain/Dependencies/IMemberMemberDependency.cs index c240e9fb5..5bf416a90 100644 --- a/ArchUnitNET/Domain/Dependencies/IMemberMemberDependency.cs +++ b/ArchUnitNET/Domain/Dependencies/IMemberMemberDependency.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -13,4 +13,4 @@ public interface IMemberMemberDependency : IMemberTypeDependency IMember TargetMember { get; } IEnumerable TargetMemberGenericArguments { get; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Dependencies/IMemberTypeDependency.cs b/ArchUnitNET/Domain/Dependencies/IMemberTypeDependency.cs index 95f770753..f721143fb 100644 --- a/ArchUnitNET/Domain/Dependencies/IMemberTypeDependency.cs +++ b/ArchUnitNET/Domain/Dependencies/IMemberTypeDependency.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 namespace ArchUnitNET.Domain.Dependencies @@ -10,4 +10,4 @@ public interface IMemberTypeDependency : ITypeDependency { IMember OriginMember { get; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Dependencies/ITypeDependency.cs b/ArchUnitNET/Domain/Dependencies/ITypeDependency.cs index 6f212bd24..1730221be 100644 --- a/ArchUnitNET/Domain/Dependencies/ITypeDependency.cs +++ b/ArchUnitNET/Domain/Dependencies/ITypeDependency.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -17,4 +17,4 @@ public interface ITypeDependency bool TargetIsArray { get; } IEnumerable TargetArrayDimensions { get; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Dependencies/ImplementsInterfaceDependency.cs b/ArchUnitNET/Domain/Dependencies/ImplementsInterfaceDependency.cs index d923b8388..7ab82925d 100644 --- a/ArchUnitNET/Domain/Dependencies/ImplementsInterfaceDependency.cs +++ b/ArchUnitNET/Domain/Dependencies/ImplementsInterfaceDependency.cs @@ -1,16 +1,17 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 namespace ArchUnitNET.Domain.Dependencies { public class ImplementsInterfaceDependency : TypeInstanceDependency { - public ImplementsInterfaceDependency(IType origin, ITypeInstance implementedInterface) : base(origin, - implementedInterface) - { - } + public ImplementsInterfaceDependency( + IType origin, + ITypeInstance implementedInterface + ) + : base(origin, implementedInterface) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Dependencies/InheritsBaseClassDependency.cs b/ArchUnitNET/Domain/Dependencies/InheritsBaseClassDependency.cs index c816d4685..8187ac065 100644 --- a/ArchUnitNET/Domain/Dependencies/InheritsBaseClassDependency.cs +++ b/ArchUnitNET/Domain/Dependencies/InheritsBaseClassDependency.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 namespace ArchUnitNET.Domain.Dependencies @@ -9,8 +9,6 @@ namespace ArchUnitNET.Domain.Dependencies public class InheritsBaseClassDependency : TypeInstanceDependency { public InheritsBaseClassDependency(IType origin, ITypeInstance targetInstance) - : base(origin, targetInstance) - { - } + : base(origin, targetInstance) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Dependencies/MemberGenericParameterTypeConstraintDependency.cs b/ArchUnitNET/Domain/Dependencies/MemberGenericParameterTypeConstraintDependency.cs index b8f237299..c4676c3aa 100644 --- a/ArchUnitNET/Domain/Dependencies/MemberGenericParameterTypeConstraintDependency.cs +++ b/ArchUnitNET/Domain/Dependencies/MemberGenericParameterTypeConstraintDependency.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System; @@ -11,14 +11,17 @@ namespace ArchUnitNET.Domain.Dependencies { public class MemberGenericParameterTypeConstraintDependency : MemberTypeInstanceDependency { - public MemberGenericParameterTypeConstraintDependency(GenericParameter originGenericParameter, - ITypeInstance typeConstraintInstance) + public MemberGenericParameterTypeConstraintDependency( + GenericParameter originGenericParameter, + ITypeInstance typeConstraintInstance + ) : base(originGenericParameter.DeclaringMethod, typeConstraintInstance) { if (!originGenericParameter.DeclarerIsMethod) { throw new ArgumentException( - "Use TypeGenericParameterTypeConstraintDependency for Generic Parameters of Types."); + "Use TypeGenericParameterTypeConstraintDependency for Generic Parameters of Types." + ); } OriginGenericParameter = originGenericParameter; @@ -38,23 +41,26 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((MemberGenericParameterTypeConstraintDependency) obj); + return obj.GetType() == GetType() + && Equals((MemberGenericParameterTypeConstraintDependency)obj); } private bool Equals(MemberGenericParameterTypeConstraintDependency other) { - return Equals(OriginGenericParameter, other.OriginGenericParameter) && - Equals(TargetInstance, other.TargetInstance); + return Equals(OriginGenericParameter, other.OriginGenericParameter) + && Equals(TargetInstance, other.TargetInstance); } public override int GetHashCode() { unchecked { - var hashCode = OriginGenericParameter != null ? OriginGenericParameter.GetHashCode() : 0; - hashCode = (hashCode * 397) ^ (TargetInstance != null ? TargetInstance.GetHashCode() : 0); + var hashCode = + OriginGenericParameter != null ? OriginGenericParameter.GetHashCode() : 0; + hashCode = + (hashCode * 397) ^ (TargetInstance != null ? TargetInstance.GetHashCode() : 0); return hashCode; } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Dependencies/MemberTypeInstanceDependency.cs b/ArchUnitNET/Domain/Dependencies/MemberTypeInstanceDependency.cs index 15de8fcf5..8fb5828fc 100644 --- a/ArchUnitNET/Domain/Dependencies/MemberTypeInstanceDependency.cs +++ b/ArchUnitNET/Domain/Dependencies/MemberTypeInstanceDependency.cs @@ -1,15 +1,20 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// namespace ArchUnitNET.Domain.Dependencies { - public abstract class MemberTypeInstanceDependency : TypeInstanceDependency, IMemberTypeDependency + public abstract class MemberTypeInstanceDependency + : TypeInstanceDependency, + IMemberTypeDependency { - protected MemberTypeInstanceDependency(IMember originMember, ITypeInstance targetInstance) + protected MemberTypeInstanceDependency( + IMember originMember, + ITypeInstance targetInstance + ) : base(originMember.DeclaringType, targetInstance) { OriginMember = originMember; @@ -29,12 +34,13 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((MemberTypeInstanceDependency) obj); + return obj.GetType() == GetType() && Equals((MemberTypeInstanceDependency)obj); } private bool Equals(MemberTypeInstanceDependency other) { - return Equals(OriginMember, other.OriginMember) && Equals(TargetInstance, other.TargetInstance); + return Equals(OriginMember, other.OriginMember) + && Equals(TargetInstance, other.TargetInstance); } public override int GetHashCode() @@ -42,9 +48,10 @@ public override int GetHashCode() unchecked { var hashCode = OriginMember != null ? OriginMember.GetHashCode() : 0; - hashCode = (hashCode * 397) ^ (TargetInstance != null ? TargetInstance.GetHashCode() : 0); + hashCode = + (hashCode * 397) ^ (TargetInstance != null ? TargetInstance.GetHashCode() : 0); return hashCode; } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Dependencies/MetaDataDependency.cs b/ArchUnitNET/Domain/Dependencies/MetaDataDependency.cs index fa02647ee..771cf5ae7 100644 --- a/ArchUnitNET/Domain/Dependencies/MetaDataDependency.cs +++ b/ArchUnitNET/Domain/Dependencies/MetaDataDependency.cs @@ -1,17 +1,15 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// namespace ArchUnitNET.Domain.Dependencies { public class MetaDataDependency : MemberTypeInstanceDependency { public MetaDataDependency(IMember originMember, ITypeInstance metaDataTypeInstance) - : base(originMember, metaDataTypeInstance) - { - } + : base(originMember, metaDataTypeInstance) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Dependencies/MethodCallDependency.cs b/ArchUnitNET/Domain/Dependencies/MethodCallDependency.cs index b3958ae55..272e2417d 100644 --- a/ArchUnitNET/Domain/Dependencies/MethodCallDependency.cs +++ b/ArchUnitNET/Domain/Dependencies/MethodCallDependency.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -21,4 +21,4 @@ public MethodCallDependency(IMember originMember, MethodMemberInstance calledMet public IMember TargetMember { get; } public IEnumerable TargetMemberGenericArguments { get; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Dependencies/MethodSignatureDependency.cs b/ArchUnitNET/Domain/Dependencies/MethodSignatureDependency.cs index 272e36910..717f8cad0 100644 --- a/ArchUnitNET/Domain/Dependencies/MethodSignatureDependency.cs +++ b/ArchUnitNET/Domain/Dependencies/MethodSignatureDependency.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 namespace ArchUnitNET.Domain.Dependencies @@ -9,9 +9,10 @@ namespace ArchUnitNET.Domain.Dependencies public class MethodSignatureDependency : MemberTypeInstanceDependency { // ReSharper disable once SuggestBaseTypeForParameter - public MethodSignatureDependency(MethodMember method, ITypeInstance signatureTypeInstance) : base(method, - signatureTypeInstance) - { - } + public MethodSignatureDependency( + MethodMember method, + ITypeInstance signatureTypeInstance + ) + : base(method, signatureTypeInstance) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Dependencies/PropertyTypeDependency.cs b/ArchUnitNET/Domain/Dependencies/PropertyTypeDependency.cs index 4f3a06ab4..9cead9a7c 100644 --- a/ArchUnitNET/Domain/Dependencies/PropertyTypeDependency.cs +++ b/ArchUnitNET/Domain/Dependencies/PropertyTypeDependency.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 namespace ArchUnitNET.Domain.Dependencies @@ -9,8 +9,6 @@ namespace ArchUnitNET.Domain.Dependencies public class PropertyTypeDependency : MemberTypeInstanceDependency { public PropertyTypeDependency(PropertyMember property) - : base(property, property) - { - } + : base(property, property) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Dependencies/TypeCheckDependency.cs b/ArchUnitNET/Domain/Dependencies/TypeCheckDependency.cs index a71cba385..b0d34d8c1 100644 --- a/ArchUnitNET/Domain/Dependencies/TypeCheckDependency.cs +++ b/ArchUnitNET/Domain/Dependencies/TypeCheckDependency.cs @@ -1,17 +1,15 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// namespace ArchUnitNET.Domain.Dependencies { public class TypeCheckDependency : MemberTypeInstanceDependency { public TypeCheckDependency(IMember originMember, ITypeInstance typeCheckTypeInstance) - : base(originMember, typeCheckTypeInstance) - { - } + : base(originMember, typeCheckTypeInstance) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Dependencies/TypeGenericParameterTypeConstraintDependency.cs b/ArchUnitNET/Domain/Dependencies/TypeGenericParameterTypeConstraintDependency.cs index 6f53b19ff..5bbbe8215 100644 --- a/ArchUnitNET/Domain/Dependencies/TypeGenericParameterTypeConstraintDependency.cs +++ b/ArchUnitNET/Domain/Dependencies/TypeGenericParameterTypeConstraintDependency.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System; @@ -11,14 +11,17 @@ namespace ArchUnitNET.Domain.Dependencies { public class TypeGenericParameterTypeConstraintDependency : TypeInstanceDependency { - public TypeGenericParameterTypeConstraintDependency(GenericParameter originGenericParameter, - ITypeInstance typeConstraintInstance) + public TypeGenericParameterTypeConstraintDependency( + GenericParameter originGenericParameter, + ITypeInstance typeConstraintInstance + ) : base(originGenericParameter, typeConstraintInstance) { if (originGenericParameter.DeclarerIsMethod) { throw new ArgumentException( - "Use MemberGenericParameterTypeConstraintDependency for Generic Parameters of Methods."); + "Use MemberGenericParameterTypeConstraintDependency for Generic Parameters of Methods." + ); } OriginGenericParameter = originGenericParameter; @@ -38,23 +41,26 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((TypeGenericParameterTypeConstraintDependency) obj); + return obj.GetType() == GetType() + && Equals((TypeGenericParameterTypeConstraintDependency)obj); } private bool Equals(TypeGenericParameterTypeConstraintDependency other) { - return Equals(OriginGenericParameter, other.OriginGenericParameter) && - Equals(TargetInstance, other.TargetInstance); + return Equals(OriginGenericParameter, other.OriginGenericParameter) + && Equals(TargetInstance, other.TargetInstance); } public override int GetHashCode() { unchecked { - var hashCode = OriginGenericParameter != null ? OriginGenericParameter.GetHashCode() : 0; - hashCode = (hashCode * 397) ^ (TargetInstance != null ? TargetInstance.GetHashCode() : 0); + var hashCode = + OriginGenericParameter != null ? OriginGenericParameter.GetHashCode() : 0; + hashCode = + (hashCode * 397) ^ (TargetInstance != null ? TargetInstance.GetHashCode() : 0); return hashCode; } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Dependencies/TypeInstanceDependency.cs b/ArchUnitNET/Domain/Dependencies/TypeInstanceDependency.cs index bc44afcfd..46a9985d4 100644 --- a/ArchUnitNET/Domain/Dependencies/TypeInstanceDependency.cs +++ b/ArchUnitNET/Domain/Dependencies/TypeInstanceDependency.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Collections.Generic; @@ -21,7 +21,8 @@ protected TypeInstanceDependency(IType origin, ITypeInstance targetInstan public IType Origin { get; } public IType Target => TargetInstance.Type; - public IEnumerable TargetGenericArguments => TargetInstance.GenericArguments; + public IEnumerable TargetGenericArguments => + TargetInstance.GenericArguments; public bool TargetIsArray => TargetInstance.IsArray; public IEnumerable TargetArrayDimensions => TargetInstance.ArrayDimensions; @@ -37,7 +38,7 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((TypeInstanceDependency) obj); + return obj.GetType() == GetType() && Equals((TypeInstanceDependency)obj); } private bool Equals(TypeInstanceDependency other) @@ -50,9 +51,10 @@ public override int GetHashCode() unchecked { var hashCode = Origin != null ? Origin.GetHashCode() : 0; - hashCode = (hashCode * 397) ^ (TargetInstance != null ? TargetInstance.GetHashCode() : 0); + hashCode = + (hashCode * 397) ^ (TargetInstance != null ? TargetInstance.GetHashCode() : 0); return hashCode; } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Dependencies/TypeReferenceDependency.cs b/ArchUnitNET/Domain/Dependencies/TypeReferenceDependency.cs index 5896e68a5..4d6537380 100644 --- a/ArchUnitNET/Domain/Dependencies/TypeReferenceDependency.cs +++ b/ArchUnitNET/Domain/Dependencies/TypeReferenceDependency.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 namespace ArchUnitNET.Domain.Dependencies @@ -9,8 +9,6 @@ namespace ArchUnitNET.Domain.Dependencies public class TypeReferenceDependency : TypeInstanceDependency { public TypeReferenceDependency(IType origin, ITypeInstance targetInstance) - : base(origin, targetInstance) - { - } + : base(origin, targetInstance) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Enum.cs b/ArchUnitNET/Domain/Enum.cs index 7e9b815b4..25b18254d 100644 --- a/ArchUnitNET/Domain/Enum.cs +++ b/ArchUnitNET/Domain/Enum.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -27,9 +27,10 @@ public Enum(IType type) public Class BaseClass => (Class)Dependencies.OfType().FirstOrDefault()?.Target; - public IEnumerable InheritedClasses => BaseClass == null - ? Enumerable.Empty() - : BaseClass.InheritedClasses.Concat(new[] { BaseClass }); + public IEnumerable InheritedClasses => + BaseClass == null + ? Enumerable.Empty() + : BaseClass.InheritedClasses.Concat(new[] { BaseClass }); public Visibility Visibility => Type.Visibility; public bool IsNested => Type.IsNested; @@ -41,7 +42,8 @@ public Enum(IType type) public Namespace Namespace => Type.Namespace; public Assembly Assembly => Type.Assembly; - public IEnumerable Attributes => AttributeInstances.Select(instance => instance.Type); + public IEnumerable Attributes => + AttributeInstances.Select(instance => instance.Type); public List AttributeInstances => Type.AttributeInstances; public List Dependencies => Type.Dependencies; @@ -81,4 +83,4 @@ public override int GetHashCode() return Type != null ? Type.GetHashCode() : 0; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/EnumerableIdentifier.cs b/ArchUnitNET/Domain/EnumerableIdentifier.cs index 8db381be8..80de8615f 100644 --- a/ArchUnitNET/Domain/EnumerableIdentifier.cs +++ b/ArchUnitNET/Domain/EnumerableIdentifier.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Collections.Generic; using System.Text; @@ -12,9 +12,8 @@ namespace ArchUnitNET.Domain { public class EnumerableIdentifier : StringIdentifier { - public EnumerableIdentifier(IEnumerable enumerable) : base(CreateIdentifierString(enumerable)) - { - } + public EnumerableIdentifier(IEnumerable enumerable) + : base(CreateIdentifierString(enumerable)) { } private static string CreateIdentifierString(IEnumerable enumerable) { @@ -29,4 +28,4 @@ private static string CreateIdentifierString(IEnumerable enume return sb.ToString(); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Exceptions/AssemblyDoesNotExistInArchitecture.cs b/ArchUnitNET/Domain/Exceptions/AssemblyDoesNotExistInArchitecture.cs index 2e1d71335..1ee64025a 100644 --- a/ArchUnitNET/Domain/Exceptions/AssemblyDoesNotExistInArchitecture.cs +++ b/ArchUnitNET/Domain/Exceptions/AssemblyDoesNotExistInArchitecture.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -10,8 +10,7 @@ namespace ArchUnitNET.Domain.Exceptions { public class AssemblyDoesNotExistInArchitecture : Exception { - public AssemblyDoesNotExistInArchitecture(string message) : base(message) - { - } + public AssemblyDoesNotExistInArchitecture(string message) + : base(message) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Exceptions/InvalidStateException.cs b/ArchUnitNET/Domain/Exceptions/InvalidStateException.cs index fb856f72f..5274f53b3 100644 --- a/ArchUnitNET/Domain/Exceptions/InvalidStateException.cs +++ b/ArchUnitNET/Domain/Exceptions/InvalidStateException.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -10,8 +10,7 @@ namespace ArchUnitNET.Domain.Exceptions { public class InvalidStateException : Exception { - public InvalidStateException(string message) : base(message) - { - } + public InvalidStateException(string message) + : base(message) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Exceptions/MultipleOccurrencesInSequenceException.cs b/ArchUnitNET/Domain/Exceptions/MultipleOccurrencesInSequenceException.cs index f3c9f36ad..cac137fcc 100644 --- a/ArchUnitNET/Domain/Exceptions/MultipleOccurrencesInSequenceException.cs +++ b/ArchUnitNET/Domain/Exceptions/MultipleOccurrencesInSequenceException.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -10,8 +10,7 @@ namespace ArchUnitNET.Domain.Exceptions { public class MultipleOccurrencesInSequenceException : Exception { - public MultipleOccurrencesInSequenceException(string message) : base(message) - { - } + public MultipleOccurrencesInSequenceException(string message) + : base(message) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Exceptions/TypeDoesNotExistInArchitecture.cs b/ArchUnitNET/Domain/Exceptions/TypeDoesNotExistInArchitecture.cs index ca1be47c1..debb309a4 100644 --- a/ArchUnitNET/Domain/Exceptions/TypeDoesNotExistInArchitecture.cs +++ b/ArchUnitNET/Domain/Exceptions/TypeDoesNotExistInArchitecture.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -10,8 +10,7 @@ namespace ArchUnitNET.Domain.Exceptions { public class TypeDoesNotExistInArchitecture : Exception { - public TypeDoesNotExistInArchitecture(string message) : base(message) - { - } + public TypeDoesNotExistInArchitecture(string message) + : base(message) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Extensions/ArchitectureExtensions.cs b/ArchUnitNET/Domain/Extensions/ArchitectureExtensions.cs index e6f2f91aa..724742562 100644 --- a/ArchUnitNET/Domain/Extensions/ArchitectureExtensions.cs +++ b/ArchUnitNET/Domain/Extensions/ArchitectureExtensions.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -35,7 +35,10 @@ public static IEnumerable AllAttributes(Architecture architecture) } [NotNull] - public static IType GetITypeOfType([NotNull] this Architecture architecture, [NotNull] Type type) + public static IType GetITypeOfType( + [NotNull] this Architecture architecture, + [NotNull] Type type + ) { if (type.IsClass) { @@ -56,18 +59,23 @@ public static IType GetITypeOfType([NotNull] this Architecture architecture, [No } throw new TypeDoesNotExistInArchitecture( - $"Type {type.FullName} does not exist in provided architecture."); + $"Type {type.FullName} does not exist in provided architecture." + ); } catch (MultipleOccurrencesInSequenceException) { throw new NotSupportedException( $"Type {type.FullName} found multiple times in provided architecture. Please use extern " - + "alias to reference assemblies that have the same fully-qualified type names."); + + "alias to reference assemblies that have the same fully-qualified type names." + ); } } [NotNull] - public static Class GetClassOfType([NotNull] this Architecture architecture, [NotNull] Type type) + public static Class GetClassOfType( + [NotNull] this Architecture architecture, + [NotNull] Type type + ) { try { @@ -78,18 +86,23 @@ public static Class GetClassOfType([NotNull] this Architecture architecture, [No } throw new TypeDoesNotExistInArchitecture( - $"Type {type.FullName} does not exist in provided architecture or is no class."); + $"Type {type.FullName} does not exist in provided architecture or is no class." + ); } catch (MultipleOccurrencesInSequenceException) { throw new NotSupportedException( $"Type {type.FullName} found multiple times in provided architecture. Please use extern " - + "alias to reference assemblies that have the same fully-qualified type names."); + + "alias to reference assemblies that have the same fully-qualified type names." + ); } } [NotNull] - public static Interface GetInterfaceOfType([NotNull] this Architecture architecture, [NotNull] Type type) + public static Interface GetInterfaceOfType( + [NotNull] this Architecture architecture, + [NotNull] Type type + ) { try { @@ -100,18 +113,23 @@ public static Interface GetInterfaceOfType([NotNull] this Architecture architect } throw new TypeDoesNotExistInArchitecture( - $"Type {type.FullName} does not exist in provided architecture or is no interface."); + $"Type {type.FullName} does not exist in provided architecture or is no interface." + ); } catch (MultipleOccurrencesInSequenceException) { throw new NotSupportedException( $"Type {type.FullName} found multiple times in provided architecture. Please use extern " - + "alias to reference assemblies that have the same fully-qualified type names."); + + "alias to reference assemblies that have the same fully-qualified type names." + ); } } [NotNull] - public static Attribute GetAttributeOfType([NotNull] this Architecture architecture, [NotNull] Type type) + public static Attribute GetAttributeOfType( + [NotNull] this Architecture architecture, + [NotNull] Type type + ) { try { @@ -122,19 +140,23 @@ public static Attribute GetAttributeOfType([NotNull] this Architecture architect } throw new TypeDoesNotExistInArchitecture( - $"Type {type.FullName} does not exist in provided architecture or is no attribute."); + $"Type {type.FullName} does not exist in provided architecture or is no attribute." + ); } catch (MultipleOccurrencesInSequenceException) { throw new NotSupportedException( $"Type {type.FullName} found multiple times in provided architecture. Please use extern " - + "alias to reference assemblies that have the same fully-qualified type names."); + + "alias to reference assemblies that have the same fully-qualified type names." + ); } } [NotNull] - public static Assembly GetAssemblyOfAssembly([NotNull] this Architecture architecture, - [NotNull] System.Reflection.Assembly assembly) + public static Assembly GetAssemblyOfAssembly( + [NotNull] this Architecture architecture, + [NotNull] System.Reflection.Assembly assembly + ) { try { @@ -145,13 +167,15 @@ public static Assembly GetAssemblyOfAssembly([NotNull] this Architecture archite } throw new AssemblyDoesNotExistInArchitecture( - $"Assembly {assembly.FullName} does not exist in provided architecture."); + $"Assembly {assembly.FullName} does not exist in provided architecture." + ); } catch (MultipleOccurrencesInSequenceException) { throw new NotSupportedException( - $"Assembly {assembly.FullName} found multiple times in provided architecture."); + $"Assembly {assembly.FullName} found multiple times in provided architecture." + ); } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Extensions/AssemblyExtensions.cs b/ArchUnitNET/Domain/Extensions/AssemblyExtensions.cs index c98615dc2..42b5245c4 100644 --- a/ArchUnitNET/Domain/Extensions/AssemblyExtensions.cs +++ b/ArchUnitNET/Domain/Extensions/AssemblyExtensions.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Linq; using System.Runtime.Versioning; @@ -14,28 +14,34 @@ public static class AssemblyExtensions { public static bool IsDotNetStandard(this Assembly assembly) { - return assembly.Name.StartsWith("netstandard") || assembly.GetTargetFramework().StartsWith(".NETStandard"); + return assembly.Name.StartsWith("netstandard") + || assembly.GetTargetFramework().StartsWith(".NETStandard"); } public static bool IsDotNetCore(this Assembly assembly) { return assembly.GetTargetFramework().StartsWith(".NETCore"); } - + public static bool IsDotNetFramework(this Assembly assembly) { - return assembly.Name.StartsWith("mscorlib") || assembly.GetTargetFramework().StartsWith(".NETFramework"); + return assembly.Name.StartsWith("mscorlib") + || assembly.GetTargetFramework().StartsWith(".NETFramework"); } public static string GetTargetFramework(this Assembly assembly) { var targetFrameworkAttribute = assembly.AttributeInstances.FirstOrDefault(att => - att.Type.FullName == typeof(TargetFrameworkAttribute).FullName); + att.Type.FullName == typeof(TargetFrameworkAttribute).FullName + ); - var frameworkNameAttribute = targetFrameworkAttribute?.AttributeArguments.FirstOrDefault(argument => - !(argument is AttributeNamedArgument namedArgument) || namedArgument.Name != "FrameworkDisplayName"); + var frameworkNameAttribute = + targetFrameworkAttribute?.AttributeArguments.FirstOrDefault(argument => + !(argument is AttributeNamedArgument namedArgument) + || namedArgument.Name != "FrameworkDisplayName" + ); return frameworkNameAttribute?.Value as string ?? ""; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Extensions/AttributeExtensions.cs b/ArchUnitNET/Domain/Extensions/AttributeExtensions.cs index cde988ae3..88df21bf6 100644 --- a/ArchUnitNET/Domain/Extensions/AttributeExtensions.cs +++ b/ArchUnitNET/Domain/Extensions/AttributeExtensions.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Linq; @@ -11,15 +11,27 @@ namespace ArchUnitNET.Domain.Extensions { public static class AttributeExtensions { - public static bool HasAttribute(this IHasAttributes a, string pattern, bool useRegularExpressions = false) + public static bool HasAttribute( + this IHasAttributes a, + string pattern, + bool useRegularExpressions = false + ) { - return a.Attributes.Any(attribute => attribute.FullNameMatches(pattern, useRegularExpressions)); + return a.Attributes.Any(attribute => + attribute.FullNameMatches(pattern, useRegularExpressions) + ); } - public static bool OnlyHasAttributes(this IHasAttributes a, string pattern, bool useRegularExpressions = false) + public static bool OnlyHasAttributes( + this IHasAttributes a, + string pattern, + bool useRegularExpressions = false + ) { - return a.Attributes.IsNullOrEmpty() || - a.Attributes.All(attribute => attribute.FullNameMatches(pattern, useRegularExpressions)); + 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 index 6e3e8ba85..565bd218a 100644 --- a/ArchUnitNET/Domain/Extensions/DependencyExtensions.cs +++ b/ArchUnitNET/Domain/Extensions/DependencyExtensions.cs @@ -1,9 +1,9 @@ // 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; @@ -13,32 +13,48 @@ namespace ArchUnitNET.Domain.Extensions { public static class DependencyExtensions { - public static bool CallsMethod(this IHasDependencies type, string pattern, bool useRegularExpressions = false) + public static bool CallsMethod( + this IHasDependencies type, + string pattern, + bool useRegularExpressions = false + ) { - return type.GetCalledMethods().Any(member => member.FullNameMatches(pattern, useRegularExpressions)); + 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); + return type + .Dependencies.OfType() + .Select(dependency => (MethodMember)dependency.TargetMember); } public static IEnumerable GetAccessedFieldMembers(this IHasDependencies type) { - return type.Dependencies.OfType() - .Select(dependency => (FieldMember) dependency.TargetMember); + return type + .Dependencies.OfType() + .Select(dependency => (FieldMember)dependency.TargetMember); } - public static bool DependsOn(this IHasDependencies c, string pattern, bool useRegularExpressions = false) + public static bool DependsOn( + this IHasDependencies c, + string pattern, + bool useRegularExpressions = false + ) { - return c.GetTypeDependencies().Any(d => d.FullNameMatches(pattern, useRegularExpressions)); + return c.GetTypeDependencies() + .Any(d => d.FullNameMatches(pattern, useRegularExpressions)); } - - public static bool OnlyDependsOn(this IHasDependencies c, string pattern, bool useRegularExpressions = false) + public static bool OnlyDependsOn( + this IHasDependencies c, + string pattern, + bool useRegularExpressions = false + ) { - return c.GetTypeDependencies().All(d => d.FullNameMatches(pattern, useRegularExpressions)); + return c.GetTypeDependencies() + .All(d => d.FullNameMatches(pattern, useRegularExpressions)); } public static IEnumerable GetTypeDependencies(this IHasDependencies c) @@ -46,17 +62,24 @@ public static IEnumerable GetTypeDependencies(this IHasDependencies c) return c.Dependencies.Select(dependency => dependency.Target); } - public static IEnumerable GetTypeDependencies(this IHasDependencies c, Architecture architecture) + public static IEnumerable GetTypeDependencies( + this IHasDependencies c, + Architecture architecture + ) { - return c.Dependencies.Select(dependency => dependency.Target).Intersect(architecture.Types); + return c + .Dependencies.Select(dependency => dependency.Target) + .Intersect(architecture.Types); } - public static IEnumerable GetFieldTypeDependencies(this IHasDependencies type, - bool getBackwardsDependencies = false) + 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 index f2367b47e..e43df29f4 100644 --- a/ArchUnitNET/Domain/Extensions/EnumerableExtensions.cs +++ b/ArchUnitNET/Domain/Extensions/EnumerableExtensions.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -28,4 +28,4 @@ public static bool IsNullOrEmpty(this IEnumerable source) return source == null || !source.Any(); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Extensions/MemberExtensions.cs b/ArchUnitNET/Domain/Extensions/MemberExtensions.cs index 7376e799e..854eaa0e9 100644 --- a/ArchUnitNET/Domain/Extensions/MemberExtensions.cs +++ b/ArchUnitNET/Domain/Extensions/MemberExtensions.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -12,7 +12,11 @@ namespace ArchUnitNET.Domain.Extensions { public static class MemberExtensions { - public static bool IsDeclaredIn(this IMember member, string pattern, bool useRegularExpressions = false) + public static bool IsDeclaredIn( + this IMember member, + string pattern, + bool useRegularExpressions = false + ) { return member.DeclaringType.FullNameMatches(pattern, useRegularExpressions); } @@ -22,80 +26,122 @@ public static bool IsDeclaredIn(this IMember member, IType type) return member.DeclaringType.Equals(type); } - public static IEnumerable GetBodyTypeMemberDependencies(this IMember member, - bool getBackwardsDependencies = false) + public static IEnumerable GetBodyTypeMemberDependencies( + this IMember member, + bool getBackwardsDependencies = false + ) { return getBackwardsDependencies ? member.MemberBackwardsDependencies.OfType() : member.MemberDependencies.OfType(); } - public static bool HasBodyTypeMemberDependencies(this IMember member, bool getBackwardsDependencies = false) + public static bool HasBodyTypeMemberDependencies( + this IMember member, + bool getBackwardsDependencies = false + ) { return member.GetBodyTypeMemberDependencies(getBackwardsDependencies).Any(); } - public static IEnumerable GetMethodCallDependencies(this IMember member, - bool getBackwardsDependencies = false) + public static IEnumerable GetMethodCallDependencies( + this IMember member, + bool getBackwardsDependencies = false + ) { return getBackwardsDependencies ? member.MemberBackwardsDependencies.OfType() : member.MemberDependencies.OfType(); } - public static bool HasMethodCallDependencies(this IMember member, bool getBackwardsDependencies = false) + public static bool HasMethodCallDependencies( + this IMember member, + bool getBackwardsDependencies = false + ) { return member.GetMethodCallDependencies(getBackwardsDependencies).Any(); } - public static bool IsCalledBy(this MethodMember member, string pattern, bool useRegularExpressions = false) + public static bool IsCalledBy( + this MethodMember member, + string pattern, + bool useRegularExpressions = false + ) { - return member.GetMethodCallDependencies(true).Any(dependency => - dependency.Origin.FullNameMatches(pattern, useRegularExpressions)); + return member + .GetMethodCallDependencies(true) + .Any(dependency => + dependency.Origin.FullNameMatches(pattern, useRegularExpressions) + ); } public static IEnumerable GetCallingTypes(this MethodMember member) { - return member.MemberBackwardsDependencies.OfType() - .Select(dependency => dependency.Origin).Distinct(); + return member + .MemberBackwardsDependencies.OfType() + .Select(dependency => dependency.Origin) + .Distinct(); } - public static bool HasDependencyInMethodBodyTo(this MethodMember member, string pattern, - bool useRegularExpressions = false) + public static bool HasDependencyInMethodBodyTo( + this MethodMember member, + string pattern, + bool useRegularExpressions = false + ) { - return member.GetBodyTypeMemberDependencies().Any(dependency => - dependency.Target.FullNameMatches(pattern, useRegularExpressions)); + return member + .GetBodyTypeMemberDependencies() + .Any(dependency => + dependency.Target.FullNameMatches(pattern, useRegularExpressions) + ); } - public static bool HasFieldTypeDependencies(this IMember member, bool getBackwardsDependencies = false) + public static bool HasFieldTypeDependencies( + this IMember member, + bool getBackwardsDependencies = false + ) { return member.GetFieldTypeDependencies(getBackwardsDependencies).Any(); } public static Attribute GetAttributeFromMember(this IMember member, Class attributeClass) { - return member.Attributes.FirstOrDefault(attribute => attribute.FullName.Equals(attributeClass.FullName)); + return member.Attributes.FirstOrDefault(attribute => + attribute.FullName.Equals(attributeClass.FullName) + ); } - public static bool HasMethodSignatureDependency(this IMember member, - MethodSignatureDependency methodSignatureDependency, bool getBackwardsDependencies = false) + public static bool HasMethodSignatureDependency( + this IMember member, + MethodSignatureDependency methodSignatureDependency, + bool getBackwardsDependencies = false + ) { return getBackwardsDependencies - ? member.MemberBackwardsDependencies.OfType() + ? member + .MemberBackwardsDependencies.OfType() .Contains(methodSignatureDependency) - : member.MemberDependencies.OfType().Contains(methodSignatureDependency); + : member + .MemberDependencies.OfType() + .Contains(methodSignatureDependency); } - public static bool HasMemberDependency(this IMember member, - IMemberTypeDependency memberDependency, bool getBackwardsDependencies = false) + public static bool HasMemberDependency( + this IMember member, + IMemberTypeDependency memberDependency, + bool getBackwardsDependencies = false + ) { return getBackwardsDependencies ? member.MemberBackwardsDependencies.Contains(memberDependency) : member.MemberDependencies.Contains(memberDependency); } - public static bool HasDependency(this IMember member, - IMemberTypeDependency memberDependency, bool getBackwardsDependencies = false) + public static bool HasDependency( + this IMember member, + IMemberTypeDependency memberDependency, + bool getBackwardsDependencies = false + ) { return getBackwardsDependencies ? member.BackwardsDependencies.Contains(memberDependency) @@ -107,4 +153,4 @@ public static bool IsConstructor(this MethodMember methodMember) return methodMember.MethodForm == MethodForm.Constructor; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Extensions/NamingExtensions.cs b/ArchUnitNET/Domain/Extensions/NamingExtensions.cs index bf43f8012..f695c8968 100644 --- a/ArchUnitNET/Domain/Extensions/NamingExtensions.cs +++ b/ArchUnitNET/Domain/Extensions/NamingExtensions.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System; using System.Collections.Generic; @@ -16,25 +16,38 @@ namespace ArchUnitNET.Domain.Extensions { public static class NamingExtensions { - public static bool NameEndsWith(this IHasName cls, string pattern, - StringComparison stringComparison = StringComparison.CurrentCulture) + public static bool NameEndsWith( + this IHasName cls, + string pattern, + StringComparison stringComparison = StringComparison.CurrentCulture + ) { return cls.Name.EndsWith(pattern, stringComparison); } - public static bool NameStartsWith(this IHasName cls, string pattern, - StringComparison stringComparison = StringComparison.CurrentCulture) + public static bool NameStartsWith( + this IHasName cls, + string pattern, + StringComparison stringComparison = StringComparison.CurrentCulture + ) { return cls.Name.StartsWith(pattern, stringComparison); } - public static bool NameContains(this IHasName cls, string pattern, - StringComparison stringComparison = StringComparison.Ordinal) + public static bool NameContains( + this IHasName cls, + string pattern, + StringComparison stringComparison = StringComparison.Ordinal + ) { return cls.Name.IndexOf(pattern, stringComparison) >= 0; } - public static bool NameMatches(this IHasName cls, string pattern, bool useRegularExpressions = false) + public static bool NameMatches( + this IHasName cls, + string pattern, + bool useRegularExpressions = false + ) { if (useRegularExpressions) { @@ -44,7 +57,11 @@ public static bool NameMatches(this IHasName cls, string pattern, bool useRegula return string.Equals(cls.Name, pattern, StringComparison.OrdinalIgnoreCase); } - public static bool FullNameMatches(this IHasName cls, string pattern, bool useRegularExpressions = false) + public static bool FullNameMatches( + this IHasName cls, + string pattern, + bool useRegularExpressions = false + ) { if (useRegularExpressions) { @@ -60,7 +77,10 @@ public static bool FullNameContains(this IHasName cls, string pattern) } [NotNull] - public static IEnumerable WhereNameIs(this IEnumerable source, string name) + public static IEnumerable WhereNameIs( + this IEnumerable source, + string name + ) where TType : IHasName { return source.Where(hasName => hasName.Name == name); @@ -76,10 +96,11 @@ public static TType WhereFullNameIs(this IEnumerable source, strin { throw new MultipleOccurrencesInSequenceException( $"Full name {fullName} found multiple times in provided types. Please use extern " - + "alias to reference assemblies that have the same fully-qualified type names."); + + "alias to reference assemblies that have the same fully-qualified type names." + ); } return withFullName.FirstOrDefault(); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Extensions/NullableExtensions.cs b/ArchUnitNET/Domain/Extensions/NullableExtensions.cs index b582f67d2..19a77152d 100644 --- a/ArchUnitNET/Domain/Extensions/NullableExtensions.cs +++ b/ArchUnitNET/Domain/Extensions/NullableExtensions.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain.Exceptions; @@ -20,4 +20,4 @@ public static T RequiredNotNull(this T obj) return obj; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Extensions/TypeExtensions.cs b/ArchUnitNET/Domain/Extensions/TypeExtensions.cs index 29614c298..32e2b1f64 100644 --- a/ArchUnitNET/Domain/Extensions/TypeExtensions.cs +++ b/ArchUnitNET/Domain/Extensions/TypeExtensions.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -21,10 +21,15 @@ public static bool ImplementsInterface(this IType type, Interface intf) } return type.ImplementedInterfaces.Any(implementedInterface => - Equals(implementedInterface, intf)); + Equals(implementedInterface, intf) + ); } - public static bool ImplementsInterface(this IType type, string pattern, bool useRegularExpressions = false) + public static bool ImplementsInterface( + this IType type, + string pattern, + bool useRegularExpressions = false + ) { if (type is GenericParameter) { @@ -32,27 +37,37 @@ public static bool ImplementsInterface(this IType type, string pattern, bool use } return type.ImplementedInterfaces.Any(implementedInterface => - implementedInterface.FullNameMatches(pattern, useRegularExpressions)); + implementedInterface.FullNameMatches(pattern, useRegularExpressions) + ); } public static bool IsAssignableTo(this IType type, IType assignableToType) { if (type is GenericParameter genericParameter) { - return genericParameter.TypeConstraints.All(t => t.IsAssignableTo(assignableToType)); + return genericParameter.TypeConstraints.All(t => + t.IsAssignableTo(assignableToType) + ); } return type.GetAssignableTypes().Contains(assignableToType); } - public static bool IsAssignableTo(this IType type, string pattern, bool useRegularExpressions = false) + public static bool IsAssignableTo( + this IType type, + string pattern, + bool useRegularExpressions = false + ) { if (type is GenericParameter genericParameter) { - return genericParameter.TypeConstraints.All(t => t.IsAssignableTo(pattern, useRegularExpressions)); + return genericParameter.TypeConstraints.All(t => + t.IsAssignableTo(pattern, useRegularExpressions) + ); } - return type.GetAssignableTypes().Any(t => t.FullNameMatches(pattern, useRegularExpressions)); + return type.GetAssignableTypes() + .Any(t => t.FullNameMatches(pattern, useRegularExpressions)); } public static bool IsNestedIn(this IType type, IType assignableToType) @@ -72,8 +87,12 @@ public static bool IsAnonymousType(this IType type) public static IEnumerable SlicedBy(this IEnumerable source, string fullName) { - return source.GroupBy(type => type.FullName) - .Select(sliceItems => new Slice(SliceIdentifier.Of(sliceItems.Key), sliceItems.ToList())); + return source + .GroupBy(type => type.FullName) + .Select(sliceItems => new Slice( + SliceIdentifier.Of(sliceItems.Key), + sliceItems.ToList() + )); } public static IEnumerable GetAssignableTypes(this IType type) @@ -81,13 +100,19 @@ public static IEnumerable GetAssignableTypes(this IType type) switch (type) { case Interface intf: - return intf.ImplementedInterfaces.Concat(new[] {intf}); + return intf.ImplementedInterfaces.Concat(new[] { intf }); case Class cls: - return cls.InheritedClasses.Concat(new[] {cls}).Concat(cls.ImplementedInterfaces); + return cls + .InheritedClasses.Concat(new[] { cls }) + .Concat(cls.ImplementedInterfaces); case Struct str: - return str.InheritedClasses.Concat(new IType[] {str}).Concat(str.ImplementedInterfaces); + return str + .InheritedClasses.Concat(new IType[] { str }) + .Concat(str.ImplementedInterfaces); case Enum en: - return en.InheritedClasses.Concat(new IType[] {en}).Concat(en.ImplementedInterfaces); + return en + .InheritedClasses.Concat(new IType[] { en }) + .Concat(en.ImplementedInterfaces); default: return Enumerable.Empty(); } @@ -98,19 +123,28 @@ public static IEnumerable GetNestedTypes(this IType type) switch (type) { case Interface intf: - return intf.ImplementedInterfaces.Concat(new[] {intf}); + return intf.ImplementedInterfaces.Concat(new[] { intf }); case Class cls: - return cls.InheritedClasses.Concat(new[] {cls}).Concat(cls.ImplementedInterfaces); + return cls + .InheritedClasses.Concat(new[] { cls }) + .Concat(cls.ImplementedInterfaces); case Struct str: - return str.InheritedClasses.Concat(new IType[] {str}).Concat(str.ImplementedInterfaces); + return str + .InheritedClasses.Concat(new IType[] { str }) + .Concat(str.ImplementedInterfaces); case Enum en: - return en.InheritedClasses.Concat(new IType[] {en}).Concat(en.ImplementedInterfaces); + return en + .InheritedClasses.Concat(new IType[] { en }) + .Concat(en.ImplementedInterfaces); default: return Enumerable.Empty(); } } - public static IEnumerable GetPropertyMembersWithName(this IType type, string name) + public static IEnumerable GetPropertyMembersWithName( + this IType type, + string name + ) { return type.GetPropertyMembers().WhereNameIs(name); } @@ -130,7 +164,10 @@ public static bool HasFieldMemberWithName(this IType type, string name) return !type.GetFieldMembersWithName(name).IsNullOrEmpty(); } - public static IEnumerable GetMethodMembersWithName(this IType type, string name) + public static IEnumerable GetMethodMembersWithName( + this IType type, + string name + ) { return type.GetMethodMembers().WhereNameIs(name); } @@ -192,23 +229,39 @@ public static bool HasMemberWithFullName(this IType type, string fullname) public static Attribute GetAttributeOfType(this IType type, Class attributeClass) { - return type.Attributes.FirstOrDefault(attribute => attribute.FullName.Equals(attributeClass.FullName)); + return type.Attributes.FirstOrDefault(attribute => + attribute.FullName.Equals(attributeClass.FullName) + ); } - public static bool ResidesInNamespace(this IType e, string pattern, bool useRegularExpressions = false) + 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) + 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) + public static bool IsDeclaredAsFieldIn( + this IType type, + string pattern, + bool useRegularExpressions = false + ) { - return type.GetFieldTypeDependencies(true).Any(dependency => - dependency.Target.FullNameMatches(pattern, useRegularExpressions)); + return type.GetFieldTypeDependencies(true) + .Any(dependency => + dependency.Target.FullNameMatches(pattern, useRegularExpressions) + ); } public static bool HasDependency(this IType type, ITypeDependency dependency) @@ -216,7 +269,10 @@ public static bool HasDependency(this IType type, ITypeDependency dependency) return type.Dependencies.Contains(dependency); } - public static bool HasDependencies(this IType type, IEnumerable dependencies) + public static bool HasDependencies( + this IType type, + IEnumerable dependencies + ) { return dependencies.All(dependency => type.Dependencies.Contains(dependency)); } @@ -241,24 +297,30 @@ public static IEnumerable GetConstructors(this IType type) return type.GetMethodMembers().Where(method => method.IsConstructor()); } - public static IEnumerable GetAttributeTypeDependencies(this IType type, - bool getBackwardsDependencies = false) + 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) + 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) + public static IEnumerable GetInheritsBaseClassDependencies( + this IType type, + bool getBackwardsDependencies = false + ) { return getBackwardsDependencies ? type.BackwardsDependencies.OfType() @@ -281,8 +343,13 @@ public static bool MatchesType(this ITypeInstance typeInstance, Type targ return true; } - return !typeInstance.GenericArguments.Where((t, i) => - !targetGenericArguments[i].IsGenericParameter && !t.MatchesType(targetGenericArguments[i])).Any(); + return !typeInstance + .GenericArguments.Where( + (t, i) => + !targetGenericArguments[i].IsGenericParameter + && !t.MatchesType(targetGenericArguments[i]) + ) + .Any(); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/FieldMember.cs b/ArchUnitNET/Domain/FieldMember.cs index ba981f383..03e5b75b2 100644 --- a/ArchUnitNET/Domain/FieldMember.cs +++ b/ArchUnitNET/Domain/FieldMember.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -14,8 +14,16 @@ public class FieldMember : IMember, ITypeInstance { private readonly ITypeInstance _typeInstance; - public FieldMember(IType declaringType, string name, string fullName, Visibility visibility, - ITypeInstance typeInstance, bool isCompilerGenerated, bool? isStatic, Writability writability) + public FieldMember( + IType declaringType, + string name, + string fullName, + Visibility visibility, + ITypeInstance typeInstance, + bool isCompilerGenerated, + bool? isStatic, + Writability writability + ) { DeclaringType = declaringType; Name = name; @@ -38,11 +46,15 @@ public FieldMember(IType declaringType, string name, string fullName, Visibility public Writability? Writability { get; } public bool IsGeneric => false; public List GenericParameters => new List(); - public IEnumerable Attributes => AttributeInstances.Select(instance => instance.Type); + public IEnumerable Attributes => + AttributeInstances.Select(instance => instance.Type); public List AttributeInstances { get; } = new List(); - public List MemberDependencies { get; } = new List(); - public List MemberBackwardsDependencies { get; } = new List(); - public List Dependencies => MemberDependencies.Cast().ToList(); + public List MemberDependencies { get; } = + new List(); + public List MemberBackwardsDependencies { get; } = + new List(); + public List Dependencies => + MemberDependencies.Cast().ToList(); public List BackwardsDependencies => MemberBackwardsDependencies.Cast().ToList(); @@ -69,7 +81,7 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((FieldMember) obj); + return obj.GetType() == GetType() && Equals((FieldMember)obj); } private bool Equals(FieldMember other) @@ -82,4 +94,4 @@ public override int GetHashCode() return FullName.GetHashCode(); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/GenericArgument.cs b/ArchUnitNET/Domain/GenericArgument.cs index 4e9a1057c..b5460a902 100644 --- a/ArchUnitNET/Domain/GenericArgument.cs +++ b/ArchUnitNET/Domain/GenericArgument.cs @@ -1,9 +1,9 @@ // 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; @@ -35,7 +35,7 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((GenericArgument) obj); + return obj.GetType() == GetType() && Equals((GenericArgument)obj); } private bool Equals(GenericArgument other) @@ -50,7 +50,8 @@ private bool Equals(GenericArgument other) return true; } - return Equals(Type, other.Type) && GenericArguments.SequenceEqual(other.GenericArguments); + return Equals(Type, other.Type) + && GenericArguments.SequenceEqual(other.GenericArguments); } public override int GetHashCode() @@ -58,8 +59,10 @@ public override int GetHashCode() unchecked { var hashCode = Type != null ? Type.GetHashCode() : 0; - hashCode = GenericArguments.Aggregate(hashCode, - (current, type) => (current * 397) ^ (type != null ? type.GetHashCode() : 0)); + hashCode = GenericArguments.Aggregate( + hashCode, + (current, type) => (current * 397) ^ (type != null ? type.GetHashCode() : 0) + ); return hashCode; } } @@ -69,4 +72,4 @@ public override string ToString() return Type.FullName; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/GenericParameter.cs b/ArchUnitNET/Domain/GenericParameter.cs index 1e4a177df..337e6a8ad 100644 --- a/ArchUnitNET/Domain/GenericParameter.cs +++ b/ArchUnitNET/Domain/GenericParameter.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -17,10 +17,17 @@ public class GenericParameter : IType private readonly string _declarerFullName; internal readonly IEnumerable> TypeInstanceConstraints; - public GenericParameter(string declarerFullName, string name, GenericParameterVariance variance, - IEnumerable> typeConstraints, bool hasReferenceTypeConstraint, - bool hasNotNullableValueTypeConstraint, bool hasDefaultConstructorConstraint, bool isCompilerGenerated, - bool declarerIsMethod) + public GenericParameter( + string declarerFullName, + string name, + GenericParameterVariance variance, + IEnumerable> typeConstraints, + bool hasReferenceTypeConstraint, + bool hasNotNullableValueTypeConstraint, + bool hasDefaultConstructorConstraint, + bool isCompilerGenerated, + bool declarerIsMethod + ) { _declarerFullName = declarerFullName; Name = name; @@ -34,22 +41,29 @@ public GenericParameter(string declarerFullName, string name, GenericParameterVa } public IType DeclaringType { get; private set; } - [CanBeNull] public IMember DeclaringMethod { get; private set; } + + [CanBeNull] + public IMember DeclaringMethod { get; private set; } public bool DeclarerIsMethod { get; } public GenericParameterVariance Variance { get; } - public IEnumerable TypeConstraints => TypeInstanceConstraints.Select(instance => instance.Type); + public IEnumerable TypeConstraints => + TypeInstanceConstraints.Select(instance => instance.Type); public bool HasReferenceTypeConstraint { get; } public bool HasNotNullableValueTypeConstraint { get; } public bool HasDefaultConstructorConstraint { get; } - public bool HasConstraints => HasReferenceTypeConstraint || HasNotNullableValueTypeConstraint || - HasDefaultConstructorConstraint || TypeConstraints.Any(); + public bool HasConstraints => + HasReferenceTypeConstraint + || HasNotNullableValueTypeConstraint + || HasDefaultConstructorConstraint + || TypeConstraints.Any(); public string Name { get; } public string FullName => _declarerFullName + "+<" + Name + ">"; public bool IsCompilerGenerated { get; } - public IEnumerable Attributes => AttributeInstances.Select(instance => instance.Type); - public List AttributeInstances { get; } = new List(); + public IEnumerable Attributes => + AttributeInstances.Select(instance => instance.Type); + public List AttributeInstances { get; } = new List(); public List Dependencies { get; } = new List(); public List BackwardsDependencies { get; } = new List(); @@ -118,7 +132,7 @@ public override bool Equals(object obj) return false; } - return Equals((GenericParameter) obj); + return Equals((GenericParameter)obj); } public override int GetHashCode() @@ -138,4 +152,4 @@ public enum GenericParameterVariance Covariant, Contravariant } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/ICanBeAnalyzed.cs b/ArchUnitNET/Domain/ICanBeAnalyzed.cs index 00f4f3613..077f5741e 100644 --- a/ArchUnitNET/Domain/ICanBeAnalyzed.cs +++ b/ArchUnitNET/Domain/ICanBeAnalyzed.cs @@ -1,14 +1,16 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 namespace ArchUnitNET.Domain { - public interface - ICanBeAnalyzed : IHasName, IHasDependencies, IHasAttributes, IHasVisibility, ICanBeGeneric, - ICanBeCompilerGenerated - { - } -} \ No newline at end of file + public interface ICanBeAnalyzed + : IHasName, + IHasDependencies, + IHasAttributes, + IHasVisibility, + ICanBeGeneric, + ICanBeCompilerGenerated { } +} diff --git a/ArchUnitNET/Domain/ICanBeCompilerGenerated.cs b/ArchUnitNET/Domain/ICanBeCompilerGenerated.cs index 13d9ad6cc..12929bce8 100644 --- a/ArchUnitNET/Domain/ICanBeCompilerGenerated.cs +++ b/ArchUnitNET/Domain/ICanBeCompilerGenerated.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// namespace ArchUnitNET.Domain { @@ -11,4 +11,4 @@ public interface ICanBeCompilerGenerated { bool IsCompilerGenerated { get; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/ICanBeGeneric.cs b/ArchUnitNET/Domain/ICanBeGeneric.cs index 3a2c91c4e..11a6fee7a 100644 --- a/ArchUnitNET/Domain/ICanBeGeneric.cs +++ b/ArchUnitNET/Domain/ICanBeGeneric.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Collections.Generic; @@ -14,4 +14,4 @@ public interface ICanBeGeneric bool IsGeneric { get; } List GenericParameters { get; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/IHasAttributes.cs b/ArchUnitNET/Domain/IHasAttributes.cs index 0e0f4dfa2..b9bdf612c 100644 --- a/ArchUnitNET/Domain/IHasAttributes.cs +++ b/ArchUnitNET/Domain/IHasAttributes.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -13,4 +13,4 @@ public interface IHasAttributes IEnumerable Attributes { get; } List AttributeInstances { get; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/IHasDependencies.cs b/ArchUnitNET/Domain/IHasDependencies.cs index 29fa98b34..f6b433dc3 100644 --- a/ArchUnitNET/Domain/IHasDependencies.cs +++ b/ArchUnitNET/Domain/IHasDependencies.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -14,4 +14,4 @@ public interface IHasDependencies List Dependencies { get; } List BackwardsDependencies { get; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/IHasDescription.cs b/ArchUnitNET/Domain/IHasDescription.cs index dacc0ae8c..19cd18b4b 100644 --- a/ArchUnitNET/Domain/IHasDescription.cs +++ b/ArchUnitNET/Domain/IHasDescription.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 namespace ArchUnitNET.Domain @@ -10,4 +10,4 @@ public interface IHasDescription { string Description { get; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/IHasName.cs b/ArchUnitNET/Domain/IHasName.cs index d3e58e0d5..4ec49255c 100644 --- a/ArchUnitNET/Domain/IHasName.cs +++ b/ArchUnitNET/Domain/IHasName.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 namespace ArchUnitNET.Domain @@ -11,4 +11,4 @@ public interface IHasName string Name { get; } string FullName { get; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/IHasVisibility.cs b/ArchUnitNET/Domain/IHasVisibility.cs index 525b77b88..1f81e19c5 100644 --- a/ArchUnitNET/Domain/IHasVisibility.cs +++ b/ArchUnitNET/Domain/IHasVisibility.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 namespace ArchUnitNET.Domain @@ -10,4 +10,4 @@ public interface IHasVisibility { Visibility Visibility { get; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/IMember.cs b/ArchUnitNET/Domain/IMember.cs index 433ef2857..dbe618971 100644 --- a/ArchUnitNET/Domain/IMember.cs +++ b/ArchUnitNET/Domain/IMember.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -17,4 +17,4 @@ public interface IMember : ICanBeAnalyzed bool? IsStatic { get; } Writability? Writability { get; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/IObjectProvider.cs b/ArchUnitNET/Domain/IObjectProvider.cs index b3589dd1c..6f0190fa6 100644 --- a/ArchUnitNET/Domain/IObjectProvider.cs +++ b/ArchUnitNET/Domain/IObjectProvider.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -12,4 +12,4 @@ public interface IObjectProvider : IHasDescription { IEnumerable GetObjects(Architecture architecture); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/IType.cs b/ArchUnitNET/Domain/IType.cs index 5d35d7878..56ba06e4b 100644 --- a/ArchUnitNET/Domain/IType.cs +++ b/ArchUnitNET/Domain/IType.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -18,4 +18,4 @@ public interface IType : ICanBeAnalyzed bool IsStub { get; } bool IsGenericParameter { get; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/ITypeInstance.cs b/ArchUnitNET/Domain/ITypeInstance.cs index eee503e48..6556311c0 100644 --- a/ArchUnitNET/Domain/ITypeInstance.cs +++ b/ArchUnitNET/Domain/ITypeInstance.cs @@ -1,19 +1,20 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Collections.Generic; namespace ArchUnitNET.Domain { - public interface ITypeInstance where T : IType + public interface ITypeInstance + where T : IType { T Type { get; } IEnumerable GenericArguments { get; } bool IsArray { get; } IEnumerable ArrayDimensions { get; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Interface.cs b/ArchUnitNET/Domain/Interface.cs index bbeff3370..81d50add4 100644 --- a/ArchUnitNET/Domain/Interface.cs +++ b/ArchUnitNET/Domain/Interface.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -32,7 +32,8 @@ public Interface(IType type) public Namespace Namespace => Type.Namespace; public Assembly Assembly => Type.Assembly; - public IEnumerable Attributes => AttributeInstances.Select(instance => instance.Type); + public IEnumerable Attributes => + AttributeInstances.Select(instance => instance.Type); public List AttributeInstances => Type.AttributeInstances; public List Dependencies => Type.Dependencies; @@ -64,7 +65,7 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((Interface) obj); + return obj.GetType() == GetType() && Equals((Interface)obj); } public override int GetHashCode() @@ -72,4 +73,4 @@ public override int GetHashCode() return Type != null ? Type.GetHashCode() : 0; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/MemberList.cs b/ArchUnitNET/Domain/MemberList.cs index afb80bb7d..9cac00bf7 100644 --- a/ArchUnitNET/Domain/MemberList.cs +++ b/ArchUnitNET/Domain/MemberList.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections; @@ -15,9 +15,7 @@ public class MemberList : IList { private readonly IList _list = new List(); - public MemberList() - { - } + public MemberList() { } public MemberList(IList list) { @@ -112,9 +110,9 @@ public bool Equals(MemberList other) return true; } - - return _list.SequenceEqual(other._list) && Equals(Count, other.Count) && - Equals(IsReadOnly, other.IsReadOnly); + return _list.SequenceEqual(other._list) + && Equals(Count, other.Count) + && Equals(IsReadOnly, other.IsReadOnly); } public override bool Equals(object obj) @@ -134,7 +132,7 @@ public override bool Equals(object obj) return false; } - return Equals((MemberList) obj); + return Equals((MemberList)obj); } public override int GetHashCode() @@ -148,4 +146,4 @@ public override int GetHashCode() } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/MethodForm.cs b/ArchUnitNET/Domain/MethodForm.cs index 85ad04a13..1ac821232 100644 --- a/ArchUnitNET/Domain/MethodForm.cs +++ b/ArchUnitNET/Domain/MethodForm.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 namespace ArchUnitNET.Domain @@ -13,4 +13,4 @@ public enum MethodForm Setter, Normal } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/MethodMember.cs b/ArchUnitNET/Domain/MethodMember.cs index 0f0cceda9..4e5ae9ab1 100644 --- a/ArchUnitNET/Domain/MethodMember.cs +++ b/ArchUnitNET/Domain/MethodMember.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -12,9 +12,20 @@ namespace ArchUnitNET.Domain { public class MethodMember : IMember { - public MethodMember(string name, string fullName, IType declaringType, Visibility visibility, - ITypeInstance returnTypeInstance, bool isVirtual, MethodForm methodForm, bool isGeneric, bool isStub, - bool isCompilerGenerated, bool? isIterator, bool? isStatic) + public MethodMember( + string name, + string fullName, + IType declaringType, + Visibility visibility, + ITypeInstance returnTypeInstance, + bool isVirtual, + MethodForm methodForm, + bool isGeneric, + bool isStub, + bool isCompilerGenerated, + bool? isIterator, + bool? isStatic + ) { Name = name; FullName = fullName; @@ -33,8 +44,10 @@ public MethodMember(string name, string fullName, IType declaringType, Visibilit public bool IsVirtual { get; } public MethodForm MethodForm { get; } - public List> ParameterInstances { get; } = new List>(); - public IEnumerable Parameters => ParameterInstances.Select(instance => instance.Type); + public List> ParameterInstances { get; } = + new List>(); + public IEnumerable Parameters => + ParameterInstances.Select(instance => instance.Type); public ITypeInstance ReturnTypeInstance { get; } public IType ReturnType => ReturnTypeInstance.Type; public bool IsStub { get; } @@ -45,11 +58,15 @@ public MethodMember(string name, string fullName, IType declaringType, Visibilit public Writability? Writability => null; public List GenericParameters { get; } = new List(); public Visibility Visibility { get; } - public IEnumerable Attributes => AttributeInstances.Select(instance => instance.Type); + public IEnumerable Attributes => + AttributeInstances.Select(instance => instance.Type); public List AttributeInstances { get; } = new List(); - public List MemberDependencies { get; } = new List(); - public List MemberBackwardsDependencies { get; } = new List(); - public List Dependencies => MemberDependencies.Cast().ToList(); + public List MemberDependencies { get; } = + new List(); + public List MemberBackwardsDependencies { get; } = + new List(); + public List Dependencies => + MemberDependencies.Cast().ToList(); public List BackwardsDependencies => MemberBackwardsDependencies.Cast().ToList(); @@ -88,4 +105,4 @@ public override int GetHashCode() return FullName.GetHashCode(); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/MethodMemberInstance.cs b/ArchUnitNET/Domain/MethodMemberInstance.cs index e0939c561..241b98443 100644 --- a/ArchUnitNET/Domain/MethodMemberInstance.cs +++ b/ArchUnitNET/Domain/MethodMemberInstance.cs @@ -1,9 +1,9 @@ // 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; @@ -12,8 +12,11 @@ namespace ArchUnitNET.Domain { public class MethodMemberInstance : ITypeInstance { - public MethodMemberInstance(MethodMember member, IEnumerable declaringTypeGenericArguments, - IEnumerable memberGenericArguments) + public MethodMemberInstance( + MethodMember member, + IEnumerable declaringTypeGenericArguments, + IEnumerable memberGenericArguments + ) { Member = member; GenericArguments = declaringTypeGenericArguments; @@ -39,9 +42,9 @@ public bool Equals(MethodMemberInstance other) return true; } - return Equals(Member, other.Member) && - GenericArguments.SequenceEqual(other.GenericArguments) && - MemberGenericArguments.SequenceEqual(other.MemberGenericArguments); + return Equals(Member, other.Member) + && GenericArguments.SequenceEqual(other.GenericArguments) + && MemberGenericArguments.SequenceEqual(other.MemberGenericArguments); } public override bool Equals(object obj) @@ -61,7 +64,7 @@ public override bool Equals(object obj) return false; } - return Equals((MethodMemberInstance) obj); + return Equals((MethodMemberInstance)obj); } public override int GetHashCode() @@ -69,12 +72,16 @@ public override int GetHashCode() unchecked { var hashCode = Member != null ? Member.GetHashCode() : 0; - hashCode = GenericArguments.Aggregate(hashCode, - (current, type) => (current * 397) ^ (type != null ? type.GetHashCode() : 0)); - hashCode = MemberGenericArguments.Aggregate(hashCode, - (current, type) => (current * 397) ^ (type != null ? type.GetHashCode() : 0)); + hashCode = GenericArguments.Aggregate( + hashCode, + (current, type) => (current * 397) ^ (type != null ? type.GetHashCode() : 0) + ); + hashCode = MemberGenericArguments.Aggregate( + hashCode, + (current, type) => (current * 397) ^ (type != null ? type.GetHashCode() : 0) + ); return hashCode; } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Namespace.cs b/ArchUnitNET/Domain/Namespace.cs index 6c35a5cb3..c46f9a213 100644 --- a/ArchUnitNET/Domain/Namespace.cs +++ b/ArchUnitNET/Domain/Namespace.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -10,11 +10,10 @@ namespace ArchUnitNET.Domain { public class Namespace : Slice, IHasName { - public Namespace(string name, IEnumerable types) : base(SliceIdentifier.Of(name), types) - { - } + public Namespace(string name, IEnumerable types) + : base(SliceIdentifier.Of(name), types) { } public string Name => Description; public string FullName => Description; } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/ObjectProviderCache.cs b/ArchUnitNET/Domain/ObjectProviderCache.cs index 2507604aa..39da80d0f 100644 --- a/ArchUnitNET/Domain/ObjectProviderCache.cs +++ b/ArchUnitNET/Domain/ObjectProviderCache.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -22,14 +22,18 @@ public ObjectProviderCache(Architecture architecture) _cache = new ConcurrentDictionary(); } - public IEnumerable GetOrCreateObjects(IObjectProvider objectProvider, - Func> providingFunction) where T : ICanBeAnalyzed + public IEnumerable GetOrCreateObjects( + IObjectProvider objectProvider, + Func> providingFunction + ) + where T : ICanBeAnalyzed { unchecked { - var key = (objectProvider.GetHashCode() * 397) ^ objectProvider.GetType().GetHashCode(); - return (IEnumerable) _cache.GetOrAdd(key, k => providingFunction(_architecture)); + var key = + (objectProvider.GetHashCode() * 397) ^ objectProvider.GetType().GetHashCode(); + return (IEnumerable)_cache.GetOrAdd(key, k => providingFunction(_architecture)); } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Exceptions/ComponentIntersectionException.cs b/ArchUnitNET/Domain/PlantUml/Exceptions/ComponentIntersectionException.cs index bebdab4cc..3dd15d62c 100644 --- a/ArchUnitNET/Domain/PlantUml/Exceptions/ComponentIntersectionException.cs +++ b/ArchUnitNET/Domain/PlantUml/Exceptions/ComponentIntersectionException.cs @@ -6,20 +6,15 @@ namespace ArchUnitNET.Domain.PlantUml.Exceptions [Serializable] internal class ComponentIntersectionException : Exception { - public ComponentIntersectionException() - { - } + public ComponentIntersectionException() { } - public ComponentIntersectionException(string message) : base(message) - { - } + public ComponentIntersectionException(string message) + : base(message) { } - public ComponentIntersectionException(string message, Exception innerException) : base(message, innerException) - { - } + public ComponentIntersectionException(string message, Exception innerException) + : base(message, innerException) { } - protected ComponentIntersectionException(SerializationInfo info, StreamingContext context) : base(info, context) - { - } + protected ComponentIntersectionException(SerializationInfo info, StreamingContext context) + : base(info, context) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Exceptions/FileAlreadyExistsException.cs b/ArchUnitNET/Domain/PlantUml/Exceptions/FileAlreadyExistsException.cs index d82addf68..1710a86e8 100644 --- a/ArchUnitNET/Domain/PlantUml/Exceptions/FileAlreadyExistsException.cs +++ b/ArchUnitNET/Domain/PlantUml/Exceptions/FileAlreadyExistsException.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System; using System.Runtime.Serialization; @@ -12,20 +12,15 @@ namespace ArchUnitNET.Domain.PlantUml.Exceptions { public class FileAlreadyExistsException : Exception { - public FileAlreadyExistsException() - { - } + public FileAlreadyExistsException() { } - public FileAlreadyExistsException(string message) : base(message) - { - } + public FileAlreadyExistsException(string message) + : base(message) { } - public FileAlreadyExistsException(string message, Exception innerException) : base(message, innerException) - { - } + public FileAlreadyExistsException(string message, Exception innerException) + : base(message, innerException) { } - protected FileAlreadyExistsException(SerializationInfo info, StreamingContext context) : base(info, context) - { - } + protected FileAlreadyExistsException(SerializationInfo info, StreamingContext context) + : base(info, context) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Exceptions/IllegalComponentNameException.cs b/ArchUnitNET/Domain/PlantUml/Exceptions/IllegalComponentNameException.cs index 3decad612..6b6b80140 100644 --- a/ArchUnitNET/Domain/PlantUml/Exceptions/IllegalComponentNameException.cs +++ b/ArchUnitNET/Domain/PlantUml/Exceptions/IllegalComponentNameException.cs @@ -6,20 +6,15 @@ namespace ArchUnitNET.Domain.PlantUml.Exceptions [Serializable] internal class IllegalComponentNameException : Exception { - public IllegalComponentNameException() - { - } + public IllegalComponentNameException() { } - public IllegalComponentNameException(string message) : base(message) - { - } + public IllegalComponentNameException(string message) + : base(message) { } - public IllegalComponentNameException(string message, Exception innerException) : base(message, innerException) - { - } + public IllegalComponentNameException(string message, Exception innerException) + : base(message, innerException) { } - protected IllegalComponentNameException(SerializationInfo info, StreamingContext context) : base(info, context) - { - } + protected IllegalComponentNameException(SerializationInfo info, StreamingContext context) + : base(info, context) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Exceptions/IllegalDiagramException.cs b/ArchUnitNET/Domain/PlantUml/Exceptions/IllegalDiagramException.cs index 9ccf4ba1a..e76e987fa 100644 --- a/ArchUnitNET/Domain/PlantUml/Exceptions/IllegalDiagramException.cs +++ b/ArchUnitNET/Domain/PlantUml/Exceptions/IllegalDiagramException.cs @@ -8,25 +8,20 @@ internal class IllegalDiagramException : Exception { private object p; - public IllegalDiagramException() - { - } + public IllegalDiagramException() { } public IllegalDiagramException(object p) { this.p = p; } - public IllegalDiagramException(string message) : base(message) - { - } + public IllegalDiagramException(string message) + : base(message) { } - public IllegalDiagramException(string message, Exception innerException) : base(message, innerException) - { - } + public IllegalDiagramException(string message, Exception innerException) + : base(message, innerException) { } - protected IllegalDiagramException(SerializationInfo info, StreamingContext context) : base(info, context) - { - } + protected IllegalDiagramException(SerializationInfo info, StreamingContext context) + : base(info, context) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Exceptions/PlantUmlParseException.cs b/ArchUnitNET/Domain/PlantUml/Exceptions/PlantUmlParseException.cs index ab655f931..2b6afc766 100644 --- a/ArchUnitNET/Domain/PlantUml/Exceptions/PlantUmlParseException.cs +++ b/ArchUnitNET/Domain/PlantUml/Exceptions/PlantUmlParseException.cs @@ -6,20 +6,15 @@ namespace ArchUnitNET.Domain.PlantUml.Exceptions [Serializable] internal class PlantUmlParseException : Exception { - public PlantUmlParseException() - { - } + public PlantUmlParseException() { } - public PlantUmlParseException(string message) : base(message) - { - } + public PlantUmlParseException(string message) + : base(message) { } - public PlantUmlParseException(string message, Exception innerException) : base(message, innerException) - { - } + public PlantUmlParseException(string message, Exception innerException) + : base(message, innerException) { } - protected PlantUmlParseException(SerializationInfo info, StreamingContext context) : base(info, context) - { - } + protected PlantUmlParseException(SerializationInfo info, StreamingContext context) + : base(info, context) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Exceptions/UmlNotBuiltException.cs b/ArchUnitNET/Domain/PlantUml/Exceptions/UmlNotBuiltException.cs index 7dea37238..840c66bd1 100644 --- a/ArchUnitNET/Domain/PlantUml/Exceptions/UmlNotBuiltException.cs +++ b/ArchUnitNET/Domain/PlantUml/Exceptions/UmlNotBuiltException.cs @@ -6,20 +6,15 @@ namespace ArchUnitNET.Domain.PlantUml.Exceptions [Serializable] internal class UmlNotBuiltException : Exception { - public UmlNotBuiltException() - { - } + public UmlNotBuiltException() { } - public UmlNotBuiltException(string message) : base(message) - { - } + public UmlNotBuiltException(string message) + : base(message) { } - public UmlNotBuiltException(string message, Exception innerException) : base(message, innerException) - { - } + public UmlNotBuiltException(string message, Exception innerException) + : base(message, innerException) { } - protected UmlNotBuiltException(SerializationInfo info, StreamingContext context) : base(info, context) - { - } + protected UmlNotBuiltException(SerializationInfo info, StreamingContext context) + : base(info, context) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Export/DependencyFilters.cs b/ArchUnitNET/Domain/PlantUml/Export/DependencyFilters.cs index 647c9207f..139110fa1 100644 --- a/ArchUnitNET/Domain/PlantUml/Export/DependencyFilters.cs +++ b/ArchUnitNET/Domain/PlantUml/Export/DependencyFilters.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System; using System.Collections.Generic; @@ -17,26 +17,30 @@ public static class DependencyFilters { public static Func IgnoreDependenciesToParents() { - return dependency => OriginAndTargetHaveNoParents(dependency) || - !dependency.Origin.FullName.StartsWith(dependency.Target.FullName); + return dependency => + OriginAndTargetHaveNoParents(dependency) + || !dependency.Origin.FullName.StartsWith(dependency.Target.FullName); } public static Func IgnoreDependenciesToChildren() { - return dependency => OriginAndTargetHaveNoParents(dependency) || - !dependency.Target.FullName.StartsWith(dependency.Origin.FullName); + return dependency => + OriginAndTargetHaveNoParents(dependency) + || !dependency.Target.FullName.StartsWith(dependency.Origin.FullName); } public static Func IgnoreDependenciesToChildrenAndParents() { - return dependency => OriginAndTargetHaveNoParents(dependency) || - !dependency.Target.FullName.StartsWith(dependency.Origin.FullName) && - !dependency.Origin.FullName.StartsWith(dependency.Target.FullName); + return dependency => + OriginAndTargetHaveNoParents(dependency) + || !dependency.Target.FullName.StartsWith(dependency.Origin.FullName) + && !dependency.Origin.FullName.StartsWith(dependency.Target.FullName); } private static bool OriginAndTargetHaveNoParents(ITypeDependency dependency) { - return !dependency.Origin.FullNameContains(".") && !dependency.Target.FullNameContains("."); + return !dependency.Origin.FullNameContains(".") + && !dependency.Target.FullNameContains("."); } public static Func FocusOn(IType type) @@ -53,10 +57,14 @@ public static Func FocusOn(IEnumerable types) }; } - public static Func FocusOn(string pattern, bool useRegularExpressions = false) + public static Func FocusOn( + string pattern, + bool useRegularExpressions = false + ) { - return dependency => dependency.Target.FullNameMatches(pattern, useRegularExpressions) ^ - dependency.Origin.FullNameMatches(pattern, useRegularExpressions); + return dependency => + dependency.Target.FullNameMatches(pattern, useRegularExpressions) + ^ dependency.Origin.FullNameMatches(pattern, useRegularExpressions); } public static Func HasOrigin(IType type) @@ -69,7 +77,10 @@ public static Func HasOrigin(IEnumerable types) return dependency => types.Contains(dependency.Origin); } - public static Func HasOrigin(string pattern, bool useRegularExpressions = false) + public static Func HasOrigin( + string pattern, + bool useRegularExpressions = false + ) { return dependency => dependency.Origin.FullNameMatches(pattern, useRegularExpressions); } @@ -84,9 +95,12 @@ public static Func HasTarget(IEnumerable types) return dependency => types.Contains(dependency.Target); } - public static Func HasTarget(string pattern, bool useRegularExpressions = false) + public static Func HasTarget( + string pattern, + bool useRegularExpressions = false + ) { return dependency => dependency.Target.FullNameMatches(pattern, useRegularExpressions); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Export/GenerationOptions.cs b/ArchUnitNET/Domain/PlantUml/Export/GenerationOptions.cs index 3b3ea4efd..427fe3e02 100644 --- a/ArchUnitNET/Domain/PlantUml/Export/GenerationOptions.cs +++ b/ArchUnitNET/Domain/PlantUml/Export/GenerationOptions.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System; using ArchUnitNET.Domain.Dependencies; @@ -15,7 +15,7 @@ public class GenerationOptions public Func DependencyFilter { get; set; } public bool IncludeDependenciesToOther { get; set; } public bool IncludeNodesWithoutDependencies { get; set; } = true; - public bool LimitDependencies { get; set; } = false; + public bool LimitDependencies { get; set; } = false; public bool C4Style { get; set; } = false; } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Export/IPlantUmlContainer.cs b/ArchUnitNET/Domain/PlantUml/Export/IPlantUmlContainer.cs index ae8e62d19..aca1939cc 100644 --- a/ArchUnitNET/Domain/PlantUml/Export/IPlantUmlContainer.cs +++ b/ArchUnitNET/Domain/PlantUml/Export/IPlantUmlContainer.cs @@ -8,4 +8,4 @@ public interface IPlantUmlContainer : IPlantUmlElement void AddElement(IPlantUmlElement plantUmlElement); void AddElements(IEnumerable plantUmlElements); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Export/IPlantUmlElement.cs b/ArchUnitNET/Domain/PlantUml/Export/IPlantUmlElement.cs index ef83dbcd9..b62812b61 100644 --- a/ArchUnitNET/Domain/PlantUml/Export/IPlantUmlElement.cs +++ b/ArchUnitNET/Domain/PlantUml/Export/IPlantUmlElement.cs @@ -4,4 +4,4 @@ public interface IPlantUmlElement { string GetPlantUmlString(RenderOptions renderOptions); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Export/PlantUmlClass.cs b/ArchUnitNET/Domain/PlantUml/Export/PlantUmlClass.cs index f96bf9ca9..84db00f5b 100644 --- a/ArchUnitNET/Domain/PlantUml/Export/PlantUmlClass.cs +++ b/ArchUnitNET/Domain/PlantUml/Export/PlantUmlClass.cs @@ -10,7 +10,6 @@ public class PlantUmlClass : IPlantUmlElement private readonly List _fields = new List(); string _hyperlink { get; } - public PlantUmlClass(string name, string hyperlink = null) { PlantUmlNameChecker.AssertNoForbiddenCharacters(name, hyperlink); @@ -31,12 +30,14 @@ public string GetPlantUmlString(RenderOptions renderOptions) if (!renderOptions.OmitClassFields) { - result += _fields.Aggregate("", - (umlstring, field) => umlstring + "\"" + field + "\"" + Environment.NewLine); + result += _fields.Aggregate( + "", + (umlstring, field) => umlstring + "\"" + field + "\"" + Environment.NewLine + ); } result += "}" + Environment.NewLine; return result; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Export/PlantUmlDependency.cs b/ArchUnitNET/Domain/PlantUml/Export/PlantUmlDependency.cs index acc619ba4..ae0a366a1 100644 --- a/ArchUnitNET/Domain/PlantUml/Export/PlantUmlDependency.cs +++ b/ArchUnitNET/Domain/PlantUml/Export/PlantUmlDependency.cs @@ -41,44 +41,74 @@ public string GetPlantUmlString(RenderOptions renderOptions = null) return "[" + Origin + "]" + " --|> " + "[" + Target + "]" + Environment.NewLine; case DependencyType.OneToMany: - return "[" + Origin + "]" + " \"1\" --|> \"many\" " + "[" + Target + "]" + - Environment.NewLine; + return "[" + + Origin + + "]" + + " \"1\" --|> \"many\" " + + "[" + + Target + + "]" + + Environment.NewLine; case DependencyType.OneToPackage: - return "["+ Origin + "] -[#red]> " + GetChildNamespace(Target) + Environment.NewLine; + return "[" + + Origin + + "] -[#red]> " + + GetChildNamespace(Target) + + Environment.NewLine; case DependencyType.PackageToOne: - return GetChildNamespace(Origin) + " -[#blue]> [" + Target + "]" +Environment.NewLine; - + return GetChildNamespace(Origin) + + " -[#blue]> [" + + Target + + "]" + + Environment.NewLine; + case DependencyType.PackageToPackage: - return GetChildNamespace(Origin) + " -[#green]> " + GetChildNamespace(Target) + Environment.NewLine; - + return GetChildNamespace(Origin) + + " -[#green]> " + + GetChildNamespace(Target) + + Environment.NewLine; + case DependencyType.OneToOneCompact: if (OriginCountOfDots() == TargetCountOfDots()) { - return "[" + Origin + "] --> [" + Target + "]" + Environment.NewLine; + return "[" + Origin + "] --> [" + Target + "]" + Environment.NewLine; } return ""; - + case DependencyType.Circle: - return "[" + Origin + "]" + " <-[#red]> " + "[" + Target + "]" + Environment.NewLine; + return "[" + + Origin + + "]" + + " <-[#red]> " + + "[" + + Target + + "]" + + Environment.NewLine; case DependencyType.PackageToPackageIfSameParentNamespace: - if (OriginCountOfDots() == TargetCountOfDots() && - (OriginCountOfDots() == 0 || HaveSameParentNamespace(Origin, Target))) + if ( + OriginCountOfDots() == TargetCountOfDots() + && (OriginCountOfDots() == 0 || HaveSameParentNamespace(Origin, Target)) + ) { - return GetChildNamespace(Origin) + " ..> " + GetChildNamespace(Target) + Environment.NewLine; + return GetChildNamespace(Origin) + + " ..> " + + GetChildNamespace(Target) + + Environment.NewLine; } return ""; case DependencyType.OneToOneIfSameParentNamespace: - if (OriginCountOfDots() == TargetCountOfDots() && - (OriginCountOfDots() == 0 || HaveSameParentNamespace(Origin, Target)) - ) + if ( + OriginCountOfDots() == TargetCountOfDots() + && (OriginCountOfDots() == 0 || HaveSameParentNamespace(Origin, Target)) + ) { return Origin + " --|> " + Target + Environment.NewLine; - } - + } + if (OriginCountOfDots() < TargetCountOfDots()) { var tmp = GetParentNamespace(Target); @@ -99,10 +129,10 @@ public string GetPlantUmlString(RenderOptions renderOptions = null) { tmp = GetParentNamespace(tmp); } - + if (tmp != Target && HaveSameParentNamespace(tmp, Target)) { - return GetChildNamespace(tmp) + " -> " + Target + Environment.NewLine; + return GetChildNamespace(tmp) + " -> " + Target + Environment.NewLine; } } return ""; @@ -114,19 +144,20 @@ public string GetPlantUmlString(RenderOptions renderOptions = null) return ""; } - private static string GetParentNamespace(string ns) => + private static string GetParentNamespace(string ns) => ns.Remove(ns.LastIndexOf(".", StringComparison.Ordinal)); - private static string GetChildNamespace(string ns) => - ns.Remove(0,ns.LastIndexOf(".", StringComparison.Ordinal) + 1); + private static string GetChildNamespace(string ns) => + ns.Remove(0, ns.LastIndexOf(".", StringComparison.Ordinal) + 1); - private static bool HaveSameParentNamespace(string origin, string target) => + private static bool HaveSameParentNamespace(string origin, string target) => (GetParentNamespace(origin) == GetParentNamespace(target)); private bool Equals(PlantUmlDependency other) { - return Equals(Target, other.Target) && Equals(Origin, other.Origin) && - Equals(DependencyType, other.DependencyType); + return Equals(Target, other.Target) + && Equals(Origin, other.Origin) + && Equals(DependencyType, other.DependencyType); } public override bool Equals(object obj) @@ -169,4 +200,4 @@ public enum DependencyType Circle, NoDependency } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Export/PlantUmlDiagram.cs b/ArchUnitNET/Domain/PlantUml/Export/PlantUmlDiagram.cs index a5b6bfc2e..bdc6996a7 100644 --- a/ArchUnitNET/Domain/PlantUml/Export/PlantUmlDiagram.cs +++ b/ArchUnitNET/Domain/PlantUml/Export/PlantUmlDiagram.cs @@ -23,17 +23,26 @@ public string GetPlantUmlString(RenderOptions renderOptions) { var result = new StringBuilder(); result.AppendLine("@startuml").AppendLine(); - result.AppendLine("!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml") + result + .AppendLine( + "!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml" + ) .AppendLine(); result.AppendLine("HIDE_STEREOTYPE()").AppendLine(); - result.Append(PlantUmlElements - .OrderBy(element => element.GetType() != typeof(PlantUmlNamespace)) - .ThenBy(element => element.GetType() != typeof(PlantUmlSlice)) - .ThenBy(element => element.GetType() != typeof(PlantUmlClass)) - .ThenBy(element => element.GetType() != typeof(PlantUmlInterface)) - .Aggregate("", (umlString, umlElement) => umlString + umlElement.GetPlantUmlString(renderOptions))); + result.Append( + PlantUmlElements + .OrderBy(element => element.GetType() != typeof(PlantUmlNamespace)) + .ThenBy(element => element.GetType() != typeof(PlantUmlSlice)) + .ThenBy(element => element.GetType() != typeof(PlantUmlClass)) + .ThenBy(element => element.GetType() != typeof(PlantUmlInterface)) + .Aggregate( + "", + (umlString, umlElement) => + umlString + umlElement.GetPlantUmlString(renderOptions) + ) + ); result.AppendLine("@enduml"); return result.ToString(); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Export/PlantUmlFileBuilder.cs b/ArchUnitNET/Domain/PlantUml/Export/PlantUmlFileBuilder.cs index 825e5f25c..ae3e365b3 100644 --- a/ArchUnitNET/Domain/PlantUml/Export/PlantUmlFileBuilder.cs +++ b/ArchUnitNET/Domain/PlantUml/Export/PlantUmlFileBuilder.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System; using System.Collections.Generic; @@ -17,7 +17,7 @@ namespace ArchUnitNET.Domain.PlantUml.Export public class PlantUmlFileBuilder { private readonly PlantUmlDiagram _diagram = new PlantUmlDiagram(); - + private readonly List _dependencies = new List(); private List _sliceList = new List(); @@ -40,10 +40,14 @@ public void WriteToFile(string path, RenderOptions renderOptions = null) } if (!renderOptions.Overwrite && File.Exists(path)) { - throw new FileAlreadyExistsException("File already exists and overwriting is disabled."); + throw new FileAlreadyExistsException( + "File already exists and overwriting is disabled." + ); } - Directory.CreateDirectory(Path.GetDirectoryName(path) ?? throw new ArgumentException("Invalid path.")); + Directory.CreateDirectory( + Path.GetDirectoryName(path) ?? throw new ArgumentException("Invalid path.") + ); using (var sw = File.CreateText(path)) { @@ -57,7 +61,10 @@ public PlantUmlFileBuilder WithElements(IEnumerable elements) return this; } - public PlantUmlFileBuilder WithDependenciesFrom(IEnumerable types, GenerationOptions generationOptions = null) + public PlantUmlFileBuilder WithDependenciesFrom( + IEnumerable types, + GenerationOptions generationOptions = null + ) { var typeList = types.Distinct().ToList(); if (generationOptions == null) @@ -69,17 +76,24 @@ public PlantUmlFileBuilder WithDependenciesFrom(IEnumerable types, Genera foreach (var type in typeList) { - var filteredTypeDependencies = - type.Dependencies.Where(dep => - (generationOptions.DependencyFilter?.Invoke(dep) ?? true) && !Equals(dep.Origin, dep.Target)); + var filteredTypeDependencies = type.Dependencies.Where(dep => + (generationOptions.DependencyFilter?.Invoke(dep) ?? true) + && !Equals(dep.Origin, dep.Target) + ); if (!generationOptions.IncludeDependenciesToOther) { - filteredTypeDependencies = filteredTypeDependencies.Where(dep => typeList.Contains(dep.Target)); + filteredTypeDependencies = filteredTypeDependencies.Where(dep => + typeList.Contains(dep.Target) + ); } - var plantUmlDependencies = filteredTypeDependencies.Select(dep => - new PlantUmlDependency(dep.Origin.FullName, dep.Target.FullName, DependencyType.OneToOne)) + var plantUmlDependencies = filteredTypeDependencies + .Select(dep => new PlantUmlDependency( + dep.Origin.FullName, + dep.Target.FullName, + DependencyType.OneToOne + )) .Distinct(); _dependencies.AddRange(plantUmlDependencies); @@ -99,12 +113,15 @@ public PlantUmlFileBuilder WithDependenciesFrom(IEnumerable types, Genera } } - var nodeElements = - generationOptions.IncludeNodesWithoutDependencies - ? nodes.Values - : nodes.Where(node => - _dependencies.SelectMany(dep => new[] {dep.Origin, dep.Target}).Contains(node.Key.FullName)) - .Select(node => node.Value); + var nodeElements = generationOptions.IncludeNodesWithoutDependencies + ? nodes.Values + : nodes + .Where(node => + _dependencies + .SelectMany(dep => new[] { dep.Origin, dep.Target }) + .Contains(node.Key.FullName) + ) + .Select(node => node.Value); _diagram.AddElements(nodeElements); _diagram.AddElements(_dependencies); @@ -112,7 +129,10 @@ public PlantUmlFileBuilder WithDependenciesFrom(IEnumerable types, Genera return this; } - public PlantUmlFileBuilder WithDependenciesFrom(IEnumerable slices, GenerationOptions generationOptions = null) + public PlantUmlFileBuilder WithDependenciesFrom( + IEnumerable slices, + GenerationOptions generationOptions = null + ) { _sliceList = slices.Distinct().ToList(); RemovePatternInappropriateSlices(); @@ -146,39 +166,64 @@ public PlantUmlFileBuilder WithDependenciesFrom(IEnumerable slices, Gener { if (sliceIsPackage) { - _dependencies.AddRange(dependencyTargets.Select(target => - new PlantUmlDependency(slice.Description, target.Description, DependencyType.PackageToOne))); + _dependencies.AddRange( + dependencyTargets.Select(target => new PlantUmlDependency( + slice.Description, + target.Description, + DependencyType.PackageToOne + )) + ); } else { - _dependencies.AddRange(dependencyTargets.Select(target => - new PlantUmlDependency(slice.Description, target.Description, DependencyType.OneToOne))); + _dependencies.AddRange( + dependencyTargets.Select(target => new PlantUmlDependency( + slice.Description, + target.Description, + DependencyType.OneToOne + )) + ); } } else if (slice.ContainsNamespace()) { if (sliceIsPackage) { - _dependencies.AddRange(dependencyTargets.Select(target => - new PlantUmlDependency(slice.Description, target.Description, DependencyType.PackageToPackageIfSameParentNamespace))); + _dependencies.AddRange( + dependencyTargets.Select(target => new PlantUmlDependency( + slice.Description, + target.Description, + DependencyType.PackageToPackageIfSameParentNamespace + )) + ); } else { - var dt = dependencyTargets.Select( - target => new PlantUmlDependency(slice.Description, target.Description, - DependencyType.OneToOneIfSameParentNamespace) - ) - .Where(dependency => dependency.OriginCountOfDots() < dependency.TargetCountOfDots() || - _sliceList.All(slc => - slc.Description == dependency.Target || - !slc.Description.Contains(dependency.Target))); + var dt = dependencyTargets + .Select(target => new PlantUmlDependency( + slice.Description, + target.Description, + DependencyType.OneToOneIfSameParentNamespace + )) + .Where(dependency => + dependency.OriginCountOfDots() < dependency.TargetCountOfDots() + || _sliceList.All(slc => + slc.Description == dependency.Target + || !slc.Description.Contains(dependency.Target) + ) + ); _dependencies.AddRange(dt); } } else { - _dependencies.AddRange(dependencyTargets.Select(target => - new PlantUmlDependency(slice.Description, target.Description, DependencyType.OneToOneCompact))); + _dependencies.AddRange( + dependencyTargets.Select(target => new PlantUmlDependency( + slice.Description, + target.Description, + DependencyType.OneToOneCompact + )) + ); } } @@ -192,18 +237,24 @@ public PlantUmlFileBuilder WithDependenciesFrom(IEnumerable slices, Gener if (!generationOptions.LimitDependencies) { RemoveDuplicateDependenciesWhenShowingPackages(); - ReplaceCirclesWithAppropriateDependencyType(); + ReplaceCirclesWithAppropriateDependencyType(); } RemoveDuplicatedArrowsIfExist(); - _diagram.AddElements(nodeElements.OrderBy(element => - element is PlantUmlNamespace @namespace ? @namespace.Name.Length : -1)); + _diagram.AddElements( + nodeElements.OrderBy(element => + element is PlantUmlNamespace @namespace ? @namespace.Name.Length : -1 + ) + ); _diagram.AddElements(_dependencies); return this; } - public PlantUmlFileBuilder WithDependenciesFromFocusOn(IEnumerable slices, string package) + public PlantUmlFileBuilder WithDependenciesFromFocusOn( + IEnumerable slices, + string package + ) { _sliceList = slices.Distinct().ToList(); @@ -215,17 +266,21 @@ public PlantUmlFileBuilder WithDependenciesFromFocusOn(IEnumerable slices throw new ArgumentException("Package can't contain a single dot only"); } - if (package[package.Length-1] == '.') + if (package[package.Length - 1] == '.') { package = package.Remove(package.Length - 1); } RemovePatternInappropriateSlices(package); - var existPackage = _sliceList.Any(slice => (slice.NameSpace + slice.Description).Contains(package)); + var existPackage = _sliceList.Any(slice => + (slice.NameSpace + slice.Description).Contains(package) + ); if (!existPackage) { - throw new ArgumentException("The package [" + package + "] is not contained in this slice"); + throw new ArgumentException( + "The package [" + package + "] is not contained in this slice" + ); } var nodes = new Dictionary(); @@ -238,13 +293,23 @@ public PlantUmlFileBuilder WithDependenciesFromFocusOn(IEnumerable slices if (sliceIsPackage) { - _dependencies.AddRange(dependencyTargets.Select(target => - new PlantUmlDependency(slice.Description, target.Description, DependencyType.PackageToOne))); + _dependencies.AddRange( + dependencyTargets.Select(target => new PlantUmlDependency( + slice.Description, + target.Description, + DependencyType.PackageToOne + )) + ); } else { - _dependencies.AddRange(dependencyTargets.Select(target => - new PlantUmlDependency(slice.Description, target.Description, DependencyType.OneToOne))); + _dependencies.AddRange( + dependencyTargets.Select(target => new PlantUmlDependency( + slice.Description, + target.Description, + DependencyType.OneToOne + )) + ); } if (slice is Namespace) //This throws errors if namespaces and slices are used in the same diagram, the syntax can't be mixed in PlantUML @@ -253,13 +318,15 @@ public PlantUmlFileBuilder WithDependenciesFromFocusOn(IEnumerable slices } else if (!sliceIsPackage) { - nodes.Add(slice, + nodes.Add( + slice, slice.Description.Contains(package) ? new PlantUmlSlice(slice.Description, slice.NameSpace, "99ffd1") - : new PlantUmlSlice(slice.Description, slice.NameSpace)); + : new PlantUmlSlice(slice.Description, slice.NameSpace) + ); } else if (!slice.Description.Contains(package)) - { + { nodes.Add(slice, new PlantUmlSlice(slice.Description + ".", slice.NameSpace)); } } @@ -275,7 +342,10 @@ public PlantUmlFileBuilder WithDependenciesFromFocusOn(IEnumerable slices for (var j = _dependencies.Count - 1; j >= 0; j--) { - if (!_dependencies[j].Origin.Contains(package) && !_dependencies[j].Target.Contains(package)) + if ( + !_dependencies[j].Origin.Contains(package) + && !_dependencies[j].Target.Contains(package) + ) { _dependencies.RemoveAt(j); } @@ -283,7 +353,10 @@ public PlantUmlFileBuilder WithDependenciesFromFocusOn(IEnumerable slices for (var i = nodes.Count - 1; i >= 0; i--) { - var nodeExist = _dependencies.Any(dep => nodes.ElementAt(i).Key.Description == dep.Origin || nodes.ElementAt(i).Key.Description == dep.Target); + var nodeExist = _dependencies.Any(dep => + nodes.ElementAt(i).Key.Description == dep.Origin + || nodes.ElementAt(i).Key.Description == dep.Target + ); if (!nodeExist) { nodes.Remove(nodes.ElementAt(i).Key); @@ -292,11 +365,19 @@ public PlantUmlFileBuilder WithDependenciesFromFocusOn(IEnumerable slices var nodeElements = HandleNodes(nodes); - _diagram.AddElements(nodeElements.OrderBy(element => - element is PlantUmlNamespace @namespace ? @namespace.Name.Length : -1)); - - var tempList = _sliceList.Where(slice => IsPackage(slice) && slice.Description.Contains(package)) - .Select(slice => new PlantUmlSlice(slice.Description + ".", slice.NameSpace, "99ffd1")) + _diagram.AddElements( + nodeElements.OrderBy(element => + element is PlantUmlNamespace @namespace ? @namespace.Name.Length : -1 + ) + ); + + var tempList = _sliceList + .Where(slice => IsPackage(slice) && slice.Description.Contains(package)) + .Select(slice => new PlantUmlSlice( + slice.Description + ".", + slice.NameSpace, + "99ffd1" + )) .ToList(); if (tempList.Count > 0) { @@ -307,18 +388,26 @@ public PlantUmlFileBuilder WithDependenciesFromFocusOn(IEnumerable slices return this; } - private Dictionary RemoveNodesNotContainedInDependencies(Dictionary nodes) + private Dictionary RemoveNodesNotContainedInDependencies( + Dictionary nodes + ) { - foreach (var entry in nodes.Where(node => - !_dependencies.SelectMany(dep => new[] {dep.Origin, dep.Target}) - .Contains(node.Key.Description))) + foreach ( + var entry in nodes.Where(node => + !_dependencies + .SelectMany(dep => new[] { dep.Origin, dep.Target }) + .Contains(node.Key.Description) + ) + ) { nodes.Remove(entry.Key); } return nodes; } - private static IEnumerable HandleNodes(Dictionary nodes) + private static IEnumerable HandleNodes( + Dictionary nodes + ) { var nodeElements = nodes.Values.ToList(); @@ -337,9 +426,13 @@ private static IEnumerable HandleNodes(Dictionary nodeElements - .OfType() - .All(element => element.Name != namespcName))) + foreach ( + var namespc in parentNamespaces.Where(namespcName => + nodeElements + .OfType() + .All(element => element.Name != namespcName) + ) + ) { nodeElements.Add(new PlantUmlNamespace(namespc)); } @@ -349,11 +442,18 @@ private static IEnumerable HandleNodes(Dictionary SelectDependencies(Slice slice, GenerationOptions generationOptions) => + private IEnumerable SelectDependencies( + Slice slice, + GenerationOptions generationOptions + ) => _sliceList.Where(targetSlice => - targetSlice.Description != slice.Description && - slice.Dependencies.Where(dep => generationOptions.DependencyFilter?.Invoke(dep) ?? true) - .Any(dep => targetSlice.Types.Contains(dep.Target))); + targetSlice.Description != slice.Description + && slice + .Dependencies.Where(dep => + generationOptions.DependencyFilter?.Invoke(dep) ?? true + ) + .Any(dep => targetSlice.Types.Contains(dep.Target)) + ); private void RemovePatternInappropriateSlices(string thatContainsThisString = null) { @@ -361,7 +461,12 @@ private void RemovePatternInappropriateSlices(string thatContainsThisString = nu { return; } - if (thatContainsThisString != null && !_sliceList.Any(slice => (slice.NameSpace+slice.Description).Contains(thatContainsThisString))) + if ( + thatContainsThisString != null + && !_sliceList.Any(slice => + (slice.NameSpace + slice.Description).Contains(thatContainsThisString) + ) + ) { return; } @@ -370,7 +475,10 @@ private void RemovePatternInappropriateSlices(string thatContainsThisString = nu { var dots = 0; - if (thatContainsThisString != null && !(_sliceList[i].Description).Contains(thatContainsThisString)) + if ( + thatContainsThisString != null + && !(_sliceList[i].Description).Contains(thatContainsThisString) + ) { continue; } @@ -391,7 +499,9 @@ private void RemoveDuplicatedArrowsIfExist() { for (var j = i - 1; j >= 0; j--) { - if (_dependencies[i].GetPlantUmlString() == _dependencies[j].GetPlantUmlString()) + if ( + _dependencies[i].GetPlantUmlString() == _dependencies[j].GetPlantUmlString() + ) { _dependencies.RemoveAt(i); break; @@ -407,24 +517,34 @@ private void RemoveDuplicateDependenciesWhenShowingPackages() return; } - for (var j = _dependencies.Count-1; j >= 0; j--) + for (var j = _dependencies.Count - 1; j >= 0; j--) { - if (_sliceList.Any(slice => slice.Description.Contains(_dependencies[j].Target) && - slice.Description != _dependencies[j].Target)) + if ( + _sliceList.Any(slice => + slice.Description.Contains(_dependencies[j].Target) + && slice.Description != _dependencies[j].Target + ) + ) { if (_dependencies[j].Origin.Contains(_dependencies[j].Target)) { _dependencies.RemoveAt(j); } else if (_dependencies[j].DependencyType == DependencyType.PackageToOne) - { - _dependencies[j] = - new PlantUmlDependency(_dependencies[j].Origin, _dependencies[j].Target, DependencyType.PackageToPackage); + { + _dependencies[j] = new PlantUmlDependency( + _dependencies[j].Origin, + _dependencies[j].Target, + DependencyType.PackageToPackage + ); } else - { - _dependencies[j] = - new PlantUmlDependency(_dependencies[j].Origin, _dependencies[j].Target, DependencyType.OneToPackage); + { + _dependencies[j] = new PlantUmlDependency( + _dependencies[j].Origin, + _dependencies[j].Target, + DependencyType.OneToPackage + ); } continue; } @@ -442,24 +562,36 @@ private void RemoveDuplicateDependenciesWhenShowingPackages() for (var i = _dependencies.Count - 1; i >= 0; i--) { - if (_dependencies[i].DependencyType == DependencyType.PackageToOne || - _dependencies[i].DependencyType == DependencyType.PackageToPackage) + if ( + _dependencies[i].DependencyType == DependencyType.PackageToOne + || _dependencies[i].DependencyType == DependencyType.PackageToPackage + ) { - if (_dependencies.Any(dependency => _dependencies[i].Target == dependency.Target && - dependency.Origin.Contains(_dependencies[i].Origin) && - dependency.Origin != _dependencies[i].Origin)) + if ( + _dependencies.Any(dependency => + _dependencies[i].Target == dependency.Target + && dependency.Origin.Contains(_dependencies[i].Origin) + && dependency.Origin != _dependencies[i].Origin + ) + ) { _dependencies.RemoveAt(i); continue; } } - if (_dependencies[i].DependencyType == DependencyType.OneToPackage || - _dependencies[i].DependencyType == DependencyType.PackageToPackage) + if ( + _dependencies[i].DependencyType == DependencyType.OneToPackage + || _dependencies[i].DependencyType == DependencyType.PackageToPackage + ) { - if (_dependencies.Any(dependency => dependency.Target.Contains(_dependencies[i].Target) && - dependency.Target != _dependencies[i].Target && - dependency.Origin.Contains(_dependencies[i].Origin))) + if ( + _dependencies.Any(dependency => + dependency.Target.Contains(_dependencies[i].Target) + && dependency.Target != _dependencies[i].Target + && dependency.Origin.Contains(_dependencies[i].Origin) + ) + ) { _dependencies.RemoveAt(i); continue; @@ -467,8 +599,8 @@ private void RemoveDuplicateDependenciesWhenShowingPackages() } if ( - _dependencies[i].Target.Contains(_dependencies[i].Origin) && - _dependencies[i].Target != _dependencies[i].Origin + _dependencies[i].Target.Contains(_dependencies[i].Origin) + && _dependencies[i].Target != _dependencies[i].Origin ) { _dependencies.RemoveAt(i); @@ -478,19 +610,24 @@ private void RemoveDuplicateDependenciesWhenShowingPackages() private void ReplaceCirclesWithAppropriateDependencyType() { - for (var i = _dependencies.Count-1; i >= 0; i--) + for (var i = _dependencies.Count - 1; i >= 0; i--) { - for (var j = i-1; j >= 0; j--) + for (var j = i - 1; j >= 0; j--) { - if (_dependencies[i].Target != _dependencies[j].Origin || - _dependencies[i].Origin != _dependencies[j].Target) + if ( + _dependencies[i].Target != _dependencies[j].Origin + || _dependencies[i].Origin != _dependencies[j].Target + ) { continue; } _dependencies.RemoveAt(i); - _dependencies[j] = new PlantUmlDependency(_dependencies[j].Origin, _dependencies[j].Target, - DependencyType.Circle); + _dependencies[j] = new PlantUmlDependency( + _dependencies[j].Origin, + _dependencies[j].Target, + DependencyType.Circle + ); break; } } @@ -505,8 +642,10 @@ private bool IsPackage(Slice slice) for (var i = _sliceList.Count - 1; i >= 0; i--) { - if (_sliceList[i].Description != slice.Description & - _sliceList[i].Description.StartsWith(slice.Description)) + if ( + _sliceList[i].Description != slice.Description + & _sliceList[i].Description.StartsWith(slice.Description) + ) { return true; } @@ -515,4 +654,4 @@ private bool IsPackage(Slice slice) return false; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Export/PlantUmlInterface.cs b/ArchUnitNET/Domain/PlantUml/Export/PlantUmlInterface.cs index 658a4867e..4bdd571ee 100644 --- a/ArchUnitNET/Domain/PlantUml/Export/PlantUmlInterface.cs +++ b/ArchUnitNET/Domain/PlantUml/Export/PlantUmlInterface.cs @@ -18,9 +18,16 @@ public PlantUmlInterface(string name, string hyperlink = null) public string GetPlantUmlString(RenderOptions renderOptions) { var hyperlinkString = _hyperlink != null ? " [[" + _hyperlink + "]] " : null; - var result = "interface \"" + _name + "\"" + hyperlinkString + " {" + Environment.NewLine + "}" + - Environment.NewLine; + var result = + "interface \"" + + _name + + "\"" + + hyperlinkString + + " {" + + Environment.NewLine + + "}" + + Environment.NewLine; return result; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Export/PlantUmlNameChecker.cs b/ArchUnitNET/Domain/PlantUml/Export/PlantUmlNameChecker.cs index b674b9a83..b986c33f0 100644 --- a/ArchUnitNET/Domain/PlantUml/Export/PlantUmlNameChecker.cs +++ b/ArchUnitNET/Domain/PlantUml/Export/PlantUmlNameChecker.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Linq; using ArchUnitNET.Domain.Extensions; @@ -14,7 +14,17 @@ namespace ArchUnitNET.Domain.PlantUml.Export { public static class PlantUmlNameChecker { - private static readonly string[] ForbiddenCharacters = {"[", "]", "\r", "\n", "\f", "\a", "\b", "\v"}; + private static readonly string[] ForbiddenCharacters = + { + "[", + "]", + "\r", + "\n", + "\f", + "\a", + "\b", + "\v" + }; public static bool ContainsForbiddenCharacters([CanBeNull] string name) { @@ -26,7 +36,8 @@ public static void AssertNoForbiddenCharacters(params string[] names) if (names.Any(ContainsForbiddenCharacters)) { throw new IllegalComponentNameException( - "PlantUml component names must not contain \"[\" or \"]\" or any of the escape characters \"\\r\", \"\\n\", \"\\f\", \"\\a\", \"\\b\", \"\\v\"."); + "PlantUml component names must not contain \"[\" or \"]\" or any of the escape characters \"\\r\", \"\\n\", \"\\f\", \"\\a\", \"\\b\", \"\\v\"." + ); } } @@ -34,8 +45,10 @@ public static void AssertNotNullOrEmpty(params string[] names) { if (names.Any(name => name.IsNullOrEmpty())) { - throw new IllegalComponentNameException("PlantUml component names can't be null or empty."); + throw new IllegalComponentNameException( + "PlantUml component names can't be null or empty." + ); } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Export/PlantUmlNamespace.cs b/ArchUnitNET/Domain/PlantUml/Export/PlantUmlNamespace.cs index 1d404cbe1..9b3382a1e 100644 --- a/ArchUnitNET/Domain/PlantUml/Export/PlantUmlNamespace.cs +++ b/ArchUnitNET/Domain/PlantUml/Export/PlantUmlNamespace.cs @@ -33,10 +33,12 @@ public string GetPlantUmlString(RenderOptions renderOptions) var hyperlinkString = _hyperlink != null ? " [[" + _hyperlink + "]] " : null; var result = "namespace " + Name + hyperlinkString + " {" + Environment.NewLine; - result += PlantUmlElements.Aggregate("", (umlString, umlElement) => - umlString + umlElement.GetPlantUmlString(renderOptions)); + result += PlantUmlElements.Aggregate( + "", + (umlString, umlElement) => umlString + umlElement.GetPlantUmlString(renderOptions) + ); result += "}" + Environment.NewLine; return result; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Export/PlantUmlSlice.cs b/ArchUnitNET/Domain/PlantUml/Export/PlantUmlSlice.cs index 44602f61a..1c117be7e 100644 --- a/ArchUnitNET/Domain/PlantUml/Export/PlantUmlSlice.cs +++ b/ArchUnitNET/Domain/PlantUml/Export/PlantUmlSlice.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System; using System.ComponentModel.Design; @@ -20,7 +20,12 @@ public class PlantUmlSlice : IPlantUmlElement private string Color { get; } private bool C4Style { get; set; } - public PlantUmlSlice(string name, string nameSpace = null, string color = null, string hyperlink = null) + public PlantUmlSlice( + string name, + string nameSpace = null, + string color = null, + string hyperlink = null + ) { PlantUmlNameChecker.AssertNoForbiddenCharacters(name, hyperlink, nameSpace); PlantUmlNameChecker.AssertNotNullOrEmpty(name); @@ -124,11 +129,13 @@ private StringBuilder BuildStringC4Style() { var dotPattern = name.IndexOf(".", StringComparison.Ordinal); result.AppendLine(" {"); - result.Append("Boundary(" + name.Remove(dotPattern) + ", " + name.Remove(dotPattern) + ") "); + result.Append( + "Boundary(" + name.Remove(dotPattern) + ", " + name.Remove(dotPattern) + ") " + ); name = name.Remove(0, dotPattern + 1); iter++; } - + result.AppendLine(" {"); if (name != "") { @@ -144,4 +151,4 @@ private StringBuilder BuildStringC4Style() return result; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Export/RenderOptions.cs b/ArchUnitNET/Domain/PlantUml/Export/RenderOptions.cs index 02728bc28..c45f3d000 100644 --- a/ArchUnitNET/Domain/PlantUml/Export/RenderOptions.cs +++ b/ArchUnitNET/Domain/PlantUml/Export/RenderOptions.cs @@ -5,4 +5,4 @@ public class RenderOptions public bool OmitClassFields { get; set; } = true; public bool Overwrite { get; set; } = true; } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Import/Alias.cs b/ArchUnitNET/Domain/PlantUml/Import/Alias.cs index a9915d8f5..5e676f2d9 100644 --- a/ArchUnitNET/Domain/PlantUml/Import/Alias.cs +++ b/ArchUnitNET/Domain/PlantUml/Import/Alias.cs @@ -12,7 +12,11 @@ public Alias(string value) if (value.Contains("[") || value.Contains("]") || value.Contains(@"""")) { throw new IllegalDiagramException( - string.Format(@"Alias '{0}' should not contain character(s): '[' or ']' or '""'", value)); + string.Format( + @"Alias '{0}' should not contain character(s): '[' or ']' or '""'", + value + ) + ); } _value = value ?? throw new ArgumentNullException(nameof(value)); @@ -20,8 +24,7 @@ public Alias(string value) public override bool Equals(object obj) { - return obj is Alias alias && - _value == alias._value; + return obj is Alias alias && _value == alias._value; } public override int GetHashCode() @@ -35,4 +38,4 @@ internal string asString() return _value; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Import/ClassDiagramAssociation.cs b/ArchUnitNET/Domain/PlantUml/Import/ClassDiagramAssociation.cs index 5d4313106..44f949564 100644 --- a/ArchUnitNET/Domain/PlantUml/Import/ClassDiagramAssociation.cs +++ b/ArchUnitNET/Domain/PlantUml/Import/ClassDiagramAssociation.cs @@ -31,7 +31,12 @@ private void ValidateStereotypes(PlantUmlParsedDiagram plantUmlDiagram) { if (visited.Contains(stereotype)) { - throw new IllegalDiagramException(string.Format("Stereotype '{0}' should be unique", stereotype.AsString())); + throw new IllegalDiagramException( + string.Format( + "Stereotype '{0}' should be unique", + stereotype.AsString() + ) + ); } visited.Add(stereotype); } @@ -78,13 +83,18 @@ private PlantUmlComponent GetComponentOf(IType clazz) if (associatedComponents.Count > 1) { throw new ComponentIntersectionException( - string.Format("Class {0} may not be contained in more than one component, but is contained in [{1}]", - clazz.Name, - string.Join(", ", GetComponentNames(associatedComponents)))); + string.Format( + "Class {0} may not be contained in more than one component, but is contained in [{1}]", + clazz.Name, + string.Join(", ", GetComponentNames(associatedComponents)) + ) + ); } else if (associatedComponents.Count == 0) { - throw new InvalidOperationException(string.Format("Class {0} is not contained in any component", clazz.Name)); + throw new InvalidOperationException( + string.Format("Class {0} is not contained in any component", clazz.Name) + ); } return associatedComponents.Single(); @@ -93,7 +103,11 @@ private PlantUmlComponent GetComponentOf(IType clazz) private ISet GetComponentNames(ISet associatedComponents) { ISet associatedComponentNames = new HashSet(); - foreach (PlantUmlComponent associatedComponent in associatedComponents.OrderBy(component => component.ComponentName.AsString())) + foreach ( + PlantUmlComponent associatedComponent in associatedComponents.OrderBy(component => + component.ComponentName.AsString() + ) + ) { associatedComponentNames.Add(associatedComponent.ComponentName.AsString()); } @@ -138,8 +152,6 @@ public bool Contains(IType clazz) } return false; } - - } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Import/ComponentIdentifier.cs b/ArchUnitNET/Domain/PlantUml/Import/ComponentIdentifier.cs index 49f798a48..c920f1e2c 100644 --- a/ArchUnitNET/Domain/PlantUml/Import/ComponentIdentifier.cs +++ b/ArchUnitNET/Domain/PlantUml/Import/ComponentIdentifier.cs @@ -4,9 +4,8 @@ namespace ArchUnitNET.Domain.PlantUml.Import { internal class ComponentIdentifier { - public ComponentIdentifier(ComponentName componentName) : this(componentName, null) - { - } + public ComponentIdentifier(ComponentName componentName) + : this(componentName, null) { } public ComponentIdentifier(ComponentName componentName, Alias alias) { @@ -20,9 +19,12 @@ public ComponentIdentifier(ComponentName componentName, Alias alias) public override bool Equals(object obj) { - return obj is ComponentIdentifier identifier && - EqualityComparer.Default.Equals(ComponentName, identifier.ComponentName) && - EqualityComparer.Default.Equals(Alias, identifier.Alias); + return obj is ComponentIdentifier identifier + && EqualityComparer.Default.Equals( + ComponentName, + identifier.ComponentName + ) + && EqualityComparer.Default.Equals(Alias, identifier.Alias); } public override int GetHashCode() @@ -35,4 +37,4 @@ public override int GetHashCode() } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Import/ComponentName.cs b/ArchUnitNET/Domain/PlantUml/Import/ComponentName.cs index 3953a7546..531a7cce2 100644 --- a/ArchUnitNET/Domain/PlantUml/Import/ComponentName.cs +++ b/ArchUnitNET/Domain/PlantUml/Import/ComponentName.cs @@ -18,8 +18,7 @@ public string AsString() public override bool Equals(object obj) { - return obj is ComponentName name && - _value == name._value; + return obj is ComponentName name && _value == name._value; } public override int GetHashCode() @@ -28,4 +27,4 @@ public override int GetHashCode() return hashCode; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Import/ParsedDependency.cs b/ArchUnitNET/Domain/PlantUml/Import/ParsedDependency.cs index 0417b5724..4c3c69cf9 100644 --- a/ArchUnitNET/Domain/PlantUml/Import/ParsedDependency.cs +++ b/ArchUnitNET/Domain/PlantUml/Import/ParsedDependency.cs @@ -15,9 +15,9 @@ public ParsedDependency(ComponentIdentifier origin, ComponentIdentifier target) public override bool Equals(object obj) { - return obj is ParsedDependency dependency && - EqualityComparer.Default.Equals(Origin, dependency.Origin) && - EqualityComparer.Default.Equals(Target, dependency.Target); + return obj is ParsedDependency dependency + && EqualityComparer.Default.Equals(Origin, dependency.Origin) + && EqualityComparer.Default.Equals(Target, dependency.Target); } public override int GetHashCode() @@ -30,4 +30,4 @@ public override int GetHashCode() } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Import/PlantUmlComponent.cs b/ArchUnitNET/Domain/PlantUml/Import/PlantUmlComponent.cs index 7ebc0d4e4..f3838cf78 100644 --- a/ArchUnitNET/Domain/PlantUml/Import/PlantUmlComponent.cs +++ b/ArchUnitNET/Domain/PlantUml/Import/PlantUmlComponent.cs @@ -9,7 +9,11 @@ internal class PlantUmlComponent { private IEnumerable _dependencies; - public PlantUmlComponent(ComponentName componentName, ISet stereotypes, Alias alias) + public PlantUmlComponent( + ComponentName componentName, + ISet stereotypes, + Alias alias + ) { ComponentName = componentName ?? throw new ArgumentNullException(nameof(componentName)); Stereotypes = stereotypes ?? throw new ArgumentNullException(nameof(stereotypes)); @@ -39,10 +43,13 @@ public IList Dependencies public override bool Equals(object obj) { - return obj is PlantUmlComponent component && - Stereotypes.SequenceEqual(component.Stereotypes) && - EqualityComparer.Default.Equals(Alias, component.Alias) && - EqualityComparer.Default.Equals(ComponentName, component.ComponentName); + return obj is PlantUmlComponent component + && Stereotypes.SequenceEqual(component.Stereotypes) + && EqualityComparer.Default.Equals(Alias, component.Alias) + && EqualityComparer.Default.Equals( + ComponentName, + component.ComponentName + ); } public override int GetHashCode() @@ -50,10 +57,14 @@ public override int GetHashCode() unchecked { var hashCode = 397 ^ (Alias != null ? Alias.GetHashCode() : 0); - hashCode = (hashCode * 397) ^ (ComponentName != null ? ComponentName.GetHashCode() : 0); + hashCode = + (hashCode * 397) ^ (ComponentName != null ? ComponentName.GetHashCode() : 0); - return Stereotypes.Aggregate(hashCode, - (current, element) => (current * 397) ^ (element != null ? element.GetHashCode() : 0)); + return Stereotypes.Aggregate( + hashCode, + (current, element) => + (current * 397) ^ (element != null ? element.GetHashCode() : 0) + ); } } @@ -62,4 +73,4 @@ internal void Finish(IList dependencies) _dependencies = ImmutableList.CreateRange(dependencies); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Import/PlantUmlComponentDependency.cs b/ArchUnitNET/Domain/PlantUml/Import/PlantUmlComponentDependency.cs index 0c33ba1cf..0815455ab 100644 --- a/ArchUnitNET/Domain/PlantUml/Import/PlantUmlComponentDependency.cs +++ b/ArchUnitNET/Domain/PlantUml/Import/PlantUmlComponentDependency.cs @@ -15,9 +15,12 @@ public PlantUmlComponentDependency(PlantUmlComponent component, PlantUmlComponen public override bool Equals(object obj) { - return obj is PlantUmlComponentDependency dependency && - EqualityComparer.Default.Equals(Component, dependency.Component) && - EqualityComparer.Default.Equals(Target, dependency.Target); + return obj is PlantUmlComponentDependency dependency + && EqualityComparer.Default.Equals( + Component, + dependency.Component + ) + && EqualityComparer.Default.Equals(Target, dependency.Target); } public override int GetHashCode() @@ -30,4 +33,4 @@ public override int GetHashCode() } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Import/PlantUmlComponents.cs b/ArchUnitNET/Domain/PlantUml/Import/PlantUmlComponents.cs index 62fdf817a..23ca74f04 100644 --- a/ArchUnitNET/Domain/PlantUml/Import/PlantUmlComponents.cs +++ b/ArchUnitNET/Domain/PlantUml/Import/PlantUmlComponents.cs @@ -20,18 +20,12 @@ public PlantUmlComponents(ISet components) public IEnumerable AllComponents { - get - { - return _componentsByName.Values; - } + get { return _componentsByName.Values; } } public IEnumerable CompomenentsWithAlias { - get - { - return _componentsByAlias.Values; - } + get { return _componentsByAlias.Values; } } internal PlantUmlComponent FindComponentWith(string nameOrAlias) @@ -49,8 +43,13 @@ internal PlantUmlComponent FindComponentWith(string nameOrAlias) } if (result == null) { - throw new IllegalDiagramException(string.Format("There is no Component with name or alias = '{0}'. {1}", nameOrAlias, - "Components must be specified separately from dependencies.")); + throw new IllegalDiagramException( + string.Format( + "There is no Component with name or alias = '{0}'. {1}", + nameOrAlias, + "Components must be specified separately from dependencies." + ) + ); } return result; } @@ -60,4 +59,4 @@ internal PlantUmlComponent findComponentWith(ComponentIdentifier identifier) return _componentsByName[identifier.ComponentName]; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Import/PlantUmlDiagramBuilder.cs b/ArchUnitNET/Domain/PlantUml/Import/PlantUmlDiagramBuilder.cs index 6937eb57c..7396ca951 100644 --- a/ArchUnitNET/Domain/PlantUml/Import/PlantUmlDiagramBuilder.cs +++ b/ArchUnitNET/Domain/PlantUml/Import/PlantUmlDiagramBuilder.cs @@ -7,7 +7,8 @@ namespace ArchUnitNET.Domain.PlantUml.Import internal class PlantUmlDiagramBuilder { private readonly PlantUmlComponents _plantUmlComponents; - private Dictionary> _originToParsedDependency = new Dictionary>(); + private Dictionary> _originToParsedDependency = + new Dictionary>(); public PlantUmlDiagramBuilder(PlantUmlComponents plantUmlComponents) { @@ -16,15 +17,15 @@ public PlantUmlDiagramBuilder(PlantUmlComponents plantUmlComponents) public PlantUmlDiagramBuilder WithDependencies(IEnumerable dependencies) { - var groupedByOrigin = from d in dependencies - group d by d.Origin into g - select (Origin: g.Key, Dependencies: g); + var groupedByOrigin = + from d in dependencies + group d by d.Origin into g + select (Origin: g.Key, Dependencies: g); foreach (var g in groupedByOrigin) { _originToParsedDependency.Add(g.Origin, g.Dependencies.Distinct().ToList()); } return this; - } public PlantUmlParsedDiagram Build() @@ -42,9 +43,15 @@ private void Finish(PlantUmlComponent component) if (_originToParsedDependency.ContainsKey(component.Identifier)) { - foreach (ParsedDependency dependencyOriginatingFromComponent in _originToParsedDependency[component.Identifier]) + foreach ( + ParsedDependency dependencyOriginatingFromComponent in _originToParsedDependency[ + component.Identifier + ] + ) { - PlantUmlComponent target = _plantUmlComponents.findComponentWith(dependencyOriginatingFromComponent.Target); + PlantUmlComponent target = _plantUmlComponents.findComponentWith( + dependencyOriginatingFromComponent.Target + ); dependencies.Add(new PlantUmlComponentDependency(component, target)); } } diff --git a/ArchUnitNET/Domain/PlantUml/Import/PlantUmlParsedDiagram.cs b/ArchUnitNET/Domain/PlantUml/Import/PlantUmlParsedDiagram.cs index e8b848407..fe9a67bd7 100644 --- a/ArchUnitNET/Domain/PlantUml/Import/PlantUmlParsedDiagram.cs +++ b/ArchUnitNET/Domain/PlantUml/Import/PlantUmlParsedDiagram.cs @@ -4,6 +4,7 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("ArchUnitNETTests")] + namespace ArchUnitNET.Domain.PlantUml.Import { internal class PlantUmlParsedDiagram @@ -12,23 +13,18 @@ internal class PlantUmlParsedDiagram public PlantUmlParsedDiagram(PlantUmlComponents plantUmlComponents) { - _plantUmlComponents = plantUmlComponents ?? throw new ArgumentNullException(nameof(plantUmlComponents)); + _plantUmlComponents = + plantUmlComponents ?? throw new ArgumentNullException(nameof(plantUmlComponents)); } public ISet AllComponents { - get - { - return _plantUmlComponents.AllComponents.ToImmutableHashSet(); - } + get { return _plantUmlComponents.AllComponents.ToImmutableHashSet(); } } public ISet ComponentsWithAlias { - get - { - return _plantUmlComponents.CompomenentsWithAlias.ToImmutableHashSet(); - } + get { return _plantUmlComponents.CompomenentsWithAlias.ToImmutableHashSet(); } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Import/PlantUmlParser.cs b/ArchUnitNET/Domain/PlantUml/Import/PlantUmlParser.cs index b14fa7e7f..90ce70484 100644 --- a/ArchUnitNET/Domain/PlantUml/Import/PlantUmlParser.cs +++ b/ArchUnitNET/Domain/PlantUml/Import/PlantUmlParser.cs @@ -14,6 +14,7 @@ namespace ArchUnitNET.Domain.PlantUml.Import internal class PlantUmlParser { private PlantUmlPatterns _plantUmlPatterns = new PlantUmlPatterns(); + public PlantUmlParsedDiagram Parse(string filename) { if (filename is null) @@ -37,9 +38,12 @@ private IEnumerable ReadLines(string filename) try { return File.ReadAllLines(filename, Encoding.UTF8); - } - catch (Exception ex) when (ex is IOException || ex is UnauthorizedAccessException || ex is SecurityException) + catch (Exception ex) + when (ex is IOException + || ex is UnauthorizedAccessException + || ex is SecurityException + ) { throw new PlantUmlParseException("Could not parse diagram from " + filename, ex); } @@ -60,7 +64,11 @@ private IEnumerable ReadLines(Stream stream) } return lines; } - catch (Exception ex) when (ex is IOException || ex is UnauthorizedAccessException || ex is SecurityException) + catch (Exception ex) + when (ex is IOException + || ex is UnauthorizedAccessException + || ex is SecurityException + ) { throw new PlantUmlParseException("Could not parse diagram from stream", ex); } @@ -73,24 +81,45 @@ private PlantUmlParsedDiagram CreateDiagram(IEnumerable rawDiagramLines) var plantUmlComponents = new PlantUmlComponents(components); - IEnumerable dependencies = ParseDependencies(plantUmlComponents, diagramLines); + IEnumerable dependencies = ParseDependencies( + plantUmlComponents, + diagramLines + ); - return new PlantUmlDiagramBuilder(plantUmlComponents).WithDependencies(dependencies).Build(); + return new PlantUmlDiagramBuilder(plantUmlComponents) + .WithDependencies(dependencies) + .Build(); } - private IEnumerable ParseDependencies(PlantUmlComponents plantUmlComponents, IEnumerable plantUmlDiagramLines) + private IEnumerable ParseDependencies( + PlantUmlComponents plantUmlComponents, + IEnumerable plantUmlDiagramLines + ) { var result = new List(); - foreach (PlantUmlDependencyMatcher matcher in _plantUmlPatterns.MatchDependencies(plantUmlDiagramLines)) + foreach ( + PlantUmlDependencyMatcher matcher in _plantUmlPatterns.MatchDependencies( + plantUmlDiagramLines + ) + ) { - PlantUmlComponent origin = FindComponentMatching(plantUmlComponents, matcher.MatchOrigin); - PlantUmlComponent target = FindComponentMatching(plantUmlComponents, matcher.MatchTarget); + PlantUmlComponent origin = FindComponentMatching( + plantUmlComponents, + matcher.MatchOrigin + ); + PlantUmlComponent target = FindComponentMatching( + plantUmlComponents, + matcher.MatchTarget + ); result.Add(new ParsedDependency(origin.Identifier, target.Identifier)); } return result; } - private PlantUmlComponent FindComponentMatching(PlantUmlComponents plantUmlComponents, string originOrTargetString) + private PlantUmlComponent FindComponentMatching( + PlantUmlComponents plantUmlComponents, + string originOrTargetString + ) { originOrTargetString = Regex.Replace(originOrTargetString.Trim(), @"^\[", ""); originOrTargetString = Regex.Replace(originOrTargetString, "]$", ""); @@ -100,9 +129,12 @@ private PlantUmlComponent FindComponentMatching(PlantUmlComponents plantUmlCompo private ISet ParseComponents(IEnumerable plantUmlDiagramLines) { - return new HashSet(_plantUmlPatterns.FilterComponents(plantUmlDiagramLines) + return new HashSet( + _plantUmlPatterns + .FilterComponents(plantUmlDiagramLines) .Select(p => CreateNewComponent(p)) - .Distinct()); + .Distinct() + ); } private PlantUmlComponent CreateNewComponent(string input) @@ -110,13 +142,22 @@ private PlantUmlComponent CreateNewComponent(string input) PlantUmlComponentMatcher matcher = _plantUmlPatterns.MatchComponent(input); var componentName = new ComponentName(matcher.MatchComponentName()); - ImmutableHashSet immutableStereotypes = IdentifyStereotypes(matcher, componentName); + ImmutableHashSet immutableStereotypes = IdentifyStereotypes( + matcher, + componentName + ); string alias = matcher.MatchAlias(); - return new PlantUmlComponent(componentName, immutableStereotypes, alias != null ? new Alias(alias) : null); + return new PlantUmlComponent( + componentName, + immutableStereotypes, + alias != null ? new Alias(alias) : null + ); } - - private ImmutableHashSet IdentifyStereotypes(PlantUmlComponentMatcher matcher, ComponentName componentName) + private ImmutableHashSet IdentifyStereotypes( + PlantUmlComponentMatcher matcher, + ComponentName componentName + ) { var stereotypes = ImmutableHashSet.CreateBuilder(); foreach (string stereotype in matcher.MatchStereoTypes()) @@ -127,8 +168,13 @@ private ImmutableHashSet IdentifyStereotypes(PlantUmlComponentMatche ImmutableHashSet result = stereotypes.ToImmutable(); if (result.IsEmpty) { - throw new IllegalDiagramException(string.Format("Components must include at least one stereotype" - + " specifying the namespace identifier (<<.*>>), but component '{0}' does not", componentName.AsString())); + throw new IllegalDiagramException( + string.Format( + "Components must include at least one stereotype" + + " specifying the namespace identifier (<<.*>>), but component '{0}' does not", + componentName.AsString() + ) + ); } return result; } diff --git a/ArchUnitNET/Domain/PlantUml/Import/PlantUmlPatterns.cs b/ArchUnitNET/Domain/PlantUml/Import/PlantUmlPatterns.cs index 8bbabfd05..cca03f89f 100644 --- a/ArchUnitNET/Domain/PlantUml/Import/PlantUmlPatterns.cs +++ b/ArchUnitNET/Domain/PlantUml/Import/PlantUmlPatterns.cs @@ -19,10 +19,19 @@ internal class PlantUmlPatterns static PlantUmlPatterns() { StereotypeFormat = "(?:<<" + Capture(AnythingBut("<>")) + ">>\\s*)"; - ComponentNameFormat = "\\[" + Capture(AnythingBut("\\[\\]"), ComponentNameGroupName) + "]"; + ComponentNameFormat = + "\\[" + Capture(AnythingBut("\\[\\]"), ComponentNameGroupName) + "]"; StereotypePattern = new Regex(StereotypeFormat); AliasFormat = "\\s*(?:as \"?" + Capture("[^\"]+", AliasGroupName) + "\"?)?"; - PlantUmlComponentPattern = new Regex(@"\A(?:^\s*" + ComponentNameFormat + @"\s*" + StereotypeFormat + "*" + AliasFormat + @"\s*)\z"); + PlantUmlComponentPattern = new Regex( + @"\A(?:^\s*" + + ComponentNameFormat + + @"\s*" + + StereotypeFormat + + "*" + + AliasFormat + + @"\s*)\z" + ); } private static string Capture(string pattern) @@ -45,7 +54,9 @@ internal IEnumerable FilterComponents(IEnumerable plantUmlDiagra return plantUmlDiagramLines.Where(l => PlantUmlComponentPattern.Match(l).Success); } - internal IEnumerable MatchDependencies(IEnumerable diagramLines) + internal IEnumerable MatchDependencies( + IEnumerable diagramLines + ) { var result = new List(); foreach (string line in diagramLines) @@ -64,9 +75,15 @@ internal PlantUmlComponentMatcher MatchComponent(string input) internal class PlantUmlDependencyMatcher { private static readonly string ColorRegex = @"\[[^]]+]"; // for arrows like '--[#green]->' - private static readonly string DeppendencyArrowCenterRegex = @"(left|right|up|down|" + ColorRegex + ")?"; - private static readonly Regex DependencyRightArrowPattern = new Regex(@"\s-+" + DeppendencyArrowCenterRegex + @"-*>\s"); - private static readonly Regex DependencyLeftArrowPattern = new Regex(@"\s<-*" + DeppendencyArrowCenterRegex + @"-+\s"); + private static readonly string DeppendencyArrowCenterRegex = + @"(left|right|up|down|" + ColorRegex + ")?"; + private static readonly Regex DependencyRightArrowPattern = new Regex( + @"\s-+" + DeppendencyArrowCenterRegex + @"-*>\s" + ); + private static readonly Regex DependencyLeftArrowPattern = new Regex( + @"\s<-*" + DeppendencyArrowCenterRegex + @"-+\s" + ); + public PlantUmlDependencyMatcher(string origin, string target) { if (origin is null) @@ -86,17 +103,25 @@ public PlantUmlDependencyMatcher(string origin, string target) public string MatchTarget { get; private set; } public string MatchOrigin { get; private set; } - internal static IEnumerable TryParseFromLeftToRight(string line) + internal static IEnumerable TryParseFromLeftToRight( + string line + ) { return IsDependencyFromLeftToRight(line) - ? ImmutableList.CreateRange(new List { ParseDependencyFromLeftToRight(line) }) + ? ImmutableList.CreateRange( + new List { ParseDependencyFromLeftToRight(line) } + ) : Enumerable.Empty(); } - internal static IEnumerable TryParseFromRightToLeft(string line) + internal static IEnumerable TryParseFromRightToLeft( + string line + ) { return IsDependencyFromRightToLeft(line) - ? ImmutableList.CreateRange(new List { ParseDependencyFromRightToLeft(line) }) + ? ImmutableList.CreateRange( + new List { ParseDependencyFromRightToLeft(line) } + ) : Enumerable.Empty(); } @@ -125,7 +150,12 @@ private static PlantUmlDependencyMatcher ParseDependencyFromLeftToRight(string l private static IList ParseParts(string line, Regex dependencyRightArrowPattern) { line = RemoveOptionalDescription(line); - return dependencyRightArrowPattern.Replace(line, " ").Split(' ').Select(l => l.Trim()).Take(2).ToList(); + return dependencyRightArrowPattern + .Replace(line, " ") + .Split(' ') + .Select(l => l.Trim()) + .Take(2) + .ToList(); } private static string RemoveOptionalDescription(string line) @@ -138,12 +168,19 @@ internal class PlantUmlComponentMatcher { private Match _componentMatch; private Match _stereotypeMatch; + public PlantUmlComponentMatcher(string input) { _componentMatch = PlantUmlComponentPattern.Match(input); if (!_componentMatch.Success) { - throw new InvalidOperationException(string.Format("input {0} does not match pattern {1}", input, PlantUmlComponentPattern)); + throw new InvalidOperationException( + string.Format( + "input {0} does not match pattern {1}", + input, + PlantUmlComponentPattern + ) + ); } _stereotypeMatch = StereotypePattern.Match(input); } @@ -174,4 +211,4 @@ internal ISet MatchStereoTypes() } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PlantUml/Import/Stereotype.cs b/ArchUnitNET/Domain/PlantUml/Import/Stereotype.cs index 1b162558a..757428055 100644 --- a/ArchUnitNET/Domain/PlantUml/Import/Stereotype.cs +++ b/ArchUnitNET/Domain/PlantUml/Import/Stereotype.cs @@ -3,10 +3,12 @@ internal class Stereotype { private readonly string _value; + public Stereotype(string stereotype) { _value = stereotype ?? throw new System.ArgumentNullException(nameof(stereotype)); } + public string AsString() { return _value; @@ -14,8 +16,7 @@ public string AsString() public override bool Equals(object obj) { - return obj is Stereotype stereotype && - _value == stereotype._value; + return obj is Stereotype stereotype && _value == stereotype._value; } public override int GetHashCode() @@ -24,4 +25,4 @@ public override int GetHashCode() return hashCode; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/PropertyMember.cs b/ArchUnitNET/Domain/PropertyMember.cs index 174d087a8..7f093c596 100644 --- a/ArchUnitNET/Domain/PropertyMember.cs +++ b/ArchUnitNET/Domain/PropertyMember.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -16,8 +16,15 @@ public class PropertyMember : IMember, ITypeInstance { private readonly ITypeInstance _typeInstance; - public PropertyMember(IType declaringType, string name, string fullName, ITypeInstance type, - bool isCompilerGenerated, bool? isStatic, Writability writability) + public PropertyMember( + IType declaringType, + string name, + string fullName, + ITypeInstance type, + bool isCompilerGenerated, + bool? isStatic, + Writability writability + ) { Name = name; FullName = fullName; @@ -34,13 +41,16 @@ public PropertyMember(IType declaringType, string name, string fullName, ITypeIn public Visibility SetterVisibility => Setter?.Visibility ?? NotAccessible; public Visibility GetterVisibility => Getter?.Visibility ?? NotAccessible; - [CanBeNull] public MethodMember Getter { get; internal set; } + [CanBeNull] + public MethodMember Getter { get; internal set; } - [CanBeNull] public MethodMember Setter { get; internal set; } + [CanBeNull] + public MethodMember Setter { get; internal set; } public Writability? Writability { get; } - public List AttributeDependencies { get; } = new List(); + public List AttributeDependencies { get; } = + new List(); public IMemberTypeDependency PropertyTypeDependency { get; } public bool IsCompilerGenerated { get; } @@ -50,27 +60,36 @@ public PropertyMember(IType declaringType, string name, string fullName, ITypeIn public List GenericParameters => new List(); - public Visibility Visibility => GetterVisibility < SetterVisibility ? GetterVisibility : SetterVisibility; + public Visibility Visibility => + GetterVisibility < SetterVisibility ? GetterVisibility : SetterVisibility; public string Name { get; } public string FullName { get; } public IType DeclaringType { get; } - public IEnumerable Attributes => AttributeInstances.Select(instance => instance.Type); + public IEnumerable Attributes => + AttributeInstances.Select(instance => instance.Type); public List AttributeInstances { get; } = new List(); public List MemberDependencies { get { - var setterDependencies = Setter?.MemberDependencies ?? Enumerable.Empty(); - var getterDependencies = Getter?.MemberDependencies ?? Enumerable.Empty(); - return setterDependencies.Concat(getterDependencies).Concat(AttributeDependencies) - .Concat(new[] {PropertyTypeDependency}).ToList(); + var setterDependencies = + Setter?.MemberDependencies ?? Enumerable.Empty(); + var getterDependencies = + Getter?.MemberDependencies ?? Enumerable.Empty(); + return setterDependencies + .Concat(getterDependencies) + .Concat(AttributeDependencies) + .Concat(new[] { PropertyTypeDependency }) + .ToList(); } } - public List MemberBackwardsDependencies { get; } = new List(); + public List MemberBackwardsDependencies { get; } = + new List(); - public List Dependencies => MemberDependencies.Cast().ToList(); + public List Dependencies => + MemberDependencies.Cast().ToList(); public List BackwardsDependencies => MemberBackwardsDependencies.Cast().ToList(); @@ -97,7 +116,7 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((PropertyMember) obj); + return obj.GetType() == GetType() && Equals((PropertyMember)obj); } private bool Equals(PropertyMember other) @@ -110,4 +129,4 @@ public override int GetHashCode() return FullName.GetHashCode(); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Slice.cs b/ArchUnitNET/Domain/Slice.cs index 150fcba46..ad5384895 100644 --- a/ArchUnitNET/Domain/Slice.cs +++ b/ArchUnitNET/Domain/Slice.cs @@ -1,9 +1,9 @@ // 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; @@ -26,13 +26,16 @@ public Slice(SliceIdentifier identifier, IEnumerable types) public IEnumerable Classes => Types.OfType(); public IEnumerable Interfaces => Types.OfType(); - public List Dependencies => Types.SelectMany(type => type.Dependencies).ToList(); + public List Dependencies => + Types.SelectMany(type => type.Dependencies).ToList(); public List BackwardsDependencies => Types.SelectMany(type => type.BackwardsDependencies).ToList(); public string Description => Identifier.Description; - [CanBeNull] public string NameSpace => Identifier.NameSpace; + + [CanBeNull] + public string NameSpace => Identifier.NameSpace; public int? CountOfAsteriskInPattern => Identifier.CountOfAsteriskInPattern; protected bool Equals(Slice other) @@ -64,8 +67,8 @@ public override int GetHashCode() { unchecked { - return ((Identifier != null ? Identifier.GetHashCode() : 0) * 397) ^ - (Types != null ? Types.GetHashCode() : 0); + return ((Identifier != null ? Identifier.GetHashCode() : 0) * 397) + ^ (Types != null ? Types.GetHashCode() : 0); } } @@ -79,4 +82,4 @@ public bool ContainsNamespace() return NameSpace != null; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/SliceIdentifier.cs b/ArchUnitNET/Domain/SliceIdentifier.cs index 272165efc..2e15f31d2 100644 --- a/ArchUnitNET/Domain/SliceIdentifier.cs +++ b/ArchUnitNET/Domain/SliceIdentifier.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using JetBrains.Annotations; @@ -14,8 +14,13 @@ public class SliceIdentifier : StringIdentifier, IHasDescription public static readonly SliceIdentifierComparer Comparer = new SliceIdentifierComparer(); public readonly bool Ignored; - - private SliceIdentifier(string identifier, bool ignored, int? countOfAsteriskInPattern = null, string nameSpace = null) : base(identifier) + private SliceIdentifier( + string identifier, + bool ignored, + int? countOfAsteriskInPattern = null, + string nameSpace = null + ) + : base(identifier) { Ignored = ignored; CountOfAsteriskInPattern = countOfAsteriskInPattern; @@ -23,10 +28,16 @@ private SliceIdentifier(string identifier, bool ignored, int? countOfAsteriskInP } public string Description => Identifier; - [CanBeNull] public readonly string NameSpace; + + [CanBeNull] + public readonly string NameSpace; public readonly int? CountOfAsteriskInPattern; - public static SliceIdentifier Of(string identifier, int? countOfAsteriskInPattern = null, string nameSpace = null) + public static SliceIdentifier Of( + string identifier, + int? countOfAsteriskInPattern = null, + string nameSpace = null + ) { return new SliceIdentifier(identifier, false, countOfAsteriskInPattern, nameSpace); } @@ -48,7 +59,8 @@ public bool CompareTo(SliceIdentifier other) return false; } - return Ignored && other.Ignored || !Ignored && !other.Ignored && Identifier == other.Identifier; + return Ignored && other.Ignored + || !Ignored && !other.Ignored && Identifier == other.Identifier; } private bool Equals(SliceIdentifier other) @@ -81,4 +93,4 @@ public override int GetHashCode() } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/SliceIdentifierComparer.cs b/ArchUnitNET/Domain/SliceIdentifierComparer.cs index 49527168d..b9cd23b92 100644 --- a/ArchUnitNET/Domain/SliceIdentifierComparer.cs +++ b/ArchUnitNET/Domain/SliceIdentifierComparer.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Collections.Generic; @@ -21,4 +21,4 @@ public int GetHashCode(SliceIdentifier obj) return obj.GetHashCode(); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/StaticConstants.cs b/ArchUnitNET/Domain/StaticConstants.cs index b4c614628..102b82152 100644 --- a/ArchUnitNET/Domain/StaticConstants.cs +++ b/ArchUnitNET/Domain/StaticConstants.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 // ReSharper disable InconsistentNaming @@ -14,4 +14,4 @@ public static class StaticConstants public const string ConstructorNameBase = ".ctor"; public const string SystemNamespace = "System"; } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/StringIdentifier.cs b/ArchUnitNET/Domain/StringIdentifier.cs index 781ba6db3..77002e407 100644 --- a/ArchUnitNET/Domain/StringIdentifier.cs +++ b/ArchUnitNET/Domain/StringIdentifier.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// namespace ArchUnitNET.Domain { @@ -23,8 +23,9 @@ public override string ToString() public override bool Equals(object obj) { - return obj != null && obj.GetType() == GetType() && - Identifier == ((StringIdentifier)obj).Identifier; + return obj != null + && obj.GetType() == GetType() + && Identifier == ((StringIdentifier)obj).Identifier; } public override int GetHashCode() @@ -37,4 +38,4 @@ public override int GetHashCode() } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/StringIdentifierComparer.cs b/ArchUnitNET/Domain/StringIdentifierComparer.cs index 58304566f..ed858f89a 100644 --- a/ArchUnitNET/Domain/StringIdentifierComparer.cs +++ b/ArchUnitNET/Domain/StringIdentifierComparer.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Collections.Generic; @@ -26,4 +26,4 @@ public override int GetHashCode(StringIdentifier obj) return obj.Identifier.GetHashCode(); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Struct.cs b/ArchUnitNET/Domain/Struct.cs index 779113b8a..b693e5148 100644 --- a/ArchUnitNET/Domain/Struct.cs +++ b/ArchUnitNET/Domain/Struct.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -25,12 +25,13 @@ public Struct(IType type) [CanBeNull] public Class BaseClass => - (Class) Dependencies.OfType().FirstOrDefault()?.Target; - - public IEnumerable InheritedClasses => BaseClass == null - ? Enumerable.Empty() - : BaseClass.InheritedClasses.Concat(new[] {BaseClass}); - + (Class)Dependencies.OfType().FirstOrDefault()?.Target; + + public IEnumerable InheritedClasses => + BaseClass == null + ? Enumerable.Empty() + : BaseClass.InheritedClasses.Concat(new[] { BaseClass }); + public Visibility Visibility => Type.Visibility; public bool IsNested => Type.IsNested; public bool IsGeneric => Type.IsGeneric; @@ -41,7 +42,8 @@ public Struct(IType type) public Namespace Namespace => Type.Namespace; public Assembly Assembly => Type.Assembly; - public IEnumerable Attributes => AttributeInstances.Select(instance => instance.Type); + public IEnumerable Attributes => + AttributeInstances.Select(instance => instance.Type); public List AttributeInstances => Type.AttributeInstances; public List Dependencies => Type.Dependencies; @@ -73,7 +75,7 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((Struct) obj); + return obj.GetType() == GetType() && Equals((Struct)obj); } public override int GetHashCode() @@ -81,4 +83,4 @@ public override int GetHashCode() return Type != null ? Type.GetHashCode() : 0; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/TypeDependencyComparer.cs b/ArchUnitNET/Domain/TypeDependencyComparer.cs index e73e3d248..b1fab9fca 100644 --- a/ArchUnitNET/Domain/TypeDependencyComparer.cs +++ b/ArchUnitNET/Domain/TypeDependencyComparer.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Collections.Generic; using ArchUnitNET.Domain.Dependencies; @@ -19,7 +19,10 @@ public bool Equals(ITypeDependency x, ITypeDependency y) return true; } - return x != null && y != null && Equals(x.Origin, y.Origin) && Equals(x.Target, y.Target); + return x != null + && y != null + && Equals(x.Origin, y.Origin) + && Equals(x.Target, y.Target); } public int GetHashCode(ITypeDependency obj) @@ -30,4 +33,4 @@ public int GetHashCode(ITypeDependency obj) } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/TypeInstance.cs b/ArchUnitNET/Domain/TypeInstance.cs index c30dd8080..4e14cc720 100644 --- a/ArchUnitNET/Domain/TypeInstance.cs +++ b/ArchUnitNET/Domain/TypeInstance.cs @@ -1,18 +1,23 @@ // 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; namespace ArchUnitNET.Domain { - public class TypeInstance : ITypeInstance where T : IType + public class TypeInstance : ITypeInstance + where T : IType { - public TypeInstance(T type, IEnumerable genericArguments, IEnumerable arrayDimensions) + public TypeInstance( + T type, + IEnumerable genericArguments, + IEnumerable arrayDimensions + ) { Type = type; GenericArguments = genericArguments; @@ -21,14 +26,10 @@ public TypeInstance(T type, IEnumerable genericArguments, IEnum } public TypeInstance(T type, IEnumerable genericArguments) - : this(type, genericArguments, Enumerable.Empty()) - { - } + : this(type, genericArguments, Enumerable.Empty()) { } public TypeInstance(T type) - : this(type, Enumerable.Empty()) - { - } + : this(type, Enumerable.Empty()) { } public T Type { get; } public IEnumerable GenericArguments { get; } @@ -47,7 +48,7 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((TypeInstance) obj); + return obj.GetType() == GetType() && Equals((TypeInstance)obj); } private bool Equals(TypeInstance other) @@ -62,8 +63,10 @@ private bool Equals(TypeInstance other) return true; } - return Equals(Type, other.Type) && GenericArguments.SequenceEqual(other.GenericArguments) && - Equals(IsArray, other.IsArray) && ArrayDimensions.SequenceEqual(other.ArrayDimensions); + return Equals(Type, other.Type) + && GenericArguments.SequenceEqual(other.GenericArguments) + && Equals(IsArray, other.IsArray) + && ArrayDimensions.SequenceEqual(other.ArrayDimensions); } public override int GetHashCode() @@ -71,12 +74,17 @@ public override int GetHashCode() unchecked { var hashCode = Type != null ? Type.GetHashCode() : 0; - hashCode = GenericArguments.Aggregate(hashCode, - (current, type) => (current * 397) ^ (type != null ? type.GetHashCode() : 0)); + hashCode = GenericArguments.Aggregate( + hashCode, + (current, type) => (current * 397) ^ (type != null ? type.GetHashCode() : 0) + ); hashCode = (hashCode * 397) ^ IsArray.GetHashCode(); - hashCode = ArrayDimensions.Aggregate(hashCode, (current, dim) => (current * 397) ^ dim.GetHashCode()); + hashCode = ArrayDimensions.Aggregate( + hashCode, + (current, dim) => (current * 397) ^ dim.GetHashCode() + ); return hashCode; } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Domain/Visibility.cs b/ArchUnitNET/Domain/Visibility.cs index c41d29384..721391de7 100644 --- a/ArchUnitNET/Domain/Visibility.cs +++ b/ArchUnitNET/Domain/Visibility.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 namespace ArchUnitNET.Domain @@ -20,14 +20,30 @@ public enum Visibility public static class VisibilityStrings { private static readonly string[] CapitalLetters = - {"Public", "Protected Internal", "Internal", "Protected", "Private Protected", "Private", "Not Accessible"}; + { + "Public", + "Protected Internal", + "Internal", + "Protected", + "Private Protected", + "Private", + "Not Accessible" + }; private static readonly string[] LowerCase = - {"public", "protected internal", "internal", "protected", "private protected", "private", "not accessible"}; + { + "public", + "protected internal", + "internal", + "protected", + "private protected", + "private", + "not accessible" + }; public static string ToString(this Visibility visibility, bool useCapitalLetters = false) { - return useCapitalLetters ? CapitalLetters[(int) visibility] : LowerCase[(int) visibility]; + return useCapitalLetters ? CapitalLetters[(int)visibility] : LowerCase[(int)visibility]; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/ArchRule.cs b/ArchUnitNET/Fluent/ArchRule.cs index b82348552..5feafc63f 100644 --- a/ArchUnitNET/Fluent/ArchRule.cs +++ b/ArchUnitNET/Fluent/ArchRule.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -11,11 +11,11 @@ namespace ArchUnitNET.Fluent { - public class ArchRule : SyntaxElement, IArchRule where TRuleType : ICanBeAnalyzed + public class ArchRule : SyntaxElement, IArchRule + where TRuleType : ICanBeAnalyzed { - protected ArchRule(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + protected ArchRule(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } /// /// By default, rules are evaluated so positive results are required to be present. @@ -27,7 +27,6 @@ public ArchRule WithoutRequiringPositiveResults() return this; } - public bool HasNoViolations(Architecture architecture) { if (_ruleCreator.RequirePositiveResults) @@ -38,22 +37,26 @@ public bool HasNoViolations(Architecture architecture) { return _ruleCreator.HasNoViolations(architecture); } - } public IEnumerable Evaluate(Architecture architecture) { var result = _ruleCreator.Evaluate(architecture).ToList(); - + // To require positives, we only ever need to add // a non-passing result if there are no results. - if (_ruleCreator.RequirePositiveResults && - result.Count == 0) + if (_ruleCreator.RequirePositiveResults && result.Count == 0) { - result.Add(new EvaluationResult( - this, new StringIdentifier(Description), false, - $"The rule requires positive evaluation, not just absence of violations. Use {nameof(WithoutRequiringPositiveResults)}() or improve your rule's predicates.", - this, architecture)); + result.Add( + new EvaluationResult( + this, + new StringIdentifier(Description), + false, + $"The rule requires positive evaluation, not just absence of violations. Use {nameof(WithoutRequiringPositiveResults)}() or improve your rule's predicates.", + this, + architecture + ) + ); } return result; @@ -79,4 +82,4 @@ public IArchRule Or(IArchRule archRule) return new CombinedArchRule(_ruleCreator, LogicalConjunctionDefinition.Or, archRule); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/ArchRuleCreator.cs b/ArchUnitNET/Fluent/ArchRuleCreator.cs index 5e2d2787b..ab30edee3 100644 --- a/ArchUnitNET/Fluent/ArchRuleCreator.cs +++ b/ArchUnitNET/Fluent/ArchRuleCreator.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -13,7 +13,8 @@ namespace ArchUnitNET.Fluent { - public class ArchRuleCreator : IArchRuleCreator where TRuleType : ICanBeAnalyzed + public class ArchRuleCreator : IArchRuleCreator + where TRuleType : ICanBeAnalyzed { private readonly ConditionManager _conditionManager; private readonly PredicateManager _predicateManager; @@ -25,7 +26,8 @@ public ArchRuleCreator(BasicObjectProvider basicObjectProvider) _conditionManager = new ConditionManager(); } - public string Description => (_predicateManager.Description + " " + _conditionManager.Description).Trim(); + public string Description => + (_predicateManager.Description + " " + _conditionManager.Description).Trim(); public bool HasNoViolations(Architecture architecture) { @@ -67,8 +69,10 @@ public void AddPredicateReason(string reason) _predicateManager.AddReason(reason); } - public void BeginComplexCondition(IObjectProvider relatedObjects, - RelationCondition relationCondition) + public void BeginComplexCondition( + IObjectProvider relatedObjects, + RelationCondition relationCondition + ) where TRelatedType : ICanBeAnalyzed { _conditionManager.BeginComplexCondition(relatedObjects, relationCondition); @@ -97,8 +101,7 @@ public void SetCustomConditionDescription(string description) private void SetRequirePositiveResults(bool requirePositive) { - if (_requirePositiveResults != null && - _requirePositiveResults != requirePositive) + if (_requirePositiveResults != null && _requirePositiveResults != requirePositive) throw new InvalidOperationException("conflicting positive expectation"); _requirePositiveResults = requirePositive; } @@ -109,13 +112,18 @@ public bool RequirePositiveResults set => SetRequirePositiveResults(value); } - private bool HasNoViolations(IEnumerable filteredObjects, Architecture architecture) + private bool HasNoViolations( + IEnumerable filteredObjects, + Architecture architecture + ) { return EvaluateConditions(filteredObjects, architecture).All(result => result.Passed); } - private IEnumerable EvaluateConditions(IEnumerable filteredObjects, - Architecture architecture) + private IEnumerable EvaluateConditions( + IEnumerable filteredObjects, + Architecture architecture + ) { return _conditionManager.EvaluateConditions(filteredObjects, architecture, this); } @@ -127,8 +135,8 @@ public override string ToString() private bool Equals(ArchRuleCreator other) { - return _conditionManager.Equals(other._conditionManager) && - _predicateManager.Equals(other._predicateManager); + return _conditionManager.Equals(other._conditionManager) + && _predicateManager.Equals(other._predicateManager); } public override bool Equals(object obj) @@ -143,17 +151,20 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((ArchRuleCreator) obj); + return obj.GetType() == GetType() && Equals((ArchRuleCreator)obj); } public override int GetHashCode() { unchecked { - var hashCode = 397 ^ (_conditionManager != null ? _conditionManager.GetHashCode() : 0); - hashCode = (hashCode * 397) ^ (_predicateManager != null ? _predicateManager.GetHashCode() : 0); + var hashCode = + 397 ^ (_conditionManager != null ? _conditionManager.GetHashCode() : 0); + hashCode = + (hashCode * 397) + ^ (_predicateManager != null ? _predicateManager.GetHashCode() : 0); return hashCode; } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/ArchRuleDefinition.cs b/ArchUnitNET/Fluent/ArchRuleDefinition.cs index bc0da4ab8..d908dbca4 100644 --- a/ArchUnitNET/Fluent/ArchRuleDefinition.cs +++ b/ArchUnitNET/Fluent/ArchRuleDefinition.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -29,7 +29,9 @@ public static GivenTypes Types(bool includeReferenced = false) public static GivenAttributes Attributes(bool includeReferenced = false) { var ruleCreator = includeReferenced - ? new ArchRuleCreator(BasicObjectProviderDefinition.AttributesIncludingReferenced) + ? new ArchRuleCreator( + BasicObjectProviderDefinition.AttributesIncludingReferenced + ) : new ArchRuleCreator(BasicObjectProviderDefinition.Attributes); return new GivenAttributes(ruleCreator); } @@ -37,7 +39,9 @@ public static GivenAttributes Attributes(bool includeReferenced = false) public static GivenClasses Classes(bool includeReferenced = false) { var ruleCreator = includeReferenced - ? new ArchRuleCreator(BasicObjectProviderDefinition.ClassesIncludingReferenced) + ? new ArchRuleCreator( + BasicObjectProviderDefinition.ClassesIncludingReferenced + ) : new ArchRuleCreator(BasicObjectProviderDefinition.Classes); return new GivenClasses(ruleCreator); } @@ -45,7 +49,9 @@ public static GivenClasses Classes(bool includeReferenced = false) public static GivenInterfaces Interfaces(bool includeReferenced = false) { var ruleCreator = includeReferenced - ? new ArchRuleCreator(BasicObjectProviderDefinition.InterfacesIncludingReferenced) + ? new ArchRuleCreator( + BasicObjectProviderDefinition.InterfacesIncludingReferenced + ) : new ArchRuleCreator(BasicObjectProviderDefinition.Interfaces); return new GivenInterfaces(ruleCreator); } @@ -58,23 +64,26 @@ public static GivenMembers Members() public static GivenFieldMembers FieldMembers() { - var ruleCreator = - new ArchRuleCreator(BasicObjectProviderDefinition.FieldMembers); + var ruleCreator = new ArchRuleCreator( + BasicObjectProviderDefinition.FieldMembers + ); return new GivenFieldMembers(ruleCreator); } public static GivenMethodMembers MethodMembers() { - var ruleCreator = - new ArchRuleCreator(BasicObjectProviderDefinition.MethodMembers); + var ruleCreator = new ArchRuleCreator( + BasicObjectProviderDefinition.MethodMembers + ); return new GivenMethodMembers(ruleCreator); } public static GivenPropertyMembers PropertyMembers() { - var ruleCreator = - new ArchRuleCreator(BasicObjectProviderDefinition.PropertyMembers); + var ruleCreator = new ArchRuleCreator( + BasicObjectProviderDefinition.PropertyMembers + ); return new GivenPropertyMembers(ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/BasicObjectProvider.cs b/ArchUnitNET/Fluent/BasicObjectProvider.cs index ac405d9e4..876f7b42d 100644 --- a/ArchUnitNET/Fluent/BasicObjectProvider.cs +++ b/ArchUnitNET/Fluent/BasicObjectProvider.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -10,7 +10,8 @@ namespace ArchUnitNET.Fluent { - public class BasicObjectProvider : IObjectProvider where T : ICanBeAnalyzed + public class BasicObjectProvider : IObjectProvider + where T : ICanBeAnalyzed { private readonly Func> _objects; @@ -49,7 +50,7 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((BasicObjectProvider) obj); + return obj.GetType() == GetType() && Equals((BasicObjectProvider)obj); } public override int GetHashCode() @@ -57,4 +58,4 @@ public override int GetHashCode() return Description != null ? Description.GetHashCode() : 0; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/BasicObjectProviderDefinition.cs b/ArchUnitNET/Fluent/BasicObjectProviderDefinition.cs index 52e9ea480..fb1c86f7f 100644 --- a/ArchUnitNET/Fluent/BasicObjectProviderDefinition.cs +++ b/ArchUnitNET/Fluent/BasicObjectProviderDefinition.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Linq; @@ -11,46 +11,71 @@ namespace ArchUnitNET.Fluent { public static class BasicObjectProviderDefinition { - public static readonly BasicObjectProvider Types = - new BasicObjectProvider(architecture => architecture.Types, "Types"); + public static readonly BasicObjectProvider Types = new BasicObjectProvider( + architecture => architecture.Types, + "Types" + ); public static readonly BasicObjectProvider Attributes = - new BasicObjectProvider(architecture => architecture.Attributes, "Attributes"); + new BasicObjectProvider( + architecture => architecture.Attributes, + "Attributes" + ); - public static readonly BasicObjectProvider Classes = - new BasicObjectProvider(architecture => architecture.Classes, "Classes"); + public static readonly BasicObjectProvider Classes = new BasicObjectProvider( + architecture => architecture.Classes, + "Classes" + ); public static readonly BasicObjectProvider Interfaces = - new BasicObjectProvider(architecture => architecture.Interfaces, "Interfaces"); + new BasicObjectProvider( + architecture => architecture.Interfaces, + "Interfaces" + ); public static readonly BasicObjectProvider Members = new BasicObjectProvider(architecture => architecture.Members, "Members"); public static readonly BasicObjectProvider FieldMembers = - new BasicObjectProvider(architecture => architecture.FieldMembers, "Field members"); + new BasicObjectProvider( + architecture => architecture.FieldMembers, + "Field members" + ); public static readonly BasicObjectProvider MethodMembers = - new BasicObjectProvider(architecture => architecture.MethodMembers, "Method members"); + new BasicObjectProvider( + architecture => architecture.MethodMembers, + "Method members" + ); public static readonly BasicObjectProvider PropertyMembers = - new BasicObjectProvider(architecture => architecture.PropertyMembers, "Property members"); + new BasicObjectProvider( + architecture => architecture.PropertyMembers, + "Property members" + ); public static readonly BasicObjectProvider TypesIncludingReferenced = - new BasicObjectProvider(architecture => architecture.Types.Concat(architecture.ReferencedTypes), - "Types (including referenced)"); + new BasicObjectProvider( + architecture => architecture.Types.Concat(architecture.ReferencedTypes), + "Types (including referenced)" + ); public static readonly BasicObjectProvider AttributesIncludingReferenced = new BasicObjectProvider( architecture => architecture.Attributes.Concat(architecture.ReferencedAttributes), - "Attributes (including referenced)"); + "Attributes (including referenced)" + ); public static readonly BasicObjectProvider ClassesIncludingReferenced = - new BasicObjectProvider(architecture => architecture.Classes.Concat(architecture.ReferencedClasses), - "Classes (including referenced)"); + new BasicObjectProvider( + architecture => architecture.Classes.Concat(architecture.ReferencedClasses), + "Classes (including referenced)" + ); public static readonly BasicObjectProvider InterfacesIncludingReferenced = new BasicObjectProvider( architecture => architecture.Interfaces.Concat(architecture.ReferencedInterfaces), - "Interfaces (including referenced)"); + "Interfaces (including referenced)" + ); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/CombinedArchRule.cs b/ArchUnitNET/Fluent/CombinedArchRule.cs index 0193a6e57..f91ee3c3b 100644 --- a/ArchUnitNET/Fluent/CombinedArchRule.cs +++ b/ArchUnitNET/Fluent/CombinedArchRule.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -16,21 +16,30 @@ public class CombinedArchRule : IArchRule private readonly LogicalConjunction _logicalConjunction; private readonly ICanBeEvaluated _secondRule; - public CombinedArchRule(ICanBeEvaluated firstRule, LogicalConjunction logicalConjunction, - ICanBeEvaluated secondRule) + public CombinedArchRule( + ICanBeEvaluated firstRule, + LogicalConjunction logicalConjunction, + ICanBeEvaluated secondRule + ) { _firstRule = firstRule; _secondRule = secondRule; _logicalConjunction = logicalConjunction; } - public string Description => _firstRule.Description + " " + _logicalConjunction.Description + " " + - _secondRule.Description; + public string Description => + _firstRule.Description + + " " + + _logicalConjunction.Description + + " " + + _secondRule.Description; public bool HasNoViolations(Architecture architecture) { - return _logicalConjunction.Evaluate(_firstRule.HasNoViolations(architecture), - _secondRule.HasNoViolations(architecture)); + return _logicalConjunction.Evaluate( + _firstRule.HasNoViolations(architecture), + _secondRule.HasNoViolations(architecture) + ); } public IEnumerable Evaluate(Architecture architecture) @@ -65,9 +74,9 @@ public override string ToString() private bool Equals(CombinedArchRule other) { - return Equals(_firstRule, other._firstRule) && - Equals(_secondRule, other._secondRule) && - Equals(_logicalConjunction, other._logicalConjunction); + return Equals(_firstRule, other._firstRule) + && Equals(_secondRule, other._secondRule) + && Equals(_logicalConjunction, other._logicalConjunction); } public override bool Equals(object obj) @@ -82,7 +91,7 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((CombinedArchRule) obj); + return obj.GetType() == GetType() && Equals((CombinedArchRule)obj); } public override int GetHashCode() @@ -91,11 +100,12 @@ public override int GetHashCode() { var hashCode = Description != null ? Description.GetHashCode() : 0; hashCode = (hashCode * 397) ^ (_firstRule != null ? _firstRule.GetHashCode() : 0); - hashCode = (hashCode * 397) ^ (_logicalConjunction != null ? _logicalConjunction.GetHashCode() : 0); - hashCode = (hashCode * 397) ^ - (_secondRule != null ? _secondRule.GetHashCode() : 0); + hashCode = + (hashCode * 397) + ^ (_logicalConjunction != null ? _logicalConjunction.GetHashCode() : 0); + hashCode = (hashCode * 397) ^ (_secondRule != null ? _secondRule.GetHashCode() : 0); return hashCode; } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/CombinedArchRuleCreator.cs b/ArchUnitNET/Fluent/CombinedArchRuleCreator.cs index dce8d07b9..5fcb27377 100644 --- a/ArchUnitNET/Fluent/CombinedArchRuleCreator.cs +++ b/ArchUnitNET/Fluent/CombinedArchRuleCreator.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -14,33 +14,45 @@ namespace ArchUnitNET.Fluent { - public class CombinedArchRuleCreator : IArchRuleCreator where TRuleType : ICanBeAnalyzed + public class CombinedArchRuleCreator : IArchRuleCreator + where TRuleType : ICanBeAnalyzed { private readonly ArchRuleCreator _currentArchRuleCreator; private readonly LogicalConjunction _logicalConjunction; private readonly ICanBeEvaluated _oldRule; private bool? _requirePositiveResults; - public CombinedArchRuleCreator(ICanBeEvaluated oldRule, LogicalConjunction logicalConjunction, - BasicObjectProvider basicObjectProvider) + public CombinedArchRuleCreator( + ICanBeEvaluated oldRule, + LogicalConjunction logicalConjunction, + BasicObjectProvider basicObjectProvider + ) { _oldRule = oldRule; _logicalConjunction = logicalConjunction; _currentArchRuleCreator = new ArchRuleCreator(basicObjectProvider); } - public string Description => _oldRule.Description + " " + _logicalConjunction.Description + " " + - _currentArchRuleCreator.Description; + public string Description => + _oldRule.Description + + " " + + _logicalConjunction.Description + + " " + + _currentArchRuleCreator.Description; public bool HasNoViolations(Architecture architecture) { - return _logicalConjunction.Evaluate(_oldRule.HasNoViolations(architecture), - _currentArchRuleCreator.HasNoViolations(architecture)); + return _logicalConjunction.Evaluate( + _oldRule.HasNoViolations(architecture), + _currentArchRuleCreator.HasNoViolations(architecture) + ); } public IEnumerable Evaluate(Architecture architecture) { - return _oldRule.Evaluate(architecture).Concat(_currentArchRuleCreator.Evaluate(architecture)); + return _oldRule + .Evaluate(architecture) + .Concat(_currentArchRuleCreator.Evaluate(architecture)); } public void AddPredicate(IPredicate predicate) @@ -73,8 +85,11 @@ public void AddPredicateReason(string reason) _currentArchRuleCreator.AddPredicateReason(reason); } - public void BeginComplexCondition(IObjectProvider relatedObjects, - RelationCondition relationCondition) where TRelatedType : ICanBeAnalyzed + public void BeginComplexCondition( + IObjectProvider relatedObjects, + RelationCondition relationCondition + ) + where TRelatedType : ICanBeAnalyzed { _currentArchRuleCreator.BeginComplexCondition(relatedObjects, relationCondition); } @@ -88,7 +103,8 @@ public void ContinueComplexCondition(IPredicate pred public IEnumerable GetAnalyzedObjects(Architecture architecture) { throw new CannotGetObjectsOfCombinedArchRuleCreatorException( - "GetFilteredObjects() can't be used with CombinedArchRuleCreators because the analyzed objects might be of different type."); + "GetFilteredObjects() can't be used with CombinedArchRuleCreators because the analyzed objects might be of different type." + ); } public void SetCustomPredicateDescription(string description) @@ -103,8 +119,7 @@ public void SetCustomConditionDescription(string description) private void SetRequirePositiveResults(bool requirePositive) { - if (_requirePositiveResults != null && - _requirePositiveResults != requirePositive) + if (_requirePositiveResults != null && _requirePositiveResults != requirePositive) throw new InvalidOperationException("conflicting positive expectation"); _requirePositiveResults = requirePositive; } @@ -115,7 +130,6 @@ public bool RequirePositiveResults set => SetRequirePositiveResults(value); } - public override string ToString() { return Description; @@ -123,9 +137,9 @@ public override string ToString() private bool Equals(CombinedArchRuleCreator other) { - return Equals(_oldRule, other._oldRule) && - Equals(_logicalConjunction, other._logicalConjunction) && - Equals(_currentArchRuleCreator, other._currentArchRuleCreator); + return Equals(_oldRule, other._oldRule) + && Equals(_logicalConjunction, other._logicalConjunction) + && Equals(_currentArchRuleCreator, other._currentArchRuleCreator); } public override bool Equals(object obj) @@ -140,7 +154,7 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((CombinedArchRuleCreator) obj); + return obj.GetType() == GetType() && Equals((CombinedArchRuleCreator)obj); } public override int GetHashCode() @@ -148,11 +162,14 @@ public override int GetHashCode() unchecked { var hashCode = _oldRule != null ? _oldRule.GetHashCode() : 0; - hashCode = (hashCode * 397) ^ (_logicalConjunction != null ? _logicalConjunction.GetHashCode() : 0); - hashCode = (hashCode * 397) ^ - (_currentArchRuleCreator != null ? _currentArchRuleCreator.GetHashCode() : 0); + hashCode = + (hashCode * 397) + ^ (_logicalConjunction != null ? _logicalConjunction.GetHashCode() : 0); + hashCode = + (hashCode * 397) + ^ (_currentArchRuleCreator != null ? _currentArchRuleCreator.GetHashCode() : 0); return hashCode; } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/CombinedArchRuleDefinition.cs b/ArchUnitNET/Fluent/CombinedArchRuleDefinition.cs index bc95b6113..55fa6c41a 100644 --- a/ArchUnitNET/Fluent/CombinedArchRuleDefinition.cs +++ b/ArchUnitNET/Fluent/CombinedArchRuleDefinition.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -21,7 +21,10 @@ public class CombinedArchRuleDefinition private readonly LogicalConjunction _logicalConjunction; private readonly ICanBeEvaluated _oldRule; - public CombinedArchRuleDefinition(ICanBeEvaluated oldRule, LogicalConjunction logicalConjunction) + public CombinedArchRuleDefinition( + ICanBeEvaluated oldRule, + LogicalConjunction logicalConjunction + ) { _oldRule = oldRule; _logicalConjunction = logicalConjunction; @@ -29,58 +32,82 @@ public CombinedArchRuleDefinition(ICanBeEvaluated oldRule, LogicalConjunction lo public GivenTypes Types() { - var combinedRuleCreator = new CombinedArchRuleCreator(_oldRule, _logicalConjunction, - BasicObjectProviderDefinition.Types); + var combinedRuleCreator = new CombinedArchRuleCreator( + _oldRule, + _logicalConjunction, + BasicObjectProviderDefinition.Types + ); return new GivenTypes(combinedRuleCreator); } public GivenAttributes Attributes() { - var combinedRuleCreator = new CombinedArchRuleCreator(_oldRule, - _logicalConjunction, BasicObjectProviderDefinition.Attributes); + var combinedRuleCreator = new CombinedArchRuleCreator( + _oldRule, + _logicalConjunction, + BasicObjectProviderDefinition.Attributes + ); return new GivenAttributes(combinedRuleCreator); } public GivenClasses Classes() { - var combinedRuleCreator = new CombinedArchRuleCreator(_oldRule, _logicalConjunction, - BasicObjectProviderDefinition.Classes); + var combinedRuleCreator = new CombinedArchRuleCreator( + _oldRule, + _logicalConjunction, + BasicObjectProviderDefinition.Classes + ); return new GivenClasses(combinedRuleCreator); } public GivenInterfaces Interfaces() { - var combinedRuleCreator = new CombinedArchRuleCreator(_oldRule, - _logicalConjunction, BasicObjectProviderDefinition.Interfaces); + var combinedRuleCreator = new CombinedArchRuleCreator( + _oldRule, + _logicalConjunction, + BasicObjectProviderDefinition.Interfaces + ); return new GivenInterfaces(combinedRuleCreator); } public GivenMembers Members() { - var combinedRuleCreator = new CombinedArchRuleCreator(_oldRule, _logicalConjunction, - BasicObjectProviderDefinition.Members); + var combinedRuleCreator = new CombinedArchRuleCreator( + _oldRule, + _logicalConjunction, + BasicObjectProviderDefinition.Members + ); return new GivenMembers(combinedRuleCreator); } public GivenFieldMembers FieldMembers() { - var combinedRuleCreator = new CombinedArchRuleCreator(_oldRule, - _logicalConjunction, BasicObjectProviderDefinition.FieldMembers); + var combinedRuleCreator = new CombinedArchRuleCreator( + _oldRule, + _logicalConjunction, + BasicObjectProviderDefinition.FieldMembers + ); return new GivenFieldMembers(combinedRuleCreator); } public GivenMethodMembers MethodMembers() { - var combinedRuleCreator = new CombinedArchRuleCreator(_oldRule, - _logicalConjunction, BasicObjectProviderDefinition.MethodMembers); + var combinedRuleCreator = new CombinedArchRuleCreator( + _oldRule, + _logicalConjunction, + BasicObjectProviderDefinition.MethodMembers + ); return new GivenMethodMembers(combinedRuleCreator); } public GivenPropertyMembers PropertyMembers() { - var combinedRuleCreator = new CombinedArchRuleCreator(_oldRule, - _logicalConjunction, BasicObjectProviderDefinition.PropertyMembers); + var combinedRuleCreator = new CombinedArchRuleCreator( + _oldRule, + _logicalConjunction, + BasicObjectProviderDefinition.PropertyMembers + ); return new GivenPropertyMembers(combinedRuleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/ConditionManager.cs b/ArchUnitNET/Fluent/ConditionManager.cs index a9b705920..ba056db53 100644 --- a/ArchUnitNET/Fluent/ConditionManager.cs +++ b/ArchUnitNET/Fluent/ConditionManager.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -16,7 +16,8 @@ namespace ArchUnitNET.Fluent { - internal class ConditionManager : IHasDescription where T : ICanBeAnalyzed + internal class ConditionManager : IHasDescription + where T : ICanBeAnalyzed { private readonly List> _conditionElements; private Type _referenceTypeTemp; @@ -31,11 +32,18 @@ public ConditionManager() }; } - public string Description => _conditionElements - .Aggregate("", (current, conditionElement) => current + " " + conditionElement.Description).Trim(); - - public void BeginComplexCondition(IObjectProvider relatedObjects, - RelationCondition relationCondition) + public string Description => + _conditionElements + .Aggregate( + "", + (current, conditionElement) => current + " " + conditionElement.Description + ) + .Trim(); + + public void BeginComplexCondition( + IObjectProvider relatedObjects, + RelationCondition relationCondition + ) where TRelatedType : ICanBeAnalyzed { _relatedObjectsTemp = relatedObjects; @@ -49,13 +57,18 @@ public void ContinueComplexCondition(IPredicate filt if (typeof(TRelatedType) == _referenceTypeTemp) { AddCondition( - new ComplexCondition((IObjectProvider) _relatedObjectsTemp, - (RelationCondition) _relationConditionTemp, filter)); + 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()."); + "ContinueComplexCondition() has to be called with the same generic type argument that was used for BeginComplexCondition()." + ); } } @@ -71,7 +84,9 @@ public void AddReason(string reason) public void SetCustomDescription(string description) { - _conditionElements.ForEach(conditionElement => conditionElement.SetCustomDescription("")); + _conditionElements.ForEach(conditionElement => + conditionElement.SetCustomDescription("") + ); _conditionElements.Last().SetCustomDescription(description); } @@ -82,19 +97,29 @@ public void SetNextLogicalConjunction(LogicalConjunction logicalConjunction) private bool CheckEmpty() { - return _conditionElements.Aggregate(true, - (currentResult, conditionElement) => conditionElement.CheckEmpty(currentResult)); + return _conditionElements.Aggregate( + true, + (currentResult, conditionElement) => conditionElement.CheckEmpty(currentResult) + ); } - public IEnumerable EvaluateConditions(IEnumerable filteredObjects, - Architecture architecture, ICanBeEvaluated archRuleCreator) + public IEnumerable EvaluateConditions( + IEnumerable filteredObjects, + Architecture architecture, + ICanBeEvaluated archRuleCreator + ) { var filteredObjectsList = filteredObjects.ToList(); - if (filteredObjectsList.IsNullOrEmpty() && - !CheckEmpty()) + if (filteredObjectsList.IsNullOrEmpty() && !CheckEmpty()) { - yield return new EvaluationResult(null, new StringIdentifier(""), false, - "There are no objects matching the criteria", archRuleCreator, architecture); + yield return new EvaluationResult( + null, + new StringIdentifier(""), + false, + "There are no objects matching the criteria", + archRuleCreator, + architecture + ); yield break; } @@ -102,47 +127,76 @@ public IEnumerable EvaluateConditions(IEnumerable filteredO //but in large cases its quadratic behavior becomes too slow and building of a dictionary is justified if (filteredObjectsList.Count * _conditionElements.Count > 256) { - var conditionResults = _conditionElements.Select(conditionElement => - conditionElement.Check(filteredObjectsList, architecture).ToDictionary(x => x.ConditionResult.AnalyzedObject)) + var conditionResults = _conditionElements + .Select(conditionElement => + conditionElement + .Check(filteredObjectsList, architecture) + .ToDictionary(x => x.ConditionResult.AnalyzedObject) + ) .ToList(); foreach (var t in filteredObjectsList) { - yield return CreateEvaluationResult(FindResultsForObject(conditionResults, t), architecture, archRuleCreator); + yield return CreateEvaluationResult( + FindResultsForObject(conditionResults, t), + architecture, + archRuleCreator + ); } } else { - var conditionResults = _conditionElements.Select(conditionElement => - conditionElement.Check(filteredObjectsList, architecture).ToList()).ToList(); + var conditionResults = _conditionElements + .Select(conditionElement => + conditionElement.Check(filteredObjectsList, architecture).ToList() + ) + .ToList(); foreach (var t in filteredObjectsList) { - yield return CreateEvaluationResult(FindResultsForObject(conditionResults, t), architecture, archRuleCreator); + yield return CreateEvaluationResult( + FindResultsForObject(conditionResults, t), + architecture, + archRuleCreator + ); } } } - private IEnumerable FindResultsForObject(List> conditionResults, T canBeAnalyzed) + private IEnumerable FindResultsForObject( + List> conditionResults, + T canBeAnalyzed + ) { return conditionResults.Select(results => results[canBeAnalyzed]); } - private static IEnumerable FindResultsForObject(List> conditionResults, T t) + private static IEnumerable FindResultsForObject( + List> conditionResults, + T t + ) { - return conditionResults.Select(results => results.Find(x => x.ConditionResult.AnalyzedObject.Equals(t))); + return conditionResults.Select(results => + results.Find(x => x.ConditionResult.AnalyzedObject.Equals(t)) + ); } private static EvaluationResult CreateEvaluationResult( IEnumerable conditionElementResults, - Architecture architecture, ICanBeEvaluated archRuleCreator) + Architecture architecture, + ICanBeEvaluated archRuleCreator + ) { var conditionElementResultsList = conditionElementResults.ToList(); var analyzedObject = conditionElementResultsList.First().ConditionResult.AnalyzedObject; - var passRule = conditionElementResultsList.Aggregate(true, + var passRule = conditionElementResultsList.Aggregate( + true, (currentResult, conditionElementResult) => - conditionElementResult.LogicalConjunction.Evaluate(currentResult, - conditionElementResult.ConditionResult.Pass)); + conditionElementResult.LogicalConjunction.Evaluate( + currentResult, + conditionElementResult.ConditionResult.Pass + ) + ); var description = analyzedObject.FullName; if (passRule) { @@ -151,11 +205,15 @@ private static EvaluationResult CreateEvaluationResult( 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))) + 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) { @@ -169,8 +227,14 @@ private static EvaluationResult CreateEvaluationResult( } var identifier = new StringIdentifier(analyzedObject.FullName); - return new EvaluationResult(analyzedObject, identifier, passRule, description, archRuleCreator, - architecture); + return new EvaluationResult( + analyzedObject, + identifier, + passRule, + description, + archRuleCreator, + architecture + ); } public override string ToString() @@ -190,32 +254,37 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((ConditionManager) obj); + return obj.GetType() == GetType() && Equals((ConditionManager)obj); } public override int GetHashCode() { unchecked { - return _conditionElements.Aggregate(397, + return _conditionElements.Aggregate( + 397, (current, conditionElement) => - (current * 397) ^ (conditionElement != null ? conditionElement.GetHashCode() : 0)); + (current * 397) + ^ (conditionElement != null ? conditionElement.GetHashCode() : 0) + ); } } private bool Equals(ConditionManager other) { - return _conditionElements.SequenceEqual(other._conditionElements) && - _referenceTypeTemp == other._referenceTypeTemp && - _relationConditionTemp == other._relationConditionTemp; + return _conditionElements.SequenceEqual(other._conditionElements) + && _referenceTypeTemp == other._referenceTypeTemp + && _relationConditionTemp == other._relationConditionTemp; } #pragma warning disable 693 - private class ConditionElement : IHasDescription where T : ICanBeAnalyzed + private class ConditionElement : IHasDescription + where T : ICanBeAnalyzed { private readonly LogicalConjunction _logicalConjunction; private ICondition _condition; - [CanBeNull] private string _customDescription; + [CanBeNull] + private string _customDescription; private string _reason; @@ -226,23 +295,34 @@ public ConditionElement(LogicalConjunction logicalConjunction) _reason = ""; } - public string Description => _customDescription ?? (_condition == null - ? "" - : (_logicalConjunction.Description + " should " + - _condition.GetShortDescription() + " " + _reason).Trim()); + 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."); + "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."); + "Can't add a reason to a ConditionElement which already has a reason." + ); } _reason = "because " + reason; @@ -258,15 +338,20 @@ public void SetCustomDescription(string description) _customDescription = description; } - public IEnumerable Check(IEnumerable objects, Architecture architecture) + public IEnumerable Check( + IEnumerable objects, + Architecture architecture + ) { if (_condition == null) { throw new InvalidOperationException( - "Can't check a ConditionElement before the condition is set."); + "Can't check a ConditionElement before the condition is set." + ); } - return _condition.Check(objects, architecture) + return _condition + .Check(objects, architecture) .Select(result => new ConditionElementResult(result, _logicalConjunction)); } @@ -275,7 +360,8 @@ public bool CheckEmpty(bool currentResult) if (_condition == null) { throw new InvalidOperationException( - "Can't check a ConditionElement before the condition is set."); + "Can't check a ConditionElement before the condition is set." + ); } return _logicalConjunction.Evaluate(currentResult, _condition.CheckEmpty()); @@ -298,43 +384,47 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((ConditionElement) obj); + 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; + 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); + 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) + public ConditionElementResult( + ConditionResult conditionResult, + LogicalConjunction logicalConjunction + ) { ConditionResult = conditionResult; LogicalConjunction = logicalConjunction; } } } - - -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Conditions/ArchitectureCondition.cs b/ArchUnitNET/Fluent/Conditions/ArchitectureCondition.cs index 88293edfc..4ad3f61b2 100644 --- a/ArchUnitNET/Fluent/Conditions/ArchitectureCondition.cs +++ b/ArchUnitNET/Fluent/Conditions/ArchitectureCondition.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -11,42 +11,70 @@ namespace ArchUnitNET.Fluent.Conditions { - public class ArchitectureCondition : ICondition where TRuleType : ICanBeAnalyzed + public class ArchitectureCondition : ICondition + where TRuleType : ICanBeAnalyzed { - private readonly Func, Architecture, IEnumerable> _condition; + private readonly Func< + IEnumerable, + Architecture, + IEnumerable + > _condition; - public ArchitectureCondition(Func condition, string description, - string failDescription) + public ArchitectureCondition( + Func condition, + string description, + string failDescription + ) { - _condition = (ruleTypes, architecture) => ruleTypes.Select(type => - new ConditionResult(type, condition(type, architecture), failDescription)); + _condition = (ruleTypes, architecture) => + ruleTypes.Select(type => new ConditionResult( + type, + condition(type, architecture), + failDescription + )); Description = description; } - public ArchitectureCondition(Func condition, string description) + public ArchitectureCondition( + Func condition, + string description + ) { - _condition = (ruleTypes, architecture) => ruleTypes.Select(type => condition(type, architecture)); + _condition = (ruleTypes, architecture) => + ruleTypes.Select(type => condition(type, architecture)); Description = description; } - public ArchitectureCondition(Func, Architecture, IEnumerable> condition, - string description) + public ArchitectureCondition( + Func, Architecture, IEnumerable> condition, + string description + ) { _condition = condition; Description = description; } - public ArchitectureCondition(Func condition, - Func dynamicFailDescription, string description) + public ArchitectureCondition( + Func condition, + Func dynamicFailDescription, + string description + ) { - _condition = (ruleTypes, architecture) => ruleTypes.Select(type => - new ConditionResult(type, condition(type, architecture), dynamicFailDescription(type, architecture))); + _condition = (ruleTypes, architecture) => + ruleTypes.Select(type => new ConditionResult( + type, + condition(type, architecture), + dynamicFailDescription(type, architecture) + )); Description = description; } public string Description { get; } - public IEnumerable Check(IEnumerable objects, Architecture architecture) + public IEnumerable Check( + IEnumerable objects, + Architecture architecture + ) { return _condition(objects, architecture); } @@ -78,7 +106,7 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((ArchitectureCondition) obj); + return obj.GetType() == GetType() && Equals((ArchitectureCondition)obj); } public override int GetHashCode() @@ -86,4 +114,4 @@ public override int GetHashCode() return Description != null ? Description.GetHashCode() : 0; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Conditions/ComplexCondition.cs b/ArchUnitNET/Fluent/Conditions/ComplexCondition.cs index 40bd59101..75c997bea 100644 --- a/ArchUnitNET/Fluent/Conditions/ComplexCondition.cs +++ b/ArchUnitNET/Fluent/Conditions/ComplexCondition.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -11,15 +11,18 @@ namespace ArchUnitNET.Fluent.Conditions { public class ComplexCondition : ICondition - where TRuleType : ICanBeAnalyzed where TRelatedType : ICanBeAnalyzed + where TRuleType : ICanBeAnalyzed + where TRelatedType : ICanBeAnalyzed { private readonly IPredicate _predicate; private readonly IObjectProvider _relatedTypes; private readonly RelationCondition _relation; - public ComplexCondition(IObjectProvider relatedTypes, + public ComplexCondition( + IObjectProvider relatedTypes, RelationCondition relation, - IPredicate predicate) + IPredicate predicate + ) { _relatedTypes = relatedTypes; _relation = relation; @@ -28,10 +31,18 @@ public ComplexCondition(IObjectProvider relatedTypes, public string Description => _relation.Description + " " + _predicate.Description; - public IEnumerable Check(IEnumerable objects, Architecture architecture) + public IEnumerable Check( + IEnumerable objects, + Architecture architecture + ) { return _relation - .GetCondition(_predicate.GetMatchingObjects(_relatedTypes.GetObjects(architecture), architecture)) + .GetCondition( + _predicate.GetMatchingObjects( + _relatedTypes.GetObjects(architecture), + architecture + ) + ) .Check(objects, architecture); } @@ -62,16 +73,17 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((ComplexCondition) obj); + return obj.GetType() == GetType() + && Equals((ComplexCondition)obj); } public override int GetHashCode() { unchecked { - return ((_predicate != null ? _predicate.GetHashCode() : 0) * 397) ^ - (_relation != null ? _relation.GetHashCode() : 0); + return ((_predicate != null ? _predicate.GetHashCode() : 0) * 397) + ^ (_relation != null ? _relation.GetHashCode() : 0); } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Conditions/ConditionResult.cs b/ArchUnitNET/Fluent/Conditions/ConditionResult.cs index a8220f88e..ec701044e 100644 --- a/ArchUnitNET/Fluent/Conditions/ConditionResult.cs +++ b/ArchUnitNET/Fluent/Conditions/ConditionResult.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -12,14 +12,20 @@ namespace ArchUnitNET.Fluent.Conditions public class ConditionResult { public readonly ICanBeAnalyzed AnalyzedObject; - [CanBeNull] public readonly string FailDescription; + + [CanBeNull] + public readonly string FailDescription; public readonly bool Pass; - public ConditionResult(ICanBeAnalyzed analyzedObject, bool pass, string failDescription = null) + public ConditionResult( + ICanBeAnalyzed analyzedObject, + bool pass, + string failDescription = null + ) { Pass = pass; AnalyzedObject = analyzedObject; FailDescription = pass ? null : failDescription; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Conditions/EnumerableCondition.cs b/ArchUnitNET/Fluent/Conditions/EnumerableCondition.cs index 59b30b23e..a913ca812 100644 --- a/ArchUnitNET/Fluent/Conditions/EnumerableCondition.cs +++ b/ArchUnitNET/Fluent/Conditions/EnumerableCondition.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -10,12 +10,15 @@ namespace ArchUnitNET.Fluent.Conditions { - public class EnumerableCondition : ICondition where TRuleType : ICanBeAnalyzed + public class EnumerableCondition : ICondition + where TRuleType : ICanBeAnalyzed { private readonly Func, IEnumerable> _condition; - public EnumerableCondition(Func, IEnumerable> condition, - string description) + public EnumerableCondition( + Func, IEnumerable> condition, + string description + ) { _condition = condition; Description = description; @@ -23,7 +26,10 @@ public EnumerableCondition(Func, IEnumerable Check(IEnumerable objects, Architecture architecture) + public IEnumerable Check( + IEnumerable objects, + Architecture architecture + ) { return _condition(objects); } @@ -33,4 +39,4 @@ public bool CheckEmpty() return true; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Conditions/ExistsCondition.cs b/ArchUnitNET/Fluent/Conditions/ExistsCondition.cs index 09fb157db..c26f81bdb 100644 --- a/ArchUnitNET/Fluent/Conditions/ExistsCondition.cs +++ b/ArchUnitNET/Fluent/Conditions/ExistsCondition.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -10,7 +10,8 @@ namespace ArchUnitNET.Fluent.Conditions { - public class ExistsCondition : ICondition where TRuleType : ICanBeAnalyzed + public class ExistsCondition : ICondition + where TRuleType : ICanBeAnalyzed { private readonly bool _valueIfExists; @@ -21,7 +22,10 @@ public ExistsCondition(bool valueIfExists) public string Description => _valueIfExists ? "exist" : "not exist"; - public IEnumerable Check(IEnumerable objects, Architecture architecture) + public IEnumerable Check( + IEnumerable objects, + Architecture architecture + ) { return objects.Select(obj => new ConditionResult(obj, _valueIfExists, "does exist")); } @@ -53,7 +57,7 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((ExistsCondition) obj); + return obj.GetType() == GetType() && Equals((ExistsCondition)obj); } public override int GetHashCode() @@ -61,4 +65,4 @@ public override int GetHashCode() return _valueIfExists.GetHashCode(); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Conditions/ICondition.cs b/ArchUnitNET/Fluent/Conditions/ICondition.cs index ae2b52b51..9aceb3612 100644 --- a/ArchUnitNET/Fluent/Conditions/ICondition.cs +++ b/ArchUnitNET/Fluent/Conditions/ICondition.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -9,9 +9,13 @@ namespace ArchUnitNET.Fluent.Conditions { - public interface ICondition : IHasDescription where TRuleType : ICanBeAnalyzed + public interface ICondition : IHasDescription + where TRuleType : ICanBeAnalyzed { - IEnumerable Check(IEnumerable objects, Architecture architecture); + IEnumerable Check( + IEnumerable objects, + Architecture architecture + ); bool CheckEmpty(); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Conditions/RelationCondition.cs b/ArchUnitNET/Fluent/Conditions/RelationCondition.cs index b406c8751..9c2dd424f 100644 --- a/ArchUnitNET/Fluent/Conditions/RelationCondition.cs +++ b/ArchUnitNET/Fluent/Conditions/RelationCondition.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -11,12 +11,16 @@ namespace ArchUnitNET.Fluent.Conditions { public class RelationCondition : IHasDescription - where TRuleType : ICanBeAnalyzed where TRelatedType : ICanBeAnalyzed + where TRuleType : ICanBeAnalyzed + where TRelatedType : ICanBeAnalyzed { private readonly Func, ICondition> _relation; - public RelationCondition(Func, ICondition> relation, - string description, string failDescription) + public RelationCondition( + Func, ICondition> relation, + string description, + string failDescription + ) { _relation = relation; Description = description; @@ -34,8 +38,7 @@ public ICondition GetCondition(IEnumerable objectProvid private bool Equals(RelationCondition other) { - return FailDescription == other.FailDescription && - Description == other.Description; + return FailDescription == other.FailDescription && Description == other.Description; } public override bool Equals(object obj) @@ -50,7 +53,8 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((RelationCondition) obj); + return obj.GetType() == GetType() + && Equals((RelationCondition)obj); } public override int GetHashCode() @@ -63,4 +67,4 @@ public override int GetHashCode() } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Conditions/SimpleCondition.cs b/ArchUnitNET/Fluent/Conditions/SimpleCondition.cs index 1024e9911..5564921fa 100644 --- a/ArchUnitNET/Fluent/Conditions/SimpleCondition.cs +++ b/ArchUnitNET/Fluent/Conditions/SimpleCondition.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -11,11 +11,16 @@ namespace ArchUnitNET.Fluent.Conditions { - public class SimpleCondition : ICondition where TRuleType : ICanBeAnalyzed + public class SimpleCondition : ICondition + where TRuleType : ICanBeAnalyzed { private readonly Func _condition; - public SimpleCondition(Func condition, string description, string failDescription) + public SimpleCondition( + Func condition, + string description, + string failDescription + ) { _condition = obj => new ConditionResult(obj, condition(obj), failDescription); Description = description; @@ -27,16 +32,26 @@ public SimpleCondition(Func condition, string descri Description = description; } - public SimpleCondition(Func condition, Func dynamicFailDescription, - string description) + public SimpleCondition( + Func condition, + Func dynamicFailDescription, + string description + ) { - _condition = obj => new ConditionResult(obj, condition(obj), dynamicFailDescription(obj)); + _condition = obj => new ConditionResult( + obj, + condition(obj), + dynamicFailDescription(obj) + ); Description = description; } public string Description { get; } - public IEnumerable Check(IEnumerable objects, Architecture architecture) + public IEnumerable Check( + IEnumerable objects, + Architecture architecture + ) { return objects.Select(obj => _condition(obj)); } @@ -68,7 +83,7 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((SimpleCondition) obj); + return obj.GetType() == GetType() && Equals((SimpleCondition)obj); } public override int GetHashCode() @@ -76,4 +91,4 @@ public override int GetHashCode() return Description != null ? Description.GetHashCode() : 0; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/CustomArchRule.cs b/ArchUnitNET/Fluent/CustomArchRule.cs index 296123424..e34fce978 100644 --- a/ArchUnitNET/Fluent/CustomArchRule.cs +++ b/ArchUnitNET/Fluent/CustomArchRule.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System; using System.Collections.Generic; @@ -16,10 +16,16 @@ public class CustomArchRule : IArchRule { public string Description { get; } - private readonly Func> _evaluationFunc; + private readonly Func< + Architecture, + IArchRule, + IEnumerable + > _evaluationFunc; - public CustomArchRule(Func> evaluationFunc, - string description) + public CustomArchRule( + Func> evaluationFunc, + string description + ) { _evaluationFunc = evaluationFunc; Description = description; @@ -55,4 +61,4 @@ public IArchRule Or(IArchRule archRule) return new CombinedArchRule(this, LogicalConjunctionDefinition.Or, archRule); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/EvaluationResult.cs b/ArchUnitNET/Fluent/EvaluationResult.cs index 59903595f..a1ae6dfdb 100644 --- a/ArchUnitNET/Fluent/EvaluationResult.cs +++ b/ArchUnitNET/Fluent/EvaluationResult.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -12,8 +12,14 @@ namespace ArchUnitNET.Fluent { public class EvaluationResult : IHasDescription { - public EvaluationResult(object obj, StringIdentifier evaluatedObjectIdentifier, bool passed, string description, - ICanBeEvaluated archRule, Architecture architecture) + public EvaluationResult( + object obj, + StringIdentifier evaluatedObjectIdentifier, + bool passed, + string description, + ICanBeEvaluated archRule, + Architecture architecture + ) { EvaluatedObject = obj; EvaluatedObjectIdentifier = evaluatedObjectIdentifier; @@ -24,8 +30,12 @@ public EvaluationResult(object obj, StringIdentifier evaluatedObjectIdentifier, } public ICanBeEvaluated ArchRule { get; } - [CanBeNull] public object EvaluatedObject { get; } - [NotNull] public StringIdentifier EvaluatedObjectIdentifier { get; } + + [CanBeNull] + public object EvaluatedObject { get; } + + [NotNull] + public StringIdentifier EvaluatedObjectIdentifier { get; } public bool Passed { get; } public Architecture Architecture { get; } public string Description { get; } @@ -37,12 +47,12 @@ public override string ToString() private bool Equals(EvaluationResult other) { - return string.Equals(Description, other.Description) && - Equals(EvaluatedObject, other.EvaluatedObject) && - Equals(EvaluatedObjectIdentifier, other.EvaluatedObjectIdentifier) && - Equals(Passed, other.Passed) && - Equals(ArchRule, other.ArchRule) && - Equals(Architecture, other.Architecture); + return string.Equals(Description, other.Description) + && Equals(EvaluatedObject, other.EvaluatedObject) + && Equals(EvaluatedObjectIdentifier, other.EvaluatedObjectIdentifier) + && Equals(Passed, other.Passed) + && Equals(ArchRule, other.ArchRule) + && Equals(Architecture, other.Architecture); } public override bool Equals(object obj) @@ -57,7 +67,7 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((EvaluationResult) obj); + return obj.GetType() == GetType() && Equals((EvaluationResult)obj); } public override int GetHashCode() @@ -65,13 +75,16 @@ public override int GetHashCode() unchecked { var hashCode = Description != null ? Description.GetHashCode() : 0; - hashCode = (hashCode * 397) ^ (EvaluatedObject != null ? EvaluatedObject.GetHashCode() : 0); + hashCode = + (hashCode * 397) + ^ (EvaluatedObject != null ? EvaluatedObject.GetHashCode() : 0); hashCode = (hashCode * 397) ^ EvaluatedObjectIdentifier.GetHashCode(); hashCode = (hashCode * 397) ^ Passed.GetHashCode(); hashCode = (hashCode * 397) ^ (ArchRule != null ? ArchRule.GetHashCode() : 0); - hashCode = (hashCode * 397) ^ (Architecture != null ? Architecture.GetHashCode() : 0); + hashCode = + (hashCode * 397) ^ (Architecture != null ? Architecture.GetHashCode() : 0); return hashCode; } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Exceptions/CannotGetObjectsOfCombinedArchRuleCreatorException.cs b/ArchUnitNET/Fluent/Exceptions/CannotGetObjectsOfCombinedArchRuleCreatorException.cs index 7ea403f46..6c2626b26 100644 --- a/ArchUnitNET/Fluent/Exceptions/CannotGetObjectsOfCombinedArchRuleCreatorException.cs +++ b/ArchUnitNET/Fluent/Exceptions/CannotGetObjectsOfCombinedArchRuleCreatorException.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -10,13 +10,10 @@ namespace ArchUnitNET.Fluent.Exceptions { public class CannotGetObjectsOfCombinedArchRuleCreatorException : Exception { - public CannotGetObjectsOfCombinedArchRuleCreatorException(string message) : base(message) - { - } + public CannotGetObjectsOfCombinedArchRuleCreatorException(string message) + : base(message) { } - public CannotGetObjectsOfCombinedArchRuleCreatorException(string message, Exception inner) : base(message, - inner) - { - } + public CannotGetObjectsOfCombinedArchRuleCreatorException(string message, Exception inner) + : base(message, inner) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Exceptions/CannotGetObjectsOfCombinedArchRuleException.cs b/ArchUnitNET/Fluent/Exceptions/CannotGetObjectsOfCombinedArchRuleException.cs index 2fddf80ca..c670c89a1 100644 --- a/ArchUnitNET/Fluent/Exceptions/CannotGetObjectsOfCombinedArchRuleException.cs +++ b/ArchUnitNET/Fluent/Exceptions/CannotGetObjectsOfCombinedArchRuleException.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -10,12 +10,10 @@ namespace ArchUnitNET.Fluent.Exceptions { public class CannotGetObjectsOfCombinedArchRuleException : Exception { - public CannotGetObjectsOfCombinedArchRuleException(string message) : base(message) - { - } + public CannotGetObjectsOfCombinedArchRuleException(string message) + : base(message) { } - public CannotGetObjectsOfCombinedArchRuleException(string message, Exception inner) : base(message, inner) - { - } + public CannotGetObjectsOfCombinedArchRuleException(string message, Exception inner) + : base(message, inner) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Extensions/EvaluationResultExtensions.cs b/ArchUnitNET/Fluent/Extensions/EvaluationResultExtensions.cs index 026a556b9..653741860 100644 --- a/ArchUnitNET/Fluent/Extensions/EvaluationResultExtensions.cs +++ b/ArchUnitNET/Fluent/Extensions/EvaluationResultExtensions.cs @@ -1,9 +1,9 @@ // 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; @@ -38,4 +38,4 @@ public static string ToErrorMessage(this IEnumerable evaluatio return errorMessage.ToString(); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Extensions/SyntaxElementExtensions.cs b/ArchUnitNET/Fluent/Extensions/SyntaxElementExtensions.cs index ca8078108..bb449a367 100644 --- a/ArchUnitNET/Fluent/Extensions/SyntaxElementExtensions.cs +++ b/ArchUnitNET/Fluent/Extensions/SyntaxElementExtensions.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -17,4 +17,4 @@ public static string GetShortDescription(this IHasDescription obj, int maxLength : obj.Description; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Freeze/FreezingArchRule.cs b/ArchUnitNET/Fluent/Freeze/FreezingArchRule.cs index 01fad4ca0..18a99b6c4 100644 --- a/ArchUnitNET/Fluent/Freeze/FreezingArchRule.cs +++ b/ArchUnitNET/Fluent/Freeze/FreezingArchRule.cs @@ -1,9 +1,9 @@ // 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; @@ -33,7 +33,8 @@ public IEnumerable Evaluate(Architecture architecture) { var evalResults = _frozenRule.Evaluate(architecture).ToList(); var evalResultsIgnoringFrozen = new List(); - var identifiersOfFailedResults = evalResults.Where(result => !result.Passed) + var identifiersOfFailedResults = evalResults + .Where(result => !result.Passed) .Select(result => result.EvaluatedObjectIdentifier); if (!_violationStore.RuleAlreadyFrozen(_frozenRule)) @@ -47,8 +48,12 @@ public IEnumerable Evaluate(Architecture architecture) var stillUnresolvedViolations = new List(); foreach (var evalResult in evalResults) { - if (frozenViolations.Contains(evalResult.EvaluatedObjectIdentifier, - new StringIdentifierComparer()) && !evalResult.Passed) + if ( + frozenViolations.Contains( + evalResult.EvaluatedObjectIdentifier, + new StringIdentifierComparer() + ) && !evalResult.Passed + ) { evalResultsIgnoringFrozen.Add(MarkAsPassed(evalResult)); stillUnresolvedViolations.Add(evalResult.EvaluatedObjectIdentifier); @@ -102,9 +107,14 @@ public static FreezingArchRule Freeze(IArchRule rule) private static EvaluationResult MarkAsPassed(EvaluationResult evaluationResult) { - return new EvaluationResult(evaluationResult.EvaluatedObject, evaluationResult.EvaluatedObjectIdentifier, + return new EvaluationResult( + evaluationResult.EvaluatedObject, + evaluationResult.EvaluatedObjectIdentifier, true, - evaluationResult.Description, evaluationResult.ArchRule, evaluationResult.Architecture); + evaluationResult.Description, + evaluationResult.ArchRule, + evaluationResult.Architecture + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Freeze/FrozenRule.cs b/ArchUnitNET/Fluent/Freeze/FrozenRule.cs index c1d1fdfbd..9565d0444 100644 --- a/ArchUnitNET/Fluent/Freeze/FrozenRule.cs +++ b/ArchUnitNET/Fluent/Freeze/FrozenRule.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Collections.Generic; @@ -20,4 +20,4 @@ public FrozenRule(string archRuleDescription, List violations) Violations = violations; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Freeze/IViolationStore.cs b/ArchUnitNET/Fluent/Freeze/IViolationStore.cs index 8cbe22650..e27dd67c2 100644 --- a/ArchUnitNET/Fluent/Freeze/IViolationStore.cs +++ b/ArchUnitNET/Fluent/Freeze/IViolationStore.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Collections.Generic; using ArchUnitNET.Domain; @@ -16,4 +16,4 @@ public interface IViolationStore IEnumerable GetFrozenViolations(IArchRule rule); void StoreCurrentViolations(IArchRule rule, IEnumerable violations); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Freeze/JsonViolationStore.cs b/ArchUnitNET/Fluent/Freeze/JsonViolationStore.cs index 3657b5880..16e93a110 100644 --- a/ArchUnitNET/Fluent/Freeze/JsonViolationStore.cs +++ b/ArchUnitNET/Fluent/Freeze/JsonViolationStore.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System; using System.Collections.Generic; @@ -34,7 +34,9 @@ public bool RuleAlreadyFrozen(IArchRule rule) public IEnumerable GetFrozenViolations(IArchRule rule) { var storedRules = LoadStorage(); - var matchingRules = storedRules.Where(r => r.ArchRuleDescription == rule.Description).ToList(); + var matchingRules = storedRules + .Where(r => r.ArchRuleDescription == rule.Description) + .ToList(); if (!matchingRules.Any()) { return Enumerable.Empty(); @@ -42,15 +44,21 @@ public IEnumerable GetFrozenViolations(IArchRule rule) if (matchingRules.Count > 1) { - throw new MultipleOccurrencesInSequenceException("Multiple stored rules with same description found."); + throw new MultipleOccurrencesInSequenceException( + "Multiple stored rules with same description found." + ); } - return matchingRules.First().Violations.Select(violation => new StringIdentifier(violation)); + return matchingRules + .First() + .Violations.Select(violation => new StringIdentifier(violation)); } public void StoreCurrentViolations(IArchRule rule, IEnumerable violations) { - var violationIdentifiers = violations.Select(violation => violation.Identifier).ToList(); + var violationIdentifiers = violations + .Select(violation => violation.Identifier) + .ToList(); var directory = Path.GetDirectoryName(_storagePath); if (directory == null) @@ -64,16 +72,20 @@ public void StoreCurrentViolations(IArchRule rule, IEnumerable } var storedRules = LoadStorage(); - var matchingRulesAmount = storedRules.Count(r => r.ArchRuleDescription == rule.Description); + var matchingRulesAmount = storedRules.Count(r => + r.ArchRuleDescription == rule.Description + ); if (matchingRulesAmount > 1) { throw new MultipleOccurrencesInSequenceException( - "Multiple Rules with the same description were found in the given Json."); + "Multiple Rules with the same description were found in the given Json." + ); } if (matchingRulesAmount == 1) { - storedRules.First(r => r.ArchRuleDescription == rule.Description).Violations = violationIdentifiers; + storedRules.First(r => r.ArchRuleDescription == rule.Description).Violations = + violationIdentifiers; } else { @@ -109,4 +121,4 @@ private List LoadStorage() } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Freeze/XmlViolationStore.cs b/ArchUnitNET/Fluent/Freeze/XmlViolationStore.cs index 12e359db9..7dc3c2197 100644 --- a/ArchUnitNET/Fluent/Freeze/XmlViolationStore.cs +++ b/ArchUnitNET/Fluent/Freeze/XmlViolationStore.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System; using System.Collections.Generic; @@ -23,7 +23,10 @@ public class XmlViolationStore : IViolationStore private readonly string _storagePath; private static readonly XmlWriterSettings WriterSettings = new XmlWriterSettings - { Indent = true, Encoding = Encoding.UTF8 }; + { + Indent = true, + Encoding = Encoding.UTF8 + }; public XmlViolationStore(string storagePath = DefaultStoragePath) { @@ -67,9 +70,10 @@ public void StoreCurrentViolations(IArchRule rule, IEnumerable Directory.CreateDirectory(directory); } - var violationElements = - violations.Select(violation => - new XElement("Violation", violation.Identifier)); + var violationElements = violations.Select(violation => new XElement( + "Violation", + violation.Identifier + )); var ruleElement = new XElement("FrozenRule", violationElements); ruleElement.SetAttributeValue("ArchRule", rule.Description); @@ -87,8 +91,11 @@ public void StoreCurrentViolations(IArchRule rule, IEnumerable [CanBeNull] private static XElement FindStoredRule(XDocument xDocument, IArchRule rule) { - return xDocument.Root?.Elements().FirstOrDefault(element => - element.Attribute("ArchRule")?.Value.ToString() == rule.Description); + return xDocument + .Root?.Elements() + .FirstOrDefault(element => + element.Attribute("ArchRule")?.Value.ToString() == rule.Description + ); } private XDocument LoadStorage() @@ -96,7 +103,9 @@ private XDocument LoadStorage() try { var doc = XDocument.Load(_storagePath); - return doc.Root?.Name == "FrozenRules" ? doc : new XDocument(new XElement("FrozenRules")); + return doc.Root?.Name == "FrozenRules" + ? doc + : new XDocument(new XElement("FrozenRules")); } catch (Exception) //file not found or invalid xml document { @@ -104,4 +113,4 @@ private XDocument LoadStorage() } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/IArchRule.cs b/ArchUnitNET/Fluent/IArchRule.cs index ca5995e68..27dde4ad9 100644 --- a/ArchUnitNET/Fluent/IArchRule.cs +++ b/ArchUnitNET/Fluent/IArchRule.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 namespace ArchUnitNET.Fluent @@ -13,4 +13,4 @@ public interface IArchRule : ICanBeEvaluated IArchRule And(IArchRule archRule); IArchRule Or(IArchRule archRule); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/IArchRuleCreator.cs b/ArchUnitNET/Fluent/IArchRuleCreator.cs index a191dc38d..05ba91a5d 100644 --- a/ArchUnitNET/Fluent/IArchRuleCreator.cs +++ b/ArchUnitNET/Fluent/IArchRuleCreator.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -11,7 +11,8 @@ namespace ArchUnitNET.Fluent { - public interface IArchRuleCreator : ICanBeEvaluated where TRuleType : ICanBeAnalyzed + public interface IArchRuleCreator : ICanBeEvaluated + where TRuleType : ICanBeAnalyzed { void AddPredicate(IPredicate predicate); void AddPredicateConjunction(LogicalConjunction logicalConjunction); @@ -20,8 +21,10 @@ public interface IArchRuleCreator : ICanBeEvaluated where TRuleType : void AddConditionReason(string reason); void AddPredicateReason(string reason); - void BeginComplexCondition(IObjectProvider relatedObjects, - RelationCondition relationCondition) + void BeginComplexCondition( + IObjectProvider relatedObjects, + RelationCondition relationCondition + ) where TRelatedType : ICanBeAnalyzed; void ContinueComplexCondition(IPredicate predicate) @@ -34,4 +37,4 @@ void ContinueComplexCondition(IPredicate predicate) bool RequirePositiveResults { get; set; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/ICanBeEvaluated.cs b/ArchUnitNET/Fluent/ICanBeEvaluated.cs index 42cdfbff1..ab3dad389 100644 --- a/ArchUnitNET/Fluent/ICanBeEvaluated.cs +++ b/ArchUnitNET/Fluent/ICanBeEvaluated.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -14,4 +14,4 @@ public interface ICanBeEvaluated : IHasDescription bool HasNoViolations(Architecture architecture); IEnumerable Evaluate(Architecture architecture); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/LogicalConjunction.cs b/ArchUnitNET/Fluent/LogicalConjunction.cs index 1d84123c6..8b73955a7 100644 --- a/ArchUnitNET/Fluent/LogicalConjunction.cs +++ b/ArchUnitNET/Fluent/LogicalConjunction.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -27,7 +27,10 @@ public bool Evaluate(bool value1, bool value2) return _logicalConjunction(value1, value2); } - public abstract IEnumerable Evaluate(IEnumerable enumerable1, IEnumerable enumerable2); + public abstract IEnumerable Evaluate( + IEnumerable enumerable1, + IEnumerable enumerable2 + ); public override string ToString() { @@ -51,7 +54,7 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((LogicalConjunction) obj); + return obj.GetType() == GetType() && Equals((LogicalConjunction)obj); } public override int GetHashCode() @@ -59,4 +62,4 @@ public override int GetHashCode() return Description != null ? Description.GetHashCode() : 0; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/LogicalConjunctionDefinition.cs b/ArchUnitNET/Fluent/LogicalConjunctionDefinition.cs index a1c5642a1..747590a9e 100644 --- a/ArchUnitNET/Fluent/LogicalConjunctionDefinition.cs +++ b/ArchUnitNET/Fluent/LogicalConjunctionDefinition.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -15,15 +15,18 @@ public static class LogicalConjunctionDefinition public static readonly LogicalConjunction Or = new OrConjunction(); - public static readonly LogicalConjunction ForwardSecondValue = new ForwardSecondValueConjunction(); + public static readonly LogicalConjunction ForwardSecondValue = + new ForwardSecondValueConjunction(); private class AndConjunction : LogicalConjunction { - public AndConjunction() : base((b1, b2) => b1 && b2, "and") - { - } + public AndConjunction() + : base((b1, b2) => b1 && b2, "and") { } - public override IEnumerable Evaluate(IEnumerable enumerable1, IEnumerable enumerable2) + public override IEnumerable Evaluate( + IEnumerable enumerable1, + IEnumerable enumerable2 + ) { return enumerable1.Intersect(enumerable2); } @@ -31,11 +34,13 @@ public override IEnumerable Evaluate(IEnumerable enumerable1, IEnumerab private class OrConjunction : LogicalConjunction { - public OrConjunction() : base((b1, b2) => b1 || b2, "or") - { - } + public OrConjunction() + : base((b1, b2) => b1 || b2, "or") { } - public override IEnumerable Evaluate(IEnumerable enumerable1, IEnumerable enumerable2) + public override IEnumerable Evaluate( + IEnumerable enumerable1, + IEnumerable enumerable2 + ) { return enumerable1.Union(enumerable2); } @@ -43,14 +48,16 @@ public override IEnumerable Evaluate(IEnumerable enumerable1, IEnumerab private class ForwardSecondValueConjunction : LogicalConjunction { - public ForwardSecondValueConjunction() : base((b1, b2) => b2, "") - { - } + public ForwardSecondValueConjunction() + : base((b1, b2) => b2, "") { } - public override IEnumerable Evaluate(IEnumerable enumerable1, IEnumerable enumerable2) + public override IEnumerable Evaluate( + IEnumerable enumerable1, + IEnumerable enumerable2 + ) { return enumerable2; } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/PlantUml/GivenPlantUmlFluentComponentDiagram.cs b/ArchUnitNET/Fluent/PlantUml/GivenPlantUmlFluentComponentDiagram.cs index ed8326667..cea616d43 100644 --- a/ArchUnitNET/Fluent/PlantUml/GivenPlantUmlFluentComponentDiagram.cs +++ b/ArchUnitNET/Fluent/PlantUml/GivenPlantUmlFluentComponentDiagram.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using ArchUnitNET.Domain.PlantUml.Export; @@ -14,7 +14,8 @@ public class GivenPlantUmlFluentComponentDiagram private readonly PlantUmlFluentComponentDiagramCreator _fluentComponentDiagramCreator; internal GivenPlantUmlFluentComponentDiagram( - PlantUmlFluentComponentDiagramCreator fluentComponentDiagramCreator) + PlantUmlFluentComponentDiagramCreator fluentComponentDiagramCreator + ) { _fluentComponentDiagramCreator = fluentComponentDiagramCreator; } @@ -29,4 +30,4 @@ public void WriteToFile(string path, RenderOptions renderOptions = null) _fluentComponentDiagramCreator.Builder.WriteToFile(path, renderOptions); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/PlantUml/PlantUmlDefinition.cs b/ArchUnitNET/Fluent/PlantUml/PlantUmlDefinition.cs index cfc69e50f..c53d002d2 100644 --- a/ArchUnitNET/Fluent/PlantUml/PlantUmlDefinition.cs +++ b/ArchUnitNET/Fluent/PlantUml/PlantUmlDefinition.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// namespace ArchUnitNET.Fluent.PlantUml { @@ -15,4 +15,4 @@ public static PlantUmlFluentComponentDiagramInitializer ComponentDiagram() return new PlantUmlFluentComponentDiagramInitializer(fluentCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/PlantUml/PlantUmlFluentComponentDiagramCreator.cs b/ArchUnitNET/Fluent/PlantUml/PlantUmlFluentComponentDiagramCreator.cs index f5d5d6869..aec30a55c 100644 --- a/ArchUnitNET/Fluent/PlantUml/PlantUmlFluentComponentDiagramCreator.cs +++ b/ArchUnitNET/Fluent/PlantUml/PlantUmlFluentComponentDiagramCreator.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using ArchUnitNET.Domain; using ArchUnitNET.Domain.PlantUml.Export; @@ -27,4 +27,4 @@ public void AddToDescription(string description) public string Description { get; private set; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/PlantUml/PlantUmlFluentComponentDiagramInitializer.cs b/ArchUnitNET/Fluent/PlantUml/PlantUmlFluentComponentDiagramInitializer.cs index 535022424..9013f27de 100644 --- a/ArchUnitNET/Fluent/PlantUml/PlantUmlFluentComponentDiagramInitializer.cs +++ b/ArchUnitNET/Fluent/PlantUml/PlantUmlFluentComponentDiagramInitializer.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Collections.Generic; using ArchUnitNET.Domain; @@ -16,12 +16,15 @@ public class PlantUmlFluentComponentDiagramInitializer private readonly PlantUmlFluentComponentDiagramCreator _fluentComponentDiagramCreator; internal PlantUmlFluentComponentDiagramInitializer( - PlantUmlFluentComponentDiagramCreator fluentComponentDiagramCreator) + PlantUmlFluentComponentDiagramCreator fluentComponentDiagramCreator + ) { _fluentComponentDiagramCreator = fluentComponentDiagramCreator; } - public GivenPlantUmlFluentComponentDiagram WithElements(IEnumerable elements) + public GivenPlantUmlFluentComponentDiagram WithElements( + IEnumerable elements + ) { _fluentComponentDiagramCreator.Builder.WithElements(elements); _fluentComponentDiagramCreator.AddToDescription("with custom elements"); @@ -35,43 +38,63 @@ public GivenPlantUmlFluentComponentDiagram WithElements(params IPlantUmlElement[ return new GivenPlantUmlFluentComponentDiagram(_fluentComponentDiagramCreator); } - public GivenPlantUmlFluentComponentDiagram WithDependenciesFromTypes(IEnumerable types, - GenerationOptions generationOptions = null) + public GivenPlantUmlFluentComponentDiagram WithDependenciesFromTypes( + IEnumerable types, + GenerationOptions generationOptions = null + ) { _fluentComponentDiagramCreator.Builder.WithDependenciesFrom(types, generationOptions); _fluentComponentDiagramCreator.AddToDescription("with dependencies from types"); return new GivenPlantUmlFluentComponentDiagram(_fluentComponentDiagramCreator); } - public GivenPlantUmlFluentComponentDiagram WithDependenciesFromTypes(IObjectProvider types, - Architecture architecture, GenerationOptions generationOptions = null) + public GivenPlantUmlFluentComponentDiagram WithDependenciesFromTypes( + IObjectProvider types, + Architecture architecture, + GenerationOptions generationOptions = null + ) { - _fluentComponentDiagramCreator.Builder.WithDependenciesFrom(types.GetObjects(architecture), - generationOptions); + _fluentComponentDiagramCreator.Builder.WithDependenciesFrom( + types.GetObjects(architecture), + generationOptions + ); _fluentComponentDiagramCreator.AddToDescription("with dependencies from types"); return new GivenPlantUmlFluentComponentDiagram(_fluentComponentDiagramCreator); } - public GivenPlantUmlFluentComponentDiagram WithDependenciesFromSlices(IEnumerable slices, GenerationOptions generationOptions = null) + public GivenPlantUmlFluentComponentDiagram WithDependenciesFromSlices( + IEnumerable slices, + GenerationOptions generationOptions = null + ) { _fluentComponentDiagramCreator.Builder.WithDependenciesFrom(slices, generationOptions); _fluentComponentDiagramCreator.AddToDescription("with dependencies from slices"); return new GivenPlantUmlFluentComponentDiagram(_fluentComponentDiagramCreator); } - - public GivenPlantUmlFluentComponentDiagram WithDependenciesFromSlices(IEnumerable slices, string focusOnPackage) + + public GivenPlantUmlFluentComponentDiagram WithDependenciesFromSlices( + IEnumerable slices, + string focusOnPackage + ) { - _fluentComponentDiagramCreator.Builder.WithDependenciesFromFocusOn(slices, focusOnPackage); + _fluentComponentDiagramCreator.Builder.WithDependenciesFromFocusOn( + slices, + focusOnPackage + ); _fluentComponentDiagramCreator.AddToDescription("with dependencies from slices"); return new GivenPlantUmlFluentComponentDiagram(_fluentComponentDiagramCreator); } - - public GivenPlantUmlFluentComponentDiagram WithDependenciesFromSlices(IObjectProvider slices, - Architecture architecture) + + public GivenPlantUmlFluentComponentDiagram WithDependenciesFromSlices( + IObjectProvider slices, + Architecture architecture + ) { - _fluentComponentDiagramCreator.Builder.WithDependenciesFrom(slices.GetObjects(architecture)); + _fluentComponentDiagramCreator.Builder.WithDependenciesFrom( + slices.GetObjects(architecture) + ); _fluentComponentDiagramCreator.AddToDescription("with dependencies from slices"); return new GivenPlantUmlFluentComponentDiagram(_fluentComponentDiagramCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/PredicateManager.PredicateManager.cs b/ArchUnitNET/Fluent/PredicateManager.PredicateManager.cs index e4607fed3..310d00870 100644 --- a/ArchUnitNET/Fluent/PredicateManager.PredicateManager.cs +++ b/ArchUnitNET/Fluent/PredicateManager.PredicateManager.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -14,7 +14,8 @@ namespace ArchUnitNET.Fluent { - internal class PredicateManager : IHasDescription where T : ICanBeAnalyzed + internal class PredicateManager : IHasDescription + where T : ICanBeAnalyzed { private const string NotSet = "not set"; private readonly BasicObjectProvider _basicObjectProvider; @@ -26,26 +27,40 @@ public PredicateManager(BasicObjectProvider basicObjectProvider) _basicObjectProvider = basicObjectProvider; _predicateElements = new List> { - new PredicateElement(LogicalConjunctionDefinition.ForwardSecondValue, - new SimplePredicate(t => true, NotSet)) + 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 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)); + return _predicateElements.Aggregate( + filteredObjects, + (current, predicateElement) => + predicateElement.CheckPredicate(current, objects, architecture) + ); } public void AddPredicate(IPredicate predicate) @@ -61,7 +76,9 @@ public void AddReason(string reason) public void SetCustomDescription(string description) { _hasCustomDescription = true; - _predicateElements.ForEach(predicateElement => predicateElement.SetCustomDescription("")); + _predicateElements.ForEach(predicateElement => + predicateElement.SetCustomDescription("") + ); _predicateElements.Last().SetCustomDescription(description); } @@ -87,29 +104,34 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((PredicateManager) obj); + return obj.GetType() == GetType() && Equals((PredicateManager)obj); } private bool Equals(PredicateManager other) { - return Equals(_basicObjectProvider, other._basicObjectProvider) && - _predicateElements.SequenceEqual(other._predicateElements) && - _hasCustomDescription == other._hasCustomDescription; + 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, + var hashCode = + _basicObjectProvider != null ? _basicObjectProvider.GetHashCode() : 0; + return _predicateElements.Aggregate( + hashCode, (current, predicateElement) => - (current * 397) ^ (predicateElement != null ? predicateElement.GetHashCode() : 0)); + (current * 397) + ^ (predicateElement != null ? predicateElement.GetHashCode() : 0) + ); } } #pragma warning disable 693 - private class PredicateElement : IHasDescription where T : ICanBeAnalyzed + private class PredicateElement : IHasDescription + where T : ICanBeAnalyzed { private readonly LogicalConjunction _logicalConjunction; @@ -119,30 +141,44 @@ private class PredicateElement : IHasDescription where T : ICanBeAnalyzed private IPredicate _predicate; private string _reason; - public PredicateElement(LogicalConjunction logicalConjunction, IPredicate predicate = null) + 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 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."); + "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."); + "Can't add a reason to a PredicateElement which already has a reason." + ); } _reason = "because " + reason; @@ -158,17 +194,23 @@ public void SetPredicate(IPredicate predicate) _predicate = predicate; } - public IEnumerable CheckPredicate(IEnumerable currentObjects, IEnumerable allObjects, - Architecture architecture) + 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."); + "Can't check a PredicateElement before the predicate is set." + ); } - return _logicalConjunction.Evaluate(currentObjects, - _predicate.GetMatchingObjects(allObjects, architecture)); + return _logicalConjunction.Evaluate( + currentObjects, + _predicate.GetMatchingObjects(allObjects, architecture) + ); } public override string ToString() @@ -178,10 +220,10 @@ public override string ToString() private bool Equals(PredicateElement other) { - return Equals(_logicalConjunction, other._logicalConjunction) && - _customDescription == other._customDescription && - Equals(_predicate, other._predicate) && - _reason == other._reason; + return Equals(_logicalConjunction, other._logicalConjunction) + && _customDescription == other._customDescription + && Equals(_predicate, other._predicate) + && _reason == other._reason; } public override bool Equals(object obj) @@ -196,21 +238,24 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((PredicateElement) obj); + 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); + 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/Predicates/ArchitecturePredicate.cs b/ArchUnitNET/Fluent/Predicates/ArchitecturePredicate.cs index dc49851ed..8a7621fd1 100644 --- a/ArchUnitNET/Fluent/Predicates/ArchitecturePredicate.cs +++ b/ArchUnitNET/Fluent/Predicates/ArchitecturePredicate.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -11,18 +11,29 @@ namespace ArchUnitNET.Fluent.Predicates { - public class ArchitecturePredicate : IPredicate where TRuleType : ICanBeAnalyzed + public class ArchitecturePredicate : IPredicate + where TRuleType : ICanBeAnalyzed { - private readonly Func, Architecture, IEnumerable> _predicate; + private readonly Func< + IEnumerable, + Architecture, + IEnumerable + > _predicate; - public ArchitecturePredicate(Func predicate, string description) + public ArchitecturePredicate( + Func predicate, + string description + ) { - _predicate = (ruleTypes, architecture) => ruleTypes.Where(obj => predicate(obj, architecture)); + _predicate = (ruleTypes, architecture) => + ruleTypes.Where(obj => predicate(obj, architecture)); Description = description; } - public ArchitecturePredicate(Func, Architecture, IEnumerable> predicate, - string description) + public ArchitecturePredicate( + Func, Architecture, IEnumerable> predicate, + string description + ) { _predicate = predicate; Description = description; @@ -30,7 +41,10 @@ public ArchitecturePredicate(Func, Architecture, IEnumera public string Description { get; } - public IEnumerable GetMatchingObjects(IEnumerable objects, Architecture architecture) + public IEnumerable GetMatchingObjects( + IEnumerable objects, + Architecture architecture + ) { return _predicate(objects, architecture); } @@ -57,7 +71,7 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((ArchitecturePredicate) obj); + return obj.GetType() == GetType() && Equals((ArchitecturePredicate)obj); } public override int GetHashCode() @@ -65,4 +79,4 @@ public override int GetHashCode() return Description != null ? Description.GetHashCode() : 0; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Predicates/EnumerablePredicate.cs b/ArchUnitNET/Fluent/Predicates/EnumerablePredicate.cs index aa42c120a..98a007b93 100644 --- a/ArchUnitNET/Fluent/Predicates/EnumerablePredicate.cs +++ b/ArchUnitNET/Fluent/Predicates/EnumerablePredicate.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -10,12 +10,15 @@ namespace ArchUnitNET.Fluent.Predicates { - public class EnumerablePredicate : IPredicate where TRuleType : ICanBeAnalyzed + public class EnumerablePredicate : IPredicate + where TRuleType : ICanBeAnalyzed { private readonly Func, IEnumerable> _predicate; - public EnumerablePredicate(Func, IEnumerable> predicate, - string description) + public EnumerablePredicate( + Func, IEnumerable> predicate, + string description + ) { _predicate = predicate; Description = description; @@ -23,7 +26,10 @@ public EnumerablePredicate(Func, IEnumerable> public string Description { get; } - public IEnumerable GetMatchingObjects(IEnumerable objects, Architecture architecture) + public IEnumerable GetMatchingObjects( + IEnumerable objects, + Architecture architecture + ) { return _predicate(objects); } @@ -50,7 +56,7 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((EnumerablePredicate) obj); + return obj.GetType() == GetType() && Equals((EnumerablePredicate)obj); } public override int GetHashCode() @@ -58,4 +64,4 @@ public override int GetHashCode() return Description != null ? Description.GetHashCode() : 0; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Predicates/IPredicate.cs b/ArchUnitNET/Fluent/Predicates/IPredicate.cs index e2d7b9831..d98d40fb6 100644 --- a/ArchUnitNET/Fluent/Predicates/IPredicate.cs +++ b/ArchUnitNET/Fluent/Predicates/IPredicate.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -9,8 +9,12 @@ namespace ArchUnitNET.Fluent.Predicates { - public interface IPredicate : IHasDescription where TRuleType : ICanBeAnalyzed + public interface IPredicate : IHasDescription + where TRuleType : ICanBeAnalyzed { - IEnumerable GetMatchingObjects(IEnumerable objects, Architecture architecture); + IEnumerable GetMatchingObjects( + IEnumerable objects, + Architecture architecture + ); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Predicates/SimplePredicate.cs b/ArchUnitNET/Fluent/Predicates/SimplePredicate.cs index bf05c2407..bb22aa4f8 100644 --- a/ArchUnitNET/Fluent/Predicates/SimplePredicate.cs +++ b/ArchUnitNET/Fluent/Predicates/SimplePredicate.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -11,7 +11,8 @@ namespace ArchUnitNET.Fluent.Predicates { - public class SimplePredicate : IPredicate where TRuleType : ICanBeAnalyzed + public class SimplePredicate : IPredicate + where TRuleType : ICanBeAnalyzed { private readonly Func _predicate; @@ -23,7 +24,10 @@ public SimplePredicate(Func predicate, string description) public string Description { get; } - public IEnumerable GetMatchingObjects(IEnumerable objects, Architecture architecture) + public IEnumerable GetMatchingObjects( + IEnumerable objects, + Architecture architecture + ) { return objects.Where(_predicate); } @@ -50,7 +54,7 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((SimplePredicate) obj); + return obj.GetType() == GetType() && Equals((SimplePredicate)obj); } public override int GetHashCode() @@ -58,4 +62,4 @@ public override int GetHashCode() return Description != null ? Description.GetHashCode() : 0; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Slices/GivenSlices.cs b/ArchUnitNET/Fluent/Slices/GivenSlices.cs index 7abb09203..8d1f5da09 100644 --- a/ArchUnitNET/Fluent/Slices/GivenSlices.cs +++ b/ArchUnitNET/Fluent/Slices/GivenSlices.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Collections.Generic; using ArchUnitNET.Domain; @@ -32,4 +32,4 @@ public IEnumerable GetObjects(Architecture architecture) return _ruleCreator.GetSlices(architecture); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Slices/SliceAssignment.cs b/ArchUnitNET/Fluent/Slices/SliceAssignment.cs index 9a8956c05..e1f746f16 100644 --- a/ArchUnitNET/Fluent/Slices/SliceAssignment.cs +++ b/ArchUnitNET/Fluent/Slices/SliceAssignment.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System; using System.Collections.Generic; @@ -16,8 +16,10 @@ public class SliceAssignment : IHasDescription { private readonly Func _assignIdentifierFunc; - - public SliceAssignment(Func assignIdentifierFunc, string description) + public SliceAssignment( + Func assignIdentifierFunc, + string description + ) { _assignIdentifierFunc = assignIdentifierFunc; Description = description; @@ -27,8 +29,11 @@ public SliceAssignment(Func assignIdentifierFunc, string public IEnumerable Apply(IEnumerable types) { - return types.GroupBy(_assignIdentifierFunc, (identifier, enumerable) => new Slice(identifier, enumerable), - SliceIdentifier.Comparer); + return types.GroupBy( + _assignIdentifierFunc, + (identifier, enumerable) => new Slice(identifier, enumerable), + SliceIdentifier.Comparer + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Slices/SliceRule.cs b/ArchUnitNET/Fluent/Slices/SliceRule.cs index 5a25ddd45..f622a3c57 100644 --- a/ArchUnitNET/Fluent/Slices/SliceRule.cs +++ b/ArchUnitNET/Fluent/Slices/SliceRule.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Collections.Generic; using ArchUnitNET.Domain; @@ -51,4 +51,4 @@ public IArchRule Or(IArchRule archRule) return new CombinedArchRule(_ruleCreator, LogicalConjunctionDefinition.Or, archRule); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Slices/SliceRuleCreator.cs b/ArchUnitNET/Fluent/Slices/SliceRuleCreator.cs index e3a251584..530b35546 100644 --- a/ArchUnitNET/Fluent/Slices/SliceRuleCreator.cs +++ b/ArchUnitNET/Fluent/Slices/SliceRuleCreator.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System; using System.Collections.Generic; @@ -14,7 +14,12 @@ namespace ArchUnitNET.Fluent.Slices { public class SliceRuleCreator : ICanBeEvaluated { - private Func, ICanBeEvaluated, Architecture, IEnumerable> _evaluationFunc; + private Func< + IEnumerable, + ICanBeEvaluated, + Architecture, + IEnumerable + > _evaluationFunc; private SliceAssignment _sliceAssignment; public SliceRuleCreator() @@ -41,7 +46,13 @@ public void SetSliceAssignment(SliceAssignment sliceAssignment) } public void SetEvaluationFunction( - Func, ICanBeEvaluated, Architecture, IEnumerable> evaluationFunc) + Func< + IEnumerable, + ICanBeEvaluated, + Architecture, + IEnumerable + > evaluationFunc + ) { _evaluationFunc = evaluationFunc; } @@ -56,10 +67,13 @@ public IEnumerable GetSlices(Architecture architecture) if (_sliceAssignment == null) { throw new InvalidOperationException( - "The Slice Assignment has to be set before GetSlices() can be called."); + "The Slice Assignment has to be set before GetSlices() can be called." + ); } - return _sliceAssignment.Apply(architecture.Types).Where(slice => !slice.Identifier.Ignored); + return _sliceAssignment + .Apply(architecture.Types) + .Where(slice => !slice.Identifier.Ignored); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Slices/SliceRuleDefinition.cs b/ArchUnitNET/Fluent/Slices/SliceRuleDefinition.cs index aee056e9b..4c69d10d9 100644 --- a/ArchUnitNET/Fluent/Slices/SliceRuleDefinition.cs +++ b/ArchUnitNET/Fluent/Slices/SliceRuleDefinition.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 -// +// namespace ArchUnitNET.Fluent.Slices { @@ -15,4 +15,4 @@ public static SliceRuleInitializer Slices() return new SliceRuleInitializer(ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Slices/SliceRuleInitializer.cs b/ArchUnitNET/Fluent/Slices/SliceRuleInitializer.cs index 680a97cbf..a6703b88f 100644 --- a/ArchUnitNET/Fluent/Slices/SliceRuleInitializer.cs +++ b/ArchUnitNET/Fluent/Slices/SliceRuleInitializer.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System; using ArchUnitNET.Domain; @@ -13,6 +13,7 @@ namespace ArchUnitNET.Fluent.Slices public class SliceRuleInitializer { private readonly SliceRuleCreator _ruleCreator; + public SliceRuleInitializer(SliceRuleCreator ruleCreator) { _ruleCreator = ruleCreator; @@ -27,23 +28,31 @@ public SliceRuleInitializer(SliceRuleCreator ruleCreator) /// public GivenSlices Matching(string pattern) { - _ruleCreator.SetSliceAssignment(new SliceAssignment(t => - { - var parseResult = Parse(pattern); - return AssignFunc(t, parseResult.pattern, parseResult.asterisk); - }, - "matching \"" + pattern + "\"")); + _ruleCreator.SetSliceAssignment( + new SliceAssignment( + t => + { + var parseResult = Parse(pattern); + return AssignFunc(t, parseResult.pattern, parseResult.asterisk); + }, + "matching \"" + pattern + "\"" + ) + ); return new GivenSlices(_ruleCreator); } - + public GivenSlices MatchingWithPackages(string pattern) { - _ruleCreator.SetSliceAssignment(new SliceAssignment(t => - { - var parseResult = Parse(pattern); - return AssignFunc(t, parseResult.pattern, parseResult.asterisk, true); - }, - "matching \"" + pattern + "\"")); + _ruleCreator.SetSliceAssignment( + new SliceAssignment( + t => + { + var parseResult = Parse(pattern); + return AssignFunc(t, parseResult.pattern, parseResult.asterisk, true); + }, + "matching \"" + pattern + "\"" + ) + ); return new GivenSlices(_ruleCreator); } @@ -52,7 +61,7 @@ private static (string pattern, int? asterisk) Parse(string pattern) var indexOfAsteriskInPattern = pattern.IndexOf("(*", StringComparison.Ordinal); var containsSingleAsterisk = pattern.Contains("(*)"); var containsDoubleAsterisk = pattern.Contains("(**)"); - + if (!containsSingleAsterisk && !containsDoubleAsterisk) { throw new ArgumentException("Patterns for Slices have to contain (*) or (**)."); @@ -63,7 +72,10 @@ private static (string pattern, int? asterisk) Parse(string pattern) throw new ArgumentException("Patterns for Slices can't contain both (*) and (**)."); } - if (pattern.IndexOf("(**", StringComparison.Ordinal) != pattern.LastIndexOf("(**", StringComparison.Ordinal)) + if ( + pattern.IndexOf("(**", StringComparison.Ordinal) + != pattern.LastIndexOf("(**", StringComparison.Ordinal) + ) { throw new ArgumentException("Patterns for Slices can contain (**) only once."); } @@ -73,18 +85,26 @@ private static (string pattern, int? asterisk) Parse(string pattern) return (pattern, null); } - var countOfSingleAsterisk = pattern.Split(new[] { "(*)" }, StringSplitOptions.None).Length - 1; + var countOfSingleAsterisk = + pattern.Split(new[] { "(*)" }, StringSplitOptions.None).Length - 1; pattern = pattern.Remove(indexOfAsteriskInPattern) + "(**)."; return (pattern, countOfSingleAsterisk); } - private static SliceIdentifier AssignFunc(IType type, string pattern, int? countOfSingleAsterisk, bool fullName = false) + private static SliceIdentifier AssignFunc( + IType type, + string pattern, + int? countOfSingleAsterisk, + bool fullName = false + ) { var indexOfAsteriskInPattern = pattern.IndexOf("(*", StringComparison.Ordinal); var namespc = type.Namespace.FullName; var slicePrefix = pattern.Remove(indexOfAsteriskInPattern); - var slicePostfix = pattern.Substring(pattern.IndexOf("*)", StringComparison.Ordinal) + 2); + var slicePostfix = pattern.Substring( + pattern.IndexOf("*)", StringComparison.Ordinal) + 2 + ); if (slicePrefix.StartsWith(".")) { @@ -102,8 +122,14 @@ private static SliceIdentifier AssignFunc(IType type, string pattern, int? count if (slicePostfix.EndsWith(".")) { slicePostfix = slicePostfix.Remove(slicePostfix.Length - 1); - if (!namespc.Substring(namespc.IndexOf(slicePrefix, StringComparison.Ordinal) + slicePrefix.Length) - .Contains(slicePostfix)) + if ( + !namespc + .Substring( + namespc.IndexOf(slicePrefix, StringComparison.Ordinal) + + slicePrefix.Length + ) + .Contains(slicePostfix) + ) { return SliceIdentifier.Ignore(); } @@ -118,25 +144,33 @@ private static SliceIdentifier AssignFunc(IType type, string pattern, int? count if (slicePrefix != "") { sliceString = namespc - .Substring(namespc.IndexOf(slicePrefix, StringComparison.Ordinal) + slicePrefix.Length) + .Substring( + namespc.IndexOf(slicePrefix, StringComparison.Ordinal) + slicePrefix.Length + ) .TrimStart('.'); } if (!sliceString.Contains(slicePostfix)) { - throw new ArgumentException("\"" + type.FullName + - "\" is not clearly assignable to a slice with the pattern: \"" + - pattern + "\""); + throw new ArgumentException( + "\"" + + type.FullName + + "\" is not clearly assignable to a slice with the pattern: \"" + + pattern + + "\"" + ); } if (slicePostfix != "") { - sliceString = sliceString.Remove(sliceString.IndexOf(slicePostfix, StringComparison.Ordinal)); + sliceString = sliceString.Remove( + sliceString.IndexOf(slicePostfix, StringComparison.Ordinal) + ); } - return fullName - ? SliceIdentifier.Of(slicePrefix + sliceString, countOfSingleAsterisk,slicePrefix) + return fullName + ? SliceIdentifier.Of(slicePrefix + sliceString, countOfSingleAsterisk, slicePrefix) : SliceIdentifier.Of(sliceString, countOfSingleAsterisk); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Slices/SlicesShould.cs b/ArchUnitNET/Fluent/Slices/SlicesShould.cs index 392e07245..9e77d931d 100644 --- a/ArchUnitNET/Fluent/Slices/SlicesShould.cs +++ b/ArchUnitNET/Fluent/Slices/SlicesShould.cs @@ -1,9 +1,9 @@ // 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; @@ -23,10 +23,16 @@ public SlicesShould(SliceRuleCreator ruleCreator) _ruleCreator = ruleCreator; } - private static IEnumerable FindDependencies(Slice slice, IEnumerable otherSlices) + private static IEnumerable FindDependencies( + Slice slice, + IEnumerable otherSlices + ) { - var typeDependencies = slice.Dependencies.Select(dependency => dependency.Target).Distinct(); - return typeDependencies.Select(type => otherSlices.FirstOrDefault(slc => slc.Types.Contains(type))) + var typeDependencies = slice + .Dependencies.Select(dependency => dependency.Target) + .Distinct(); + return typeDependencies + .Select(type => otherSlices.FirstOrDefault(slc => slc.Types.Contains(type))) .Where(slc => slc != null); } @@ -37,14 +43,18 @@ public SliceRule BeFreeOfCycles() return new SliceRule(_ruleCreator); } - private static IEnumerable EvaluateBeFreeOfCycles(IEnumerable slices, + private static IEnumerable EvaluateBeFreeOfCycles( + IEnumerable slices, ICanBeEvaluated archRule, - Architecture architecture) + Architecture architecture + ) { var slicesList = slices.ToList(); - var cycles = slicesList.DetectCycles(slc => FindDependencies(slc, slicesList)) - .Where(dependencyCycle => dependencyCycle.IsCyclic).ToList(); + var cycles = slicesList + .DetectCycles(slc => FindDependencies(slc, slicesList)) + .Where(dependencyCycle => dependencyCycle.IsCyclic) + .ToList(); if (cycles.Any()) { @@ -56,15 +66,21 @@ private static IEnumerable EvaluateBeFreeOfCycles(IEnumerable< var dependencies = slice.Dependencies.ToList(); foreach (var otherSlice in cycle.Contents.Except(new[] { slice })) { - var depsToSlice = dependencies.Where(dependency => - otherSlice.Types.Contains(dependency.Target)) - .Distinct(new TypeDependencyComparer()).ToList(); + var depsToSlice = dependencies + .Where(dependency => otherSlice.Types.Contains(dependency.Target)) + .Distinct(new TypeDependencyComparer()) + .ToList(); if (depsToSlice.Any()) { var depsFromThisSliceToOtherSlice = new List - { slice.Description + " -> " + otherSlice.Description }; - depsFromThisSliceToOtherSlice.AddRange(depsToSlice.Select(dependency => - "\t" + dependency.Origin + " -> " + dependency.Target)); + { + slice.Description + " -> " + otherSlice.Description + }; + depsFromThisSliceToOtherSlice.AddRange( + depsToSlice.Select(dependency => + "\t" + dependency.Origin + " -> " + dependency.Target + ) + ); depsBetweenSlices.Add(depsFromThisSliceToOtherSlice); } } @@ -81,17 +97,32 @@ private static IEnumerable EvaluateBeFreeOfCycles(IEnumerable< } } - var cycleIdentifier = new EnumerableIdentifier(cycle.Contents.Select(slice => slice.Identifier)); - yield return new EvaluationResult(cycle, cycleIdentifier, false, description.ToString(), archRule, - architecture); + var cycleIdentifier = new EnumerableIdentifier( + cycle.Contents.Select(slice => slice.Identifier) + ); + yield return new EvaluationResult( + cycle, + cycleIdentifier, + false, + description.ToString(), + archRule, + architecture + ); } } else { - var slicesIdentifier = new EnumerableIdentifier(slicesList.Select(slice => slice.Identifier)); - yield return new EvaluationResult(slicesList, slicesIdentifier, true, "All Slices are free of cycles.", + var slicesIdentifier = new EnumerableIdentifier( + slicesList.Select(slice => slice.Identifier) + ); + yield return new EvaluationResult( + slicesList, + slicesIdentifier, + true, + "All Slices are free of cycles.", archRule, - architecture); + architecture + ); } } @@ -102,15 +133,19 @@ public SliceRule NotDependOnEachOther() return new SliceRule(_ruleCreator); } - private static IEnumerable EvaluateNotDependOnEachOther(IEnumerable slices, + private static IEnumerable EvaluateNotDependOnEachOther( + IEnumerable slices, ICanBeEvaluated archRule, - Architecture architecture) + Architecture architecture + ) { var slicesList = slices.ToList(); foreach (var slice in slicesList) { - var sliceDependencies = FindDependencies(slice, slicesList).Except(new[] { slice }).ToList(); + var sliceDependencies = FindDependencies(slice, slicesList) + .Except(new[] { slice }) + .ToList(); var passed = !sliceDependencies.Any(); var description = slice.Description + " does not depend on another slice."; if (!passed) @@ -118,20 +153,33 @@ private static IEnumerable EvaluateNotDependOnEachOther(IEnume description = slice.Description + " does depend on other slices:"; foreach (var sliceDependency in sliceDependencies) { - var depsToSlice = slice.Dependencies.Where(dependency => - sliceDependency.Types.Contains(dependency.Target)) - .Distinct(new TypeDependencyComparer()).ToList(); - description += "\n" + slice.Description + " -> " + sliceDependency.Description; - description = depsToSlice.Aggregate(description, + var depsToSlice = slice + .Dependencies.Where(dependency => + sliceDependency.Types.Contains(dependency.Target) + ) + .Distinct(new TypeDependencyComparer()) + .ToList(); + description += + "\n" + slice.Description + " -> " + sliceDependency.Description; + description = depsToSlice.Aggregate( + description, (current, dependency) => - current + ("\n\t" + dependency.Origin + " -> " + dependency.Target)); + current + ("\n\t" + dependency.Origin + " -> " + dependency.Target) + ); } description += "\n"; } - yield return new EvaluationResult(slice, slice.Identifier, passed, description, archRule, architecture); + yield return new EvaluationResult( + slice, + slice.Identifier, + passed, + description, + archRule, + architecture + ); } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/ConjunctionFactory.cs b/ArchUnitNET/Fluent/Syntax/ConjunctionFactory.cs index 7cae5ead8..cbc8d9248 100644 --- a/ArchUnitNET/Fluent/Syntax/ConjunctionFactory.cs +++ b/ArchUnitNET/Fluent/Syntax/ConjunctionFactory.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -11,10 +11,12 @@ namespace ArchUnitNET.Fluent.Syntax { public static class ConjunctionFactory { - public static TConjunction Create(IArchRuleCreator ruleCreator) + public static TConjunction Create( + IArchRuleCreator ruleCreator + ) where TRuleType : ICanBeAnalyzed { - return (TConjunction) Activator.CreateInstance(typeof(TConjunction), ruleCreator); + return (TConjunction)Activator.CreateInstance(typeof(TConjunction), ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/GivenObjects.cs b/ArchUnitNET/Fluent/Syntax/Elements/GivenObjects.cs index 83945f355..ee72b4995 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/GivenObjects.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/GivenObjects.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -11,13 +11,13 @@ namespace ArchUnitNET.Fluent.Syntax.Elements { - public abstract class GivenObjects : SyntaxElement, - IObjectProvider + public abstract class GivenObjects + : SyntaxElement, + IObjectProvider where TRuleType : ICanBeAnalyzed { - protected GivenObjects(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + protected GivenObjects(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } public IEnumerable GetObjects(Architecture architecture) { @@ -28,9 +28,11 @@ public IEnumerable GetObjects(Architecture architecture) catch (CannotGetObjectsOfCombinedArchRuleCreatorException exception) { throw new CannotGetObjectsOfCombinedArchRuleException( - "GetObjects() can't be used with CombinedArchRule \"" + ToString() + - "\" because the analyzed objects might be of different type. Try to use simple ArchRules instead.", - exception); + "GetObjects() can't be used with CombinedArchRule \"" + + ToString() + + "\" because the analyzed objects might be of different type. Try to use simple ArchRules instead.", + exception + ); } } @@ -44,4 +46,4 @@ public TRuleTypeShould Should() return Create(_ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsConjunction.cs b/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsConjunction.cs index ebfbac9a8..bf43e387c 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsConjunction.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsConjunction.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -9,14 +9,16 @@ namespace ArchUnitNET.Fluent.Syntax.Elements { - public abstract class - GivenObjectsConjunction - : GivenObjectsConjunctionWithDescription + public abstract class GivenObjectsConjunction< + TGivenRuleTypeThat, + TRuleTypeShould, + TGivenRuleTypeConjunctionWithReason, + TRuleType + > : GivenObjectsConjunctionWithDescription where TRuleType : ICanBeAnalyzed { - protected GivenObjectsConjunction(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + protected GivenObjectsConjunction(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } public TGivenRuleTypeConjunctionWithReason Because(string reason) { @@ -30,4 +32,4 @@ public TGivenRuleTypeConjunctionWithReason As(string description) return Create(_ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsConjunctionWithDescription.cs b/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsConjunctionWithDescription.cs index 1fda75c83..380138bfc 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsConjunctionWithDescription.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsConjunctionWithDescription.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -11,14 +11,15 @@ namespace ArchUnitNET.Fluent.Syntax.Elements { - public abstract class - GivenObjectsConjunctionWithDescription : - SyntaxElement, IObjectProvider + public abstract class GivenObjectsConjunctionWithDescription< + TGivenRuleTypeThat, + TRuleTypeShould, + TRuleType + > : SyntaxElement, IObjectProvider where TRuleType : ICanBeAnalyzed { - protected GivenObjectsConjunctionWithDescription(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + protected GivenObjectsConjunctionWithDescription(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } public IEnumerable GetObjects(Architecture architecture) { @@ -29,9 +30,11 @@ public IEnumerable GetObjects(Architecture architecture) catch (CannotGetObjectsOfCombinedArchRuleCreatorException exception) { throw new CannotGetObjectsOfCombinedArchRuleException( - "GetObjects() can't be used with CombinedArchRule \"" + ToString() + - "\" because the analyzed objects might be of different type. Try to use simple ArchRules instead.", - exception); + "GetObjects() can't be used with CombinedArchRule \"" + + ToString() + + "\" because the analyzed objects might be of different type. Try to use simple ArchRules instead.", + exception + ); } } @@ -52,4 +55,4 @@ public TRuleTypeShould Should() return Create(_ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsThat.cs index 9e289908c..9b8fbbb58 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsThat.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -13,30 +13,41 @@ namespace ArchUnitNET.Fluent.Syntax.Elements { - public abstract class GivenObjectsThat : SyntaxElement, - IObjectPredicates where TRuleType : ICanBeAnalyzed + public abstract class GivenObjectsThat + : SyntaxElement, + IObjectPredicates + where TRuleType : ICanBeAnalyzed { - protected GivenObjectsThat(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + protected GivenObjectsThat(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } public TGivenRuleTypeConjunction Are(string pattern, bool useRegularExpressions = false) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.Are(pattern, useRegularExpressions)); + ObjectPredicatesDefinition.Are(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction Are(IEnumerable patterns, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction Are( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.Are(patterns, useRegularExpressions)); + ObjectPredicatesDefinition.Are(patterns, useRegularExpressions) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction Are(ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects) + public TGivenRuleTypeConjunction Are( + ICanBeAnalyzed firstObject, + params ICanBeAnalyzed[] moreObjects + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.Are(firstObject, moreObjects)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.Are(firstObject, moreObjects) + ); return Create(_ruleCreator); } @@ -55,20 +66,30 @@ public TGivenRuleTypeConjunction Are(IObjectProvider objects) public TGivenRuleTypeConjunction CallAny(string pattern, bool useRegularExpressions = false) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.CallAny(pattern, useRegularExpressions)); + ObjectPredicatesDefinition.CallAny(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction CallAny(IEnumerable patterns, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction CallAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.CallAny(patterns, useRegularExpressions)); + ObjectPredicatesDefinition.CallAny(patterns, useRegularExpressions) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction CallAny(MethodMember method, params MethodMember[] moreMethods) + public TGivenRuleTypeConjunction CallAny( + MethodMember method, + params MethodMember[] moreMethods + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.CallAny(method, moreMethods)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.CallAny(method, moreMethods) + ); return Create(_ruleCreator); } @@ -84,29 +105,41 @@ public TGivenRuleTypeConjunction CallAny(IObjectProvider methods) return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DependOnAny(string pattern, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction DependOnAny( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.DependOnAny(pattern, useRegularExpressions)); + ObjectPredicatesDefinition.DependOnAny(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DependOnAny(IEnumerable patterns, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction DependOnAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.DependOnAny(patterns, useRegularExpressions)); + ObjectPredicatesDefinition.DependOnAny(patterns, useRegularExpressions) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction DependOnAny(Type firstType, params Type[] moreTypes) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DependOnAny(firstType, moreTypes)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DependOnAny(firstType, moreTypes) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction DependOnAny(IType firstType, params IType[] moreTypes) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DependOnAny(firstType, moreTypes)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DependOnAny(firstType, moreTypes) + ); return Create(_ruleCreator); } @@ -134,36 +167,52 @@ public TGivenRuleTypeConjunction FollowCustomPredicate(IPredicate pre return Create(_ruleCreator); } - public TGivenRuleTypeConjunction FollowCustomPredicate(Func predicate, string description) + public TGivenRuleTypeConjunction FollowCustomPredicate( + Func predicate, + string description + ) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.FollowCustomPredicate(predicate, description)); + ObjectPredicatesDefinition.FollowCustomPredicate(predicate, description) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction OnlyDependOn(string pattern, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction OnlyDependOn( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.OnlyDependOn(pattern, useRegularExpressions)); + ObjectPredicatesDefinition.OnlyDependOn(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction OnlyDependOn(IEnumerable patterns, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction OnlyDependOn( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.OnlyDependOn(patterns, useRegularExpressions)); + ObjectPredicatesDefinition.OnlyDependOn(patterns, useRegularExpressions) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction OnlyDependOn(Type firstType, params Type[] moreTypes) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.OnlyDependOn(firstType, moreTypes)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.OnlyDependOn(firstType, moreTypes) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction OnlyDependOn(IType firstType, params IType[] moreTypes) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.OnlyDependOn(firstType, moreTypes)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.OnlyDependOn(firstType, moreTypes) + ); return Create(_ruleCreator); } @@ -185,236 +234,447 @@ public TGivenRuleTypeConjunction OnlyDependOn(IEnumerable types) return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveAnyAttributes(string pattern, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction HaveAnyAttributes( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.HaveAnyAttributes(pattern, useRegularExpressions)); + ObjectPredicatesDefinition.HaveAnyAttributes( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveAnyAttributes(IEnumerable patterns, - bool useRegularExpressions = false) + public TGivenRuleTypeConjunction HaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.HaveAnyAttributes(patterns, useRegularExpressions)); + ObjectPredicatesDefinition.HaveAnyAttributes( + patterns, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveAnyAttributes(Type firstAttribute, params Type[] moreAttributes) + public TGivenRuleTypeConjunction HaveAnyAttributes( + Type firstAttribute, + params Type[] moreAttributes + ) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.HaveAnyAttributes(firstAttribute, moreAttributes)); + ObjectPredicatesDefinition.HaveAnyAttributes( + firstAttribute, + moreAttributes + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveAnyAttributes(Attribute firstAttribute, params Attribute[] moreAttributes) + public TGivenRuleTypeConjunction HaveAnyAttributes( + Attribute firstAttribute, + params Attribute[] moreAttributes + ) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.HaveAnyAttributes(firstAttribute, moreAttributes)); + ObjectPredicatesDefinition.HaveAnyAttributes( + firstAttribute, + moreAttributes + ) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction HaveAnyAttributes(IObjectProvider attributes) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveAnyAttributes(attributes)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveAnyAttributes(attributes) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction HaveAnyAttributes(IEnumerable attributes) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveAnyAttributes(attributes)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveAnyAttributes(attributes) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction HaveAnyAttributes(IEnumerable attributes) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveAnyAttributes(attributes)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveAnyAttributes(attributes) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction OnlyHaveAttributes(string pattern, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction OnlyHaveAttributes( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.OnlyHaveAttributes(pattern, useRegularExpressions)); + ObjectPredicatesDefinition.OnlyHaveAttributes( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction OnlyHaveAttributes(IEnumerable patterns, - bool useRegularExpressions = false) + public TGivenRuleTypeConjunction OnlyHaveAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.OnlyHaveAttributes(patterns, useRegularExpressions)); + ObjectPredicatesDefinition.OnlyHaveAttributes( + patterns, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction OnlyHaveAttributes(Type firstAttribute, params Type[] moreAttributes) + public TGivenRuleTypeConjunction OnlyHaveAttributes( + Type firstAttribute, + params Type[] moreAttributes + ) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.OnlyHaveAttributes(firstAttribute, moreAttributes)); + ObjectPredicatesDefinition.OnlyHaveAttributes( + firstAttribute, + moreAttributes + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction OnlyHaveAttributes(Attribute firstAttribute, params Attribute[] moreAttributes) + public TGivenRuleTypeConjunction OnlyHaveAttributes( + Attribute firstAttribute, + params Attribute[] moreAttributes + ) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.OnlyHaveAttributes(firstAttribute, moreAttributes)); + ObjectPredicatesDefinition.OnlyHaveAttributes( + firstAttribute, + moreAttributes + ) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction OnlyHaveAttributes(IObjectProvider attributes) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.OnlyHaveAttributes(attributes)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.OnlyHaveAttributes(attributes) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction OnlyHaveAttributes(IEnumerable attributes) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.OnlyHaveAttributes(attributes)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.OnlyHaveAttributes(attributes) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction OnlyHaveAttributes(IEnumerable attributes) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.OnlyHaveAttributes(attributes)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.OnlyHaveAttributes(attributes) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveAnyAttributesWithArguments(IEnumerable argumentValues) + public TGivenRuleTypeConjunction HaveAnyAttributesWithArguments( + IEnumerable argumentValues + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveAnyAttributesWithArguments(argumentValues)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveAnyAttributesWithArguments(argumentValues) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveAnyAttributesWithArguments(object firstArgumentValue, params object[] moreArgumentValues) + public TGivenRuleTypeConjunction HaveAnyAttributesWithArguments( + object firstArgumentValue, + params object[] moreArgumentValues + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveAnyAttributesWithArguments(firstArgumentValue,moreArgumentValues)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveAnyAttributesWithArguments( + firstArgumentValue, + moreArgumentValues + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveAttributeWithArguments(string attribute, IEnumerable argumentValues) + public TGivenRuleTypeConjunction HaveAttributeWithArguments( + string attribute, + IEnumerable argumentValues + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveAttributeWithArguments(attribute,argumentValues)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveAttributeWithArguments( + attribute, + argumentValues + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveAttributeWithArguments(string attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public TGivenRuleTypeConjunction HaveAttributeWithArguments( + string attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveAttributeWithArguments(attribute,firstArgumentValue,moreArgumentValues)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveAttributeWithArguments( + attribute, + firstArgumentValue, + moreArgumentValues + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveAttributeWithArguments(Attribute attribute, IEnumerable argumentValues) + public TGivenRuleTypeConjunction HaveAttributeWithArguments( + Attribute attribute, + IEnumerable argumentValues + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveAttributeWithArguments(attribute,argumentValues)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveAttributeWithArguments( + attribute, + argumentValues + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveAttributeWithArguments(Attribute attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public TGivenRuleTypeConjunction HaveAttributeWithArguments( + Attribute attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveAttributeWithArguments(attribute,firstArgumentValue,moreArgumentValues)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveAttributeWithArguments( + attribute, + firstArgumentValue, + moreArgumentValues + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveAttributeWithArguments(Type attribute, IEnumerable argumentValues) + public TGivenRuleTypeConjunction HaveAttributeWithArguments( + Type attribute, + IEnumerable argumentValues + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveAttributeWithArguments(attribute,argumentValues)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveAttributeWithArguments( + attribute, + argumentValues + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveAttributeWithArguments(Type attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public TGivenRuleTypeConjunction HaveAttributeWithArguments( + Type attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveAttributeWithArguments(attribute,firstArgumentValue,moreArgumentValues)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveAttributeWithArguments( + attribute, + firstArgumentValue, + moreArgumentValues + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveAnyAttributesWithNamedArguments(IEnumerable<(string, object)> attributeArguments) + public TGivenRuleTypeConjunction HaveAnyAttributesWithNamedArguments( + IEnumerable<(string, object)> attributeArguments + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveAnyAttributesWithNamedArguments(attributeArguments)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveAnyAttributesWithNamedArguments( + attributeArguments + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveAnyAttributesWithNamedArguments((string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments) + public TGivenRuleTypeConjunction HaveAnyAttributesWithNamedArguments( + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveAnyAttributesWithNamedArguments(firstAttributeArgument,moreAttributeArguments)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveAnyAttributesWithNamedArguments( + firstAttributeArgument, + moreAttributeArguments + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveAttributeWithNamedArguments(string attribute, IEnumerable<(string, object)> attributeArguments) + public TGivenRuleTypeConjunction HaveAttributeWithNamedArguments( + string attribute, + IEnumerable<(string, object)> attributeArguments + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveAttributeWithNamedArguments(attribute,attributeArguments)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveAttributeWithNamedArguments( + attribute, + attributeArguments + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveAttributeWithNamedArguments(string attribute, (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments) + public TGivenRuleTypeConjunction HaveAttributeWithNamedArguments( + string attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveAttributeWithNamedArguments(attribute,firstAttributeArgument,moreAttributeArguments)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveAttributeWithNamedArguments( + attribute, + firstAttributeArgument, + moreAttributeArguments + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveAttributeWithNamedArguments(Attribute attribute, IEnumerable<(string, object)> attributeArguments) + public TGivenRuleTypeConjunction HaveAttributeWithNamedArguments( + Attribute attribute, + IEnumerable<(string, object)> attributeArguments + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveAttributeWithNamedArguments(attribute,attributeArguments)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveAttributeWithNamedArguments( + attribute, + attributeArguments + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveAttributeWithNamedArguments(Attribute attribute, (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments) + public TGivenRuleTypeConjunction HaveAttributeWithNamedArguments( + Attribute attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveAttributeWithNamedArguments(attribute,firstAttributeArgument,moreAttributeArguments)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveAttributeWithNamedArguments( + attribute, + firstAttributeArgument, + moreAttributeArguments + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveAttributeWithNamedArguments(Type attribute, IEnumerable<(string, object)> attributeArguments) + public TGivenRuleTypeConjunction HaveAttributeWithNamedArguments( + Type attribute, + IEnumerable<(string, object)> attributeArguments + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveAttributeWithNamedArguments(attribute,attributeArguments)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveAttributeWithNamedArguments( + attribute, + attributeArguments + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveAttributeWithNamedArguments(Type attribute, (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments) + public TGivenRuleTypeConjunction HaveAttributeWithNamedArguments( + Type attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveAttributeWithNamedArguments(attribute,firstAttributeArgument,moreAttributeArguments)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveAttributeWithNamedArguments( + attribute, + firstAttributeArgument, + moreAttributeArguments + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveName(string pattern, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction HaveName( + string pattern, + bool useRegularExpressions = false + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveName(pattern, useRegularExpressions)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveName(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction HaveFullName(string pattern, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction HaveFullName( + string pattern, + bool useRegularExpressions = false + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveFullName(pattern, useRegularExpressions)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveFullName(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction HaveNameStartingWith(string pattern) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveNameStartingWith(pattern)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveNameStartingWith(pattern) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction HaveNameEndingWith(string pattern) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveNameEndingWith(pattern)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveNameEndingWith(pattern) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction HaveNameContaining(string pattern) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveNameContaining(pattern)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveNameContaining(pattern) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction HaveFullNameContaining(string pattern) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.HaveFullNameContaining(pattern)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.HaveFullNameContaining(pattern) + ); return Create(_ruleCreator); } @@ -454,27 +714,36 @@ public TGivenRuleTypeConjunction ArePrivateProtected() return Create(_ruleCreator); } - //Negations public TGivenRuleTypeConjunction AreNot(string pattern, bool useRegularExpressions = false) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.AreNot(pattern, useRegularExpressions)); + ObjectPredicatesDefinition.AreNot(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction AreNot(IEnumerable patterns, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction AreNot( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.AreNot(patterns, useRegularExpressions)); + ObjectPredicatesDefinition.AreNot(patterns, useRegularExpressions) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction AreNot(ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects) + public TGivenRuleTypeConjunction AreNot( + ICanBeAnalyzed firstObject, + params ICanBeAnalyzed[] moreObjects + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.AreNot(firstObject, moreObjects)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.AreNot(firstObject, moreObjects) + ); return Create(_ruleCreator); } @@ -490,24 +759,36 @@ public TGivenRuleTypeConjunction AreNot(IObjectProvider objects) return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotCallAny(string pattern, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction DoNotCallAny( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.DoNotCallAny(pattern, useRegularExpressions)); + ObjectPredicatesDefinition.DoNotCallAny(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotCallAny(IEnumerable patterns, - bool useRegularExpressions = false) + public TGivenRuleTypeConjunction DoNotCallAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.DoNotCallAny(patterns, useRegularExpressions)); + ObjectPredicatesDefinition.DoNotCallAny(patterns, useRegularExpressions) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotCallAny(MethodMember method, params MethodMember[] moreMethods) + public TGivenRuleTypeConjunction DoNotCallAny( + MethodMember method, + params MethodMember[] moreMethods + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotCallAny(method, moreMethods)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotCallAny(method, moreMethods) + ); return Create(_ruleCreator); } @@ -523,236 +804,442 @@ public TGivenRuleTypeConjunction DoNotCallAny(IObjectProvider meth return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotDependOnAny(string pattern, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction DoNotDependOnAny( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.DoNotDependOnAny(pattern, useRegularExpressions)); + ObjectPredicatesDefinition.DoNotDependOnAny( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotDependOnAny(IEnumerable patterns, - bool useRegularExpressions = false) + public TGivenRuleTypeConjunction DoNotDependOnAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.DoNotDependOnAny(patterns, useRegularExpressions)); + ObjectPredicatesDefinition.DoNotDependOnAny( + patterns, + useRegularExpressions + ) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction DoNotDependOnAny(Type firstType, params Type[] moreTypes) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotDependOnAny(firstType, moreTypes)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotDependOnAny(firstType, moreTypes) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction DoNotDependOnAny(IType firstType, params IType[] moreTypes) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotDependOnAny(firstType, moreTypes)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotDependOnAny(firstType, moreTypes) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction DoNotDependOnAny(IObjectProvider types) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotDependOnAny(types)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotDependOnAny(types) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction DoNotDependOnAny(IEnumerable types) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotDependOnAny(types)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotDependOnAny(types) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction DoNotDependOnAny(IEnumerable types) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotDependOnAny(types)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotDependOnAny(types) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveAnyAttributes(string pattern, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction DoNotHaveAnyAttributes( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.DoNotHaveAnyAttributes(pattern, useRegularExpressions)); + ObjectPredicatesDefinition.DoNotHaveAnyAttributes( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveAnyAttributes(IEnumerable patterns, - bool useRegularExpressions = false) + public TGivenRuleTypeConjunction DoNotHaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.DoNotHaveAnyAttributes(patterns, useRegularExpressions)); + ObjectPredicatesDefinition.DoNotHaveAnyAttributes( + patterns, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveAnyAttributes(Type firstAttribute, params Type[] moreAttributes) + public TGivenRuleTypeConjunction DoNotHaveAnyAttributes( + Type firstAttribute, + params Type[] moreAttributes + ) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.DoNotHaveAnyAttributes(firstAttribute, moreAttributes)); + ObjectPredicatesDefinition.DoNotHaveAnyAttributes( + firstAttribute, + moreAttributes + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveAnyAttributes(Attribute firstAttribute, - params Attribute[] moreAttributes) + public TGivenRuleTypeConjunction DoNotHaveAnyAttributes( + Attribute firstAttribute, + params Attribute[] moreAttributes + ) { _ruleCreator.AddPredicate( - ObjectPredicatesDefinition.DoNotHaveAnyAttributes(firstAttribute, moreAttributes)); + ObjectPredicatesDefinition.DoNotHaveAnyAttributes( + firstAttribute, + moreAttributes + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveAnyAttributes(IObjectProvider attributes) + public TGivenRuleTypeConjunction DoNotHaveAnyAttributes( + IObjectProvider attributes + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveAnyAttributes(attributes)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveAnyAttributes(attributes) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction DoNotHaveAnyAttributes(IEnumerable attributes) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveAnyAttributes(attributes)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveAnyAttributes(attributes) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction DoNotHaveAnyAttributes(IEnumerable attributes) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveAnyAttributes(attributes)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveAnyAttributes(attributes) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveAnyAttributesWithArguments(IEnumerable argumentValues) + public TGivenRuleTypeConjunction DoNotHaveAnyAttributesWithArguments( + IEnumerable argumentValues + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveAnyAttributesWithArguments(argumentValues)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveAnyAttributesWithArguments( + argumentValues + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveAnyAttributesWithArguments(object firstArgumentValue, - params object[] moreArgumentValues) + public TGivenRuleTypeConjunction DoNotHaveAnyAttributesWithArguments( + object firstArgumentValue, + params object[] moreArgumentValues + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveAnyAttributesWithArguments(firstArgumentValue,moreArgumentValues)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveAnyAttributesWithArguments( + firstArgumentValue, + moreArgumentValues + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveAttributeWithArguments(string attribute, IEnumerable argumentValues) + public TGivenRuleTypeConjunction DoNotHaveAttributeWithArguments( + string attribute, + IEnumerable argumentValues + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments(attribute,argumentValues)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments( + attribute, + argumentValues + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveAttributeWithArguments(string attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public TGivenRuleTypeConjunction DoNotHaveAttributeWithArguments( + string attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments(attribute,firstArgumentValue,moreArgumentValues)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments( + attribute, + firstArgumentValue, + moreArgumentValues + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveAttributeWithNamedArguments(string attribute, IEnumerable<(string, object)> attributeArguments) + public TGivenRuleTypeConjunction DoNotHaveAttributeWithNamedArguments( + string attribute, + IEnumerable<(string, object)> attributeArguments + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments(attribute,attributeArguments)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments( + attribute, + attributeArguments + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveAttributeWithNamedArguments(string attribute, - (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments) + public TGivenRuleTypeConjunction DoNotHaveAttributeWithNamedArguments( + string attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments(attribute,firstAttributeArgument,moreAttributeArguments)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments( + attribute, + firstAttributeArgument, + moreAttributeArguments + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveAttributeWithArguments(Attribute attribute, IEnumerable argumentValues) + public TGivenRuleTypeConjunction DoNotHaveAttributeWithArguments( + Attribute attribute, + IEnumerable argumentValues + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments(attribute,argumentValues)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments( + attribute, + argumentValues + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveAttributeWithArguments(Attribute attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public TGivenRuleTypeConjunction DoNotHaveAttributeWithArguments( + Attribute attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments(attribute,firstArgumentValue,moreArgumentValues)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments( + attribute, + firstArgumentValue, + moreArgumentValues + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveAttributeWithArguments(Type attribute, IEnumerable argumentValues) + public TGivenRuleTypeConjunction DoNotHaveAttributeWithArguments( + Type attribute, + IEnumerable argumentValues + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments(attribute,argumentValues)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments( + attribute, + argumentValues + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveAttributeWithArguments(Type attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public TGivenRuleTypeConjunction DoNotHaveAttributeWithArguments( + Type attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments(attribute,firstArgumentValue,moreArgumentValues)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments( + attribute, + firstArgumentValue, + moreArgumentValues + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveAnyAttributesWithNamedArguments(IEnumerable<(string, object)> attributeArguments) + public TGivenRuleTypeConjunction DoNotHaveAnyAttributesWithNamedArguments( + IEnumerable<(string, object)> attributeArguments + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveAnyAttributesWithNamedArguments(attributeArguments)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveAnyAttributesWithNamedArguments( + attributeArguments + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveAnyAttributesWithNamedArguments((string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments) + public TGivenRuleTypeConjunction DoNotHaveAnyAttributesWithNamedArguments( + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveAnyAttributesWithNamedArguments(firstAttributeArgument,moreAttributeArguments)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveAnyAttributesWithNamedArguments( + firstAttributeArgument, + moreAttributeArguments + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveAttributeWithNamedArguments(Attribute attribute, IEnumerable<(string, object)> attributeArguments) + public TGivenRuleTypeConjunction DoNotHaveAttributeWithNamedArguments( + Attribute attribute, + IEnumerable<(string, object)> attributeArguments + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments(attribute,attributeArguments)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments( + attribute, + attributeArguments + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveAttributeWithNamedArguments(Attribute attribute, - (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments) + public TGivenRuleTypeConjunction DoNotHaveAttributeWithNamedArguments( + Attribute attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments(attribute,firstAttributeArgument,moreAttributeArguments)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments( + attribute, + firstAttributeArgument, + moreAttributeArguments + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveAttributeWithNamedArguments(Type attribute, IEnumerable<(string, object)> attributeArguments) + public TGivenRuleTypeConjunction DoNotHaveAttributeWithNamedArguments( + Type attribute, + IEnumerable<(string, object)> attributeArguments + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments(attribute,attributeArguments)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments( + attribute, + attributeArguments + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveAttributeWithNamedArguments(Type attribute, (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments) + public TGivenRuleTypeConjunction DoNotHaveAttributeWithNamedArguments( + Type attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments(attribute,firstAttributeArgument,moreAttributeArguments)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments( + attribute, + firstAttributeArgument, + moreAttributeArguments + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveName(string pattern, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction DoNotHaveName( + string pattern, + bool useRegularExpressions = false + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveName(pattern, useRegularExpressions)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveName(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotHaveFullName(string pattern, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction DoNotHaveFullName( + string pattern, + bool useRegularExpressions = false + ) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveFullName(pattern, useRegularExpressions)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveFullName( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction DoNotHaveNameStartingWith(string pattern) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveNameStartingWith(pattern)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveNameStartingWith(pattern) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction DoNotHaveNameEndingWith(string pattern) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveNameEndingWith(pattern)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveNameEndingWith(pattern) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction DoNotHaveNameContaining(string pattern) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveNameContaining(pattern)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveNameContaining(pattern) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction DoNotHaveFullNameContaining(string pattern) { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.DoNotHaveFullNameContaining(pattern)); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.DoNotHaveFullNameContaining(pattern) + ); return Create(_ruleCreator); } @@ -782,14 +1269,18 @@ public TGivenRuleTypeConjunction AreNotInternal() public TGivenRuleTypeConjunction AreNotProtectedInternal() { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.AreNotProtectedInternal()); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.AreNotProtectedInternal() + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction AreNotPrivateProtected() { - _ruleCreator.AddPredicate(ObjectPredicatesDefinition.AreNotPrivateProtected()); + _ruleCreator.AddPredicate( + ObjectPredicatesDefinition.AreNotPrivateProtected() + ); return Create(_ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/IComplexObjectConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/IComplexObjectConditions.cs index 073a63581..0f4c6ee1a 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/IComplexObjectConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/IComplexObjectConditions.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -10,21 +10,37 @@ namespace ArchUnitNET.Fluent.Syntax.Elements { - public interface - IComplexObjectConditions : IObjectConditions + public interface IComplexObjectConditions + : IObjectConditions where TRuleType : ICanBeAnalyzed where TRuleTypeShouldConjunction : SyntaxElement { - ShouldRelateToTypesThat DependOnAnyTypesThat(); - ShouldRelateToTypesThat OnlyDependOnTypesThat(); + ShouldRelateToTypesThat< + TRuleTypeShouldConjunction, + IType, + TRuleType + > DependOnAnyTypesThat(); + ShouldRelateToTypesThat< + TRuleTypeShouldConjunction, + IType, + TRuleType + > OnlyDependOnTypesThat(); ShouldRelateToAttributesThat HaveAnyAttributesThat(); - ShouldRelateToAttributesThat OnlyHaveAttributesThat(); - + ShouldRelateToAttributesThat< + TRuleTypeShouldConjunction, + TRuleType + > OnlyHaveAttributesThat(); //Negations - ShouldRelateToTypesThat NotDependOnAnyTypesThat(); - ShouldRelateToAttributesThat NotHaveAnyAttributesThat(); + ShouldRelateToTypesThat< + TRuleTypeShouldConjunction, + IType, + TRuleType + > NotDependOnAnyTypesThat(); + ShouldRelateToAttributesThat< + TRuleTypeShouldConjunction, + TRuleType + > NotHaveAnyAttributesThat(); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/IObjectConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/IObjectConditions.cs index 04f03f667..01738d28b 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/IObjectConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/IObjectConditions.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -12,7 +12,8 @@ namespace ArchUnitNET.Fluent.Syntax.Elements { - public interface IObjectConditions where TRuleType : ICanBeAnalyzed + public interface IObjectConditions + where TRuleType : ICanBeAnalyzed { TReturnType Exist(); TReturnType Be(string pattern, bool useRegularExpressions = false); @@ -33,8 +34,15 @@ public interface IObjectConditions where TRuleTy TReturnType DependOnAny(IEnumerable types); TReturnType DependOnAny(IEnumerable types); TReturnType FollowCustomCondition(ICondition condition); - TReturnType FollowCustomCondition(Func condition, string description); - TReturnType FollowCustomCondition(Func condition, string description, string failDescription); + TReturnType FollowCustomCondition( + Func condition, + string description + ); + TReturnType FollowCustomCondition( + Func condition, + string description, + string failDescription + ); TReturnType OnlyDependOn(string pattern, bool useRegularExpressions = false); TReturnType OnlyDependOn(IEnumerable patterns, bool useRegularExpressions = false); TReturnType OnlyDependOn(IType firstType, params IType[] moreTypes); @@ -43,35 +51,88 @@ public interface IObjectConditions where TRuleTy TReturnType OnlyDependOn(IEnumerable types); TReturnType OnlyDependOn(IEnumerable types); TReturnType HaveAnyAttributes(string pattern, bool useRegularExpressions = false); - TReturnType HaveAnyAttributes(IEnumerable patterns, bool useRegularExpressions = false); + TReturnType HaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType HaveAnyAttributes(Attribute firstAttribute, params Attribute[] moreAttributes); TReturnType HaveAnyAttributes(Type firstAttribute, params Type[] moreAttributes); TReturnType HaveAnyAttributes(IObjectProvider attributes); TReturnType HaveAnyAttributes(IEnumerable attributes); TReturnType HaveAnyAttributes(IEnumerable attributes); TReturnType OnlyHaveAttributes(string pattern, bool useRegularExpressions = false); - TReturnType OnlyHaveAttributes(IEnumerable patterns, bool useRegularExpressions = false); + TReturnType OnlyHaveAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType OnlyHaveAttributes(Attribute firstAttribute, params Attribute[] moreAttributes); TReturnType OnlyHaveAttributes(Type firstAttribute, params Type[] moreAttributes); TReturnType OnlyHaveAttributes(IObjectProvider attributes); TReturnType OnlyHaveAttributes(IEnumerable attributes); TReturnType OnlyHaveAttributes(IEnumerable attributes); TReturnType HaveAnyAttributesWithArguments(IEnumerable argumentValues); - TReturnType HaveAnyAttributesWithArguments(object firstArgumentValue, params object[] moreArgumentValues); - TReturnType HaveAttributeWithArguments(string attribute, IEnumerable argumentValues); - TReturnType HaveAttributeWithArguments(string attribute, object firstArgumentValue, params object[] moreArgumentValues); - TReturnType HaveAttributeWithArguments(Attribute attribute, IEnumerable argumentValues); - TReturnType HaveAttributeWithArguments(Attribute attribute, object firstArgumentValue, params object[] moreArgumentValues); + TReturnType HaveAnyAttributesWithArguments( + object firstArgumentValue, + params object[] moreArgumentValues + ); + TReturnType HaveAttributeWithArguments( + string attribute, + IEnumerable argumentValues + ); + TReturnType HaveAttributeWithArguments( + string attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ); + TReturnType HaveAttributeWithArguments( + Attribute attribute, + IEnumerable argumentValues + ); + TReturnType HaveAttributeWithArguments( + Attribute attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ); TReturnType HaveAttributeWithArguments(Type attribute, IEnumerable argumentValues); - TReturnType HaveAttributeWithArguments(Type attribute, object firstArgumentValue, params object[] moreArgumentValues); - TReturnType HaveAnyAttributesWithNamedArguments(IEnumerable<(string,object)> attributeArguments); - TReturnType HaveAnyAttributesWithNamedArguments((string,object) firstAttributeArgument, params (string,object)[] moreAttributeArguments); - TReturnType HaveAttributeWithNamedArguments(string attribute, IEnumerable<(string,object)> attributeArguments); - TReturnType HaveAttributeWithNamedArguments(string attribute, (string,object) firstAttributeArgument, params (string,object)[] moreAttributeArguments); - TReturnType HaveAttributeWithNamedArguments(Attribute attribute, IEnumerable<(string,object)> attributeArguments); - TReturnType HaveAttributeWithNamedArguments(Attribute attribute, (string,object) firstAttributeArgument, params (string,object)[] moreAttributeArguments); - TReturnType HaveAttributeWithNamedArguments(Type attribute, IEnumerable<(string,object)> attributeArguments); - TReturnType HaveAttributeWithNamedArguments(Type attribute, (string,object) firstAttributeArgument, params (string,object)[] moreAttributeArguments); + TReturnType HaveAttributeWithArguments( + Type attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ); + TReturnType HaveAnyAttributesWithNamedArguments( + IEnumerable<(string, object)> attributeArguments + ); + TReturnType HaveAnyAttributesWithNamedArguments( + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ); + TReturnType HaveAttributeWithNamedArguments( + string attribute, + IEnumerable<(string, object)> attributeArguments + ); + TReturnType HaveAttributeWithNamedArguments( + string attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ); + TReturnType HaveAttributeWithNamedArguments( + Attribute attribute, + IEnumerable<(string, object)> attributeArguments + ); + TReturnType HaveAttributeWithNamedArguments( + Attribute attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ); + TReturnType HaveAttributeWithNamedArguments( + Type attribute, + IEnumerable<(string, object)> attributeArguments + ); + TReturnType HaveAttributeWithNamedArguments( + Type attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ); TReturnType HaveName(string pattern, bool useRegularExpressions = false); TReturnType HaveFullName(string pattern, bool useRegularExpressions = false); TReturnType HaveNameStartingWith(string pattern); @@ -85,7 +146,6 @@ public interface IObjectConditions where TRuleTy TReturnType BeProtectedInternal(); TReturnType BePrivateProtected(); - //Negations @@ -101,31 +161,76 @@ public interface IObjectConditions where TRuleTy TReturnType NotCallAny(IEnumerable methods); TReturnType NotCallAny(IObjectProvider methods); TReturnType NotDependOnAny(string pattern, bool useRegularExpressions = false); - TReturnType NotDependOnAny(IEnumerable patterns, bool useRegularExpressions = false); + TReturnType NotDependOnAny( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType NotDependOnAny(IType firstType, params IType[] moreTypes); TReturnType NotDependOnAny(Type firstType, params Type[] moreTypes); TReturnType NotDependOnAny(IObjectProvider types); TReturnType NotDependOnAny(IEnumerable types); TReturnType NotDependOnAny(IEnumerable types); TReturnType NotHaveAnyAttributes(string pattern, bool useRegularExpressions = false); - TReturnType NotHaveAnyAttributes(IEnumerable patterns, bool useRegularExpressions = false); - TReturnType NotHaveAnyAttributes(Attribute firstAttribute, params Attribute[] moreAttributes); + TReturnType NotHaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ); + TReturnType NotHaveAnyAttributes( + Attribute firstAttribute, + params Attribute[] moreAttributes + ); TReturnType NotHaveAnyAttributes(Type firstAttribute, params Type[] moreAttributes); TReturnType NotHaveAnyAttributes(IObjectProvider attributes); TReturnType NotHaveAnyAttributes(IEnumerable attributes); TReturnType NotHaveAnyAttributes(IEnumerable attributes); TReturnType NotHaveAnyAttributesWithArguments(IEnumerable argumentValues); - TReturnType NotHaveAnyAttributesWithArguments(object firstArgumentValue, params object[] moreArgumentValues); - TReturnType NotHaveAttributeWithArguments(Attribute attribute, IEnumerable argumentValues); - TReturnType NotHaveAttributeWithArguments(Attribute attribute, object firstArgumentValue, params object[] moreArgumentValues); - TReturnType NotHaveAttributeWithArguments(Type attribute, IEnumerable argumentValues); - TReturnType NotHaveAttributeWithArguments(Type attribute, object firstArgumentValue, params object[] moreArgumentValues); - TReturnType NotHaveAnyAttributesWithNamedArguments(IEnumerable<(string,object)> attributeArguments); - TReturnType NotHaveAnyAttributesWithNamedArguments((string,object) firstAttributeArgument, params (string,object)[] moreAttributeArguments); - TReturnType NotHaveAttributeWithNamedArguments(Attribute attribute, IEnumerable<(string,object)> attributeArguments); - TReturnType NotHaveAttributeWithNamedArguments(Attribute attribute, (string,object) firstAttributeArgument, params (string,object)[] moreAttributeArguments); - TReturnType NotHaveAttributeWithNamedArguments(Type attribute, IEnumerable<(string,object)> attributeArguments); - TReturnType NotHaveAttributeWithNamedArguments(Type attribute, (string,object) firstAttributeArgument, params (string,object)[] moreAttributeArguments); + TReturnType NotHaveAnyAttributesWithArguments( + object firstArgumentValue, + params object[] moreArgumentValues + ); + TReturnType NotHaveAttributeWithArguments( + Attribute attribute, + IEnumerable argumentValues + ); + TReturnType NotHaveAttributeWithArguments( + Attribute attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ); + TReturnType NotHaveAttributeWithArguments( + Type attribute, + IEnumerable argumentValues + ); + TReturnType NotHaveAttributeWithArguments( + Type attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ); + TReturnType NotHaveAnyAttributesWithNamedArguments( + IEnumerable<(string, object)> attributeArguments + ); + TReturnType NotHaveAnyAttributesWithNamedArguments( + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ); + TReturnType NotHaveAttributeWithNamedArguments( + Attribute attribute, + IEnumerable<(string, object)> attributeArguments + ); + TReturnType NotHaveAttributeWithNamedArguments( + Attribute attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ); + TReturnType NotHaveAttributeWithNamedArguments( + Type attribute, + IEnumerable<(string, object)> attributeArguments + ); + TReturnType NotHaveAttributeWithNamedArguments( + Type attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ); TReturnType NotHaveName(string pattern, bool useRegularExpressions = false); TReturnType NotHaveFullName(string pattern, bool useRegularExpressions = false); TReturnType NotHaveNameStartingWith(string pattern); @@ -139,4 +244,4 @@ public interface IObjectConditions where TRuleTy TReturnType NotBeProtectedInternal(); TReturnType NotBePrivateProtected(); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/IObjectPredicates.cs b/ArchUnitNET/Fluent/Syntax/Elements/IObjectPredicates.cs index 79ae2d89b..ac382780e 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/IObjectPredicates.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/IObjectPredicates.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -12,7 +12,8 @@ namespace ArchUnitNET.Fluent.Syntax.Elements { - public interface IObjectPredicates where TRuleType : ICanBeAnalyzed + public interface IObjectPredicates + where TRuleType : ICanBeAnalyzed { TReturnType Are(string pattern, bool useRegularExpressions = false); TReturnType Are(IEnumerable patterns, bool useRegularExpressions = false); @@ -41,35 +42,88 @@ public interface IObjectPredicates where TRuleType : TReturnType OnlyDependOn(IEnumerable types); TReturnType OnlyDependOn(IEnumerable types); TReturnType HaveAnyAttributes(string pattern, bool useRegularExpressions = false); - TReturnType HaveAnyAttributes(IEnumerable patterns, bool useRegularExpressions = false); + TReturnType HaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType HaveAnyAttributes(Attribute firstAttribute, params Attribute[] moreAttributes); TReturnType HaveAnyAttributes(Type firstAttribute, params Type[] moreAttributes); TReturnType HaveAnyAttributes(IObjectProvider attributes); TReturnType HaveAnyAttributes(IEnumerable attributes); TReturnType HaveAnyAttributes(IEnumerable attributes); TReturnType OnlyHaveAttributes(string pattern, bool useRegularExpressions = false); - TReturnType OnlyHaveAttributes(IEnumerable patterns, bool useRegularExpressions = false); + TReturnType OnlyHaveAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType OnlyHaveAttributes(Attribute firstAttribute, params Attribute[] moreAttributes); TReturnType OnlyHaveAttributes(Type firstAttribute, params Type[] moreAttributes); TReturnType OnlyHaveAttributes(IObjectProvider attributes); TReturnType OnlyHaveAttributes(IEnumerable attributes); TReturnType OnlyHaveAttributes(IEnumerable attributes); TReturnType HaveAnyAttributesWithArguments(IEnumerable argumentValues); - TReturnType HaveAnyAttributesWithArguments(object firstArgumentValue, params object[] moreArgumentValues); - TReturnType HaveAttributeWithArguments(string attribute, IEnumerable argumentValues); - TReturnType HaveAttributeWithArguments(string attribute, object firstArgumentValue, params object[] moreArgumentValues); - TReturnType HaveAttributeWithArguments(Attribute attribute, IEnumerable argumentValues); - TReturnType HaveAttributeWithArguments(Attribute attribute, object firstArgumentValue, params object[] moreArgumentValues); + TReturnType HaveAnyAttributesWithArguments( + object firstArgumentValue, + params object[] moreArgumentValues + ); + TReturnType HaveAttributeWithArguments( + string attribute, + IEnumerable argumentValues + ); + TReturnType HaveAttributeWithArguments( + string attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ); + TReturnType HaveAttributeWithArguments( + Attribute attribute, + IEnumerable argumentValues + ); + TReturnType HaveAttributeWithArguments( + Attribute attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ); TReturnType HaveAttributeWithArguments(Type attribute, IEnumerable argumentValues); - TReturnType HaveAttributeWithArguments(Type attribute, object firstArgumentValue, params object[] moreArgumentValues); - TReturnType HaveAnyAttributesWithNamedArguments(IEnumerable<(string,object)> attributeArguments); - TReturnType HaveAnyAttributesWithNamedArguments((string,object) firstAttributeArgument, params (string,object)[] moreAttributeArguments); - TReturnType HaveAttributeWithNamedArguments(string attribute, IEnumerable<(string,object)> attributeArguments); - TReturnType HaveAttributeWithNamedArguments(string attribute, (string,object) firstAttributeArgument, params (string,object)[] moreAttributeArguments); - TReturnType HaveAttributeWithNamedArguments(Attribute attribute, IEnumerable<(string,object)> attributeArguments); - TReturnType HaveAttributeWithNamedArguments(Attribute attribute, (string,object) firstAttributeArgument, params (string,object)[] moreAttributeArguments); - TReturnType HaveAttributeWithNamedArguments(Type attribute, IEnumerable<(string,object)> attributeArguments); - TReturnType HaveAttributeWithNamedArguments(Type attribute, (string,object) firstAttributeArgument, params (string,object)[] moreAttributeArguments); + TReturnType HaveAttributeWithArguments( + Type attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ); + TReturnType HaveAnyAttributesWithNamedArguments( + IEnumerable<(string, object)> attributeArguments + ); + TReturnType HaveAnyAttributesWithNamedArguments( + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ); + TReturnType HaveAttributeWithNamedArguments( + string attribute, + IEnumerable<(string, object)> attributeArguments + ); + TReturnType HaveAttributeWithNamedArguments( + string attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ); + TReturnType HaveAttributeWithNamedArguments( + Attribute attribute, + IEnumerable<(string, object)> attributeArguments + ); + TReturnType HaveAttributeWithNamedArguments( + Attribute attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ); + TReturnType HaveAttributeWithNamedArguments( + Type attribute, + IEnumerable<(string, object)> attributeArguments + ); + TReturnType HaveAttributeWithNamedArguments( + Type attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ); TReturnType HaveName(string pattern, bool useRegularExpressions = false); TReturnType HaveFullName(string pattern, bool useRegularExpressions = false); TReturnType HaveNameStartingWith(string pattern); @@ -83,7 +137,6 @@ public interface IObjectPredicates where TRuleType : TReturnType AreProtectedInternal(); TReturnType ArePrivateProtected(); - //Negations @@ -98,35 +151,94 @@ public interface IObjectPredicates where TRuleType : TReturnType DoNotCallAny(IEnumerable methods); TReturnType DoNotCallAny(IObjectProvider methods); TReturnType DoNotDependOnAny(string pattern, bool useRegularExpressions = false); - TReturnType DoNotDependOnAny(IEnumerable patterns, bool useRegularExpressions = false); + TReturnType DoNotDependOnAny( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType DoNotDependOnAny(Type firstType, params Type[] moreTypes); TReturnType DoNotDependOnAny(IType firstType, params IType[] moreTypes); TReturnType DoNotDependOnAny(IObjectProvider types); TReturnType DoNotDependOnAny(IEnumerable types); TReturnType DoNotDependOnAny(IEnumerable types); TReturnType DoNotHaveAnyAttributes(string pattern, bool useRegularExpressions = false); - TReturnType DoNotHaveAnyAttributes(IEnumerable patterns, bool useRegularExpressions = false); - TReturnType DoNotHaveAnyAttributes(Attribute firstAttribute, params Attribute[] moreAttributes); + TReturnType DoNotHaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ); + TReturnType DoNotHaveAnyAttributes( + Attribute firstAttribute, + params Attribute[] moreAttributes + ); TReturnType DoNotHaveAnyAttributes(Type firstAttribute, params Type[] moreAttributes); TReturnType DoNotHaveAnyAttributes(IObjectProvider attributes); TReturnType DoNotHaveAnyAttributes(IEnumerable attributes); TReturnType DoNotHaveAnyAttributes(IEnumerable attributes); TReturnType DoNotHaveAnyAttributesWithArguments(IEnumerable argumentValues); - TReturnType DoNotHaveAnyAttributesWithArguments(object firstArgumentValue, params object[] moreArgumentValues); - TReturnType DoNotHaveAttributeWithArguments(string attribute, IEnumerable argumentValues); - TReturnType DoNotHaveAttributeWithArguments(string attribute, object firstArgumentValue, params object[] moreArgumentValues); - TReturnType DoNotHaveAttributeWithArguments(Attribute attribute, IEnumerable argumentValues); - TReturnType DoNotHaveAttributeWithArguments(Attribute attribute, object firstArgumentValue, params object[] moreArgumentValues); - TReturnType DoNotHaveAttributeWithArguments(Type attribute, IEnumerable argumentValues); - TReturnType DoNotHaveAttributeWithArguments(Type attribute, object firstArgumentValue, params object[] moreArgumentValues); - TReturnType DoNotHaveAnyAttributesWithNamedArguments(IEnumerable<(string,object)> attributeArguments); - TReturnType DoNotHaveAnyAttributesWithNamedArguments((string,object) firstAttributeArgument, params (string,object)[] moreAttributeArguments); - TReturnType DoNotHaveAttributeWithNamedArguments(string attribute, IEnumerable<(string,object)> attributeArguments); - TReturnType DoNotHaveAttributeWithNamedArguments(string attribute, (string,object) firstAttributeArgument, params (string,object)[] moreAttributeArguments); - TReturnType DoNotHaveAttributeWithNamedArguments(Attribute attribute, IEnumerable<(string,object)> attributeArguments); - TReturnType DoNotHaveAttributeWithNamedArguments(Attribute attribute, (string,object) firstAttributeArgument, params (string,object)[] moreAttributeArguments); - TReturnType DoNotHaveAttributeWithNamedArguments(Type attribute, IEnumerable<(string,object)> attributeArguments); - TReturnType DoNotHaveAttributeWithNamedArguments(Type attribute, (string,object) firstAttributeArgument, params (string,object)[] moreAttributeArguments); + TReturnType DoNotHaveAnyAttributesWithArguments( + object firstArgumentValue, + params object[] moreArgumentValues + ); + TReturnType DoNotHaveAttributeWithArguments( + string attribute, + IEnumerable argumentValues + ); + TReturnType DoNotHaveAttributeWithArguments( + string attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ); + TReturnType DoNotHaveAttributeWithArguments( + Attribute attribute, + IEnumerable argumentValues + ); + TReturnType DoNotHaveAttributeWithArguments( + Attribute attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ); + TReturnType DoNotHaveAttributeWithArguments( + Type attribute, + IEnumerable argumentValues + ); + TReturnType DoNotHaveAttributeWithArguments( + Type attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ); + TReturnType DoNotHaveAnyAttributesWithNamedArguments( + IEnumerable<(string, object)> attributeArguments + ); + TReturnType DoNotHaveAnyAttributesWithNamedArguments( + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ); + TReturnType DoNotHaveAttributeWithNamedArguments( + string attribute, + IEnumerable<(string, object)> attributeArguments + ); + TReturnType DoNotHaveAttributeWithNamedArguments( + string attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ); + TReturnType DoNotHaveAttributeWithNamedArguments( + Attribute attribute, + IEnumerable<(string, object)> attributeArguments + ); + TReturnType DoNotHaveAttributeWithNamedArguments( + Attribute attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ); + TReturnType DoNotHaveAttributeWithNamedArguments( + Type attribute, + IEnumerable<(string, object)> attributeArguments + ); + TReturnType DoNotHaveAttributeWithNamedArguments( + Type attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ); TReturnType DoNotHaveName(string pattern, bool useRegularExpressions = false); TReturnType DoNotHaveFullName(string pattern, bool useRegularExpressions = false); TReturnType DoNotHaveNameStartingWith(string pattern); @@ -140,4 +252,4 @@ public interface IObjectPredicates where TRuleType : TReturnType AreNotProtectedInternal(); TReturnType AreNotPrivateProtected(); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/FieldMembersShould.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/FieldMembersShould.cs index ec00166f1..461846ffc 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/FieldMembersShould.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/FieldMembersShould.cs @@ -1,18 +1,18 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.FieldMembers { - public class FieldMembersShould : MembersShould, - IComplexFieldMemberConditions + public class FieldMembersShould + : MembersShould, + IComplexFieldMemberConditions { - public FieldMembersShould(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public FieldMembersShould(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/FieldMembersShouldConjunction.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/FieldMembersShouldConjunction.cs index 1be1b3a00..bbb285501 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/FieldMembersShouldConjunction.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/FieldMembersShouldConjunction.cs @@ -1,18 +1,21 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.FieldMembers { - public class FieldMembersShouldConjunction : ObjectsShouldConjunction + public class FieldMembersShouldConjunction + : ObjectsShouldConjunction< + FieldMembersShould, + FieldMembersShouldConjunctionWithDescription, + FieldMember + > { - public FieldMembersShouldConjunction(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public FieldMembersShouldConjunction(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/FieldMembersShouldConjunctionWithDescription.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/FieldMembersShouldConjunctionWithDescription.cs index 1395d4d88..61c0ef196 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/FieldMembersShouldConjunctionWithDescription.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/FieldMembersShouldConjunctionWithDescription.cs @@ -1,20 +1,19 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.FieldMembers { - public class - FieldMembersShouldConjunctionWithDescription : - ObjectsShouldConjunctionWithDescription + public class FieldMembersShouldConjunctionWithDescription + : ObjectsShouldConjunctionWithDescription { - public FieldMembersShouldConjunctionWithDescription(IArchRuleCreator ruleCreator) - : base(ruleCreator) - { - } + public FieldMembersShouldConjunctionWithDescription( + IArchRuleCreator ruleCreator + ) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/GivenFieldMembers.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/GivenFieldMembers.cs index 7a5a1b8ff..9bbd8395e 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/GivenFieldMembers.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/GivenFieldMembers.cs @@ -1,17 +1,17 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.FieldMembers { - public class GivenFieldMembers : GivenObjects + public class GivenFieldMembers + : GivenObjects { - public GivenFieldMembers(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenFieldMembers(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/GivenFieldMembersConjunction.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/GivenFieldMembersConjunction.cs index cb67681d7..4224567af 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/GivenFieldMembersConjunction.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/GivenFieldMembersConjunction.cs @@ -1,19 +1,22 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.FieldMembers { - public class - GivenFieldMembersConjunction : GivenObjectsConjunction + public class GivenFieldMembersConjunction + : GivenObjectsConjunction< + GivenFieldMembersThat, + FieldMembersShould, + GivenFieldMembersConjunctionWithDescription, + FieldMember + > { - public GivenFieldMembersConjunction(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenFieldMembersConjunction(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/GivenFieldMembersConjunctionWithDescription.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/GivenFieldMembersConjunctionWithDescription.cs index ed8728d6f..a6f336c98 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/GivenFieldMembersConjunctionWithDescription.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/GivenFieldMembersConjunctionWithDescription.cs @@ -1,20 +1,23 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.FieldMembers { - public class - GivenFieldMembersConjunctionWithDescription : GivenObjectsConjunctionWithDescription + public class GivenFieldMembersConjunctionWithDescription + : GivenObjectsConjunctionWithDescription< + GivenFieldMembersThat, + FieldMembersShould, + FieldMember + > { - public GivenFieldMembersConjunctionWithDescription(IArchRuleCreator ruleCreator) : base( - ruleCreator) - { - } + public GivenFieldMembersConjunctionWithDescription( + IArchRuleCreator ruleCreator + ) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/GivenFieldMembersThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/GivenFieldMembersThat.cs index 6a9099bed..8a6045cfe 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/GivenFieldMembersThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/GivenFieldMembersThat.cs @@ -1,18 +1,18 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.FieldMembers { - public class GivenFieldMembersThat : GivenMembersThat, - IFieldMemberPredicates + public class GivenFieldMembersThat + : GivenMembersThat, + IFieldMemberPredicates { - public GivenFieldMembersThat(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenFieldMembersThat(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/IComplexFieldMemberConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/IComplexFieldMemberConditions.cs index add3eac95..844d54caf 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/IComplexFieldMemberConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/IComplexFieldMemberConditions.cs @@ -1,16 +1,14 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.FieldMembers { - public interface IComplexFieldMemberConditions : - IComplexMemberConditions, - IFieldMemberConditions - { - } -} \ No newline at end of file + public interface IComplexFieldMemberConditions + : IComplexMemberConditions, + IFieldMemberConditions { } +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/IFieldMemberConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/IFieldMemberConditions.cs index 39996519c..f300b7a5b 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/IFieldMemberConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/IFieldMemberConditions.cs @@ -1,15 +1,14 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.FieldMembers { - public interface IFieldMemberConditions : IMemberConditions - where TRuleType : ICanBeAnalyzed - { - } -} \ No newline at end of file + public interface IFieldMemberConditions + : IMemberConditions + where TRuleType : ICanBeAnalyzed { } +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/IFieldMemberPredicates.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/IFieldMemberPredicates.cs index 947787949..654acdce4 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/IFieldMemberPredicates.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/IFieldMemberPredicates.cs @@ -1,16 +1,14 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.FieldMembers { - public interface - IFieldMemberPredicates : IMemberPredicates - where TRuleType : ICanBeAnalyzed - { - } -} \ No newline at end of file + public interface IFieldMemberPredicates + : IMemberPredicates + where TRuleType : ICanBeAnalyzed { } +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/ShouldRelateToFieldMembersThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/ShouldRelateToFieldMembersThat.cs index f2b668cb6..5fd6ec5a0 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/ShouldRelateToFieldMembersThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/FieldMembers/ShouldRelateToFieldMembersThat.cs @@ -1,21 +1,20 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.FieldMembers { - public class ShouldRelateToFieldMembersThat : - ShouldRelateToMembersThat, - IFieldMemberPredicates + public class ShouldRelateToFieldMembersThat + : ShouldRelateToMembersThat, + IFieldMemberPredicates where TRuleTypeShouldConjunction : SyntaxElement where TRuleType : ICanBeAnalyzed { - public ShouldRelateToFieldMembersThat(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public ShouldRelateToFieldMembersThat(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembers.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembers.cs index a7ac86847..5239ae06a 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembers.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembers.cs @@ -1,18 +1,21 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members { - public class GivenMembers : GivenObjects, - MembersShould, IMember> + public class GivenMembers + : GivenObjects< + GivenMembersThat, + MembersShould, + IMember + > { - public GivenMembers(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenMembers(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembersConjunction.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembersConjunction.cs index c3eb24b8a..51adf0df4 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembersConjunction.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembersConjunction.cs @@ -1,18 +1,22 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members { - public class GivenMembersConjunction : GivenObjectsConjunction, - MembersShould, GivenMembersConjunctionWithDescription, IMember> + public class GivenMembersConjunction + : GivenObjectsConjunction< + GivenMembersThat, + MembersShould, + GivenMembersConjunctionWithDescription, + IMember + > { - public GivenMembersConjunction(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenMembersConjunction(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembersConjunctionWithDescription.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembersConjunctionWithDescription.cs index 95fb28c12..a5f6ea620 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembersConjunctionWithDescription.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembersConjunctionWithDescription.cs @@ -1,19 +1,21 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members { - public class GivenMembersConjunctionWithDescription : GivenObjectsConjunctionWithDescription< - GivenMembersThat, - MembersShould, IMember> + public class GivenMembersConjunctionWithDescription + : GivenObjectsConjunctionWithDescription< + GivenMembersThat, + MembersShould, + IMember + > { - public GivenMembersConjunctionWithDescription(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenMembersConjunctionWithDescription(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembersThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembersThat.cs index ca72033ff..d8737365e 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembersThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/GivenMembersThat.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -12,39 +12,50 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Members { - public class GivenMembersThat : - GivenObjectsThat, - IMemberPredicates + public class GivenMembersThat + : GivenObjectsThat, + IMemberPredicates where TRuleType : IMember { // ReSharper disable once MemberCanBeProtected.Global - public GivenMembersThat(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenMembersThat(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } - public TGivenRuleTypeConjunction AreDeclaredIn(string pattern, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction AreDeclaredIn( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - MemberPredicatesDefinition.AreDeclaredIn(pattern, useRegularExpressions)); + MemberPredicatesDefinition.AreDeclaredIn(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction AreDeclaredIn(IEnumerable patterns, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction AreDeclaredIn( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - MemberPredicatesDefinition.AreDeclaredIn(patterns, useRegularExpressions)); + MemberPredicatesDefinition.AreDeclaredIn(patterns, useRegularExpressions) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction AreDeclaredIn(IType firstType, params IType[] moreTypes) { - _ruleCreator.AddPredicate(MemberPredicatesDefinition.AreDeclaredIn(firstType, moreTypes)); + _ruleCreator.AddPredicate( + MemberPredicatesDefinition.AreDeclaredIn(firstType, moreTypes) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction AreDeclaredIn(Type firstType, params Type[] moreTypes) { - _ruleCreator.AddPredicate(MemberPredicatesDefinition.AreDeclaredIn(firstType, moreTypes)); + _ruleCreator.AddPredicate( + MemberPredicatesDefinition.AreDeclaredIn(firstType, moreTypes) + ); return Create(_ruleCreator); } @@ -87,48 +98,71 @@ public TGivenRuleTypeConjunction AreImmutable() //Negations - public TGivenRuleTypeConjunction AreNotDeclaredIn(string pattern, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction AreNotDeclaredIn( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - MemberPredicatesDefinition.AreNotDeclaredIn(pattern, useRegularExpressions)); + MemberPredicatesDefinition.AreNotDeclaredIn( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction AreNotDeclaredIn(IEnumerable patterns, - bool useRegularExpressions = false) + public TGivenRuleTypeConjunction AreNotDeclaredIn( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - MemberPredicatesDefinition.AreNotDeclaredIn(patterns, useRegularExpressions)); + MemberPredicatesDefinition.AreNotDeclaredIn( + patterns, + useRegularExpressions + ) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction AreNotDeclaredIn(IType firstType, params IType[] moreTypes) { - _ruleCreator.AddPredicate(MemberPredicatesDefinition.AreNotDeclaredIn(firstType, moreTypes)); + _ruleCreator.AddPredicate( + MemberPredicatesDefinition.AreNotDeclaredIn(firstType, moreTypes) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction AreNotDeclaredIn(Type firstType, params Type[] moreTypes) { - _ruleCreator.AddPredicate(MemberPredicatesDefinition.AreNotDeclaredIn(firstType, moreTypes)); + _ruleCreator.AddPredicate( + MemberPredicatesDefinition.AreNotDeclaredIn(firstType, moreTypes) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction AreNotDeclaredIn(IObjectProvider types) { - _ruleCreator.AddPredicate(MemberPredicatesDefinition.AreNotDeclaredIn(types)); + _ruleCreator.AddPredicate( + MemberPredicatesDefinition.AreNotDeclaredIn(types) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction AreNotDeclaredIn(IEnumerable types) { - _ruleCreator.AddPredicate(MemberPredicatesDefinition.AreNotDeclaredIn(types)); + _ruleCreator.AddPredicate( + MemberPredicatesDefinition.AreNotDeclaredIn(types) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction AreNotDeclaredIn(IEnumerable types) { - _ruleCreator.AddPredicate(MemberPredicatesDefinition.AreNotDeclaredIn(types)); + _ruleCreator.AddPredicate( + MemberPredicatesDefinition.AreNotDeclaredIn(types) + ); return Create(_ruleCreator); } @@ -137,7 +171,7 @@ public TGivenRuleTypeConjunction AreNotStatic() _ruleCreator.AddPredicate(MemberPredicatesDefinition.AreNotStatic()); return Create(_ruleCreator); } - + public TGivenRuleTypeConjunction AreNotReadOnly() { _ruleCreator.AddPredicate(MemberPredicatesDefinition.AreNotReadOnly()); @@ -150,4 +184,4 @@ public TGivenRuleTypeConjunction AreNotImmutable() return Create(_ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/IComplexMemberConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/IComplexMemberConditions.cs index 5e196c0d7..c07cfceb9 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/IComplexMemberConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/IComplexMemberConditions.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -9,19 +9,25 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Members { - public interface - IComplexMemberConditions : - IComplexObjectConditions, + public interface IComplexMemberConditions + : IComplexObjectConditions, IMemberConditions where TRuleType : IMember where TRuleTypeShouldConjunction : SyntaxElement { - ShouldRelateToTypesThat BeDeclaredInTypesThat(); - + ShouldRelateToTypesThat< + TRuleTypeShouldConjunction, + IType, + TRuleType + > BeDeclaredInTypesThat(); //Negations - ShouldRelateToTypesThat NotBeDeclaredInTypesThat(); + ShouldRelateToTypesThat< + TRuleTypeShouldConjunction, + IType, + TRuleType + > NotBeDeclaredInTypesThat(); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/IMemberConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/IMemberConditions.cs index b8f66e9fe..563673905 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/IMemberConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/IMemberConditions.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -10,7 +10,8 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Members { - public interface IMemberConditions : IObjectConditions + public interface IMemberConditions + : IObjectConditions where TRuleType : ICanBeAnalyzed { TReturnType BeDeclaredIn(string pattern, bool useRegularExpressions = false); @@ -23,11 +24,13 @@ public interface IMemberConditions : IObjectCond TReturnType BeStatic(); TReturnType BeImmutable(); - //Negations TReturnType NotBeDeclaredIn(string pattern, bool useRegularExpressions = false); - TReturnType NotBeDeclaredIn(IEnumerable patterns, bool useRegularExpressions = false); + TReturnType NotBeDeclaredIn( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType NotBeDeclaredIn(IType firstType, params IType[] moreTypes); TReturnType NotBeDeclaredIn(Type firstType, params Type[] moreTypes); TReturnType NotBeDeclaredIn(IObjectProvider types); @@ -36,4 +39,4 @@ public interface IMemberConditions : IObjectCond TReturnType NotBeStatic(); TReturnType NotBeImmutable(); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/IMemberPredicates.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/IMemberPredicates.cs index b3d2707c4..2369a5b03 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/IMemberPredicates.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/IMemberPredicates.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -10,12 +10,15 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Members { - public interface - IMemberPredicates : IObjectPredicates + public interface IMemberPredicates + : IObjectPredicates where TRuleType : ICanBeAnalyzed { TRuleTypeConjunction AreDeclaredIn(string pattern, bool useRegularExpressions = false); - TRuleTypeConjunction AreDeclaredIn(IEnumerable patterns, bool useRegularExpressions = false); + TRuleTypeConjunction AreDeclaredIn( + IEnumerable patterns, + bool useRegularExpressions = false + ); TRuleTypeConjunction AreDeclaredIn(IType firstType, params IType[] moreTypes); TRuleTypeConjunction AreDeclaredIn(Type firstType, params Type[] moreTypes); TRuleTypeConjunction AreDeclaredIn(IObjectProvider types); @@ -28,7 +31,10 @@ public interface TRuleTypeConjunction AreNotDeclaredIn(string pattern, bool useRegularExpressions = false); - TRuleTypeConjunction AreNotDeclaredIn(IEnumerable patterns, bool useRegularExpressions = false); + TRuleTypeConjunction AreNotDeclaredIn( + IEnumerable patterns, + bool useRegularExpressions = false + ); TRuleTypeConjunction AreNotDeclaredIn(IType firstType, params IType[] moreTypes); TRuleTypeConjunction AreNotDeclaredIn(Type firstType, params Type[] moreTypes); TRuleTypeConjunction AreNotDeclaredIn(IObjectProvider types); @@ -37,4 +43,4 @@ public interface TRuleTypeConjunction AreNotStatic(); TRuleTypeConjunction AreNotImmutable(); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberConditionsDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberConditionsDefinition.cs index 69bad5680..837f33702 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberConditionsDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberConditionsDefinition.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -14,24 +14,37 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Members { - public static class MemberConditionsDefinition where TRuleType : IMember + public static class MemberConditionsDefinition + where TRuleType : IMember { - public static ICondition BeDeclaredIn(string pattern, bool useRegularExpressions = false) + public static ICondition BeDeclaredIn( + string pattern, + bool useRegularExpressions = false + ) { - return new SimpleCondition(member => member.IsDeclaredIn(pattern, useRegularExpressions), + return new SimpleCondition( + member => member.IsDeclaredIn(pattern, useRegularExpressions), member => "is declared in " + member.DeclaringType.FullName, - "be declared in types with full name " + (useRegularExpressions ? "matching " : "") + "\"" + - pattern + "\""); + "be declared in types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static ICondition BeDeclaredIn(IEnumerable patterns, - bool useRegularExpressions = false) + public static ICondition BeDeclaredIn( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Condition(TRuleType ruleType) { - return patternList.Any(pattern => ruleType.IsDeclaredIn(pattern, useRegularExpressions)); + return patternList.Any(pattern => + ruleType.IsDeclaredIn(pattern, useRegularExpressions) + ); } string description; @@ -42,37 +55,52 @@ bool Condition(TRuleType ruleType) else { var firstPattern = patternList.First(); - description = patternList.Where(obj => !obj.Equals(firstPattern)).Distinct().Aggregate( - "be declared in types with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", - (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(obj => !obj.Equals(firstPattern)) + .Distinct() + .Aggregate( + "be declared in types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } - return new SimpleCondition(Condition, - member => "is declared in " + member.DeclaringType.FullName, description); + return new SimpleCondition( + Condition, + member => "is declared in " + member.DeclaringType.FullName, + description + ); } public static ICondition BeDeclaredIn(IType firstType, params IType[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return BeDeclaredIn(types); } public static ICondition BeDeclaredIn(Type firstType, params Type[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return BeDeclaredIn(types); } public static ICondition BeDeclaredIn(IObjectProvider objectProvider) { - IEnumerable Condition(IEnumerable methods, Architecture architecture) + IEnumerable Condition( + IEnumerable methods, + Architecture architecture + ) { var typeList = objectProvider.GetObjects(architecture).ToList(); var methodList = methods.ToList(); - var passedObjects = methodList.Where(method => typeList.Contains(method.DeclaringType)).ToList(); + var passedObjects = methodList + .Where(method => typeList.Contains(method.DeclaringType)) + .ToList(); foreach (var failedObject in methodList.Except(passedObjects)) { var failDescription = "is declared in " + failedObject.DeclaringType.FullName; @@ -96,7 +124,9 @@ public static ICondition BeDeclaredIn(IEnumerable types) IEnumerable Condition(IEnumerable methods) { var methodList = methods.ToList(); - var passedObjects = methodList.Where(method => typeList.Contains(method.DeclaringType)).ToList(); + var passedObjects = methodList + .Where(method => typeList.Contains(method.DeclaringType)) + .ToList(); foreach (var failedObject in methodList.Except(passedObjects)) { var failDescription = "is declared in " + failedObject.DeclaringType.FullName; @@ -117,9 +147,13 @@ IEnumerable Condition(IEnumerable methods) else { var firstType = typeList.First(); - description = typeList.Where(obj => !obj.Equals(firstType)).Distinct().Aggregate( - "be declared in \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(obj => !obj.Equals(firstType)) + .Distinct() + .Aggregate( + "be declared in \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new EnumerableCondition(Condition, description); @@ -129,7 +163,10 @@ public static ICondition BeDeclaredIn(IEnumerable types) { var typeList = types.ToList(); - IEnumerable Condition(IEnumerable methods, Architecture architecture) + IEnumerable Condition( + IEnumerable methods, + Architecture architecture + ) { var archUnitTypeList = new List(); foreach (var type in typeList) @@ -146,7 +183,8 @@ IEnumerable Condition(IEnumerable methods, Architect } var methodList = methods.ToList(); - var passedObjects = methodList.Where(method => archUnitTypeList.Contains(method.DeclaringType)) + var passedObjects = methodList + .Where(method => archUnitTypeList.Contains(method.DeclaringType)) .ToList(); foreach (var failedObject in methodList.Except(passedObjects)) { @@ -168,9 +206,13 @@ IEnumerable Condition(IEnumerable methods, Architect else { var firstType = typeList.First(); - description = typeList.Where(obj => obj != firstType).Distinct().Aggregate( - "be declared in \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(obj => obj != firstType) + .Distinct() + .Aggregate( + "be declared in \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new ArchitectureCondition(Condition, description); @@ -178,20 +220,29 @@ IEnumerable Condition(IEnumerable methods, Architect public static ICondition BeStatic() { - return new SimpleCondition(member => !member.IsStatic.HasValue || member.IsStatic.Value, - "be static", "is not static"); + return new SimpleCondition( + member => !member.IsStatic.HasValue || member.IsStatic.Value, + "be static", + "is not static" + ); } - + public static ICondition BeReadOnly() { - return new SimpleCondition(member => member.Writability == Writability.ReadOnly, - "be read only", "is not read only"); + return new SimpleCondition( + member => member.Writability == Writability.ReadOnly, + "be read only", + "is not read only" + ); } public static ICondition BeImmutable() { - return new SimpleCondition(member => member.Writability.IsImmutable(), - "be immutable", "is not immutable"); + return new SimpleCondition( + member => member.Writability.IsImmutable(), + "be immutable", + "is not immutable" + ); } //Relation Conditions @@ -199,30 +250,44 @@ public static ICondition BeImmutable() public static RelationCondition BeDeclaredInTypesThat() { - return new RelationCondition(BeDeclaredIn, "be declared in types that", - "is not declared in types that"); + return new RelationCondition( + BeDeclaredIn, + "be declared in types that", + "is not declared in types that" + ); } - //Negations - public static ICondition NotBeDeclaredIn(string pattern, bool useRegularExpressions = false) + public static ICondition NotBeDeclaredIn( + string pattern, + bool useRegularExpressions = false + ) { - return new SimpleCondition(member => !member.IsDeclaredIn(pattern, useRegularExpressions), + return new SimpleCondition( + member => !member.IsDeclaredIn(pattern, useRegularExpressions), member => "is declared in " + member.DeclaringType.FullName, - "not be declared in types with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + pattern + "\""); + "not be declared in types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static ICondition NotBeDeclaredIn(IEnumerable patterns, - bool useRegularExpressions = false) + public static ICondition NotBeDeclaredIn( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Condition(TRuleType ruleType) { - return patternList.All(pattern => !ruleType.IsDeclaredIn(pattern, useRegularExpressions)); + return patternList.All(pattern => + !ruleType.IsDeclaredIn(pattern, useRegularExpressions) + ); } string description; @@ -233,37 +298,55 @@ bool Condition(TRuleType ruleType) else { var firstPattern = patternList.First(); - description = patternList.Where(obj => !obj.Equals(firstPattern)).Distinct().Aggregate( - "not be declared in types with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", - (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(obj => !obj.Equals(firstPattern)) + .Distinct() + .Aggregate( + "not be declared in types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } - return new SimpleCondition(Condition, - member => "is declared in " + member.DeclaringType.FullName, description); + return new SimpleCondition( + Condition, + member => "is declared in " + member.DeclaringType.FullName, + description + ); } - public static ICondition NotBeDeclaredIn(IType firstType, params IType[] moreTypes) + public static ICondition NotBeDeclaredIn( + IType firstType, + params IType[] moreTypes + ) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return NotBeDeclaredIn(types); } public static ICondition NotBeDeclaredIn(Type firstType, params Type[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return NotBeDeclaredIn(types); } public static ICondition NotBeDeclaredIn(IObjectProvider objectProvider) { - IEnumerable Condition(IEnumerable methods, Architecture architecture) + IEnumerable Condition( + IEnumerable methods, + Architecture architecture + ) { var typeList = objectProvider.GetObjects(architecture).ToList(); var methodList = methods.ToList(); - var failedObjects = methodList.Where(method => typeList.Contains(method.DeclaringType)).ToList(); + var failedObjects = methodList + .Where(method => typeList.Contains(method.DeclaringType)) + .ToList(); foreach (var failedObject in failedObjects) { var failDescription = "is declared in " + failedObject.DeclaringType.FullName; @@ -287,7 +370,9 @@ public static ICondition NotBeDeclaredIn(IEnumerable types) IEnumerable Condition(IEnumerable methods) { var methodList = methods.ToList(); - var failedObjects = methodList.Where(method => typeList.Contains(method.DeclaringType)).ToList(); + var failedObjects = methodList + .Where(method => typeList.Contains(method.DeclaringType)) + .ToList(); foreach (var failedObject in failedObjects) { var failDescription = "is declared in " + failedObject.DeclaringType.FullName; @@ -308,9 +393,13 @@ IEnumerable Condition(IEnumerable methods) else { var firstType = typeList.First(); - description = typeList.Where(obj => !obj.Equals(firstType)).Distinct().Aggregate( - "not be declared in \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(obj => !obj.Equals(firstType)) + .Distinct() + .Aggregate( + "not be declared in \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new EnumerableCondition(Condition, description); @@ -320,7 +409,10 @@ public static ICondition NotBeDeclaredIn(IEnumerable types) { var typeList = types.ToList(); - IEnumerable Condition(IEnumerable methods, Architecture architecture) + IEnumerable Condition( + IEnumerable methods, + Architecture architecture + ) { var archUnitTypeList = new List(); foreach (var type in typeList) @@ -337,7 +429,8 @@ IEnumerable Condition(IEnumerable methods, Architect } var methodList = methods.ToList(); - var failedObjects = methodList.Where(method => archUnitTypeList.Contains(method.DeclaringType)) + var failedObjects = methodList + .Where(method => archUnitTypeList.Contains(method.DeclaringType)) .ToList(); foreach (var failedObject in failedObjects) { @@ -359,9 +452,13 @@ IEnumerable Condition(IEnumerable methods, Architect else { var firstType = typeList.First(); - description = typeList.Where(obj => obj != firstType).Distinct().Aggregate( - "not be declared in \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(obj => obj != firstType) + .Distinct() + .Aggregate( + "not be declared in \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new ArchitectureCondition(Condition, description); @@ -369,20 +466,29 @@ IEnumerable Condition(IEnumerable methods, Architect public static ICondition NotBeStatic() { - return new SimpleCondition(member => !member.IsStatic.HasValue || !member.IsStatic.Value, - "not be static", "is static"); + return new SimpleCondition( + member => !member.IsStatic.HasValue || !member.IsStatic.Value, + "not be static", + "is static" + ); } - + public static ICondition NotBeReadOnly() { - return new SimpleCondition(member => member.Writability != Writability.ReadOnly, - "not be read only", "is read only"); + return new SimpleCondition( + member => member.Writability != Writability.ReadOnly, + "not be read only", + "is read only" + ); } public static ICondition NotBeImmutable() { - return new SimpleCondition(member => !member.Writability.IsImmutable(), - "not be immutable", "is immutable"); + return new SimpleCondition( + member => !member.Writability.IsImmutable(), + "not be immutable", + "is immutable" + ); } //Relation Condition Negations @@ -390,8 +496,11 @@ public static ICondition NotBeImmutable() public static RelationCondition NotBeDeclaredInTypesThat() { - return new RelationCondition(NotBeDeclaredIn, "not be declared in types that", - "is declared in types that"); + return new RelationCondition( + NotBeDeclaredIn, + "not be declared in types that", + "is declared in types that" + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberPredicatesDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberPredicatesDefinition.cs index d9f6ac714..1771751b1 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberPredicatesDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberPredicatesDefinition.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -14,22 +14,36 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Members { - public static class MemberPredicatesDefinition where T : IMember + public static class MemberPredicatesDefinition + where T : IMember { - public static IPredicate AreDeclaredIn(string pattern, bool useRegularExpressions = false) + public static IPredicate AreDeclaredIn( + string pattern, + bool useRegularExpressions = false + ) { - return new SimplePredicate(member => member.IsDeclaredIn(pattern, useRegularExpressions), - "are declared in types with full name " + (useRegularExpressions ? "matching " : "") + "\"" + - pattern + "\""); + return new SimplePredicate( + member => member.IsDeclaredIn(pattern, useRegularExpressions), + "are declared in types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static IPredicate AreDeclaredIn(IEnumerable patterns, bool useRegularExpressions = false) + public static IPredicate AreDeclaredIn( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Condition(T ruleType) { - return patternList.Any(pattern => ruleType.IsDeclaredIn(pattern, useRegularExpressions)); + return patternList.Any(pattern => + ruleType.IsDeclaredIn(pattern, useRegularExpressions) + ); } string description; @@ -40,9 +54,17 @@ bool Condition(T ruleType) else { var firstPattern = patternList.First(); - description = patternList.Where(obj => !obj.Equals(firstPattern)).Distinct().Aggregate( - "are declared in types with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(obj => !obj.Equals(firstPattern)) + .Distinct() + .Aggregate( + "are declared in types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimplePredicate(Condition, description); @@ -50,14 +72,14 @@ bool Condition(T ruleType) public static IPredicate AreDeclaredIn(IType firstType, params IType[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return AreDeclaredIn(types); } public static IPredicate AreDeclaredIn(Type firstType, params Type[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return AreDeclaredIn(types); } @@ -91,9 +113,13 @@ IEnumerable Condition(IEnumerable members) else { var firstType = typeList.First(); - description = typeList.Where(obj => !obj.Equals(firstType)).Distinct().Aggregate( - "are declared in \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(obj => !obj.Equals(firstType)) + .Distinct() + .Aggregate( + "are declared in \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new EnumerablePredicate(Condition, description); @@ -118,7 +144,9 @@ IEnumerable Condition(IEnumerable members, Architecture architecture) //ignore, can't have a dependency anyways } } - return members.Intersect(archUnitTypeList.SelectMany(type => type.Members).OfType()); + return members.Intersect( + archUnitTypeList.SelectMany(type => type.Members).OfType() + ); } string description; @@ -129,9 +157,13 @@ IEnumerable Condition(IEnumerable members, Architecture architecture) else { var firstType = typeList.First(); - description = typeList.Where(obj => obj != firstType).Distinct().Aggregate( - "are declared in \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(obj => obj != firstType) + .Distinct() + .Aggregate( + "are declared in \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new ArchitecturePredicate(Condition, description); @@ -139,36 +171,58 @@ IEnumerable Condition(IEnumerable members, Architecture architecture) public static IPredicate AreStatic() { - return new SimplePredicate(member => member.IsStatic.HasValue && member.IsStatic.Value, "are static"); + return new SimplePredicate( + member => member.IsStatic.HasValue && member.IsStatic.Value, + "are static" + ); } - + public static IPredicate AreReadOnly() { - return new SimplePredicate(member => member.Writability == Writability.ReadOnly, "are read only"); + return new SimplePredicate( + member => member.Writability == Writability.ReadOnly, + "are read only" + ); } public static IPredicate AreImmutable() { - return new SimplePredicate(member => member.Writability.IsImmutable(), "are immutable"); + return new SimplePredicate( + member => member.Writability.IsImmutable(), + "are immutable" + ); } //Negations - public static IPredicate AreNotDeclaredIn(string pattern, bool useRegularExpressions = false) + public static IPredicate AreNotDeclaredIn( + string pattern, + bool useRegularExpressions = false + ) { - return new SimplePredicate(member => !member.IsDeclaredIn(pattern, useRegularExpressions), - "are not declared in types with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + pattern + "\""); + return new SimplePredicate( + member => !member.IsDeclaredIn(pattern, useRegularExpressions), + "are not declared in types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static IPredicate AreNotDeclaredIn(IEnumerable patterns, bool useRegularExpressions = false) + public static IPredicate AreNotDeclaredIn( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Condition(T ruleType) { - return patternList.All(pattern => !ruleType.IsDeclaredIn(pattern, useRegularExpressions)); + return patternList.All(pattern => + !ruleType.IsDeclaredIn(pattern, useRegularExpressions) + ); } string description; @@ -179,9 +233,17 @@ bool Condition(T ruleType) else { var firstPattern = patternList.First(); - description = patternList.Where(obj => !obj.Equals(firstPattern)).Distinct().Aggregate( - "are not declared in types with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(obj => !obj.Equals(firstPattern)) + .Distinct() + .Aggregate( + "are not declared in types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimplePredicate(Condition, description); @@ -189,14 +251,14 @@ bool Condition(T ruleType) public static IPredicate AreNotDeclaredIn(IType firstType, params IType[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return AreNotDeclaredIn(types); } public static IPredicate AreNotDeclaredIn(Type firstType, params Type[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return AreNotDeclaredIn(types); } @@ -230,9 +292,13 @@ IEnumerable Condition(IEnumerable members) else { var firstType = typeList.First(); - description = typeList.Where(obj => !obj.Equals(firstType)).Distinct().Aggregate( - "are not declared in \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(obj => !obj.Equals(firstType)) + .Distinct() + .Aggregate( + "are not declared in \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new EnumerablePredicate(Condition, description); @@ -257,7 +323,9 @@ IEnumerable Condition(IEnumerable members, Architecture architecture) //ignore, can't have a dependency anyways } } - return members.Except(archUnitTypeList.SelectMany(type => type.Members).OfType()); + return members.Except( + archUnitTypeList.SelectMany(type => type.Members).OfType() + ); } string description; @@ -268,9 +336,13 @@ IEnumerable Condition(IEnumerable members, Architecture architecture) else { var firstType = typeList.First(); - description = typeList.Where(obj => obj != firstType).Distinct().Aggregate( - "are not declared in \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(obj => obj != firstType) + .Distinct() + .Aggregate( + "are not declared in \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new ArchitecturePredicate(Condition, description); @@ -278,19 +350,26 @@ IEnumerable Condition(IEnumerable members, Architecture architecture) public static IPredicate AreNotStatic() { - return new SimplePredicate(member => member.IsStatic.HasValue && !member.IsStatic.Value, - "are not static"); + return new SimplePredicate( + member => member.IsStatic.HasValue && !member.IsStatic.Value, + "are not static" + ); } - + public static IPredicate AreNotReadOnly() { - return new SimplePredicate(member => member.Writability == Writability.ReadOnly, - "are not read only"); + return new SimplePredicate( + member => member.Writability == Writability.ReadOnly, + "are not read only" + ); } public static IPredicate AreNotImmutable() { - return new SimplePredicate(member => !member.Writability.IsImmutable(), "are not immutablee"); + return new SimplePredicate( + member => !member.Writability.IsImmutable(), + "are not immutablee" + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MembersShould.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MembersShould.cs index 9c29b643f..6ce322882 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MembersShould.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MembersShould.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -12,40 +12,51 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Members { - public class MembersShould : - ObjectsShould, - IComplexMemberConditions + public class MembersShould + : ObjectsShould, + IComplexMemberConditions where TRuleType : IMember where TRuleTypeShouldConjunction : SyntaxElement { // ReSharper disable once MemberCanBeProtected.Global - public MembersShould(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public MembersShould(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } - public TRuleTypeShouldConjunction BeDeclaredIn(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction BeDeclaredIn( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - MemberConditionsDefinition.BeDeclaredIn(pattern, useRegularExpressions)); + MemberConditionsDefinition.BeDeclaredIn(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction BeDeclaredIn(IEnumerable patterns, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction BeDeclaredIn( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - MemberConditionsDefinition.BeDeclaredIn(patterns, useRegularExpressions)); + MemberConditionsDefinition.BeDeclaredIn(patterns, useRegularExpressions) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction BeDeclaredIn(IType firstType, params IType[] moreTypes) { - _ruleCreator.AddCondition(MemberConditionsDefinition.BeDeclaredIn(firstType, moreTypes)); + _ruleCreator.AddCondition( + MemberConditionsDefinition.BeDeclaredIn(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction BeDeclaredIn(Type firstType, params Type[] moreTypes) { - _ruleCreator.AddCondition(MemberConditionsDefinition.BeDeclaredIn(firstType, moreTypes)); + _ruleCreator.AddCondition( + MemberConditionsDefinition.BeDeclaredIn(firstType, moreTypes) + ); return Create(_ruleCreator); } @@ -72,7 +83,7 @@ public TRuleTypeShouldConjunction BeStatic() _ruleCreator.AddCondition(MemberConditionsDefinition.BeStatic()); return Create(_ruleCreator); } - + public TRuleTypeShouldConjunction BeReadOnly() { _ruleCreator.AddCondition(MemberConditionsDefinition.BeReadOnly()); @@ -87,42 +98,65 @@ public TRuleTypeShouldConjunction BeImmutable() //Relation Conditions - public ShouldRelateToTypesThat BeDeclaredInTypesThat() + public ShouldRelateToTypesThat< + TRuleTypeShouldConjunction, + IType, + TRuleType + > BeDeclaredInTypesThat() { - _ruleCreator.BeginComplexCondition(ArchRuleDefinition.Types(true), - MemberConditionsDefinition.BeDeclaredInTypesThat()); - return new ShouldRelateToTypesThat(_ruleCreator); + _ruleCreator.BeginComplexCondition( + ArchRuleDefinition.Types(true), + MemberConditionsDefinition.BeDeclaredInTypesThat() + ); + return new ShouldRelateToTypesThat( + _ruleCreator + ); } - //Negations - public TRuleTypeShouldConjunction NotBeDeclaredIn(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction NotBeDeclaredIn( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - MemberConditionsDefinition.NotBeDeclaredIn(pattern, useRegularExpressions)); + MemberConditionsDefinition.NotBeDeclaredIn( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotBeDeclaredIn(IEnumerable patterns, - bool useRegularExpressions = false) + public TRuleTypeShouldConjunction NotBeDeclaredIn( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - MemberConditionsDefinition.NotBeDeclaredIn(patterns, useRegularExpressions)); + MemberConditionsDefinition.NotBeDeclaredIn( + patterns, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotBeDeclaredIn(IType firstType, params IType[] moreTypes) { - _ruleCreator.AddCondition(MemberConditionsDefinition.NotBeDeclaredIn(firstType, moreTypes)); + _ruleCreator.AddCondition( + MemberConditionsDefinition.NotBeDeclaredIn(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction NotBeDeclaredIn(Type firstType, params Type[] moreTypes) { - _ruleCreator.AddCondition(MemberConditionsDefinition.NotBeDeclaredIn(firstType, moreTypes)); + _ruleCreator.AddCondition( + MemberConditionsDefinition.NotBeDeclaredIn(firstType, moreTypes) + ); return Create(_ruleCreator); } @@ -149,7 +183,7 @@ public TRuleTypeShouldConjunction NotBeStatic() _ruleCreator.AddCondition(MemberConditionsDefinition.NotBeStatic()); return Create(_ruleCreator); } - + public TRuleTypeShouldConjunction NotBeReadOnly() { _ruleCreator.AddCondition(MemberConditionsDefinition.NotBeReadOnly()); @@ -164,11 +198,19 @@ public TRuleTypeShouldConjunction NotBeImmutable() //Relation Condition Negations - public ShouldRelateToTypesThat NotBeDeclaredInTypesThat() + public ShouldRelateToTypesThat< + TRuleTypeShouldConjunction, + IType, + TRuleType + > NotBeDeclaredInTypesThat() { - _ruleCreator.BeginComplexCondition(ArchRuleDefinition.Types(true), - MemberConditionsDefinition.NotBeDeclaredInTypesThat()); - return new ShouldRelateToTypesThat(_ruleCreator); + _ruleCreator.BeginComplexCondition( + ArchRuleDefinition.Types(true), + MemberConditionsDefinition.NotBeDeclaredInTypesThat() + ); + return new ShouldRelateToTypesThat( + _ruleCreator + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MembersShouldConjunction.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MembersShouldConjunction.cs index b79d83e9a..38c8f53a3 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MembersShouldConjunction.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MembersShouldConjunction.cs @@ -1,19 +1,21 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members { - public class - MembersShouldConjunction : ObjectsShouldConjunction, - MembersShouldConjunctionWithDescription, IMember> + public class MembersShouldConjunction + : ObjectsShouldConjunction< + MembersShould, + MembersShouldConjunctionWithDescription, + IMember + > { - public MembersShouldConjunction(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public MembersShouldConjunction(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MembersShouldConjunctionWithDescription.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MembersShouldConjunctionWithDescription.cs index f7d2286c3..f8c36ea4d 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MembersShouldConjunctionWithDescription.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MembersShouldConjunctionWithDescription.cs @@ -1,19 +1,20 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members { - public class - MembersShouldConjunctionWithDescription : ObjectsShouldConjunctionWithDescription< - MembersShould, IMember> + public class MembersShouldConjunctionWithDescription + : ObjectsShouldConjunctionWithDescription< + MembersShould, + IMember + > { - public MembersShouldConjunctionWithDescription(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public MembersShouldConjunctionWithDescription(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/GivenMethodMembers.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/GivenMethodMembers.cs index 0eef8e4cb..fa2c3efaf 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/GivenMethodMembers.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/GivenMethodMembers.cs @@ -1,17 +1,17 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.MethodMembers { - public class GivenMethodMembers : GivenObjects + public class GivenMethodMembers + : GivenObjects { - public GivenMethodMembers(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenMethodMembers(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/GivenMethodMembersConjunction.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/GivenMethodMembersConjunction.cs index 4ac86cb08..9a195c504 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/GivenMethodMembersConjunction.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/GivenMethodMembersConjunction.cs @@ -1,19 +1,22 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.MethodMembers { - public class - GivenMethodMembersConjunction : GivenObjectsConjunction + public class GivenMethodMembersConjunction + : GivenObjectsConjunction< + GivenMethodMembersThat, + MethodMembersShould, + GivenMethodMembersConjunctionWithDescription, + MethodMember + > { - public GivenMethodMembersConjunction(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenMethodMembersConjunction(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/GivenMethodMembersConjunctionWithDescription.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/GivenMethodMembersConjunctionWithDescription.cs index 308334b00..c5bb0ba63 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/GivenMethodMembersConjunctionWithDescription.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/GivenMethodMembersConjunctionWithDescription.cs @@ -1,20 +1,23 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.MethodMembers { - public class - GivenMethodMembersConjunctionWithDescription : GivenObjectsConjunctionWithDescription + public class GivenMethodMembersConjunctionWithDescription + : GivenObjectsConjunctionWithDescription< + GivenMethodMembersThat, + MethodMembersShould, + MethodMember + > { - public GivenMethodMembersConjunctionWithDescription(IArchRuleCreator ruleCreator) : base( - ruleCreator) - { - } + public GivenMethodMembersConjunctionWithDescription( + IArchRuleCreator ruleCreator + ) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/GivenMethodMembersThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/GivenMethodMembersThat.cs index eab5db115..bfd76c9c5 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/GivenMethodMembersThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/GivenMethodMembersThat.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -10,12 +10,12 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Members.MethodMembers { - public class GivenMethodMembersThat : GivenMembersThat, - IMethodMemberPredicates + public class GivenMethodMembersThat + : GivenMembersThat, + IMethodMemberPredicates { - public GivenMethodMembersThat(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenMethodMembersThat(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } public GivenMethodMembersConjunction AreConstructors() { @@ -29,28 +29,41 @@ public GivenMethodMembersConjunction AreVirtual() return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction AreCalledBy(string pattern, bool useRegularExpressions = false) + public GivenMethodMembersConjunction AreCalledBy( + string pattern, + bool useRegularExpressions = false + ) { - _ruleCreator.AddPredicate(MethodMemberPredicatesDefinition.AreCalledBy(pattern, useRegularExpressions)); + _ruleCreator.AddPredicate( + MethodMemberPredicatesDefinition.AreCalledBy(pattern, useRegularExpressions) + ); return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction AreCalledBy(IEnumerable patterns, - bool useRegularExpressions = false) + public GivenMethodMembersConjunction AreCalledBy( + IEnumerable patterns, + bool useRegularExpressions = false + ) { - _ruleCreator.AddPredicate(MethodMemberPredicatesDefinition.AreCalledBy(patterns, useRegularExpressions)); + _ruleCreator.AddPredicate( + MethodMemberPredicatesDefinition.AreCalledBy(patterns, useRegularExpressions) + ); return new GivenMethodMembersConjunction(_ruleCreator); } public GivenMethodMembersConjunction AreCalledBy(IType firstType, params IType[] moreTypes) { - _ruleCreator.AddPredicate(MethodMemberPredicatesDefinition.AreCalledBy(firstType, moreTypes)); + _ruleCreator.AddPredicate( + MethodMemberPredicatesDefinition.AreCalledBy(firstType, moreTypes) + ); return new GivenMethodMembersConjunction(_ruleCreator); } public GivenMethodMembersConjunction AreCalledBy(Type type, params Type[] moreTypes) { - _ruleCreator.AddPredicate(MethodMemberPredicatesDefinition.AreCalledBy(type, moreTypes)); + _ruleCreator.AddPredicate( + MethodMemberPredicatesDefinition.AreCalledBy(type, moreTypes) + ); return new GivenMethodMembersConjunction(_ruleCreator); } @@ -72,104 +85,138 @@ public GivenMethodMembersConjunction AreCalledBy(IEnumerable types) return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo(string pattern, - bool useRegularExpressions = false) + public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(pattern, useRegularExpressions)); + MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo( + pattern, + useRegularExpressions + ) + ); return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo(IEnumerable patterns, - bool useRegularExpressions = false) + public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(patterns, useRegularExpressions)); + MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo( + patterns, + useRegularExpressions + ) + ); return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo(IType firstType, params IType[] moreTypes) + public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo( + IType firstType, + params IType[] moreTypes + ) { _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(firstType, moreTypes)); + MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(firstType, moreTypes) + ); return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo(Type type, params Type[] moreTypes) + public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo( + Type type, + params Type[] moreTypes + ) { _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(type, moreTypes)); + MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(type, moreTypes) + ); return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo(IObjectProvider types) + public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo( + IObjectProvider types + ) { _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(types)); + MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(types) + ); return new GivenMethodMembersConjunction(_ruleCreator); } public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo(IEnumerable types) { _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(types)); + MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(types) + ); return new GivenMethodMembersConjunction(_ruleCreator); } public GivenMethodMembersConjunction HaveDependencyInMethodBodyTo(IEnumerable types) { _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(types)); + MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(types) + ); return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction HaveReturnType(string pattern, bool useRegularExpressions = false) + public GivenMethodMembersConjunction HaveReturnType( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.HaveReturnType(pattern, useRegularExpressions)); + MethodMemberPredicatesDefinition.HaveReturnType(pattern, useRegularExpressions) + ); return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction HaveReturnType(IEnumerable patterns, - bool useRegularExpressions = false) + public GivenMethodMembersConjunction HaveReturnType( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.HaveReturnType(patterns, useRegularExpressions)); + MethodMemberPredicatesDefinition.HaveReturnType(patterns, useRegularExpressions) + ); return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction HaveReturnType(IType firstType, params IType[] moreTypes) + public GivenMethodMembersConjunction HaveReturnType( + IType firstType, + params IType[] moreTypes + ) { _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.HaveReturnType(firstType, moreTypes)); + MethodMemberPredicatesDefinition.HaveReturnType(firstType, moreTypes) + ); return new GivenMethodMembersConjunction(_ruleCreator); } public GivenMethodMembersConjunction HaveReturnType(IEnumerable types) { - _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.HaveReturnType(types)); + _ruleCreator.AddPredicate(MethodMemberPredicatesDefinition.HaveReturnType(types)); return new GivenMethodMembersConjunction(_ruleCreator); } public GivenMethodMembersConjunction HaveReturnType(IObjectProvider types) { - _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.HaveReturnType(types)); + _ruleCreator.AddPredicate(MethodMemberPredicatesDefinition.HaveReturnType(types)); return new GivenMethodMembersConjunction(_ruleCreator); } public GivenMethodMembersConjunction HaveReturnType(Type type, params Type[] moreTypes) { _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.HaveReturnType(type, moreTypes)); + MethodMemberPredicatesDefinition.HaveReturnType(type, moreTypes) + ); return new GivenMethodMembersConjunction(_ruleCreator); } public GivenMethodMembersConjunction HaveReturnType(IEnumerable types) { - _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.HaveReturnType(types)); + _ruleCreator.AddPredicate(MethodMemberPredicatesDefinition.HaveReturnType(types)); return new GivenMethodMembersConjunction(_ruleCreator); } @@ -188,28 +235,44 @@ public GivenMethodMembersConjunction AreNotVirtual() return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction AreNotCalledBy(string pattern, bool useRegularExpressions = false) + public GivenMethodMembersConjunction AreNotCalledBy( + string pattern, + bool useRegularExpressions = false + ) { - _ruleCreator.AddPredicate(MethodMemberPredicatesDefinition.AreNotCalledBy(pattern, useRegularExpressions)); + _ruleCreator.AddPredicate( + MethodMemberPredicatesDefinition.AreNotCalledBy(pattern, useRegularExpressions) + ); return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction AreNotCalledBy(IEnumerable patterns, - bool useRegularExpressions = false) + public GivenMethodMembersConjunction AreNotCalledBy( + IEnumerable patterns, + bool useRegularExpressions = false + ) { - _ruleCreator.AddPredicate(MethodMemberPredicatesDefinition.AreNotCalledBy(patterns, useRegularExpressions)); + _ruleCreator.AddPredicate( + MethodMemberPredicatesDefinition.AreNotCalledBy(patterns, useRegularExpressions) + ); return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction AreNotCalledBy(IType firstType, params IType[] moreTypes) + public GivenMethodMembersConjunction AreNotCalledBy( + IType firstType, + params IType[] moreTypes + ) { - _ruleCreator.AddPredicate(MethodMemberPredicatesDefinition.AreNotCalledBy(firstType, moreTypes)); + _ruleCreator.AddPredicate( + MethodMemberPredicatesDefinition.AreNotCalledBy(firstType, moreTypes) + ); return new GivenMethodMembersConjunction(_ruleCreator); } public GivenMethodMembersConjunction AreNotCalledBy(Type type, params Type[] moreTypes) { - _ruleCreator.AddPredicate(MethodMemberPredicatesDefinition.AreNotCalledBy(type, moreTypes)); + _ruleCreator.AddPredicate( + MethodMemberPredicatesDefinition.AreNotCalledBy(type, moreTypes) + ); return new GivenMethodMembersConjunction(_ruleCreator); } @@ -231,106 +294,149 @@ public GivenMethodMembersConjunction AreNotCalledBy(IEnumerable types) return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction DoNotHaveDependencyInMethodBodyTo(string pattern, - bool useRegularExpressions = false) + public GivenMethodMembersConjunction DoNotHaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(pattern, useRegularExpressions)); + MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo( + pattern, + useRegularExpressions + ) + ); return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction DoNotHaveDependencyInMethodBodyTo(IEnumerable patterns, - bool useRegularExpressions = false) + public GivenMethodMembersConjunction DoNotHaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(patterns, useRegularExpressions)); + MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo( + patterns, + useRegularExpressions + ) + ); return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction DoNotHaveDependencyInMethodBodyTo(IType firstType, - params IType[] moreTypes) + public GivenMethodMembersConjunction DoNotHaveDependencyInMethodBodyTo( + IType firstType, + params IType[] moreTypes + ) { _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(firstType, moreTypes)); + MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo( + firstType, + moreTypes + ) + ); return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction DoNotHaveDependencyInMethodBodyTo(Type type, params Type[] moreTypes) + public GivenMethodMembersConjunction DoNotHaveDependencyInMethodBodyTo( + Type type, + params Type[] moreTypes + ) { _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(type, moreTypes)); + MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(type, moreTypes) + ); return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction DoNotHaveDependencyInMethodBodyTo(IObjectProvider types) + public GivenMethodMembersConjunction DoNotHaveDependencyInMethodBodyTo( + IObjectProvider types + ) { _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(types)); + MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(types) + ); return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction DoNotHaveDependencyInMethodBodyTo(IEnumerable types) + public GivenMethodMembersConjunction DoNotHaveDependencyInMethodBodyTo( + IEnumerable types + ) { _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(types)); + MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(types) + ); return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction DoNotHaveDependencyInMethodBodyTo(IEnumerable types) + public GivenMethodMembersConjunction DoNotHaveDependencyInMethodBodyTo( + IEnumerable types + ) { _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(types)); + MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(types) + ); return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction DoNotHaveReturnType(string pattern, bool useRegularExpressions = false) + public GivenMethodMembersConjunction DoNotHaveReturnType( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.DoNotHaveReturnType(pattern, useRegularExpressions)); + MethodMemberPredicatesDefinition.DoNotHaveReturnType(pattern, useRegularExpressions) + ); return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction DoNotHaveReturnType(IEnumerable patterns, - bool useRegularExpressions = false) + public GivenMethodMembersConjunction DoNotHaveReturnType( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.DoNotHaveReturnType(patterns, useRegularExpressions)); + MethodMemberPredicatesDefinition.DoNotHaveReturnType( + patterns, + useRegularExpressions + ) + ); return new GivenMethodMembersConjunction(_ruleCreator); } - public GivenMethodMembersConjunction DoNotHaveReturnType(IType firstType, params IType[] moreTypes) + public GivenMethodMembersConjunction DoNotHaveReturnType( + IType firstType, + params IType[] moreTypes + ) { _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.DoNotHaveReturnType(firstType, moreTypes)); + MethodMemberPredicatesDefinition.DoNotHaveReturnType(firstType, moreTypes) + ); return new GivenMethodMembersConjunction(_ruleCreator); } public GivenMethodMembersConjunction DoNotHaveReturnType(IEnumerable types) { - _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.DoNotHaveReturnType(types)); + _ruleCreator.AddPredicate(MethodMemberPredicatesDefinition.DoNotHaveReturnType(types)); return new GivenMethodMembersConjunction(_ruleCreator); } public GivenMethodMembersConjunction DoNotHaveReturnType(IObjectProvider types) { - _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.DoNotHaveReturnType(types)); + _ruleCreator.AddPredicate(MethodMemberPredicatesDefinition.DoNotHaveReturnType(types)); return new GivenMethodMembersConjunction(_ruleCreator); } public GivenMethodMembersConjunction DoNotHaveReturnType(Type type, params Type[] moreTypes) { _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.DoNotHaveReturnType(type, moreTypes)); + MethodMemberPredicatesDefinition.DoNotHaveReturnType(type, moreTypes) + ); return new GivenMethodMembersConjunction(_ruleCreator); } public GivenMethodMembersConjunction DoNotHaveReturnType(IEnumerable types) { - _ruleCreator.AddPredicate( - MethodMemberPredicatesDefinition.DoNotHaveReturnType(types)); + _ruleCreator.AddPredicate(MethodMemberPredicatesDefinition.DoNotHaveReturnType(types)); return new GivenMethodMembersConjunction(_ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IComplexMethodMemberConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IComplexMethodMemberConditions.cs index 906a8851f..3e3563aa7 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IComplexMethodMemberConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IComplexMethodMemberConditions.cs @@ -1,16 +1,14 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.MethodMembers { - public interface IComplexMethodMemberConditions : - IComplexMemberConditions, - IMethodMemberConditions - { - } -} \ No newline at end of file + public interface IComplexMethodMemberConditions + : IComplexMemberConditions, + IMethodMemberConditions { } +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IMethodMemberConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IMethodMemberConditions.cs index 8efeabb7f..4620039a1 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IMethodMemberConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IMethodMemberConditions.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -10,7 +10,8 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Members.MethodMembers { - public interface IMethodMemberConditions : IMemberConditions + public interface IMethodMemberConditions + : IMemberConditions where TRuleType : ICanBeAnalyzed { TReturnType BeConstructor(); @@ -22,22 +23,30 @@ public interface IMethodMemberConditions : IMemb TReturnType BeCalledBy(IObjectProvider types); TReturnType BeCalledBy(IEnumerable types); TReturnType BeCalledBy(IEnumerable types); - TReturnType HaveDependencyInMethodBodyTo(string pattern, bool useRegularExpressions = false); - TReturnType HaveDependencyInMethodBodyTo(IEnumerable patterns, bool useRegularExpressions = false); + TReturnType HaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ); + TReturnType HaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType HaveDependencyInMethodBodyTo(IType firstType, params IType[] moreTypes); TReturnType HaveDependencyInMethodBodyTo(Type type, params Type[] moreTypes); TReturnType HaveDependencyInMethodBodyTo(IObjectProvider types); TReturnType HaveDependencyInMethodBodyTo(IEnumerable types); TReturnType HaveDependencyInMethodBodyTo(IEnumerable types); TReturnType HaveReturnType(string pattern, bool useRegularExpressions = false); - TReturnType HaveReturnType(IEnumerable patterns, bool useRegularExpressions = false); + TReturnType HaveReturnType( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType HaveReturnType(IType firstType, params IType[] moreTypes); TReturnType HaveReturnType(IEnumerable types); TReturnType HaveReturnType(IObjectProvider types); TReturnType HaveReturnType(Type type, params Type[] moreTypes); TReturnType HaveReturnType(IEnumerable types); - //Negations @@ -50,19 +59,28 @@ public interface IMethodMemberConditions : IMemb TReturnType NotBeCalledBy(IObjectProvider types); TReturnType NotBeCalledBy(IEnumerable types); TReturnType NotBeCalledBy(IEnumerable types); - TReturnType NotHaveDependencyInMethodBodyTo(string pattern, bool useRegularExpressions = false); - TReturnType NotHaveDependencyInMethodBodyTo(IEnumerable patterns, bool useRegularExpressions = false); + TReturnType NotHaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ); + TReturnType NotHaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType NotHaveDependencyInMethodBodyTo(IType firstType, params IType[] moreTypes); TReturnType NotHaveDependencyInMethodBodyTo(Type type, params Type[] moreTypes); TReturnType NotHaveDependencyInMethodBodyTo(IObjectProvider types); TReturnType NotHaveDependencyInMethodBodyTo(IEnumerable types); TReturnType NotHaveDependencyInMethodBodyTo(IEnumerable types); TReturnType NotHaveReturnType(string pattern, bool useRegularExpressions = false); - TReturnType NotHaveReturnType(IEnumerable patterns, bool useRegularExpressions = false); + TReturnType NotHaveReturnType( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType NotHaveReturnType(IType firstType, params IType[] moreTypes); TReturnType NotHaveReturnType(IEnumerable types); TReturnType NotHaveReturnType(IObjectProvider types); TReturnType NotHaveReturnType(Type type, params Type[] moreTypes); TReturnType NotHaveReturnType(IEnumerable types); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IMethodMemberPredicates.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IMethodMemberPredicates.cs index 0165f49cb..d4cfcbf36 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IMethodMemberPredicates.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/IMethodMemberPredicates.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -10,67 +10,97 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Members.MethodMembers { - public interface - IMethodMemberPredicates : IMemberPredicates where TRuleType : ICanBeAnalyzed + public interface IMethodMemberPredicates + : IMemberPredicates + where TRuleType : ICanBeAnalyzed { TRuleTypeConjunction AreConstructors(); TRuleTypeConjunction AreVirtual(); TRuleTypeConjunction AreCalledBy(string pattern, bool useRegularExpressions = false); - TRuleTypeConjunction AreCalledBy(IEnumerable patterns, bool useRegularExpressions = false); + TRuleTypeConjunction AreCalledBy( + IEnumerable patterns, + bool useRegularExpressions = false + ); TRuleTypeConjunction AreCalledBy(IType firstType, params IType[] moreTypes); TRuleTypeConjunction AreCalledBy(Type type, params Type[] moreTypes); TRuleTypeConjunction AreCalledBy(IObjectProvider types); TRuleTypeConjunction AreCalledBy(IEnumerable types); TRuleTypeConjunction AreCalledBy(IEnumerable types); - TRuleTypeConjunction HaveDependencyInMethodBodyTo(string pattern, bool useRegularExpressions = false); + TRuleTypeConjunction HaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ); - TRuleTypeConjunction HaveDependencyInMethodBodyTo(IEnumerable patterns, - bool useRegularExpressions = false); + TRuleTypeConjunction HaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ); - TRuleTypeConjunction HaveDependencyInMethodBodyTo(IType firstType, params IType[] moreTypes); + TRuleTypeConjunction HaveDependencyInMethodBodyTo( + IType firstType, + params IType[] moreTypes + ); TRuleTypeConjunction HaveDependencyInMethodBodyTo(Type type, params Type[] moreTypes); TRuleTypeConjunction HaveDependencyInMethodBodyTo(IObjectProvider types); TRuleTypeConjunction HaveDependencyInMethodBodyTo(IEnumerable types); TRuleTypeConjunction HaveDependencyInMethodBodyTo(IEnumerable types); TRuleTypeConjunction HaveReturnType(string pattern, bool useRegularExpressions = false); - TRuleTypeConjunction HaveReturnType(IEnumerable patterns, bool useRegularExpressions = false); + TRuleTypeConjunction HaveReturnType( + IEnumerable patterns, + bool useRegularExpressions = false + ); TRuleTypeConjunction HaveReturnType(IType firstType, params IType[] moreTypes); TRuleTypeConjunction HaveReturnType(IEnumerable types); TRuleTypeConjunction HaveReturnType(IObjectProvider types); TRuleTypeConjunction HaveReturnType(Type type, params Type[] moreTypes); TRuleTypeConjunction HaveReturnType(IEnumerable types); - //Negations TRuleTypeConjunction AreNoConstructors(); TRuleTypeConjunction AreNotVirtual(); TRuleTypeConjunction AreNotCalledBy(string pattern, bool useRegularExpressions = false); - TRuleTypeConjunction AreNotCalledBy(IEnumerable patterns, bool useRegularExpressions = false); + TRuleTypeConjunction AreNotCalledBy( + IEnumerable patterns, + bool useRegularExpressions = false + ); TRuleTypeConjunction AreNotCalledBy(IType firstType, params IType[] moreTypes); TRuleTypeConjunction AreNotCalledBy(Type type, params Type[] moreTypes); TRuleTypeConjunction AreNotCalledBy(IObjectProvider types); TRuleTypeConjunction AreNotCalledBy(IEnumerable types); TRuleTypeConjunction AreNotCalledBy(IEnumerable types); - TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo(string pattern, bool useRegularExpressions = false); + TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ); - TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo(IEnumerable patterns, - bool useRegularExpressions = false); + TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ); - TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo(IType firstType, params IType[] moreTypes); + TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo( + IType firstType, + params IType[] moreTypes + ); TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo(Type type, params Type[] moreTypes); TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo(IObjectProvider types); TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo(IEnumerable types); TRuleTypeConjunction DoNotHaveDependencyInMethodBodyTo(IEnumerable types); - TRuleTypeConjunction DoNotHaveReturnType(string pattern, bool useRegularExpressions = false); - TRuleTypeConjunction DoNotHaveReturnType(IEnumerable patterns, bool useRegularExpressions = false); + TRuleTypeConjunction DoNotHaveReturnType( + string pattern, + bool useRegularExpressions = false + ); + TRuleTypeConjunction DoNotHaveReturnType( + IEnumerable patterns, + bool useRegularExpressions = false + ); TRuleTypeConjunction DoNotHaveReturnType(IType firstType, params IType[] moreTypes); TRuleTypeConjunction DoNotHaveReturnType(IEnumerable types); TRuleTypeConjunction DoNotHaveReturnType(IObjectProvider types); TRuleTypeConjunction DoNotHaveReturnType(Type type, params Type[] moreTypes); TRuleTypeConjunction DoNotHaveReturnType(IEnumerable types); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberConditionsDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberConditionsDefinition.cs index 1dac4b526..42739d622 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberConditionsDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberConditionsDefinition.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -18,33 +18,54 @@ public static class MethodMemberConditionsDefinition { public static ICondition BeConstructor() { - return new SimpleCondition(member => member.IsConstructor(), "be a constructor", - "is no constructor"); + return new SimpleCondition( + member => member.IsConstructor(), + "be a constructor", + "is no constructor" + ); } public static ICondition BeVirtual() { - return new SimpleCondition(member => member.IsVirtual, "be virtual", "is not virtual"); + return new SimpleCondition( + member => member.IsVirtual, + "be virtual", + "is not virtual" + ); } - public static ICondition BeCalledBy(string pattern, bool useRegularExpressions = false) + public static ICondition BeCalledBy( + string pattern, + bool useRegularExpressions = false + ) { return new SimpleCondition( member => member.IsCalledBy(pattern, useRegularExpressions), - "be called by types with full name " + (useRegularExpressions ? "matching " : "") + "\"" + - pattern + "\"", - "is called by a type with full name " + (useRegularExpressions ? "matching " : "") + "\"" + - pattern + "\""); + "be called by types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"", + "is called by a type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static ICondition BeCalledBy(IEnumerable patterns, - bool useRegularExpressions = false) + public static ICondition BeCalledBy( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Condition(MethodMember ruleType) { - return patternList.Any(pattern => ruleType.IsCalledBy(pattern, useRegularExpressions)); + return patternList.Any(pattern => + ruleType.IsCalledBy(pattern, useRegularExpressions) + ); } string description; @@ -57,37 +78,53 @@ bool Condition(MethodMember ruleType) else { var firstPattern = patternList.First(); - description = patternList.Where(type => !type.Equals(firstPattern)).Distinct().Aggregate( - "be called by types with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", - (current, pattern) => current + " or \"" + pattern + "\""); - failDescription = patternList.Where(type => !type.Equals(firstPattern)).Distinct().Aggregate( - "is not called by types with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", - (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "be called by types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + failDescription = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "is not called by types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } - return new SimpleCondition(Condition, description, failDescription); } public static ICondition BeCalledBy(IType firstType, params IType[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return BeCalledBy(types); } public static ICondition BeCalledBy(Type firstType, params Type[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return BeCalledBy(types); } public static ICondition BeCalledBy(IObjectProvider objectProvider) { - IEnumerable Condition(IEnumerable methodMembers, Architecture architecture) + IEnumerable Condition( + IEnumerable methodMembers, + Architecture architecture + ) { var typeList = objectProvider.GetObjects(architecture).ToList(); var methodMemberList = methodMembers.ToList(); @@ -128,9 +165,13 @@ IEnumerable Condition(IEnumerable methodMembers) } else { - failDescription = typeList.Where(type => !type.Equals(firstType)).Distinct().Aggregate( - "is not called by \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + failDescription = typeList + .Where(type => !type.Equals(firstType)) + .Distinct() + .Aggregate( + "is not called by \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } foreach (var failedObject in methodMemberList.Except(passedObjects)) @@ -151,9 +192,13 @@ IEnumerable Condition(IEnumerable methodMembers) } else { - description = typeList.Where(type => !type.Equals(firstType)).Distinct().Aggregate( - "be called by \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => !type.Equals(firstType)) + .Distinct() + .Aggregate( + "be called by \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new EnumerableCondition(Condition, description); @@ -164,7 +209,10 @@ public static ICondition BeCalledBy(IEnumerable types) var typeList = types.ToList(); var firstType = typeList.First(); - IEnumerable Condition(IEnumerable methodMembers, Architecture architecture) + IEnumerable Condition( + IEnumerable methodMembers, + Architecture architecture + ) { var archUnitTypeList = new List(); foreach (var type in typeList) @@ -181,7 +229,9 @@ IEnumerable Condition(IEnumerable methodMembers, } var methodMemberList = methodMembers.ToList(); var passedObjects = methodMemberList - .Where(methodMember => methodMember.GetCallingTypes().Intersect(archUnitTypeList).Any()) + .Where(methodMember => + methodMember.GetCallingTypes().Intersect(archUnitTypeList).Any() + ) .ToList(); string failDescription; if (typeList.IsNullOrEmpty()) @@ -190,9 +240,13 @@ IEnumerable Condition(IEnumerable methodMembers, } else { - failDescription = typeList.Where(type => type != firstType).Distinct().Aggregate( - "is not called by \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + failDescription = typeList + .Where(type => type != firstType) + .Distinct() + .Aggregate( + "is not called by \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } foreach (var failedObject in methodMemberList.Except(passedObjects)) @@ -213,33 +267,50 @@ IEnumerable Condition(IEnumerable methodMembers, } else { - description = typeList.Where(type => type != firstType).Distinct().Aggregate( - "be called by \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => type != firstType) + .Distinct() + .Aggregate( + "be called by \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new ArchitectureCondition(Condition, description); } - public static ICondition HaveDependencyInMethodBodyTo(string pattern, - bool useRegularExpressions = false) + public static ICondition HaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ) { return new SimpleCondition( member => member.HasDependencyInMethodBodyTo(pattern, useRegularExpressions), - "have dependencies in method body to types with full name " + - (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\"", - "does not have dependencies in method body to a type with full name " + - (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\""); + "have dependencies in method body to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"", + "does not have dependencies in method body to a type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static ICondition HaveDependencyInMethodBodyTo(IEnumerable patterns, - bool useRegularExpressions = false) + public static ICondition HaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Condition(MethodMember ruleType) { - return patternList.Any(pattern => ruleType.HasDependencyInMethodBodyTo(pattern, useRegularExpressions)); + return patternList.Any(pattern => + ruleType.HasDependencyInMethodBodyTo(pattern, useRegularExpressions) + ); } string description; @@ -247,50 +318,81 @@ bool Condition(MethodMember ruleType) if (patternList.IsNullOrEmpty()) { description = "have dependency in method body to one of no types (always false)"; - failDescription = "does not have dependencies in method body to one of no types (always true)"; + failDescription = + "does not have dependencies in method body to one of no types (always true)"; } else { var firstPattern = patternList.First(); - description = patternList.Where(type => !type.Equals(firstPattern)).Distinct().Aggregate( - "have dependencies in method body to types with full name " + - (useRegularExpressions ? "matching " : "") + "\"" + firstPattern + "\"", - (current, pattern) => current + " or \"" + pattern + "\""); - failDescription = patternList.Where(type => !type.Equals(firstPattern)).Distinct().Aggregate( - "does not have dependencies in method body to types with full name " + - (useRegularExpressions ? "matching " : "") + "\"" + firstPattern + "\"", - (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "have dependencies in method body to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + failDescription = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "does not have dependencies in method body to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } - return new SimpleCondition(Condition, description, failDescription); } - public static ICondition HaveDependencyInMethodBodyTo(IType firstType, params IType[] moreTypes) + public static ICondition HaveDependencyInMethodBodyTo( + IType firstType, + params IType[] moreTypes + ) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return HaveDependencyInMethodBodyTo(types); } - public static ICondition HaveDependencyInMethodBodyTo(Type firstType, params Type[] moreTypes) + public static ICondition HaveDependencyInMethodBodyTo( + Type firstType, + params Type[] moreTypes + ) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return HaveDependencyInMethodBodyTo(types); } - public static ICondition HaveDependencyInMethodBodyTo(IObjectProvider objectProvider) + public static ICondition HaveDependencyInMethodBodyTo( + IObjectProvider objectProvider + ) { - IEnumerable Condition(IEnumerable methodMembers, Architecture architecture) + IEnumerable Condition( + IEnumerable methodMembers, + Architecture architecture + ) { var typeList = objectProvider.GetObjects(architecture).ToList(); var methodMemberList = methodMembers.ToList(); - var passedObjects = methodMemberList.Where(methodMember => - methodMember.GetBodyTypeMemberDependencies().Select(dependency => dependency.Target) - .Intersect(typeList).Any()) + var passedObjects = methodMemberList + .Where(methodMember => + methodMember + .GetBodyTypeMemberDependencies() + .Select(dependency => dependency.Target) + .Intersect(typeList) + .Any() + ) .ToList(); - var failDescription = "does not have dependencies in method body to " + objectProvider.Description; + var failDescription = + "does not have dependencies in method body to " + objectProvider.Description; foreach (var failedObject in methodMemberList.Except(passedObjects)) { yield return new ConditionResult(failedObject, false, failDescription); @@ -306,7 +408,9 @@ IEnumerable Condition(IEnumerable methodMembers, return new ArchitectureCondition(Condition, description); } - public static ICondition HaveDependencyInMethodBodyTo(IEnumerable types) + public static ICondition HaveDependencyInMethodBodyTo( + IEnumerable types + ) { var typeList = types.ToList(); var firstType = typeList.First(); @@ -314,20 +418,32 @@ public static ICondition HaveDependencyInMethodBodyTo(IEnumerable< IEnumerable Condition(IEnumerable methodMembers) { var methodMemberList = methodMembers.ToList(); - var passedObjects = methodMemberList.Where(methodMember => - methodMember.GetBodyTypeMemberDependencies().Select(dependency => dependency.Target) - .Intersect(typeList).Any()) + var passedObjects = methodMemberList + .Where(methodMember => + methodMember + .GetBodyTypeMemberDependencies() + .Select(dependency => dependency.Target) + .Intersect(typeList) + .Any() + ) .ToList(); string failDescription; if (typeList.IsNullOrEmpty()) { - failDescription = "does not have dependencies in method body to one of no types (always true)"; + failDescription = + "does not have dependencies in method body to one of no types (always true)"; } else { - failDescription = typeList.Where(type => !type.Equals(firstType)).Distinct().Aggregate( - "does not have dependencies in method body to \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + failDescription = typeList + .Where(type => !type.Equals(firstType)) + .Distinct() + .Aggregate( + "does not have dependencies in method body to \"" + + firstType.FullName + + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } foreach (var failedObject in methodMemberList.Except(passedObjects)) @@ -348,9 +464,13 @@ IEnumerable Condition(IEnumerable methodMembers) } else { - description = typeList.Where(type => !type.Equals(firstType)).Distinct().Aggregate( - "have dependencies in method body to \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => !type.Equals(firstType)) + .Distinct() + .Aggregate( + "have dependencies in method body to \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new EnumerableCondition(Condition, description); @@ -361,7 +481,10 @@ public static ICondition HaveDependencyInMethodBodyTo(IEnumerable< var typeList = types.ToList(); var firstType = typeList.First(); - IEnumerable Condition(IEnumerable methodMembers, Architecture architecture) + IEnumerable Condition( + IEnumerable methodMembers, + Architecture architecture + ) { var archUnitTypeList = new List(); foreach (var type in typeList) @@ -377,20 +500,32 @@ IEnumerable Condition(IEnumerable methodMembers, } } var methodMemberList = methodMembers.ToList(); - var passedObjects = methodMemberList.Where(methodMember => - methodMember.GetBodyTypeMemberDependencies().Select(dependency => dependency.Target) - .Intersect(archUnitTypeList).Any()) + var passedObjects = methodMemberList + .Where(methodMember => + methodMember + .GetBodyTypeMemberDependencies() + .Select(dependency => dependency.Target) + .Intersect(archUnitTypeList) + .Any() + ) .ToList(); string failDescription; if (typeList.IsNullOrEmpty()) { - failDescription = "does not have dependencies in method body to one of no types (always true)"; + failDescription = + "does not have dependencies in method body to one of no types (always true)"; } else { - failDescription = typeList.Where(type => type != firstType).Distinct().Aggregate( - "does not have dependencies in method body to \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + failDescription = typeList + .Where(type => type != firstType) + .Distinct() + .Aggregate( + "does not have dependencies in method body to \"" + + firstType.FullName + + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } foreach (var failedObject in methodMemberList.Except(passedObjects)) @@ -411,50 +546,80 @@ IEnumerable Condition(IEnumerable methodMembers, } else { - description = typeList.Where(type => type != firstType).Distinct().Aggregate( - "have dependencies in method body to \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => type != firstType) + .Distinct() + .Aggregate( + "have dependencies in method body to \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new ArchitectureCondition(Condition, description); } - public static ICondition HaveReturnType(string pattern, bool useRegularExpressions = false) + public static ICondition HaveReturnType( + string pattern, + bool useRegularExpressions = false + ) { - var description = "have return type with full name " + - (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\""; - - var failDescription = "does not have return type with full name " + - (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\""; + var description = + "have return type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\""; + + var failDescription = + "does not have return type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\""; return new SimpleCondition( - member => member.ReturnType.FullNameMatches(pattern, useRegularExpressions), description, - failDescription); + member => member.ReturnType.FullNameMatches(pattern, useRegularExpressions), + description, + failDescription + ); } - public static ICondition HaveReturnType(IEnumerable patterns, - bool useRegularExpressions = false) + public static ICondition HaveReturnType( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternsArray = patterns.ToArray(); - var description = "have return type with full name " + - (useRegularExpressions ? "matching " : "") + "\"" + - string.Join("\" or \"", patternsArray) + "\""; - - var failDescription = "does not have return type with full name " + - (useRegularExpressions ? "matching " : "") + "\"" + - string.Join("\" or \"", patternsArray) + "\""; + var description = + "have return type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + string.Join("\" or \"", patternsArray) + + "\""; + + var failDescription = + "does not have return type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + string.Join("\" or \"", patternsArray) + + "\""; bool Condition(MethodMember member) { - return patternsArray.Any(pattern => member.ReturnType.FullNameMatches(pattern, useRegularExpressions)); + return patternsArray.Any(pattern => + member.ReturnType.FullNameMatches(pattern, useRegularExpressions) + ); } return new SimpleCondition(Condition, description, failDescription); } - public static ICondition HaveReturnType(IType firstType, params IType[] moreTypes) + public static ICondition HaveReturnType( + IType firstType, + params IType[] moreTypes + ) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return HaveReturnType(types); } @@ -463,30 +628,42 @@ public static ICondition HaveReturnType(IEnumerable types) { var typeList = types.ToList(); var typeStringList = typeList.Select(type => type.FullName).ToList(); - var description = "have return type \"" + string.Join("\" or \"", typeStringList) + "\""; + var description = + "have return type \"" + string.Join("\" or \"", typeStringList) + "\""; bool Condition(MethodMember member) { return typeList.Any(type => member.ReturnType.FullNameMatches(type.FullName)); } - return new SimpleCondition(Condition, - member => "has return type \"" + member.ReturnType.FullName + "\"", description); + return new SimpleCondition( + Condition, + member => "has return type \"" + member.ReturnType.FullName + "\"", + description + ); } public static ICondition HaveReturnType(IObjectProvider types) { - IEnumerable Condition(IEnumerable methodMembers, Architecture architecture) + IEnumerable Condition( + IEnumerable methodMembers, + Architecture architecture + ) { var typeList = types.GetObjects(architecture).ToList(); var methodMemberList = methodMembers.ToList(); - var passedObjects = methodMemberList.Where(methodMember => - typeList.Any(type => methodMember.ReturnType.FullNameMatches(type.FullName))) + var passedObjects = methodMemberList + .Where(methodMember => + typeList.Any(type => methodMember.ReturnType.FullNameMatches(type.FullName)) + ) .ToList(); foreach (var failedObject in methodMemberList.Except(passedObjects)) { - yield return new ConditionResult(failedObject, false, - "has return type \"" + failedObject.ReturnType.FullName + "\""); + yield return new ConditionResult( + failedObject, + false, + "has return type \"" + failedObject.ReturnType.FullName + "\"" + ); } foreach (var passedObject in passedObjects) @@ -499,9 +676,12 @@ IEnumerable Condition(IEnumerable methodMembers, return new ArchitectureCondition(Condition, description); } - public static ICondition HaveReturnType(Type firstType, params Type[] moreTypes) + public static ICondition HaveReturnType( + Type firstType, + params Type[] moreTypes + ) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return HaveReturnType(types); } @@ -510,40 +690,57 @@ public static ICondition HaveReturnType(IEnumerable types) { var typeList = types.ToList(); var typeStringList = typeList.Select(type => type.ToString()).ToList(); - var description = "have return type \"" + string.Join("\" or \"", typeStringList) + "\""; + var description = + "have return type \"" + string.Join("\" or \"", typeStringList) + "\""; bool Condition(MethodMember member) { return typeList.Any(type => member.ReturnTypeInstance.MatchesType(type)); } - return new SimpleCondition(Condition, - member => "has return type \"" + member.ReturnType.FullName + "\"", description); + return new SimpleCondition( + Condition, + member => "has return type \"" + member.ReturnType.FullName + "\"", + description + ); } - //Negations public static ICondition BeNoConstructor() { - return new SimpleCondition(member => !member.IsConstructor(), "be no constructor", - "is a constructor"); + return new SimpleCondition( + member => !member.IsConstructor(), + "be no constructor", + "is a constructor" + ); } public static ICondition NotBeVirtual() { - return new SimpleCondition(member => !member.IsVirtual, "not be virtual", "is virtual"); + return new SimpleCondition( + member => !member.IsVirtual, + "not be virtual", + "is virtual" + ); } - public static ICondition NotBeCalledBy(string pattern, bool useRegularExpressions = false) + public static ICondition NotBeCalledBy( + string pattern, + bool useRegularExpressions = false + ) { ConditionResult Condition(MethodMember member) { var pass = true; var description = "is called by"; - foreach (var type in member.GetMethodCallDependencies(true).Select(dependency => dependency.Origin) - .Distinct()) + foreach ( + var type in member + .GetMethodCallDependencies(true) + .Select(dependency => dependency.Origin) + .Distinct() + ) { if (type.FullNameMatches(pattern, useRegularExpressions)) { @@ -555,19 +752,28 @@ ConditionResult Condition(MethodMember member) return new ConditionResult(member, pass, description); } - return new SimpleCondition(Condition, - "not be called by types with full name " + (useRegularExpressions ? "matching " : "") + "\"" + - pattern + "\""); + return new SimpleCondition( + Condition, + "not be called by types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static ICondition NotBeCalledBy(IEnumerable patterns, - bool useRegularExpressions = false) + public static ICondition NotBeCalledBy( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Condition(MethodMember ruleType) { - return !patternList.Any(pattern => ruleType.IsCalledBy(pattern, useRegularExpressions)); + return !patternList.Any(pattern => + ruleType.IsCalledBy(pattern, useRegularExpressions) + ); } string description; @@ -580,37 +786,59 @@ bool Condition(MethodMember ruleType) else { var firstPattern = patternList.First(); - description = patternList.Where(type => !type.Equals(firstPattern)).Distinct().Aggregate( - "not be called by types with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", - (current, pattern) => current + " or \"" + pattern + "\""); - failDescription = patternList.Where(type => !type.Equals(firstPattern)).Distinct().Aggregate( - "is called by types with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", - (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "not be called by types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + failDescription = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "is called by types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } - return new SimpleCondition(Condition, description, failDescription); } - public static ICondition NotBeCalledBy(IType firstType, params IType[] moreTypes) + public static ICondition NotBeCalledBy( + IType firstType, + params IType[] moreTypes + ) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return NotBeCalledBy(types); } - public static ICondition NotBeCalledBy(Type firstType, params Type[] moreTypes) + public static ICondition NotBeCalledBy( + Type firstType, + params Type[] moreTypes + ) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return NotBeCalledBy(types); } public static ICondition NotBeCalledBy(IObjectProvider objectProvider) { - IEnumerable Condition(IEnumerable methodMembers, Architecture architecture) + IEnumerable Condition( + IEnumerable methodMembers, + Architecture architecture + ) { var typeList = objectProvider.GetObjects(architecture).ToList(); var methodMemberList = methodMembers.ToList(); @@ -651,9 +879,13 @@ IEnumerable Condition(IEnumerable methodMembers) } else { - failDescription = typeList.Where(type => !type.Equals(firstType)).Distinct().Aggregate( - "is called by \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + failDescription = typeList + .Where(type => !type.Equals(firstType)) + .Distinct() + .Aggregate( + "is called by \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } foreach (var failedObject in failedObjects) @@ -674,9 +906,13 @@ IEnumerable Condition(IEnumerable methodMembers) } else { - description = typeList.Where(type => !type.Equals(firstType)).Distinct().Aggregate( - "not be called by \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => !type.Equals(firstType)) + .Distinct() + .Aggregate( + "not be called by \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new EnumerableCondition(Condition, description); @@ -687,7 +923,10 @@ public static ICondition NotBeCalledBy(IEnumerable types) var typeList = types.ToList(); var firstType = typeList.First(); - IEnumerable Condition(IEnumerable methodMembers, Architecture architecture) + IEnumerable Condition( + IEnumerable methodMembers, + Architecture architecture + ) { var archUnitTypeList = new List(); foreach (var type in typeList) @@ -704,7 +943,9 @@ IEnumerable Condition(IEnumerable methodMembers, } var methodMemberList = methodMembers.ToList(); var failedObjects = methodMemberList - .Where(methodMember => methodMember.GetCallingTypes().Intersect(archUnitTypeList).Any()) + .Where(methodMember => + methodMember.GetCallingTypes().Intersect(archUnitTypeList).Any() + ) .ToList(); string failDescription; if (typeList.IsNullOrEmpty()) @@ -713,9 +954,13 @@ IEnumerable Condition(IEnumerable methodMembers, } else { - failDescription = typeList.Where(type => type != firstType).Distinct().Aggregate( - "is called by \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + failDescription = typeList + .Where(type => type != firstType) + .Distinct() + .Aggregate( + "is called by \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } foreach (var failedObject in failedObjects) @@ -736,23 +981,33 @@ IEnumerable Condition(IEnumerable methodMembers, } else { - description = typeList.Where(type => type != firstType).Distinct().Aggregate( - "not be called by \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => type != firstType) + .Distinct() + .Aggregate( + "not be called by \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new ArchitectureCondition(Condition, description); } - public static ICondition NotHaveDependencyInMethodBodyTo(string pattern, - bool useRegularExpressions = false) + public static ICondition NotHaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ) { ConditionResult Condition(MethodMember member) { var pass = true; var description = "does have dependencies in method body to"; - foreach (var type in member.GetBodyTypeMemberDependencies().Select(dependency => dependency.Target) - .Distinct()) + foreach ( + var type in member + .GetBodyTypeMemberDependencies() + .Select(dependency => dependency.Target) + .Distinct() + ) { if (type.FullNameMatches(pattern, useRegularExpressions)) { @@ -764,72 +1019,111 @@ ConditionResult Condition(MethodMember member) return new ConditionResult(member, pass, description); } - return new SimpleCondition(Condition, - "not have dependencies in method body to types with full name " + - (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\""); + return new SimpleCondition( + Condition, + "not have dependencies in method body to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static ICondition NotHaveDependencyInMethodBodyTo(IEnumerable patterns, - bool useRegularExpressions = false) + public static ICondition NotHaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Condition(MethodMember ruleType) { return !patternList.Any(pattern => - ruleType.HasDependencyInMethodBodyTo(pattern, useRegularExpressions)); + ruleType.HasDependencyInMethodBodyTo(pattern, useRegularExpressions) + ); } string description; string failDescription; if (patternList.IsNullOrEmpty()) { - description = "not have dependencies in method body to one of no types (always true)"; - failDescription = "does have dependencies in method body to one of no types (always false)"; + description = + "not have dependencies in method body to one of no types (always true)"; + failDescription = + "does have dependencies in method body to one of no types (always false)"; } else { var firstPattern = patternList.First(); - description = patternList.Where(type => !type.Equals(firstPattern)).Distinct().Aggregate( - "not have dependencies in method body to types with full name " + - (useRegularExpressions ? "matching " : "") + "\"" + firstPattern + "\"", - (current, pattern) => current + " or \"" + pattern + "\""); - failDescription = patternList.Where(type => !type.Equals(firstPattern)).Distinct().Aggregate( - "does have dependencies in method body to types with full name " + - (useRegularExpressions ? "matching " : "") + "\"" + firstPattern + "\"", - (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "not have dependencies in method body to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + failDescription = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "does have dependencies in method body to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } - return new SimpleCondition(Condition, description, failDescription); } - public static ICondition NotHaveDependencyInMethodBodyTo(IType firstType, - params IType[] moreTypes) + public static ICondition NotHaveDependencyInMethodBodyTo( + IType firstType, + params IType[] moreTypes + ) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return NotHaveDependencyInMethodBodyTo(types); } - public static ICondition NotHaveDependencyInMethodBodyTo(Type firstType, params Type[] moreTypes) + public static ICondition NotHaveDependencyInMethodBodyTo( + Type firstType, + params Type[] moreTypes + ) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return NotHaveDependencyInMethodBodyTo(types); } - public static ICondition NotHaveDependencyInMethodBodyTo(IObjectProvider objectProvider) + public static ICondition NotHaveDependencyInMethodBodyTo( + IObjectProvider objectProvider + ) { - IEnumerable Condition(IEnumerable methodMembers, Architecture architecture) + IEnumerable Condition( + IEnumerable methodMembers, + Architecture architecture + ) { var typeList = objectProvider.GetObjects(architecture).ToList(); var methodMemberList = methodMembers.ToList(); - var failedObjects = methodMemberList.Where(methodMember => - methodMember.GetBodyTypeMemberDependencies().Select(dependency => dependency.Target) - .Intersect(typeList).Any()) + var failedObjects = methodMemberList + .Where(methodMember => + methodMember + .GetBodyTypeMemberDependencies() + .Select(dependency => dependency.Target) + .Intersect(typeList) + .Any() + ) .ToList(); - var failDescription = "does have dependencies in method body to " + objectProvider.Description; + var failDescription = + "does have dependencies in method body to " + objectProvider.Description; foreach (var failedObject in failedObjects) { yield return new ConditionResult(failedObject, false, failDescription); @@ -841,11 +1135,14 @@ IEnumerable Condition(IEnumerable methodMembers, } } - var description = "not have dependencies in method body to " + objectProvider.Description; + var description = + "not have dependencies in method body to " + objectProvider.Description; return new ArchitectureCondition(Condition, description); } - public static ICondition NotHaveDependencyInMethodBodyTo(IEnumerable types) + public static ICondition NotHaveDependencyInMethodBodyTo( + IEnumerable types + ) { var typeList = types.ToList(); var firstType = typeList.First(); @@ -853,20 +1150,32 @@ public static ICondition NotHaveDependencyInMethodBodyTo(IEnumerab IEnumerable Condition(IEnumerable methodMembers) { var methodMemberList = methodMembers.ToList(); - var passedObjects = methodMemberList.Where(methodMember => - methodMember.GetBodyTypeMemberDependencies().Select(dependency => dependency.Target) - .Intersect(typeList).Any()) + var passedObjects = methodMemberList + .Where(methodMember => + methodMember + .GetBodyTypeMemberDependencies() + .Select(dependency => dependency.Target) + .Intersect(typeList) + .Any() + ) .ToList(); string failDescription; if (typeList.IsNullOrEmpty()) { - failDescription = "does not have dependencies in method body to one of no types (always true)"; + failDescription = + "does not have dependencies in method body to one of no types (always true)"; } else { - failDescription = typeList.Where(type => !type.Equals(firstType)).Distinct().Aggregate( - "does not have dependencies in method body to \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + failDescription = typeList + .Where(type => !type.Equals(firstType)) + .Distinct() + .Aggregate( + "does not have dependencies in method body to \"" + + firstType.FullName + + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } foreach (var failedObject in methodMemberList.Except(passedObjects)) @@ -887,20 +1196,29 @@ IEnumerable Condition(IEnumerable methodMembers) } else { - description = typeList.Where(type => !type.Equals(firstType)).Distinct().Aggregate( - "have dependencies in method body to \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => !type.Equals(firstType)) + .Distinct() + .Aggregate( + "have dependencies in method body to \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new EnumerableCondition(Condition, description); } - public static ICondition NotHaveDependencyInMethodBodyTo(IEnumerable types) + public static ICondition NotHaveDependencyInMethodBodyTo( + IEnumerable types + ) { var typeList = types.ToList(); var firstType = typeList.First(); - IEnumerable Condition(IEnumerable methodMembers, Architecture architecture) + IEnumerable Condition( + IEnumerable methodMembers, + Architecture architecture + ) { var archUnitTypeList = new List(); foreach (var type in typeList) @@ -916,20 +1234,32 @@ IEnumerable Condition(IEnumerable methodMembers, } } var methodMemberList = methodMembers.ToList(); - var failedObjects = methodMemberList.Where(methodMember => - methodMember.GetBodyTypeMemberDependencies().Select(dependency => dependency.Target) - .Intersect(archUnitTypeList).Any()) + var failedObjects = methodMemberList + .Where(methodMember => + methodMember + .GetBodyTypeMemberDependencies() + .Select(dependency => dependency.Target) + .Intersect(archUnitTypeList) + .Any() + ) .ToList(); string failDescription; if (typeList.IsNullOrEmpty()) { - failDescription = "does have dependencies in method body to one of no types (always false)"; + failDescription = + "does have dependencies in method body to one of no types (always false)"; } else { - failDescription = typeList.Where(type => type != firstType).Distinct().Aggregate( - "does have dependencies in method body to \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + failDescription = typeList + .Where(type => type != firstType) + .Distinct() + .Aggregate( + "does have dependencies in method body to \"" + + firstType.FullName + + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } foreach (var failedObject in failedObjects) @@ -946,54 +1276,85 @@ IEnumerable Condition(IEnumerable methodMembers, string description; if (typeList.IsNullOrEmpty()) { - description = "not have dependencies in method body to one of no types (always true)"; + description = + "not have dependencies in method body to one of no types (always true)"; } else { - description = typeList.Where(type => type != firstType).Distinct().Aggregate( - "not have dependencies in method body to \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => type != firstType) + .Distinct() + .Aggregate( + "not have dependencies in method body to \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new ArchitectureCondition(Condition, description); } - public static ICondition NotHaveReturnType(string pattern, bool useRegularExpressions = false) + public static ICondition NotHaveReturnType( + string pattern, + bool useRegularExpressions = false + ) { - var description = "not have return type with full name " + - (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\""; - - var failDescription = "does have return type with full name " + - (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\""; + var description = + "not have return type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\""; + + var failDescription = + "does have return type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\""; return new SimpleCondition( - member => !member.ReturnType.FullNameMatches(pattern, useRegularExpressions), description, - failDescription); + member => !member.ReturnType.FullNameMatches(pattern, useRegularExpressions), + description, + failDescription + ); } - public static ICondition NotHaveReturnType(IEnumerable patterns, - bool useRegularExpressions = false) + public static ICondition NotHaveReturnType( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternsArray = patterns.ToArray(); - var description = "not have return type with full name " + - (useRegularExpressions ? "matching " : "") + "\"" + - string.Join("\" or \"", patternsArray) + "\""; - - var failDescription = "does have return type with full name " + - (useRegularExpressions ? "matching " : "") + "\"" + - string.Join("\" or \"", patternsArray) + "\""; + var description = + "not have return type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + string.Join("\" or \"", patternsArray) + + "\""; + + var failDescription = + "does have return type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + string.Join("\" or \"", patternsArray) + + "\""; bool Condition(MethodMember member) { - return patternsArray.All(pattern => !member.ReturnType.FullNameMatches(pattern, useRegularExpressions)); + return patternsArray.All(pattern => + !member.ReturnType.FullNameMatches(pattern, useRegularExpressions) + ); } return new SimpleCondition(Condition, description, failDescription); } - public static ICondition NotHaveReturnType(IType firstType, params IType[] moreTypes) + public static ICondition NotHaveReturnType( + IType firstType, + params IType[] moreTypes + ) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return NotHaveReturnType(types); } @@ -1002,30 +1363,44 @@ public static ICondition NotHaveReturnType(IEnumerable type { var typeList = types.ToList(); var typeStringList = typeList.Select(type => type.FullName).ToList(); - var description = "not have return type \"" + string.Join("\" or \"", typeStringList) + "\""; + var description = + "not have return type \"" + string.Join("\" or \"", typeStringList) + "\""; bool Condition(MethodMember member) { return typeList.All(type => !member.ReturnType.FullNameMatches(type.FullName)); } - return new SimpleCondition(Condition, - member => "has return type \"" + member.ReturnType.FullName + "\"", description); + return new SimpleCondition( + Condition, + member => "has return type \"" + member.ReturnType.FullName + "\"", + description + ); } public static ICondition NotHaveReturnType(IObjectProvider types) { - IEnumerable Condition(IEnumerable methodMembers, Architecture architecture) + IEnumerable Condition( + IEnumerable methodMembers, + Architecture architecture + ) { var typeList = types.GetObjects(architecture).ToList(); var methodMemberList = methodMembers.ToList(); - var passedObjects = methodMemberList.Where(methodMember => - typeList.All(type => !methodMember.ReturnType.FullNameMatches(type.FullName))) + var passedObjects = methodMemberList + .Where(methodMember => + typeList.All(type => + !methodMember.ReturnType.FullNameMatches(type.FullName) + ) + ) .ToList(); foreach (var failedObject in methodMemberList.Except(passedObjects)) { - yield return new ConditionResult(failedObject, false, - "has return type \"" + failedObject.ReturnType.FullName + "\""); + yield return new ConditionResult( + failedObject, + false, + "has return type \"" + failedObject.ReturnType.FullName + "\"" + ); } foreach (var passedObject in passedObjects) @@ -1038,9 +1413,12 @@ IEnumerable Condition(IEnumerable methodMembers, return new ArchitectureCondition(Condition, description); } - public static ICondition NotHaveReturnType(Type firstType, params Type[] moreTypes) + public static ICondition NotHaveReturnType( + Type firstType, + params Type[] moreTypes + ) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return NotHaveReturnType(types); } @@ -1049,15 +1427,19 @@ public static ICondition NotHaveReturnType(IEnumerable types { var typeList = types.ToList(); var typeStringList = typeList.Select(type => type.ToString()).ToList(); - var description = "not have return type \"" + string.Join("\" or \"", typeStringList) + "\""; + var description = + "not have return type \"" + string.Join("\" or \"", typeStringList) + "\""; bool Condition(MethodMember member) { return typeList.All(type => !member.ReturnTypeInstance.MatchesType(type)); } - return new SimpleCondition(Condition, - member => "has return type \"" + member.ReturnType.FullName + "\"", description); + return new SimpleCondition( + Condition, + member => "has return type \"" + member.ReturnType.FullName + "\"", + description + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberPredicatesDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberPredicatesDefinition.cs index 1e30c91c5..cf1347f3e 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberPredicatesDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberPredicatesDefinition.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -18,7 +18,10 @@ public static class MethodMemberPredicatesDefinition { public static IPredicate AreConstructors() { - return new SimplePredicate(member => member.IsConstructor(), "are constructors"); + return new SimplePredicate( + member => member.IsConstructor(), + "are constructors" + ); } public static IPredicate AreVirtual() @@ -26,22 +29,33 @@ public static IPredicate AreVirtual() return new SimplePredicate(member => member.IsVirtual, "are virtual"); } - public static IPredicate AreCalledBy(string pattern, bool useRegularExpressions = false) + public static IPredicate AreCalledBy( + string pattern, + bool useRegularExpressions = false + ) { return new SimplePredicate( member => member.IsCalledBy(pattern, useRegularExpressions), - "are called by types with full name " + (useRegularExpressions ? "matching " : "") + "\"" + - pattern + "\""); + "are called by types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static IPredicate AreCalledBy(IEnumerable patterns, - bool useRegularExpressions = false) + public static IPredicate AreCalledBy( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Condition(MethodMember ruleType) { - return patternList.Any(pattern => ruleType.IsCalledBy(pattern, useRegularExpressions)); + return patternList.Any(pattern => + ruleType.IsCalledBy(pattern, useRegularExpressions) + ); } string description; @@ -52,31 +66,45 @@ bool Condition(MethodMember ruleType) else { var firstPattern = patternList.First(); - description = patternList.Where(type => !type.Equals(firstPattern)).Distinct().Aggregate( - "are called by types with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "are called by types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimplePredicate(Condition, description); } - public static IPredicate AreCalledBy(IType firstType, params IType[] moreTypes) + public static IPredicate AreCalledBy( + IType firstType, + params IType[] moreTypes + ) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return AreCalledBy(types); } public static IPredicate AreCalledBy(Type firstType, params Type[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return AreCalledBy(types); } public static IPredicate AreCalledBy(IObjectProvider objectProvider) { - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var types = objectProvider.GetObjects(architecture); return ruleTypes.Where(type => type.GetCallingTypes().Intersect(types).Any()); @@ -103,9 +131,13 @@ IEnumerable Condition(IEnumerable ruleTypes) else { var firstType = typeList.First(); - description = typeList.Where(type => !type.Equals(firstType)).Distinct().Aggregate( - "are called by \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => !type.Equals(firstType)) + .Distinct() + .Aggregate( + "are called by \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new EnumerablePredicate(Condition, description); @@ -115,7 +147,10 @@ public static IPredicate AreCalledBy(IEnumerable types) { var typeList = types.ToList(); - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var archUnitTypeList = new List(); foreach (var type in typeList) @@ -130,7 +165,9 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite //ignore, can't have a dependency anyways } } - return ruleTypes.Where(type => type.GetCallingTypes().Intersect(archUnitTypeList).Any()); + return ruleTypes.Where(type => + type.GetCallingTypes().Intersect(archUnitTypeList).Any() + ); } string description; @@ -141,31 +178,45 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite else { var firstType = typeList.First(); - description = typeList.Where(type => type != firstType).Distinct().Aggregate( - "are called by \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => type != firstType) + .Distinct() + .Aggregate( + "are called by \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new ArchitecturePredicate(Condition, description); } - public static IPredicate HaveDependencyInMethodBodyTo(string pattern, - bool useRegularExpressions = false) + public static IPredicate HaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ) { return new SimplePredicate( member => member.HasDependencyInMethodBodyTo(pattern, useRegularExpressions), - "have dependencies in method body to types with full name " + - (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\""); + "have dependencies in method body to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static IPredicate HaveDependencyInMethodBodyTo(IEnumerable patterns, - bool useRegularExpressions = false) + public static IPredicate HaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Condition(MethodMember ruleType) { - return patternList.Any(pattern => ruleType.HasDependencyInMethodBodyTo(pattern, useRegularExpressions)); + return patternList.Any(pattern => + ruleType.HasDependencyInMethodBodyTo(pattern, useRegularExpressions) + ); } string description; @@ -176,52 +227,78 @@ bool Condition(MethodMember ruleType) else { var firstPattern = patternList.First(); - description = patternList.Where(type => !type.Equals(firstPattern)).Distinct().Aggregate( - "have dependencies in method body to types with full name " + - (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "have dependencies in method body to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimplePredicate(Condition, description); } - public static IPredicate HaveDependencyInMethodBodyTo(IType firstType, params IType[] moreTypes) + public static IPredicate HaveDependencyInMethodBodyTo( + IType firstType, + params IType[] moreTypes + ) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return HaveDependencyInMethodBodyTo(types); } - public static IPredicate HaveDependencyInMethodBodyTo(Type firstType, params Type[] moreTypes) + public static IPredicate HaveDependencyInMethodBodyTo( + Type firstType, + params Type[] moreTypes + ) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return HaveDependencyInMethodBodyTo(types); } - public static IPredicate HaveDependencyInMethodBodyTo(IObjectProvider objectProvider) + public static IPredicate HaveDependencyInMethodBodyTo( + IObjectProvider objectProvider + ) { - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var types = objectProvider.GetObjects(architecture); return ruleTypes.Where(type => - type.GetBodyTypeMemberDependencies().Select(dependency => dependency.Target).Intersect(types) - .Any()); + type.GetBodyTypeMemberDependencies() + .Select(dependency => dependency.Target) + .Intersect(types) + .Any() + ); } var description = "have dependencies in method body to " + objectProvider.Description; return new ArchitecturePredicate(Condition, description); } - public static IPredicate HaveDependencyInMethodBodyTo(IEnumerable types) + public static IPredicate HaveDependencyInMethodBodyTo( + IEnumerable types + ) { var typeList = types.ToList(); IEnumerable Condition(IEnumerable ruleTypes) { return ruleTypes.Where(type => - type.GetBodyTypeMemberDependencies().Select(dependency => dependency.Target).Intersect(typeList) - .Any()); + type.GetBodyTypeMemberDependencies() + .Select(dependency => dependency.Target) + .Intersect(typeList) + .Any() + ); } string description; @@ -232,9 +309,13 @@ IEnumerable Condition(IEnumerable ruleTypes) else { var firstType = typeList.First(); - description = typeList.Where(type => !type.Equals(firstType)).Distinct().Aggregate( - "have dependencies in method body to \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => !type.Equals(firstType)) + .Distinct() + .Aggregate( + "have dependencies in method body to \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new EnumerablePredicate(Condition, description); @@ -244,7 +325,10 @@ public static IPredicate HaveDependencyInMethodBodyTo(IEnumerable< { var typeList = types.ToList(); - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var archUnitTypeList = new List(); foreach (var type in typeList) @@ -260,8 +344,11 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite } } return ruleTypes.Where(type => - type.GetBodyTypeMemberDependencies().Select(dependency => dependency.Target).Intersect(archUnitTypeList) - .Any()); + type.GetBodyTypeMemberDependencies() + .Select(dependency => dependency.Target) + .Intersect(archUnitTypeList) + .Any() + ); } string description; @@ -272,38 +359,61 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite else { var firstType = typeList.First(); - description = typeList.Where(type => type != firstType).Distinct().Aggregate( - "have dependencies in method body to \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => type != firstType) + .Distinct() + .Aggregate( + "have dependencies in method body to \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new ArchitecturePredicate(Condition, description); } - public static IPredicate HaveReturnType(string pattern, bool useRegularExpressions = false) + public static IPredicate HaveReturnType( + string pattern, + bool useRegularExpressions = false + ) { return new SimplePredicate( member => member.ReturnType.FullNameMatches(pattern, useRegularExpressions), - "have return type with full name " + - (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\""); + "have return type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static IPredicate HaveReturnType(IEnumerable patterns, - bool useRegularExpressions = false) + public static IPredicate HaveReturnType( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternsArray = patterns.ToArray(); - var description = "have return type with full name " + - (useRegularExpressions ? "matching " : "") + "\"" + - string.Join("\" or \"", patternsArray) + "\""; + var description = + "have return type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + string.Join("\" or \"", patternsArray) + + "\""; return new SimplePredicate( - member => patternsArray.Any( - pattern => member.ReturnType.FullNameMatches(pattern, useRegularExpressions)), description); + member => + patternsArray.Any(pattern => + member.ReturnType.FullNameMatches(pattern, useRegularExpressions) + ), + description + ); } - public static IPredicate HaveReturnType(IType firstType, params IType[] moreTypes) + public static IPredicate HaveReturnType( + IType firstType, + params IType[] moreTypes + ) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return HaveReturnType(types); } @@ -312,29 +422,39 @@ public static IPredicate HaveReturnType(IEnumerable types) { var typeList = types.ToList(); var typeStringList = typeList.Select(type => type.FullName).ToList(); - var description = "have return type \"" + string.Join("\" or \"", typeStringList) + "\""; + var description = + "have return type \"" + string.Join("\" or \"", typeStringList) + "\""; return new SimplePredicate( - member => typeList.Any(type => member.ReturnType.FullNameMatches(type.FullName)), description); + member => typeList.Any(type => member.ReturnType.FullNameMatches(type.FullName)), + description + ); } public static IPredicate HaveReturnType(IObjectProvider types) { - IEnumerable Condition(IEnumerable methodMembers, Architecture architecture) + IEnumerable Condition( + IEnumerable methodMembers, + Architecture architecture + ) { var typeList = types.GetObjects(architecture).ToList(); var methodMemberList = methodMembers.ToList(); return methodMemberList.Where(methodMember => - typeList.Any(type => methodMember.ReturnType.FullNameMatches(type.FullName))); + typeList.Any(type => methodMember.ReturnType.FullNameMatches(type.FullName)) + ); } var description = "have return type " + types.Description; return new ArchitecturePredicate(Condition, description); } - public static IPredicate HaveReturnType(Type firstType, params Type[] moreTypes) + public static IPredicate HaveReturnType( + Type firstType, + params Type[] moreTypes + ) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return HaveReturnType(types); } @@ -343,42 +463,61 @@ public static IPredicate HaveReturnType(IEnumerable types) { var typeList = types.ToList(); var typeStringList = typeList.Select(type => type.ToString()).ToList(); - var description = "have return type \"" + string.Join("\" or \"", typeStringList) + "\""; + var description = + "have return type \"" + string.Join("\" or \"", typeStringList) + "\""; return new SimplePredicate( - member => typeList.Any(type => member.ReturnTypeInstance.MatchesType(type)), description); + member => typeList.Any(type => member.ReturnTypeInstance.MatchesType(type)), + description + ); } - //Negations public static IPredicate AreNoConstructors() { - return new SimplePredicate(member => !member.IsConstructor(), "are no constructors"); + return new SimplePredicate( + member => !member.IsConstructor(), + "are no constructors" + ); } public static IPredicate AreNotVirtual() { - return new SimplePredicate(member => !member.IsVirtual, "are not virtual"); + return new SimplePredicate( + member => !member.IsVirtual, + "are not virtual" + ); } - public static IPredicate AreNotCalledBy(string pattern, bool useRegularExpressions = false) + public static IPredicate AreNotCalledBy( + string pattern, + bool useRegularExpressions = false + ) { return new SimplePredicate( member => !member.IsCalledBy(pattern, useRegularExpressions), - "are not called by types with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + pattern + "\""); + "are not called by types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static IPredicate AreNotCalledBy(IEnumerable patterns, - bool useRegularExpressions = false) + public static IPredicate AreNotCalledBy( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Condition(MethodMember ruleType) { - return !patternList.Any(pattern => ruleType.IsCalledBy(pattern, useRegularExpressions)); + return !patternList.Any(pattern => + ruleType.IsCalledBy(pattern, useRegularExpressions) + ); } string description; @@ -389,31 +528,48 @@ bool Condition(MethodMember ruleType) else { var firstPattern = patternList.First(); - description = patternList.Where(type => !type.Equals(firstPattern)).Distinct().Aggregate( - "are not called by types with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "are not called by types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimplePredicate(Condition, description); } - public static IPredicate AreNotCalledBy(IType firstType, params IType[] moreTypes) + public static IPredicate AreNotCalledBy( + IType firstType, + params IType[] moreTypes + ) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return AreNotCalledBy(types); } - public static IPredicate AreNotCalledBy(Type firstType, params Type[] moreTypes) + public static IPredicate AreNotCalledBy( + Type firstType, + params Type[] moreTypes + ) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return AreNotCalledBy(types); } public static IPredicate AreNotCalledBy(IObjectProvider objectProvider) { - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var types = objectProvider.GetObjects(architecture); return ruleTypes.Where(type => !type.GetCallingTypes().Intersect(types).Any()); @@ -440,9 +596,13 @@ IEnumerable Condition(IEnumerable ruleTypes) else { var firstType = typeList.First(); - description = typeList.Where(type => !type.Equals(firstType)).Distinct().Aggregate( - "are not called by \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => !type.Equals(firstType)) + .Distinct() + .Aggregate( + "are not called by \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new EnumerablePredicate(Condition, description); @@ -452,7 +612,10 @@ public static IPredicate AreNotCalledBy(IEnumerable types) { var typeList = types.ToList(); - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var archUnitTypeList = new List(); foreach (var type in typeList) @@ -467,7 +630,9 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite //ignore, can't have a dependency anyways } } - return ruleTypes.Where(type => !type.GetCallingTypes().Intersect(archUnitTypeList).Any()); + return ruleTypes.Where(type => + !type.GetCallingTypes().Intersect(archUnitTypeList).Any() + ); } string description; @@ -478,113 +643,162 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite else { var firstType = typeList.First(); - description = typeList.Where(type => type != firstType).Distinct().Aggregate( - "are not called by \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => type != firstType) + .Distinct() + .Aggregate( + "are not called by \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new ArchitecturePredicate(Condition, description); } - public static IPredicate DoNotHaveDependencyInMethodBodyTo(string pattern, - bool useRegularExpressions = false) + public static IPredicate DoNotHaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ) { return new SimplePredicate( member => !member.HasDependencyInMethodBodyTo(pattern, useRegularExpressions), - "do not have dependencies in method body to types with full name " + - (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\""); + "do not have dependencies in method body to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static IPredicate DoNotHaveDependencyInMethodBodyTo(IEnumerable patterns, - bool useRegularExpressions = false) + public static IPredicate DoNotHaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Condition(MethodMember ruleType) { return !patternList.Any(pattern => - ruleType.HasDependencyInMethodBodyTo(pattern, useRegularExpressions)); + ruleType.HasDependencyInMethodBodyTo(pattern, useRegularExpressions) + ); } string description; if (patternList.IsNullOrEmpty()) { - description = "do not have dependencies in method body to one of no types (always true)"; + description = + "do not have dependencies in method body to one of no types (always true)"; } else { var firstPattern = patternList.First(); - description = patternList.Where(type => !type.Equals(firstPattern)).Distinct().Aggregate( - "do not have dependencies in method body to types with full name " + - (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "do not have dependencies in method body to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimplePredicate(Condition, description); } - public static IPredicate DoNotHaveDependencyInMethodBodyTo(IType firstType, - params IType[] moreTypes) + public static IPredicate DoNotHaveDependencyInMethodBodyTo( + IType firstType, + params IType[] moreTypes + ) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return DoNotHaveDependencyInMethodBodyTo(types); } - public static IPredicate DoNotHaveDependencyInMethodBodyTo(Type firstType, - params Type[] moreTypes) + public static IPredicate DoNotHaveDependencyInMethodBodyTo( + Type firstType, + params Type[] moreTypes + ) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return DoNotHaveDependencyInMethodBodyTo(types); } - public static IPredicate DoNotHaveDependencyInMethodBodyTo(IObjectProvider objectProvider) + public static IPredicate DoNotHaveDependencyInMethodBodyTo( + IObjectProvider objectProvider + ) { - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var types = objectProvider.GetObjects(architecture); return ruleTypes.Where(type => - !type.GetBodyTypeMemberDependencies().Select(dependency => dependency.Target).Intersect(types) - .Any()); + !type.GetBodyTypeMemberDependencies() + .Select(dependency => dependency.Target) + .Intersect(types) + .Any() + ); } - var description = "do not have dependencies in method body to " + objectProvider.Description; + var description = + "do not have dependencies in method body to " + objectProvider.Description; return new ArchitecturePredicate(Condition, description); } - public static IPredicate DoNotHaveDependencyInMethodBodyTo(IEnumerable types) + public static IPredicate DoNotHaveDependencyInMethodBodyTo( + IEnumerable types + ) { var typeList = types.ToList(); IEnumerable Condition(IEnumerable ruleTypes) { return ruleTypes.Where(type => - !type.GetBodyTypeMemberDependencies().Select(dependency => dependency.Target).Intersect(typeList) - .Any()); + !type.GetBodyTypeMemberDependencies() + .Select(dependency => dependency.Target) + .Intersect(typeList) + .Any() + ); } string description; if (typeList.IsNullOrEmpty()) { - description = "do not have dependencies in method body to one of no types (always true)"; + description = + "do not have dependencies in method body to one of no types (always true)"; } else { var firstType = typeList.First(); - description = typeList.Where(type => !type.Equals(firstType)).Distinct().Aggregate( - "do not have dependencies in method body to \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => !type.Equals(firstType)) + .Distinct() + .Aggregate( + "do not have dependencies in method body to \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new EnumerablePredicate(Condition, description); } - public static IPredicate DoNotHaveDependencyInMethodBodyTo(IEnumerable types) + public static IPredicate DoNotHaveDependencyInMethodBodyTo( + IEnumerable types + ) { var typeList = types.ToList(); - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var archUnitTypeList = new List(); foreach (var type in typeList) @@ -600,50 +814,77 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite } } return ruleTypes.Where(type => - !type.GetBodyTypeMemberDependencies().Select(dependency => dependency.Target).Intersect(archUnitTypeList) - .Any()); + !type.GetBodyTypeMemberDependencies() + .Select(dependency => dependency.Target) + .Intersect(archUnitTypeList) + .Any() + ); } string description; if (typeList.IsNullOrEmpty()) { - description = "do not have dependencies in method body to one of no types (always true)"; + description = + "do not have dependencies in method body to one of no types (always true)"; } else { var firstType = typeList.First(); - description = typeList.Where(type => type != firstType).Distinct().Aggregate( - "do not have dependencies in method body to \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => type != firstType) + .Distinct() + .Aggregate( + "do not have dependencies in method body to \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new ArchitecturePredicate(Condition, description); } - public static IPredicate DoNotHaveReturnType(string pattern, bool useRegularExpressions = false) + public static IPredicate DoNotHaveReturnType( + string pattern, + bool useRegularExpressions = false + ) { return new SimplePredicate( member => !member.ReturnType.FullNameMatches(pattern, useRegularExpressions), - "do not have return type with full name " + - (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\""); + "do not have return type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static IPredicate DoNotHaveReturnType(IEnumerable patterns, - bool useRegularExpressions = false) + public static IPredicate DoNotHaveReturnType( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternsArray = patterns.ToArray(); - var description = "do not have return type with full name " + - (useRegularExpressions ? "matching " : "") + "\"" + - string.Join("\" or \"", patternsArray) + "\""; + var description = + "do not have return type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + string.Join("\" or \"", patternsArray) + + "\""; return new SimplePredicate( - member => patternsArray.All( - pattern => !member.ReturnType.FullNameMatches(pattern, useRegularExpressions)), description); + member => + patternsArray.All(pattern => + !member.ReturnType.FullNameMatches(pattern, useRegularExpressions) + ), + description + ); } - public static IPredicate DoNotHaveReturnType(IType firstType, params IType[] moreTypes) + public static IPredicate DoNotHaveReturnType( + IType firstType, + params IType[] moreTypes + ) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return DoNotHaveReturnType(types); } @@ -652,29 +893,39 @@ public static IPredicate DoNotHaveReturnType(IEnumerable ty { var typeList = types.ToList(); var typeStringList = typeList.Select(type => type.FullName).ToList(); - var description = "do not have return type \"" + string.Join("\" or \"", typeStringList) + "\""; + var description = + "do not have return type \"" + string.Join("\" or \"", typeStringList) + "\""; return new SimplePredicate( - member => typeList.Any(type => !member.ReturnType.FullNameMatches(type.FullName)), description); + member => typeList.Any(type => !member.ReturnType.FullNameMatches(type.FullName)), + description + ); } public static IPredicate DoNotHaveReturnType(IObjectProvider types) { - IEnumerable Condition(IEnumerable methodMembers, Architecture architecture) + IEnumerable Condition( + IEnumerable methodMembers, + Architecture architecture + ) { var typeList = types.GetObjects(architecture).ToList(); var methodMemberList = methodMembers.ToList(); return methodMemberList.Where(methodMember => - typeList.All(type => !methodMember.ReturnType.FullNameMatches(type.FullName))); + typeList.All(type => !methodMember.ReturnType.FullNameMatches(type.FullName)) + ); } var description = "do not have return type " + types.Description; return new ArchitecturePredicate(Condition, description); } - public static IPredicate DoNotHaveReturnType(Type firstType, params Type[] moreTypes) + public static IPredicate DoNotHaveReturnType( + Type firstType, + params Type[] moreTypes + ) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return DoNotHaveReturnType(types); } @@ -683,10 +934,13 @@ public static IPredicate DoNotHaveReturnType(IEnumerable typ { var typeList = types.ToList(); var typeStringList = typeList.Select(type => type.ToString()).ToList(); - var description = "do not have return type \"" + string.Join("\" or \"", typeStringList) + "\""; + var description = + "do not have return type \"" + string.Join("\" or \"", typeStringList) + "\""; return new SimplePredicate( - member => typeList.All(type => !member.ReturnTypeInstance.MatchesType(type)), description); + member => typeList.All(type => !member.ReturnTypeInstance.MatchesType(type)), + description + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMembersShould.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMembersShould.cs index 4102d58bd..318eea920 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMembersShould.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMembersShould.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -10,12 +10,12 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Members.MethodMembers { - public class MethodMembersShould : MembersShould, - IComplexMethodMemberConditions + public class MethodMembersShould + : MembersShould, + IComplexMethodMemberConditions { - public MethodMembersShould(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public MethodMembersShould(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } public MethodMembersShouldConjunction BeConstructor() { @@ -29,22 +29,33 @@ public MethodMembersShouldConjunction BeVirtual() return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction BeCalledBy(string pattern, bool useRegularExpressions = false) + public MethodMembersShouldConjunction BeCalledBy( + string pattern, + bool useRegularExpressions = false + ) { - _ruleCreator.AddCondition(MethodMemberConditionsDefinition.BeCalledBy(pattern, useRegularExpressions)); + _ruleCreator.AddCondition( + MethodMemberConditionsDefinition.BeCalledBy(pattern, useRegularExpressions) + ); return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction BeCalledBy(IEnumerable patterns, - bool useRegularExpressions = false) + public MethodMembersShouldConjunction BeCalledBy( + IEnumerable patterns, + bool useRegularExpressions = false + ) { - _ruleCreator.AddCondition(MethodMemberConditionsDefinition.BeCalledBy(patterns, useRegularExpressions)); + _ruleCreator.AddCondition( + MethodMemberConditionsDefinition.BeCalledBy(patterns, useRegularExpressions) + ); return new MethodMembersShouldConjunction(_ruleCreator); } public MethodMembersShouldConjunction BeCalledBy(IType firstType, params IType[] moreTypes) { - _ruleCreator.AddCondition(MethodMemberConditionsDefinition.BeCalledBy(firstType, moreTypes)); + _ruleCreator.AddCondition( + MethodMemberConditionsDefinition.BeCalledBy(firstType, moreTypes) + ); return new MethodMembersShouldConjunction(_ruleCreator); } @@ -72,73 +83,112 @@ public MethodMembersShouldConjunction BeCalledBy(IEnumerable types) return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction HaveDependencyInMethodBodyTo(string pattern, - bool useRegularExpressions = false) + public MethodMembersShouldConjunction HaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.HaveDependencyInMethodBodyTo(pattern, useRegularExpressions)); + MethodMemberConditionsDefinition.HaveDependencyInMethodBodyTo( + pattern, + useRegularExpressions + ) + ); return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction HaveDependencyInMethodBodyTo(IEnumerable patterns, - bool useRegularExpressions = false) + public MethodMembersShouldConjunction HaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.HaveDependencyInMethodBodyTo(patterns, useRegularExpressions)); + MethodMemberConditionsDefinition.HaveDependencyInMethodBodyTo( + patterns, + useRegularExpressions + ) + ); return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction HaveDependencyInMethodBodyTo(IType firstType, params IType[] moreTypes) + public MethodMembersShouldConjunction HaveDependencyInMethodBodyTo( + IType firstType, + params IType[] moreTypes + ) { _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.HaveDependencyInMethodBodyTo(firstType, moreTypes)); + MethodMemberConditionsDefinition.HaveDependencyInMethodBodyTo(firstType, moreTypes) + ); return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction HaveDependencyInMethodBodyTo(Type type, params Type[] moreTypes) + public MethodMembersShouldConjunction HaveDependencyInMethodBodyTo( + Type type, + params Type[] moreTypes + ) { _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.HaveDependencyInMethodBodyTo(type, moreTypes)); + MethodMemberConditionsDefinition.HaveDependencyInMethodBodyTo(type, moreTypes) + ); return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction HaveDependencyInMethodBodyTo(IObjectProvider types) + public MethodMembersShouldConjunction HaveDependencyInMethodBodyTo( + IObjectProvider types + ) { _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.HaveDependencyInMethodBodyTo(types)); + MethodMemberConditionsDefinition.HaveDependencyInMethodBodyTo(types) + ); return new MethodMembersShouldConjunction(_ruleCreator); } public MethodMembersShouldConjunction HaveDependencyInMethodBodyTo(IEnumerable types) { _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.HaveDependencyInMethodBodyTo(types)); + MethodMemberConditionsDefinition.HaveDependencyInMethodBodyTo(types) + ); return new MethodMembersShouldConjunction(_ruleCreator); } public MethodMembersShouldConjunction HaveDependencyInMethodBodyTo(IEnumerable types) { _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.HaveDependencyInMethodBodyTo(types)); + MethodMemberConditionsDefinition.HaveDependencyInMethodBodyTo(types) + ); return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction HaveReturnType(string pattern, bool useRegularExpressions = false) + public MethodMembersShouldConjunction HaveReturnType( + string pattern, + bool useRegularExpressions = false + ) { - _ruleCreator.AddCondition(MethodMemberConditionsDefinition.HaveReturnType(pattern, useRegularExpressions)); + _ruleCreator.AddCondition( + MethodMemberConditionsDefinition.HaveReturnType(pattern, useRegularExpressions) + ); return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction HaveReturnType(IEnumerable patterns, - bool useRegularExpressions = false) + public MethodMembersShouldConjunction HaveReturnType( + IEnumerable patterns, + bool useRegularExpressions = false + ) { - _ruleCreator.AddCondition(MethodMemberConditionsDefinition.HaveReturnType(patterns, useRegularExpressions)); + _ruleCreator.AddCondition( + MethodMemberConditionsDefinition.HaveReturnType(patterns, useRegularExpressions) + ); return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction HaveReturnType(IType firstType, params IType[] moreTypes) + public MethodMembersShouldConjunction HaveReturnType( + IType firstType, + params IType[] moreTypes + ) { - _ruleCreator.AddCondition(MethodMemberConditionsDefinition.HaveReturnType(firstType, moreTypes)); + _ruleCreator.AddCondition( + MethodMemberConditionsDefinition.HaveReturnType(firstType, moreTypes) + ); return new MethodMembersShouldConjunction(_ruleCreator); } @@ -156,7 +206,9 @@ public MethodMembersShouldConjunction HaveReturnType(IObjectProvider type public MethodMembersShouldConjunction HaveReturnType(Type type, params Type[] moreTypes) { - _ruleCreator.AddCondition(MethodMemberConditionsDefinition.HaveReturnType(type, moreTypes)); + _ruleCreator.AddCondition( + MethodMemberConditionsDefinition.HaveReturnType(type, moreTypes) + ); return new MethodMembersShouldConjunction(_ruleCreator); } @@ -181,28 +233,44 @@ public MethodMembersShouldConjunction NotBeVirtual() return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction NotBeCalledBy(string pattern, bool useRegularExpressions = false) + public MethodMembersShouldConjunction NotBeCalledBy( + string pattern, + bool useRegularExpressions = false + ) { - _ruleCreator.AddCondition(MethodMemberConditionsDefinition.NotBeCalledBy(pattern, useRegularExpressions)); + _ruleCreator.AddCondition( + MethodMemberConditionsDefinition.NotBeCalledBy(pattern, useRegularExpressions) + ); return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction NotBeCalledBy(IEnumerable patterns, - bool useRegularExpressions = false) + public MethodMembersShouldConjunction NotBeCalledBy( + IEnumerable patterns, + bool useRegularExpressions = false + ) { - _ruleCreator.AddCondition(MethodMemberConditionsDefinition.NotBeCalledBy(patterns, useRegularExpressions)); + _ruleCreator.AddCondition( + MethodMemberConditionsDefinition.NotBeCalledBy(patterns, useRegularExpressions) + ); return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction NotBeCalledBy(IType firstType, params IType[] moreTypes) + public MethodMembersShouldConjunction NotBeCalledBy( + IType firstType, + params IType[] moreTypes + ) { - _ruleCreator.AddCondition(MethodMemberConditionsDefinition.NotBeCalledBy(firstType, moreTypes)); + _ruleCreator.AddCondition( + MethodMemberConditionsDefinition.NotBeCalledBy(firstType, moreTypes) + ); return new MethodMembersShouldConjunction(_ruleCreator); } public MethodMembersShouldConjunction NotBeCalledBy(Type type, params Type[] moreTypes) { - _ruleCreator.AddCondition(MethodMemberConditionsDefinition.NotBeCalledBy(type, moreTypes)); + _ruleCreator.AddCondition( + MethodMemberConditionsDefinition.NotBeCalledBy(type, moreTypes) + ); return new MethodMembersShouldConjunction(_ruleCreator); } @@ -224,75 +292,119 @@ public MethodMembersShouldConjunction NotBeCalledBy(IEnumerable types) return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction NotHaveDependencyInMethodBodyTo(string pattern, - bool useRegularExpressions = false) + public MethodMembersShouldConjunction NotHaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.NotHaveDependencyInMethodBodyTo(pattern, useRegularExpressions)); + MethodMemberConditionsDefinition.NotHaveDependencyInMethodBodyTo( + pattern, + useRegularExpressions + ) + ); return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction - NotHaveDependencyInMethodBodyTo(IEnumerable patterns, bool useRegularExpressions = false) + public MethodMembersShouldConjunction NotHaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.NotHaveDependencyInMethodBodyTo(patterns, useRegularExpressions)); + MethodMemberConditionsDefinition.NotHaveDependencyInMethodBodyTo( + patterns, + useRegularExpressions + ) + ); return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction NotHaveDependencyInMethodBodyTo(IType firstType, params IType[] moreTypes) + public MethodMembersShouldConjunction NotHaveDependencyInMethodBodyTo( + IType firstType, + params IType[] moreTypes + ) { _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.NotHaveDependencyInMethodBodyTo(firstType, moreTypes)); + MethodMemberConditionsDefinition.NotHaveDependencyInMethodBodyTo( + firstType, + moreTypes + ) + ); return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction NotHaveDependencyInMethodBodyTo(Type type, params Type[] moreTypes) + public MethodMembersShouldConjunction NotHaveDependencyInMethodBodyTo( + Type type, + params Type[] moreTypes + ) { _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.NotHaveDependencyInMethodBodyTo(type, moreTypes)); + MethodMemberConditionsDefinition.NotHaveDependencyInMethodBodyTo(type, moreTypes) + ); return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction NotHaveDependencyInMethodBodyTo(IObjectProvider types) + public MethodMembersShouldConjunction NotHaveDependencyInMethodBodyTo( + IObjectProvider types + ) { _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.NotHaveDependencyInMethodBodyTo(types)); + MethodMemberConditionsDefinition.NotHaveDependencyInMethodBodyTo(types) + ); return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction NotHaveDependencyInMethodBodyTo(IEnumerable types) + public MethodMembersShouldConjunction NotHaveDependencyInMethodBodyTo( + IEnumerable types + ) { _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.NotHaveDependencyInMethodBodyTo(types)); + MethodMemberConditionsDefinition.NotHaveDependencyInMethodBodyTo(types) + ); return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction NotHaveDependencyInMethodBodyTo(IEnumerable types) + public MethodMembersShouldConjunction NotHaveDependencyInMethodBodyTo( + IEnumerable types + ) { _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.NotHaveDependencyInMethodBodyTo(types)); + MethodMemberConditionsDefinition.NotHaveDependencyInMethodBodyTo(types) + ); return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction NotHaveReturnType(string pattern, bool useRegularExpressions = false) + public MethodMembersShouldConjunction NotHaveReturnType( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.NotHaveReturnType(pattern, useRegularExpressions)); + MethodMemberConditionsDefinition.NotHaveReturnType(pattern, useRegularExpressions) + ); return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction NotHaveReturnType(IEnumerable patterns, - bool useRegularExpressions = false) + public MethodMembersShouldConjunction NotHaveReturnType( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - MethodMemberConditionsDefinition.NotHaveReturnType(patterns, useRegularExpressions)); + MethodMemberConditionsDefinition.NotHaveReturnType(patterns, useRegularExpressions) + ); return new MethodMembersShouldConjunction(_ruleCreator); } - public MethodMembersShouldConjunction NotHaveReturnType(IType firstType, params IType[] moreTypes) + public MethodMembersShouldConjunction NotHaveReturnType( + IType firstType, + params IType[] moreTypes + ) { - _ruleCreator.AddCondition(MethodMemberConditionsDefinition.NotHaveReturnType(firstType, moreTypes)); + _ruleCreator.AddCondition( + MethodMemberConditionsDefinition.NotHaveReturnType(firstType, moreTypes) + ); return new MethodMembersShouldConjunction(_ruleCreator); } @@ -310,7 +422,9 @@ public MethodMembersShouldConjunction NotHaveReturnType(IObjectProvider t public MethodMembersShouldConjunction NotHaveReturnType(Type type, params Type[] moreTypes) { - _ruleCreator.AddCondition(MethodMemberConditionsDefinition.NotHaveReturnType(type, moreTypes)); + _ruleCreator.AddCondition( + MethodMemberConditionsDefinition.NotHaveReturnType(type, moreTypes) + ); return new MethodMembersShouldConjunction(_ruleCreator); } @@ -320,4 +434,4 @@ public MethodMembersShouldConjunction NotHaveReturnType(IEnumerable types) return new MethodMembersShouldConjunction(_ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMembersShouldConjunction.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMembersShouldConjunction.cs index c8936e60a..3ed97cecf 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMembersShouldConjunction.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMembersShouldConjunction.cs @@ -1,18 +1,21 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.MethodMembers { - public class MethodMembersShouldConjunction : ObjectsShouldConjunction + public class MethodMembersShouldConjunction + : ObjectsShouldConjunction< + MethodMembersShould, + MethodMembersShouldConjunctionWithDescription, + MethodMember + > { - public MethodMembersShouldConjunction(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public MethodMembersShouldConjunction(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMembersShouldConjunctionWithDescription.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMembersShouldConjunctionWithDescription.cs index fd5a50220..74ae4ae7a 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMembersShouldConjunctionWithDescription.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMembersShouldConjunctionWithDescription.cs @@ -1,20 +1,19 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.MethodMembers { - public class - MethodMembersShouldConjunctionWithDescription : ObjectsShouldConjunctionWithDescription + public class MethodMembersShouldConjunctionWithDescription + : ObjectsShouldConjunctionWithDescription { - public MethodMembersShouldConjunctionWithDescription(IArchRuleCreator ruleCreator) : base( - ruleCreator) - { - } + public MethodMembersShouldConjunctionWithDescription( + IArchRuleCreator ruleCreator + ) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/ShouldRelateToMethodMembersThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/ShouldRelateToMethodMembersThat.cs index 2f8c6dd8a..78236f36d 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/ShouldRelateToMethodMembersThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/ShouldRelateToMethodMembersThat.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -11,19 +11,20 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Members.MethodMembers { - public class ShouldRelateToMethodMembersThat : - ShouldRelateToMembersThat, - IMethodMemberPredicates + public class ShouldRelateToMethodMembersThat + : ShouldRelateToMembersThat, + IMethodMemberPredicates where TRuleTypeShouldConjunction : SyntaxElement where TRuleType : ICanBeAnalyzed { - public ShouldRelateToMethodMembersThat(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public ShouldRelateToMethodMembersThat(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } public TRuleTypeShouldConjunction AreConstructors() { - _ruleCreator.ContinueComplexCondition(MethodMemberPredicatesDefinition.AreConstructors()); + _ruleCreator.ContinueComplexCondition( + MethodMemberPredicatesDefinition.AreConstructors() + ); return Create(_ruleCreator); } @@ -33,163 +34,212 @@ public TRuleTypeShouldConjunction AreVirtual() return Create(_ruleCreator); } - public TRuleTypeShouldConjunction AreCalledBy(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction AreCalledBy( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.AreCalledBy(pattern, useRegularExpressions)); + MethodMemberPredicatesDefinition.AreCalledBy(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction AreCalledBy(IEnumerable patterns, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction AreCalledBy( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.AreCalledBy(patterns, useRegularExpressions)); + MethodMemberPredicatesDefinition.AreCalledBy(patterns, useRegularExpressions) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreCalledBy(IType firstType, params IType[] moreTypes) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.AreCalledBy(firstType, moreTypes)); + MethodMemberPredicatesDefinition.AreCalledBy(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreCalledBy(Type type, params Type[] moreTypes) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.AreCalledBy(type, moreTypes)); + MethodMemberPredicatesDefinition.AreCalledBy(type, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreCalledBy(IObjectProvider types) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.AreCalledBy(types)); + MethodMemberPredicatesDefinition.AreCalledBy(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreCalledBy(IEnumerable types) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.AreCalledBy(types)); + MethodMemberPredicatesDefinition.AreCalledBy(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreCalledBy(IEnumerable types) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.AreCalledBy(types)); + MethodMemberPredicatesDefinition.AreCalledBy(types) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveDependencyInMethodBodyTo(string pattern, - bool useRegularExpressions = false) + public TRuleTypeShouldConjunction HaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(pattern, useRegularExpressions)); + MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveDependencyInMethodBodyTo(IEnumerable patterns, - bool useRegularExpressions = false) + public TRuleTypeShouldConjunction HaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(patterns, useRegularExpressions)); + MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo( + patterns, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveDependencyInMethodBodyTo(IType firstType, params IType[] moreTypes) + public TRuleTypeShouldConjunction HaveDependencyInMethodBodyTo( + IType firstType, + params IType[] moreTypes + ) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(firstType, moreTypes)); + MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(firstType, moreTypes) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveDependencyInMethodBodyTo(Type type, params Type[] moreTypes) + public TRuleTypeShouldConjunction HaveDependencyInMethodBodyTo( + Type type, + params Type[] moreTypes + ) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(type, moreTypes)); + MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(type, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveDependencyInMethodBodyTo(IObjectProvider types) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(types)); + MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveDependencyInMethodBodyTo(IEnumerable types) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(types)); + MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveDependencyInMethodBodyTo(IEnumerable types) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(types)); + MethodMemberPredicatesDefinition.HaveDependencyInMethodBodyTo(types) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveReturnType(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction HaveReturnType( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.HaveReturnType(pattern, useRegularExpressions)); + MethodMemberPredicatesDefinition.HaveReturnType(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveReturnType(IEnumerable patterns, - bool useRegularExpressions = false) + public TRuleTypeShouldConjunction HaveReturnType( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.HaveReturnType(patterns, useRegularExpressions)); + MethodMemberPredicatesDefinition.HaveReturnType(patterns, useRegularExpressions) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveReturnType(IType firstType, params IType[] moreTypes) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.HaveReturnType(firstType, moreTypes)); + MethodMemberPredicatesDefinition.HaveReturnType(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveReturnType(IEnumerable types) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.HaveReturnType(types)); + MethodMemberPredicatesDefinition.HaveReturnType(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveReturnType(IObjectProvider types) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.HaveReturnType(types)); + MethodMemberPredicatesDefinition.HaveReturnType(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveReturnType(Type type, params Type[] moreTypes) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.HaveReturnType(type, moreTypes)); + MethodMemberPredicatesDefinition.HaveReturnType(type, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveReturnType(IEnumerable types) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.HaveReturnType(types)); + MethodMemberPredicatesDefinition.HaveReturnType(types) + ); return Create(_ruleCreator); } - //Negations public TRuleTypeShouldConjunction AreNoConstructors() { - _ruleCreator.ContinueComplexCondition(MethodMemberPredicatesDefinition.AreNoConstructors()); + _ruleCreator.ContinueComplexCondition( + MethodMemberPredicatesDefinition.AreNoConstructors() + ); return Create(_ruleCreator); } @@ -199,155 +249,215 @@ public TRuleTypeShouldConjunction AreNotVirtual() return Create(_ruleCreator); } - public TRuleTypeShouldConjunction AreNotCalledBy(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction AreNotCalledBy( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.AreNotCalledBy(pattern, useRegularExpressions)); + MethodMemberPredicatesDefinition.AreNotCalledBy(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction AreNotCalledBy(IEnumerable patterns, - bool useRegularExpressions = false) + public TRuleTypeShouldConjunction AreNotCalledBy( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.AreNotCalledBy(patterns, useRegularExpressions)); + MethodMemberPredicatesDefinition.AreNotCalledBy(patterns, useRegularExpressions) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNotCalledBy(IType firstType, params IType[] moreTypes) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.AreNotCalledBy(firstType, moreTypes)); + MethodMemberPredicatesDefinition.AreNotCalledBy(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNotCalledBy(Type type, params Type[] moreTypes) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.AreNotCalledBy(type, moreTypes)); + MethodMemberPredicatesDefinition.AreNotCalledBy(type, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNotCalledBy(IObjectProvider types) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.AreNotCalledBy(types)); + MethodMemberPredicatesDefinition.AreNotCalledBy(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNotCalledBy(IEnumerable types) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.AreNotCalledBy(types)); + MethodMemberPredicatesDefinition.AreNotCalledBy(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNotCalledBy(IEnumerable types) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.AreNotCalledBy(types)); + MethodMemberPredicatesDefinition.AreNotCalledBy(types) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveDependencyInMethodBodyTo(string pattern, - bool useRegularExpressions = false) + public TRuleTypeShouldConjunction DoNotHaveDependencyInMethodBodyTo( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(pattern, useRegularExpressions)); + MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveDependencyInMethodBodyTo(IEnumerable patterns, - bool useRegularExpressions = false) + public TRuleTypeShouldConjunction DoNotHaveDependencyInMethodBodyTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(patterns, useRegularExpressions)); + MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo( + patterns, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveDependencyInMethodBodyTo(IType firstType, params IType[] moreTypes) + public TRuleTypeShouldConjunction DoNotHaveDependencyInMethodBodyTo( + IType firstType, + params IType[] moreTypes + ) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(firstType, moreTypes)); + MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo( + firstType, + moreTypes + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveDependencyInMethodBodyTo(Type type, params Type[] moreTypes) + public TRuleTypeShouldConjunction DoNotHaveDependencyInMethodBodyTo( + Type type, + params Type[] moreTypes + ) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(type, moreTypes)); + MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(type, moreTypes) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveDependencyInMethodBodyTo(IObjectProvider types) + public TRuleTypeShouldConjunction DoNotHaveDependencyInMethodBodyTo( + IObjectProvider types + ) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(types)); + MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(types) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveDependencyInMethodBodyTo(IEnumerable types) + public TRuleTypeShouldConjunction DoNotHaveDependencyInMethodBodyTo( + IEnumerable types + ) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(types)); + MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotHaveDependencyInMethodBodyTo(IEnumerable types) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(types)); + MethodMemberPredicatesDefinition.DoNotHaveDependencyInMethodBodyTo(types) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveReturnType(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction DoNotHaveReturnType( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.DoNotHaveReturnType(pattern, useRegularExpressions)); + MethodMemberPredicatesDefinition.DoNotHaveReturnType(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveReturnType(IEnumerable patterns, - bool useRegularExpressions = false) + public TRuleTypeShouldConjunction DoNotHaveReturnType( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.DoNotHaveReturnType(patterns, useRegularExpressions)); + MethodMemberPredicatesDefinition.DoNotHaveReturnType( + patterns, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveReturnType(IType firstType, params IType[] moreTypes) + public TRuleTypeShouldConjunction DoNotHaveReturnType( + IType firstType, + params IType[] moreTypes + ) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.DoNotHaveReturnType(firstType, moreTypes)); + MethodMemberPredicatesDefinition.DoNotHaveReturnType(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotHaveReturnType(IEnumerable types) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.DoNotHaveReturnType(types)); + MethodMemberPredicatesDefinition.DoNotHaveReturnType(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotHaveReturnType(IObjectProvider types) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.DoNotHaveReturnType(types)); + MethodMemberPredicatesDefinition.DoNotHaveReturnType(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotHaveReturnType(Type type, params Type[] moreTypes) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.DoNotHaveReturnType(type, moreTypes)); + MethodMemberPredicatesDefinition.DoNotHaveReturnType(type, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotHaveReturnType(IEnumerable types) { _ruleCreator.ContinueComplexCondition( - MethodMemberPredicatesDefinition.DoNotHaveReturnType(types)); + MethodMemberPredicatesDefinition.DoNotHaveReturnType(types) + ); return Create(_ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/GivenPropertyMembers.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/GivenPropertyMembers.cs index 7d3ff7e78..7e1fd6268 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/GivenPropertyMembers.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/GivenPropertyMembers.cs @@ -1,17 +1,17 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.PropertyMembers { - public class GivenPropertyMembers : GivenObjects + public class GivenPropertyMembers + : GivenObjects { - public GivenPropertyMembers(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenPropertyMembers(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/GivenPropertyMembersConjunction.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/GivenPropertyMembersConjunction.cs index 5382dd30a..3824ed009 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/GivenPropertyMembersConjunction.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/GivenPropertyMembersConjunction.cs @@ -1,18 +1,22 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.PropertyMembers { - public class GivenPropertyMembersConjunction : GivenObjectsConjunction + public class GivenPropertyMembersConjunction + : GivenObjectsConjunction< + GivenPropertyMembersThat, + PropertyMembersShould, + GivenPropertyMembersConjunctionWithDescription, + PropertyMember + > { - public GivenPropertyMembersConjunction(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenPropertyMembersConjunction(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/GivenPropertyMembersConjunctionWithDescription.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/GivenPropertyMembersConjunctionWithDescription.cs index 42531aa11..4c734f185 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/GivenPropertyMembersConjunctionWithDescription.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/GivenPropertyMembersConjunctionWithDescription.cs @@ -1,20 +1,23 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.PropertyMembers { - public class GivenPropertyMembersConjunctionWithDescription : GivenObjectsConjunctionWithDescription< - GivenPropertyMembersThat, - PropertyMembersShould, PropertyMember> + public class GivenPropertyMembersConjunctionWithDescription + : GivenObjectsConjunctionWithDescription< + GivenPropertyMembersThat, + PropertyMembersShould, + PropertyMember + > { - public GivenPropertyMembersConjunctionWithDescription(IArchRuleCreator ruleCreator) : base( - ruleCreator) - { - } + public GivenPropertyMembersConjunctionWithDescription( + IArchRuleCreator ruleCreator + ) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/GivenPropertyMembersThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/GivenPropertyMembersThat.cs index 55e7b70df..7221b8861 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/GivenPropertyMembersThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/GivenPropertyMembersThat.cs @@ -1,19 +1,19 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.PropertyMembers { - public class GivenPropertyMembersThat : GivenMembersThat, - IPropertyMemberPredicates + public class GivenPropertyMembersThat + : GivenMembersThat, + IPropertyMemberPredicates { - public GivenPropertyMembersThat(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenPropertyMembersThat(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } public GivenPropertyMembersConjunction HaveGetter() { @@ -47,13 +47,17 @@ public GivenPropertyMembersConjunction HaveInternalGetter() public GivenPropertyMembersConjunction HaveProtectedInternalGetter() { - _ruleCreator.AddPredicate(PropertyMemberPredicateDefinition.HaveProtectedInternalGetter()); + _ruleCreator.AddPredicate( + PropertyMemberPredicateDefinition.HaveProtectedInternalGetter() + ); return new GivenPropertyMembersConjunction(_ruleCreator); } public GivenPropertyMembersConjunction HavePrivateProtectedGetter() { - _ruleCreator.AddPredicate(PropertyMemberPredicateDefinition.HavePrivateProtectedGetter()); + _ruleCreator.AddPredicate( + PropertyMemberPredicateDefinition.HavePrivateProtectedGetter() + ); return new GivenPropertyMembersConjunction(_ruleCreator); } @@ -89,13 +93,17 @@ public GivenPropertyMembersConjunction HaveInternalSetter() public GivenPropertyMembersConjunction HaveProtectedInternalSetter() { - _ruleCreator.AddPredicate(PropertyMemberPredicateDefinition.HaveProtectedInternalSetter()); + _ruleCreator.AddPredicate( + PropertyMemberPredicateDefinition.HaveProtectedInternalSetter() + ); return new GivenPropertyMembersConjunction(_ruleCreator); } public GivenPropertyMembersConjunction HavePrivateProtectedSetter() { - _ruleCreator.AddPredicate(PropertyMemberPredicateDefinition.HavePrivateProtectedSetter()); + _ruleCreator.AddPredicate( + PropertyMemberPredicateDefinition.HavePrivateProtectedSetter() + ); return new GivenPropertyMembersConjunction(_ruleCreator); } @@ -111,7 +119,6 @@ public GivenPropertyMembersConjunction AreVirtual() return new GivenPropertyMembersConjunction(_ruleCreator); } - //Negations @@ -147,13 +154,17 @@ public GivenPropertyMembersConjunction DoNotHaveInternalGetter() public GivenPropertyMembersConjunction DoNotHaveProtectedInternalGetter() { - _ruleCreator.AddPredicate(PropertyMemberPredicateDefinition.DoNotHaveProtectedInternalGetter()); + _ruleCreator.AddPredicate( + PropertyMemberPredicateDefinition.DoNotHaveProtectedInternalGetter() + ); return new GivenPropertyMembersConjunction(_ruleCreator); } public GivenPropertyMembersConjunction DoNotHavePrivateProtectedGetter() { - _ruleCreator.AddPredicate(PropertyMemberPredicateDefinition.DoNotHavePrivateProtectedGetter()); + _ruleCreator.AddPredicate( + PropertyMemberPredicateDefinition.DoNotHavePrivateProtectedGetter() + ); return new GivenPropertyMembersConjunction(_ruleCreator); } @@ -189,13 +200,17 @@ public GivenPropertyMembersConjunction DoNotHaveInternalSetter() public GivenPropertyMembersConjunction DoNotHaveProtectedInternalSetter() { - _ruleCreator.AddPredicate(PropertyMemberPredicateDefinition.DoNotHaveProtectedInternalSetter()); + _ruleCreator.AddPredicate( + PropertyMemberPredicateDefinition.DoNotHaveProtectedInternalSetter() + ); return new GivenPropertyMembersConjunction(_ruleCreator); } public GivenPropertyMembersConjunction DoNotHavePrivateProtectedSetter() { - _ruleCreator.AddPredicate(PropertyMemberPredicateDefinition.DoNotHavePrivateProtectedSetter()); + _ruleCreator.AddPredicate( + PropertyMemberPredicateDefinition.DoNotHavePrivateProtectedSetter() + ); return new GivenPropertyMembersConjunction(_ruleCreator); } @@ -211,4 +226,4 @@ public GivenPropertyMembersConjunction AreNotVirtual() return new GivenPropertyMembersConjunction(_ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/IComplexPropertyMemberConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/IComplexPropertyMemberConditions.cs index e996b180b..564909fde 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/IComplexPropertyMemberConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/IComplexPropertyMemberConditions.cs @@ -1,16 +1,14 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.PropertyMembers { - public interface IComplexPropertyMemberConditions : - IComplexMemberConditions, - IPropertyMemberConditions - { - } -} \ No newline at end of file + public interface IComplexPropertyMemberConditions + : IComplexMemberConditions, + IPropertyMemberConditions { } +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/IPropertyMemberConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/IPropertyMemberConditions.cs index 3cafde41b..da2bec719 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/IPropertyMemberConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/IPropertyMemberConditions.cs @@ -1,15 +1,15 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.PropertyMembers { - public interface - IPropertyMemberConditions : IMemberConditions + public interface IPropertyMemberConditions + : IMemberConditions where TRuleType : ICanBeAnalyzed { TReturnType HaveGetter(); @@ -29,7 +29,6 @@ public interface TReturnType HaveInitOnlySetter(); TReturnType BeVirtual(); - //Negations @@ -50,4 +49,4 @@ public interface TReturnType NotHaveInitOnlySetter(); TReturnType NotBeVirtual(); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/IPropertyMemberPredicates.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/IPropertyMemberPredicates.cs index 222013ee4..1ee8a047a 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/IPropertyMemberPredicates.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/IPropertyMemberPredicates.cs @@ -1,16 +1,16 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.PropertyMembers { - public interface - IPropertyMemberPredicates : IMemberPredicates where TRuleType : ICanBeAnalyzed + public interface IPropertyMemberPredicates + : IMemberPredicates + where TRuleType : ICanBeAnalyzed { TRuleTypeConjunction HaveGetter(); TRuleTypeConjunction HavePrivateGetter(); @@ -29,7 +29,6 @@ public interface TRuleTypeConjunction HaveInitOnlySetter(); TRuleTypeConjunction AreVirtual(); - //Negations @@ -50,4 +49,4 @@ public interface TRuleTypeConjunction DoNotHaveInitOnlySetter(); TRuleTypeConjunction AreNotVirtual(); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/PropertyMemberConditionsDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/PropertyMemberConditionsDefinition.cs index af4b3fa6c..c7f742641 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/PropertyMemberConditionsDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/PropertyMemberConditionsDefinition.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -14,225 +14,325 @@ public static class PropertyMemberConditionsDefinition { public static ICondition HaveGetter() { - return new SimpleCondition(member => member.GetterVisibility != NotAccessible, + return new SimpleCondition( + member => member.GetterVisibility != NotAccessible, "have a getter", - "has no getter"); + "has no getter" + ); } public static ICondition HavePrivateGetter() { return new SimpleCondition( member => member.GetterVisibility == Private, - member => "does have a " + VisibilityStrings.ToString(member.GetterVisibility) + " getter", - "have a private getter"); + member => + "does have a " + + VisibilityStrings.ToString(member.GetterVisibility) + + " getter", + "have a private getter" + ); } public static ICondition HavePublicGetter() { return new SimpleCondition( member => member.GetterVisibility == Public, - member => "does have a " + VisibilityStrings.ToString(member.GetterVisibility) + " getter", - "have a public getter"); + member => + "does have a " + + VisibilityStrings.ToString(member.GetterVisibility) + + " getter", + "have a public getter" + ); } public static ICondition HaveProtectedGetter() { return new SimpleCondition( member => member.GetterVisibility == Protected, - member => "does have a " + VisibilityStrings.ToString(member.GetterVisibility) + " getter", - "have a protected getter"); + member => + "does have a " + + VisibilityStrings.ToString(member.GetterVisibility) + + " getter", + "have a protected getter" + ); } public static ICondition HaveInternalGetter() { return new SimpleCondition( member => member.GetterVisibility == Internal, - member => "does have a " + VisibilityStrings.ToString(member.GetterVisibility) + " getter", - "have an internal getter"); + member => + "does have a " + + VisibilityStrings.ToString(member.GetterVisibility) + + " getter", + "have an internal getter" + ); } public static ICondition HaveProtectedInternalGetter() { - return new SimpleCondition(member => member.GetterVisibility == ProtectedInternal, - member => "does have a " + VisibilityStrings.ToString(member.GetterVisibility) + " getter", - "have a protected internal getter"); + return new SimpleCondition( + member => member.GetterVisibility == ProtectedInternal, + member => + "does have a " + + VisibilityStrings.ToString(member.GetterVisibility) + + " getter", + "have a protected internal getter" + ); } public static ICondition HavePrivateProtectedGetter() { - return new SimpleCondition(member => member.GetterVisibility == PrivateProtected, - member => "does have " + VisibilityStrings.ToString(member.GetterVisibility) + " getter", - "have a private protected getter"); + return new SimpleCondition( + member => member.GetterVisibility == PrivateProtected, + member => + "does have " + VisibilityStrings.ToString(member.GetterVisibility) + " getter", + "have a private protected getter" + ); } public static ICondition HaveSetter() { return new SimpleCondition( - member => member.SetterVisibility != NotAccessible, "have a setter", - "has no setter"); + member => member.SetterVisibility != NotAccessible, + "have a setter", + "has no setter" + ); } public static ICondition HavePrivateSetter() { return new SimpleCondition( member => member.SetterVisibility == Private, - member => "does have a " + VisibilityStrings.ToString(member.SetterVisibility) + " setter", - "have a private setter"); + member => + "does have a " + + VisibilityStrings.ToString(member.SetterVisibility) + + " setter", + "have a private setter" + ); } public static ICondition HavePublicSetter() { return new SimpleCondition( member => member.SetterVisibility == Public, - member => "does have a " + VisibilityStrings.ToString(member.SetterVisibility) + " setter", - "have a public setter"); + member => + "does have a " + + VisibilityStrings.ToString(member.SetterVisibility) + + " setter", + "have a public setter" + ); } public static ICondition HaveProtectedSetter() { return new SimpleCondition( member => member.SetterVisibility == Protected, - member => "does have a " + VisibilityStrings.ToString(member.SetterVisibility) + " setter", - "have a protected setter"); + member => + "does have a " + + VisibilityStrings.ToString(member.SetterVisibility) + + " setter", + "have a protected setter" + ); } public static ICondition HaveInternalSetter() { return new SimpleCondition( member => member.SetterVisibility == Internal, - member => "does have a " + VisibilityStrings.ToString(member.SetterVisibility) + " setter", - "have an internal setter"); + member => + "does have a " + + VisibilityStrings.ToString(member.SetterVisibility) + + " setter", + "have an internal setter" + ); } public static ICondition HaveProtectedInternalSetter() { - return new SimpleCondition(member => member.SetterVisibility == ProtectedInternal, - member => "does have a " + VisibilityStrings.ToString(member.SetterVisibility) + " setter", - "have a protected internal setter"); + return new SimpleCondition( + member => member.SetterVisibility == ProtectedInternal, + member => + "does have a " + + VisibilityStrings.ToString(member.SetterVisibility) + + " setter", + "have a protected internal setter" + ); } public static ICondition HavePrivateProtectedSetter() { - return new SimpleCondition(member => member.SetterVisibility == PrivateProtected, - member => "does have " + VisibilityStrings.ToString(member.SetterVisibility) + " setter", - "have a private protected setter"); + return new SimpleCondition( + member => member.SetterVisibility == PrivateProtected, + member => + "does have " + VisibilityStrings.ToString(member.SetterVisibility) + " setter", + "have a private protected setter" + ); } public static ICondition HaveInitSetter() { - return new SimpleCondition(member => member.Writability == Writability.InitOnly, + return new SimpleCondition( + member => member.Writability == Writability.InitOnly, "have an only init only setter", - "does not have an init only setter"); + "does not have an init only setter" + ); } public static ICondition BeVirtual() { - return new SimpleCondition(member => member.IsVirtual, "be virtual", "is not virtual"); + return new SimpleCondition( + member => member.IsVirtual, + "be virtual", + "is not virtual" + ); } - //Negations public static ICondition NotHaveGetter() { return new SimpleCondition( - member => member.GetterVisibility == NotAccessible, "have no getter", "does have a getter"); + member => member.GetterVisibility == NotAccessible, + "have no getter", + "does have a getter" + ); } public static ICondition NotHavePrivateGetter() { return new SimpleCondition( - member => member.GetterVisibility != Private, "not have a private getter", - "does have a private getter"); + member => member.GetterVisibility != Private, + "not have a private getter", + "does have a private getter" + ); } public static ICondition NotHavePublicGetter() { return new SimpleCondition( - member => member.GetterVisibility != Public, "not have a public getter", "does have a public getter"); + member => member.GetterVisibility != Public, + "not have a public getter", + "does have a public getter" + ); } public static ICondition NotHaveProtectedGetter() { return new SimpleCondition( - member => member.GetterVisibility != Protected, "not have a protected getter", - "does have a protected getter"); + member => member.GetterVisibility != Protected, + "not have a protected getter", + "does have a protected getter" + ); } public static ICondition NotHaveInternalGetter() { return new SimpleCondition( - member => member.GetterVisibility != Internal, "not have an internal getter", - "does have an internal getter"); + member => member.GetterVisibility != Internal, + "not have an internal getter", + "does have an internal getter" + ); } public static ICondition NotHaveProtectedInternalGetter() { - return new SimpleCondition(member => member.GetterVisibility != ProtectedInternal, - "not have a protected internal getter", "does have a protected internal getter"); + return new SimpleCondition( + member => member.GetterVisibility != ProtectedInternal, + "not have a protected internal getter", + "does have a protected internal getter" + ); } public static ICondition NotHavePrivateProtectedGetter() { - return new SimpleCondition(member => member.GetterVisibility != PrivateProtected, - "not have a private protected getter", "does have a private protected getter"); + return new SimpleCondition( + member => member.GetterVisibility != PrivateProtected, + "not have a private protected getter", + "does have a private protected getter" + ); } public static ICondition NotHaveSetter() { return new SimpleCondition( - member => member.SetterVisibility == NotAccessible, "have no setter", "does have a setter"); + member => member.SetterVisibility == NotAccessible, + "have no setter", + "does have a setter" + ); } public static ICondition NotHavePrivateSetter() { return new SimpleCondition( - member => member.SetterVisibility != Private, "not have a private setter", - "does have a private setter"); + member => member.SetterVisibility != Private, + "not have a private setter", + "does have a private setter" + ); } public static ICondition NotHavePublicSetter() { return new SimpleCondition( - member => member.SetterVisibility != Public, "not have a public setter", "does have a public setter"); + member => member.SetterVisibility != Public, + "not have a public setter", + "does have a public setter" + ); } public static ICondition NotHaveProtectedSetter() { return new SimpleCondition( - member => member.SetterVisibility != Protected, "not have a protected setter", - "does have a protected setter"); + member => member.SetterVisibility != Protected, + "not have a protected setter", + "does have a protected setter" + ); } public static ICondition NotHaveInternalSetter() { return new SimpleCondition( - member => member.SetterVisibility != Internal, "not have an internal setter", - "does have an internal setter"); + member => member.SetterVisibility != Internal, + "not have an internal setter", + "does have an internal setter" + ); } public static ICondition NotHaveProtectedInternalSetter() { - return new SimpleCondition(member => member.SetterVisibility != ProtectedInternal, - "not have a protected internal setter", "does have a protected internal setter"); + return new SimpleCondition( + member => member.SetterVisibility != ProtectedInternal, + "not have a protected internal setter", + "does have a protected internal setter" + ); } public static ICondition NotHavePrivateProtectedSetter() { - return new SimpleCondition(member => member.SetterVisibility != PrivateProtected, - "not have a private protected setter", "does have a private protected setter"); + return new SimpleCondition( + member => member.SetterVisibility != PrivateProtected, + "not have a private protected setter", + "does have a private protected setter" + ); } public static ICondition NotHaveInitSetter() { - return new SimpleCondition(member => member.Writability != Writability.InitOnly, - "not have an init only setter", "has an init only setter"); + return new SimpleCondition( + member => member.Writability != Writability.InitOnly, + "not have an init only setter", + "has an init only setter" + ); } public static ICondition NotBeVirtual() { - return new SimpleCondition(member => !member.IsVirtual, "not be virtual", "is virtual"); + return new SimpleCondition( + member => !member.IsVirtual, + "not be virtual", + "is virtual" + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/PropertyMemberPredicateDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/PropertyMemberPredicateDefinition.cs index 556fed14c..b4632f6d6 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/PropertyMemberPredicateDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/PropertyMemberPredicateDefinition.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -14,92 +14,122 @@ public static class PropertyMemberPredicateDefinition { public static IPredicate HaveGetter() { - return new SimplePredicate(member => member.GetterVisibility != NotAccessible, - "have getter"); + return new SimplePredicate( + member => member.GetterVisibility != NotAccessible, + "have getter" + ); } public static IPredicate HavePrivateGetter() { - return new SimplePredicate(member => member.GetterVisibility == Private, - "have private getter"); + return new SimplePredicate( + member => member.GetterVisibility == Private, + "have private getter" + ); } public static IPredicate HavePublicGetter() { - return new SimplePredicate(member => member.GetterVisibility == Public, - "have public getter"); + return new SimplePredicate( + member => member.GetterVisibility == Public, + "have public getter" + ); } public static IPredicate HaveProtectedGetter() { - return new SimplePredicate(member => member.GetterVisibility == Protected, - "have protected getter"); + return new SimplePredicate( + member => member.GetterVisibility == Protected, + "have protected getter" + ); } public static IPredicate HaveInternalGetter() { - return new SimplePredicate(member => member.GetterVisibility == Internal, - "have internal getter"); + return new SimplePredicate( + member => member.GetterVisibility == Internal, + "have internal getter" + ); } public static IPredicate HaveProtectedInternalGetter() { - return new SimplePredicate(member => member.GetterVisibility == ProtectedInternal, - "have protected internal getter"); + return new SimplePredicate( + member => member.GetterVisibility == ProtectedInternal, + "have protected internal getter" + ); } public static IPredicate HavePrivateProtectedGetter() { - return new SimplePredicate(member => member.GetterVisibility == PrivateProtected, - "have private protected getter"); + return new SimplePredicate( + member => member.GetterVisibility == PrivateProtected, + "have private protected getter" + ); } public static IPredicate HaveSetter() { - return new SimplePredicate(member => member.SetterVisibility != NotAccessible, - "have setter"); + return new SimplePredicate( + member => member.SetterVisibility != NotAccessible, + "have setter" + ); } public static IPredicate HavePrivateSetter() { - return new SimplePredicate(member => member.SetterVisibility == Private, - "have private setter"); + return new SimplePredicate( + member => member.SetterVisibility == Private, + "have private setter" + ); } public static IPredicate HavePublicSetter() { - return new SimplePredicate(member => member.SetterVisibility == Public, - "have public setter"); + return new SimplePredicate( + member => member.SetterVisibility == Public, + "have public setter" + ); } public static IPredicate HaveProtectedSetter() { - return new SimplePredicate(member => member.SetterVisibility == Protected, - "have protected setter"); + return new SimplePredicate( + member => member.SetterVisibility == Protected, + "have protected setter" + ); } public static IPredicate HaveInternalSetter() { - return new SimplePredicate(member => member.SetterVisibility == Internal, - "have internal setter"); + return new SimplePredicate( + member => member.SetterVisibility == Internal, + "have internal setter" + ); } public static IPredicate HaveProtectedInternalSetter() { - return new SimplePredicate(member => member.SetterVisibility == ProtectedInternal, - "have protected internal setter"); + return new SimplePredicate( + member => member.SetterVisibility == ProtectedInternal, + "have protected internal setter" + ); } public static IPredicate HavePrivateProtectedSetter() { - return new SimplePredicate(member => member.SetterVisibility == PrivateProtected, - "have private protected setter"); + return new SimplePredicate( + member => member.SetterVisibility == PrivateProtected, + "have private protected setter" + ); } public static IPredicate HaveInitSetter() { - return new SimplePredicate(member => member.Writability == Writability.InitOnly, - "have an init only setter"); + return new SimplePredicate( + member => member.Writability == Writability.InitOnly, + "have an init only setter" + ); } public static IPredicate AreVirtual() @@ -112,98 +142,130 @@ public static IPredicate AreVirtual() public static IPredicate HaveNoGetter() { - return new SimplePredicate(member => member.GetterVisibility == NotAccessible, - "have no getter"); + return new SimplePredicate( + member => member.GetterVisibility == NotAccessible, + "have no getter" + ); } - public static IPredicate DoNotHavePrivateGetter() { - return new SimplePredicate(member => member.GetterVisibility != Private, - "do not have private getter"); + return new SimplePredicate( + member => member.GetterVisibility != Private, + "do not have private getter" + ); } public static IPredicate DoNotHavePublicGetter() { - return new SimplePredicate(member => member.GetterVisibility != Public, - "do not have public getter"); + return new SimplePredicate( + member => member.GetterVisibility != Public, + "do not have public getter" + ); } public static IPredicate DoNotHaveProtectedGetter() { - return new SimplePredicate(member => member.GetterVisibility != Protected, - "do not have protected getter"); + return new SimplePredicate( + member => member.GetterVisibility != Protected, + "do not have protected getter" + ); } public static IPredicate DoNotHaveInternalGetter() { - return new SimplePredicate(member => member.GetterVisibility != Internal, - "do not have internal getter"); + return new SimplePredicate( + member => member.GetterVisibility != Internal, + "do not have internal getter" + ); } public static IPredicate DoNotHaveProtectedInternalGetter() { - return new SimplePredicate(member => member.GetterVisibility != ProtectedInternal, - "do not have protected internal getter"); + return new SimplePredicate( + member => member.GetterVisibility != ProtectedInternal, + "do not have protected internal getter" + ); } public static IPredicate DoNotHavePrivateProtectedGetter() { - return new SimplePredicate(member => member.GetterVisibility != PrivateProtected, - "do not have private protected getter"); + return new SimplePredicate( + member => member.GetterVisibility != PrivateProtected, + "do not have private protected getter" + ); } public static IPredicate HaveNoSetter() { - return new SimplePredicate(member => member.SetterVisibility == NotAccessible, - "have no setter"); + return new SimplePredicate( + member => member.SetterVisibility == NotAccessible, + "have no setter" + ); } public static IPredicate DoNotHavePrivateSetter() { - return new SimplePredicate(member => member.SetterVisibility != Private, - "do not have private setter"); + return new SimplePredicate( + member => member.SetterVisibility != Private, + "do not have private setter" + ); } public static IPredicate DoNotHavePublicSetter() { - return new SimplePredicate(member => member.SetterVisibility != Public, - "do not have public setter"); + return new SimplePredicate( + member => member.SetterVisibility != Public, + "do not have public setter" + ); } public static IPredicate DoNotHaveProtectedSetter() { - return new SimplePredicate(member => member.SetterVisibility != Protected, - "do not have protected setter"); + return new SimplePredicate( + member => member.SetterVisibility != Protected, + "do not have protected setter" + ); } public static IPredicate DoNotHaveInternalSetter() { - return new SimplePredicate(member => member.SetterVisibility != Internal, - "do not have internal setter"); + return new SimplePredicate( + member => member.SetterVisibility != Internal, + "do not have internal setter" + ); } public static IPredicate DoNotHaveProtectedInternalSetter() { - return new SimplePredicate(member => member.SetterVisibility != ProtectedInternal, - "do not have protected internal setter"); + return new SimplePredicate( + member => member.SetterVisibility != ProtectedInternal, + "do not have protected internal setter" + ); } public static IPredicate DoNotHavePrivateProtectedSetter() { - return new SimplePredicate(member => member.SetterVisibility != PrivateProtected, - "do not have private protected setter"); + return new SimplePredicate( + member => member.SetterVisibility != PrivateProtected, + "do not have private protected setter" + ); } public static IPredicate DoNotHaveInitSetter() { - return new SimplePredicate(member => member.Writability != Writability.InitOnly, - "do not have an init only setter"); + return new SimplePredicate( + member => member.Writability != Writability.InitOnly, + "do not have an init only setter" + ); } public static IPredicate AreNotVirtual() { - return new SimplePredicate(member => !member.IsVirtual, "are not virtual"); + return new SimplePredicate( + member => !member.IsVirtual, + "are not virtual" + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/PropertyMembersShould.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/PropertyMembersShould.cs index bd1a25691..d1cc1e1de 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/PropertyMembersShould.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/PropertyMembersShould.cs @@ -1,19 +1,19 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.PropertyMembers { - public class PropertyMembersShould : MembersShould, - IComplexPropertyMemberConditions + public class PropertyMembersShould + : MembersShould, + IComplexPropertyMemberConditions { - public PropertyMembersShould(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public PropertyMembersShould(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } public PropertyMembersShouldConjunction HaveGetter() { @@ -47,13 +47,17 @@ public PropertyMembersShouldConjunction HaveInternalGetter() public PropertyMembersShouldConjunction HaveProtectedInternalGetter() { - _ruleCreator.AddCondition(PropertyMemberConditionsDefinition.HaveProtectedInternalGetter()); + _ruleCreator.AddCondition( + PropertyMemberConditionsDefinition.HaveProtectedInternalGetter() + ); return new PropertyMembersShouldConjunction(_ruleCreator); } public PropertyMembersShouldConjunction HavePrivateProtectedGetter() { - _ruleCreator.AddCondition(PropertyMemberConditionsDefinition.HavePrivateProtectedGetter()); + _ruleCreator.AddCondition( + PropertyMemberConditionsDefinition.HavePrivateProtectedGetter() + ); return new PropertyMembersShouldConjunction(_ruleCreator); } @@ -89,13 +93,17 @@ public PropertyMembersShouldConjunction HaveInternalSetter() public PropertyMembersShouldConjunction HaveProtectedInternalSetter() { - _ruleCreator.AddCondition(PropertyMemberConditionsDefinition.HaveProtectedInternalSetter()); + _ruleCreator.AddCondition( + PropertyMemberConditionsDefinition.HaveProtectedInternalSetter() + ); return new PropertyMembersShouldConjunction(_ruleCreator); } public PropertyMembersShouldConjunction HavePrivateProtectedSetter() { - _ruleCreator.AddCondition(PropertyMemberConditionsDefinition.HavePrivateProtectedSetter()); + _ruleCreator.AddCondition( + PropertyMemberConditionsDefinition.HavePrivateProtectedSetter() + ); return new PropertyMembersShouldConjunction(_ruleCreator); } @@ -111,7 +119,6 @@ public PropertyMembersShouldConjunction BeVirtual() return new PropertyMembersShouldConjunction(_ruleCreator); } - //Negations @@ -147,13 +154,17 @@ public PropertyMembersShouldConjunction NotHaveInternalGetter() public PropertyMembersShouldConjunction NotHaveProtectedInternalGetter() { - _ruleCreator.AddCondition(PropertyMemberConditionsDefinition.NotHaveProtectedInternalGetter()); + _ruleCreator.AddCondition( + PropertyMemberConditionsDefinition.NotHaveProtectedInternalGetter() + ); return new PropertyMembersShouldConjunction(_ruleCreator); } public PropertyMembersShouldConjunction NotHavePrivateProtectedGetter() { - _ruleCreator.AddCondition(PropertyMemberConditionsDefinition.NotHavePrivateProtectedGetter()); + _ruleCreator.AddCondition( + PropertyMemberConditionsDefinition.NotHavePrivateProtectedGetter() + ); return new PropertyMembersShouldConjunction(_ruleCreator); } @@ -189,13 +200,17 @@ public PropertyMembersShouldConjunction NotHaveInternalSetter() public PropertyMembersShouldConjunction NotHaveProtectedInternalSetter() { - _ruleCreator.AddCondition(PropertyMemberConditionsDefinition.NotHaveProtectedInternalSetter()); + _ruleCreator.AddCondition( + PropertyMemberConditionsDefinition.NotHaveProtectedInternalSetter() + ); return new PropertyMembersShouldConjunction(_ruleCreator); } public PropertyMembersShouldConjunction NotHavePrivateProtectedSetter() { - _ruleCreator.AddCondition(PropertyMemberConditionsDefinition.NotHavePrivateProtectedSetter()); + _ruleCreator.AddCondition( + PropertyMemberConditionsDefinition.NotHavePrivateProtectedSetter() + ); return new PropertyMembersShouldConjunction(_ruleCreator); } @@ -211,4 +226,4 @@ public PropertyMembersShouldConjunction NotBeVirtual() return new PropertyMembersShouldConjunction(_ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/PropertyMembersShouldConjunction.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/PropertyMembersShouldConjunction.cs index fa0007ae4..df66c24cc 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/PropertyMembersShouldConjunction.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/PropertyMembersShouldConjunction.cs @@ -1,19 +1,21 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.PropertyMembers { - public class - PropertyMembersShouldConjunction : ObjectsShouldConjunction + public class PropertyMembersShouldConjunction + : ObjectsShouldConjunction< + PropertyMembersShould, + PropertyMembersShouldConjunctionWithDescription, + PropertyMember + > { - public PropertyMembersShouldConjunction(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public PropertyMembersShouldConjunction(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/PropertyMembersShouldConjunctionWithDescription.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/PropertyMembersShouldConjunctionWithDescription.cs index 27081a571..f408eb670 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/PropertyMembersShouldConjunctionWithDescription.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/PropertyMembersShouldConjunctionWithDescription.cs @@ -1,20 +1,19 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Members.PropertyMembers { - public class - PropertyMembersShouldConjunctionWithDescription : ObjectsShouldConjunctionWithDescription + public class PropertyMembersShouldConjunctionWithDescription + : ObjectsShouldConjunctionWithDescription { - public PropertyMembersShouldConjunctionWithDescription(IArchRuleCreator ruleCreator) : base( - ruleCreator) - { - } + public PropertyMembersShouldConjunctionWithDescription( + IArchRuleCreator ruleCreator + ) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/ShouldRelateToPropertyMembersThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/ShouldRelateToPropertyMembersThat.cs index a17cace76..e3688bc84 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/ShouldRelateToPropertyMembersThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/PropertyMembers/ShouldRelateToPropertyMembersThat.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -9,15 +9,14 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Members.PropertyMembers { - public class ShouldRelateToPropertyMembersThat : - ShouldRelateToMembersThat, - IPropertyMemberPredicates + public class ShouldRelateToPropertyMembersThat + : ShouldRelateToMembersThat, + IPropertyMemberPredicates where TRuleTypeShouldConjunction : SyntaxElement where TRuleType : ICanBeAnalyzed { - public ShouldRelateToPropertyMembersThat(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public ShouldRelateToPropertyMembersThat(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } public TRuleTypeShouldConjunction HaveGetter() { @@ -27,37 +26,49 @@ public TRuleTypeShouldConjunction HaveGetter() public TRuleTypeShouldConjunction HavePrivateGetter() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.HavePrivateGetter()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.HavePrivateGetter() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HavePublicGetter() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.HavePublicGetter()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.HavePublicGetter() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveProtectedGetter() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.HaveProtectedGetter()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.HaveProtectedGetter() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveInternalGetter() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.HaveInternalGetter()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.HaveInternalGetter() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveProtectedInternalGetter() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.HaveProtectedInternalGetter()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.HaveProtectedInternalGetter() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HavePrivateProtectedGetter() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.HavePrivateProtectedGetter()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.HavePrivateProtectedGetter() + ); return Create(_ruleCreator); } @@ -69,43 +80,57 @@ public TRuleTypeShouldConjunction HaveSetter() public TRuleTypeShouldConjunction HavePrivateSetter() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.HavePrivateSetter()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.HavePrivateSetter() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HavePublicSetter() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.HavePublicSetter()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.HavePublicSetter() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveProtectedSetter() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.HaveProtectedSetter()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.HaveProtectedSetter() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveInternalSetter() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.HaveInternalSetter()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.HaveInternalSetter() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveProtectedInternalSetter() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.HaveProtectedInternalSetter()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.HaveProtectedInternalSetter() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HavePrivateProtectedSetter() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.HavePrivateProtectedSetter()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.HavePrivateProtectedSetter() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveInitOnlySetter() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.HaveInitSetter()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.HaveInitSetter() + ); return Create(_ruleCreator); } @@ -115,7 +140,6 @@ public TRuleTypeShouldConjunction AreVirtual() return Create(_ruleCreator); } - //Negations @@ -127,37 +151,49 @@ public TRuleTypeShouldConjunction HaveNoGetter() public TRuleTypeShouldConjunction DoNotHavePrivateGetter() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.DoNotHavePrivateGetter()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.DoNotHavePrivateGetter() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotHavePublicGetter() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.DoNotHavePublicGetter()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.DoNotHavePublicGetter() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotHaveProtectedGetter() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.DoNotHaveProtectedGetter()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.DoNotHaveProtectedGetter() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotHaveInternalGetter() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.DoNotHaveInternalGetter()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.DoNotHaveInternalGetter() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotHaveProtectedInternalGetter() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.DoNotHaveProtectedInternalGetter()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.DoNotHaveProtectedInternalGetter() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotHavePrivateProtectedGetter() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.DoNotHavePrivateProtectedGetter()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.DoNotHavePrivateProtectedGetter() + ); return Create(_ruleCreator); } @@ -169,50 +205,66 @@ public TRuleTypeShouldConjunction HaveNoSetter() public TRuleTypeShouldConjunction DoNotHavePrivateSetter() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.DoNotHavePrivateSetter()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.DoNotHavePrivateSetter() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotHavePublicSetter() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.DoNotHavePublicSetter()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.DoNotHavePublicSetter() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotHaveProtectedSetter() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.DoNotHaveProtectedSetter()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.DoNotHaveProtectedSetter() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotHaveInternalSetter() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.DoNotHaveInternalSetter()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.DoNotHaveInternalSetter() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotHaveProtectedInternalSetter() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.DoNotHaveProtectedInternalSetter()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.DoNotHaveProtectedInternalSetter() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotHavePrivateProtectedSetter() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.DoNotHavePrivateProtectedSetter()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.DoNotHavePrivateProtectedSetter() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotHaveInitOnlySetter() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.DoNotHaveInitSetter()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.DoNotHaveInitSetter() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNotVirtual() { - _ruleCreator.ContinueComplexCondition(PropertyMemberPredicateDefinition.AreNotVirtual()); + _ruleCreator.ContinueComplexCondition( + PropertyMemberPredicateDefinition.AreNotVirtual() + ); return Create(_ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/ShouldRelateToMembersThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/ShouldRelateToMembersThat.cs index e7ef54cdf..186175ee5 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/ShouldRelateToMembersThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/ShouldRelateToMembersThat.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -11,148 +11,204 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Members { - public class ShouldRelateToMembersThat : - ShouldRelateToObjectsThat, - IMemberPredicates + public class ShouldRelateToMembersThat + : ShouldRelateToObjectsThat, + IMemberPredicates where TReferenceType : IMember where TRuleType : ICanBeAnalyzed { // ReSharper disable once MemberCanBeProtected.Global - public ShouldRelateToMembersThat(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public ShouldRelateToMembersThat(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } - public TRuleTypeShouldConjunction AreDeclaredIn(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction AreDeclaredIn( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - MemberPredicatesDefinition.AreDeclaredIn(pattern, useRegularExpressions)); + MemberPredicatesDefinition.AreDeclaredIn( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction AreDeclaredIn(IEnumerable patterns, - bool useRegularExpressions = false) + public TRuleTypeShouldConjunction AreDeclaredIn( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - MemberPredicatesDefinition.AreDeclaredIn(patterns, useRegularExpressions)); + MemberPredicatesDefinition.AreDeclaredIn( + patterns, + useRegularExpressions + ) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreDeclaredIn(IType firstType, params IType[] moreTypes) { _ruleCreator.ContinueComplexCondition( - MemberPredicatesDefinition.AreDeclaredIn(firstType, moreTypes)); + MemberPredicatesDefinition.AreDeclaredIn(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreDeclaredIn(Type firstType, params Type[] moreTypes) { _ruleCreator.ContinueComplexCondition( - MemberPredicatesDefinition.AreDeclaredIn(firstType, moreTypes)); + MemberPredicatesDefinition.AreDeclaredIn(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreDeclaredIn(IObjectProvider types) { - _ruleCreator.ContinueComplexCondition(MemberPredicatesDefinition.AreDeclaredIn(types)); + _ruleCreator.ContinueComplexCondition( + MemberPredicatesDefinition.AreDeclaredIn(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreDeclaredIn(IEnumerable types) { - _ruleCreator.ContinueComplexCondition(MemberPredicatesDefinition.AreDeclaredIn(types)); + _ruleCreator.ContinueComplexCondition( + MemberPredicatesDefinition.AreDeclaredIn(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreDeclaredIn(IEnumerable types) { - _ruleCreator.ContinueComplexCondition(MemberPredicatesDefinition.AreDeclaredIn(types)); + _ruleCreator.ContinueComplexCondition( + MemberPredicatesDefinition.AreDeclaredIn(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreStatic() { - _ruleCreator.ContinueComplexCondition(MemberPredicatesDefinition.AreStatic()); + _ruleCreator.ContinueComplexCondition( + MemberPredicatesDefinition.AreStatic() + ); return Create(_ruleCreator); } - + public TRuleTypeShouldConjunction AreReadOnly() { - _ruleCreator.ContinueComplexCondition(MemberPredicatesDefinition.AreReadOnly()); + _ruleCreator.ContinueComplexCondition( + MemberPredicatesDefinition.AreReadOnly() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreImmutable() { - _ruleCreator.ContinueComplexCondition(MemberPredicatesDefinition.AreImmutable()); + _ruleCreator.ContinueComplexCondition( + MemberPredicatesDefinition.AreImmutable() + ); return Create(_ruleCreator); } //Negations - public TRuleTypeShouldConjunction AreNotDeclaredIn(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction AreNotDeclaredIn( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - MemberPredicatesDefinition.AreNotDeclaredIn(pattern, useRegularExpressions)); + MemberPredicatesDefinition.AreNotDeclaredIn( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction AreNotDeclaredIn(IEnumerable patterns, - bool useRegularExpressions = false) + public TRuleTypeShouldConjunction AreNotDeclaredIn( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - MemberPredicatesDefinition.AreNotDeclaredIn(patterns, useRegularExpressions)); + MemberPredicatesDefinition.AreNotDeclaredIn( + patterns, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction AreNotDeclaredIn(IType firstType, params IType[] moreTypes) + public TRuleTypeShouldConjunction AreNotDeclaredIn( + IType firstType, + params IType[] moreTypes + ) { _ruleCreator.ContinueComplexCondition( - MemberPredicatesDefinition.AreNotDeclaredIn(firstType, moreTypes)); + MemberPredicatesDefinition.AreNotDeclaredIn(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNotDeclaredIn(Type firstType, params Type[] moreTypes) { _ruleCreator.ContinueComplexCondition( - MemberPredicatesDefinition.AreNotDeclaredIn(firstType, moreTypes)); + MemberPredicatesDefinition.AreNotDeclaredIn(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNotDeclaredIn(IObjectProvider types) { - _ruleCreator.ContinueComplexCondition(MemberPredicatesDefinition.AreNotDeclaredIn(types)); + _ruleCreator.ContinueComplexCondition( + MemberPredicatesDefinition.AreNotDeclaredIn(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNotDeclaredIn(IEnumerable types) { - _ruleCreator.ContinueComplexCondition(MemberPredicatesDefinition.AreNotDeclaredIn(types)); + _ruleCreator.ContinueComplexCondition( + MemberPredicatesDefinition.AreNotDeclaredIn(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNotDeclaredIn(IEnumerable types) { - _ruleCreator.ContinueComplexCondition(MemberPredicatesDefinition.AreNotDeclaredIn(types)); + _ruleCreator.ContinueComplexCondition( + MemberPredicatesDefinition.AreNotDeclaredIn(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNotStatic() { - _ruleCreator.ContinueComplexCondition(MemberPredicatesDefinition.AreNotStatic()); + _ruleCreator.ContinueComplexCondition( + MemberPredicatesDefinition.AreNotStatic() + ); return Create(_ruleCreator); } - + public TRuleTypeShouldConjunction AreNotReadOnly() { - _ruleCreator.ContinueComplexCondition(MemberPredicatesDefinition.AreNotReadOnly()); + _ruleCreator.ContinueComplexCondition( + MemberPredicatesDefinition.AreNotReadOnly() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNotImmutable() { - _ruleCreator.ContinueComplexCondition(MemberPredicatesDefinition.AreNotImmutable()); + _ruleCreator.ContinueComplexCondition( + MemberPredicatesDefinition.AreNotImmutable() + ); return Create(_ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/ObjectConditionsDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/ObjectConditionsDefinition.cs index c4e58fc13..96df6b2ee 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/ObjectConditionsDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/ObjectConditionsDefinition.cs @@ -29,12 +29,23 @@ public static ICondition Be(string pattern, bool useRegularExpression { return new SimpleCondition( obj => obj.FullNameMatches(pattern, useRegularExpressions), - "have full name " + (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\"", - "does not have full name " + (useRegularExpressions ? "matching " : "") + "\"" + pattern + - "\""); - } - - public static ICondition Be(IEnumerable patterns, bool useRegularExpressions = false) + "have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"", + "does not have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + public static ICondition Be( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); string description; @@ -47,25 +58,44 @@ public static ICondition Be(IEnumerable patterns, bool useReg else { var firstPattern = patternList.First(); - description = patternList.Where(pattern => !pattern.Equals(firstPattern)).Distinct().Aggregate( - "have full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", - (current, pattern) => current + " or \"" + pattern + "\""); - failDescription = patternList.Where(pattern => !pattern.Equals(firstPattern)).Distinct().Aggregate( - "does not have full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", - (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + failDescription = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "does not have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimpleCondition( - obj => patternList.Any(pattern => obj.FullNameMatches(pattern, useRegularExpressions)), - description, failDescription); + obj => + patternList.Any(pattern => obj.FullNameMatches(pattern, useRegularExpressions)), + description, + failDescription + ); } - - public static ICondition Be(ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects) + public static ICondition Be( + ICanBeAnalyzed firstObject, + params ICanBeAnalyzed[] moreObjects + ) { - var objects = new List {firstObject}; + var objects = new List { firstObject }; objects.AddRange(moreObjects); return Be(objects); } @@ -84,12 +114,20 @@ public static ICondition Be(IEnumerable objects) else { var firstObject = objectList.First(); - description = objectList.Where(obj => !obj.Equals(firstObject)).Distinct().Aggregate( - "be \"" + firstObject.FullName + "\"", - (current, obj) => current + " or \"" + obj.FullName + "\""); - failDescription = objectList.Where(obj => !obj.Equals(firstObject)).Distinct().Aggregate( - "is not \"" + firstObject.FullName + "\"", - (current, obj) => current + " or \"" + obj.FullName + "\""); + description = objectList + .Where(obj => !obj.Equals(firstObject)) + .Distinct() + .Aggregate( + "be \"" + firstObject.FullName + "\"", + (current, obj) => current + " or \"" + obj.FullName + "\"" + ); + failDescription = objectList + .Where(obj => !obj.Equals(firstObject)) + .Distinct() + .Aggregate( + "is not \"" + firstObject.FullName + "\"", + (current, obj) => current + " or \"" + obj.FullName + "\"" + ); } IEnumerable Condition(IEnumerable ruleTypes) @@ -107,20 +145,26 @@ IEnumerable Condition(IEnumerable ruleTypes) } } - return new EnumerableCondition(Condition, description); } public static ICondition Be(IObjectProvider objectProvider) { - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var objectList = objectProvider.GetObjects(architecture).ToList(); var typeList = ruleTypes.ToList(); var passedObjects = objectList.OfType().Intersect(typeList).ToList(); foreach (var failedObject in typeList.Except(passedObjects)) { - yield return new ConditionResult(failedObject, false, "is not " + objectProvider.Description); + yield return new ConditionResult( + failedObject, + false, + "is not " + objectProvider.Description + ); } foreach (var passedObject in passedObjects) @@ -129,27 +173,44 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite } } - return new ArchitectureCondition(Condition, "be " + objectProvider.Description); + return new ArchitectureCondition( + Condition, + "be " + objectProvider.Description + ); } - public static ICondition CallAny(string pattern, bool useRegularExpressions = false) + public static ICondition CallAny( + string pattern, + bool useRegularExpressions = false + ) { return new SimpleCondition( obj => obj.CallsMethod(pattern, useRegularExpressions), - "calls any method with full name " + (useRegularExpressions ? "matching " : "") + "\"" + - pattern + "\"", - "does not call any method with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + pattern + "\""); - } - - public static ICondition CallAny(IEnumerable patterns, - bool useRegularExpressions = false) + "calls any method with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"", + "does not call any method with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + public static ICondition CallAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Condition(TRuleType ruleType) { - return patternList.Any(pattern => ruleType.CallsMethod(pattern, useRegularExpressions)); + return patternList.Any(pattern => + ruleType.CallsMethod(pattern, useRegularExpressions) + ); } string description; @@ -162,33 +223,54 @@ bool Condition(TRuleType ruleType) else { var firstPattern = patternList.First(); - description = patternList.Where(pattern => !pattern.Equals(firstPattern)).Distinct().Aggregate( - "calls any method with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", - (current, pattern) => current + " or \"" + pattern + "\""); - failDescription = patternList.Where(pattern => !pattern.Equals(firstPattern)).Distinct().Aggregate( - "does not call any methods with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", - (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "calls any method with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + failDescription = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "does not call any methods with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimpleCondition(Condition, description, failDescription); } - public static ICondition CallAny(MethodMember method, params MethodMember[] moreMethods) + public static ICondition CallAny( + MethodMember method, + params MethodMember[] moreMethods + ) { - var methods = new List {method}; + var methods = new List { method }; methods.AddRange(moreMethods); return CallAny(methods); } public static ICondition CallAny(IObjectProvider objectProvider) { - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var methodList = objectProvider.GetObjects(architecture).ToList(); var typeList = ruleTypes.ToList(); - var passedObjects = typeList.Where(type => type.GetCalledMethods().Intersect(methodList).Any()) + var passedObjects = typeList + .Where(type => type.GetCalledMethods().Intersect(methodList).Any()) .ToList(); foreach (var failedObject in typeList.Except(passedObjects)) { @@ -196,7 +278,9 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite var first = true; foreach (var method in failedObject.GetCalledMethods().Except(methodList)) { - dynamicFailDescription += first ? " " + method.FullName : " and " + method.FullName; + dynamicFailDescription += first + ? " " + method.FullName + : " and " + method.FullName; first = false; } @@ -220,7 +304,8 @@ public static ICondition CallAny(IEnumerable methods) IEnumerable Condition(IEnumerable ruleTypes) { var typeList = ruleTypes.ToList(); - var passedObjects = typeList.Where(type => type.GetCalledMethods().Intersect(methodList).Any()) + var passedObjects = typeList + .Where(type => type.GetCalledMethods().Intersect(methodList).Any()) .ToList(); foreach (var failedObject in typeList.Except(passedObjects)) { @@ -228,7 +313,9 @@ IEnumerable Condition(IEnumerable ruleTypes) var first = true; foreach (var method in failedObject.GetCalledMethods().Except(methodList)) { - dynamicFailDescription += first ? " " + method.FullName : " and " + method.FullName; + dynamicFailDescription += first + ? " " + method.FullName + : " and " + method.FullName; first = false; } @@ -249,34 +336,55 @@ IEnumerable Condition(IEnumerable ruleTypes) else { var firstMethod = methodList.First(); - description = methodList.Where(method => !method.Equals(firstMethod)).Distinct().Aggregate( - "call \"" + firstMethod.FullName + "\"", - (current, method) => current + " or \"" + method.FullName + "\""); + description = methodList + .Where(method => !method.Equals(firstMethod)) + .Distinct() + .Aggregate( + "call \"" + firstMethod.FullName + "\"", + (current, method) => current + " or \"" + method.FullName + "\"" + ); } return new EnumerableCondition(Condition, description); } - public static ICondition DependOnAny(string pattern, bool useRegularExpressions = false) + public static ICondition DependOnAny( + string pattern, + bool useRegularExpressions = false + ) { return new SimpleCondition( obj => obj.DependsOn(pattern, useRegularExpressions), - "depend on any types with full name " + (useRegularExpressions ? "matching " : "") + "\"" + - pattern + "\"", - "does not depend on any type with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + pattern + "\""); - } - - public static ICondition DependOnAny(IEnumerable patterns, - bool useRegularExpressions = false) + "depend on any types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"", + "does not depend on any type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + public static ICondition DependOnAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Condition(TRuleType ruleType) { - return !ruleType.GetTypeDependencies().IsNullOrEmpty() && - ruleType.GetTypeDependencies().Any(target => - patternList.Any(pattern => target.FullNameMatches(pattern, useRegularExpressions))); + return !ruleType.GetTypeDependencies().IsNullOrEmpty() + && ruleType + .GetTypeDependencies() + .Any(target => + patternList.Any(pattern => + target.FullNameMatches(pattern, useRegularExpressions) + ) + ); } string description; @@ -289,14 +397,28 @@ bool Condition(TRuleType ruleType) else { var firstPattern = patternList.First(); - description = patternList.Where(pattern => !pattern.Equals(firstPattern)).Distinct().Aggregate( - "depend on any types with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", - (current, pattern) => current + " or \"" + pattern + "\""); - failDescription = patternList.Where(pattern => !pattern.Equals(firstPattern)).Distinct().Aggregate( - "does not depend any types with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", - (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "depend on any types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + failDescription = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "does not depend any types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimpleCondition(Condition, description, failDescription); @@ -304,25 +426,29 @@ bool Condition(TRuleType ruleType) public static ICondition DependOnAny(IType firstType, params IType[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return DependOnAny(types); } public static ICondition DependOnAny(Type firstType, params Type[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return DependOnAny(types); } public static ICondition DependOnAny(IObjectProvider objectProvider) { - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var typeList = objectProvider.GetObjects(architecture).ToList(); var ruleTypeList = ruleTypes.ToList(); - var passedObjects = ruleTypeList.Where(type => type.GetTypeDependencies().Intersect(typeList).Any()) + var passedObjects = ruleTypeList + .Where(type => type.GetTypeDependencies().Intersect(typeList).Any()) .ToList(); foreach (var failedObject in ruleTypeList.Except(passedObjects)) { @@ -330,7 +456,9 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite var first = true; foreach (var type in failedObject.GetTypeDependencies().Except(typeList)) { - dynamicFailDescription += first ? " " + type.FullName : " and " + type.FullName; + dynamicFailDescription += first + ? " " + type.FullName + : " and " + type.FullName; first = false; } @@ -354,7 +482,8 @@ public static ICondition DependOnAny(IEnumerable types) IEnumerable Condition(IEnumerable ruleTypes) { var ruleTypeList = ruleTypes.ToList(); - var passedObjects = ruleTypeList.Where(type => type.GetTypeDependencies().Intersect(typeList).Any()) + var passedObjects = ruleTypeList + .Where(type => type.GetTypeDependencies().Intersect(typeList).Any()) .ToList(); foreach (var failedObject in ruleTypeList.Except(passedObjects)) { @@ -362,7 +491,9 @@ IEnumerable Condition(IEnumerable ruleTypes) var first = true; foreach (var type in failedObject.GetTypeDependencies().Except(typeList)) { - dynamicFailDescription += first ? " " + type.FullName : " and " + type.FullName; + dynamicFailDescription += first + ? " " + type.FullName + : " and " + type.FullName; first = false; } @@ -383,9 +514,13 @@ IEnumerable Condition(IEnumerable ruleTypes) else { var firstType = typeList.First(); - description = typeList.Where(type => !type.Equals(firstType)).Distinct().Aggregate( - "depend on \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => !type.Equals(firstType)) + .Distinct() + .Aggregate( + "depend on \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new EnumerableCondition(Condition, description); @@ -395,7 +530,10 @@ public static ICondition DependOnAny(IEnumerable types) { var typeList = types.ToList(); - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var archUnitTypeList = new List(); foreach (var type in typeList) @@ -419,9 +557,13 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite { var dynamicFailDescription = "does depend on"; var first = true; - foreach (var type in failedObject.GetTypeDependencies().Except(archUnitTypeList)) + foreach ( + var type in failedObject.GetTypeDependencies().Except(archUnitTypeList) + ) { - dynamicFailDescription += first ? " " + type.FullName : " and " + type.FullName; + dynamicFailDescription += first + ? " " + type.FullName + : " and " + type.FullName; first = false; } @@ -442,27 +584,39 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite else { var firstType = typeList.First(); - description = typeList.Where(type => type != firstType).Distinct().Aggregate( - "depend on \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => type != firstType) + .Distinct() + .Aggregate( + "depend on \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new ArchitectureCondition(Condition, description); } - public static ICondition FollowCustomCondition(Func condition, - string description) + public static ICondition FollowCustomCondition( + Func condition, + string description + ) { return new SimpleCondition(condition, description); } - public static ICondition FollowCustomCondition(Func condition, string description, - string failDescription) + public static ICondition FollowCustomCondition( + Func condition, + string description, + string failDescription + ) { return new SimpleCondition(condition, description, failDescription); } - public static ICondition OnlyDependOn(string pattern, bool useRegularExpressions = false) + public static ICondition OnlyDependOn( + string pattern, + bool useRegularExpressions = false + ) { ConditionResult Condition(TRuleType ruleType) { @@ -472,7 +626,9 @@ ConditionResult Condition(TRuleType ruleType) { if (!dependency.FullNameMatches(pattern, useRegularExpressions)) { - dynamicFailDescription += pass ? " " + dependency.FullName : " and " + dependency.FullName; + dynamicFailDescription += pass + ? " " + dependency.FullName + : " and " + dependency.FullName; pass = false; } } @@ -480,13 +636,20 @@ ConditionResult Condition(TRuleType ruleType) return new ConditionResult(ruleType, pass, dynamicFailDescription); } - return new SimpleCondition(Condition, - "only depend on types with full name " + (useRegularExpressions ? "matching " : "") + "\"" + - pattern + "\""); + return new SimpleCondition( + Condition, + "only depend on types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static ICondition OnlyDependOn(IEnumerable patterns, - bool useRegularExpressions = false) + public static ICondition OnlyDependOn( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); @@ -496,9 +659,15 @@ ConditionResult Condition(TRuleType ruleType) var dynamicFailDescription = "does depend on"; foreach (var dependency in ruleType.GetTypeDependencies()) { - if (!patternList.Any(pattern => dependency.FullNameMatches(pattern, useRegularExpressions))) + if ( + !patternList.Any(pattern => + dependency.FullNameMatches(pattern, useRegularExpressions) + ) + ) { - dynamicFailDescription += pass ? " " + dependency.FullName : " and " + dependency.FullName; + dynamicFailDescription += pass + ? " " + dependency.FullName + : " and " + dependency.FullName; pass = false; } } @@ -514,9 +683,17 @@ ConditionResult Condition(TRuleType ruleType) else { var firstPattern = patternList.First(); - description = patternList.Where(pattern => !pattern.Equals(firstPattern)).Distinct().Aggregate( - "only depend on types with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "only depend on types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimpleCondition(Condition, description); @@ -524,21 +701,24 @@ ConditionResult Condition(TRuleType ruleType) public static ICondition OnlyDependOn(IType firstType, params IType[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return OnlyDependOn(types); } public static ICondition OnlyDependOn(Type firstType, params Type[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return OnlyDependOn(types); } public static ICondition OnlyDependOn(IObjectProvider objectProvider) { - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var typeList = objectProvider.GetObjects(architecture).ToList(); var ruleTypeList = ruleTypes.ToList(); @@ -551,7 +731,9 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite var first = true; foreach (var type in failedObject.GetTypeDependencies().Except(typeList)) { - dynamicFailDescription += first ? " " + type.FullName : " and " + type.FullName; + dynamicFailDescription += first + ? " " + type.FullName + : " and " + type.FullName; first = false; } @@ -572,7 +754,10 @@ public static ICondition OnlyDependOn(IEnumerable types) { var typeList = types.ToList(); - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var ruleTypeList = ruleTypes.ToList(); var failedObjects = ruleTypeList @@ -584,7 +769,9 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite var first = true; foreach (var type in failedObject.GetTypeDependencies().Except(typeList)) { - dynamicFailDescription += first ? " " + type.FullName : " and " + type.FullName; + dynamicFailDescription += first + ? " " + type.FullName + : " and " + type.FullName; first = false; } @@ -605,9 +792,13 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite else { var firstType = typeList.First(); - description = typeList.Where(type => !type.Equals(firstType)).Distinct().Aggregate( - "only depend on \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => !type.Equals(firstType)) + .Distinct() + .Aggregate( + "only depend on \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new ArchitectureCondition(Condition, description); @@ -617,7 +808,10 @@ public static ICondition OnlyDependOn(IEnumerable types) { var typeList = types.ToList(); - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var archUnitTypeList = new List(); foreach (var type in typeList) @@ -635,15 +829,21 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite var ruleTypeList = ruleTypes.ToList(); var failedObjects = ruleTypeList - .Where(type => type.GetTypeDependencies(architecture).Except(archUnitTypeList).Any()) + .Where(type => + type.GetTypeDependencies(architecture).Except(archUnitTypeList).Any() + ) .ToList(); foreach (var failedObject in failedObjects) { var dynamicFailDescription = "does depend on"; var first = true; - foreach (var type in failedObject.GetTypeDependencies().Except(archUnitTypeList)) + foreach ( + var type in failedObject.GetTypeDependencies().Except(archUnitTypeList) + ) { - dynamicFailDescription += first ? " " + type.FullName : " and " + type.FullName; + dynamicFailDescription += first + ? " " + type.FullName + : " and " + type.FullName; first = false; } @@ -664,33 +864,52 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite else { var firstType = typeList.First(); - description = typeList.Where(type => type != firstType).Distinct().Aggregate( - "only depend on \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => type != firstType) + .Distinct() + .Aggregate( + "only depend on \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new ArchitectureCondition(Condition, description); } - public static ICondition HaveAnyAttributes(string pattern, bool useRegularExpressions = false) + public static ICondition HaveAnyAttributes( + string pattern, + bool useRegularExpressions = false + ) { return new SimpleCondition( obj => obj.HasAttribute(pattern, useRegularExpressions), - "have any attribute with full name " + (useRegularExpressions ? "matching " : "") + "\"" + - pattern + "\"", - "does not have any attribute with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + pattern + "\""); - } - - public static ICondition HaveAnyAttributes(IEnumerable patterns, - bool useRegularExpressions = false) + "have any attribute with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"", + "does not have any attribute with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + public static ICondition HaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Condition(TRuleType ruleType) { return ruleType.Attributes.Any(attribute => - patternList.Any(pattern => attribute.FullNameMatches(pattern, useRegularExpressions))); + patternList.Any(pattern => + attribute.FullNameMatches(pattern, useRegularExpressions) + ) + ); } string description; @@ -703,47 +922,74 @@ bool Condition(TRuleType ruleType) else { var firstPattern = patternList.First(); - description = patternList.Where(pattern => !pattern.Equals(firstPattern)).Distinct().Aggregate( - "have any attribute with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", - (current, pattern) => current + " or \"" + pattern + "\""); - failDescription = patternList.Where(pattern => !pattern.Equals(firstPattern)).Distinct().Aggregate( - "does not have any attribute with full name " + - (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", - (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "have any attribute with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + failDescription = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "does not have any attribute with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimpleCondition(Condition, description, failDescription); } - public static ICondition HaveAnyAttributes(Attribute firstAttribute, - params Attribute[] moreAttributes) + public static ICondition HaveAnyAttributes( + Attribute firstAttribute, + params Attribute[] moreAttributes + ) { - var attributes = new List {firstAttribute}; + var attributes = new List { firstAttribute }; attributes.AddRange(moreAttributes); return HaveAnyAttributes(attributes); } - public static ICondition HaveAnyAttributes(Type firstAttribute, params Type[] moreAttributes) + public static ICondition HaveAnyAttributes( + Type firstAttribute, + params Type[] moreAttributes + ) { - var attributes = new List {firstAttribute}; + var attributes = new List { firstAttribute }; attributes.AddRange(moreAttributes); return HaveAnyAttributes(attributes); } - public static ICondition HaveAnyAttributes(IObjectProvider objectProvider) + public static ICondition HaveAnyAttributes( + IObjectProvider objectProvider + ) { - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var attributeList = objectProvider.GetObjects(architecture).ToList(); var ruleTypeList = ruleTypes.ToList(); - var passedObjects = ruleTypeList.Where(type => type.Attributes.Intersect(attributeList).Any()) + var passedObjects = ruleTypeList + .Where(type => type.Attributes.Intersect(attributeList).Any()) .ToList(); foreach (var failedObject in ruleTypeList.Except(passedObjects)) { - yield return new ConditionResult(failedObject, false, - "does not have any " + objectProvider.Description); + yield return new ConditionResult( + failedObject, + false, + "does not have any " + objectProvider.Description + ); } foreach (var passedObject in passedObjects) @@ -770,19 +1016,27 @@ public static ICondition HaveAnyAttributes(IEnumerable att else { var firstAttribute = attributeList.First(); - description = attributeList.Where(attribute => !attribute.Equals(firstAttribute)).Distinct().Aggregate( - "have attribute \"" + firstAttribute.FullName + "\"", - (current, attribute) => current + " or \"" + attribute.FullName + "\""); - failDescription = attributeList.Where(attribute => !attribute.Equals(firstAttribute)).Distinct() + description = attributeList + .Where(attribute => !attribute.Equals(firstAttribute)) + .Distinct() + .Aggregate( + "have attribute \"" + firstAttribute.FullName + "\"", + (current, attribute) => current + " or \"" + attribute.FullName + "\"" + ); + failDescription = attributeList + .Where(attribute => !attribute.Equals(firstAttribute)) + .Distinct() .Aggregate( "does not have attribute \"" + firstAttribute.FullName + "\"", - (current, attribute) => current + " or \"" + attribute.FullName + "\""); + (current, attribute) => current + " or \"" + attribute.FullName + "\"" + ); } IEnumerable Condition(IEnumerable ruleTypes) { var ruleTypeList = ruleTypes.ToList(); - var passedObjects = ruleTypeList.Where(type => type.Attributes.Intersect(attributeList).Any()) + var passedObjects = ruleTypeList + .Where(type => type.Attributes.Intersect(attributeList).Any()) .ToList(); foreach (var failedObject in ruleTypeList.Except(passedObjects)) { @@ -812,19 +1066,33 @@ public static ICondition HaveAnyAttributes(IEnumerable attribut else { var firstAttribute = attributeList.First(); - description = attributeList.Where(attribute => attribute != firstAttribute).Distinct().Aggregate( - "have attribute \"" + firstAttribute.FullName + "\"", - (current, attribute) => current + " or \"" + attribute.FullName + "\""); - failDescription = attributeList.Where(attribute => attribute != firstAttribute).Distinct().Aggregate( - "does not have attribute \"" + firstAttribute.FullName + "\"", - (current, attribute) => current + " or \"" + attribute.FullName + "\""); + description = attributeList + .Where(attribute => attribute != firstAttribute) + .Distinct() + .Aggregate( + "have attribute \"" + firstAttribute.FullName + "\"", + (current, attribute) => current + " or \"" + attribute.FullName + "\"" + ); + failDescription = attributeList + .Where(attribute => attribute != firstAttribute) + .Distinct() + .Aggregate( + "does not have attribute \"" + firstAttribute.FullName + "\"", + (current, attribute) => current + " or \"" + attribute.FullName + "\"" + ); } - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { - var archAttributeList = attributeList.Select(architecture.GetAttributeOfType).ToList(); + var archAttributeList = attributeList + .Select(architecture.GetAttributeOfType) + .ToList(); var ruleTypeList = ruleTypes.ToList(); - var passedObjects = ruleTypeList.Where(type => type.Attributes.Intersect(archAttributeList).Any()) + var passedObjects = ruleTypeList + .Where(type => type.Attributes.Intersect(archAttributeList).Any()) .ToList(); foreach (var failedObject in ruleTypeList.Except(passedObjects)) { @@ -840,26 +1108,41 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite return new ArchitectureCondition(Condition, description); } - - public static ICondition OnlyHaveAttributes(string pattern, bool useRegularExpressions = false) + public static ICondition OnlyHaveAttributes( + string pattern, + bool useRegularExpressions = false + ) { return new SimpleCondition( obj => obj.OnlyHasAttributes(pattern, useRegularExpressions), - "only have attributes with full name " + (useRegularExpressions ? "matching " : "") + "\"" + - pattern + "\"", - "does not only have attributes with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + pattern + "\""); - } - - public static ICondition OnlyHaveAttributes(IEnumerable patterns, - bool useRegularExpressions = false) + "only have attributes with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"", + "does not only have attributes with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + public static ICondition OnlyHaveAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Condition(TRuleType ruleType) { - return ruleType.Attributes.IsNullOrEmpty() || ruleType.Attributes.All(attribute => - patternList.Any(pattern => attribute.FullNameMatches(pattern, useRegularExpressions))); + return ruleType.Attributes.IsNullOrEmpty() + || ruleType.Attributes.All(attribute => + patternList.Any(pattern => + attribute.FullNameMatches(pattern, useRegularExpressions) + ) + ); } string description; @@ -872,42 +1155,66 @@ bool Condition(TRuleType ruleType) else { var firstPattern = patternList.First(); - description = patternList.Where(pattern => !pattern.Equals(firstPattern)).Distinct().Aggregate( - "only have attributes with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", - (current, pattern) => current + " and \"" + pattern + "\""); - failDescription = patternList.Where(pattern => !pattern.Equals(firstPattern)).Distinct().Aggregate( - "does not only have attributes with full name " + - (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", - (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "only have attributes with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " and \"" + pattern + "\"" + ); + failDescription = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "does not only have attributes with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimpleCondition(Condition, description, failDescription); } - public static ICondition OnlyHaveAttributes(Attribute firstAttribute, - params Attribute[] moreAttributes) + public static ICondition OnlyHaveAttributes( + Attribute firstAttribute, + params Attribute[] moreAttributes + ) { - var attributes = new List {firstAttribute}; + var attributes = new List { firstAttribute }; attributes.AddRange(moreAttributes); return OnlyHaveAttributes(attributes); } - public static ICondition OnlyHaveAttributes(Type firstAttribute, params Type[] moreAttributes) + public static ICondition OnlyHaveAttributes( + Type firstAttribute, + params Type[] moreAttributes + ) { - var attributes = new List {firstAttribute}; + var attributes = new List { firstAttribute }; attributes.AddRange(moreAttributes); return OnlyHaveAttributes(attributes); } - public static ICondition OnlyHaveAttributes(IObjectProvider objectProvider) + public static ICondition OnlyHaveAttributes( + IObjectProvider objectProvider + ) { - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var attributeList = objectProvider.GetObjects(architecture).ToList(); var ruleTypeList = ruleTypes.ToList(); - var failedObjects = ruleTypeList.Where(type => type.Attributes.Except(attributeList).Any()) + var failedObjects = ruleTypeList + .Where(type => type.Attributes.Except(attributeList).Any()) .ToList(); foreach (var failedObject in failedObjects) { @@ -915,7 +1222,9 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite var first = true; foreach (var attribute in failedObject.Attributes.Except(attributeList)) { - dynamicFailDescription += first ? " " + attribute.FullName : " and " + attribute.FullName; + dynamicFailDescription += first + ? " " + attribute.FullName + : " and " + attribute.FullName; first = false; } @@ -939,7 +1248,8 @@ public static ICondition OnlyHaveAttributes(IEnumerable at IEnumerable Condition(IEnumerable ruleTypes) { var ruleTypeList = ruleTypes.ToList(); - var failedObjects = ruleTypeList.Where(type => type.Attributes.Except(attributeList).Any()) + var failedObjects = ruleTypeList + .Where(type => type.Attributes.Except(attributeList).Any()) .ToList(); foreach (var failedObject in failedObjects) { @@ -947,7 +1257,9 @@ IEnumerable Condition(IEnumerable ruleTypes) var first = true; foreach (var attribute in failedObject.Attributes.Except(attributeList)) { - dynamicFailDescription += first ? " " + attribute.FullName : " and " + attribute.FullName; + dynamicFailDescription += first + ? " " + attribute.FullName + : " and " + attribute.FullName; first = false; } @@ -968,9 +1280,13 @@ IEnumerable Condition(IEnumerable ruleTypes) else { var firstAttribute = attributeList.First(); - description = attributeList.Where(attribute => !attribute.Equals(firstAttribute)).Distinct().Aggregate( - "only have attributes \"" + firstAttribute.FullName + "\"", - (current, attribute) => current + " and \"" + attribute.FullName + "\""); + description = attributeList + .Where(attribute => !attribute.Equals(firstAttribute)) + .Distinct() + .Aggregate( + "only have attributes \"" + firstAttribute.FullName + "\"", + (current, attribute) => current + " and \"" + attribute.FullName + "\"" + ); } return new EnumerableCondition(Condition, description); @@ -980,7 +1296,10 @@ public static ICondition OnlyHaveAttributes(IEnumerable attribu { var attributeList = attributes.ToList(); - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var archUnitAttributeList = new List(); foreach (var type in attributeList) @@ -997,7 +1316,8 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite } var ruleTypeList = ruleTypes.ToList(); - var failedObjects = ruleTypeList.Where(type => type.Attributes.Except(archUnitAttributeList).Any()) + var failedObjects = ruleTypeList + .Where(type => type.Attributes.Except(archUnitAttributeList).Any()) .ToList(); foreach (var failedObject in failedObjects) { @@ -1005,7 +1325,9 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite var first = true; foreach (var attribute in failedObject.Attributes.Except(archUnitAttributeList)) { - dynamicFailDescription += first ? " " + attribute.FullName : " and " + attribute.FullName; + dynamicFailDescription += first + ? " " + attribute.FullName + : " and " + attribute.FullName; first = false; } @@ -1026,81 +1348,109 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite else { var firstAttribute = attributeList.First(); - description = attributeList.Where(attribute => attribute != firstAttribute).Distinct().Aggregate( - "only have attributes \"" + firstAttribute.FullName + "\"", - (current, attribute) => current + " and \"" + attribute.FullName + "\""); + description = attributeList + .Where(attribute => attribute != firstAttribute) + .Distinct() + .Aggregate( + "only have attributes \"" + firstAttribute.FullName + "\"", + (current, attribute) => current + " and \"" + attribute.FullName + "\"" + ); } return new ArchitectureCondition(Condition, description); } - public static ICondition HaveAnyAttributesWithArguments(object firstArgumentValue, - params object[] moreArgumentValues) + public static ICondition HaveAnyAttributesWithArguments( + object firstArgumentValue, + params object[] moreArgumentValues + ) { - var argumentValues = new List {firstArgumentValue}; + var argumentValues = new List { firstArgumentValue }; argumentValues.AddRange(moreArgumentValues); return HaveAnyAttributesWithArguments(argumentValues); } - public static ICondition HaveAttributeWithArguments(string attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public static ICondition HaveAttributeWithArguments( + string attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { - var argumentValues = new List {firstArgumentValue}; + var argumentValues = new List { firstArgumentValue }; argumentValues.AddRange(moreArgumentValues); return HaveAttributeWithArguments(attribute, argumentValues); } - public static ICondition HaveAttributeWithArguments(Attribute attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public static ICondition HaveAttributeWithArguments( + Attribute attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { - var argumentValues = new List {firstArgumentValue}; + var argumentValues = new List { firstArgumentValue }; argumentValues.AddRange(moreArgumentValues); return HaveAttributeWithArguments(attribute, argumentValues); } - public static ICondition HaveAttributeWithArguments(Type attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public static ICondition HaveAttributeWithArguments( + Type attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { - var argumentValues = new List {firstArgumentValue}; + var argumentValues = new List { firstArgumentValue }; argumentValues.AddRange(moreArgumentValues); return HaveAttributeWithArguments(attribute, argumentValues); } - public static ICondition HaveAnyAttributesWithNamedArguments((string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments) + public static ICondition HaveAnyAttributesWithNamedArguments( + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { - var attributeArguments = new List<(string, object)> {firstAttributeArgument}; + var attributeArguments = new List<(string, object)> { firstAttributeArgument }; attributeArguments.AddRange(moreAttributeArguments); return HaveAnyAttributesWithNamedArguments(attributeArguments); } - public static ICondition HaveAttributeWithNamedArguments(string attribute, - (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments) + public static ICondition HaveAttributeWithNamedArguments( + string attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { - var attributeArguments = new List<(string, object)> {firstAttributeArgument}; + var attributeArguments = new List<(string, object)> { firstAttributeArgument }; attributeArguments.AddRange(moreAttributeArguments); return HaveAttributeWithNamedArguments(attribute, attributeArguments); } - public static ICondition HaveAttributeWithNamedArguments(Attribute attribute, - (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments) + public static ICondition HaveAttributeWithNamedArguments( + Attribute attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { - var attributeArguments = new List<(string, object)> {firstAttributeArgument}; + var attributeArguments = new List<(string, object)> { firstAttributeArgument }; attributeArguments.AddRange(moreAttributeArguments); return HaveAttributeWithNamedArguments(attribute, attributeArguments); } - public static ICondition HaveAttributeWithNamedArguments(Type attribute, - (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments) + public static ICondition HaveAttributeWithNamedArguments( + Type attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { - var attributeArguments = new List<(string, object)> {firstAttributeArgument}; + var attributeArguments = new List<(string, object)> { firstAttributeArgument }; attributeArguments.AddRange(moreAttributeArguments); return HaveAttributeWithNamedArguments(attribute, attributeArguments); } - public static ICondition HaveAnyAttributesWithArguments(IEnumerable argumentValues) + public static ICondition HaveAnyAttributesWithArguments( + IEnumerable argumentValues + ) { - var argumentValueList = argumentValues?.ToList() ?? new List {null}; + var argumentValueList = argumentValues?.ToList() ?? new List { null }; string description; Func failDescription; if (argumentValueList.IsNullOrEmpty()) @@ -1112,16 +1462,20 @@ public static ICondition HaveAnyAttributesWithArguments(IEnumerable attribute != firstArgument).Aggregate( - "have any attributes with arguments \"" + firstArgument + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\""); - + description = argumentValueList + .Where(attribute => attribute != firstArgument) + .Aggregate( + "have any attributes with arguments \"" + firstArgument + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); failDescription = (ruleType, architecture) => { - var actualArgumentValues = ruleType.AttributeInstances - .SelectMany(instance => - instance.AttributeArguments.Select(argument => argument.Value)).ToList(); + var actualArgumentValues = ruleType + .AttributeInstances.SelectMany(instance => + instance.AttributeArguments.Select(argument => argument.Value) + ) + .ToList(); if (!actualArgumentValues.Any()) { return "does have no attribute with an argument"; @@ -1129,17 +1483,26 @@ public static ICondition HaveAnyAttributesWithArguments(IEnumerable current + " and \"" + argumentValue + "\""); + "does have attributes with argument values \"" + + firstActualArgumentValue + + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); }; } bool Condition(TRuleType obj, Architecture architecture) { - var attributeArguments = obj.AttributeInstances - .SelectMany(instance => instance.AttributeArguments.Select(arg => arg.Value)).ToList(); - var typeAttributeArguments = attributeArguments.OfType>().Select(t => t.Type) - .Union(attributeArguments.OfType()).ToList(); + var attributeArguments = obj + .AttributeInstances.SelectMany(instance => + instance.AttributeArguments.Select(arg => arg.Value) + ) + .ToList(); + var typeAttributeArguments = attributeArguments + .OfType>() + .Select(t => t.Type) + .Union(attributeArguments.OfType()) + .ToList(); foreach (var arg in argumentValueList) { if (arg is Type argType) @@ -1161,11 +1524,14 @@ bool Condition(TRuleType obj, Architecture architecture) return new ArchitectureCondition(Condition, failDescription, description); } - public static ICondition HaveAttributeWithArguments([NotNull] string attribute, - IEnumerable argumentValues) + public static ICondition HaveAttributeWithArguments( + [NotNull] string attribute, + IEnumerable argumentValues + ) { - string description, failDescription; - var argumentValueList = argumentValues?.ToList() ?? new List {null}; + string description, + failDescription; + var argumentValueList = argumentValues?.ToList() ?? new List { null }; if (argumentValueList.IsNullOrEmpty()) { description = "have attribute \"" + attribute + "\""; @@ -1174,12 +1540,26 @@ public static ICondition HaveAttributeWithArguments([NotNull] string else { var firstArgument = argumentValueList.First(); - description = argumentValueList.Where(att => att != firstArgument).Aggregate( - "have attribute \"" + attribute + "\" with arguments \"" + firstArgument + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\""); - failDescription = argumentValueList.Where(att => att != firstArgument).Aggregate( - "does not have attribute \"" + attribute + "\" with arguments \"" + firstArgument + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\""); + description = argumentValueList + .Where(att => att != firstArgument) + .Aggregate( + "have attribute \"" + + attribute + + "\" with arguments \"" + + firstArgument + + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); + failDescription = argumentValueList + .Where(att => att != firstArgument) + .Aggregate( + "does not have attribute \"" + + attribute + + "\" with arguments \"" + + firstArgument + + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); } bool Condition(TRuleType obj, Architecture architecture) @@ -1191,9 +1571,14 @@ bool Condition(TRuleType obj, Architecture architecture) goto NextAttribute; } - var attributeArguments = attributeInstance.AttributeArguments.Select(arg => arg.Value).ToList(); - var typeAttributeArguments = attributeArguments.OfType>().Select(t => t.Type) - .Union(attributeArguments.OfType()).ToList(); + var attributeArguments = attributeInstance + .AttributeArguments.Select(arg => arg.Value) + .ToList(); + var typeAttributeArguments = attributeArguments + .OfType>() + .Select(t => t.Type) + .Union(attributeArguments.OfType()) + .ToList(); foreach (var arg in argumentValueList) { if (arg is Type argType) @@ -1210,7 +1595,8 @@ bool Condition(TRuleType obj, Architecture architecture) } return true; - NextAttribute: ; + NextAttribute: + ; } return false; @@ -1219,11 +1605,14 @@ bool Condition(TRuleType obj, Architecture architecture) return new ArchitectureCondition(Condition, description, failDescription); } - public static ICondition HaveAttributeWithArguments([NotNull] Attribute attribute, - IEnumerable argumentValues) + public static ICondition HaveAttributeWithArguments( + [NotNull] Attribute attribute, + IEnumerable argumentValues + ) { - string description, failDescription; - var argumentValueList = argumentValues?.ToList() ?? new List {null}; + string description, + failDescription; + var argumentValueList = argumentValues?.ToList() ?? new List { null }; if (argumentValueList.IsNullOrEmpty()) { description = "have attribute \"" + attribute.FullName + "\""; @@ -1232,12 +1621,26 @@ public static ICondition HaveAttributeWithArguments([NotNull] Attribu else { var firstArgument = argumentValueList.First(); - description = argumentValueList.Where(att => att != firstArgument).Aggregate( - "have attribute \"" + attribute.FullName + "\" with arguments \"" + firstArgument + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\""); - failDescription = argumentValueList.Where(att => att != firstArgument).Aggregate( - "does not have attribute \"" + attribute.FullName + "\" with arguments \"" + firstArgument + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\""); + description = argumentValueList + .Where(att => att != firstArgument) + .Aggregate( + "have attribute \"" + + attribute.FullName + + "\" with arguments \"" + + firstArgument + + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); + failDescription = argumentValueList + .Where(att => att != firstArgument) + .Aggregate( + "does not have attribute \"" + + attribute.FullName + + "\" with arguments \"" + + firstArgument + + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); } bool Condition(TRuleType obj, Architecture architecture) @@ -1249,9 +1652,14 @@ bool Condition(TRuleType obj, Architecture architecture) goto NextAttribute; } - var attributeArguments = attributeInstance.AttributeArguments.Select(arg => arg.Value).ToList(); - var typeAttributeArguments = attributeArguments.OfType>().Select(t => t.Type) - .Union(attributeArguments.OfType()).ToList(); + var attributeArguments = attributeInstance + .AttributeArguments.Select(arg => arg.Value) + .ToList(); + var typeAttributeArguments = attributeArguments + .OfType>() + .Select(t => t.Type) + .Union(attributeArguments.OfType()) + .ToList(); foreach (var arg in argumentValueList) { if (arg is Type argType) @@ -1268,7 +1676,8 @@ bool Condition(TRuleType obj, Architecture architecture) } return true; - NextAttribute: ; + NextAttribute: + ; } return false; @@ -1277,11 +1686,14 @@ bool Condition(TRuleType obj, Architecture architecture) return new ArchitectureCondition(Condition, description, failDescription); } - public static ICondition HaveAttributeWithArguments([NotNull] Type attribute, - IEnumerable argumentValues) + public static ICondition HaveAttributeWithArguments( + [NotNull] Type attribute, + IEnumerable argumentValues + ) { - string description, failDescription; - var argumentValueList = argumentValues?.ToList() ?? new List {null}; + string description, + failDescription; + var argumentValueList = argumentValues?.ToList() ?? new List { null }; if (argumentValueList.IsNullOrEmpty()) { description = "have attribute \"" + attribute.FullName + "\""; @@ -1290,12 +1702,26 @@ public static ICondition HaveAttributeWithArguments([NotNull] Type at else { var firstArgument = argumentValueList.First(); - description = argumentValueList.Where(att => att != firstArgument).Aggregate( - "have attribute \"" + attribute.FullName + "\" with arguments \"" + firstArgument + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\""); - failDescription = argumentValueList.Where(att => att != firstArgument).Aggregate( - "does not have attribute \"" + attribute.FullName + "\" with arguments \"" + firstArgument + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\""); + description = argumentValueList + .Where(att => att != firstArgument) + .Aggregate( + "have attribute \"" + + attribute.FullName + + "\" with arguments \"" + + firstArgument + + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); + failDescription = argumentValueList + .Where(att => att != firstArgument) + .Aggregate( + "does not have attribute \"" + + attribute.FullName + + "\" with arguments \"" + + firstArgument + + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); } bool Condition(TRuleType obj, Architecture architecture) @@ -1318,9 +1744,14 @@ bool Condition(TRuleType obj, Architecture architecture) goto NextAttribute; } - var attributeArguments = attributeInstance.AttributeArguments.Select(arg => arg.Value).ToList(); - var typeAttributeArguments = attributeArguments.OfType>().Select(t => t.Type) - .Union(attributeArguments.OfType()).ToList(); + var attributeArguments = attributeInstance + .AttributeArguments.Select(arg => arg.Value) + .ToList(); + var typeAttributeArguments = attributeArguments + .OfType>() + .Select(t => t.Type) + .Union(attributeArguments.OfType()) + .ToList(); foreach (var arg in argumentValueList) { if (arg is Type argType) @@ -1337,7 +1768,8 @@ bool Condition(TRuleType obj, Architecture architecture) } return true; - NextAttribute: ; + NextAttribute: + ; } return false; @@ -1347,7 +1779,8 @@ bool Condition(TRuleType obj, Architecture architecture) } public static ICondition HaveAnyAttributesWithNamedArguments( - IEnumerable<(string, object)> attributeArguments) + IEnumerable<(string, object)> attributeArguments + ) { var argumentList = attributeArguments.ToList(); string description; @@ -1361,18 +1794,24 @@ public static ICondition HaveAnyAttributesWithNamedArguments( else { var firstArgument = argumentList.First(); - description = argumentList.Where(attribute => attribute != firstArgument).Aggregate( - "have any attributes with named arguments \"" + firstArgument.Item1 + "=" + firstArgument.Item2 + - "\"", - (current, arg) => - current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\""); - + description = argumentList + .Where(attribute => attribute != firstArgument) + .Aggregate( + "have any attributes with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); failDescription = (ruleType, architecture) => { - var actualNamedArguments = ruleType.AttributeInstances - .SelectMany(instance => - instance.AttributeArguments.OfType()).ToList(); + var actualNamedArguments = ruleType + .AttributeInstances.SelectMany(instance => + instance.AttributeArguments.OfType() + ) + .ToList(); if (!actualNamedArguments.Any()) { return "does have no attribute with a named argument"; @@ -1380,30 +1819,40 @@ public static ICondition HaveAnyAttributesWithNamedArguments( var firstActualNamedArgument = actualNamedArguments.First(); return actualNamedArguments.Aggregate( - "does have attributes with named arguments \"" + firstActualNamedArgument.Name + "=" + - firstActualNamedArgument.Value + "\"", - (current, arg) => - current + " and \"" + arg.Name + "=" + arg.Value + "\""); + "does have attributes with named arguments \"" + + firstActualNamedArgument.Name + + "=" + + firstActualNamedArgument.Value + + "\"", + (current, arg) => current + " and \"" + arg.Name + "=" + arg.Value + "\"" + ); }; } bool Condition(TRuleType obj, Architecture architecture) { - var attArguments = obj.AttributeInstances.SelectMany(instance => - instance.AttributeArguments.OfType() - .Select(arg => (arg.Name, arg.Value))) + var attArguments = obj + .AttributeInstances.SelectMany(instance => + instance + .AttributeArguments.OfType() + .Select(arg => (arg.Name, arg.Value)) + ) .ToList(); var typeAttributeArguments = attArguments - .Where(arg => arg.Value is ITypeInstance || arg.Value is IType).ToList(); + .Where(arg => arg.Value is ITypeInstance || arg.Value is IType) + .ToList(); foreach (var arg in argumentList) { if (arg.Item2 is Type argType) { - if (typeAttributeArguments.All(t => - t.Name != arg.Item1 || - t.Value is ITypeInstance typeInstance && - typeInstance.Type.FullName != argType.FullName || - t.Value is IType type && type.FullName != argType.FullName)) + if ( + typeAttributeArguments.All(t => + t.Name != arg.Item1 + || t.Value is ITypeInstance typeInstance + && typeInstance.Type.FullName != argType.FullName + || t.Value is IType type && type.FullName != argType.FullName + ) + ) { return false; } @@ -1420,10 +1869,13 @@ t.Value is ITypeInstance typeInstance && return new ArchitectureCondition(Condition, failDescription, description); } - public static ICondition HaveAttributeWithNamedArguments([NotNull] string attribute, - IEnumerable<(string, object)> attributeArguments) + public static ICondition HaveAttributeWithNamedArguments( + [NotNull] string attribute, + IEnumerable<(string, object)> attributeArguments + ) { - string description, failDescription; + string description, + failDescription; var argumentList = attributeArguments.ToList(); if (argumentList.IsNullOrEmpty()) { @@ -1433,14 +1885,30 @@ public static ICondition HaveAttributeWithNamedArguments([NotNull] st else { var firstArgument = argumentList.First(); - description = argumentList.Where(att => att != firstArgument).Aggregate( - "have attribute \"" + attribute + "\" with named arguments \"" + firstArgument.Item1 + - "=" + firstArgument.Item2 + "\"", - (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\""); - failDescription = argumentList.Where(att => att != firstArgument).Aggregate( - "does not have attribute \"" + attribute + "\" with named arguments \"" + - firstArgument.Item1 + "=" + firstArgument.Item2 + "\"", - (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\""); + description = argumentList + .Where(att => att != firstArgument) + .Aggregate( + "have attribute \"" + + attribute + + "\" with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); + failDescription = argumentList + .Where(att => att != firstArgument) + .Aggregate( + "does not have attribute \"" + + attribute + + "\" with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); } bool Condition(TRuleType obj, Architecture architecture) @@ -1452,19 +1920,25 @@ bool Condition(TRuleType obj, Architecture architecture) goto NextAttribute; } - var attributeArgs = attributeInstance.AttributeArguments.OfType() - .Select(arg => (arg.Name, arg.Value)).ToList(); + var attributeArgs = attributeInstance + .AttributeArguments.OfType() + .Select(arg => (arg.Name, arg.Value)) + .ToList(); var typeAttributeArguments = attributeArgs - .Where(arg => arg.Value is ITypeInstance || arg.Value is IType).ToList(); + .Where(arg => arg.Value is ITypeInstance || arg.Value is IType) + .ToList(); foreach (var arg in argumentList) { if (arg.Item2 is Type argType) { - if (typeAttributeArguments.All(t => - t.Name != arg.Item1 || - t.Value is ITypeInstance typeInstance && - typeInstance.Type.FullName != argType.FullName || - t.Value is IType type && type.FullName != argType.FullName)) + if ( + typeAttributeArguments.All(t => + t.Name != arg.Item1 + || t.Value is ITypeInstance typeInstance + && typeInstance.Type.FullName != argType.FullName + || t.Value is IType type && type.FullName != argType.FullName + ) + ) { goto NextAttribute; } @@ -1476,7 +1950,8 @@ t.Value is ITypeInstance typeInstance && } return true; - NextAttribute: ; + NextAttribute: + ; } return false; @@ -1485,10 +1960,13 @@ t.Value is ITypeInstance typeInstance && return new ArchitectureCondition(Condition, description, failDescription); } - public static ICondition HaveAttributeWithNamedArguments([NotNull] Attribute attribute, - IEnumerable<(string, object)> attributeArguments) + public static ICondition HaveAttributeWithNamedArguments( + [NotNull] Attribute attribute, + IEnumerable<(string, object)> attributeArguments + ) { - string description, failDescription; + string description, + failDescription; var argumentList = attributeArguments.ToList(); if (argumentList.IsNullOrEmpty()) { @@ -1498,14 +1976,30 @@ public static ICondition HaveAttributeWithNamedArguments([NotNull] At else { var firstArgument = argumentList.First(); - description = argumentList.Where(att => att != firstArgument).Aggregate( - "have attribute \"" + attribute.FullName + "\" with named arguments \"" + firstArgument.Item1 + - "=" + firstArgument.Item2 + "\"", - (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\""); - failDescription = argumentList.Where(att => att != firstArgument).Aggregate( - "does not have attribute \"" + attribute.FullName + "\" with named arguments \"" + - firstArgument.Item1 + "=" + firstArgument.Item2 + "\"", - (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\""); + description = argumentList + .Where(att => att != firstArgument) + .Aggregate( + "have attribute \"" + + attribute.FullName + + "\" with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); + failDescription = argumentList + .Where(att => att != firstArgument) + .Aggregate( + "does not have attribute \"" + + attribute.FullName + + "\" with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); } bool Condition(TRuleType obj, Architecture architecture) @@ -1517,19 +2011,25 @@ bool Condition(TRuleType obj, Architecture architecture) goto NextAttribute; } - var attributeArgs = attributeInstance.AttributeArguments.OfType() - .Select(arg => (arg.Name, arg.Value)).ToList(); + var attributeArgs = attributeInstance + .AttributeArguments.OfType() + .Select(arg => (arg.Name, arg.Value)) + .ToList(); var typeAttributeArguments = attributeArgs - .Where(arg => arg.Value is ITypeInstance || arg.Value is IType).ToList(); + .Where(arg => arg.Value is ITypeInstance || arg.Value is IType) + .ToList(); foreach (var arg in argumentList) { if (arg.Item2 is Type argType) { - if (typeAttributeArguments.All(t => - t.Name != arg.Item1 || - t.Value is ITypeInstance typeInstance && - typeInstance.Type.FullName != argType.FullName || - t.Value is IType type && type.FullName != argType.FullName)) + if ( + typeAttributeArguments.All(t => + t.Name != arg.Item1 + || t.Value is ITypeInstance typeInstance + && typeInstance.Type.FullName != argType.FullName + || t.Value is IType type && type.FullName != argType.FullName + ) + ) { goto NextAttribute; } @@ -1541,7 +2041,8 @@ t.Value is ITypeInstance typeInstance && } return true; - NextAttribute: ; + NextAttribute: + ; } return false; @@ -1550,10 +2051,13 @@ t.Value is ITypeInstance typeInstance && return new ArchitectureCondition(Condition, description, failDescription); } - public static ICondition HaveAttributeWithNamedArguments([NotNull] Type attribute, - IEnumerable<(string, object)> attributeArguments) + public static ICondition HaveAttributeWithNamedArguments( + [NotNull] Type attribute, + IEnumerable<(string, object)> attributeArguments + ) { - string description, failDescription; + string description, + failDescription; var argumentList = attributeArguments.ToList(); if (argumentList.IsNullOrEmpty()) { @@ -1563,14 +2067,30 @@ public static ICondition HaveAttributeWithNamedArguments([NotNull] Ty else { var firstArgument = argumentList.First(); - description = argumentList.Where(att => att != firstArgument).Aggregate( - "have attribute \"" + attribute.FullName + "\" with named arguments \"" + firstArgument.Item1 + - "=" + firstArgument.Item2 + "\"", - (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\""); - failDescription = argumentList.Where(att => att != firstArgument).Aggregate( - "does not have attribute \"" + attribute.FullName + "\" with named arguments \"" + - firstArgument.Item1 + "=" + firstArgument.Item2 + "\"", - (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\""); + description = argumentList + .Where(att => att != firstArgument) + .Aggregate( + "have attribute \"" + + attribute.FullName + + "\" with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); + failDescription = argumentList + .Where(att => att != firstArgument) + .Aggregate( + "does not have attribute \"" + + attribute.FullName + + "\" with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); } bool Condition(TRuleType obj, Architecture architecture) @@ -1593,19 +2113,25 @@ bool Condition(TRuleType obj, Architecture architecture) goto NextAttribute; } - var attributeArgs = attributeInstance.AttributeArguments.OfType() - .Select(arg => (arg.Name, arg.Value)).ToList(); + var attributeArgs = attributeInstance + .AttributeArguments.OfType() + .Select(arg => (arg.Name, arg.Value)) + .ToList(); var typeAttributeArguments = attributeArgs - .Where(arg => arg.Value is ITypeInstance || arg.Value is IType).ToList(); + .Where(arg => arg.Value is ITypeInstance || arg.Value is IType) + .ToList(); foreach (var arg in argumentList) { if (arg.Item2 is Type argType) { - if (typeAttributeArguments.All(t => - t.Name != arg.Item1 || - t.Value is ITypeInstance typeInstance && - typeInstance.Type.FullName != argType.FullName || - t.Value is IType type && type.FullName != argType.FullName)) + if ( + typeAttributeArguments.All(t => + t.Name != arg.Item1 + || t.Value is ITypeInstance typeInstance + && typeInstance.Type.FullName != argType.FullName + || t.Value is IType type && type.FullName != argType.FullName + ) + ) { goto NextAttribute; } @@ -1617,7 +2143,8 @@ t.Value is ITypeInstance typeInstance && } return true; - NextAttribute: ; + NextAttribute: + ; } return false; @@ -1626,115 +2153,167 @@ t.Value is ITypeInstance typeInstance && return new ArchitectureCondition(Condition, description, failDescription); } - public static ICondition HaveName(string pattern, bool useRegularExpressions = false) + public static ICondition HaveName( + string pattern, + bool useRegularExpressions = false + ) { - return new SimpleCondition(obj => obj.NameMatches(pattern, useRegularExpressions), + return new SimpleCondition( + obj => obj.NameMatches(pattern, useRegularExpressions), obj => "does have name " + obj.Name, - "have full name " + (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\""); + "have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static ICondition HaveFullName(string pattern, bool useRegularExpressions = false) + public static ICondition HaveFullName( + string pattern, + bool useRegularExpressions = false + ) { - return new SimpleCondition(obj => obj.FullNameMatches(pattern, useRegularExpressions), + return new SimpleCondition( + obj => obj.FullNameMatches(pattern, useRegularExpressions), obj => "does have full name " + obj.FullName, - "have full name " + (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\""); + "have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } public static ICondition HaveNameStartingWith(string pattern) { return new SimpleCondition( - obj => obj.NameStartsWith(pattern), obj => "does have name " + obj.Name, - "have name starting with \"" + pattern + "\""); + obj => obj.NameStartsWith(pattern), + obj => "does have name " + obj.Name, + "have name starting with \"" + pattern + "\"" + ); } public static ICondition HaveNameEndingWith(string pattern) { return new SimpleCondition( - obj => obj.NameEndsWith(pattern), obj => "does have name " + obj.Name, - "have name ending with \"" + pattern + "\""); + obj => obj.NameEndsWith(pattern), + obj => "does have name " + obj.Name, + "have name ending with \"" + pattern + "\"" + ); } public static ICondition HaveNameContaining(string pattern) { return new SimpleCondition( - obj => obj.NameContains(pattern), obj => "does have name " + obj.Name, - "have name containing \"" + pattern + "\""); + obj => obj.NameContains(pattern), + obj => "does have name " + obj.Name, + "have name containing \"" + pattern + "\"" + ); } public static ICondition HaveFullNameContaining(string pattern) { return new SimpleCondition( - obj => obj.FullNameContains(pattern), obj => "does have full name " + obj.FullName, - "have full name containing \"" + pattern + "\""); + obj => obj.FullNameContains(pattern), + obj => "does have full name " + obj.FullName, + "have full name containing \"" + pattern + "\"" + ); } public static ICondition BePrivate() { - return new SimpleCondition(obj => obj.Visibility == Private, - obj => "is " + VisibilityStrings.ToString(obj.Visibility), "be private"); + return new SimpleCondition( + obj => obj.Visibility == Private, + obj => "is " + VisibilityStrings.ToString(obj.Visibility), + "be private" + ); } public static ICondition BePublic() { - return new SimpleCondition(obj => obj.Visibility == Public, - obj => "is " + VisibilityStrings.ToString(obj.Visibility), "be public"); + return new SimpleCondition( + obj => obj.Visibility == Public, + obj => "is " + VisibilityStrings.ToString(obj.Visibility), + "be public" + ); } public static ICondition BeProtected() { - return new SimpleCondition(obj => obj.Visibility == Protected, - obj => "is " + VisibilityStrings.ToString(obj.Visibility), "be protected"); + return new SimpleCondition( + obj => obj.Visibility == Protected, + obj => "is " + VisibilityStrings.ToString(obj.Visibility), + "be protected" + ); } public static ICondition BeInternal() { - return new SimpleCondition(obj => obj.Visibility == Internal, - obj => "is " + VisibilityStrings.ToString(obj.Visibility), "be internal"); + return new SimpleCondition( + obj => obj.Visibility == Internal, + obj => "is " + VisibilityStrings.ToString(obj.Visibility), + "be internal" + ); } public static ICondition BeProtectedInternal() { return new SimpleCondition( - obj => obj.Visibility == ProtectedInternal, obj => "is " + VisibilityStrings.ToString(obj.Visibility), - "be protected internal"); + obj => obj.Visibility == ProtectedInternal, + obj => "is " + VisibilityStrings.ToString(obj.Visibility), + "be protected internal" + ); } public static ICondition BePrivateProtected() { return new SimpleCondition( - obj => obj.Visibility == PrivateProtected, obj => "is " + VisibilityStrings.ToString(obj.Visibility), - "be private protected"); + obj => obj.Visibility == PrivateProtected, + obj => "is " + VisibilityStrings.ToString(obj.Visibility), + "be private protected" + ); } - //Relation Conditions public static RelationCondition DependOnAnyTypesThat() { - return new RelationCondition(DependOnAny, "depend on any types that", - "does not depend on any types that"); + return new RelationCondition( + DependOnAny, + "depend on any types that", + "does not depend on any types that" + ); } public static RelationCondition OnlyDependOnTypesThat() { - return new RelationCondition(OnlyDependOn, "only depend on types that", - "does not only depend on types that"); + return new RelationCondition( + OnlyDependOn, + "only depend on types that", + "does not only depend on types that" + ); } public static RelationCondition HaveAnyAttributesThat() { - return new RelationCondition(HaveAnyAttributes, "have attributes that", - "does not have attributes that"); + return new RelationCondition( + HaveAnyAttributes, + "have attributes that", + "does not have attributes that" + ); } public static RelationCondition OnlyHaveAttributesThat() { - return new RelationCondition(OnlyHaveAttributes, "only have attributes that", - "does not only have attributes that"); + return new RelationCondition( + OnlyHaveAttributes, + "only have attributes that", + "does not only have attributes that" + ); } - //Negations @@ -1743,15 +2322,26 @@ public static ICondition NotExist() return new ExistsCondition(false); } - public static ICondition NotBe(string pattern, bool useRegularExpressions = false) + public static ICondition NotBe( + string pattern, + bool useRegularExpressions = false + ) { return new SimpleCondition( obj => !obj.FullNameMatches(pattern, useRegularExpressions), obj => "is " + obj.FullName, - "not have full name " + (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\""); + "not have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static ICondition NotBe(IEnumerable patterns, bool useRegularExpressions = false) + public static ICondition NotBe( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); string description; @@ -1762,19 +2352,35 @@ public static ICondition NotBe(IEnumerable patterns, bool use else { var firstPattern = patternList.First(); - description = patternList.Where(pattern => !pattern.Equals(firstPattern)).Distinct().Aggregate( - "not have full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "not have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimpleCondition( - obj => patternList.All(pattern => !obj.FullNameMatches(pattern, useRegularExpressions)), - obj => "is " + obj.FullName, description); + obj => + patternList.All(pattern => + !obj.FullNameMatches(pattern, useRegularExpressions) + ), + obj => "is " + obj.FullName, + description + ); } - public static ICondition NotBe(ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects) + public static ICondition NotBe( + ICanBeAnalyzed firstObject, + params ICanBeAnalyzed[] moreObjects + ) { - var objects = new List {firstObject}; + var objects = new List { firstObject }; objects.AddRange(moreObjects); return NotBe(objects); } @@ -1789,7 +2395,11 @@ IEnumerable Condition(IEnumerable ruleTypes) var failedObjects = objectList.OfType().Intersect(typeList).ToList(); foreach (var failedObject in failedObjects) { - yield return new ConditionResult(failedObject, false, "is " + failedObject.FullName); + yield return new ConditionResult( + failedObject, + false, + "is " + failedObject.FullName + ); } foreach (var passedObject in typeList.Except(failedObjects)) @@ -1806,9 +2416,13 @@ IEnumerable Condition(IEnumerable ruleTypes) else { var firstObject = objectList.First(); - description = objectList.Where(obj => !obj.Equals(firstObject)).Distinct().Aggregate( - "not be \"" + firstObject.FullName + "\"", - (current, obj) => current + " or \"" + obj.FullName + "\""); + description = objectList + .Where(obj => !obj.Equals(firstObject)) + .Distinct() + .Aggregate( + "not be \"" + firstObject.FullName + "\"", + (current, obj) => current + " or \"" + obj.FullName + "\"" + ); } return new EnumerableCondition(Condition, description); @@ -1816,14 +2430,21 @@ IEnumerable Condition(IEnumerable ruleTypes) public static ICondition NotBe(IObjectProvider objectProvider) { - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var objectList = objectProvider.GetObjects(architecture).ToList(); var typeList = ruleTypes.ToList(); var failedObjects = objectList.OfType().Intersect(typeList).ToList(); foreach (var failedObject in failedObjects) { - yield return new ConditionResult(failedObject, false, "is " + objectProvider.Description); + yield return new ConditionResult( + failedObject, + false, + "is " + objectProvider.Description + ); } foreach (var passedObject in typeList.Except(failedObjects)) @@ -1832,10 +2453,16 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite } } - return new ArchitectureCondition(Condition, "not be " + objectProvider.Description); + return new ArchitectureCondition( + Condition, + "not be " + objectProvider.Description + ); } - public static ICondition NotCallAny(string pattern, bool useRegularExpressions = false) + public static ICondition NotCallAny( + string pattern, + bool useRegularExpressions = false + ) { ConditionResult Condition(TRuleType ruleType) { @@ -1845,7 +2472,9 @@ ConditionResult Condition(TRuleType ruleType) { if (dependency.FullNameMatches(pattern, useRegularExpressions)) { - dynamicFailDescription += pass ? " " + dependency.FullName : " and " + dependency.FullName; + dynamicFailDescription += pass + ? " " + dependency.FullName + : " and " + dependency.FullName; pass = false; } } @@ -1853,13 +2482,20 @@ ConditionResult Condition(TRuleType ruleType) return new ConditionResult(ruleType, pass, dynamicFailDescription); } - return new SimpleCondition(Condition, - "not call any method with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + pattern + "\""); + return new SimpleCondition( + Condition, + "not call any method with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static ICondition NotCallAny(IEnumerable patterns, - bool useRegularExpressions = false) + public static ICondition NotCallAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); @@ -1869,9 +2505,15 @@ ConditionResult Condition(TRuleType ruleType) var dynamicFailDescription = "does call"; foreach (var dependency in ruleType.GetCalledMethods()) { - if (patternList.Any(pattern => dependency.FullNameMatches(pattern, useRegularExpressions))) + if ( + patternList.Any(pattern => + dependency.FullNameMatches(pattern, useRegularExpressions) + ) + ) { - dynamicFailDescription += pass ? " " + dependency.FullName : " and " + dependency.FullName; + dynamicFailDescription += pass + ? " " + dependency.FullName + : " and " + dependency.FullName; pass = false; } } @@ -1887,28 +2529,43 @@ ConditionResult Condition(TRuleType ruleType) else { var firstPattern = patternList.First(); - description = patternList.Where(pattern => !pattern.Equals(firstPattern)).Distinct().Aggregate( - "not call methods with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "not call methods with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimpleCondition(Condition, description); } - public static ICondition NotCallAny(MethodMember method, params MethodMember[] moreMethods) + public static ICondition NotCallAny( + MethodMember method, + params MethodMember[] moreMethods + ) { - var methods = new List {method}; + var methods = new List { method }; methods.AddRange(moreMethods); return NotCallAny(methods); } public static ICondition NotCallAny(IObjectProvider objectProvider) { - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var methodList = objectProvider.GetObjects(architecture).ToList(); var typeList = ruleTypes.ToList(); - var failedObjects = typeList.Where(type => type.GetCalledMethods().Intersect(methodList).Any()) + var failedObjects = typeList + .Where(type => type.GetCalledMethods().Intersect(methodList).Any()) .ToList(); foreach (var failedObject in failedObjects) { @@ -1916,7 +2573,9 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite var first = true; foreach (var method in failedObject.GetCalledMethods().Intersect(methodList)) { - dynamicFailDescription += first ? " " + method.FullName : " and " + method.FullName; + dynamicFailDescription += first + ? " " + method.FullName + : " and " + method.FullName; first = false; } @@ -1940,7 +2599,8 @@ public static ICondition NotCallAny(IEnumerable methods IEnumerable Condition(IEnumerable ruleTypes) { var typeList = ruleTypes.ToList(); - var failedObjects = typeList.Where(type => type.GetCalledMethods().Intersect(methodList).Any()) + var failedObjects = typeList + .Where(type => type.GetCalledMethods().Intersect(methodList).Any()) .ToList(); foreach (var failedObject in failedObjects) { @@ -1948,7 +2608,9 @@ IEnumerable Condition(IEnumerable ruleTypes) var first = true; foreach (var method in failedObject.GetCalledMethods().Intersect(methodList)) { - dynamicFailDescription += first ? " " + method.FullName : " and " + method.FullName; + dynamicFailDescription += first + ? " " + method.FullName + : " and " + method.FullName; first = false; } @@ -1969,16 +2631,22 @@ IEnumerable Condition(IEnumerable ruleTypes) else { var firstMethod = methodList.First(); - description = methodList.Where(obj => !obj.Equals(firstMethod)).Distinct().Aggregate( - "not call \"" + firstMethod.FullName + "\"", - (current, obj) => current + " or \"" + obj.FullName + "\""); + description = methodList + .Where(obj => !obj.Equals(firstMethod)) + .Distinct() + .Aggregate( + "not call \"" + firstMethod.FullName + "\"", + (current, obj) => current + " or \"" + obj.FullName + "\"" + ); } return new EnumerableCondition(Condition, description); } - - public static ICondition NotDependOnAny(string pattern, bool useRegularExpressions = false) + public static ICondition NotDependOnAny( + string pattern, + bool useRegularExpressions = false + ) { ConditionResult Condition(TRuleType ruleType) { @@ -1988,7 +2656,9 @@ ConditionResult Condition(TRuleType ruleType) { if (dependency.FullNameMatches(pattern, useRegularExpressions)) { - dynamicFailDescription += pass ? " " + dependency.FullName : " and " + dependency.FullName; + dynamicFailDescription += pass + ? " " + dependency.FullName + : " and " + dependency.FullName; pass = false; } } @@ -1996,13 +2666,20 @@ ConditionResult Condition(TRuleType ruleType) return new ConditionResult(ruleType, pass, dynamicFailDescription); } - return new SimpleCondition(Condition, - "not depend on any types with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + pattern + "\""); + return new SimpleCondition( + Condition, + "not depend on any types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static ICondition NotDependOnAny(IEnumerable patterns, - bool useRegularExpressions = false) + public static ICondition NotDependOnAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); @@ -2012,9 +2689,15 @@ ConditionResult Condition(TRuleType ruleType) var dynamicFailDescription = "does depend on"; foreach (var dependency in ruleType.GetTypeDependencies()) { - if (patternList.Any(pattern => dependency.FullNameMatches(pattern, useRegularExpressions))) + if ( + patternList.Any(pattern => + dependency.FullNameMatches(pattern, useRegularExpressions) + ) + ) { - dynamicFailDescription += pass ? " " + dependency.FullName : " and " + dependency.FullName; + dynamicFailDescription += pass + ? " " + dependency.FullName + : " and " + dependency.FullName; pass = false; } } @@ -2030,35 +2713,50 @@ ConditionResult Condition(TRuleType ruleType) else { var firstPattern = patternList.First(); - description = patternList.Where(pattern => !pattern.Equals(firstPattern)).Distinct().Aggregate( - "not depend on types with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "not depend on types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimpleCondition(Condition, description); } - public static ICondition NotDependOnAny(IType firstType, params IType[] moreTypes) + public static ICondition NotDependOnAny( + IType firstType, + params IType[] moreTypes + ) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return NotDependOnAny(types); } public static ICondition NotDependOnAny(Type firstType, params Type[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return NotDependOnAny(types); } public static ICondition NotDependOnAny(IObjectProvider objectProvider) { - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var typeList = objectProvider.GetObjects(architecture).ToList(); var ruleTypeList = ruleTypes.ToList(); - var failedObjects = ruleTypeList.Where(type => type.GetTypeDependencies().Intersect(typeList).Any()) + var failedObjects = ruleTypeList + .Where(type => type.GetTypeDependencies().Intersect(typeList).Any()) .ToList(); foreach (var failedObject in failedObjects) { @@ -2066,7 +2764,9 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite var first = true; foreach (var type in failedObject.GetTypeDependencies().Intersect(typeList)) { - dynamicFailDescription += first ? " " + type.FullName : " and " + type.FullName; + dynamicFailDescription += first + ? " " + type.FullName + : " and " + type.FullName; first = false; } @@ -2090,7 +2790,8 @@ public static ICondition NotDependOnAny(IEnumerable types) IEnumerable Condition(IEnumerable ruleTypes) { var ruleTypeList = ruleTypes.ToList(); - var failedObjects = ruleTypeList.Where(type => type.GetTypeDependencies().Intersect(typeList).Any()) + var failedObjects = ruleTypeList + .Where(type => type.GetTypeDependencies().Intersect(typeList).Any()) .ToList(); foreach (var failedObject in failedObjects) { @@ -2098,7 +2799,9 @@ IEnumerable Condition(IEnumerable ruleTypes) var first = true; foreach (var type in failedObject.GetTypeDependencies().Intersect(typeList)) { - dynamicFailDescription += first ? " " + type.FullName : " and " + type.FullName; + dynamicFailDescription += first + ? " " + type.FullName + : " and " + type.FullName; first = false; } @@ -2119,9 +2822,13 @@ IEnumerable Condition(IEnumerable ruleTypes) else { var firstType = typeList.First(); - description = typeList.Where(obj => !obj.Equals(firstType)).Distinct().Aggregate( - "not depend on \"" + firstType.FullName + "\"", - (current, obj) => current + " or \"" + obj.FullName + "\""); + description = typeList + .Where(obj => !obj.Equals(firstType)) + .Distinct() + .Aggregate( + "not depend on \"" + firstType.FullName + "\"", + (current, obj) => current + " or \"" + obj.FullName + "\"" + ); } return new EnumerableCondition(Condition, description); @@ -2131,7 +2838,10 @@ public static ICondition NotDependOnAny(IEnumerable types) { var typeList = types.ToList(); - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var ruleTypeList = ruleTypes.ToList(); var archUnitTypeList = new List(); @@ -2155,9 +2865,13 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite { var dynamicFailDescription = "does depend on"; var first = true; - foreach (var type in failedObject.GetTypeDependencies().Intersect(archUnitTypeList)) + foreach ( + var type in failedObject.GetTypeDependencies().Intersect(archUnitTypeList) + ) { - dynamicFailDescription += first ? " " + type.FullName : " and " + type.FullName; + dynamicFailDescription += first + ? " " + type.FullName + : " and " + type.FullName; first = false; } @@ -2178,33 +2892,52 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite else { var firstType = typeList.First(); - description = typeList.Where(obj => obj != firstType).Distinct().Aggregate( - "not depend on \"" + firstType.FullName + "\"", - (current, obj) => current + " or \"" + obj.FullName + "\""); + description = typeList + .Where(obj => obj != firstType) + .Distinct() + .Aggregate( + "not depend on \"" + firstType.FullName + "\"", + (current, obj) => current + " or \"" + obj.FullName + "\"" + ); } return new ArchitectureCondition(Condition, description); } - public static ICondition NotHaveAnyAttributes(string pattern, bool useRegularExpressions = false) + public static ICondition NotHaveAnyAttributes( + string pattern, + bool useRegularExpressions = false + ) { return new SimpleCondition( obj => !obj.HasAttribute(pattern, useRegularExpressions), - "not have any attribute with full name " + (useRegularExpressions ? "matching " : "") + "\"" + - pattern + "\"", - "does have any attribute with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + pattern + "\""); - } - - public static ICondition NotHaveAnyAttributes(IEnumerable patterns, - bool useRegularExpressions = false) + "not have any attribute with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"", + "does have any attribute with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); + } + + public static ICondition NotHaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Condition(TRuleType ruleType) { return !ruleType.Attributes.Any(attribute => - patternList.Any(pattern => attribute.FullNameMatches(pattern, useRegularExpressions))); + patternList.Any(pattern => + attribute.FullNameMatches(pattern, useRegularExpressions) + ) + ); } string description; @@ -2217,42 +2950,66 @@ bool Condition(TRuleType ruleType) else { var firstPattern = patternList.First(); - description = patternList.Where(pattern => !pattern.Equals(firstPattern)).Distinct().Aggregate( - "not have any attribute with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", - (current, pattern) => current + " or \"" + pattern + "\""); - failDescription = patternList.Where(pattern => !pattern.Equals(firstPattern)).Distinct().Aggregate( - "does have any attribute with full name " + - (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", - (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "not have any attribute with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + failDescription = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "does have any attribute with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimpleCondition(Condition, description, failDescription); } - public static ICondition NotHaveAnyAttributes(Attribute firstAttribute, - params Attribute[] moreAttributes) + public static ICondition NotHaveAnyAttributes( + Attribute firstAttribute, + params Attribute[] moreAttributes + ) { - var attributes = new List {firstAttribute}; + var attributes = new List { firstAttribute }; attributes.AddRange(moreAttributes); return NotHaveAnyAttributes(attributes); } - public static ICondition NotHaveAnyAttributes(Type firstAttribute, params Type[] moreAttributes) + public static ICondition NotHaveAnyAttributes( + Type firstAttribute, + params Type[] moreAttributes + ) { - var attributes = new List {firstAttribute}; + var attributes = new List { firstAttribute }; attributes.AddRange(moreAttributes); return NotHaveAnyAttributes(attributes); } - public static ICondition NotHaveAnyAttributes(IObjectProvider objectProvider) + public static ICondition NotHaveAnyAttributes( + IObjectProvider objectProvider + ) { - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var attributeList = objectProvider.GetObjects(architecture).ToList(); var ruleTypeList = ruleTypes.ToList(); - var failedObjects = ruleTypeList.Where(type => type.Attributes.Intersect(attributeList).Any()) + var failedObjects = ruleTypeList + .Where(type => type.Attributes.Intersect(attributeList).Any()) .ToList(); foreach (var failedObject in failedObjects) { @@ -2260,7 +3017,9 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite var first = true; foreach (var attribute in failedObject.Attributes.Intersect(attributeList)) { - dynamicFailDescription += first ? " " + attribute.FullName : " and " + attribute.FullName; + dynamicFailDescription += first + ? " " + attribute.FullName + : " and " + attribute.FullName; first = false; } @@ -2284,7 +3043,8 @@ public static ICondition NotHaveAnyAttributes(IEnumerable IEnumerable Condition(IEnumerable ruleTypes) { var ruleTypeList = ruleTypes.ToList(); - var failedObjects = ruleTypeList.Where(type => type.Attributes.Intersect(attributeList).Any()) + var failedObjects = ruleTypeList + .Where(type => type.Attributes.Intersect(attributeList).Any()) .ToList(); foreach (var failedObject in failedObjects) { @@ -2292,7 +3052,9 @@ IEnumerable Condition(IEnumerable ruleTypes) var first = true; foreach (var attribute in failedObject.Attributes.Intersect(attributeList)) { - dynamicFailDescription += first ? " " + attribute.FullName : " and " + attribute.FullName; + dynamicFailDescription += first + ? " " + attribute.FullName + : " and " + attribute.FullName; first = false; } @@ -2313,9 +3075,13 @@ IEnumerable Condition(IEnumerable ruleTypes) else { var firstAttribute = attributeList.First(); - description = attributeList.Where(attribute => !attribute.Equals(firstAttribute)).Distinct().Aggregate( - "not have attribute \"" + firstAttribute.FullName + "\"", - (current, attribute) => current + " or \"" + attribute.FullName + "\""); + description = attributeList + .Where(attribute => !attribute.Equals(firstAttribute)) + .Distinct() + .Aggregate( + "not have attribute \"" + firstAttribute.FullName + "\"", + (current, attribute) => current + " or \"" + attribute.FullName + "\"" + ); } return new EnumerableCondition(Condition, description); @@ -2325,7 +3091,10 @@ public static ICondition NotHaveAnyAttributes(IEnumerable attri { var attributeList = attributes.ToList(); - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var archUnitAttributeList = new List(); foreach (var type in attributeList) @@ -2342,15 +3111,20 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite } var ruleTypeList = ruleTypes.ToList(); - var failedObjects = ruleTypeList.Where(type => type.Attributes.Intersect(archUnitAttributeList).Any()) + var failedObjects = ruleTypeList + .Where(type => type.Attributes.Intersect(archUnitAttributeList).Any()) .ToList(); foreach (var failedObject in failedObjects) { var dynamicFailDescription = "does have attribute"; var first = true; - foreach (var attribute in failedObject.Attributes.Intersect(archUnitAttributeList)) + foreach ( + var attribute in failedObject.Attributes.Intersect(archUnitAttributeList) + ) { - dynamicFailDescription += first ? " " + attribute.FullName : " and " + attribute.FullName; + dynamicFailDescription += first + ? " " + attribute.FullName + : " and " + attribute.FullName; first = false; } @@ -2371,103 +3145,134 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite else { var firstAttribute = attributeList.First(); - description = attributeList.Where(attribute => attribute != firstAttribute).Distinct().Aggregate( - "not have attribute \"" + firstAttribute.FullName + "\"", - (current, attribute) => current + " or \"" + attribute.FullName + "\""); + description = attributeList + .Where(attribute => attribute != firstAttribute) + .Distinct() + .Aggregate( + "not have attribute \"" + firstAttribute.FullName + "\"", + (current, attribute) => current + " or \"" + attribute.FullName + "\"" + ); } return new ArchitectureCondition(Condition, description); } - public static ICondition NotHaveAnyAttributesWithArguments(object firstArgumentValue, - params object[] moreArgumentValues) + public static ICondition NotHaveAnyAttributesWithArguments( + object firstArgumentValue, + params object[] moreArgumentValues + ) { - var argumentValues = new List {firstArgumentValue}; + var argumentValues = new List { firstArgumentValue }; argumentValues.AddRange(moreArgumentValues); return NotHaveAnyAttributesWithArguments(argumentValues); } - public static ICondition NotHaveAttributeWithArguments(string attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public static ICondition NotHaveAttributeWithArguments( + string attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { - var argumentValues = new List {firstArgumentValue}; + var argumentValues = new List { firstArgumentValue }; argumentValues.AddRange(moreArgumentValues); return NotHaveAttributeWithArguments(attribute, argumentValues); } - public static ICondition NotHaveAttributeWithArguments(Attribute attribute, + public static ICondition NotHaveAttributeWithArguments( + Attribute attribute, object firstArgumentValue, - params object[] moreArgumentValues) + params object[] moreArgumentValues + ) { - var argumentValues = new List {firstArgumentValue}; + var argumentValues = new List { firstArgumentValue }; argumentValues.AddRange(moreArgumentValues); return NotHaveAttributeWithArguments(attribute, argumentValues); } - public static ICondition NotHaveAttributeWithArguments(Type attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public static ICondition NotHaveAttributeWithArguments( + Type attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { - var argumentValues = new List {firstArgumentValue}; + var argumentValues = new List { firstArgumentValue }; argumentValues.AddRange(moreArgumentValues); return NotHaveAttributeWithArguments(attribute, argumentValues); } public static ICondition NotHaveAnyAttributesWithNamedArguments( (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments) + params (string, object)[] moreAttributeArguments + ) { - var attributeArguments = new List<(string, object)> {firstAttributeArgument}; + var attributeArguments = new List<(string, object)> { firstAttributeArgument }; attributeArguments.AddRange(moreAttributeArguments); return NotHaveAnyAttributesWithNamedArguments(attributeArguments); } - public static ICondition NotHaveAttributeWithNamedArguments(string attribute, - (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments) + public static ICondition NotHaveAttributeWithNamedArguments( + string attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { - var attributeArguments = new List<(string, object)> {firstAttributeArgument}; + var attributeArguments = new List<(string, object)> { firstAttributeArgument }; attributeArguments.AddRange(moreAttributeArguments); return NotHaveAttributeWithNamedArguments(attribute, attributeArguments); } - public static ICondition NotHaveAttributeWithNamedArguments(Attribute attribute, - (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments) + public static ICondition NotHaveAttributeWithNamedArguments( + Attribute attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { - var attributeArguments = new List<(string, object)> {firstAttributeArgument}; + var attributeArguments = new List<(string, object)> { firstAttributeArgument }; attributeArguments.AddRange(moreAttributeArguments); return NotHaveAttributeWithNamedArguments(attribute, attributeArguments); } - public static ICondition NotHaveAttributeWithNamedArguments(Type attribute, - (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments) + public static ICondition NotHaveAttributeWithNamedArguments( + Type attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { - var attributeArguments = new List<(string, object)> {firstAttributeArgument}; + var attributeArguments = new List<(string, object)> { firstAttributeArgument }; attributeArguments.AddRange(moreAttributeArguments); return NotHaveAttributeWithNamedArguments(attribute, attributeArguments); } - public static ICondition NotHaveAnyAttributesWithArguments(IEnumerable argumentValues) + public static ICondition NotHaveAnyAttributesWithArguments( + IEnumerable argumentValues + ) { - var argumentValueList = argumentValues?.ToList() ?? new List {null}; + var argumentValueList = argumentValues?.ToList() ?? new List { null }; string description; Func failDescription; if (argumentValueList.IsNullOrEmpty()) { description = "not have no or any attributes with arguments (impossible)"; - failDescription = (ruleType, architecture) => "have no or any attributes with arguments (always)"; + failDescription = (ruleType, architecture) => + "have no or any attributes with arguments (always)"; } else { var firstArgument = argumentValueList.First(); - description = argumentValueList.Where(attribute => attribute != firstArgument).Aggregate( - "not have any attributes with arguments \"" + firstArgument + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\""); - + description = argumentValueList + .Where(attribute => attribute != firstArgument) + .Aggregate( + "not have any attributes with arguments \"" + firstArgument + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); failDescription = (ruleType, architecture) => { - var actualArgumentValues = ruleType.AttributeInstances - .SelectMany(instance => - instance.AttributeArguments.Select(argument => argument.Value)).ToList(); + var actualArgumentValues = ruleType + .AttributeInstances.SelectMany(instance => + instance.AttributeArguments.Select(argument => argument.Value) + ) + .ToList(); if (!actualArgumentValues.Any()) { return "does have no attribute with an argument"; @@ -2475,17 +3280,26 @@ public static ICondition NotHaveAnyAttributesWithArguments(IEnumerabl var firstActualArgumentValue = actualArgumentValues.First(); return actualArgumentValues.Aggregate( - "does have attributes with argument values \"" + firstActualArgumentValue + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\""); + "does have attributes with argument values \"" + + firstActualArgumentValue + + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); }; } bool Condition(TRuleType obj, Architecture architecture) { - var attributeArguments = obj.AttributeInstances - .SelectMany(instance => instance.AttributeArguments.Select(arg => arg.Value)).ToList(); - var typeAttributeArguments = attributeArguments.OfType>().Select(t => t.Type) - .Union(attributeArguments.OfType()).ToList(); + var attributeArguments = obj + .AttributeInstances.SelectMany(instance => + instance.AttributeArguments.Select(arg => arg.Value) + ) + .ToList(); + var typeAttributeArguments = attributeArguments + .OfType>() + .Select(t => t.Type) + .Union(attributeArguments.OfType()) + .ToList(); foreach (var arg in argumentValueList) { if (arg is Type argType) @@ -2507,11 +3321,14 @@ bool Condition(TRuleType obj, Architecture architecture) return new ArchitectureCondition(Condition, failDescription, description); } - public static ICondition NotHaveAttributeWithArguments([NotNull] string attribute, - IEnumerable argumentValues) + public static ICondition NotHaveAttributeWithArguments( + [NotNull] string attribute, + IEnumerable argumentValues + ) { - string description, failDescription; - var argumentValueList = argumentValues?.ToList() ?? new List {null}; + string description, + failDescription; + var argumentValueList = argumentValues?.ToList() ?? new List { null }; if (argumentValueList.IsNullOrEmpty()) { description = "not have attribute \"" + attribute + "\""; @@ -2520,12 +3337,26 @@ public static ICondition NotHaveAttributeWithArguments([NotNull] stri else { var firstArgument = argumentValueList.First(); - description = argumentValueList.Where(att => att != firstArgument).Aggregate( - "not have attribute \"" + attribute + "\" with arguments \"" + firstArgument + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\""); - failDescription = argumentValueList.Where(att => att != firstArgument).Aggregate( - "does have attribute \"" + attribute + "\" with arguments \"" + firstArgument + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\""); + description = argumentValueList + .Where(att => att != firstArgument) + .Aggregate( + "not have attribute \"" + + attribute + + "\" with arguments \"" + + firstArgument + + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); + failDescription = argumentValueList + .Where(att => att != firstArgument) + .Aggregate( + "does have attribute \"" + + attribute + + "\" with arguments \"" + + firstArgument + + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); } bool Condition(TRuleType obj, Architecture architecture) @@ -2537,9 +3368,14 @@ bool Condition(TRuleType obj, Architecture architecture) goto NextAttribute; } - var attributeArguments = attributeInstance.AttributeArguments.Select(arg => arg.Value).ToList(); - var typeAttributeArguments = attributeArguments.OfType>().Select(t => t.Type) - .Union(attributeArguments.OfType()).ToList(); + var attributeArguments = attributeInstance + .AttributeArguments.Select(arg => arg.Value) + .ToList(); + var typeAttributeArguments = attributeArguments + .OfType>() + .Select(t => t.Type) + .Union(attributeArguments.OfType()) + .ToList(); foreach (var arg in argumentValueList) { if (arg is Type argType) @@ -2556,7 +3392,8 @@ bool Condition(TRuleType obj, Architecture architecture) } return false; - NextAttribute: ; + NextAttribute: + ; } return true; @@ -2565,11 +3402,14 @@ bool Condition(TRuleType obj, Architecture architecture) return new ArchitectureCondition(Condition, description, failDescription); } - public static ICondition NotHaveAttributeWithArguments([NotNull] Attribute attribute, - IEnumerable argumentValues) + public static ICondition NotHaveAttributeWithArguments( + [NotNull] Attribute attribute, + IEnumerable argumentValues + ) { - string description, failDescription; - var argumentValueList = argumentValues?.ToList() ?? new List {null}; + string description, + failDescription; + var argumentValueList = argumentValues?.ToList() ?? new List { null }; if (argumentValueList.IsNullOrEmpty()) { description = "not have attribute \"" + attribute.FullName + "\""; @@ -2578,12 +3418,26 @@ public static ICondition NotHaveAttributeWithArguments([NotNull] Attr else { var firstArgument = argumentValueList.First(); - description = argumentValueList.Where(att => att != firstArgument).Aggregate( - "not have attribute \"" + attribute.FullName + "\" with arguments \"" + firstArgument + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\""); - failDescription = argumentValueList.Where(att => att != firstArgument).Aggregate( - "does have attribute \"" + attribute.FullName + "\" with arguments \"" + firstArgument + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\""); + description = argumentValueList + .Where(att => att != firstArgument) + .Aggregate( + "not have attribute \"" + + attribute.FullName + + "\" with arguments \"" + + firstArgument + + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); + failDescription = argumentValueList + .Where(att => att != firstArgument) + .Aggregate( + "does have attribute \"" + + attribute.FullName + + "\" with arguments \"" + + firstArgument + + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); } bool Condition(TRuleType obj, Architecture architecture) @@ -2595,9 +3449,14 @@ bool Condition(TRuleType obj, Architecture architecture) goto NextAttribute; } - var attributeArguments = attributeInstance.AttributeArguments.Select(arg => arg.Value).ToList(); - var typeAttributeArguments = attributeArguments.OfType>().Select(t => t.Type) - .Union(attributeArguments.OfType()).ToList(); + var attributeArguments = attributeInstance + .AttributeArguments.Select(arg => arg.Value) + .ToList(); + var typeAttributeArguments = attributeArguments + .OfType>() + .Select(t => t.Type) + .Union(attributeArguments.OfType()) + .ToList(); foreach (var arg in argumentValueList) { if (arg is Type argType) @@ -2614,7 +3473,8 @@ bool Condition(TRuleType obj, Architecture architecture) } return false; - NextAttribute: ; + NextAttribute: + ; } return true; @@ -2623,11 +3483,14 @@ bool Condition(TRuleType obj, Architecture architecture) return new ArchitectureCondition(Condition, failDescription, description); } - public static ICondition NotHaveAttributeWithArguments([NotNull] Type attribute, - IEnumerable argumentValues) + public static ICondition NotHaveAttributeWithArguments( + [NotNull] Type attribute, + IEnumerable argumentValues + ) { - string description, failDescription; - var argumentValueList = argumentValues?.ToList() ?? new List {null}; + string description, + failDescription; + var argumentValueList = argumentValues?.ToList() ?? new List { null }; if (argumentValueList.IsNullOrEmpty()) { description = "not have attribute \"" + attribute.FullName + "\""; @@ -2636,12 +3499,26 @@ public static ICondition NotHaveAttributeWithArguments([NotNull] Type else { var firstArgument = argumentValueList.First(); - description = argumentValueList.Where(att => att != firstArgument).Aggregate( - "not have attribute \"" + attribute.FullName + "\" with arguments \"" + firstArgument + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\""); - failDescription = argumentValueList.Where(att => att != firstArgument).Aggregate( - "does have attribute \"" + attribute.FullName + "\" with arguments \"" + firstArgument + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\""); + description = argumentValueList + .Where(att => att != firstArgument) + .Aggregate( + "not have attribute \"" + + attribute.FullName + + "\" with arguments \"" + + firstArgument + + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); + failDescription = argumentValueList + .Where(att => att != firstArgument) + .Aggregate( + "does have attribute \"" + + attribute.FullName + + "\" with arguments \"" + + firstArgument + + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); } bool Condition(TRuleType obj, Architecture architecture) @@ -2664,9 +3541,14 @@ bool Condition(TRuleType obj, Architecture architecture) goto NextAttribute; } - var attributeArguments = attributeInstance.AttributeArguments.Select(arg => arg.Value).ToList(); - var typeAttributeArguments = attributeArguments.OfType>().Select(t => t.Type) - .Union(attributeArguments.OfType()).ToList(); + var attributeArguments = attributeInstance + .AttributeArguments.Select(arg => arg.Value) + .ToList(); + var typeAttributeArguments = attributeArguments + .OfType>() + .Select(t => t.Type) + .Union(attributeArguments.OfType()) + .ToList(); foreach (var arg in argumentValueList) { if (arg is Type argType) @@ -2683,7 +3565,8 @@ bool Condition(TRuleType obj, Architecture architecture) } return false; - NextAttribute: ; + NextAttribute: + ; } return true; @@ -2693,7 +3576,8 @@ bool Condition(TRuleType obj, Architecture architecture) } public static ICondition NotHaveAnyAttributesWithNamedArguments( - IEnumerable<(string, object)> attributeArguments) + IEnumerable<(string, object)> attributeArguments + ) { var argumentList = attributeArguments.ToList(); string description; @@ -2707,19 +3591,24 @@ public static ICondition NotHaveAnyAttributesWithNamedArguments( else { var firstArgument = argumentList.First(); - description = argumentList.Where(attribute => attribute != firstArgument).Aggregate( - "not have any attributes with named arguments \"" + firstArgument.Item1 + "=" + - firstArgument.Item2 + - "\"", - (current, arg) => - current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\""); - + description = argumentList + .Where(attribute => attribute != firstArgument) + .Aggregate( + "not have any attributes with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); failDescription = (ruleType, architecture) => { - var actualNamedArguments = ruleType.AttributeInstances - .SelectMany(instance => - instance.AttributeArguments.OfType()).ToList(); + var actualNamedArguments = ruleType + .AttributeInstances.SelectMany(instance => + instance.AttributeArguments.OfType() + ) + .ToList(); if (!actualNamedArguments.Any()) { return "does have no attribute with a named argument"; @@ -2727,30 +3616,42 @@ public static ICondition NotHaveAnyAttributesWithNamedArguments( var firstActualNamedArgument = actualNamedArguments.First(); return actualNamedArguments.Aggregate( - "does have attributes with named arguments \"" + firstActualNamedArgument.Name + "=" + - firstActualNamedArgument.Value + "\"", - (current, arg) => - current + " and \"" + arg.Name + "=" + arg.Value + "\""); + "does have attributes with named arguments \"" + + firstActualNamedArgument.Name + + "=" + + firstActualNamedArgument.Value + + "\"", + (current, arg) => current + " and \"" + arg.Name + "=" + arg.Value + "\"" + ); }; } bool Condition(TRuleType obj, Architecture architecture) { - var attArguments = obj.AttributeInstances.SelectMany(instance => - instance.AttributeArguments.OfType() - .Select(arg => (arg.Name, arg.Value))) + var attArguments = obj + .AttributeInstances.SelectMany(instance => + instance + .AttributeArguments.OfType() + .Select(arg => (arg.Name, arg.Value)) + ) .ToList(); var typeAttributeArguments = attArguments - .Where(arg => arg.Value is ITypeInstance || arg.Value is IType).ToList(); + .Where(arg => arg.Value is ITypeInstance || arg.Value is IType) + .ToList(); foreach (var arg in argumentList) { if (arg.Item2 is Type argType) { - if (typeAttributeArguments.Any(t => - t.Name == arg.Item1 && - (t.Value is ITypeInstance typeInstance && - typeInstance.Type.FullName == argType.FullName || - t.Value is IType type && type.FullName == argType.FullName))) + if ( + typeAttributeArguments.Any(t => + t.Name == arg.Item1 + && ( + t.Value is ITypeInstance typeInstance + && typeInstance.Type.FullName == argType.FullName + || t.Value is IType type && type.FullName == argType.FullName + ) + ) + ) { return false; } @@ -2767,10 +3668,13 @@ bool Condition(TRuleType obj, Architecture architecture) return new ArchitectureCondition(Condition, failDescription, description); } - public static ICondition NotHaveAttributeWithNamedArguments([NotNull] string attribute, - IEnumerable<(string, object)> attributeArguments) + public static ICondition NotHaveAttributeWithNamedArguments( + [NotNull] string attribute, + IEnumerable<(string, object)> attributeArguments + ) { - string description, failDescription; + string description, + failDescription; var argumentList = attributeArguments.ToList(); if (argumentList.IsNullOrEmpty()) { @@ -2780,14 +3684,30 @@ public static ICondition NotHaveAttributeWithNamedArguments([NotNull] else { var firstArgument = argumentList.First(); - description = argumentList.Where(att => att != firstArgument).Aggregate( - "not have attribute \"" + attribute + "\" with named arguments \"" + firstArgument.Item1 + - "=" + firstArgument.Item2 + "\"", - (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\""); - failDescription = argumentList.Where(att => att != firstArgument).Aggregate( - "does have attribute \"" + attribute + "\" with named arguments \"" + - firstArgument.Item1 + "=" + firstArgument.Item2 + "\"", - (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\""); + description = argumentList + .Where(att => att != firstArgument) + .Aggregate( + "not have attribute \"" + + attribute + + "\" with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); + failDescription = argumentList + .Where(att => att != firstArgument) + .Aggregate( + "does have attribute \"" + + attribute + + "\" with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); } bool Condition(TRuleType obj, Architecture architecture) @@ -2799,19 +3719,25 @@ bool Condition(TRuleType obj, Architecture architecture) goto NextAttribute; } - var attributeArgs = attributeInstance.AttributeArguments.OfType() - .Select(arg => (arg.Name, arg.Value)).ToList(); + var attributeArgs = attributeInstance + .AttributeArguments.OfType() + .Select(arg => (arg.Name, arg.Value)) + .ToList(); var typeAttributeArguments = attributeArgs - .Where(arg => arg.Value is ITypeInstance || arg.Value is IType).ToList(); + .Where(arg => arg.Value is ITypeInstance || arg.Value is IType) + .ToList(); foreach (var arg in argumentList) { if (arg.Item2 is Type argType) { - if (typeAttributeArguments.All(t => t.Name != arg.Item1 || - t.Value is ITypeInstance typeInstance && - typeInstance.Type.FullName != argType.FullName || - t.Value is IType type && - type.FullName != argType.FullName)) + if ( + typeAttributeArguments.All(t => + t.Name != arg.Item1 + || t.Value is ITypeInstance typeInstance + && typeInstance.Type.FullName != argType.FullName + || t.Value is IType type && type.FullName != argType.FullName + ) + ) { goto NextAttribute; } @@ -2823,7 +3749,8 @@ t.Value is IType type && } return false; - NextAttribute: ; + NextAttribute: + ; } return true; @@ -2832,10 +3759,13 @@ t.Value is IType type && return new ArchitectureCondition(Condition, failDescription, description); } - public static ICondition NotHaveAttributeWithNamedArguments([NotNull] Attribute attribute, - IEnumerable<(string, object)> attributeArguments) + public static ICondition NotHaveAttributeWithNamedArguments( + [NotNull] Attribute attribute, + IEnumerable<(string, object)> attributeArguments + ) { - string description, failDescription; + string description, + failDescription; var argumentList = attributeArguments.ToList(); if (argumentList.IsNullOrEmpty()) { @@ -2845,14 +3775,30 @@ public static ICondition NotHaveAttributeWithNamedArguments([NotNull] else { var firstArgument = argumentList.First(); - description = argumentList.Where(att => att != firstArgument).Aggregate( - "not have attribute \"" + attribute.FullName + "\" with named arguments \"" + firstArgument.Item1 + - "=" + firstArgument.Item2 + "\"", - (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\""); - failDescription = argumentList.Where(att => att != firstArgument).Aggregate( - "does have attribute \"" + attribute.FullName + "\" with named arguments \"" + - firstArgument.Item1 + "=" + firstArgument.Item2 + "\"", - (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\""); + description = argumentList + .Where(att => att != firstArgument) + .Aggregate( + "not have attribute \"" + + attribute.FullName + + "\" with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); + failDescription = argumentList + .Where(att => att != firstArgument) + .Aggregate( + "does have attribute \"" + + attribute.FullName + + "\" with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); } bool Condition(TRuleType obj, Architecture architecture) @@ -2864,19 +3810,25 @@ bool Condition(TRuleType obj, Architecture architecture) goto NextAttribute; } - var attributeArgs = attributeInstance.AttributeArguments.OfType() - .Select(arg => (arg.Name, arg.Value)).ToList(); + var attributeArgs = attributeInstance + .AttributeArguments.OfType() + .Select(arg => (arg.Name, arg.Value)) + .ToList(); var typeAttributeArguments = attributeArgs - .Where(arg => arg.Value is ITypeInstance || arg.Value is IType).ToList(); + .Where(arg => arg.Value is ITypeInstance || arg.Value is IType) + .ToList(); foreach (var arg in argumentList) { if (arg.Item2 is Type argType) { - if (typeAttributeArguments.All(t => t.Name != arg.Item1 || - t.Value is ITypeInstance typeInstance && - typeInstance.Type.FullName != argType.FullName || - t.Value is IType type && - type.FullName != argType.FullName)) + if ( + typeAttributeArguments.All(t => + t.Name != arg.Item1 + || t.Value is ITypeInstance typeInstance + && typeInstance.Type.FullName != argType.FullName + || t.Value is IType type && type.FullName != argType.FullName + ) + ) { goto NextAttribute; } @@ -2888,7 +3840,8 @@ t.Value is IType type && } return false; - NextAttribute: ; + NextAttribute: + ; } return true; @@ -2897,10 +3850,13 @@ t.Value is IType type && return new ArchitectureCondition(Condition, failDescription, description); } - public static ICondition NotHaveAttributeWithNamedArguments([NotNull] Type attribute, - IEnumerable<(string, object)> attributeArguments) + public static ICondition NotHaveAttributeWithNamedArguments( + [NotNull] Type attribute, + IEnumerable<(string, object)> attributeArguments + ) { - string description, failDescription; + string description, + failDescription; var argumentList = attributeArguments.ToList(); if (argumentList.IsNullOrEmpty()) { @@ -2910,14 +3866,30 @@ public static ICondition NotHaveAttributeWithNamedArguments([NotNull] else { var firstArgument = argumentList.First(); - description = argumentList.Where(att => att != firstArgument).Aggregate( - "not have attribute \"" + attribute.FullName + "\" with named arguments \"" + firstArgument.Item1 + - "=" + firstArgument.Item2 + "\"", - (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\""); - failDescription = argumentList.Where(att => att != firstArgument).Aggregate( - "does have attribute \"" + attribute.FullName + "\" with named arguments \"" + - firstArgument.Item1 + "=" + firstArgument.Item2 + "\"", - (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\""); + description = argumentList + .Where(att => att != firstArgument) + .Aggregate( + "not have attribute \"" + + attribute.FullName + + "\" with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); + failDescription = argumentList + .Where(att => att != firstArgument) + .Aggregate( + "does have attribute \"" + + attribute.FullName + + "\" with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); } bool Condition(TRuleType obj, Architecture architecture) @@ -2940,19 +3912,25 @@ bool Condition(TRuleType obj, Architecture architecture) goto NextAttribute; } - var attributeArgs = attributeInstance.AttributeArguments.OfType() - .Select(arg => (arg.Name, arg.Value)).ToList(); + var attributeArgs = attributeInstance + .AttributeArguments.OfType() + .Select(arg => (arg.Name, arg.Value)) + .ToList(); var typeAttributeArguments = attributeArgs - .Where(arg => arg.Value is ITypeInstance || arg.Value is IType).ToList(); + .Where(arg => arg.Value is ITypeInstance || arg.Value is IType) + .ToList(); foreach (var arg in argumentList) { if (arg.Item2 is Type argType) { - if (typeAttributeArguments.All(t => t.Name != arg.Item1 || - t.Value is ITypeInstance typeInstance && - typeInstance.Type.FullName != argType.FullName || - t.Value is IType type && - type.FullName != argType.FullName)) + if ( + typeAttributeArguments.All(t => + t.Name != arg.Item1 + || t.Value is ITypeInstance typeInstance + && typeInstance.Type.FullName != argType.FullName + || t.Value is IType type && type.FullName != argType.FullName + ) + ) { goto NextAttribute; } @@ -2964,7 +3942,8 @@ t.Value is IType type && } return false; - NextAttribute: ; + NextAttribute: + ; } return true; @@ -2973,93 +3952,146 @@ t.Value is IType type && return new ArchitectureCondition(Condition, failDescription, description); } - public static ICondition NotHaveName(string pattern, bool useRegularExpressions = false) + public static ICondition NotHaveName( + string pattern, + bool useRegularExpressions = false + ) { - return new SimpleCondition(obj => !obj.NameMatches(pattern, useRegularExpressions), obj => "does have name " + obj.Name, - "not have name " + (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\""); + return new SimpleCondition( + obj => !obj.NameMatches(pattern, useRegularExpressions), + obj => "does have name " + obj.Name, + "not have name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static ICondition NotHaveFullName(string pattern, bool useRegularExpressions = false) + public static ICondition NotHaveFullName( + string pattern, + bool useRegularExpressions = false + ) { - return new SimpleCondition(obj => !obj.FullNameMatches(pattern, useRegularExpressions), + return new SimpleCondition( + obj => !obj.FullNameMatches(pattern, useRegularExpressions), obj => "does have full name " + obj.FullName, - "not have full name " + (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\""); + "not have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } public static ICondition NotHaveNameStartingWith(string pattern) { - return new SimpleCondition(obj => !obj.NameStartsWith(pattern), + return new SimpleCondition( + obj => !obj.NameStartsWith(pattern), obj => "does have name " + obj.Name, - "not have name starting with \"" + pattern + "\""); + "not have name starting with \"" + pattern + "\"" + ); } public static ICondition NotHaveNameEndingWith(string pattern) { - return new SimpleCondition(obj => !obj.NameEndsWith(pattern), + return new SimpleCondition( + obj => !obj.NameEndsWith(pattern), obj => "does have name " + obj.Name, - "not have name ending with \"" + pattern + "\""); + "not have name ending with \"" + pattern + "\"" + ); } public static ICondition NotHaveNameContaining(string pattern) { - return new SimpleCondition(obj => !obj.NameContains(pattern), + return new SimpleCondition( + obj => !obj.NameContains(pattern), obj => "does have name " + obj.Name, - "not have name containing \"" + pattern + "\""); + "not have name containing \"" + pattern + "\"" + ); } public static ICondition NotHaveFullNameContaining(string pattern) { - return new SimpleCondition(obj => !obj.FullNameContains(pattern), + return new SimpleCondition( + obj => !obj.FullNameContains(pattern), obj => "does have full name " + obj.FullName, - "not have full name containing \"" + pattern + "\""); + "not have full name containing \"" + pattern + "\"" + ); } public static ICondition NotBePrivate() { - return new SimpleCondition(obj => obj.Visibility != Private, "not be private", "is private"); + return new SimpleCondition( + obj => obj.Visibility != Private, + "not be private", + "is private" + ); } public static ICondition NotBePublic() { - return new SimpleCondition(obj => obj.Visibility != Public, "not be public", "is public"); + return new SimpleCondition( + obj => obj.Visibility != Public, + "not be public", + "is public" + ); } public static ICondition NotBeProtected() { - return new SimpleCondition(obj => obj.Visibility != Protected, "not be protected", - "is protected"); + return new SimpleCondition( + obj => obj.Visibility != Protected, + "not be protected", + "is protected" + ); } public static ICondition NotBeInternal() { - return new SimpleCondition(obj => obj.Visibility != Internal, "not be internal", "is internal"); + return new SimpleCondition( + obj => obj.Visibility != Internal, + "not be internal", + "is internal" + ); } public static ICondition NotBeProtectedInternal() { return new SimpleCondition( - obj => obj.Visibility != ProtectedInternal, "not be protected internal", "is protected internal"); + obj => obj.Visibility != ProtectedInternal, + "not be protected internal", + "is protected internal" + ); } public static ICondition NotBePrivateProtected() { - return new SimpleCondition(obj => obj.Visibility != PrivateProtected, "not be private protected", - "is private protected"); + return new SimpleCondition( + obj => obj.Visibility != PrivateProtected, + "not be private protected", + "is private protected" + ); } - //Relation Condition Negations public static RelationCondition NotDependOnAnyTypesThat() { - return new RelationCondition(NotDependOnAny, "not depend on any types that", - "does depend on any types that"); + return new RelationCondition( + NotDependOnAny, + "not depend on any types that", + "does depend on any types that" + ); } public static RelationCondition NotHaveAnyAttributesThat() { - return new RelationCondition(NotHaveAnyAttributes, "not have attributes that", - "does have attributes that"); + return new RelationCondition( + NotHaveAnyAttributes, + "not have attributes that", + "does have attributes that" + ); } } } diff --git a/ArchUnitNET/Fluent/Syntax/Elements/ObjectPredicatesDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/ObjectPredicatesDefinition.cs index 0b774cb4d..f8a9152dd 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/ObjectPredicatesDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/ObjectPredicatesDefinition.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -17,15 +17,25 @@ namespace ArchUnitNET.Fluent.Syntax.Elements { - public static class ObjectPredicatesDefinition where T : ICanBeAnalyzed + public static class ObjectPredicatesDefinition + where T : ICanBeAnalyzed { public static IPredicate Are(string pattern, bool useRegularExpressions = false) { - return new SimplePredicate(obj => obj.FullNameMatches(pattern, useRegularExpressions), - "have full name " + (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\""); + return new SimplePredicate( + obj => obj.FullNameMatches(pattern, useRegularExpressions), + "have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static IPredicate Are(IEnumerable patterns, bool useRegularExpressions = false) + public static IPredicate Are( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); string description; @@ -36,20 +46,38 @@ public static IPredicate Are(IEnumerable patterns, bool useRegularExp else { var firstPattern = patternList.First(); - description = patternList.Where(pattern => !pattern.Equals(firstPattern)).Distinct().Aggregate( - "have full name " + (useRegularExpressions ? "matching " : "") + "\"" + - firstPattern + "\"", (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimplePredicate( - obj => patternList.Any(pattern => obj.FullNameMatches(pattern, useRegularExpressions)), description); - } - - public static IPredicate Are(ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects) - { - var objects = new List {firstObject}.Union(moreObjects).OfType(); - var description = moreObjects.Aggregate("are \"" + firstObject.FullName + "\"", - (current, obj) => current + " or \"" + obj.FullName + "\""); + obj => + patternList.Any(pattern => obj.FullNameMatches(pattern, useRegularExpressions)), + description + ); + } + + public static IPredicate Are( + ICanBeAnalyzed firstObject, + params ICanBeAnalyzed[] moreObjects + ) + { + var objects = new List { firstObject } + .Union(moreObjects) + .OfType(); + var description = moreObjects.Aggregate( + "are \"" + firstObject.FullName + "\"", + (current, obj) => current + " or \"" + obj.FullName + "\"" + ); return new EnumerablePredicate(e => e.Intersect(objects), description); } @@ -64,12 +92,19 @@ public static IPredicate Are(IEnumerable objects) else { var firstObject = objectList.First(); - description = objectList.Where(obj => !obj.Equals(firstObject)).Distinct().Aggregate( - "are \"" + firstObject.FullName + "\"", - (current, obj) => current + " or \"" + obj.FullName + "\""); + description = objectList + .Where(obj => !obj.Equals(firstObject)) + .Distinct() + .Aggregate( + "are \"" + firstObject.FullName + "\"", + (current, obj) => current + " or \"" + obj.FullName + "\"" + ); } - return new EnumerablePredicate(e => e.Intersect(objectList.OfType()), description); + return new EnumerablePredicate( + e => e.Intersect(objectList.OfType()), + description + ); } public static IPredicate Are(IObjectProvider objectProvider) @@ -84,12 +119,20 @@ IEnumerable Filter(IEnumerable objects, Architecture architecture) public static IPredicate CallAny(string pattern, bool useRegularExpressions = false) { - return new SimplePredicate(obj => obj.CallsMethod(pattern, useRegularExpressions), - "calls any method with full name " + (useRegularExpressions ? "matching " : "") + "\"" + - pattern + "\""); + return new SimplePredicate( + obj => obj.CallsMethod(pattern, useRegularExpressions), + "calls any method with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static IPredicate CallAny(IEnumerable patterns, bool useRegularExpressions = false) + public static IPredicate CallAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); @@ -106,10 +149,17 @@ bool Filter(T type) else { var firstPattern = patternList.First(); - description = patternList.Where(pattern => !pattern.Equals(firstPattern)).Distinct().Aggregate( - "call any method with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + - firstPattern + "\"", (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "call any method with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimplePredicate(Filter, description); @@ -117,7 +167,7 @@ bool Filter(T type) public static IPredicate CallAny(MethodMember method, params MethodMember[] moreMethods) { - var methods = new List {method}; + var methods = new List { method }; methods.AddRange(moreMethods); return CallAny(methods); } @@ -151,9 +201,13 @@ IEnumerable Filter(IEnumerable objects) else { var firstMethod = methodList.First(); - description = methodList.Where(obj => !obj.Equals(firstMethod)).Distinct().Aggregate( - "call \"" + firstMethod.FullName + "\"", - (current, obj) => current + " or \"" + obj.FullName + "\""); + description = methodList + .Where(obj => !obj.Equals(firstMethod)) + .Distinct() + .Aggregate( + "call \"" + firstMethod.FullName + "\"", + (current, obj) => current + " or \"" + obj.FullName + "\"" + ); } return new EnumerablePredicate(Filter, description); @@ -161,19 +215,31 @@ IEnumerable Filter(IEnumerable objects) public static IPredicate DependOnAny(string pattern, bool useRegularExpressions = false) { - return new SimplePredicate(obj => obj.DependsOn(pattern, useRegularExpressions), - "depend on any types with full name " + (useRegularExpressions ? "matching " : "") + "\"" + - pattern + "\""); + return new SimplePredicate( + obj => obj.DependsOn(pattern, useRegularExpressions), + "depend on any types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static IPredicate DependOnAny(IEnumerable patterns, bool useRegularExpressions = false) + public static IPredicate DependOnAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Filter(T type) { - return type.GetTypeDependencies().Any(target => - patternList.Any(pattern => target.FullNameMatches(pattern, useRegularExpressions))); + return type.GetTypeDependencies() + .Any(target => + patternList.Any(pattern => + target.FullNameMatches(pattern, useRegularExpressions) + ) + ); } string description; @@ -184,10 +250,17 @@ bool Filter(T type) else { var firstPattern = patternList.First(); - description = patternList.Where(pattern => !pattern.Equals(firstPattern)).Distinct().Aggregate( - "depend on any types with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + - firstPattern + "\"", (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "depend on any types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimplePredicate(Filter, description); @@ -195,14 +268,14 @@ bool Filter(T type) public static IPredicate DependOnAny(IType firstType, params IType[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return DependOnAny(types); } public static IPredicate DependOnAny(Type firstType, params Type[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return DependOnAny(types); } @@ -236,9 +309,13 @@ IEnumerable Filter(IEnumerable objects) else { var firstType = typeList.First(); - description = typeList.Where(obj => !obj.Equals(firstType)).Distinct().Aggregate( - "depend on \"" + firstType.FullName + "\"", - (current, obj) => current + " or \"" + obj.FullName + "\""); + description = typeList + .Where(obj => !obj.Equals(firstType)) + .Distinct() + .Aggregate( + "depend on \"" + firstType.FullName + "\"", + (current, obj) => current + " or \"" + obj.FullName + "\"" + ); } return new EnumerablePredicate(Filter, description); @@ -264,7 +341,9 @@ IEnumerable Filter(IEnumerable objects, Architecture architecture) } } - return objects.Where(obj => obj.GetTypeDependencies().Intersect(archUnitTypeList).Any()); + return objects.Where(obj => + obj.GetTypeDependencies().Intersect(archUnitTypeList).Any() + ); } string description; @@ -275,34 +354,53 @@ IEnumerable Filter(IEnumerable objects, Architecture architecture) else { var firstType = typeList.First(); - description = typeList.Where(obj => obj != firstType).Distinct().Aggregate( - "depend on \"" + firstType.FullName + "\"", - (current, obj) => current + " or \"" + obj.FullName + "\""); + description = typeList + .Where(obj => obj != firstType) + .Distinct() + .Aggregate( + "depend on \"" + firstType.FullName + "\"", + (current, obj) => current + " or \"" + obj.FullName + "\"" + ); } return new ArchitecturePredicate(Filter, description); } - public static IPredicate FollowCustomPredicate(Func predicate, string description) + public static IPredicate FollowCustomPredicate( + Func predicate, + string description + ) { return new SimplePredicate(predicate, description); } public static IPredicate OnlyDependOn(string pattern, bool useRegularExpressions = false) { - return new SimplePredicate(obj => obj.OnlyDependsOn(pattern, useRegularExpressions), - "only depend on types with full name " + (useRegularExpressions ? "matching " : "") + "\"" + - pattern + "\""); + return new SimplePredicate( + obj => obj.OnlyDependsOn(pattern, useRegularExpressions), + "only depend on types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static IPredicate OnlyDependOn(IEnumerable patterns, bool useRegularExpressions = false) + public static IPredicate OnlyDependOn( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Filter(T type) { - return type.GetTypeDependencies().All(target => - patternList.Any(pattern => target.FullNameMatches(pattern, useRegularExpressions))); + return type.GetTypeDependencies() + .All(target => + patternList.Any(pattern => + target.FullNameMatches(pattern, useRegularExpressions) + ) + ); } string description; @@ -313,10 +411,17 @@ bool Filter(T type) else { var firstPattern = patternList.First(); - description = patternList.Where(pattern => !pattern.Equals(firstPattern)).Distinct().Aggregate( - "only depend on types with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + - firstPattern + "\"", (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "only depend on types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimplePredicate(Filter, description); @@ -324,14 +429,14 @@ bool Filter(T type) public static IPredicate OnlyDependOn(IType firstType, params IType[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return OnlyDependOn(types); } public static IPredicate OnlyDependOn(Type firstType, params Type[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return OnlyDependOn(types); } @@ -341,7 +446,9 @@ public static IPredicate OnlyDependOn(IObjectProvider objectProvider) IEnumerable Filter(IEnumerable objects, Architecture architecture) { var types = objectProvider.GetObjects(architecture); - return objects.Where(obj => obj.GetTypeDependencies(architecture).Except(types).IsNullOrEmpty()); + return objects.Where(obj => + obj.GetTypeDependencies(architecture).Except(types).IsNullOrEmpty() + ); } var description = "only depend on " + objectProvider.Description; @@ -354,7 +461,9 @@ public static IPredicate OnlyDependOn(IEnumerable types) IEnumerable Filter(IEnumerable objects, Architecture architecture) { - return objects.Where(obj => obj.GetTypeDependencies(architecture).Except(typeList).IsNullOrEmpty()); + return objects.Where(obj => + obj.GetTypeDependencies(architecture).Except(typeList).IsNullOrEmpty() + ); } string description; @@ -365,9 +474,13 @@ IEnumerable Filter(IEnumerable objects, Architecture architecture) else { var firstType = typeList.First(); - description = typeList.Where(obj => !obj.Equals(firstType)).Distinct().Aggregate( - "only depend on \"" + firstType.FullName + "\"", - (current, obj) => current + " or \"" + obj.FullName + "\""); + description = typeList + .Where(obj => !obj.Equals(firstType)) + .Distinct() + .Aggregate( + "only depend on \"" + firstType.FullName + "\"", + (current, obj) => current + " or \"" + obj.FullName + "\"" + ); } return new ArchitecturePredicate(Filter, description); @@ -394,7 +507,8 @@ IEnumerable Filter(IEnumerable objects, Architecture architecture) } return objects.Where(obj => - obj.GetTypeDependencies(architecture).Except(archUnitTypeList).IsNullOrEmpty()); + obj.GetTypeDependencies(architecture).Except(archUnitTypeList).IsNullOrEmpty() + ); } string description; @@ -405,29 +519,47 @@ IEnumerable Filter(IEnumerable objects, Architecture architecture) else { var firstType = typeList.First(); - description = typeList.Where(obj => obj != firstType).Distinct().Aggregate( - "only depend on \"" + firstType.FullName + "\"", - (current, obj) => current + " or \"" + obj.FullName + "\""); + description = typeList + .Where(obj => obj != firstType) + .Distinct() + .Aggregate( + "only depend on \"" + firstType.FullName + "\"", + (current, obj) => current + " or \"" + obj.FullName + "\"" + ); } return new ArchitecturePredicate(Filter, description); } - public static IPredicate HaveAnyAttributes(string pattern, bool useRegularExpressions = false) + public static IPredicate HaveAnyAttributes( + string pattern, + bool useRegularExpressions = false + ) { - return new SimplePredicate(obj => obj.HasAttribute(pattern, useRegularExpressions), - "have any attribute with full name " + (useRegularExpressions ? "matching " : "") + "\"" + - pattern + "\""); + return new SimplePredicate( + obj => obj.HasAttribute(pattern, useRegularExpressions), + "have any attribute with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static IPredicate HaveAnyAttributes(IEnumerable patterns, bool useRegularExpressions = false) + public static IPredicate HaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Filter(T type) { return type.Attributes.Any(attribute => - patternList.Any(pattern => attribute.FullNameMatches(pattern, useRegularExpressions))); + patternList.Any(pattern => + attribute.FullNameMatches(pattern, useRegularExpressions) + ) + ); } string description; @@ -438,25 +570,38 @@ bool Filter(T type) else { var firstPattern = patternList.First(); - description = patternList.Where(pattern => !pattern.Equals(firstPattern)).Distinct().Aggregate( - "have any attribute with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + - firstPattern + "\"", (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "have any attribute with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimplePredicate(Filter, description); } - public static IPredicate HaveAnyAttributes(Attribute firstAttribute, params Attribute[] moreAttributes) + public static IPredicate HaveAnyAttributes( + Attribute firstAttribute, + params Attribute[] moreAttributes + ) { - var attributes = new List {firstAttribute}; + var attributes = new List { firstAttribute }; attributes.AddRange(moreAttributes); return HaveAnyAttributes(attributes); } - public static IPredicate HaveAnyAttributes(Type firstAttribute, params Type[] moreAttributes) + public static IPredicate HaveAnyAttributes( + Type firstAttribute, + params Type[] moreAttributes + ) { - var attributes = new List {firstAttribute}; + var attributes = new List { firstAttribute }; attributes.AddRange(moreAttributes); return HaveAnyAttributes(attributes); } @@ -490,9 +635,13 @@ IEnumerable Filter(IEnumerable objects) else { var firstAttribute = attributeList.First(); - description = attributeList.Where(obj => !obj.Equals(firstAttribute)).Distinct().Aggregate( - "have attribute \"" + firstAttribute.FullName + "\"", - (current, attribute) => current + " or \"" + attribute.FullName + "\""); + description = attributeList + .Where(obj => !obj.Equals(firstAttribute)) + .Distinct() + .Aggregate( + "have attribute \"" + firstAttribute.FullName + "\"", + (current, attribute) => current + " or \"" + attribute.FullName + "\"" + ); } return new EnumerablePredicate(Filter, description); @@ -516,29 +665,48 @@ IEnumerable Filter(IEnumerable objects, Architecture architecture) else { var firstType = attributeList.First(); - description = attributeList.Where(obj => obj != firstType).Distinct().Aggregate( - "have attribute \"" + firstType.FullName + "\"", - (current, obj) => current + " or \"" + obj.FullName + "\""); + description = attributeList + .Where(obj => obj != firstType) + .Distinct() + .Aggregate( + "have attribute \"" + firstType.FullName + "\"", + (current, obj) => current + " or \"" + obj.FullName + "\"" + ); } return new ArchitecturePredicate(Filter, description); } - public static IPredicate OnlyHaveAttributes(string pattern, bool useRegularExpressions = false) + public static IPredicate OnlyHaveAttributes( + string pattern, + bool useRegularExpressions = false + ) { - return new SimplePredicate(obj => obj.OnlyHasAttributes(pattern, useRegularExpressions), - "only have attributes with full name " + (useRegularExpressions ? "matching " : "") + "\"" + - pattern + "\""); + return new SimplePredicate( + obj => obj.OnlyHasAttributes(pattern, useRegularExpressions), + "only have attributes with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static IPredicate OnlyHaveAttributes(IEnumerable patterns, bool useRegularExpressions = false) + public static IPredicate OnlyHaveAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Filter(T type) { - return type.Attributes.IsNullOrEmpty() || type.Attributes.All(attribute => - patternList.Any(pattern => attribute.FullNameMatches(pattern, useRegularExpressions))); + return type.Attributes.IsNullOrEmpty() + || type.Attributes.All(attribute => + patternList.Any(pattern => + attribute.FullNameMatches(pattern, useRegularExpressions) + ) + ); } string description; @@ -549,25 +717,38 @@ bool Filter(T type) else { var firstPattern = patternList.First(); - description = patternList.Where(pattern => !pattern.Equals(firstPattern)).Distinct().Aggregate( - "only have attributes with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + - firstPattern + "\"", (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "only have attributes with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimplePredicate(Filter, description); } - public static IPredicate OnlyHaveAttributes(Attribute firstAttribute, params Attribute[] moreAttributes) + public static IPredicate OnlyHaveAttributes( + Attribute firstAttribute, + params Attribute[] moreAttributes + ) { - var attributes = new List {firstAttribute}; + var attributes = new List { firstAttribute }; attributes.AddRange(moreAttributes); return OnlyHaveAttributes(attributes); } - public static IPredicate OnlyHaveAttributes(Type firstAttribute, params Type[] moreAttributes) + public static IPredicate OnlyHaveAttributes( + Type firstAttribute, + params Type[] moreAttributes + ) { - var attributes = new List {firstAttribute}; + var attributes = new List { firstAttribute }; attributes.AddRange(moreAttributes); return OnlyHaveAttributes(attributes); } @@ -601,9 +782,13 @@ IEnumerable Filter(IEnumerable objects) else { var firstAttribute = attributeList.First(); - description = attributeList.Where(obj => !obj.Equals(firstAttribute)).Distinct().Aggregate( - "only have attribute \"" + firstAttribute.FullName + "\"", - (current, attribute) => current + " or \"" + attribute.FullName + "\""); + description = attributeList + .Where(obj => !obj.Equals(firstAttribute)) + .Distinct() + .Aggregate( + "only have attribute \"" + firstAttribute.FullName + "\"", + (current, attribute) => current + " or \"" + attribute.FullName + "\"" + ); } return new EnumerablePredicate(Filter, description); @@ -640,81 +825,109 @@ IEnumerable Filter(IEnumerable objects, Architecture architecture) else { var firstType = attributeList.First(); - description = attributeList.Where(obj => obj != firstType).Distinct().Aggregate( - "only have attribute \"" + firstType.FullName + "\"", - (current, obj) => current + " or \"" + obj.FullName + "\""); + description = attributeList + .Where(obj => obj != firstType) + .Distinct() + .Aggregate( + "only have attribute \"" + firstType.FullName + "\"", + (current, obj) => current + " or \"" + obj.FullName + "\"" + ); } return new ArchitecturePredicate(Filter, description); } - public static IPredicate HaveAnyAttributesWithArguments(object firstArgumentValue, - params object[] moreArgumentValues) + public static IPredicate HaveAnyAttributesWithArguments( + object firstArgumentValue, + params object[] moreArgumentValues + ) { - var argumentValues = new List {firstArgumentValue}; + var argumentValues = new List { firstArgumentValue }; argumentValues.AddRange(moreArgumentValues); return HaveAnyAttributesWithArguments(argumentValues); } - public static IPredicate HaveAttributeWithArguments(string attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public static IPredicate HaveAttributeWithArguments( + string attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { - var argumentValues = new List {firstArgumentValue}; + var argumentValues = new List { firstArgumentValue }; argumentValues.AddRange(moreArgumentValues); return HaveAttributeWithArguments(attribute, argumentValues); } - public static IPredicate HaveAttributeWithArguments(Attribute attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public static IPredicate HaveAttributeWithArguments( + Attribute attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { - var argumentValues = new List {firstArgumentValue}; + var argumentValues = new List { firstArgumentValue }; argumentValues.AddRange(moreArgumentValues); return HaveAttributeWithArguments(attribute, argumentValues); } - public static IPredicate HaveAttributeWithArguments(Type attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public static IPredicate HaveAttributeWithArguments( + Type attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { - var argumentValues = new List {firstArgumentValue}; + var argumentValues = new List { firstArgumentValue }; argumentValues.AddRange(moreArgumentValues); return HaveAttributeWithArguments(attribute, argumentValues); } - public static IPredicate HaveAnyAttributesWithNamedArguments((string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments) + public static IPredicate HaveAnyAttributesWithNamedArguments( + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { - var attributeArguments = new List<(string, object)> {firstAttributeArgument}; + var attributeArguments = new List<(string, object)> { firstAttributeArgument }; attributeArguments.AddRange(moreAttributeArguments); return HaveAnyAttributesWithNamedArguments(attributeArguments); } - public static IPredicate HaveAttributeWithNamedArguments(string attribute, - (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments) + public static IPredicate HaveAttributeWithNamedArguments( + string attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { - var attributeArguments = new List<(string, object)> {firstAttributeArgument}; + var attributeArguments = new List<(string, object)> { firstAttributeArgument }; attributeArguments.AddRange(moreAttributeArguments); return HaveAttributeWithNamedArguments(attribute, attributeArguments); } - public static IPredicate HaveAttributeWithNamedArguments(Attribute attribute, - (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments) + public static IPredicate HaveAttributeWithNamedArguments( + Attribute attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { - var attributeArguments = new List<(string, object)> {firstAttributeArgument}; + var attributeArguments = new List<(string, object)> { firstAttributeArgument }; attributeArguments.AddRange(moreAttributeArguments); return HaveAttributeWithNamedArguments(attribute, attributeArguments); } - public static IPredicate HaveAttributeWithNamedArguments(Type attribute, - (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments) + public static IPredicate HaveAttributeWithNamedArguments( + Type attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { - var attributeArguments = new List<(string, object)> {firstAttributeArgument}; + var attributeArguments = new List<(string, object)> { firstAttributeArgument }; attributeArguments.AddRange(moreAttributeArguments); return HaveAttributeWithNamedArguments(attribute, attributeArguments); } - public static IPredicate HaveAnyAttributesWithArguments(IEnumerable argumentValues) + public static IPredicate HaveAnyAttributesWithArguments( + IEnumerable argumentValues + ) { - var argumentValueList = argumentValues?.ToList() ?? new List {null}; + var argumentValueList = argumentValues?.ToList() ?? new List { null }; string description; if (argumentValueList.IsNullOrEmpty()) { @@ -723,17 +936,26 @@ public static IPredicate HaveAnyAttributesWithArguments(IEnumerable a else { var firstArgument = argumentValueList.First(); - description = argumentValueList.Where(attribute => attribute != firstArgument).Aggregate( - "have any attributes with arguments \"" + firstArgument + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\""); + description = argumentValueList + .Where(attribute => attribute != firstArgument) + .Aggregate( + "have any attributes with arguments \"" + firstArgument + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); } bool Predicate(T obj, Architecture architecture) { - var attributeArguments = obj.AttributeInstances - .SelectMany(instance => instance.AttributeArguments.Select(arg => arg.Value)).ToList(); - var typeAttributeArguments = attributeArguments.OfType>().Select(t => t.Type) - .Union(attributeArguments.OfType()).ToList(); + var attributeArguments = obj + .AttributeInstances.SelectMany(instance => + instance.AttributeArguments.Select(arg => arg.Value) + ) + .ToList(); + var typeAttributeArguments = attributeArguments + .OfType>() + .Select(t => t.Type) + .Union(attributeArguments.OfType()) + .ToList(); foreach (var arg in argumentValueList) { if (arg is Type argType) @@ -755,11 +977,13 @@ bool Predicate(T obj, Architecture architecture) return new ArchitecturePredicate(Predicate, description); } - public static IPredicate HaveAttributeWithArguments([NotNull] string attribute, - IEnumerable argumentValues) + public static IPredicate HaveAttributeWithArguments( + [NotNull] string attribute, + IEnumerable argumentValues + ) { string description; - var argumentValueList = argumentValues?.ToList() ?? new List {null}; + var argumentValueList = argumentValues?.ToList() ?? new List { null }; if (argumentValueList.IsNullOrEmpty()) { description = "have attribute \"" + attribute + "\""; @@ -767,9 +991,16 @@ public static IPredicate HaveAttributeWithArguments([NotNull] string attribut else { var firstArgument = argumentValueList.First(); - description = argumentValueList.Where(att => att != firstArgument).Aggregate( - "have attribute \"" + attribute + "\" with arguments \"" + firstArgument + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\""); + description = argumentValueList + .Where(att => att != firstArgument) + .Aggregate( + "have attribute \"" + + attribute + + "\" with arguments \"" + + firstArgument + + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); } bool Predicate(T obj, Architecture architecture) @@ -781,9 +1012,14 @@ bool Predicate(T obj, Architecture architecture) goto NextAttribute; } - var attributeArguments = attributeInstance.AttributeArguments.Select(arg => arg.Value).ToList(); - var typeAttributeArguments = attributeArguments.OfType>().Select(t => t.Type) - .Union(attributeArguments.OfType()).ToList(); + var attributeArguments = attributeInstance + .AttributeArguments.Select(arg => arg.Value) + .ToList(); + var typeAttributeArguments = attributeArguments + .OfType>() + .Select(t => t.Type) + .Union(attributeArguments.OfType()) + .ToList(); foreach (var arg in argumentValueList) { if (arg is Type argType) @@ -800,7 +1036,8 @@ bool Predicate(T obj, Architecture architecture) } return true; - NextAttribute: ; + NextAttribute: + ; } return false; @@ -809,11 +1046,13 @@ bool Predicate(T obj, Architecture architecture) return new ArchitecturePredicate(Predicate, description); } - public static IPredicate HaveAttributeWithArguments([NotNull] Attribute attribute, - IEnumerable argumentValues) + public static IPredicate HaveAttributeWithArguments( + [NotNull] Attribute attribute, + IEnumerable argumentValues + ) { string description; - var argumentValueList = argumentValues?.ToList() ?? new List {null}; + var argumentValueList = argumentValues?.ToList() ?? new List { null }; if (argumentValueList.IsNullOrEmpty()) { description = "have attribute \"" + attribute.FullName + "\""; @@ -821,9 +1060,16 @@ public static IPredicate HaveAttributeWithArguments([NotNull] Attribute attri else { var firstArgument = argumentValueList.First(); - description = argumentValueList.Where(att => att != firstArgument).Aggregate( - "have attribute \"" + attribute.FullName + "\" with arguments \"" + firstArgument + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\""); + description = argumentValueList + .Where(att => att != firstArgument) + .Aggregate( + "have attribute \"" + + attribute.FullName + + "\" with arguments \"" + + firstArgument + + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); } bool Predicate(T obj, Architecture architecture) @@ -835,9 +1081,14 @@ bool Predicate(T obj, Architecture architecture) goto NextAttribute; } - var attributeArguments = attributeInstance.AttributeArguments.Select(arg => arg.Value).ToList(); - var typeAttributeArguments = attributeArguments.OfType>().Select(t => t.Type) - .Union(attributeArguments.OfType()).ToList(); + var attributeArguments = attributeInstance + .AttributeArguments.Select(arg => arg.Value) + .ToList(); + var typeAttributeArguments = attributeArguments + .OfType>() + .Select(t => t.Type) + .Union(attributeArguments.OfType()) + .ToList(); foreach (var arg in argumentValueList) { if (arg is Type argType) @@ -854,7 +1105,8 @@ bool Predicate(T obj, Architecture architecture) } return true; - NextAttribute: ; + NextAttribute: + ; } return false; @@ -863,11 +1115,13 @@ bool Predicate(T obj, Architecture architecture) return new ArchitecturePredicate(Predicate, description); } - public static IPredicate HaveAttributeWithArguments([NotNull] Type attribute, - IEnumerable argumentValues) + public static IPredicate HaveAttributeWithArguments( + [NotNull] Type attribute, + IEnumerable argumentValues + ) { string description; - var argumentValueList = argumentValues?.ToList() ?? new List {null}; + var argumentValueList = argumentValues?.ToList() ?? new List { null }; if (argumentValueList.IsNullOrEmpty()) { description = "have attribute \"" + attribute.FullName + "\""; @@ -875,9 +1129,16 @@ public static IPredicate HaveAttributeWithArguments([NotNull] Type attribute, else { var firstArgument = argumentValueList.First(); - description = argumentValueList.Where(att => att != firstArgument).Aggregate( - "have attribute \"" + attribute.FullName + "\" with arguments \"" + firstArgument + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\""); + description = argumentValueList + .Where(att => att != firstArgument) + .Aggregate( + "have attribute \"" + + attribute.FullName + + "\" with arguments \"" + + firstArgument + + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); } bool Predicate(T obj, Architecture architecture) @@ -900,9 +1161,14 @@ bool Predicate(T obj, Architecture architecture) goto NextAttribute; } - var attributeArguments = attributeInstance.AttributeArguments.Select(arg => arg.Value).ToList(); - var typeAttributeArguments = attributeArguments.OfType>().Select(t => t.Type) - .Union(attributeArguments.OfType()).ToList(); + var attributeArguments = attributeInstance + .AttributeArguments.Select(arg => arg.Value) + .ToList(); + var typeAttributeArguments = attributeArguments + .OfType>() + .Select(t => t.Type) + .Union(attributeArguments.OfType()) + .ToList(); foreach (var arg in argumentValueList) { if (arg is Type argType) @@ -919,7 +1185,8 @@ bool Predicate(T obj, Architecture architecture) } return true; - NextAttribute: ; + NextAttribute: + ; } return false; @@ -929,7 +1196,8 @@ bool Predicate(T obj, Architecture architecture) } public static IPredicate HaveAnyAttributesWithNamedArguments( - IEnumerable<(string, object)> attributeArguments) + IEnumerable<(string, object)> attributeArguments + ) { var argumentList = attributeArguments.ToList(); string description; @@ -940,30 +1208,42 @@ public static IPredicate HaveAnyAttributesWithNamedArguments( else { var firstArgument = argumentList.First(); - description = argumentList.Where(attribute => attribute != firstArgument).Aggregate( - "have any attributes with named arguments \"" + firstArgument.Item1 + "=" + firstArgument.Item2 + - "\"", - (current, arg) => - current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\""); + description = argumentList + .Where(attribute => attribute != firstArgument) + .Aggregate( + "have any attributes with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); } bool Predicate(T obj, Architecture architecture) { - var attArguments = obj.AttributeInstances.SelectMany(instance => - instance.AttributeArguments.OfType() - .Select(arg => (arg.Name, arg.Value))) + var attArguments = obj + .AttributeInstances.SelectMany(instance => + instance + .AttributeArguments.OfType() + .Select(arg => (arg.Name, arg.Value)) + ) .ToList(); var typeAttributeArguments = attArguments - .Where(arg => arg.Value is ITypeInstance || arg.Value is IType).ToList(); + .Where(arg => arg.Value is ITypeInstance || arg.Value is IType) + .ToList(); foreach (var arg in argumentList) { if (arg.Item2 is Type argType) { - if (typeAttributeArguments.All(t => - t.Name != arg.Item1 || - t.Value is ITypeInstance typeInstance && - typeInstance.Type.FullName != argType.FullName || - t.Value is IType type && type.FullName != argType.FullName)) + if ( + typeAttributeArguments.All(t => + t.Name != arg.Item1 + || t.Value is ITypeInstance typeInstance + && typeInstance.Type.FullName != argType.FullName + || t.Value is IType type && type.FullName != argType.FullName + ) + ) { return false; } @@ -980,8 +1260,10 @@ t.Value is ITypeInstance typeInstance && return new ArchitecturePredicate(Predicate, description); } - public static IPredicate HaveAttributeWithNamedArguments([NotNull] string attribute, - IEnumerable<(string, object)> attributeArguments) + public static IPredicate HaveAttributeWithNamedArguments( + [NotNull] string attribute, + IEnumerable<(string, object)> attributeArguments + ) { string description; var argumentList = attributeArguments.ToList(); @@ -992,10 +1274,18 @@ public static IPredicate HaveAttributeWithNamedArguments([NotNull] string att else { var firstArgument = argumentList.First(); - description = argumentList.Where(att => att != firstArgument).Aggregate( - "have attribute \"" + attribute + "\" with named arguments \"" + firstArgument.Item1 + - "=" + firstArgument.Item2 + "\"", - (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\""); + description = argumentList + .Where(att => att != firstArgument) + .Aggregate( + "have attribute \"" + + attribute + + "\" with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); } bool Predicate(T obj, Architecture architecture) @@ -1007,19 +1297,25 @@ bool Predicate(T obj, Architecture architecture) goto NextAttribute; } - var attributeArgs = attributeInstance.AttributeArguments.OfType() - .Select(arg => (arg.Name, arg.Value)).ToList(); + var attributeArgs = attributeInstance + .AttributeArguments.OfType() + .Select(arg => (arg.Name, arg.Value)) + .ToList(); var typeAttributeArguments = attributeArgs - .Where(arg => arg.Value is ITypeInstance || arg.Value is IType).ToList(); + .Where(arg => arg.Value is ITypeInstance || arg.Value is IType) + .ToList(); foreach (var arg in argumentList) { if (arg.Item2 is Type argType) { - if (typeAttributeArguments.All(t => - t.Name != arg.Item1 || - t.Value is ITypeInstance typeInstance && - typeInstance.Type.FullName != argType.FullName || - t.Value is IType type && type.FullName != argType.FullName)) + if ( + typeAttributeArguments.All(t => + t.Name != arg.Item1 + || t.Value is ITypeInstance typeInstance + && typeInstance.Type.FullName != argType.FullName + || t.Value is IType type && type.FullName != argType.FullName + ) + ) { goto NextAttribute; } @@ -1031,7 +1327,8 @@ t.Value is ITypeInstance typeInstance && } return true; - NextAttribute: ; + NextAttribute: + ; } return false; @@ -1040,8 +1337,10 @@ t.Value is ITypeInstance typeInstance && return new ArchitecturePredicate(Predicate, description); } - public static IPredicate HaveAttributeWithNamedArguments([NotNull] Attribute attribute, - IEnumerable<(string, object)> attributeArguments) + public static IPredicate HaveAttributeWithNamedArguments( + [NotNull] Attribute attribute, + IEnumerable<(string, object)> attributeArguments + ) { string description; var argumentList = attributeArguments.ToList(); @@ -1052,10 +1351,18 @@ public static IPredicate HaveAttributeWithNamedArguments([NotNull] Attribute else { var firstArgument = argumentList.First(); - description = argumentList.Where(att => att != firstArgument).Aggregate( - "have attribute \"" + attribute.FullName + "\" with named arguments \"" + firstArgument.Item1 + - "=" + firstArgument.Item2 + "\"", - (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\""); + description = argumentList + .Where(att => att != firstArgument) + .Aggregate( + "have attribute \"" + + attribute.FullName + + "\" with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); } bool Condition(T obj, Architecture architecture) @@ -1067,19 +1374,25 @@ bool Condition(T obj, Architecture architecture) goto NextAttribute; } - var attributeArgs = attributeInstance.AttributeArguments.OfType() - .Select(arg => (arg.Name, arg.Value)).ToList(); + var attributeArgs = attributeInstance + .AttributeArguments.OfType() + .Select(arg => (arg.Name, arg.Value)) + .ToList(); var typeAttributeArguments = attributeArgs - .Where(arg => arg.Value is ITypeInstance || arg.Value is IType).ToList(); + .Where(arg => arg.Value is ITypeInstance || arg.Value is IType) + .ToList(); foreach (var arg in argumentList) { if (arg.Item2 is Type argType) { - if (typeAttributeArguments.All(t => - t.Name != arg.Item1 || - t.Value is ITypeInstance typeInstance && - typeInstance.Type.FullName != argType.FullName || - t.Value is IType type && type.FullName != argType.FullName)) + if ( + typeAttributeArguments.All(t => + t.Name != arg.Item1 + || t.Value is ITypeInstance typeInstance + && typeInstance.Type.FullName != argType.FullName + || t.Value is IType type && type.FullName != argType.FullName + ) + ) { goto NextAttribute; } @@ -1091,7 +1404,8 @@ t.Value is ITypeInstance typeInstance && } return true; - NextAttribute: ; + NextAttribute: + ; } return false; @@ -1100,8 +1414,10 @@ t.Value is ITypeInstance typeInstance && return new ArchitecturePredicate(Condition, description); } - public static IPredicate HaveAttributeWithNamedArguments([NotNull] Type attribute, - IEnumerable<(string, object)> attributeArguments) + public static IPredicate HaveAttributeWithNamedArguments( + [NotNull] Type attribute, + IEnumerable<(string, object)> attributeArguments + ) { string description; var argumentList = attributeArguments.ToList(); @@ -1112,10 +1428,18 @@ public static IPredicate HaveAttributeWithNamedArguments([NotNull] Type attri else { var firstArgument = argumentList.First(); - description = argumentList.Where(att => att != firstArgument).Aggregate( - "have attribute \"" + attribute.FullName + "\" with named arguments \"" + firstArgument.Item1 + - "=" + firstArgument.Item2 + "\"", - (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\""); + description = argumentList + .Where(att => att != firstArgument) + .Aggregate( + "have attribute \"" + + attribute.FullName + + "\" with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); } bool Predicate(T obj, Architecture architecture) @@ -1138,19 +1462,25 @@ bool Predicate(T obj, Architecture architecture) goto NextAttribute; } - var attributeArgs = attributeInstance.AttributeArguments.OfType() - .Select(arg => (arg.Name, arg.Value)).ToList(); + var attributeArgs = attributeInstance + .AttributeArguments.OfType() + .Select(arg => (arg.Name, arg.Value)) + .ToList(); var typeAttributeArguments = attributeArgs - .Where(arg => arg.Value is ITypeInstance || arg.Value is IType).ToList(); + .Where(arg => arg.Value is ITypeInstance || arg.Value is IType) + .ToList(); foreach (var arg in argumentList) { if (arg.Item2 is Type argType) { - if (typeAttributeArguments.All(t => - t.Name != arg.Item1 || - t.Value is ITypeInstance typeInstance && - typeInstance.Type.FullName != argType.FullName || - t.Value is IType type && type.FullName != argType.FullName)) + if ( + typeAttributeArguments.All(t => + t.Name != arg.Item1 + || t.Value is ITypeInstance typeInstance + && typeInstance.Type.FullName != argType.FullName + || t.Value is IType type && type.FullName != argType.FullName + ) + ) { goto NextAttribute; } @@ -1162,7 +1492,8 @@ t.Value is ITypeInstance typeInstance && } return true; - NextAttribute: ; + NextAttribute: + ; } return false; @@ -1173,37 +1504,54 @@ t.Value is ITypeInstance typeInstance && public static IPredicate HaveName(string pattern, bool useRegularExpressions = false) { - return new SimplePredicate(obj => obj.NameMatches(pattern, useRegularExpressions), - "have name " + (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\""); + return new SimplePredicate( + obj => obj.NameMatches(pattern, useRegularExpressions), + "have name " + (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\"" + ); } public static IPredicate HaveFullName(string pattern, bool useRegularExpressions = false) { - return new SimplePredicate(obj => obj.FullNameMatches(pattern, useRegularExpressions), - "have full name " + (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\""); + return new SimplePredicate( + obj => obj.FullNameMatches(pattern, useRegularExpressions), + "have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } public static IPredicate HaveNameStartingWith(string pattern) { - return new SimplePredicate(obj => obj.NameStartsWith(pattern), - "have name starting with \"" + pattern + "\""); + return new SimplePredicate( + obj => obj.NameStartsWith(pattern), + "have name starting with \"" + pattern + "\"" + ); } public static IPredicate HaveNameEndingWith(string pattern) { - return new SimplePredicate(obj => obj.NameEndsWith(pattern), - "have name ending with \"" + pattern + "\""); + return new SimplePredicate( + obj => obj.NameEndsWith(pattern), + "have name ending with \"" + pattern + "\"" + ); } public static IPredicate HaveNameContaining(string pattern) { - return new SimplePredicate(obj => obj.NameContains(pattern), "have name containing \"" + pattern + "\""); + return new SimplePredicate( + obj => obj.NameContains(pattern), + "have name containing \"" + pattern + "\"" + ); } public static IPredicate HaveFullNameContaining(string pattern) { - return new SimplePredicate(obj => obj.FullNameContains(pattern), - "have full name containing \"" + pattern + "\""); + return new SimplePredicate( + obj => obj.FullNameContains(pattern), + "have full name containing \"" + pattern + "\"" + ); } public static IPredicate ArePrivate() @@ -1228,26 +1576,39 @@ public static IPredicate AreInternal() public static IPredicate AreProtectedInternal() { - return new SimplePredicate(obj => obj.Visibility == ProtectedInternal, "are protected internal"); + return new SimplePredicate( + obj => obj.Visibility == ProtectedInternal, + "are protected internal" + ); } public static IPredicate ArePrivateProtected() { - return new SimplePredicate(obj => obj.Visibility == PrivateProtected, "are private protected"); + return new SimplePredicate( + obj => obj.Visibility == PrivateProtected, + "are private protected" + ); } - //Negations public static IPredicate AreNot(string pattern, bool useRegularExpressions = false) { - return new SimplePredicate(obj => !obj.FullNameMatches(pattern, useRegularExpressions), - "do not have full name " + (useRegularExpressions ? "matching " : "") + "\"" + pattern + - "\""); + return new SimplePredicate( + obj => !obj.FullNameMatches(pattern, useRegularExpressions), + "do not have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static IPredicate AreNot(IEnumerable patterns, bool useRegularExpressions = false) + public static IPredicate AreNot( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); string description; @@ -1258,20 +1619,40 @@ public static IPredicate AreNot(IEnumerable patterns, bool useRegular else { var firstPattern = patternList.First(); - description = patternList.Where(pattern => !pattern.Equals(firstPattern)).Distinct().Aggregate( - "do not have full name " + (useRegularExpressions ? "matching " : "") + "\"" + - firstPattern + "\"", (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "do not have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimplePredicate( - obj => patternList.All(pattern => !obj.FullNameMatches(pattern, useRegularExpressions)), description); - } - - public static IPredicate AreNot(ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects) - { - var objects = new List {firstObject}.Concat(moreObjects).OfType(); - var description = moreObjects.Aggregate("are not \"" + firstObject.FullName + "\"", - (current, obj) => current + " or \"" + obj.FullName + "\""); + obj => + patternList.All(pattern => + !obj.FullNameMatches(pattern, useRegularExpressions) + ), + description + ); + } + + public static IPredicate AreNot( + ICanBeAnalyzed firstObject, + params ICanBeAnalyzed[] moreObjects + ) + { + var objects = new List { firstObject } + .Concat(moreObjects) + .OfType(); + var description = moreObjects.Aggregate( + "are not \"" + firstObject.FullName + "\"", + (current, obj) => current + " or \"" + obj.FullName + "\"" + ); return new EnumerablePredicate(e => e.Except(objects), description); } @@ -1286,9 +1667,13 @@ public static IPredicate AreNot(IEnumerable objects) else { var firstObject = objectList.First(); - description = objectList.Where(obj => !obj.Equals(firstObject)).Distinct().Aggregate( - "are not \"" + firstObject.FullName + "\"", - (current, obj) => current + " or \"" + obj.FullName + "\""); + description = objectList + .Where(obj => !obj.Equals(firstObject)) + .Distinct() + .Aggregate( + "are not \"" + firstObject.FullName + "\"", + (current, obj) => current + " or \"" + obj.FullName + "\"" + ); } return new EnumerablePredicate(e => e.Except(objectList.OfType()), description); @@ -1306,18 +1691,28 @@ IEnumerable Filter(IEnumerable objects, Architecture architecture) public static IPredicate DoNotCallAny(string pattern, bool useRegularExpressions = false) { - return new SimplePredicate(obj => !obj.CallsMethod(pattern, useRegularExpressions), - "do not call any methods with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + pattern + "\""); + return new SimplePredicate( + obj => !obj.CallsMethod(pattern, useRegularExpressions), + "do not call any methods with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static IPredicate DoNotCallAny(IEnumerable patterns, bool useRegularExpressions = false) + public static IPredicate DoNotCallAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Filter(T type) { - return patternList.All(pattern => !type.CallsMethod(pattern, useRegularExpressions)); + return patternList.All(pattern => + !type.CallsMethod(pattern, useRegularExpressions) + ); } string description; @@ -1328,18 +1723,28 @@ bool Filter(T type) else { var firstPattern = patternList.First(); - description = patternList.Where(pattern => !pattern.Equals(firstPattern)).Distinct().Aggregate( - "do not call any methods with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + - firstPattern + "\"", (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "do not call any methods with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimplePredicate(Filter, description); } - public static IPredicate DoNotCallAny(MethodMember method, params MethodMember[] moreMethods) + public static IPredicate DoNotCallAny( + MethodMember method, + params MethodMember[] moreMethods + ) { - var methods = new List {method}; + var methods = new List { method }; methods.AddRange(moreMethods); return DoNotCallAny(methods); } @@ -1373,29 +1778,48 @@ IEnumerable Filter(IEnumerable objects) else { var firstMethod = methodList.First(); - description = methodList.Where(obj => !obj.Equals(firstMethod)).Distinct().Aggregate( - "do not call \"" + firstMethod.FullName + "\"", - (current, obj) => current + " or \"" + obj.FullName + "\""); + description = methodList + .Where(obj => !obj.Equals(firstMethod)) + .Distinct() + .Aggregate( + "do not call \"" + firstMethod.FullName + "\"", + (current, obj) => current + " or \"" + obj.FullName + "\"" + ); } return new EnumerablePredicate(Filter, description); } - public static IPredicate DoNotDependOnAny(string pattern, bool useRegularExpressions = false) + public static IPredicate DoNotDependOnAny( + string pattern, + bool useRegularExpressions = false + ) { - return new SimplePredicate(obj => !obj.DependsOn(pattern, useRegularExpressions), - "do not depend on any types with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + pattern + "\""); + return new SimplePredicate( + obj => !obj.DependsOn(pattern, useRegularExpressions), + "do not depend on any types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static IPredicate DoNotDependOnAny(IEnumerable patterns, bool useRegularExpressions = false) + public static IPredicate DoNotDependOnAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Filter(T type) { - return type.GetTypeDependencies().All(target => - patternList.All(pattern => target.FullNameMatches(pattern, useRegularExpressions))); + return type.GetTypeDependencies() + .All(target => + patternList.All(pattern => + target.FullNameMatches(pattern, useRegularExpressions) + ) + ); } string description; @@ -1406,10 +1830,17 @@ bool Filter(T type) else { var firstPattern = patternList.First(); - description = patternList.Where(pattern => !pattern.Equals(firstPattern)).Distinct().Aggregate( - "do not depend on any types with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + - firstPattern + "\"", (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "do not depend on any types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimplePredicate(Filter, description); @@ -1417,14 +1848,14 @@ bool Filter(T type) public static IPredicate DoNotDependOnAny(IType firstType, params IType[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return DoNotDependOnAny(types); } public static IPredicate DoNotDependOnAny(Type firstType, params Type[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return DoNotDependOnAny(types); } @@ -1458,9 +1889,13 @@ IEnumerable Filter(IEnumerable objects) else { var firstType = typeList.First(); - description = typeList.Where(obj => !obj.Equals(firstType)).Distinct().Aggregate( - "do not depend on \"" + firstType.FullName + "\"", - (current, obj) => current + " or \"" + obj.FullName + "\""); + description = typeList + .Where(obj => !obj.Equals(firstType)) + .Distinct() + .Aggregate( + "do not depend on \"" + firstType.FullName + "\"", + (current, obj) => current + " or \"" + obj.FullName + "\"" + ); } return new EnumerablePredicate(Filter, description); @@ -1486,7 +1921,9 @@ IEnumerable Filter(IEnumerable objects, Architecture architecture) } } - return objects.Where(obj => !obj.GetTypeDependencies().Intersect(archUnitTypeList).Any()); + return objects.Where(obj => + !obj.GetTypeDependencies().Intersect(archUnitTypeList).Any() + ); } string description; @@ -1497,31 +1934,47 @@ IEnumerable Filter(IEnumerable objects, Architecture architecture) else { var firstType = typeList.First(); - description = typeList.Where(obj => obj != firstType).Distinct().Aggregate( - "do not depend on \"" + firstType.FullName + "\"", - (current, obj) => current + " or \"" + obj.FullName + "\""); + description = typeList + .Where(obj => obj != firstType) + .Distinct() + .Aggregate( + "do not depend on \"" + firstType.FullName + "\"", + (current, obj) => current + " or \"" + obj.FullName + "\"" + ); } return new ArchitecturePredicate(Filter, description); } - public static IPredicate DoNotHaveAnyAttributes(string pattern, bool useRegularExpressions = false) + public static IPredicate DoNotHaveAnyAttributes( + string pattern, + bool useRegularExpressions = false + ) { - return new SimplePredicate(obj => !obj.HasAttribute(pattern, useRegularExpressions), - "do not have any attribute with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + - pattern + "\""); + return new SimplePredicate( + obj => !obj.HasAttribute(pattern, useRegularExpressions), + "do not have any attribute with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static IPredicate DoNotHaveAnyAttributes(IEnumerable patterns, - bool useRegularExpressions = false) + public static IPredicate DoNotHaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Filter(T type) { return !type.Attributes.Any(attribute => - patternList.Any(pattern => attribute.FullNameMatches(pattern, useRegularExpressions))); + patternList.Any(pattern => + attribute.FullNameMatches(pattern, useRegularExpressions) + ) + ); } string description; @@ -1532,30 +1985,45 @@ bool Filter(T type) else { var firstPattern = patternList.First(); - description = patternList.Where(pattern => !pattern.Equals(firstPattern)).Distinct().Aggregate( - "do not have any attribute with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + - firstPattern + "\"", (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(pattern => !pattern.Equals(firstPattern)) + .Distinct() + .Aggregate( + "do not have any attribute with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimplePredicate(Filter, description); } - public static IPredicate DoNotHaveAnyAttributes(Attribute firstAttribute, params Attribute[] moreAttributes) + public static IPredicate DoNotHaveAnyAttributes( + Attribute firstAttribute, + params Attribute[] moreAttributes + ) { - var attributes = new List {firstAttribute}; + var attributes = new List { firstAttribute }; attributes.AddRange(moreAttributes); return DoNotHaveAnyAttributes(attributes); } - public static IPredicate DoNotHaveAnyAttributes(Type firstAttribute, params Type[] moreAttributes) + public static IPredicate DoNotHaveAnyAttributes( + Type firstAttribute, + params Type[] moreAttributes + ) { - var attributes = new List {firstAttribute}; + var attributes = new List { firstAttribute }; attributes.AddRange(moreAttributes); return DoNotHaveAnyAttributes(attributes); } - public static IPredicate DoNotHaveAnyAttributes(IObjectProvider objectProvider) + public static IPredicate DoNotHaveAnyAttributes( + IObjectProvider objectProvider + ) { IEnumerable Filter(IEnumerable objects, Architecture architecture) { @@ -1584,9 +2052,13 @@ IEnumerable Filter(IEnumerable objects) else { var firstAttribute = attributeList.First(); - description = attributeList.Where(obj => !obj.Equals(firstAttribute)).Distinct().Aggregate( - "do not have attribute \"" + firstAttribute.FullName + "\"", - (current, attribute) => current + " or \"" + attribute.FullName + "\""); + description = attributeList + .Where(obj => !obj.Equals(firstAttribute)) + .Distinct() + .Aggregate( + "do not have attribute \"" + firstAttribute.FullName + "\"", + (current, attribute) => current + " or \"" + attribute.FullName + "\"" + ); } return new EnumerablePredicate(Filter, description); @@ -1623,83 +2095,109 @@ IEnumerable Filter(IEnumerable objects, Architecture architecture) else { var firstType = attributeList.First(); - description = attributeList.Where(obj => obj != firstType).Distinct().Aggregate( - "do not have attribute \"" + firstType.FullName + "\"", - (current, obj) => current + " or \"" + obj.FullName + "\""); + description = attributeList + .Where(obj => obj != firstType) + .Distinct() + .Aggregate( + "do not have attribute \"" + firstType.FullName + "\"", + (current, obj) => current + " or \"" + obj.FullName + "\"" + ); } return new ArchitecturePredicate(Filter, description); } - public static IPredicate DoNotHaveAnyAttributesWithArguments(object firstArgumentValue, - params object[] moreArgumentValues) + public static IPredicate DoNotHaveAnyAttributesWithArguments( + object firstArgumentValue, + params object[] moreArgumentValues + ) { - var argumentValues = new List {firstArgumentValue}; + var argumentValues = new List { firstArgumentValue }; argumentValues.AddRange(moreArgumentValues); return DoNotHaveAnyAttributesWithArguments(argumentValues); } - public static IPredicate DoNotHaveAttributeWithArguments(string attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public static IPredicate DoNotHaveAttributeWithArguments( + string attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { - var argumentValues = new List {firstArgumentValue}; + var argumentValues = new List { firstArgumentValue }; argumentValues.AddRange(moreArgumentValues); return DoNotHaveAttributeWithArguments(attribute, argumentValues); } - public static IPredicate DoNotHaveAttributeWithArguments(Attribute attribute, + public static IPredicate DoNotHaveAttributeWithArguments( + Attribute attribute, object firstArgumentValue, - params object[] moreArgumentValues) + params object[] moreArgumentValues + ) { - var argumentValues = new List {firstArgumentValue}; + var argumentValues = new List { firstArgumentValue }; argumentValues.AddRange(moreArgumentValues); return DoNotHaveAttributeWithArguments(attribute, argumentValues); } - public static IPredicate DoNotHaveAttributeWithArguments(Type attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public static IPredicate DoNotHaveAttributeWithArguments( + Type attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { - var argumentValues = new List {firstArgumentValue}; + var argumentValues = new List { firstArgumentValue }; argumentValues.AddRange(moreArgumentValues); return DoNotHaveAttributeWithArguments(attribute, argumentValues); } public static IPredicate DoNotHaveAnyAttributesWithNamedArguments( (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments) + params (string, object)[] moreAttributeArguments + ) { - var attributeArguments = new List<(string, object)> {firstAttributeArgument}; + var attributeArguments = new List<(string, object)> { firstAttributeArgument }; attributeArguments.AddRange(moreAttributeArguments); return DoNotHaveAnyAttributesWithNamedArguments(attributeArguments); } - public static IPredicate DoNotHaveAttributeWithNamedArguments(string attribute, - (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments) + public static IPredicate DoNotHaveAttributeWithNamedArguments( + string attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { - var attributeArguments = new List<(string, object)> {firstAttributeArgument}; + var attributeArguments = new List<(string, object)> { firstAttributeArgument }; attributeArguments.AddRange(moreAttributeArguments); return DoNotHaveAttributeWithNamedArguments(attribute, attributeArguments); } - public static IPredicate DoNotHaveAttributeWithNamedArguments(Attribute attribute, - (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments) + public static IPredicate DoNotHaveAttributeWithNamedArguments( + Attribute attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { - var attributeArguments = new List<(string, object)> {firstAttributeArgument}; + var attributeArguments = new List<(string, object)> { firstAttributeArgument }; attributeArguments.AddRange(moreAttributeArguments); return DoNotHaveAttributeWithNamedArguments(attribute, attributeArguments); } - public static IPredicate DoNotHaveAttributeWithNamedArguments(Type attribute, - (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments) + public static IPredicate DoNotHaveAttributeWithNamedArguments( + Type attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { - var attributeArguments = new List<(string, object)> {firstAttributeArgument}; + var attributeArguments = new List<(string, object)> { firstAttributeArgument }; attributeArguments.AddRange(moreAttributeArguments); return DoNotHaveAttributeWithNamedArguments(attribute, attributeArguments); } - public static IPredicate DoNotHaveAnyAttributesWithArguments(IEnumerable argumentValues) + public static IPredicate DoNotHaveAnyAttributesWithArguments( + IEnumerable argumentValues + ) { - var argumentValueList = argumentValues?.ToList() ?? new List {null}; + var argumentValueList = argumentValues?.ToList() ?? new List { null }; string description; if (argumentValueList.IsNullOrEmpty()) { @@ -1708,17 +2206,26 @@ public static IPredicate DoNotHaveAnyAttributesWithArguments(IEnumerable attribute != firstArgument).Aggregate( - "do not have any attributes with arguments \"" + firstArgument + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\""); + description = argumentValueList + .Where(attribute => attribute != firstArgument) + .Aggregate( + "do not have any attributes with arguments \"" + firstArgument + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); } bool Predicate(T obj, Architecture architecture) { - var attributeArguments = obj.AttributeInstances - .SelectMany(instance => instance.AttributeArguments.Select(arg => arg.Value)).ToList(); - var typeAttributeArguments = attributeArguments.OfType>().Select(t => t.Type) - .Union(attributeArguments.OfType()).ToList(); + var attributeArguments = obj + .AttributeInstances.SelectMany(instance => + instance.AttributeArguments.Select(arg => arg.Value) + ) + .ToList(); + var typeAttributeArguments = attributeArguments + .OfType>() + .Select(t => t.Type) + .Union(attributeArguments.OfType()) + .ToList(); foreach (var arg in argumentValueList) { if (arg is Type argType) @@ -1740,11 +2247,13 @@ bool Predicate(T obj, Architecture architecture) return new ArchitecturePredicate(Predicate, description); } - public static IPredicate DoNotHaveAttributeWithArguments([NotNull] string attribute, - IEnumerable argumentValues) + public static IPredicate DoNotHaveAttributeWithArguments( + [NotNull] string attribute, + IEnumerable argumentValues + ) { string description; - var argumentValueList = argumentValues?.ToList() ?? new List {null}; + var argumentValueList = argumentValues?.ToList() ?? new List { null }; if (argumentValueList.IsNullOrEmpty()) { description = "do not have attribute \"" + attribute + "\""; @@ -1752,9 +2261,16 @@ public static IPredicate DoNotHaveAttributeWithArguments([NotNull] string att else { var firstArgument = argumentValueList.First(); - description = argumentValueList.Where(att => att != firstArgument).Aggregate( - "do not have attribute \"" + attribute + "\" with arguments \"" + firstArgument + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\""); + description = argumentValueList + .Where(att => att != firstArgument) + .Aggregate( + "do not have attribute \"" + + attribute + + "\" with arguments \"" + + firstArgument + + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); } bool Predicate(T obj, Architecture architecture) @@ -1766,9 +2282,14 @@ bool Predicate(T obj, Architecture architecture) goto NextAttribute; } - var attributeArguments = attributeInstance.AttributeArguments.Select(arg => arg.Value).ToList(); - var typeAttributeArguments = attributeArguments.OfType>().Select(t => t.Type) - .Union(attributeArguments.OfType()).ToList(); + var attributeArguments = attributeInstance + .AttributeArguments.Select(arg => arg.Value) + .ToList(); + var typeAttributeArguments = attributeArguments + .OfType>() + .Select(t => t.Type) + .Union(attributeArguments.OfType()) + .ToList(); foreach (var arg in argumentValueList) { if (arg is Type argType) @@ -1785,7 +2306,8 @@ bool Predicate(T obj, Architecture architecture) } return false; - NextAttribute: ; + NextAttribute: + ; } return true; @@ -1794,11 +2316,13 @@ bool Predicate(T obj, Architecture architecture) return new ArchitecturePredicate(Predicate, description); } - public static IPredicate DoNotHaveAttributeWithArguments([NotNull] Attribute attribute, - IEnumerable argumentValues) + public static IPredicate DoNotHaveAttributeWithArguments( + [NotNull] Attribute attribute, + IEnumerable argumentValues + ) { string description; - var argumentValueList = argumentValues?.ToList() ?? new List {null}; + var argumentValueList = argumentValues?.ToList() ?? new List { null }; if (argumentValueList.IsNullOrEmpty()) { description = "do not have attribute \"" + attribute.FullName + "\""; @@ -1806,9 +2330,16 @@ public static IPredicate DoNotHaveAttributeWithArguments([NotNull] Attribute else { var firstArgument = argumentValueList.First(); - description = argumentValueList.Where(att => att != firstArgument).Aggregate( - "do not have attribute \"" + attribute.FullName + "\" with arguments \"" + firstArgument + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\""); + description = argumentValueList + .Where(att => att != firstArgument) + .Aggregate( + "do not have attribute \"" + + attribute.FullName + + "\" with arguments \"" + + firstArgument + + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); } bool Predicate(T obj, Architecture architecture) @@ -1820,9 +2351,14 @@ bool Predicate(T obj, Architecture architecture) goto NextAttribute; } - var attributeArguments = attributeInstance.AttributeArguments.Select(arg => arg.Value).ToList(); - var typeAttributeArguments = attributeArguments.OfType>().Select(t => t.Type) - .Union(attributeArguments.OfType()).ToList(); + var attributeArguments = attributeInstance + .AttributeArguments.Select(arg => arg.Value) + .ToList(); + var typeAttributeArguments = attributeArguments + .OfType>() + .Select(t => t.Type) + .Union(attributeArguments.OfType()) + .ToList(); foreach (var arg in argumentValueList) { if (arg is Type argType) @@ -1839,7 +2375,8 @@ bool Predicate(T obj, Architecture architecture) } return false; - NextAttribute: ; + NextAttribute: + ; } return true; @@ -1848,11 +2385,13 @@ bool Predicate(T obj, Architecture architecture) return new ArchitecturePredicate(Predicate, description); } - public static IPredicate DoNotHaveAttributeWithArguments([NotNull] Type attribute, - IEnumerable argumentValues) + public static IPredicate DoNotHaveAttributeWithArguments( + [NotNull] Type attribute, + IEnumerable argumentValues + ) { string description; - var argumentValueList = argumentValues?.ToList() ?? new List {null}; + var argumentValueList = argumentValues?.ToList() ?? new List { null }; if (argumentValueList.IsNullOrEmpty()) { description = "do not have attribute \"" + attribute.FullName + "\""; @@ -1860,9 +2399,16 @@ public static IPredicate DoNotHaveAttributeWithArguments([NotNull] Type attri else { var firstArgument = argumentValueList.First(); - description = argumentValueList.Where(att => att != firstArgument).Aggregate( - "do not have attribute \"" + attribute.FullName + "\" with arguments \"" + firstArgument + "\"", - (current, argumentValue) => current + " and \"" + argumentValue + "\""); + description = argumentValueList + .Where(att => att != firstArgument) + .Aggregate( + "do not have attribute \"" + + attribute.FullName + + "\" with arguments \"" + + firstArgument + + "\"", + (current, argumentValue) => current + " and \"" + argumentValue + "\"" + ); } bool Predicate(T obj, Architecture architecture) @@ -1885,9 +2431,14 @@ bool Predicate(T obj, Architecture architecture) goto NextAttribute; } - var attributeArguments = attributeInstance.AttributeArguments.Select(arg => arg.Value).ToList(); - var typeAttributeArguments = attributeArguments.OfType>().Select(t => t.Type) - .Union(attributeArguments.OfType()).ToList(); + var attributeArguments = attributeInstance + .AttributeArguments.Select(arg => arg.Value) + .ToList(); + var typeAttributeArguments = attributeArguments + .OfType>() + .Select(t => t.Type) + .Union(attributeArguments.OfType()) + .ToList(); foreach (var arg in argumentValueList) { if (arg is Type argType) @@ -1904,7 +2455,8 @@ bool Predicate(T obj, Architecture architecture) } return false; - NextAttribute: ; + NextAttribute: + ; } return true; @@ -1914,7 +2466,8 @@ bool Predicate(T obj, Architecture architecture) } public static IPredicate DoNotHaveAnyAttributesWithNamedArguments( - IEnumerable<(string, object)> attributeArguments) + IEnumerable<(string, object)> attributeArguments + ) { var argumentList = attributeArguments.ToList(); string description; @@ -1925,31 +2478,44 @@ public static IPredicate DoNotHaveAnyAttributesWithNamedArguments( else { var firstArgument = argumentList.First(); - description = argumentList.Where(attribute => attribute != firstArgument).Aggregate( - "do not have any attributes with named arguments \"" + firstArgument.Item1 + "=" + - firstArgument.Item2 + - "\"", - (current, arg) => - current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\""); + description = argumentList + .Where(attribute => attribute != firstArgument) + .Aggregate( + "do not have any attributes with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); } bool Condition(T obj, Architecture architecture) { - var attArguments = obj.AttributeInstances.SelectMany(instance => - instance.AttributeArguments.OfType() - .Select(arg => (arg.Name, arg.Value))) + var attArguments = obj + .AttributeInstances.SelectMany(instance => + instance + .AttributeArguments.OfType() + .Select(arg => (arg.Name, arg.Value)) + ) .ToList(); var typeAttributeArguments = attArguments - .Where(arg => arg.Value is ITypeInstance || arg.Value is IType).ToList(); + .Where(arg => arg.Value is ITypeInstance || arg.Value is IType) + .ToList(); foreach (var arg in argumentList) { if (arg.Item2 is Type argType) { - if (typeAttributeArguments.Any(t => - t.Name == arg.Item1 && - (t.Value is ITypeInstance typeInstance && - typeInstance.Type.FullName == argType.FullName || - t.Value is IType type && type.FullName == argType.FullName))) + if ( + typeAttributeArguments.Any(t => + t.Name == arg.Item1 + && ( + t.Value is ITypeInstance typeInstance + && typeInstance.Type.FullName == argType.FullName + || t.Value is IType type && type.FullName == argType.FullName + ) + ) + ) { return false; } @@ -1966,8 +2532,10 @@ bool Condition(T obj, Architecture architecture) return new ArchitecturePredicate(Condition, description); } - public static IPredicate DoNotHaveAttributeWithNamedArguments([NotNull] string attribute, - IEnumerable<(string, object)> attributeArguments) + public static IPredicate DoNotHaveAttributeWithNamedArguments( + [NotNull] string attribute, + IEnumerable<(string, object)> attributeArguments + ) { string description; var argumentList = attributeArguments.ToList(); @@ -1978,10 +2546,18 @@ public static IPredicate DoNotHaveAttributeWithNamedArguments([NotNull] strin else { var firstArgument = argumentList.First(); - description = argumentList.Where(att => att != firstArgument).Aggregate( - "do not have attribute \"" + attribute + "\" with named arguments \"" + firstArgument.Item1 + - "=" + firstArgument.Item2 + "\"", - (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\""); + description = argumentList + .Where(att => att != firstArgument) + .Aggregate( + "do not have attribute \"" + + attribute + + "\" with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); } bool Predicate(T obj, Architecture architecture) @@ -1993,19 +2569,25 @@ bool Predicate(T obj, Architecture architecture) goto NextAttribute; } - var attributeArgs = attributeInstance.AttributeArguments.OfType() - .Select(arg => (arg.Name, arg.Value)).ToList(); + var attributeArgs = attributeInstance + .AttributeArguments.OfType() + .Select(arg => (arg.Name, arg.Value)) + .ToList(); var typeAttributeArguments = attributeArgs - .Where(arg => arg.Value is ITypeInstance || arg.Value is IType).ToList(); + .Where(arg => arg.Value is ITypeInstance || arg.Value is IType) + .ToList(); foreach (var arg in argumentList) { if (arg.Item2 is Type argType) { - if (typeAttributeArguments.All(t => t.Name != arg.Item1 || - t.Value is ITypeInstance typeInstance && - typeInstance.Type.FullName != argType.FullName || - t.Value is IType type && - type.FullName != argType.FullName)) + if ( + typeAttributeArguments.All(t => + t.Name != arg.Item1 + || t.Value is ITypeInstance typeInstance + && typeInstance.Type.FullName != argType.FullName + || t.Value is IType type && type.FullName != argType.FullName + ) + ) { goto NextAttribute; } @@ -2017,7 +2599,8 @@ t.Value is IType type && } return false; - NextAttribute: ; + NextAttribute: + ; } return true; @@ -2026,8 +2609,10 @@ t.Value is IType type && return new ArchitecturePredicate(Predicate, description); } - public static IPredicate DoNotHaveAttributeWithNamedArguments([NotNull] Attribute attribute, - IEnumerable<(string, object)> attributeArguments) + public static IPredicate DoNotHaveAttributeWithNamedArguments( + [NotNull] Attribute attribute, + IEnumerable<(string, object)> attributeArguments + ) { string description; var argumentList = attributeArguments.ToList(); @@ -2038,11 +2623,18 @@ public static IPredicate DoNotHaveAttributeWithNamedArguments([NotNull] Attri else { var firstArgument = argumentList.First(); - description = argumentList.Where(att => att != firstArgument).Aggregate( - "do not have attribute \"" + attribute.FullName + "\" with named arguments \"" + - firstArgument.Item1 + - "=" + firstArgument.Item2 + "\"", - (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\""); + description = argumentList + .Where(att => att != firstArgument) + .Aggregate( + "do not have attribute \"" + + attribute.FullName + + "\" with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); } bool Predicate(T obj, Architecture architecture) @@ -2054,19 +2646,25 @@ bool Predicate(T obj, Architecture architecture) goto NextAttribute; } - var attributeArgs = attributeInstance.AttributeArguments.OfType() - .Select(arg => (arg.Name, arg.Value)).ToList(); + var attributeArgs = attributeInstance + .AttributeArguments.OfType() + .Select(arg => (arg.Name, arg.Value)) + .ToList(); var typeAttributeArguments = attributeArgs - .Where(arg => arg.Value is ITypeInstance || arg.Value is IType).ToList(); + .Where(arg => arg.Value is ITypeInstance || arg.Value is IType) + .ToList(); foreach (var arg in argumentList) { if (arg.Item2 is Type argType) { - if (typeAttributeArguments.All(t => t.Name != arg.Item1 || - t.Value is ITypeInstance typeInstance && - typeInstance.Type.FullName != argType.FullName || - t.Value is IType type && - type.FullName != argType.FullName)) + if ( + typeAttributeArguments.All(t => + t.Name != arg.Item1 + || t.Value is ITypeInstance typeInstance + && typeInstance.Type.FullName != argType.FullName + || t.Value is IType type && type.FullName != argType.FullName + ) + ) { goto NextAttribute; } @@ -2078,7 +2676,8 @@ t.Value is IType type && } return false; - NextAttribute: ; + NextAttribute: + ; } return true; @@ -2087,8 +2686,10 @@ t.Value is IType type && return new ArchitecturePredicate(Predicate, description); } - public static IPredicate DoNotHaveAttributeWithNamedArguments([NotNull] Type attribute, - IEnumerable<(string, object)> attributeArguments) + public static IPredicate DoNotHaveAttributeWithNamedArguments( + [NotNull] Type attribute, + IEnumerable<(string, object)> attributeArguments + ) { string description; var argumentList = attributeArguments.ToList(); @@ -2099,11 +2700,18 @@ public static IPredicate DoNotHaveAttributeWithNamedArguments([NotNull] Type else { var firstArgument = argumentList.First(); - description = argumentList.Where(att => att != firstArgument).Aggregate( - "do not have attribute \"" + attribute.FullName + "\" with named arguments \"" + - firstArgument.Item1 + - "=" + firstArgument.Item2 + "\"", - (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\""); + description = argumentList + .Where(att => att != firstArgument) + .Aggregate( + "do not have attribute \"" + + attribute.FullName + + "\" with named arguments \"" + + firstArgument.Item1 + + "=" + + firstArgument.Item2 + + "\"", + (current, arg) => current + " and \"" + arg.Item1 + "=" + arg.Item2 + "\"" + ); } bool Predicate(T obj, Architecture architecture) @@ -2126,19 +2734,25 @@ bool Predicate(T obj, Architecture architecture) goto NextAttribute; } - var attributeArgs = attributeInstance.AttributeArguments.OfType() - .Select(arg => (arg.Name, arg.Value)).ToList(); + var attributeArgs = attributeInstance + .AttributeArguments.OfType() + .Select(arg => (arg.Name, arg.Value)) + .ToList(); var typeAttributeArguments = attributeArgs - .Where(arg => arg.Value is ITypeInstance || arg.Value is IType).ToList(); + .Where(arg => arg.Value is ITypeInstance || arg.Value is IType) + .ToList(); foreach (var arg in argumentList) { if (arg.Item2 is Type argType) { - if (typeAttributeArguments.All(t => t.Name != arg.Item1 || - t.Value is ITypeInstance typeInstance && - typeInstance.Type.FullName != argType.FullName || - t.Value is IType type && - type.FullName != argType.FullName)) + if ( + typeAttributeArguments.All(t => + t.Name != arg.Item1 + || t.Value is ITypeInstance typeInstance + && typeInstance.Type.FullName != argType.FullName + || t.Value is IType type && type.FullName != argType.FullName + ) + ) { goto NextAttribute; } @@ -2150,7 +2764,8 @@ t.Value is IType type && } return false; - NextAttribute: ; + NextAttribute: + ; } return true; @@ -2159,40 +2774,66 @@ t.Value is IType type && return new ArchitecturePredicate(Predicate, description); } - public static IPredicate DoNotHaveName(string pattern, bool useRegularExpressions = false) + public static IPredicate DoNotHaveName( + string pattern, + bool useRegularExpressions = false + ) { - return new SimplePredicate(obj => !obj.NameMatches(pattern, useRegularExpressions), - "do not have name " + (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\""); + return new SimplePredicate( + obj => !obj.NameMatches(pattern, useRegularExpressions), + "do not have name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static IPredicate DoNotHaveFullName(string pattern, bool useRegularExpressions = false) + public static IPredicate DoNotHaveFullName( + string pattern, + bool useRegularExpressions = false + ) { - return new SimplePredicate(obj => !obj.FullNameMatches(pattern, useRegularExpressions), - "do not have full name " + (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\""); + return new SimplePredicate( + obj => !obj.FullNameMatches(pattern, useRegularExpressions), + "do not have full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } public static IPredicate DoNotHaveNameStartingWith(string pattern) { - return new SimplePredicate(obj => !obj.NameStartsWith(pattern), - "do not have name starting with \"" + pattern + "\""); + return new SimplePredicate( + obj => !obj.NameStartsWith(pattern), + "do not have name starting with \"" + pattern + "\"" + ); } public static IPredicate DoNotHaveNameEndingWith(string pattern) { - return new SimplePredicate(obj => !obj.NameEndsWith(pattern), - "do not have name ending with \"" + pattern + "\""); + return new SimplePredicate( + obj => !obj.NameEndsWith(pattern), + "do not have name ending with \"" + pattern + "\"" + ); } public static IPredicate DoNotHaveNameContaining(string pattern) { - return new SimplePredicate(obj => !obj.NameContains(pattern), - "do not have name containing \"" + pattern + "\""); + return new SimplePredicate( + obj => !obj.NameContains(pattern), + "do not have name containing \"" + pattern + "\"" + ); } public static IPredicate DoNotHaveFullNameContaining(string pattern) { - return new SimplePredicate(obj => !obj.FullNameContains(pattern), - "do not have full name containing \"" + pattern + "\""); + return new SimplePredicate( + obj => !obj.FullNameContains(pattern), + "do not have full name containing \"" + pattern + "\"" + ); } public static IPredicate AreNotPrivate() @@ -2217,12 +2858,18 @@ public static IPredicate AreNotInternal() public static IPredicate AreNotProtectedInternal() { - return new SimplePredicate(obj => obj.Visibility != ProtectedInternal, "are not protected internal"); + return new SimplePredicate( + obj => obj.Visibility != ProtectedInternal, + "are not protected internal" + ); } public static IPredicate AreNotPrivateProtected() { - return new SimplePredicate(obj => obj.Visibility != PrivateProtected, "are not private protected"); + return new SimplePredicate( + obj => obj.Visibility != PrivateProtected, + "are not private protected" + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShould.cs b/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShould.cs index 99d50935e..c90b142f9 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShould.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShould.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -10,20 +10,20 @@ using ArchUnitNET.Fluent.Conditions; using ArchUnitNET.Fluent.Syntax.Elements.Types; using ArchUnitNET.Fluent.Syntax.Elements.Types.Attributes; -using static ArchUnitNET.Fluent.Syntax.ConjunctionFactory; using static ArchUnitNET.Fluent.ArchRuleDefinition; +using static ArchUnitNET.Fluent.Syntax.ConjunctionFactory; using Attribute = ArchUnitNET.Domain.Attribute; namespace ArchUnitNET.Fluent.Syntax.Elements { - public abstract class ObjectsShould : SyntaxElement, - IComplexObjectConditions + public abstract class ObjectsShould + : SyntaxElement, + IComplexObjectConditions where TRuleType : ICanBeAnalyzed where TRuleTypeShouldConjunction : SyntaxElement { - protected ObjectsShould(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + protected ObjectsShould(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } public TRuleTypeShouldConjunction Exist() { @@ -35,20 +35,30 @@ public TRuleTypeShouldConjunction Exist() public TRuleTypeShouldConjunction Be(string pattern, bool useRegularExpressions = false) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.Be(pattern, useRegularExpressions)); + ObjectConditionsDefinition.Be(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction Be(IEnumerable patterns, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction Be( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.Be(patterns, useRegularExpressions)); + ObjectConditionsDefinition.Be(patterns, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction Be(ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects) + public TRuleTypeShouldConjunction Be( + ICanBeAnalyzed firstObject, + params ICanBeAnalyzed[] moreObjects + ) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.Be(firstObject, moreObjects)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.Be(firstObject, moreObjects) + ); return Create(_ruleCreator); } @@ -64,24 +74,36 @@ public TRuleTypeShouldConjunction Be(IObjectProvider objects) return Create(_ruleCreator); } - public TRuleTypeShouldConjunction CallAny(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction CallAny( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.CallAny(pattern, useRegularExpressions)); + ObjectConditionsDefinition.CallAny(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction CallAny(IEnumerable patterns, - bool useRegularExpressions = false) + public TRuleTypeShouldConjunction CallAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.CallAny(patterns, useRegularExpressions)); + ObjectConditionsDefinition.CallAny(patterns, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction CallAny(MethodMember method, params MethodMember[] moreMethods) + public TRuleTypeShouldConjunction CallAny( + MethodMember method, + params MethodMember[] moreMethods + ) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.CallAny(method, moreMethods)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.CallAny(method, moreMethods) + ); return Create(_ruleCreator); } @@ -97,29 +119,41 @@ public TRuleTypeShouldConjunction CallAny(IObjectProvider methods) return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DependOnAny(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction DependOnAny( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.DependOnAny(pattern, useRegularExpressions)); + ObjectConditionsDefinition.DependOnAny(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DependOnAny(IEnumerable patterns, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction DependOnAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.DependOnAny(patterns, useRegularExpressions)); + ObjectConditionsDefinition.DependOnAny(patterns, useRegularExpressions) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DependOnAny(IType firstType, params IType[] moreTypes) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.DependOnAny(firstType, moreTypes)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.DependOnAny(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DependOnAny(Type firstType, params Type[] moreTypes) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.DependOnAny(firstType, moreTypes)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.DependOnAny(firstType, moreTypes) + ); return Create(_ruleCreator); } @@ -147,45 +181,68 @@ public TRuleTypeShouldConjunction FollowCustomCondition(ICondition co return Create(_ruleCreator); } - public TRuleTypeShouldConjunction FollowCustomCondition(Func condition, - string description) + public TRuleTypeShouldConjunction FollowCustomCondition( + Func condition, + string description + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.FollowCustomCondition(condition, description)); + ObjectConditionsDefinition.FollowCustomCondition(condition, description) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction FollowCustomCondition(Func condition, string description, - string failDescription) + public TRuleTypeShouldConjunction FollowCustomCondition( + Func condition, + string description, + string failDescription + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.FollowCustomCondition(condition, description, failDescription)); + ObjectConditionsDefinition.FollowCustomCondition( + condition, + description, + failDescription + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction OnlyDependOn(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction OnlyDependOn( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.OnlyDependOn(pattern, useRegularExpressions)); + ObjectConditionsDefinition.OnlyDependOn(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction OnlyDependOn(IEnumerable patterns, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction OnlyDependOn( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.OnlyDependOn(patterns, useRegularExpressions)); + ObjectConditionsDefinition.OnlyDependOn(patterns, useRegularExpressions) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction OnlyDependOn(IType firstType, params IType[] moreTypes) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.OnlyDependOn(firstType, moreTypes)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.OnlyDependOn(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction OnlyDependOn(Type firstType, params Type[] moreTypes) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.OnlyDependOn(firstType, moreTypes)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.OnlyDependOn(firstType, moreTypes) + ); return Create(_ruleCreator); } @@ -207,271 +264,447 @@ public TRuleTypeShouldConjunction OnlyDependOn(IEnumerable types) return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAnyAttributes(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction HaveAnyAttributes( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveAnyAttributes(pattern, useRegularExpressions)); + ObjectConditionsDefinition.HaveAnyAttributes( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAnyAttributes(IEnumerable patterns, - bool useRegularExpressions = false) + public TRuleTypeShouldConjunction HaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveAnyAttributes(patterns, useRegularExpressions)); + ObjectConditionsDefinition.HaveAnyAttributes( + patterns, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAnyAttributes(Attribute firstAttribute, params Attribute[] moreAttributes) + public TRuleTypeShouldConjunction HaveAnyAttributes( + Attribute firstAttribute, + params Attribute[] moreAttributes + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveAnyAttributes(firstAttribute, moreAttributes)); + ObjectConditionsDefinition.HaveAnyAttributes( + firstAttribute, + moreAttributes + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAnyAttributes(Type firstAttribute, params Type[] moreAttributes) + public TRuleTypeShouldConjunction HaveAnyAttributes( + Type firstAttribute, + params Type[] moreAttributes + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveAnyAttributes(firstAttribute, moreAttributes)); + ObjectConditionsDefinition.HaveAnyAttributes( + firstAttribute, + moreAttributes + ) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveAnyAttributes(IObjectProvider attributes) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.HaveAnyAttributes(attributes)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.HaveAnyAttributes(attributes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveAnyAttributes(IEnumerable attributes) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.HaveAnyAttributes(attributes)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.HaveAnyAttributes(attributes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveAnyAttributes(IEnumerable attributes) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.HaveAnyAttributes(attributes)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.HaveAnyAttributes(attributes) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction OnlyHaveAttributes(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction OnlyHaveAttributes( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.OnlyHaveAttributes(pattern, useRegularExpressions)); + ObjectConditionsDefinition.OnlyHaveAttributes( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction OnlyHaveAttributes(IEnumerable patterns, - bool useRegularExpressions = false) + public TRuleTypeShouldConjunction OnlyHaveAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.OnlyHaveAttributes(patterns, useRegularExpressions)); + ObjectConditionsDefinition.OnlyHaveAttributes( + patterns, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction OnlyHaveAttributes(Attribute firstAttribute, - params Attribute[] moreAttributes) + public TRuleTypeShouldConjunction OnlyHaveAttributes( + Attribute firstAttribute, + params Attribute[] moreAttributes + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.OnlyHaveAttributes(firstAttribute, moreAttributes)); + ObjectConditionsDefinition.OnlyHaveAttributes( + firstAttribute, + moreAttributes + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction OnlyHaveAttributes(Type firstAttribute, params Type[] moreAttributes) + public TRuleTypeShouldConjunction OnlyHaveAttributes( + Type firstAttribute, + params Type[] moreAttributes + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.OnlyHaveAttributes(firstAttribute, moreAttributes)); + ObjectConditionsDefinition.OnlyHaveAttributes( + firstAttribute, + moreAttributes + ) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction OnlyHaveAttributes(IObjectProvider attributes) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.OnlyHaveAttributes(attributes)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.OnlyHaveAttributes(attributes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction OnlyHaveAttributes(IEnumerable attributes) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.OnlyHaveAttributes(attributes)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.OnlyHaveAttributes(attributes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction OnlyHaveAttributes(IEnumerable attributes) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.OnlyHaveAttributes(attributes)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.OnlyHaveAttributes(attributes) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAnyAttributesWithArguments(IEnumerable argumentValues) + public TRuleTypeShouldConjunction HaveAnyAttributesWithArguments( + IEnumerable argumentValues + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveAnyAttributesWithArguments(argumentValues)); + ObjectConditionsDefinition.HaveAnyAttributesWithArguments(argumentValues) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction - HaveAnyAttributesWithArguments(object firstArgumentValue, params object[] moreArgumentValues) + public TRuleTypeShouldConjunction HaveAnyAttributesWithArguments( + object firstArgumentValue, + params object[] moreArgumentValues + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveAnyAttributesWithArguments(firstArgumentValue, - moreArgumentValues)); + ObjectConditionsDefinition.HaveAnyAttributesWithArguments( + firstArgumentValue, + moreArgumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAttributeWithArguments(string attribute, - IEnumerable argumentValues) + public TRuleTypeShouldConjunction HaveAttributeWithArguments( + string attribute, + IEnumerable argumentValues + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveAttributeWithArguments(attribute, argumentValues)); + ObjectConditionsDefinition.HaveAttributeWithArguments( + attribute, + argumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAttributeWithArguments(string attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public TRuleTypeShouldConjunction HaveAttributeWithArguments( + string attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveAttributeWithArguments(attribute, firstArgumentValue, - moreArgumentValues)); + ObjectConditionsDefinition.HaveAttributeWithArguments( + attribute, + firstArgumentValue, + moreArgumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAttributeWithArguments(Attribute attribute, - IEnumerable argumentValues) + public TRuleTypeShouldConjunction HaveAttributeWithArguments( + Attribute attribute, + IEnumerable argumentValues + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveAttributeWithArguments(attribute, argumentValues)); + ObjectConditionsDefinition.HaveAttributeWithArguments( + attribute, + argumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAttributeWithArguments(Attribute attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public TRuleTypeShouldConjunction HaveAttributeWithArguments( + Attribute attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveAttributeWithArguments(attribute, firstArgumentValue, - moreArgumentValues)); + ObjectConditionsDefinition.HaveAttributeWithArguments( + attribute, + firstArgumentValue, + moreArgumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAttributeWithArguments(Type attribute, IEnumerable argumentValues) + public TRuleTypeShouldConjunction HaveAttributeWithArguments( + Type attribute, + IEnumerable argumentValues + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveAttributeWithArguments(attribute, argumentValues)); + ObjectConditionsDefinition.HaveAttributeWithArguments( + attribute, + argumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAttributeWithArguments(Type attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public TRuleTypeShouldConjunction HaveAttributeWithArguments( + Type attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveAttributeWithArguments(attribute, firstArgumentValue, - moreArgumentValues)); + ObjectConditionsDefinition.HaveAttributeWithArguments( + attribute, + firstArgumentValue, + moreArgumentValues + ) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveAnyAttributesWithNamedArguments( - IEnumerable<(string, object)> attributeArguments) + IEnumerable<(string, object)> attributeArguments + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveAnyAttributesWithNamedArguments(attributeArguments)); + ObjectConditionsDefinition.HaveAnyAttributesWithNamedArguments( + attributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAnyAttributesWithNamedArguments((string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments) + public TRuleTypeShouldConjunction HaveAnyAttributesWithNamedArguments( + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveAnyAttributesWithNamedArguments(firstAttributeArgument, - moreAttributeArguments)); + ObjectConditionsDefinition.HaveAnyAttributesWithNamedArguments( + firstAttributeArgument, + moreAttributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments(string attribute, - IEnumerable<(string, object)> attributeArguments) + public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( + string attribute, + IEnumerable<(string, object)> attributeArguments + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveAttributeWithNamedArguments(attribute, attributeArguments)); + ObjectConditionsDefinition.HaveAttributeWithNamedArguments( + attribute, + attributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments(string attribute, + public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( + string attribute, (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments) + params (string, object)[] moreAttributeArguments + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveAttributeWithNamedArguments(attribute, firstAttributeArgument, - moreAttributeArguments)); + ObjectConditionsDefinition.HaveAttributeWithNamedArguments( + attribute, + firstAttributeArgument, + moreAttributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments(Attribute attribute, - IEnumerable<(string, object)> attributeArguments) + public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( + Attribute attribute, + IEnumerable<(string, object)> attributeArguments + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveAttributeWithNamedArguments(attribute, attributeArguments)); + ObjectConditionsDefinition.HaveAttributeWithNamedArguments( + attribute, + attributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments(Attribute attribute, + public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( + Attribute attribute, (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments) + params (string, object)[] moreAttributeArguments + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveAttributeWithNamedArguments(attribute, firstAttributeArgument, - moreAttributeArguments)); + ObjectConditionsDefinition.HaveAttributeWithNamedArguments( + attribute, + firstAttributeArgument, + moreAttributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments(Type attribute, - IEnumerable<(string, object)> attributeArguments) + public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( + Type attribute, + IEnumerable<(string, object)> attributeArguments + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveAttributeWithNamedArguments(attribute, attributeArguments)); + ObjectConditionsDefinition.HaveAttributeWithNamedArguments( + attribute, + attributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments(Type attribute, + public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( + Type attribute, (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments) + params (string, object)[] moreAttributeArguments + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.HaveAttributeWithNamedArguments(attribute, firstAttributeArgument, - moreAttributeArguments)); + ObjectConditionsDefinition.HaveAttributeWithNamedArguments( + attribute, + firstAttributeArgument, + moreAttributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveName(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction HaveName( + string pattern, + bool useRegularExpressions = false + ) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.HaveName(pattern, useRegularExpressions)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.HaveName(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveFullName(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction HaveFullName( + string pattern, + bool useRegularExpressions = false + ) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.HaveFullName(pattern, useRegularExpressions)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.HaveFullName(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveNameStartingWith(string pattern) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.HaveNameStartingWith(pattern)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.HaveNameStartingWith(pattern) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveNameEndingWith(string pattern) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.HaveNameEndingWith(pattern)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.HaveNameEndingWith(pattern) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveNameContaining(string pattern) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.HaveNameContaining(pattern)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.HaveNameContaining(pattern) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveFullNameContaining(string pattern) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.HaveFullNameContaining(pattern)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.HaveFullNameContaining(pattern) + ); return Create(_ruleCreator); } @@ -513,32 +746,62 @@ public TRuleTypeShouldConjunction BePrivateProtected() //Relation Conditions - public ShouldRelateToTypesThat DependOnAnyTypesThat() - { - _ruleCreator.BeginComplexCondition(ArchRuleDefinition.Types(true), - ObjectConditionsDefinition.DependOnAnyTypesThat()); - return new ShouldRelateToTypesThat(_ruleCreator); - } - - public ShouldRelateToTypesThat OnlyDependOnTypesThat() - { - _ruleCreator.BeginComplexCondition(ArchRuleDefinition.Types(true), - ObjectConditionsDefinition.OnlyDependOnTypesThat()); - return new ShouldRelateToTypesThat(_ruleCreator); - } - - public ShouldRelateToAttributesThat HaveAnyAttributesThat() - { - _ruleCreator.BeginComplexCondition(Attributes(true), - ObjectConditionsDefinition.HaveAnyAttributesThat()); - return new ShouldRelateToAttributesThat(_ruleCreator); - } - - public ShouldRelateToAttributesThat OnlyHaveAttributesThat() - { - _ruleCreator.BeginComplexCondition(Attributes(true), - ObjectConditionsDefinition.OnlyHaveAttributesThat()); - return new ShouldRelateToAttributesThat(_ruleCreator); + public ShouldRelateToTypesThat< + TRuleTypeShouldConjunction, + IType, + TRuleType + > DependOnAnyTypesThat() + { + _ruleCreator.BeginComplexCondition( + ArchRuleDefinition.Types(true), + ObjectConditionsDefinition.DependOnAnyTypesThat() + ); + return new ShouldRelateToTypesThat( + _ruleCreator + ); + } + + public ShouldRelateToTypesThat< + TRuleTypeShouldConjunction, + IType, + TRuleType + > OnlyDependOnTypesThat() + { + _ruleCreator.BeginComplexCondition( + ArchRuleDefinition.Types(true), + ObjectConditionsDefinition.OnlyDependOnTypesThat() + ); + return new ShouldRelateToTypesThat( + _ruleCreator + ); + } + + public ShouldRelateToAttributesThat< + TRuleTypeShouldConjunction, + TRuleType + > HaveAnyAttributesThat() + { + _ruleCreator.BeginComplexCondition( + Attributes(true), + ObjectConditionsDefinition.HaveAnyAttributesThat() + ); + return new ShouldRelateToAttributesThat( + _ruleCreator + ); + } + + public ShouldRelateToAttributesThat< + TRuleTypeShouldConjunction, + TRuleType + > OnlyHaveAttributesThat() + { + _ruleCreator.BeginComplexCondition( + Attributes(true), + ObjectConditionsDefinition.OnlyHaveAttributesThat() + ); + return new ShouldRelateToAttributesThat( + _ruleCreator + ); } //Negations @@ -554,20 +817,30 @@ public TRuleTypeShouldConjunction NotExist() public TRuleTypeShouldConjunction NotBe(string pattern, bool useRegularExpressions = false) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotBe(pattern, useRegularExpressions)); + ObjectConditionsDefinition.NotBe(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotBe(IEnumerable patterns, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction NotBe( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotBe(patterns, useRegularExpressions)); + ObjectConditionsDefinition.NotBe(patterns, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotBe(ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects) + public TRuleTypeShouldConjunction NotBe( + ICanBeAnalyzed firstObject, + params ICanBeAnalyzed[] moreObjects + ) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.NotBe(firstObject, moreObjects)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotBe(firstObject, moreObjects) + ); return Create(_ruleCreator); } @@ -583,24 +856,36 @@ public TRuleTypeShouldConjunction NotBe(IObjectProvider objects) return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotCallAny(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction NotCallAny( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotCallAny(pattern, useRegularExpressions)); + ObjectConditionsDefinition.NotCallAny(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotCallAny(IEnumerable patterns, - bool useRegularExpressions = false) + public TRuleTypeShouldConjunction NotCallAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotCallAny(patterns, useRegularExpressions)); + ObjectConditionsDefinition.NotCallAny(patterns, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotCallAny(MethodMember method, params MethodMember[] moreMethods) + public TRuleTypeShouldConjunction NotCallAny( + MethodMember method, + params MethodMember[] moreMethods + ) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.NotCallAny(method, moreMethods)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotCallAny(method, moreMethods) + ); return Create(_ruleCreator); } @@ -616,30 +901,44 @@ public TRuleTypeShouldConjunction NotCallAny(IObjectProvider metho return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotDependOnAny(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction NotDependOnAny( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotDependOnAny(pattern, useRegularExpressions)); + ObjectConditionsDefinition.NotDependOnAny(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotDependOnAny(IEnumerable patterns, - bool useRegularExpressions = false) + public TRuleTypeShouldConjunction NotDependOnAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotDependOnAny(patterns, useRegularExpressions)); + ObjectConditionsDefinition.NotDependOnAny( + patterns, + useRegularExpressions + ) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction NotDependOnAny(IType firstType, params IType[] moreTypes) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.NotDependOnAny(firstType, moreTypes)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotDependOnAny(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction NotDependOnAny(Type firstType, params Type[] moreTypes) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.NotDependOnAny(firstType, moreTypes)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotDependOnAny(firstType, moreTypes) + ); return Create(_ruleCreator); } @@ -661,232 +960,374 @@ public TRuleTypeShouldConjunction NotDependOnAny(IEnumerable types) return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotHaveAnyAttributes(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction NotHaveAnyAttributes( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveAnyAttributes(pattern, useRegularExpressions)); + ObjectConditionsDefinition.NotHaveAnyAttributes( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotHaveAnyAttributes(IEnumerable patterns, - bool useRegularExpressions = false) + public TRuleTypeShouldConjunction NotHaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveAnyAttributes(patterns, useRegularExpressions)); + ObjectConditionsDefinition.NotHaveAnyAttributes( + patterns, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotHaveAnyAttributes(Attribute firstAttribute, - params Attribute[] moreAttributes) + public TRuleTypeShouldConjunction NotHaveAnyAttributes( + Attribute firstAttribute, + params Attribute[] moreAttributes + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveAnyAttributes(firstAttribute, moreAttributes)); + ObjectConditionsDefinition.NotHaveAnyAttributes( + firstAttribute, + moreAttributes + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotHaveAnyAttributes(Type firstAttribute, params Type[] moreAttributes) + public TRuleTypeShouldConjunction NotHaveAnyAttributes( + Type firstAttribute, + params Type[] moreAttributes + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveAnyAttributes(firstAttribute, moreAttributes)); + ObjectConditionsDefinition.NotHaveAnyAttributes( + firstAttribute, + moreAttributes + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotHaveAnyAttributes(IObjectProvider attributes) + public TRuleTypeShouldConjunction NotHaveAnyAttributes( + IObjectProvider attributes + ) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.NotHaveAnyAttributes(attributes)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotHaveAnyAttributes(attributes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction NotHaveAnyAttributes(IEnumerable attributes) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.NotHaveAnyAttributes(attributes)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotHaveAnyAttributes(attributes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction NotHaveAnyAttributes(IEnumerable attributes) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.NotHaveAnyAttributes(attributes)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotHaveAnyAttributes(attributes) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotHaveAnyAttributesWithArguments(IEnumerable argumentValues) + public TRuleTypeShouldConjunction NotHaveAnyAttributesWithArguments( + IEnumerable argumentValues + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveAnyAttributesWithArguments(argumentValues)); + ObjectConditionsDefinition.NotHaveAnyAttributesWithArguments( + argumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction - NotHaveAnyAttributesWithArguments(object firstArgumentValue, params object[] moreArgumentValues) + public TRuleTypeShouldConjunction NotHaveAnyAttributesWithArguments( + object firstArgumentValue, + params object[] moreArgumentValues + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveAnyAttributesWithArguments(firstArgumentValue, - moreArgumentValues)); + ObjectConditionsDefinition.NotHaveAnyAttributesWithArguments( + firstArgumentValue, + moreArgumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotHaveAttributeWithArguments(string attribute, - IEnumerable argumentValues) + public TRuleTypeShouldConjunction NotHaveAttributeWithArguments( + string attribute, + IEnumerable argumentValues + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveAttributeWithArguments(attribute, argumentValues)); + ObjectConditionsDefinition.NotHaveAttributeWithArguments( + attribute, + argumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotHaveAttributeWithArguments(string attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public TRuleTypeShouldConjunction NotHaveAttributeWithArguments( + string attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveAttributeWithArguments(attribute, firstArgumentValue, - moreArgumentValues)); + ObjectConditionsDefinition.NotHaveAttributeWithArguments( + attribute, + firstArgumentValue, + moreArgumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotHaveAttributeWithArguments(Attribute attribute, - IEnumerable argumentValues) + public TRuleTypeShouldConjunction NotHaveAttributeWithArguments( + Attribute attribute, + IEnumerable argumentValues + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveAttributeWithArguments(attribute, argumentValues)); + ObjectConditionsDefinition.NotHaveAttributeWithArguments( + attribute, + argumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotHaveAttributeWithArguments(Attribute attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public TRuleTypeShouldConjunction NotHaveAttributeWithArguments( + Attribute attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveAttributeWithArguments(attribute, firstArgumentValue, - moreArgumentValues)); + ObjectConditionsDefinition.NotHaveAttributeWithArguments( + attribute, + firstArgumentValue, + moreArgumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotHaveAttributeWithArguments(Type attribute, - IEnumerable argumentValues) + public TRuleTypeShouldConjunction NotHaveAttributeWithArguments( + Type attribute, + IEnumerable argumentValues + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveAttributeWithArguments(attribute, argumentValues)); + ObjectConditionsDefinition.NotHaveAttributeWithArguments( + attribute, + argumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotHaveAttributeWithArguments(Type attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public TRuleTypeShouldConjunction NotHaveAttributeWithArguments( + Type attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveAttributeWithArguments(attribute, firstArgumentValue, - moreArgumentValues)); + ObjectConditionsDefinition.NotHaveAttributeWithArguments( + attribute, + firstArgumentValue, + moreArgumentValues + ) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction NotHaveAnyAttributesWithNamedArguments( - IEnumerable<(string, object)> attributeArguments) + IEnumerable<(string, object)> attributeArguments + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveAnyAttributesWithNamedArguments(attributeArguments)); + ObjectConditionsDefinition.NotHaveAnyAttributesWithNamedArguments( + attributeArguments + ) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction NotHaveAnyAttributesWithNamedArguments( (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments) + params (string, object)[] moreAttributeArguments + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveAnyAttributesWithNamedArguments(firstAttributeArgument, - moreAttributeArguments)); + ObjectConditionsDefinition.NotHaveAnyAttributesWithNamedArguments( + firstAttributeArgument, + moreAttributeArguments + ) + ); return Create(_ruleCreator); } - - public TRuleTypeShouldConjunction NotHaveAttributeWithNamedArguments(string attribute, - IEnumerable<(string, object)> attributeArguments) + + public TRuleTypeShouldConjunction NotHaveAttributeWithNamedArguments( + string attribute, + IEnumerable<(string, object)> attributeArguments + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveAttributeWithNamedArguments(attribute, - attributeArguments)); + ObjectConditionsDefinition.NotHaveAttributeWithNamedArguments( + attribute, + attributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotHaveAttributeWithNamedArguments(string attribute, + public TRuleTypeShouldConjunction NotHaveAttributeWithNamedArguments( + string attribute, (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments) + params (string, object)[] moreAttributeArguments + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveAttributeWithNamedArguments(attribute, + ObjectConditionsDefinition.NotHaveAttributeWithNamedArguments( + attribute, firstAttributeArgument, - moreAttributeArguments)); + moreAttributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotHaveAttributeWithNamedArguments(Attribute attribute, - IEnumerable<(string, object)> attributeArguments) + public TRuleTypeShouldConjunction NotHaveAttributeWithNamedArguments( + Attribute attribute, + IEnumerable<(string, object)> attributeArguments + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveAttributeWithNamedArguments(attribute, - attributeArguments)); + ObjectConditionsDefinition.NotHaveAttributeWithNamedArguments( + attribute, + attributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotHaveAttributeWithNamedArguments(Attribute attribute, + public TRuleTypeShouldConjunction NotHaveAttributeWithNamedArguments( + Attribute attribute, (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments) + params (string, object)[] moreAttributeArguments + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveAttributeWithNamedArguments(attribute, + ObjectConditionsDefinition.NotHaveAttributeWithNamedArguments( + attribute, firstAttributeArgument, - moreAttributeArguments)); + moreAttributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotHaveAttributeWithNamedArguments(Type attribute, - IEnumerable<(string, object)> attributeArguments) + public TRuleTypeShouldConjunction NotHaveAttributeWithNamedArguments( + Type attribute, + IEnumerable<(string, object)> attributeArguments + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveAttributeWithNamedArguments(attribute, - attributeArguments)); + ObjectConditionsDefinition.NotHaveAttributeWithNamedArguments( + attribute, + attributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotHaveAttributeWithNamedArguments(Type attribute, + public TRuleTypeShouldConjunction NotHaveAttributeWithNamedArguments( + Type attribute, (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments) + params (string, object)[] moreAttributeArguments + ) { _ruleCreator.AddCondition( - ObjectConditionsDefinition.NotHaveAttributeWithNamedArguments(attribute, + ObjectConditionsDefinition.NotHaveAttributeWithNamedArguments( + attribute, firstAttributeArgument, - moreAttributeArguments)); + moreAttributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotHaveName(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction NotHaveName( + string pattern, + bool useRegularExpressions = false + ) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.NotHaveName(pattern, useRegularExpressions)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotHaveName(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotHaveFullName(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction NotHaveFullName( + string pattern, + bool useRegularExpressions = false + ) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.NotHaveFullName(pattern, useRegularExpressions)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotHaveFullName( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction NotHaveNameStartingWith(string pattern) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.NotHaveNameStartingWith(pattern)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotHaveNameStartingWith(pattern) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction NotHaveNameEndingWith(string pattern) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.NotHaveNameEndingWith(pattern)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotHaveNameEndingWith(pattern) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction NotHaveNameContaining(string pattern) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.NotHaveNameContaining(pattern)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotHaveNameContaining(pattern) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction NotHaveFullNameContaining(string pattern) { - _ruleCreator.AddCondition(ObjectConditionsDefinition.NotHaveFullNameContaining(pattern)); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotHaveFullNameContaining(pattern) + ); return Create(_ruleCreator); } @@ -916,30 +1357,49 @@ public TRuleTypeShouldConjunction NotBeInternal() public TRuleTypeShouldConjunction NotBeProtectedInternal() { - _ruleCreator.AddCondition(ObjectConditionsDefinition.NotBeProtectedInternal()); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotBeProtectedInternal() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction NotBePrivateProtected() { - _ruleCreator.AddCondition(ObjectConditionsDefinition.NotBePrivateProtected()); + _ruleCreator.AddCondition( + ObjectConditionsDefinition.NotBePrivateProtected() + ); return Create(_ruleCreator); } //Relation Condition Negations - public ShouldRelateToTypesThat NotDependOnAnyTypesThat() - { - _ruleCreator.BeginComplexCondition(ArchRuleDefinition.Types(true), - ObjectConditionsDefinition.NotDependOnAnyTypesThat()); - return new ShouldRelateToTypesThat(_ruleCreator); - } - - public ShouldRelateToAttributesThat NotHaveAnyAttributesThat() - { - _ruleCreator.BeginComplexCondition(Attributes(true), - ObjectConditionsDefinition.NotHaveAnyAttributesThat()); - return new ShouldRelateToAttributesThat(_ruleCreator); + public ShouldRelateToTypesThat< + TRuleTypeShouldConjunction, + IType, + TRuleType + > NotDependOnAnyTypesThat() + { + _ruleCreator.BeginComplexCondition( + ArchRuleDefinition.Types(true), + ObjectConditionsDefinition.NotDependOnAnyTypesThat() + ); + return new ShouldRelateToTypesThat( + _ruleCreator + ); + } + + public ShouldRelateToAttributesThat< + TRuleTypeShouldConjunction, + TRuleType + > NotHaveAnyAttributesThat() + { + _ruleCreator.BeginComplexCondition( + Attributes(true), + ObjectConditionsDefinition.NotHaveAnyAttributesThat() + ); + return new ShouldRelateToAttributesThat( + _ruleCreator + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShouldConjunction.cs b/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShouldConjunction.cs index 8c07459c2..8464c51c2 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShouldConjunction.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShouldConjunction.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -9,14 +9,15 @@ namespace ArchUnitNET.Fluent.Syntax.Elements { - public abstract class - ObjectsShouldConjunction : - ObjectsShouldConjunctionWithDescription + public abstract class ObjectsShouldConjunction< + TRuleTypeShould, + TRuleTypeShouldConjunctionWithReason, + TRuleType + > : ObjectsShouldConjunctionWithDescription where TRuleType : ICanBeAnalyzed { - protected ObjectsShouldConjunction(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + protected ObjectsShouldConjunction(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } public TRuleTypeShouldConjunctionWithReason Because(string reason) { @@ -30,4 +31,4 @@ public TRuleTypeShouldConjunctionWithReason As(string description) return Create(_ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShouldConjunctionWithDescription.cs b/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShouldConjunctionWithDescription.cs index 801cdce67..347fc04a8 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShouldConjunctionWithDescription.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/ObjectsShouldConjunctionWithDescription.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -9,12 +9,12 @@ namespace ArchUnitNET.Fluent.Syntax.Elements { - public abstract class ObjectsShouldConjunctionWithDescription : ArchRule + public abstract class ObjectsShouldConjunctionWithDescription + : ArchRule where TRuleType : ICanBeAnalyzed { - protected ObjectsShouldConjunctionWithDescription(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + protected ObjectsShouldConjunctionWithDescription(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } public TRuleTypeShould AndShould() { @@ -28,4 +28,4 @@ public TRuleTypeShould OrShould() return Create(_ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/ShouldRelateToObjectsThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/ShouldRelateToObjectsThat.cs index 2d87fe177..b73207081 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/ShouldRelateToObjectsThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/ShouldRelateToObjectsThat.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -13,862 +13,1360 @@ namespace ArchUnitNET.Fluent.Syntax.Elements { - public class ShouldRelateToObjectsThat : - SyntaxElement, - IObjectPredicates + public class ShouldRelateToObjectsThat + : SyntaxElement, + IObjectPredicates where TReferenceType : ICanBeAnalyzed where TRuleType : ICanBeAnalyzed { - protected ShouldRelateToObjectsThat(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } - + protected ShouldRelateToObjectsThat(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } public TRuleTypeShouldConjunction Are(string pattern, bool useRegularExpressions = false) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.Are(pattern, useRegularExpressions)); + ObjectPredicatesDefinition.Are(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction Are(IEnumerable patterns, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction Are( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.Are(patterns, useRegularExpressions)); + ObjectPredicatesDefinition.Are(patterns, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction Are(ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects) + public TRuleTypeShouldConjunction Are( + ICanBeAnalyzed firstObject, + params ICanBeAnalyzed[] moreObjects + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.Are(firstObject, moreObjects)); + ObjectPredicatesDefinition.Are(firstObject, moreObjects) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction Are(IEnumerable objects) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.Are(objects)); + ObjectPredicatesDefinition.Are(objects) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction Are(IObjectProvider objects) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.Are(objects)); + ObjectPredicatesDefinition.Are(objects) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction CallAny(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction CallAny( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.CallAny(pattern, useRegularExpressions)); + ObjectPredicatesDefinition.CallAny(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction CallAny(IEnumerable patterns, - bool useRegularExpressions = false) + public TRuleTypeShouldConjunction CallAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.CallAny(patterns, useRegularExpressions)); + ObjectPredicatesDefinition.CallAny(patterns, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction CallAny(MethodMember method, params MethodMember[] moreMethods) + public TRuleTypeShouldConjunction CallAny( + MethodMember method, + params MethodMember[] moreMethods + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.CallAny(method, moreMethods)); + ObjectPredicatesDefinition.CallAny(method, moreMethods) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction CallAny(IEnumerable methods) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.CallAny(methods)); + ObjectPredicatesDefinition.CallAny(methods) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction CallAny(IObjectProvider methods) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.CallAny(methods)); + ObjectPredicatesDefinition.CallAny(methods) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DependOnAny(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction DependOnAny( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DependOnAny(pattern, useRegularExpressions)); + ObjectPredicatesDefinition.DependOnAny( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DependOnAny(IEnumerable patterns, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction DependOnAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DependOnAny(patterns, useRegularExpressions)); + ObjectPredicatesDefinition.DependOnAny( + patterns, + useRegularExpressions + ) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DependOnAny(Type firstType, params Type[] moreTypes) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DependOnAny(firstType, moreTypes)); + ObjectPredicatesDefinition.DependOnAny(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DependOnAny(IType firstType, params IType[] moreTypes) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DependOnAny(firstType, moreTypes)); + ObjectPredicatesDefinition.DependOnAny(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DependOnAny(IObjectProvider types) { - _ruleCreator.ContinueComplexCondition(ObjectPredicatesDefinition.DependOnAny(types)); + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.DependOnAny(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DependOnAny(IEnumerable types) { - _ruleCreator.ContinueComplexCondition(ObjectPredicatesDefinition.DependOnAny(types)); + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.DependOnAny(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DependOnAny(IEnumerable types) { - _ruleCreator.ContinueComplexCondition(ObjectPredicatesDefinition.DependOnAny(types)); + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.DependOnAny(types) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction FollowCustomPredicate(IPredicate predicate) + public TRuleTypeShouldConjunction FollowCustomPredicate( + IPredicate predicate + ) { _ruleCreator.ContinueComplexCondition(predicate); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction FollowCustomPredicate(Func predicate, - string description) + public TRuleTypeShouldConjunction FollowCustomPredicate( + Func predicate, + string description + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.FollowCustomPredicate(predicate, description)); + ObjectPredicatesDefinition.FollowCustomPredicate( + predicate, + description + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction OnlyDependOn(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction OnlyDependOn( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.OnlyDependOn(pattern, useRegularExpressions)); + ObjectPredicatesDefinition.OnlyDependOn( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction OnlyDependOn(IEnumerable patterns, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction OnlyDependOn( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.OnlyDependOn(patterns, useRegularExpressions)); + ObjectPredicatesDefinition.OnlyDependOn( + patterns, + useRegularExpressions + ) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction OnlyDependOn(Type firstType, params Type[] moreTypes) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.OnlyDependOn(firstType, moreTypes)); + ObjectPredicatesDefinition.OnlyDependOn(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction OnlyDependOn(IType firstType, params IType[] moreTypes) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.OnlyDependOn(firstType, moreTypes)); + ObjectPredicatesDefinition.OnlyDependOn(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction OnlyDependOn(IObjectProvider types) { - _ruleCreator.ContinueComplexCondition(ObjectPredicatesDefinition.OnlyDependOn(types)); + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.OnlyDependOn(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction OnlyDependOn(IEnumerable types) { - _ruleCreator.ContinueComplexCondition(ObjectPredicatesDefinition.OnlyDependOn(types)); + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.OnlyDependOn(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction OnlyDependOn(IEnumerable types) { - _ruleCreator.ContinueComplexCondition(ObjectPredicatesDefinition.OnlyDependOn(types)); + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.OnlyDependOn(types) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAnyAttributes(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction HaveAnyAttributes( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAnyAttributes(pattern, useRegularExpressions)); + ObjectPredicatesDefinition.HaveAnyAttributes( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAnyAttributes(IEnumerable patterns, - bool useRegularExpressions = false) + public TRuleTypeShouldConjunction HaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAnyAttributes(patterns, useRegularExpressions)); + ObjectPredicatesDefinition.HaveAnyAttributes( + patterns, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAnyAttributes(Type firstAttribute, params Type[] moreAttributes) + public TRuleTypeShouldConjunction HaveAnyAttributes( + Type firstAttribute, + params Type[] moreAttributes + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAnyAttributes(firstAttribute, moreAttributes)); + ObjectPredicatesDefinition.HaveAnyAttributes( + firstAttribute, + moreAttributes + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAnyAttributes(Attribute firstAttribute, params Attribute[] moreAttributes) + public TRuleTypeShouldConjunction HaveAnyAttributes( + Attribute firstAttribute, + params Attribute[] moreAttributes + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAnyAttributes(firstAttribute, moreAttributes)); + ObjectPredicatesDefinition.HaveAnyAttributes( + firstAttribute, + moreAttributes + ) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveAnyAttributes(IObjectProvider attributes) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAnyAttributes(attributes)); + ObjectPredicatesDefinition.HaveAnyAttributes(attributes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveAnyAttributes(IEnumerable attributes) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAnyAttributes(attributes)); + ObjectPredicatesDefinition.HaveAnyAttributes(attributes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveAnyAttributes(IEnumerable attributes) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAnyAttributes(attributes)); + ObjectPredicatesDefinition.HaveAnyAttributes(attributes) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction OnlyHaveAttributes(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction OnlyHaveAttributes( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.OnlyHaveAttributes(pattern, useRegularExpressions)); + ObjectPredicatesDefinition.OnlyHaveAttributes( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction OnlyHaveAttributes(IEnumerable patterns, - bool useRegularExpressions = false) + public TRuleTypeShouldConjunction OnlyHaveAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.OnlyHaveAttributes(patterns, useRegularExpressions)); + ObjectPredicatesDefinition.OnlyHaveAttributes( + patterns, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction OnlyHaveAttributes(Type firstAttribute, params Type[] moreAttributes) + public TRuleTypeShouldConjunction OnlyHaveAttributes( + Type firstAttribute, + params Type[] moreAttributes + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.OnlyHaveAttributes(firstAttribute, moreAttributes)); + ObjectPredicatesDefinition.OnlyHaveAttributes( + firstAttribute, + moreAttributes + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction OnlyHaveAttributes(Attribute firstAttribute, - params Attribute[] moreAttributes) + public TRuleTypeShouldConjunction OnlyHaveAttributes( + Attribute firstAttribute, + params Attribute[] moreAttributes + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.OnlyHaveAttributes(firstAttribute, moreAttributes)); + ObjectPredicatesDefinition.OnlyHaveAttributes( + firstAttribute, + moreAttributes + ) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction OnlyHaveAttributes(IObjectProvider attributes) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.OnlyHaveAttributes(attributes)); + ObjectPredicatesDefinition.OnlyHaveAttributes(attributes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction OnlyHaveAttributes(IEnumerable attributes) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.OnlyHaveAttributes(attributes)); + ObjectPredicatesDefinition.OnlyHaveAttributes(attributes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction OnlyHaveAttributes(IEnumerable attributes) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.OnlyHaveAttributes(attributes)); + ObjectPredicatesDefinition.OnlyHaveAttributes(attributes) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAnyAttributesWithArguments(IEnumerable argumentValues) + public TRuleTypeShouldConjunction HaveAnyAttributesWithArguments( + IEnumerable argumentValues + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAnyAttributesWithArguments(argumentValues)); + ObjectPredicatesDefinition.HaveAnyAttributesWithArguments( + argumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction - HaveAnyAttributesWithArguments(object firstArgumentValue, params object[] moreArgumentValues) + public TRuleTypeShouldConjunction HaveAnyAttributesWithArguments( + object firstArgumentValue, + params object[] moreArgumentValues + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAnyAttributesWithArguments(firstArgumentValue,moreArgumentValues)); + ObjectPredicatesDefinition.HaveAnyAttributesWithArguments( + firstArgumentValue, + moreArgumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAttributeWithArguments(string attribute, IEnumerable argumentValues) + public TRuleTypeShouldConjunction HaveAttributeWithArguments( + string attribute, + IEnumerable argumentValues + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAttributeWithArguments(attribute,argumentValues)); + ObjectPredicatesDefinition.HaveAttributeWithArguments( + attribute, + argumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAttributeWithArguments(string attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public TRuleTypeShouldConjunction HaveAttributeWithArguments( + string attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAttributeWithArguments(attribute,firstArgumentValue,moreArgumentValues)); + ObjectPredicatesDefinition.HaveAttributeWithArguments( + attribute, + firstArgumentValue, + moreArgumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAttributeWithArguments(Attribute attribute, IEnumerable argumentValues) + public TRuleTypeShouldConjunction HaveAttributeWithArguments( + Attribute attribute, + IEnumerable argumentValues + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAttributeWithArguments(attribute,argumentValues)); + ObjectPredicatesDefinition.HaveAttributeWithArguments( + attribute, + argumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAttributeWithArguments(Attribute attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public TRuleTypeShouldConjunction HaveAttributeWithArguments( + Attribute attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAttributeWithArguments(attribute,firstArgumentValue,moreArgumentValues)); + ObjectPredicatesDefinition.HaveAttributeWithArguments( + attribute, + firstArgumentValue, + moreArgumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAttributeWithArguments(Type attribute, IEnumerable argumentValues) + public TRuleTypeShouldConjunction HaveAttributeWithArguments( + Type attribute, + IEnumerable argumentValues + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAttributeWithArguments(attribute,argumentValues)); + ObjectPredicatesDefinition.HaveAttributeWithArguments( + attribute, + argumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAttributeWithArguments(Type attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public TRuleTypeShouldConjunction HaveAttributeWithArguments( + Type attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAttributeWithArguments(attribute,firstArgumentValue,moreArgumentValues)); + ObjectPredicatesDefinition.HaveAttributeWithArguments( + attribute, + firstArgumentValue, + moreArgumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAnyAttributesWithNamedArguments(IEnumerable<(string, object)> attributeArguments) + public TRuleTypeShouldConjunction HaveAnyAttributesWithNamedArguments( + IEnumerable<(string, object)> attributeArguments + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAnyAttributesWithNamedArguments(attributeArguments)); + ObjectPredicatesDefinition.HaveAnyAttributesWithNamedArguments( + attributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAnyAttributesWithNamedArguments((string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments) + public TRuleTypeShouldConjunction HaveAnyAttributesWithNamedArguments( + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAnyAttributesWithNamedArguments(firstAttributeArgument,moreAttributeArguments)); + ObjectPredicatesDefinition.HaveAnyAttributesWithNamedArguments( + firstAttributeArgument, + moreAttributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments(string attribute, IEnumerable<(string, object)> attributeArguments) + public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( + string attribute, + IEnumerable<(string, object)> attributeArguments + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAttributeWithNamedArguments(attribute,attributeArguments)); + ObjectPredicatesDefinition.HaveAttributeWithNamedArguments( + attribute, + attributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments(string attribute, (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments) + public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( + string attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAttributeWithNamedArguments(attribute,firstAttributeArgument,moreAttributeArguments)); + ObjectPredicatesDefinition.HaveAttributeWithNamedArguments( + attribute, + firstAttributeArgument, + moreAttributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments(Attribute attribute, IEnumerable<(string, object)> attributeArguments) + public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( + Attribute attribute, + IEnumerable<(string, object)> attributeArguments + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAttributeWithNamedArguments(attribute,attributeArguments)); + ObjectPredicatesDefinition.HaveAttributeWithNamedArguments( + attribute, + attributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments(Attribute attribute, (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments) + public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( + Attribute attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAttributeWithNamedArguments(attribute,firstAttributeArgument,moreAttributeArguments)); + ObjectPredicatesDefinition.HaveAttributeWithNamedArguments( + attribute, + firstAttributeArgument, + moreAttributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments(Type attribute, IEnumerable<(string, object)> attributeArguments) + public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( + Type attribute, + IEnumerable<(string, object)> attributeArguments + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAttributeWithNamedArguments(attribute,attributeArguments)); + ObjectPredicatesDefinition.HaveAttributeWithNamedArguments( + attribute, + attributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments(Type attribute, (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments) + public TRuleTypeShouldConjunction HaveAttributeWithNamedArguments( + Type attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveAttributeWithNamedArguments(attribute,firstAttributeArgument,moreAttributeArguments)); + ObjectPredicatesDefinition.HaveAttributeWithNamedArguments( + attribute, + firstAttributeArgument, + moreAttributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveName(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction HaveName( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveName(pattern, useRegularExpressions)); + ObjectPredicatesDefinition.HaveName(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction HaveFullName(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction HaveFullName( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveFullName(pattern, useRegularExpressions)); + ObjectPredicatesDefinition.HaveFullName( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveNameStartingWith(string pattern) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveNameStartingWith(pattern)); + ObjectPredicatesDefinition.HaveNameStartingWith(pattern) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveNameEndingWith(string pattern) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveNameEndingWith(pattern)); + ObjectPredicatesDefinition.HaveNameEndingWith(pattern) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveNameContaining(string pattern) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveNameContaining(pattern)); + ObjectPredicatesDefinition.HaveNameContaining(pattern) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveFullNameContaining(string pattern) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.HaveFullNameContaining(pattern)); + ObjectPredicatesDefinition.HaveFullNameContaining(pattern) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction ArePrivate() { - _ruleCreator.ContinueComplexCondition(ObjectPredicatesDefinition.ArePrivate()); + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.ArePrivate() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction ArePublic() { - _ruleCreator.ContinueComplexCondition(ObjectPredicatesDefinition.ArePublic()); + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.ArePublic() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreProtected() { - _ruleCreator.ContinueComplexCondition(ObjectPredicatesDefinition.AreProtected()); + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.AreProtected() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreInternal() { - _ruleCreator.ContinueComplexCondition(ObjectPredicatesDefinition.AreInternal()); + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.AreInternal() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreProtectedInternal() { - _ruleCreator.ContinueComplexCondition(ObjectPredicatesDefinition.AreProtectedInternal()); + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.AreProtectedInternal() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction ArePrivateProtected() { - _ruleCreator.ContinueComplexCondition(ObjectPredicatesDefinition.ArePrivateProtected()); + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.ArePrivateProtected() + ); return Create(_ruleCreator); } - //Negations public TRuleTypeShouldConjunction AreNot(string pattern, bool useRegularExpressions = false) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.AreNot(pattern, useRegularExpressions)); + ObjectPredicatesDefinition.AreNot(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction AreNot(IEnumerable patterns, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction AreNot( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.AreNot(patterns, useRegularExpressions)); + ObjectPredicatesDefinition.AreNot(patterns, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction AreNot(ICanBeAnalyzed firstObject, params ICanBeAnalyzed[] moreObjects) + public TRuleTypeShouldConjunction AreNot( + ICanBeAnalyzed firstObject, + params ICanBeAnalyzed[] moreObjects + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.AreNot(firstObject, moreObjects)); + ObjectPredicatesDefinition.AreNot(firstObject, moreObjects) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNot(IEnumerable objects) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.AreNot(objects)); + ObjectPredicatesDefinition.AreNot(objects) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNot(IObjectProvider objects) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.AreNot(objects)); + ObjectPredicatesDefinition.AreNot(objects) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotCallAny(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction DoNotCallAny( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotCallAny(pattern, useRegularExpressions)); + ObjectPredicatesDefinition.DoNotCallAny( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotCallAny(IEnumerable patterns, - bool useRegularExpressions = false) + public TRuleTypeShouldConjunction DoNotCallAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotCallAny(patterns, useRegularExpressions)); + ObjectPredicatesDefinition.DoNotCallAny( + patterns, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotCallAny(MethodMember method, params MethodMember[] moreMethods) + public TRuleTypeShouldConjunction DoNotCallAny( + MethodMember method, + params MethodMember[] moreMethods + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotCallAny(method, moreMethods)); + ObjectPredicatesDefinition.DoNotCallAny(method, moreMethods) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotCallAny(IEnumerable methods) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotCallAny(methods)); + ObjectPredicatesDefinition.DoNotCallAny(methods) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotCallAny(IObjectProvider methods) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotCallAny(methods)); + ObjectPredicatesDefinition.DoNotCallAny(methods) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotDependOnAny(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction DoNotDependOnAny( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotDependOnAny(pattern, useRegularExpressions)); + ObjectPredicatesDefinition.DoNotDependOnAny( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotDependOnAny(IEnumerable patterns, - bool useRegularExpressions = false) + public TRuleTypeShouldConjunction DoNotDependOnAny( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotDependOnAny(patterns, useRegularExpressions)); + ObjectPredicatesDefinition.DoNotDependOnAny( + patterns, + useRegularExpressions + ) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotDependOnAny(Type firstType, params Type[] moreTypes) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotDependOnAny(firstType, moreTypes)); + ObjectPredicatesDefinition.DoNotDependOnAny(firstType, moreTypes) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotDependOnAny(IType firstType, params IType[] moreTypes) + public TRuleTypeShouldConjunction DoNotDependOnAny( + IType firstType, + params IType[] moreTypes + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotDependOnAny(firstType, moreTypes)); + ObjectPredicatesDefinition.DoNotDependOnAny(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotDependOnAny(IObjectProvider types) { - _ruleCreator.ContinueComplexCondition(ObjectPredicatesDefinition.DoNotDependOnAny(types)); + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.DoNotDependOnAny(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotDependOnAny(IEnumerable types) { - _ruleCreator.ContinueComplexCondition(ObjectPredicatesDefinition.DoNotDependOnAny(types)); + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.DoNotDependOnAny(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotDependOnAny(IEnumerable types) { - _ruleCreator.ContinueComplexCondition(ObjectPredicatesDefinition.DoNotDependOnAny(types)); + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.DoNotDependOnAny(types) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveAnyAttributes(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction DoNotHaveAnyAttributes( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAnyAttributes(pattern, useRegularExpressions)); + ObjectPredicatesDefinition.DoNotHaveAnyAttributes( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveAnyAttributes(IEnumerable patterns, - bool useRegularExpressions = false) + public TRuleTypeShouldConjunction DoNotHaveAnyAttributes( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAnyAttributes(patterns, useRegularExpressions)); + ObjectPredicatesDefinition.DoNotHaveAnyAttributes( + patterns, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveAnyAttributes(Type firstAttribute, params Type[] moreAttributes) + public TRuleTypeShouldConjunction DoNotHaveAnyAttributes( + Type firstAttribute, + params Type[] moreAttributes + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAnyAttributes(firstAttribute, moreAttributes)); + ObjectPredicatesDefinition.DoNotHaveAnyAttributes( + firstAttribute, + moreAttributes + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveAnyAttributes(Attribute firstAttribute, - params Attribute[] moreAttributes) + public TRuleTypeShouldConjunction DoNotHaveAnyAttributes( + Attribute firstAttribute, + params Attribute[] moreAttributes + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAnyAttributes(firstAttribute, moreAttributes)); + ObjectPredicatesDefinition.DoNotHaveAnyAttributes( + firstAttribute, + moreAttributes + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveAnyAttributes(IObjectProvider attributes) + public TRuleTypeShouldConjunction DoNotHaveAnyAttributes( + IObjectProvider attributes + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAnyAttributes(attributes)); + ObjectPredicatesDefinition.DoNotHaveAnyAttributes(attributes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotHaveAnyAttributes(IEnumerable attributes) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAnyAttributes(attributes)); + ObjectPredicatesDefinition.DoNotHaveAnyAttributes(attributes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotHaveAnyAttributes(IEnumerable attributes) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAnyAttributes(attributes)); + ObjectPredicatesDefinition.DoNotHaveAnyAttributes(attributes) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveAnyAttributesWithArguments(IEnumerable argumentValues) + public TRuleTypeShouldConjunction DoNotHaveAnyAttributesWithArguments( + IEnumerable argumentValues + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAnyAttributesWithArguments(argumentValues)); + ObjectPredicatesDefinition.DoNotHaveAnyAttributesWithArguments( + argumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveAnyAttributesWithArguments(object firstArgumentValue, - params object[] moreArgumentValues) + public TRuleTypeShouldConjunction DoNotHaveAnyAttributesWithArguments( + object firstArgumentValue, + params object[] moreArgumentValues + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAnyAttributesWithArguments(firstArgumentValue,moreArgumentValues)); + ObjectPredicatesDefinition.DoNotHaveAnyAttributesWithArguments( + firstArgumentValue, + moreArgumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveAttributeWithArguments(Attribute attribute, IEnumerable argumentValues) + public TRuleTypeShouldConjunction DoNotHaveAttributeWithArguments( + Attribute attribute, + IEnumerable argumentValues + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAnyAttributesWithArguments(attribute,argumentValues)); + ObjectPredicatesDefinition.DoNotHaveAnyAttributesWithArguments( + attribute, + argumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveAttributeWithArguments(Attribute attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public TRuleTypeShouldConjunction DoNotHaveAttributeWithArguments( + Attribute attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments(attribute,firstArgumentValue,moreArgumentValues)); + ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments( + attribute, + firstArgumentValue, + moreArgumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveAttributeWithArguments(Type attribute, IEnumerable argumentValues) + public TRuleTypeShouldConjunction DoNotHaveAttributeWithArguments( + Type attribute, + IEnumerable argumentValues + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments(attribute,argumentValues)); + ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments( + attribute, + argumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveAttributeWithArguments(Type attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public TRuleTypeShouldConjunction DoNotHaveAttributeWithArguments( + Type attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments(attribute,firstArgumentValue,moreArgumentValues)); + ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments( + attribute, + firstArgumentValue, + moreArgumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveAnyAttributesWithNamedArguments(IEnumerable<(string, object)> attributeArguments) + public TRuleTypeShouldConjunction DoNotHaveAnyAttributesWithNamedArguments( + IEnumerable<(string, object)> attributeArguments + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAnyAttributesWithNamedArguments(attributeArguments)); + ObjectPredicatesDefinition.DoNotHaveAnyAttributesWithNamedArguments( + attributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveAnyAttributesWithNamedArguments((string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments) + public TRuleTypeShouldConjunction DoNotHaveAnyAttributesWithNamedArguments( + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAnyAttributesWithNamedArguments(firstAttributeArgument,moreAttributeArguments)); + ObjectPredicatesDefinition.DoNotHaveAnyAttributesWithNamedArguments( + firstAttributeArgument, + moreAttributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveAttributeWithArguments(string attribute, IEnumerable argumentValues) + public TRuleTypeShouldConjunction DoNotHaveAttributeWithArguments( + string attribute, + IEnumerable argumentValues + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments(attribute,argumentValues)); + ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments( + attribute, + argumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveAttributeWithArguments(string attribute, object firstArgumentValue, - params object[] moreArgumentValues) + public TRuleTypeShouldConjunction DoNotHaveAttributeWithArguments( + string attribute, + object firstArgumentValue, + params object[] moreArgumentValues + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments(attribute,firstArgumentValue,moreArgumentValues)); + ObjectPredicatesDefinition.DoNotHaveAttributeWithArguments( + attribute, + firstArgumentValue, + moreArgumentValues + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveAttributeWithNamedArguments(string attribute, IEnumerable<(string, object)> attributeArguments) + public TRuleTypeShouldConjunction DoNotHaveAttributeWithNamedArguments( + string attribute, + IEnumerable<(string, object)> attributeArguments + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments(attribute,attributeArguments)); + ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments( + attribute, + attributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveAttributeWithNamedArguments(string attribute, - (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments) + public TRuleTypeShouldConjunction DoNotHaveAttributeWithNamedArguments( + string attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments(attribute,firstAttributeArgument,moreAttributeArguments)); + ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments( + attribute, + firstAttributeArgument, + moreAttributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveAttributeWithNamedArguments(Attribute attribute, IEnumerable<(string, object)> attributeArguments) + public TRuleTypeShouldConjunction DoNotHaveAttributeWithNamedArguments( + Attribute attribute, + IEnumerable<(string, object)> attributeArguments + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments(attribute,attributeArguments)); + ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments( + attribute, + attributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveAttributeWithNamedArguments(Attribute attribute, - (string, object) firstAttributeArgument, params (string, object)[] moreAttributeArguments) + public TRuleTypeShouldConjunction DoNotHaveAttributeWithNamedArguments( + Attribute attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments(attribute,firstAttributeArgument,moreAttributeArguments)); + ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments( + attribute, + firstAttributeArgument, + moreAttributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveAttributeWithNamedArguments(Type attribute, IEnumerable<(string, object)> attributeArguments) + public TRuleTypeShouldConjunction DoNotHaveAttributeWithNamedArguments( + Type attribute, + IEnumerable<(string, object)> attributeArguments + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments(attribute,attributeArguments)); + ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments( + attribute, + attributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveAttributeWithNamedArguments(Type attribute, (string, object) firstAttributeArgument, - params (string, object)[] moreAttributeArguments) + public TRuleTypeShouldConjunction DoNotHaveAttributeWithNamedArguments( + Type attribute, + (string, object) firstAttributeArgument, + params (string, object)[] moreAttributeArguments + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments(attribute,firstAttributeArgument,moreAttributeArguments)); + ObjectPredicatesDefinition.DoNotHaveAttributeWithNamedArguments( + attribute, + firstAttributeArgument, + moreAttributeArguments + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveName(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction DoNotHaveName( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveName(pattern, useRegularExpressions)); + ObjectPredicatesDefinition.DoNotHaveName( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotHaveFullName(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction DoNotHaveFullName( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveFullName(pattern, useRegularExpressions)); + ObjectPredicatesDefinition.DoNotHaveFullName( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotHaveNameStartingWith(string pattern) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveNameStartingWith(pattern)); + ObjectPredicatesDefinition.DoNotHaveNameStartingWith(pattern) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotHaveNameEndingWith(string pattern) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveNameEndingWith(pattern)); + ObjectPredicatesDefinition.DoNotHaveNameEndingWith(pattern) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotHaveNameContaining(string pattern) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveNameContaining(pattern)); + ObjectPredicatesDefinition.DoNotHaveNameContaining(pattern) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotHaveFullNameContaining(string pattern) { _ruleCreator.ContinueComplexCondition( - ObjectPredicatesDefinition.DoNotHaveFullNameContaining(pattern)); + ObjectPredicatesDefinition.DoNotHaveFullNameContaining(pattern) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNotPrivate() { - _ruleCreator.ContinueComplexCondition(ObjectPredicatesDefinition.AreNotPrivate()); + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.AreNotPrivate() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNotPublic() { - _ruleCreator.ContinueComplexCondition(ObjectPredicatesDefinition.AreNotPublic()); + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.AreNotPublic() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNotProtected() { - _ruleCreator.ContinueComplexCondition(ObjectPredicatesDefinition.AreNotProtected()); + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.AreNotProtected() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNotInternal() { - _ruleCreator.ContinueComplexCondition(ObjectPredicatesDefinition.AreNotInternal()); + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.AreNotInternal() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNotProtectedInternal() { - _ruleCreator.ContinueComplexCondition(ObjectPredicatesDefinition.AreNotProtectedInternal()); + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.AreNotProtectedInternal() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNotPrivateProtected() { - _ruleCreator.ContinueComplexCondition(ObjectPredicatesDefinition.AreNotPrivateProtected()); + _ruleCreator.ContinueComplexCondition( + ObjectPredicatesDefinition.AreNotPrivateProtected() + ); return Create(_ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/AttributeConditionsDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/AttributeConditionsDefinition.cs index c6402f840..6f54e070e 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/AttributeConditionsDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/AttributeConditionsDefinition.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -14,31 +14,40 @@ public static class AttributeConditionsDefinition public static ICondition BeAbstract() { return new SimpleCondition( - attribute => !attribute.IsAbstract.HasValue || attribute.IsAbstract.Value, "be abstract", - "is not abstract"); + attribute => !attribute.IsAbstract.HasValue || attribute.IsAbstract.Value, + "be abstract", + "is not abstract" + ); } public static ICondition BeSealed() { - return new SimpleCondition(attribute => !attribute.IsSealed.HasValue || attribute.IsSealed.Value, - "be sealed", "is not sealed"); + return new SimpleCondition( + attribute => !attribute.IsSealed.HasValue || attribute.IsSealed.Value, + "be sealed", + "is not sealed" + ); } - //Negations public static ICondition NotBeAbstract() { return new SimpleCondition( - attribute => !attribute.IsAbstract.HasValue || !attribute.IsAbstract.Value, "not be abstract", - "is abstract"); + attribute => !attribute.IsAbstract.HasValue || !attribute.IsAbstract.Value, + "not be abstract", + "is abstract" + ); } public static ICondition NotBeSealed() { return new SimpleCondition( - attribute => !attribute.IsSealed.HasValue || !attribute.IsSealed.Value, "not be sealed", "is sealed"); + attribute => !attribute.IsSealed.HasValue || !attribute.IsSealed.Value, + "not be sealed", + "is sealed" + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/AttributePredicatesDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/AttributePredicatesDefinition.cs index c91947f16..c7b312e4b 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/AttributePredicatesDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/AttributePredicatesDefinition.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -14,13 +14,17 @@ public static class AttributePredicatesDefinition public static IPredicate AreAbstract() { return new SimplePredicate( - attribute => !attribute.IsAbstract.HasValue || attribute.IsAbstract.Value, "are abstract"); + attribute => !attribute.IsAbstract.HasValue || attribute.IsAbstract.Value, + "are abstract" + ); } public static IPredicate AreSealed() { - return new SimplePredicate(attribute => !attribute.IsSealed.HasValue || attribute.IsSealed.Value, - "are sealed"); + return new SimplePredicate( + attribute => !attribute.IsSealed.HasValue || attribute.IsSealed.Value, + "are sealed" + ); } //Negations @@ -28,14 +32,17 @@ public static IPredicate AreSealed() public static IPredicate AreNotAbstract() { return new SimplePredicate( - attribute => !attribute.IsAbstract.HasValue || !attribute.IsAbstract.Value, "are not abstract"); + attribute => !attribute.IsAbstract.HasValue || !attribute.IsAbstract.Value, + "are not abstract" + ); } public static IPredicate AreNotSealed() { return new SimplePredicate( attribute => !attribute.IsSealed.HasValue || !attribute.IsSealed.Value, - "are not sealed"); + "are not sealed" + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/AttributesShould.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/AttributesShould.cs index 74b97f7a7..a339fa7da 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/AttributesShould.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/AttributesShould.cs @@ -1,18 +1,19 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Attributes { - public class AttributesShould : TypesShould, IComplexAttributeConditions + public class AttributesShould + : TypesShould, + IComplexAttributeConditions { - public AttributesShould(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public AttributesShould(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } public AttributesShouldConjunction BeAbstract() { @@ -26,7 +27,6 @@ public AttributesShouldConjunction BeSealed() return new AttributesShouldConjunction(_ruleCreator); } - //Negations @@ -42,4 +42,4 @@ public AttributesShouldConjunction NotBeSealed() return new AttributesShouldConjunction(_ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/AttributesShouldConjunction.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/AttributesShouldConjunction.cs index a4e3e806f..eaa4f0612 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/AttributesShouldConjunction.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/AttributesShouldConjunction.cs @@ -1,18 +1,21 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Attributes { - public class AttributesShouldConjunction : ObjectsShouldConjunction + public class AttributesShouldConjunction + : ObjectsShouldConjunction< + AttributesShould, + AttributesShouldConjunctionWithDescription, + Attribute + > { - public AttributesShouldConjunction(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public AttributesShouldConjunction(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/AttributesShouldConjunctionWithDescription.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/AttributesShouldConjunctionWithDescription.cs index 1c19f93ae..6c869f045 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/AttributesShouldConjunctionWithDescription.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/AttributesShouldConjunctionWithDescription.cs @@ -1,19 +1,17 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Attributes { - public class - AttributesShouldConjunctionWithDescription : ObjectsShouldConjunctionWithDescription + public class AttributesShouldConjunctionWithDescription + : ObjectsShouldConjunctionWithDescription { - public AttributesShouldConjunctionWithDescription(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public AttributesShouldConjunctionWithDescription(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/GivenAttributes.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/GivenAttributes.cs index d497ed27b..637bd854f 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/GivenAttributes.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/GivenAttributes.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -10,8 +10,7 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Attributes { public class GivenAttributes : GivenObjects { - public GivenAttributes(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenAttributes(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/GivenAttributesConjunction.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/GivenAttributesConjunction.cs index c4cd01b42..a48e2f9b6 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/GivenAttributesConjunction.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/GivenAttributesConjunction.cs @@ -1,18 +1,22 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Attributes { - public class GivenAttributesConjunction : GivenObjectsConjunction + public class GivenAttributesConjunction + : GivenObjectsConjunction< + GivenAttributesThat, + AttributesShould, + GivenAttributesConjunctionWithDescription, + Attribute + > { - public GivenAttributesConjunction(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenAttributesConjunction(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/GivenAttributesConjunctionWithDescription.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/GivenAttributesConjunctionWithDescription.cs index 6f54c007c..d2e15bad6 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/GivenAttributesConjunctionWithDescription.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/GivenAttributesConjunctionWithDescription.cs @@ -1,18 +1,17 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Attributes { - public class GivenAttributesConjunctionWithDescription : GivenObjectsConjunctionWithDescription + public class GivenAttributesConjunctionWithDescription + : GivenObjectsConjunctionWithDescription { - public GivenAttributesConjunctionWithDescription(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenAttributesConjunctionWithDescription(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/GivenAttributesThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/GivenAttributesThat.cs index 74831a03a..d32c6f3b2 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/GivenAttributesThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/GivenAttributesThat.cs @@ -1,19 +1,19 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Attributes { - public class GivenAttributesThat : GivenTypesThat, - IAttributePredicates + public class GivenAttributesThat + : GivenTypesThat, + IAttributePredicates { - public GivenAttributesThat(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenAttributesThat(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } public GivenAttributesConjunction AreAbstract() { @@ -27,7 +27,6 @@ public GivenAttributesConjunction AreSealed() return new GivenAttributesConjunction(_ruleCreator); } - //Negations @@ -43,4 +42,4 @@ public GivenAttributesConjunction AreNotSealed() return new GivenAttributesConjunction(_ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/IAttributeConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/IAttributeConditions.cs index 84b8f0e67..40945d06e 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/IAttributeConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/IAttributeConditions.cs @@ -1,24 +1,24 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Attributes { - public interface IAttributeConditions : ITypeConditions + public interface IAttributeConditions + : ITypeConditions where TRuleType : ICanBeAnalyzed { TReturnType BeAbstract(); TReturnType BeSealed(); - //Negations TReturnType NotBeAbstract(); TReturnType NotBeSealed(); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/IAttributePredicates.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/IAttributePredicates.cs index 5fd8e5ed9..eb2db756a 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/IAttributePredicates.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/IAttributePredicates.cs @@ -1,24 +1,24 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Attributes { - public interface IAttributePredicates : ITypePredicates + public interface IAttributePredicates + : ITypePredicates where TRuleType : ICanBeAnalyzed { TReturnType AreAbstract(); TReturnType AreSealed(); - //Negations TReturnType AreNotAbstract(); TReturnType AreNotSealed(); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/IComplexAttributeConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/IComplexAttributeConditions.cs index a716fe4c4..5df76410e 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/IComplexAttributeConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/IComplexAttributeConditions.cs @@ -1,15 +1,14 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Attributes { - public interface IComplexAttributeConditions : IComplexTypeConditions, - IAttributeConditions - { - } -} \ No newline at end of file + public interface IComplexAttributeConditions + : IComplexTypeConditions, + IAttributeConditions { } +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/ShouldRelateToAttributesThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/ShouldRelateToAttributesThat.cs index c5776b1af..9ab5d0440 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/ShouldRelateToAttributesThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Attributes/ShouldRelateToAttributesThat.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -9,15 +9,14 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Attributes { - public class ShouldRelateToAttributesThat : - ShouldRelateToTypesThat, - IAttributePredicates + public class ShouldRelateToAttributesThat + : ShouldRelateToTypesThat, + IAttributePredicates where TRuleType : ICanBeAnalyzed where TRuleTypeShouldConjunction : SyntaxElement { - public ShouldRelateToAttributesThat(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public ShouldRelateToAttributesThat(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } public TRuleTypeShouldConjunction AreAbstract() { @@ -31,7 +30,6 @@ public TRuleTypeShouldConjunction AreSealed() return Create(_ruleCreator); } - //Negations @@ -47,4 +45,4 @@ public TRuleTypeShouldConjunction AreNotSealed() return Create(_ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/ClassConditionsDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/ClassConditionsDefinition.cs index 89927165e..f4a4aff74 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/ClassConditionsDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/ClassConditionsDefinition.cs @@ -1,12 +1,12 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 +using System.Linq; using ArchUnitNET.Domain; using ArchUnitNET.Fluent.Conditions; -using System.Linq; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Classes { @@ -14,20 +14,31 @@ public static class ClassConditionsDefinition { public static ICondition BeAbstract() { - return new SimpleCondition(cls => !cls.IsAbstract.HasValue || cls.IsAbstract.Value, "be abstract", - "is not abstract"); + return new SimpleCondition( + cls => !cls.IsAbstract.HasValue || cls.IsAbstract.Value, + "be abstract", + "is not abstract" + ); } public static ICondition BeSealed() { - return new SimpleCondition(cls => !cls.IsSealed.HasValue || cls.IsSealed.Value, "be sealed", - "is not sealed"); + return new SimpleCondition( + cls => !cls.IsSealed.HasValue || cls.IsSealed.Value, + "be sealed", + "is not sealed" + ); } public static ICondition BeImmutable() { - return new SimpleCondition(cls => cls.Members.Where(m => m.IsStatic == false).All(m => m.Writability.IsImmutable()), "be immutable", - "is not immutable"); + return new SimpleCondition( + cls => + cls.Members.Where(m => m.IsStatic == false) + .All(m => m.Writability.IsImmutable()), + "be immutable", + "is not immutable" + ); } //Negations @@ -35,20 +46,29 @@ public static ICondition BeImmutable() public static ICondition NotBeAbstract() { - return new SimpleCondition(cls => !cls.IsAbstract.HasValue || !cls.IsAbstract.Value, - "not be abstract", "is abstract"); + return new SimpleCondition( + cls => !cls.IsAbstract.HasValue || !cls.IsAbstract.Value, + "not be abstract", + "is abstract" + ); } public static ICondition NotBeSealed() { - return new SimpleCondition(cls => !cls.IsSealed.HasValue || !cls.IsSealed.Value, "not be sealed", - "is sealed"); + return new SimpleCondition( + cls => !cls.IsSealed.HasValue || !cls.IsSealed.Value, + "not be sealed", + "is sealed" + ); } public static ICondition NotBeImmutable() { - return new SimpleCondition(cls => cls.Members.Any(m => m.IsStatic == false && !m.Writability.IsImmutable()), "not be immutable", - "is immutable"); + return new SimpleCondition( + cls => cls.Members.Any(m => m.IsStatic == false && !m.Writability.IsImmutable()), + "not be immutable", + "is immutable" + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/ClassPredicatesDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/ClassPredicatesDefinition.cs index 0b8e2a185..afdeddca5 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/ClassPredicatesDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/ClassPredicatesDefinition.cs @@ -1,12 +1,12 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 +using System.Linq; using ArchUnitNET.Domain; using ArchUnitNET.Fluent.Predicates; -using System.Linq; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Classes { @@ -14,35 +14,54 @@ public static class ClassPredicatesDefinition { public static IPredicate AreAbstract() { - return new SimplePredicate(cls => !cls.IsAbstract.HasValue || cls.IsAbstract.Value, "are abstract"); + return new SimplePredicate( + cls => !cls.IsAbstract.HasValue || cls.IsAbstract.Value, + "are abstract" + ); } public static IPredicate AreSealed() { - return new SimplePredicate(cls => !cls.IsSealed.HasValue || cls.IsSealed.Value, "are sealed"); + return new SimplePredicate( + cls => !cls.IsSealed.HasValue || cls.IsSealed.Value, + "are sealed" + ); } public static IPredicate AreImmutable() { - return new SimplePredicate(cls => cls.Members.Where(m => m.IsStatic == false).All(m => m.Writability.IsImmutable()), "are immutable"); + return new SimplePredicate( + cls => + cls.Members.Where(m => m.IsStatic == false) + .All(m => m.Writability.IsImmutable()), + "are immutable" + ); } //Negations public static IPredicate AreNotAbstract() { - return new SimplePredicate(cls => !cls.IsAbstract.HasValue || !cls.IsAbstract.Value, - "are not abstract"); + return new SimplePredicate( + cls => !cls.IsAbstract.HasValue || !cls.IsAbstract.Value, + "are not abstract" + ); } public static IPredicate AreNotSealed() { - return new SimplePredicate(cls => !cls.IsSealed.HasValue || !cls.IsSealed.Value, "are not sealed"); + return new SimplePredicate( + cls => !cls.IsSealed.HasValue || !cls.IsSealed.Value, + "are not sealed" + ); } public static IPredicate AreNotImmutable() { - return new SimplePredicate(cls => cls.Members.Any(m => m.IsStatic == false && !m.Writability.IsImmutable()), "are not immutable"); + return new SimplePredicate( + cls => cls.Members.Any(m => m.IsStatic == false && !m.Writability.IsImmutable()), + "are not immutable" + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/ClassesShould.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/ClassesShould.cs index 79d61105f..6479153f1 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/ClassesShould.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/ClassesShould.cs @@ -1,18 +1,19 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Classes { - public class ClassesShould : TypesShould, IComplexClassConditions + public class ClassesShould + : TypesShould, + IComplexClassConditions { - public ClassesShould(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public ClassesShould(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } public ClassesShouldConjunction BeAbstract() { @@ -53,4 +54,4 @@ public ClassesShouldConjunction NotBeImmutable() return new ClassesShouldConjunction(_ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/ClassesShouldConjunction.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/ClassesShouldConjunction.cs index 9a416ce12..7f3871f80 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/ClassesShouldConjunction.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/ClassesShouldConjunction.cs @@ -1,20 +1,17 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Classes { - public class - ClassesShouldConjunction : ObjectsShouldConjunction + public class ClassesShouldConjunction + : ObjectsShouldConjunction { - public ClassesShouldConjunction(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public ClassesShouldConjunction(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/ClassesShouldConjunctionWithDescription.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/ClassesShouldConjunctionWithDescription.cs index b0a2f9bd7..e8abe59bc 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/ClassesShouldConjunctionWithDescription.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/ClassesShouldConjunctionWithDescription.cs @@ -1,17 +1,17 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Classes { - public class ClassesShouldConjunctionWithDescription : ObjectsShouldConjunctionWithDescription + public class ClassesShouldConjunctionWithDescription + : ObjectsShouldConjunctionWithDescription { - public ClassesShouldConjunctionWithDescription(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public ClassesShouldConjunctionWithDescription(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/GivenClasses.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/GivenClasses.cs index 754d9408b..28c4822ac 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/GivenClasses.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/GivenClasses.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -10,8 +10,7 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Classes { public class GivenClasses : GivenObjects { - public GivenClasses(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenClasses(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/GivenClassesConjunction.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/GivenClassesConjunction.cs index 31916b9b1..6ea22d8da 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/GivenClassesConjunction.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/GivenClassesConjunction.cs @@ -1,18 +1,22 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Classes { - public class GivenClassesConjunction : GivenObjectsConjunction + public class GivenClassesConjunction + : GivenObjectsConjunction< + GivenClassesThat, + ClassesShould, + GivenClassesConjunctionWithDescription, + Class + > { - public GivenClassesConjunction(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenClassesConjunction(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/GivenClassesConjunctionWithDescription.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/GivenClassesConjunctionWithDescription.cs index a2ac954fa..670cbbbf8 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/GivenClassesConjunctionWithDescription.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/GivenClassesConjunctionWithDescription.cs @@ -1,19 +1,17 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Classes { - public class - GivenClassesConjunctionWithDescription : GivenObjectsConjunctionWithDescription + public class GivenClassesConjunctionWithDescription + : GivenObjectsConjunctionWithDescription { - public GivenClassesConjunctionWithDescription(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenClassesConjunctionWithDescription(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/GivenClassesThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/GivenClassesThat.cs index 3f8d6b342..8efddcab1 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/GivenClassesThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/GivenClassesThat.cs @@ -1,19 +1,19 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Classes { - public class GivenClassesThat : GivenTypesThat, - IClassPredicates + public class GivenClassesThat + : GivenTypesThat, + IClassPredicates { - public GivenClassesThat(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenClassesThat(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } public GivenClassesConjunction AreAbstract() { @@ -54,4 +54,4 @@ public GivenClassesConjunction AreNotImmutable() return new GivenClassesConjunction(_ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/IClassConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/IClassConditions.cs index f7312f901..6411b9498 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/IClassConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/IClassConditions.cs @@ -1,21 +1,21 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Classes { - public interface IClassConditions : ITypeConditions + public interface IClassConditions + : ITypeConditions where TRuleType : ICanBeAnalyzed { TReturnType BeAbstract(); TReturnType BeSealed(); TReturnType BeImmutable(); - //Negations @@ -23,4 +23,4 @@ public interface IClassConditions : ITypeConditi TReturnType NotBeSealed(); TReturnType NotBeImmutable(); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/IClassPredicates.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/IClassPredicates.cs index e300fa5ac..adb6acf20 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/IClassPredicates.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/IClassPredicates.cs @@ -1,21 +1,21 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Classes { - public interface IClassPredicates : ITypePredicates + public interface IClassPredicates + : ITypePredicates where TRuleType : ICanBeAnalyzed { TReturnType AreAbstract(); TReturnType AreSealed(); TReturnType AreImmutable(); - //Negations @@ -23,4 +23,4 @@ public interface IClassPredicates : ITypePredicates< TReturnType AreNotSealed(); TReturnType AreNotImmutable(); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/IComplexClassConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/IComplexClassConditions.cs index 4380e59dd..6d176e54e 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/IComplexClassConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/IComplexClassConditions.cs @@ -1,15 +1,14 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Classes { - public interface IComplexClassConditions : IComplexTypeConditions, - IClassConditions - { - } -} \ No newline at end of file + public interface IComplexClassConditions + : IComplexTypeConditions, + IClassConditions { } +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/ShouldRelateToClassesThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/ShouldRelateToClassesThat.cs index 2a705aa76..0a8f74876 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/ShouldRelateToClassesThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Classes/ShouldRelateToClassesThat.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -9,14 +9,14 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Classes { - public class ShouldRelateToClassesThat : - ShouldRelateToTypesThat, - IClassPredicates where TRuleTypeShouldConjunction : SyntaxElement + public class ShouldRelateToClassesThat + : ShouldRelateToTypesThat, + IClassPredicates + where TRuleTypeShouldConjunction : SyntaxElement where TRuleType : ICanBeAnalyzed { - public ShouldRelateToClassesThat(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public ShouldRelateToClassesThat(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } public TRuleTypeShouldConjunction AreAbstract() { @@ -57,4 +57,4 @@ public TRuleTypeShouldConjunction AreNotImmutable() return Create(_ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypes.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypes.cs index e090c85a1..bb55e682a 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypes.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypes.cs @@ -1,18 +1,21 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types { - public class GivenTypes : GivenObjects, - TypesShould, IType> + public class GivenTypes + : GivenObjects< + GivenTypesThat, + TypesShould, + IType + > { - public GivenTypes(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenTypes(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesConjunction.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesConjunction.cs index 2c0483e78..81e2218b7 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesConjunction.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesConjunction.cs @@ -1,19 +1,22 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types { - public class GivenTypesConjunction : - GivenObjectsConjunction, TypesShould - , GivenTypesConjunctionWithDescription, IType> + public class GivenTypesConjunction + : GivenObjectsConjunction< + GivenTypesThat, + TypesShould, + GivenTypesConjunctionWithDescription, + IType + > { - public GivenTypesConjunction(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenTypesConjunction(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesConjunctionWithDescription.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesConjunctionWithDescription.cs index 3c9754d0a..3ca4e20ec 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesConjunctionWithDescription.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesConjunctionWithDescription.cs @@ -1,19 +1,21 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types { - public class GivenTypesConjunctionWithDescription : - GivenObjectsConjunctionWithDescription, - TypesShould, IType> + public class GivenTypesConjunctionWithDescription + : GivenObjectsConjunctionWithDescription< + GivenTypesThat, + TypesShould, + IType + > { - public GivenTypesConjunctionWithDescription(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenTypesConjunctionWithDescription(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesThat.cs index 6df17c8ff..ec0035f00 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/GivenTypesThat.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -11,20 +11,21 @@ using Assembly = System.Reflection.Assembly; namespace ArchUnitNET.Fluent.Syntax.Elements.Types - { - public class GivenTypesThat : - GivenObjectsThat, ITypePredicates + public class GivenTypesThat + : GivenObjectsThat, + ITypePredicates where TRuleType : IType { // ReSharper disable once MemberCanBeProtected.Global - public GivenTypesThat(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenTypesThat(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } public TGivenRuleTypeConjunction Are(Type firstType, params Type[] moreTypes) { - _ruleCreator.AddPredicate(TypePredicatesDefinition.Are(firstType, moreTypes)); + _ruleCreator.AddPredicate( + TypePredicatesDefinition.Are(firstType, moreTypes) + ); return Create(_ruleCreator); } @@ -34,30 +35,41 @@ public TGivenRuleTypeConjunction Are(IEnumerable types) return Create(_ruleCreator); } - public TGivenRuleTypeConjunction AreAssignableTo(string pattern, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction AreAssignableTo( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - TypePredicatesDefinition.AreAssignableTo(pattern, useRegularExpressions)); + TypePredicatesDefinition.AreAssignableTo(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction AreAssignableTo(IEnumerable patterns, - bool useRegularExpressions = false) + public TGivenRuleTypeConjunction AreAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - TypePredicatesDefinition.AreAssignableTo(patterns, useRegularExpressions)); + TypePredicatesDefinition.AreAssignableTo(patterns, useRegularExpressions) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction AreAssignableTo(IType firstType, params IType[] moreTypes) { - _ruleCreator.AddPredicate(TypePredicatesDefinition.AreAssignableTo(firstType, moreTypes)); + _ruleCreator.AddPredicate( + TypePredicatesDefinition.AreAssignableTo(firstType, moreTypes) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction AreAssignableTo(Type firstType, params Type[] moreTypes) { - _ruleCreator.AddPredicate(TypePredicatesDefinition.AreAssignableTo(firstType, moreTypes)); + _ruleCreator.AddPredicate( + TypePredicatesDefinition.AreAssignableTo(firstType, moreTypes) + ); return Create(_ruleCreator); } @@ -81,13 +93,17 @@ public TGivenRuleTypeConjunction AreAssignableTo(IEnumerable types) public TGivenRuleTypeConjunction AreNestedIn(IType firstType, params IType[] moreTypes) { - _ruleCreator.AddPredicate(TypePredicatesDefinition.AreNestedIn(firstType, moreTypes)); + _ruleCreator.AddPredicate( + TypePredicatesDefinition.AreNestedIn(firstType, moreTypes) + ); return Create(_ruleCreator); } - + public TGivenRuleTypeConjunction AreNestedIn(Type firstType, params Type[] moreTypes) { - _ruleCreator.AddPredicate(TypePredicatesDefinition.AreNestedIn(firstType, moreTypes)); + _ruleCreator.AddPredicate( + TypePredicatesDefinition.AreNestedIn(firstType, moreTypes) + ); return Create(_ruleCreator); } @@ -108,7 +124,7 @@ public TGivenRuleTypeConjunction AreNestedIn(IEnumerable types) _ruleCreator.AddPredicate(TypePredicatesDefinition.AreNestedIn(types)); return Create(_ruleCreator); } - + public TGivenRuleTypeConjunction AreValueTypes() { _ruleCreator.AddPredicate(TypePredicatesDefinition.AreValueTypes()); @@ -127,70 +143,100 @@ public TGivenRuleTypeConjunction AreStructs() return Create(_ruleCreator); } - public TGivenRuleTypeConjunction ImplementInterface(string pattern, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction ImplementInterface( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - TypePredicatesDefinition.ImplementInterface(pattern, useRegularExpressions)); + TypePredicatesDefinition.ImplementInterface( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction ImplementInterface(Interface intf) { - _ruleCreator.AddPredicate( - TypePredicatesDefinition.ImplementInterface(intf)); + _ruleCreator.AddPredicate(TypePredicatesDefinition.ImplementInterface(intf)); return Create(_ruleCreator); } public TGivenRuleTypeConjunction ImplementInterface(Type intf) { - _ruleCreator.AddPredicate( - TypePredicatesDefinition.ImplementInterface(intf)); + _ruleCreator.AddPredicate(TypePredicatesDefinition.ImplementInterface(intf)); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction ResideInNamespace(string pattern, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction ResideInNamespace( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - TypePredicatesDefinition.ResideInNamespace(pattern, useRegularExpressions)); + TypePredicatesDefinition.ResideInNamespace( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction ResideInAssembly(string pattern, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction ResideInAssembly( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - TypePredicatesDefinition.ResideInAssembly(pattern, useRegularExpressions)); + TypePredicatesDefinition.ResideInAssembly(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction ResideInAssembly(Assembly assembly, params Assembly[] moreAssemblies) + public TGivenRuleTypeConjunction ResideInAssembly( + Assembly assembly, + params Assembly[] moreAssemblies + ) { _ruleCreator.AddPredicate( - TypePredicatesDefinition.ResideInAssembly(assembly, moreAssemblies)); + TypePredicatesDefinition.ResideInAssembly(assembly, moreAssemblies) + ); return Create(_ruleCreator); } - - public TGivenRuleTypeConjunction ResideInAssembly(Domain.Assembly assembly, params Domain.Assembly[] moreAssemblies) + + public TGivenRuleTypeConjunction ResideInAssembly( + Domain.Assembly assembly, + params Domain.Assembly[] moreAssemblies + ) { _ruleCreator.AddPredicate( - TypePredicatesDefinition.ResideInAssembly(assembly, moreAssemblies)); + TypePredicatesDefinition.ResideInAssembly(assembly, moreAssemblies) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction HavePropertyMemberWithName(string name) { - _ruleCreator.AddPredicate(TypePredicatesDefinition.HavePropertyMemberWithName(name)); + _ruleCreator.AddPredicate( + TypePredicatesDefinition.HavePropertyMemberWithName(name) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction HaveFieldMemberWithName(string name) { - _ruleCreator.AddPredicate(TypePredicatesDefinition.HaveFieldMemberWithName(name)); + _ruleCreator.AddPredicate( + TypePredicatesDefinition.HaveFieldMemberWithName(name) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction HaveMethodMemberWithName(string name) { - _ruleCreator.AddPredicate(TypePredicatesDefinition.HaveMethodMemberWithName(name)); + _ruleCreator.AddPredicate( + TypePredicatesDefinition.HaveMethodMemberWithName(name) + ); return Create(_ruleCreator); } @@ -206,13 +252,14 @@ public TGivenRuleTypeConjunction AreNested() return Create(_ruleCreator); } - //Negations public TGivenRuleTypeConjunction AreNot(Type firstType, params Type[] moreTypes) { - _ruleCreator.AddPredicate(TypePredicatesDefinition.AreNot(firstType, moreTypes)); + _ruleCreator.AddPredicate( + TypePredicatesDefinition.AreNot(firstType, moreTypes) + ); return Create(_ruleCreator); } @@ -222,48 +269,74 @@ public TGivenRuleTypeConjunction AreNot(IEnumerable types) return Create(_ruleCreator); } - public TGivenRuleTypeConjunction AreNotAssignableTo(string pattern, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction AreNotAssignableTo( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - TypePredicatesDefinition.AreNotAssignableTo(pattern, useRegularExpressions)); + TypePredicatesDefinition.AreNotAssignableTo( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction AreNotAssignableTo(IEnumerable patterns, - bool useRegularExpressions = false) + public TGivenRuleTypeConjunction AreNotAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - TypePredicatesDefinition.AreNotAssignableTo(patterns, useRegularExpressions)); + TypePredicatesDefinition.AreNotAssignableTo( + patterns, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction AreNotAssignableTo(IType firstType, params IType[] moreTypes) + public TGivenRuleTypeConjunction AreNotAssignableTo( + IType firstType, + params IType[] moreTypes + ) { - _ruleCreator.AddPredicate(TypePredicatesDefinition.AreNotAssignableTo(firstType, moreTypes)); + _ruleCreator.AddPredicate( + TypePredicatesDefinition.AreNotAssignableTo(firstType, moreTypes) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction AreNotAssignableTo(Type firstType, params Type[] moreTypes) { - _ruleCreator.AddPredicate(TypePredicatesDefinition.AreNotAssignableTo(firstType, moreTypes)); + _ruleCreator.AddPredicate( + TypePredicatesDefinition.AreNotAssignableTo(firstType, moreTypes) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction AreNotAssignableTo(IObjectProvider types) { - _ruleCreator.AddPredicate(TypePredicatesDefinition.AreNotAssignableTo(types)); + _ruleCreator.AddPredicate( + TypePredicatesDefinition.AreNotAssignableTo(types) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction AreNotAssignableTo(IEnumerable types) { - _ruleCreator.AddPredicate(TypePredicatesDefinition.AreNotAssignableTo(types)); + _ruleCreator.AddPredicate( + TypePredicatesDefinition.AreNotAssignableTo(types) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction AreNotAssignableTo(IEnumerable types) { - _ruleCreator.AddPredicate(TypePredicatesDefinition.AreNotAssignableTo(types)); + _ruleCreator.AddPredicate( + TypePredicatesDefinition.AreNotAssignableTo(types) + ); return Create(_ruleCreator); } @@ -285,76 +358,115 @@ public TGivenRuleTypeConjunction AreNotStructs() return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotImplementInterface(string pattern, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction DoNotImplementInterface( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - TypePredicatesDefinition.DoNotImplementInterface(pattern, useRegularExpressions)); + TypePredicatesDefinition.DoNotImplementInterface( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction DoNotImplementInterface(Interface intf) { _ruleCreator.AddPredicate( - TypePredicatesDefinition.DoNotImplementInterface(intf)); + TypePredicatesDefinition.DoNotImplementInterface(intf) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction DoNotImplementInterface(Type intf) { _ruleCreator.AddPredicate( - TypePredicatesDefinition.DoNotImplementInterface(intf)); + TypePredicatesDefinition.DoNotImplementInterface(intf) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotResideInNamespace(string pattern, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction DoNotResideInNamespace( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - TypePredicatesDefinition.DoNotResideInNamespace(pattern, useRegularExpressions)); + TypePredicatesDefinition.DoNotResideInNamespace( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotResideInAssembly(string pattern, bool useRegularExpressions = false) + public TGivenRuleTypeConjunction DoNotResideInAssembly( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddPredicate( - TypePredicatesDefinition.DoNotResideInAssembly(pattern, useRegularExpressions)); + TypePredicatesDefinition.DoNotResideInAssembly( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TGivenRuleTypeConjunction DoNotResideInAssembly(Assembly assembly, params Assembly[] moreAssemblies) + public TGivenRuleTypeConjunction DoNotResideInAssembly( + Assembly assembly, + params Assembly[] moreAssemblies + ) { _ruleCreator.AddPredicate( - TypePredicatesDefinition.DoNotResideInAssembly(assembly, moreAssemblies)); + TypePredicatesDefinition.DoNotResideInAssembly(assembly, moreAssemblies) + ); return Create(_ruleCreator); } - - public TGivenRuleTypeConjunction DoNotResideInAssembly(Domain.Assembly assembly, params Domain.Assembly[] moreAssemblies) + + public TGivenRuleTypeConjunction DoNotResideInAssembly( + Domain.Assembly assembly, + params Domain.Assembly[] moreAssemblies + ) { _ruleCreator.AddPredicate( - TypePredicatesDefinition.DoNotResideInAssembly(assembly, moreAssemblies)); + TypePredicatesDefinition.DoNotResideInAssembly(assembly, moreAssemblies) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction DoNotHavePropertyMemberWithName(string name) { - _ruleCreator.AddPredicate(TypePredicatesDefinition.DoNotHavePropertyMemberWithName(name)); + _ruleCreator.AddPredicate( + TypePredicatesDefinition.DoNotHavePropertyMemberWithName(name) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction DoNotHaveFieldMemberWithName(string name) { - _ruleCreator.AddPredicate(TypePredicatesDefinition.DoNotHaveFieldMemberWithName(name)); + _ruleCreator.AddPredicate( + TypePredicatesDefinition.DoNotHaveFieldMemberWithName(name) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction DoNotHaveMethodMemberWithName(string name) { - _ruleCreator.AddPredicate(TypePredicatesDefinition.DoNotHaveMethodMemberWithName(name)); + _ruleCreator.AddPredicate( + TypePredicatesDefinition.DoNotHaveMethodMemberWithName(name) + ); return Create(_ruleCreator); } public TGivenRuleTypeConjunction DoNotHaveMemberWithName(string name) { - _ruleCreator.AddPredicate(TypePredicatesDefinition.DoNotHaveMemberWithName(name)); + _ruleCreator.AddPredicate( + TypePredicatesDefinition.DoNotHaveMemberWithName(name) + ); return Create(_ruleCreator); } @@ -364,4 +476,4 @@ public TGivenRuleTypeConjunction AreNotNested() return Create(_ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/IComplexTypeConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/IComplexTypeConditions.cs index 7eb88844f..99fb5059f 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/IComplexTypeConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/IComplexTypeConditions.cs @@ -1,26 +1,32 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types { - public interface - IComplexTypeConditions : - IComplexObjectConditions, + public interface IComplexTypeConditions + : IComplexObjectConditions, ITypeConditions where TRuleType : IType where TRuleTypeShouldConjunction : SyntaxElement { - ShouldRelateToTypesThat BeAssignableToTypesThat(); - + ShouldRelateToTypesThat< + TRuleTypeShouldConjunction, + IType, + TRuleType + > BeAssignableToTypesThat(); //Negations - ShouldRelateToTypesThat NotBeAssignableToTypesThat(); + ShouldRelateToTypesThat< + TRuleTypeShouldConjunction, + IType, + TRuleType + > NotBeAssignableToTypesThat(); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypeConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypeConditions.cs index c5afd31b3..b201630c8 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypeConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypeConditions.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -11,13 +11,17 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Types { - public interface ITypeConditions : IObjectConditions + public interface ITypeConditions + : IObjectConditions where TRuleType : ICanBeAnalyzed { TReturnType Be(Type firstType, params Type[] moreTypes); TReturnType Be(IEnumerable types); TReturnType BeAssignableTo(string pattern, bool useRegularExpressions = false); - TReturnType BeAssignableTo(IEnumerable patterns, bool useRegularExpressions = false); + TReturnType BeAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType BeAssignableTo(IType firstType, params IType[] moreTypes); TReturnType BeAssignableTo(Type type, params Type[] moreTypes); TReturnType BeAssignableTo(IObjectProvider types); @@ -32,21 +36,26 @@ public interface ITypeConditions : IObjectCondit TReturnType ResideInNamespace(string pattern, bool useRegularExpressions = false); TReturnType ResideInAssembly(string pattern, bool useRegularExpressions = false); TReturnType ResideInAssembly(Assembly assembly, params Assembly[] moreAssemblies); - TReturnType ResideInAssembly(Domain.Assembly assembly, params Domain.Assembly[] moreAssemblies); + TReturnType ResideInAssembly( + Domain.Assembly assembly, + params Domain.Assembly[] moreAssemblies + ); TReturnType HavePropertyMemberWithName(string name); TReturnType HaveFieldMemberWithName(string name); TReturnType HaveMethodMemberWithName(string name); TReturnType HaveMemberWithName(string name); TReturnType BeNested(); - //Negations TReturnType NotBe(Type firstType, params Type[] moreTypes); TReturnType NotBe(IEnumerable types); TReturnType NotBeAssignableTo(string pattern, bool useRegularExpressions = false); - TReturnType NotBeAssignableTo(IEnumerable patterns, bool useRegularExpressions = false); + TReturnType NotBeAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType NotBeAssignableTo(IType type, params IType[] moreTypes); TReturnType NotBeAssignableTo(Type type, params Type[] moreTypes); TReturnType NotBeAssignableTo(IObjectProvider types); @@ -61,11 +70,14 @@ public interface ITypeConditions : IObjectCondit TReturnType NotResideInNamespace(string pattern, bool useRegularExpressions = false); TReturnType NotResideInAssembly(string pattern, bool useRegularExpressions = false); TReturnType NotResideInAssembly(Assembly assembly, params Assembly[] moreAssemblies); - TReturnType NotResideInAssembly(Domain.Assembly assembly, params Domain.Assembly[] moreAssemblies); + TReturnType NotResideInAssembly( + Domain.Assembly assembly, + params Domain.Assembly[] moreAssemblies + ); TReturnType NotHavePropertyMemberWithName(string name); TReturnType NotHaveFieldMemberWithName(string name); TReturnType NotHaveMethodMemberWithName(string name); TReturnType NotHaveMemberWithName(string name); TReturnType NotBeNested(); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypePredicates.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypePredicates.cs index 81ee96b38..e585222cb 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypePredicates.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/ITypePredicates.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -11,13 +11,17 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Types { - public interface ITypePredicates : IObjectPredicates + public interface ITypePredicates + : IObjectPredicates where TRuleType : ICanBeAnalyzed { TReturnType Are(Type firstType, params Type[] moreTypes); TReturnType Are(IEnumerable types); TReturnType AreAssignableTo(string pattern, bool useRegularExpressions = false); - TReturnType AreAssignableTo(IEnumerable patterns, bool useRegularExpressions = false); + TReturnType AreAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType AreAssignableTo(IType firstType, params IType[] moreTypes); TReturnType AreAssignableTo(Type type, params Type[] moreTypes); TReturnType AreAssignableTo(IObjectProvider types); @@ -32,21 +36,26 @@ public interface ITypePredicates : IObjectPredicates TReturnType ResideInNamespace(string pattern, bool useRegularExpressions = false); TReturnType ResideInAssembly(string pattern, bool useRegularExpressions = false); TReturnType ResideInAssembly(Assembly assembly, params Assembly[] moreAssemblies); - TReturnType ResideInAssembly(Domain.Assembly assembly, params Domain.Assembly[] moreAssemblies); + TReturnType ResideInAssembly( + Domain.Assembly assembly, + params Domain.Assembly[] moreAssemblies + ); TReturnType HavePropertyMemberWithName(string name); TReturnType HaveFieldMemberWithName(string name); TReturnType HaveMethodMemberWithName(string name); TReturnType HaveMemberWithName(string name); TReturnType AreNested(); - //Negations TReturnType AreNot(Type firstType, params Type[] moreTypes); TReturnType AreNot(IEnumerable types); TReturnType AreNotAssignableTo(string pattern, bool useRegularExpressions = false); - TReturnType AreNotAssignableTo(IEnumerable patterns, bool useRegularExpressions = false); + TReturnType AreNotAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ); TReturnType AreNotAssignableTo(IType type, params IType[] moreTypes); TReturnType AreNotAssignableTo(Type type, params Type[] moreTypes); TReturnType AreNotAssignableTo(IObjectProvider types); @@ -61,11 +70,14 @@ public interface ITypePredicates : IObjectPredicates TReturnType DoNotResideInNamespace(string pattern, bool useRegularExpressions = false); TReturnType DoNotResideInAssembly(string pattern, bool useRegularExpressions = false); TReturnType DoNotResideInAssembly(Assembly assembly, params Assembly[] moreAssemblies); - TReturnType DoNotResideInAssembly(Domain.Assembly assembly, params Domain.Assembly[] moreAssemblies); + TReturnType DoNotResideInAssembly( + Domain.Assembly assembly, + params Domain.Assembly[] moreAssemblies + ); TReturnType DoNotHavePropertyMemberWithName(string name); TReturnType DoNotHaveFieldMemberWithName(string name); TReturnType DoNotHaveMethodMemberWithName(string name); TReturnType DoNotHaveMemberWithName(string name); TReturnType AreNotNested(); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/GivenInterfaces.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/GivenInterfaces.cs index c43ebc8e0..02b853bc1 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/GivenInterfaces.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/GivenInterfaces.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -10,8 +10,7 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Interfaces { public class GivenInterfaces : GivenObjects { - public GivenInterfaces(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenInterfaces(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/GivenInterfacesConjunction.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/GivenInterfacesConjunction.cs index 04a74c21b..9127c8782 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/GivenInterfacesConjunction.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/GivenInterfacesConjunction.cs @@ -1,18 +1,22 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Interfaces { - public class GivenInterfacesConjunction : GivenObjectsConjunction + public class GivenInterfacesConjunction + : GivenObjectsConjunction< + GivenInterfacesThat, + InterfacesShould, + GivenInterfacesConjunction, + Interface + > { - public GivenInterfacesConjunction(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenInterfacesConjunction(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/GivenInterfacesConjunctionWithDescription.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/GivenInterfacesConjunctionWithDescription.cs index 62f36f913..09ed5d331 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/GivenInterfacesConjunctionWithDescription.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/GivenInterfacesConjunctionWithDescription.cs @@ -1,18 +1,17 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Interfaces { - public class GivenInterfacesConjunctionWithDescription : GivenObjectsConjunctionWithDescription + public class GivenInterfacesConjunctionWithDescription + : GivenObjectsConjunctionWithDescription { - public GivenInterfacesConjunctionWithDescription(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenInterfacesConjunctionWithDescription(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/GivenInterfacesThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/GivenInterfacesThat.cs index 51771b269..64f4ed525 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/GivenInterfacesThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/GivenInterfacesThat.cs @@ -1,18 +1,18 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Interfaces { - public class GivenInterfacesThat : GivenTypesThat, - IInterfacePredicates + public class GivenInterfacesThat + : GivenTypesThat, + IInterfacePredicates { - public GivenInterfacesThat(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public GivenInterfacesThat(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/IComplexInterfaceConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/IComplexInterfaceConditions.cs index 2dadefe14..23a46eccb 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/IComplexInterfaceConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/IComplexInterfaceConditions.cs @@ -1,15 +1,14 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Interfaces { - public interface IComplexInterfaceConditions : IComplexTypeConditions, - IInterfaceConditions - { - } -} \ No newline at end of file + public interface IComplexInterfaceConditions + : IComplexTypeConditions, + IInterfaceConditions { } +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/IInterfaceConditions.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/IInterfaceConditions.cs index 389031296..5bb806298 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/IInterfaceConditions.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/IInterfaceConditions.cs @@ -1,15 +1,14 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Interfaces { - public interface IInterfaceConditions : ITypeConditions - where TRuleType : ICanBeAnalyzed - { - } -} \ No newline at end of file + public interface IInterfaceConditions + : ITypeConditions + where TRuleType : ICanBeAnalyzed { } +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/IInterfacePredicates.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/IInterfacePredicates.cs index 30783384c..23967d88b 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/IInterfacePredicates.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/IInterfacePredicates.cs @@ -1,15 +1,14 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Interfaces { - public interface IInterfacePredicates : ITypePredicates - where TRuleType : ICanBeAnalyzed - { - } -} \ No newline at end of file + public interface IInterfacePredicates + : ITypePredicates + where TRuleType : ICanBeAnalyzed { } +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/InterfacesShould.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/InterfacesShould.cs index 5403145b9..ab0e5f313 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/InterfacesShould.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/InterfacesShould.cs @@ -1,17 +1,18 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Interfaces { - public class InterfacesShould : TypesShould, IComplexInterfaceConditions + public class InterfacesShould + : TypesShould, + IComplexInterfaceConditions { - public InterfacesShould(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public InterfacesShould(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/InterfacesShouldConjunction.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/InterfacesShouldConjunction.cs index 044268364..bcee1cba0 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/InterfacesShouldConjunction.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/InterfacesShouldConjunction.cs @@ -1,18 +1,21 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Interfaces { - public class InterfacesShouldConjunction : ObjectsShouldConjunction + public class InterfacesShouldConjunction + : ObjectsShouldConjunction< + InterfacesShould, + InterfacesShouldConjunctionWithDescription, + Interface + > { - public InterfacesShouldConjunction(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public InterfacesShouldConjunction(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/InterfacesShouldConjunctionWithDescription.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/InterfacesShouldConjunctionWithDescription.cs index 70164e82e..6c4750df8 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/InterfacesShouldConjunctionWithDescription.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/InterfacesShouldConjunctionWithDescription.cs @@ -1,19 +1,17 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Interfaces { - public class - InterfacesShouldConjunctionWithDescription : ObjectsShouldConjunctionWithDescription + public class InterfacesShouldConjunctionWithDescription + : ObjectsShouldConjunctionWithDescription { - public InterfacesShouldConjunctionWithDescription(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public InterfacesShouldConjunctionWithDescription(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/ShouldRelateToInterfacesThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/ShouldRelateToInterfacesThat.cs index 7e9de862e..6f82c2f96 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/ShouldRelateToInterfacesThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/Interfaces/ShouldRelateToInterfacesThat.cs @@ -1,19 +1,19 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types.Interfaces { - public class ShouldRelateToInterfacesThat : - ShouldRelateToTypesThat, - IInterfacePredicates where TRuleType : ICanBeAnalyzed + public class ShouldRelateToInterfacesThat + : ShouldRelateToTypesThat, + IInterfacePredicates + where TRuleType : ICanBeAnalyzed { - public ShouldRelateToInterfacesThat(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public ShouldRelateToInterfacesThat(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/ShouldRelateToTypesThat.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/ShouldRelateToTypesThat.cs index 2574619ee..aa4a668ee 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/ShouldRelateToTypesThat.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/ShouldRelateToTypesThat.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -12,374 +12,525 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Types { - public class ShouldRelateToTypesThat : - ShouldRelateToObjectsThat, - ITypePredicates + public class ShouldRelateToTypesThat + : ShouldRelateToObjectsThat, + ITypePredicates where TReferenceType : IType where TRuleType : ICanBeAnalyzed { // ReSharper disable once MemberCanBeProtected.Global - public ShouldRelateToTypesThat(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public ShouldRelateToTypesThat(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } public TRuleTypeShouldConjunction Are(Type firstType, params Type[] moreTypes) { - _ruleCreator.ContinueComplexCondition(TypePredicatesDefinition.Are(firstType, moreTypes)); + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.Are(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction Are(IEnumerable types) { - _ruleCreator.ContinueComplexCondition(TypePredicatesDefinition.Are(types)); + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.Are(types) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction AreAssignableTo(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction AreAssignableTo( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.AreAssignableTo(pattern, useRegularExpressions)); + TypePredicatesDefinition.AreAssignableTo( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction AreAssignableTo(IEnumerable patterns, - bool useRegularExpressions = false) + public TRuleTypeShouldConjunction AreAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.AreAssignableTo(patterns, useRegularExpressions)); + TypePredicatesDefinition.AreAssignableTo( + patterns, + useRegularExpressions + ) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreAssignableTo(IType firstType, params IType[] moreTypes) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.AreAssignableTo(firstType, moreTypes)); + TypePredicatesDefinition.AreAssignableTo(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreAssignableTo(Type firstType, params Type[] moreTypes) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.AreAssignableTo(firstType, moreTypes)); + TypePredicatesDefinition.AreAssignableTo(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreAssignableTo(IObjectProvider types) { - _ruleCreator.ContinueComplexCondition(TypePredicatesDefinition.AreAssignableTo(types)); + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.AreAssignableTo(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreAssignableTo(IEnumerable types) { - _ruleCreator.ContinueComplexCondition(TypePredicatesDefinition.AreAssignableTo(types)); + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.AreAssignableTo(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreAssignableTo(IEnumerable types) { - _ruleCreator.ContinueComplexCondition(TypePredicatesDefinition.AreAssignableTo(types)); + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.AreAssignableTo(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNestedIn(IType firstType, params IType[] moreTypes) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.AreNestedIn(firstType, moreTypes)); + TypePredicatesDefinition.AreNestedIn(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNestedIn(Type firstType, params Type[] moreTypes) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.AreNestedIn(firstType, moreTypes)); + TypePredicatesDefinition.AreNestedIn(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNestedIn(IObjectProvider types) { - _ruleCreator.ContinueComplexCondition(TypePredicatesDefinition.AreNestedIn(types)); + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.AreNestedIn(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNestedIn(IEnumerable types) { - _ruleCreator.ContinueComplexCondition(TypePredicatesDefinition.AreNestedIn(types)); + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.AreNestedIn(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNestedIn(IEnumerable types) { - _ruleCreator.ContinueComplexCondition(TypePredicatesDefinition.AreNestedIn(types)); + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.AreNestedIn(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreValueTypes() { - _ruleCreator.ContinueComplexCondition(TypePredicatesDefinition.AreValueTypes()); + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.AreValueTypes() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreEnums() { - _ruleCreator.ContinueComplexCondition(TypePredicatesDefinition.AreEnums()); + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.AreEnums() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreStructs() { - _ruleCreator.ContinueComplexCondition(TypePredicatesDefinition.AreStructs()); + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.AreStructs() + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction ImplementInterface(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction ImplementInterface( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.ImplementInterface(pattern, useRegularExpressions)); + TypePredicatesDefinition.ImplementInterface( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction ImplementInterface(Interface intf) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.ImplementInterface(intf)); + TypePredicatesDefinition.ImplementInterface(intf) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction ImplementInterface(Type intf) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.ImplementInterface(intf)); + TypePredicatesDefinition.ImplementInterface(intf) + ); return Create(_ruleCreator); } - - public TRuleTypeShouldConjunction ResideInNamespace(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction ResideInNamespace( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.ResideInNamespace(pattern, useRegularExpressions)); + TypePredicatesDefinition.ResideInNamespace( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction ResideInAssembly(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction ResideInAssembly( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.ResideInAssembly(pattern, useRegularExpressions)); + TypePredicatesDefinition.ResideInAssembly( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction ResideInAssembly(Assembly assembly, params Assembly[] moreAssemblies) + public TRuleTypeShouldConjunction ResideInAssembly( + Assembly assembly, + params Assembly[] moreAssemblies + ) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.ResideInAssembly(assembly, moreAssemblies)); + TypePredicatesDefinition.ResideInAssembly(assembly, moreAssemblies) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction ResideInAssembly(Domain.Assembly assembly, - params Domain.Assembly[] moreAssemblies) + public TRuleTypeShouldConjunction ResideInAssembly( + Domain.Assembly assembly, + params Domain.Assembly[] moreAssemblies + ) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.ResideInAssembly(assembly, moreAssemblies)); + TypePredicatesDefinition.ResideInAssembly(assembly, moreAssemblies) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HavePropertyMemberWithName(string name) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.HaveMethodMemberWithName(name)); + TypePredicatesDefinition.HaveMethodMemberWithName(name) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveFieldMemberWithName(string name) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.HaveFieldMemberWithName(name)); + TypePredicatesDefinition.HaveFieldMemberWithName(name) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveMethodMemberWithName(string name) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.HaveFieldMemberWithName(name)); + TypePredicatesDefinition.HaveFieldMemberWithName(name) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveMemberWithName(string name) { - _ruleCreator.ContinueComplexCondition(TypePredicatesDefinition.HaveMemberWithName(name)); + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.HaveMemberWithName(name) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNested() { - _ruleCreator.ContinueComplexCondition(TypePredicatesDefinition.AreNested()); + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.AreNested() + ); return Create(_ruleCreator); } - //Negations public TRuleTypeShouldConjunction AreNot(Type firstType, params Type[] moreTypes) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.AreNot(firstType, moreTypes)); + TypePredicatesDefinition.AreNot(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNot(IEnumerable types) { - _ruleCreator.ContinueComplexCondition(TypePredicatesDefinition.AreNot(types)); + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.AreNot(types) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction AreNotAssignableTo(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction AreNotAssignableTo( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.AreNotAssignableTo(pattern, useRegularExpressions)); + TypePredicatesDefinition.AreNotAssignableTo( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction AreNotAssignableTo(IEnumerable patterns, - bool useRegularExpressions = false) + public TRuleTypeShouldConjunction AreNotAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.AreNotAssignableTo(patterns, useRegularExpressions)); + TypePredicatesDefinition.AreNotAssignableTo( + patterns, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction AreNotAssignableTo(IType firstType, params IType[] moreTypes) + public TRuleTypeShouldConjunction AreNotAssignableTo( + IType firstType, + params IType[] moreTypes + ) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.AreNotAssignableTo(firstType, moreTypes)); + TypePredicatesDefinition.AreNotAssignableTo(firstType, moreTypes) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction AreNotAssignableTo(Type firstType, params Type[] moreTypes) + public TRuleTypeShouldConjunction AreNotAssignableTo( + Type firstType, + params Type[] moreTypes + ) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.AreNotAssignableTo(firstType, moreTypes)); + TypePredicatesDefinition.AreNotAssignableTo(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNotAssignableTo(IObjectProvider types) { - _ruleCreator.ContinueComplexCondition(TypePredicatesDefinition.AreNotAssignableTo(types)); + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.AreNotAssignableTo(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNotAssignableTo(IEnumerable types) { - _ruleCreator.ContinueComplexCondition(TypePredicatesDefinition.AreNotAssignableTo(types)); + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.AreNotAssignableTo(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNotAssignableTo(IEnumerable types) { - _ruleCreator.ContinueComplexCondition(TypePredicatesDefinition.AreNotAssignableTo(types)); + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.AreNotAssignableTo(types) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNotValueTypes() { - _ruleCreator.ContinueComplexCondition(TypePredicatesDefinition.AreNotValueTypes()); + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.AreNotValueTypes() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNotEnums() { - _ruleCreator.ContinueComplexCondition(TypePredicatesDefinition.AreNotEnums()); + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.AreNotEnums() + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNotStructs() { - _ruleCreator.ContinueComplexCondition(TypePredicatesDefinition.AreNotStructs()); + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.AreNotStructs() + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotImplementInterface(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction DoNotImplementInterface( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.DoNotImplementInterface(pattern, useRegularExpressions)); + TypePredicatesDefinition.DoNotImplementInterface( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotImplementInterface(Interface intf) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.DoNotImplementInterface(intf)); + TypePredicatesDefinition.DoNotImplementInterface(intf) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotImplementInterface(Type intf) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.DoNotImplementInterface(intf)); + TypePredicatesDefinition.DoNotImplementInterface(intf) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotResideInNamespace(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction DoNotResideInNamespace( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.DoNotResideInNamespace(pattern, useRegularExpressions)); + TypePredicatesDefinition.DoNotResideInNamespace( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotResideInAssembly(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction DoNotResideInAssembly( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.DoNotResideInAssembly(pattern, useRegularExpressions)); + TypePredicatesDefinition.DoNotResideInAssembly( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotResideInAssembly(Assembly assembly, params Assembly[] moreAssemblies) + public TRuleTypeShouldConjunction DoNotResideInAssembly( + Assembly assembly, + params Assembly[] moreAssemblies + ) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.DoNotResideInAssembly(assembly, moreAssemblies)); + TypePredicatesDefinition.DoNotResideInAssembly( + assembly, + moreAssemblies + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction DoNotResideInAssembly(Domain.Assembly assembly, - params Domain.Assembly[] moreAssemblies) + public TRuleTypeShouldConjunction DoNotResideInAssembly( + Domain.Assembly assembly, + params Domain.Assembly[] moreAssemblies + ) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.DoNotResideInAssembly(assembly, moreAssemblies)); + TypePredicatesDefinition.DoNotResideInAssembly( + assembly, + moreAssemblies + ) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotHavePropertyMemberWithName(string name) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.DoNotHavePropertyMemberWithName(name)); + TypePredicatesDefinition.DoNotHavePropertyMemberWithName(name) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotHaveFieldMemberWithName(string name) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.DoNotHaveFieldMemberWithName(name)); + TypePredicatesDefinition.DoNotHaveFieldMemberWithName(name) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotHaveMethodMemberWithName(string name) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.DoNotHaveMethodMemberWithName(name)); + TypePredicatesDefinition.DoNotHaveMethodMemberWithName(name) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction DoNotHaveMemberWithName(string name) { _ruleCreator.ContinueComplexCondition( - TypePredicatesDefinition.DoNotHaveMethodMemberWithName(name)); + TypePredicatesDefinition.DoNotHaveMethodMemberWithName(name) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AreNotNested() { - _ruleCreator.ContinueComplexCondition(TypePredicatesDefinition.AreNotNested()); + _ruleCreator.ContinueComplexCondition( + TypePredicatesDefinition.AreNotNested() + ); return Create(_ruleCreator); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypeConditionsDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypeConditionsDefinition.cs index cc7b7f3b1..9c9e7286a 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypeConditionsDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypeConditionsDefinition.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -17,11 +17,12 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Types { - public static class TypeConditionsDefinition where TRuleType : IType + public static class TypeConditionsDefinition + where TRuleType : IType { public static ICondition Be(Type firstType, params Type[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return Be(types); } @@ -30,7 +31,10 @@ public static ICondition Be(IEnumerable types) { var typeList = types.ToList(); - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var archUnitTypeList = new List(); foreach (var type in typeList) @@ -47,10 +51,17 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite } var ruleTypeList = ruleTypes.ToList(); - var passedObjects = ruleTypeList.OfType().Intersect(archUnitTypeList).ToList(); + var passedObjects = ruleTypeList + .OfType() + .Intersect(archUnitTypeList) + .ToList(); foreach (var failedObject in ruleTypeList.Cast().Except(passedObjects)) { - yield return new ConditionResult(failedObject, false, "is " + failedObject.FullName); + yield return new ConditionResult( + failedObject, + false, + "is " + failedObject.FullName + ); } foreach (var passedObject in passedObjects) @@ -67,32 +78,54 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite else { var firstType = typeList.First(); - description = typeList.Where(type => type != firstType).Distinct().Aggregate( - "be \"" + firstType.FullName + "\"", (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => type != firstType) + .Distinct() + .Aggregate( + "be \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } - return new ArchitectureCondition(Condition, description); } - public static ICondition BeAssignableTo(string pattern, bool useRegularExpressions = false) + public static ICondition BeAssignableTo( + string pattern, + bool useRegularExpressions = false + ) { - var description = "be assignable to types with full name " + - (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\""; - var failDescription = "is not assignable to a type with full name " + - (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\""; - return new SimpleCondition(type => type.IsAssignableTo(pattern, useRegularExpressions), - description, failDescription); + var description = + "be assignable to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\""; + var failDescription = + "is not assignable to a type with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\""; + return new SimpleCondition( + type => type.IsAssignableTo(pattern, useRegularExpressions), + description, + failDescription + ); } - public static ICondition BeAssignableTo(IEnumerable patterns, - bool useRegularExpressions = false) + public static ICondition BeAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Condition(TRuleType ruleType) { - return patternList.Any(pattern => ruleType.IsAssignableTo(pattern, useRegularExpressions)); + return patternList.Any(pattern => + ruleType.IsAssignableTo(pattern, useRegularExpressions) + ); } string description; @@ -105,40 +138,61 @@ bool Condition(TRuleType ruleType) else { var firstPattern = patternList.First(); - description = patternList.Where(type => !type.Equals(firstPattern)).Distinct().Aggregate( - "be assignable to types with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", - (current, pattern) => current + " or \"" + pattern + "\""); - failDescription = patternList.Where(type => !type.Equals(firstPattern)).Distinct().Aggregate( - "is not assignable to types with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", - (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "be assignable to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); + failDescription = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "is not assignable to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimpleCondition(Condition, description, failDescription); } - public static ICondition BeAssignableTo(IType firstType, params IType[] moreTypes) + public static ICondition BeAssignableTo( + IType firstType, + params IType[] moreTypes + ) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return BeAssignableTo(types); } public static ICondition BeAssignableTo(Type firstType, params Type[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return BeAssignableTo(types); } public static ICondition BeAssignableTo(IObjectProvider objectProvider) { - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var typeList = objectProvider.GetObjects(architecture).ToList(); var ruleTypeList = ruleTypes.ToList(); - var passedObjects = ruleTypeList.Where(type => type.GetAssignableTypes().Intersect(typeList).Any()) + var passedObjects = ruleTypeList + .Where(type => type.GetAssignableTypes().Intersect(typeList).Any()) .ToList(); var failDescription = "is not assignable to " + objectProvider.Description; foreach (var failedObject in ruleTypeList.Except(passedObjects)) @@ -164,7 +218,8 @@ public static ICondition BeAssignableTo(IEnumerable types) IEnumerable Condition(IEnumerable ruleTypes) { var ruleTypeList = ruleTypes.ToList(); - var passedObjects = ruleTypeList.Where(type => type.GetAssignableTypes().Intersect(typeList).Any()) + var passedObjects = ruleTypeList + .Where(type => type.GetAssignableTypes().Intersect(typeList).Any()) .ToList(); string failDescription; if (typeList.IsNullOrEmpty()) @@ -173,9 +228,13 @@ IEnumerable Condition(IEnumerable ruleTypes) } else { - failDescription = typeList.Where(type => !type.Equals(firstType)).Distinct().Aggregate( - "is not assignable to \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + failDescription = typeList + .Where(type => !type.Equals(firstType)) + .Distinct() + .Aggregate( + "is not assignable to \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } foreach (var failedObject in ruleTypeList.Except(passedObjects)) @@ -196,9 +255,13 @@ IEnumerable Condition(IEnumerable ruleTypes) } else { - description = typeList.Where(type => !type.Equals(firstType)).Distinct().Aggregate( - "be assignable to \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => !type.Equals(firstType)) + .Distinct() + .Aggregate( + "be assignable to \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new EnumerableCondition(Condition, description); @@ -209,7 +272,10 @@ public static ICondition BeAssignableTo(IEnumerable types) var typeList = types.ToList(); var firstType = typeList.First(); - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var archUnitTypeList = new List(); foreach (var type in typeList) @@ -236,9 +302,13 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite } else { - failDescription = typeList.Where(type => type != firstType).Distinct().Aggregate( - "is not assignable to \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + failDescription = typeList + .Where(type => type != firstType) + .Distinct() + .Aggregate( + "is not assignable to \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } foreach (var failedObject in ruleTypeList.Except(passedObjects)) @@ -259,9 +329,13 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite } else { - description = typeList.Where(type => type != firstType).Distinct().Aggregate( - "be assignable to \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => type != firstType) + .Distinct() + .Aggregate( + "be assignable to \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new ArchitectureCondition(Condition, description); @@ -269,26 +343,34 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite public static ICondition BeNestedIn(IType firstType, params IType[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return BeNestedIn(types); } public static ICondition BeNestedIn(Type firstType, params Type[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return BeNestedIn(types); } public static ICondition BeNestedIn(IObjectProvider objectProvider) { - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var typeList = objectProvider.GetObjects(architecture).ToList(); var ruleTypeList = ruleTypes.ToList(); - var passedObjects = ruleTypeList.Where(type => typeList.Any(outerType - => type.FullName.StartsWith(outerType.FullName + "+"))).ToList(); + var passedObjects = ruleTypeList + .Where(type => + typeList.Any(outerType => + type.FullName.StartsWith(outerType.FullName + "+") + ) + ) + .ToList(); var failDescription = "is not nested in " + objectProvider.Description; foreach (var failedObject in ruleTypeList.Except(passedObjects)) { @@ -313,8 +395,13 @@ public static ICondition BeNestedIn(IEnumerable types) IEnumerable Condition(IEnumerable ruleTypes) { var ruleTypeList = ruleTypes.ToList(); - var passedObjects = ruleTypeList.Where(type => typeList.Any(outerType - => type.FullName.StartsWith(outerType.FullName + "+"))).ToList(); + var passedObjects = ruleTypeList + .Where(type => + typeList.Any(outerType => + type.FullName.StartsWith(outerType.FullName + "+") + ) + ) + .ToList(); string failDescription; if (typeList.IsNullOrEmpty()) { @@ -322,9 +409,13 @@ IEnumerable Condition(IEnumerable ruleTypes) } else { - failDescription = typeList.Where(type => !type.Equals(firstType)).Distinct().Aggregate( - "is not nested in \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + failDescription = typeList + .Where(type => !type.Equals(firstType)) + .Distinct() + .Aggregate( + "is not nested in \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } foreach (var failedObject in ruleTypeList.Except(passedObjects)) @@ -345,9 +436,13 @@ IEnumerable Condition(IEnumerable ruleTypes) } else { - description = typeList.Where(type => !type.Equals(firstType)).Distinct().Aggregate( - "be nested in \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => !type.Equals(firstType)) + .Distinct() + .Aggregate( + "be nested in \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new EnumerableCondition(Condition, description); @@ -358,11 +453,19 @@ public static ICondition BeNestedIn(IEnumerable types) var typeList = types.ToList(); var firstType = typeList.First(); - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var ruleTypeList = ruleTypes.ToList(); - var passedObjects = ruleTypeList.Where(type => typeList.Any(outerType - => type.FullName.StartsWith(outerType.FullName + "+"))).ToList(); + var passedObjects = ruleTypeList + .Where(type => + typeList.Any(outerType => + type.FullName.StartsWith(outerType.FullName + "+") + ) + ) + .ToList(); string failDescription; if (typeList.IsNullOrEmpty()) { @@ -370,9 +473,13 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite } else { - failDescription = typeList.Where(type => type != firstType).Distinct().Aggregate( - "is not nested in \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + failDescription = typeList + .Where(type => type != firstType) + .Distinct() + .Aggregate( + "is not nested in \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } foreach (var failedObject in ruleTypeList.Except(passedObjects)) @@ -393,9 +500,13 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite } else { - description = typeList.Where(type => type != firstType).Distinct().Aggregate( - "be nested in \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => type != firstType) + .Distinct() + .Aggregate( + "be nested in \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new ArchitectureCondition(Condition, description); @@ -403,8 +514,11 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite public static ICondition BeValueTypes() { - return new SimpleCondition(type => type is Enum || type is Struct, "be value types", - "is no value type"); + return new SimpleCondition( + type => type is Enum || type is Struct, + "be value types", + "is no value type" + ); } public static ICondition BeEnums() @@ -414,17 +528,31 @@ public static ICondition BeEnums() public static ICondition BeStructs() { - return new SimpleCondition(type => type is Struct, "be structs", "is no struct"); + return new SimpleCondition( + type => type is Struct, + "be structs", + "is no struct" + ); } - public static ICondition ImplementInterface(string pattern, bool useRegularExpressions = false) + public static ICondition ImplementInterface( + string pattern, + bool useRegularExpressions = false + ) { return new SimpleCondition( type => type.ImplementsInterface(pattern, useRegularExpressions), - "implement interface with full name " + (useRegularExpressions ? "matching " : "") + "\"" + - pattern + "\"", - "does not implement interface with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + pattern + "\""); + "implement interface with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"", + "does not implement interface with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } public static ICondition ImplementInterface(Interface intf) @@ -432,12 +560,16 @@ public static ICondition ImplementInterface(Interface intf) return new SimpleCondition( type => type.ImplementsInterface(intf), "implement interface \"" + intf.FullName + "\"", - "does not implement interface \"" + intf.FullName + "\""); + "does not implement interface \"" + intf.FullName + "\"" + ); } public static ICondition ImplementInterface(Type intf) { - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var ruleTypeList = ruleTypes.ToList(); Interface archUnitInterface = null; @@ -456,19 +588,27 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite { foreach (var ruleType in ruleTypeList) { - yield return new ConditionResult(ruleType, false, - "does not implement interface \"" + intf.FullName + "\""); + yield return new ConditionResult( + ruleType, + false, + "does not implement interface \"" + intf.FullName + "\"" + ); } yield break; } - var passedObjects = ruleTypeList.Where(type => type.ImplementsInterface(archUnitInterface)).ToList(); + var passedObjects = ruleTypeList + .Where(type => type.ImplementsInterface(archUnitInterface)) + .ToList(); foreach (var failedObject in ruleTypeList.Except(passedObjects)) { - yield return new ConditionResult(failedObject, false, - "does not implement interface \"" + intf.FullName + "\""); + yield return new ConditionResult( + failedObject, + false, + "does not implement interface \"" + intf.FullName + "\"" + ); } foreach (var passedObject in passedObjects) @@ -477,63 +617,99 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite } } - return new ArchitectureCondition(Condition, "implement interface \"" + intf.FullName + "\""); + return new ArchitectureCondition( + Condition, + "implement interface \"" + intf.FullName + "\"" + ); } - public static ICondition ResideInNamespace(string pattern, bool useRegularExpressions = false) + public static ICondition ResideInNamespace( + string pattern, + bool useRegularExpressions = false + ) { return new SimpleCondition( type => type.ResidesInNamespace(pattern, useRegularExpressions), obj => "does reside in " + obj.Namespace.FullName, - "reside in namespace with full name " + (useRegularExpressions ? "matching " : "") + "\"" + - pattern + "\""); + "reside in namespace with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static ICondition ResideInAssembly(string pattern, bool useRegularExpressions = false) + public static ICondition ResideInAssembly( + string pattern, + bool useRegularExpressions = false + ) { return new SimpleCondition( type => type.ResidesInAssembly(pattern, useRegularExpressions), obj => "does reside in " + obj.Assembly.FullName, - "reside in assembly with full name " + (useRegularExpressions ? "matching " : "") + "\"" + - pattern + "\""); + "reside in assembly with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static ICondition ResideInAssembly(System.Reflection.Assembly assembly, - params System.Reflection.Assembly[] moreAssemblies) + public static ICondition ResideInAssembly( + System.Reflection.Assembly assembly, + params System.Reflection.Assembly[] moreAssemblies + ) { bool Condition(TRuleType ruleType, Architecture architecture) { - return ruleType.Assembly.Equals(architecture.GetAssemblyOfAssembly(assembly)) || - moreAssemblies.Any(asm => ruleType.Assembly.Equals(architecture.GetAssemblyOfAssembly(asm))); + return ruleType.Assembly.Equals(architecture.GetAssemblyOfAssembly(assembly)) + || moreAssemblies.Any(asm => + ruleType.Assembly.Equals(architecture.GetAssemblyOfAssembly(asm)) + ); } - var description = moreAssemblies.Aggregate("reside in assembly \"" + assembly.FullName + "\"", - (current, asm) => current + " or \"" + asm.FullName + "\""); + var description = moreAssemblies.Aggregate( + "reside in assembly \"" + assembly.FullName + "\"", + (current, asm) => current + " or \"" + asm.FullName + "\"" + ); - return new ArchitectureCondition(Condition, - (type, architecture) => "does reside in " + type.Assembly.FullName, description); + return new ArchitectureCondition( + Condition, + (type, architecture) => "does reside in " + type.Assembly.FullName, + description + ); } - public static ICondition ResideInAssembly(Assembly assembly, Assembly[] moreAssemblies) + public static ICondition ResideInAssembly( + Assembly assembly, + Assembly[] moreAssemblies + ) { bool Condition(TRuleType ruleType) { - var assemblies = new[] {assembly}.Concat(moreAssemblies); + var assemblies = new[] { assembly }.Concat(moreAssemblies); return assemblies.Contains(ruleType.Assembly); } - var description = moreAssemblies.Aggregate("reside in assembly \"" + assembly.FullName + "\"", - (current, asm) => current + " or \"" + asm.FullName + "\""); + var description = moreAssemblies.Aggregate( + "reside in assembly \"" + assembly.FullName + "\"", + (current, asm) => current + " or \"" + asm.FullName + "\"" + ); - return new SimpleCondition(Condition, type => "does reside in " + type.Assembly.FullName, - description); + return new SimpleCondition( + Condition, + type => "does reside in " + type.Assembly.FullName, + description + ); } public static ICondition HavePropertyMemberWithName(string name) { - return new SimpleCondition(type => type.HasPropertyMemberWithName(name), + return new SimpleCondition( + type => type.HasPropertyMemberWithName(name), "have a property member with name \"" + name + "\"", - "does not have a property member with name \"" + name + "\""); + "does not have a property member with name \"" + name + "\"" + ); } public static ICondition AdhereToPlantUmlDiagram(Stream stream) @@ -561,23 +737,33 @@ ConditionResult Condition(TRuleType ruleType) List allAllowedTargets = new List(); - allAllowedTargets.AddRange(classDiagramAssociation.GetNamespaceIdentifiersFromComponentOf(ruleType) - .Concat(classDiagramAssociation.GetTargetNamespaceIdentifiers(ruleType)) - .ToList()); - + allAllowedTargets.AddRange( + classDiagramAssociation + .GetNamespaceIdentifiersFromComponentOf(ruleType) + .Concat(classDiagramAssociation.GetTargetNamespaceIdentifiers(ruleType)) + .ToList() + ); var pass = true; var dynamicFailDescription = "does depend on"; //Prevent failDescriptions like "does depend on X and does depend on X and does depend on Y and does depend on Y - var ruleTypeDependencies = - ruleType.GetTypeDependencies().GroupBy(p => p.FullName).Select(g => g.First()); + var ruleTypeDependencies = ruleType + .GetTypeDependencies() + .GroupBy(p => p.FullName) + .Select(g => g.First()); foreach (var dependency in ruleTypeDependencies) { - if (classDiagramAssociation.Contains(dependency) - && !allAllowedTargets.Any(pattern => dependency.FullNameMatches(pattern, true))) + if ( + classDiagramAssociation.Contains(dependency) + && !allAllowedTargets.Any(pattern => + dependency.FullNameMatches(pattern, true) + ) + ) { - dynamicFailDescription += pass ? " " + dependency.FullName : " and " + dependency.FullName; + dynamicFailDescription += pass + ? " " + dependency.FullName + : " and " + dependency.FullName; pass = false; } @@ -592,46 +778,57 @@ ConditionResult Condition(TRuleType ruleType) public static ICondition HaveFieldMemberWithName(string name) { return new SimpleCondition( - type => type.HasFieldMemberWithName(name), "have a field member with name \"" + name + "\"", - "does not have a field member with name \"" + name + "\""); + type => type.HasFieldMemberWithName(name), + "have a field member with name \"" + name + "\"", + "does not have a field member with name \"" + name + "\"" + ); } public static ICondition HaveMethodMemberWithName(string name) { - return new SimpleCondition(type => type.HasMethodMemberWithName(name), + return new SimpleCondition( + type => type.HasMethodMemberWithName(name), "have a method member with name \"" + name + "\"", - "does not have a method member with name \"" + name + "\""); + "does not have a method member with name \"" + name + "\"" + ); } public static ICondition HaveMemberWithName(string name) { return new SimpleCondition( - type => type.HasMemberWithName(name), "have a member with name \"" + name + "\"", - "does not have a member with name \"" + name + "\""); + type => type.HasMemberWithName(name), + "have a member with name \"" + name + "\"", + "does not have a member with name \"" + name + "\"" + ); } public static ICondition BeNested() { - return new SimpleCondition(type => type.IsNested, "be nested", "is not nested"); + return new SimpleCondition( + type => type.IsNested, + "be nested", + "is not nested" + ); } - //Relation Conditions public static RelationCondition BeAssignableToTypesThat() { - return new RelationCondition(BeAssignableTo, "be assignable to types that", - "is not assignable to types that"); + return new RelationCondition( + BeAssignableTo, + "be assignable to types that", + "is not assignable to types that" + ); } - //Negations public static ICondition NotBe(Type firstType, params Type[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return NotBe(types); } @@ -640,7 +837,10 @@ public static ICondition NotBe(IEnumerable types) { var typeList = types.ToList(); - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var archUnitTypeList = new List(); foreach (var type in typeList) @@ -657,10 +857,17 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite } var ruleTypeList = ruleTypes.ToList(); - var failedObjects = ruleTypeList.OfType().Intersect(archUnitTypeList).ToList(); + var failedObjects = ruleTypeList + .OfType() + .Intersect(archUnitTypeList) + .ToList(); foreach (var failedObject in failedObjects) { - yield return new ConditionResult(failedObject, false, "is " + failedObject.FullName); + yield return new ConditionResult( + failedObject, + false, + "is " + failedObject.FullName + ); } foreach (var passedObject in ruleTypeList.Cast().Except(failedObjects)) @@ -677,15 +884,22 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite else { var firstType = typeList.First(); - description = typeList.Where(type => type != firstType).Distinct().Aggregate( - "not be \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => type != firstType) + .Distinct() + .Aggregate( + "not be \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new ArchitectureCondition(Condition, description); } - public static ICondition NotBeAssignableTo(string pattern, bool useRegularExpressions = false) + public static ICondition NotBeAssignableTo( + string pattern, + bool useRegularExpressions = false + ) { ConditionResult Condition(TRuleType ruleType) { @@ -703,13 +917,19 @@ ConditionResult Condition(TRuleType ruleType) return new ConditionResult(ruleType, pass, dynamicFailDescription); } - var description = "not be assignable to types with full name " + - (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\""; + var description = + "not be assignable to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\""; return new SimpleCondition(Condition, description); } - public static ICondition NotBeAssignableTo(IEnumerable patterns, - bool useRegularExpressions = false) + public static ICondition NotBeAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); @@ -719,7 +939,11 @@ ConditionResult Condition(TRuleType ruleType) var dynamicFailDescription = "is assignable to"; foreach (var type in ruleType.GetAssignableTypes()) { - if (patternList.Any(pattern => type.FullNameMatches(pattern, useRegularExpressions))) + if ( + patternList.Any(pattern => + type.FullNameMatches(pattern, useRegularExpressions) + ) + ) { dynamicFailDescription += (pass ? " " : " and ") + type.FullName; pass = false; @@ -737,35 +961,53 @@ ConditionResult Condition(TRuleType ruleType) else { var firstPattern = patternList.First(); - description = patternList.Where(type => !type.Equals(firstPattern)).Distinct().Aggregate( - "not be assignable to types with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "not be assignable to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimpleCondition(Condition, description); } - public static ICondition NotBeAssignableTo(IType firstType, params IType[] moreTypes) + public static ICondition NotBeAssignableTo( + IType firstType, + params IType[] moreTypes + ) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return NotBeAssignableTo(types); } - public static ICondition NotBeAssignableTo(Type firstType, params Type[] moreTypes) + public static ICondition NotBeAssignableTo( + Type firstType, + params Type[] moreTypes + ) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return NotBeAssignableTo(types); } public static ICondition NotBeAssignableTo(IObjectProvider objectProvider) { - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var typeList = objectProvider.GetObjects(architecture).ToList(); var ruleTypeList = ruleTypes.ToList(); - var failedObjects = ruleTypeList.Where(type => type.GetAssignableTypes().Intersect(typeList).Any()) + var failedObjects = ruleTypeList + .Where(type => type.GetAssignableTypes().Intersect(typeList).Any()) .ToList(); var failDescription = "is assignable to " + objectProvider.Description; foreach (var failedObject in failedObjects) @@ -791,7 +1033,8 @@ public static ICondition NotBeAssignableTo(IEnumerable types) IEnumerable Condition(IEnumerable ruleTypes) { var ruleTypeList = ruleTypes.ToList(); - var failedObjects = ruleTypeList.Where(type => type.GetAssignableTypes().Intersect(typeList).Any()) + var failedObjects = ruleTypeList + .Where(type => type.GetAssignableTypes().Intersect(typeList).Any()) .ToList(); string dynamicFailDescription; if (typeList.IsNullOrEmpty()) @@ -799,7 +1042,11 @@ IEnumerable Condition(IEnumerable ruleTypes) dynamicFailDescription = "is assignable to any type (always true)"; foreach (var failedObject in failedObjects) { - yield return new ConditionResult(failedObject, false, dynamicFailDescription); + yield return new ConditionResult( + failedObject, + false, + dynamicFailDescription + ); } } else @@ -810,11 +1057,17 @@ IEnumerable Condition(IEnumerable ruleTypes) var first = true; foreach (var type in failedObject.GetAssignableTypes().Intersect(typeList)) { - dynamicFailDescription += first ? " " + type.FullName : " and " + type.FullName; + dynamicFailDescription += first + ? " " + type.FullName + : " and " + type.FullName; first = false; } - yield return new ConditionResult(failedObject, false, dynamicFailDescription); + yield return new ConditionResult( + failedObject, + false, + dynamicFailDescription + ); } } @@ -831,9 +1084,13 @@ IEnumerable Condition(IEnumerable ruleTypes) } else { - description = typeList.Where(type => !type.Equals(firstType)).Distinct().Aggregate( - "not be assignable to \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => !type.Equals(firstType)) + .Distinct() + .Aggregate( + "not be assignable to \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new EnumerableCondition(Condition, description); @@ -844,7 +1101,10 @@ public static ICondition NotBeAssignableTo(IEnumerable types) var typeList = types.ToList(); var firstType = typeList.First(); - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var archUnitTypeList = new List(); foreach (var type in typeList) @@ -870,7 +1130,11 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite dynamicFailDescription = "is assignable to any type (always true)"; foreach (var failedObject in failedObjects) { - yield return new ConditionResult(failedObject, false, dynamicFailDescription); + yield return new ConditionResult( + failedObject, + false, + dynamicFailDescription + ); } } else @@ -879,13 +1143,23 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite { dynamicFailDescription = "is assignable to"; var first = true; - foreach (var type in failedObject.GetAssignableTypes().Intersect(archUnitTypeList)) + foreach ( + var type in failedObject + .GetAssignableTypes() + .Intersect(archUnitTypeList) + ) { - dynamicFailDescription += first ? " " + type.FullName : " and " + type.FullName; + dynamicFailDescription += first + ? " " + type.FullName + : " and " + type.FullName; first = false; } - yield return new ConditionResult(failedObject, false, dynamicFailDescription); + yield return new ConditionResult( + failedObject, + false, + dynamicFailDescription + ); } } @@ -902,9 +1176,13 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite } else { - description = typeList.Where(type => type != firstType).Distinct().Aggregate( - "not be assignable to \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => type != firstType) + .Distinct() + .Aggregate( + "not be assignable to \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new ArchitectureCondition(Condition, description); @@ -912,27 +1190,49 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite public static ICondition NotBeValueTypes() { - return new SimpleCondition(type => !(type is Enum) && !(type is Struct), "not be value types", - "is a value type"); + return new SimpleCondition( + type => !(type is Enum) && !(type is Struct), + "not be value types", + "is a value type" + ); } public static ICondition NotBeEnums() { - return new SimpleCondition(type => !(type is Enum), "not be enums", "is an enum"); + return new SimpleCondition( + type => !(type is Enum), + "not be enums", + "is an enum" + ); } public static ICondition NotBeStructs() { - return new SimpleCondition(type => !(type is Struct), "not be structs", "is a struct"); + return new SimpleCondition( + type => !(type is Struct), + "not be structs", + "is a struct" + ); } - public static ICondition NotImplementInterface(string pattern, bool useRegularExpressions = false) + public static ICondition NotImplementInterface( + string pattern, + bool useRegularExpressions = false + ) { - return new SimpleCondition(type => !type.ImplementsInterface(pattern, useRegularExpressions), - "not implement interface with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + pattern + "\"", - "does implement interface with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + pattern + "\""); + return new SimpleCondition( + type => !type.ImplementsInterface(pattern, useRegularExpressions), + "not implement interface with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"", + "does implement interface with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } public static ICondition NotImplementInterface(Interface intf) @@ -940,12 +1240,16 @@ public static ICondition NotImplementInterface(Interface intf) return new SimpleCondition( type => !type.ImplementsInterface(intf), "not implement interface \"" + intf.FullName + "\"", - "does implement interface \"" + intf.FullName + "\""); + "does implement interface \"" + intf.FullName + "\"" + ); } public static ICondition NotImplementInterface(Type intf) { - IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) + IEnumerable Condition( + IEnumerable ruleTypes, + Architecture architecture + ) { var ruleTypeList = ruleTypes.ToList(); Interface archUnitInterface = null; @@ -970,12 +1274,17 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite yield break; } - var passedObjects = ruleTypeList.Where(type => !type.ImplementsInterface(archUnitInterface)).ToList(); + var passedObjects = ruleTypeList + .Where(type => !type.ImplementsInterface(archUnitInterface)) + .ToList(); foreach (var failedObject in ruleTypeList.Except(passedObjects)) { - yield return new ConditionResult(failedObject, false, - "does implement interface \"" + intf.FullName + "\""); + yield return new ConditionResult( + failedObject, + false, + "does implement interface \"" + intf.FullName + "\"" + ); } foreach (var passedObject in passedObjects) @@ -984,98 +1293,147 @@ IEnumerable Condition(IEnumerable ruleTypes, Archite } } - return new ArchitectureCondition(Condition, "not implement interface \"" + intf.FullName + "\""); + return new ArchitectureCondition( + Condition, + "not implement interface \"" + intf.FullName + "\"" + ); } - public static ICondition NotResideInNamespace(string pattern, bool useRegularExpressions = false) + public static ICondition NotResideInNamespace( + string pattern, + bool useRegularExpressions = false + ) { return new SimpleCondition( type => !type.ResidesInNamespace(pattern, useRegularExpressions), obj => "does reside in " + obj.Namespace.FullName, - "not reside in namespace with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + pattern + "\""); + "not reside in namespace with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static ICondition NotResideInAssembly(string pattern, bool useRegularExpressions = false) + public static ICondition NotResideInAssembly( + string pattern, + bool useRegularExpressions = false + ) { return new SimpleCondition( type => !type.ResidesInAssembly(pattern, useRegularExpressions), obj => "does reside in " + obj.Assembly.FullName, - "not reside in assembly with full name " + (useRegularExpressions ? "matching " : "") + "\"" + - pattern + "\""); + "not reside in assembly with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static ICondition NotResideInAssembly(System.Reflection.Assembly assembly, - params System.Reflection.Assembly[] moreAssemblies) + public static ICondition NotResideInAssembly( + System.Reflection.Assembly assembly, + params System.Reflection.Assembly[] moreAssemblies + ) { bool Condition(TRuleType ruleType, Architecture architecture) { - return !ruleType.Assembly.Equals(architecture.GetAssemblyOfAssembly(assembly)) && - !moreAssemblies.Any(asm => ruleType.Assembly.Equals(architecture.GetAssemblyOfAssembly(asm))); + return !ruleType.Assembly.Equals(architecture.GetAssemblyOfAssembly(assembly)) + && !moreAssemblies.Any(asm => + ruleType.Assembly.Equals(architecture.GetAssemblyOfAssembly(asm)) + ); } - var description = moreAssemblies.Aggregate("not reside in assembly \"" + assembly.FullName + "\"", - (current, asm) => current + " or \"" + asm.FullName + "\""); + var description = moreAssemblies.Aggregate( + "not reside in assembly \"" + assembly.FullName + "\"", + (current, asm) => current + " or \"" + asm.FullName + "\"" + ); - return new ArchitectureCondition(Condition, - (type, architecture) => "does reside in " + type.Assembly.FullName, description); + return new ArchitectureCondition( + Condition, + (type, architecture) => "does reside in " + type.Assembly.FullName, + description + ); } - - public static ICondition NotResideInAssembly(Assembly assembly, params Assembly[] moreAssemblies) + + public static ICondition NotResideInAssembly( + Assembly assembly, + params Assembly[] moreAssemblies + ) { bool Condition(TRuleType ruleType) { - var assemblies = new[] {assembly}.Concat(moreAssemblies); + var assemblies = new[] { assembly }.Concat(moreAssemblies); return !assemblies.Contains(ruleType.Assembly); } - var description = moreAssemblies.Aggregate("not reside in assembly \"" + assembly.FullName + "\"", - (current, asm) => current + " or \"" + asm.FullName + "\""); + var description = moreAssemblies.Aggregate( + "not reside in assembly \"" + assembly.FullName + "\"", + (current, asm) => current + " or \"" + asm.FullName + "\"" + ); - return new SimpleCondition(Condition, type => "does reside in " + type.Assembly.FullName, description); + return new SimpleCondition( + Condition, + type => "does reside in " + type.Assembly.FullName, + description + ); } public static ICondition NotHavePropertyMemberWithName(string name) { - return new SimpleCondition(type => !type.HasPropertyMemberWithName(name), + return new SimpleCondition( + type => !type.HasPropertyMemberWithName(name), "not have property member with name \"" + name + "\"", - "does have property member with name \"" + name + "\""); + "does have property member with name \"" + name + "\"" + ); } public static ICondition NotHaveFieldMemberWithName(string name) { - return new SimpleCondition(type => !type.HasFieldMemberWithName(name), + return new SimpleCondition( + type => !type.HasFieldMemberWithName(name), "not have field member with name \"" + name + "\"", - "does have field member with name \"" + name + "\""); + "does have field member with name \"" + name + "\"" + ); } public static ICondition NotHaveMethodMemberWithName(string name) { - return new SimpleCondition(type => !type.HasMethodMemberWithName(name), + return new SimpleCondition( + type => !type.HasMethodMemberWithName(name), "not have method member with name \"" + name + "\"", - "does have method member with name \"" + name + "\""); + "does have method member with name \"" + name + "\"" + ); } public static ICondition NotHaveMemberWithName(string name) { return new SimpleCondition( - type => !type.HasMemberWithName(name), "not have member with name \"" + name + "\"", - "does have member with name \"" + name + "\""); + type => !type.HasMemberWithName(name), + "not have member with name \"" + name + "\"", + "does have member with name \"" + name + "\"" + ); } public static ICondition NotBeNested() { - return new SimpleCondition(type => !type.IsNested, "not be nested", "is nested"); + return new SimpleCondition( + type => !type.IsNested, + "not be nested", + "is nested" + ); } - //Relation Condition Negations public static RelationCondition NotBeAssignableToTypesThat() { - return new RelationCondition(NotBeAssignableTo, "not be assignable to types that", - "is assignable to types that"); + return new RelationCondition( + NotBeAssignableTo, + "not be assignable to types that", + "is assignable to types that" + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypePredicatesDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypePredicatesDefinition.cs index 849be7d9f..8ab6851ac 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypePredicatesDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypePredicatesDefinition.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -16,11 +16,12 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Types { - public static class TypePredicatesDefinition where T : IType + public static class TypePredicatesDefinition + where T : IType { public static IPredicate Are(Type firstType, params Type[] moreTypes) { - var types = new List {firstType}; + var types = new List { firstType }; types.AddRange(moreTypes); return Are(types); } @@ -56,27 +57,47 @@ IEnumerable Filter(IEnumerable ruleTypes, Architecture architecture) else { var firstType = typeList.First(); - description = typeList.Where(obj => obj != firstType).Distinct().Aggregate( - "are \"" + firstType.FullName + "\"", (current, obj) => current + " or \"" + obj.FullName + "\""); + description = typeList + .Where(obj => obj != firstType) + .Distinct() + .Aggregate( + "are \"" + firstType.FullName + "\"", + (current, obj) => current + " or \"" + obj.FullName + "\"" + ); } return new ArchitecturePredicate(Filter, description); } - public static IPredicate AreAssignableTo(string pattern, bool useRegularExpressions = false) + public static IPredicate AreAssignableTo( + string pattern, + bool useRegularExpressions = false + ) { - var description = "are assignable to types with full name " + - (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\""; - return new SimplePredicate(type => type.IsAssignableTo(pattern, useRegularExpressions), description); + var description = + "are assignable to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\""; + return new SimplePredicate( + type => type.IsAssignableTo(pattern, useRegularExpressions), + description + ); } - public static IPredicate AreAssignableTo(IEnumerable patterns, bool useRegularExpressions = false) + public static IPredicate AreAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Condition(T ruleType) { - return patternList.Any(pattern => ruleType.IsAssignableTo(pattern, useRegularExpressions)); + return patternList.Any(pattern => + ruleType.IsAssignableTo(pattern, useRegularExpressions) + ); } string description; @@ -87,9 +108,17 @@ bool Condition(T ruleType) else { var firstPattern = patternList.First(); - description = patternList.Where(type => !type.Equals(firstPattern)).Distinct().Aggregate( - "are assignable to types with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "are assignable to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimplePredicate(Condition, description); @@ -99,12 +128,14 @@ public static IPredicate AreAssignableTo(IType firstType, params IType[] more { IEnumerable Condition(IEnumerable ruleTypes) { - var types = moreTypes.Concat(new[] {firstType}); + var types = moreTypes.Concat(new[] { firstType }); return ruleTypes.Where(type => type.GetAssignableTypes().Intersect(types).Any()); } - var description = moreTypes.Aggregate("are assignable to \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + var description = moreTypes.Aggregate( + "are assignable to \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); return new EnumerablePredicate(Condition, description); } @@ -112,12 +143,16 @@ public static IPredicate AreAssignableTo(Type firstType, params Type[] moreTy { IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) { - var types = moreTypes.Concat(new[] {firstType}).Select(architecture.GetITypeOfType); + var types = moreTypes + .Concat(new[] { firstType }) + .Select(architecture.GetITypeOfType); return ruleTypes.Where(type => type.GetAssignableTypes().Intersect(types).Any()); } - var description = moreTypes.Aggregate("are assignable to \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + var description = moreTypes.Aggregate( + "are assignable to \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); return new ArchitecturePredicate(Condition, description); } @@ -150,9 +185,13 @@ IEnumerable Condition(IEnumerable ruleTypes) else { var firstType = typeList.First(); - description = typeList.Where(type => !type.Equals(firstType)).Distinct().Aggregate( - "are assignable to \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => !type.Equals(firstType)) + .Distinct() + .Aggregate( + "are assignable to \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new EnumerablePredicate(Condition, description); @@ -178,7 +217,9 @@ IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) } } - return ruleTypes.Where(type => type.GetAssignableTypes().Intersect(archUnitTypeList).Any()); + return ruleTypes.Where(type => + type.GetAssignableTypes().Intersect(archUnitTypeList).Any() + ); } string description; @@ -189,10 +230,14 @@ IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) else { var firstType = typeList.First(); - description = typeList.Where(type => type != firstType).Distinct().Aggregate( - "are assignable to \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); - } + description = typeList + .Where(type => type != firstType) + .Distinct() + .Aggregate( + "are assignable to \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); + } return new ArchitecturePredicate(Condition, description); } @@ -200,13 +245,16 @@ public static IPredicate AreNestedIn(IType firstType, params IType[] moreType { IEnumerable Condition(IEnumerable ruleTypes) { - var types = moreTypes.Concat(new[] {firstType}); - return ruleTypes.Where(type => - types.Any(outerType => type.FullName.StartsWith(outerType.FullName + "+"))); + var types = moreTypes.Concat(new[] { firstType }); + return ruleTypes.Where(type => + types.Any(outerType => type.FullName.StartsWith(outerType.FullName + "+")) + ); } - var description = moreTypes.Aggregate("are nested in \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + var description = moreTypes.Aggregate( + "are nested in \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); return new EnumerablePredicate(Condition, description); } @@ -214,12 +262,17 @@ public static IPredicate AreNestedIn(Type firstType, params Type[] moreTypes) { IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) { - var types = moreTypes.Concat(new[] {firstType}).Select(architecture.GetITypeOfType); - return ruleTypes.Where(type => - types.Any(outerType => type.FullName.StartsWith(outerType.FullName + "+"))); - } - var description = moreTypes.Aggregate("are nested in \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + var types = moreTypes + .Concat(new[] { firstType }) + .Select(architecture.GetITypeOfType); + return ruleTypes.Where(type => + types.Any(outerType => type.FullName.StartsWith(outerType.FullName + "+")) + ); + } + var description = moreTypes.Aggregate( + "are nested in \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); return new ArchitecturePredicate(Condition, description); } @@ -228,8 +281,9 @@ public static IPredicate AreNestedIn(IObjectProvider objectProvider) IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) { var types = objectProvider.GetObjects(architecture); - return ruleTypes.Where(type => - types.Any(outerType => type.FullName.StartsWith(outerType.FullName + "+"))); + return ruleTypes.Where(type => + types.Any(outerType => type.FullName.StartsWith(outerType.FullName + "+")) + ); } var description = "are nested in " + objectProvider.Description; @@ -241,9 +295,10 @@ public static IPredicate AreNestedIn(IEnumerable types) var typeList = types.ToList(); IEnumerable Condition(IEnumerable ruleTypes) - { - return ruleTypes.Where(type => - typeList.Any(outerType => type.FullName.StartsWith(outerType.FullName + "+"))); + { + return ruleTypes.Where(type => + typeList.Any(outerType => type.FullName.StartsWith(outerType.FullName + "+")) + ); } string description; @@ -254,9 +309,13 @@ IEnumerable Condition(IEnumerable ruleTypes) else { var firstType = typeList.First(); - description = typeList.Where(type => !type.Equals(firstType)).Distinct().Aggregate( - "are nested in \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => !type.Equals(firstType)) + .Distinct() + .Aggregate( + "are nested in \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new EnumerablePredicate(Condition, description); @@ -268,8 +327,9 @@ public static IPredicate AreNestedIn(IEnumerable types) IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) { - return ruleTypes.Where(type => - typeList.Any(outerType => type.FullName.StartsWith(outerType.FullName + "+"))); + return ruleTypes.Where(type => + typeList.Any(outerType => type.FullName.StartsWith(outerType.FullName + "+")) + ); } string description; @@ -280,9 +340,13 @@ IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) else { var firstType = typeList.First(); - description = typeList.Where(type => type != firstType).Distinct().Aggregate( - "are nested in \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => type != firstType) + .Distinct() + .Aggregate( + "are nested in \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new ArchitecturePredicate(Condition, description); @@ -290,7 +354,10 @@ IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) public static IPredicate AreValueTypes() { - return new SimplePredicate(type => type is Enum || type is Struct, "are value types"); + return new SimplePredicate( + type => type is Enum || type is Struct, + "are value types" + ); } public static IPredicate AreEnums() @@ -303,17 +370,27 @@ public static IPredicate AreStructs() return new SimplePredicate(type => type is Struct, "are structs"); } - public static IPredicate ImplementInterface(string pattern, bool useRegularExpressions = false) + public static IPredicate ImplementInterface( + string pattern, + bool useRegularExpressions = false + ) { - return new SimplePredicate(type => type.ImplementsInterface(pattern, useRegularExpressions), - "implement interface with full name " + (useRegularExpressions ? "matching " : "") + "\"" + - pattern + "\""); + return new SimplePredicate( + type => type.ImplementsInterface(pattern, useRegularExpressions), + "implement interface with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } public static IPredicate ImplementInterface(Interface intf) { - return new SimplePredicate(type => type.ImplementsInterface(intf), - "implement interface \"" + intf.FullName + "\""); + return new SimplePredicate( + type => type.ImplementsInterface(intf), + "implement interface \"" + intf.FullName + "\"" + ); } public static IPredicate ImplementInterface(Type intf) @@ -334,74 +411,112 @@ IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) return ruleTypes.Where(type => type.ImplementsInterface(archUnitInterface)); } - return new ArchitecturePredicate(Condition, - "implement interface \"" + intf.FullName + "\""); + return new ArchitecturePredicate( + Condition, + "implement interface \"" + intf.FullName + "\"" + ); } - public static IPredicate ResideInNamespace(string pattern, bool useRegularExpressions = false) + public static IPredicate ResideInNamespace( + string pattern, + bool useRegularExpressions = false + ) { - return new SimplePredicate(type => type.ResidesInNamespace(pattern, useRegularExpressions), - "reside in namespace with full name " + (useRegularExpressions ? "matching " : "") + "\"" + - pattern + "\""); + return new SimplePredicate( + type => type.ResidesInNamespace(pattern, useRegularExpressions), + "reside in namespace with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static IPredicate ResideInAssembly(string pattern, bool useRegularExpressions = false) + public static IPredicate ResideInAssembly( + string pattern, + bool useRegularExpressions = false + ) { - return new SimplePredicate(type => type.ResidesInAssembly(pattern, useRegularExpressions), - "reside in assembly with full name " + (useRegularExpressions ? "matching " : "") + "\"" + - pattern + "\""); + return new SimplePredicate( + type => type.ResidesInAssembly(pattern, useRegularExpressions), + "reside in assembly with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static IPredicate ResideInAssembly(Assembly assembly, params Assembly[] moreAssemblies) + public static IPredicate ResideInAssembly( + Assembly assembly, + params Assembly[] moreAssemblies + ) { IEnumerable Condition(IEnumerable types, Architecture architecture) { - var assemblyList = moreAssemblies.Concat(new[] {assembly}).Select(architecture.GetAssemblyOfAssembly); + var assemblyList = moreAssemblies + .Concat(new[] { assembly }) + .Select(architecture.GetAssemblyOfAssembly); return types.Where(type => assemblyList.Contains(type.Assembly)); } - var description = moreAssemblies.Aggregate("reside in assembly \"" + assembly.FullName + "\"", - (current, asm) => current + " or \"" + asm.FullName + "\""); + var description = moreAssemblies.Aggregate( + "reside in assembly \"" + assembly.FullName + "\"", + (current, asm) => current + " or \"" + asm.FullName + "\"" + ); return new ArchitecturePredicate(Condition, description); } - public static IPredicate ResideInAssembly(Domain.Assembly assembly, params Domain.Assembly[] moreAssemblies) + public static IPredicate ResideInAssembly( + Domain.Assembly assembly, + params Domain.Assembly[] moreAssemblies + ) { IEnumerable Condition(IEnumerable types) { - var assemblyList = moreAssemblies.Concat(new[] {assembly}); + var assemblyList = moreAssemblies.Concat(new[] { assembly }); return types.Where(type => assemblyList.Contains(type.Assembly)); } - var description = moreAssemblies.Aggregate("reside in assembly \"" + assembly.FullName + "\"", - (current, asm) => current + " or \"" + asm.FullName + "\""); + var description = moreAssemblies.Aggregate( + "reside in assembly \"" + assembly.FullName + "\"", + (current, asm) => current + " or \"" + asm.FullName + "\"" + ); return new EnumerablePredicate(Condition, description); } public static IPredicate HavePropertyMemberWithName(string name) { - return new SimplePredicate(type => type.HasPropertyMemberWithName(name), - "have property member with name\"" + name + "\""); + return new SimplePredicate( + type => type.HasPropertyMemberWithName(name), + "have property member with name\"" + name + "\"" + ); } public static IPredicate HaveFieldMemberWithName(string name) { - return new SimplePredicate(type => type.HasFieldMemberWithName(name), - "have field member with name \"" + name + "\""); + return new SimplePredicate( + type => type.HasFieldMemberWithName(name), + "have field member with name \"" + name + "\"" + ); } public static IPredicate HaveMethodMemberWithName(string name) { - return new SimplePredicate(type => type.HasMethodMemberWithName(name), - "have method member with name \"" + name + "\""); + return new SimplePredicate( + type => type.HasMethodMemberWithName(name), + "have method member with name \"" + name + "\"" + ); } public static IPredicate HaveMemberWithName(string name) { - return new SimplePredicate(type => type.HasMemberWithName(name), - "have member with name \"" + name + "\""); + return new SimplePredicate( + type => type.HasMemberWithName(name), + "have member with name \"" + name + "\"" + ); } public static IPredicate AreNested() @@ -409,13 +524,12 @@ public static IPredicate AreNested() return new SimplePredicate(type => type.IsNested, "are nested"); } - //Negations public static IPredicate AreNot(Type firstType, params Type[] moreTypes) { - return AreNot(new List() {firstType}.Concat(moreTypes)); + return AreNot(new List() { firstType }.Concat(moreTypes)); } public static IPredicate AreNot(IEnumerable types) @@ -449,28 +563,47 @@ IEnumerable Filter(IEnumerable ruleTypes, Architecture architecture) else { var firstType = typeList.First(); - description = typeList.Where(obj => obj != firstType).Distinct().Aggregate( - "are not \"" + firstType.FullName + "\"", - (current, obj) => current + " or \"" + obj.FullName + "\""); + description = typeList + .Where(obj => obj != firstType) + .Distinct() + .Aggregate( + "are not \"" + firstType.FullName + "\"", + (current, obj) => current + " or \"" + obj.FullName + "\"" + ); } return new ArchitecturePredicate(Filter, description); } - public static IPredicate AreNotAssignableTo(string pattern, bool useRegularExpressions = false) + public static IPredicate AreNotAssignableTo( + string pattern, + bool useRegularExpressions = false + ) { - var description = "are not assignable to types with full name " + - (useRegularExpressions ? "matching " : "") + "\"" + pattern + "\""; - return new SimplePredicate(type => !type.IsAssignableTo(pattern, useRegularExpressions), description); + var description = + "are not assignable to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\""; + return new SimplePredicate( + type => !type.IsAssignableTo(pattern, useRegularExpressions), + description + ); } - public static IPredicate AreNotAssignableTo(IEnumerable patterns, bool useRegularExpressions = false) + public static IPredicate AreNotAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) { var patternList = patterns.ToList(); bool Condition(T ruleType) { - return patternList.All(pattern => !ruleType.IsAssignableTo(pattern, useRegularExpressions)); + return patternList.All(pattern => + !ruleType.IsAssignableTo(pattern, useRegularExpressions) + ); } string description; @@ -481,10 +614,17 @@ bool Condition(T ruleType) else { var firstPattern = patternList.First(); - description = patternList.Where(type => !type.Equals(firstPattern)).Distinct().Aggregate( - "are not assignable to types with full name " + - (useRegularExpressions ? "matching " : "") + - "\"" + firstPattern + "\"", (current, pattern) => current + " or \"" + pattern + "\""); + description = patternList + .Where(type => !type.Equals(firstPattern)) + .Distinct() + .Aggregate( + "are not assignable to types with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + firstPattern + + "\"", + (current, pattern) => current + " or \"" + pattern + "\"" + ); } return new SimplePredicate(Condition, description); @@ -494,12 +634,14 @@ public static IPredicate AreNotAssignableTo(IType firstType, params IType[] m { IEnumerable Condition(IEnumerable ruleTypes) { - var types = moreTypes.Concat(new[] {firstType}); + var types = moreTypes.Concat(new[] { firstType }); return ruleTypes.Where(type => !type.GetAssignableTypes().Intersect(types).Any()); } - var description = moreTypes.Aggregate("are not assignable to \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + var description = moreTypes.Aggregate( + "are not assignable to \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); return new EnumerablePredicate(Condition, description); } @@ -507,12 +649,16 @@ public static IPredicate AreNotAssignableTo(Type firstType, params Type[] mor { IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) { - var types = moreTypes.Concat(new[] {firstType}).Select(architecture.GetITypeOfType); + var types = moreTypes + .Concat(new[] { firstType }) + .Select(architecture.GetITypeOfType); return ruleTypes.Where(type => !type.GetAssignableTypes().Intersect(types).Any()); } - var description = moreTypes.Aggregate("are not assignable to \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + var description = moreTypes.Aggregate( + "are not assignable to \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); return new ArchitecturePredicate(Condition, description); } @@ -534,7 +680,9 @@ public static IPredicate AreNotAssignableTo(IEnumerable types) IEnumerable Condition(IEnumerable ruleTypes) { - return ruleTypes.Where(type => !type.GetAssignableTypes().Intersect(typeList).Any()); + return ruleTypes.Where(type => + !type.GetAssignableTypes().Intersect(typeList).Any() + ); } string description; @@ -545,9 +693,13 @@ IEnumerable Condition(IEnumerable ruleTypes) else { var firstType = typeList.First(); - description = typeList.Where(type => !type.Equals(firstType)).Distinct().Aggregate( - "are not assignable to \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => !type.Equals(firstType)) + .Distinct() + .Aggregate( + "are not assignable to \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new EnumerablePredicate(Condition, description); @@ -573,7 +725,9 @@ IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) } } - return ruleTypes.Where(type => !type.GetAssignableTypes().Intersect(archUnitTypeList).Any()); + return ruleTypes.Where(type => + !type.GetAssignableTypes().Intersect(archUnitTypeList).Any() + ); } string description; @@ -584,9 +738,13 @@ IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) else { var firstType = typeList.First(); - description = typeList.Where(type => type != firstType).Distinct().Aggregate( - "are not assignable to \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\""); + description = typeList + .Where(type => type != firstType) + .Distinct() + .Aggregate( + "are not assignable to \"" + firstType.FullName + "\"", + (current, type) => current + " or \"" + type.FullName + "\"" + ); } return new ArchitecturePredicate(Condition, description); @@ -594,7 +752,10 @@ IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) public static IPredicate AreNotValueTypes() { - return new SimplePredicate(cls => !(cls is Enum) && !(cls is Struct), "are not value types"); + return new SimplePredicate( + cls => !(cls is Enum) && !(cls is Struct), + "are not value types" + ); } public static IPredicate AreNotEnums() @@ -607,17 +768,27 @@ public static IPredicate AreNotStructs() return new SimplePredicate(cls => !(cls is Struct), "are not structs"); } - public static IPredicate DoNotImplementInterface(string pattern, bool useRegularExpressions = false) + public static IPredicate DoNotImplementInterface( + string pattern, + bool useRegularExpressions = false + ) { - return new SimplePredicate(type => !type.ImplementsInterface(pattern, useRegularExpressions), - "do not implement interface with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + pattern + "\""); + return new SimplePredicate( + type => !type.ImplementsInterface(pattern, useRegularExpressions), + "do not implement interface with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } public static IPredicate DoNotImplementInterface(Interface intf) { - return new SimplePredicate(type => !type.ImplementsInterface(intf), - "do not implement interface \"" + intf.FullName + "\""); + return new SimplePredicate( + type => !type.ImplementsInterface(intf), + "do not implement interface \"" + intf.FullName + "\"" + ); } public static IPredicate DoNotImplementInterface(Type intf) @@ -638,75 +809,112 @@ IEnumerable Condition(IEnumerable ruleTypes, Architecture architecture) return ruleTypes.Where(type => !type.ImplementsInterface(archUnitInterface)); } - return new ArchitecturePredicate(Condition, - "do not implement interface \"" + intf.FullName + "\""); + return new ArchitecturePredicate( + Condition, + "do not implement interface \"" + intf.FullName + "\"" + ); } - public static IPredicate DoNotResideInNamespace(string pattern, bool useRegularExpressions = false) + public static IPredicate DoNotResideInNamespace( + string pattern, + bool useRegularExpressions = false + ) { - return new SimplePredicate(type => !type.ResidesInNamespace(pattern, useRegularExpressions), - "do not reside in namespace with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + pattern + "\""); + return new SimplePredicate( + type => !type.ResidesInNamespace(pattern, useRegularExpressions), + "do not reside in namespace with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static IPredicate DoNotResideInAssembly(string pattern, bool useRegularExpressions = false) + public static IPredicate DoNotResideInAssembly( + string pattern, + bool useRegularExpressions = false + ) { - return new SimplePredicate(type => !type.ResidesInAssembly(pattern, useRegularExpressions), - "do not reside in assembly with full name " + (useRegularExpressions ? "matching " : "") + - "\"" + pattern + "\""); + return new SimplePredicate( + type => !type.ResidesInAssembly(pattern, useRegularExpressions), + "do not reside in assembly with full name " + + (useRegularExpressions ? "matching " : "") + + "\"" + + pattern + + "\"" + ); } - public static IPredicate DoNotResideInAssembly(Assembly assembly, params Assembly[] moreAssemblies) + public static IPredicate DoNotResideInAssembly( + Assembly assembly, + params Assembly[] moreAssemblies + ) { IEnumerable Condition(IEnumerable types, Architecture architecture) { - var assemblyList = moreAssemblies.Concat(new[] {assembly}).Select(architecture.GetAssemblyOfAssembly); + var assemblyList = moreAssemblies + .Concat(new[] { assembly }) + .Select(architecture.GetAssemblyOfAssembly); return types.Where(type => !assemblyList.Contains(type.Assembly)); } - var description = moreAssemblies.Aggregate("do not reside in assembly \"" + assembly.FullName + "\"", - (current, asm) => current + " or \"" + asm.FullName + "\""); + var description = moreAssemblies.Aggregate( + "do not reside in assembly \"" + assembly.FullName + "\"", + (current, asm) => current + " or \"" + asm.FullName + "\"" + ); return new ArchitecturePredicate(Condition, description); } - public static IPredicate DoNotResideInAssembly(Domain.Assembly assembly, - params Domain.Assembly[] moreAssemblies) + public static IPredicate DoNotResideInAssembly( + Domain.Assembly assembly, + params Domain.Assembly[] moreAssemblies + ) { IEnumerable Condition(IEnumerable types) { - var assemblyList = moreAssemblies.Concat(new[] {assembly}); + var assemblyList = moreAssemblies.Concat(new[] { assembly }); return types.Where(type => !assemblyList.Contains(type.Assembly)); } - var description = moreAssemblies.Aggregate("do not reside in assembly \"" + assembly.FullName + "\"", - (current, asm) => current + " or \"" + asm.FullName + "\""); + var description = moreAssemblies.Aggregate( + "do not reside in assembly \"" + assembly.FullName + "\"", + (current, asm) => current + " or \"" + asm.FullName + "\"" + ); return new EnumerablePredicate(Condition, description); } public static IPredicate DoNotHavePropertyMemberWithName(string name) { - return new SimplePredicate(type => !type.HasPropertyMemberWithName(name), - "do not have property member with name \"" + name + "\""); + return new SimplePredicate( + type => !type.HasPropertyMemberWithName(name), + "do not have property member with name \"" + name + "\"" + ); } public static IPredicate DoNotHaveFieldMemberWithName(string name) { - return new SimplePredicate(type => !type.HasFieldMemberWithName(name), - "do not have field member with name \"" + name + "\""); + return new SimplePredicate( + type => !type.HasFieldMemberWithName(name), + "do not have field member with name \"" + name + "\"" + ); } public static IPredicate DoNotHaveMethodMemberWithName(string name) { - return new SimplePredicate(type => !type.HasMethodMemberWithName(name), - "do not have method member with name \"" + name + "\""); + return new SimplePredicate( + type => !type.HasMethodMemberWithName(name), + "do not have method member with name \"" + name + "\"" + ); } public static IPredicate DoNotHaveMemberWithName(string name) { - return new SimplePredicate(type => !type.HasMemberWithName(name), - "do not have member with name \"" + name + "\""); + return new SimplePredicate( + type => !type.HasMemberWithName(name), + "do not have member with name \"" + name + "\"" + ); } public static IPredicate AreNotNested() @@ -714,4 +922,4 @@ public static IPredicate AreNotNested() return new SimplePredicate(type => !type.IsNested, "are not nested"); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShould.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShould.cs index 4a120230d..20267d115 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShould.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShould.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -13,16 +13,15 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Types { - public class TypesShould : - ObjectsShould, - IComplexTypeConditions + public class TypesShould + : ObjectsShould, + IComplexTypeConditions where TRuleType : IType where TRuleTypeShouldConjunction : SyntaxElement { // ReSharper disable once MemberCanBeProtected.Global - public TypesShould(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public TypesShould(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } public TRuleTypeShouldConjunction Be(Type firstType, params Type[] moreTypes) { @@ -36,30 +35,41 @@ public TRuleTypeShouldConjunction Be(IEnumerable types) return Create(_ruleCreator); } - public TRuleTypeShouldConjunction BeAssignableTo(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction BeAssignableTo( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - TypeConditionsDefinition.BeAssignableTo(pattern, useRegularExpressions)); + TypeConditionsDefinition.BeAssignableTo(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction BeAssignableTo(IEnumerable patterns, - bool useRegularExpressions = false) + public TRuleTypeShouldConjunction BeAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - TypeConditionsDefinition.BeAssignableTo(patterns, useRegularExpressions)); + TypeConditionsDefinition.BeAssignableTo(patterns, useRegularExpressions) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction BeAssignableTo(IType firstType, params IType[] moreTypes) { - _ruleCreator.AddCondition(TypeConditionsDefinition.BeAssignableTo(firstType, moreTypes)); + _ruleCreator.AddCondition( + TypeConditionsDefinition.BeAssignableTo(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction BeAssignableTo(Type firstType, params Type[] moreTypes) { - _ruleCreator.AddCondition(TypeConditionsDefinition.BeAssignableTo(firstType, moreTypes)); + _ruleCreator.AddCondition( + TypeConditionsDefinition.BeAssignableTo(firstType, moreTypes) + ); return Create(_ruleCreator); } @@ -83,13 +93,17 @@ public TRuleTypeShouldConjunction BeAssignableTo(IEnumerable types) public TRuleTypeShouldConjunction BeNestedIn(IType firstType, params IType[] moreTypes) { - _ruleCreator.AddCondition(TypeConditionsDefinition.BeNestedIn(firstType, moreTypes)); + _ruleCreator.AddCondition( + TypeConditionsDefinition.BeNestedIn(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction BeNestedIn(Type firstType, params Type[] moreTypes) { - _ruleCreator.AddCondition(TypeConditionsDefinition.BeNestedIn(firstType, moreTypes)); + _ruleCreator.AddCondition( + TypeConditionsDefinition.BeNestedIn(firstType, moreTypes) + ); return Create(_ruleCreator); } @@ -109,7 +123,8 @@ public TRuleTypeShouldConjunction BeNestedIn(IEnumerable types) { _ruleCreator.AddCondition(TypeConditionsDefinition.BeNestedIn(types)); return Create(_ruleCreator); - } + } + public TRuleTypeShouldConjunction BeValueTypes() { _ruleCreator.AddCondition(TypeConditionsDefinition.BeValueTypes()); @@ -128,71 +143,100 @@ public TRuleTypeShouldConjunction BeStructs() return Create(_ruleCreator); } - public TRuleTypeShouldConjunction ImplementInterface(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction ImplementInterface( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - TypeConditionsDefinition.ImplementInterface(pattern, useRegularExpressions)); + TypeConditionsDefinition.ImplementInterface( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction ImplementInterface(Interface intf) { - _ruleCreator.AddCondition( - TypeConditionsDefinition.ImplementInterface(intf)); + _ruleCreator.AddCondition(TypeConditionsDefinition.ImplementInterface(intf)); return Create(_ruleCreator); } public TRuleTypeShouldConjunction ImplementInterface(Type intf) { - _ruleCreator.AddCondition( - TypeConditionsDefinition.ImplementInterface(intf)); + _ruleCreator.AddCondition(TypeConditionsDefinition.ImplementInterface(intf)); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction ResideInNamespace(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction ResideInNamespace( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - TypeConditionsDefinition.ResideInNamespace(pattern, useRegularExpressions)); + TypeConditionsDefinition.ResideInNamespace( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction ResideInAssembly(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction ResideInAssembly( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - TypeConditionsDefinition.ResideInAssembly(pattern, useRegularExpressions)); + TypeConditionsDefinition.ResideInAssembly(pattern, useRegularExpressions) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction ResideInAssembly(Assembly assembly, params Assembly[] moreAssemblies) + public TRuleTypeShouldConjunction ResideInAssembly( + Assembly assembly, + params Assembly[] moreAssemblies + ) { _ruleCreator.AddCondition( - TypeConditionsDefinition.ResideInAssembly(assembly, moreAssemblies)); + TypeConditionsDefinition.ResideInAssembly(assembly, moreAssemblies) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction ResideInAssembly(Domain.Assembly assembly, - params Domain.Assembly[] moreAssemblies) + public TRuleTypeShouldConjunction ResideInAssembly( + Domain.Assembly assembly, + params Domain.Assembly[] moreAssemblies + ) { _ruleCreator.AddCondition( - TypeConditionsDefinition.ResideInAssembly(assembly, moreAssemblies)); + TypeConditionsDefinition.ResideInAssembly(assembly, moreAssemblies) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HavePropertyMemberWithName(string name) { - _ruleCreator.AddCondition(TypeConditionsDefinition.HavePropertyMemberWithName(name)); + _ruleCreator.AddCondition( + TypeConditionsDefinition.HavePropertyMemberWithName(name) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveFieldMemberWithName(string name) { - _ruleCreator.AddCondition(TypeConditionsDefinition.HaveFieldMemberWithName(name)); + _ruleCreator.AddCondition( + TypeConditionsDefinition.HaveFieldMemberWithName(name) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction HaveMethodMemberWithName(string name) { - _ruleCreator.AddCondition(TypeConditionsDefinition.HaveMethodMemberWithName(name)); + _ruleCreator.AddCondition( + TypeConditionsDefinition.HaveMethodMemberWithName(name) + ); return Create(_ruleCreator); } @@ -208,23 +252,31 @@ public TRuleTypeShouldConjunction BeNested() return Create(_ruleCreator); } - //Relation Conditions - public ShouldRelateToTypesThat BeAssignableToTypesThat() + public ShouldRelateToTypesThat< + TRuleTypeShouldConjunction, + IType, + TRuleType + > BeAssignableToTypesThat() { - _ruleCreator.BeginComplexCondition(ArchRuleDefinition.Types(true), - TypeConditionsDefinition.BeAssignableToTypesThat()); - return new ShouldRelateToTypesThat(_ruleCreator); + _ruleCreator.BeginComplexCondition( + ArchRuleDefinition.Types(true), + TypeConditionsDefinition.BeAssignableToTypesThat() + ); + return new ShouldRelateToTypesThat( + _ruleCreator + ); } - //Negations public TRuleTypeShouldConjunction NotBe(Type firstType, params Type[] moreTypes) { - _ruleCreator.AddCondition(TypeConditionsDefinition.NotBe(firstType, moreTypes)); + _ruleCreator.AddCondition( + TypeConditionsDefinition.NotBe(firstType, moreTypes) + ); return Create(_ruleCreator); } @@ -234,30 +286,50 @@ public TRuleTypeShouldConjunction NotBe(IEnumerable types) return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotBeAssignableTo(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction NotBeAssignableTo( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - TypeConditionsDefinition.NotBeAssignableTo(pattern, useRegularExpressions)); + TypeConditionsDefinition.NotBeAssignableTo( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotBeAssignableTo(IEnumerable patterns, - bool useRegularExpressions = false) + public TRuleTypeShouldConjunction NotBeAssignableTo( + IEnumerable patterns, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - TypeConditionsDefinition.NotBeAssignableTo(patterns, useRegularExpressions)); + TypeConditionsDefinition.NotBeAssignableTo( + patterns, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotBeAssignableTo(IType firstType, params IType[] moreTypes) + public TRuleTypeShouldConjunction NotBeAssignableTo( + IType firstType, + params IType[] moreTypes + ) { - _ruleCreator.AddCondition(TypeConditionsDefinition.NotBeAssignableTo(firstType, moreTypes)); + _ruleCreator.AddCondition( + TypeConditionsDefinition.NotBeAssignableTo(firstType, moreTypes) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction NotBeAssignableTo(Type firstType, params Type[] moreTypes) { - _ruleCreator.AddCondition(TypeConditionsDefinition.NotBeAssignableTo(firstType, moreTypes)); + _ruleCreator.AddCondition( + TypeConditionsDefinition.NotBeAssignableTo(firstType, moreTypes) + ); return Create(_ruleCreator); } @@ -297,76 +369,115 @@ public TRuleTypeShouldConjunction NotBeStructs() return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotImplementInterface(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction NotImplementInterface( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - TypeConditionsDefinition.NotImplementInterface(pattern, useRegularExpressions)); + TypeConditionsDefinition.NotImplementInterface( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction NotImplementInterface(Interface intf) { _ruleCreator.AddCondition( - TypeConditionsDefinition.NotImplementInterface(intf)); + TypeConditionsDefinition.NotImplementInterface(intf) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction NotImplementInterface(Type intf) { _ruleCreator.AddCondition( - TypeConditionsDefinition.NotImplementInterface(intf)); + TypeConditionsDefinition.NotImplementInterface(intf) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotResideInNamespace(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction NotResideInNamespace( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - TypeConditionsDefinition.NotResideInNamespace(pattern, useRegularExpressions)); + TypeConditionsDefinition.NotResideInNamespace( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotResideInAssembly(string pattern, bool useRegularExpressions = false) + public TRuleTypeShouldConjunction NotResideInAssembly( + string pattern, + bool useRegularExpressions = false + ) { _ruleCreator.AddCondition( - TypeConditionsDefinition.NotResideInAssembly(pattern, useRegularExpressions)); + TypeConditionsDefinition.NotResideInAssembly( + pattern, + useRegularExpressions + ) + ); return Create(_ruleCreator); } - public TRuleTypeShouldConjunction NotResideInAssembly(Assembly assembly, params Assembly[] moreAssemblies) + public TRuleTypeShouldConjunction NotResideInAssembly( + Assembly assembly, + params Assembly[] moreAssemblies + ) { _ruleCreator.AddCondition( - TypeConditionsDefinition.NotResideInAssembly(assembly, moreAssemblies)); + TypeConditionsDefinition.NotResideInAssembly(assembly, moreAssemblies) + ); return Create(_ruleCreator); } - - public TRuleTypeShouldConjunction NotResideInAssembly(Domain.Assembly assembly, params Domain.Assembly[] moreAssemblies) + + public TRuleTypeShouldConjunction NotResideInAssembly( + Domain.Assembly assembly, + params Domain.Assembly[] moreAssemblies + ) { _ruleCreator.AddCondition( - TypeConditionsDefinition.NotResideInAssembly(assembly, moreAssemblies)); + TypeConditionsDefinition.NotResideInAssembly(assembly, moreAssemblies) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction NotHavePropertyMemberWithName(string name) { - _ruleCreator.AddCondition(TypeConditionsDefinition.NotHavePropertyMemberWithName(name)); + _ruleCreator.AddCondition( + TypeConditionsDefinition.NotHavePropertyMemberWithName(name) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction NotHaveFieldMemberWithName(string name) { - _ruleCreator.AddCondition(TypeConditionsDefinition.NotHaveFieldMemberWithName(name)); + _ruleCreator.AddCondition( + TypeConditionsDefinition.NotHaveFieldMemberWithName(name) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction NotHaveMethodMemberWithName(string name) { - _ruleCreator.AddCondition(TypeConditionsDefinition.NotHaveMethodMemberWithName(name)); + _ruleCreator.AddCondition( + TypeConditionsDefinition.NotHaveMethodMemberWithName(name) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction NotHaveMemberWithName(string name) { - _ruleCreator.AddCondition(TypeConditionsDefinition.NotHaveMemberWithName(name)); + _ruleCreator.AddCondition( + TypeConditionsDefinition.NotHaveMemberWithName(name) + ); return Create(_ruleCreator); } @@ -376,26 +487,37 @@ public TRuleTypeShouldConjunction NotBeNested() return Create(_ruleCreator); } - public TRuleTypeShouldConjunction AdhereToPlantUmlDiagram(string file) { - _ruleCreator.AddCondition(TypeConditionsDefinition.AdhereToPlantUmlDiagram(file)); + _ruleCreator.AddCondition( + TypeConditionsDefinition.AdhereToPlantUmlDiagram(file) + ); return Create(_ruleCreator); } public TRuleTypeShouldConjunction AdhereToPlantUmlDiagram(Stream stream) { - _ruleCreator.AddCondition(TypeConditionsDefinition.AdhereToPlantUmlDiagram(stream)); + _ruleCreator.AddCondition( + TypeConditionsDefinition.AdhereToPlantUmlDiagram(stream) + ); return Create(_ruleCreator); } //Relation Condition Negations - public ShouldRelateToTypesThat NotBeAssignableToTypesThat() + public ShouldRelateToTypesThat< + TRuleTypeShouldConjunction, + IType, + TRuleType + > NotBeAssignableToTypesThat() { - _ruleCreator.BeginComplexCondition(ArchRuleDefinition.Types(true), - TypeConditionsDefinition.NotBeAssignableToTypesThat()); - return new ShouldRelateToTypesThat(_ruleCreator); + _ruleCreator.BeginComplexCondition( + ArchRuleDefinition.Types(true), + TypeConditionsDefinition.NotBeAssignableToTypesThat() + ); + return new ShouldRelateToTypesThat( + _ruleCreator + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShouldConjunction.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShouldConjunction.cs index 9cfcd85e7..b412d96f8 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShouldConjunction.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShouldConjunction.cs @@ -1,18 +1,21 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types { - public class TypesShouldConjunction : ObjectsShouldConjunction, - TypesShouldConjunctionWithDescription, IType> + public class TypesShouldConjunction + : ObjectsShouldConjunction< + TypesShould, + TypesShouldConjunctionWithDescription, + IType + > { - public TypesShouldConjunction(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public TypesShouldConjunction(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShouldConjunctionWithDescription.cs b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShouldConjunctionWithDescription.cs index eed4fec36..9022dacc6 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShouldConjunctionWithDescription.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Types/TypesShouldConjunctionWithDescription.cs @@ -1,18 +1,17 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; namespace ArchUnitNET.Fluent.Syntax.Elements.Types { - public class TypesShouldConjunctionWithDescription : ObjectsShouldConjunctionWithDescription< - TypesShould, IType> + public class TypesShouldConjunctionWithDescription + : ObjectsShouldConjunctionWithDescription, IType> { - public TypesShouldConjunctionWithDescription(IArchRuleCreator ruleCreator) : base(ruleCreator) - { - } + public TypesShouldConjunctionWithDescription(IArchRuleCreator ruleCreator) + : base(ruleCreator) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Fluent/Syntax/SyntaxElement.cs b/ArchUnitNET/Fluent/Syntax/SyntaxElement.cs index 07fe125ab..21f83037b 100644 --- a/ArchUnitNET/Fluent/Syntax/SyntaxElement.cs +++ b/ArchUnitNET/Fluent/Syntax/SyntaxElement.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -9,7 +9,8 @@ namespace ArchUnitNET.Fluent.Syntax { - public abstract class SyntaxElement : IHasDescription where TRuleType : ICanBeAnalyzed + public abstract class SyntaxElement : IHasDescription + where TRuleType : ICanBeAnalyzed { // ReSharper disable once InconsistentNaming protected readonly IArchRuleCreator _ruleCreator; @@ -38,7 +39,7 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((SyntaxElement) obj); + return obj.GetType() == GetType() && Equals((SyntaxElement)obj); } private bool Equals(SyntaxElement other) @@ -51,4 +52,4 @@ public override int GetHashCode() return _ruleCreator != null ? _ruleCreator.GetHashCode() : 0; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Library/Rules/TargetFrameworkRules.cs b/ArchUnitNET/Library/Rules/TargetFrameworkRules.cs index 470b9825b..deb3f2fb8 100644 --- a/ArchUnitNET/Library/Rules/TargetFrameworkRules.cs +++ b/ArchUnitNET/Library/Rules/TargetFrameworkRules.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Collections.Generic; using ArchUnitNET.Domain; @@ -22,8 +22,14 @@ IEnumerable Evaluate(Architecture architecture, IArchRule arch { var passed = assembly.IsDotNetStandard(); var description = "has target framework " + assembly.GetTargetFramework(); - yield return new EvaluationResult(assembly, new StringIdentifier(assembly.FullName), passed, - description, archRule, architecture); + yield return new EvaluationResult( + assembly, + new StringIdentifier(assembly.FullName), + passed, + description, + archRule, + architecture + ); } } @@ -38,8 +44,14 @@ IEnumerable Evaluate(Architecture architecture, IArchRule arch { var passed = assembly.IsDotNetCore(); var description = "has target framework " + assembly.GetTargetFramework(); - yield return new EvaluationResult(assembly, new StringIdentifier(assembly.FullName), passed, - description, archRule, architecture); + yield return new EvaluationResult( + assembly, + new StringIdentifier(assembly.FullName), + passed, + description, + archRule, + architecture + ); } } @@ -54,12 +66,18 @@ IEnumerable Evaluate(Architecture architecture, IArchRule arch { var passed = assembly.IsDotNetFramework(); var description = "has target framework " + assembly.GetTargetFramework(); - yield return new EvaluationResult(assembly, new StringIdentifier(assembly.FullName), passed, - description, archRule, architecture); + yield return new EvaluationResult( + assembly, + new StringIdentifier(assembly.FullName), + passed, + description, + archRule, + architecture + ); } } return new CustomArchRule(Evaluate, "Should be .Net Framework"); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/ArchBuilder.cs b/ArchUnitNET/Loader/ArchBuilder.cs index b56941777..12b470cc9 100644 --- a/ArchUnitNET/Loader/ArchBuilder.cs +++ b/ArchUnitNET/Loader/ArchBuilder.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -32,8 +32,13 @@ public ArchBuilder() _loadTaskRegistry = new LoadTaskRegistry(); var typeRegistry = new TypeRegistry(); var methodMemberRegistry = new MethodMemberRegistry(); - _typeFactory = new TypeFactory(typeRegistry, methodMemberRegistry, _loadTaskRegistry, _assemblyRegistry, - _namespaceRegistry); + _typeFactory = new TypeFactory( + typeRegistry, + methodMemberRegistry, + _loadTaskRegistry, + _assemblyRegistry, + _namespaceRegistry + ); _architectureCacheKey = new ArchitectureCacheKey(); _architectureCache = ArchitectureCache.Instance; } @@ -42,16 +47,26 @@ public ArchBuilder() public IEnumerable Assemblies => _assemblyRegistry.Assemblies; public IEnumerable Namespaces => _namespaceRegistry.Namespaces; - public void AddAssembly([NotNull] AssemblyDefinition moduleAssembly, bool isOnlyReferenced, [CanBeNull] IEnumerable moduleReferences) + public void AddAssembly( + [NotNull] AssemblyDefinition moduleAssembly, + bool isOnlyReferenced, + [CanBeNull] IEnumerable moduleReferences + ) { var references = moduleReferences?.Select(reference => reference.Name).ToList(); if (!_assemblyRegistry.ContainsAssembly(moduleAssembly.Name.FullName)) { - var assembly = _assemblyRegistry.GetOrCreateAssembly(moduleAssembly.Name.FullName, - moduleAssembly.FullName, isOnlyReferenced, references); - _loadTaskRegistry.Add(typeof(CollectAssemblyAttributes), - new CollectAssemblyAttributes(assembly, moduleAssembly, _typeFactory)); + var assembly = _assemblyRegistry.GetOrCreateAssembly( + moduleAssembly.Name.FullName, + moduleAssembly.FullName, + isOnlyReferenced, + references + ); + _loadTaskRegistry.Add( + typeof(CollectAssemblyAttributes), + new CollectAssemblyAttributes(assembly, moduleAssembly, _typeFactory) + ); } } @@ -63,22 +78,34 @@ public void LoadTypesForModule(ModuleDefinition module, string namespaceFilter) ? module.Types.Skip(1).ToList() : module.Types.ToList(); - types = types.Where(t => t.FullName != "Microsoft.CodeAnalysis.EmbeddedAttribute" && - t.FullName != "System.Runtime.CompilerServices.NullableAttribute" && - t.FullName != "System.Runtime.CompilerServices.NullableContextAttribute").ToList(); + types = types + .Where(t => + t.FullName != "Microsoft.CodeAnalysis.EmbeddedAttribute" + && t.FullName != "System.Runtime.CompilerServices.NullableAttribute" + && t.FullName != "System.Runtime.CompilerServices.NullableContextAttribute" + ) + .ToList(); var nestedTypes = types; while (nestedTypes.Any()) { - nestedTypes = nestedTypes.SelectMany(typeDefinition => - typeDefinition.NestedTypes.Where(type => !type.IsCompilerGenerated())).ToList(); + nestedTypes = nestedTypes + .SelectMany(typeDefinition => + typeDefinition.NestedTypes.Where(type => !type.IsCompilerGenerated()) + ) + .ToList(); types.AddRange(nestedTypes); } var currentTypes = new List(types.Count); - types.Where(typeDefinition => RegexUtils.MatchNamespaces(namespaceFilter, - typeDefinition.Namespace) && typeDefinition.CustomAttributes.All(att => - att.AttributeType.FullName != "Microsoft.VisualStudio.TestPlatform.TestSDKAutoGeneratedCode")) + types + .Where(typeDefinition => + RegexUtils.MatchNamespaces(namespaceFilter, typeDefinition.Namespace) + && typeDefinition.CustomAttributes.All(att => + att.AttributeType.FullName + != "Microsoft.VisualStudio.TestPlatform.TestSDKAutoGeneratedCode" + ) + ) .ForEach(typeDefinition => { var type = _typeFactory.GetOrCreateTypeFromTypeReference(typeDefinition); @@ -89,30 +116,34 @@ public void LoadTypesForModule(ModuleDefinition module, string namespaceFilter) } }); - _namespaceRegistry.Namespaces - .Where(ns => RegexUtils.MatchNamespaces(namespaceFilter, ns.FullName)) + _namespaceRegistry + .Namespaces.Where(ns => RegexUtils.MatchNamespaces(namespaceFilter, ns.FullName)) .ForEach(ns => { - _loadTaskRegistry.Add(typeof(AddTypesToNamespace), - new AddTypesToNamespace(ns, currentTypes)); + _loadTaskRegistry.Add( + typeof(AddTypesToNamespace), + new AddTypesToNamespace(ns, currentTypes) + ); }); } private void UpdateTypeDefinitions() { - _loadTaskRegistry.ExecuteTasks(new List - { - typeof(AddMembers), - typeof(AddGenericParameterDependencies), - typeof(AddAttributesAndAttributeDependencies), - typeof(CollectAssemblyAttributes), - typeof(AddFieldAndPropertyDependencies), - typeof(AddMethodDependencies), - typeof(AddGenericArgumentDependencies), - typeof(AddClassDependencies), - typeof(AddBackwardsDependencies), - typeof(AddTypesToNamespace) - }); + _loadTaskRegistry.ExecuteTasks( + new List + { + typeof(AddMembers), + typeof(AddGenericParameterDependencies), + typeof(AddAttributesAndAttributeDependencies), + typeof(CollectAssemblyAttributes), + typeof(AddFieldAndPropertyDependencies), + typeof(AddMethodDependencies), + typeof(AddGenericArgumentDependencies), + typeof(AddClassDependencies), + typeof(AddBackwardsDependencies), + typeof(AddTypesToNamespace) + } + ); } public Architecture Build() @@ -128,9 +159,15 @@ public Architecture Build() var genericParameters = allTypes.OfType().ToList(); var referencedTypes = allTypes.Except(Types).Except(genericParameters); var namespaces = Namespaces.Where(ns => ns.Types.Any()); - var newArchitecture = new Architecture(Assemblies, namespaces, Types, genericParameters, referencedTypes); + var newArchitecture = new Architecture( + Assemblies, + namespaces, + Types, + genericParameters, + referencedTypes + ); _architectureCache.Add(_architectureCacheKey, newArchitecture); return newArchitecture; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/ArchLoader.cs b/ArchUnitNET/Loader/ArchLoader.cs index 48567facc..e1046214a 100644 --- a/ArchUnitNET/Loader/ArchLoader.cs +++ b/ArchUnitNET/Loader/ArchLoader.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -42,42 +42,58 @@ public ArchLoader LoadAssembliesIncludingDependencies(params Assembly[] assembli return LoadAssembliesIncludingDependencies(assemblies, false); } - public ArchLoader LoadAssembliesIncludingDependencies(IEnumerable assemblies, bool recursive) + public ArchLoader LoadAssembliesIncludingDependencies( + IEnumerable assemblies, + bool recursive + ) { var assemblySet = new HashSet(assemblies); assemblySet.ForEach(assembly => LoadAssemblyIncludingDependencies(assembly, recursive)); return this; } - public ArchLoader LoadFilteredDirectory(string directory, string filter, - SearchOption searchOption = TopDirectoryOnly) + public ArchLoader LoadFilteredDirectory( + string directory, + string filter, + SearchOption searchOption = TopDirectoryOnly + ) { var path = Path.GetFullPath(directory); _assemblyResolver.AssemblyPath = path; var assemblies = Directory.GetFiles(path, filter, searchOption); var result = this; - return assemblies.Aggregate(result, - (current, assembly) => current.LoadAssembly(assembly, false, false)); + return assemblies.Aggregate( + result, + (current, assembly) => current.LoadAssembly(assembly, false, false) + ); } - public ArchLoader LoadFilteredDirectoryIncludingDependencies(string directory, string filter, + public ArchLoader LoadFilteredDirectoryIncludingDependencies( + string directory, + string filter, bool recursive = false, - SearchOption searchOption = TopDirectoryOnly) + SearchOption searchOption = TopDirectoryOnly + ) { var path = Path.GetFullPath(directory); _assemblyResolver.AssemblyPath = path; var assemblies = Directory.GetFiles(path, filter, searchOption); var result = this; - return assemblies.Aggregate(result, - (current, assembly) => current.LoadAssembly(assembly, true, recursive)); + return assemblies.Aggregate( + result, + (current, assembly) => current.LoadAssembly(assembly, true, recursive) + ); } public ArchLoader LoadNamespacesWithinAssembly(Assembly assembly, params string[] namespc) { var nameSpaces = new HashSet(namespc); - nameSpaces.ForEach(nameSpace => { LoadModule(assembly.Location, nameSpace, false, false); }); + nameSpaces.ForEach(nameSpace => + { + LoadModule(assembly.Location, nameSpace, false, false); + }); return this; } @@ -86,7 +102,10 @@ public ArchLoader LoadAssembly(Assembly assembly) return LoadAssembly(assembly.Location, false, false); } - public ArchLoader LoadAssemblyIncludingDependencies(Assembly assembly, bool recursive = false) + public ArchLoader LoadAssemblyIncludingDependencies( + Assembly assembly, + bool recursive = false + ) { return LoadAssembly(assembly.Location, true, recursive); } @@ -98,12 +117,20 @@ private ArchLoader LoadAssembly(string fileName, bool includeDependencies, bool return this; } - private void LoadModule(string fileName, string nameSpace, bool includeDependencies, bool recursive, FilterFunc filterFunc = null) + private void LoadModule( + string fileName, + string nameSpace, + bool includeDependencies, + bool recursive, + FilterFunc filterFunc = null + ) { try { - var module = ModuleDefinition.ReadModule(fileName, - new ReaderParameters { AssemblyResolver = _assemblyResolver }); + var module = ModuleDefinition.ReadModule( + fileName, + new ReaderParameters { AssemblyResolver = _assemblyResolver } + ); var processedAssemblies = new List { module.Assembly.Name }; var resolvedModules = new List(); _assemblyResolver.AddLib(module.Assembly); @@ -112,7 +139,12 @@ private void LoadModule(string fileName, string nameSpace, bool includeDependenc { if (includeDependencies && recursive) { - AddReferencedAssembliesRecursively(assemblyReference, processedAssemblies, resolvedModules, filterFunc); + AddReferencedAssembliesRecursively( + assemblyReference, + processedAssemblies, + resolvedModules, + filterFunc + ); } else { @@ -122,8 +154,9 @@ private void LoadModule(string fileName, string nameSpace, bool includeDependenc _assemblyResolver.AddLib(assemblyReference); if (includeDependencies) { - var assemblyDefinition = _assemblyResolver.Resolve(assemblyReference) ?? - throw new AssemblyResolutionException(assemblyReference); + var assemblyDefinition = + _assemblyResolver.Resolve(assemblyReference) + ?? throw new AssemblyResolutionException(assemblyReference); _archBuilder.AddAssembly(assemblyDefinition, false, null); resolvedModules.AddRange(assemblyDefinition.Modules); } @@ -147,9 +180,12 @@ private void LoadModule(string fileName, string nameSpace, bool includeDependenc } } - private void AddReferencedAssembliesRecursively(AssemblyNameReference currentAssemblyReference, - ICollection processedAssemblies, List resolvedModules, - FilterFunc filterFunc) + private void AddReferencedAssembliesRecursively( + AssemblyNameReference currentAssemblyReference, + ICollection processedAssemblies, + List resolvedModules, + FilterFunc filterFunc + ) { if (processedAssemblies.Contains(currentAssemblyReference)) { @@ -160,20 +196,30 @@ private void AddReferencedAssembliesRecursively(AssemblyNameReference currentAss try { _assemblyResolver.AddLib(currentAssemblyReference); - var assemblyDefinition = _assemblyResolver.Resolve(currentAssemblyReference) ?? - throw new AssemblyResolutionException(currentAssemblyReference); - + var assemblyDefinition = + _assemblyResolver.Resolve(currentAssemblyReference) + ?? throw new AssemblyResolutionException(currentAssemblyReference); + var filterResult = filterFunc?.Invoke(assemblyDefinition); if (filterResult?.LoadThisAssembly != false) { _archBuilder.AddAssembly(assemblyDefinition, false, null); resolvedModules.AddRange(assemblyDefinition.Modules); } - - foreach (var reference in assemblyDefinition.Modules.SelectMany(m => m.AssemblyReferences)) + + foreach ( + var reference in assemblyDefinition.Modules.SelectMany(m => + m.AssemblyReferences + ) + ) { if (filterResult?.TraverseDependencies != false) - AddReferencedAssembliesRecursively(reference, processedAssemblies, resolvedModules, filterFunc); + AddReferencedAssembliesRecursively( + reference, + processedAssemblies, + resolvedModules, + filterFunc + ); } } catch (AssemblyResolutionException) @@ -188,7 +234,10 @@ private void AddReferencedAssembliesRecursively(AssemblyNameReference currentAss /// Assemblies to start traversal from /// Delegate to control loading and traversal logic /// - public ArchLoader LoadAssembliesRecursively(IEnumerable assemblies, FilterFunc filterFunc) + public ArchLoader LoadAssembliesRecursively( + IEnumerable assemblies, + FilterFunc filterFunc + ) { foreach (var assembly in assemblies) { @@ -197,4 +246,4 @@ public ArchLoader LoadAssembliesRecursively(IEnumerable assemblies, Fi return this; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/AssemblyRegistry.cs b/ArchUnitNET/Loader/AssemblyRegistry.cs index 66180e8ea..37061b3d5 100644 --- a/ArchUnitNET/Loader/AssemblyRegistry.cs +++ b/ArchUnitNET/Loader/AssemblyRegistry.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -11,14 +11,28 @@ namespace ArchUnitNET.Loader { internal class AssemblyRegistry { - private readonly Dictionary _assemblies = new Dictionary(); + private readonly Dictionary _assemblies = + new Dictionary(); public IEnumerable Assemblies => _assemblies.Values; - public Assembly GetOrCreateAssembly(string assemblyName, string assemblyFullName, bool isOnlyReferenced, List assemblyReferences) + public Assembly GetOrCreateAssembly( + string assemblyName, + string assemblyFullName, + bool isOnlyReferenced, + List assemblyReferences + ) { - return RegistryUtils.GetFromDictOrCreateAndAdd(assemblyName, _assemblies, - s => new Assembly(assemblyName, assemblyFullName, isOnlyReferenced, assemblyReferences)); + return RegistryUtils.GetFromDictOrCreateAndAdd( + assemblyName, + _assemblies, + s => new Assembly( + assemblyName, + assemblyFullName, + isOnlyReferenced, + assemblyReferences + ) + ); } public bool ContainsAssembly(string assemblyName) @@ -26,4 +40,4 @@ public bool ContainsAssembly(string assemblyName) return _assemblies.ContainsKey(assemblyName); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/DotNetCoreAssemblyResolver.cs b/ArchUnitNET/Loader/DotNetCoreAssemblyResolver.cs index 6a60f5ebd..db097fb94 100644 --- a/ArchUnitNET/Loader/DotNetCoreAssemblyResolver.cs +++ b/ArchUnitNET/Loader/DotNetCoreAssemblyResolver.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -29,7 +29,7 @@ public DotNetCoreAssemblyResolver() [CanBeNull] public AssemblyDefinition Resolve(AssemblyNameReference name) { - return Resolve(name, new ReaderParameters {AssemblyResolver = this}); + return Resolve(name, new ReaderParameters { AssemblyResolver = this }); } [CanBeNull] @@ -40,12 +40,16 @@ public AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters p throw new ArgumentNullException(nameof(name)); } - if (_libraries.TryGetValue(name.FullName, out var assemblyDefinition) || string.IsNullOrEmpty(AssemblyPath)) + if ( + _libraries.TryGetValue(name.FullName, out var assemblyDefinition) + || string.IsNullOrEmpty(AssemblyPath) + ) { return assemblyDefinition; } - var file = Directory.EnumerateFiles(AssemblyPath, $"{name.Name}.dll", SearchOption.AllDirectories) + var file = Directory + .EnumerateFiles(AssemblyPath, $"{name.Name}.dll", SearchOption.AllDirectories) .FirstOrDefault(); if (file == null) @@ -73,7 +77,10 @@ public void AddLib([NotNull] AssemblyDefinition moduleAssembly) } } - private void AddLib([NotNull] AssemblyNameReference name, [NotNull] AssemblyDefinition moduleAssembly) + private void AddLib( + [NotNull] AssemblyNameReference name, + [NotNull] AssemblyDefinition moduleAssembly + ) { if (!_libraries.ContainsKey(name.FullName)) { @@ -97,4 +104,4 @@ private void Dispose(bool disposing) _libraries.Values.ForEach(def => def.Dispose()); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/FilterResult.cs b/ArchUnitNET/Loader/FilterResult.cs index 7ab008652..5740cd56e 100644 --- a/ArchUnitNET/Loader/FilterResult.cs +++ b/ArchUnitNET/Loader/FilterResult.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using Mono.Cecil; @@ -14,7 +14,7 @@ namespace ArchUnitNET.Loader /// /// Current assembly definition public delegate FilterResult FilterFunc(AssemblyDefinition assemblyDefinition); - + /// /// Filter function result options /// @@ -24,22 +24,22 @@ public struct FilterResult /// Load this assembly and traverse its dependencies /// public static FilterResult LoadAndContinue = new FilterResult(true, true); - + /// /// Do not load this assembly, but traverse its dependencies /// public static FilterResult SkipAndContinue = new FilterResult(true, false); - + /// /// Load this assembly and do not traverse its dependencies /// public static FilterResult LoadAndStop = new FilterResult(false, true); - + /// /// Do not load this assembly and do not traverse its dependencies /// public static FilterResult DontLoadAndStop = new FilterResult(false, false); - + private FilterResult(bool traverseDependencies, bool loadThisAssembly) { TraverseDependencies = traverseDependencies; @@ -47,7 +47,7 @@ private FilterResult(bool traverseDependencies, bool loadThisAssembly) } internal bool TraverseDependencies { get; } - + internal bool LoadThisAssembly { get; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/InstructionExtensions.cs b/ArchUnitNET/Loader/InstructionExtensions.cs index f2146b630..a5e774035 100644 --- a/ArchUnitNET/Loader/InstructionExtensions.cs +++ b/ArchUnitNET/Loader/InstructionExtensions.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -13,15 +13,17 @@ namespace ArchUnitNET.Loader { public static class InstructionExtensions { - public static bool IsOperationForBackedProperty([NotNull] this Instruction methodBodyInstruction) + public static bool IsOperationForBackedProperty( + [NotNull] this Instruction methodBodyInstruction + ) { if (methodBodyInstruction == null) { throw new ArgumentNullException(nameof(methodBodyInstruction)); } - return IsMethodCallToSetBackingFieldDefinition(methodBodyInstruction) || - IsNewObjectToSetBackingField(methodBodyInstruction); + return IsMethodCallToSetBackingFieldDefinition(methodBodyInstruction) + || IsNewObjectToSetBackingField(methodBodyInstruction); } public static bool IsMethodCallAssignment([NotNull] this Instruction instruction) @@ -35,7 +37,9 @@ public static bool IsMethodCallAssignment([NotNull] this Instruction instruction return IsReturnOp(nextOp) && IsMethodCallOp(instruction); } - public static FieldDefinition GetAssigneeFieldDefinition([NotNull] this Instruction methodCallInstruction) + public static FieldDefinition GetAssigneeFieldDefinition( + [NotNull] this Instruction methodCallInstruction + ) { if (methodCallInstruction == null) { @@ -43,7 +47,10 @@ public static FieldDefinition GetAssigneeFieldDefinition([NotNull] this Instruct } var methodCallAssignment = methodCallInstruction.Next; - if (methodCallAssignment != null && methodCallAssignment.Operand is FieldReference fieldReference) + if ( + methodCallAssignment != null + && methodCallAssignment.Operand is FieldReference fieldReference + ) { return fieldReference.Resolve(); } @@ -51,7 +58,9 @@ public static FieldDefinition GetAssigneeFieldDefinition([NotNull] this Instruct return null; } - public static bool IsMethodCallToSetBackingFieldDefinition([NotNull] this Instruction instruction) + public static bool IsMethodCallToSetBackingFieldDefinition( + [NotNull] this Instruction instruction + ) { if (instruction == null) { @@ -113,7 +122,8 @@ public static bool IsMethodCallOp([NotNull] this Instruction methodBodyInstructi throw new ArgumentNullException(nameof(methodBodyInstruction)); } - return methodBodyInstruction.OpCode == OpCodes.Call || methodBodyInstruction.OpCode == OpCodes.Callvirt; + return methodBodyInstruction.OpCode == OpCodes.Call + || methodBodyInstruction.OpCode == OpCodes.Callvirt; } public static bool IsSetFieldOp([NotNull] this Instruction nextOp) @@ -136,4 +146,4 @@ public static bool IsReturnOp([NotNull] this Instruction operation) return operation.OpCode == OpCodes.Ret; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/LoadTaskRegistry.cs b/ArchUnitNET/Loader/LoadTaskRegistry.cs index 66a410e06..9704ced40 100644 --- a/ArchUnitNET/Loader/LoadTaskRegistry.cs +++ b/ArchUnitNET/Loader/LoadTaskRegistry.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -63,7 +63,6 @@ public void Add(System.Type taskType, ILoadTask task) } private class TaskComparer : IComparer - { private readonly List _taskOrder; @@ -91,4 +90,4 @@ public int Compare(System.Type x, System.Type y) } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/LoadTasks/AddAttributesAndAttributeDependencies.cs b/ArchUnitNET/Loader/LoadTasks/AddAttributesAndAttributeDependencies.cs index d0bee0411..7539cfe0b 100644 --- a/ArchUnitNET/Loader/LoadTasks/AddAttributesAndAttributeDependencies.cs +++ b/ArchUnitNET/Loader/LoadTasks/AddAttributesAndAttributeDependencies.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -20,7 +20,11 @@ internal class AddAttributesAndAttributeDependencies : ILoadTask private readonly TypeDefinition _typeDefinition; private readonly TypeFactory _typeFactory; - public AddAttributesAndAttributeDependencies(IType type, TypeDefinition typeDefinition, TypeFactory typeFactory) + public AddAttributesAndAttributeDependencies( + IType type, + TypeDefinition typeDefinition, + TypeFactory typeFactory + ) { _type = type; _typeDefinition = typeDefinition; @@ -29,13 +33,17 @@ public AddAttributesAndAttributeDependencies(IType type, TypeDefinition typeDefi public void Execute() { - _typeDefinition.CustomAttributes.ForEach(AddAttributeArgumentReferenceDependenciesToOriginType); - var typeAttributeInstances = - CreateAttributesFromCustomAttributes(_typeDefinition.CustomAttributes).ToList(); + _typeDefinition.CustomAttributes.ForEach( + AddAttributeArgumentReferenceDependenciesToOriginType + ); + var typeAttributeInstances = CreateAttributesFromCustomAttributes( + _typeDefinition.CustomAttributes + ) + .ToList(); _type.AttributeInstances.AddRange(typeAttributeInstances); - var typeAttributeDependencies = - typeAttributeInstances.Select( - attributeInstance => new AttributeTypeDependency(_type, attributeInstance)); + var typeAttributeDependencies = typeAttributeInstances.Select( + attributeInstance => new AttributeTypeDependency(_type, attributeInstance) + ); _type.Dependencies.AddRange(typeAttributeDependencies); SetUpAttributesForTypeGenericParameters(); CollectAttributesForMembers(); @@ -45,95 +53,148 @@ private void SetUpAttributesForTypeGenericParameters() { foreach (var genericParameter in _typeDefinition.GenericParameters) { - var param = _type.GenericParameters.First(parameter => parameter.Name == genericParameter.Name); - var attributeInstances = - CreateAttributesFromCustomAttributes(genericParameter.CustomAttributes).ToList(); + var param = _type.GenericParameters.First(parameter => + parameter.Name == genericParameter.Name + ); + var attributeInstances = CreateAttributesFromCustomAttributes( + genericParameter.CustomAttributes + ) + .ToList(); _type.AttributeInstances.AddRange(attributeInstances); param.AttributeInstances.AddRange(attributeInstances); - var genericParameterAttributeDependencies = attributeInstances.Select(attributeInstance => - new AttributeTypeDependency(_type, attributeInstance)); + var genericParameterAttributeDependencies = attributeInstances.Select( + attributeInstance => new AttributeTypeDependency(_type, attributeInstance) + ); _type.Dependencies.AddRange(genericParameterAttributeDependencies); } } private void CollectAttributesForMembers() { - _typeDefinition.Fields.Where(x => !x.IsBackingField() && !x.IsCompilerGenerated()) + _typeDefinition + .Fields.Where(x => !x.IsBackingField() && !x.IsCompilerGenerated()) .ForEach(SetUpAttributesForFields); - _typeDefinition.Properties.Where(x => !x.IsCompilerGenerated()).ForEach(SetUpAttributesForProperties); + _typeDefinition + .Properties.Where(x => !x.IsCompilerGenerated()) + .ForEach(SetUpAttributesForProperties); - _typeDefinition.Methods.Where(x => !x.IsCompilerGenerated()).ForEach(SetUpAttributesForMethods); + _typeDefinition + .Methods.Where(x => !x.IsCompilerGenerated()) + .ForEach(SetUpAttributesForMethods); } private void SetUpAttributesForFields(FieldDefinition fieldDefinition) { - var fieldMember = _type.GetFieldMembers().WhereFullNameIs(fieldDefinition.FullName) + var fieldMember = _type + .GetFieldMembers() + .WhereFullNameIs(fieldDefinition.FullName) .RequiredNotNull(); - CollectMemberAttributesAndDependencies(fieldMember, fieldDefinition.CustomAttributes.ToList(), - fieldMember.MemberDependencies); + CollectMemberAttributesAndDependencies( + fieldMember, + fieldDefinition.CustomAttributes.ToList(), + fieldMember.MemberDependencies + ); } private void SetUpAttributesForProperties(PropertyDefinition propertyDefinition) { - var propertyMember = _type.GetPropertyMembers().WhereFullNameIs(propertyDefinition.FullName) + var propertyMember = _type + .GetPropertyMembers() + .WhereFullNameIs(propertyDefinition.FullName) .RequiredNotNull(); - CollectMemberAttributesAndDependencies(propertyMember, propertyDefinition.CustomAttributes.ToList(), - propertyMember.AttributeDependencies); + CollectMemberAttributesAndDependencies( + propertyMember, + propertyDefinition.CustomAttributes.ToList(), + propertyMember.AttributeDependencies + ); } private void SetUpAttributesForMethods(MethodDefinition methodDefinition) { - var methodMember = _type.GetMethodMembers().WhereFullNameIs(methodDefinition.BuildFullName()) + var methodMember = _type + .GetMethodMembers() + .WhereFullNameIs(methodDefinition.BuildFullName()) .RequiredNotNull(); var memberCustomAttributes = methodDefinition.GetAllMethodCustomAttributes().ToList(); SetUpAttributesForMethodGenericParameters(methodDefinition, methodMember); - CollectMemberAttributesAndDependencies(methodMember, memberCustomAttributes, - methodMember.MemberDependencies); + CollectMemberAttributesAndDependencies( + methodMember, + memberCustomAttributes, + methodMember.MemberDependencies + ); } - private void SetUpAttributesForMethodGenericParameters(MethodDefinition methodDefinition, - MethodMember methodMember) + private void SetUpAttributesForMethodGenericParameters( + MethodDefinition methodDefinition, + MethodMember methodMember + ) { foreach (var genericParameter in methodDefinition.GenericParameters) { - var param = methodMember.GenericParameters.First(parameter => parameter.Name == genericParameter.Name); + var param = methodMember.GenericParameters.First(parameter => + parameter.Name == genericParameter.Name + ); var customAttributes = genericParameter.CustomAttributes; customAttributes.ForEach(AddAttributeArgumentReferenceDependenciesToOriginType); - var attributeInstances = CreateAttributesFromCustomAttributes(customAttributes).ToList(); + var attributeInstances = CreateAttributesFromCustomAttributes(customAttributes) + .ToList(); methodMember.AttributeInstances.AddRange(attributeInstances); param.AttributeInstances.AddRange(attributeInstances); - var genericParameterAttributeDependencies = attributeInstances.Select(attributeInstance => - new AttributeMemberDependency(methodMember, attributeInstance)); + var genericParameterAttributeDependencies = attributeInstances.Select( + attributeInstance => new AttributeMemberDependency( + methodMember, + attributeInstance + ) + ); methodMember.MemberDependencies.AddRange(genericParameterAttributeDependencies); } } - private void CollectMemberAttributesAndDependencies(IMember methodMember, - List memberCustomAttributes, List attributeDependencies) + private void CollectMemberAttributesAndDependencies( + IMember methodMember, + List memberCustomAttributes, + List attributeDependencies + ) { memberCustomAttributes.ForEach(AddAttributeArgumentReferenceDependenciesToOriginType); - var memberAttributeInstances = CreateAttributesFromCustomAttributes(memberCustomAttributes).ToList(); + var memberAttributeInstances = CreateAttributesFromCustomAttributes( + memberCustomAttributes + ) + .ToList(); methodMember.AttributeInstances.AddRange(memberAttributeInstances); - var methodAttributeDependencies = CreateMemberAttributeDependencies(methodMember, memberAttributeInstances); + var methodAttributeDependencies = CreateMemberAttributeDependencies( + methodMember, + memberAttributeInstances + ); attributeDependencies.AddRange(methodAttributeDependencies); } [NotNull] public IEnumerable CreateAttributesFromCustomAttributes( - IEnumerable customAttributes) + IEnumerable customAttributes + ) { - return customAttributes.Select(attr => attr.CreateAttributeFromCustomAttribute(_typeFactory)); + return customAttributes.Select(attr => + attr.CreateAttributeFromCustomAttribute(_typeFactory) + ); } [NotNull] - private static IEnumerable CreateMemberAttributeDependencies(IMember member, - IEnumerable attributes) + private static IEnumerable CreateMemberAttributeDependencies( + IMember member, + IEnumerable attributes + ) { - return attributes.Select(attributeInstance => new AttributeMemberDependency(member, attributeInstance)); + return attributes.Select(attributeInstance => new AttributeMemberDependency( + member, + attributeInstance + )); } - private void AddAttributeArgumentReferenceDependenciesToOriginType(ICustomAttribute customAttribute) + private void AddAttributeArgumentReferenceDependenciesToOriginType( + ICustomAttribute customAttribute + ) { if (!customAttribute.HasConstructorArguments) { @@ -142,16 +203,21 @@ private void AddAttributeArgumentReferenceDependenciesToOriginType(ICustomAttrib var attributeConstructorArgs = customAttribute.ConstructorArguments; attributeConstructorArgs - .Where(attributeArgument => attributeArgument.Value is TypeReference typeReference && - !typeReference.IsCompilerGenerated()) - .Select(attributeArgument => (typeReference: attributeArgument.Value as TypeReference, - attributeArgument)) + .Where(attributeArgument => + attributeArgument.Value is TypeReference typeReference + && !typeReference.IsCompilerGenerated() + ) + .Select(attributeArgument => + (typeReference: attributeArgument.Value as TypeReference, attributeArgument) + ) .ForEach(tuple => { - var argumentType = _typeFactory.GetOrCreateStubTypeInstanceFromTypeReference(tuple.typeReference); + var argumentType = _typeFactory.GetOrCreateStubTypeInstanceFromTypeReference( + tuple.typeReference + ); var dependency = new TypeReferenceDependency(_type, argumentType); _type.Dependencies.Add(dependency); }); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/LoadTasks/AddBackwardsDependencies.cs b/ArchUnitNET/Loader/LoadTasks/AddBackwardsDependencies.cs index a232f968e..ef21a1b25 100644 --- a/ArchUnitNET/Loader/LoadTasks/AddBackwardsDependencies.cs +++ b/ArchUnitNET/Loader/LoadTasks/AddBackwardsDependencies.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Linq; @@ -22,12 +22,16 @@ public AddBackwardsDependencies(IType type) public void Execute() { - _type.Dependencies.ForEach(dependency => dependency.Target.BackwardsDependencies.Add(dependency)); + _type.Dependencies.ForEach(dependency => + dependency.Target.BackwardsDependencies.Add(dependency) + ); - var memberMemberDependencies = _type.Members.SelectMany(member => member.MemberDependencies) + var memberMemberDependencies = _type + .Members.SelectMany(member => member.MemberDependencies) .OfType(); memberMemberDependencies.ForEach(memberDependency => - memberDependency.TargetMember.MemberBackwardsDependencies.Add(memberDependency)); + memberDependency.TargetMember.MemberBackwardsDependencies.Add(memberDependency) + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/LoadTasks/AddBaseClassDependency.cs b/ArchUnitNET/Loader/LoadTasks/AddBaseClassDependency.cs index d1347b35c..2ad543d17 100644 --- a/ArchUnitNET/Loader/LoadTasks/AddBaseClassDependency.cs +++ b/ArchUnitNET/Loader/LoadTasks/AddBaseClassDependency.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -17,7 +17,12 @@ internal class AddBaseClassDependency : ILoadTask private readonly TypeDefinition _typeDefinition; private readonly TypeFactory _typeFactory; - public AddBaseClassDependency(IType cls, Type type, TypeDefinition typeDefinition, TypeFactory typeFactory) + public AddBaseClassDependency( + IType cls, + Type type, + TypeDefinition typeDefinition, + TypeFactory typeFactory + ) { _cls = cls; _type = type; @@ -34,16 +39,23 @@ public void Execute() return; } - var baseType = _typeFactory.GetOrCreateStubTypeInstanceFromTypeReference(typeDefinitionBaseType); + var baseType = _typeFactory.GetOrCreateStubTypeInstanceFromTypeReference( + typeDefinitionBaseType + ); if (!(baseType.Type is Class baseClass)) { return; } - var dependency = - new InheritsBaseClassDependency(_cls, - new TypeInstance(baseClass, baseType.GenericArguments, baseType.ArrayDimensions)); + var dependency = new InheritsBaseClassDependency( + _cls, + new TypeInstance( + baseClass, + baseType.GenericArguments, + baseType.ArrayDimensions + ) + ); _type.Dependencies.Add(dependency); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/LoadTasks/AddClassDependencies.cs b/ArchUnitNET/Loader/LoadTasks/AddClassDependencies.cs index 1568e4e45..ed71d7d8c 100644 --- a/ArchUnitNET/Loader/LoadTasks/AddClassDependencies.cs +++ b/ArchUnitNET/Loader/LoadTasks/AddClassDependencies.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -20,8 +20,12 @@ internal class AddClassDependencies : ILoadTask private readonly TypeDefinition _typeDefinition; private readonly TypeFactory _typeFactory; - public AddClassDependencies(IType type, TypeDefinition typeDefinition, TypeFactory typeFactory, - List dependencies) + public AddClassDependencies( + IType type, + TypeDefinition typeDefinition, + TypeFactory typeFactory, + List dependencies + ) { _type = type; _typeDefinition = typeDefinition; @@ -37,28 +41,37 @@ public void Execute() private void AddMemberDependencies() { - _type.Members.ForEach(member => { _dependencies.AddRange(member.Dependencies); }); + _type.Members.ForEach(member => + { + _dependencies.AddRange(member.Dependencies); + }); } private void AddInterfaceDependencies() { - GetInterfacesImplementedByClass(_typeDefinition).ForEach(target => - { - var targetType = _typeFactory.GetOrCreateStubTypeInstanceFromTypeReference(target); - _dependencies.Add(new ImplementsInterfaceDependency(_type, targetType)); - }); + GetInterfacesImplementedByClass(_typeDefinition) + .ForEach(target => + { + var targetType = _typeFactory.GetOrCreateStubTypeInstanceFromTypeReference( + target + ); + _dependencies.Add(new ImplementsInterfaceDependency(_type, targetType)); + }); } - private static IEnumerable GetInterfacesImplementedByClass(TypeDefinition typeDefinition) + private static IEnumerable GetInterfacesImplementedByClass( + TypeDefinition typeDefinition + ) { var baseType = typeDefinition.BaseType?.Resolve(); - var baseInterfaces = baseType != null - ? GetInterfacesImplementedByClass(baseType) - : new List(); + var baseInterfaces = + baseType != null + ? GetInterfacesImplementedByClass(baseType) + : new List(); - return typeDefinition.Interfaces - .Select(implementation => implementation.InterfaceType) + return typeDefinition + .Interfaces.Select(implementation => implementation.InterfaceType) .Concat(baseInterfaces); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/LoadTasks/AddFieldAndPropertyDependencies.cs b/ArchUnitNET/Loader/LoadTasks/AddFieldAndPropertyDependencies.cs index afaa62352..50696756a 100644 --- a/ArchUnitNET/Loader/LoadTasks/AddFieldAndPropertyDependencies.cs +++ b/ArchUnitNET/Loader/LoadTasks/AddFieldAndPropertyDependencies.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -21,17 +21,21 @@ public AddFieldAndPropertyDependencies(IType type) public void Execute() { - _type.GetFieldMembers().ForEach(field => - { - var dependency = new FieldTypeDependency(field); - AddDependencyIfMissing(field, dependency); - }); + _type + .GetFieldMembers() + .ForEach(field => + { + var dependency = new FieldTypeDependency(field); + AddDependencyIfMissing(field, dependency); + }); - _type.GetPropertyMembers().ForEach(property => - { - var dependency = new PropertyTypeDependency(property); - AddDependencyIfMissing(property, dependency); - }); + _type + .GetPropertyMembers() + .ForEach(property => + { + var dependency = new PropertyTypeDependency(property); + AddDependencyIfMissing(property, dependency); + }); } private static void AddDependencyIfMissing(IMember member, IMemberTypeDependency dependency) @@ -42,4 +46,4 @@ private static void AddDependencyIfMissing(IMember member, IMemberTypeDependency } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/LoadTasks/AddGenericArgumentDependencies.cs b/ArchUnitNET/Loader/LoadTasks/AddGenericArgumentDependencies.cs index 81a904cf4..e6dd1fb6b 100644 --- a/ArchUnitNET/Loader/LoadTasks/AddGenericArgumentDependencies.cs +++ b/ArchUnitNET/Loader/LoadTasks/AddGenericArgumentDependencies.cs @@ -1,9 +1,9 @@ // 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; @@ -15,7 +15,8 @@ namespace ArchUnitNET.Loader.LoadTasks { public class AddGenericArgumentDependencies : ILoadTask { - [NotNull] private readonly IType _type; + [NotNull] + private readonly IType _type; public AddGenericArgumentDependencies([NotNull] IType type) { @@ -30,19 +31,24 @@ public void Execute() var typeDependencies = new List(); foreach (var dependency in _type.Dependencies) { - FindGenericArgumentsInTypeDependenciesRecursive(dependency.TargetGenericArguments, typeDependencies); + FindGenericArgumentsInTypeDependenciesRecursive( + dependency.TargetGenericArguments, + typeDependencies + ); } _type.Dependencies.AddRange(typeDependencies); - foreach (var member in _type.Members) { var memberDependencies = new List(); foreach (var dependency in member.Dependencies) { - FindGenericArgumentsInMemberDependenciesRecursive(member, dependency.TargetGenericArguments, - memberDependencies); + FindGenericArgumentsInMemberDependenciesRecursive( + member, + dependency.TargetGenericArguments, + memberDependencies + ); } member.MemberDependencies.AddRange(memberDependencies); @@ -59,12 +65,20 @@ private void AddTypeGenericArgumentDependencies() private void FindGenericArgumentsInTypeDependenciesRecursive( IEnumerable targetGenericArguments, - ICollection createdDependencies) + ICollection createdDependencies + ) { - foreach (var genericArgument in targetGenericArguments.Where(argument => !argument.Type.IsGenericParameter)) + foreach ( + var genericArgument in targetGenericArguments.Where(argument => + !argument.Type.IsGenericParameter + ) + ) { createdDependencies.Add(new GenericArgumentTypeDependency(_type, genericArgument)); - FindGenericArgumentsInTypeDependenciesRecursive(genericArgument.GenericArguments, createdDependencies); + FindGenericArgumentsInTypeDependenciesRecursive( + genericArgument.GenericArguments, + createdDependencies + ); } } @@ -74,21 +88,34 @@ private void AddMemberGenericArgumentDependencies() { foreach (var parameter in member.GenericParameters) { - member.MemberDependencies.AddRange(parameter.Dependencies.Cast()); + member.MemberDependencies.AddRange( + parameter.Dependencies.Cast() + ); } } } - private static void FindGenericArgumentsInMemberDependenciesRecursive(IMember member, + private static void FindGenericArgumentsInMemberDependenciesRecursive( + IMember member, IEnumerable targetGenericArguments, - ICollection createdDependencies) + ICollection createdDependencies + ) { - foreach (var genericArgument in targetGenericArguments.Where(argument => !argument.Type.IsGenericParameter)) + foreach ( + var genericArgument in targetGenericArguments.Where(argument => + !argument.Type.IsGenericParameter + ) + ) { - createdDependencies.Add(new GenericArgumentMemberDependency(member, genericArgument)); - FindGenericArgumentsInMemberDependenciesRecursive(member, genericArgument.GenericArguments, - createdDependencies); + createdDependencies.Add( + new GenericArgumentMemberDependency(member, genericArgument) + ); + FindGenericArgumentsInMemberDependenciesRecursive( + member, + genericArgument.GenericArguments, + createdDependencies + ); } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/LoadTasks/AddGenericParameterDependencies.cs b/ArchUnitNET/Loader/LoadTasks/AddGenericParameterDependencies.cs index f42468043..1b1eade50 100644 --- a/ArchUnitNET/Loader/LoadTasks/AddGenericParameterDependencies.cs +++ b/ArchUnitNET/Loader/LoadTasks/AddGenericParameterDependencies.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using ArchUnitNET.Domain; using ArchUnitNET.Domain.Dependencies; @@ -13,7 +13,8 @@ namespace ArchUnitNET.Loader.LoadTasks { public class AddGenericParameterDependencies : ILoadTask { - [NotNull] private readonly IType _type; + [NotNull] + private readonly IType _type; public AddGenericParameterDependencies([NotNull] IType type) { @@ -33,8 +34,10 @@ private void AddTypeGenericParameterDependencies() genericParameter.AssignDeclarer(_type); foreach (var typeInstanceConstraint in genericParameter.TypeInstanceConstraints) { - var dependency = - new TypeGenericParameterTypeConstraintDependency(genericParameter, typeInstanceConstraint); + var dependency = new TypeGenericParameterTypeConstraintDependency( + genericParameter, + typeInstanceConstraint + ); genericParameter.Dependencies.Add(dependency); } } @@ -49,13 +52,14 @@ private void AddMemberGenericParameterDependencies() genericParameter.AssignDeclarer(member); foreach (var typeInstanceConstraint in genericParameter.TypeInstanceConstraints) { - var dependency = - new MemberGenericParameterTypeConstraintDependency(genericParameter, - typeInstanceConstraint); + var dependency = new MemberGenericParameterTypeConstraintDependency( + genericParameter, + typeInstanceConstraint + ); genericParameter.Dependencies.Add(dependency); } } } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/LoadTasks/AddMembers.cs b/ArchUnitNET/Loader/LoadTasks/AddMembers.cs index c7cbebae7..8c6183cb4 100644 --- a/ArchUnitNET/Loader/LoadTasks/AddMembers.cs +++ b/ArchUnitNET/Loader/LoadTasks/AddMembers.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -21,9 +21,13 @@ internal class AddMembers : ILoadTask private readonly IType _type; private readonly TypeDefinition _typeDefinition; private readonly TypeFactory _typeFactory; - - - public AddMembers(IType type, TypeDefinition typeDefinition, TypeFactory typeFactory, MemberList memberList) + + public AddMembers( + IType type, + TypeDefinition typeDefinition, + TypeFactory typeFactory, + MemberList memberList + ) { _type = type; _typeDefinition = typeDefinition; @@ -40,10 +44,20 @@ public void Execute() [NotNull] private IEnumerable CreateMembers([NotNull] TypeDefinition typeDefinition) { - return typeDefinition.Fields.Where(fieldDefinition => !fieldDefinition.IsBackingField()) - .Select(CreateFieldMember).Concat(typeDefinition.Properties.Select(CreatePropertyMember) - .Concat(typeDefinition.Methods.Select(method => - _typeFactory.GetOrCreateMethodMemberFromMethodReference(_type, method).Member))) + return typeDefinition + .Fields.Where(fieldDefinition => !fieldDefinition.IsBackingField()) + .Select(CreateFieldMember) + .Concat( + typeDefinition + .Properties.Select(CreatePropertyMember) + .Concat( + typeDefinition.Methods.Select(method => + _typeFactory + .GetOrCreateMethodMemberFromMethodReference(_type, method) + .Member + ) + ) + ) .Where(member => !member.IsCompilerGenerated); } @@ -51,28 +65,50 @@ private IEnumerable CreateMembers([NotNull] TypeDefinition typeDefiniti private IMember CreateFieldMember([NotNull] FieldDefinition fieldDefinition) { var typeReference = fieldDefinition.FieldType; - var fieldType = _typeFactory.GetOrCreateStubTypeInstanceFromTypeReference(typeReference); + var fieldType = _typeFactory.GetOrCreateStubTypeInstanceFromTypeReference( + typeReference + ); var visibility = GetVisibilityFromFieldDefinition(fieldDefinition); var isCompilerGenerated = fieldDefinition.IsCompilerGenerated(); var writeAccessor = GetWriteAccessor(fieldDefinition); - return new FieldMember(_type, fieldDefinition.Name, fieldDefinition.FullName, visibility, fieldType, - isCompilerGenerated, fieldDefinition.IsStatic, writeAccessor); + return new FieldMember( + _type, + fieldDefinition.Name, + fieldDefinition.FullName, + visibility, + fieldType, + isCompilerGenerated, + fieldDefinition.IsStatic, + writeAccessor + ); } [NotNull] private IMember CreatePropertyMember(PropertyDefinition propertyDefinition) { var typeReference = propertyDefinition.PropertyType; - var propertyType = _typeFactory.GetOrCreateStubTypeInstanceFromTypeReference(typeReference); + var propertyType = _typeFactory.GetOrCreateStubTypeInstanceFromTypeReference( + typeReference + ); var isCompilerGenerated = propertyDefinition.IsCompilerGenerated(); - var isStatic = (propertyDefinition.SetMethod != null && propertyDefinition.SetMethod.IsStatic) || - (propertyDefinition.GetMethod != null && propertyDefinition.GetMethod.IsStatic); + var isStatic = + (propertyDefinition.SetMethod != null && propertyDefinition.SetMethod.IsStatic) + || (propertyDefinition.GetMethod != null && propertyDefinition.GetMethod.IsStatic); var writeAccessor = GetWriteAccessor(propertyDefinition); - return new PropertyMember(_type, propertyDefinition.Name, propertyDefinition.FullName, propertyType, - isCompilerGenerated, isStatic, writeAccessor); + return new PropertyMember( + _type, + propertyDefinition.Name, + propertyDefinition.FullName, + propertyType, + isCompilerGenerated, + isStatic, + writeAccessor + ); } - private static Visibility GetVisibilityFromFieldDefinition([NotNull] FieldDefinition fieldDefinition) + private static Visibility GetVisibilityFromFieldDefinition( + [NotNull] FieldDefinition fieldDefinition + ) { if (fieldDefinition.IsPublic) { @@ -121,15 +157,20 @@ private static Writability GetWriteAccessor([NotNull] PropertyDefinition propert return Writability.ReadOnly; } - bool isInitSetter = CheckPropertyHasInitSetterInNetStandardCompatibleWay(propertyDefinition); + bool isInitSetter = CheckPropertyHasInitSetterInNetStandardCompatibleWay( + propertyDefinition + ); return isInitSetter ? Writability.InitOnly : Writability.Writable; } - private static bool CheckPropertyHasInitSetterInNetStandardCompatibleWay(PropertyDefinition propertyDefinition) + private static bool CheckPropertyHasInitSetterInNetStandardCompatibleWay( + PropertyDefinition propertyDefinition + ) { return propertyDefinition.SetMethod?.ReturnType.IsRequiredModifier == true - && ((RequiredModifierType)propertyDefinition.SetMethod.ReturnType).ModifierType.FullName - == "System.Runtime.CompilerServices.IsExternalInit"; + && ((RequiredModifierType)propertyDefinition.SetMethod.ReturnType) + .ModifierType + .FullName == "System.Runtime.CompilerServices.IsExternalInit"; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/LoadTasks/AddMethodDependencies.cs b/ArchUnitNET/Loader/LoadTasks/AddMethodDependencies.cs index be9c5ef0d..2a853adfe 100644 --- a/ArchUnitNET/Loader/LoadTasks/AddMethodDependencies.cs +++ b/ArchUnitNET/Loader/LoadTasks/AddMethodDependencies.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -24,7 +24,11 @@ internal class AddMethodDependencies : ILoadTask private readonly TypeDefinition _typeDefinition; private readonly TypeFactory _typeFactory; - public AddMethodDependencies(IType type, TypeDefinition typeDefinition, TypeFactory typeFactory) + public AddMethodDependencies( + IType type, + TypeDefinition typeDefinition, + TypeFactory typeFactory + ) { _type = type; _typeDefinition = typeDefinition; @@ -33,16 +37,24 @@ public AddMethodDependencies(IType type, TypeDefinition typeDefinition, TypeFact public void Execute() { - _typeDefinition.Methods - .Where(methodDefinition => - _type.GetMemberWithFullName(methodDefinition.BuildFullName()) is MethodMember) - .Select(definition => ( - methodMember: _type.GetMemberWithFullName(definition.BuildFullName()) as MethodMember, - methodDefinition: definition)) + _typeDefinition + .Methods.Where(methodDefinition => + _type.GetMemberWithFullName(methodDefinition.BuildFullName()) is MethodMember + ) + .Select(definition => + ( + methodMember: _type.GetMemberWithFullName(definition.BuildFullName()) + as MethodMember, + methodDefinition: definition + ) + ) .Select(tuple => { var (methodMember, methodDefinition) = tuple; - var dependencies = CreateMethodSignatureDependencies(methodDefinition, methodMember) + var dependencies = CreateMethodSignatureDependencies( + methodDefinition, + methodMember + ) .Concat(CreateMethodBodyDependencies(methodDefinition, methodMember)); if (methodDefinition.IsSetter || methodDefinition.IsGetter) { @@ -58,14 +70,20 @@ public void Execute() }); } - private void AssignDependenciesToProperty(MethodMember methodMember, MethodDefinition methodDefinition) + private void AssignDependenciesToProperty( + MethodMember methodMember, + MethodDefinition methodDefinition + ) { var methodForm = methodDefinition.GetMethodForm(); var matchFunction = GetMatchFunction(methodForm); matchFunction.RequiredNotNull(); - var accessedProperty = - MatchToPropertyMember(methodMember.Name, methodMember.FullName, matchFunction); + var accessedProperty = MatchToPropertyMember( + methodMember.Name, + methodMember.FullName, + matchFunction + ); if (accessedProperty == null) { return; @@ -90,9 +108,12 @@ private void AssignDependenciesToProperty(MethodMember methodMember, MethodDefin return; } - if (!methodBody.Instructions - .Select(instruction => instruction.Operand).OfType() - .Any(definition => definition.IsBackingField())) + if ( + !methodBody + .Instructions.Select(instruction => instruction.Operand) + .OfType() + .Any(definition => definition.IsBackingField()) + ) { accessedProperty.IsAutoProperty = false; } @@ -100,16 +121,23 @@ private void AssignDependenciesToProperty(MethodMember methodMember, MethodDefin [NotNull] private IEnumerable CreateMethodSignatureDependencies( - MethodReference methodReference, MethodMember methodMember) + MethodReference methodReference, + MethodMember methodMember + ) { return methodReference .GetSignatureTypes(_typeFactory) - .Select(signatureType => new MethodSignatureDependency(methodMember, signatureType)); + .Select(signatureType => new MethodSignatureDependency( + methodMember, + signatureType + )); } [NotNull] - private IEnumerable CreateMethodBodyDependencies(MethodDefinition methodDefinition, - MethodMember methodMember) + private IEnumerable CreateMethodBodyDependencies( + MethodDefinition methodDefinition, + MethodMember methodMember + ) { var methodBody = methodDefinition.Body; if (methodBody == null) @@ -117,17 +145,27 @@ private IEnumerable CreateMethodBodyDependencies(MethodDe yield break; } - var visitedMethodReferences = new List {methodDefinition}; + var visitedMethodReferences = new List { methodDefinition }; var bodyTypes = new List>(); if (methodDefinition.IsAsync()) { - HandleAsync(out methodDefinition, ref methodBody, bodyTypes, visitedMethodReferences); + HandleAsync( + out methodDefinition, + ref methodBody, + bodyTypes, + visitedMethodReferences + ); } if (methodDefinition.IsIterator()) { - HandleIterator(out methodDefinition, ref methodBody, bodyTypes, visitedMethodReferences); + HandleIterator( + out methodDefinition, + ref methodBody, + bodyTypes, + visitedMethodReferences + ); } bodyTypes.AddRange(methodDefinition.GetBodyTypes(_typeFactory).ToList()); @@ -138,54 +176,92 @@ private IEnumerable CreateMethodBodyDependencies(MethodDe var metaDataTypes = methodDefinition.GetMetaDataTypes(_typeFactory).ToList(); - var accessedFieldMembers = methodDefinition.GetAccessedFieldMembers(_typeFactory).ToList(); - - var calledMethodMembers = CreateMethodBodyDependenciesRecursive(methodBody, visitedMethodReferences, - bodyTypes, castTypes, typeCheckTypes, metaDataTypes, accessedFieldMembers); - - foreach (var calledMethodMember in calledMethodMembers.Where(method => !method.Member.IsCompilerGenerated) - .Distinct()) + var accessedFieldMembers = methodDefinition + .GetAccessedFieldMembers(_typeFactory) + .ToList(); + + var calledMethodMembers = CreateMethodBodyDependenciesRecursive( + methodBody, + visitedMethodReferences, + bodyTypes, + castTypes, + typeCheckTypes, + metaDataTypes, + accessedFieldMembers + ); + + foreach ( + var calledMethodMember in calledMethodMembers + .Where(method => !method.Member.IsCompilerGenerated) + .Distinct() + ) { yield return new MethodCallDependency(methodMember, calledMethodMember); } - foreach (var bodyType in bodyTypes.Where(instance => !instance.Type.IsCompilerGenerated).Distinct()) + foreach ( + var bodyType in bodyTypes + .Where(instance => !instance.Type.IsCompilerGenerated) + .Distinct() + ) { yield return new BodyTypeMemberDependency(methodMember, bodyType); } - foreach (var castType in castTypes.Where(instance => !instance.Type.IsCompilerGenerated).Distinct()) + foreach ( + var castType in castTypes + .Where(instance => !instance.Type.IsCompilerGenerated) + .Distinct() + ) { yield return new CastTypeDependency(methodMember, castType); } - foreach (var typeCheckType in typeCheckTypes.Where(instance => !instance.Type.IsCompilerGenerated) - .Distinct()) + foreach ( + var typeCheckType in typeCheckTypes + .Where(instance => !instance.Type.IsCompilerGenerated) + .Distinct() + ) { yield return new TypeCheckDependency(methodMember, typeCheckType); } - foreach (var metaDataType in metaDataTypes.Where(instance => !instance.Type.IsCompilerGenerated).Distinct()) + foreach ( + var metaDataType in metaDataTypes + .Where(instance => !instance.Type.IsCompilerGenerated) + .Distinct() + ) { yield return new MetaDataDependency(methodMember, metaDataType); } - foreach (var fieldMember in accessedFieldMembers.Where(field => !field.IsCompilerGenerated).Distinct()) + foreach ( + var fieldMember in accessedFieldMembers + .Where(field => !field.IsCompilerGenerated) + .Distinct() + ) { yield return new AccessFieldDependency(methodMember, fieldMember); } } - - private IEnumerable CreateMethodBodyDependenciesRecursive(MethodBody methodBody, - ICollection visitedMethodReferences, List> bodyTypes, - List> castTypes, List> typeCheckTypes, - List> metaDataTypes, List accessedFieldMembers) + private IEnumerable CreateMethodBodyDependenciesRecursive( + MethodBody methodBody, + ICollection visitedMethodReferences, + List> bodyTypes, + List> castTypes, + List> typeCheckTypes, + List> metaDataTypes, + List accessedFieldMembers + ) { - var calledMethodReferences = methodBody.Instructions.Select(instruction => instruction.Operand) + var calledMethodReferences = methodBody + .Instructions.Select(instruction => instruction.Operand) .OfType(); - foreach (var calledMethodReference in calledMethodReferences.Except(visitedMethodReferences)) + foreach ( + var calledMethodReference in calledMethodReferences.Except(visitedMethodReferences) + ) { visitedMethodReferences.Add(calledMethodReference); @@ -211,58 +287,96 @@ private IEnumerable CreateMethodBodyDependenciesRecursive( if (calledMethodDefinition.IsIterator()) { - HandleIterator(out calledMethodDefinition, ref calledMethodBody, bodyTypes, - visitedMethodReferences); + HandleIterator( + out calledMethodDefinition, + ref calledMethodBody, + bodyTypes, + visitedMethodReferences + ); } bodyTypes.AddRange(calledMethodDefinition.GetBodyTypes(_typeFactory)); castTypes.AddRange(calledMethodDefinition.GetCastTypes(_typeFactory)); typeCheckTypes.AddRange(calledMethodDefinition.GetTypeCheckTypes(_typeFactory)); metaDataTypes.AddRange(calledMethodDefinition.GetMetaDataTypes(_typeFactory)); - accessedFieldMembers.AddRange(calledMethodDefinition.GetAccessedFieldMembers(_typeFactory)); - - foreach (var dep in CreateMethodBodyDependenciesRecursive(calledMethodBody, - visitedMethodReferences, bodyTypes, castTypes, typeCheckTypes, metaDataTypes, - accessedFieldMembers)) + accessedFieldMembers.AddRange( + calledMethodDefinition.GetAccessedFieldMembers(_typeFactory) + ); + + foreach ( + var dep in CreateMethodBodyDependenciesRecursive( + calledMethodBody, + visitedMethodReferences, + bodyTypes, + castTypes, + typeCheckTypes, + metaDataTypes, + accessedFieldMembers + ) + ) { yield return dep; } } else { - var calledType = - _typeFactory.GetOrCreateStubTypeInstanceFromTypeReference(calledMethodReference.DeclaringType); + var calledType = _typeFactory.GetOrCreateStubTypeInstanceFromTypeReference( + calledMethodReference.DeclaringType + ); var calledMethodMember = - _typeFactory.GetOrCreateMethodMemberFromMethodReference(calledType, calledMethodReference); + _typeFactory.GetOrCreateMethodMemberFromMethodReference( + calledType, + calledMethodReference + ); yield return calledMethodMember; } } } - private void HandleIterator(out MethodDefinition methodDefinition, ref MethodBody methodBody, - List> bodyTypes, ICollection visitedMethodReferences) + private void HandleIterator( + out MethodDefinition methodDefinition, + ref MethodBody methodBody, + List> bodyTypes, + ICollection visitedMethodReferences + ) { - var compilerGeneratedGeneratorObject = - ((MethodReference) methodBody.Instructions.First(inst => inst.IsNewObjectOp()).Operand) - .DeclaringType.Resolve(); - methodDefinition = compilerGeneratedGeneratorObject.Methods - .First(method => method.Name == nameof(IEnumerator.MoveNext)); + var compilerGeneratedGeneratorObject = ( + (MethodReference)methodBody.Instructions.First(inst => inst.IsNewObjectOp()).Operand + ).DeclaringType.Resolve(); + methodDefinition = compilerGeneratedGeneratorObject.Methods.First(method => + method.Name == nameof(IEnumerator.MoveNext) + ); visitedMethodReferences.Add(methodDefinition); methodBody = methodDefinition.Body; - var fieldsExceptGeneratorStateInfo = compilerGeneratedGeneratorObject.Fields.Where(field => ! - (field.Name.EndsWith("__state") || field.Name.EndsWith("__current") || - field.Name.EndsWith("__initialThreadId") || field.Name.EndsWith("__this"))); - - bodyTypes.AddRange(fieldsExceptGeneratorStateInfo.Select(bodyField => - _typeFactory.GetOrCreateStubTypeInstanceFromTypeReference(bodyField.FieldType))); + var fieldsExceptGeneratorStateInfo = compilerGeneratedGeneratorObject.Fields.Where( + field => + !( + field.Name.EndsWith("__state") + || field.Name.EndsWith("__current") + || field.Name.EndsWith("__initialThreadId") + || field.Name.EndsWith("__this") + ) + ); + + bodyTypes.AddRange( + fieldsExceptGeneratorStateInfo.Select(bodyField => + _typeFactory.GetOrCreateStubTypeInstanceFromTypeReference(bodyField.FieldType) + ) + ); } - private void HandleAsync(out MethodDefinition methodDefinition, ref MethodBody methodBody, - List> bodyTypes, ICollection visitedMethodReferences) + private void HandleAsync( + out MethodDefinition methodDefinition, + ref MethodBody methodBody, + List> bodyTypes, + ICollection visitedMethodReferences + ) { - var compilerGeneratedGeneratorObject = ((MethodReference)methodBody.Instructions - .FirstOrDefault(inst => inst.IsNewObjectOp())?.Operand)?.DeclaringType.Resolve(); + var compilerGeneratedGeneratorObject = ( + (MethodReference) + methodBody.Instructions.FirstOrDefault(inst => inst.IsNewObjectOp())?.Operand + )?.DeclaringType.Resolve(); if (compilerGeneratedGeneratorObject == null) { @@ -270,18 +384,28 @@ private void HandleAsync(out MethodDefinition methodDefinition, ref MethodBody m return; } - methodDefinition = compilerGeneratedGeneratorObject.Methods - .First(method => method.Name == nameof(IAsyncStateMachine.MoveNext)); + methodDefinition = compilerGeneratedGeneratorObject.Methods.First(method => + method.Name == nameof(IAsyncStateMachine.MoveNext) + ); visitedMethodReferences.Add(methodDefinition); methodBody = methodDefinition.Body; - var fieldsExceptGeneratorStateInfo = compilerGeneratedGeneratorObject.Fields.Where(field => ! - (field.Name.EndsWith("__state") || field.Name.EndsWith("__builder") || - field.Name.EndsWith("__this"))).ToArray(); - - bodyTypes.AddRange(fieldsExceptGeneratorStateInfo.Select(bodyField => - _typeFactory.GetOrCreateStubTypeInstanceFromTypeReference(bodyField.FieldType))); + var fieldsExceptGeneratorStateInfo = compilerGeneratedGeneratorObject + .Fields.Where(field => + !( + field.Name.EndsWith("__state") + || field.Name.EndsWith("__builder") + || field.Name.EndsWith("__this") + ) + ) + .ToArray(); + + bodyTypes.AddRange( + fieldsExceptGeneratorStateInfo.Select(bodyField => + _typeFactory.GetOrCreateStubTypeInstanceFromTypeReference(bodyField.FieldType) + ) + ); } private static MatchFunction GetMatchFunction(MethodForm methodForm) @@ -303,23 +427,27 @@ private static MatchFunction GetMatchFunction(MethodForm methodForm) return matchFunction.RequiredNotNull(); } - private PropertyMember MatchToPropertyMember(string name, string fullName, MatchFunction matchFunction) + private PropertyMember MatchToPropertyMember( + string name, + string fullName, + MatchFunction matchFunction + ) { try { var accessedMemberName = matchFunction.MatchNameFunction(name); if (accessedMemberName != null) { - var foundNameMatches = _type.GetPropertyMembersWithName(accessedMemberName).SingleOrDefault(); + var foundNameMatches = _type + .GetPropertyMembersWithName(accessedMemberName) + .SingleOrDefault(); if (foundNameMatches != null) { return foundNameMatches; } } } - catch (InvalidOperationException) - { - } + catch (InvalidOperationException) { } var accessedMemberFullName = matchFunction.MatchNameFunction(fullName); return accessedMemberFullName != null @@ -327,10 +455,14 @@ private PropertyMember MatchToPropertyMember(string name, string fullName, Match : null; } - private PropertyMember GetPropertyMemberWithFullNameEndingWith(IType type, string detailedName) + private PropertyMember GetPropertyMemberWithFullNameEndingWith( + IType type, + string detailedName + ) { - return type.Members.OfType().FirstOrDefault(propertyMember => - propertyMember.FullName.EndsWith(detailedName)); + return type + .Members.OfType() + .FirstOrDefault(propertyMember => propertyMember.FullName.EndsWith(detailedName)); } } @@ -343,4 +475,4 @@ public MatchFunction(Func matchNameFunction) public Func MatchNameFunction { get; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/LoadTasks/AddTypesToNamespace.cs b/ArchUnitNET/Loader/LoadTasks/AddTypesToNamespace.cs index aa79fc343..71d18faea 100644 --- a/ArchUnitNET/Loader/LoadTasks/AddTypesToNamespace.cs +++ b/ArchUnitNET/Loader/LoadTasks/AddTypesToNamespace.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -23,7 +23,7 @@ public AddTypesToNamespace(Namespace ns, List types) public void Execute() { - ((List) _ns.Types).AddRange(_types.Where(type => type.Namespace.Equals(_ns))); + ((List)_ns.Types).AddRange(_types.Where(type => type.Namespace.Equals(_ns))); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/LoadTasks/CollectAssemblyAttributes.cs b/ArchUnitNET/Loader/LoadTasks/CollectAssemblyAttributes.cs index 725ead04e..461fa348b 100644 --- a/ArchUnitNET/Loader/LoadTasks/CollectAssemblyAttributes.cs +++ b/ArchUnitNET/Loader/LoadTasks/CollectAssemblyAttributes.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Linq; using ArchUnitNET.Domain; @@ -17,8 +17,11 @@ internal class CollectAssemblyAttributes : ILoadTask private readonly AssemblyDefinition _assemblyDefinition; private readonly TypeFactory _typeFactory; - public CollectAssemblyAttributes(Assembly assembly, AssemblyDefinition assemblyDefinition, - TypeFactory typeFactory) + public CollectAssemblyAttributes( + Assembly assembly, + AssemblyDefinition assemblyDefinition, + TypeFactory typeFactory + ) { _assembly = assembly; _assemblyDefinition = assemblyDefinition; @@ -27,10 +30,12 @@ public CollectAssemblyAttributes(Assembly assembly, AssemblyDefinition assemblyD public void Execute() { - var attributeInstances = - _assemblyDefinition.CustomAttributes - .Select(attr => attr.CreateAttributeFromCustomAttribute(_typeFactory)).ToList(); + var attributeInstances = _assemblyDefinition + .CustomAttributes.Select(attr => + attr.CreateAttributeFromCustomAttribute(_typeFactory) + ) + .ToList(); _assembly.AttributeInstances.AddRange(attributeInstances); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/LoadTasks/ILoadTask.cs b/ArchUnitNET/Loader/LoadTasks/ILoadTask.cs index c8590a25b..eae3d50c0 100644 --- a/ArchUnitNET/Loader/LoadTasks/ILoadTask.cs +++ b/ArchUnitNET/Loader/LoadTasks/ILoadTask.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 namespace ArchUnitNET.Loader.LoadTasks @@ -10,4 +10,4 @@ internal interface ILoadTask { void Execute(); } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/MethodMemberRegistry.cs b/ArchUnitNET/Loader/MethodMemberRegistry.cs index 07c49f01f..41870fe37 100644 --- a/ArchUnitNET/Loader/MethodMemberRegistry.cs +++ b/ArchUnitNET/Loader/MethodMemberRegistry.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System; using System.Collections.Generic; @@ -19,10 +19,16 @@ internal class MethodMemberRegistry private readonly Dictionary _allMethods = new Dictionary(); - public MethodMemberInstance GetOrCreateMethodFromMethodReference([NotNull] MethodReference methodReference, - [NotNull] Func createFunc) + public MethodMemberInstance GetOrCreateMethodFromMethodReference( + [NotNull] MethodReference methodReference, + [NotNull] Func createFunc + ) { - return RegistryUtils.GetFromDictOrCreateAndAdd(methodReference.BuildFullName(), _allMethods, createFunc); + return RegistryUtils.GetFromDictOrCreateAndAdd( + methodReference.BuildFullName(), + _allMethods, + createFunc + ); } public IEnumerable GetAllMethodMembers() @@ -30,4 +36,4 @@ public IEnumerable GetAllMethodMembers() return _allMethods.Values.Select(instance => instance.Member).Distinct(); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/MonoCecilAttributeExtensions.cs b/ArchUnitNET/Loader/MonoCecilAttributeExtensions.cs index d0c92ae14..b408162fc 100644 --- a/ArchUnitNET/Loader/MonoCecilAttributeExtensions.cs +++ b/ArchUnitNET/Loader/MonoCecilAttributeExtensions.cs @@ -1,9 +1,9 @@ // 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; @@ -16,11 +16,15 @@ namespace ArchUnitNET.Loader internal static class MonoCecilAttributeExtensions { [NotNull] - public static AttributeInstance CreateAttributeFromCustomAttribute(this CustomAttribute customAttribute, - TypeFactory typeFactory) + public static AttributeInstance CreateAttributeFromCustomAttribute( + this CustomAttribute customAttribute, + TypeFactory typeFactory + ) { var attributeTypeReference = customAttribute.AttributeType; - var attributeType = typeFactory.GetOrCreateStubTypeInstanceFromTypeReference(attributeTypeReference); + var attributeType = typeFactory.GetOrCreateStubTypeInstanceFromTypeReference( + attributeTypeReference + ); var attribute = attributeType.Type is Class cls ? new Attribute(cls) : new Attribute(attributeType.Type, null, null); @@ -29,22 +33,36 @@ public static AttributeInstance CreateAttributeFromCustomAttribute(this CustomAt foreach (var constructorArgument in customAttribute.ConstructorArguments) { - HandleAttributeArgument(constructorArgument, typeFactory, out var value, out var type); + HandleAttributeArgument( + constructorArgument, + typeFactory, + out var value, + out var type + ); attributeArguments.Add(new AttributeArgument(value, type)); } foreach (var namedArgument in customAttribute.Fields.Concat(customAttribute.Properties)) { var name = namedArgument.Name; - HandleAttributeArgument(namedArgument.Argument, typeFactory, out var value, out var type); + HandleAttributeArgument( + namedArgument.Argument, + typeFactory, + out var value, + out var type + ); attributeArguments.Add(new AttributeNamedArgument(name, value, type)); } return new AttributeInstance(attribute, attributeArguments); } - private static void HandleAttributeArgument(CustomAttributeArgument argument, TypeFactory typeFactory, - out object value, out ITypeInstance type) + private static void HandleAttributeArgument( + CustomAttributeArgument argument, + TypeFactory typeFactory, + out object value, + out ITypeInstance type + ) { while (argument.Value is CustomAttributeArgument arg) //if would work too { @@ -55,11 +73,12 @@ private static void HandleAttributeArgument(CustomAttributeArgument argument, Ty if (argument.Value is IEnumerable attArgEnumerable) { - value = (from attArg in attArgEnumerable - select attArg.Value is TypeReference tr - ? typeFactory.GetOrCreateStubTypeInstanceFromTypeReference(tr) - : attArg.Value) - .ToArray(); + value = ( + from attArg in attArgEnumerable + select attArg.Value is TypeReference tr + ? typeFactory.GetOrCreateStubTypeInstanceFromTypeReference(tr) + : attArg.Value + ).ToArray(); } else { @@ -69,4 +88,4 @@ select attArg.Value is TypeReference tr } } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/MonoCecilMemberExtensions.cs b/ArchUnitNET/Loader/MonoCecilMemberExtensions.cs index 9c681f954..faef7edb3 100644 --- a/ArchUnitNET/Loader/MonoCecilMemberExtensions.cs +++ b/ArchUnitNET/Loader/MonoCecilMemberExtensions.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -22,14 +22,25 @@ internal static class MonoCecilMemberExtensions { private static readonly OpCode[] BodyTypeOpCodes = { - OpCodes.Box, OpCodes.Newarr, OpCodes.Initobj, OpCodes.Unbox, OpCodes.Unbox_Any, OpCodes.Ldelem_Any, - OpCodes.Ldobj, OpCodes.Stelem_Any, OpCodes.Ldelema, OpCodes.Stobj + OpCodes.Box, + OpCodes.Newarr, + OpCodes.Initobj, + OpCodes.Unbox, + OpCodes.Unbox_Any, + OpCodes.Ldelem_Any, + OpCodes.Ldobj, + OpCodes.Stelem_Any, + OpCodes.Ldelema, + OpCodes.Stobj }; //maybe not complete internal static string BuildFullName(this MethodReference methodReference) { - return methodReference.FullName + methodReference.GenericParameters.Aggregate(string.Empty, - (current, newElement) => current + "<" + newElement.Name + ">"); + return methodReference.FullName + + methodReference.GenericParameters.Aggregate( + string.Empty, + (current, newElement) => current + "<" + newElement.Name + ">" + ); } [NotNull] @@ -65,17 +76,23 @@ internal static string BuildMethodMemberName(this MethodReference methodReferenc [NotNull] internal static IEnumerable GetAllMethodCustomAttributes( - this MethodDefinition methodDefinition) + this MethodDefinition methodDefinition + ) { - return methodDefinition.CustomAttributes - .Concat(methodDefinition.Parameters.SelectMany(parameterDefinition => - parameterDefinition.CustomAttributes)) + return methodDefinition + .CustomAttributes.Concat( + methodDefinition.Parameters.SelectMany(parameterDefinition => + parameterDefinition.CustomAttributes + ) + ) .Concat(methodDefinition.MethodReturnType.CustomAttributes); } [NotNull] - internal static IEnumerable> GetSignatureTypes(this MethodReference methodReference, - TypeFactory typeFactory) + internal static IEnumerable> GetSignatureTypes( + this MethodReference methodReference, + TypeFactory typeFactory + ) { var parameters = GetAllParameters(methodReference, typeFactory).ToList(); var returnType = GetReturnType(methodReference, typeFactory); @@ -87,16 +104,23 @@ internal static IEnumerable> GetSignatureTypes(this MethodR return parameters; } - private static ITypeInstance GetReturnType(this MethodReference methodReference, TypeFactory typeFactory) + private static ITypeInstance GetReturnType( + this MethodReference methodReference, + TypeFactory typeFactory + ) { return ReturnsVoid(methodReference) ? null - : typeFactory.GetOrCreateStubTypeInstanceFromTypeReference(methodReference.MethodReturnType.ReturnType); + : typeFactory.GetOrCreateStubTypeInstanceFromTypeReference( + methodReference.MethodReturnType.ReturnType + ); } [NotNull] - private static IEnumerable> GetAllParameters(this MethodReference methodReference, - TypeFactory typeFactory) + private static IEnumerable> GetAllParameters( + this MethodReference methodReference, + TypeFactory typeFactory + ) { var parameters = methodReference.GetParameters(typeFactory).ToList(); var genericParameters = methodReference.GetGenericParameters(typeFactory).ToList(); @@ -105,111 +129,172 @@ private static IEnumerable> GetAllParameters(this MethodRef } [NotNull] - internal static IEnumerable> GetParameters(this MethodReference method, - TypeFactory typeFactory) + internal static IEnumerable> GetParameters( + this MethodReference method, + TypeFactory typeFactory + ) { - return method.Parameters.Select(parameter => - { - var typeReference = parameter.ParameterType; - return typeFactory.GetOrCreateStubTypeInstanceFromTypeReference(typeReference); - }).Distinct(); + return method + .Parameters.Select(parameter => + { + var typeReference = parameter.ParameterType; + return typeFactory.GetOrCreateStubTypeInstanceFromTypeReference(typeReference); + }) + .Distinct(); } [NotNull] - private static IEnumerable> GetGenericParameters(this MethodReference method, - TypeFactory typeFactory) + private static IEnumerable> GetGenericParameters( + this MethodReference method, + TypeFactory typeFactory + ) { - return method.GenericParameters.Select(parameter => - { - var typeReference = parameter.GetElementType(); - return typeFactory.GetOrCreateStubTypeInstanceFromTypeReference(typeReference); - }).Distinct(); + return method + .GenericParameters.Select(parameter => + { + var typeReference = parameter.GetElementType(); + return typeFactory.GetOrCreateStubTypeInstanceFromTypeReference(typeReference); + }) + .Distinct(); } [NotNull] - internal static IEnumerable> GetBodyTypes(this MethodDefinition methodDefinition, - TypeFactory typeFactory) + internal static IEnumerable> GetBodyTypes( + this MethodDefinition methodDefinition, + TypeFactory typeFactory + ) { - var instructions = methodDefinition.Body?.Instructions ?? Enumerable.Empty(); + var instructions = + methodDefinition.Body?.Instructions ?? Enumerable.Empty(); var bodyTypes = instructions - .Where(inst => BodyTypeOpCodes.Contains(inst.OpCode) && inst.Operand is TypeReference) - .Select(inst => typeFactory.GetOrCreateStubTypeInstanceFromTypeReference((TypeReference) inst.Operand)); + .Where(inst => + BodyTypeOpCodes.Contains(inst.OpCode) && inst.Operand is TypeReference + ) + .Select(inst => + typeFactory.GetOrCreateStubTypeInstanceFromTypeReference( + (TypeReference)inst.Operand + ) + ); //OpCodes.Ldstr should create a dependency to string, but it does not have a TypeReference as Operand so no Type can be created - bodyTypes = bodyTypes.Union(methodDefinition.Body?.Variables.Select(variableDefinition => - { - var variableTypeReference = variableDefinition.VariableType; - return typeFactory.GetOrCreateStubTypeInstanceFromTypeReference(variableTypeReference); - }) ?? Enumerable.Empty>()).Distinct(); + bodyTypes = bodyTypes + .Union( + methodDefinition.Body?.Variables.Select(variableDefinition => + { + var variableTypeReference = variableDefinition.VariableType; + return typeFactory.GetOrCreateStubTypeInstanceFromTypeReference( + variableTypeReference + ); + }) ?? Enumerable.Empty>() + ) + .Distinct(); return bodyTypes; } [NotNull] - internal static IEnumerable> GetCastTypes(this MethodDefinition methodDefinition, - TypeFactory typeFactory) + internal static IEnumerable> GetCastTypes( + this MethodDefinition methodDefinition, + TypeFactory typeFactory + ) { - var instructions = methodDefinition.Body?.Instructions ?? Enumerable.Empty(); - - return instructions.Where(inst => inst.OpCode == OpCodes.Castclass && inst.Operand is TypeReference) - .Select(inst => typeFactory.GetOrCreateStubTypeInstanceFromTypeReference((TypeReference) inst.Operand)); + var instructions = + methodDefinition.Body?.Instructions ?? Enumerable.Empty(); + + return instructions + .Where(inst => inst.OpCode == OpCodes.Castclass && inst.Operand is TypeReference) + .Select(inst => + typeFactory.GetOrCreateStubTypeInstanceFromTypeReference( + (TypeReference)inst.Operand + ) + ); } [NotNull] - internal static IEnumerable> GetMetaDataTypes(this MethodDefinition methodDefinition, - TypeFactory typeFactory) + internal static IEnumerable> GetMetaDataTypes( + this MethodDefinition methodDefinition, + TypeFactory typeFactory + ) { - var instructions = methodDefinition.Body?.Instructions ?? Enumerable.Empty(); - - return instructions.Where(inst => inst.OpCode == OpCodes.Ldtoken && inst.Operand is TypeReference) - .Select(inst => typeFactory.GetOrCreateStubTypeInstanceFromTypeReference((TypeReference) inst.Operand)); + var instructions = + methodDefinition.Body?.Instructions ?? Enumerable.Empty(); + + return instructions + .Where(inst => inst.OpCode == OpCodes.Ldtoken && inst.Operand is TypeReference) + .Select(inst => + typeFactory.GetOrCreateStubTypeInstanceFromTypeReference( + (TypeReference)inst.Operand + ) + ); } [NotNull] - internal static IEnumerable> GetTypeCheckTypes(this MethodDefinition methodDefinition, - TypeFactory typeFactory) + internal static IEnumerable> GetTypeCheckTypes( + this MethodDefinition methodDefinition, + TypeFactory typeFactory + ) { - var instructions = methodDefinition.Body?.Instructions ?? Enumerable.Empty(); - - return instructions.Where(inst => inst.OpCode == OpCodes.Isinst && inst.Operand is TypeReference) - .Select(inst => typeFactory.GetOrCreateStubTypeInstanceFromTypeReference((TypeReference) inst.Operand)); + var instructions = + methodDefinition.Body?.Instructions ?? Enumerable.Empty(); + + return instructions + .Where(inst => inst.OpCode == OpCodes.Isinst && inst.Operand is TypeReference) + .Select(inst => + typeFactory.GetOrCreateStubTypeInstanceFromTypeReference( + (TypeReference)inst.Operand + ) + ); } internal static bool IsIterator(this MethodDefinition methodDefinition) { - return methodDefinition.CustomAttributes.Any(att => att.AttributeType.FullName == typeof(System.Runtime - .CompilerServices.IteratorStateMachineAttribute).FullName); + return methodDefinition.CustomAttributes.Any(att => + att.AttributeType.FullName + == typeof(System.Runtime.CompilerServices.IteratorStateMachineAttribute).FullName + ); } internal static bool IsAsync(this MethodDefinition methodDefinition) { - return methodDefinition.CustomAttributes.Any(att => att.AttributeType.FullName == typeof(System.Runtime - .CompilerServices.AsyncStateMachineAttribute).FullName); + return methodDefinition.CustomAttributes.Any(att => + att.AttributeType.FullName + == typeof(System.Runtime.CompilerServices.AsyncStateMachineAttribute).FullName + ); } [NotNull] - internal static IEnumerable GetAccessedFieldMembers(this MethodDefinition methodDefinition, - TypeFactory typeFactory) + internal static IEnumerable GetAccessedFieldMembers( + this MethodDefinition methodDefinition, + TypeFactory typeFactory + ) { var accessedFieldMembers = new List(); - var instructions = methodDefinition.Body?.Instructions.ToList() ?? new List(); - var accessedFieldReferences = - instructions.Select(inst => inst.Operand).OfType().Distinct(); + var instructions = + methodDefinition.Body?.Instructions.ToList() ?? new List(); + var accessedFieldReferences = instructions + .Select(inst => inst.Operand) + .OfType() + .Distinct(); foreach (var fieldReference in accessedFieldReferences) { - var declaringType = - typeFactory.GetOrCreateStubTypeInstanceFromTypeReference(fieldReference.DeclaringType); - var matchingFieldMembers = declaringType.Type.GetFieldMembers() - .Where(member => member.Name == fieldReference.Name).ToList(); + var declaringType = typeFactory.GetOrCreateStubTypeInstanceFromTypeReference( + fieldReference.DeclaringType + ); + var matchingFieldMembers = declaringType + .Type.GetFieldMembers() + .Where(member => member.Name == fieldReference.Name) + .ToList(); switch (matchingFieldMembers.Count) { case 0: - var stubFieldMember = - typeFactory.CreateStubFieldMemberFromFieldReference(declaringType.Type, fieldReference); + var stubFieldMember = typeFactory.CreateStubFieldMemberFromFieldReference( + declaringType.Type, + fieldReference + ); accessedFieldMembers.Add(stubFieldMember); break; case 1: @@ -217,7 +302,8 @@ internal static IEnumerable GetAccessedFieldMembers(this MethodDefi break; default: throw new MultipleOccurrencesInSequenceException( - $"Multiple Fields matching {fieldReference.FullName} found in provided type."); + $"Multiple Fields matching {fieldReference.FullName} found in provided type." + ); } } @@ -226,9 +312,10 @@ internal static IEnumerable GetAccessedFieldMembers(this MethodDefi internal static bool IsCompilerGenerated(this MemberReference memberReference) { - var declaringType = memberReference.Resolve()?.DeclaringType ?? memberReference.DeclaringType; - return declaringType != null && declaringType.Name.HasCompilerGeneratedName() || - memberReference.Name.HasCompilerGeneratedName(); + var declaringType = + memberReference.Resolve()?.DeclaringType ?? memberReference.DeclaringType; + return declaringType != null && declaringType.Name.HasCompilerGeneratedName() + || memberReference.Name.HasCompilerGeneratedName(); } internal static bool HasCompilerGeneratedName(this string name) @@ -306,4 +393,4 @@ internal static Visibility GetVisibility([CanBeNull] this MethodDefinition metho throw new ArgumentException("The method definition seems to have no visibility."); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/MonoCecilTypeExtensions.cs b/ArchUnitNET/Loader/MonoCecilTypeExtensions.cs index 34ccc632d..ea3246203 100644 --- a/ArchUnitNET/Loader/MonoCecilTypeExtensions.cs +++ b/ArchUnitNET/Loader/MonoCecilTypeExtensions.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System; using ArchUnitNET.Domain; @@ -20,12 +20,16 @@ internal static string BuildFullName(this TypeReference typeReference) { if (typeReference.IsGenericParameter) { - var genericParameter = (GenericParameter) typeReference; - - return (genericParameter.Type == GenericParameterType.Type - ? genericParameter.DeclaringType.BuildFullName() - : genericParameter.DeclaringMethod.BuildFullName()) - + "+<" + genericParameter.Name + ">"; + var genericParameter = (GenericParameter)typeReference; + + return ( + genericParameter.Type == GenericParameterType.Type + ? genericParameter.DeclaringType.BuildFullName() + : genericParameter.DeclaringMethod.BuildFullName() + ) + + "+<" + + genericParameter.Name + + ">"; } return typeReference.FullName.Replace("/", "+"); @@ -50,8 +54,8 @@ internal static bool IsAttribute([CanBeNull] this TypeDefinition typeDefinition) { if (typeDefinition?.BaseType != null) { - return typeDefinition.BaseType.FullName == "System.Attribute" || - IsAttribute(typeDefinition.BaseType.Resolve()); + return typeDefinition.BaseType.FullName == "System.Attribute" + || IsAttribute(typeDefinition.BaseType.Resolve()); } return false; @@ -94,7 +98,9 @@ internal static Visibility GetVisibility([CanBeNull] this TypeDefinition typeDef return Internal; } - throw new ArgumentException("The provided type definition seems to have no visibility."); + throw new ArgumentException( + "The provided type definition seems to have no visibility." + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/NamespaceRegistry.cs b/ArchUnitNET/Loader/NamespaceRegistry.cs index 2c696616a..79478ee73 100644 --- a/ArchUnitNET/Loader/NamespaceRegistry.cs +++ b/ArchUnitNET/Loader/NamespaceRegistry.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -11,14 +11,18 @@ namespace ArchUnitNET.Loader { internal class NamespaceRegistry { - private readonly Dictionary _namespaces = new Dictionary(); + private readonly Dictionary _namespaces = + new Dictionary(); public IEnumerable Namespaces => _namespaces.Values; public Namespace GetOrCreateNamespace(string typeNamespaceName) { - return RegistryUtils.GetFromDictOrCreateAndAdd(typeNamespaceName, _namespaces, - s => new Namespace(typeNamespaceName, new List())); + return RegistryUtils.GetFromDictOrCreateAndAdd( + typeNamespaceName, + _namespaces, + s => new Namespace(typeNamespaceName, new List()) + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/RegexUtils.cs b/ArchUnitNET/Loader/RegexUtils.cs index dce173dcc..c0da96dc4 100644 --- a/ArchUnitNET/Loader/RegexUtils.cs +++ b/ArchUnitNET/Loader/RegexUtils.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Text.RegularExpressions; @@ -42,4 +42,4 @@ public static bool MatchNamespaces(string goalNamespace, string currentNamespace return goalNamespace == null || currentNamespace.StartsWith(goalNamespace); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/RegistryUtils.cs b/ArchUnitNET/Loader/RegistryUtils.cs index 8e13c0643..446f3c52e 100644 --- a/ArchUnitNET/Loader/RegistryUtils.cs +++ b/ArchUnitNET/Loader/RegistryUtils.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -11,7 +11,11 @@ namespace ArchUnitNET.Loader { internal static class RegistryUtils { - public static T GetFromDictOrCreateAndAdd(TK key, Dictionary dict, Func createFunc) + public static T GetFromDictOrCreateAndAdd( + TK key, + Dictionary dict, + Func createFunc + ) { if (dict.TryGetValue(key, out var value)) { @@ -24,4 +28,4 @@ public static T GetFromDictOrCreateAndAdd(TK key, Dictionary dict, return value; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/Type.cs b/ArchUnitNET/Loader/Type.cs index 8cb76250b..219433af8 100644 --- a/ArchUnitNET/Loader/Type.cs +++ b/ArchUnitNET/Loader/Type.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -14,8 +14,17 @@ namespace ArchUnitNET.Loader { public class Type : IType { - public Type(string fullname, string name, Assembly assembly, Namespace namespc, Visibility visibility, - bool isNested, bool isGeneric, bool isStub, bool isCompilerGenerated) + public Type( + string fullname, + string name, + Assembly assembly, + Namespace namespc, + Visibility visibility, + bool isNested, + bool isGeneric, + bool isStub, + bool isCompilerGenerated + ) { FullName = fullname; Name = name; @@ -49,16 +58,18 @@ public Type(string fullname, string name, Assembly assembly, Namespace namespc, public bool IsStub { get; } public MemberList Members { get; } = new MemberList(); - public IEnumerable Attributes => AttributeInstances.Select(instance => instance.Type); - public List AttributeInstances { get; } = new List(); + public IEnumerable Attributes => + AttributeInstances.Select(instance => instance.Type); + public List AttributeInstances { get; } = new List(); public List Dependencies { get; } = new List(); public List BackwardsDependencies { get; } = new List(); - public IEnumerable ImplementedInterfaces => Dependencies - .OfType() - .Select(dependency => dependency.Target); + public IEnumerable ImplementedInterfaces => + Dependencies + .OfType() + .Select(dependency => dependency.Target); public override string ToString() { @@ -82,7 +93,7 @@ public override bool Equals(object obj) return true; } - return obj.GetType() == GetType() && Equals((Type) obj); + return obj.GetType() == GetType() && Equals((Type)obj); } public override int GetHashCode() @@ -90,4 +101,4 @@ public override int GetHashCode() return FullName != null ? FullName.GetHashCode() : 0; } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/TypeFactory.cs b/ArchUnitNET/Loader/TypeFactory.cs index acc21c80e..ab5071b28 100644 --- a/ArchUnitNET/Loader/TypeFactory.cs +++ b/ArchUnitNET/Loader/TypeFactory.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -28,8 +28,13 @@ internal class TypeFactory private readonly NamespaceRegistry _namespaceRegistry; private readonly TypeRegistry _typeRegistry; - public TypeFactory(TypeRegistry typeRegistry, MethodMemberRegistry methodMemberRegistry, - LoadTaskRegistry loadTaskRegistry, AssemblyRegistry assemblyRegistry, NamespaceRegistry namespaceRegistry) + public TypeFactory( + TypeRegistry typeRegistry, + MethodMemberRegistry methodMemberRegistry, + LoadTaskRegistry loadTaskRegistry, + AssemblyRegistry assemblyRegistry, + NamespaceRegistry namespaceRegistry + ) { _loadTaskRegistry = loadTaskRegistry; _assemblyRegistry = assemblyRegistry; @@ -46,35 +51,58 @@ public IEnumerable GetAllNonCompilerGeneratedTypes() [NotNull] internal IType GetOrCreateTypeFromTypeReference(TypeReference typeReference) { - return _typeRegistry.GetOrCreateTypeFromTypeReference(typeReference, - s => CreateTypeFromTypeReference(typeReference, false)).Type; + return _typeRegistry + .GetOrCreateTypeFromTypeReference( + typeReference, + s => CreateTypeFromTypeReference(typeReference, false) + ) + .Type; } [NotNull] - internal ITypeInstance GetOrCreateStubTypeInstanceFromTypeReference(TypeReference typeReference) + internal ITypeInstance GetOrCreateStubTypeInstanceFromTypeReference( + TypeReference typeReference + ) { - return _typeRegistry.GetOrCreateTypeFromTypeReference(typeReference, - s => CreateTypeFromTypeReference(typeReference, true)); + return _typeRegistry.GetOrCreateTypeFromTypeReference( + typeReference, + s => CreateTypeFromTypeReference(typeReference, true) + ); } [NotNull] - internal MethodMemberInstance GetOrCreateMethodMemberFromMethodReference([NotNull] IType type, - [NotNull] MethodReference methodReference) + internal MethodMemberInstance GetOrCreateMethodMemberFromMethodReference( + [NotNull] IType type, + [NotNull] MethodReference methodReference + ) { - return _methodMemberRegistry.GetOrCreateMethodFromMethodReference(methodReference, - s => CreateMethodMemberFromMethodReference(new TypeInstance(type), methodReference)); + return _methodMemberRegistry.GetOrCreateMethodFromMethodReference( + methodReference, + s => + CreateMethodMemberFromMethodReference( + new TypeInstance(type), + methodReference + ) + ); } [NotNull] internal MethodMemberInstance GetOrCreateMethodMemberFromMethodReference( - [NotNull] ITypeInstance typeInstance, [NotNull] MethodReference methodReference) + [NotNull] ITypeInstance typeInstance, + [NotNull] MethodReference methodReference + ) { - return _methodMemberRegistry.GetOrCreateMethodFromMethodReference(methodReference, - s => CreateMethodMemberFromMethodReference(typeInstance, methodReference)); + return _methodMemberRegistry.GetOrCreateMethodFromMethodReference( + methodReference, + s => CreateMethodMemberFromMethodReference(typeInstance, methodReference) + ); } [NotNull] - private ITypeInstance CreateTypeFromTypeReference(TypeReference typeReference, bool isStub) + private ITypeInstance CreateTypeFromTypeReference( + TypeReference typeReference, + bool isStub + ) { if (typeReference.IsGenericParameter) { @@ -84,9 +112,13 @@ private ITypeInstance CreateTypeFromTypeReference(TypeReference typeRefer ? genericParameter.DeclaringMethod.BuildFullName() : genericParameter.DeclaringType.BuildFullName(); - return new TypeInstance(CreateGenericParameter(genericParameter, - declaringTypeFullName, - declarerIsMethod)); + return new TypeInstance( + CreateGenericParameter( + genericParameter, + declaringTypeFullName, + declarerIsMethod + ) + ); } if (typeReference.IsArray) @@ -99,31 +131,58 @@ private ITypeInstance CreateTypeFromTypeReference(TypeReference typeRefer typeReference = arrayType.ElementType; } while (typeReference.IsArray); - var elementTypeInstance = GetOrCreateStubTypeInstanceFromTypeReference(typeReference); + var elementTypeInstance = GetOrCreateStubTypeInstanceFromTypeReference( + typeReference + ); switch (elementTypeInstance.Type) { case Interface intf: - return new TypeInstance(intf, elementTypeInstance.GenericArguments, dimensions); + return new TypeInstance( + intf, + elementTypeInstance.GenericArguments, + dimensions + ); case Attribute att: - return new TypeInstance(att, elementTypeInstance.GenericArguments, dimensions); + return new TypeInstance( + att, + elementTypeInstance.GenericArguments, + dimensions + ); case Class cls: - return new TypeInstance(cls, elementTypeInstance.GenericArguments, dimensions); + return new TypeInstance( + cls, + elementTypeInstance.GenericArguments, + dimensions + ); case Struct str: - return new TypeInstance(str, elementTypeInstance.GenericArguments, dimensions); + return new TypeInstance( + str, + elementTypeInstance.GenericArguments, + dimensions + ); case Enum en: - return new TypeInstance(en, elementTypeInstance.GenericArguments, dimensions); + return new TypeInstance( + en, + elementTypeInstance.GenericArguments, + dimensions + ); default: - return new TypeInstance(elementTypeInstance.Type, elementTypeInstance.GenericArguments, - dimensions); + return new TypeInstance( + elementTypeInstance.Type, + elementTypeInstance.GenericArguments, + dimensions + ); } } if (typeReference.IsGenericInstance) { - var elementType = GetOrCreateStubTypeInstanceFromTypeReference(typeReference.GetElementType()).Type; + var elementType = GetOrCreateStubTypeInstanceFromTypeReference( + typeReference.GetElementType() + ).Type; var genericInstance = (GenericInstanceType)typeReference; - var genericArguments = genericInstance.GenericArguments - .Select(CreateGenericArgumentFromTypeReference) + var genericArguments = genericInstance + .GenericArguments.Select(CreateGenericArgumentFromTypeReference) .Where(argument => !argument.Type.IsCompilerGenerated); switch (elementType) { @@ -159,49 +218,93 @@ private ITypeInstance CreateTypeFromTypeReference(TypeReference typeRefer declaringTypeReference = declaringTypeReference.DeclaringType; } - var currentNamespace = _namespaceRegistry.GetOrCreateNamespace(declaringTypeReference.Namespace); - var currentAssembly = _assemblyRegistry.GetOrCreateAssembly(typeReference.Module.Assembly.Name.FullName, - typeReference.Module.Assembly.FullName, true, null); + var currentNamespace = _namespaceRegistry.GetOrCreateNamespace( + declaringTypeReference.Namespace + ); + var currentAssembly = _assemblyRegistry.GetOrCreateAssembly( + typeReference.Module.Assembly.Name.FullName, + typeReference.Module.Assembly.FullName, + true, + null + ); Type type; - bool isCompilerGenerated, isNested, isGeneric; + bool isCompilerGenerated, + isNested, + isGeneric; if (typeDefinition == null) { isCompilerGenerated = typeReference.IsCompilerGenerated(); isNested = typeReference.IsNested; isGeneric = typeReference.HasGenericParameters; - type = new Type(typeName, typeReference.Name, currentAssembly, currentNamespace, NotAccessible, - isNested, isGeneric, true, isCompilerGenerated); + type = new Type( + typeName, + typeReference.Name, + currentAssembly, + currentNamespace, + NotAccessible, + isNested, + isGeneric, + true, + isCompilerGenerated + ); return new TypeInstance(type); } const string fixedElementField = "FixedElementField"; - if (typeDefinition.CustomAttributes - .Any(att => att.AttributeType.FullName == typeof(UnsafeValueTypeAttribute).FullName) && - typeDefinition.Fields.Any(field => field.Name == fixedElementField)) + if ( + typeDefinition.CustomAttributes.Any(att => + att.AttributeType.FullName == typeof(UnsafeValueTypeAttribute).FullName + ) && typeDefinition.Fields.Any(field => field.Name == fixedElementField) + ) { - var arrayType = typeDefinition.Fields.First(field => field.Name == fixedElementField).FieldType; + var arrayType = typeDefinition + .Fields.First(field => field.Name == fixedElementField) + .FieldType; var arrayTypeInstance = GetOrCreateStubTypeInstanceFromTypeReference(arrayType); var dimensions = new List { 1 }; switch (arrayTypeInstance.Type) { case Interface intf: - return new TypeInstance(intf, arrayTypeInstance.GenericArguments, dimensions); + return new TypeInstance( + intf, + arrayTypeInstance.GenericArguments, + dimensions + ); case Attribute att: - return new TypeInstance(att, arrayTypeInstance.GenericArguments, dimensions); + return new TypeInstance( + att, + arrayTypeInstance.GenericArguments, + dimensions + ); case Class cls: - return new TypeInstance(cls, arrayTypeInstance.GenericArguments, dimensions); + return new TypeInstance( + cls, + arrayTypeInstance.GenericArguments, + dimensions + ); case Struct str: - return new TypeInstance(str, arrayTypeInstance.GenericArguments, dimensions); + return new TypeInstance( + str, + arrayTypeInstance.GenericArguments, + dimensions + ); case Enum en: - return new TypeInstance(en, arrayTypeInstance.GenericArguments, dimensions); + return new TypeInstance( + en, + arrayTypeInstance.GenericArguments, + dimensions + ); default: - return new TypeInstance(arrayTypeInstance.Type, arrayTypeInstance.GenericArguments, - dimensions); + return new TypeInstance( + arrayTypeInstance.Type, + arrayTypeInstance.GenericArguments, + dimensions + ); } } @@ -209,8 +312,17 @@ private ITypeInstance CreateTypeFromTypeReference(TypeReference typeRefer isCompilerGenerated = typeDefinition.IsCompilerGenerated(); isNested = typeDefinition.IsNested; isGeneric = typeDefinition.HasGenericParameters; - type = new Type(typeName, typeReference.Name, currentAssembly, currentNamespace, visibility, isNested, - isGeneric, isStub, isCompilerGenerated); + type = new Type( + typeName, + typeReference.Name, + currentAssembly, + currentNamespace, + visibility, + isNested, + isGeneric, + isStub, + isCompilerGenerated + ); var genericParameters = GetGenericParameters(typeDefinition); type.GenericParameters.AddRange(genericParameters); @@ -223,9 +335,9 @@ private ITypeInstance CreateTypeFromTypeReference(TypeReference typeRefer } else if (typeDefinition.IsAttribute()) { - createdTypeInstance = - new TypeInstance(new Attribute(type, typeDefinition.IsAbstract, - typeDefinition.IsSealed)); + createdTypeInstance = new TypeInstance( + new Attribute(type, typeDefinition.IsAbstract, typeDefinition.IsSealed) + ); } else if (typeDefinition.IsValueType) { @@ -240,11 +352,11 @@ private ITypeInstance CreateTypeFromTypeReference(TypeReference typeRefer } else { - createdTypeInstance = - new TypeInstance(new Class(type, typeDefinition.IsAbstract, typeDefinition.IsSealed)); + createdTypeInstance = new TypeInstance( + new Class(type, typeDefinition.IsAbstract, typeDefinition.IsSealed) + ); } - if (!isStub && !isCompilerGenerated) { if (!typeDefinition.IsInterface) @@ -260,19 +372,27 @@ private ITypeInstance CreateTypeFromTypeReference(TypeReference typeRefer [NotNull] private MethodMemberInstance CreateMethodMemberFromMethodReference( - [NotNull] ITypeInstance typeInstance, [NotNull] MethodReference methodReference) + [NotNull] ITypeInstance typeInstance, + [NotNull] MethodReference methodReference + ) { if (methodReference.IsGenericInstance) { - var elementMethod = - CreateMethodMemberFromMethodReference(typeInstance, methodReference.GetElementMethod()).Member; + var elementMethod = CreateMethodMemberFromMethodReference( + typeInstance, + methodReference.GetElementMethod() + ).Member; var genericInstanceMethod = (GenericInstanceMethod)methodReference; - var genericArguments = genericInstanceMethod.GenericArguments - .Select(CreateGenericArgumentFromTypeReference) + var genericArguments = genericInstanceMethod + .GenericArguments.Select(CreateGenericArgumentFromTypeReference) .Where(argument => !argument.Type.IsCompilerGenerated); - return new MethodMemberInstance(elementMethod, typeInstance.GenericArguments, genericArguments); + return new MethodMemberInstance( + elementMethod, + typeInstance.GenericArguments, + genericArguments + ); } var returnTypeReference = methodReference.ReturnType; @@ -301,7 +421,9 @@ private MethodMemberInstance CreateMethodMemberFromMethodReference( if (methodDefinition == null) { visibility = Public; - methodForm = methodReference.HasConstructorName() ? MethodForm.Constructor : MethodForm.Normal; + methodForm = methodReference.HasConstructorName() + ? MethodForm.Constructor + : MethodForm.Normal; isIterator = null; isStatic = null; isStub = true; @@ -315,8 +437,20 @@ private MethodMemberInstance CreateMethodMemberFromMethodReference( isStub = false; } - var methodMember = new MethodMember(name, fullName, typeInstance.Type, visibility, returnType, - false, methodForm, isGeneric, isStub, isCompilerGenerated, isIterator, isStatic); + var methodMember = new MethodMember( + name, + fullName, + typeInstance.Type, + visibility, + returnType, + false, + methodForm, + isGeneric, + isStub, + isCompilerGenerated, + isIterator, + isStatic + ); var parameters = methodReference.GetParameters(this).ToList(); methodMember.ParameterInstances.AddRange(parameters); @@ -324,18 +458,23 @@ private MethodMemberInstance CreateMethodMemberFromMethodReference( var genericParameters = GetGenericParameters(methodReference); methodMember.GenericParameters.AddRange(genericParameters); - return new MethodMemberInstance(methodMember, typeInstance.GenericArguments, - Enumerable.Empty()); + return new MethodMemberInstance( + methodMember, + typeInstance.GenericArguments, + Enumerable.Empty() + ); } [NotNull] - internal FieldMember CreateStubFieldMemberFromFieldReference([NotNull] IType type, - [NotNull] FieldReference fieldReference) + internal FieldMember CreateStubFieldMemberFromFieldReference( + [NotNull] IType type, + [NotNull] FieldReference fieldReference + ) { var typeReference = fieldReference.FieldType; var fieldType = GetOrCreateStubTypeInstanceFromTypeReference(typeReference); var isCompilerGenerated = fieldReference.IsCompilerGenerated(); - bool? isStatic = null; + bool? isStatic = null; var isReadOnly = false; if (fieldReference is FieldDefinition fieldDefinition) @@ -344,29 +483,53 @@ internal FieldMember CreateStubFieldMemberFromFieldReference([NotNull] IType typ isReadOnly = fieldDefinition.IsInitOnly; } - return new FieldMember(type, fieldReference.Name, fieldReference.FullName, Public, fieldType, - isCompilerGenerated, isStatic, isReadOnly ? Writability.ReadOnly : Writability.Writable); + return new FieldMember( + type, + fieldReference.Name, + fieldReference.FullName, + Public, + fieldType, + isCompilerGenerated, + isStatic, + isReadOnly ? Writability.ReadOnly : Writability.Writable + ); } - public IEnumerable GetGenericParameters(IGenericParameterProvider genericParameterProvider) + public IEnumerable GetGenericParameters( + IGenericParameterProvider genericParameterProvider + ) { return genericParameterProvider == null ? Enumerable.Empty() - : genericParameterProvider.GenericParameters - .Select(param => GetOrCreateStubTypeInstanceFromTypeReference(param).Type).Cast(); + : genericParameterProvider + .GenericParameters.Select(param => + GetOrCreateStubTypeInstanceFromTypeReference(param).Type + ) + .Cast(); } - - private GenericParameter CreateGenericParameter(Mono.Cecil.GenericParameter genericParameter, - [NotNull] string declarerFullName, bool declarerIsMethod) + private GenericParameter CreateGenericParameter( + Mono.Cecil.GenericParameter genericParameter, + [NotNull] string declarerFullName, + bool declarerIsMethod + ) { var isCompilerGenerated = genericParameter.IsCompilerGenerated(); var variance = genericParameter.GetVariance(); var typeConstraints = genericParameter.Constraints.Select(con => - GetOrCreateStubTypeInstanceFromTypeReference(con.ConstraintType)); - return new GenericParameter(declarerFullName, genericParameter.Name, variance, typeConstraints, - genericParameter.HasReferenceTypeConstraint, genericParameter.HasNotNullableValueTypeConstraint, - genericParameter.HasDefaultConstructorConstraint, isCompilerGenerated, declarerIsMethod); + GetOrCreateStubTypeInstanceFromTypeReference(con.ConstraintType) + ); + return new GenericParameter( + declarerFullName, + genericParameter.Name, + variance, + typeConstraints, + genericParameter.HasReferenceTypeConstraint, + genericParameter.HasNotNullableValueTypeConstraint, + genericParameter.HasDefaultConstructorConstraint, + isCompilerGenerated, + declarerIsMethod + ); } internal GenericArgument CreateGenericArgumentFromTypeReference(TypeReference typeReference) @@ -381,8 +544,10 @@ private void LoadBaseTask(IType cls, Type type, TypeDefinition typeDefinition) return; } - _loadTaskRegistry.Add(typeof(AddBaseClassDependency), - new AddBaseClassDependency(cls, type, typeDefinition, this)); + _loadTaskRegistry.Add( + typeof(AddBaseClassDependency), + new AddBaseClassDependency(cls, type, typeDefinition, this) + ); } private void LoadNonBaseTasks(IType createdType, Type type, TypeDefinition typeDefinition) @@ -392,21 +557,38 @@ private void LoadNonBaseTasks(IType createdType, Type type, TypeDefinition typeD return; } - _loadTaskRegistry.Add(typeof(AddMembers), - new AddMembers(createdType, typeDefinition, this, type.Members)); - _loadTaskRegistry.Add(typeof(AddGenericParameterDependencies), - new AddGenericParameterDependencies(type)); - _loadTaskRegistry.Add(typeof(AddAttributesAndAttributeDependencies), - new AddAttributesAndAttributeDependencies(createdType, typeDefinition, this)); - _loadTaskRegistry.Add(typeof(AddFieldAndPropertyDependencies), - new AddFieldAndPropertyDependencies(createdType)); - _loadTaskRegistry.Add(typeof(AddMethodDependencies), - new AddMethodDependencies(createdType, typeDefinition, this)); - _loadTaskRegistry.Add(typeof(AddGenericArgumentDependencies), - new AddGenericArgumentDependencies(type)); - _loadTaskRegistry.Add(typeof(AddClassDependencies), - new AddClassDependencies(createdType, typeDefinition, this, type.Dependencies)); - _loadTaskRegistry.Add(typeof(AddBackwardsDependencies), new AddBackwardsDependencies(createdType)); + _loadTaskRegistry.Add( + typeof(AddMembers), + new AddMembers(createdType, typeDefinition, this, type.Members) + ); + _loadTaskRegistry.Add( + typeof(AddGenericParameterDependencies), + new AddGenericParameterDependencies(type) + ); + _loadTaskRegistry.Add( + typeof(AddAttributesAndAttributeDependencies), + new AddAttributesAndAttributeDependencies(createdType, typeDefinition, this) + ); + _loadTaskRegistry.Add( + typeof(AddFieldAndPropertyDependencies), + new AddFieldAndPropertyDependencies(createdType) + ); + _loadTaskRegistry.Add( + typeof(AddMethodDependencies), + new AddMethodDependencies(createdType, typeDefinition, this) + ); + _loadTaskRegistry.Add( + typeof(AddGenericArgumentDependencies), + new AddGenericArgumentDependencies(type) + ); + _loadTaskRegistry.Add( + typeof(AddClassDependencies), + new AddClassDependencies(createdType, typeDefinition, this, type.Dependencies) + ); + _loadTaskRegistry.Add( + typeof(AddBackwardsDependencies), + new AddBackwardsDependencies(createdType) + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNET/Loader/TypeRegistry.cs b/ArchUnitNET/Loader/TypeRegistry.cs index c5ab2e092..9731a9e08 100644 --- a/ArchUnitNET/Loader/TypeRegistry.cs +++ b/ArchUnitNET/Loader/TypeRegistry.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -18,10 +18,16 @@ internal class TypeRegistry private readonly Dictionary> _allTypes = new Dictionary>(); - public ITypeInstance GetOrCreateTypeFromTypeReference([NotNull] TypeReference typeReference, - [NotNull] Func> createFunc) + public ITypeInstance GetOrCreateTypeFromTypeReference( + [NotNull] TypeReference typeReference, + [NotNull] Func> createFunc + ) { - return RegistryUtils.GetFromDictOrCreateAndAdd(typeReference.BuildFullName(), _allTypes, createFunc); + return RegistryUtils.GetFromDictOrCreateAndAdd( + typeReference.BuildFullName(), + _allTypes, + createFunc + ); } public IEnumerable GetAllTypes() @@ -29,4 +35,4 @@ public IEnumerable GetAllTypes() return _allTypes.Values.Select(instance => instance.Type).Distinct(); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/ArchitectureTests/ArchUnitArchitectureTests.cs b/ArchUnitNETTests/ArchitectureTests/ArchUnitArchitectureTests.cs index a83db06dd..0214565ed 100644 --- a/ArchUnitNETTests/ArchitectureTests/ArchUnitArchitectureTests.cs +++ b/ArchUnitNETTests/ArchitectureTests/ArchUnitArchitectureTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using ArchUnitNET.Domain; using ArchUnitNET.Fluent; @@ -21,39 +21,52 @@ public class ArchUnitArchitectureTests private static readonly string LoaderNamespace = typeof(ArchLoader).Namespace; private static readonly string FluentNamespace = typeof(IArchRule).Namespace; - private readonly Architecture _architecture = - new ArchLoader().LoadAssembly(typeof(Architecture).Assembly).Build(); + private readonly Architecture _architecture = new ArchLoader() + .LoadAssembly(typeof(Architecture).Assembly) + .Build(); [Fact] public void DomainHasNoDependencyOnFluent() { - Types().That().ResideInNamespace(DomainNamespace) - .Should().NotDependOnAny(FluentNamespace) + Types() + .That() + .ResideInNamespace(DomainNamespace) + .Should() + .NotDependOnAny(FluentNamespace) .Check(_architecture); } [Fact] public void DomainHasNoDependencyOnLoader() { - Types().That().ResideInNamespace(DomainNamespace) - .Should().NotDependOnAny(LoaderNamespace) + Types() + .That() + .ResideInNamespace(DomainNamespace) + .Should() + .NotDependOnAny(LoaderNamespace) .Check(_architecture); } [Fact] public void LoaderHasNoDependencyOnFluent() { - Types().That().ResideInNamespace(LoaderNamespace) - .Should().NotDependOnAny(FluentNamespace) + Types() + .That() + .ResideInNamespace(LoaderNamespace) + .Should() + .NotDependOnAny(FluentNamespace) .Check(_architecture); } [Fact] public void FluentHasNoDependencyOnLoader() { - Types().That().ResideInNamespace(FluentNamespace) - .Should().NotDependOnAny(LoaderNamespace) + Types() + .That() + .ResideInNamespace(FluentNamespace) + .Should() + .NotDependOnAny(LoaderNamespace) .Check(_architecture); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Dependencies/AccessFieldDependenciesTests.cs b/ArchUnitNETTests/Dependencies/AccessFieldDependenciesTests.cs index c3cd26eb2..d104f305f 100644 --- a/ArchUnitNETTests/Dependencies/AccessFieldDependenciesTests.cs +++ b/ArchUnitNETTests/Dependencies/AccessFieldDependenciesTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Linq; using ArchUnitNET.Domain; @@ -15,8 +15,9 @@ namespace ArchUnitNETTests.Dependencies { public class AccessFieldDependenciesTests { - private static readonly Architecture Architecture = - new ArchLoader().LoadAssembly(typeof(AccessFieldDependenciesTests).Assembly).Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssembly(typeof(AccessFieldDependenciesTests).Assembly) + .Build(); private readonly Class _accessingClass; @@ -28,19 +29,25 @@ public class AccessFieldDependenciesTests public AccessFieldDependenciesTests() { - _classWithNonStaticFields = Architecture.GetClassOfType(typeof(ClassWithNonStaticFields)); + _classWithNonStaticFields = Architecture.GetClassOfType( + typeof(ClassWithNonStaticFields) + ); _classWithStaticFields = Architecture.GetClassOfType(typeof(ClassWithStaticFields)); _accessingClass = Architecture.GetClassOfType(typeof(ClassAccessingFields)); - - _nonStaticFieldMember = _classWithNonStaticFields.GetFieldMembersWithName("NonStaticField").First(); - _staticFieldMember = _classWithStaticFields.GetFieldMembersWithName("StaticField").First(); + _nonStaticFieldMember = _classWithNonStaticFields + .GetFieldMembersWithName("NonStaticField") + .First(); + _staticFieldMember = _classWithStaticFields + .GetFieldMembersWithName("StaticField") + .First(); } [Fact] public void PropertyAccessToStaticFieldFound() { - var property = _accessingClass.GetPropertyMembers() + var property = _accessingClass + .GetPropertyMembers() .First(member => member.FullNameContains("PropertyAccessingStaticField")); var propertyTypeDependencies = property.GetTypeDependencies().ToList(); var propertyFieldDependencies = property.GetAccessedFieldMembers().ToList(); @@ -52,7 +59,8 @@ public void PropertyAccessToStaticFieldFound() [Fact] public void PropertyAccessToNonStaticFieldFound() { - var property = _accessingClass.GetPropertyMembers() + var property = _accessingClass + .GetPropertyMembers() .First(member => member.FullNameContains("PropertyAccessingNonStaticField")); var propertyTypeDependencies = property.GetTypeDependencies().ToList(); var propertyFieldDependencies = property.GetAccessedFieldMembers().ToList(); @@ -64,7 +72,8 @@ public void PropertyAccessToNonStaticFieldFound() [Fact] public void SettingStaticFieldDependencyFound() { - var method = _accessingClass.GetMethodMembers() + var method = _accessingClass + .GetMethodMembers() .First(member => member.FullNameContains("MethodSettingStaticField")); var methodTypeDependencies = method.GetTypeDependencies().ToList(); var methodFieldDependencies = method.GetAccessedFieldMembers().ToList(); @@ -76,7 +85,8 @@ public void SettingStaticFieldDependencyFound() [Fact] public void GettingStaticFieldDependencyFound() { - var method = _accessingClass.GetMethodMembers() + var method = _accessingClass + .GetMethodMembers() .First(member => member.FullNameContains("MethodGettingStaticField")); var methodTypeDependencies = method.GetTypeDependencies().ToList(); var methodFieldDependencies = method.GetAccessedFieldMembers().ToList(); @@ -88,7 +98,8 @@ public void GettingStaticFieldDependencyFound() [Fact] public void SettingNonStaticFieldDependencyFound() { - var method = _accessingClass.GetMethodMembers() + var method = _accessingClass + .GetMethodMembers() .First(member => member.FullNameContains("MethodSettingNonStaticField")); var methodTypeDependencies = method.GetTypeDependencies().ToList(); var methodFieldDependencies = method.GetAccessedFieldMembers().ToList(); @@ -100,7 +111,8 @@ public void SettingNonStaticFieldDependencyFound() [Fact] public void GettingNonStaticFieldDependencyFound() { - var method = _accessingClass.GetMethodMembers() + var method = _accessingClass + .GetMethodMembers() .First(member => member.FullNameContains("MethodGettingNonStaticField")); var methodTypeDependencies = method.GetTypeDependencies().ToList(); var methodFieldDependencies = method.GetAccessedFieldMembers().ToList(); @@ -122,8 +134,10 @@ internal static class ClassWithStaticFields internal class ClassAccessingFields { - public ClassAccessingFields PropertyAccessingStaticField => ClassWithStaticFields.StaticField; - public ClassAccessingFields PropertyAccessingNonStaticField => new ClassWithNonStaticFields().NonStaticField; + public ClassAccessingFields PropertyAccessingStaticField => + ClassWithStaticFields.StaticField; + public ClassAccessingFields PropertyAccessingNonStaticField => + new ClassWithNonStaticFields().NonStaticField; public void MethodGettingStaticField() { @@ -143,7 +157,7 @@ public void MethodGettingNonStaticField() public void MethodSettingNonStaticField() { - var cls = new ClassWithNonStaticFields {NonStaticField = new ClassAccessingFields()}; + var cls = new ClassWithNonStaticFields { NonStaticField = new ClassAccessingFields() }; } } } diff --git a/ArchUnitNETTests/Dependencies/ArrayTests.cs b/ArchUnitNETTests/Dependencies/ArrayTests.cs index 90d72421c..f13b64f73 100644 --- a/ArchUnitNETTests/Dependencies/ArrayTests.cs +++ b/ArchUnitNETTests/Dependencies/ArrayTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Linq; using ArchUnitNET.Domain; @@ -16,8 +16,9 @@ namespace ArchUnitNETTests.Dependencies { public class ArrayTests { - private static readonly Architecture Architecture = - new ArchLoader().LoadAssembly(typeof(ArrayTests).Assembly).Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssembly(typeof(ArrayTests).Assembly) + .Build(); private readonly IType _bool; @@ -26,30 +27,37 @@ public class ArrayTests private readonly IType _int; - public ArrayTests() { _bool = Architecture.GetITypeOfType(typeof(bool)); _int = Architecture.GetITypeOfType(typeof(int)); - _classWithBoolArrayFields = Architecture.GetClassOfType(typeof(ClassWithBoolArrayFields)); + _classWithBoolArrayFields = Architecture.GetClassOfType( + typeof(ClassWithBoolArrayFields) + ); _classWithArrayMethod = Architecture.GetClassOfType(typeof(ClassWithArrayMethod)); } [Fact] public void FindDependenciesInArrayFields() { - var fieldTypeDependencies = _classWithBoolArrayFields.Dependencies.OfType(); + var fieldTypeDependencies = + _classWithBoolArrayFields.Dependencies.OfType(); var fieldMembers = _classWithBoolArrayFields.GetFieldMembers(); Assert.DoesNotContain(fieldMembers, member => !Equals(member.Type, _bool)); - Assert.DoesNotContain(fieldTypeDependencies, dependency => !dependency.Target.Equals(_bool)); + Assert.DoesNotContain( + fieldTypeDependencies, + dependency => !dependency.Target.Equals(_bool) + ); } [Fact] public void FindDependenciesInArrayMethods() { var typeDependencies = _classWithArrayMethod.GetTypeDependencies().ToList(); - var method = _classWithArrayMethod.GetMethodMembers().First(member => member.NameContains("ArrayMethod")); + var method = _classWithArrayMethod + .GetMethodMembers() + .First(member => member.NameContains("ArrayMethod")); Assert.Contains(_bool, typeDependencies); Assert.Contains(_int, typeDependencies); @@ -63,11 +71,21 @@ public void FindDependenciesInArrayMethods() [Fact] public void FindArrayDimensions() { - var bool1Array = _classWithBoolArrayFields.GetFieldMembersWithName("_bool1Array").First(); - var bool11Array = _classWithBoolArrayFields.GetFieldMembersWithName("_bool11Array").First(); - var bool2Array = _classWithBoolArrayFields.GetFieldMembersWithName("_bool2Array").First(); - var bool21Array = _classWithBoolArrayFields.GetFieldMembersWithName("_bool21Array").First(); - var bool412Array = _classWithBoolArrayFields.GetFieldMembersWithName("_bool412Array").First(); + var bool1Array = _classWithBoolArrayFields + .GetFieldMembersWithName("_bool1Array") + .First(); + var bool11Array = _classWithBoolArrayFields + .GetFieldMembersWithName("_bool11Array") + .First(); + var bool2Array = _classWithBoolArrayFields + .GetFieldMembersWithName("_bool2Array") + .First(); + var bool21Array = _classWithBoolArrayFields + .GetFieldMembersWithName("_bool21Array") + .First(); + var bool412Array = _classWithBoolArrayFields + .GetFieldMembersWithName("_bool412Array") + .First(); Assert.True(bool1Array.IsArray); Assert.True(bool11Array.IsArray); @@ -75,11 +93,11 @@ public void FindArrayDimensions() Assert.True(bool21Array.IsArray); Assert.True(bool412Array.IsArray); - Assert.Equal(new[] {1}, bool1Array.ArrayDimensions); - Assert.Equal(new[] {1, 1}, bool11Array.ArrayDimensions); - Assert.Equal(new[] {2}, bool2Array.ArrayDimensions); - Assert.Equal(new[] {2, 1}, bool21Array.ArrayDimensions); - Assert.Equal(new[] {4, 1, 2}, bool412Array.ArrayDimensions); + Assert.Equal(new[] { 1 }, bool1Array.ArrayDimensions); + Assert.Equal(new[] { 1, 1 }, bool11Array.ArrayDimensions); + Assert.Equal(new[] { 2 }, bool2Array.ArrayDimensions); + Assert.Equal(new[] { 2, 1 }, bool21Array.ArrayDimensions); + Assert.Equal(new[] { 4, 1, 2 }, bool412Array.ArrayDimensions); } } diff --git a/ArchUnitNETTests/Dependencies/CastDependenciesTest.cs b/ArchUnitNETTests/Dependencies/CastDependenciesTest.cs index 9c7bc347c..f7a263fec 100644 --- a/ArchUnitNETTests/Dependencies/CastDependenciesTest.cs +++ b/ArchUnitNETTests/Dependencies/CastDependenciesTest.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Linq; using ArchUnitNET.Domain; @@ -15,8 +15,9 @@ namespace ArchUnitNETTests.Dependencies { public class CastDependenciesTest { - private static readonly Architecture Architecture = - new ArchLoader().LoadAssembly(typeof(ClassWithCastDependency).Assembly).Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssembly(typeof(ClassWithCastDependency).Assembly) + .Build(); private readonly Class _castClassA; private readonly Class _castClassB; @@ -30,14 +31,21 @@ public CastDependenciesTest() _castClassB = Architecture.GetClassOfType(typeof(CastClassB)); _castInterfaceA = Architecture.GetInterfaceOfType(typeof(ICastInterfaceA)); _classWithCastDependency = Architecture.GetClassOfType(typeof(ClassWithCastDependency)); - _methodWithCastDependency = (MethodMember) _classWithCastDependency.Members - .WhereNameIs("MethodWithCastDependencies(ArchUnitNETTests.Dependencies.CastClassA)").ToList().First(); + _methodWithCastDependency = (MethodMember) + _classWithCastDependency + .Members.WhereNameIs( + "MethodWithCastDependencies(ArchUnitNETTests.Dependencies.CastClassA)" + ) + .ToList() + .First(); } [SkipInReleaseBuild] public void CastTest() { - var typeDependencies = _classWithCastDependency.GetTypeDependencies(Architecture).ToList(); + var typeDependencies = _classWithCastDependency + .GetTypeDependencies(Architecture) + .ToList(); Assert.Contains(_castClassA, typeDependencies); Assert.Contains(_castClassB, typeDependencies); @@ -47,7 +55,9 @@ public void CastTest() [Fact] public void MethodCastTest() { - var typeDependencies = _methodWithCastDependency.GetTypeDependencies(Architecture).ToList(); + var typeDependencies = _methodWithCastDependency + .GetTypeDependencies(Architecture) + .ToList(); Assert.Contains(_castClassB, typeDependencies); } } @@ -58,25 +68,19 @@ internal class ClassWithCastDependency public ClassWithCastDependency() { - var type = (CastClassA) new CastClassB(); - var type2 = (ICastInterfaceA) new CastClassB(); + var type = (CastClassA)new CastClassB(); + var type2 = (ICastInterfaceA)new CastClassB(); } public void MethodWithCastDependencies(CastClassA value) { - target = (CastClassB) value; + target = (CastClassB)value; } } - internal class CastClassA - { - } + internal class CastClassA { } - internal interface ICastInterfaceA - { - } + internal interface ICastInterfaceA { } - internal class CastClassB : CastClassA, ICastInterfaceA - { - } -} \ No newline at end of file + internal class CastClassB : CastClassA, ICastInterfaceA { } +} diff --git a/ArchUnitNETTests/Dependencies/CppDependenciesTests.cs b/ArchUnitNETTests/Dependencies/CppDependenciesTests.cs index 50bafc842..a9ab521f9 100644 --- a/ArchUnitNETTests/Dependencies/CppDependenciesTests.cs +++ b/ArchUnitNETTests/Dependencies/CppDependenciesTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using ArchUnitNET.Domain; using ArchUnitNET.Domain.Extensions; @@ -15,8 +15,10 @@ namespace ArchUnitNETTests.Dependencies public class CppDependenciesTests { private static readonly Architecture Architecture = new ArchLoader() - .LoadAssembliesRecursively(new[] { typeof(CppExampleClassUser).Assembly }, - filterFunc => FilterResult.LoadAndContinue) + .LoadAssembliesRecursively( + new[] { typeof(CppExampleClassUser).Assembly }, + filterFunc => FilterResult.LoadAndContinue + ) .Build(); [Fact] @@ -38,8 +40,8 @@ internal class CppExampleClassUser #pragma once public ref class CppExampleClass { - public: - void DoCall(); + public: + void DoCall(); }; CppExampleClass.cpp @@ -50,4 +52,4 @@ public ref class CppExampleClass { } */ -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Dependencies/DependenciesToStaticMethodsTests.cs b/ArchUnitNETTests/Dependencies/DependenciesToStaticMethodsTests.cs index a7a072ca1..5a091d465 100644 --- a/ArchUnitNETTests/Dependencies/DependenciesToStaticMethodsTests.cs +++ b/ArchUnitNETTests/Dependencies/DependenciesToStaticMethodsTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System; using System.Collections.Generic; @@ -17,8 +17,9 @@ namespace ArchUnitNETTests.Dependencies { public class DependenciesToStaticMethodsTests { - private static readonly Architecture Architecture = - new ArchLoader().LoadAssembly(typeof(DependenciesToStaticMethodsTests).Assembly).Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssembly(typeof(DependenciesToStaticMethodsTests).Assembly) + .Build(); private readonly Class _accessingClass; private readonly Class _classAccessingStaticMethodInGenerator; @@ -27,19 +28,24 @@ public class DependenciesToStaticMethodsTests private readonly MethodMember _staticMethodMemberWithBody; private readonly FieldMember _staticMethodMemberAsField; - public DependenciesToStaticMethodsTests() { _accessingClass = Architecture.GetClassOfType(typeof(ClassAccessingStaticMethod)); - _classAccessingStaticMethodInGenerator = - Architecture.GetClassOfType(typeof(ClassAccessingStaticMethodInGenerator)); - _classAccessingStaticMethodWithoutGenerator = - Architecture.GetClassOfType(typeof(ClassAccessingStaticMethodWithoutGenerator)); + _classAccessingStaticMethodInGenerator = Architecture.GetClassOfType( + typeof(ClassAccessingStaticMethodInGenerator) + ); + _classAccessingStaticMethodWithoutGenerator = Architecture.GetClassOfType( + typeof(ClassAccessingStaticMethodWithoutGenerator) + ); _classWithStaticMethod = Architecture.GetClassOfType(typeof(ClassWithStaticMethods)); _staticMethodMemberWithBody = _classWithStaticMethod - .GetMethodMembersWithName(nameof(ClassWithStaticMethods.StaticMethodWithBody) + "(System.Int32)").First(); + .GetMethodMembersWithName( + nameof(ClassWithStaticMethods.StaticMethodWithBody) + "(System.Int32)" + ) + .First(); _staticMethodMemberAsField = _classWithStaticMethod - .GetFieldMembersWithName(nameof(ClassWithStaticMethods.StaticMethodAsField)).First(); + .GetFieldMembersWithName(nameof(ClassWithStaticMethods.StaticMethodAsField)) + .First(); } [Fact] @@ -65,21 +71,33 @@ public void StaticMethodCallToFieldFound() [Fact] public void StaticReferencesInGeneratorFound() { - var typeDependencies = _classAccessingStaticMethodInGenerator.GetTypeDependencies().ToList(); - var methodDependencies = _classAccessingStaticMethodInGenerator.GetCalledMethods().ToList(); - var fieldDependencies = _classAccessingStaticMethodInGenerator.GetAccessedFieldMembers().ToList(); + var typeDependencies = _classAccessingStaticMethodInGenerator + .GetTypeDependencies() + .ToList(); + var methodDependencies = _classAccessingStaticMethodInGenerator + .GetCalledMethods() + .ToList(); + var fieldDependencies = _classAccessingStaticMethodInGenerator + .GetAccessedFieldMembers() + .ToList(); Assert.Contains(_classWithStaticMethod, typeDependencies); Assert.Contains(_staticMethodMemberWithBody, methodDependencies); Assert.Contains(_staticMethodMemberAsField, fieldDependencies); } - + [Fact] public void StaticReferencesWithoutGeneratorFound() { - var typeDependencies = _classAccessingStaticMethodWithoutGenerator.GetTypeDependencies().ToList(); - var methodDependencies = _classAccessingStaticMethodWithoutGenerator.GetCalledMethods().ToList(); - var fieldDependencies = _classAccessingStaticMethodWithoutGenerator.GetAccessedFieldMembers().ToList(); + var typeDependencies = _classAccessingStaticMethodWithoutGenerator + .GetTypeDependencies() + .ToList(); + var methodDependencies = _classAccessingStaticMethodWithoutGenerator + .GetCalledMethods() + .ToList(); + var fieldDependencies = _classAccessingStaticMethodWithoutGenerator + .GetAccessedFieldMembers() + .ToList(); Assert.Contains(_classWithStaticMethod, typeDependencies); Assert.Contains(_staticMethodMemberWithBody, methodDependencies); @@ -97,7 +115,6 @@ public static int StaticMethodWithBody(int a) public static Func StaticMethodAsField = i => i + 2; } - internal class ClassAccessingStaticMethod { private int _a; @@ -148,4 +165,4 @@ public IEnumerable WithoutGenerator(bool useField) return results; } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Dependencies/ExceptionDependenciesTests.cs b/ArchUnitNETTests/Dependencies/ExceptionDependenciesTests.cs index 221d47a3b..c158c2710 100644 --- a/ArchUnitNETTests/Dependencies/ExceptionDependenciesTests.cs +++ b/ArchUnitNETTests/Dependencies/ExceptionDependenciesTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System; using System.Linq; @@ -16,8 +16,9 @@ namespace ArchUnitNETTests.Dependencies { public class ExceptionDependenciesTests { - private static readonly Architecture Architecture = - new ArchLoader().LoadAssembly(typeof(ExceptionDependenciesTests).Assembly).Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssembly(typeof(ExceptionDependenciesTests).Assembly) + .Build(); private readonly Class _classWithException; private readonly Class _throwingClass; @@ -32,7 +33,9 @@ public ExceptionDependenciesTests() public void ThrowDependencyFound() { var typeDependencies = _throwingClass.GetTypeDependencies().ToList(); - var method = _throwingClass.GetMethodMembers().First(member => member.FullNameContains("ThrowingMethod")); + var method = _throwingClass + .GetMethodMembers() + .First(member => member.FullNameContains("ThrowingMethod")); var methodTypeDependencies = method.GetTypeDependencies().ToList(); Assert.Contains(_classWithException, typeDependencies); @@ -52,4 +55,4 @@ public void ThrowingMethod() throw ClassWithException.Exception; } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Dependencies/ExternalDependenciesTests.cs b/ArchUnitNETTests/Dependencies/ExternalDependenciesTests.cs index 8fc8f73d5..f58882536 100644 --- a/ArchUnitNETTests/Dependencies/ExternalDependenciesTests.cs +++ b/ArchUnitNETTests/Dependencies/ExternalDependenciesTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using ArchUnitNET.Domain; using ArchUnitNET.Loader; @@ -15,26 +15,33 @@ namespace ArchUnitNETTests.Dependencies { public class ExternalDependenciesTests { - private static readonly Architecture Architecture = - new ArchLoader().LoadAssembly(typeof(ExternalDependenciesTests).Assembly).Build(); - - private static readonly Architecture ArchitectureBothAssemblies = new ArchLoader().LoadAssemblies( - System.Reflection.Assembly.Load("ArchUnitNETTests"), - System.Reflection.Assembly.Load("TestAssembly")) + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssembly(typeof(ExternalDependenciesTests).Assembly) .Build(); - private static readonly Architecture ArchitectureExternalDependency = - new ArchLoader().LoadAssemblyIncludingDependencies(typeof(ExternalDependenciesTests).Assembly).Build(); + private static readonly Architecture ArchitectureBothAssemblies = new ArchLoader() + .LoadAssemblies( + System.Reflection.Assembly.Load("ArchUnitNETTests"), + System.Reflection.Assembly.Load("TestAssembly") + ) + .Build(); + private static readonly Architecture ArchitectureExternalDependency = new ArchLoader() + .LoadAssemblyIncludingDependencies(typeof(ExternalDependenciesTests).Assembly) + .Build(); [Fact] public void PropertyDependencyTest() { - var notDependOnAnyRuleClass = Classes().That() - .HaveFullName(typeof(PropertyDependency).FullName).Should() + var notDependOnAnyRuleClass = Classes() + .That() + .HaveFullName(typeof(PropertyDependency).FullName) + .Should() .NotDependOnAny(typeof(Class2)); - var notDependOnAnyRuleString = Classes().That() - .HaveFullName(typeof(PropertyDependency).FullName).Should() + var notDependOnAnyRuleString = Classes() + .That() + .HaveFullName(typeof(PropertyDependency).FullName) + .Should() .NotDependOnAny(typeof(Class2).FullName); Assert.False(notDependOnAnyRuleClass.HasNoViolations(Architecture)); //Class2 does not exist in Architecture Assert.False(notDependOnAnyRuleString.HasNoViolations(Architecture)); @@ -44,11 +51,15 @@ public void PropertyDependencyTest() [Fact] public void MethodBodyDependencyTest() { - var notDependOnAnyRuleClass = Classes().That() - .HaveFullName(typeof(MethodBodyDependency).FullName).Should() + var notDependOnAnyRuleClass = Classes() + .That() + .HaveFullName(typeof(MethodBodyDependency).FullName) + .Should() .NotDependOnAny(typeof(Class3)); - var notDependOnAnyRuleString = Classes().That() - .HaveFullName(typeof(MethodBodyDependency).FullName).Should() + var notDependOnAnyRuleString = Classes() + .That() + .HaveFullName(typeof(MethodBodyDependency).FullName) + .Should() .NotDependOnAny(typeof(Class3).FullName); Assert.False(notDependOnAnyRuleClass.HasNoViolations(Architecture)); //Class3 does not exist in Architecture Assert.False(notDependOnAnyRuleString.HasNoViolations(Architecture)); @@ -58,11 +69,15 @@ public void MethodBodyDependencyTest() [Fact] public void MethodArgumentDependencyTest() { - var notDependOnAnyRuleClass = Classes().That() - .HaveFullName(typeof(MethodArgumentDependency).FullName).Should() + var notDependOnAnyRuleClass = Classes() + .That() + .HaveFullName(typeof(MethodArgumentDependency).FullName) + .Should() .NotDependOnAny(typeof(Class2)); - var notDependOnAnyRuleString = Classes().That() - .HaveFullName(typeof(MethodArgumentDependency).FullName).Should() + var notDependOnAnyRuleString = Classes() + .That() + .HaveFullName(typeof(MethodArgumentDependency).FullName) + .Should() .NotDependOnAny(typeof(Class2).FullName); Assert.False(notDependOnAnyRuleClass.HasNoViolations(Architecture)); //Class3 does not exist in Architecture Assert.False(notDependOnAnyRuleString.HasNoViolations(Architecture)); @@ -71,11 +86,15 @@ public void MethodArgumentDependencyTest() [Fact] public void FieldDependencyTest() { - var notDependOnAnyRuleClass = Classes().That() - .HaveFullName(typeof(FieldDependency).FullName).Should() + var notDependOnAnyRuleClass = Classes() + .That() + .HaveFullName(typeof(FieldDependency).FullName) + .Should() .NotDependOnAny(typeof(Class2)); - var notDependOnAnyRuleString = Classes().That() - .HaveFullName(typeof(FieldDependency).FullName).Should() + var notDependOnAnyRuleString = Classes() + .That() + .HaveFullName(typeof(FieldDependency).FullName) + .Should() .NotDependOnAny(typeof(Class2).FullName); Assert.False(notDependOnAnyRuleClass.HasNoViolations(Architecture)); //Class3 does not exist in Architecture Assert.False(notDependOnAnyRuleString.HasNoViolations(Architecture)); @@ -106,9 +125,7 @@ public void Method() public class MethodArgumentDependency { - public void Method(Class2 class2) - { - } + public void Method(Class2 class2) { } } public class FieldDependency diff --git a/ArchUnitNETTests/Dependencies/GeneratorDependenciesTests.cs b/ArchUnitNETTests/Dependencies/GeneratorDependenciesTests.cs index d042e4ab2..3f1fbc1f5 100644 --- a/ArchUnitNETTests/Dependencies/GeneratorDependenciesTests.cs +++ b/ArchUnitNETTests/Dependencies/GeneratorDependenciesTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System; using System.Collections.Generic; @@ -17,8 +17,9 @@ namespace ArchUnitNETTests.Dependencies { public class GeneratorDependenciesTests { - private static readonly Architecture Architecture = - new ArchLoader().LoadAssembly(typeof(GeneratorDependenciesTests).Assembly).Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssembly(typeof(GeneratorDependenciesTests).Assembly) + .Build(); private readonly Class _accessedClass; private readonly FieldMember _accessedStaticField; @@ -30,28 +31,39 @@ public class GeneratorDependenciesTests public GeneratorDependenciesTests() { _accessedClass = Architecture.GetClassOfType(typeof(AccessedClass)); - _accessedStaticField = _accessedClass.GetFieldMembersWithName(nameof(AccessedClass.StringField)).First(); - _accessedBoolField = _accessedClass.GetFieldMembersWithName(nameof(AccessedClass.BoolField)).First(); - _accessedStaticMethodAsField = - _accessedClass.GetFieldMembersWithName(nameof(AccessedClass.StaticMethodAsField)).First(); + _accessedStaticField = _accessedClass + .GetFieldMembersWithName(nameof(AccessedClass.StringField)) + .First(); + _accessedBoolField = _accessedClass + .GetFieldMembersWithName(nameof(AccessedClass.BoolField)) + .First(); + _accessedStaticMethodAsField = _accessedClass + .GetFieldMembersWithName(nameof(AccessedClass.StaticMethodAsField)) + .First(); _accessedConstructor = _accessedClass.Constructors.First(); _accessedStaticMethodWithBody = _accessedClass - .GetMethodMembersWithName(nameof(AccessedClass.StaticMethodWithBody) + "(System.Int32)").First(); + .GetMethodMembersWithName( + nameof(AccessedClass.StaticMethodWithBody) + "(System.Int32)" + ) + .First(); } public static IEnumerable GetGenerators() { var classWithGenerators = Architecture.GetClassOfType(typeof(ClassWithGenerators)); var simpleGenerator = classWithGenerators - .GetMethodMembersWithName(nameof(ClassWithGenerators.SimpleGenerator) + "()").First(); + .GetMethodMembersWithName(nameof(ClassWithGenerators.SimpleGenerator) + "()") + .First(); var complexGenerator = classWithGenerators - .GetMethodMembersWithName(nameof(ClassWithGenerators.ComplexGenerator) + "()").First(); + .GetMethodMembersWithName(nameof(ClassWithGenerators.ComplexGenerator) + "()") + .First(); var nestedGenerator = classWithGenerators - .GetMethodMembersWithName(nameof(ClassWithGenerators.ContainingGenerator) + "()").First(); + .GetMethodMembersWithName(nameof(ClassWithGenerators.ContainingGenerator) + "()") + .First(); - yield return new object[] {simpleGenerator}; - yield return new object[] {complexGenerator}; - yield return new object[] {nestedGenerator}; + yield return new object[] { simpleGenerator }; + yield return new object[] { complexGenerator }; + yield return new object[] { nestedGenerator }; } [Theory] @@ -60,7 +72,10 @@ public void AssignDependenciesInGeneratorMethodBody(MethodMember generator) { var accessedFieldMembers = generator.GetAccessedFieldMembers().ToList(); var calledMethods = generator.GetCalledMethods().ToList(); - var bodyTypes = generator.GetBodyTypeMemberDependencies().Select(dep => dep.Target).ToList(); + var bodyTypes = generator + .GetBodyTypeMemberDependencies() + .Select(dep => dep.Target) + .ToList(); Assert.Contains(_accessedBoolField, accessedFieldMembers); Assert.Contains(_accessedStaticField, accessedFieldMembers); @@ -134,4 +149,4 @@ public static int StaticMethodWithBody(int a) public static Func StaticMethodAsField = i => i + 2; } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Dependencies/GenericMemberDependenciesTests.cs b/ArchUnitNETTests/Dependencies/GenericMemberDependenciesTests.cs index ead8942e0..04fcf4490 100644 --- a/ArchUnitNETTests/Dependencies/GenericMemberDependenciesTests.cs +++ b/ArchUnitNETTests/Dependencies/GenericMemberDependenciesTests.cs @@ -1,21 +1,20 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// namespace ArchUnitNETTests.Dependencies { - public class GenericMemberDependenciesTests - { - } + public class GenericMemberDependenciesTests { } internal class GenericClass { - public M GenericMethod(T t) where M : new() + public M GenericMethod(T t) + where M : new() { return new M(); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Dependencies/KeepDependenciesInCompilerGeneratedTypesTests.cs b/ArchUnitNETTests/Dependencies/KeepDependenciesInCompilerGeneratedTypesTests.cs index 34aeba7cd..aedc7bc0d 100644 --- a/ArchUnitNETTests/Dependencies/KeepDependenciesInCompilerGeneratedTypesTests.cs +++ b/ArchUnitNETTests/Dependencies/KeepDependenciesInCompilerGeneratedTypesTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System; using System.Linq; @@ -16,8 +16,9 @@ namespace ArchUnitNETTests.Dependencies { public class KeepDependenciesInCompilerGeneratedTypesTests { - private static readonly Architecture Architecture = - new ArchLoader().LoadAssembly(typeof(KeepDependenciesInCompilerGeneratedTypesTests).Assembly).Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssembly(typeof(KeepDependenciesInCompilerGeneratedTypesTests).Assembly) + .Build(); private readonly Class _argumentClass; private readonly Class _classWithIndexing; @@ -43,7 +44,6 @@ public void PropertyDependenciesNotLost() var property = _classWithProperty.GetPropertyMembers().First(); var propertyTypeDependencies = property.GetTypeDependencies().ToList(); - Assert.Contains(_returnedClass, typeDependencies); Assert.Contains(_argumentClass, typeDependencies); Assert.Single(_classWithProperty.GetPropertyMembers()); @@ -89,7 +89,9 @@ public void LambdaGenericArgumentDependenciesNotLost() Assert.Contains(_genericArgumentClass, methodTypeDependencies); } - [Fact(Skip = "Fails because the string is created with OpCode Ldstr which has no TypeReference as Operand")] + [Fact( + Skip = "Fails because the string is created with OpCode Ldstr which has no TypeReference as Operand" + )] public void LambdaPrimitiveDependenciesNotLost() { var typeDependencies = _classWithLambda.GetTypeDependencies().ToList(); @@ -112,10 +114,12 @@ public void IndexingDependenciesNotLost() [Fact] public void BackwardDependenciesAssignedCorrectly() { - var argumentTypeBackwardDependencies = - _argumentClass.BackwardsDependencies.Select(dep => dep.Origin).ToList(); - var returnedTypeBackwardDependencies = - _returnedClass.BackwardsDependencies.Select(dep => dep.Origin).ToList(); + var argumentTypeBackwardDependencies = _argumentClass + .BackwardsDependencies.Select(dep => dep.Origin) + .ToList(); + var returnedTypeBackwardDependencies = _returnedClass + .BackwardsDependencies.Select(dep => dep.Origin) + .ToList(); Assert.Contains(_classWithProperty, argumentTypeBackwardDependencies); Assert.Contains(_classWithLambda, argumentTypeBackwardDependencies); @@ -150,9 +154,7 @@ public ClassWithLambdaDependency() } } - internal class GenericArgumentClass - { - } + internal class GenericArgumentClass { } internal class ClassWithIndexingDependency { @@ -161,13 +163,9 @@ internal class ClassWithIndexingDependency internal class ReturnedClass { - public ReturnedClass(object argument) - { - } + public ReturnedClass(object argument) { } } - internal class ArgumentClass - { - } + internal class ArgumentClass { } } #pragma warning restore 219 diff --git a/ArchUnitNETTests/Dependencies/PlantUmlDependenciesTest.cs b/ArchUnitNETTests/Dependencies/PlantUmlDependenciesTest.cs index b6a799f5f..1ae156a52 100644 --- a/ArchUnitNETTests/Dependencies/PlantUmlDependenciesTest.cs +++ b/ArchUnitNETTests/Dependencies/PlantUmlDependenciesTest.cs @@ -1,12 +1,12 @@ -using ArchUnitNET.Domain; -using ArchUnitNET.Fluent.Conditions; -using ArchUnitNET.Loader; -using ArchUnitNETTests.Domain.PlantUml; -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; +using ArchUnitNET.Domain; +using ArchUnitNET.Fluent.Conditions; +using ArchUnitNET.Loader; +using ArchUnitNETTests.Domain.PlantUml; using TestAssembly.Diagram.NoDependencies.Independent; using Xunit; using static ArchUnitNET.Fluent.ArchRuleDefinition; @@ -18,12 +18,18 @@ public class PlantUmlDependenciesTest [Fact] public void DiagramWithNoDependenciesFileBased() { - string path = Path.Combine(Path.GetTempPath(), "plantuml_diagram_" + Guid.NewGuid() + ".puml"); + string path = Path.Combine( + Path.GetTempPath(), + "plantuml_diagram_" + Guid.NewGuid() + ".puml" + ); using (FileStream fileStream = File.Create(path)) { - TestDiagram.From(fileStream) - .Component("A").WithStereoTypes("TestAssembly.Diagram.NoDependencies.Independent.*") - .Component("B").WithStereoTypes("TestAssembly.Diagram.NoDependencies.SomeNamespace.*") + TestDiagram + .From(fileStream) + .Component("A") + .WithStereoTypes("TestAssembly.Diagram.NoDependencies.Independent.*") + .Component("B") + .WithStereoTypes("TestAssembly.Diagram.NoDependencies.SomeNamespace.*") .Write(); } AssertNoViolation(path, "NoDependencies"); @@ -34,9 +40,12 @@ public void DiagramWithNoDependencies() { using (MemoryStream memoryStream = new MemoryStream()) { - TestDiagram.From(memoryStream) - .Component("A").WithStereoTypes("TestAssembly.Diagram.NoDependencies.Independent.*") - .Component("B").WithStereoTypes("TestAssembly.Diagram.NoDependencies.SomeNamespace.*") + TestDiagram + .From(memoryStream) + .Component("A") + .WithStereoTypes("TestAssembly.Diagram.NoDependencies.Independent.*") + .Component("B") + .WithStereoTypes("TestAssembly.Diagram.NoDependencies.SomeNamespace.*") .Write(); AssertNoViolation(memoryStream, "NoDependencies"); @@ -48,10 +57,14 @@ public void DefinedButUnusedDependencyIsAllowed() { using (MemoryStream memoryStream = new MemoryStream()) { - TestDiagram.From(memoryStream) - .Component("SomeOrigin").WithStereoTypes("TestAssembly.Diagram.NoDependencies.Independent.*") - .Component("SomeTarget").WithStereoTypes("TestAssembly.Diagram.NoDependencies.SomeNamespace.*") - .DependencyFrom("SomeOrigin").To("SomeTarget") + TestDiagram + .From(memoryStream) + .Component("SomeOrigin") + .WithStereoTypes("TestAssembly.Diagram.NoDependencies.Independent.*") + .Component("SomeTarget") + .WithStereoTypes("TestAssembly.Diagram.NoDependencies.SomeNamespace.*") + .DependencyFrom("SomeOrigin") + .To("SomeTarget") .Write(); AssertNoViolation(memoryStream, "NoDependencies"); @@ -74,15 +87,19 @@ private void AssertNoViolation(string file, string namespc) private static Architecture GetArchitectureFrom(string namespc) { - Architecture architecture = new ArchLoader().LoadNamespacesWithinAssembly(typeof(IndependentClass).Assembly, "TestAssembly.Diagram." + namespc).Build(); + Architecture architecture = new ArchLoader() + .LoadNamespacesWithinAssembly( + typeof(IndependentClass).Assembly, + "TestAssembly.Diagram." + namespc + ) + .Build(); if (architecture.Classes.Count() == 0) { throw new InvalidOperationException( - string.Format("No classes were imported from '{0}'", namespc)); + string.Format("No classes were imported from '{0}'", namespc) + ); } return architecture; } } - - } diff --git a/ArchUnitNETTests/Dependencies/PropertyDependencyTests.cs b/ArchUnitNETTests/Dependencies/PropertyDependencyTests.cs index 0f5fd0559..1158d7151 100644 --- a/ArchUnitNETTests/Dependencies/PropertyDependencyTests.cs +++ b/ArchUnitNETTests/Dependencies/PropertyDependencyTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Linq; using ArchUnitNET.Domain; @@ -15,7 +15,8 @@ namespace ArchUnitNETTests.Dependencies { public class PropertyDependencyTests { - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; private readonly Class _dependOnClass; private readonly Class _propertyTestDataClass; @@ -26,9 +27,13 @@ public PropertyDependencyTests() { _dependOnClass = Architecture.GetClassOfType(typeof(PropertyDependOnClass)); _propertyTestDataClass = Architecture.GetClassOfType(typeof(PropertyTestDataClass)); - _testStringProperty = _propertyTestDataClass.GetPropertyMembersWithName("TestStringProperty").ToList().First(); - _testStringPropertyGetter = - _propertyTestDataClass.GetMethodMembersWithName("get_TestStringProperty()").First(); + _testStringProperty = _propertyTestDataClass + .GetPropertyMembersWithName("TestStringProperty") + .ToList() + .First(); + _testStringPropertyGetter = _propertyTestDataClass + .GetMethodMembersWithName("get_TestStringProperty()") + .First(); } [Fact] @@ -49,8 +54,10 @@ public void PropertyGetterClassGetterSameDependencies() { if (_testStringProperty.Getter != null) { - Assert.Equal(_testStringPropertyGetter.MemberDependencies, - _testStringProperty.Getter.MemberDependencies); + Assert.Equal( + _testStringPropertyGetter.MemberDependencies, + _testStringProperty.Getter.MemberDependencies + ); } else { @@ -61,47 +68,62 @@ public void PropertyGetterClassGetterSameDependencies() [Fact] public void ClassHasDependencyFromProperty() { - Assert.Contains(_dependOnClass, _propertyTestDataClass.Dependencies.Select(d => d.Target)); + Assert.Contains( + _dependOnClass, + _propertyTestDataClass.Dependencies.Select(d => d.Target) + ); } - + [Fact] public void PropertyHasDependencyFromProperty() { - Assert.Contains(_dependOnClass, _testStringProperty.MemberDependencies.Select(d => d.Target)); + Assert.Contains( + _dependOnClass, + _testStringProperty.MemberDependencies.Select(d => d.Target) + ); } - + [Fact] public void GetterHasDependencyFromProperty() { - Assert.Contains(_dependOnClass, _testStringPropertyGetter.MemberDependencies.Select(d => d.Target)); + Assert.Contains( + _dependOnClass, + _testStringPropertyGetter.MemberDependencies.Select(d => d.Target) + ); } [Fact] public void ClassHasMethodCallDependencyFromProperty() { - var methodCalls = _propertyTestDataClass.Dependencies.Where(d => d is MethodCallDependency).ToList(); + var methodCalls = _propertyTestDataClass + .Dependencies.Where(d => d is MethodCallDependency) + .ToList(); if (methodCalls.IsNullOrEmpty()) { Assert.True(false, "Class must have Method Call Dependency"); } Assert.Contains(_dependOnClass, methodCalls.Select(d => d.Target)); } - + [Fact] public void PropertyHasMethodCallDependencyFromProperty() { - var methodCalls = _testStringProperty.MemberDependencies.Where(d => d is MethodCallDependency).ToList(); + var methodCalls = _testStringProperty + .MemberDependencies.Where(d => d is MethodCallDependency) + .ToList(); if (methodCalls.IsNullOrEmpty()) { Assert.True(false, "Property must have Method Call Dependency"); } Assert.Contains(_dependOnClass, methodCalls.Select(d => d.Target)); } - + [Fact] public void GetterHasMethodCallDependencyFromProperty() { - var methodCalls = _testStringPropertyGetter.MemberDependencies.Where(d => d is MethodCallDependency).ToList(); + var methodCalls = _testStringPropertyGetter + .MemberDependencies.Where(d => d is MethodCallDependency) + .ToList(); if (methodCalls.IsNullOrEmpty()) { Assert.True(false, "Getter must have Method Call Dependency"); @@ -112,10 +134,18 @@ public void GetterHasMethodCallDependencyFromProperty() [Fact] public void PropertyDependencyPassedOn() { - Assert.Equal(_testStringPropertyGetter.MemberDependencies, - _testStringPropertyGetter.MemberDependencies.Intersect(_testStringProperty.MemberDependencies)); - Assert.Equal(_testStringProperty.MemberDependencies, - _testStringProperty.MemberDependencies.Intersect(_propertyTestDataClass.Dependencies)); + Assert.Equal( + _testStringPropertyGetter.MemberDependencies, + _testStringPropertyGetter.MemberDependencies.Intersect( + _testStringProperty.MemberDependencies + ) + ); + Assert.Equal( + _testStringProperty.MemberDependencies, + _testStringProperty.MemberDependencies.Intersect( + _propertyTestDataClass.Dependencies + ) + ); } } @@ -134,10 +164,6 @@ public string TestStringProperty public class PropertyDependOnClass { - public void PropertyDependOnClassMethod() - { - - } - + public void PropertyDependOnClassMethod() { } } } diff --git a/ArchUnitNETTests/Dependencies/StringDependenciesTests.cs b/ArchUnitNETTests/Dependencies/StringDependenciesTests.cs index bf0b4180f..f8f7845e9 100644 --- a/ArchUnitNETTests/Dependencies/StringDependenciesTests.cs +++ b/ArchUnitNETTests/Dependencies/StringDependenciesTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Linq; using ArchUnitNET.Domain; @@ -15,8 +15,9 @@ namespace ArchUnitNETTests.Dependencies { public class StringDependenciesTests { - private static readonly Architecture Architecture = - new ArchLoader().LoadAssembly(typeof(StringDependenciesTests).Assembly).Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssembly(typeof(StringDependenciesTests).Assembly) + .Build(); private readonly Class _classWithLocalString; private readonly Class _classWithPropertyString; @@ -30,14 +31,18 @@ public StringDependenciesTests() _classWithPropertyString = Architecture.GetClassOfType(typeof(ClassWithPropertyString)); } - [Fact(Skip = "Fails because the string is created with OpCode Ldstr which has no TypeReference as Operand")] + [Fact( + Skip = "Fails because the string is created with OpCode Ldstr which has no TypeReference as Operand" + )] public void StringFieldDependencyFound() { var typeDependencies = _classWithStringField.GetTypeDependencies().ToList(); Assert.Contains(typeof(string).FullName, typeDependencies.Select(dep => dep.FullName)); } - [Fact(Skip = "Fails because the string is created with OpCode Ldstr which has no TypeReference as Operand")] + [Fact( + Skip = "Fails because the string is created with OpCode Ldstr which has no TypeReference as Operand" + )] public void LocalStringDependencyFound() { var typeDependencies = _classWithLocalString.GetTypeDependencies().ToList(); @@ -45,10 +50,15 @@ public void LocalStringDependencyFound() var methodTypeDependencies = method.GetTypeDependencies().ToList(); Assert.Contains(typeof(string).FullName, typeDependencies.Select(dep => dep.FullName)); - Assert.Contains(typeof(string).FullName, methodTypeDependencies.Select(dep => dep.FullName)); + Assert.Contains( + typeof(string).FullName, + methodTypeDependencies.Select(dep => dep.FullName) + ); } - [Fact(Skip = "Fails because the string is created with OpCode Ldstr which has no TypeReference as Operand")] + [Fact( + Skip = "Fails because the string is created with OpCode Ldstr which has no TypeReference as Operand" + )] public void PropertyStringDependencyFound() { var typeDependencies = _classWithPropertyString.GetTypeDependencies().ToList(); @@ -56,7 +66,10 @@ public void PropertyStringDependencyFound() var propertyTypeDependencies = property.GetTypeDependencies().ToList(); Assert.Contains(typeof(string).FullName, typeDependencies.Select(dep => dep.FullName)); - Assert.Contains(typeof(string).FullName, propertyTypeDependencies.Select(dep => dep.FullName)); + Assert.Contains( + typeof(string).FullName, + propertyTypeDependencies.Select(dep => dep.FullName) + ); } } @@ -77,4 +90,4 @@ internal class ClassWithPropertyString { public object Prop => "PropertyString"; } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Dependencies/TypeCheckDependenciesTests.cs b/ArchUnitNETTests/Dependencies/TypeCheckDependenciesTests.cs index 0485e5f7e..5fec7aa18 100644 --- a/ArchUnitNETTests/Dependencies/TypeCheckDependenciesTests.cs +++ b/ArchUnitNETTests/Dependencies/TypeCheckDependenciesTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Linq; using ArchUnitNET.Domain; @@ -15,8 +15,9 @@ namespace ArchUnitNETTests.Dependencies { public class TypeCheckDependenciesTests { - private static readonly Architecture Architecture = - new ArchLoader().LoadAssembly(typeof(TypeCheckDependenciesTests).Assembly).Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssembly(typeof(TypeCheckDependenciesTests).Assembly) + .Build(); private readonly Class _classWithTypeDepencency; private readonly Class _dependingClass; @@ -30,8 +31,9 @@ public TypeCheckDependenciesTests() [Fact] public void TypeCheckDependencyTest() { - var methodMember = - _classWithTypeDepencency.Members.First(member => member.NameContains("MethodWithTypeDependency")); + var methodMember = _classWithTypeDepencency.Members.First(member => + member.NameContains("MethodWithTypeDependency") + ); var typeDependencies = _classWithTypeDepencency.GetTypeDependencies().ToList(); var methodTypeDependencies = methodMember.GetTypeDependencies().ToList(); @@ -44,13 +46,9 @@ internal class ClassWithTypeDependency { public void MethodWithTypeDependency(object obj) { - if (obj is DependingClass) - { - } + if (obj is DependingClass) { } } } - internal class DependingClass - { - } -} \ No newline at end of file + internal class DependingClass { } +} diff --git a/ArchUnitNETTests/Dependencies/TypeOfDependenciesTests.cs b/ArchUnitNETTests/Dependencies/TypeOfDependenciesTests.cs index 9966623b7..ded0c03f2 100644 --- a/ArchUnitNETTests/Dependencies/TypeOfDependenciesTests.cs +++ b/ArchUnitNETTests/Dependencies/TypeOfDependenciesTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Linq; using ArchUnitNET.Domain; @@ -15,23 +15,27 @@ namespace ArchUnitNETTests.Dependencies { public class TypeOfDependenciesTests { - private static readonly Architecture Architecture = - new ArchLoader().LoadAssembly(typeof(TypeOfDependenciesTests).Assembly).Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssembly(typeof(TypeOfDependenciesTests).Assembly) + .Build(); private readonly Class _classWithTypeOfDependency; private readonly Class _dependingTypeOfClass; public TypeOfDependenciesTests() { - _classWithTypeOfDependency = Architecture.GetClassOfType(typeof(ClassWithTypeOfDependency)); + _classWithTypeOfDependency = Architecture.GetClassOfType( + typeof(ClassWithTypeOfDependency) + ); _dependingTypeOfClass = Architecture.GetClassOfType(typeof(DependingTypeOfClass)); } [SkipInReleaseBuild] public void TypeOfDependencyTest() { - var methodMember = - _classWithTypeOfDependency.Members.First(member => member.NameContains("MethodWithTypeOfDependency")); + var methodMember = _classWithTypeOfDependency.Members.First(member => + member.NameContains("MethodWithTypeOfDependency") + ); var typeDependencies = _classWithTypeOfDependency.GetTypeDependencies().ToList(); var methodTypeDependencies = methodMember.GetTypeDependencies().ToList(); @@ -48,7 +52,5 @@ public void MethodWithTypeOfDependency() } } - internal class DependingTypeOfClass - { - } -} \ No newline at end of file + internal class DependingTypeOfClass { } +} diff --git a/ArchUnitNETTests/Domain/ArchitectureCacheKeyTests.cs b/ArchUnitNETTests/Domain/ArchitectureCacheKeyTests.cs index 44c20720e..8d33192a0 100644 --- a/ArchUnitNETTests/Domain/ArchitectureCacheKeyTests.cs +++ b/ArchUnitNETTests/Domain/ArchitectureCacheKeyTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -17,10 +17,15 @@ public class ArchitectureCacheKeyTests public ArchitectureCacheKeyTests() { _baseClassModuleName = ModuleDefinition - .ReadModule(typeof(BaseClass).Assembly.Location, new ReaderParameters()).Name; + .ReadModule(typeof(BaseClass).Assembly.Location, new ReaderParameters()) + .Name; _architectureCacheTestsClassModuleName = ModuleDefinition - .ReadModule(typeof(ArchitectureCacheTests).Assembly.Location, new ReaderParameters()).Name; + .ReadModule( + typeof(ArchitectureCacheTests).Assembly.Location, + new ReaderParameters() + ) + .Name; _memberDependencyTests = typeof(BodyTypeMemberDependencyTests).Namespace; _attributeDependencyTests = typeof(AttributeDependencyTests).Namespace; @@ -45,7 +50,7 @@ public void ArchitectureCacheKeyContentEquivalentsAreEqual() [Fact] public void ArchitectureCacheKeyDoesNotEqualNull() { - Assert.False(_architectureCacheKey.Equals((object) null)); + Assert.False(_architectureCacheKey.Equals((object)null)); } [Fact] @@ -122,4 +127,4 @@ public void SameObjectReferenceIsSameArchitectureCacheKet() Assert.True(_architectureCacheKey.Equals(referenceDuplicate)); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/ArchitectureCacheTests.cs b/ArchUnitNETTests/Domain/ArchitectureCacheTests.cs index f9d318131..2613121fe 100644 --- a/ArchUnitNETTests/Domain/ArchitectureCacheTests.cs +++ b/ArchUnitNETTests/Domain/ArchitectureCacheTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -23,8 +23,13 @@ public ArchitectureCacheTests() _testArchitectureCacheKey = new ArchitectureCacheKey(); _testArchitectureCacheKey.Add(typeof(ArchitectureCacheTests).Assembly.FullName, null); - _testEmptyArchitecture = new Architecture(new List(), new List(), new List(), - new List(), new List()); + _testEmptyArchitecture = new Architecture( + new List(), + new List(), + new List(), + new List(), + new List() + ); } [Fact] @@ -36,13 +41,14 @@ public void DuplicateArchitectureDetected() Assert.True(_testArchitectureCache.Size() == 1); } - [Fact] public void GetExistingArchitecture() { _testArchitectureCache.Add(_testArchitectureCacheKey, _testEmptyArchitecture); - Assert.Equal(_testArchitectureCache.TryGetArchitecture(_testArchitectureCacheKey), - _testEmptyArchitecture); + Assert.Equal( + _testArchitectureCache.TryGetArchitecture(_testArchitectureCacheKey), + _testEmptyArchitecture + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/AttributeArgumentTests.cs b/ArchUnitNETTests/Domain/AttributeArgumentTests.cs index 5102a0026..8da8b6043 100644 --- a/ArchUnitNETTests/Domain/AttributeArgumentTests.cs +++ b/ArchUnitNETTests/Domain/AttributeArgumentTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System; using System.Linq; @@ -19,8 +19,9 @@ namespace ArchUnitNETTests.Domain { public class AttributeArgumentTests { - private static readonly Architecture Architecture = - new ArchLoader().LoadAssembly(typeof(AttributeArgumentTests).Assembly).Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssembly(typeof(AttributeArgumentTests).Assembly) + .Build(); private readonly Class _classWithMultipleAttributesWithParameters; private readonly Class _classWithTypeParameterAttribute; @@ -32,35 +33,46 @@ public class AttributeArgumentTests public AttributeArgumentTests() { - _classWithMultipleAttributesWithParameters = - Architecture.GetClassOfType(typeof(ClassWithMultipleAttributesWithParameters)); - _classWithTypeParameterAttribute = - Architecture.GetClassOfType(typeof(ClassWithTypeParameterAttribute)); - _classWithArrayParameterAttribute = - Architecture.GetClassOfType(typeof(ClassWithArrayParameterAttribute)); - _classWithMixedParameterAttribute = - Architecture.GetClassOfType(typeof(ClassWithMixedParameterAttribute)); - _attributeWithStringParameters = Architecture - .GetAttributeOfType(typeof(AttributeWithStringParameters)); - _attributeWithObjectParameter = Architecture - .GetAttributeOfType(typeof(AttributeWithObjectParameter)); + _classWithMultipleAttributesWithParameters = Architecture.GetClassOfType( + typeof(ClassWithMultipleAttributesWithParameters) + ); + _classWithTypeParameterAttribute = Architecture.GetClassOfType( + typeof(ClassWithTypeParameterAttribute) + ); + _classWithArrayParameterAttribute = Architecture.GetClassOfType( + typeof(ClassWithArrayParameterAttribute) + ); + _classWithMixedParameterAttribute = Architecture.GetClassOfType( + typeof(ClassWithMixedParameterAttribute) + ); + _attributeWithStringParameters = Architecture.GetAttributeOfType( + typeof(AttributeWithStringParameters) + ); + _attributeWithObjectParameter = Architecture.GetAttributeOfType( + typeof(AttributeWithObjectParameter) + ); } [Fact] public void AssignArrayParametersToAttributeInstance() { - var argumentValues = _classWithArrayParameterAttribute.AttributeInstances.First().AttributeArguments - .Select(arg => (object[]) arg.Value).ToList(); - Assert.Contains(new object[] {1, 2, 3}, argumentValues); - Assert.Contains(new object[] {"a", "b", "c", "d"}, argumentValues); + var argumentValues = _classWithArrayParameterAttribute + .AttributeInstances.First() + .AttributeArguments.Select(arg => (object[])arg.Value) + .ToList(); + Assert.Contains(new object[] { 1, 2, 3 }, argumentValues); + Assert.Contains(new object[] { "a", "b", "c", "d" }, argumentValues); Assert.Contains(new object[] { }, argumentValues); } [Fact] public void AssignTypeParametersToAttributeInstance() { - var argumentValues = _classWithTypeParameterAttribute.AttributeInstances.First().AttributeArguments - .Select(arg => (ITypeInstance) arg.Value).Select(instance => instance.Type).ToList(); + var argumentValues = _classWithTypeParameterAttribute + .AttributeInstances.First() + .AttributeArguments.Select(arg => (ITypeInstance)arg.Value) + .Select(instance => instance.Type) + .ToList(); Assert.Contains(_classWithTypeParameterAttribute, argumentValues); Assert.Contains(_classWithArrayParameterAttribute, argumentValues); Assert.Contains(_classWithMixedParameterAttribute, argumentValues); @@ -69,9 +81,11 @@ public void AssignTypeParametersToAttributeInstance() [Fact] public void AssignMixedParametersToAttributeInstance() { - var argumentValues = _classWithMixedParameterAttribute.AttributeInstances.First().AttributeArguments - .Select(arg => arg.Value).ToList(); - Assert.Contains((uint) 10, argumentValues); + var argumentValues = _classWithMixedParameterAttribute + .AttributeInstances.First() + .AttributeArguments.Select(arg => arg.Value) + .ToList(); + Assert.Contains((uint)10, argumentValues); Assert.Contains(true, argumentValues); Assert.Contains("test", argumentValues); } @@ -79,173 +93,424 @@ public void AssignMixedParametersToAttributeInstance() [Fact] public void FindMultipleAttributesOfTheSameType() { - Assert.Equal(3, + Assert.Equal( + 3, _classWithMultipleAttributesWithParameters.Attributes.Count(att => - Equals(att, _attributeWithStringParameters))); - Assert.Equal(1, + Equals(att, _attributeWithStringParameters) + ) + ); + Assert.Equal( + 1, _classWithMultipleAttributesWithParameters.Attributes.Count(att => - Equals(att, _attributeWithObjectParameter))); + Equals(att, _attributeWithObjectParameter) + ) + ); } [Fact] public void AssignNamesToAttributeParameters() { - var namedArguments = _classWithMultipleAttributesWithParameters.AttributeInstances - .SelectMany(instance => instance.AttributeArguments).OfType().ToList(); - Assert.Contains(namedArguments, arg => arg.Name == "Parameter2" && (string) arg.Value == "param2_1"); - Assert.Contains(namedArguments, arg => arg.Name == "Parameter3" && (string) arg.Value == "param3_2"); + var namedArguments = _classWithMultipleAttributesWithParameters + .AttributeInstances.SelectMany(instance => instance.AttributeArguments) + .OfType() + .ToList(); + Assert.Contains( + namedArguments, + arg => arg.Name == "Parameter2" && (string)arg.Value == "param2_1" + ); + Assert.Contains( + namedArguments, + arg => arg.Name == "Parameter3" && (string)arg.Value == "param3_2" + ); } [Fact] public void FluentPredicatesTest() { - Types().That().Are(typeof(ClassWithMultipleAttributesWithParameters)).And() - .HaveAttributeWithArguments(_attributeWithStringParameters, "param1_1").Should().Exist() - .Check(Architecture); - Types().That().Are(typeof(ClassWithMultipleAttributesWithParameters)).And() - .HaveAnyAttributesWithArguments("param1_0").Should() - .Exist().Check(Architecture); - Types().That().Are(typeof(ClassWithMultipleAttributesWithParameters)).And() - .HaveAnyAttributesWithNamedArguments(("Parameter2", "param2_1")).Should() - .Exist().Check(Architecture); - Types().That().Are(typeof(ClassWithMultipleAttributesWithParameters)).And() - .HaveAnyAttributesWithNamedArguments(("Parameter2", "param2_1"), ("Parameter3", "param3_2")).Should() - .Exist().Check(Architecture); - Types().That().Are(typeof(ClassWithMultipleAttributesWithParameters)).And() - .HaveAnyAttributesWithArguments(null).Should() - .Exist().Check(Architecture); - Types().That().Are(typeof(ClassWithTypeParameterAttribute)).And() - .HaveAnyAttributesWithArguments(typeof(ClassWithArrayParameterAttribute)).Should() - .Exist().Check(Architecture); - Types().That().Are(typeof(ClassWithTypeParameterAttribute)).And() - .HaveAnyAttributesWithNamedArguments(("Type2", typeof(ClassWithArrayParameterAttribute))).Should() - .Exist().Check(Architecture); - + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .And() + .HaveAttributeWithArguments(_attributeWithStringParameters, "param1_1") + .Should() + .Exist() + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .And() + .HaveAnyAttributesWithArguments("param1_0") + .Should() + .Exist() + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .And() + .HaveAnyAttributesWithNamedArguments(("Parameter2", "param2_1")) + .Should() + .Exist() + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .And() + .HaveAnyAttributesWithNamedArguments( + ("Parameter2", "param2_1"), + ("Parameter3", "param3_2") + ) + .Should() + .Exist() + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .And() + .HaveAnyAttributesWithArguments(null) + .Should() + .Exist() + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithTypeParameterAttribute)) + .And() + .HaveAnyAttributesWithArguments(typeof(ClassWithArrayParameterAttribute)) + .Should() + .Exist() + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithTypeParameterAttribute)) + .And() + .HaveAnyAttributesWithNamedArguments( + ("Type2", typeof(ClassWithArrayParameterAttribute)) + ) + .Should() + .Exist() + .Check(Architecture); - Types().That().Are(typeof(ClassWithMultipleAttributesWithParameters)).And() - .HaveAnyAttributesWithNamedArguments(("Parameter2", "param1_1")).Should() - .NotExist().Check(Architecture); - Types().That().Are(typeof(ClassWithMultipleAttributesWithParameters)).And() - .HaveAttributeWithArguments(_attributeWithStringParameters, "non_existent").Should() - .NotExist().Check(Architecture); - Types().That().Are(typeof(ClassWithTypeParameterAttribute)).And() - .HaveAnyAttributesWithNamedArguments(("Type3", typeof(ClassWithArrayParameterAttribute))).Should() - .NotExist().Check(Architecture); - Types().That().Are(typeof(ClassWithMultipleAttributesWithParameters)).And() - .HaveAnyAttributesWithArguments("1").Should() - .NotExist().Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .And() + .HaveAnyAttributesWithNamedArguments(("Parameter2", "param1_1")) + .Should() + .NotExist() + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .And() + .HaveAttributeWithArguments(_attributeWithStringParameters, "non_existent") + .Should() + .NotExist() + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithTypeParameterAttribute)) + .And() + .HaveAnyAttributesWithNamedArguments( + ("Type3", typeof(ClassWithArrayParameterAttribute)) + ) + .Should() + .NotExist() + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .And() + .HaveAnyAttributesWithArguments("1") + .Should() + .NotExist() + .Check(Architecture); //Negations - Types().That().Are(typeof(ClassWithMultipleAttributesWithParameters)).And() - .DoNotHaveAttributeWithArguments(_attributeWithStringParameters, "param1_1").Should().NotExist() - .Check(Architecture); - Types().That().Are(typeof(ClassWithMultipleAttributesWithParameters)).And() - .DoNotHaveAnyAttributesWithArguments("param1_0").Should() - .NotExist().Check(Architecture); - Types().That().Are(typeof(ClassWithMultipleAttributesWithParameters)).And() - .DoNotHaveAnyAttributesWithNamedArguments(("Parameter2", "param2_1")).Should() - .NotExist().Check(Architecture); - Types().That().Are(typeof(ClassWithMultipleAttributesWithParameters)).And() - .DoNotHaveAnyAttributesWithNamedArguments(("Parameter2", "param2_1"), ("Parameter3", "param3_2")) - .Should() - .NotExist().Check(Architecture); - Types().That().Are(typeof(ClassWithMultipleAttributesWithParameters)).And() - .DoNotHaveAnyAttributesWithArguments(null).Should() - .NotExist().Check(Architecture); - Types().That().Are(typeof(ClassWithTypeParameterAttribute)).And() - .DoNotHaveAnyAttributesWithArguments(typeof(ClassWithArrayParameterAttribute)).Should() - .NotExist().Check(Architecture); - Types().That().Are(typeof(ClassWithTypeParameterAttribute)).And() - .DoNotHaveAnyAttributesWithNamedArguments(("Type2", typeof(ClassWithArrayParameterAttribute))).Should() - .NotExist().Check(Architecture); - + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .And() + .DoNotHaveAttributeWithArguments(_attributeWithStringParameters, "param1_1") + .Should() + .NotExist() + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .And() + .DoNotHaveAnyAttributesWithArguments("param1_0") + .Should() + .NotExist() + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .And() + .DoNotHaveAnyAttributesWithNamedArguments(("Parameter2", "param2_1")) + .Should() + .NotExist() + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .And() + .DoNotHaveAnyAttributesWithNamedArguments( + ("Parameter2", "param2_1"), + ("Parameter3", "param3_2") + ) + .Should() + .NotExist() + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .And() + .DoNotHaveAnyAttributesWithArguments(null) + .Should() + .NotExist() + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithTypeParameterAttribute)) + .And() + .DoNotHaveAnyAttributesWithArguments(typeof(ClassWithArrayParameterAttribute)) + .Should() + .NotExist() + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithTypeParameterAttribute)) + .And() + .DoNotHaveAnyAttributesWithNamedArguments( + ("Type2", typeof(ClassWithArrayParameterAttribute)) + ) + .Should() + .NotExist() + .Check(Architecture); - Types().That().Are(typeof(ClassWithMultipleAttributesWithParameters)).And() - .DoNotHaveAnyAttributesWithNamedArguments(("Parameter2", "param1_1")).Should() - .Exist().Check(Architecture); - Types().That().Are(typeof(ClassWithMultipleAttributesWithParameters)).And() - .DoNotHaveAttributeWithArguments(_attributeWithStringParameters, "non_existent").Should() - .Exist().Check(Architecture); - Types().That().Are(typeof(ClassWithTypeParameterAttribute)).And() - .DoNotHaveAnyAttributesWithNamedArguments(("Type3", typeof(ClassWithArrayParameterAttribute))).Should() - .Exist().Check(Architecture); - Types().That().Are(typeof(ClassWithMultipleAttributesWithParameters)).And() - .DoNotHaveAnyAttributesWithArguments("1").Should() - .Exist().Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .And() + .DoNotHaveAnyAttributesWithNamedArguments(("Parameter2", "param1_1")) + .Should() + .Exist() + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .And() + .DoNotHaveAttributeWithArguments(_attributeWithStringParameters, "non_existent") + .Should() + .Exist() + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithTypeParameterAttribute)) + .And() + .DoNotHaveAnyAttributesWithNamedArguments( + ("Type3", typeof(ClassWithArrayParameterAttribute)) + ) + .Should() + .Exist() + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .And() + .DoNotHaveAnyAttributesWithArguments("1") + .Should() + .Exist() + .Check(Architecture); } [Fact] public void FluentConditionsTest() { - Types().That().Are(typeof(ClassWithMultipleAttributesWithParameters)).Should() - .HaveAttributeWithArguments(_attributeWithStringParameters, "param1_1").Check(Architecture); - Types().That().Are(typeof(ClassWithMultipleAttributesWithParameters)).Should() - .HaveAnyAttributesWithArguments("param1_0").Check(Architecture); - Types().That().Are(typeof(ClassWithMultipleAttributesWithParameters)).Should() - .HaveAnyAttributesWithNamedArguments(("Parameter2", "param2_1")).Check(Architecture); - Types().That().Are(typeof(ClassWithMultipleAttributesWithParameters)).Should() - .HaveAnyAttributesWithNamedArguments(("Parameter2", "param2_1"), ("Parameter3", "param3_2")) - .Check(Architecture); - Types().That().Are(typeof(ClassWithMultipleAttributesWithParameters)).Should() - .HaveAnyAttributesWithArguments(null).Check(Architecture); - Types().That().Are(typeof(ClassWithTypeParameterAttribute)).Should() - .HaveAnyAttributesWithArguments(typeof(ClassWithArrayParameterAttribute)).Check(Architecture); - Types().That().Are(typeof(ClassWithTypeParameterAttribute)).Should() - .HaveAnyAttributesWithNamedArguments(("Type2", typeof(ClassWithArrayParameterAttribute))) + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .Should() + .HaveAttributeWithArguments(_attributeWithStringParameters, "param1_1") + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .Should() + .HaveAnyAttributesWithArguments("param1_0") + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .Should() + .HaveAnyAttributesWithNamedArguments(("Parameter2", "param2_1")) + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .Should() + .HaveAnyAttributesWithNamedArguments( + ("Parameter2", "param2_1"), + ("Parameter3", "param3_2") + ) + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .Should() + .HaveAnyAttributesWithArguments(null) + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithTypeParameterAttribute)) + .Should() + .HaveAnyAttributesWithArguments(typeof(ClassWithArrayParameterAttribute)) + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithTypeParameterAttribute)) + .Should() + .HaveAnyAttributesWithNamedArguments( + ("Type2", typeof(ClassWithArrayParameterAttribute)) + ) .Check(Architecture); - - Assert.Throws(() => Types().That() - .Are(typeof(ClassWithMultipleAttributesWithParameters)).Should() - .HaveAnyAttributesWithNamedArguments(("Parameter2", "param1_1")).Check(Architecture)); - Assert.Throws(() => Types().That() - .Are(typeof(ClassWithMultipleAttributesWithParameters)).Should() - .HaveAttributeWithArguments(_attributeWithStringParameters, "non_existent").Check(Architecture)); - Assert.Throws(() => Types().That().Are(typeof(ClassWithTypeParameterAttribute)) - .Should() - .HaveAnyAttributesWithNamedArguments(("Type3", typeof(ClassWithArrayParameterAttribute))) - .Check(Architecture)); - Assert.Throws(() => Types().That() - .Are(typeof(ClassWithMultipleAttributesWithParameters)).Should() - .HaveAnyAttributesWithArguments("1").Check(Architecture)); + Assert.Throws( + () => + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .Should() + .HaveAnyAttributesWithNamedArguments(("Parameter2", "param1_1")) + .Check(Architecture) + ); + Assert.Throws( + () => + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .Should() + .HaveAttributeWithArguments(_attributeWithStringParameters, "non_existent") + .Check(Architecture) + ); + Assert.Throws( + () => + Types() + .That() + .Are(typeof(ClassWithTypeParameterAttribute)) + .Should() + .HaveAnyAttributesWithNamedArguments( + ("Type3", typeof(ClassWithArrayParameterAttribute)) + ) + .Check(Architecture) + ); + Assert.Throws( + () => + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .Should() + .HaveAnyAttributesWithArguments("1") + .Check(Architecture) + ); //Negations - Assert.Throws(() => Types().That() - .Are(typeof(ClassWithMultipleAttributesWithParameters)).Should() - .NotHaveAttributeWithArguments(_attributeWithStringParameters, "param1_1").Check(Architecture)); - Assert.Throws(() => Types().That() - .Are(typeof(ClassWithMultipleAttributesWithParameters)).Should() - .NotHaveAnyAttributesWithArguments("param1_0").Check(Architecture)); - Assert.Throws(() => Types().That() - .Are(typeof(ClassWithMultipleAttributesWithParameters)).Should() - .NotHaveAnyAttributesWithNamedArguments(("Parameter2", "param2_1")).Check(Architecture)); - Assert.Throws(() => Types().That() - .Are(typeof(ClassWithMultipleAttributesWithParameters)).Should() - .NotHaveAnyAttributesWithNamedArguments(("Parameter2", "param2_1"), ("Parameter3", "param3_2")) - .Check(Architecture)); - Assert.Throws(() => Types().That() - .Are(typeof(ClassWithMultipleAttributesWithParameters)).Should() - .NotHaveAnyAttributesWithArguments(null).Check(Architecture)); - Assert.Throws(() => Types().That().Are(typeof(ClassWithTypeParameterAttribute)) - .Should() - .NotHaveAnyAttributesWithArguments(typeof(ClassWithArrayParameterAttribute)).Check(Architecture)); - Assert.Throws(() => Types().That().Are(typeof(ClassWithTypeParameterAttribute)) - .Should() - .NotHaveAnyAttributesWithNamedArguments(("Type2", typeof(ClassWithArrayParameterAttribute))) - .Check(Architecture)); - - - Types().That().Are(typeof(ClassWithMultipleAttributesWithParameters)).Should() - .NotHaveAnyAttributesWithNamedArguments(("Parameter2", "param1_1")).Check(Architecture); - Types().That().Are(typeof(ClassWithMultipleAttributesWithParameters)).Should() - .NotHaveAttributeWithArguments(_attributeWithStringParameters, "non_existent").Check(Architecture); - Types().That().Are(typeof(ClassWithTypeParameterAttribute)).Should() - .NotHaveAnyAttributesWithNamedArguments(("Type3", typeof(ClassWithArrayParameterAttribute))) - .Check(Architecture); - Types().That().Are(typeof(ClassWithMultipleAttributesWithParameters)).Should() - .NotHaveAnyAttributesWithArguments("1").Check(Architecture); + Assert.Throws( + () => + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .Should() + .NotHaveAttributeWithArguments(_attributeWithStringParameters, "param1_1") + .Check(Architecture) + ); + Assert.Throws( + () => + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .Should() + .NotHaveAnyAttributesWithArguments("param1_0") + .Check(Architecture) + ); + Assert.Throws( + () => + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .Should() + .NotHaveAnyAttributesWithNamedArguments(("Parameter2", "param2_1")) + .Check(Architecture) + ); + Assert.Throws( + () => + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .Should() + .NotHaveAnyAttributesWithNamedArguments( + ("Parameter2", "param2_1"), + ("Parameter3", "param3_2") + ) + .Check(Architecture) + ); + Assert.Throws( + () => + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .Should() + .NotHaveAnyAttributesWithArguments(null) + .Check(Architecture) + ); + Assert.Throws( + () => + Types() + .That() + .Are(typeof(ClassWithTypeParameterAttribute)) + .Should() + .NotHaveAnyAttributesWithArguments(typeof(ClassWithArrayParameterAttribute)) + .Check(Architecture) + ); + Assert.Throws( + () => + Types() + .That() + .Are(typeof(ClassWithTypeParameterAttribute)) + .Should() + .NotHaveAnyAttributesWithNamedArguments( + ("Type2", typeof(ClassWithArrayParameterAttribute)) + ) + .Check(Architecture) + ); + + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .Should() + .NotHaveAnyAttributesWithNamedArguments(("Parameter2", "param1_1")) + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .Should() + .NotHaveAttributeWithArguments(_attributeWithStringParameters, "non_existent") + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithTypeParameterAttribute)) + .Should() + .NotHaveAnyAttributesWithNamedArguments( + ("Type3", typeof(ClassWithArrayParameterAttribute)) + ) + .Check(Architecture); + Types() + .That() + .Are(typeof(ClassWithMultipleAttributesWithParameters)) + .Should() + .NotHaveAnyAttributesWithArguments("1") + .Check(Architecture); } } @@ -270,13 +535,9 @@ public AttributeWithStringParameters(string parameter1, string parameter2) internal class AttributeWithObjectParameter : Attribute { - public AttributeWithObjectParameter(params object[] arguments) - { - } + public AttributeWithObjectParameter(params object[] arguments) { } - public AttributeWithObjectParameter(object arg) - { - } + public AttributeWithObjectParameter(object arg) { } public object Type { get; } public object Type2; @@ -287,27 +548,28 @@ public AttributeWithObjectParameter(object arg) [AttributeWithStringParameters("param1_1", Parameter2 = "param2_1")] [AttributeWithStringParameters("param1_2", "param2_2", Parameter3 = "param3_2")] [AttributeWithObjectParameter(null)] - internal class ClassWithMultipleAttributesWithParameters - { - } + internal class ClassWithMultipleAttributesWithParameters { } - [AttributeWithObjectParameter(typeof(ClassWithTypeParameterAttribute), - Type2 = typeof(ClassWithArrayParameterAttribute), Type3 = typeof(ClassWithMixedParameterAttribute))] + [AttributeWithObjectParameter( + typeof(ClassWithTypeParameterAttribute), + Type2 = typeof(ClassWithArrayParameterAttribute), + Type3 = typeof(ClassWithMixedParameterAttribute) + )] internal class ClassWithTypeParameterAttribute { public ClassWithTypeParameterAttribute() { - var a = new[] {new[] {"a", "b"}, new[] {"c", "d"}}; + var a = new[] { new[] { "a", "b" }, new[] { "c", "d" } }; } } - [AttributeWithObjectParameter(new[] {1, 2, 3}, Type2 = new[] {"a", "b", "c", "d"}, Type3 = new bool[] { })] - internal class ClassWithArrayParameterAttribute - { - } + [AttributeWithObjectParameter( + new[] { 1, 2, 3 }, + Type2 = new[] { "a", "b", "c", "d" }, + Type3 = new bool[] { } + )] + internal class ClassWithArrayParameterAttribute { } - [AttributeWithObjectParameter((uint) 10, Type2 = true, Type3 = "test")] - internal class ClassWithMixedParameterAttribute - { - } -} \ No newline at end of file + [AttributeWithObjectParameter((uint)10, Type2 = true, Type3 = "test")] + internal class ClassWithMixedParameterAttribute { } +} diff --git a/ArchUnitNETTests/Domain/AttributeTests.cs b/ArchUnitNETTests/Domain/AttributeTests.cs index fa2b9013c..b6551a7f5 100644 --- a/ArchUnitNETTests/Domain/AttributeTests.cs +++ b/ArchUnitNETTests/Domain/AttributeTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Linq; @@ -17,7 +17,8 @@ namespace ArchUnitNETTests.Domain { public class AttributeTests { - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; private readonly AttributeOriginClassPair _abstractAttributePair; private readonly AttributeEquivalencyTestData _attributeEquivalencyTestData; @@ -39,31 +40,53 @@ public class AttributeTests public AttributeTests() { - _developerAttributePair = new AttributeOriginClassPair(typeof(CountryAttributeWithParameters)); + _developerAttributePair = new AttributeOriginClassPair( + typeof(CountryAttributeWithParameters) + ); _abstractAttributePair = new AttributeOriginClassPair(typeof(ExampleAbstractAttribute)); - _attributeEquivalencyTestData = new AttributeEquivalencyTestData(typeof(CountryAttributeWithParameters)); + _attributeEquivalencyTestData = new AttributeEquivalencyTestData( + typeof(CountryAttributeWithParameters) + ); _iAttribute = Architecture.GetInterfaceOfType(typeof(IAttribute)); - _interfaceImplementingAttributePair = new AttributeOriginClassPair(typeof(InterfaceImplementingAttribute)); - _implementsAbstractAttribute = new Attribute(Architecture.GetClassOfType(typeof(ChildOfAbstractAttribute))); - _unrelatedType = new Type(_abstractAttributePair.OriginClass.Name, - _abstractAttributePair.OriginClass.FullName, _abstractAttributePair.OriginClass.Assembly, - _abstractAttributePair.OriginClass.Namespace, _abstractAttributePair.OriginClass.Visibility, - _abstractAttributePair.OriginClass.IsNested, _abstractAttributePair.OriginClass.IsGeneric, - _abstractAttributePair.OriginClass.IsStub, false); - _unrelatedType.GenericParameters.AddRange(_abstractAttributePair.OriginClass.GenericParameters); + _interfaceImplementingAttributePair = new AttributeOriginClassPair( + typeof(InterfaceImplementingAttribute) + ); + _implementsAbstractAttribute = new Attribute( + Architecture.GetClassOfType(typeof(ChildOfAbstractAttribute)) + ); + _unrelatedType = new Type( + _abstractAttributePair.OriginClass.Name, + _abstractAttributePair.OriginClass.FullName, + _abstractAttributePair.OriginClass.Assembly, + _abstractAttributePair.OriginClass.Namespace, + _abstractAttributePair.OriginClass.Visibility, + _abstractAttributePair.OriginClass.IsNested, + _abstractAttributePair.OriginClass.IsGeneric, + _abstractAttributePair.OriginClass.IsStub, + false + ); + _unrelatedType.GenericParameters.AddRange( + _abstractAttributePair.OriginClass.GenericParameters + ); _propertyMember = _implementsAbstractAttribute - .GetPropertyMembersWithName(nameof(ChildOfAbstractAttribute.Property)).SingleOrDefault(); - _inheritedFieldMember = _abstractAttributePair.Attribute - .GetFieldMembersWithName("_fieldType").SingleOrDefault(); + .GetPropertyMembersWithName(nameof(ChildOfAbstractAttribute.Property)) + .SingleOrDefault(); + _inheritedFieldMember = _abstractAttributePair + .Attribute.GetFieldMembersWithName("_fieldType") + .SingleOrDefault(); _constructorAttributePair = new AttributeOriginClassPair(typeof(ConstructorAttribute)); - _attributeWithAttributesPair = new AttributeOriginClassPair(typeof(AttributeWithAttributes)); + _attributeWithAttributesPair = new AttributeOriginClassPair( + typeof(AttributeWithAttributes) + ); } [Fact] public void AssemblyAsExpected() { - Assert.Equal(_developerAttributePair.OriginClass.Assembly, - _developerAttributePair.Attribute.Assembly); + Assert.Equal( + _developerAttributePair.OriginClass.Assembly, + _developerAttributePair.Attribute.Assembly + ); } [Fact] @@ -84,7 +107,9 @@ public void AttributeHasConsistentHashCode() public void AttributesAreSubsetOfClasses() { Assert.NotEmpty(Architecture.Attributes); - Architecture.Attributes.ForEach(attribute => Assert.Contains(attribute, Architecture.Classes)); + Architecture.Attributes.ForEach(attribute => + Assert.Contains(attribute, Architecture.Classes) + ); } [Fact] @@ -101,60 +126,85 @@ public void AttributesCorrectlyAssigned() public void AttributesOfAttributeAsExpected() { _attributeWithAttributesPair.OriginClass.Attributes.ForEach(originClassAttribute => - Assert.Contains(originClassAttribute, _attributeWithAttributesPair.Attribute.Attributes)); + Assert.Contains( + originClassAttribute, + _attributeWithAttributesPair.Attribute.Attributes + ) + ); } [Fact] public void ConstructorsAsExpected() { _constructorAttributePair.OriginClass.Constructors.ForEach(originClassConstructor => - Assert.Contains(originClassConstructor, _constructorAttributePair.Attribute.Constructors)); + Assert.Contains( + originClassConstructor, + _constructorAttributePair.Attribute.Constructors + ) + ); } [Fact] public void DependenciesAsExpected() { - Assert.Equal(_developerAttributePair.OriginClass.Dependencies, - _developerAttributePair.Attribute.Dependencies); + Assert.Equal( + _developerAttributePair.OriginClass.Dependencies, + _developerAttributePair.Attribute.Dependencies + ); } [Fact] public void DuplicateAttributeObjectReferencesAreEqual() { - Assert.True(_attributeEquivalencyTestData.OriginAttribute - .Equals(_attributeEquivalencyTestData.ObjectReferenceDuplicate)); + Assert.True( + _attributeEquivalencyTestData.OriginAttribute.Equals( + _attributeEquivalencyTestData.ObjectReferenceDuplicate + ) + ); } [Fact] public void DuplicateAttributeReferencesAreEqual() { - Assert.True(_attributeEquivalencyTestData.OriginAttribute - .Equals(_attributeEquivalencyTestData.AttributeReferenceDuplicate)); + Assert.True( + _attributeEquivalencyTestData.OriginAttribute.Equals( + _attributeEquivalencyTestData.AttributeReferenceDuplicate + ) + ); } [Fact] public void DuplicateAttributesAreEqual() { - Assert.True(_attributeEquivalencyTestData.OriginAttribute - .Equals(_attributeEquivalencyTestData.DuplicateAttribute)); + Assert.True( + _attributeEquivalencyTestData.OriginAttribute.Equals( + _attributeEquivalencyTestData.DuplicateAttribute + ) + ); } [Fact] public void ImplementedInterfacesRecognized() { - _interfaceImplementingAttributePair.OriginClass.ImplementedInterfaces - .ForEach(implementedInterface => + _interfaceImplementingAttributePair.OriginClass.ImplementedInterfaces.ForEach( + implementedInterface => { - Assert.Contains(implementedInterface, - _interfaceImplementingAttributePair.Attribute.ImplementedInterfaces); - }); + Assert.Contains( + implementedInterface, + _interfaceImplementingAttributePair.Attribute.ImplementedInterfaces + ); + } + ); } [Fact] public void InheritsBaseClassDependenciesAsExpected() { var expectedInheritedDependency = new FieldTypeDependency(_inheritedFieldMember); - Assert.Contains(expectedInheritedDependency, _implementsAbstractAttribute.DependenciesIncludingInherited); + Assert.Contains( + expectedInheritedDependency, + _implementsAbstractAttribute.DependenciesIncludingInherited + ); } [Fact] @@ -173,40 +223,52 @@ public void IsAssignableToImplementedInterface() [Fact] public void IsAssignableToItself() { - Assert.True(_abstractAttributePair.Attribute.IsAssignableTo(_abstractAttributePair.Attribute)); + Assert.True( + _abstractAttributePair.Attribute.IsAssignableTo(_abstractAttributePair.Attribute) + ); } [Fact] public void IsAssignableToParentAttribute() { - Assert.True(_implementsAbstractAttribute.IsAssignableTo(_abstractAttributePair.Attribute)); + Assert.True( + _implementsAbstractAttribute.IsAssignableTo(_abstractAttributePair.Attribute) + ); } [Fact] public void IsAssignableToParentClass() { - Assert.True(_implementsAbstractAttribute.IsAssignableTo(_abstractAttributePair.OriginClass)); + Assert.True( + _implementsAbstractAttribute.IsAssignableTo(_abstractAttributePair.OriginClass) + ); } [Fact] public void MembersAsExpected() { - Assert.Equal(_developerAttributePair.OriginClass.Members, - _developerAttributePair.Attribute.Members); + Assert.Equal( + _developerAttributePair.OriginClass.Members, + _developerAttributePair.Attribute.Members + ); } [Fact] public void NameAsExpected() { - Assert.Equal(_developerAttributePair.OriginClass.Name, - _developerAttributePair.Attribute.Name); + Assert.Equal( + _developerAttributePair.OriginClass.Name, + _developerAttributePair.Attribute.Name + ); } [Fact] public void NamespaceAsExpected() { - Assert.Equal(_developerAttributePair.OriginClass.Namespace, - _developerAttributePair.Attribute.Namespace); + Assert.Equal( + _developerAttributePair.OriginClass.Namespace, + _developerAttributePair.Attribute.Namespace + ); } [Fact] @@ -219,7 +281,11 @@ public void NotAssignableToUnRelatedType() public void ParentMembersProperlyInherited() { _interfaceImplementingAttributePair.OriginClass.Members.ForEach(parentMember => - Assert.Contains(parentMember, _interfaceImplementingAttributePair.Attribute.MembersIncludingInherited)); + Assert.Contains( + parentMember, + _interfaceImplementingAttributePair.Attribute.MembersIncludingInherited + ) + ); } [Fact] @@ -242,9 +308,11 @@ public AttributeOriginClassPair(System.Type originType) Attribute = Architecture.GetAttributeOfType(originType); } - [NotNull] public Class OriginClass { get; } + [NotNull] + public Class OriginClass { get; } - [NotNull] public Attribute Attribute { get; } + [NotNull] + public Attribute Attribute { get; } } private class AttributeEquivalencyTestData @@ -252,19 +320,22 @@ private class AttributeEquivalencyTestData public AttributeEquivalencyTestData([NotNull] System.Type originType) { OriginAttribute = new Attribute(Architecture.GetClassOfType(originType)); - DuplicateAttribute = - new Attribute(Architecture.GetClassOfType(originType)); + DuplicateAttribute = new Attribute(Architecture.GetClassOfType(originType)); AttributeReferenceDuplicate = OriginAttribute; ObjectReferenceDuplicate = OriginAttribute; } - [NotNull] public Attribute OriginAttribute { get; } + [NotNull] + public Attribute OriginAttribute { get; } - [NotNull] public object DuplicateAttribute { get; } + [NotNull] + public object DuplicateAttribute { get; } - [NotNull] public Attribute AttributeReferenceDuplicate { get; } + [NotNull] + public Attribute AttributeReferenceDuplicate { get; } - [NotNull] public object ObjectReferenceDuplicate { get; } + [NotNull] + public object ObjectReferenceDuplicate { get; } } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/ClassTests.cs b/ArchUnitNETTests/Domain/ClassTests.cs index 975022ddf..7f84e9a4d 100644 --- a/ArchUnitNETTests/Domain/ClassTests.cs +++ b/ArchUnitNETTests/Domain/ClassTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -13,12 +13,12 @@ using static ArchUnitNET.Domain.Visibility; using static ArchUnitNETTests.Domain.StaticTestTypes; - namespace ArchUnitNETTests.Domain { public class ClassTests { - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; private readonly Class _baseClass; private readonly Interface _chainedInterface; private readonly Class _childClass; @@ -36,9 +36,17 @@ public ClassTests() _childClass = Architecture.GetClassOfType(typeof(ChildClass)); _duplicateChildClass = _baseClass; var backingType = Architecture.GetITypeOfType(typeof(PropertyType)); - _misMatchType = - new Type(backingType.FullName, backingType.Name, backingType.Assembly, backingType.Namespace, - backingType.Visibility, backingType.IsNested, backingType.IsGeneric, backingType.IsStub, false); + _misMatchType = new Type( + backingType.FullName, + backingType.Name, + backingType.Assembly, + backingType.Namespace, + backingType.Visibility, + backingType.IsNested, + backingType.IsGeneric, + backingType.IsStub, + false + ); _misMatchType.GenericParameters.AddRange(backingType.GenericParameters); _implementsInterface = Architecture.GetClassOfType(typeof(InheritingType)); @@ -122,22 +130,29 @@ public void ClassHasConsistentHashCode() [Fact] public void DuplicateClassesAreEqual() { - Assert.Equal(_classEquivalencyTestData.OriginClass, - _classEquivalencyTestData.DuplicateClass); + Assert.Equal( + _classEquivalencyTestData.OriginClass, + _classEquivalencyTestData.DuplicateClass + ); } [Fact] public void DuplicateClassObjectReferencesAreEqual() { - Assert.Equal(_classEquivalencyTestData.OriginClass, - _classEquivalencyTestData.ObjectReferenceDuplicate); + Assert.Equal( + _classEquivalencyTestData.OriginClass, + _classEquivalencyTestData.ObjectReferenceDuplicate + ); } [Fact] public void DuplicateClassReferencesAreEqual() { - Assert.True(_classEquivalencyTestData.OriginClass - .Equals(_classEquivalencyTestData.ClassReferenceDuplicate)); + Assert.True( + _classEquivalencyTestData.OriginClass.Equals( + _classEquivalencyTestData.ClassReferenceDuplicate + ) + ); } [Fact] @@ -165,13 +180,17 @@ public ClassEquivalencyTestData([NotNull] System.Type originType) ObjectReferenceDuplicate = OriginClass; } - [NotNull] public Class OriginClass { get; } + [NotNull] + public Class OriginClass { get; } - [NotNull] public object DuplicateClass { get; } + [NotNull] + public object DuplicateClass { get; } - [NotNull] public Class ClassReferenceDuplicate { get; } + [NotNull] + public Class ClassReferenceDuplicate { get; } - [NotNull] public object ObjectReferenceDuplicate { get; } + [NotNull] + public object ObjectReferenceDuplicate { get; } } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/CompilerGeneratedTypesTests.cs b/ArchUnitNETTests/Domain/CompilerGeneratedTypesTests.cs index f8d2736bb..82153204a 100644 --- a/ArchUnitNETTests/Domain/CompilerGeneratedTypesTests.cs +++ b/ArchUnitNETTests/Domain/CompilerGeneratedTypesTests.cs @@ -1,9 +1,9 @@ // 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; @@ -28,15 +28,23 @@ public CompilerGeneratedTypesTests() [Fact] public void RecognizeCompilerGeneratedTypes() { - Assert.DoesNotContain(Architecture.Types, - type => !type.IsCompilerGenerated && (type.Name.StartsWith("<") || type.Name.StartsWith("!"))); + Assert.DoesNotContain( + Architecture.Types, + type => + !type.IsCompilerGenerated + && (type.Name.StartsWith("<") || type.Name.StartsWith("!")) + ); } [Fact] public void RecognizeCompilerGeneratedMethods() { - Assert.DoesNotContain(Architecture.MethodMembers, - method => !method.IsCompilerGenerated && (method.Name.StartsWith("<") || method.Name.StartsWith("!"))); + Assert.DoesNotContain( + Architecture.MethodMembers, + method => + !method.IsCompilerGenerated + && (method.Name.StartsWith("<") || method.Name.StartsWith("!")) + ); } [Fact] @@ -51,7 +59,9 @@ public void NoCompilerGeneratedTypeInArchitecture() public void NoCompilerGeneratedTypesAsDependencyTarget() { var dependencyTargets = _dependencies.Select(dep => dep.Target); - var compilerGeneratedDependencyTargets = dependencyTargets.Where(type => type.IsCompilerGenerated); + var compilerGeneratedDependencyTargets = dependencyTargets.Where(type => + type.IsCompilerGenerated + ); Assert.Empty(compilerGeneratedDependencyTargets); } @@ -59,11 +69,14 @@ public void NoCompilerGeneratedTypesAsDependencyTarget() [Fact] public void NoCompilerGeneratedTypesAsGenericArguments() { - var genericArgumentTypes = - _dependencies.SelectMany(dep => dep.TargetGenericArguments.Select(argument => argument.Type)); - var compilerGeneratedGenericArgumentTypes = genericArgumentTypes.Where(type => type.IsCompilerGenerated); + var genericArgumentTypes = _dependencies.SelectMany(dep => + dep.TargetGenericArguments.Select(argument => argument.Type) + ); + var compilerGeneratedGenericArgumentTypes = genericArgumentTypes.Where(type => + type.IsCompilerGenerated + ); Assert.Empty(compilerGeneratedGenericArgumentTypes); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/Dependencies/Attributes/AttributeAssertionRepository.cs b/ArchUnitNETTests/Domain/Dependencies/Attributes/AttributeAssertionRepository.cs index e2aa4dd2f..d677ac74f 100644 --- a/ArchUnitNETTests/Domain/Dependencies/Attributes/AttributeAssertionRepository.cs +++ b/ArchUnitNETTests/Domain/Dependencies/Attributes/AttributeAssertionRepository.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -15,8 +15,12 @@ namespace ArchUnitNETTests.Domain.Dependencies.Attributes { public static class AttributeAssertionRepository { - public static void TypeAttributeAsExpected(TTargetType targetType, Class expectedAttributeType, - Attribute actualAttribute) where TTargetType : IType + public static void TypeAttributeAsExpected( + TTargetType targetType, + Class expectedAttributeType, + Attribute actualAttribute + ) + where TTargetType : IType { //Precondition Checks if (targetType == null) @@ -40,8 +44,11 @@ public static void TypeAttributeAsExpected(TTargetType targetType, Assert.Equal(expectedAttributeType, actualAttribute); } - public static void MemberAttributeAsExpected(IMember targetMember, Class expectedAttributeType, - Attribute actualAttribute) + public static void MemberAttributeAsExpected( + IMember targetMember, + Class expectedAttributeType, + Attribute actualAttribute + ) { //Precondition Checks if (targetMember == null) @@ -65,7 +72,10 @@ public static void MemberAttributeAsExpected(IMember targetMember, Class expecte Assert.Equal(expectedAttributeType, actualAttribute); } - public static void AttributeDependencyAsExpected(IMember targetMember, Class expectedAttributeClass) + public static void AttributeDependencyAsExpected( + IMember targetMember, + Class expectedAttributeClass + ) { //Precondition Checks if (targetMember == null) @@ -81,14 +91,19 @@ public static void AttributeDependencyAsExpected(IMember targetMember, Class exp //Arrange, Act var expectedAttribute = new Attribute(expectedAttributeClass); - var expectedAttributeDependency = - new AttributeMemberDependency(targetMember, new AttributeInstance(expectedAttribute)); + var expectedAttributeDependency = new AttributeMemberDependency( + targetMember, + new AttributeInstance(expectedAttribute) + ); //Assert Assert.Contains(expectedAttributeDependency, targetMember.Dependencies); } - public static void AttributeDependencyAsExpected(IType targetType, Class expectedAttributeClass) + public static void AttributeDependencyAsExpected( + IType targetType, + Class expectedAttributeClass + ) { //Precondition Checks if (targetType == null) @@ -104,11 +119,13 @@ public static void AttributeDependencyAsExpected(IType targetType, Class expecte //Arrange, Act var expectedAttribute = new Attribute(expectedAttributeClass); - var expectedAttributeDependency = - new AttributeTypeDependency(targetType, new AttributeInstance(expectedAttribute)); + var expectedAttributeDependency = new AttributeTypeDependency( + targetType, + new AttributeInstance(expectedAttribute) + ); //Assert Assert.True(targetType.HasDependency(expectedAttributeDependency)); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/Dependencies/Attributes/AttributeDependencyTests.cs b/ArchUnitNETTests/Domain/Dependencies/Attributes/AttributeDependencyTests.cs index c2927ac6b..0d5874550 100644 --- a/ArchUnitNETTests/Domain/Dependencies/Attributes/AttributeDependencyTests.cs +++ b/ArchUnitNETTests/Domain/Dependencies/Attributes/AttributeDependencyTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -21,7 +21,9 @@ public class AttributeDependencyTests public AttributeDependencyTests() { var eventHandler = Architecture.GetInterfaceOfType(typeof(IEventHandler<>)); - _eventHandlerImplementClasses = Architecture.Classes.Where(cls => cls.ImplementsInterface(eventHandler)); + _eventHandlerImplementClasses = Architecture.Classes.Where(cls => + cls.ImplementsInterface(eventHandler) + ); _originClass = Architecture.GetClassOfType(typeof(ClassWithInnerAttributeDependency)); _hello = Architecture.GetClassOfType(typeof(Hello)); _helloEvent = Architecture.GetClassOfType(typeof(HelloEvent)); @@ -32,7 +34,8 @@ public AttributeDependencyTests() _classWithBodyTypeA = Architecture.GetClassOfType(typeof(ClassWithBodyTypeA)); } - private static readonly Architecture Architecture = StaticTestArchitectures.AttributeDependencyTestArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.AttributeDependencyTestArchitecture; private readonly IEnumerable _eventHandlerImplementClasses; private readonly Class _originClass; private readonly Class _hello; @@ -44,7 +47,11 @@ public AttributeDependencyTests() [Theory] [ClassData(typeof(AttributeTestsBuild.TypeAttributesAreFoundData))] - public void TypeAttributesAreFound(IType targetType, Class attributeClass, Attribute attribute) + public void TypeAttributesAreFound( + IType targetType, + Class attributeClass, + Attribute attribute + ) { TypeAttributeAsExpected(targetType, attributeClass, attribute); AttributeDependencyAsExpected(targetType, attributeClass); @@ -52,8 +59,11 @@ public void TypeAttributesAreFound(IType targetType, Class attributeClass, Attri [Theory] [ClassData(typeof(AttributeTestsBuild.MemberAttributesAreFoundData))] - public void MemberAttributesAreFound(IMember targetMember, Class attributeClass, - Attribute attribute) + public void MemberAttributesAreFound( + IMember targetMember, + Class attributeClass, + Attribute attribute + ) { MemberAttributeAsExpected(targetMember, attributeClass, attribute); AttributeDependencyAsExpected(targetMember, attributeClass); @@ -63,33 +73,50 @@ public void MemberAttributesAreFound(IMember targetMember, Class attributeClass, public void ClassAttributeInnerDependencyAssignedToOriginClass() { //Setup - var expectedClassTargets = new[] {_hello, _helloEvent}; + var expectedClassTargets = new[] { _hello, _helloEvent }; //Assert - Assert.All(expectedClassTargets, targetClass => Assert.True(_originClass.DependsOn(targetClass.FullName))); + Assert.All( + expectedClassTargets, + targetClass => Assert.True(_originClass.DependsOn(targetClass.FullName)) + ); } [Fact] public void ForbidAttributeForClass() { - Assert.All(_eventHandlerImplementClasses, cls => Assert.False(cls.DependsOn("forbidden"))); + Assert.All( + _eventHandlerImplementClasses, + cls => Assert.False(cls.DependsOn("forbidden")) + ); } [Fact] public void MemberAttributeInnerDependencyAssignedToOriginClass() { //Setup - var expectedClassTargets = new[] {_class1, _class2, _classWithAttribute, _classWithBodyTypeA}; + var expectedClassTargets = new[] + { + _class1, + _class2, + _classWithAttribute, + _classWithBodyTypeA + }; //Assert - Assert.All(expectedClassTargets, targetClass => Assert.True(_originClass.DependsOn(targetClass.FullName))); + Assert.All( + expectedClassTargets, + targetClass => Assert.True(_originClass.DependsOn(targetClass.FullName)) + ); } [Fact] public void OriginAsExpected() { - Assert.All(((IHasDependencies) _originClass).Dependencies.OfType(), - dependency => Assert.True(dependency.Origin.Equals(_originClass))); + Assert.All( + ((IHasDependencies)_originClass).Dependencies.OfType(), + dependency => Assert.True(dependency.Origin.Equals(_originClass)) + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/Dependencies/Attributes/AttributeTestsBuild.cs b/ArchUnitNETTests/Domain/Dependencies/Attributes/AttributeTestsBuild.cs index 49659b3d9..2cc1366a0 100644 --- a/ArchUnitNETTests/Domain/Dependencies/Attributes/AttributeTestsBuild.cs +++ b/ArchUnitNETTests/Domain/Dependencies/Attributes/AttributeTestsBuild.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -15,20 +15,23 @@ namespace ArchUnitNETTests.Domain.Dependencies.Attributes { public static class AttributeTestsBuild { - private static readonly Architecture Architecture = StaticTestArchitectures.AttributeDependencyTestArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.AttributeDependencyTestArchitecture; private static object[] BuildTypeAttributeTestData(Type classType, Type attributeType) { var targetClass = Architecture.GetITypeOfType(classType); - var attributeClass = - Architecture.GetClassOfType(attributeType); + var attributeClass = Architecture.GetClassOfType(attributeType); var attribute = targetClass.GetAttributeOfType(attributeClass); - return new object[] {targetClass, attributeClass, attribute}; + return new object[] { targetClass, attributeClass, attribute }; } - - private static object[] BuildMemberAttributeTestData(Type classType, string memberName, Type attributeType) + private static object[] BuildMemberAttributeTestData( + Type classType, + string memberName, + Type attributeType + ) { if (classType == null) { @@ -52,19 +55,30 @@ private static object[] BuildMemberAttributeTestData(Type classType, string memb var attribute = targetMember.GetAttributeFromMember(attributeClass); attribute.RequiredNotNull(); - return new object[] {targetMember, attributeClass, attribute}; + return new object[] { targetMember, attributeClass, attribute }; } public class TypeAttributesAreFoundData : IEnumerable { private readonly List _typeAttributeData = new List { - BuildTypeAttributeTestData(typeof(ClassWithExampleAttribute), typeof(ExampleClassAttribute)), - BuildTypeAttributeTestData(typeof(DelegateWithAttribute), typeof(ExampleDelegateAttribute)), + BuildTypeAttributeTestData( + typeof(ClassWithExampleAttribute), + typeof(ExampleClassAttribute) + ), + BuildTypeAttributeTestData( + typeof(DelegateWithAttribute), + typeof(ExampleDelegateAttribute) + ), BuildTypeAttributeTestData(typeof(EnumWithAttribute), typeof(ExampleEnumAttribute)), - BuildTypeAttributeTestData(typeof(IInterfaceWithExampleAttribute), - typeof(ExampleInterfaceAttribute)), - BuildTypeAttributeTestData(typeof(StructWithAttribute), typeof(ExampleStructAttribute)) + BuildTypeAttributeTestData( + typeof(IInterfaceWithExampleAttribute), + typeof(ExampleInterfaceAttribute) + ), + BuildTypeAttributeTestData( + typeof(StructWithAttribute), + typeof(ExampleStructAttribute) + ) }; public IEnumerator GetEnumerator() @@ -82,25 +96,44 @@ public class MemberAttributesAreFoundData : IEnumerable { private readonly List _memberAttributeData = new List { - BuildMemberAttributeTestData(typeof(ClassWithExampleAttribute), - nameof(ClassWithExampleAttribute.FieldA), typeof(ExampleFieldAttribute)), - BuildMemberAttributeTestData(typeof(ClassWithExampleAttribute), + BuildMemberAttributeTestData( + typeof(ClassWithExampleAttribute), + nameof(ClassWithExampleAttribute.FieldA), + typeof(ExampleFieldAttribute) + ), + BuildMemberAttributeTestData( + typeof(ClassWithExampleAttribute), nameof(ClassWithExampleAttribute.MethodWithAttribute).BuildMethodMemberName(), - typeof(ExampleMethodAttribute)), - BuildMemberAttributeTestData(typeof(ClassWithExampleAttribute), + typeof(ExampleMethodAttribute) + ), + BuildMemberAttributeTestData( + typeof(ClassWithExampleAttribute), nameof(ClassWithExampleAttribute.MethodWithParameterAttribute) - .BuildMethodMemberName(typeof(string)), typeof(ExampleParameterAttribute)), - BuildMemberAttributeTestData(typeof(ClassWithExampleAttribute), - nameof(ClassWithExampleAttribute.PropertyA), typeof(ExamplePropertyAttribute)), - BuildMemberAttributeTestData(typeof(ClassWithExampleAttribute), - nameof(ClassWithExampleAttribute.MethodWithReturnAttribute).BuildMethodMemberName(), - typeof(ExampleReturnAttribute)), - BuildMemberAttributeTestData(typeof(ClassWithExampleAttribute), - nameof(ClassWithExampleAttribute.set_ParameterProperty).BuildMethodMemberName(typeof(string)), - typeof(ExampleParameterAttribute)), - BuildMemberAttributeTestData(typeof(ClassWithExampleAttribute), + .BuildMethodMemberName(typeof(string)), + typeof(ExampleParameterAttribute) + ), + BuildMemberAttributeTestData( + typeof(ClassWithExampleAttribute), + nameof(ClassWithExampleAttribute.PropertyA), + typeof(ExamplePropertyAttribute) + ), + BuildMemberAttributeTestData( + typeof(ClassWithExampleAttribute), + nameof(ClassWithExampleAttribute.MethodWithReturnAttribute) + .BuildMethodMemberName(), + typeof(ExampleReturnAttribute) + ), + BuildMemberAttributeTestData( + typeof(ClassWithExampleAttribute), + nameof(ClassWithExampleAttribute.set_ParameterProperty) + .BuildMethodMemberName(typeof(string)), + typeof(ExampleParameterAttribute) + ), + BuildMemberAttributeTestData( + typeof(ClassWithExampleAttribute), nameof(ClassWithExampleAttribute.FieldWithAbstractAttributeImplemented), - typeof(ChildOfAbstractAttribute)) + typeof(ChildOfAbstractAttribute) + ) }; public IEnumerator GetEnumerator() @@ -114,4 +147,4 @@ IEnumerator IEnumerable.GetEnumerator() } } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/Dependencies/Attributes/TestAttributes.cs b/ArchUnitNETTests/Domain/Dependencies/Attributes/TestAttributes.cs index 89640b520..714ed8a45 100644 --- a/ArchUnitNETTests/Domain/Dependencies/Attributes/TestAttributes.cs +++ b/ArchUnitNETTests/Domain/Dependencies/Attributes/TestAttributes.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -25,64 +25,40 @@ namespace ArchUnitNETTests.Domain.Dependencies.Attributes { - public class TestAttributes - { - } + public class TestAttributes { } [AttributeUsage(AttributeTargets.All)] - public class ExampleAttribute : Attribute - { - } + public class ExampleAttribute : Attribute { } [AttributeUsage(AttributeTargets.Class)] - public class ExampleClassAttribute : Attribute - { - } + public class ExampleClassAttribute : Attribute { } [AttributeUsage(AttributeTargets.Interface)] - public class ExampleInterfaceAttribute : Attribute - { - } + public class ExampleInterfaceAttribute : Attribute { } [AttributeUsage(AttributeTargets.Method)] - public class ExampleMethodAttribute : Attribute - { - } + public class ExampleMethodAttribute : Attribute { } [AttributeUsage(AttributeTargets.Field)] - public class ExampleFieldAttribute : Attribute - { - } + public class ExampleFieldAttribute : Attribute { } [AttributeUsage(AttributeTargets.Property)] - public class ExamplePropertyAttribute : Attribute - { - } + public class ExamplePropertyAttribute : Attribute { } [AttributeUsage(AttributeTargets.Parameter)] - public class ExampleParameterAttribute : Attribute - { - } + public class ExampleParameterAttribute : Attribute { } [AttributeUsage(AttributeTargets.Struct)] - public class ExampleStructAttribute : Attribute - { - } + public class ExampleStructAttribute : Attribute { } [AttributeUsage(AttributeTargets.Enum)] - public class ExampleEnumAttribute : Attribute - { - } + public class ExampleEnumAttribute : Attribute { } [AttributeUsage(AttributeTargets.Delegate)] - public class ExampleDelegateAttribute : Attribute - { - } + public class ExampleDelegateAttribute : Attribute { } [AttributeUsage(AttributeTargets.ReturnValue)] - public class ExampleReturnAttribute : Attribute - { - } + public class ExampleReturnAttribute : Attribute { } public abstract class ExampleAbstractAttribute : Attribute { @@ -109,17 +85,11 @@ private ConstructorAttribute(FieldType insideField) } } - public class ForbiddenAttribute : Attribute - { - } + public class ForbiddenAttribute : Attribute { } - public class InterfaceImplementingAttribute : Attribute, IAttribute - { - } + public class InterfaceImplementingAttribute : Attribute, IAttribute { } - public interface IAttribute - { - } + public interface IAttribute { } [AttributeUsage(AttributeTargets.All)] public class CountryAttributeWithParameters : Attribute @@ -170,19 +140,13 @@ public void set_ParameterProperty([ExampleParameter] string value) _parameterProperty = value; } - private static void MethodForDelegate(FieldType fieldType) - { - } + private static void MethodForDelegate(FieldType fieldType) { } [ExampleMethod] - public void MethodWithAttribute() - { - } + public void MethodWithAttribute() { } [CountryAttributeWithParameters("Germany", 83000000, Visited = true)] - public void MethodWithCountryAttribute() - { - } + public void MethodWithCountryAttribute() { } public void MethodWithParameterAttribute([ExampleParameter] string example) { @@ -235,16 +199,12 @@ public class ClassWithInnerAttributeDependency [TypeDependent(typeof(Class1))] [TypeDependent(typeof(Class2))] - public void Method() - { - } + public void Method() { } } [TypeDependent(typeof(Hello))] [TypeDependent(typeof(HelloEvent))] - public class AttributeWithAttributes : Attribute - { - } + public class AttributeWithAttributes : Attribute { } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class TypeDependentAttribute : Attribute @@ -259,10 +219,8 @@ public TypeDependentAttribute(Type type) public class Hello : IEventHandler { -// [Forbidden] - public void Handle(HelloEvent helloEvent) - { - } + // [Forbidden] + public void Handle(HelloEvent helloEvent) { } public static int StaticMethod() { @@ -270,15 +228,9 @@ public static int StaticMethod() } } - public class HelloEvent : IPersistentEvent - { - } + public class HelloEvent : IPersistentEvent { } - public interface IEventHandler - { - } + public interface IEventHandler { } - public interface IPersistentEvent - { - } -} \ No newline at end of file + public interface IPersistentEvent { } +} diff --git a/ArchUnitNETTests/Domain/Dependencies/Members/BodyTypeMemberDependencyTests.cs b/ArchUnitNETTests/Domain/Dependencies/Members/BodyTypeMemberDependencyTests.cs index 8af0181e5..8c1aae7c5 100644 --- a/ArchUnitNETTests/Domain/Dependencies/Members/BodyTypeMemberDependencyTests.cs +++ b/ArchUnitNETTests/Domain/Dependencies/Members/BodyTypeMemberDependencyTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Linq; @@ -17,12 +17,15 @@ public class BodyTypeMemberDependencyTests public BodyTypeMemberDependencyTests() { var classWithBodyTypeA = _architecture.GetClassOfType(typeof(ClassWithBodyTypeA)); - _methodWithTypeA = classWithBodyTypeA - .Members[nameof(ClassWithBodyTypeA.MethodWithTypeA).BuildMethodMemberName()] as MethodMember; + _methodWithTypeA = + classWithBodyTypeA.Members[ + nameof(ClassWithBodyTypeA.MethodWithTypeA).BuildMethodMemberName() + ] as MethodMember; _typeA = _architecture.GetClassOfType(typeof(TypeA)); } - private readonly Architecture _architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private readonly Architecture _architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; private readonly MethodMember _methodWithTypeA; private readonly Class _typeA; @@ -30,12 +33,14 @@ public BodyTypeMemberDependencyTests() [Fact] public void BodyTypeDependenciesFound() { - var bodyTypeDependencies = - _methodWithTypeA.GetBodyTypeMemberDependencies().ToList(); + var bodyTypeDependencies = _methodWithTypeA.GetBodyTypeMemberDependencies().ToList(); Assert.Equal("AABC", ClassWithBodyTypeA.MethodWithTypeA()); Assert.True(bodyTypeDependencies.Count >= 3); - Assert.Contains(_typeA, bodyTypeDependencies.Select(dependency => (Class) dependency.Target)); + Assert.Contains( + _typeA, + bodyTypeDependencies.Select(dependency => (Class)dependency.Target) + ); } } @@ -79,4 +84,4 @@ public override string ToString() return "C"; } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/Dependencies/Members/ClassDependenciesIncludeMemberDependencies.cs b/ArchUnitNETTests/Domain/Dependencies/Members/ClassDependenciesIncludeMemberDependencies.cs index 0987c7c55..0b34f90ad 100644 --- a/ArchUnitNETTests/Domain/Dependencies/Members/ClassDependenciesIncludeMemberDependencies.cs +++ b/ArchUnitNETTests/Domain/Dependencies/Members/ClassDependenciesIncludeMemberDependencies.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -16,24 +16,27 @@ namespace ArchUnitNETTests.Domain.Dependencies.Members public class ClassDependenciesIncludeMemberDependencies { [Theory] - [ClassData(typeof(ClassDependenciesIncludeMemberDependenciesBuild.MethodDependenciesWithClassTestData))] + [ClassData( + typeof(ClassDependenciesIncludeMemberDependenciesBuild.MethodDependenciesWithClassTestData) + )] public void DependenciesOfMembersAreDependenciesOfDeclaringType(Class clazz) { var methodMembers = clazz.GetMethodMembers(); methodMembers.ForEach(methodMember => - Assert.True(clazz.HasDependencies(methodMember.MemberDependencies))); + Assert.True(clazz.HasDependencies(methodMember.MemberDependencies)) + ); } } - public static class ClassDependenciesIncludeMemberDependenciesBuild { - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; internal static object[] BuildClassTestData(Type originType) { var originClass = Architecture.GetClassOfType(originType); - return new object[] {originClass}; + return new object[] { originClass }; } public class MethodDependenciesWithClassTestData : IEnumerable @@ -59,4 +62,4 @@ IEnumerator IEnumerable.GetEnumerator() } } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/Dependencies/Members/FieldDependencyTests.cs b/ArchUnitNETTests/Domain/Dependencies/Members/FieldDependencyTests.cs index 387cca22b..891985756 100644 --- a/ArchUnitNETTests/Domain/Dependencies/Members/FieldDependencyTests.cs +++ b/ArchUnitNETTests/Domain/Dependencies/Members/FieldDependencyTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Linq; @@ -19,9 +19,13 @@ public FieldDependencyTests() { var architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; _classWithFieldA = architecture.GetClassOfType(typeof(ClassWithFieldA)); - _fieldAMember = _classWithFieldA.GetFieldMembersWithName(nameof(ClassWithFieldA.FieldA)).SingleOrDefault(); + _fieldAMember = _classWithFieldA + .GetFieldMembersWithName(nameof(ClassWithFieldA.FieldA)) + .SingleOrDefault(); _fieldType = architecture.GetClassOfType(typeof(FieldType)); - _privateFieldAMember = _classWithFieldA.GetFieldMembersWithName("_privateFieldA").SingleOrDefault(); + _privateFieldAMember = _classWithFieldA + .GetFieldMembersWithName("_privateFieldA") + .SingleOrDefault(); } private readonly Class _classWithFieldA; @@ -47,8 +51,11 @@ public void FieldDependenciesAddedToClassDependencies() var fieldMembers = _classWithFieldA.GetFieldMembers(); //Assert - Assert.All(fieldMembers, fieldMember => - Assert.True(_classWithFieldA.HasDependencies(fieldMember.MemberDependencies))); + Assert.All( + fieldMembers, + fieldMember => + Assert.True(_classWithFieldA.HasDependencies(fieldMember.MemberDependencies)) + ); } [Fact] @@ -73,7 +80,5 @@ public class ClassWithFieldA public FieldType FieldA; } - public class FieldType - { - } -} \ No newline at end of file + public class FieldType { } +} diff --git a/ArchUnitNETTests/Domain/Dependencies/Members/GetterSetterExamples.cs b/ArchUnitNETTests/Domain/Dependencies/Members/GetterSetterExamples.cs index 51d86ffae..98a15dc36 100644 --- a/ArchUnitNETTests/Domain/Dependencies/Members/GetterSetterExamples.cs +++ b/ArchUnitNETTests/Domain/Dependencies/Members/GetterSetterExamples.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -18,18 +18,12 @@ public class GetterMethodDependencyExamples { public Guid AcceptedCase { - get - { - return new Guid("35353"); - } + get { return new Guid("35353"); } } public Guid FirstUnacceptedCase { - get - { - return Guid.NewGuid(); - } + get { return Guid.NewGuid(); } } public Guid SecondUnacceptedCase => Guid.NewGuid(); @@ -46,14 +40,8 @@ public class SetterMethodDependencyExamples public ChildField CustomProperty { - set - { - _customPropertyBacking = value; - } - get - { - return _customPropertyBacking; - } + set { _customPropertyBacking = value; } + get { return _customPropertyBacking; } } public ChildField LambdaPair @@ -63,7 +51,7 @@ public ChildField LambdaPair public PropertyType ConstructorPair { - set {_constructorPairBacking = new PropertyType(value);} + set { _constructorPairBacking = new PropertyType(value); } } public PropertyType ConstructorLambdaPair @@ -89,4 +77,4 @@ public static PropertyType NewPropertyType(object thing) return new PropertyType(thing); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/Dependencies/Members/GetterSetterMethodDependencyTests.cs b/ArchUnitNETTests/Domain/Dependencies/Members/GetterSetterMethodDependencyTests.cs index 46efc24ae..45e269484 100644 --- a/ArchUnitNETTests/Domain/Dependencies/Members/GetterSetterMethodDependencyTests.cs +++ b/ArchUnitNETTests/Domain/Dependencies/Members/GetterSetterMethodDependencyTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Linq; @@ -18,17 +18,23 @@ namespace ArchUnitNETTests.Domain.Dependencies.Members { public class GetterSetterMethodDependencyTests { - private readonly Architecture _architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private readonly Architecture _architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; public GetterSetterMethodDependencyTests() { - var getterExampleClass = _architecture.GetClassOfType(typeof(GetterMethodDependencyExamples)); + var getterExampleClass = _architecture.GetClassOfType( + typeof(GetterMethodDependencyExamples) + ); getterExampleClass.RequiredNotNull(); } [Theory] [ClassData(typeof(GetterSetterTestsBuild.SetterTestData))] - public void AssertSetterMethodDependencies(PropertyMember backedProperty, Class expectedTarget) + public void AssertSetterMethodDependencies( + PropertyMember backedProperty, + Class expectedTarget + ) { if (backedProperty.Setter != null) { @@ -42,21 +48,32 @@ public void AssertSetterMethodDependencies(PropertyMember backedProperty, Class [Theory] [ClassData(typeof(GetterSetterTestsBuild.GetterTestData))] - public void AssertGetterMethodDependencies(PropertyMember propertyMember, IType mockTargetType, - MethodCallDependency expectedDependency) + public void AssertGetterMethodDependencies( + PropertyMember propertyMember, + IType mockTargetType, + MethodCallDependency expectedDependency + ) { Assert.NotEmpty(propertyMember.MemberDependencies); Assert.Single(propertyMember.GetMethodCallDependencies()); - Assert.Contains(mockTargetType, - propertyMember.GetMethodCallDependencies().Select(dependency => dependency.Target)); - Assert.Contains(expectedDependency.TargetMember.FullName, - propertyMember.GetMethodCallDependencies() - .Select(dependency => dependency.TargetMember.FullName)); + Assert.Contains( + mockTargetType, + propertyMember.GetMethodCallDependencies().Select(dependency => dependency.Target) + ); + Assert.Contains( + expectedDependency.TargetMember.FullName, + propertyMember + .GetMethodCallDependencies() + .Select(dependency => dependency.TargetMember.FullName) + ); } [Theory] [ClassData(typeof(GetterSetterTestsBuild.AccessMethodDependenciesByPropertyTestData))] - public void AccessorMethodDependenciesByProperty(PropertyMember accessedProperty, MethodMember accessorMethod) + public void AccessorMethodDependenciesByProperty( + PropertyMember accessedProperty, + MethodMember accessorMethod + ) { accessorMethod.MemberDependencies.ForEach(dependency => { @@ -64,4 +81,4 @@ public void AccessorMethodDependenciesByProperty(PropertyMember accessedProperty }); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/Dependencies/Members/GetterSetterTestsBuild.cs b/ArchUnitNETTests/Domain/Dependencies/Members/GetterSetterTestsBuild.cs index 7841cef29..9b94503cc 100644 --- a/ArchUnitNETTests/Domain/Dependencies/Members/GetterSetterTestsBuild.cs +++ b/ArchUnitNETTests/Domain/Dependencies/Members/GetterSetterTestsBuild.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -20,20 +20,29 @@ namespace ArchUnitNETTests.Domain.Dependencies.Members { public class GetterSetterTestsBuild { - private static readonly Architecture Architecture = - new ArchLoader().LoadAssemblies(System.Reflection.Assembly.Load("ArchUnitNETTests")).Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssemblies(System.Reflection.Assembly.Load("ArchUnitNETTests")) + .Build(); private static readonly Type GuidType = typeof(Guid); private static readonly IType MockGuidStruct = GuidType.CreateStubIType(); - private static readonly MethodInfo NewGuid = GuidType.GetMethods().First(method => method.Name == "NewGuid"); + private static readonly MethodInfo NewGuid = GuidType + .GetMethods() + .First(method => method.Name == "NewGuid"); private static readonly MethodMember MockNewGuid = NewGuid.CreateStubMethodMember(); - private static readonly Type[] ExpectedParameters = {typeof(string)}; - private static readonly ConstructorInfo ConstructGuid = GuidType.GetConstructor(ExpectedParameters); - private static readonly MethodMember MockConstructorMember = ConstructGuid.CreateStubMethodMember(); + private static readonly Type[] ExpectedParameters = { typeof(string) }; + private static readonly ConstructorInfo ConstructGuid = GuidType.GetConstructor( + ExpectedParameters + ); + private static readonly MethodMember MockConstructorMember = + ConstructGuid.CreateStubMethodMember(); - private static object[] BuildSetterTestData(Type classType, string backedPropertyName, - Type expectedFieldDependencyTarget) + private static object[] BuildSetterTestData( + Type classType, + string backedPropertyName, + Type expectedFieldDependencyTarget + ) { if (classType == null) { @@ -52,13 +61,19 @@ private static object[] BuildSetterTestData(Type classType, string backedPropert var baseClass = Architecture.GetClassOfType(classType); var backedProperty = baseClass.GetPropertyMembersWithName(backedPropertyName).First(); - var expectedDependencyTargetClass = Architecture.GetClassOfType(expectedFieldDependencyTarget); + var expectedDependencyTargetClass = Architecture.GetClassOfType( + expectedFieldDependencyTarget + ); - return new object[] {backedProperty, expectedDependencyTargetClass}; + return new object[] { backedProperty, expectedDependencyTargetClass }; } - private static object[] BuildGetterTestData(Type classType, string propertyName, - IType expectedFieldDependencyTarget, MethodMember expectedTargetMember) + private static object[] BuildGetterTestData( + Type classType, + string propertyName, + IType expectedFieldDependencyTarget, + MethodMember expectedTargetMember + ) { if (classType == null) { @@ -77,11 +92,23 @@ private static object[] BuildGetterTestData(Type classType, string propertyName, var baseClass = Architecture.GetClassOfType(classType); var accessedProperty = baseClass.GetPropertyMembersWithName(propertyName).First(); - var expectedDependency = CreateStubMethodCallDependency(accessedProperty, expectedTargetMember); - return new object[] {accessedProperty, expectedFieldDependencyTarget, expectedDependency}; + var expectedDependency = CreateStubMethodCallDependency( + accessedProperty, + expectedTargetMember + ); + return new object[] + { + accessedProperty, + expectedFieldDependencyTarget, + expectedDependency + }; } - private static object[] BuildAccessMethodTestData(Type classType, string propertyName, MethodForm methodForm) + private static object[] BuildAccessMethodTestData( + Type classType, + string propertyName, + MethodForm methodForm + ) { if (classType == null) { @@ -96,21 +123,30 @@ private static object[] BuildAccessMethodTestData(Type classType, string propert if (methodForm != MethodForm.Getter && methodForm != MethodForm.Setter) { throw new InvalidInputException( - $"Given MethodForm {nameof(methodForm)} is not valid for this test. Please give the form of Getter or Setter."); + $"Given MethodForm {nameof(methodForm)} is not valid for this test. Please give the form of Getter or Setter." + ); } var baseClass = Architecture.GetClassOfType(classType); var accessedProperty = baseClass.GetPropertyMembersWithName(propertyName).First(); - var accessorMethod = methodForm == MethodForm.Getter ? accessedProperty.Getter : accessedProperty.Setter; - return new object[] {accessedProperty, accessorMethod}; + var accessorMethod = + methodForm == MethodForm.Getter ? accessedProperty.Getter : accessedProperty.Setter; + return new object[] { accessedProperty, accessorMethod }; } - private static MethodCallDependency CreateStubMethodCallDependency(IMember originMember, - MethodMember targetMember) + private static MethodCallDependency CreateStubMethodCallDependency( + IMember originMember, + MethodMember targetMember + ) { - var methodCallDependency = new MethodCallDependency(originMember, - new MethodMemberInstance(targetMember, Enumerable.Empty(), - Enumerable.Empty())); + var methodCallDependency = new MethodCallDependency( + originMember, + new MethodMemberInstance( + targetMember, + Enumerable.Empty(), + Enumerable.Empty() + ) + ); methodCallDependency.TargetMember.MemberBackwardsDependencies.Add(methodCallDependency); return methodCallDependency; } @@ -119,24 +155,36 @@ public class SetterTestData : IEnumerable { private readonly List _setterTestData = new List { - BuildSetterTestData(typeof(SetterMethodDependencyExamples), + BuildSetterTestData( + typeof(SetterMethodDependencyExamples), nameof(SetterMethodDependencyExamples.CustomProperty), - typeof(ChildField)), - BuildSetterTestData(typeof(SetterMethodDependencyExamples), + typeof(ChildField) + ), + BuildSetterTestData( + typeof(SetterMethodDependencyExamples), nameof(SetterMethodDependencyExamples.LambdaPair), - typeof(ChildField)), - BuildSetterTestData(typeof(SetterMethodDependencyExamples), + typeof(ChildField) + ), + BuildSetterTestData( + typeof(SetterMethodDependencyExamples), nameof(SetterMethodDependencyExamples.ConstructorPair), - typeof(PropertyType)), - BuildSetterTestData(typeof(SetterMethodDependencyExamples), + typeof(PropertyType) + ), + BuildSetterTestData( + typeof(SetterMethodDependencyExamples), nameof(SetterMethodDependencyExamples.ConstructorLambdaPair), - typeof(PropertyType)), - BuildSetterTestData(typeof(SetterMethodDependencyExamples), + typeof(PropertyType) + ), + BuildSetterTestData( + typeof(SetterMethodDependencyExamples), nameof(SetterMethodDependencyExamples.MethodPair), - typeof(PropertyType)), - BuildSetterTestData(typeof(SetterMethodDependencyExamples), + typeof(PropertyType) + ), + BuildSetterTestData( + typeof(SetterMethodDependencyExamples), nameof(SetterMethodDependencyExamples.MethodLambdaPair), - typeof(PropertyType)) + typeof(PropertyType) + ) }; public IEnumerator GetEnumerator() @@ -154,15 +202,24 @@ public class GetterTestData : IEnumerable { private readonly List _getterTestData = new List { - BuildGetterTestData(typeof(GetterMethodDependencyExamples), + BuildGetterTestData( + typeof(GetterMethodDependencyExamples), nameof(GetterMethodDependencyExamples.AcceptedCase), - MockGuidStruct, MockConstructorMember), - BuildGetterTestData(typeof(GetterMethodDependencyExamples), + MockGuidStruct, + MockConstructorMember + ), + BuildGetterTestData( + typeof(GetterMethodDependencyExamples), nameof(GetterMethodDependencyExamples.FirstUnacceptedCase), - MockGuidStruct, MockNewGuid), - BuildGetterTestData(typeof(GetterMethodDependencyExamples), + MockGuidStruct, + MockNewGuid + ), + BuildGetterTestData( + typeof(GetterMethodDependencyExamples), nameof(GetterMethodDependencyExamples.SecondUnacceptedCase), - MockGuidStruct, MockNewGuid) + MockGuidStruct, + MockNewGuid + ) }; public IEnumerator GetEnumerator() @@ -180,33 +237,51 @@ public class AccessMethodDependenciesByPropertyTestData : IEnumerable { private readonly List _accessMethodTestData = new List { - BuildAccessMethodTestData(typeof(SetterMethodDependencyExamples), + BuildAccessMethodTestData( + typeof(SetterMethodDependencyExamples), nameof(SetterMethodDependencyExamples.CustomProperty), - MethodForm.Setter), - BuildAccessMethodTestData(typeof(SetterMethodDependencyExamples), + MethodForm.Setter + ), + BuildAccessMethodTestData( + typeof(SetterMethodDependencyExamples), nameof(SetterMethodDependencyExamples.LambdaPair), - MethodForm.Setter), - BuildAccessMethodTestData(typeof(SetterMethodDependencyExamples), + MethodForm.Setter + ), + BuildAccessMethodTestData( + typeof(SetterMethodDependencyExamples), nameof(SetterMethodDependencyExamples.ConstructorPair), - MethodForm.Setter), - BuildAccessMethodTestData(typeof(SetterMethodDependencyExamples), + MethodForm.Setter + ), + BuildAccessMethodTestData( + typeof(SetterMethodDependencyExamples), nameof(SetterMethodDependencyExamples.ConstructorLambdaPair), - MethodForm.Setter), - BuildAccessMethodTestData(typeof(SetterMethodDependencyExamples), + MethodForm.Setter + ), + BuildAccessMethodTestData( + typeof(SetterMethodDependencyExamples), nameof(SetterMethodDependencyExamples.MethodPair), - MethodForm.Setter), - BuildAccessMethodTestData(typeof(SetterMethodDependencyExamples), + MethodForm.Setter + ), + BuildAccessMethodTestData( + typeof(SetterMethodDependencyExamples), nameof(SetterMethodDependencyExamples.MethodLambdaPair), - MethodForm.Setter), - BuildAccessMethodTestData(typeof(GetterMethodDependencyExamples), + MethodForm.Setter + ), + BuildAccessMethodTestData( + typeof(GetterMethodDependencyExamples), nameof(GetterMethodDependencyExamples.AcceptedCase), - MethodForm.Getter), - BuildAccessMethodTestData(typeof(GetterMethodDependencyExamples), + MethodForm.Getter + ), + BuildAccessMethodTestData( + typeof(GetterMethodDependencyExamples), nameof(GetterMethodDependencyExamples.FirstUnacceptedCase), - MethodForm.Getter), - BuildAccessMethodTestData(typeof(GetterMethodDependencyExamples), + MethodForm.Getter + ), + BuildAccessMethodTestData( + typeof(GetterMethodDependencyExamples), nameof(GetterMethodDependencyExamples.SecondUnacceptedCase), - MethodForm.Getter) + MethodForm.Getter + ) }; public IEnumerator GetEnumerator() @@ -220,4 +295,4 @@ IEnumerator IEnumerable.GetEnumerator() } } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/Dependencies/Members/InheritsBaseClassDependencyTests.cs b/ArchUnitNETTests/Domain/Dependencies/Members/InheritsBaseClassDependencyTests.cs index f4642d0fe..07911453d 100644 --- a/ArchUnitNETTests/Domain/Dependencies/Members/InheritsBaseClassDependencyTests.cs +++ b/ArchUnitNETTests/Domain/Dependencies/Members/InheritsBaseClassDependencyTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -14,7 +14,8 @@ namespace ArchUnitNETTests.Domain.Dependencies.Members { public class BaseClassTest { - private readonly Architecture _architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private readonly Architecture _architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; private readonly Class _baseClass; private readonly Class _childClass; @@ -43,8 +44,10 @@ public void ChildClassHasBaseClass() [Fact] public void ChildClassHasBaseClassDependency() { - var expectedDependency = - new InheritsBaseClassDependency(_childClass, new TypeInstance(_baseClass)); + var expectedDependency = new InheritsBaseClassDependency( + _childClass, + new TypeInstance(_baseClass) + ); Assert.True(_childClass.HasDependency(expectedDependency)); } @@ -52,8 +55,10 @@ public void ChildClassHasBaseClassDependency() [Fact] public void OriginAsExpected() { - Assert.All(_childClass.GetInheritsBaseClassDependencies(), - dependency => Assert.Equal(_childClass, dependency.Origin)); + Assert.All( + _childClass.GetInheritsBaseClassDependencies(), + dependency => Assert.Equal(_childClass, dependency.Origin) + ); } } @@ -68,11 +73,8 @@ public class ChildClass : BaseClass } // ReSharper disable once UnusedTypeParameter - public abstract class GenericBaseClass where TSelf : class - { - } + public abstract class GenericBaseClass + where TSelf : class { } - public class ChildClassOfGeneric : GenericBaseClass - { - } -} \ No newline at end of file + public class ChildClassOfGeneric : GenericBaseClass { } +} diff --git a/ArchUnitNETTests/Domain/Dependencies/Members/InvalidInputException.cs b/ArchUnitNETTests/Domain/Dependencies/Members/InvalidInputException.cs index 2c080cc9d..9306343f5 100644 --- a/ArchUnitNETTests/Domain/Dependencies/Members/InvalidInputException.cs +++ b/ArchUnitNETTests/Domain/Dependencies/Members/InvalidInputException.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -10,12 +10,10 @@ namespace ArchUnitNETTests.Domain.Dependencies.Members { public class InvalidInputException : Exception { - public InvalidInputException(string message) : base(message) - { - } + public InvalidInputException(string message) + : base(message) { } - public InvalidInputException(string message, Exception innerException) : base(message, innerException) - { - } + public InvalidInputException(string message, Exception innerException) + : base(message, innerException) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/Dependencies/Members/KeepDependenciesInAnonymousTypesTests.cs b/ArchUnitNETTests/Domain/Dependencies/Members/KeepDependenciesInAnonymousTypesTests.cs index 4d2588574..1326e7469 100644 --- a/ArchUnitNETTests/Domain/Dependencies/Members/KeepDependenciesInAnonymousTypesTests.cs +++ b/ArchUnitNETTests/Domain/Dependencies/Members/KeepDependenciesInAnonymousTypesTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Linq; using ArchUnitNET.Domain; @@ -16,15 +16,15 @@ namespace ArchUnitNETTests.Domain.Dependencies.Members { public class KeepDependenciesInAnonymousTypesTests { - private static readonly Architecture Architecture = - new ArchLoader().LoadAssembly(typeof(KeepDependenciesInCompilerGeneratedTypesTests).Assembly).Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssembly(typeof(KeepDependenciesInCompilerGeneratedTypesTests).Assembly) + .Build(); private readonly Class _castType; private readonly Class _class1WithAnonymous; private readonly Class _class2WithAnonymous; private readonly Class _instantiatedType; - public KeepDependenciesInAnonymousTypesTests() { _class1WithAnonymous = Architecture.GetClassOfType(typeof(Class1WithAnonymousType)); @@ -62,10 +62,12 @@ public void CastDependenciesInAnonymousTypesNotLost() [Fact] public void BackwardDependenciesAssignedCorrectly() { - var instantiatedTypeBackwardDependencies = - _instantiatedType.BackwardsDependencies.Select(dep => dep.Origin).ToList(); - var castTypeBackwardDependencies = - _castType.BackwardsDependencies.Select(dep => dep.Origin).ToList(); + var instantiatedTypeBackwardDependencies = _instantiatedType + .BackwardsDependencies.Select(dep => dep.Origin) + .ToList(); + var castTypeBackwardDependencies = _castType + .BackwardsDependencies.Select(dep => dep.Origin) + .ToList(); Assert.Contains(_class1WithAnonymous, instantiatedTypeBackwardDependencies); Assert.Contains(_class2WithAnonymous, instantiatedTypeBackwardDependencies); @@ -78,7 +80,7 @@ internal class Class1WithAnonymousType { public Class1WithAnonymousType() { - var anonymousType = new {referencedType = new InstantiatedType()}; + var anonymousType = new { referencedType = new InstantiatedType() }; } } @@ -86,15 +88,11 @@ internal class Class2WithAnonymousType { public Class2WithAnonymousType() { - var anonymousType = new {castType = (CastType) new InstantiatedType(), i = 3}; + var anonymousType = new { castType = (CastType)new InstantiatedType(), i = 3 }; } } - internal class InstantiatedType - { - } + internal class InstantiatedType { } - internal class CastType : InstantiatedType - { - } -} \ No newline at end of file + internal class CastType : InstantiatedType { } +} diff --git a/ArchUnitNETTests/Domain/Dependencies/Members/MemberDependencyTestBuild.cs b/ArchUnitNETTests/Domain/Dependencies/Members/MemberDependencyTestBuild.cs index a6cbf637e..9bef205f2 100644 --- a/ArchUnitNETTests/Domain/Dependencies/Members/MemberDependencyTestBuild.cs +++ b/ArchUnitNETTests/Domain/Dependencies/Members/MemberDependencyTestBuild.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections; @@ -18,40 +18,61 @@ namespace ArchUnitNETTests.Domain.Dependencies.Members { public static class MemberDependencyTestBuild { - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; - private static object[] BuildBodyTypeMemberDependencyTestData(Type originType, string originMemberName, - Type targetType) + private static object[] BuildBodyTypeMemberDependencyTestData( + Type originType, + string originMemberName, + Type targetType + ) { - var classMemberInfo = - BuildMemberDependencyTestData(originType, originMemberName, targetType); + var classMemberInfo = BuildMemberDependencyTestData( + originType, + originMemberName, + targetType + ); if (!(classMemberInfo.OriginMember is MethodMember originMember)) { - return new object[] {null, null, null, null}; + return new object[] { null, null, null, null }; } - var memberTypeDependency = - new BodyTypeMemberDependency(originMember, new TypeInstance(classMemberInfo.TargetClass)); - object duplicateMemberTypeDependency = - new BodyTypeMemberDependency(originMember, new TypeInstance(classMemberInfo.TargetClass)); + var memberTypeDependency = new BodyTypeMemberDependency( + originMember, + new TypeInstance(classMemberInfo.TargetClass) + ); + object duplicateMemberTypeDependency = new BodyTypeMemberDependency( + originMember, + new TypeInstance(classMemberInfo.TargetClass) + ); var dependencyReferenceDuplicate = memberTypeDependency; object objectReferenceDuplicate = memberTypeDependency; return new[] { - memberTypeDependency, duplicateMemberTypeDependency, dependencyReferenceDuplicate, + memberTypeDependency, + duplicateMemberTypeDependency, + dependencyReferenceDuplicate, objectReferenceDuplicate }; } - private static object[] BuildFieldDependencyTestData(Type originType, string originMemberName, Type targetType) + private static object[] BuildFieldDependencyTestData( + Type originType, + string originMemberName, + Type targetType + ) { - var classMemberInfo = BuildMemberDependencyTestData(originType, originMemberName, targetType); + var classMemberInfo = BuildMemberDependencyTestData( + originType, + originMemberName, + targetType + ); if (!(classMemberInfo.OriginMember is FieldMember originMember)) { - return new object[] {null, null, null, null}; + return new object[] { null, null, null, null }; } var memberTypeDependency = new FieldTypeDependency(originMember); @@ -61,68 +82,110 @@ private static object[] BuildFieldDependencyTestData(Type originType, string ori return new[] { - memberTypeDependency, duplicateMemberTypeDependency, dependencyReferenceDuplicate, + memberTypeDependency, + duplicateMemberTypeDependency, + dependencyReferenceDuplicate, objectReferenceDuplicate }; } - private static object[] BuildMethodCallDependencyTestData(Type originType, string originMemberName, - Type targetType, string targetMemberName) + private static object[] BuildMethodCallDependencyTestData( + Type originType, + string originMemberName, + Type targetType, + string targetMemberName + ) { - var classMemberInfo = BuildMemberDependencyTestData(originType, originMemberName, targetType, - targetMemberName); + var classMemberInfo = BuildMemberDependencyTestData( + originType, + originMemberName, + targetType, + targetMemberName + ); if (!(classMemberInfo.TargetMember is MethodMember targetMember)) { - return new object[] {null, null, null, null}; + return new object[] { null, null, null, null }; } - var memberTypeDependency = new MethodCallDependency(classMemberInfo.OriginMember, - new MethodMemberInstance(targetMember, Enumerable.Empty(), - Enumerable.Empty())); - object duplicateMemberTypeDependency = new MethodCallDependency(classMemberInfo.OriginMember, - new MethodMemberInstance(targetMember, Enumerable.Empty(), - Enumerable.Empty())); + var memberTypeDependency = new MethodCallDependency( + classMemberInfo.OriginMember, + new MethodMemberInstance( + targetMember, + Enumerable.Empty(), + Enumerable.Empty() + ) + ); + object duplicateMemberTypeDependency = new MethodCallDependency( + classMemberInfo.OriginMember, + new MethodMemberInstance( + targetMember, + Enumerable.Empty(), + Enumerable.Empty() + ) + ); var dependencyReferenceDuplicate = memberTypeDependency; object objectReferenceDuplicate = memberTypeDependency; return new[] { - memberTypeDependency, duplicateMemberTypeDependency, dependencyReferenceDuplicate, + memberTypeDependency, + duplicateMemberTypeDependency, + dependencyReferenceDuplicate, objectReferenceDuplicate }; } - private static object[] BuildMethodSignatureDependencyTestData(Type originType, string originMemberName, - Type targetType) + private static object[] BuildMethodSignatureDependencyTestData( + Type originType, + string originMemberName, + Type targetType + ) { - var classMemberInfo = BuildMemberDependencyTestData(originType, originMemberName, targetType); + var classMemberInfo = BuildMemberDependencyTestData( + originType, + originMemberName, + targetType + ); if (!(classMemberInfo.OriginMember is MethodMember originMember)) { - return new object[] {null, null, null, null}; + return new object[] { null, null, null, null }; } - var memberTypeDependency = - new MethodSignatureDependency(originMember, new TypeInstance(classMemberInfo.TargetClass)); - object duplicateMemberTypeDependency = - new MethodSignatureDependency(originMember, new TypeInstance(classMemberInfo.TargetClass)); + var memberTypeDependency = new MethodSignatureDependency( + originMember, + new TypeInstance(classMemberInfo.TargetClass) + ); + object duplicateMemberTypeDependency = new MethodSignatureDependency( + originMember, + new TypeInstance(classMemberInfo.TargetClass) + ); var dependencyReferenceDuplicate = memberTypeDependency; object objectReferenceDuplicate = memberTypeDependency; return new[] { - memberTypeDependency, duplicateMemberTypeDependency, dependencyReferenceDuplicate, + memberTypeDependency, + duplicateMemberTypeDependency, + dependencyReferenceDuplicate, objectReferenceDuplicate }; } - private static object[] BuildPropertyDependencyTestData(Type originType, string originMemberName, - Type targetType) + private static object[] BuildPropertyDependencyTestData( + Type originType, + string originMemberName, + Type targetType + ) { - var classMemberInfo = BuildMemberDependencyTestData(originType, originMemberName, targetType); + var classMemberInfo = BuildMemberDependencyTestData( + originType, + originMemberName, + targetType + ); if (!(classMemberInfo.OriginMember is PropertyMember originMember)) { - return new object[] {null, null, null, null}; + return new object[] { null, null, null, null }; } var memberTypeDependency = new PropertyTypeDependency(originMember); @@ -132,13 +195,19 @@ private static object[] BuildPropertyDependencyTestData(Type originType, string return new[] { - memberTypeDependency, duplicateMemberTypeDependency, dependencyReferenceDuplicate, + memberTypeDependency, + duplicateMemberTypeDependency, + dependencyReferenceDuplicate, objectReferenceDuplicate }; } - private static ClassMemberInfo BuildMemberDependencyTestData(Type originType, string originMemberName, - Type targetType, string targetMemberName = null) + private static ClassMemberInfo BuildMemberDependencyTestData( + Type originType, + string originMemberName, + Type targetType, + string targetMemberName = null + ) { var originClass = Architecture.GetClassOfType(originType); var originMember = originClass.GetMembersWithName(originMemberName).SingleOrDefault(); @@ -152,18 +221,32 @@ public class MemberDependencyModelingTestData : IEnumerable { private readonly List _memberDependencyModelingData = new List { - BuildPropertyDependencyTestData(typeof(ClassWithPropertyA), nameof(ClassWithPropertyA.PropertyA), - typeof(PropertyType)), - BuildBodyTypeMemberDependencyTestData(typeof(ClassWithBodyTypeA), - nameof(ClassWithBodyTypeA.MethodWithTypeA).BuildMethodMemberName(), typeof(TypeA)), - BuildFieldDependencyTestData(typeof(ClassWithFieldA), nameof(ClassWithFieldA.FieldA), - typeof(FieldType)), - BuildMethodCallDependencyTestData(typeof(ClassWithMethodA), - nameof(ClassWithMethodA.MethodA).BuildMethodMemberName(), typeof(ClassWithMethodB), - nameof(ClassWithMethodB.MethodB).BuildMethodMemberName()), - BuildMethodSignatureDependencyTestData(typeof(ClassWithMethodSignatureA), + BuildPropertyDependencyTestData( + typeof(ClassWithPropertyA), + nameof(ClassWithPropertyA.PropertyA), + typeof(PropertyType) + ), + BuildBodyTypeMemberDependencyTestData( + typeof(ClassWithBodyTypeA), + nameof(ClassWithBodyTypeA.MethodWithTypeA).BuildMethodMemberName(), + typeof(TypeA) + ), + BuildFieldDependencyTestData( + typeof(ClassWithFieldA), + nameof(ClassWithFieldA.FieldA), + typeof(FieldType) + ), + BuildMethodCallDependencyTestData( + typeof(ClassWithMethodA), + nameof(ClassWithMethodA.MethodA).BuildMethodMemberName(), + typeof(ClassWithMethodB), + nameof(ClassWithMethodB.MethodB).BuildMethodMemberName() + ), + BuildMethodSignatureDependencyTestData( + typeof(ClassWithMethodSignatureA), nameof(ClassWithMethodSignatureA.MethodA).BuildMethodMemberName(), - typeof(ClassWithMethodSignatureB)) + typeof(ClassWithMethodSignatureB) + ) }; public IEnumerator GetEnumerator() @@ -180,7 +263,12 @@ IEnumerator IEnumerable.GetEnumerator() public class ClassMemberInfo { - public ClassMemberInfo(Class originClass, IMember originMember, Class targetClass, IMember targetMember) + public ClassMemberInfo( + Class originClass, + IMember originMember, + Class targetClass, + IMember targetMember + ) { OriginClass = originClass; OriginMember = originMember; @@ -193,4 +281,4 @@ public ClassMemberInfo(Class originClass, IMember originMember, Class targetClas public Class TargetClass { get; } public IMember TargetMember { get; } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/Dependencies/Members/MemberDependencyTests.cs b/ArchUnitNETTests/Domain/Dependencies/Members/MemberDependencyTests.cs index 5a497054e..771c78037 100644 --- a/ArchUnitNETTests/Domain/Dependencies/Members/MemberDependencyTests.cs +++ b/ArchUnitNETTests/Domain/Dependencies/Members/MemberDependencyTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain.Dependencies; @@ -15,25 +15,45 @@ public class MemberDependencyTests { [Theory] [ClassData(typeof(MemberDependencyTestBuild.MemberDependencyModelingTestData))] - public void MemberTypeDependencyEquivalencyTests(IMemberTypeDependency memberTypeDependency, - object duplicateMemberTypeDependency, IMemberTypeDependency dependencyReferenceDuplicate, - [CanBeNull] object objectReferenceDuplicate) + public void MemberTypeDependencyEquivalencyTests( + IMemberTypeDependency memberTypeDependency, + object duplicateMemberTypeDependency, + IMemberTypeDependency dependencyReferenceDuplicate, + [CanBeNull] object objectReferenceDuplicate + ) { - if (memberTypeDependency == null || duplicateMemberTypeDependency == null - || dependencyReferenceDuplicate == null) + if ( + memberTypeDependency == null + || duplicateMemberTypeDependency == null + || dependencyReferenceDuplicate == null + ) { return; } - DuplicateMemberDependenciesAreEqual(memberTypeDependency, duplicateMemberTypeDependency); - DuplicateMemberDependencyObjectReferencesAreEqual(memberTypeDependency, objectReferenceDuplicate); - DuplicateMemberDependencyReferencesAreEqual(memberTypeDependency, dependencyReferenceDuplicate); + DuplicateMemberDependenciesAreEqual( + memberTypeDependency, + duplicateMemberTypeDependency + ); + DuplicateMemberDependencyObjectReferencesAreEqual( + memberTypeDependency, + objectReferenceDuplicate + ); + DuplicateMemberDependencyReferencesAreEqual( + memberTypeDependency, + dependencyReferenceDuplicate + ); MemberDependencyDoesNotEqualNull(memberTypeDependency); - MemberDependencyHasConsistentHashCode(memberTypeDependency, duplicateMemberTypeDependency); + MemberDependencyHasConsistentHashCode( + memberTypeDependency, + duplicateMemberTypeDependency + ); } - private static void DuplicateMemberDependenciesAreEqual([NotNull] IMemberTypeDependency originMember, - [NotNull] object duplicateMember) + private static void DuplicateMemberDependenciesAreEqual( + [NotNull] IMemberTypeDependency originMember, + [NotNull] object duplicateMember + ) { originMember.RequiredNotNull(); duplicateMember.RequiredNotNull(); @@ -43,7 +63,8 @@ private static void DuplicateMemberDependenciesAreEqual([NotNull] IMemberTypeDep private static void DuplicateMemberDependencyObjectReferencesAreEqual( [NotNull] IMemberTypeDependency memberDependency, - object objectReferenceDuplicate) + object objectReferenceDuplicate + ) { memberDependency.RequiredNotNull(); objectReferenceDuplicate.RequiredNotNull(); @@ -51,8 +72,10 @@ private static void DuplicateMemberDependencyObjectReferencesAreEqual( Assert.Equal(memberDependency, objectReferenceDuplicate); } - private static void DuplicateMemberDependencyReferencesAreEqual([NotNull] IMemberTypeDependency dependency, - [NotNull] IMemberTypeDependency dependencyReferenceDuplicate) + private static void DuplicateMemberDependencyReferencesAreEqual( + [NotNull] IMemberTypeDependency dependency, + [NotNull] IMemberTypeDependency dependencyReferenceDuplicate + ) { dependency.RequiredNotNull(); dependencyReferenceDuplicate.RequiredNotNull(); @@ -60,15 +83,19 @@ private static void DuplicateMemberDependencyReferencesAreEqual([NotNull] IMembe Assert.True(dependency.Equals(dependencyReferenceDuplicate)); } - private static void MemberDependencyDoesNotEqualNull([NotNull] IMemberTypeDependency memberDependency) + private static void MemberDependencyDoesNotEqualNull( + [NotNull] IMemberTypeDependency memberDependency + ) { memberDependency.RequiredNotNull(); Assert.False(memberDependency.Equals(null)); } - private static void MemberDependencyHasConsistentHashCode([NotNull] IMemberTypeDependency memberDependency, - [NotNull] object duplicateMemberDependency) + private static void MemberDependencyHasConsistentHashCode( + [NotNull] IMemberTypeDependency memberDependency, + [NotNull] object duplicateMemberDependency + ) { memberDependency.RequiredNotNull(); duplicateMemberDependency.RequiredNotNull(); @@ -78,4 +105,4 @@ private static void MemberDependencyHasConsistentHashCode([NotNull] IMemberTypeD Assert.Equal(hash, duplicateHash); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/Dependencies/Members/MethodCallDependencyTests.cs b/ArchUnitNETTests/Domain/Dependencies/Members/MethodCallDependencyTests.cs index 3499cc3ec..0e9fe1b0b 100644 --- a/ArchUnitNETTests/Domain/Dependencies/Members/MethodCallDependencyTests.cs +++ b/ArchUnitNETTests/Domain/Dependencies/Members/MethodCallDependencyTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Linq; @@ -19,7 +19,8 @@ namespace ArchUnitNETTests.Domain.Dependencies.Members { public class MethodCallDependencyTests { - private readonly Architecture _architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private readonly Architecture _architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; private readonly Class _classWithConstructors; private readonly MethodMember _methodAMember; @@ -28,10 +29,14 @@ public class MethodCallDependencyTests public MethodCallDependencyTests() { _classWithConstructors = _architecture.GetClassOfType(typeof(ClassWithConstructors)); - _methodAMember = _architecture.GetClassOfType(typeof(ClassWithMethodA)) - .GetMethodMembersWithName(nameof(ClassWithMethodA.MethodA).BuildMethodMemberName()).FirstOrDefault(); - _methodBMember = _architecture.GetClassOfType(typeof(ClassWithMethodB)) - .GetMethodMembersWithName(nameof(ClassWithMethodB.MethodB).BuildMethodMemberName()).FirstOrDefault(); + _methodAMember = _architecture + .GetClassOfType(typeof(ClassWithMethodA)) + .GetMethodMembersWithName(nameof(ClassWithMethodA.MethodA).BuildMethodMemberName()) + .FirstOrDefault(); + _methodBMember = _architecture + .GetClassOfType(typeof(ClassWithMethodB)) + .GetMethodMembersWithName(nameof(ClassWithMethodB.MethodB).BuildMethodMemberName()) + .FirstOrDefault(); } [Theory] @@ -50,7 +55,10 @@ public void ConstructorsAddedToClass(Class classWithConstructors) [Theory] [ClassData(typeof(MethodDependencyTestBuild.MethodCallDependencyTestData))] - public void MethodCallDependenciesAreFound(IMember originMember, MethodCallDependency expectedDependency) + public void MethodCallDependenciesAreFound( + IMember originMember, + MethodCallDependency expectedDependency + ) { Assert.True(originMember.HasMemberDependency(expectedDependency)); Assert.Contains(expectedDependency, originMember.GetMethodCallDependencies()); @@ -58,7 +66,10 @@ public void MethodCallDependenciesAreFound(IMember originMember, MethodCallDepen [Theory] [ClassData(typeof(MethodDependencyTestBuild.MethodCallDependencyInAsyncMethodTestData))] - public void MethodCallDependenciesAreFoundInAsyncMethod(IMember originMember, MethodCallDependency expectedDependency) + public void MethodCallDependenciesAreFoundInAsyncMethod( + IMember originMember, + MethodCallDependency expectedDependency + ) { Assert.True(originMember.HasMemberDependency(expectedDependency)); Assert.Contains(expectedDependency, originMember.GetMethodCallDependencies()); @@ -99,13 +110,11 @@ public class ClassWithConstructors private FieldType _fieldTest; private FieldType _privateFieldTest; - public ClassWithConstructors() : this(new FieldType()) - { - } + public ClassWithConstructors() + : this(new FieldType()) { } - private ClassWithConstructors(FieldType fieldTest) : this(fieldTest, fieldTest) - { - } + private ClassWithConstructors(FieldType fieldTest) + : this(fieldTest, fieldTest) { } private ClassWithConstructors(FieldType fieldTest, FieldType privateFieldTest) { @@ -113,4 +122,4 @@ private ClassWithConstructors(FieldType fieldTest, FieldType privateFieldTest) _privateFieldTest = privateFieldTest; } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/Dependencies/Members/MethodDependencyTestBuild.cs b/ArchUnitNETTests/Domain/Dependencies/Members/MethodDependencyTestBuild.cs index 6a9ad5bd1..6703d48bc 100644 --- a/ArchUnitNETTests/Domain/Dependencies/Members/MethodDependencyTestBuild.cs +++ b/ArchUnitNETTests/Domain/Dependencies/Members/MethodDependencyTestBuild.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections; @@ -18,47 +18,75 @@ namespace ArchUnitNETTests.Domain.Dependencies.Members { public static class MethodDependencyTestBuild { - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; - - private static object[] BuildMethodCallDependencyTestData(Type originType, string nameOfOriginMember, - Type targetType, string nameOfTargetMember) + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; + + private static object[] BuildMethodCallDependencyTestData( + Type originType, + string nameOfOriginMember, + Type targetType, + string nameOfTargetMember + ) { var originClass = Architecture.GetClassOfType(originType); var originMember = originClass.GetMembersWithName(nameOfOriginMember).Single(); var targetClass = Architecture.GetClassOfType(targetType); var targetMember = targetClass.GetMethodMembersWithName(nameOfTargetMember).Single(); - var expectedDependency = new MethodCallDependency(originMember, new MethodMemberInstance(targetMember, - Enumerable.Empty(), Enumerable.Empty())); - return new object[] {originMember, expectedDependency}; + var expectedDependency = new MethodCallDependency( + originMember, + new MethodMemberInstance( + targetMember, + Enumerable.Empty(), + Enumerable.Empty() + ) + ); + return new object[] { originMember, expectedDependency }; } - private static object[] BuildMethodSignatureDependencyTestData(Type originType, - string nameOfOriginMember, Type targetType) + private static object[] BuildMethodSignatureDependencyTestData( + Type originType, + string nameOfOriginMember, + Type targetType + ) { var originClass = Architecture.GetClassOfType(originType); var originMember = originClass.GetMethodMembersWithName(nameOfOriginMember).Single(); var target = Architecture.GetClassOfType(targetType); - var expectedDependency = - new MethodSignatureDependency(originMember, new TypeInstance(target)); - return new object[] {originMember, expectedDependency}; + var expectedDependency = new MethodSignatureDependency( + originMember, + new TypeInstance(target) + ); + return new object[] { originMember, expectedDependency }; } public class MethodCallDependencyTestData : IEnumerable { private readonly List _methodCallDependencyData = new List { - BuildMethodCallDependencyTestData(typeof(ClassWithMethodA), - nameof(ClassWithMethodA.MethodA).BuildMethodMemberName(), typeof(ClassWithMethodB), - StaticConstants.ConstructorNameBase.BuildMethodMemberName()), - BuildMethodCallDependencyTestData(typeof(ClassWithMethodA), - nameof(ClassWithMethodA.MethodA).BuildMethodMemberName(), typeof(ClassWithMethodB), - nameof(ClassWithMethodB.MethodB).BuildMethodMemberName()), - BuildMethodCallDependencyTestData(typeof(ClassWithMethodB), - nameof(ClassWithMethodB.MethodB).BuildMethodMemberName(), typeof(ClassWithMethodA), - StaticConstants.ConstructorNameBase.BuildMethodMemberName()), - BuildMethodCallDependencyTestData(typeof(ClassWithMethodB), - nameof(ClassWithMethodB.MethodB).BuildMethodMemberName(), typeof(ClassWithMethodA), - nameof(ClassWithMethodA.MethodA).BuildMethodMemberName()) + BuildMethodCallDependencyTestData( + typeof(ClassWithMethodA), + nameof(ClassWithMethodA.MethodA).BuildMethodMemberName(), + typeof(ClassWithMethodB), + StaticConstants.ConstructorNameBase.BuildMethodMemberName() + ), + BuildMethodCallDependencyTestData( + typeof(ClassWithMethodA), + nameof(ClassWithMethodA.MethodA).BuildMethodMemberName(), + typeof(ClassWithMethodB), + nameof(ClassWithMethodB.MethodB).BuildMethodMemberName() + ), + BuildMethodCallDependencyTestData( + typeof(ClassWithMethodB), + nameof(ClassWithMethodB.MethodB).BuildMethodMemberName(), + typeof(ClassWithMethodA), + StaticConstants.ConstructorNameBase.BuildMethodMemberName() + ), + BuildMethodCallDependencyTestData( + typeof(ClassWithMethodB), + nameof(ClassWithMethodB.MethodB).BuildMethodMemberName(), + typeof(ClassWithMethodA), + nameof(ClassWithMethodA.MethodA).BuildMethodMemberName() + ) }; public IEnumerator GetEnumerator() @@ -76,18 +104,30 @@ public class MethodCallDependencyInAsyncMethodTestData : IEnumerable { private readonly List _methodCallDependencyData = new List { - BuildMethodCallDependencyTestData(typeof(ClassWithMethodAAsync), - nameof(ClassWithMethodAAsync.MethodAAsync).BuildMethodMemberName(), typeof(ClassWithMethodB), - StaticConstants.ConstructorNameBase.BuildMethodMemberName()), - BuildMethodCallDependencyTestData(typeof(ClassWithMethodAAsync), - nameof(ClassWithMethodAAsync.MethodAAsync).BuildMethodMemberName(), typeof(ClassWithMethodB), - nameof(ClassWithMethodB.MethodB).BuildMethodMemberName()), - BuildMethodCallDependencyTestData(typeof(ClassWithMethodB), - nameof(ClassWithMethodB.MethodB).BuildMethodMemberName(), typeof(ClassWithMethodA), - StaticConstants.ConstructorNameBase.BuildMethodMemberName()), - BuildMethodCallDependencyTestData(typeof(ClassWithMethodB), - nameof(ClassWithMethodB.MethodB).BuildMethodMemberName(), typeof(ClassWithMethodA), - nameof(ClassWithMethodA.MethodA).BuildMethodMemberName()) + BuildMethodCallDependencyTestData( + typeof(ClassWithMethodAAsync), + nameof(ClassWithMethodAAsync.MethodAAsync).BuildMethodMemberName(), + typeof(ClassWithMethodB), + StaticConstants.ConstructorNameBase.BuildMethodMemberName() + ), + BuildMethodCallDependencyTestData( + typeof(ClassWithMethodAAsync), + nameof(ClassWithMethodAAsync.MethodAAsync).BuildMethodMemberName(), + typeof(ClassWithMethodB), + nameof(ClassWithMethodB.MethodB).BuildMethodMemberName() + ), + BuildMethodCallDependencyTestData( + typeof(ClassWithMethodB), + nameof(ClassWithMethodB.MethodB).BuildMethodMemberName(), + typeof(ClassWithMethodA), + StaticConstants.ConstructorNameBase.BuildMethodMemberName() + ), + BuildMethodCallDependencyTestData( + typeof(ClassWithMethodB), + nameof(ClassWithMethodB.MethodB).BuildMethodMemberName(), + typeof(ClassWithMethodA), + nameof(ClassWithMethodA.MethodA).BuildMethodMemberName() + ) }; public IEnumerator GetEnumerator() @@ -105,15 +145,25 @@ public class MethodSignatureDependencyTestData : IEnumerable { private readonly List _methodSignatureDependencyData = new List { - BuildMethodSignatureDependencyTestData(typeof(ClassWithMethodSignatureA), - nameof(ClassWithMethodSignatureA.MethodA).BuildMethodMemberName(typeof(ClassWithMethodSignatureB)), - typeof(ClassWithMethodSignatureB)), - BuildMethodSignatureDependencyTestData(typeof(ClassWithMethodSignatureB), - nameof(ClassWithMethodSignatureB.MethodB).BuildMethodMemberName(typeof(ClassWithMethodSignatureA)), - typeof(ClassWithMethodSignatureA)), - BuildMethodSignatureDependencyTestData(typeof(ClassWithMethodSignatureC), - StaticConstants.ConstructorNameBase.BuildMethodMemberName(typeof(ClassWithMethodSignatureB)), - typeof(ClassWithMethodSignatureB)) + BuildMethodSignatureDependencyTestData( + typeof(ClassWithMethodSignatureA), + nameof(ClassWithMethodSignatureA.MethodA) + .BuildMethodMemberName(typeof(ClassWithMethodSignatureB)), + typeof(ClassWithMethodSignatureB) + ), + BuildMethodSignatureDependencyTestData( + typeof(ClassWithMethodSignatureB), + nameof(ClassWithMethodSignatureB.MethodB) + .BuildMethodMemberName(typeof(ClassWithMethodSignatureA)), + typeof(ClassWithMethodSignatureA) + ), + BuildMethodSignatureDependencyTestData( + typeof(ClassWithMethodSignatureC), + StaticConstants.ConstructorNameBase.BuildMethodMemberName( + typeof(ClassWithMethodSignatureB) + ), + typeof(ClassWithMethodSignatureB) + ) }; public IEnumerator GetEnumerator() @@ -131,9 +181,15 @@ public class ConstructorTestData : IEnumerable { private readonly List _methodCallDependencyData = new List { - ClassDependenciesIncludeMemberDependenciesBuild.BuildClassTestData(typeof(ClassWithMethodA)), - ClassDependenciesIncludeMemberDependenciesBuild.BuildClassTestData(typeof(ClassWithMethodA)), - ClassDependenciesIncludeMemberDependenciesBuild.BuildClassTestData(typeof(ClassWithConstructors)) + ClassDependenciesIncludeMemberDependenciesBuild.BuildClassTestData( + typeof(ClassWithMethodA) + ), + ClassDependenciesIncludeMemberDependenciesBuild.BuildClassTestData( + typeof(ClassWithMethodA) + ), + ClassDependenciesIncludeMemberDependenciesBuild.BuildClassTestData( + typeof(ClassWithConstructors) + ) }; public IEnumerator GetEnumerator() @@ -147,4 +203,4 @@ IEnumerator IEnumerable.GetEnumerator() } } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/Dependencies/Members/MethodSignatureMemberDependencyTests.cs b/ArchUnitNETTests/Domain/Dependencies/Members/MethodSignatureMemberDependencyTests.cs index f1c14eb27..2848e5166 100644 --- a/ArchUnitNETTests/Domain/Dependencies/Members/MethodSignatureMemberDependencyTests.cs +++ b/ArchUnitNETTests/Domain/Dependencies/Members/MethodSignatureMemberDependencyTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -19,8 +19,10 @@ public class MethodSignatureMemberDependencyTests { [Theory] [ClassData(typeof(MethodDependencyTestBuild.MethodSignatureDependencyTestData))] - public void MethodSignatureDependenciesAreFound(MethodMember originMember, - MethodSignatureDependency expectedDependency) + public void MethodSignatureDependenciesAreFound( + MethodMember originMember, + MethodSignatureDependency expectedDependency + ) { Assert.True(originMember.HasMethodSignatureDependency(expectedDependency)); } @@ -51,12 +53,8 @@ public ClassWithMethodSignatureC(ClassWithMethodSignatureB classWithMethodSignat _innerField = classWithMethodSignatureB; } - public void OverloadedMethod(string s) - { - } + public void OverloadedMethod(string s) { } - public void OverloadedMethod(int i) - { - } + public void OverloadedMethod(int i) { } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/Dependencies/Members/PropertyDependencyTests.cs b/ArchUnitNETTests/Domain/Dependencies/Members/PropertyDependencyTests.cs index 95e33b85d..9c076ab5e 100644 --- a/ArchUnitNETTests/Domain/Dependencies/Members/PropertyDependencyTests.cs +++ b/ArchUnitNETTests/Domain/Dependencies/Members/PropertyDependencyTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -24,10 +24,12 @@ public PropertyDependencyTests() _classWithPropertyA = _architecture.GetClassOfType(typeof(ClassWithPropertyA)); _propertyType = _architecture.GetClassOfType(typeof(PropertyType)); _propertyAMember = _classWithPropertyA.Members["PropertyA"] as PropertyMember; - _privatePropertyAMember = _classWithPropertyA.Members["PrivatePropertyA"] as PropertyMember; + _privatePropertyAMember = + _classWithPropertyA.Members["PrivatePropertyA"] as PropertyMember; } - private readonly Architecture _architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private readonly Architecture _architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; private readonly Class _classWithPropertyA; private readonly PropertyMember _propertyAMember; @@ -54,7 +56,8 @@ public void PropertyDependenciesAddedToClassDependencies() { var propertyMembers = _classWithPropertyA.GetPropertyMembers(); propertyMembers.ForEach(propertyMember => - Assert.True(_classWithPropertyA.HasDependencies(propertyMember.MemberDependencies))); + Assert.True(_classWithPropertyA.HasDependencies(propertyMember.MemberDependencies)) + ); } [Fact] @@ -87,4 +90,4 @@ public PropertyType(object field) _field = field; } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/Dependencies/Types/GenericInterfaceTests.cs b/ArchUnitNETTests/Domain/Dependencies/Types/GenericInterfaceTests.cs index 7d08403c8..92d6a6c6c 100644 --- a/ArchUnitNETTests/Domain/Dependencies/Types/GenericInterfaceTests.cs +++ b/ArchUnitNETTests/Domain/Dependencies/Types/GenericInterfaceTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Linq; @@ -16,7 +16,8 @@ namespace ArchUnitNETTests.Domain.Dependencies.Types { public class GenericInterfaceTests { - private readonly Architecture _architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private readonly Architecture _architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; private readonly Interface _genericInterface; private readonly Class _genericInterfaceImplementation; @@ -25,17 +26,21 @@ public class GenericInterfaceTests public GenericInterfaceTests() { _genericInterface = _architecture.GetInterfaceOfType(typeof(IGenericInterface<>)); - _genericInterfaceImplementation = _architecture.GetClassOfType(typeof(GenericInterfaceImplementation)); + _genericInterfaceImplementation = _architecture.GetClassOfType( + typeof(GenericInterfaceImplementation) + ); _genericType = _architecture.GetClassOfType(typeof(GenericType)); } [Fact] public void ClassImplementsGenericInterface() { - var implementsInterfaceDependency = _genericInterfaceImplementation.Dependencies - .OfType().First(); - var genericArgumentsOfImplementedInterface = implementsInterfaceDependency.TargetGenericArguments - .Select(argument => argument.Type).ToList(); + var implementsInterfaceDependency = _genericInterfaceImplementation + .Dependencies.OfType() + .First(); + var genericArgumentsOfImplementedInterface = implementsInterfaceDependency + .TargetGenericArguments.Select(argument => argument.Type) + .ToList(); Assert.True(_genericInterfaceImplementation.ImplementsInterface(_genericInterface)); Assert.Single(genericArgumentsOfImplementedInterface); @@ -43,15 +48,9 @@ public void ClassImplementsGenericInterface() } } - public interface IGenericInterface - { - } + public interface IGenericInterface { } - public class GenericType - { - } + public class GenericType { } - public class GenericInterfaceImplementation : IGenericInterface - { - } -} \ No newline at end of file + public class GenericInterfaceImplementation : IGenericInterface { } +} diff --git a/ArchUnitNETTests/Domain/Dependencies/Types/ImplementingInterfacesTest.cs b/ArchUnitNETTests/Domain/Dependencies/Types/ImplementingInterfacesTest.cs index 3787b8e37..524a4fe0d 100644 --- a/ArchUnitNETTests/Domain/Dependencies/Types/ImplementingInterfacesTest.cs +++ b/ArchUnitNETTests/Domain/Dependencies/Types/ImplementingInterfacesTest.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -29,8 +29,10 @@ public ImplementingInterfacesTest() [Fact] public void InheritingTypeImplementsInheritedInterface() { - var expectedDependency = - new ImplementsInterfaceDependency(_inheritingType, new TypeInstance(_implementingInterface)); + var expectedDependency = new ImplementsInterfaceDependency( + _inheritingType, + new TypeInstance(_implementingInterface) + ); Assert.True(_inheritingType.HasDependency(expectedDependency)); Assert.True(_inheritingType.ImplementsInterface(_implementingInterface)); @@ -40,8 +42,10 @@ public void InheritingTypeImplementsInheritedInterface() [Fact] public void OriginAsExpected() { - Assert.All(_inheritingType.GetImplementsInterfaceDependencies(), - dependency => Assert.Equal(_inheritingType, dependency.Origin)); + Assert.All( + _inheritingType.GetImplementsInterfaceDependencies(), + dependency => Assert.Equal(_inheritingType, dependency.Origin) + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/Extensions/ArchitectureExtensionTests.cs b/ArchUnitNETTests/Domain/Extensions/ArchitectureExtensionTests.cs index a8b29096a..d6839637b 100644 --- a/ArchUnitNETTests/Domain/Extensions/ArchitectureExtensionTests.cs +++ b/ArchUnitNETTests/Domain/Extensions/ArchitectureExtensionTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -17,27 +17,37 @@ namespace ArchUnitNETTests.Domain.Extensions { public class ArchitectureExtensionTests { - private readonly Architecture _architecture = StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture; + private readonly Architecture _architecture = + StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture; [Fact] public void FoundCorrectClassInArchitecture() { - Assert.Equal(_architecture.Classes.SingleOrDefault(archClass => archClass.Name == nameof(Class1)), - _architecture.GetClassOfType(typeof(Class1))); + Assert.Equal( + _architecture.Classes.SingleOrDefault(archClass => + archClass.Name == nameof(Class1) + ), + _architecture.GetClassOfType(typeof(Class1)) + ); } [Fact] public void FoundCorrectInterfaceInArchitecture() { - Assert.Equal(_architecture.Interfaces - .SingleOrDefault(archClass => archClass.Name == nameof(IEntity)), - _architecture.GetInterfaceOfType(typeof(IEntity))); + Assert.Equal( + _architecture.Interfaces.SingleOrDefault(archClass => + archClass.Name == nameof(IEntity) + ), + _architecture.GetInterfaceOfType(typeof(IEntity)) + ); } [Fact] public void TypeNotInArchitectureNotFound() { - Assert.Throws(() => _architecture.GetITypeOfType(typeof(Guid))); + Assert.Throws( + () => _architecture.GetITypeOfType(typeof(Guid)) + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/Extensions/NullableExtensionTests.cs b/ArchUnitNETTests/Domain/Extensions/NullableExtensionTests.cs index ab22e408e..ea9298960 100644 --- a/ArchUnitNETTests/Domain/Extensions/NullableExtensionTests.cs +++ b/ArchUnitNETTests/Domain/Extensions/NullableExtensionTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain.Exceptions; @@ -22,7 +22,7 @@ public void RequiredNotNullReturnsThisWhenNotNull() [Fact] public void RequiredNotNullThrowsExceptionWhenNull() { - Assert.Throws(() => ((object) null).RequiredNotNull()); + Assert.Throws(() => ((object)null).RequiredNotNull()); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/Extensions/TypeExtensionTests.cs b/ArchUnitNETTests/Domain/Extensions/TypeExtensionTests.cs index 8ac2bb1ea..dca9dbbe4 100644 --- a/ArchUnitNETTests/Domain/Extensions/TypeExtensionTests.cs +++ b/ArchUnitNETTests/Domain/Extensions/TypeExtensionTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -22,18 +22,23 @@ public TypeExtensionTests() { _methodOriginClass = Architecture.GetClassOfType(typeof(ClassWithMethodA)); _methodMember = _methodOriginClass - .GetMembersWithName(nameof(ClassWithMethodA.MethodA).BuildMethodMemberName()).SingleOrDefault(); + .GetMembersWithName(nameof(ClassWithMethodA.MethodA).BuildMethodMemberName()) + .SingleOrDefault(); _fieldOriginClass = Architecture.GetClassOfType(typeof(ClassWithFieldA)); - _fieldMember = _fieldOriginClass.GetMembersWithName(nameof(ClassWithFieldA.FieldA)).SingleOrDefault(); + _fieldMember = _fieldOriginClass + .GetMembersWithName(nameof(ClassWithFieldA.FieldA)) + .SingleOrDefault(); _propertyOriginClass = Architecture.GetClassOfType(typeof(ClassWithPropertyA)); - _propertyMember = _propertyOriginClass.GetMembersWithName(nameof(ClassWithPropertyA.PropertyA)) + _propertyMember = _propertyOriginClass + .GetMembersWithName(nameof(ClassWithPropertyA.PropertyA)) .SingleOrDefault(); _exampleAttribute = Architecture.GetClassOfType(typeof(ExampleAttribute)); _regexUtilsTests = Architecture.GetClassOfType(typeof(RegexUtilsTest)); } - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; private readonly Class _methodOriginClass; private readonly IMember _methodMember; private readonly Class _fieldOriginClass; @@ -42,7 +47,8 @@ public TypeExtensionTests() private readonly IMember _propertyMember; private readonly Class _exampleAttribute; - private const string ExpectedAttributeNamespace = "ArchUnitNETTests.Domain.Dependencies.Attributes"; + private const string ExpectedAttributeNamespace = + "ArchUnitNETTests.Domain.Dependencies.Attributes"; private const string ParentAttributeNamespace = "ArchUnitNETTests.Domain.Dependencies"; private readonly Class _regexUtilsTests; @@ -80,14 +86,29 @@ public void FullNameMatchesTest() [Fact] public void HasMembersWithFullNameTest() { - Assert.True(Architecture.Types.All(type => - type.GetPropertyMembers().All(member => type.HasPropertyMemberWithFullName(member.FullName)))); - Assert.True(Architecture.Types.All(type => - type.GetFieldMembers().All(member => type.HasFieldMemberWithFullName(member.FullName)))); - Assert.True(Architecture.Types.All(type => - type.GetMethodMembers().All(member => type.HasMethodMemberWithFullName(member.FullName)))); - Assert.True(Architecture.Types.All(type => - type.Members.All(member => type.HasMemberWithFullName(member.FullName)))); + Assert.True( + Architecture.Types.All(type => + type.GetPropertyMembers() + .All(member => type.HasPropertyMemberWithFullName(member.FullName)) + ) + ); + Assert.True( + Architecture.Types.All(type => + type.GetFieldMembers() + .All(member => type.HasFieldMemberWithFullName(member.FullName)) + ) + ); + Assert.True( + Architecture.Types.All(type => + type.GetMethodMembers() + .All(member => type.HasMethodMemberWithFullName(member.FullName)) + ) + ); + Assert.True( + Architecture.Types.All(type => + type.Members.All(member => type.HasMemberWithFullName(member.FullName)) + ) + ); Assert.False(_methodOriginClass.HasPropertyMemberWithFullName("nonExistentMember")); Assert.False(_methodOriginClass.HasFieldMemberWithFullName("nonExistentMember")); Assert.False(_methodOriginClass.HasMethodMemberWithFullName("nonExistentMember")); @@ -97,14 +118,27 @@ public void HasMembersWithFullNameTest() [Fact] public void HasMembersWithNameTest() { - Assert.True(Architecture.Types.All(type => - type.GetPropertyMembers().All(member => type.HasPropertyMemberWithName(member.Name)))); - Assert.True(Architecture.Types.All(type => - type.GetFieldMembers().All(member => type.HasFieldMemberWithName(member.Name)))); - Assert.True(Architecture.Types.All(type => - type.GetMethodMembers().All(member => type.HasMethodMemberWithName(member.Name)))); - Assert.True(Architecture.Types.All(type => - type.Members.All(member => type.HasMemberWithName(member.Name)))); + Assert.True( + Architecture.Types.All(type => + type.GetPropertyMembers() + .All(member => type.HasPropertyMemberWithName(member.Name)) + ) + ); + Assert.True( + Architecture.Types.All(type => + type.GetFieldMembers().All(member => type.HasFieldMemberWithName(member.Name)) + ) + ); + Assert.True( + Architecture.Types.All(type => + type.GetMethodMembers().All(member => type.HasMethodMemberWithName(member.Name)) + ) + ); + Assert.True( + Architecture.Types.All(type => + type.Members.All(member => type.HasMemberWithName(member.Name)) + ) + ); Assert.False(_methodOriginClass.HasPropertyMemberWithName("nonExistentMember")); Assert.False(_methodOriginClass.HasFieldMemberWithName("nonExistentMember")); Assert.False(_methodOriginClass.HasMethodMemberWithName("nonExistentMember")); @@ -114,9 +148,11 @@ public void HasMembersWithNameTest() [Fact] public void ImplementsInterfaceTest() { - Assert.True(Architecture.Types.All(type => - type.ImplementedInterfaces.All(intf => - type.ImplementsInterface(intf.FullName)))); + Assert.True( + Architecture.Types.All(type => + type.ImplementedInterfaces.All(intf => type.ImplementsInterface(intf.FullName)) + ) + ); } [Fact] @@ -129,8 +165,15 @@ public void MethodMemberFoundFromMembers() [Fact] public void NameContainsTest() { - Assert.True(_fieldMember.NameContains("ieLda", StringComparison.InvariantCultureIgnoreCase)); - Assert.True(_propertyOriginClass.NameContains("sswITH", StringComparison.InvariantCultureIgnoreCase)); + Assert.True( + _fieldMember.NameContains("ieLda", StringComparison.InvariantCultureIgnoreCase) + ); + Assert.True( + _propertyOriginClass.NameContains( + "sswITH", + StringComparison.InvariantCultureIgnoreCase + ) + ); Assert.False(_methodOriginClass.NameContains("ClassMethod")); Assert.True(_methodMember.NameContains("")); Assert.ThrowsAny(() => _exampleAttribute.NameContains(null)); @@ -139,8 +182,15 @@ public void NameContainsTest() [Fact] public void NameEndsWithTest() { - Assert.True(_fieldMember.NameEndsWith("ieLda", StringComparison.InvariantCultureIgnoreCase)); - Assert.False(_propertyOriginClass.NameEndsWith("sswITH", StringComparison.InvariantCultureIgnoreCase)); + Assert.True( + _fieldMember.NameEndsWith("ieLda", StringComparison.InvariantCultureIgnoreCase) + ); + Assert.False( + _propertyOriginClass.NameEndsWith( + "sswITH", + StringComparison.InvariantCultureIgnoreCase + ) + ); Assert.False(_methodOriginClass.NameEndsWith("ClassMethod")); Assert.True(_methodMember.NameEndsWith("")); Assert.Throws(() => _exampleAttribute.NameEndsWith(null)); @@ -171,8 +221,15 @@ public void NamespaceMatchAsExpected() [Fact] public void NameStartsWithTest() { - Assert.True(_fieldMember.NameStartsWith("fIEldA", StringComparison.InvariantCultureIgnoreCase)); - Assert.True(_propertyOriginClass.NameStartsWith("cLassw", StringComparison.InvariantCultureIgnoreCase)); + Assert.True( + _fieldMember.NameStartsWith("fIEldA", StringComparison.InvariantCultureIgnoreCase) + ); + Assert.True( + _propertyOriginClass.NameStartsWith( + "cLassw", + StringComparison.InvariantCultureIgnoreCase + ) + ); Assert.False(_methodOriginClass.NameStartsWith("With")); Assert.True(_methodMember.NameStartsWith("")); Assert.Throws(() => _exampleAttribute.NameStartsWith(null)); @@ -185,4 +242,4 @@ public void PropertyMemberFoundFromMembers() Assert.NotNull(_propertyOriginClass.Members[_propertyMember.Name]); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/FixedSizeBufferTests.cs b/ArchUnitNETTests/Domain/FixedSizeBufferTests.cs index 08ccca46a..b2a16c6d7 100644 --- a/ArchUnitNETTests/Domain/FixedSizeBufferTests.cs +++ b/ArchUnitNETTests/Domain/FixedSizeBufferTests.cs @@ -1,9 +1,9 @@ // 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; @@ -16,14 +16,17 @@ namespace ArchUnitNETTests.Domain { public class FixedSizeBufferTests { - private static readonly Architecture Architecture = - new ArchLoader().LoadAssembly(typeof(FixedSizeBufferTests).Assembly).Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssembly(typeof(FixedSizeBufferTests).Assembly) + .Build(); private readonly IType _structWithUnsafeContent; public FixedSizeBufferTests() { - _structWithUnsafeContent = Architecture.GetITypeOfType(typeof(StructWithFixedSizeBuffer)); + _structWithUnsafeContent = Architecture.GetITypeOfType( + typeof(StructWithFixedSizeBuffer) + ); } [Fact] @@ -33,8 +36,8 @@ public void HandleFixedSizeBuffersCorrectly() Assert.Single(fieldMembers); Assert.False(fieldMembers[0].Type.IsCompilerGenerated); var fieldTypeDependency = _structWithUnsafeContent.GetFieldTypeDependencies().First(); - Assert.Equal(typeof(char).FullName,fieldTypeDependency.Target.FullName); - Assert.Equal(new List{1},fieldTypeDependency.TargetArrayDimensions); + Assert.Equal(typeof(char).FullName, fieldTypeDependency.Target.FullName); + Assert.Equal(new List { 1 }, fieldTypeDependency.TargetArrayDimensions); Assert.True(fieldTypeDependency.TargetIsArray); } } @@ -43,4 +46,4 @@ public struct StructWithFixedSizeBuffer { public unsafe fixed char FixedCharArray[256]; } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/GenericClassTests.cs b/ArchUnitNETTests/Domain/GenericClassTests.cs index 51d8d88ec..d4837a662 100644 --- a/ArchUnitNETTests/Domain/GenericClassTests.cs +++ b/ArchUnitNETTests/Domain/GenericClassTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -19,10 +19,12 @@ namespace ArchUnitNETTests.Domain public class GenericClassTests { private const string GuidClassName = "Guid"; - private const string SystemGuidFullName = StaticConstants.SystemNamespace + "." + GuidClassName; + private const string SystemGuidFullName = + StaticConstants.SystemNamespace + "." + GuidClassName; - private static readonly Architecture Architecture = - new ArchLoader().LoadAssembly(typeof(GenericClassTests).Assembly).Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssembly(typeof(GenericClassTests).Assembly) + .Build(); private readonly Class _classWithGenericParameters; private readonly IType _expectedGenericArgument; @@ -30,13 +32,24 @@ public class GenericClassTests public GenericClassTests() { - _classWithGenericParameters = Architecture.GetClassOfType(typeof(ClassWithGenericParameters<>)); + _classWithGenericParameters = Architecture.GetClassOfType( + typeof(ClassWithGenericParameters<>) + ); var invokesGenericClass = Architecture.GetClassOfType(typeof(InvokesGenericClass)); _genericallyTypedField = invokesGenericClass - .GetFieldMembersWithName(nameof(InvokesGenericClass.GuidGenericArgument)).SingleOrDefault(); - var guidMock = new Type(SystemGuidFullName, GuidClassName, + .GetFieldMembersWithName(nameof(InvokesGenericClass.GuidGenericArgument)) + .SingleOrDefault(); + var guidMock = new Type( + SystemGuidFullName, + GuidClassName, _classWithGenericParameters.Assembly, - new Namespace(StaticConstants.SystemNamespace, new List()), Public, false, false, true, false); + new Namespace(StaticConstants.SystemNamespace, new List()), + Public, + false, + false, + true, + false + ); _expectedGenericArgument = new Struct(guidMock); } @@ -73,13 +86,12 @@ public void GenericTypeParametersFound() public class ClassWithGenericParameters { - public void Add(T item) - { - } + public void Add(T item) { } } public class InvokesGenericClass { - public ClassWithGenericParameters GuidGenericArgument = new ClassWithGenericParameters(); + public ClassWithGenericParameters GuidGenericArgument = + new ClassWithGenericParameters(); } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/GenericMethodTests.cs b/ArchUnitNETTests/Domain/GenericMethodTests.cs index 78e40c688..5bc05db60 100644 --- a/ArchUnitNETTests/Domain/GenericMethodTests.cs +++ b/ArchUnitNETTests/Domain/GenericMethodTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Linq; using ArchUnitNET.Domain; @@ -15,22 +15,24 @@ namespace ArchUnitNETTests.Domain { public class GenericMethodTests { - private static readonly Architecture Architecture = - new ArchLoader().LoadAssembly(typeof(GenericMethodTests).Assembly).Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssembly(typeof(GenericMethodTests).Assembly) + .Build(); private readonly MethodMember _oneGenericArgumentMethod; private readonly MethodMember _twoGenericArgumentsMethod; public GenericMethodTests() { - var intf = Architecture.GetInterfaceOfType(typeof(IInterfaceWithGenericMethodsWithSameName)); + var intf = Architecture.GetInterfaceOfType( + typeof(IInterfaceWithGenericMethodsWithSameName) + ); _oneGenericArgumentMethod = intf.GetMethodMembers() .First(member => member.GenericParameters.Count == 1); _twoGenericArgumentsMethod = intf.GetMethodMembers() .First(member => member.GenericParameters.Count == 2); } - [Fact] public void AssignDifferentGenericParametersToMethodsWithSameName() { @@ -38,7 +40,10 @@ public void AssignDifferentGenericParametersToMethodsWithSameName() Assert.NotNull(_twoGenericArgumentsMethod); Assert.Empty( - _oneGenericArgumentMethod.GenericParameters.Intersect(_twoGenericArgumentsMethod.GenericParameters)); + _oneGenericArgumentMethod.GenericParameters.Intersect( + _twoGenericArgumentsMethod.GenericParameters + ) + ); } } @@ -47,4 +52,4 @@ internal interface IInterfaceWithGenericMethodsWithSameName void Method(); void Method(); } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/InterfaceTests.cs b/ArchUnitNETTests/Domain/InterfaceTests.cs index d1f1da64e..e3f1cf8ca 100644 --- a/ArchUnitNETTests/Domain/InterfaceTests.cs +++ b/ArchUnitNETTests/Domain/InterfaceTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -60,22 +60,29 @@ public void ChildInterfaceAssignableToParent() [Fact] public void DuplicateInterfaceObjectReferencesAreEqual() { - Assert.Equal(_interfaceEquivalencyTestData.OriginInterface, - _interfaceEquivalencyTestData.ObjectReferenceDuplicate); + Assert.Equal( + _interfaceEquivalencyTestData.OriginInterface, + _interfaceEquivalencyTestData.ObjectReferenceDuplicate + ); } [Fact] public void DuplicateInterfaceReferencesAreEqual() { - Assert.True(_interfaceEquivalencyTestData.OriginInterface - .Equals(_interfaceEquivalencyTestData.InterfaceReferenceDuplicate)); + Assert.True( + _interfaceEquivalencyTestData.OriginInterface.Equals( + _interfaceEquivalencyTestData.InterfaceReferenceDuplicate + ) + ); } [Fact] public void DuplicateInterfacesAreEqual() { - Assert.Equal(_interfaceEquivalencyTestData.OriginInterface, - _interfaceEquivalencyTestData.DuplicateInterface); + Assert.Equal( + _interfaceEquivalencyTestData.OriginInterface, + _interfaceEquivalencyTestData.DuplicateInterface + ); } [Fact] @@ -130,4 +137,4 @@ public void InterfacesHaveCorrectIsNestedProperty() Assert.True(NestedPrivateProtectedTestInterface.IsNested); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/MemberListTests.cs b/ArchUnitNETTests/Domain/MemberListTests.cs index 4d8732c34..bd7ca398a 100644 --- a/ArchUnitNETTests/Domain/MemberListTests.cs +++ b/ArchUnitNETTests/Domain/MemberListTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -18,18 +18,25 @@ public class MemberListTests { public MemberListTests() { - _fieldA = Architecture.GetClassOfType(typeof(ClassWithFieldA)) - .GetFieldMembersWithName(nameof(ClassWithFieldA.FieldA)).SingleOrDefault(); - _propertyA = Architecture.GetClassOfType(typeof(ClassWithPropertyA)) - .GetPropertyMembersWithName(nameof(ClassWithPropertyA.PropertyA)).SingleOrDefault(); - _methodA = Architecture.GetClassOfType(typeof(ClassWithMethodA)) - .GetMethodMembersWithName(nameof(ClassWithMethodA.MethodA).BuildMethodMemberName()).SingleOrDefault(); + _fieldA = Architecture + .GetClassOfType(typeof(ClassWithFieldA)) + .GetFieldMembersWithName(nameof(ClassWithFieldA.FieldA)) + .SingleOrDefault(); + _propertyA = Architecture + .GetClassOfType(typeof(ClassWithPropertyA)) + .GetPropertyMembersWithName(nameof(ClassWithPropertyA.PropertyA)) + .SingleOrDefault(); + _methodA = Architecture + .GetClassOfType(typeof(ClassWithMethodA)) + .GetMethodMembersWithName(nameof(ClassWithMethodA.MethodA).BuildMethodMemberName()) + .SingleOrDefault(); _memberList = new MemberList(); - _listOfMembers = new List {_fieldA, _propertyA, _methodA}; + _listOfMembers = new List { _fieldA, _propertyA, _methodA }; } - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; private readonly MemberList _memberList; private readonly FieldMember _fieldA; private readonly PropertyMember _propertyA; @@ -91,7 +98,9 @@ public void SuccessfullyGetMemberByName() { Assert.Empty(_memberList); _memberList.Add(_methodA); - var memberFromMethodAName = _memberList[nameof(ClassWithMethodA.MethodA).BuildMethodMemberName()]; + var memberFromMethodAName = _memberList[ + nameof(ClassWithMethodA.MethodA).BuildMethodMemberName() + ]; Assert.Equal(_methodA, memberFromMethodAName); } @@ -136,7 +145,6 @@ public void SuccessfullyRemoveMemberListMember() Assert.Single(_memberList); } - [Fact] public void SuccessfullySetAtIndex() { @@ -158,4 +166,4 @@ public void SuccessfullySetMemberByName() Assert.Contains(_fieldA, _memberList); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/MemberTestBuild.cs b/ArchUnitNETTests/Domain/MemberTestBuild.cs index 3545522de..281b838c6 100644 --- a/ArchUnitNETTests/Domain/MemberTestBuild.cs +++ b/ArchUnitNETTests/Domain/MemberTestBuild.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -17,13 +17,16 @@ namespace ArchUnitNETTests.Domain { public static class MemberTestBuild { - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; private static object[] BuildOriginMemberTestData(Type originType, string memberName) { return new object[] { - Architecture.GetClassOfType(originType).GetMembersWithName(memberName) + Architecture + .GetClassOfType(originType) + .GetMembersWithName(memberName) .SingleOrDefault() }; } @@ -32,10 +35,15 @@ public class OriginMemberTestData : IEnumerable { private readonly List _originMemberData = new List { - BuildOriginMemberTestData(typeof(ClassWithMethodA), - nameof(ClassWithMethodA.MethodA).BuildMethodMemberName()), + BuildOriginMemberTestData( + typeof(ClassWithMethodA), + nameof(ClassWithMethodA.MethodA).BuildMethodMemberName() + ), BuildOriginMemberTestData(typeof(ClassWithFieldA), nameof(ClassWithFieldA.FieldA)), - BuildOriginMemberTestData(typeof(ClassWithPropertyA), nameof(ClassWithPropertyA.PropertyA)) + BuildOriginMemberTestData( + typeof(ClassWithPropertyA), + nameof(ClassWithPropertyA.PropertyA) + ) }; public IEnumerator GetEnumerator() @@ -49,4 +57,4 @@ IEnumerator IEnumerable.GetEnumerator() } } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/MemberTests.cs b/ArchUnitNETTests/Domain/MemberTests.cs index 6d7dcc59e..619440121 100644 --- a/ArchUnitNETTests/Domain/MemberTests.cs +++ b/ArchUnitNETTests/Domain/MemberTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -23,21 +23,27 @@ public class MemberTests { public MemberTests() { - _methodMemberEquivalencyTestData = new MemberEquivalencyTestData(typeof(ClassWithMethodA), - nameof(ClassWithMethodA.MethodA).BuildMethodMemberName()); - _fieldMemberEquivalencyTestData = - new MemberEquivalencyTestData(typeof(ClassWithFieldA), nameof(ClassWithFieldA.FieldA)); - _propertyMemberEquivalencyTestData = new MemberEquivalencyTestData(typeof(ClassWithPropertyA), - nameof(ClassWithPropertyA.PropertyA)); + _methodMemberEquivalencyTestData = new MemberEquivalencyTestData( + typeof(ClassWithMethodA), + nameof(ClassWithMethodA.MethodA).BuildMethodMemberName() + ); + _fieldMemberEquivalencyTestData = new MemberEquivalencyTestData( + typeof(ClassWithFieldA), + nameof(ClassWithFieldA.FieldA) + ); + _propertyMemberEquivalencyTestData = new MemberEquivalencyTestData( + typeof(ClassWithPropertyA), + nameof(ClassWithPropertyA.PropertyA) + ); } - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; private readonly MemberEquivalencyTestData _methodMemberEquivalencyTestData; private readonly MemberEquivalencyTestData _fieldMemberEquivalencyTestData; private readonly MemberEquivalencyTestData _propertyMemberEquivalencyTestData; - [Theory] [ClassData(typeof(MemberTestBuild.OriginMemberTestData))] public void BackwardsDependenciesTests(IMember originMember) @@ -47,7 +53,10 @@ public void BackwardsDependenciesTests(IMember originMember) MemberTypeBackwardsDependenciesByTargetType(originMember); } - private static void DuplicateMembersAreEqual([NotNull] IMember originMember, [NotNull] object duplicateMember) + private static void DuplicateMembersAreEqual( + [NotNull] IMember originMember, + [NotNull] object duplicateMember + ) { originMember.RequiredNotNull(); duplicateMember.RequiredNotNull(); @@ -55,16 +64,20 @@ private static void DuplicateMembersAreEqual([NotNull] IMember originMember, [No Assert.Equal(originMember, duplicateMember); } - private static void DuplicateMemberObjectReferencesAreEqual([NotNull] IMember originMember, - object objectReferenceDuplicate) + private static void DuplicateMemberObjectReferencesAreEqual( + [NotNull] IMember originMember, + object objectReferenceDuplicate + ) { originMember.RequiredNotNull(); Assert.Equal(originMember, objectReferenceDuplicate); } - private static void DuplicateMemberReferencesAreEqual([NotNull] IMember originMember, - [NotNull] IMember memberReferenceDuplicate) + private static void DuplicateMemberReferencesAreEqual( + [NotNull] IMember originMember, + [NotNull] IMember memberReferenceDuplicate + ) { originMember.RequiredNotNull(); memberReferenceDuplicate.RequiredNotNull(); @@ -79,8 +92,10 @@ private static void MemberDoesNotEqualNull([NotNull] IMember member) Assert.False(member.Equals(null)); } - private static void MemberHasConsistentHashCode([NotNull] IMember originMember, - [NotNull] object duplicateMember) + private static void MemberHasConsistentHashCode( + [NotNull] IMember originMember, + [NotNull] object duplicateMember + ) { originMember.RequiredNotNull(); duplicateMember.RequiredNotNull(); @@ -98,33 +113,49 @@ private static void BackwardsDependenciesByTargetType([NotNull] IMember originMe }); } - private static void MemberMemberBackwardsDependenciesByTargetMember([NotNull] IMember originMember) + private static void MemberMemberBackwardsDependenciesByTargetMember( + [NotNull] IMember originMember + ) { - originMember.MemberBackwardsDependencies - .OfType() + originMember + .MemberBackwardsDependencies.OfType() .ForEach(memberMemberBackwardsDependency => { - Assert.Contains(memberMemberBackwardsDependency, - memberMemberBackwardsDependency.OriginMember.MemberDependencies); + Assert.Contains( + memberMemberBackwardsDependency, + memberMemberBackwardsDependency.OriginMember.MemberDependencies + ); }); } - private static void MemberTypeBackwardsDependenciesByTargetType([NotNull] IMember originMember) + private static void MemberTypeBackwardsDependenciesByTargetType( + [NotNull] IMember originMember + ) { - originMember.MemberBackwardsDependencies - .OfType() + originMember + .MemberBackwardsDependencies.OfType() .ForEach(memberTypeBackwardsDependency => - Assert.Contains(memberTypeBackwardsDependency, - memberTypeBackwardsDependency.Origin.Dependencies)); + Assert.Contains( + memberTypeBackwardsDependency, + memberTypeBackwardsDependency.Origin.Dependencies + ) + ); } private class MemberEquivalencyTestData { - public MemberEquivalencyTestData([NotNull] Type originType, [NotNull] string originMemberName) + public MemberEquivalencyTestData( + [NotNull] Type originType, + [NotNull] string originMemberName + ) { var methodOriginClass = Architecture.GetClassOfType(originType); - OriginMember = methodOriginClass.GetMembersWithName(originMemberName).SingleOrDefault(); - DuplicateMember = methodOriginClass.GetMembersWithName(originMemberName).SingleOrDefault(); + OriginMember = methodOriginClass + .GetMembersWithName(originMemberName) + .SingleOrDefault(); + DuplicateMember = methodOriginClass + .GetMembersWithName(originMemberName) + .SingleOrDefault(); } public IMember OriginMember { get; } @@ -134,87 +165,154 @@ public MemberEquivalencyTestData([NotNull] Type originType, [NotNull] string ori [Fact] public void CorrectlyAssignNotAccessibleGetter() { - Assert.Contains(Architecture.PropertyMembers.WhereNameIs("FieldWithoutGetter"), - member => member.GetterVisibility == NotAccessible); + Assert.Contains( + Architecture.PropertyMembers.WhereNameIs("FieldWithoutGetter"), + member => member.GetterVisibility == NotAccessible + ); } [Fact] public void CorrectlyAssignNotAccessibleSetter() { - Assert.Contains(Architecture.PropertyMembers.WhereNameIs("FieldWithoutSetter"), - member => member.SetterVisibility == NotAccessible); + Assert.Contains( + Architecture.PropertyMembers.WhereNameIs("FieldWithoutSetter"), + member => member.SetterVisibility == NotAccessible + ); } [Fact] public void AreReadOnlyMethodMembersAndFieldMembersAndPropertyMembers() { - Assert.Contains(Architecture.Members.WhereNameIs(nameof(ClassReadOnly.PropertyWithoutSet)), - member => member.Writability == Writability.ReadOnly); - Assert.Contains(Architecture.Members.WhereNameIs(nameof(ClassReadOnly.InitOnlyProperty)), - member => member.Writability != Writability.ReadOnly); - Assert.Contains(Architecture.Members.WhereNameIs(nameof(ClassReadOnly.PropertyWithGetAndSet)), - member => member.Writability != Writability.ReadOnly); - Assert.Contains(Architecture.Members.WhereNameIs(nameof(ClassReadOnly.ReadonlyVar)), - member => member.Writability == Writability.ReadOnly); - Assert.Contains(Architecture.Members.WhereNameIs(nameof(ClassReadOnly.ReadonlyVarInit)), - member => member.Writability == Writability.ReadOnly); - Assert.Contains(Architecture.Members.WhereNameIs(nameof(ClassReadOnly.NotReadOnlyVarInit)), - member => member.Writability != Writability.ReadOnly); - Assert.Contains(Architecture.Members.WhereNameIs(nameof(ClassReadOnly.CheckForReadOnlyMethod) + "()"), - member => member.Writability == null); + Assert.Contains( + Architecture.Members.WhereNameIs(nameof(ClassReadOnly.PropertyWithoutSet)), + member => member.Writability == Writability.ReadOnly + ); + Assert.Contains( + Architecture.Members.WhereNameIs(nameof(ClassReadOnly.InitOnlyProperty)), + member => member.Writability != Writability.ReadOnly + ); + Assert.Contains( + Architecture.Members.WhereNameIs(nameof(ClassReadOnly.PropertyWithGetAndSet)), + member => member.Writability != Writability.ReadOnly + ); + Assert.Contains( + Architecture.Members.WhereNameIs(nameof(ClassReadOnly.ReadonlyVar)), + member => member.Writability == Writability.ReadOnly + ); + Assert.Contains( + Architecture.Members.WhereNameIs(nameof(ClassReadOnly.ReadonlyVarInit)), + member => member.Writability == Writability.ReadOnly + ); + Assert.Contains( + Architecture.Members.WhereNameIs(nameof(ClassReadOnly.NotReadOnlyVarInit)), + member => member.Writability != Writability.ReadOnly + ); + Assert.Contains( + Architecture.Members.WhereNameIs( + nameof(ClassReadOnly.CheckForReadOnlyMethod) + "()" + ), + member => member.Writability == null + ); } [Fact] public void ArePropertyMembersWithInitOnlySetter() { - Assert.Contains(Architecture.PropertyMembers.WhereNameIs(nameof(ClassReadOnly.InitOnlyProperty)), - member => member.Writability == Writability.InitOnly); - Assert.Contains(Architecture.PropertyMembers.WhereNameIs(nameof(ClassReadOnly.PropertyWithoutSet)), - member => member.Writability != Writability.InitOnly); - Assert.Contains(Architecture.PropertyMembers.WhereNameIs(nameof(ClassReadOnly.PropertyWithGetAndSet)), - member => member.Writability != Writability.InitOnly); - Assert.Contains(Architecture.PropertyMembers.WhereNameIs(nameof(RecordReadOnly.PositionalInitOnlyProperty)), - member => member.Writability == Writability.InitOnly); - Assert.Contains(Architecture.PropertyMembers.WhereNameIs(nameof(RecordReadOnly.InitOnlyProperty)), - member => member.Writability == Writability.InitOnly); - Assert.Contains(Architecture.PropertyMembers.WhereNameIs(nameof(RecordReadOnly.PropertyWithoutSet)), - member => member.Writability != Writability.InitOnly); - Assert.Contains(Architecture.PropertyMembers.WhereNameIs(nameof(RecordReadOnly.PropertyWithSet)), - member => member.Writability != Writability.InitOnly); + Assert.Contains( + Architecture.PropertyMembers.WhereNameIs(nameof(ClassReadOnly.InitOnlyProperty)), + member => member.Writability == Writability.InitOnly + ); + Assert.Contains( + Architecture.PropertyMembers.WhereNameIs(nameof(ClassReadOnly.PropertyWithoutSet)), + member => member.Writability != Writability.InitOnly + ); + Assert.Contains( + Architecture.PropertyMembers.WhereNameIs( + nameof(ClassReadOnly.PropertyWithGetAndSet) + ), + member => member.Writability != Writability.InitOnly + ); + Assert.Contains( + Architecture.PropertyMembers.WhereNameIs( + nameof(RecordReadOnly.PositionalInitOnlyProperty) + ), + member => member.Writability == Writability.InitOnly + ); + Assert.Contains( + Architecture.PropertyMembers.WhereNameIs(nameof(RecordReadOnly.InitOnlyProperty)), + member => member.Writability == Writability.InitOnly + ); + Assert.Contains( + Architecture.PropertyMembers.WhereNameIs(nameof(RecordReadOnly.PropertyWithoutSet)), + member => member.Writability != Writability.InitOnly + ); + Assert.Contains( + Architecture.PropertyMembers.WhereNameIs(nameof(RecordReadOnly.PropertyWithSet)), + member => member.Writability != Writability.InitOnly + ); } [Fact] public void AreMembersImmutable() { - Assert.Contains(Architecture.Members.WhereNameIs(nameof(ClassReadOnly.ReadonlyVar)), - member => member.Writability.IsImmutable()); - Assert.Contains(Architecture.Members.WhereNameIs(nameof(ClassReadOnly.ReadonlyVarInit)), - member => member.Writability.IsImmutable()); - Assert.Contains(Architecture.Members.WhereNameIs(nameof(ClassReadOnly.NotReadOnlyVarInit)), - member => !member.Writability.IsImmutable()); - Assert.Contains(Architecture.Members.WhereNameIs(nameof(ClassReadOnly.PropertyWithoutSet)), - member => member.Writability.IsImmutable()); - Assert.Contains(Architecture.Members.WhereNameIs(nameof(ClassReadOnly.InitOnlyProperty)), - member => member.Writability.IsImmutable()); - Assert.Contains(Architecture.Members.WhereNameIs(nameof(ClassReadOnly.PropertyWithGetAndSet)), - member => !member.Writability.IsImmutable()); - Assert.Contains(Architecture.Members.WhereNameIs(nameof(ClassReadOnly.CheckForReadOnlyMethod) + "()"), - member => member.Writability.IsImmutable()); - Assert.Contains(Architecture.Members.WhereNameIs(nameof(RecordReadOnly.PositionalInitOnlyProperty)), - member => member.Writability.IsImmutable()); - Assert.Contains(Architecture.Members.WhereNameIs(nameof(RecordReadOnly.PropertyWithoutSet)), - member => member.Writability.IsImmutable()); - Assert.Contains(Architecture.Members.WhereNameIs(nameof(RecordReadOnly.InitOnlyProperty)), - member => member.Writability.IsImmutable()); - Assert.Contains(Architecture.Members.WhereNameIs(nameof(RecordReadOnly.PropertyWithSet)), - member => !member.Writability.IsImmutable()); + Assert.Contains( + Architecture.Members.WhereNameIs(nameof(ClassReadOnly.ReadonlyVar)), + member => member.Writability.IsImmutable() + ); + Assert.Contains( + Architecture.Members.WhereNameIs(nameof(ClassReadOnly.ReadonlyVarInit)), + member => member.Writability.IsImmutable() + ); + Assert.Contains( + Architecture.Members.WhereNameIs(nameof(ClassReadOnly.NotReadOnlyVarInit)), + member => !member.Writability.IsImmutable() + ); + Assert.Contains( + Architecture.Members.WhereNameIs(nameof(ClassReadOnly.PropertyWithoutSet)), + member => member.Writability.IsImmutable() + ); + Assert.Contains( + Architecture.Members.WhereNameIs(nameof(ClassReadOnly.InitOnlyProperty)), + member => member.Writability.IsImmutable() + ); + Assert.Contains( + Architecture.Members.WhereNameIs(nameof(ClassReadOnly.PropertyWithGetAndSet)), + member => !member.Writability.IsImmutable() + ); + Assert.Contains( + Architecture.Members.WhereNameIs( + nameof(ClassReadOnly.CheckForReadOnlyMethod) + "()" + ), + member => member.Writability.IsImmutable() + ); + Assert.Contains( + Architecture.Members.WhereNameIs(nameof(RecordReadOnly.PositionalInitOnlyProperty)), + member => member.Writability.IsImmutable() + ); + Assert.Contains( + Architecture.Members.WhereNameIs(nameof(RecordReadOnly.PropertyWithoutSet)), + member => member.Writability.IsImmutable() + ); + Assert.Contains( + Architecture.Members.WhereNameIs(nameof(RecordReadOnly.InitOnlyProperty)), + member => member.Writability.IsImmutable() + ); + Assert.Contains( + Architecture.Members.WhereNameIs(nameof(RecordReadOnly.PropertyWithSet)), + member => !member.Writability.IsImmutable() + ); } [Fact] public void FieldMemberEquivalencyTests() { //Setup - if (!(_fieldMemberEquivalencyTestData.OriginMember is FieldMember memberReferenceDuplicate)) + if ( + !( + _fieldMemberEquivalencyTestData.OriginMember + is FieldMember memberReferenceDuplicate + ) + ) { return; } @@ -222,21 +320,32 @@ public void FieldMemberEquivalencyTests() object objectReferenceDuplicate = _fieldMemberEquivalencyTestData.OriginMember; //Assert - MemberHasConsistentHashCode(_fieldMemberEquivalencyTestData.OriginMember, - _fieldMemberEquivalencyTestData.DuplicateMember); - DuplicateMembersAreEqual(_fieldMemberEquivalencyTestData.OriginMember, - _fieldMemberEquivalencyTestData.DuplicateMember); + MemberHasConsistentHashCode( + _fieldMemberEquivalencyTestData.OriginMember, + _fieldMemberEquivalencyTestData.DuplicateMember + ); + DuplicateMembersAreEqual( + _fieldMemberEquivalencyTestData.OriginMember, + _fieldMemberEquivalencyTestData.DuplicateMember + ); MemberDoesNotEqualNull(_fieldMemberEquivalencyTestData.OriginMember); - DuplicateMemberReferencesAreEqual(_fieldMemberEquivalencyTestData.OriginMember, memberReferenceDuplicate); - DuplicateMemberObjectReferencesAreEqual(_fieldMemberEquivalencyTestData.OriginMember, - objectReferenceDuplicate); + DuplicateMemberReferencesAreEqual( + _fieldMemberEquivalencyTestData.OriginMember, + memberReferenceDuplicate + ); + DuplicateMemberObjectReferencesAreEqual( + _fieldMemberEquivalencyTestData.OriginMember, + objectReferenceDuplicate + ); } [Fact] public void FieldMembersMustHaveAccessibleVisibility() { - Assert.True(Architecture.FieldMembers.All(member => member.Visibility != NotAccessible)); + Assert.True( + Architecture.FieldMembers.All(member => member.Visibility != NotAccessible) + ); } [Fact] @@ -246,8 +355,13 @@ public void MembersAreMethodMembersAndFieldMembersAndPropertyMembers() var methodMembers = Architecture.MethodMembers; var fieldMembers = Architecture.FieldMembers; var propertyMembers = Architecture.PropertyMembers; - Assert.True(members.All(member => - methodMembers.Contains(member) ^ fieldMembers.Contains(member) ^ propertyMembers.Contains(member))); + Assert.True( + members.All(member => + methodMembers.Contains(member) + ^ fieldMembers.Contains(member) + ^ propertyMembers.Contains(member) + ) + ); Assert.True(methodMembers.All(member => members.Contains(member))); Assert.True(fieldMembers.All(member => members.Contains(member))); Assert.True(propertyMembers.All(member => members.Contains(member))); @@ -257,7 +371,12 @@ public void MembersAreMethodMembersAndFieldMembersAndPropertyMembers() public void MethodMemberEquivalencyTests() { //Setup - if (!(_methodMemberEquivalencyTestData.OriginMember is MethodMember memberReferenceDuplicate)) + if ( + !( + _methodMemberEquivalencyTestData.OriginMember + is MethodMember memberReferenceDuplicate + ) + ) { return; } @@ -265,28 +384,44 @@ public void MethodMemberEquivalencyTests() object objectReferenceDuplicate = _methodMemberEquivalencyTestData.OriginMember; //Assert - MemberHasConsistentHashCode(_methodMemberEquivalencyTestData.OriginMember, - _methodMemberEquivalencyTestData.DuplicateMember); - DuplicateMembersAreEqual(_methodMemberEquivalencyTestData.OriginMember, - _methodMemberEquivalencyTestData.DuplicateMember); + MemberHasConsistentHashCode( + _methodMemberEquivalencyTestData.OriginMember, + _methodMemberEquivalencyTestData.DuplicateMember + ); + DuplicateMembersAreEqual( + _methodMemberEquivalencyTestData.OriginMember, + _methodMemberEquivalencyTestData.DuplicateMember + ); MemberDoesNotEqualNull(_methodMemberEquivalencyTestData.OriginMember); - DuplicateMemberReferencesAreEqual(_methodMemberEquivalencyTestData.OriginMember, memberReferenceDuplicate); - DuplicateMemberObjectReferencesAreEqual(_methodMemberEquivalencyTestData.OriginMember, - objectReferenceDuplicate); + DuplicateMemberReferencesAreEqual( + _methodMemberEquivalencyTestData.OriginMember, + memberReferenceDuplicate + ); + DuplicateMemberObjectReferencesAreEqual( + _methodMemberEquivalencyTestData.OriginMember, + objectReferenceDuplicate + ); } [Fact] public void MethodMembersMustHaveAccessibleVisibility() { - Assert.True(Architecture.MethodMembers.All(member => member.Visibility != NotAccessible)); + Assert.True( + Architecture.MethodMembers.All(member => member.Visibility != NotAccessible) + ); } [Fact] public void PropertyMemberEquivalencyTests() { //Setup - if (!(_propertyMemberEquivalencyTestData.OriginMember is PropertyMember memberReferenceDuplicate)) + if ( + !( + _propertyMemberEquivalencyTestData.OriginMember + is PropertyMember memberReferenceDuplicate + ) + ) { return; } @@ -294,16 +429,24 @@ public void PropertyMemberEquivalencyTests() object objectReferenceDuplicate = _propertyMemberEquivalencyTestData.OriginMember; //Assert - MemberHasConsistentHashCode(_propertyMemberEquivalencyTestData.OriginMember, - _propertyMemberEquivalencyTestData.DuplicateMember); - DuplicateMembersAreEqual(_propertyMemberEquivalencyTestData.OriginMember, - _propertyMemberEquivalencyTestData.DuplicateMember); + MemberHasConsistentHashCode( + _propertyMemberEquivalencyTestData.OriginMember, + _propertyMemberEquivalencyTestData.DuplicateMember + ); + DuplicateMembersAreEqual( + _propertyMemberEquivalencyTestData.OriginMember, + _propertyMemberEquivalencyTestData.DuplicateMember + ); MemberDoesNotEqualNull(_propertyMemberEquivalencyTestData.OriginMember); - DuplicateMemberReferencesAreEqual(_propertyMemberEquivalencyTestData.OriginMember, - memberReferenceDuplicate); - DuplicateMemberObjectReferencesAreEqual(_propertyMemberEquivalencyTestData.OriginMember, - objectReferenceDuplicate); + DuplicateMemberReferencesAreEqual( + _propertyMemberEquivalencyTestData.OriginMember, + memberReferenceDuplicate + ); + DuplicateMemberObjectReferencesAreEqual( + _propertyMemberEquivalencyTestData.OriginMember, + objectReferenceDuplicate + ); } // ReSharper disable All @@ -319,10 +462,8 @@ private FieldType FieldWithoutGetter } } - public class FieldType - { - } - + public class FieldType { } + private class ClassReadOnly { public readonly string ReadonlyVar; @@ -331,9 +472,8 @@ private class ClassReadOnly public string PropertyWithoutSet { get; } public string InitOnlyProperty { get; init; } public string PropertyWithGetAndSet { get; set; } - public void CheckForReadOnlyMethod() - { - } + + public void CheckForReadOnlyMethod() { } } private record RecordReadOnly(string PositionalInitOnlyProperty) @@ -343,4 +483,4 @@ private record RecordReadOnly(string PositionalInitOnlyProperty) public string PropertyWithSet { get; set; } } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/NullableReferenceTypeTests.cs b/ArchUnitNETTests/Domain/NullableReferenceTypeTests.cs index 0828161af..6d6ca687e 100644 --- a/ArchUnitNETTests/Domain/NullableReferenceTypeTests.cs +++ b/ArchUnitNETTests/Domain/NullableReferenceTypeTests.cs @@ -2,21 +2,25 @@ using ArchUnitNET.xUnit; using TestAssembly; using Xunit; - using static ArchUnitNET.Fluent.ArchRuleDefinition; namespace ArchUnitNETTests.Domain { public class NullableReferenceTypeTests { - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture; [Fact] public void ClassUsingNullableReferenceTypeShouldDependOnlyOnItself() { - var classUsingNullableReferenceType = Types().That().Are(typeof(ClassUsingNullableReferenceType)); + var classUsingNullableReferenceType = Types() + .That() + .Are(typeof(ClassUsingNullableReferenceType)); - var classDependsOnlyOnItself = classUsingNullableReferenceType.Should().OnlyDependOn(classUsingNullableReferenceType); + var classDependsOnlyOnItself = classUsingNullableReferenceType + .Should() + .OnlyDependOn(classUsingNullableReferenceType); classDependsOnlyOnItself.Check(Architecture); } diff --git a/ArchUnitNETTests/Domain/PlantUml/ClassDiagramAssociationTest.cs b/ArchUnitNETTests/Domain/PlantUml/ClassDiagramAssociationTest.cs index 8887f32e8..83bbd7736 100644 --- a/ArchUnitNETTests/Domain/PlantUml/ClassDiagramAssociationTest.cs +++ b/ArchUnitNETTests/Domain/PlantUml/ClassDiagramAssociationTest.cs @@ -15,7 +15,8 @@ namespace ArchUnitNETTests.Domain.PlantUml { public class ClassDiagramAssociationTest { - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture; [Fact] public void GetNamespaceIdentifierAssociatedWithClass() @@ -23,13 +24,21 @@ public void GetNamespaceIdentifierAssociatedWithClass() using (MemoryStream memoryStream = new MemoryStream()) { string expectedNamespaceIdentifier = typeof(SomeOriginClass).Namespace; - ClassDiagramAssociation classDiagramAssociation = CreateAssociation(TestDiagram.From(memoryStream) - .Component("A").WithStereoTypes(expectedNamespaceIdentifier) - .Component("B").WithStereoTypes(".*.Noclasshere") - .Write()); + ClassDiagramAssociation classDiagramAssociation = CreateAssociation( + TestDiagram + .From(memoryStream) + .Component("A") + .WithStereoTypes(expectedNamespaceIdentifier) + .Component("B") + .WithStereoTypes(".*.Noclasshere") + .Write() + ); Class clazz = Architecture.GetClassOfType(typeof(SomeOriginClass)); - Assert.Equal(expectedNamespaceIdentifier, classDiagramAssociation.GetNamespaceIdentifiersFromComponentOf(clazz).Single()); + Assert.Equal( + expectedNamespaceIdentifier, + classDiagramAssociation.GetNamespaceIdentifiersFromComponentOf(clazz).Single() + ); } } @@ -41,17 +50,33 @@ public void GetTargetNamespaceIdentifierOfClass() using (MemoryStream memoryStream = new MemoryStream()) { - ClassDiagramAssociation classDiagramAssociation = CreateAssociation(TestDiagram.From(memoryStream) - .Component("A").WithStereoTypes(Regex.Replace(typeof(SomeOriginClass).Namespace, @".*\.", ".*.")) - .Component("B").WithStereoTypes(expectedTarget1) - .Component("C").WithStereoTypes(expectedTarget2) - .DependencyFrom("[A]").To("[B]") - .DependencyFrom("[A]").To("[C]") - .Write()); + ClassDiagramAssociation classDiagramAssociation = CreateAssociation( + TestDiagram + .From(memoryStream) + .Component("A") + .WithStereoTypes( + Regex.Replace(typeof(SomeOriginClass).Namespace, @".*\.", ".*.") + ) + .Component("B") + .WithStereoTypes(expectedTarget1) + .Component("C") + .WithStereoTypes(expectedTarget2) + .DependencyFrom("[A]") + .To("[B]") + .DependencyFrom("[A]") + .To("[C]") + .Write() + ); Class clazz = Architecture.GetClassOfType(typeof(SomeOriginClass)); - Assert.Equal(new[] { expectedTarget1, expectedTarget2 }, classDiagramAssociation.GetTargetNamespaceIdentifiers(clazz).OrderBy(s => s).ToList()); + Assert.Equal( + new[] { expectedTarget1, expectedTarget2 }, + classDiagramAssociation + .GetTargetNamespaceIdentifiers(clazz) + .OrderBy(s => s) + .ToList() + ); } } @@ -60,14 +85,26 @@ public void RejectsClassNotContainedInAnyComponent() { using (MemoryStream memoryStream = new MemoryStream()) { - ClassDiagramAssociation classDiagramAssociation = CreateAssociation(TestDiagram.From(memoryStream) - .Component("SomeComponent").WithStereoTypes(".*.SomeStereotype.") - .Write()); + ClassDiagramAssociation classDiagramAssociation = CreateAssociation( + TestDiagram + .From(memoryStream) + .Component("SomeComponent") + .WithStereoTypes(".*.SomeStereotype.") + .Write() + ); Class classNotContained = Architecture.GetClassOfType(typeof(object)); - InvalidOperationException exception = Assert.Throws(() => classDiagramAssociation.GetTargetNamespaceIdentifiers(classNotContained)); - Assert.Equal(string.Format("Class {0} is not contained in any component", typeof(object).Name), exception.Message); + InvalidOperationException exception = Assert.Throws( + () => classDiagramAssociation.GetTargetNamespaceIdentifiers(classNotContained) + ); + Assert.Equal( + string.Format( + "Class {0} is not contained in any component", + typeof(object).Name + ), + exception.Message + ); } } @@ -76,32 +113,62 @@ public void ReportsIfClassIsContainedInAnyComponent() { using (MemoryStream memoryStream = new MemoryStream()) { - ClassDiagramAssociation classDiagramAssociation = CreateAssociation(TestDiagram.From(memoryStream) - .Component("Object").WithStereoTypes(typeof(object).Namespace) - .Write()); - - Assert.True(classDiagramAssociation.Contains(Architecture.GetClassOfType(typeof(object))), "association contains " + typeof(object).Name); - Assert.False(classDiagramAssociation.Contains(Architecture.GetClassOfType(typeof(Class2))), "association contains " + typeof(Class2).Name); + ClassDiagramAssociation classDiagramAssociation = CreateAssociation( + TestDiagram + .From(memoryStream) + .Component("Object") + .WithStereoTypes(typeof(object).Namespace) + .Write() + ); + + Assert.True( + classDiagramAssociation.Contains(Architecture.GetClassOfType(typeof(object))), + "association contains " + typeof(object).Name + ); + Assert.False( + classDiagramAssociation.Contains(Architecture.GetClassOfType(typeof(Class2))), + "association contains " + typeof(Class2).Name + ); } } [Fact] public void ClassResidesInMultipleNamespaces() { - string path = Path.Combine(Path.GetTempPath(), "plantuml_diagram_" + Guid.NewGuid() + ".puml"); + string path = Path.Combine( + Path.GetTempPath(), + "plantuml_diagram_" + Guid.NewGuid() + ".puml" + ); using (FileStream fileStream = File.Create(path)) { - TestDiagram.From(fileStream) - .Component("A").WithStereoTypes(".*.FooNamespace.*") - .Component("B").WithStereoTypes(".*.BarNamespace.*") + TestDiagram + .From(fileStream) + .Component("A") + .WithStereoTypes(".*.FooNamespace.*") + .Component("B") + .WithStereoTypes(".*.BarNamespace.*") .Write(); } ClassDiagramAssociation classDiagramAssociation = CreateAssociation(path); - Class classContainedInTwoComponents = Architecture.GetClassOfType(typeof(ClassInFooAndBarNamespace)); - - ComponentIntersectionException exception = Assert.Throws(() => classDiagramAssociation.GetTargetNamespaceIdentifiers(classContainedInTwoComponents)); - Assert.Equal(string.Format("Class {0} may not be contained in more than one component, but is contained in [A, B]", typeof(ClassInFooAndBarNamespace).Name), exception.Message); + Class classContainedInTwoComponents = Architecture.GetClassOfType( + typeof(ClassInFooAndBarNamespace) + ); + + ComponentIntersectionException exception = + Assert.Throws( + () => + classDiagramAssociation.GetTargetNamespaceIdentifiers( + classContainedInTwoComponents + ) + ); + Assert.Equal( + string.Format( + "Class {0} may not be contained in more than one component, but is contained in [A, B]", + typeof(ClassInFooAndBarNamespace).Name + ), + exception.Message + ); } [Fact] @@ -109,14 +176,21 @@ public void RejectsDuplicateStereotype() { using (MemoryStream memoryStream = new MemoryStream()) { - TestDiagram.From(memoryStream) - .Component("first").WithStereoTypes(".*.Identical.*") - .Component("second").WithStereoTypes(".*.Identical.*") + TestDiagram + .From(memoryStream) + .Component("first") + .WithStereoTypes(".*.Identical.*") + .Component("second") + .WithStereoTypes(".*.Identical.*") .Write(); - Class classContainedInTwoComponents = Architecture.GetClassOfType(typeof(ClassInFooAndBarNamespace)); + Class classContainedInTwoComponents = Architecture.GetClassOfType( + typeof(ClassInFooAndBarNamespace) + ); - IllegalDiagramException exception = Assert.Throws(() => CreateAssociation(memoryStream)); + IllegalDiagramException exception = Assert.Throws( + () => CreateAssociation(memoryStream) + ); Assert.Equal("Stereotype '.*.Identical.*' should be unique", exception.Message); } } diff --git a/ArchUnitNETTests/Domain/PlantUml/PlantUmlComponentTest.cs b/ArchUnitNETTests/Domain/PlantUml/PlantUmlComponentTest.cs index a8205075f..54948750d 100644 --- a/ArchUnitNETTests/Domain/PlantUml/PlantUmlComponentTest.cs +++ b/ArchUnitNETTests/Domain/PlantUml/PlantUmlComponentTest.cs @@ -9,8 +9,16 @@ public class PlantUmlComponentTest [Fact] public void TwoComponentsWithSameNameStereoTypeAndAliasShouldBeEqual() { - var component1 = new PlantUmlComponent(new ComponentName("someName"), new HashSet() { new Stereotype("someStereoType") }, new Alias("someAlias")); - var component2 = new PlantUmlComponent(new ComponentName("someName"), new HashSet() { new Stereotype("someStereoType") }, new Alias("someAlias")); + var component1 = new PlantUmlComponent( + new ComponentName("someName"), + new HashSet() { new Stereotype("someStereoType") }, + new Alias("someAlias") + ); + var component2 = new PlantUmlComponent( + new ComponentName("someName"), + new HashSet() { new Stereotype("someStereoType") }, + new Alias("someAlias") + ); Assert.Equal(component1, component2); } @@ -18,8 +26,16 @@ public void TwoComponentsWithSameNameStereoTypeAndAliasShouldBeEqual() [Fact] public void TwoNonIdenticalComponentsShouldNotBeEqual() { - var component1 = new PlantUmlComponent(new ComponentName("someName1"), new HashSet() { new Stereotype("someStereoType") }, new Alias("someAlias")); - var component2 = new PlantUmlComponent(new ComponentName("someName2"), new HashSet() { new Stereotype("someStereoType") }, new Alias("someAlias")); + var component1 = new PlantUmlComponent( + new ComponentName("someName1"), + new HashSet() { new Stereotype("someStereoType") }, + new Alias("someAlias") + ); + var component2 = new PlantUmlComponent( + new ComponentName("someName2"), + new HashSet() { new Stereotype("someStereoType") }, + new Alias("someAlias") + ); Assert.NotEqual(component1, component2); } @@ -27,8 +43,16 @@ public void TwoNonIdenticalComponentsShouldNotBeEqual() [Fact] public void TwoComponentsWithSameNameStereoTypeAndAliasHaveSameHashCode() { - var component1 = new PlantUmlComponent(new ComponentName("someName"), new HashSet() { new Stereotype("someStereoType") }, new Alias("someAlias")); - var component2 = new PlantUmlComponent(new ComponentName("someName"), new HashSet() { new Stereotype("someStereoType") }, new Alias("someAlias")); + var component1 = new PlantUmlComponent( + new ComponentName("someName"), + new HashSet() { new Stereotype("someStereoType") }, + new Alias("someAlias") + ); + var component2 = new PlantUmlComponent( + new ComponentName("someName"), + new HashSet() { new Stereotype("someStereoType") }, + new Alias("someAlias") + ); Assert.Equal(component1.GetHashCode(), component2.GetHashCode()); } diff --git a/ArchUnitNETTests/Domain/PlantUml/PlantUmlErrorMessagesCheck.cs b/ArchUnitNETTests/Domain/PlantUml/PlantUmlErrorMessagesCheck.cs index 787d4c372..a2f6199f2 100644 --- a/ArchUnitNETTests/Domain/PlantUml/PlantUmlErrorMessagesCheck.cs +++ b/ArchUnitNETTests/Domain/PlantUml/PlantUmlErrorMessagesCheck.cs @@ -12,13 +12,18 @@ namespace ArchUnitNETTests.Domain.PlantUml { public class PlantUmlErrorMessagesCheck { - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture; private readonly string _umlFile; public PlantUmlErrorMessagesCheck() { - _umlFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Domain", "PlantUml", - "zzz_test_version_with_errors.puml"); + _umlFile = Path.Combine( + AppDomain.CurrentDomain.BaseDirectory, + "Domain", + "PlantUml", + "zzz_test_version_with_errors.puml" + ); } [Fact] @@ -28,10 +33,17 @@ public void NoDuplicatesInErrorMessageTest() Assert.False(testPassed); //CheckForDuplicates returns false when errormessage contains duplicates or is empty - var containsNoDuplicates = ContainsNoDuplicates(rawErrormessage, out var explainErrormessage); - - var errormessage = "\nOriginal (ArchUnitNet) Exception:\n" + rawErrormessage + - "\n\nAssert Error:\n" + explainErrormessage + "\n"; + var containsNoDuplicates = ContainsNoDuplicates( + rawErrormessage, + out var explainErrormessage + ); + + var errormessage = + "\nOriginal (ArchUnitNet) Exception:\n" + + rawErrormessage + + "\n\nAssert Error:\n" + + explainErrormessage + + "\n"; Assert.True(containsNoDuplicates, errormessage); } @@ -42,7 +54,9 @@ private bool CheckByPuml(out string errormessage) try { - IArchRule adhereToPlantUmlDiagram = Types().Should().AdhereToPlantUmlDiagram(_umlFile); + IArchRule adhereToPlantUmlDiagram = Types() + .Should() + .AdhereToPlantUmlDiagram(_umlFile); adhereToPlantUmlDiagram.Check(Architecture); } //xUnit @@ -91,4 +105,4 @@ private static bool ContainsNoDuplicates(string uncutMessage, out string errorme return true; } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/PlantUml/PlantUmlFileBuilderTest.cs b/ArchUnitNETTests/Domain/PlantUml/PlantUmlFileBuilderTest.cs index c2d86c447..d0ecbbf67 100644 --- a/ArchUnitNETTests/Domain/PlantUml/PlantUmlFileBuilderTest.cs +++ b/ArchUnitNETTests/Domain/PlantUml/PlantUmlFileBuilderTest.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System; using System.Collections.Generic; @@ -20,8 +20,9 @@ namespace ArchUnitNETTests.Domain.PlantUml { public class PlantUmlFileBuilderTest { - private static readonly Architecture Architecture = - new ArchLoader().LoadAssembly(typeof(PlantUmlFileBuilderTest).Assembly).Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssembly(typeof(PlantUmlFileBuilderTest).Assembly) + .Build(); private static readonly List Dependencies = new List { @@ -33,7 +34,9 @@ public class PlantUmlFileBuilderTest [Fact] public void BuildUmlByTypesTest() { - var builder = new PlantUmlFileBuilder().WithDependenciesFrom(Architecture.Types.Take(100)); + var builder = new PlantUmlFileBuilder().WithDependenciesFrom( + Architecture.Types.Take(100) + ); var uml = builder.AsString(); Assert.NotEmpty(uml); } @@ -41,8 +44,10 @@ public void BuildUmlByTypesTest() [Fact] public void BuildUmlByTypesIncludingDependenciesToOtherTest() { - var builder = new PlantUmlFileBuilder().WithDependenciesFrom(Architecture.Types.Take(100), - new GenerationOptions {IncludeDependenciesToOther = true}); + var builder = new PlantUmlFileBuilder().WithDependenciesFrom( + Architecture.Types.Take(100), + new GenerationOptions { IncludeDependenciesToOther = true } + ); var uml = builder.AsString(); Assert.NotEmpty(uml); } @@ -58,7 +63,10 @@ public void BuildUmlByNamespacesTest() [Fact] public void BuildUmlBySlicesTest() { - var slices = SliceRuleDefinition.Slices().Matching("ArchUnitNETTests.(*).").GetObjects(Architecture); + var slices = SliceRuleDefinition + .Slices() + .Matching("ArchUnitNETTests.(*).") + .GetObjects(Architecture); var builder = new PlantUmlFileBuilder().WithDependenciesFrom(slices); var uml = builder.AsString(); Assert.NotEmpty(uml); @@ -71,46 +79,82 @@ public void BuildUmlByDependenciesTest() var uml = builder.AsString(); Assert.NotEmpty(uml); - var expectedUml = "@startuml" + Environment.NewLine + Environment.NewLine + - "!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml" + - Environment.NewLine + Environment.NewLine + - "HIDE_STEREOTYPE()" + Environment.NewLine + Environment.NewLine + "[a] --|> [b]" + - Environment.NewLine + "[b] --|> [c]" + Environment.NewLine + "[c] --|> [a]" + - Environment.NewLine + "@enduml" + Environment.NewLine; + var expectedUml = + "@startuml" + + Environment.NewLine + + Environment.NewLine + + "!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml" + + Environment.NewLine + + Environment.NewLine + + "HIDE_STEREOTYPE()" + + Environment.NewLine + + Environment.NewLine + + "[a] --|> [b]" + + Environment.NewLine + + "[b] --|> [c]" + + Environment.NewLine + + "[c] --|> [a]" + + Environment.NewLine + + "@enduml" + + Environment.NewLine; Assert.Equal(expectedUml, uml); } [Fact] public void BuildUmlByDependenciesWithObjectsWithNoDependenciesTest() { - var classesWithoutDependencies = new[] {new PlantUmlClass("d")}; - var builder = new PlantUmlFileBuilder().WithElements(Dependencies.Concat(classesWithoutDependencies)); + var classesWithoutDependencies = new[] { new PlantUmlClass("d") }; + var builder = new PlantUmlFileBuilder().WithElements( + Dependencies.Concat(classesWithoutDependencies) + ); var uml = builder.AsString(); Assert.NotEmpty(uml); - var expectedUml = "@startuml" + Environment.NewLine + Environment.NewLine + - "!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml" + - Environment.NewLine + Environment.NewLine + - "HIDE_STEREOTYPE()" + Environment.NewLine + Environment.NewLine + "class \"d\" {" + Environment.NewLine + "}" + - Environment.NewLine + "[a] --|> [b]" + Environment.NewLine + "[b] --|> [c]" + - Environment.NewLine + "[c] --|> [a]" + Environment.NewLine + "@enduml" + Environment.NewLine; + var expectedUml = + "@startuml" + + Environment.NewLine + + Environment.NewLine + + "!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml" + + Environment.NewLine + + Environment.NewLine + + "HIDE_STEREOTYPE()" + + Environment.NewLine + + Environment.NewLine + + "class \"d\" {" + + Environment.NewLine + + "}" + + Environment.NewLine + + "[a] --|> [b]" + + Environment.NewLine + + "[b] --|> [c]" + + Environment.NewLine + + "[c] --|> [a]" + + Environment.NewLine + + "@enduml" + + Environment.NewLine; Assert.Equal(expectedUml, uml); } [Fact] public void HandleIllegalComponentNamesTest() { - var forbiddenCharacters = new[] {"[", "]", "\r", "\n", "\f", "\a", "\b", "\v"}; + var forbiddenCharacters = new[] { "[", "]", "\r", "\n", "\f", "\a", "\b", "\v" }; foreach (var character in forbiddenCharacters) { - Assert.Throws(() => - new PlantUmlDependency(character, "a", DependencyType.OneToOne)); - Assert.Throws(() => - new PlantUmlDependency("a", character, DependencyType.OneToOne)); + Assert.Throws( + () => new PlantUmlDependency(character, "a", DependencyType.OneToOne) + ); + Assert.Throws( + () => new PlantUmlDependency("a", character, DependencyType.OneToOne) + ); Assert.Throws(() => new PlantUmlClass(character)); - Assert.Throws(() => new PlantUmlInterface(character)); + Assert.Throws( + () => new PlantUmlInterface(character) + ); Assert.Throws(() => new PlantUmlSlice(character)); - Assert.Throws(() => new PlantUmlNamespace(character)); + Assert.Throws( + () => new PlantUmlNamespace(character) + ); } } @@ -123,34 +167,45 @@ public void SpecialCharactersInComponentNamesTest() new PlantUmlDependency("\\\t%", "äöüß", DependencyType.OneToOne), new PlantUmlDependency("^°-*+.,;:", "<>|@€", DependencyType.OneToOne) }; - var classesWithSpecialCharacters = new[] {new PlantUmlClass("!§´`$%&/()=?\\\täöüß^°-*+,-.,;:<>|@€")}; - var builder = - new PlantUmlFileBuilder().WithElements( - dependenciesWithSpecialCharacters.Concat(classesWithSpecialCharacters)); + var classesWithSpecialCharacters = new[] + { + new PlantUmlClass("!§´`$%&/()=?\\\täöüß^°-*+,-.,;:<>|@€") + }; + var builder = new PlantUmlFileBuilder().WithElements( + dependenciesWithSpecialCharacters.Concat(classesWithSpecialCharacters) + ); var uml = builder.AsString(); Assert.NotEmpty(uml); - var expectedUml = "@startuml" + Environment.NewLine + Environment.NewLine + - "!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml" + - Environment.NewLine + Environment.NewLine + - "HIDE_STEREOTYPE()" + Environment.NewLine + Environment.NewLine + "class \"!§´`$%&/()=?\\\täöüß^°-*+,-.,;:<>|@€\" {" + - Environment.NewLine + "}" + Environment.NewLine + "[!\"§´`] --|> [$%&/()=?]" + - Environment.NewLine + "[\\\t%] --|> [äöüß]" + Environment.NewLine + - "[^°-*+.,;:] --|> [<>|@€]" + - Environment.NewLine + "@enduml" + Environment.NewLine; + var expectedUml = + "@startuml" + + Environment.NewLine + + Environment.NewLine + + "!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml" + + Environment.NewLine + + Environment.NewLine + + "HIDE_STEREOTYPE()" + + Environment.NewLine + + Environment.NewLine + + "class \"!§´`$%&/()=?\\\täöüß^°-*+,-.,;:<>|@€\" {" + + Environment.NewLine + + "}" + + Environment.NewLine + + "[!\"§´`] --|> [$%&/()=?]" + + Environment.NewLine + + "[\\\t%] --|> [äöüß]" + + Environment.NewLine + + "[^°-*+.,;:] --|> [<>|@€]" + + Environment.NewLine + + "@enduml" + + Environment.NewLine; Assert.Equal(expectedUml, uml); } } - internal class ClassToFocusOn - { - } + internal class ClassToFocusOn { } - internal class DependantClassOfFocusedClass - { - } + internal class DependantClassOfFocusedClass { } - internal class DependingClassOfFocusedClass - { - } -} \ No newline at end of file + internal class DependingClassOfFocusedClass { } +} diff --git a/ArchUnitNETTests/Domain/PlantUml/PlantUmlParserTest.cs b/ArchUnitNETTests/Domain/PlantUml/PlantUmlParserTest.cs index c9c36843b..ede765b3b 100644 --- a/ArchUnitNETTests/Domain/PlantUml/PlantUmlParserTest.cs +++ b/ArchUnitNETTests/Domain/PlantUml/PlantUmlParserTest.cs @@ -28,10 +28,15 @@ public void Dispose() [Fact] public void ParsesCorrectNumberOfComponents() { - PlantUmlParsedDiagram diagram = CreateDiagram(TestDiagram.From(_memoryStream) - .Component("SomeOrigin").WithStereoTypes("Origin.*") - .Component("SomeTarget").WithStereoTypes("Target.*") - .Write()); + PlantUmlParsedDiagram diagram = CreateDiagram( + TestDiagram + .From(_memoryStream) + .Component("SomeOrigin") + .WithStereoTypes("Origin.*") + .Component("SomeTarget") + .WithStereoTypes("Target.*") + .Write() + ); Assert.Equal(2, diagram.AllComponents.Count); } @@ -39,9 +44,13 @@ public void ParsesCorrectNumberOfComponents() [Fact] public void ParsesASimpleComponent() { - PlantUmlParsedDiagram diagram = CreateDiagram(TestDiagram.From(_memoryStream) - .Component("SomeOrigin").WithStereoTypes("Origin.*") - .Write()); + PlantUmlParsedDiagram diagram = CreateDiagram( + TestDiagram + .From(_memoryStream) + .Component("SomeOrigin") + .WithStereoTypes("Origin.*") + .Write() + ); PlantUmlComponent origin = GetComponentWithName("SomeOrigin", diagram); Assert.Equal(origin.Stereotypes.SingleOrDefault(), new Stereotype("Origin.*")); @@ -50,11 +59,16 @@ public void ParsesASimpleComponent() [Theory] [ClassData(typeof(SimpleDiagramTestData))] - public void ParsesDependencyOfSimpleComponentDiagram(Func testCaseFunc) + public void ParsesDependencyOfSimpleComponentDiagram( + Func testCaseFunc + ) { - TestDiagram initialDiagram = TestDiagram.From(_memoryStream) - .Component("SomeOrigin").WithStereoTypes("Origin.*") - .Component("SomeTarget").WithStereoTypes("Target.*"); + TestDiagram initialDiagram = TestDiagram + .From(_memoryStream) + .Component("SomeOrigin") + .WithStereoTypes("Origin.*") + .Component("SomeTarget") + .WithStereoTypes("Target.*"); PlantUmlParsedDiagram diagram = CreateDiagram(testCaseFunc(initialDiagram).Write()); PlantUmlComponent origin = GetComponentWithName("SomeOrigin", diagram); @@ -70,11 +84,16 @@ public void ParsesDependencyOfSimpleComponentDiagram(Func> as commentedAlias") - .RawLine("") - .RawLine(" ' [uncommentedComponent] --> [commentedComponent]") - .Write()); - - PlantUmlComponent uncommentedComponent = GetComponentWithName("uncommentedComponent", diagram); + PlantUmlParsedDiagram diagram = CreateDiagram( + TestDiagram + .From(_memoryStream) + .Component("uncommentedComponent") + .WithAlias("uncommentedAlias") + .WithStereoTypes("UncommentedNamespace.*") + .RawLine(" ' [commentedComponent] <> as commentedAlias") + .RawLine("") + .RawLine(" ' [uncommentedComponent] --> [commentedComponent]") + .Write() + ); + + PlantUmlComponent uncommentedComponent = GetComponentWithName( + "uncommentedComponent", + diagram + ); Assert.Equal(diagram.AllComponents.Single(), uncommentedComponent); Assert.Empty(uncommentedComponent.Dependencies); @@ -101,72 +128,123 @@ public void DoesNotIncludeCommentedOutLines() [Fact] public void DoesNotIncludeDependencyDescriptions() { - PlantUmlParsedDiagram diagram = CreateDiagram(TestDiagram.From(_memoryStream) - .Component("component").WithStereoTypes("SomeNamespace.*") - .Component("otherComponent").WithStereoTypes("SomeNamespace2.*") - .RawLine("[component] --> [otherComponent] : this part should be ignored, no matter the comment tick ' ") - .Write()); + PlantUmlParsedDiagram diagram = CreateDiagram( + TestDiagram + .From(_memoryStream) + .Component("component") + .WithStereoTypes("SomeNamespace.*") + .Component("otherComponent") + .WithStereoTypes("SomeNamespace2.*") + .RawLine( + "[component] --> [otherComponent] : this part should be ignored, no matter the comment tick ' " + ) + .Write() + ); PlantUmlComponent component = GetComponentWithName("component", diagram); PlantUmlComponent targetOfDescribedDependency = component.Dependencies.Single(); - Assert.Equal(targetOfDescribedDependency.ComponentName, new ComponentName("otherComponent")); + Assert.Equal( + targetOfDescribedDependency.ComponentName, + new ComponentName("otherComponent") + ); } [Fact] public void ThrowsExceptionWithComponentsThatAreNotYetDefined() { - TestDiagram.From(_memoryStream) - .DependencyFrom("[NotYetDefined]").To("[AlsoNotYetDefined]") + TestDiagram + .From(_memoryStream) + .DependencyFrom("[NotYetDefined]") + .To("[AlsoNotYetDefined]") .Write(); - IllegalDiagramException exception = Assert.Throws(() => CreateDiagram(_memoryStream)); - Assert.Contains("There is no Component with name or alias = 'NotYetDefined'", exception.Message); - Assert.Contains("Components must be specified separately from dependencies", exception.Message); + IllegalDiagramException exception = Assert.Throws( + () => CreateDiagram(_memoryStream) + ); + Assert.Contains( + "There is no Component with name or alias = 'NotYetDefined'", + exception.Message + ); + Assert.Contains( + "Components must be specified separately from dependencies", + exception.Message + ); } [Fact] public void ThrowsExceptionWithComponentsWithoutStereotypes() { - TestDiagram.From(_memoryStream) - .RawLine("[componentWithoutStereotype]") - .Write(); + TestDiagram.From(_memoryStream).RawLine("[componentWithoutStereotype]").Write(); - IllegalDiagramException exception = Assert.Throws(() => CreateDiagram(_memoryStream)); + IllegalDiagramException exception = Assert.Throws( + () => CreateDiagram(_memoryStream) + ); Assert.Contains("componentWithoutStereotype", exception.Message); - Assert.Contains("at least one stereotype specifying the namespace identifier (<<.*>>)", exception.Message); + Assert.Contains( + "at least one stereotype specifying the namespace identifier (<<.*>>)", + exception.Message + ); } [Fact] public void ParsesTwoIdenticalComponentsNoDependency() { - PlantUmlParsedDiagram diagram = CreateDiagram(TestDiagram.From(_memoryStream) - .Component("someName").WithAlias("someAlias").WithStereoTypes("someStereotype") - .Component("someName").WithAlias("someAlias").WithStereoTypes("someStereotype") - .Write()); - - Assert.Equal(new[] { GetComponentWithName("someName", diagram) }, diagram.AllComponents); + PlantUmlParsedDiagram diagram = CreateDiagram( + TestDiagram + .From(_memoryStream) + .Component("someName") + .WithAlias("someAlias") + .WithStereoTypes("someStereotype") + .Component("someName") + .WithAlias("someAlias") + .WithStereoTypes("someStereotype") + .Write() + ); + + Assert.Equal( + new[] { GetComponentWithName("someName", diagram) }, + diagram.AllComponents + ); } [Fact] public void RejectsAComponentWithAnIllegalAlias() { - TestDiagram.From(_memoryStream) - .Component("irrelevant").WithAlias("ill[]egal").WithStereoTypes("Irrelevant.*") + TestDiagram + .From(_memoryStream) + .Component("irrelevant") + .WithAlias("ill[]egal") + .WithStereoTypes("Irrelevant.*") .Write(); - IllegalDiagramException exception = Assert.Throws(() => CreateDiagram(_memoryStream)); - Assert.Contains("Alias 'ill[]egal' should not contain character(s): '[' or ']' or '\"'", exception.Message); + IllegalDiagramException exception = Assert.Throws( + () => CreateDiagram(_memoryStream) + ); + Assert.Contains( + "Alias 'ill[]egal' should not contain character(s): '[' or ']' or '\"'", + exception.Message + ); } [Fact] public void ParsesATrickyAlias() { - PlantUmlParsedDiagram diagram = CreateDiagram(TestDiagram.From(_memoryStream) - .Component("tricky").WithAlias("because it's quoted").WithStereoTypes("Tricky.*") - .Component("tricky as hell cause of as keyword").WithAlias("other").WithStereoTypes("Other.*") - .Write()); - - PlantUmlComponent trickyAsHell = GetComponentWithName("tricky as hell cause of as keyword", diagram); + PlantUmlParsedDiagram diagram = CreateDiagram( + TestDiagram + .From(_memoryStream) + .Component("tricky") + .WithAlias("because it's quoted") + .WithStereoTypes("Tricky.*") + .Component("tricky as hell cause of as keyword") + .WithAlias("other") + .WithStereoTypes("Other.*") + .Write() + ); + + PlantUmlComponent trickyAsHell = GetComponentWithName( + "tricky as hell cause of as keyword", + diagram + ); PlantUmlComponent tricky = GetComponentWithName("tricky", diagram); Assert.Equal(new Alias("other"), trickyAsHell.Alias); @@ -176,23 +254,37 @@ public void ParsesATrickyAlias() [Fact] public void ParsesComponentDiagramWithMultipleStereotypes() { - PlantUmlParsedDiagram diagram = CreateDiagram(TestDiagram.From(_memoryStream) - .Component("someComponent") - .WithStereoTypes("FirstNamespace.*", "SecondNamespace.*", "ThirdNamespace.*") - .Write()); + PlantUmlParsedDiagram diagram = CreateDiagram( + TestDiagram + .From(_memoryStream) + .Component("someComponent") + .WithStereoTypes("FirstNamespace.*", "SecondNamespace.*", "ThirdNamespace.*") + .Write() + ); PlantUmlComponent component = diagram.AllComponents.Single(); - Assert.Equal(new[] { new Stereotype("FirstNamespace.*"), new Stereotype("SecondNamespace.*"), new Stereotype("ThirdNamespace.*") }, - component.Stereotypes.OrderBy(st => st.AsString())); + Assert.Equal( + new[] + { + new Stereotype("FirstNamespace.*"), + new Stereotype("SecondNamespace.*"), + new Stereotype("ThirdNamespace.*") + }, + component.Stereotypes.OrderBy(st => st.AsString()) + ); } [Fact] public void ParsesComponentDiagramWithMultipleStereotypesAndAlias() { - PlantUmlParsedDiagram diagram = CreateDiagram(TestDiagram.From(_memoryStream) - .Component("someComponent").WithAlias("someAlias") - .WithStereoTypes("FirstNamespace.*", "SecondNamespace.*", "ThirdNamespace.*") - .Write()); + PlantUmlParsedDiagram diagram = CreateDiagram( + TestDiagram + .From(_memoryStream) + .Component("someComponent") + .WithAlias("someAlias") + .WithStereoTypes("FirstNamespace.*", "SecondNamespace.*", "ThirdNamespace.*") + .Write() + ); PlantUmlComponent component = diagram.AllComponents.Single(); @@ -202,11 +294,19 @@ public void ParsesComponentDiagramWithMultipleStereotypesAndAlias() [Fact] public void ParsesDiagramWithDependenciesThatUseAlias() { - PlantUmlParsedDiagram diagram = CreateDiagram(TestDiagram.From(_memoryStream) - .Component("A").WithAlias("aliasForA").WithStereoTypes("Controller.*") - .Component("B").WithAlias("aliasForB").WithStereoTypes("Service.*") - .DependencyFrom("aliasForA").To("aliasForB") - .Write()); + PlantUmlParsedDiagram diagram = CreateDiagram( + TestDiagram + .From(_memoryStream) + .Component("A") + .WithAlias("aliasForA") + .WithStereoTypes("Controller.*") + .Component("B") + .WithAlias("aliasForB") + .WithStereoTypes("Service.*") + .DependencyFrom("aliasForA") + .To("aliasForB") + .Write() + ); PlantUmlComponent aliasForA = GetComponentWithAlias(new Alias("aliasForA"), diagram); PlantUmlComponent aliasForB = GetComponentWithAlias(new Alias("aliasForB"), diagram); @@ -219,11 +319,17 @@ public void ParsesDiagramWithDependenciesThatUseAlias() [Fact] public void ParsesDependenciesBetweenComponentsWithoutBrackets() { - PlantUmlParsedDiagram diagram = CreateDiagram(TestDiagram.From(_memoryStream) - .Component("A").WithStereoTypes("Origin.*") - .Component("B").WithStereoTypes("Target.*") - .DependencyFrom("A").To("B") - .Write()); + PlantUmlParsedDiagram diagram = CreateDiagram( + TestDiagram + .From(_memoryStream) + .Component("A") + .WithStereoTypes("Origin.*") + .Component("B") + .WithStereoTypes("Target.*") + .DependencyFrom("A") + .To("B") + .Write() + ); PlantUmlComponent a = GetComponentWithName("A", diagram); PlantUmlComponent b = GetComponentWithName("B", diagram); @@ -234,13 +340,20 @@ public void ParsesDependenciesBetweenComponentsWithoutBrackets() [Fact] public void ParsesMultipleComponentsAndDependencies() { - TestDiagram.From(_memoryStream) - .Component("Component1").WithStereoTypes("Origin1.*") - .Component("Component2").WithStereoTypes("Target1.*") - .Component("Component3").WithStereoTypes("Origin2.*") - .Component("Component4").WithStereoTypes("Target2.*") - .DependencyFrom("Component1").To("Component2") - .DependencyFrom("Component3").To("Component4") + TestDiagram + .From(_memoryStream) + .Component("Component1") + .WithStereoTypes("Origin1.*") + .Component("Component2") + .WithStereoTypes("Target1.*") + .Component("Component3") + .WithStereoTypes("Origin2.*") + .Component("Component4") + .WithStereoTypes("Target2.*") + .DependencyFrom("Component1") + .To("Component2") + .DependencyFrom("Component3") + .To("Component4") .Write(); PlantUmlParsedDiagram diagram = CreateDiagram(_memoryStream); @@ -250,7 +363,10 @@ public void ParsesMultipleComponentsAndDependencies() PlantUmlComponent component3 = GetComponentWithName("Component3", diagram); PlantUmlComponent component4 = GetComponentWithName("Component4", diagram); - Assert.Equal(new[] { component1, component2, component3, component4 }, diagram.AllComponents.OrderBy(c => c.ComponentName.AsString())); + Assert.Equal( + new[] { component1, component2, component3, component4 }, + diagram.AllComponents.OrderBy(c => c.ComponentName.AsString()) + ); Assert.Equal(new[] { component2 }, component1.Dependencies); Assert.Empty(component2.Dependencies); Assert.Equal(new[] { component4 }, component3.Dependencies); @@ -260,12 +376,18 @@ public void ParsesMultipleComponentsAndDependencies() [Fact] public void ParsesADiagramWithNoUniqueOrigins() { - TestDiagram.From(_memoryStream) - .Component("Component1").WithStereoTypes("Origin.*") - .Component("Component2").WithStereoTypes("Target1.*") - .Component("Component3").WithStereoTypes("Target2.*") - .DependencyFrom("[Component1]").To("[Component2]") - .DependencyFrom("[Component1]").To("[Component3]") + TestDiagram + .From(_memoryStream) + .Component("Component1") + .WithStereoTypes("Origin.*") + .Component("Component2") + .WithStereoTypes("Target1.*") + .Component("Component3") + .WithStereoTypes("Target2.*") + .DependencyFrom("[Component1]") + .To("[Component2]") + .DependencyFrom("[Component1]") + .To("[Component3]") .Write(); PlantUmlParsedDiagram diagram = CreateDiagram(_memoryStream); @@ -280,12 +402,18 @@ public void ParsesADiagramWithNoUniqueOrigins() [Fact] public void ParseADiagramWithNonUniqueTargets() { - TestDiagram.From(_memoryStream) - .Component("Component1").WithStereoTypes("Origin1.*") - .Component("Component2").WithStereoTypes("Origin2.*") - .Component("Component3").WithStereoTypes("Target.*") - .DependencyFrom("[Component1]").To("[Component3]") - .DependencyFrom("[Component2]").To("[Component3]") + TestDiagram + .From(_memoryStream) + .Component("Component1") + .WithStereoTypes("Origin1.*") + .Component("Component2") + .WithStereoTypes("Origin2.*") + .Component("Component3") + .WithStereoTypes("Target.*") + .DependencyFrom("[Component1]") + .To("[Component3]") + .DependencyFrom("[Component2]") + .To("[Component3]") .Write(); PlantUmlParsedDiagram diagram = CreateDiagram(_memoryStream); @@ -301,12 +429,20 @@ public void ParseADiagramWithNonUniqueTargets() [Fact] public void ParseAComponentDiagramWithBothAliasAndNamesUsed() { - PlantUmlParsedDiagram diagram = CreateDiagram(TestDiagram.From(_memoryStream) - .Component("A").WithAlias("foo").WithStereoTypes(".Service.*") - .Component("B").WithStereoTypes("Controller.*") - .DependencyFrom("[B]").To("foo") - .DependencyFrom("foo").To("[B]") - .Write()); + PlantUmlParsedDiagram diagram = CreateDiagram( + TestDiagram + .From(_memoryStream) + .Component("A") + .WithAlias("foo") + .WithStereoTypes(".Service.*") + .Component("B") + .WithStereoTypes("Controller.*") + .DependencyFrom("[B]") + .To("foo") + .DependencyFrom("foo") + .To("[B]") + .Write() + ); PlantUmlComponent componentB = GetComponentWithName("B", diagram); PlantUmlComponent componentFoo = GetComponentWithAlias(new Alias("foo"), diagram); @@ -318,11 +454,18 @@ public void ParseAComponentDiagramWithBothAliasAndNamesUsed() [Fact] public void ParsesAComponentDiagramThatUsesAliasWithAndWithoutBrackets() { - TestDiagram.From(_memoryStream) - .Component("A").WithAlias("foo").WithStereoTypes("Origin.*") - .Component("B").WithAlias("bar").WithStereoTypes("Target.*") - .DependencyFrom("foo").To("bar") - .DependencyFrom("[foo]").To("[bar]") + TestDiagram + .From(_memoryStream) + .Component("A") + .WithAlias("foo") + .WithStereoTypes("Origin.*") + .Component("B") + .WithAlias("bar") + .WithStereoTypes("Target.*") + .DependencyFrom("foo") + .To("bar") + .DependencyFrom("[foo]") + .To("[bar]") .Write(); PlantUmlParsedDiagram diagram = CreateDiagram(_memoryStream); @@ -337,11 +480,16 @@ public void ParsesAComponentDiagramThatUsesAliasWithAndWithoutBrackets() [Fact] public void ParsesASimpleComponentWithFile() { - string path = Path.Combine(Path.GetTempPath(), "plantuml_diagram_" + Guid.NewGuid() + ".puml"); + string path = Path.Combine( + Path.GetTempPath(), + "plantuml_diagram_" + Guid.NewGuid() + ".puml" + ); using (FileStream fileStream = File.Create(path)) { - TestDiagram.From(fileStream) - .Component("SomeOrigin").WithStereoTypes("Origin.*") + TestDiagram + .From(fileStream) + .Component("SomeOrigin") + .WithStereoTypes("Origin.*") .Write(); } @@ -352,10 +500,15 @@ public void ParsesASimpleComponentWithFile() Assert.Null(origin.Alias); } - private PlantUmlComponent GetComponentWithName(string componentName, PlantUmlParsedDiagram diagram) + private PlantUmlComponent GetComponentWithName( + string componentName, + PlantUmlParsedDiagram diagram + ) { - PlantUmlComponent component = diagram.AllComponents - .Where(comp => Equals(comp.ComponentName, new ComponentName(componentName))) + PlantUmlComponent component = diagram + .AllComponents.Where(comp => + Equals(comp.ComponentName, new ComponentName(componentName)) + ) .First(); return component; } @@ -406,9 +559,11 @@ public class SimpleDiagramTestData : IEnumerable { public IEnumerator GetEnumerator() { - Func func1 = (diagram) => diagram.DependencyFrom("[SomeOrigin]").To("[SomeTarget]"); + Func func1 = (diagram) => + diagram.DependencyFrom("[SomeOrigin]").To("[SomeTarget]"); yield return new object[] { func1 }; - Func func2 = (diagram) => diagram.DependencyTo("[SomeTarget]").From("[SomeOrigin]"); + Func func2 = (diagram) => + diagram.DependencyTo("[SomeTarget]").From("[SomeOrigin]"); yield return new object[] { func2 }; } diff --git a/ArchUnitNETTests/Domain/PlantUml/TestDiagram.cs b/ArchUnitNETTests/Domain/PlantUml/TestDiagram.cs index 95a90d3b3..166934238 100644 --- a/ArchUnitNETTests/Domain/PlantUml/TestDiagram.cs +++ b/ArchUnitNETTests/Domain/PlantUml/TestDiagram.cs @@ -39,7 +39,10 @@ public DependencyToCreator DependencyTo(string target) private TestDiagram AddComponent(ComponentBuilder creator) { - string stereotypes = string.Join(" ", creator.Stereotypes.Select(input => "<<" + input + ">>")); + string stereotypes = string.Join( + " ", + creator.Stereotypes.Select(input => "<<" + input + ">>") + ); string line = string.Format("[{0}] {1}", creator.ComponentName, stereotypes); if (creator.Alias != null) { @@ -54,10 +57,10 @@ public TestDiagram RawLine(string line) _lines.Add(line); return this; } - + internal Stream Write() { - using (StreamWriter file = new StreamWriter(_stream, leaveOpen:true)) + using (StreamWriter file = new StreamWriter(_stream, leaveOpen: true)) { file.WriteLine("@startuml"); foreach (var line in _lines) @@ -97,8 +100,6 @@ public TestDiagram WithStereoTypes(params string[] stereoTypes) Stereotypes.AddRange(ImmutableList.CreateRange(stereoTypes)); return _testDiagram.AddComponent(this); } - - } public class DependencyFromCreator @@ -136,7 +137,5 @@ public TestDiagram From(string origin) return _testDiagram.RawLine(dependency); } } - - } } diff --git a/ArchUnitNETTests/Domain/RecordTypeTests.cs b/ArchUnitNETTests/Domain/RecordTypeTests.cs index 6e292e45a..5a52211fc 100644 --- a/ArchUnitNETTests/Domain/RecordTypeTests.cs +++ b/ArchUnitNETTests/Domain/RecordTypeTests.cs @@ -6,7 +6,8 @@ namespace ArchUnitNETTests.Domain { public class RecordTypeTests { - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture; [Fact] public void RecordTypeExists() @@ -15,4 +16,4 @@ public void RecordTypeExists() Assert.Contains(Architecture.Types, type => type.Name.Equals(nameof(Record1))); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/StaticTestTypes.cs b/ArchUnitNETTests/Domain/StaticTestTypes.cs index f74af89b9..bb4ff0f7e 100644 --- a/ArchUnitNETTests/Domain/StaticTestTypes.cs +++ b/ArchUnitNETTests/Domain/StaticTestTypes.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -13,79 +13,114 @@ namespace ArchUnitNETTests.Domain { public static class StaticTestTypes { - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; public static readonly IType TestEnum = Architecture.GetITypeOfType(typeof(TestEnum)); public static readonly IType TestStruct = Architecture.GetITypeOfType(typeof(TestStruct)); - public static readonly Class SealedTestClass = Architecture.GetClassOfType(typeof(SealedTestClass)); + public static readonly Class SealedTestClass = Architecture.GetClassOfType( + typeof(SealedTestClass) + ); - public static readonly Attribute TestAttribute = - Architecture.GetAttributeOfType(typeof(TestAttribute)); + public static readonly Attribute TestAttribute = Architecture.GetAttributeOfType( + typeof(TestAttribute) + ); - public static readonly Attribute ChildTestAttribute = - Architecture.GetAttributeOfType(typeof(ChildTestAttribute)); + public static readonly Attribute ChildTestAttribute = Architecture.GetAttributeOfType( + typeof(ChildTestAttribute) + ); - public static readonly Attribute SealedTestAttribute = - Architecture.GetAttributeOfType(typeof(SealedTestAttribute)); + public static readonly Attribute SealedTestAttribute = Architecture.GetAttributeOfType( + typeof(SealedTestAttribute) + ); - public static readonly Class PublicTestClass = Architecture.GetClassOfType(typeof(PublicTestClass)); - public static readonly Class InternalTestClass = Architecture.GetClassOfType(typeof(InternalTestClass)); + public static readonly Class PublicTestClass = Architecture.GetClassOfType( + typeof(PublicTestClass) + ); + public static readonly Class InternalTestClass = Architecture.GetClassOfType( + typeof(InternalTestClass) + ); - public static readonly Class NestedPublicTestClass = - Architecture.GetClassOfType(typeof(TestClassForVisibilityTest.NestedPublicTestClass)); + public static readonly Class NestedPublicTestClass = Architecture.GetClassOfType( + typeof(TestClassForVisibilityTest.NestedPublicTestClass) + ); - public static readonly Class NestedPrivateTestClass = - Architecture.GetClassOfType(TestClassForVisibilityTest.TypeOfNestedPrivateTestClass); + public static readonly Class NestedPrivateTestClass = Architecture.GetClassOfType( + TestClassForVisibilityTest.TypeOfNestedPrivateTestClass + ); - public static readonly Class NestedProtectedTestClass = - Architecture.GetClassOfType(TestClassForVisibilityTest.TypeOfNestedProtectedTestClass); + public static readonly Class NestedProtectedTestClass = Architecture.GetClassOfType( + TestClassForVisibilityTest.TypeOfNestedProtectedTestClass + ); - public static readonly Class NestedInternalTestClass = - Architecture.GetClassOfType(typeof(TestClassForVisibilityTest.NestedInternalTestClass)); + public static readonly Class NestedInternalTestClass = Architecture.GetClassOfType( + typeof(TestClassForVisibilityTest.NestedInternalTestClass) + ); - public static readonly Class NestedProtectedInternalTestClass = - Architecture.GetClassOfType(typeof(TestClassForVisibilityTest.NestedProtectedInternalTestClass)); + public static readonly Class NestedProtectedInternalTestClass = Architecture.GetClassOfType( + typeof(TestClassForVisibilityTest.NestedProtectedInternalTestClass) + ); - public static readonly Class NestedPrivateProtectedTestClass = - Architecture.GetClassOfType(TestClassForVisibilityTest.TypeOfNestedPrivateProtectedTestClass); + public static readonly Class NestedPrivateProtectedTestClass = Architecture.GetClassOfType( + TestClassForVisibilityTest.TypeOfNestedPrivateProtectedTestClass + ); + public static readonly Interface PublicTestInterface = Architecture.GetInterfaceOfType( + typeof(IPublicTestInterface) + ); - public static readonly Interface PublicTestInterface = - Architecture.GetInterfaceOfType(typeof(IPublicTestInterface)); - - public static readonly Interface InternalTestInterface = - Architecture.GetInterfaceOfType(typeof(IInternalTestInterface)); + public static readonly Interface InternalTestInterface = Architecture.GetInterfaceOfType( + typeof(IInternalTestInterface) + ); public static readonly Interface NestedPublicTestInterface = - Architecture.GetInterfaceOfType(typeof(TestClassForVisibilityTest.INestedPublicTestInterface)); + Architecture.GetInterfaceOfType( + typeof(TestClassForVisibilityTest.INestedPublicTestInterface) + ); public static readonly Interface NestedPrivateTestInterface = - Architecture.GetInterfaceOfType(TestClassForVisibilityTest.TypeOfNestedPrivateTestInterface); + Architecture.GetInterfaceOfType( + TestClassForVisibilityTest.TypeOfNestedPrivateTestInterface + ); public static readonly Interface NestedProtectedTestInterface = - Architecture.GetInterfaceOfType(TestClassForVisibilityTest.TypeOfNestedProtectedTestInterface); + Architecture.GetInterfaceOfType( + TestClassForVisibilityTest.TypeOfNestedProtectedTestInterface + ); public static readonly Interface NestedInternalTestInterface = - Architecture.GetInterfaceOfType(typeof(TestClassForVisibilityTest.INestedInternalTestInterface)); + Architecture.GetInterfaceOfType( + typeof(TestClassForVisibilityTest.INestedInternalTestInterface) + ); public static readonly Interface NestedProtectedInternalTestInterface = - Architecture.GetInterfaceOfType(typeof(TestClassForVisibilityTest.INestedProtectedInternalTestInterface)); + Architecture.GetInterfaceOfType( + typeof(TestClassForVisibilityTest.INestedProtectedInternalTestInterface) + ); public static readonly Interface NestedPrivateProtectedTestInterface = - Architecture.GetInterfaceOfType(TestClassForVisibilityTest.TypeOfNestedPrivateProtectedTestInterface); - + Architecture.GetInterfaceOfType( + TestClassForVisibilityTest.TypeOfNestedPrivateProtectedTestInterface + ); - public static readonly Interface InheritedTestInterface = - Architecture.GetInterfaceOfType(typeof(IInheritedTestInterface)); + public static readonly Interface InheritedTestInterface = Architecture.GetInterfaceOfType( + typeof(IInheritedTestInterface) + ); - public static readonly Interface InheritingInterface = - Architecture.GetInterfaceOfType(typeof(IInheritingInterface)); + public static readonly Interface InheritingInterface = Architecture.GetInterfaceOfType( + typeof(IInheritingInterface) + ); - public static readonly Class InheritedType = Architecture.GetClassOfType(typeof(InheritedType)); - public static readonly Class InheritingType = Architecture.GetClassOfType(typeof(InheritingType)); + public static readonly Class InheritedType = Architecture.GetClassOfType( + typeof(InheritedType) + ); + public static readonly Class InheritingType = Architecture.GetClassOfType( + typeof(InheritingType) + ); - public static readonly Interface TestInterface1 = - Architecture.GetInterfaceOfType(typeof(ITestInterface1)); + public static readonly Interface TestInterface1 = Architecture.GetInterfaceOfType( + typeof(ITestInterface1) + ); public static readonly Interface InheritedFromTestInterface12 = Architecture.GetInterfaceOfType(typeof(IInheritedFromTestInterface12)); @@ -97,131 +132,78 @@ public static class StaticTestTypes internal class TestClassForVisibilityTest { internal static readonly Type TypeOfNestedPrivateTestClass = typeof(NestedPrivateTestClass); - internal static readonly Type TypeOfNestedProtectedTestClass = typeof(NestedProtectedTestClass); - internal static readonly Type TypeOfNestedPrivateProtectedTestClass = typeof(NestedPrivateProtectedTestClass); + internal static readonly Type TypeOfNestedProtectedTestClass = + typeof(NestedProtectedTestClass); + internal static readonly Type TypeOfNestedPrivateProtectedTestClass = + typeof(NestedPrivateProtectedTestClass); - internal static readonly Type TypeOfNestedPrivateTestInterface = typeof(INestedPrivateTestInterface); - internal static readonly Type TypeOfNestedProtectedTestInterface = typeof(INestedProtectedTestInterface); + internal static readonly Type TypeOfNestedPrivateTestInterface = + typeof(INestedPrivateTestInterface); + internal static readonly Type TypeOfNestedProtectedTestInterface = + typeof(INestedProtectedTestInterface); internal static readonly Type TypeOfNestedPrivateProtectedTestInterface = typeof(INestedPrivateProtectedTestInterface); + public class NestedPublicTestClass { } - public class NestedPublicTestClass - { - } - - private class NestedPrivateTestClass - { - } + private class NestedPrivateTestClass { } - protected class NestedProtectedTestClass - { - } + protected class NestedProtectedTestClass { } - internal class NestedInternalTestClass - { - } + internal class NestedInternalTestClass { } - protected internal class NestedProtectedInternalTestClass - { - } + protected internal class NestedProtectedInternalTestClass { } - private protected class NestedPrivateProtectedTestClass - { - } + private protected class NestedPrivateProtectedTestClass { } - public interface INestedPublicTestInterface - { - } + public interface INestedPublicTestInterface { } - private interface INestedPrivateTestInterface - { - } + private interface INestedPrivateTestInterface { } - protected interface INestedProtectedTestInterface - { - } + protected interface INestedProtectedTestInterface { } - internal interface INestedInternalTestInterface - { - } + internal interface INestedInternalTestInterface { } - protected internal interface INestedProtectedInternalTestInterface - { - } + protected internal interface INestedProtectedInternalTestInterface { } - private protected interface INestedPrivateProtectedTestInterface - { - } + private protected interface INestedPrivateProtectedTestInterface { } } - public enum TestEnum - { - } + public enum TestEnum { } - public struct TestStruct - { - } + public struct TestStruct { } - public sealed class SealedTestClass - { - } + public sealed class SealedTestClass { } - public class TestAttribute : System.Attribute - { - } + public class TestAttribute : System.Attribute { } - public class ChildTestAttribute : TestAttribute - { - } + public class ChildTestAttribute : TestAttribute { } - public sealed class SealedTestAttribute : System.Attribute - { - } + public sealed class SealedTestAttribute : System.Attribute { } public class PublicTestClass { - public class ChildClass{} + public class ChildClass { } } - internal class InternalTestClass - { - } + internal class InternalTestClass { } - public interface IPublicTestInterface - { - } + public interface IPublicTestInterface { } - internal interface IInternalTestInterface - { - } + internal interface IInternalTestInterface { } - internal interface IInheritedTestInterface - { - } + internal interface IInheritedTestInterface { } - internal interface IInheritingInterface : IInheritedTestInterface - { - } + internal interface IInheritingInterface : IInheritedTestInterface { } - internal abstract class InheritedType : IInheritingInterface - { - } + internal abstract class InheritedType : IInheritingInterface { } - internal class InheritingType : InheritedType - { - } + internal class InheritingType : InheritedType { } - internal interface ITestInterface1 - { - } + internal interface ITestInterface1 { } - internal interface ITestInterface12 - { - } + internal interface ITestInterface12 { } - internal interface IInheritedFromTestInterface12 : ITestInterface12 - { - } -} \ No newline at end of file + internal interface IInheritedFromTestInterface12 : ITestInterface12 { } +} diff --git a/ArchUnitNETTests/Domain/TestArchitectureCache.cs b/ArchUnitNETTests/Domain/TestArchitectureCache.cs index e57e16b68..a356d31c6 100644 --- a/ArchUnitNETTests/Domain/TestArchitectureCache.cs +++ b/ArchUnitNETTests/Domain/TestArchitectureCache.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -20,4 +20,4 @@ public void Clear() Cache.Clear(); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Domain/TypeTests.cs b/ArchUnitNETTests/Domain/TypeTests.cs index 2478f78ad..ed33da451 100644 --- a/ArchUnitNETTests/Domain/TypeTests.cs +++ b/ArchUnitNETTests/Domain/TypeTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Linq; @@ -13,7 +13,8 @@ namespace ArchUnitNETTests.Domain { public class TypeTests { - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; [Fact] public void TypesAreClassesAndInterfacesAndStructsAndEnums() @@ -23,7 +24,14 @@ public void TypesAreClassesAndInterfacesAndStructsAndEnums() var interfaces = Architecture.Interfaces; var structs = Architecture.Structs; var enums = Architecture.Enums; - Assert.True(types.All(type => classes.Contains(type) || interfaces.Contains(type) || structs.Contains(type) || enums.Contains(type))); + Assert.True( + types.All(type => + classes.Contains(type) + || interfaces.Contains(type) + || structs.Contains(type) + || enums.Contains(type) + ) + ); Assert.True(classes.All(cls => types.Contains(cls))); Assert.True(interfaces.All(intf => types.Contains(intf))); Assert.True(structs.All(str => types.Contains(str))); @@ -35,7 +43,7 @@ public void TypesMustHaveVisibility() { Assert.True(Architecture.Types.All(type => type.Visibility != NotAccessible)); } - + [Fact] public void AssignEnumsCorrectly() { @@ -48,4 +56,4 @@ public void AssignStructsCorrectly() Assert.True(StaticTestTypes.TestStruct is Struct); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Fluent/ArchRuleEqualityTests.cs b/ArchUnitNETTests/Fluent/ArchRuleEqualityTests.cs index 6d14cda06..2c07f43bd 100644 --- a/ArchUnitNETTests/Fluent/ArchRuleEqualityTests.cs +++ b/ArchUnitNETTests/Fluent/ArchRuleEqualityTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Fluent; @@ -13,14 +13,33 @@ namespace ArchUnitNETTests.Fluent { public class ArchRuleEqualityTests { - private readonly IArchRule _rule = Members().That().ArePrivate().Should().BePrivate() - .And(Classes().Should().BeAbstract().Or().Attributes().Should().Exist()).And(Types().Should().BeNested()); + private readonly IArchRule _rule = Members() + .That() + .ArePrivate() + .Should() + .BePrivate() + .And(Classes().Should().BeAbstract().Or().Attributes().Should().Exist()) + .And(Types().Should().BeNested()); - private readonly IArchRule _equalRule = Members().That().ArePrivate().Should().BePrivate() - .And(Classes().Should().BeAbstract().Or().Attributes().Should().Exist()).And(Types().Should().BeNested()); + private readonly IArchRule _equalRule = Members() + .That() + .ArePrivate() + .Should() + .BePrivate() + .And(Classes().Should().BeAbstract().Or().Attributes().Should().Exist()) + .And(Types().Should().BeNested()); - private readonly IArchRule _notEqualRule = Members().That().ArePrivate().Should().BePrivate() - .And(Classes().Should().BeAbstract()).Or().Attributes().Should().Exist().And(Types().Should().BeNested()); + private readonly IArchRule _notEqualRule = Members() + .That() + .ArePrivate() + .Should() + .BePrivate() + .And(Classes().Should().BeAbstract()) + .Or() + .Attributes() + .Should() + .Exist() + .And(Types().Should().BeNested()); [Fact] public void ArchRuleEqualityTest() @@ -30,4 +49,4 @@ public void ArchRuleEqualityTest() Assert.NotEqual(_equalRule, _notEqualRule); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Fluent/DescriptionTests.cs b/ArchUnitNETTests/Fluent/DescriptionTests.cs index 13fd48037..e1cd4f582 100644 --- a/ArchUnitNETTests/Fluent/DescriptionTests.cs +++ b/ArchUnitNETTests/Fluent/DescriptionTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Fluent; @@ -12,18 +12,50 @@ namespace ArchUnitNETTests.Fluent { public class DescriptionTests { - private readonly IArchRule _descriptionTestRule = Classes().That().HaveNameStartingWith("test") - .Because("reason1").And().AreNotNested().Should().BeAbstract().Because("reason2").OrShould().NotBeAbstract() - .And(Types().Should().BeNested()).Or().Attributes().Should().Exist().Because("reason3"); + private readonly IArchRule _descriptionTestRule = Classes() + .That() + .HaveNameStartingWith("test") + .Because("reason1") + .And() + .AreNotNested() + .Should() + .BeAbstract() + .Because("reason2") + .OrShould() + .NotBeAbstract() + .And(Types().Should().BeNested()) + .Or() + .Attributes() + .Should() + .Exist() + .Because("reason3"); - private readonly IArchRule _customDescriptionTestRule1 = Classes().Should().BeAbstract().As(CustomDescription); + private readonly IArchRule _customDescriptionTestRule1 = Classes() + .Should() + .BeAbstract() + .As(CustomDescription); - private readonly IArchRule _customDescriptionTestRule2 = Classes().That().ArePublic().As(CustomDescription) - .And().AreProtected().Should().BePublic().AndShould().BeAbstract().As(CustomDescription); + private readonly IArchRule _customDescriptionTestRule2 = Classes() + .That() + .ArePublic() + .As(CustomDescription) + .And() + .AreProtected() + .Should() + .BePublic() + .AndShould() + .BeAbstract() + .As(CustomDescription); - private readonly IArchRule _combinedCustomDescriptionTestRule = - Classes().Should().BeAbstract().As(CustomDescription).And().Attributes().Should().BeAbstract() - .As(CustomDescription); + private readonly IArchRule _combinedCustomDescriptionTestRule = Classes() + .Should() + .BeAbstract() + .As(CustomDescription) + .And() + .Attributes() + .Should() + .BeAbstract() + .As(CustomDescription); private const string ExpectedDescription = "Classes that have name starting with \"test\" because reason1 and are not nested should be abstract because reason2 or should not be abstract and Types should be nested or Attributes should exist because reason3"; @@ -35,14 +67,22 @@ public void CustomDescriptionTest() { Assert.Equal("Classes " + CustomDescription, _customDescriptionTestRule1.Description); Assert.Equal("Classes " + CustomDescription, _customDescriptionTestRule1.ToString()); - Assert.Equal(CustomDescription + " and are protected " + CustomDescription, - _customDescriptionTestRule2.Description); - Assert.Equal(CustomDescription + " and are protected " + CustomDescription, - _customDescriptionTestRule2.ToString()); - Assert.Equal("Classes " + CustomDescription + " and Attributes " + CustomDescription, - _combinedCustomDescriptionTestRule.Description); - Assert.Equal("Classes " + CustomDescription + " and Attributes " + CustomDescription, - _combinedCustomDescriptionTestRule.ToString()); + Assert.Equal( + CustomDescription + " and are protected " + CustomDescription, + _customDescriptionTestRule2.Description + ); + Assert.Equal( + CustomDescription + " and are protected " + CustomDescription, + _customDescriptionTestRule2.ToString() + ); + Assert.Equal( + "Classes " + CustomDescription + " and Attributes " + CustomDescription, + _combinedCustomDescriptionTestRule.Description + ); + Assert.Equal( + "Classes " + CustomDescription + " and Attributes " + CustomDescription, + _combinedCustomDescriptionTestRule.ToString() + ); } [Fact] @@ -52,4 +92,4 @@ public void DescriptionTest() Assert.Equal(ExpectedDescription, _descriptionTestRule.ToString()); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Fluent/Extensions/BuildMocksExtensions.cs b/ArchUnitNETTests/Fluent/Extensions/BuildMocksExtensions.cs index 01c9d55c7..b7a7b3b19 100644 --- a/ArchUnitNETTests/Fluent/Extensions/BuildMocksExtensions.cs +++ b/ArchUnitNETTests/Fluent/Extensions/BuildMocksExtensions.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -23,8 +23,17 @@ private static Type CreateStubType(this System.Type type) var assembly = type.Assembly.CreateStubAssembly(); var namespc = type.Namespace.CreateStubNamespace(); var visibility = type.GetVisibility(); - return new Type(type.FullName, type.Name, assembly, namespc, visibility, type.IsNested, type.IsGenericType, - true, false); + return new Type( + type.FullName, + type.Name, + assembly, + namespc, + visibility, + type.IsNested, + type.IsGenericType, + true, + false + ); } private static Visibility GetVisibility(this System.Type type) @@ -85,8 +94,17 @@ public static IType CreateStubIType(this System.Type type) public static Type CreateShallowStubType(this Class clazz) { - var type = new Type(clazz.FullName, clazz.Name, clazz.Assembly, clazz.Namespace, clazz.Visibility, - clazz.IsNested, clazz.IsGeneric, clazz.IsStub, clazz.IsCompilerGenerated); + var type = new Type( + clazz.FullName, + clazz.Name, + clazz.Assembly, + clazz.Namespace, + clazz.Visibility, + clazz.IsNested, + clazz.IsGeneric, + clazz.IsStub, + clazz.IsCompilerGenerated + ); type.GenericParameters.AddRange(clazz.GenericParameters); return type; } @@ -101,7 +119,10 @@ private static Namespace CreateStubNamespace(this string namespc) return new Namespace(namespc, new List()); } - public static string BuildMethodMemberName(this string methodName, params System.Type[] parameterType) + public static string BuildMethodMemberName( + this string methodName, + params System.Type[] parameterType + ) { var builder = new StringBuilder(); @@ -127,7 +148,9 @@ public static MethodMember CreateStubMethodMember(this MethodBase methodBase) var visibility = methodBase.GetVisibility(); var declaringType = methodBase.DeclaringType.CreateStubIType(); - var parameters = methodBase.CreateStubParameters().Select(parameter => new TypeInstance(parameter)); + var parameters = methodBase + .CreateStubParameters() + .Select(parameter => new TypeInstance(parameter)); var methodForm = methodBase.GetStubMethodForm(); var isStatic = methodBase.IsStatic; @@ -150,8 +173,20 @@ public static MethodMember CreateStubMethodMember(this MethodBase methodBase) fullName = methodInfo.CreateStubFullName(); } - var methodMember = new MethodMember(methodBase.BuildMockMethodName(), fullName, declaringType, visibility, - returnTypeInstance, methodBase.IsVirtual, methodForm, isGeneric, false, false, false, isStatic); + var methodMember = new MethodMember( + methodBase.BuildMockMethodName(), + fullName, + declaringType, + visibility, + returnTypeInstance, + methodBase.IsVirtual, + methodForm, + isGeneric, + false, + false, + false, + isStatic + ); methodMember.ParameterInstances.AddRange(parameters); return methodMember; @@ -161,13 +196,17 @@ private static string BuildMockMethodName(this MethodBase methodBase) { var stringBuilder = new StringBuilder(methodBase.Name); stringBuilder.Append("("); - stringBuilder.Append(ConstructParameters(methodBase.CreateStubParameters(), methodBase.CallingConvention)); + stringBuilder.Append( + ConstructParameters(methodBase.CreateStubParameters(), methodBase.CallingConvention) + ); stringBuilder.Append(")"); return stringBuilder.ToString(); } - private static string ConstructParameters(IEnumerable parameterTypes, - CallingConventions callingConvention) + private static string ConstructParameters( + IEnumerable parameterTypes, + CallingConventions callingConvention + ) { var stringBuilder = new StringBuilder(); var str1 = ""; @@ -191,26 +230,39 @@ private static string ConstructParameters(IEnumerable parameterTypes, private static List CreateStubParameters(this MethodBase methodInfo) { - return methodInfo.GetParameters().Select(info => (IType)CreateStubIType(info.ParameterType)).ToList(); + return methodInfo + .GetParameters() + .Select(info => (IType)CreateStubIType(info.ParameterType)) + .ToList(); } private static string CreateStubFullName(this MethodInfo methodInfo) { var builder = new StringBuilder(); - builder.Append(methodInfo.ReturnType.FullName).Append(" ").Append(methodInfo.MemberFullName()); + builder + .Append(methodInfo.ReturnType.FullName) + .Append(" ") + .Append(methodInfo.MemberFullName()); methodInfo.MethodSignatureFullName(builder); return builder.ToString(); } - private static string CreateStubFullName(this ConstructorInfo constructorInfo, IType returnType) + private static string CreateStubFullName( + this ConstructorInfo constructorInfo, + IType returnType + ) { var builder = new StringBuilder(); - builder.Append(returnType.FullName).Append(" ").Append(constructorInfo.MemberFullName()); + builder + .Append(returnType.FullName) + .Append(" ") + .Append(constructorInfo.MemberFullName()); constructorInfo.MethodSignatureFullName(builder); return builder.ToString(); } - private static string MemberFullName(this TMethod methodInfo) where TMethod : MethodBase + private static string MemberFullName(this TMethod methodInfo) + where TMethod : MethodBase { if (methodInfo.DeclaringType == null) { @@ -220,7 +272,10 @@ private static string MemberFullName(this TMethod methodInfo) where TMe return methodInfo.DeclaringType.FullName + "::" + methodInfo.Name; } - private static void MethodSignatureFullName(this MethodBase methodBase, StringBuilder stringBuilder) + private static void MethodSignatureFullName( + this MethodBase methodBase, + StringBuilder stringBuilder + ) { stringBuilder.Append("("); if (methodBase.GetParameters().Length != 0) @@ -241,7 +296,8 @@ private static void MethodSignatureFullName(this MethodBase methodBase, StringBu stringBuilder.Append(")"); } - private static Visibility GetVisibility(this TMethod methodInfo) where TMethod : MethodBase + private static Visibility GetVisibility(this TMethod methodInfo) + where TMethod : MethodBase { return methodInfo.IsPublic ? Public : Private; } @@ -258,4 +314,4 @@ private static MethodForm GetStubMethodForm(this TMemberInfo method return methodForm; } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Fluent/FreezeTests.cs b/ArchUnitNETTests/Fluent/FreezeTests.cs index 4093865b0..a69d9f735 100644 --- a/ArchUnitNETTests/Fluent/FreezeTests.cs +++ b/ArchUnitNETTests/Fluent/FreezeTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using ArchUnitNET.Domain; using ArchUnitNET.Fluent; @@ -19,30 +19,47 @@ namespace ArchUnitNETTests.Fluent { public class FreezeTests { - private static readonly Architecture Architecture = - new ArchLoader().LoadAssembly(typeof(FreezeTests).Assembly).Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssembly(typeof(FreezeTests).Assembly) + .Build(); - private readonly IArchRule _frozenRule = - Types().That().Are(typeof(Violation), typeof(Violation2)).Should().NotBePrivate(); + private readonly IArchRule _frozenRule = Types() + .That() + .Are(typeof(Violation), typeof(Violation2)) + .Should() + .NotBePrivate(); - private readonly IArchRule _frozenRule2 = Types().That().Are(typeof(Violation)).Should().BeProtected(); + private readonly IArchRule _frozenRule2 = Types() + .That() + .Are(typeof(Violation)) + .Should() + .BeProtected(); - private readonly IArchRule _failingFrozenRule = - Types().That().Are(typeof(Violation), typeof(Violation2)).Should().BePublic(); + private readonly IArchRule _failingFrozenRule = Types() + .That() + .Are(typeof(Violation), typeof(Violation2)) + .Should() + .BePublic(); - private readonly IArchRule _frozenSliceRule = - SliceRuleDefinition.Slices().Matching("TestAssembly.Slices.(**)").Should() - .NotDependOnEachOther(); + private readonly IArchRule _frozenSliceRule = SliceRuleDefinition + .Slices() + .Matching("TestAssembly.Slices.(**)") + .Should() + .NotDependOnEachOther(); - private readonly IArchRule _failingFrozenSliceRule = - SliceRuleDefinition.Slices().Matching("TestAssembly.Slices.(*)..").Should().NotDependOnEachOther(); + private readonly IArchRule _failingFrozenSliceRule = SliceRuleDefinition + .Slices() + .Matching("TestAssembly.Slices.(*)..") + .Should() + .NotDependOnEachOther(); [Fact] public void PassFrozenRules() { Freeze(_frozenRule).Check(Architecture); Freeze(_frozenRule2).Check(Architecture); - Freeze(_frozenSliceRule).Check(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture); + Freeze(_frozenSliceRule) + .Check(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture); } [Fact] @@ -57,33 +74,42 @@ public void PassFrozenRulesUsingXmlViolationStore() [Fact] public void FailFrozenRule() { - Assert.Throws(() => Freeze(_failingFrozenRule).Check(Architecture)); - Assert.Throws(() => Freeze(_failingFrozenSliceRule).Check(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture)); + Assert.Throws( + () => Freeze(_failingFrozenRule).Check(Architecture) + ); + Assert.Throws( + () => + Freeze(_failingFrozenSliceRule) + .Check(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture) + ); } [Fact] public void FailFrozenRuleUsingXmlViolationStore() { - Assert.Throws(() => - Freeze(_failingFrozenRule, new XmlViolationStore()).Check(Architecture)); - Assert.Throws(() => - Freeze(_failingFrozenSliceRule, new XmlViolationStore()).Check(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture)); + Assert.Throws( + () => Freeze(_failingFrozenRule, new XmlViolationStore()).Check(Architecture) + ); + Assert.Throws( + () => + Freeze(_failingFrozenSliceRule, new XmlViolationStore()) + .Check(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture) + ); } - + [Fact] public void PassFrozenRulesWithCustomViolationStorePath() { - Freeze(_frozenRule,"../../../ArchUnitNET/Storage/CustomPathFrozenRules.json").Check(Architecture); - Freeze(_frozenRule2,"../../../ArchUnitNET/Storage/CustomPathFrozenRules.json").Check(Architecture); - Freeze(_frozenSliceRule,"../../../ArchUnitNET/Storage/CustomPathFrozenRules.json").Check(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture); + Freeze(_frozenRule, "../../../ArchUnitNET/Storage/CustomPathFrozenRules.json") + .Check(Architecture); + Freeze(_frozenRule2, "../../../ArchUnitNET/Storage/CustomPathFrozenRules.json") + .Check(Architecture); + Freeze(_frozenSliceRule, "../../../ArchUnitNET/Storage/CustomPathFrozenRules.json") + .Check(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture); } - private class Violation - { - } + private class Violation { } - private class Violation2 - { - } + private class Violation2 { } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Fluent/MultipleConditionRulesTests.cs b/ArchUnitNETTests/Fluent/MultipleConditionRulesTests.cs index c767995d1..0bb4a4076 100644 --- a/ArchUnitNETTests/Fluent/MultipleConditionRulesTests.cs +++ b/ArchUnitNETTests/Fluent/MultipleConditionRulesTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Linq; using ArchUnitNET.Domain; @@ -17,8 +17,9 @@ namespace ArchUnitNETTests.Fluent { public class MultipleConditionRulesTests { - private static readonly Architecture Architecture = - new ArchLoader().LoadAssemblies(System.Reflection.Assembly.Load("ArchUnitNETTests")).Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssemblies(System.Reflection.Assembly.Load("ArchUnitNETTests")) + .Build(); private readonly Class _failingClass; @@ -35,15 +36,26 @@ public MultipleConditionRulesTests() [Fact] public void AssignCorrectTypeToEvaluationResults() { - var evaluationResults = Classes().That() - .Are(typeof(PassingClass1), typeof(FailingClass), typeof(PassingClass2)).And() - .AreNotPrivate().Should().HaveAnyAttributes(typeof(Test1)).AndShould().HaveAnyAttributes(typeof(Test2)) - .Evaluate(Architecture).ToList(); + var evaluationResults = Classes() + .That() + .Are(typeof(PassingClass1), typeof(FailingClass), typeof(PassingClass2)) + .And() + .AreNotPrivate() + .Should() + .HaveAnyAttributes(typeof(Test1)) + .AndShould() + .HaveAnyAttributes(typeof(Test2)) + .Evaluate(Architecture) + .ToList(); - var passedObjects = evaluationResults.Where(result => result.Passed) - .Select(result => result.EvaluatedObject).ToList(); - var failedObjects = evaluationResults.Where(result => !result.Passed) - .Select(result => result.EvaluatedObject).ToList(); + var passedObjects = evaluationResults + .Where(result => result.Passed) + .Select(result => result.EvaluatedObject) + .ToList(); + var failedObjects = evaluationResults + .Where(result => !result.Passed) + .Select(result => result.EvaluatedObject) + .ToList(); Assert.Equal(2, passedObjects.Count); Assert.Single(failedObjects); @@ -56,26 +68,16 @@ public void AssignCorrectTypeToEvaluationResults() [Test1] [Test2] - internal class PassingClass1 - { - } + internal class PassingClass1 { } [Test1] - internal class FailingClass - { - } + internal class FailingClass { } [Test1] [Test2] - internal class PassingClass2 - { - } + internal class PassingClass2 { } - internal class Test1 : Attribute - { - } + internal class Test1 : Attribute { } - internal class Test2 : Attribute - { - } -} \ No newline at end of file + internal class Test2 : Attribute { } +} diff --git a/ArchUnitNETTests/Fluent/NoErrorReferencingOfTypesOutsideOfArchitectureTests.cs b/ArchUnitNETTests/Fluent/NoErrorReferencingOfTypesOutsideOfArchitectureTests.cs index 127d9c45e..77d5be727 100644 --- a/ArchUnitNETTests/Fluent/NoErrorReferencingOfTypesOutsideOfArchitectureTests.cs +++ b/ArchUnitNETTests/Fluent/NoErrorReferencingOfTypesOutsideOfArchitectureTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System; using System.Linq; @@ -20,14 +20,18 @@ namespace ArchUnitNETTests.Fluent { public class NoErrorReferencingOfTypesOutsideOfArchitectureTests { - private static readonly Architecture Architecture = - new ArchLoader().LoadAssemblies(System.Reflection.Assembly.Load("TestAssembly")).Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssemblies(System.Reflection.Assembly.Load("TestAssembly")) + .Build(); - private readonly System.Type _classNotInArchitecture = typeof(NoErrorReferencingOfTypesOutsideOfArchitectureTests); + private readonly System.Type _classNotInArchitecture = + typeof(NoErrorReferencingOfTypesOutsideOfArchitectureTests); public NoErrorReferencingOfTypesOutsideOfArchitectureTests() { - Assert.Throws(() => Architecture.GetClassOfType(_classNotInArchitecture)); + Assert.Throws( + () => Architecture.GetClassOfType(_classNotInArchitecture) + ); } private static void AssertNoException(Action action) @@ -39,120 +43,247 @@ private static void AssertNoException(Action action) [Fact] public void DependOnAnyTest() { - var rule = Classes().That().Are(typeof(EmptyTestClass)).Should().DependOnAny(_classNotInArchitecture); - var negation = Classes().That().Are(typeof(EmptyTestClass)).Should() + var rule = Classes() + .That() + .Are(typeof(EmptyTestClass)) + .Should() + .DependOnAny(_classNotInArchitecture); + var negation = Classes() + .That() + .Are(typeof(EmptyTestClass)) + .Should() .NotDependOnAny(_classNotInArchitecture); Assert.Throws(() => rule.Check(Architecture)); negation.Check(Architecture); - AssertNoException(() => Classes().That().DependOnAny(_classNotInArchitecture).GetObjects(Architecture)); - AssertNoException(() => - Classes().That().DoNotDependOnAny(_classNotInArchitecture).GetObjects(Architecture)); + AssertNoException( + () => Classes().That().DependOnAny(_classNotInArchitecture).GetObjects(Architecture) + ); + AssertNoException( + () => + Classes() + .That() + .DoNotDependOnAny(_classNotInArchitecture) + .GetObjects(Architecture) + ); } [Fact] public void OnlyDependOnTest() { - var rule = Classes().That().Are(typeof(EmptyTestClass)).Should().OnlyDependOn(_classNotInArchitecture); + var rule = Classes() + .That() + .Are(typeof(EmptyTestClass)) + .Should() + .OnlyDependOn(_classNotInArchitecture); rule.Check(Architecture); - AssertNoException(() => Classes().That().OnlyDependOn(_classNotInArchitecture).GetObjects(Architecture)); + AssertNoException( + () => + Classes().That().OnlyDependOn(_classNotInArchitecture).GetObjects(Architecture) + ); } [Fact] public void OnlyHaveAttributesTest() { - var rule = Classes().That().Are(typeof(EmptyTestClass)).Should() + var rule = Classes() + .That() + .Are(typeof(EmptyTestClass)) + .Should() .OnlyHaveAttributes(_classNotInArchitecture); - var negation = Classes().That().Are(typeof(EmptyTestClass)).Should() + var negation = Classes() + .That() + .Are(typeof(EmptyTestClass)) + .Should() .NotHaveAnyAttributes(_classNotInArchitecture); rule.Check(Architecture); negation.Check(Architecture); - AssertNoException(() => - Classes().That().OnlyHaveAttributes(_classNotInArchitecture).GetObjects(Architecture)); - AssertNoException(() => - Classes().That().DoNotHaveAnyAttributes(_classNotInArchitecture).GetObjects(Architecture)); + AssertNoException( + () => + Classes() + .That() + .OnlyHaveAttributes(_classNotInArchitecture) + .GetObjects(Architecture) + ); + AssertNoException( + () => + Classes() + .That() + .DoNotHaveAnyAttributes(_classNotInArchitecture) + .GetObjects(Architecture) + ); } [Fact] public void HaveAttributeWithArgumentsTest() { - var rule = Classes().That().Are(typeof(EmptyTestClass)).Should() + var rule = Classes() + .That() + .Are(typeof(EmptyTestClass)) + .Should() .HaveAttributeWithArguments(_classNotInArchitecture, Enumerable.Empty()); - var negation = Classes().That().Are(typeof(EmptyTestClass)).Should() + var negation = Classes() + .That() + .Are(typeof(EmptyTestClass)) + .Should() .NotHaveAttributeWithArguments(_classNotInArchitecture, Enumerable.Empty()); Assert.Throws(() => rule.Check(Architecture)); negation.Check(Architecture); - AssertNoException(() => - Classes().That().HaveAttributeWithArguments(_classNotInArchitecture, Enumerable.Empty()) - .GetObjects(Architecture)); - AssertNoException(() => - Classes().That().DoNotHaveAttributeWithArguments(_classNotInArchitecture, Enumerable.Empty()) - .GetObjects(Architecture)); + AssertNoException( + () => + Classes() + .That() + .HaveAttributeWithArguments( + _classNotInArchitecture, + Enumerable.Empty() + ) + .GetObjects(Architecture) + ); + AssertNoException( + () => + Classes() + .That() + .DoNotHaveAttributeWithArguments( + _classNotInArchitecture, + Enumerable.Empty() + ) + .GetObjects(Architecture) + ); } [Fact] public void HaveAttributeWithNamedArgumentsTest() { - var rule = Classes().That().Are(typeof(EmptyTestClass)).Should() - .HaveAttributeWithNamedArguments(_classNotInArchitecture, Enumerable.Empty<(string, object)>()); - var negation = Classes().That().Are(typeof(EmptyTestClass)).Should() - .NotHaveAttributeWithNamedArguments(_classNotInArchitecture, Enumerable.Empty<(string, object)>()); + var rule = Classes() + .That() + .Are(typeof(EmptyTestClass)) + .Should() + .HaveAttributeWithNamedArguments( + _classNotInArchitecture, + Enumerable.Empty<(string, object)>() + ); + var negation = Classes() + .That() + .Are(typeof(EmptyTestClass)) + .Should() + .NotHaveAttributeWithNamedArguments( + _classNotInArchitecture, + Enumerable.Empty<(string, object)>() + ); Assert.Throws(() => rule.Check(Architecture)); negation.Check(Architecture); - AssertNoException(() => - Classes().That() - .HaveAttributeWithNamedArguments(_classNotInArchitecture, Enumerable.Empty<(string, object)>()) - .GetObjects(Architecture)); - AssertNoException(() => - Classes().That() - .DoNotHaveAttributeWithNamedArguments(_classNotInArchitecture, Enumerable.Empty<(string, object)>()) - .GetObjects(Architecture)); + AssertNoException( + () => + Classes() + .That() + .HaveAttributeWithNamedArguments( + _classNotInArchitecture, + Enumerable.Empty<(string, object)>() + ) + .GetObjects(Architecture) + ); + AssertNoException( + () => + Classes() + .That() + .DoNotHaveAttributeWithNamedArguments( + _classNotInArchitecture, + Enumerable.Empty<(string, object)>() + ) + .GetObjects(Architecture) + ); } [Fact] public void AreBeTest() { - var rule = Classes().That().Are(typeof(EmptyTestClass)).Should() + var rule = Classes() + .That() + .Are(typeof(EmptyTestClass)) + .Should() .Be(_classNotInArchitecture); - var negation = Classes().That().Are(typeof(EmptyTestClass)).Should() + var negation = Classes() + .That() + .Are(typeof(EmptyTestClass)) + .Should() .NotBe(_classNotInArchitecture); Assert.Throws(() => rule.Check(Architecture)); negation.Check(Architecture); - AssertNoException(() => Classes().That().Are(_classNotInArchitecture).GetObjects(Architecture)); - AssertNoException(() => Classes().That().AreNot(_classNotInArchitecture).GetObjects(Architecture)); + AssertNoException( + () => Classes().That().Are(_classNotInArchitecture).GetObjects(Architecture) + ); + AssertNoException( + () => Classes().That().AreNot(_classNotInArchitecture).GetObjects(Architecture) + ); } - + [Fact] public void AreAssignableTest() { - var rule = Classes().That().Are(typeof(EmptyTestClass)).Should() + var rule = Classes() + .That() + .Are(typeof(EmptyTestClass)) + .Should() .BeAssignableTo(_classNotInArchitecture); - var negation = Classes().That().Are(typeof(EmptyTestClass)).Should() + var negation = Classes() + .That() + .Are(typeof(EmptyTestClass)) + .Should() .NotBeAssignableTo(_classNotInArchitecture); Assert.Throws(() => rule.Check(Architecture)); negation.Check(Architecture); - AssertNoException(() => Classes().That().AreAssignableTo(_classNotInArchitecture).GetObjects(Architecture)); - AssertNoException(() => Classes().That().AreNotAssignableTo(_classNotInArchitecture).GetObjects(Architecture)); + AssertNoException( + () => + Classes() + .That() + .AreAssignableTo(_classNotInArchitecture) + .GetObjects(Architecture) + ); + AssertNoException( + () => + Classes() + .That() + .AreNotAssignableTo(_classNotInArchitecture) + .GetObjects(Architecture) + ); } [Fact] public void ImplementInterfaceTest() { - var rule = Classes().That().Are(typeof(EmptyTestClass)).Should() + var rule = Classes() + .That() + .Are(typeof(EmptyTestClass)) + .Should() .ImplementInterface(_classNotInArchitecture); - var negation = Classes().That().Are(typeof(EmptyTestClass)).Should() + var negation = Classes() + .That() + .Are(typeof(EmptyTestClass)) + .Should() .NotImplementInterface(_classNotInArchitecture); Assert.Throws(() => rule.Check(Architecture)); negation.Check(Architecture); - AssertNoException(() => Classes().That().ImplementInterface(_classNotInArchitecture).GetObjects(Architecture)); - AssertNoException(() => Classes().That().DoNotImplementInterface(_classNotInArchitecture).GetObjects(Architecture)); + AssertNoException( + () => + Classes() + .That() + .ImplementInterface(_classNotInArchitecture) + .GetObjects(Architecture) + ); + AssertNoException( + () => + Classes() + .That() + .DoNotImplementInterface(_classNotInArchitecture) + .GetObjects(Architecture) + ); } [Fact] @@ -163,10 +294,19 @@ public void DeclaredInTest() Assert.Throws(() => rule.Check(Architecture)); negation.Check(Architecture); - AssertNoException(() => Members().That().AreDeclaredIn(_classNotInArchitecture).GetObjects(Architecture)); - AssertNoException(() => Members().That().AreNotDeclaredIn(_classNotInArchitecture).GetObjects(Architecture)); + AssertNoException( + () => + Members().That().AreDeclaredIn(_classNotInArchitecture).GetObjects(Architecture) + ); + AssertNoException( + () => + Members() + .That() + .AreNotDeclaredIn(_classNotInArchitecture) + .GetObjects(Architecture) + ); } - + [Fact] public void CalledByTest() { @@ -175,8 +315,20 @@ public void CalledByTest() Assert.Throws(() => rule.Check(Architecture)); negation.Check(Architecture); - AssertNoException(() => MethodMembers().That().AreCalledBy(_classNotInArchitecture).GetObjects(Architecture)); - AssertNoException(() => MethodMembers().That().AreNotCalledBy(_classNotInArchitecture).GetObjects(Architecture)); + AssertNoException( + () => + MethodMembers() + .That() + .AreCalledBy(_classNotInArchitecture) + .GetObjects(Architecture) + ); + AssertNoException( + () => + MethodMembers() + .That() + .AreNotCalledBy(_classNotInArchitecture) + .GetObjects(Architecture) + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Fluent/ObjectConditionsErrorMessagesTests.cs b/ArchUnitNETTests/Fluent/ObjectConditionsErrorMessagesTests.cs index c598336ae..d357ee453 100644 --- a/ArchUnitNETTests/Fluent/ObjectConditionsErrorMessagesTests.cs +++ b/ArchUnitNETTests/Fluent/ObjectConditionsErrorMessagesTests.cs @@ -16,7 +16,8 @@ namespace ArchUnitNETTests.Fluent { public class ObjectConditionsErrorMessagesTests { - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture; private void AssertFailsWithErrorMessage(IArchRule rule, string errorMessage) { @@ -28,36 +29,60 @@ private void AssertFailsWithErrorMessage(IArchRule rule, string errorMessage) [Fact] public void OnlyListForbiddenITypesInError() { - var rule = Classes().That().Are(typeof(Class1)).Should().NotDependOnAnyTypesThat().Are(typeof(Class2)); - AssertFailsWithErrorMessage(rule, "TestAssembly.Class1 does depend on TestAssembly.Class2"); + var rule = Classes() + .That() + .Are(typeof(Class1)) + .Should() + .NotDependOnAnyTypesThat() + .Are(typeof(Class2)); + AssertFailsWithErrorMessage( + rule, + "TestAssembly.Class1 does depend on TestAssembly.Class2" + ); } [Fact] public void OnlyListForbiddenTypesInError() { var rule = Classes().That().Are(typeof(Class1)).Should().NotDependOnAny(typeof(Class2)); - AssertFailsWithErrorMessage(rule, "TestAssembly.Class1 does depend on TestAssembly.Class2"); + AssertFailsWithErrorMessage( + rule, + "TestAssembly.Class1 does depend on TestAssembly.Class2" + ); } [Fact] public void OnlyListForbiddenMethodsInErrors() { - var rule = MethodMembers().That().AreDeclaredIn(typeof(ClassCallingOtherMethod)).Should() + var rule = MethodMembers() + .That() + .AreDeclaredIn(typeof(ClassCallingOtherMethod)) + .Should() .NotCallAny(MethodMembers().That().AreDeclaredIn(typeof(Class1))); - AssertFailsWithErrorMessage(rule, - "System.Void TestAssembly.ClassCallingOtherMethod::CallingOther(TestAssembly.Class1)" + - " does call System.String TestAssembly.Class1::AccessClass2(System.Int32)"); + AssertFailsWithErrorMessage( + rule, + "System.Void TestAssembly.ClassCallingOtherMethod::CallingOther(TestAssembly.Class1)" + + " does call System.String TestAssembly.Class1::AccessClass2(System.Int32)" + ); } [Fact] public void OnlyListForbiddenMethodsFromEnumerableInErrors() { - var methodsInClass1 = MethodMembers().That().AreDeclaredIn(typeof(Class1)).GetObjects(Architecture); - var rule = MethodMembers().That().AreDeclaredIn(typeof(ClassCallingOtherMethod)).Should() + var methodsInClass1 = MethodMembers() + .That() + .AreDeclaredIn(typeof(Class1)) + .GetObjects(Architecture); + var rule = MethodMembers() + .That() + .AreDeclaredIn(typeof(ClassCallingOtherMethod)) + .Should() .NotCallAny(methodsInClass1); - AssertFailsWithErrorMessage(rule, - "System.Void TestAssembly.ClassCallingOtherMethod::CallingOther(TestAssembly.Class1)" + - " does call System.String TestAssembly.Class1::AccessClass2(System.Int32)"); + AssertFailsWithErrorMessage( + rule, + "System.Void TestAssembly.ClassCallingOtherMethod::CallingOther(TestAssembly.Class1)" + + " does call System.String TestAssembly.Class1::AccessClass2(System.Int32)" + ); } } } diff --git a/ArchUnitNETTests/Fluent/PlantUml/PlantUmlFluentComponentDiagramTests.cs b/ArchUnitNETTests/Fluent/PlantUml/PlantUmlFluentComponentDiagramTests.cs index 5e4b27d2f..b7723b342 100644 --- a/ArchUnitNETTests/Fluent/PlantUml/PlantUmlFluentComponentDiagramTests.cs +++ b/ArchUnitNETTests/Fluent/PlantUml/PlantUmlFluentComponentDiagramTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System; using System.Collections.Generic; @@ -21,8 +21,9 @@ namespace ArchUnitNETTests.Fluent.PlantUml { public class PlantUmlFluentComponentDiagramTests { - private static readonly Architecture Architecture = - new ArchLoader().LoadAssembly(typeof(PlantUmlFluentComponentDiagramTests).Assembly).Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssembly(typeof(PlantUmlFluentComponentDiagramTests).Assembly) + .Build(); private static readonly List Dependencies = new List { @@ -41,42 +42,75 @@ public class PlantUmlFluentComponentDiagramTests public void ComponentDiagramFromSlicesTest() { var sliceRule = SliceRuleDefinition.Slices().Matching("ArchUnitNETTests.(*)."); - var uml1 = ComponentDiagram().WithDependenciesFromSlices(sliceRule, Architecture).AsString(); - var uml2 = ComponentDiagram().WithDependenciesFromSlices(sliceRule.GetObjects(Architecture)).AsString(); + var uml1 = ComponentDiagram() + .WithDependenciesFromSlices(sliceRule, Architecture) + .AsString(); + var uml2 = ComponentDiagram() + .WithDependenciesFromSlices(sliceRule.GetObjects(Architecture)) + .AsString(); Assert.NotEmpty(uml1); Assert.NotEmpty(uml2); var arch1 = new ArchLoader().LoadAssembly(typeof(Architecture).Assembly).Build(); - var sliceRule1 = SliceRuleDefinition.Slices().MatchingWithPackages("ArchUnitNET.(*).(*).(*)"); + var sliceRule1 = SliceRuleDefinition + .Slices() + .MatchingWithPackages("ArchUnitNET.(*).(*).(*)"); const string path = "../../../Fluent/PlantUml/Test.puml"; var g = new GenerationOptions() { C4Style = true, LimitDependencies = true }; - ComponentDiagram().WithDependenciesFromSlices(sliceRule1.GetObjects(arch1), g).WriteToFile(path); + ComponentDiagram() + .WithDependenciesFromSlices(sliceRule1.GetObjects(arch1), g) + .WriteToFile(path); File.Delete(path); } [Fact] public void ComponentDiagramFromTypesTest() { - var typeRule = ArchRuleDefinition.Types().That().Are(typeof(PlantUmlFluentComponentDiagramTests)); - var uml1 = ComponentDiagram().WithDependenciesFromTypes(typeRule, Architecture) - .AsString(new RenderOptions {OmitClassFields = true}); - var uml2 = ComponentDiagram().WithDependenciesFromTypes(typeRule.GetObjects(Architecture)) - .AsString(new RenderOptions {OmitClassFields = true}); + var typeRule = ArchRuleDefinition + .Types() + .That() + .Are(typeof(PlantUmlFluentComponentDiagramTests)); + var uml1 = ComponentDiagram() + .WithDependenciesFromTypes(typeRule, Architecture) + .AsString(new RenderOptions { OmitClassFields = true }); + var uml2 = ComponentDiagram() + .WithDependenciesFromTypes(typeRule.GetObjects(Architecture)) + .AsString(new RenderOptions { OmitClassFields = true }); var uml3 = ComponentDiagram() - .WithDependenciesFromTypes(typeRule, Architecture, - new GenerationOptions {IncludeDependenciesToOther = true}).AsString(); - var uml4 = ComponentDiagram().WithDependenciesFromTypes(typeRule.GetObjects(Architecture), - new GenerationOptions {IncludeDependenciesToOther = true}).AsString(); + .WithDependenciesFromTypes( + typeRule, + Architecture, + new GenerationOptions { IncludeDependenciesToOther = true } + ) + .AsString(); + var uml4 = ComponentDiagram() + .WithDependenciesFromTypes( + typeRule.GetObjects(Architecture), + new GenerationOptions { IncludeDependenciesToOther = true } + ) + .AsString(); Assert.NotEmpty(uml1); Assert.NotEmpty(uml2); Assert.NotEmpty(uml3); Assert.NotEmpty(uml4); - var expectedUml = "@startuml" + Environment.NewLine + Environment.NewLine + - "!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml" + - Environment.NewLine + Environment.NewLine + - "HIDE_STEREOTYPE()" + Environment.NewLine + Environment.NewLine + "class \"" + - typeof(PlantUmlFluentComponentDiagramTests).FullName + - "\" {" + Environment.NewLine + "}" + Environment.NewLine + "@enduml" + Environment.NewLine; + var expectedUml = + "@startuml" + + Environment.NewLine + + Environment.NewLine + + "!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml" + + Environment.NewLine + + Environment.NewLine + + "HIDE_STEREOTYPE()" + + Environment.NewLine + + Environment.NewLine + + "class \"" + + typeof(PlantUmlFluentComponentDiagramTests).FullName + + "\" {" + + Environment.NewLine + + "}" + + Environment.NewLine + + "@enduml" + + Environment.NewLine; Assert.Equal(expectedUml, uml1); Assert.Equal(expectedUml, uml2); } @@ -84,50 +118,78 @@ public void ComponentDiagramFromTypesTest() [Fact] public void ComponentDiagramFromCustomDependenciesTest() { - var classesWithoutDependencies = new[] {new PlantUmlClass("X")}; - var uml = ComponentDiagram().WithElements(Dependencies.Concat(classesWithoutDependencies)).AsString(); + var classesWithoutDependencies = new[] { new PlantUmlClass("X") }; + var uml = ComponentDiagram() + .WithElements(Dependencies.Concat(classesWithoutDependencies)) + .AsString(); Assert.NotEmpty(uml); - var expectedUml = "@startuml" + Environment.NewLine + Environment.NewLine + - "!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml" + - Environment.NewLine + Environment.NewLine + - "HIDE_STEREOTYPE()" + Environment.NewLine + Environment.NewLine + - "class \"X\" {" + Environment.NewLine + "}" + - Environment.NewLine + "[a] --|> [b]" + - Environment.NewLine + "[b] <-[#red]> [c]" + - Environment.NewLine + "c ..> d" + - Environment.NewLine + "[d] \"1\" --|> \"many\" [e]" + - Environment.NewLine + "[e] -[#red]> f" + - Environment.NewLine + "f -[#blue]> [g]" + - Environment.NewLine + "g -[#green]> h" + - Environment.NewLine + "[h] --> [i]" + - Environment.NewLine + "i --|> a" + - Environment.NewLine + "@enduml" + - Environment.NewLine; + var expectedUml = + "@startuml" + + Environment.NewLine + + Environment.NewLine + + "!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml" + + Environment.NewLine + + Environment.NewLine + + "HIDE_STEREOTYPE()" + + Environment.NewLine + + Environment.NewLine + + "class \"X\" {" + + Environment.NewLine + + "}" + + Environment.NewLine + + "[a] --|> [b]" + + Environment.NewLine + + "[b] <-[#red]> [c]" + + Environment.NewLine + + "c ..> d" + + Environment.NewLine + + "[d] \"1\" --|> \"many\" [e]" + + Environment.NewLine + + "[e] -[#red]> f" + + Environment.NewLine + + "f -[#blue]> [g]" + + Environment.NewLine + + "g -[#green]> h" + + Environment.NewLine + + "[h] --> [i]" + + Environment.NewLine + + "i --|> a" + + Environment.NewLine + + "@enduml" + + Environment.NewLine; Assert.Equal(expectedUml, uml); } [Fact] public void ComponentDiagramWriteToFileTest() { - var classesWithoutDependencies = new[] {new PlantUmlClass("X")}; + var classesWithoutDependencies = new[] { new PlantUmlClass("X") }; const string path = "temp/testUml.puml"; var expectedUml = new[] - {"@startuml", "", - "!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml", - "", "HIDE_STEREOTYPE()", "", - "class \"X\" {", "}", - "[a] --|> [b]", - "[b] <-[#red]> [c]", - "c ..> d", - "[d] \"1\" --|> \"many\" [e]", - "[e] -[#red]> f", - "f -[#blue]> [g]", - "g -[#green]> h", - "[h] --> [i]", - "i --|> a", - "@enduml"}; - ComponentDiagram().WithElements(Dependencies.Concat(classesWithoutDependencies)).WriteToFile(path); + { + "@startuml", + "", + "!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml", + "", + "HIDE_STEREOTYPE()", + "", + "class \"X\" {", + "}", + "[a] --|> [b]", + "[b] <-[#red]> [c]", + "c ..> d", + "[d] \"1\" --|> \"many\" [e]", + "[e] -[#red]> f", + "f -[#blue]> [g]", + "g -[#green]> h", + "[h] --> [i]", + "i --|> a", + "@enduml" + }; + ComponentDiagram() + .WithElements(Dependencies.Concat(classesWithoutDependencies)) + .WriteToFile(path); Assert.True(File.Exists(path)); using (var sr = File.OpenText(path)) @@ -149,4 +211,4 @@ public void ComponentDiagramWriteToFileTest() } } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Fluent/RuleEvaluationTests.cs b/ArchUnitNETTests/Fluent/RuleEvaluationTests.cs index 6d944f3d2..0d72252f2 100644 --- a/ArchUnitNETTests/Fluent/RuleEvaluationTests.cs +++ b/ArchUnitNETTests/Fluent/RuleEvaluationTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -20,129 +20,214 @@ public class RuleEvaluationTests private const string NoClassName = "NotTheNameOfAnyClass_1592479214"; private const string ExpectedTrueArchRuleErrorMessage = "All Evaluations passed"; - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; - - private static readonly IArchRule TrueArchRule1 = Classes().That().ArePrivate().Should().BePrivate(); + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; + + private static readonly IArchRule TrueArchRule1 = Classes() + .That() + .ArePrivate() + .Should() + .BePrivate(); private static readonly IArchRule TrueArchRule2 = Members().Should().Exist(); - private static readonly IArchRule WrongArchRule1 = - Classes().That().Are(StaticTestTypes.PublicTestClass).Should().BePrivate(); - - private static readonly IArchRule WrongArchRule2 = Classes().That().Are(StaticTestTypes.PublicTestClass) - .Should().BePrivate().AndShould().BePublic(); - - private static readonly IArchRule WrongArchRule3 = Classes().That().Are(StaticTestTypes.PublicTestClass) - .Should().BePrivate().AndShould().BePublic().OrShould().BeProtected(); - - private static readonly IArchRule WrongArchRule4 = Classes().That().HaveName(NoClassName).Should().Exist(); - - private static readonly IArchRule WrongArchRule5 = - Classes().That().HaveName(NoClassName).Should().BePrivate().AndShould().Exist(); - - private static readonly IArchRule WrongArchRule6 = - Classes().That().Are(StaticTestTypes.PublicTestClass).Should().NotExist(); - - private static readonly IArchRule WrongArchRule7 = Classes().That().Are(StaticTestTypes.PublicTestClass) - .Should().NotExist().AndShould().BePublic(); - - private static readonly IArchRule WrongArchRule8 = Classes().That().Are(StaticTestTypes.PublicTestClass) - .Should().NotExist().OrShould().BePrivate(); - - private static readonly IArchRule WrongArchRule1AndWrongArchRule3 = WrongArchRule1.And(WrongArchRule3); - private static readonly IArchRule WrongArchRule4AndWrongArchRule8 = WrongArchRule4.And(WrongArchRule8); - - private static readonly IArchRule WrongArchRule9 = - Classes().That().HaveName(NoClassName).Should().BePrivate(); - + private static readonly IArchRule WrongArchRule1 = Classes() + .That() + .Are(StaticTestTypes.PublicTestClass) + .Should() + .BePrivate(); + + private static readonly IArchRule WrongArchRule2 = Classes() + .That() + .Are(StaticTestTypes.PublicTestClass) + .Should() + .BePrivate() + .AndShould() + .BePublic(); + + private static readonly IArchRule WrongArchRule3 = Classes() + .That() + .Are(StaticTestTypes.PublicTestClass) + .Should() + .BePrivate() + .AndShould() + .BePublic() + .OrShould() + .BeProtected(); + + private static readonly IArchRule WrongArchRule4 = Classes() + .That() + .HaveName(NoClassName) + .Should() + .Exist(); + + private static readonly IArchRule WrongArchRule5 = Classes() + .That() + .HaveName(NoClassName) + .Should() + .BePrivate() + .AndShould() + .Exist(); + + private static readonly IArchRule WrongArchRule6 = Classes() + .That() + .Are(StaticTestTypes.PublicTestClass) + .Should() + .NotExist(); + + private static readonly IArchRule WrongArchRule7 = Classes() + .That() + .Are(StaticTestTypes.PublicTestClass) + .Should() + .NotExist() + .AndShould() + .BePublic(); + + private static readonly IArchRule WrongArchRule8 = Classes() + .That() + .Are(StaticTestTypes.PublicTestClass) + .Should() + .NotExist() + .OrShould() + .BePrivate(); + + private static readonly IArchRule WrongArchRule1AndWrongArchRule3 = WrongArchRule1.And( + WrongArchRule3 + ); + private static readonly IArchRule WrongArchRule4AndWrongArchRule8 = WrongArchRule4.And( + WrongArchRule8 + ); + + private static readonly IArchRule WrongArchRule9 = Classes() + .That() + .HaveName(NoClassName) + .Should() + .BePrivate(); private readonly string _expectedWrongArchRule1AndWrongArchRule3ErrorMessage = - "\"Classes that are \"ArchUnitNETTests.Domain.PublicTestClass\" should be private\" failed:" + - NewLine + "\tArchUnitNETTests.Domain.PublicTestClass is public" + NewLine + - NewLine + - "\"Classes that are \"ArchUnitNETTests.Domain.PublicTestClass\" should be private and should be public or should be protected\" failed:" + - NewLine + "\tArchUnitNETTests.Domain.PublicTestClass is public" + - NewLine + NewLine; + "\"Classes that are \"ArchUnitNETTests.Domain.PublicTestClass\" should be private\" failed:" + + NewLine + + "\tArchUnitNETTests.Domain.PublicTestClass is public" + + NewLine + + NewLine + + "\"Classes that are \"ArchUnitNETTests.Domain.PublicTestClass\" should be private and should be public or should be protected\" failed:" + + NewLine + + "\tArchUnitNETTests.Domain.PublicTestClass is public" + + NewLine + + NewLine; private readonly string _expectedWrongArchRule1ErrorMessage = - "\"Classes that are \"ArchUnitNETTests.Domain.PublicTestClass\" should be private\" failed:" + - NewLine + "\tArchUnitNETTests.Domain.PublicTestClass is public" + NewLine + - NewLine; - + "\"Classes that are \"ArchUnitNETTests.Domain.PublicTestClass\" should be private\" failed:" + + NewLine + + "\tArchUnitNETTests.Domain.PublicTestClass is public" + + NewLine + + NewLine; private readonly string _expectedWrongArchRule2ErrorMessage = - "\"Classes that are \"ArchUnitNETTests.Domain.PublicTestClass\" should be private and should be public\" failed:" + - NewLine + "\tArchUnitNETTests.Domain.PublicTestClass is public" + NewLine + - NewLine; + "\"Classes that are \"ArchUnitNETTests.Domain.PublicTestClass\" should be private and should be public\" failed:" + + NewLine + + "\tArchUnitNETTests.Domain.PublicTestClass is public" + + NewLine + + NewLine; private readonly string _expectedWrongArchRule3ErrorMessage = - "\"Classes that are \"ArchUnitNETTests.Domain.PublicTestClass\" should be private and should be public or should be protected\" failed:" + - NewLine + "\tArchUnitNETTests.Domain.PublicTestClass is public" + - NewLine + NewLine; + "\"Classes that are \"ArchUnitNETTests.Domain.PublicTestClass\" should be private and should be public or should be protected\" failed:" + + NewLine + + "\tArchUnitNETTests.Domain.PublicTestClass is public" + + NewLine + + NewLine; private readonly string _expectedWrongArchRule4AndWrongArchRule8ErrorMessage = - "\"Classes that have name \"NotTheNameOfAnyClass_1592479214\" should exist\" failed:" + - NewLine + "\tThere are no objects matching the criteria" + NewLine + - NewLine + - "\"Classes that are \"ArchUnitNETTests.Domain.PublicTestClass\" should not exist or should be private\" failed:" + - NewLine + "\tArchUnitNETTests.Domain.PublicTestClass does exist and is public" + - NewLine + NewLine; + "\"Classes that have name \"NotTheNameOfAnyClass_1592479214\" should exist\" failed:" + + NewLine + + "\tThere are no objects matching the criteria" + + NewLine + + NewLine + + "\"Classes that are \"ArchUnitNETTests.Domain.PublicTestClass\" should not exist or should be private\" failed:" + + NewLine + + "\tArchUnitNETTests.Domain.PublicTestClass does exist and is public" + + NewLine + + NewLine; private readonly string _expectedWrongArchRule4ErrorMessage = - "\"Classes that have name \"NotTheNameOfAnyClass_1592479214\" should exist\" failed:" + - NewLine + "\tThere are no objects matching the criteria" + NewLine + - NewLine; + "\"Classes that have name \"NotTheNameOfAnyClass_1592479214\" should exist\" failed:" + + NewLine + + "\tThere are no objects matching the criteria" + + NewLine + + NewLine; private readonly string _expectedWrongArchRule5ErrorMessage = - "\"Classes that have name \"NotTheNameOfAnyClass_1592479214\" should be private and should exist\" failed:" + - NewLine + "\tThere are no objects matching the criteria" + NewLine + - NewLine; + "\"Classes that have name \"NotTheNameOfAnyClass_1592479214\" should be private and should exist\" failed:" + + NewLine + + "\tThere are no objects matching the criteria" + + NewLine + + NewLine; private readonly string _expectedWrongArchRule6ErrorMessage = - "\"Classes that are \"ArchUnitNETTests.Domain.PublicTestClass\" should not exist\" failed:" + - NewLine + "\tArchUnitNETTests.Domain.PublicTestClass does exist" + NewLine + - NewLine; + "\"Classes that are \"ArchUnitNETTests.Domain.PublicTestClass\" should not exist\" failed:" + + NewLine + + "\tArchUnitNETTests.Domain.PublicTestClass does exist" + + NewLine + + NewLine; private readonly string _expectedWrongArchRule7ErrorMessage = - "\"Classes that are \"ArchUnitNETTests.Domain.PublicTestClass\" should not exist and should be public\" failed:" + - NewLine + "\tArchUnitNETTests.Domain.PublicTestClass does exist" + NewLine + - NewLine; + "\"Classes that are \"ArchUnitNETTests.Domain.PublicTestClass\" should not exist and should be public\" failed:" + + NewLine + + "\tArchUnitNETTests.Domain.PublicTestClass does exist" + + NewLine + + NewLine; private readonly string _expectedWrongArchRule8ErrorMessage = - "\"Classes that are \"ArchUnitNETTests.Domain.PublicTestClass\" should not exist or should be private\" failed:" + - NewLine + "\tArchUnitNETTests.Domain.PublicTestClass does exist and is public" + - NewLine + NewLine; - - private readonly string _expectedWrongArchRule9ErrorMessage = "\"Classes that have name \"NotTheNameOfAnyClass_1592479214\" should be private\" failed:" + NewLine + - "\tThe rule requires positive evaluation, not just absence of violations. Use WithoutRequiringPositiveResults() or improve your rule's predicates." + - NewLine + NewLine; + "\"Classes that are \"ArchUnitNETTests.Domain.PublicTestClass\" should not exist or should be private\" failed:" + + NewLine + + "\tArchUnitNETTests.Domain.PublicTestClass does exist and is public" + + NewLine + + NewLine; + + private readonly string _expectedWrongArchRule9ErrorMessage = + "\"Classes that have name \"NotTheNameOfAnyClass_1592479214\" should be private\" failed:" + + NewLine + + "\tThe rule requires positive evaluation, not just absence of violations. Use WithoutRequiringPositiveResults() or improve your rule's predicates." + + NewLine + + NewLine; [Fact] public void AssertArchRuleTest() { ArchRuleAssert.CheckRule(Architecture, TrueArchRule1); ArchRuleAssert.CheckRule(Architecture, TrueArchRule2); - var exception1 = - Assert.Throws(() => ArchRuleAssert.CheckRule(Architecture, WrongArchRule1)); - var exception2 = - Assert.Throws(() => ArchRuleAssert.CheckRule(Architecture, WrongArchRule2)); - var exception3 = - Assert.Throws(() => ArchRuleAssert.CheckRule(Architecture, WrongArchRule3)); - var exception4 = - Assert.Throws(() => ArchRuleAssert.CheckRule(Architecture, WrongArchRule4)); - var exception5 = - Assert.Throws(() => ArchRuleAssert.CheckRule(Architecture, WrongArchRule5)); - var exception6 = - Assert.Throws(() => ArchRuleAssert.CheckRule(Architecture, WrongArchRule6)); - var exception7 = - Assert.Throws(() => ArchRuleAssert.CheckRule(Architecture, WrongArchRule7)); - var exception8 = - Assert.Throws(() => ArchRuleAssert.CheckRule(Architecture, WrongArchRule8)); - var exception1And3 = Assert.Throws(() => - ArchRuleAssert.CheckRule(Architecture, WrongArchRule1AndWrongArchRule3)); - var exception4And8 = Assert.Throws(() => - ArchRuleAssert.CheckRule(Architecture, WrongArchRule4AndWrongArchRule8)); - var exception9 = - Assert.Throws(() => ArchRuleAssert.CheckRule(Architecture, WrongArchRule9)); + var exception1 = Assert.Throws( + () => ArchRuleAssert.CheckRule(Architecture, WrongArchRule1) + ); + var exception2 = Assert.Throws( + () => ArchRuleAssert.CheckRule(Architecture, WrongArchRule2) + ); + var exception3 = Assert.Throws( + () => ArchRuleAssert.CheckRule(Architecture, WrongArchRule3) + ); + var exception4 = Assert.Throws( + () => ArchRuleAssert.CheckRule(Architecture, WrongArchRule4) + ); + var exception5 = Assert.Throws( + () => ArchRuleAssert.CheckRule(Architecture, WrongArchRule5) + ); + var exception6 = Assert.Throws( + () => ArchRuleAssert.CheckRule(Architecture, WrongArchRule6) + ); + var exception7 = Assert.Throws( + () => ArchRuleAssert.CheckRule(Architecture, WrongArchRule7) + ); + var exception8 = Assert.Throws( + () => ArchRuleAssert.CheckRule(Architecture, WrongArchRule8) + ); + var exception1And3 = Assert.Throws( + () => ArchRuleAssert.CheckRule(Architecture, WrongArchRule1AndWrongArchRule3) + ); + var exception4And8 = Assert.Throws( + () => ArchRuleAssert.CheckRule(Architecture, WrongArchRule4AndWrongArchRule8) + ); + var exception9 = Assert.Throws( + () => ArchRuleAssert.CheckRule(Architecture, WrongArchRule9) + ); Assert.Equal(_expectedWrongArchRule1ErrorMessage, exception1.Message); Assert.Equal(_expectedWrongArchRule2ErrorMessage, exception2.Message); @@ -152,10 +237,15 @@ public void AssertArchRuleTest() Assert.Equal(_expectedWrongArchRule6ErrorMessage, exception6.Message); Assert.Equal(_expectedWrongArchRule7ErrorMessage, exception7.Message); Assert.Equal(_expectedWrongArchRule8ErrorMessage, exception8.Message); - Assert.Equal(_expectedWrongArchRule1AndWrongArchRule3ErrorMessage, exception1And3.Message); - Assert.Equal(_expectedWrongArchRule4AndWrongArchRule8ErrorMessage, exception4And8.Message); + Assert.Equal( + _expectedWrongArchRule1AndWrongArchRule3ErrorMessage, + exception1And3.Message + ); + Assert.Equal( + _expectedWrongArchRule4AndWrongArchRule8ErrorMessage, + exception4And8.Message + ); Assert.Equal(_expectedWrongArchRule9ErrorMessage, exception9.Message); - } [Fact] @@ -163,26 +253,36 @@ public void CheckArchRuleTest() { TrueArchRule1.Check(Architecture); TrueArchRule2.Check(Architecture); - var exception1 = - Assert.Throws(() => WrongArchRule1.Check(Architecture)); - var exception2 = - Assert.Throws(() => WrongArchRule2.Check(Architecture)); - var exception3 = - Assert.Throws(() => WrongArchRule3.Check(Architecture)); - var exception4 = - Assert.Throws(() => WrongArchRule4.Check(Architecture)); - var exception5 = - Assert.Throws(() => WrongArchRule5.Check(Architecture)); - var exception6 = - Assert.Throws(() => WrongArchRule6.Check(Architecture)); - var exception7 = - Assert.Throws(() => WrongArchRule7.Check(Architecture)); - var exception8 = - Assert.Throws(() => WrongArchRule8.Check(Architecture)); - var exception1And3 = - Assert.Throws(() => WrongArchRule1AndWrongArchRule3.Check(Architecture)); - var exception4And8 = - Assert.Throws(() => WrongArchRule4AndWrongArchRule8.Check(Architecture)); + var exception1 = Assert.Throws( + () => WrongArchRule1.Check(Architecture) + ); + var exception2 = Assert.Throws( + () => WrongArchRule2.Check(Architecture) + ); + var exception3 = Assert.Throws( + () => WrongArchRule3.Check(Architecture) + ); + var exception4 = Assert.Throws( + () => WrongArchRule4.Check(Architecture) + ); + var exception5 = Assert.Throws( + () => WrongArchRule5.Check(Architecture) + ); + var exception6 = Assert.Throws( + () => WrongArchRule6.Check(Architecture) + ); + var exception7 = Assert.Throws( + () => WrongArchRule7.Check(Architecture) + ); + var exception8 = Assert.Throws( + () => WrongArchRule8.Check(Architecture) + ); + var exception1And3 = Assert.Throws( + () => WrongArchRule1AndWrongArchRule3.Check(Architecture) + ); + var exception4And8 = Assert.Throws( + () => WrongArchRule4AndWrongArchRule8.Check(Architecture) + ); Assert.Equal(_expectedWrongArchRule1ErrorMessage, exception1.Message); Assert.Equal(_expectedWrongArchRule2ErrorMessage, exception2.Message); @@ -192,28 +292,67 @@ public void CheckArchRuleTest() Assert.Equal(_expectedWrongArchRule6ErrorMessage, exception6.Message); Assert.Equal(_expectedWrongArchRule7ErrorMessage, exception7.Message); Assert.Equal(_expectedWrongArchRule8ErrorMessage, exception8.Message); - Assert.Equal(_expectedWrongArchRule1AndWrongArchRule3ErrorMessage, exception1And3.Message); - Assert.Equal(_expectedWrongArchRule4AndWrongArchRule8ErrorMessage, exception4And8.Message); + Assert.Equal( + _expectedWrongArchRule1AndWrongArchRule3ErrorMessage, + exception1And3.Message + ); + Assert.Equal( + _expectedWrongArchRule4AndWrongArchRule8ErrorMessage, + exception4And8.Message + ); } - [Fact] public void CreateErrorMessageTest() { - Assert.Equal(ExpectedTrueArchRuleErrorMessage, TrueArchRule1.Evaluate(Architecture).ToErrorMessage()); - Assert.Equal(ExpectedTrueArchRuleErrorMessage, TrueArchRule2.Evaluate(Architecture).ToErrorMessage()); - Assert.Equal(_expectedWrongArchRule1ErrorMessage, WrongArchRule1.Evaluate(Architecture).ToErrorMessage()); - Assert.Equal(_expectedWrongArchRule2ErrorMessage, WrongArchRule2.Evaluate(Architecture).ToErrorMessage()); - Assert.Equal(_expectedWrongArchRule3ErrorMessage, WrongArchRule3.Evaluate(Architecture).ToErrorMessage()); - Assert.Equal(_expectedWrongArchRule4ErrorMessage, WrongArchRule4.Evaluate(Architecture).ToErrorMessage()); - Assert.Equal(_expectedWrongArchRule5ErrorMessage, WrongArchRule5.Evaluate(Architecture).ToErrorMessage()); - Assert.Equal(_expectedWrongArchRule6ErrorMessage, WrongArchRule6.Evaluate(Architecture).ToErrorMessage()); - Assert.Equal(_expectedWrongArchRule7ErrorMessage, WrongArchRule7.Evaluate(Architecture).ToErrorMessage()); - Assert.Equal(_expectedWrongArchRule8ErrorMessage, WrongArchRule8.Evaluate(Architecture).ToErrorMessage()); - Assert.Equal(_expectedWrongArchRule1AndWrongArchRule3ErrorMessage, - WrongArchRule1AndWrongArchRule3.Evaluate(Architecture).ToErrorMessage()); - Assert.Equal(_expectedWrongArchRule4AndWrongArchRule8ErrorMessage, - WrongArchRule4AndWrongArchRule8.Evaluate(Architecture).ToErrorMessage()); + Assert.Equal( + ExpectedTrueArchRuleErrorMessage, + TrueArchRule1.Evaluate(Architecture).ToErrorMessage() + ); + Assert.Equal( + ExpectedTrueArchRuleErrorMessage, + TrueArchRule2.Evaluate(Architecture).ToErrorMessage() + ); + Assert.Equal( + _expectedWrongArchRule1ErrorMessage, + WrongArchRule1.Evaluate(Architecture).ToErrorMessage() + ); + Assert.Equal( + _expectedWrongArchRule2ErrorMessage, + WrongArchRule2.Evaluate(Architecture).ToErrorMessage() + ); + Assert.Equal( + _expectedWrongArchRule3ErrorMessage, + WrongArchRule3.Evaluate(Architecture).ToErrorMessage() + ); + Assert.Equal( + _expectedWrongArchRule4ErrorMessage, + WrongArchRule4.Evaluate(Architecture).ToErrorMessage() + ); + Assert.Equal( + _expectedWrongArchRule5ErrorMessage, + WrongArchRule5.Evaluate(Architecture).ToErrorMessage() + ); + Assert.Equal( + _expectedWrongArchRule6ErrorMessage, + WrongArchRule6.Evaluate(Architecture).ToErrorMessage() + ); + Assert.Equal( + _expectedWrongArchRule7ErrorMessage, + WrongArchRule7.Evaluate(Architecture).ToErrorMessage() + ); + Assert.Equal( + _expectedWrongArchRule8ErrorMessage, + WrongArchRule8.Evaluate(Architecture).ToErrorMessage() + ); + Assert.Equal( + _expectedWrongArchRule1AndWrongArchRule3ErrorMessage, + WrongArchRule1AndWrongArchRule3.Evaluate(Architecture).ToErrorMessage() + ); + Assert.Equal( + _expectedWrongArchRule4AndWrongArchRule8ErrorMessage, + WrongArchRule4AndWrongArchRule8.Evaluate(Architecture).ToErrorMessage() + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Fluent/Slices/SlicesTests.cs b/ArchUnitNETTests/Fluent/Slices/SlicesTests.cs index baa01d9ef..17148b4d9 100644 --- a/ArchUnitNETTests/Fluent/Slices/SlicesTests.cs +++ b/ArchUnitNETTests/Fluent/Slices/SlicesTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Linq; using ArchUnitNET.Fluent.Slices; @@ -17,55 +17,141 @@ public class SlicesTests [Fact] public void CycleDetectionTest() { - Assert.Throws(() => - SliceRuleDefinition.Slices().Matching("TestAssembly.Slices.(**)").Should().BeFreeOfCycles() - .Check(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture)); - Assert.False(SliceRuleDefinition.Slices().Matching("TestAssembly.Slices.(**)").Should().BeFreeOfCycles() - .HasNoViolations(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture)); - Assert.True(SliceRuleDefinition.Slices().Matching("TestAssembly.Slices.(**)..").Should().BeFreeOfCycles() - .HasNoViolations(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture)); + Assert.Throws( + () => + SliceRuleDefinition + .Slices() + .Matching("TestAssembly.Slices.(**)") + .Should() + .BeFreeOfCycles() + .Check(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture) + ); + Assert.False( + SliceRuleDefinition + .Slices() + .Matching("TestAssembly.Slices.(**)") + .Should() + .BeFreeOfCycles() + .HasNoViolations(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture) + ); + Assert.True( + SliceRuleDefinition + .Slices() + .Matching("TestAssembly.Slices.(**)..") + .Should() + .BeFreeOfCycles() + .HasNoViolations(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture) + ); } [Fact] public void MatchingTest() { - Assert.Equal(7, - SliceRuleDefinition.Slices().Matching("TestAssembly.Slices.(*)") - .GetObjects(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture).Count()); - Assert.Equal(7, - SliceRuleDefinition.Slices().Matching("TestAssembly.Slices.(**)") - .GetObjects(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture).Count()); - Assert.Equal(7, - SliceRuleDefinition.Slices().Matching("TestAssembly.Slices.(*)..") - .GetObjects(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture).Count()); - Assert.Equal(3, - SliceRuleDefinition.Slices().Matching("TestAssembly.Slices.(**)..") - .GetObjects(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture).Count()); - Assert.Equal(2, - SliceRuleDefinition.Slices().Matching("TestAssembly.Slices.Slice3.(*)") - .GetObjects(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture).Count()); - Assert.False(SliceRuleDefinition.Slices().Matching("TestAssembly.Slices.Service.(*)") - .GetObjects(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture).Any()); + Assert.Equal( + 7, + SliceRuleDefinition + .Slices() + .Matching("TestAssembly.Slices.(*)") + .GetObjects(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture) + .Count() + ); + Assert.Equal( + 7, + SliceRuleDefinition + .Slices() + .Matching("TestAssembly.Slices.(**)") + .GetObjects(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture) + .Count() + ); + Assert.Equal( + 7, + SliceRuleDefinition + .Slices() + .Matching("TestAssembly.Slices.(*)..") + .GetObjects(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture) + .Count() + ); + Assert.Equal( + 3, + SliceRuleDefinition + .Slices() + .Matching("TestAssembly.Slices.(**)..") + .GetObjects(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture) + .Count() + ); + Assert.Equal( + 2, + SliceRuleDefinition + .Slices() + .Matching("TestAssembly.Slices.Slice3.(*)") + .GetObjects(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture) + .Count() + ); + Assert.False( + SliceRuleDefinition + .Slices() + .Matching("TestAssembly.Slices.Service.(*)") + .GetObjects(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture) + .Any() + ); } [Fact] public void NotDependOnEachOtherTest() { - SliceRuleDefinition.Slices().Matching("TestAssembly.Slices.Slice3.(*)").Should().NotDependOnEachOther() + SliceRuleDefinition + .Slices() + .Matching("TestAssembly.Slices.Slice3.(*)") + .Should() + .NotDependOnEachOther() .Check(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture); - SliceRuleDefinition.Slices().Matching("TestAssembly.Slices.Slice1.(*)").Should().NotDependOnEachOther() + SliceRuleDefinition + .Slices() + .Matching("TestAssembly.Slices.Slice1.(*)") + .Should() + .NotDependOnEachOther() .Check(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture); - Assert.True(SliceRuleDefinition.Slices().Matching("TestAssembly.Slices.Slice1.(*)").Should() - .NotDependOnEachOther().HasNoViolations(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture)); - Assert.Throws(() => - SliceRuleDefinition.Slices().Matching("TestAssembly.Slices.(**)").Should().NotDependOnEachOther() - .Check(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture)); - Assert.False(SliceRuleDefinition.Slices().Matching("TestAssembly.Slices.(**)").Should() - .NotDependOnEachOther().HasNoViolations(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture)); - Assert.False(SliceRuleDefinition.Slices().Matching("TestAssembly.Slices.(*)..").Should() - .NotDependOnEachOther().HasNoViolations(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture)); - Assert.False(SliceRuleDefinition.Slices().Matching("TestAssembly.Slices.(**)..").Should() - .NotDependOnEachOther().HasNoViolations(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture)); + Assert.True( + SliceRuleDefinition + .Slices() + .Matching("TestAssembly.Slices.Slice1.(*)") + .Should() + .NotDependOnEachOther() + .HasNoViolations(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture) + ); + Assert.Throws( + () => + SliceRuleDefinition + .Slices() + .Matching("TestAssembly.Slices.(**)") + .Should() + .NotDependOnEachOther() + .Check(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture) + ); + Assert.False( + SliceRuleDefinition + .Slices() + .Matching("TestAssembly.Slices.(**)") + .Should() + .NotDependOnEachOther() + .HasNoViolations(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture) + ); + Assert.False( + SliceRuleDefinition + .Slices() + .Matching("TestAssembly.Slices.(*)..") + .Should() + .NotDependOnEachOther() + .HasNoViolations(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture) + ); + Assert.False( + SliceRuleDefinition + .Slices() + .Matching("TestAssembly.Slices.(**)..") + .Should() + .NotDependOnEachOther() + .HasNoViolations(StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture) + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Fluent/Syntax/ConjunctionFactoryTest.cs b/ArchUnitNETTests/Fluent/Syntax/ConjunctionFactoryTest.cs index 5eef5e88f..088d6f452 100644 --- a/ArchUnitNETTests/Fluent/Syntax/ConjunctionFactoryTest.cs +++ b/ArchUnitNETTests/Fluent/Syntax/ConjunctionFactoryTest.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -9,8 +9,8 @@ using ArchUnitNET.Fluent; using ArchUnitNET.Fluent.Syntax.Elements.Types; using Xunit; -using static ArchUnitNET.Fluent.Syntax.ConjunctionFactory; using static ArchUnitNET.Fluent.BasicObjectProviderDefinition; +using static ArchUnitNET.Fluent.Syntax.ConjunctionFactory; namespace ArchUnitNETTests.Fluent.Syntax { @@ -19,8 +19,9 @@ public class ConjunctionFactoryTest [Fact] public void CreateSyntaxElementTest() { - var syntaxElement = - Create(new ArchRuleCreator(Types)); + var syntaxElement = Create( + new ArchRuleCreator(Types) + ); Assert.NotNull(syntaxElement); Assert.Equal(typeof(TypesShouldConjunction), syntaxElement.GetType()); } @@ -28,8 +29,9 @@ public void CreateSyntaxElementTest() [Fact] public void CreateSyntaxElementWithInvalidParametersThrowsExceptionTest() { - Assert.Throws(() => - Create(new ArchRuleCreator(Types))); + Assert.Throws( + () => Create(new ArchRuleCreator(Types)) + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Fluent/Syntax/DependenciesToOtherAssembliesTests.cs b/ArchUnitNETTests/Fluent/Syntax/DependenciesToOtherAssembliesTests.cs index 31d009752..0d13052d3 100644 --- a/ArchUnitNETTests/Fluent/Syntax/DependenciesToOtherAssembliesTests.cs +++ b/ArchUnitNETTests/Fluent/Syntax/DependenciesToOtherAssembliesTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using ArchUnitNET.Domain; using ArchUnitNET.Domain.Extensions; @@ -19,50 +19,104 @@ public class DependenciesToOtherAssembliesTests { public class TestDependencyIssue { - private static readonly Architecture Architecture = - new ArchLoader().LoadAssemblies(System.Reflection.Assembly.Load("ArchUnitNETTests")).Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssemblies(System.Reflection.Assembly.Load("ArchUnitNETTests")) + .Build(); [Fact] public void DependOnAnyTypesThatTest() { - Types().That().Are(typeof(DependingClass)).Should() - .DependOnAnyTypesThat().Are(typeof(ClassInTestAssembly)).Check(Architecture); - Assert.Throws(() => Types().That().Are(typeof(DependingClass)).Should() - .NotDependOnAnyTypesThat().Are(typeof(ClassInTestAssembly)).Check(Architecture)); + Types() + .That() + .Are(typeof(DependingClass)) + .Should() + .DependOnAnyTypesThat() + .Are(typeof(ClassInTestAssembly)) + .Check(Architecture); + Assert.Throws( + () => + Types() + .That() + .Are(typeof(DependingClass)) + .Should() + .NotDependOnAnyTypesThat() + .Are(typeof(ClassInTestAssembly)) + .Check(Architecture) + ); } [Fact] public void BeAssignableToTypesThatTest() { - Types().That().Are(typeof(DependingClass)).Should() - .BeAssignableToTypesThat().Are(typeof(IInterfaceInTestAssembly)).Check(Architecture); - Assert.Throws(() => Types().That().Are(typeof(DependingClass)).Should() - .NotBeAssignableToTypesThat().Are(typeof(IInterfaceInTestAssembly)).Check(Architecture)); + Types() + .That() + .Are(typeof(DependingClass)) + .Should() + .BeAssignableToTypesThat() + .Are(typeof(IInterfaceInTestAssembly)) + .Check(Architecture); + Assert.Throws( + () => + Types() + .That() + .Are(typeof(DependingClass)) + .Should() + .NotBeAssignableToTypesThat() + .Are(typeof(IInterfaceInTestAssembly)) + .Check(Architecture) + ); } [Fact] public void OnlyDependOnTypesThatTest() { - Types().That().Are(typeof(DependingClass)).Should() - .OnlyDependOnTypesThat().Are(typeof(object), typeof(AttributeInTestAssembly), - typeof(IInterfaceInTestAssembly), typeof(ClassInTestAssembly), typeof(DependingClass)) + Types() + .That() + .Are(typeof(DependingClass)) + .Should() + .OnlyDependOnTypesThat() + .Are( + typeof(object), + typeof(AttributeInTestAssembly), + typeof(IInterfaceInTestAssembly), + typeof(ClassInTestAssembly), + typeof(DependingClass) + ) .Check(Architecture); } [Fact] public void HaveAnyAttributesThatTest() { - Types().That().Are(typeof(DependingClass)).Should() - .HaveAnyAttributesThat().Are(typeof(AttributeInTestAssembly)).Check(Architecture); - Assert.Throws(() => Types().That().Are(typeof(DependingClass)).Should() - .NotHaveAnyAttributesThat().Are(typeof(AttributeInTestAssembly)).Check(Architecture)); + Types() + .That() + .Are(typeof(DependingClass)) + .Should() + .HaveAnyAttributesThat() + .Are(typeof(AttributeInTestAssembly)) + .Check(Architecture); + Assert.Throws( + () => + Types() + .That() + .Are(typeof(DependingClass)) + .Should() + .NotHaveAnyAttributesThat() + .Are(typeof(AttributeInTestAssembly)) + .Check(Architecture) + ); } [Fact] public void OnlyHaveAttributesThatTest() { - Types().That().Are(typeof(DependingClass)).Should() - .OnlyHaveAttributesThat().Are(typeof(AttributeInTestAssembly)).Check(Architecture); + Types() + .That() + .Are(typeof(DependingClass)) + .Should() + .OnlyHaveAttributesThat() + .Are(typeof(AttributeInTestAssembly)) + .Check(Architecture); } [Fact] @@ -71,12 +125,16 @@ public void IncludeReferencedTypesTest() var classInTestAssembly = Architecture.GetClassOfType(typeof(ClassInTestAssembly)); Assert.Contains(classInTestAssembly, Types(true).GetObjects(Architecture)); Assert.Contains(classInTestAssembly, Classes(true).GetObjects(Architecture)); - - var attributeInTestAssembly = Architecture.GetAttributeOfType(typeof(AttributeInTestAssembly)); + + var attributeInTestAssembly = Architecture.GetAttributeOfType( + typeof(AttributeInTestAssembly) + ); Assert.Contains(attributeInTestAssembly, Types(true).GetObjects(Architecture)); Assert.Contains(attributeInTestAssembly, Attributes(true).GetObjects(Architecture)); - - var interfaceInTestAssembly = Architecture.GetInterfaceOfType(typeof(IInterfaceInTestAssembly)); + + var interfaceInTestAssembly = Architecture.GetInterfaceOfType( + typeof(IInterfaceInTestAssembly) + ); Assert.Contains(interfaceInTestAssembly, Types(true).GetObjects(Architecture)); Assert.Contains(interfaceInTestAssembly, Interfaces(true).GetObjects(Architecture)); } @@ -94,4 +152,4 @@ public DependingClass() dep.MethodInTestAssembly(); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/AttributeSyntaxElementsTests.cs b/ArchUnitNETTests/Fluent/Syntax/Elements/AttributeSyntaxElementsTests.cs index 363426fbe..87f07cb8d 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/AttributeSyntaxElementsTests.cs +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/AttributeSyntaxElementsTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -18,7 +18,8 @@ public AttributeSyntaxElementsTests() _attributes = Architecture.Attributes; } - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; private readonly IEnumerable _attributes; [Fact] @@ -27,24 +28,68 @@ public void AreAbstractTest() foreach (var attribute in _attributes) { var attributeIsAbstract = Attributes().That().Are(attribute).Should().BeAbstract(); - var attributeIsNotAbstract = Attributes().That().Are(attribute).Should().NotBeAbstract(); - var abstractAttributesDoNotIncludeType = - Attributes().That().AreAbstract().Should().NotBe(attribute).OrShould().NotExist(); - var notAbstractAttributesDoNotIncludeType = Attributes().That().AreNotAbstract().Should() - .NotBe(attribute).AndShould().Exist(); + var attributeIsNotAbstract = Attributes() + .That() + .Are(attribute) + .Should() + .NotBeAbstract(); + var abstractAttributesDoNotIncludeType = Attributes() + .That() + .AreAbstract() + .Should() + .NotBe(attribute) + .OrShould() + .NotExist(); + var notAbstractAttributesDoNotIncludeType = Attributes() + .That() + .AreNotAbstract() + .Should() + .NotBe(attribute) + .AndShould() + .Exist(); - Assert.Equal(attribute.IsAbstract, attributeIsAbstract.HasNoViolations(Architecture)); - Assert.Equal(!attribute.IsAbstract, attributeIsNotAbstract.HasNoViolations(Architecture)); - Assert.Equal(!attribute.IsAbstract, abstractAttributesDoNotIncludeType.HasNoViolations(Architecture)); - Assert.Equal(attribute.IsAbstract, notAbstractAttributesDoNotIncludeType.HasNoViolations(Architecture)); + Assert.Equal( + attribute.IsAbstract, + attributeIsAbstract.HasNoViolations(Architecture) + ); + Assert.Equal( + !attribute.IsAbstract, + attributeIsNotAbstract.HasNoViolations(Architecture) + ); + Assert.Equal( + !attribute.IsAbstract, + abstractAttributesDoNotIncludeType.HasNoViolations(Architecture) + ); + Assert.Equal( + attribute.IsAbstract, + notAbstractAttributesDoNotIncludeType.HasNoViolations(Architecture) + ); } - var abstractAttributesAreAbstract = Attributes().That().AreAbstract().Should().BeAbstract(); - var abstractAttributesAreNotAbstract = - Attributes().That().AreAbstract().Should().NotBeAbstract().AndShould().Exist(); - var notAbstractAttributesAreAbstract = - Attributes().That().AreNotAbstract().Should().BeAbstract().AndShould().Exist(); - var notAbstractAttributesAreNotAbstract = Attributes().That().AreNotAbstract().Should().NotBeAbstract(); + var abstractAttributesAreAbstract = Attributes() + .That() + .AreAbstract() + .Should() + .BeAbstract(); + var abstractAttributesAreNotAbstract = Attributes() + .That() + .AreAbstract() + .Should() + .NotBeAbstract() + .AndShould() + .Exist(); + var notAbstractAttributesAreAbstract = Attributes() + .That() + .AreNotAbstract() + .Should() + .BeAbstract() + .AndShould() + .Exist(); + var notAbstractAttributesAreNotAbstract = Attributes() + .That() + .AreNotAbstract() + .Should() + .NotBeAbstract(); Assert.True(abstractAttributesAreAbstract.HasNoViolations(Architecture)); Assert.False(abstractAttributesAreNotAbstract.HasNoViolations(Architecture)); @@ -58,22 +103,57 @@ public void AreSealedTest() foreach (var attribute in _attributes) { var attributeIsSealed = Attributes().That().Are(attribute).Should().BeSealed(); - var attributeIsNotSealed = Attributes().That().Are(attribute).Should().NotBeSealed(); - var sealedAttributesDoNotIncludeType = Attributes().That().AreSealed().Should().NotBe(attribute); - var notSealedAttributesDoNotIncludeType = Attributes().That().AreNotSealed().Should().NotBe(attribute); + var attributeIsNotSealed = Attributes() + .That() + .Are(attribute) + .Should() + .NotBeSealed(); + var sealedAttributesDoNotIncludeType = Attributes() + .That() + .AreSealed() + .Should() + .NotBe(attribute); + var notSealedAttributesDoNotIncludeType = Attributes() + .That() + .AreNotSealed() + .Should() + .NotBe(attribute); Assert.Equal(attribute.IsSealed, attributeIsSealed.HasNoViolations(Architecture)); - Assert.Equal(!attribute.IsSealed, attributeIsNotSealed.HasNoViolations(Architecture)); - Assert.Equal(!attribute.IsSealed, sealedAttributesDoNotIncludeType.HasNoViolations(Architecture)); - Assert.Equal(attribute.IsSealed, notSealedAttributesDoNotIncludeType.HasNoViolations(Architecture)); + Assert.Equal( + !attribute.IsSealed, + attributeIsNotSealed.HasNoViolations(Architecture) + ); + Assert.Equal( + !attribute.IsSealed, + sealedAttributesDoNotIncludeType.HasNoViolations(Architecture) + ); + Assert.Equal( + attribute.IsSealed, + notSealedAttributesDoNotIncludeType.HasNoViolations(Architecture) + ); } var sealedAttributesAreSealed = Attributes().That().AreSealed().Should().BeSealed(); - var sealedAttributesAreNotSealed = - Attributes().That().AreSealed().Should().NotBeSealed().AndShould().Exist(); - var notSealedAttributesAreSealed = - Attributes().That().AreNotSealed().Should().BeSealed().AndShould().Exist(); - var notSealedAttributesAreNotSealed = Attributes().That().AreNotSealed().Should().NotBeSealed(); + var sealedAttributesAreNotSealed = Attributes() + .That() + .AreSealed() + .Should() + .NotBeSealed() + .AndShould() + .Exist(); + var notSealedAttributesAreSealed = Attributes() + .That() + .AreNotSealed() + .Should() + .BeSealed() + .AndShould() + .Exist(); + var notSealedAttributesAreNotSealed = Attributes() + .That() + .AreNotSealed() + .Should() + .NotBeSealed(); Assert.True(sealedAttributesAreSealed.HasNoViolations(Architecture)); Assert.False(sealedAttributesAreNotSealed.HasNoViolations(Architecture)); @@ -81,4 +161,4 @@ public void AreSealedTest() Assert.True(notSealedAttributesAreNotSealed.HasNoViolations(Architecture)); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/ClassSyntaxElementsTests.cs b/ArchUnitNETTests/Fluent/Syntax/Elements/ClassSyntaxElementsTests.cs index 7e2fcbf9a..54fd78e7a 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/ClassSyntaxElementsTests.cs +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/ClassSyntaxElementsTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -19,7 +19,8 @@ public ClassSyntaxElementsTests() _classes = Architecture.Classes; } - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; private readonly IEnumerable _classes; [Fact] @@ -29,19 +30,45 @@ public void AreAbstractTest() { var clsIsAbstract = Classes().That().Are(cls).Should().BeAbstract(); var clsIsNotAbstract = Classes().That().Are(cls).Should().NotBeAbstract(); - var abstractClassesDoNotIncludeType = Classes().That().AreAbstract().Should().NotBe(cls); - var notAbstractClassesDoNotIncludeType = Classes().That().AreNotAbstract().Should().NotBe(cls); + var abstractClassesDoNotIncludeType = Classes() + .That() + .AreAbstract() + .Should() + .NotBe(cls); + var notAbstractClassesDoNotIncludeType = Classes() + .That() + .AreNotAbstract() + .Should() + .NotBe(cls); Assert.Equal(cls.IsAbstract, clsIsAbstract.HasNoViolations(Architecture)); Assert.Equal(!cls.IsAbstract, clsIsNotAbstract.HasNoViolations(Architecture)); - Assert.Equal(!cls.IsAbstract, abstractClassesDoNotIncludeType.HasNoViolations(Architecture)); - Assert.Equal(cls.IsAbstract, notAbstractClassesDoNotIncludeType.HasNoViolations(Architecture)); + Assert.Equal( + !cls.IsAbstract, + abstractClassesDoNotIncludeType.HasNoViolations(Architecture) + ); + Assert.Equal( + cls.IsAbstract, + notAbstractClassesDoNotIncludeType.HasNoViolations(Architecture) + ); } var abstractClassesAreAbstract = Classes().That().AreAbstract().Should().BeAbstract(); - var abstractClassesAreNotAbstract = Classes().That().AreAbstract().Should().NotBeAbstract(); - var notAbstractClassesAreAbstract = Classes().That().AreNotAbstract().Should().BeAbstract(); - var notAbstractClassesAreNotAbstract = Classes().That().AreNotAbstract().Should().NotBeAbstract(); + var abstractClassesAreNotAbstract = Classes() + .That() + .AreAbstract() + .Should() + .NotBeAbstract(); + var notAbstractClassesAreAbstract = Classes() + .That() + .AreNotAbstract() + .Should() + .BeAbstract(); + var notAbstractClassesAreNotAbstract = Classes() + .That() + .AreNotAbstract() + .Should() + .NotBeAbstract(); Assert.True(abstractClassesAreAbstract.HasNoViolations(Architecture)); Assert.False(abstractClassesAreNotAbstract.HasNoViolations(Architecture)); @@ -52,8 +79,12 @@ public void AreAbstractTest() [Fact] public void AreEnumsTest() { - Assert.True(Classes().That().AreNotEnums().Should().Be(Classes()).HasNoViolations(Architecture)); - Assert.True(Classes().That().AreEnums().Should().NotExist().HasNoViolations(Architecture)); + Assert.True( + Classes().That().AreNotEnums().Should().Be(Classes()).HasNoViolations(Architecture) + ); + Assert.True( + Classes().That().AreEnums().Should().NotExist().HasNoViolations(Architecture) + ); Assert.True(Classes().Should().NotBeEnums().HasNoViolations(Architecture)); Assert.False(Classes().Should().BeEnums().HasNoViolations(Architecture)); } @@ -65,19 +96,37 @@ public void AreSealedTest() { var clsIsSealed = Classes().That().Are(cls).Should().BeSealed(); var clsIsNotSealed = Classes().That().Are(cls).Should().NotBeSealed(); - var sealedClassesDoNotIncludeType = Classes().That().AreSealed().Should().NotBe(cls); - var notSealedClassesDoNotIncludeType = Classes().That().AreNotSealed().Should().NotBe(cls); + var sealedClassesDoNotIncludeType = Classes() + .That() + .AreSealed() + .Should() + .NotBe(cls); + var notSealedClassesDoNotIncludeType = Classes() + .That() + .AreNotSealed() + .Should() + .NotBe(cls); Assert.Equal(cls.IsSealed, clsIsSealed.HasNoViolations(Architecture)); Assert.Equal(!cls.IsSealed, clsIsNotSealed.HasNoViolations(Architecture)); - Assert.Equal(!cls.IsSealed, sealedClassesDoNotIncludeType.HasNoViolations(Architecture)); - Assert.Equal(cls.IsSealed, notSealedClassesDoNotIncludeType.HasNoViolations(Architecture)); + Assert.Equal( + !cls.IsSealed, + sealedClassesDoNotIncludeType.HasNoViolations(Architecture) + ); + Assert.Equal( + cls.IsSealed, + notSealedClassesDoNotIncludeType.HasNoViolations(Architecture) + ); } var sealedClassesAreSealed = Classes().That().AreSealed().Should().BeSealed(); var sealedClassesAreNotSealed = Classes().That().AreSealed().Should().NotBeSealed(); var notSealedClassesAreSealed = Classes().That().AreNotSealed().Should().BeSealed(); - var notSealedClassesAreNotSealed = Classes().That().AreNotSealed().Should().NotBeSealed(); + var notSealedClassesAreNotSealed = Classes() + .That() + .AreNotSealed() + .Should() + .NotBeSealed(); Assert.True(sealedClassesAreSealed.HasNoViolations(Architecture)); Assert.False(sealedClassesAreNotSealed.HasNoViolations(Architecture)); @@ -88,8 +137,17 @@ public void AreSealedTest() [Fact] public void AreStructsTest() { - Assert.True(Classes().That().AreNotStructs().Should().Be(Classes()).HasNoViolations(Architecture)); - Assert.True(Classes().That().AreStructs().Should().NotExist().HasNoViolations(Architecture)); + Assert.True( + Classes() + .That() + .AreNotStructs() + .Should() + .Be(Classes()) + .HasNoViolations(Architecture) + ); + Assert.True( + Classes().That().AreStructs().Should().NotExist().HasNoViolations(Architecture) + ); Assert.True(Classes().Should().NotBeStructs().HasNoViolations(Architecture)); Assert.False(Classes().Should().BeStructs().HasNoViolations(Architecture)); } @@ -97,8 +155,17 @@ public void AreStructsTest() [Fact] public void AreValueTypesTest() { - Assert.True(Classes().That().AreNotValueTypes().Should().Be(Classes()).HasNoViolations(Architecture)); - Assert.True(Classes().That().AreValueTypes().Should().NotExist().HasNoViolations(Architecture)); + Assert.True( + Classes() + .That() + .AreNotValueTypes() + .Should() + .Be(Classes()) + .HasNoViolations(Architecture) + ); + Assert.True( + Classes().That().AreValueTypes().Should().NotExist().HasNoViolations(Architecture) + ); Assert.True(Classes().Should().NotBeValueTypes().HasNoViolations(Architecture)); Assert.False(Classes().Should().BeValueTypes().HasNoViolations(Architecture)); } @@ -110,20 +177,52 @@ public void AreImmutableTest() { var clsIsImmutable = Classes().That().Are(cls).Should().BeImmutable(); var clsIsNotImmutable = Classes().That().Are(cls).Should().NotBeImmutable(); - var immutableClassesDoNotIncludeType = Classes().That().AreImmutable().Should().NotBe(cls); - var notImmutableClassesDoNotIncludeType = Classes().That().AreNotImmutable().Should().NotBe(cls); + var immutableClassesDoNotIncludeType = Classes() + .That() + .AreImmutable() + .Should() + .NotBe(cls); + var notImmutableClassesDoNotIncludeType = Classes() + .That() + .AreNotImmutable() + .Should() + .NotBe(cls); - bool isImmutable = cls.Members.Where(m => m.IsStatic == false).All(m => m.Writability.IsImmutable()); + bool isImmutable = cls + .Members.Where(m => m.IsStatic == false) + .All(m => m.Writability.IsImmutable()); Assert.Equal(isImmutable, clsIsImmutable.HasNoViolations(Architecture)); Assert.Equal(!isImmutable, clsIsNotImmutable.HasNoViolations(Architecture)); - Assert.Equal(!isImmutable, immutableClassesDoNotIncludeType.HasNoViolations(Architecture)); - Assert.Equal(isImmutable, notImmutableClassesDoNotIncludeType.HasNoViolations(Architecture)); + Assert.Equal( + !isImmutable, + immutableClassesDoNotIncludeType.HasNoViolations(Architecture) + ); + Assert.Equal( + isImmutable, + notImmutableClassesDoNotIncludeType.HasNoViolations(Architecture) + ); } - var immutableClassesAreImmutable = Classes().That().AreImmutable().Should().BeImmutable(); - var immutableClassesAreNotImmutable = Classes().That().AreImmutable().Should().NotBeImmutable(); - var notImmutableClassesAreImmutable = Classes().That().AreNotImmutable().Should().BeImmutable(); - var notImmutableClassesAreNotImmutabled = Classes().That().AreNotImmutable().Should().NotBeImmutable(); + var immutableClassesAreImmutable = Classes() + .That() + .AreImmutable() + .Should() + .BeImmutable(); + var immutableClassesAreNotImmutable = Classes() + .That() + .AreImmutable() + .Should() + .NotBeImmutable(); + var notImmutableClassesAreImmutable = Classes() + .That() + .AreNotImmutable() + .Should() + .BeImmutable(); + var notImmutableClassesAreNotImmutabled = Classes() + .That() + .AreNotImmutable() + .Should() + .NotBeImmutable(); Assert.True(immutableClassesAreImmutable.HasNoViolations(Architecture)); Assert.False(immutableClassesAreNotImmutable.HasNoViolations(Architecture)); @@ -151,13 +250,13 @@ private class ImmutableClassWithoutPropertiesAndFields private void Method() { } } - private class ImmutableClassWithOnlyStaticMembers { private const string ConstField = "const"; private static string StaticField; public static string StaticProperty { get; set; } + private static void Method() { } } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/CustomSyntaxElementsTests.cs b/ArchUnitNETTests/Fluent/Syntax/Elements/CustomSyntaxElementsTests.cs index a4919e74e..d112da172 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/CustomSyntaxElementsTests.cs +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/CustomSyntaxElementsTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Linq; using ArchUnitNET.Domain; @@ -17,8 +17,9 @@ namespace ArchUnitNETTests.Fluent.Syntax.Elements { public class CustomSyntaxElementsTests { - private static readonly Architecture Architecture = - new ArchLoader().LoadAssemblies(System.Reflection.Assembly.Load("ArchUnitNETTests")).Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssemblies(System.Reflection.Assembly.Load("ArchUnitNETTests")) + .Build(); private readonly Class _testClass; @@ -30,12 +31,24 @@ public CustomSyntaxElementsTests() [Fact] public void CustomConditionTest() { - var passingRule = Classes().That().Are(typeof(CustomRuleTestClass)).Should() - .FollowCustomCondition(cls => cls.FullName.Contains(nameof(CustomRuleTestClass)), - "passing custom condition", "failed custom condition which should have passed"); - var failingRule = Classes().That().Are(typeof(CustomRuleTestClass)).Should() - .FollowCustomCondition(cls => !cls.FullName.Contains(nameof(CustomRuleTestClass)), - "failing custom condition", "failed custom condition which should have failed"); + var passingRule = Classes() + .That() + .Are(typeof(CustomRuleTestClass)) + .Should() + .FollowCustomCondition( + cls => cls.FullName.Contains(nameof(CustomRuleTestClass)), + "passing custom condition", + "failed custom condition which should have passed" + ); + var failingRule = Classes() + .That() + .Are(typeof(CustomRuleTestClass)) + .Should() + .FollowCustomCondition( + cls => !cls.FullName.Contains(nameof(CustomRuleTestClass)), + "failing custom condition", + "failed custom condition which should have failed" + ); passingRule.Check(Architecture); Assert.False(failingRule.HasNoViolations(Architecture)); @@ -44,8 +57,12 @@ public void CustomConditionTest() [Fact] public void CustomPredicateTest() { - var predicateTestObjects = Classes().That() - .FollowCustomPredicate(cls => cls.Name.Equals(nameof(CustomRuleTestClass)), "custom predicate") + var predicateTestObjects = Classes() + .That() + .FollowCustomPredicate( + cls => cls.Name.Equals(nameof(CustomRuleTestClass)), + "custom predicate" + ) .GetObjects(Architecture); Assert.Single(predicateTestObjects); @@ -53,7 +70,5 @@ public void CustomPredicateTest() } } - internal class CustomRuleTestClass - { - } -} \ No newline at end of file + internal class CustomRuleTestClass { } +} diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/LogicalConjunctionTests.cs b/ArchUnitNETTests/Fluent/Syntax/Elements/LogicalConjunctionTests.cs index 05cea7286..8475905e8 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/LogicalConjunctionTests.cs +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/LogicalConjunctionTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -14,71 +14,139 @@ namespace ArchUnitNETTests.Fluent.Syntax.Elements { public class LogicalConjunctionTests { - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; - private static readonly Class ThisClass = Architecture.GetClassOfType(typeof(LogicalConjunctionTests)); + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; + private static readonly Class ThisClass = Architecture.GetClassOfType( + typeof(LogicalConjunctionTests) + ); - private static readonly Class OtherClass = - Architecture.GetClassOfType(typeof(OtherClassForLogicalConjunctionTest)); + private static readonly Class OtherClass = Architecture.GetClassOfType( + typeof(OtherClassForLogicalConjunctionTest) + ); private static readonly string ThisClassName = ThisClass.Name; private static readonly string OtherClassName = OtherClass.Name; - private static readonly IArchRule ThisClassExists = - Classes().That().Are(ThisClass).Should().Exist(); - - private static readonly IArchRule ThisClassDoesNotExist = - Classes().That().Are(ThisClass).Should().NotExist(); - - private static readonly IArchRule ThisCondition1 = - Classes().That().Are(ThisClass).Should().Be(ThisClass); - - private static readonly IArchRule ThisCondition2 = - Classes().That().HaveName(ThisClassName).Should().Be(ThisClass); - - private static readonly IArchRule OtherCondition1 = - Classes().That().Are(OtherClass).Should().Be(OtherClass); - - private static readonly IArchRule OtherCondition2 = - Classes().That().HaveName(OtherClassName).Should().Be(OtherClass); - - private static readonly IArchRule FalseThisCondition1 = - Classes().That().AreNot(ThisClass).Should().Be(ThisClass); - - private static readonly IArchRule FalseThisCondition2 = - Classes().That().DoNotHaveName(ThisClassName).Should().Be(ThisClass); - - private static readonly IArchRule ThisShouldCondition1 = - Classes().That().Are(ThisClass).Should().Be(ThisClass); - - private static readonly IArchRule ThisShouldCondition2 = - Classes().That().Are(ThisClass).Should().HaveName(ThisClassName); - - private static readonly IArchRule OtherShouldCondition1 = - Classes().That().Are(OtherClass).Should().Be(OtherClass); - - private static readonly IArchRule OtherShouldCondition2 = - Classes().That().Are(OtherClass).Should().HaveName(OtherClassName); - - private static readonly IArchRule FalseThisShouldCondition1 = - Classes().That().Are(ThisClass).Should().NotBe(ThisClass); - - private static readonly IArchRule FalseThisShouldCondition2 = - Classes().That().Are(ThisClass).Should().NotHaveName(ThisClassName); + private static readonly IArchRule ThisClassExists = Classes() + .That() + .Are(ThisClass) + .Should() + .Exist(); + + private static readonly IArchRule ThisClassDoesNotExist = Classes() + .That() + .Are(ThisClass) + .Should() + .NotExist(); + + private static readonly IArchRule ThisCondition1 = Classes() + .That() + .Are(ThisClass) + .Should() + .Be(ThisClass); + + private static readonly IArchRule ThisCondition2 = Classes() + .That() + .HaveName(ThisClassName) + .Should() + .Be(ThisClass); + + private static readonly IArchRule OtherCondition1 = Classes() + .That() + .Are(OtherClass) + .Should() + .Be(OtherClass); + + private static readonly IArchRule OtherCondition2 = Classes() + .That() + .HaveName(OtherClassName) + .Should() + .Be(OtherClass); + + private static readonly IArchRule FalseThisCondition1 = Classes() + .That() + .AreNot(ThisClass) + .Should() + .Be(ThisClass); + + private static readonly IArchRule FalseThisCondition2 = Classes() + .That() + .DoNotHaveName(ThisClassName) + .Should() + .Be(ThisClass); + + private static readonly IArchRule ThisShouldCondition1 = Classes() + .That() + .Are(ThisClass) + .Should() + .Be(ThisClass); + + private static readonly IArchRule ThisShouldCondition2 = Classes() + .That() + .Are(ThisClass) + .Should() + .HaveName(ThisClassName); + + private static readonly IArchRule OtherShouldCondition1 = Classes() + .That() + .Are(OtherClass) + .Should() + .Be(OtherClass); + + private static readonly IArchRule OtherShouldCondition2 = Classes() + .That() + .Are(OtherClass) + .Should() + .HaveName(OtherClassName); + + private static readonly IArchRule FalseThisShouldCondition1 = Classes() + .That() + .Are(ThisClass) + .Should() + .NotBe(ThisClass); + + private static readonly IArchRule FalseThisShouldCondition2 = Classes() + .That() + .Are(ThisClass) + .Should() + .NotHaveName(ThisClassName); [Fact] public void AndShouldTest() { - var thisShouldCondition1AndThisShouldCondition2 = - Classes().That().Are(ThisClass).Should().Be(ThisClass).AndShould().HaveName(ThisClassName); - var thisShouldCondition1AndOtherShouldCondition1 = - Classes().That().Are(ThisClass).Should().Be(ThisClass).AndShould().Be(OtherClass); - var otherCondition2AndThisCondition2 = - Classes().That().Are(ThisClass).Should().HaveName(OtherClassName).AndShould().HaveName(ThisClassName); - var falseThisCondition1AndFalseThisCondition2 = - Classes().That().Are(ThisClass).Should().NotBe(ThisClass).AndShould().NotHaveName(ThisClassName); + var thisShouldCondition1AndThisShouldCondition2 = Classes() + .That() + .Are(ThisClass) + .Should() + .Be(ThisClass) + .AndShould() + .HaveName(ThisClassName); + var thisShouldCondition1AndOtherShouldCondition1 = Classes() + .That() + .Are(ThisClass) + .Should() + .Be(ThisClass) + .AndShould() + .Be(OtherClass); + var otherCondition2AndThisCondition2 = Classes() + .That() + .Are(ThisClass) + .Should() + .HaveName(OtherClassName) + .AndShould() + .HaveName(ThisClassName); + var falseThisCondition1AndFalseThisCondition2 = Classes() + .That() + .Are(ThisClass) + .Should() + .NotBe(ThisClass) + .AndShould() + .NotHaveName(ThisClassName); Assert.True(thisShouldCondition1AndThisShouldCondition2.HasNoViolations(Architecture)); - Assert.False(thisShouldCondition1AndOtherShouldCondition1.HasNoViolations(Architecture)); + Assert.False( + thisShouldCondition1AndOtherShouldCondition1.HasNoViolations(Architecture) + ); Assert.False(otherCondition2AndThisCondition2.HasNoViolations(Architecture)); Assert.False(falseThisCondition1AndFalseThisCondition2.HasNoViolations(Architecture)); } @@ -86,14 +154,34 @@ public void AndShouldTest() [Fact] public void AndTest() { - var thisCondition1AndThisCondition2 = - Classes().That().Are(ThisClass).And().HaveName(ThisClassName).Should().Be(ThisClass); - var thisCondition1AndOtherCondition1 = - Classes().That().Are(ThisClass).And().Are(OtherClass).Should().NotExist(); - var otherCondition2AndThisCondition2 = - Classes().That().HaveName(OtherClassName).And().HaveName(ThisClassName).Should().NotExist(); - var falseThisCondition1AndFalseThisCondition2 = - Classes().That().AreNot(ThisClass).And().DoNotHaveName(ThisClassName).Should().NotBe(ThisClass); + var thisCondition1AndThisCondition2 = Classes() + .That() + .Are(ThisClass) + .And() + .HaveName(ThisClassName) + .Should() + .Be(ThisClass); + var thisCondition1AndOtherCondition1 = Classes() + .That() + .Are(ThisClass) + .And() + .Are(OtherClass) + .Should() + .NotExist(); + var otherCondition2AndThisCondition2 = Classes() + .That() + .HaveName(OtherClassName) + .And() + .HaveName(ThisClassName) + .Should() + .NotExist(); + var falseThisCondition1AndFalseThisCondition2 = Classes() + .That() + .AreNot(ThisClass) + .And() + .DoNotHaveName(ThisClassName) + .Should() + .NotBe(ThisClass); Assert.True(thisCondition1AndThisCondition2.HasNoViolations(Architecture)); Assert.True(thisCondition1AndOtherCondition1.HasNoViolations(Architecture)); @@ -124,83 +212,209 @@ public void BasicRulesBehaveAsExpected() [Fact] public void CombinedAndOrTest() { - var thisCondition1OrThisCondition2AndOtherCondition1 = - Classes().That().Are(ThisClass).Or().HaveName(ThisClassName).And().Are(OtherClass).Should().NotExist(); - var thisCondition1AndOtherCondition1OrThisCondition2 = - Classes().That().Are(ThisClass).And().Are(OtherClass).Or().HaveName(ThisClassName).Should().Exist(); - var thisCondition1OrOtherCondition1AndOtherCondition2 = - Classes().That().Are(ThisClass).Or().Are(OtherClass).And().HaveName(OtherClassName).Should() - .Be(OtherClass); - var thisCondition1AndThisCondition2OrFalseThisCondition1 = - Classes().That().Are(ThisClass).And().HaveName(ThisClassName).Or().AreNot(ThisClass).Should() - .Be(ThisClass); - - Assert.True(thisCondition1OrThisCondition2AndOtherCondition1.HasNoViolations(Architecture)); - Assert.True(thisCondition1AndOtherCondition1OrThisCondition2.HasNoViolations(Architecture)); - Assert.True(thisCondition1OrOtherCondition1AndOtherCondition2.HasNoViolations(Architecture)); - Assert.False(thisCondition1AndThisCondition2OrFalseThisCondition1.HasNoViolations(Architecture)); + var thisCondition1OrThisCondition2AndOtherCondition1 = Classes() + .That() + .Are(ThisClass) + .Or() + .HaveName(ThisClassName) + .And() + .Are(OtherClass) + .Should() + .NotExist(); + var thisCondition1AndOtherCondition1OrThisCondition2 = Classes() + .That() + .Are(ThisClass) + .And() + .Are(OtherClass) + .Or() + .HaveName(ThisClassName) + .Should() + .Exist(); + var thisCondition1OrOtherCondition1AndOtherCondition2 = Classes() + .That() + .Are(ThisClass) + .Or() + .Are(OtherClass) + .And() + .HaveName(OtherClassName) + .Should() + .Be(OtherClass); + var thisCondition1AndThisCondition2OrFalseThisCondition1 = Classes() + .That() + .Are(ThisClass) + .And() + .HaveName(ThisClassName) + .Or() + .AreNot(ThisClass) + .Should() + .Be(ThisClass); + + Assert.True( + thisCondition1OrThisCondition2AndOtherCondition1.HasNoViolations(Architecture) + ); + Assert.True( + thisCondition1AndOtherCondition1OrThisCondition2.HasNoViolations(Architecture) + ); + Assert.True( + thisCondition1OrOtherCondition1AndOtherCondition2.HasNoViolations(Architecture) + ); + Assert.False( + thisCondition1AndThisCondition2OrFalseThisCondition1.HasNoViolations(Architecture) + ); } [Fact] public void CombinedAndShouldOrShouldTest() { - var thisShouldCondition1AndOtherShouldCondition1OrThisShouldCondition2 = - Classes().That().Are(ThisClass).Should().Be(ThisClass).AndShould().Be(OtherClass).OrShould() - .HaveName(ThisClassName); - var otherShouldCondition1OrThisShouldCondition1AndThisShouldCondition2 = - Classes().That().Are(ThisClass).Should().Be(OtherClass).OrShould().Be(ThisClass).AndShould() - .HaveName(ThisClassName); - var thisShouldCondition1OrThisShouldCondition2AndOtherShouldCondition1 = - Classes().That().Are(ThisClass).Should().Be(ThisClass).OrShould().HaveName(ThisClassName).AndShould() - .Be(OtherClass); - var thisShouldExistAndShouldNotExistOrShouldNotExist = - Classes().That().Are(ThisClass).Should().Exist().AndShould().NotExist().OrShould().NotExist(); - var thisShouldExistOrShouldNotExistAndShouldNotExist = - Classes().That().Are(ThisClass).Should().Exist().OrShould().NotExist().AndShould().NotExist(); - var thisShouldExistAndShouldNotExistOrShouldExist = - Classes().That().Are(ThisClass).Should().Exist().AndShould().NotExist().OrShould().Exist(); + var thisShouldCondition1AndOtherShouldCondition1OrThisShouldCondition2 = Classes() + .That() + .Are(ThisClass) + .Should() + .Be(ThisClass) + .AndShould() + .Be(OtherClass) + .OrShould() + .HaveName(ThisClassName); + var otherShouldCondition1OrThisShouldCondition1AndThisShouldCondition2 = Classes() + .That() + .Are(ThisClass) + .Should() + .Be(OtherClass) + .OrShould() + .Be(ThisClass) + .AndShould() + .HaveName(ThisClassName); + var thisShouldCondition1OrThisShouldCondition2AndOtherShouldCondition1 = Classes() + .That() + .Are(ThisClass) + .Should() + .Be(ThisClass) + .OrShould() + .HaveName(ThisClassName) + .AndShould() + .Be(OtherClass); + var thisShouldExistAndShouldNotExistOrShouldNotExist = Classes() + .That() + .Are(ThisClass) + .Should() + .Exist() + .AndShould() + .NotExist() + .OrShould() + .NotExist(); + var thisShouldExistOrShouldNotExistAndShouldNotExist = Classes() + .That() + .Are(ThisClass) + .Should() + .Exist() + .OrShould() + .NotExist() + .AndShould() + .NotExist(); + var thisShouldExistAndShouldNotExistOrShouldExist = Classes() + .That() + .Are(ThisClass) + .Should() + .Exist() + .AndShould() + .NotExist() + .OrShould() + .Exist(); var thisShouldExistAndThisShouldCondition1OrOtherShouldCondition1OrShouldNotExist = - Classes().That().Are(ThisClass).Should().Exist().AndShould().Be(ThisClass).OrShould().Be(OtherClass) - .OrShould().NotExist(); + Classes() + .That() + .Are(ThisClass) + .Should() + .Exist() + .AndShould() + .Be(ThisClass) + .OrShould() + .Be(OtherClass) + .OrShould() + .NotExist(); Assert.True( - thisShouldCondition1AndOtherShouldCondition1OrThisShouldCondition2.HasNoViolations(Architecture)); + thisShouldCondition1AndOtherShouldCondition1OrThisShouldCondition2.HasNoViolations( + Architecture + ) + ); Assert.True( - otherShouldCondition1OrThisShouldCondition1AndThisShouldCondition2.HasNoViolations(Architecture)); + otherShouldCondition1OrThisShouldCondition1AndThisShouldCondition2.HasNoViolations( + Architecture + ) + ); + Assert.False( + thisShouldCondition1OrThisShouldCondition2AndOtherShouldCondition1.HasNoViolations( + Architecture + ) + ); + Assert.False( + thisShouldExistAndShouldNotExistOrShouldNotExist.HasNoViolations(Architecture) + ); Assert.False( - thisShouldCondition1OrThisShouldCondition2AndOtherShouldCondition1.HasNoViolations(Architecture)); - Assert.False(thisShouldExistAndShouldNotExistOrShouldNotExist.HasNoViolations(Architecture)); - Assert.False(thisShouldExistOrShouldNotExistAndShouldNotExist.HasNoViolations(Architecture)); - Assert.True(thisShouldExistAndShouldNotExistOrShouldExist.HasNoViolations(Architecture)); + thisShouldExistOrShouldNotExistAndShouldNotExist.HasNoViolations(Architecture) + ); + Assert.True( + thisShouldExistAndShouldNotExistOrShouldExist.HasNoViolations(Architecture) + ); Assert.True( thisShouldExistAndThisShouldCondition1OrOtherShouldCondition1OrShouldNotExist.HasNoViolations( - Architecture)); + Architecture + ) + ); } [Fact] public void CombinedArchRuleAndTest() { - var thisClassExistsAndThisClassExists1 = - ThisClassExists.And().Classes().That().Are(ThisClass).Should().Exist(); - var thisClassExistsAndThisClassDoesNotExist1 = - ThisClassExists.And().Classes().That().Are(ThisClass).Should().NotExist(); - var thisClassDoesNotExistAndThisClassExists1 = - ThisClassDoesNotExist.And().Classes().That().Are(ThisClass).Should().Exist(); - var thisClassDoesNotExistAndThisClassDoesNotExist1 = - ThisClassDoesNotExist.And().Classes().That().Are(ThisClass).Should().NotExist(); - + var thisClassExistsAndThisClassExists1 = ThisClassExists + .And() + .Classes() + .That() + .Are(ThisClass) + .Should() + .Exist(); + var thisClassExistsAndThisClassDoesNotExist1 = ThisClassExists + .And() + .Classes() + .That() + .Are(ThisClass) + .Should() + .NotExist(); + var thisClassDoesNotExistAndThisClassExists1 = ThisClassDoesNotExist + .And() + .Classes() + .That() + .Are(ThisClass) + .Should() + .Exist(); + var thisClassDoesNotExistAndThisClassDoesNotExist1 = ThisClassDoesNotExist + .And() + .Classes() + .That() + .Are(ThisClass) + .Should() + .NotExist(); var thisClassExistsAndThisClassExists2 = ThisClassExists.And(ThisClassExists); - var thisClassExistsAndThisClassDoesNotExist2 = ThisClassExists.And(ThisClassDoesNotExist); - var thisClassDoesNotExistAndThisClassExists2 = ThisClassDoesNotExist.And(ThisClassExists); - var thisClassDoesNotExistAndThisClassDoesNotExist2 = ThisClassDoesNotExist.And(ThisClassDoesNotExist); - - var thisClassExistsAndThisClassExistsAndThisClassExists = - ThisClassExists.And(thisClassExistsAndThisClassExists2); + var thisClassExistsAndThisClassDoesNotExist2 = ThisClassExists.And( + ThisClassDoesNotExist + ); + var thisClassDoesNotExistAndThisClassExists2 = ThisClassDoesNotExist.And( + ThisClassExists + ); + var thisClassDoesNotExistAndThisClassDoesNotExist2 = ThisClassDoesNotExist.And( + ThisClassDoesNotExist + ); + + var thisClassExistsAndThisClassExistsAndThisClassExists = ThisClassExists.And( + thisClassExistsAndThisClassExists2 + ); var thisClassExistsAndThisClassExistsAndThisClassExistsAndThisClassExists = thisClassExistsAndThisClassExists2.And(thisClassExistsAndThisClassExists2); - var thisClassExistsAndThisClassExistsAndThisClassDoesNotExist = - ThisClassExists.And(thisClassExistsAndThisClassDoesNotExist2); + var thisClassExistsAndThisClassExistsAndThisClassDoesNotExist = ThisClassExists.And( + thisClassExistsAndThisClassDoesNotExist2 + ); var thisClassExistsAndThisClassDoesNotExistAndThisClassExists = thisClassExistsAndThisClassDoesNotExist2.And(ThisClassExists); var thisClassDoesNotExistAndThisClassExistsAndThisClassDoesNotExist = @@ -209,76 +423,150 @@ public void CombinedArchRuleAndTest() Assert.True(thisClassExistsAndThisClassExists1.HasNoViolations(Architecture)); Assert.False(thisClassExistsAndThisClassDoesNotExist1.HasNoViolations(Architecture)); Assert.False(thisClassDoesNotExistAndThisClassExists1.HasNoViolations(Architecture)); - Assert.False(thisClassDoesNotExistAndThisClassDoesNotExist1.HasNoViolations(Architecture)); + Assert.False( + thisClassDoesNotExistAndThisClassDoesNotExist1.HasNoViolations(Architecture) + ); Assert.True(thisClassExistsAndThisClassExists2.HasNoViolations(Architecture)); Assert.False(thisClassExistsAndThisClassDoesNotExist2.HasNoViolations(Architecture)); Assert.False(thisClassDoesNotExistAndThisClassExists2.HasNoViolations(Architecture)); - Assert.False(thisClassDoesNotExistAndThisClassDoesNotExist2.HasNoViolations(Architecture)); + Assert.False( + thisClassDoesNotExistAndThisClassDoesNotExist2.HasNoViolations(Architecture) + ); - Assert.True(thisClassExistsAndThisClassExistsAndThisClassExists.HasNoViolations(Architecture)); Assert.True( - thisClassExistsAndThisClassExistsAndThisClassExistsAndThisClassExists.HasNoViolations(Architecture)); - Assert.False(thisClassExistsAndThisClassExistsAndThisClassDoesNotExist.HasNoViolations(Architecture)); - Assert.False(thisClassExistsAndThisClassDoesNotExistAndThisClassExists.HasNoViolations(Architecture)); - Assert.False(thisClassDoesNotExistAndThisClassExistsAndThisClassDoesNotExist.HasNoViolations(Architecture)); + thisClassExistsAndThisClassExistsAndThisClassExists.HasNoViolations(Architecture) + ); + Assert.True( + thisClassExistsAndThisClassExistsAndThisClassExistsAndThisClassExists.HasNoViolations( + Architecture + ) + ); + Assert.False( + thisClassExistsAndThisClassExistsAndThisClassDoesNotExist.HasNoViolations( + Architecture + ) + ); + Assert.False( + thisClassExistsAndThisClassDoesNotExistAndThisClassExists.HasNoViolations( + Architecture + ) + ); + Assert.False( + thisClassDoesNotExistAndThisClassExistsAndThisClassDoesNotExist.HasNoViolations( + Architecture + ) + ); } [Fact] public void CombinedArchRuleCombinedAndOrTest() { - var thisClassExistsAndThisClassExistsOrThisClassExists = - ThisClassExists.And(Classes().That().Are(ThisClass).Should().Exist()).Or().Classes().That() - .Are(ThisClass).Should().Exist(); + var thisClassExistsAndThisClassExistsOrThisClassExists = ThisClassExists + .And(Classes().That().Are(ThisClass).Should().Exist()) + .Or() + .Classes() + .That() + .Are(ThisClass) + .Should() + .Exist(); var thisClassExistsOrThisClassDoesNotExistOrThisClassExistsAndThisClassDoesNotExist = - ThisClassExists.Or(ThisClassDoesNotExist).Or(ThisClassExists).And(ThisClassDoesNotExist); - var thisClassExistsOrThisClassDoesNotExistAndThisClassExists = - ThisClassExists.Or(ThisClassDoesNotExist).And(ThisClassExists); + ThisClassExists + .Or(ThisClassDoesNotExist) + .Or(ThisClassExists) + .And(ThisClassDoesNotExist); + var thisClassExistsOrThisClassDoesNotExistAndThisClassExists = ThisClassExists + .Or(ThisClassDoesNotExist) + .And(ThisClassExists); var thisClassDoesNotExistAndThisClassExistsOrThisClassDoesNotExist = ThisClassDoesNotExist.And(ThisClassExists).Or(ThisClassDoesNotExist); var thisClassExistsOrThisClassDoesNotExistOrJoinedThisClassExistsAndThisClassDoesNotExist = - ThisClassExists.Or(ThisClassDoesNotExist).Or(ThisClassExists.And(ThisClassDoesNotExist)); - var thisClassExistsOrJoinedThisClassDoesNotExistAndThisClassExists = - ThisClassExists.Or(ThisClassDoesNotExist.And(ThisClassExists)); + ThisClassExists + .Or(ThisClassDoesNotExist) + .Or(ThisClassExists.And(ThisClassDoesNotExist)); + var thisClassExistsOrJoinedThisClassDoesNotExistAndThisClassExists = ThisClassExists.Or( + ThisClassDoesNotExist.And(ThisClassExists) + ); - Assert.True(thisClassExistsAndThisClassExistsOrThisClassExists.HasNoViolations(Architecture)); + Assert.True( + thisClassExistsAndThisClassExistsOrThisClassExists.HasNoViolations(Architecture) + ); Assert.False( thisClassExistsOrThisClassDoesNotExistOrThisClassExistsAndThisClassDoesNotExist.HasNoViolations( - Architecture)); - Assert.True(thisClassExistsOrThisClassDoesNotExistAndThisClassExists.HasNoViolations(Architecture)); - Assert.False(thisClassDoesNotExistAndThisClassExistsOrThisClassDoesNotExist.HasNoViolations(Architecture)); + Architecture + ) + ); + Assert.True( + thisClassExistsOrThisClassDoesNotExistAndThisClassExists.HasNoViolations( + Architecture + ) + ); + Assert.False( + thisClassDoesNotExistAndThisClassExistsOrThisClassDoesNotExist.HasNoViolations( + Architecture + ) + ); Assert.True( thisClassExistsOrThisClassDoesNotExistOrJoinedThisClassExistsAndThisClassDoesNotExist.HasNoViolations( - Architecture)); - Assert.True(thisClassExistsOrJoinedThisClassDoesNotExistAndThisClassExists.HasNoViolations(Architecture)); + Architecture + ) + ); + Assert.True( + thisClassExistsOrJoinedThisClassDoesNotExistAndThisClassExists.HasNoViolations( + Architecture + ) + ); } [Fact] public void CombinedArchRuleOrTest() { - var thisClassExistsOrThisClassExists1 = - ThisClassExists.Or().Classes().That().Are(ThisClass).Should().Exist(); - var thisClassExistsOrThisClassDoesNotExist1 = - ThisClassExists.Or().Classes().That().Are(ThisClass).Should().NotExist(); - var thisClassDoesNotExistOrThisClassExists1 = - ThisClassDoesNotExist.Or().Classes().That().Are(ThisClass).Should().Exist(); - var thisClassDoesNotExistOrThisClassDoesNotExist1 = - ThisClassDoesNotExist.Or().Classes().That().Are(ThisClass).Should().NotExist(); - + var thisClassExistsOrThisClassExists1 = ThisClassExists + .Or() + .Classes() + .That() + .Are(ThisClass) + .Should() + .Exist(); + var thisClassExistsOrThisClassDoesNotExist1 = ThisClassExists + .Or() + .Classes() + .That() + .Are(ThisClass) + .Should() + .NotExist(); + var thisClassDoesNotExistOrThisClassExists1 = ThisClassDoesNotExist + .Or() + .Classes() + .That() + .Are(ThisClass) + .Should() + .Exist(); + var thisClassDoesNotExistOrThisClassDoesNotExist1 = ThisClassDoesNotExist + .Or() + .Classes() + .That() + .Are(ThisClass) + .Should() + .NotExist(); var thisClassExistsOrThisClassExists2 = ThisClassExists.Or(ThisClassExists); var thisClassExistsOrThisClassDoesNotExist2 = ThisClassExists.Or(ThisClassDoesNotExist); var thisClassDoesNotExistOrThisClassExists2 = ThisClassDoesNotExist.Or(ThisClassExists); - var thisClassDoesNotExistOrThisClassDoesNotExist2 = ThisClassDoesNotExist.Or(ThisClassDoesNotExist); + var thisClassDoesNotExistOrThisClassDoesNotExist2 = ThisClassDoesNotExist.Or( + ThisClassDoesNotExist + ); - var thisClassExistsOrThisClassExistsOrThisClassExists = - ThisClassExists.Or(thisClassExistsOrThisClassExists2); + var thisClassExistsOrThisClassExistsOrThisClassExists = ThisClassExists.Or( + thisClassExistsOrThisClassExists2 + ); var thisClassExistsOrThisClassExistsOrThisClassExistsOrThisClassExists = thisClassExistsOrThisClassExists2.Or(thisClassExistsOrThisClassExists2); - var thisClassExistsOrThisClassExistsOrThisClassDoesNotExist = - ThisClassExists.Or(thisClassExistsOrThisClassDoesNotExist2); + var thisClassExistsOrThisClassExistsOrThisClassDoesNotExist = ThisClassExists.Or( + thisClassExistsOrThisClassDoesNotExist2 + ); var thisClassExistsOrThisClassDoesNotExistOrThisClassExists = thisClassExistsOrThisClassDoesNotExist2.Or(ThisClassExists); var thisClassDoesNotExistOrThisClassDoesNotExistOrThisClassDoesNotExist = @@ -287,33 +575,73 @@ public void CombinedArchRuleOrTest() Assert.True(thisClassExistsOrThisClassExists1.HasNoViolations(Architecture)); Assert.True(thisClassExistsOrThisClassDoesNotExist1.HasNoViolations(Architecture)); Assert.True(thisClassDoesNotExistOrThisClassExists1.HasNoViolations(Architecture)); - Assert.False(thisClassDoesNotExistOrThisClassDoesNotExist1.HasNoViolations(Architecture)); + Assert.False( + thisClassDoesNotExistOrThisClassDoesNotExist1.HasNoViolations(Architecture) + ); Assert.True(thisClassExistsOrThisClassExists2.HasNoViolations(Architecture)); Assert.True(thisClassExistsOrThisClassDoesNotExist2.HasNoViolations(Architecture)); Assert.True(thisClassDoesNotExistOrThisClassExists2.HasNoViolations(Architecture)); - Assert.False(thisClassDoesNotExistOrThisClassDoesNotExist2.HasNoViolations(Architecture)); + Assert.False( + thisClassDoesNotExistOrThisClassDoesNotExist2.HasNoViolations(Architecture) + ); - Assert.True(thisClassExistsOrThisClassExistsOrThisClassExists.HasNoViolations(Architecture)); Assert.True( - thisClassExistsOrThisClassExistsOrThisClassExistsOrThisClassExists.HasNoViolations(Architecture)); - Assert.True(thisClassExistsOrThisClassExistsOrThisClassDoesNotExist.HasNoViolations(Architecture)); - Assert.True(thisClassExistsOrThisClassDoesNotExistOrThisClassExists.HasNoViolations(Architecture)); + thisClassExistsOrThisClassExistsOrThisClassExists.HasNoViolations(Architecture) + ); + Assert.True( + thisClassExistsOrThisClassExistsOrThisClassExistsOrThisClassExists.HasNoViolations( + Architecture + ) + ); + Assert.True( + thisClassExistsOrThisClassExistsOrThisClassDoesNotExist.HasNoViolations( + Architecture + ) + ); + Assert.True( + thisClassExistsOrThisClassDoesNotExistOrThisClassExists.HasNoViolations( + Architecture + ) + ); Assert.False( - thisClassDoesNotExistOrThisClassDoesNotExistOrThisClassDoesNotExist.HasNoViolations(Architecture)); + thisClassDoesNotExistOrThisClassDoesNotExistOrThisClassDoesNotExist.HasNoViolations( + Architecture + ) + ); } [Fact] public void OrShouldTest() { - var thisShouldCondition1OrThisShouldCondition2 = - Classes().That().Are(ThisClass).Should().Be(ThisClass).OrShould().HaveName(ThisClassName); - var thisShouldCondition1OrOtherShouldCondition1 = - Classes().That().Are(ThisClass).Should().Be(ThisClass).OrShould().Be(OtherClass); - var otherCondition2OrThisCondition2 = - Classes().That().Are(ThisClass).Should().HaveName(OtherClassName).OrShould().HaveName(ThisClassName); - var falseThisCondition1OrFalseThisCondition2 = - Classes().That().Are(ThisClass).Should().NotBe(ThisClass).OrShould().NotHaveName(ThisClassName); + var thisShouldCondition1OrThisShouldCondition2 = Classes() + .That() + .Are(ThisClass) + .Should() + .Be(ThisClass) + .OrShould() + .HaveName(ThisClassName); + var thisShouldCondition1OrOtherShouldCondition1 = Classes() + .That() + .Are(ThisClass) + .Should() + .Be(ThisClass) + .OrShould() + .Be(OtherClass); + var otherCondition2OrThisCondition2 = Classes() + .That() + .Are(ThisClass) + .Should() + .HaveName(OtherClassName) + .OrShould() + .HaveName(ThisClassName); + var falseThisCondition1OrFalseThisCondition2 = Classes() + .That() + .Are(ThisClass) + .Should() + .NotBe(ThisClass) + .OrShould() + .NotHaveName(ThisClassName); Assert.True(thisShouldCondition1OrThisShouldCondition2.HasNoViolations(Architecture)); Assert.True(thisShouldCondition1OrOtherShouldCondition1.HasNoViolations(Architecture)); @@ -324,14 +652,34 @@ public void OrShouldTest() [Fact] public void OrTest() { - var thisCondition1OrThisCondition2 = - Classes().That().Are(ThisClass).Or().HaveName(ThisClassName).Should().Be(ThisClass); - var thisCondition1OrOtherCondition1 = - Classes().That().Are(ThisClass).Or().Are(OtherClass).Should().Exist(); - var otherCondition2OrThisCondition2 = - Classes().That().HaveName(OtherClassName).Or().HaveName(ThisClassName).Should().Exist(); - var falseThisCondition1OrFalseThisCondition2 = - Classes().That().AreNot(ThisClass).Or().DoNotHaveName(ThisClassName).Should().NotBe(ThisClass); + var thisCondition1OrThisCondition2 = Classes() + .That() + .Are(ThisClass) + .Or() + .HaveName(ThisClassName) + .Should() + .Be(ThisClass); + var thisCondition1OrOtherCondition1 = Classes() + .That() + .Are(ThisClass) + .Or() + .Are(OtherClass) + .Should() + .Exist(); + var otherCondition2OrThisCondition2 = Classes() + .That() + .HaveName(OtherClassName) + .Or() + .HaveName(ThisClassName) + .Should() + .Exist(); + var falseThisCondition1OrFalseThisCondition2 = Classes() + .That() + .AreNot(ThisClass) + .Or() + .DoNotHaveName(ThisClassName) + .Should() + .NotBe(ThisClass); Assert.True(thisCondition1OrThisCondition2.HasNoViolations(Architecture)); Assert.True(thisCondition1OrOtherCondition1.HasNoViolations(Architecture)); @@ -340,7 +688,5 @@ public void OrTest() } } - internal class OtherClassForLogicalConjunctionTest - { - } -} \ No newline at end of file + internal class OtherClassForLogicalConjunctionTest { } +} diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/MatchGenericReturnTypesTests.cs b/ArchUnitNETTests/Fluent/Syntax/Elements/MatchGenericReturnTypesTests.cs index 7726d40e1..06b932c48 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/MatchGenericReturnTypesTests.cs +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/MatchGenericReturnTypesTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using ArchUnitNET.Domain; using ArchUnitNET.Loader; @@ -15,82 +15,157 @@ namespace ArchUnitNETTests.Fluent.Syntax.Elements { public class MatchGenericReturnTypesTests { - private static readonly Architecture Architecture = - new ArchLoader().LoadAssemblies(System.Reflection.Assembly.Load("ArchUnitNETTests")).Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssemblies(System.Reflection.Assembly.Load("ArchUnitNETTests")) + .Build(); [Fact] public void OneGenericParameter() { - MethodMembers().That().AreDeclaredIn(typeof(OneGenericReturnTypeExample)).And() - .HaveName("CorrectGenericArgument()").Should().Exist().AndShould() - .HaveReturnType(typeof(ExampleGenericClass<>)).Check(Architecture); - MethodMembers().That().AreDeclaredIn(typeof(OneGenericReturnTypeExample)).And() - .HaveName("WrongGenericArgument()").Should().Exist().AndShould() - .HaveReturnType(typeof(ExampleGenericClass<>)).Check(Architecture); - MethodMembers().That().AreDeclaredIn(typeof(OneGenericReturnTypeExample)).And() + MethodMembers() + .That() + .AreDeclaredIn(typeof(OneGenericReturnTypeExample)) + .And() + .HaveName("CorrectGenericArgument()") + .Should() + .Exist() + .AndShould() + .HaveReturnType(typeof(ExampleGenericClass<>)) + .Check(Architecture); + MethodMembers() + .That() + .AreDeclaredIn(typeof(OneGenericReturnTypeExample)) + .And() + .HaveName("WrongGenericArgument()") + .Should() + .Exist() + .AndShould() + .HaveReturnType(typeof(ExampleGenericClass<>)) + .Check(Architecture); + MethodMembers() + .That() + .AreDeclaredIn(typeof(OneGenericReturnTypeExample)) + .And() .HaveNameContaining("WrongReturnType") - .Should().Exist().AndShould().NotHaveReturnType(typeof(ExampleGenericClass<>)).Check(Architecture); + .Should() + .Exist() + .AndShould() + .NotHaveReturnType(typeof(ExampleGenericClass<>)) + .Check(Architecture); } [Fact] public void TwoGenericParameters() { - MethodMembers().That().AreDeclaredIn(typeof(TwoGenericReturnTypesExample)).And() - .HaveName("CorrectGenericArgument()").Should().Exist().AndShould() - .HaveReturnType(typeof(ExampleGenericClass<,>)).Check(Architecture); - MethodMembers().That().AreDeclaredIn(typeof(TwoGenericReturnTypesExample)).And() - .HaveName("WrongGenericArgument()").Should().Exist().AndShould() - .HaveReturnType(typeof(ExampleGenericClass<,>)).Check(Architecture); - MethodMembers().That().AreDeclaredIn(typeof(TwoGenericReturnTypesExample)).And() + MethodMembers() + .That() + .AreDeclaredIn(typeof(TwoGenericReturnTypesExample)) + .And() + .HaveName("CorrectGenericArgument()") + .Should() + .Exist() + .AndShould() + .HaveReturnType(typeof(ExampleGenericClass<,>)) + .Check(Architecture); + MethodMembers() + .That() + .AreDeclaredIn(typeof(TwoGenericReturnTypesExample)) + .And() + .HaveName("WrongGenericArgument()") + .Should() + .Exist() + .AndShould() + .HaveReturnType(typeof(ExampleGenericClass<,>)) + .Check(Architecture); + MethodMembers() + .That() + .AreDeclaredIn(typeof(TwoGenericReturnTypesExample)) + .And() .HaveNameContaining("WrongReturnType") - .Should().Exist().AndShould().NotHaveReturnType(typeof(ExampleGenericClass<,>)).Check(Architecture); + .Should() + .Exist() + .AndShould() + .NotHaveReturnType(typeof(ExampleGenericClass<,>)) + .Check(Architecture); } [Fact] public void OneGenericArgument() { - MethodMembers().That().AreDeclaredIn(typeof(OneGenericReturnTypeExample)).And() - .HaveName("CorrectGenericArgument()").Should().Exist().AndShould() - .HaveReturnType(typeof(ExampleGenericClass)).Check(Architecture); - MethodMembers().That().AreDeclaredIn(typeof(OneGenericReturnTypeExample)).And() - .HaveName("WrongGenericArgument()").Should().Exist().AndShould() - .NotHaveReturnType(typeof(ExampleGenericClass)).Check(Architecture); - MethodMembers().That().AreDeclaredIn(typeof(OneGenericReturnTypeExample)).And() - .HaveNameContaining("WrongReturnType").Should().Exist().AndShould() - .NotHaveReturnType(typeof(ExampleGenericClass)).Check(Architecture); + MethodMembers() + .That() + .AreDeclaredIn(typeof(OneGenericReturnTypeExample)) + .And() + .HaveName("CorrectGenericArgument()") + .Should() + .Exist() + .AndShould() + .HaveReturnType(typeof(ExampleGenericClass)) + .Check(Architecture); + MethodMembers() + .That() + .AreDeclaredIn(typeof(OneGenericReturnTypeExample)) + .And() + .HaveName("WrongGenericArgument()") + .Should() + .Exist() + .AndShould() + .NotHaveReturnType(typeof(ExampleGenericClass)) + .Check(Architecture); + MethodMembers() + .That() + .AreDeclaredIn(typeof(OneGenericReturnTypeExample)) + .And() + .HaveNameContaining("WrongReturnType") + .Should() + .Exist() + .AndShould() + .NotHaveReturnType(typeof(ExampleGenericClass)) + .Check(Architecture); } [Fact] public void TwoGenericArguments() { - MethodMembers().That().AreDeclaredIn(typeof(TwoGenericReturnTypesExample)).And() - .HaveName("CorrectGenericArgument()").Should() - .Exist().AndShould().HaveReturnType(typeof(ExampleGenericClass)) + MethodMembers() + .That() + .AreDeclaredIn(typeof(TwoGenericReturnTypesExample)) + .And() + .HaveName("CorrectGenericArgument()") + .Should() + .Exist() + .AndShould() + .HaveReturnType(typeof(ExampleGenericClass)) .Check(Architecture); - MethodMembers().That().AreDeclaredIn(typeof(TwoGenericReturnTypesExample)).And() - .HaveName("WrongGenericArgument()").Should() - .Exist().AndShould().NotHaveReturnType(typeof(ExampleGenericClass)) + MethodMembers() + .That() + .AreDeclaredIn(typeof(TwoGenericReturnTypesExample)) + .And() + .HaveName("WrongGenericArgument()") + .Should() + .Exist() + .AndShould() + .NotHaveReturnType(typeof(ExampleGenericClass)) .Check(Architecture); - MethodMembers().That().AreDeclaredIn(typeof(TwoGenericReturnTypesExample)).And() + MethodMembers() + .That() + .AreDeclaredIn(typeof(TwoGenericReturnTypesExample)) + .And() .HaveNameContaining("WrongReturnType") - .Should().Exist().AndShould().NotHaveReturnType(typeof(ExampleGenericClass)) + .Should() + .Exist() + .AndShould() + .NotHaveReturnType(typeof(ExampleGenericClass)) .Check(Architecture); } } - // ReSharper disable All - class ExampleGenericClass - { - } + class ExampleGenericClass { } - class ExampleGenericClass - { - } + class ExampleGenericClass { } - class ExampleArgument - { - } + class ExampleArgument { } class OneGenericReturnTypeExample { @@ -147,4 +222,4 @@ public bool WrongReturnType3() return true; } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/MemberSyntaxElementsTests.cs b/ArchUnitNETTests/Fluent/Syntax/Elements/MemberSyntaxElementsTests.cs index 34332f229..4f6a5fbd3 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/MemberSyntaxElementsTests.cs +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/MemberSyntaxElementsTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -21,23 +21,39 @@ public MemberSyntaxElementsTests() _types = Architecture.Types; } - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; private readonly IEnumerable _members; private readonly IEnumerable _types; private readonly List _falseTypes1 = new List - {StaticTestTypes.PublicTestClass, StaticTestTypes.InternalTestClass}; + { + StaticTestTypes.PublicTestClass, + StaticTestTypes.InternalTestClass + }; - private readonly List _falseTypes2 = new List {typeof(PublicTestClass), typeof(InternalTestClass)}; + private readonly List _falseTypes2 = new List + { + typeof(PublicTestClass), + typeof(InternalTestClass) + }; private readonly List _falseTypesPattern = new List - {StaticTestTypes.PublicTestClass.FullName, StaticTestTypes.InternalTestClass.FullName}; + { + StaticTestTypes.PublicTestClass.FullName, + StaticTestTypes.InternalTestClass.FullName + }; - private readonly List _falseTypeConstructors = - new List {PublicTestClassConstructor, InternalTestClassConstructor}; + private readonly List _falseTypeConstructors = new List + { + PublicTestClassConstructor, + InternalTestClassConstructor + }; - private const string PublicTestClassConstructor = "System.Void ArchUnitNETTests.Domain.PublicTestClass::.ctor()"; - private const string InternalTestClassConstructor = "System.Void ArchUnitNETTests.Domain.InternalTestClass::.ctor()"; + private const string PublicTestClassConstructor = + "System.Void ArchUnitNETTests.Domain.PublicTestClass::.ctor()"; + private const string InternalTestClassConstructor = + "System.Void ArchUnitNETTests.Domain.InternalTestClass::.ctor()"; [Fact] public void DeclaredInTest() @@ -46,19 +62,44 @@ public void DeclaredInTest() { //One Argument - var declaredInRightType = Members().That().Are(member).Should().BeDeclaredIn(member.DeclaringType); - var notDeclaredInRightType = - Members().That().Are(member).Should().NotBeDeclaredIn(member.DeclaringType); - var declaredInOtherType1 = Members().That().Are(member).Should().BeDeclaredIn(typeof(PublicTestClass)) - .AndShould().NotBe(PublicTestClassConstructor); - var notDeclaredInOtherType1 = - Members().That().Are(member).Should().NotBeDeclaredIn(typeof(PublicTestClass)).OrShould() - .Be(PublicTestClassConstructor); - var declaredInOtherType2 = - Members().That().Are(member).Should().BeDeclaredIn(StaticTestTypes.PublicTestClass).AndShould() - .NotBe(PublicTestClassConstructor); - var notDeclaredInOtherType2 = Members().That().Are(member).Should() - .NotBeDeclaredIn(StaticTestTypes.PublicTestClass).OrShould().Be(PublicTestClassConstructor); + var declaredInRightType = Members() + .That() + .Are(member) + .Should() + .BeDeclaredIn(member.DeclaringType); + var notDeclaredInRightType = Members() + .That() + .Are(member) + .Should() + .NotBeDeclaredIn(member.DeclaringType); + var declaredInOtherType1 = Members() + .That() + .Are(member) + .Should() + .BeDeclaredIn(typeof(PublicTestClass)) + .AndShould() + .NotBe(PublicTestClassConstructor); + var notDeclaredInOtherType1 = Members() + .That() + .Are(member) + .Should() + .NotBeDeclaredIn(typeof(PublicTestClass)) + .OrShould() + .Be(PublicTestClassConstructor); + var declaredInOtherType2 = Members() + .That() + .Are(member) + .Should() + .BeDeclaredIn(StaticTestTypes.PublicTestClass) + .AndShould() + .NotBe(PublicTestClassConstructor); + var notDeclaredInOtherType2 = Members() + .That() + .Are(member) + .Should() + .NotBeDeclaredIn(StaticTestTypes.PublicTestClass) + .OrShould() + .Be(PublicTestClassConstructor); Assert.True(declaredInRightType.HasNoViolations(Architecture)); Assert.False(notDeclaredInRightType.HasNoViolations(Architecture)); @@ -69,25 +110,58 @@ public void DeclaredInTest() //Multiple Arguments - var declaredInRightTypeFluent = Members().That().Are(member).Should() + var declaredInRightTypeFluent = Members() + .That() + .Are(member) + .Should() .BeDeclaredIn(Types().That().HaveMemberWithName(member.Name)); - var notDeclaredInRightTypeFluent = Members().That().Are(member).Should() + var notDeclaredInRightTypeFluent = Members() + .That() + .Are(member) + .Should() .NotBeDeclaredIn(Types().That().HaveMemberWithName(member.Name)); - var declaredInOtherTypeMultiple1 = Members().That().Are(member).Should().BeDeclaredIn(_falseTypes1) - .AndShould().NotBe(_falseTypeConstructors); - var notDeclaredInOtherTypeMultiple1 = - Members().That().Are(member).Should().NotBeDeclaredIn(_falseTypes1).OrShould() - .Be(_falseTypeConstructors); - var declaredInOtherTypeMultiple2 = - Members().That().Are(member).Should().BeDeclaredIn(_falseTypes2).AndShould() - .NotBe(_falseTypeConstructors); - var notDeclaredInOtherTypeMultiple2 = Members().That().Are(member).Should() - .NotBeDeclaredIn(_falseTypes2).OrShould().Be(_falseTypeConstructors); - var declaredInOtherTypeMultiplePattern = - Members().That().Are(member).Should().BeDeclaredIn(_falseTypesPattern).AndShould() - .NotBe(_falseTypeConstructors); - var notDeclaredInOtherTypeMultiplePattern = Members().That().Are(member).Should() - .NotBeDeclaredIn(_falseTypesPattern).OrShould().Be(_falseTypeConstructors); + var declaredInOtherTypeMultiple1 = Members() + .That() + .Are(member) + .Should() + .BeDeclaredIn(_falseTypes1) + .AndShould() + .NotBe(_falseTypeConstructors); + var notDeclaredInOtherTypeMultiple1 = Members() + .That() + .Are(member) + .Should() + .NotBeDeclaredIn(_falseTypes1) + .OrShould() + .Be(_falseTypeConstructors); + var declaredInOtherTypeMultiple2 = Members() + .That() + .Are(member) + .Should() + .BeDeclaredIn(_falseTypes2) + .AndShould() + .NotBe(_falseTypeConstructors); + var notDeclaredInOtherTypeMultiple2 = Members() + .That() + .Are(member) + .Should() + .NotBeDeclaredIn(_falseTypes2) + .OrShould() + .Be(_falseTypeConstructors); + var declaredInOtherTypeMultiplePattern = Members() + .That() + .Are(member) + .Should() + .BeDeclaredIn(_falseTypesPattern) + .AndShould() + .NotBe(_falseTypeConstructors); + var notDeclaredInOtherTypeMultiplePattern = Members() + .That() + .Are(member) + .Should() + .NotBeDeclaredIn(_falseTypesPattern) + .OrShould() + .Be(_falseTypeConstructors); Assert.True(declaredInRightTypeFluent.HasNoViolations(Architecture)); Assert.False(notDeclaredInRightTypeFluent.HasNoViolations(Architecture)); @@ -101,9 +175,18 @@ public void DeclaredInTest() foreach (var type in _types) { - var membersShouldBeDeclaredInOwnType = Members().That().AreDeclaredIn(type).Should().BeDeclaredIn(type).WithoutRequiringPositiveResults(); - var membersShouldNotBeDeclaredInOwnType = - Members().That().AreNotDeclaredIn(type).Should().BeDeclaredIn(type).WithoutRequiringPositiveResults(); + var membersShouldBeDeclaredInOwnType = Members() + .That() + .AreDeclaredIn(type) + .Should() + .BeDeclaredIn(type) + .WithoutRequiringPositiveResults(); + var membersShouldNotBeDeclaredInOwnType = Members() + .That() + .AreNotDeclaredIn(type) + .Should() + .BeDeclaredIn(type) + .WithoutRequiringPositiveResults(); Assert.True(membersShouldBeDeclaredInOwnType.HasNoViolations(Architecture)); Assert.False(membersShouldNotBeDeclaredInOwnType.HasNoViolations(Architecture)); @@ -111,21 +194,35 @@ public void DeclaredInTest() //One Argument - var emptyTypeHasOnlyConstructor1 = Members().That().AreDeclaredIn(typeof(PublicTestClass)).Should() + var emptyTypeHasOnlyConstructor1 = Members() + .That() + .AreDeclaredIn(typeof(PublicTestClass)) + .Should() .Be(PublicTestClassConstructor); - var emptyTypeHasOnlyConstructor2 = - Members().That().AreDeclaredIn(StaticTestTypes.PublicTestClass).Should().Be(PublicTestClassConstructor); - var emptyTypeHasOnlyConstructorPattern = - Members().That().AreDeclaredIn(typeof(PublicTestClass).FullName).Should() - .Be(PublicTestClassConstructor); - var allMembersAreNotDeclaredInEmptyType1 = - Members().That().AreNotDeclaredIn(typeof(PublicTestClass)).Should() - .Be(Members().That().AreNot(PublicTestClassConstructor)); - var allMembersAreNotDeclaredInEmptyType2 = - Members().That().AreNotDeclaredIn(StaticTestTypes.PublicTestClass).Should() - .Be(Members().That().AreNot(PublicTestClassConstructor)); - var allMembersAreNotDeclaredInEmptyTypePattern = Members().That() - .AreNotDeclaredIn(typeof(PublicTestClass).FullName).Should() + var emptyTypeHasOnlyConstructor2 = Members() + .That() + .AreDeclaredIn(StaticTestTypes.PublicTestClass) + .Should() + .Be(PublicTestClassConstructor); + var emptyTypeHasOnlyConstructorPattern = Members() + .That() + .AreDeclaredIn(typeof(PublicTestClass).FullName) + .Should() + .Be(PublicTestClassConstructor); + var allMembersAreNotDeclaredInEmptyType1 = Members() + .That() + .AreNotDeclaredIn(typeof(PublicTestClass)) + .Should() + .Be(Members().That().AreNot(PublicTestClassConstructor)); + var allMembersAreNotDeclaredInEmptyType2 = Members() + .That() + .AreNotDeclaredIn(StaticTestTypes.PublicTestClass) + .Should() + .Be(Members().That().AreNot(PublicTestClassConstructor)); + var allMembersAreNotDeclaredInEmptyTypePattern = Members() + .That() + .AreNotDeclaredIn(typeof(PublicTestClass).FullName) + .Should() .Be(Members().That().AreNot(PublicTestClassConstructor)); Assert.True(emptyTypeHasOnlyConstructor1.HasNoViolations(Architecture)); @@ -137,28 +234,45 @@ public void DeclaredInTest() //Multiple Arguments - var emptyTypeHasOnlyConstructorMultiple1 = - Members().That().AreDeclaredIn(_falseTypes1).Should().Be(_falseTypeConstructors); - var emptyTypeHasOnlyConstructorMultiple2 = - Members().That().AreDeclaredIn(_falseTypes2).Should().Be(_falseTypeConstructors); - var emptyTypeHasOnlyConstructorMultiplePattern = - Members().That().AreDeclaredIn(_falseTypesPattern).Should().Be(_falseTypeConstructors); - var allMembersAreNotDeclaredInEmptyTypeMultiple1 = - Members().That().AreNotDeclaredIn(_falseTypes1).Should() - .Be(Members().That().AreNot(_falseTypeConstructors)); - var allMembersAreNotDeclaredInEmptyTypeMultiple2 = - Members().That().AreNotDeclaredIn(_falseTypes2).Should() - .Be(Members().That().AreNot(_falseTypeConstructors)); - var allMembersAreNotDeclaredInEmptyTypeMultiplePattern = - Members().That().AreNotDeclaredIn(_falseTypesPattern).Should() - .Be(Members().That().AreNot(_falseTypeConstructors)); + var emptyTypeHasOnlyConstructorMultiple1 = Members() + .That() + .AreDeclaredIn(_falseTypes1) + .Should() + .Be(_falseTypeConstructors); + var emptyTypeHasOnlyConstructorMultiple2 = Members() + .That() + .AreDeclaredIn(_falseTypes2) + .Should() + .Be(_falseTypeConstructors); + var emptyTypeHasOnlyConstructorMultiplePattern = Members() + .That() + .AreDeclaredIn(_falseTypesPattern) + .Should() + .Be(_falseTypeConstructors); + var allMembersAreNotDeclaredInEmptyTypeMultiple1 = Members() + .That() + .AreNotDeclaredIn(_falseTypes1) + .Should() + .Be(Members().That().AreNot(_falseTypeConstructors)); + var allMembersAreNotDeclaredInEmptyTypeMultiple2 = Members() + .That() + .AreNotDeclaredIn(_falseTypes2) + .Should() + .Be(Members().That().AreNot(_falseTypeConstructors)); + var allMembersAreNotDeclaredInEmptyTypeMultiplePattern = Members() + .That() + .AreNotDeclaredIn(_falseTypesPattern) + .Should() + .Be(Members().That().AreNot(_falseTypeConstructors)); Assert.True(emptyTypeHasOnlyConstructorMultiple1.HasNoViolations(Architecture)); Assert.True(emptyTypeHasOnlyConstructorMultiple2.HasNoViolations(Architecture)); Assert.True(emptyTypeHasOnlyConstructorMultiplePattern.HasNoViolations(Architecture)); Assert.True(allMembersAreNotDeclaredInEmptyTypeMultiple1.HasNoViolations(Architecture)); Assert.True(allMembersAreNotDeclaredInEmptyTypeMultiple2.HasNoViolations(Architecture)); - Assert.True(allMembersAreNotDeclaredInEmptyTypeMultiplePattern.HasNoViolations(Architecture)); + Assert.True( + allMembersAreNotDeclaredInEmptyTypeMultiplePattern.HasNoViolations(Architecture) + ); } [Fact] @@ -175,7 +289,6 @@ public void IsStaticTest() Assert.False(wrongStatic2.HasNoViolations(Architecture)); } - [Fact] public void AreImmutableTest() { @@ -183,30 +296,58 @@ public void AreImmutableTest() { var memberIsImmutable = Members().That().Are(member).Should().BeImmutable(); var memberIsNotImmutable = Members().That().Are(member).Should().NotBeImmutable(); - var membersThatAreImmutableDoNotIncludeMember = - Members().That().AreImmutable().Should().NotBe(member).OrShould().NotExist(); - var membersThatAreNotImmutableDoNotIncludeMember = - Members().That().AreNotImmutable().Should().NotBe(member).AndShould().Exist(); + var membersThatAreImmutableDoNotIncludeMember = Members() + .That() + .AreImmutable() + .Should() + .NotBe(member) + .OrShould() + .NotExist(); + var membersThatAreNotImmutableDoNotIncludeMember = Members() + .That() + .AreNotImmutable() + .Should() + .NotBe(member) + .AndShould() + .Exist(); bool isImmutable = member.Writability.IsImmutable(); - Assert.Equal(isImmutable, - memberIsImmutable.HasNoViolations(Architecture)); - Assert.Equal(!isImmutable, - memberIsNotImmutable.HasNoViolations(Architecture)); - Assert.Equal(!isImmutable, - membersThatAreImmutableDoNotIncludeMember.HasNoViolations(Architecture)); - Assert.Equal(isImmutable, - membersThatAreNotImmutableDoNotIncludeMember.HasNoViolations(Architecture)); + Assert.Equal(isImmutable, memberIsImmutable.HasNoViolations(Architecture)); + Assert.Equal(!isImmutable, memberIsNotImmutable.HasNoViolations(Architecture)); + Assert.Equal( + !isImmutable, + membersThatAreImmutableDoNotIncludeMember.HasNoViolations(Architecture) + ); + Assert.Equal( + isImmutable, + membersThatAreNotImmutableDoNotIncludeMember.HasNoViolations(Architecture) + ); } - var membersThatAreImmutableAreImmutable = - Members().That().AreImmutable().Should().BeImmutable(); - var membersThatAreImmutableAreNotImmutable = - Members().That().AreImmutable().Should().NotBeImmutable().AndShould().Exist(); - var membersThatAreNotImmutableAreImmutable = - Members().That().AreNotImmutable().Should().BeImmutable().AndShould().Exist(); - var membersThatAreNotImmutableAreNotImmutable = - Members().That().AreNotImmutable().Should().NotBeImmutable(); + var membersThatAreImmutableAreImmutable = Members() + .That() + .AreImmutable() + .Should() + .BeImmutable(); + var membersThatAreImmutableAreNotImmutable = Members() + .That() + .AreImmutable() + .Should() + .NotBeImmutable() + .AndShould() + .Exist(); + var membersThatAreNotImmutableAreImmutable = Members() + .That() + .AreNotImmutable() + .Should() + .BeImmutable() + .AndShould() + .Exist(); + var membersThatAreNotImmutableAreNotImmutable = Members() + .That() + .AreNotImmutable() + .Should() + .NotBeImmutable(); Assert.True(membersThatAreImmutableAreImmutable.HasNoViolations(Architecture)); Assert.False(membersThatAreImmutableAreNotImmutable.HasNoViolations(Architecture)); @@ -214,4 +355,4 @@ public void AreImmutableTest() Assert.True(membersThatAreNotImmutableAreNotImmutable.HasNoViolations(Architecture)); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/MethodMemberSyntaxElementsTests.cs b/ArchUnitNETTests/Fluent/Syntax/Elements/MethodMemberSyntaxElementsTests.cs index d2ddebcae..e69148972 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/MethodMemberSyntaxElementsTests.cs +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/MethodMemberSyntaxElementsTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -16,7 +16,8 @@ namespace ArchUnitNETTests.Fluent.Syntax.Elements { public class MethodMemberSyntaxElementsTests { - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; private readonly IEnumerable _methodMembers; private readonly IEnumerable _types; @@ -31,33 +32,79 @@ public void AreConstructorsTest() { foreach (var methodMember in _methodMembers) { - var methodMemberIsConstructor = MethodMembers().That().Are(methodMember).Should().BeConstructor(); - var methodMemberIsNoConstructor = MethodMembers().That().Are(methodMember).Should().BeNoConstructor(); - var constructorMethodMembersDoNotIncludeMember = - MethodMembers().That().AreConstructors().Should().NotBe(methodMember).OrShould().NotExist(); - var noConstructorMethodMembersDoNotIncludeMember = - MethodMembers().That().AreNoConstructors().Should().NotBe(methodMember).AndShould().Exist(); - - Assert.Equal(methodMember.IsConstructor(), methodMemberIsConstructor.HasNoViolations(Architecture)); - Assert.Equal(!methodMember.IsConstructor(), methodMemberIsNoConstructor.HasNoViolations(Architecture)); - Assert.Equal(!methodMember.IsConstructor(), - constructorMethodMembersDoNotIncludeMember.HasNoViolations(Architecture)); - Assert.Equal(methodMember.IsConstructor(), - noConstructorMethodMembersDoNotIncludeMember.HasNoViolations(Architecture)); + var methodMemberIsConstructor = MethodMembers() + .That() + .Are(methodMember) + .Should() + .BeConstructor(); + var methodMemberIsNoConstructor = MethodMembers() + .That() + .Are(methodMember) + .Should() + .BeNoConstructor(); + var constructorMethodMembersDoNotIncludeMember = MethodMembers() + .That() + .AreConstructors() + .Should() + .NotBe(methodMember) + .OrShould() + .NotExist(); + var noConstructorMethodMembersDoNotIncludeMember = MethodMembers() + .That() + .AreNoConstructors() + .Should() + .NotBe(methodMember) + .AndShould() + .Exist(); + + Assert.Equal( + methodMember.IsConstructor(), + methodMemberIsConstructor.HasNoViolations(Architecture) + ); + Assert.Equal( + !methodMember.IsConstructor(), + methodMemberIsNoConstructor.HasNoViolations(Architecture) + ); + Assert.Equal( + !methodMember.IsConstructor(), + constructorMethodMembersDoNotIncludeMember.HasNoViolations(Architecture) + ); + Assert.Equal( + methodMember.IsConstructor(), + noConstructorMethodMembersDoNotIncludeMember.HasNoViolations(Architecture) + ); } - var constructorMethodMembersShouldBeConstructor = - MethodMembers().That().AreConstructors().Should().BeConstructor(); - var constructorMethodMembersAreNoConstructors = - MethodMembers().That().AreConstructors().Should().BeNoConstructor().AndShould().Exist(); - var noConstructorMethodMembersShouldBeConstructor = - MethodMembers().That().AreNoConstructors().Should().BeConstructor().AndShould().Exist(); - var noConstructorMethodMembersAreNoConstructors = - MethodMembers().That().AreNoConstructors().Should().BeNoConstructor(); + var constructorMethodMembersShouldBeConstructor = MethodMembers() + .That() + .AreConstructors() + .Should() + .BeConstructor(); + var constructorMethodMembersAreNoConstructors = MethodMembers() + .That() + .AreConstructors() + .Should() + .BeNoConstructor() + .AndShould() + .Exist(); + var noConstructorMethodMembersShouldBeConstructor = MethodMembers() + .That() + .AreNoConstructors() + .Should() + .BeConstructor() + .AndShould() + .Exist(); + var noConstructorMethodMembersAreNoConstructors = MethodMembers() + .That() + .AreNoConstructors() + .Should() + .BeNoConstructor(); Assert.True(constructorMethodMembersShouldBeConstructor.HasNoViolations(Architecture)); Assert.False(constructorMethodMembersAreNoConstructors.HasNoViolations(Architecture)); - Assert.False(noConstructorMethodMembersShouldBeConstructor.HasNoViolations(Architecture)); + Assert.False( + noConstructorMethodMembersShouldBeConstructor.HasNoViolations(Architecture) + ); Assert.True(noConstructorMethodMembersAreNoConstructors.HasNoViolations(Architecture)); } @@ -66,28 +113,74 @@ public void AreVirtualTest() { foreach (var methodMember in _methodMembers) { - var methodMemberIsVirtual = MethodMembers().That().Are(methodMember).Should().BeVirtual(); - var methodMemberIsNotVirtual = MethodMembers().That().Are(methodMember).Should().NotBeVirtual(); - var virtualMethodMembersDoNotIncludeMember = - MethodMembers().That().AreVirtual().Should().NotBe(methodMember).OrShould().NotExist(); - var notVirtualMethodMembersDoNotIncludeMember = - MethodMembers().That().AreNotVirtual().Should().NotBe(methodMember).AndShould().Exist(); - - Assert.Equal(methodMember.IsVirtual, methodMemberIsVirtual.HasNoViolations(Architecture)); - Assert.Equal(!methodMember.IsVirtual, methodMemberIsNotVirtual.HasNoViolations(Architecture)); - Assert.Equal(!methodMember.IsVirtual, - virtualMethodMembersDoNotIncludeMember.HasNoViolations(Architecture)); - Assert.Equal(methodMember.IsVirtual, - notVirtualMethodMembersDoNotIncludeMember.HasNoViolations(Architecture)); + var methodMemberIsVirtual = MethodMembers() + .That() + .Are(methodMember) + .Should() + .BeVirtual(); + var methodMemberIsNotVirtual = MethodMembers() + .That() + .Are(methodMember) + .Should() + .NotBeVirtual(); + var virtualMethodMembersDoNotIncludeMember = MethodMembers() + .That() + .AreVirtual() + .Should() + .NotBe(methodMember) + .OrShould() + .NotExist(); + var notVirtualMethodMembersDoNotIncludeMember = MethodMembers() + .That() + .AreNotVirtual() + .Should() + .NotBe(methodMember) + .AndShould() + .Exist(); + + Assert.Equal( + methodMember.IsVirtual, + methodMemberIsVirtual.HasNoViolations(Architecture) + ); + Assert.Equal( + !methodMember.IsVirtual, + methodMemberIsNotVirtual.HasNoViolations(Architecture) + ); + Assert.Equal( + !methodMember.IsVirtual, + virtualMethodMembersDoNotIncludeMember.HasNoViolations(Architecture) + ); + Assert.Equal( + methodMember.IsVirtual, + notVirtualMethodMembersDoNotIncludeMember.HasNoViolations(Architecture) + ); } - var virtualMethodMembersShouldBeVirtual = MethodMembers().That().AreVirtual().Should().BeVirtual().WithoutRequiringPositiveResults(); - var virtualMethodMembersAreNotVirtual = - MethodMembers().That().AreVirtual().Should().NotBeVirtual().AndShould().Exist(); - var notVirtualMethodMembersShouldBeVirtual = - MethodMembers().That().AreNotVirtual().Should().BeVirtual().AndShould().Exist(); - var notVirtualMethodMembersAreNotVirtual = - MethodMembers().That().AreNotVirtual().Should().NotBeVirtual(); + var virtualMethodMembersShouldBeVirtual = MethodMembers() + .That() + .AreVirtual() + .Should() + .BeVirtual() + .WithoutRequiringPositiveResults(); + var virtualMethodMembersAreNotVirtual = MethodMembers() + .That() + .AreVirtual() + .Should() + .NotBeVirtual() + .AndShould() + .Exist(); + var notVirtualMethodMembersShouldBeVirtual = MethodMembers() + .That() + .AreNotVirtual() + .Should() + .BeVirtual() + .AndShould() + .Exist(); + var notVirtualMethodMembersAreNotVirtual = MethodMembers() + .That() + .AreNotVirtual() + .Should() + .NotBeVirtual(); Assert.True(virtualMethodMembersShouldBeVirtual.HasNoViolations(Architecture)); Assert.False(virtualMethodMembersAreNotVirtual.HasNoViolations(Architecture)); @@ -100,21 +193,36 @@ public void CalledByTest() { foreach (var methodMember in _methodMembers) { - foreach (var callingType in methodMember.GetMethodCallDependencies(true) - .Select(dependency => dependency.Origin.FullName)) + foreach ( + var callingType in methodMember + .GetMethodCallDependencies(true) + .Select(dependency => dependency.Origin.FullName) + ) { - var methodIsCalledByRightType = - MethodMembers().That().Are(methodMember).Should().BeCalledBy(callingType); - var methodIsNotCalledByRightType = - MethodMembers().That().Are(methodMember).Should().NotBeCalledBy(callingType); + var methodIsCalledByRightType = MethodMembers() + .That() + .Are(methodMember) + .Should() + .BeCalledBy(callingType); + var methodIsNotCalledByRightType = MethodMembers() + .That() + .Are(methodMember) + .Should() + .NotBeCalledBy(callingType); Assert.True(methodIsCalledByRightType.HasNoViolations(Architecture)); Assert.False(methodIsNotCalledByRightType.HasNoViolations(Architecture)); } - var methodIsCalledByFalseType = MethodMembers().That().Are(methodMember).Should() + var methodIsCalledByFalseType = MethodMembers() + .That() + .Are(methodMember) + .Should() .BeCalledBy(typeof(PublicTestClass).FullName); - var methodIsNotCalledByFalseType = MethodMembers().That().Are(methodMember).Should() + var methodIsNotCalledByFalseType = MethodMembers() + .That() + .Are(methodMember) + .Should() .NotBeCalledBy(typeof(PublicTestClass).FullName); Assert.False(methodIsCalledByFalseType.HasNoViolations(Architecture)); @@ -123,36 +231,57 @@ public void CalledByTest() foreach (var type in _types) { - var calledMethodsShouldBeCalled = MethodMembers().That().AreCalledBy(type.FullName).Should() - .BeCalledBy(type.FullName).WithoutRequiringPositiveResults(); - var notCalledMethodsShouldNotBeCalled = MethodMembers().That().AreNotCalledBy(type.FullName).Should() + var calledMethodsShouldBeCalled = MethodMembers() + .That() + .AreCalledBy(type.FullName) + .Should() + .BeCalledBy(type.FullName) + .WithoutRequiringPositiveResults(); + var notCalledMethodsShouldNotBeCalled = MethodMembers() + .That() + .AreNotCalledBy(type.FullName) + .Should() .NotBeCalledBy(type.FullName); Assert.True(calledMethodsShouldBeCalled.HasNoViolations(Architecture)); Assert.True(notCalledMethodsShouldNotBeCalled.HasNoViolations(Architecture)); } - var emptyTypeCallsNoMethods = - MethodMembers().That().AreCalledBy(typeof(PublicTestClass).FullName).Should().NotExist(); - var methodsNotCalledByEmptyTypeShouldExist = MethodMembers().That() - .AreNotCalledBy(typeof(PublicTestClass).FullName).Should().Exist(); + var emptyTypeCallsNoMethods = MethodMembers() + .That() + .AreCalledBy(typeof(PublicTestClass).FullName) + .Should() + .NotExist(); + var methodsNotCalledByEmptyTypeShouldExist = MethodMembers() + .That() + .AreNotCalledBy(typeof(PublicTestClass).FullName) + .Should() + .Exist(); Assert.True(emptyTypeCallsNoMethods.HasNoViolations(Architecture)); Assert.True(methodsNotCalledByEmptyTypeShouldExist.HasNoViolations(Architecture)); } - [Fact] public void HaveDependencyInMethodBodyTest() { foreach (var methodMember in _methodMembers) { - foreach (var dependency in methodMember.GetBodyTypeMemberDependencies() - .Select(dependency => dependency.Target.FullName)) + foreach ( + var dependency in methodMember + .GetBodyTypeMemberDependencies() + .Select(dependency => dependency.Target.FullName) + ) { - var hasRightDependency = MethodMembers().That().Are(methodMember).Should() + var hasRightDependency = MethodMembers() + .That() + .Are(methodMember) + .Should() .HaveDependencyInMethodBodyTo(dependency); - var doesNotHaveRightDependency = MethodMembers().That().Are(methodMember).Should() + var doesNotHaveRightDependency = MethodMembers() + .That() + .Are(methodMember) + .Should() .NotHaveDependencyInMethodBodyTo(dependency); Assert.True(hasRightDependency.HasNoViolations(Architecture)); @@ -162,12 +291,16 @@ public void HaveDependencyInMethodBodyTest() foreach (var type in _types) { - var dependentMethodsShouldBeDependent = MethodMembers().That() - .HaveDependencyInMethodBodyTo(type.FullName).Should() + var dependentMethodsShouldBeDependent = MethodMembers() + .That() + .HaveDependencyInMethodBodyTo(type.FullName) + .Should() .HaveDependencyInMethodBodyTo(type.FullName) .WithoutRequiringPositiveResults(); - var notDependentMethodsShouldNotBeDependent = MethodMembers().That() - .DoNotHaveDependencyInMethodBodyTo(type.FullName).Should() + var notDependentMethodsShouldNotBeDependent = MethodMembers() + .That() + .DoNotHaveDependencyInMethodBodyTo(type.FullName) + .Should() .NotHaveDependencyInMethodBodyTo(type.FullName); Assert.True(dependentMethodsShouldBeDependent.HasNoViolations(Architecture)); @@ -178,37 +311,59 @@ public void HaveDependencyInMethodBodyTest() [Fact] public void HaveReturnTypeConditionTest() { - var stringReturnTypes = new List {"Void", "String", "ReturnTypeClass"}; - var retTypeWithString = MethodMembers().That().HaveFullNameContaining("ReturnTypeMethod").Should() + var stringReturnTypes = new List { "Void", "String", "ReturnTypeClass" }; + var retTypeWithString = MethodMembers() + .That() + .HaveFullNameContaining("ReturnTypeMethod") + .Should() .HaveReturnType(stringReturnTypes, true); - var retTypeWithStringFail = MethodMembers().That().HaveFullNameContaining("ReturnTypeMethod").Should() + var retTypeWithStringFail = MethodMembers() + .That() + .HaveFullNameContaining("ReturnTypeMethod") + .Should() .HaveReturnType("bool", true); Assert.True(retTypeWithString.HasNoViolations(Architecture)); Assert.False(retTypeWithStringFail.HasNoViolations(Architecture)); - var retTypeWithType = MethodMembers().That().HaveFullNameContaining("ReturnTypeMethod").Should() + var retTypeWithType = MethodMembers() + .That() + .HaveFullNameContaining("ReturnTypeMethod") + .Should() .HaveReturnType(typeof(ReturnTypeClass), typeof(void), typeof(string)); - var retTypeWithTypeFail = MethodMembers().That().HaveFullNameContaining("ReturnTypeMethod").Should() + var retTypeWithTypeFail = MethodMembers() + .That() + .HaveFullNameContaining("ReturnTypeMethod") + .Should() .HaveReturnType(typeof(bool)); Assert.True(retTypeWithType.HasNoViolations(Architecture)); Assert.False(retTypeWithTypeFail.HasNoViolations(Architecture)); var objectProviderClass = Classes().That().HaveFullNameContaining("ReturnTypeClass"); - var retTypeWithObjectProvider = MethodMembers().That().HaveFullNameContaining("ReturnTypeMethodClass") + var retTypeWithObjectProvider = MethodMembers() + .That() + .HaveFullNameContaining("ReturnTypeMethodClass") .Should() .HaveReturnType(objectProviderClass); - var retTypeWithObjectProviderFail = MethodMembers().That().HaveFullNameContaining("ReturnTypeMethodVoid") + var retTypeWithObjectProviderFail = MethodMembers() + .That() + .HaveFullNameContaining("ReturnTypeMethodVoid") .Should() .HaveReturnType(objectProviderClass); Assert.True(retTypeWithObjectProvider.HasNoViolations(Architecture)); Assert.False(retTypeWithObjectProviderFail.HasNoViolations(Architecture)); - var retTypeWithIType = MethodMembers().That().HaveFullNameContaining("ReturnTypeMethodClass").Should() + var retTypeWithIType = MethodMembers() + .That() + .HaveFullNameContaining("ReturnTypeMethodClass") + .Should() .HaveReturnType(objectProviderClass.GetObjects(Architecture).ToList().First()); - var retTypeWithITypeFail = MethodMembers().That().HaveFullNameContaining("ReturnTypeMethodString").Should() + var retTypeWithITypeFail = MethodMembers() + .That() + .HaveFullNameContaining("ReturnTypeMethodString") + .Should() .HaveReturnType(objectProviderClass.GetObjects(Architecture).ToList().First()); Assert.True(retTypeWithIType.HasNoViolations(Architecture)); @@ -218,37 +373,59 @@ public void HaveReturnTypeConditionTest() [Fact] public void NotHaveReturnTypeConditionTest() { - var stringReturnTypes = new List {"Void", "String", "ReturnTypeClass"}; - var retTypeWithString = MethodMembers().That().HaveFullNameContaining("ReturnTypeMethod").Should() + var stringReturnTypes = new List { "Void", "String", "ReturnTypeClass" }; + var retTypeWithString = MethodMembers() + .That() + .HaveFullNameContaining("ReturnTypeMethod") + .Should() .NotHaveReturnType("bool", true); - var retTypeWithStringFail = MethodMembers().That().HaveFullNameContaining("ReturnTypeMethod").Should() + var retTypeWithStringFail = MethodMembers() + .That() + .HaveFullNameContaining("ReturnTypeMethod") + .Should() .NotHaveReturnType(stringReturnTypes, true); Assert.True(retTypeWithString.HasNoViolations(Architecture)); Assert.False(retTypeWithStringFail.HasNoViolations(Architecture)); - var retTypeWithType = MethodMembers().That().HaveFullNameContaining("ReturnTypeMethod").Should() + var retTypeWithType = MethodMembers() + .That() + .HaveFullNameContaining("ReturnTypeMethod") + .Should() .NotHaveReturnType(typeof(bool)); - var retTypeWithTypeFail = MethodMembers().That().HaveFullNameContaining("ReturnTypeMethod").Should() + var retTypeWithTypeFail = MethodMembers() + .That() + .HaveFullNameContaining("ReturnTypeMethod") + .Should() .NotHaveReturnType(typeof(ReturnTypeClass), typeof(void), typeof(string)); Assert.True(retTypeWithType.HasNoViolations(Architecture)); Assert.False(retTypeWithTypeFail.HasNoViolations(Architecture)); var objectProviderClass = Classes().That().HaveFullNameContaining("ReturnTypeClass"); - var retTypeWithObjectProvider = MethodMembers().That().HaveFullNameContaining("ReturnTypeMethodVoid") + var retTypeWithObjectProvider = MethodMembers() + .That() + .HaveFullNameContaining("ReturnTypeMethodVoid") .Should() .NotHaveReturnType(objectProviderClass); - var retTypeWithObjectProviderFail = MethodMembers().That().HaveFullNameContaining("ReturnTypeMethodClass") + var retTypeWithObjectProviderFail = MethodMembers() + .That() + .HaveFullNameContaining("ReturnTypeMethodClass") .Should() .NotHaveReturnType(objectProviderClass); Assert.True(retTypeWithObjectProvider.HasNoViolations(Architecture)); Assert.False(retTypeWithObjectProviderFail.HasNoViolations(Architecture)); - var retTypeWithIType = MethodMembers().That().HaveFullNameContaining("ReturnTypeMethodString").Should() + var retTypeWithIType = MethodMembers() + .That() + .HaveFullNameContaining("ReturnTypeMethodString") + .Should() .NotHaveReturnType(objectProviderClass.GetObjects(Architecture).ToList().First()); - var retTypeWithITypeFail = MethodMembers().That().HaveFullNameContaining("ReturnTypeMethodClass").Should() + var retTypeWithITypeFail = MethodMembers() + .That() + .HaveFullNameContaining("ReturnTypeMethodClass") + .Should() .NotHaveReturnType(objectProviderClass.GetObjects(Architecture).ToList().First()); Assert.True(retTypeWithIType.HasNoViolations(Architecture)); @@ -258,40 +435,78 @@ public void NotHaveReturnTypeConditionTest() [Fact] public void HaveReturnTypePredicateTest() { - var stringReturnTypes = new List {"void", "string"}; - var retTypeWithString = MethodMembers().That().HaveFullNameContaining("ReturnTypeMethod").And() - .HaveReturnType(stringReturnTypes, true).Should().HaveFullNameContaining("Void").OrShould().HaveFullNameContaining("String").WithoutRequiringPositiveResults(); - var retTypeWithStringNegate = MethodMembers().That().DoNotHaveReturnType("String", true).And() - .HaveFullNameContaining("ReturnTypeMethod").Should().NotHaveFullNameContaining("String"); + var stringReturnTypes = new List { "void", "string" }; + var retTypeWithString = MethodMembers() + .That() + .HaveFullNameContaining("ReturnTypeMethod") + .And() + .HaveReturnType(stringReturnTypes, true) + .Should() + .HaveFullNameContaining("Void") + .OrShould() + .HaveFullNameContaining("String") + .WithoutRequiringPositiveResults(); + var retTypeWithStringNegate = MethodMembers() + .That() + .DoNotHaveReturnType("String", true) + .And() + .HaveFullNameContaining("ReturnTypeMethod") + .Should() + .NotHaveFullNameContaining("String"); Assert.True(retTypeWithString.HasNoViolations(Architecture)); Assert.True(retTypeWithStringNegate.HasNoViolations(Architecture)); - var retTypeWithType = MethodMembers().That().HaveFullNameContaining("ReturnTypeMethod").And() - .HaveReturnType(typeof(ReturnTypeClass)).Should().HaveFullNameContaining("Class"); - var retTypeWithTypeFail = MethodMembers().That().HaveFullNameContaining("ReturnTypeMethod").And() - .DoNotHaveReturnType(typeof(ReturnTypeClass)).Should().HaveNameContaining("Class"); + var retTypeWithType = MethodMembers() + .That() + .HaveFullNameContaining("ReturnTypeMethod") + .And() + .HaveReturnType(typeof(ReturnTypeClass)) + .Should() + .HaveFullNameContaining("Class"); + var retTypeWithTypeFail = MethodMembers() + .That() + .HaveFullNameContaining("ReturnTypeMethod") + .And() + .DoNotHaveReturnType(typeof(ReturnTypeClass)) + .Should() + .HaveNameContaining("Class"); Assert.True(retTypeWithType.HasNoViolations(Architecture)); Assert.False(retTypeWithTypeFail.HasNoViolations(Architecture)); var objectProviderClass = Classes().That().HaveFullNameContaining("ReturnTypeClass"); - var retTypeWithObjectProvider = MethodMembers().That().HaveReturnType("ReturnTypeClass",true) - .Should().HaveFullNameContaining("ReturnTypeMethodClass"); - var retTypeWithObjectProviderFail = MethodMembers().That().DoNotHaveReturnType("ReturnTypeClass",true) - .And().HaveFullNameContaining("ReturnTypeMethod") - .Should().HaveFullNameContaining("ReturnTypeMethodClass"); + var retTypeWithObjectProvider = MethodMembers() + .That() + .HaveReturnType("ReturnTypeClass", true) + .Should() + .HaveFullNameContaining("ReturnTypeMethodClass"); + var retTypeWithObjectProviderFail = MethodMembers() + .That() + .DoNotHaveReturnType("ReturnTypeClass", true) + .And() + .HaveFullNameContaining("ReturnTypeMethod") + .Should() + .HaveFullNameContaining("ReturnTypeMethodClass"); Assert.True(retTypeWithObjectProvider.HasNoViolations(Architecture)); Assert.False(retTypeWithObjectProviderFail.HasNoViolations(Architecture)); - var retTypeWithITypeFail = MethodMembers().That() - .HaveReturnType(objectProviderClass.GetObjects(Architecture).ToList().First()).Should() + var retTypeWithITypeFail = MethodMembers() + .That() + .HaveReturnType(objectProviderClass.GetObjects(Architecture).ToList().First()) + .Should() .HaveFullNameContaining("ReturnTypeMethodVoid"); - var retTypeWithITypeNegate = MethodMembers().That().HaveFullNameContaining("ReturnTypeMethod") - .And().DoNotHaveReturnType(objectProviderClass.GetObjects(Architecture).ToList().First()).Should() - .HaveFullNameContaining("String").OrShould().HaveFullNameContaining("Void"); + var retTypeWithITypeNegate = MethodMembers() + .That() + .HaveFullNameContaining("ReturnTypeMethod") + .And() + .DoNotHaveReturnType(objectProviderClass.GetObjects(Architecture).ToList().First()) + .Should() + .HaveFullNameContaining("String") + .OrShould() + .HaveFullNameContaining("Void"); Assert.False(retTypeWithITypeFail.HasNoViolations(Architecture)); Assert.True(retTypeWithITypeNegate.HasNoViolations(Architecture)); @@ -300,9 +515,7 @@ public void HaveReturnTypePredicateTest() internal class ReturnTypeClass { - public void ReturnTypeMethodVoid() - { - } + public void ReturnTypeMethodVoid() { } public string ReturnTypeMethodString() { @@ -314,4 +527,4 @@ public ReturnTypeClass ReturnTypeMethodClass() return new ReturnTypeClass(); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectSyntaxElementsTests.cs b/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectSyntaxElementsTests.cs index 0844c1459..1ca9ee892 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectSyntaxElementsTests.cs +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/ObjectSyntaxElementsTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -13,18 +13,22 @@ using ArchUnitNET.xUnit; using ArchUnitNETTests.Domain; using Xunit; -using static ArchUnitNETTests.Domain.StaticTestTypes; using static ArchUnitNET.Fluent.ArchRuleDefinition; +using static ArchUnitNETTests.Domain.StaticTestTypes; namespace ArchUnitNETTests.Fluent.Syntax.Elements { public class ObjectSyntaxElementsTests { private const string NoTypeName = "NotTheNameOfAnyType_58391351286"; - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; private readonly IEnumerable _falseDependencies = new List - {typeof(ClassWithNoDependencies1), typeof(ClassWithNoDependencies2)}; + { + typeof(ClassWithNoDependencies1), + typeof(ClassWithNoDependencies2) + }; private readonly IEnumerable _types = Architecture.Types; @@ -40,11 +44,26 @@ public void AreTest() var otherTypesAreNotThisType = Types().That().AreNot(type).Should().NotBe(type); var otherTypesAreThisType = Types().That().AreNot(type).Should().Be(type); - var typeIsItselfPattern = Types().That().Are(type.FullName).Should().Be(type.FullName); - var typeIsNotItselfPattern = Types().That().Are(type.FullName).Should().NotBe(type.FullName); - var otherTypesAreNotThisTypePattern = - Types().That().AreNot(type.FullName).Should().NotBe(type.FullName); - var otherTypesAreThisTypePattern = Types().That().AreNot(type.FullName).Should().Be(type.FullName); + var typeIsItselfPattern = Types() + .That() + .Are(type.FullName) + .Should() + .Be(type.FullName); + var typeIsNotItselfPattern = Types() + .That() + .Are(type.FullName) + .Should() + .NotBe(type.FullName); + var otherTypesAreNotThisTypePattern = Types() + .That() + .AreNot(type.FullName) + .Should() + .NotBe(type.FullName); + var otherTypesAreThisTypePattern = Types() + .That() + .AreNot(type.FullName) + .Should() + .Be(type.FullName); Assert.True(typeIsItself.HasNoViolations(Architecture)); Assert.False(typeIsNotItself.HasNoViolations(Architecture)); @@ -57,22 +76,47 @@ public void AreTest() Assert.False(otherTypesAreThisTypePattern.HasNoViolations(Architecture)); } - var publicTestClassIsPublic = Types().That().Are(StaticTestTypes.PublicTestClass).Should().BePublic(); - var publicTestClassIsNotPublic = Types().That().Are(StaticTestTypes.PublicTestClass).Should().NotBePublic(); - var notPublicTypesAreNotPublicTestClass = - Types().That().AreNotPublic().Should().NotBe(StaticTestTypes.PublicTestClass); - var publicTypesAreNotPublicTestClass = - Types().That().ArePublic().Should().NotBe(StaticTestTypes.PublicTestClass); - - var publicTestClassIsPublicPattern = - Types().That().Are(StaticTestTypes.PublicTestClass.FullName).Should().BePublic(); - var publicTestClassIsNotPublicPattern = - Types().That().Are(StaticTestTypes.PublicTestClass.FullName).Should().NotBePublic(); - var notPublicTypesAreNotPublicTestClassPattern = - Types().That().AreNotPublic().Should().NotBe(StaticTestTypes.PublicTestClass.FullName); - var publicTypesAreNotPublicTestClassPattern = - Types().That().ArePublic().Should().NotBe(StaticTestTypes.PublicTestClass.FullName); - + var publicTestClassIsPublic = Types() + .That() + .Are(StaticTestTypes.PublicTestClass) + .Should() + .BePublic(); + var publicTestClassIsNotPublic = Types() + .That() + .Are(StaticTestTypes.PublicTestClass) + .Should() + .NotBePublic(); + var notPublicTypesAreNotPublicTestClass = Types() + .That() + .AreNotPublic() + .Should() + .NotBe(StaticTestTypes.PublicTestClass); + var publicTypesAreNotPublicTestClass = Types() + .That() + .ArePublic() + .Should() + .NotBe(StaticTestTypes.PublicTestClass); + + var publicTestClassIsPublicPattern = Types() + .That() + .Are(StaticTestTypes.PublicTestClass.FullName) + .Should() + .BePublic(); + var publicTestClassIsNotPublicPattern = Types() + .That() + .Are(StaticTestTypes.PublicTestClass.FullName) + .Should() + .NotBePublic(); + var notPublicTypesAreNotPublicTestClassPattern = Types() + .That() + .AreNotPublic() + .Should() + .NotBe(StaticTestTypes.PublicTestClass.FullName); + var publicTypesAreNotPublicTestClassPattern = Types() + .That() + .ArePublic() + .Should() + .NotBe(StaticTestTypes.PublicTestClass.FullName); Assert.True(publicTestClassIsPublic.HasNoViolations(Architecture)); Assert.False(publicTestClassIsNotPublic.HasNoViolations(Architecture)); @@ -84,63 +128,141 @@ public void AreTest() Assert.True(notPublicTypesAreNotPublicTestClassPattern.HasNoViolations(Architecture)); Assert.False(publicTypesAreNotPublicTestClassPattern.HasNoViolations(Architecture)); - //Tests with multiple arguments - var publicTestClassAndInternalTestClassIsPublicOrInternal = Types().That() - .Are(StaticTestTypes.PublicTestClass, StaticTestTypes.InternalTestClass).Should().BePublic().OrShould() + var publicTestClassAndInternalTestClassIsPublicOrInternal = Types() + .That() + .Are(StaticTestTypes.PublicTestClass, StaticTestTypes.InternalTestClass) + .Should() + .BePublic() + .OrShould() .BeInternal(); - var publicTestClassAndInternalTestClassIsPublic = Types().That() - .Are(StaticTestTypes.PublicTestClass, StaticTestTypes.InternalTestClass).Should().BePublic(); - var notPublicAndNotInternalClassesAreNotPublicTestClassOrInternalTestClass = Types().That().AreNotPublic() - .And().AreNotInternal().Should() + var publicTestClassAndInternalTestClassIsPublic = Types() + .That() + .Are(StaticTestTypes.PublicTestClass, StaticTestTypes.InternalTestClass) + .Should() + .BePublic(); + var notPublicAndNotInternalClassesAreNotPublicTestClassOrInternalTestClass = Types() + .That() + .AreNotPublic() + .And() + .AreNotInternal() + .Should() .NotBe(StaticTestTypes.PublicTestClass, StaticTestTypes.InternalTestClass); - var internalTypesAreNotPublicTestClassOrInternalTestClass = Types().That().AreInternal().Should() + var internalTypesAreNotPublicTestClassOrInternalTestClass = Types() + .That() + .AreInternal() + .Should() .NotBe(StaticTestTypes.PublicTestClass, StaticTestTypes.InternalTestClass); - Assert.True(publicTestClassAndInternalTestClassIsPublicOrInternal.HasNoViolations(Architecture)); + Assert.True( + publicTestClassAndInternalTestClassIsPublicOrInternal.HasNoViolations(Architecture) + ); Assert.False(publicTestClassAndInternalTestClassIsPublic.HasNoViolations(Architecture)); Assert.True( - notPublicAndNotInternalClassesAreNotPublicTestClassOrInternalTestClass.HasNoViolations(Architecture)); - Assert.False(internalTypesAreNotPublicTestClassOrInternalTestClass.HasNoViolations(Architecture)); - + notPublicAndNotInternalClassesAreNotPublicTestClassOrInternalTestClass.HasNoViolations( + Architecture + ) + ); + Assert.False( + internalTypesAreNotPublicTestClassOrInternalTestClass.HasNoViolations(Architecture) + ); //Tests with list - var list = new List {StaticTestTypes.PublicTestClass, StaticTestTypes.InternalTestClass}; - var listPublicTestClassAndInternalTestClassIsPublicOrInternal = - Types().That().Are(list).Should().BePublic().OrShould().BeInternal(); - var listPublicTestClassAndInternalTestClassIsPublic = Types().That().Are(list).Should().BePublic(); - var listNotPublicAndNotInternalClassesAreNotPublicTestClassOrInternalTestClass = - Types().That().AreNotPublic().And().AreNotInternal().Should().NotBe(list); - var listInternalTypesAreNotPublicTestClassOrInternalTestClass = - Types().That().AreInternal().Should().NotBe(list); + var list = new List + { + StaticTestTypes.PublicTestClass, + StaticTestTypes.InternalTestClass + }; + var listPublicTestClassAndInternalTestClassIsPublicOrInternal = Types() + .That() + .Are(list) + .Should() + .BePublic() + .OrShould() + .BeInternal(); + var listPublicTestClassAndInternalTestClassIsPublic = Types() + .That() + .Are(list) + .Should() + .BePublic(); + var listNotPublicAndNotInternalClassesAreNotPublicTestClassOrInternalTestClass = Types() + .That() + .AreNotPublic() + .And() + .AreNotInternal() + .Should() + .NotBe(list); + var listInternalTypesAreNotPublicTestClassOrInternalTestClass = Types() + .That() + .AreInternal() + .Should() + .NotBe(list); var patternList = new List - {StaticTestTypes.PublicTestClass.FullName, StaticTestTypes.InternalTestClass.FullName}; - var publicTestClassAndInternalTestClassIsPublicOrInternalPattern = - Types().That().Are(patternList).Should().BePublic().OrShould().BeInternal(); - var publicTestClassAndInternalTestClassIsPublicPattern = - Types().That().Are(patternList).Should().BePublic(); + { + StaticTestTypes.PublicTestClass.FullName, + StaticTestTypes.InternalTestClass.FullName + }; + var publicTestClassAndInternalTestClassIsPublicOrInternalPattern = Types() + .That() + .Are(patternList) + .Should() + .BePublic() + .OrShould() + .BeInternal(); + var publicTestClassAndInternalTestClassIsPublicPattern = Types() + .That() + .Are(patternList) + .Should() + .BePublic(); var notPublicAndNotInternalClassesAreNotPublicTestClassOrInternalTestClassPattern = Types().That().AreNotPublic().And().AreNotInternal().Should().NotBe(patternList); - var internalTypesAreNotPublicTestClassOrInternalTestClassPattern = - Types().That().AreInternal().Should().NotBe(patternList); + var internalTypesAreNotPublicTestClassOrInternalTestClassPattern = Types() + .That() + .AreInternal() + .Should() + .NotBe(patternList); - Assert.True(listPublicTestClassAndInternalTestClassIsPublicOrInternal.HasNoViolations(Architecture)); - Assert.False(listPublicTestClassAndInternalTestClassIsPublic.HasNoViolations(Architecture)); Assert.True( - listNotPublicAndNotInternalClassesAreNotPublicTestClassOrInternalTestClass - .HasNoViolations(Architecture)); - Assert.False(listInternalTypesAreNotPublicTestClassOrInternalTestClass.HasNoViolations(Architecture)); + listPublicTestClassAndInternalTestClassIsPublicOrInternal.HasNoViolations( + Architecture + ) + ); + Assert.False( + listPublicTestClassAndInternalTestClassIsPublic.HasNoViolations(Architecture) + ); + Assert.True( + listNotPublicAndNotInternalClassesAreNotPublicTestClassOrInternalTestClass.HasNoViolations( + Architecture + ) + ); + Assert.False( + listInternalTypesAreNotPublicTestClassOrInternalTestClass.HasNoViolations( + Architecture + ) + ); - Assert.True(publicTestClassAndInternalTestClassIsPublicOrInternalPattern.HasNoViolations(Architecture)); - Assert.False(publicTestClassAndInternalTestClassIsPublicPattern.HasNoViolations(Architecture)); + Assert.True( + publicTestClassAndInternalTestClassIsPublicOrInternalPattern.HasNoViolations( + Architecture + ) + ); + Assert.False( + publicTestClassAndInternalTestClassIsPublicPattern.HasNoViolations(Architecture) + ); Assert.True( notPublicAndNotInternalClassesAreNotPublicTestClassOrInternalTestClassPattern.HasNoViolations( - Architecture)); - Assert.False(internalTypesAreNotPublicTestClassOrInternalTestClassPattern.HasNoViolations(Architecture)); + Architecture + ) + ); + Assert.False( + internalTypesAreNotPublicTestClassOrInternalTestClassPattern.HasNoViolations( + Architecture + ) + ); } [Fact] @@ -150,13 +272,23 @@ public void DependOnPatternTest() { //One Argument - var typesDependOnOwnDependencies = - Types().That().DependOnAny(type.FullName).Should() - .DependOnAny(type.FullName).WithoutRequiringPositiveResults(); - var typeDoesNotDependOnFalseDependency = - Types().That().Are(type).Should().NotDependOnAny(NoTypeName); - var typeDependsOnFalseDependency = - Types().That().Are(type).Should().DependOnAny(NoTypeName).WithoutRequiringPositiveResults(); + var typesDependOnOwnDependencies = Types() + .That() + .DependOnAny(type.FullName) + .Should() + .DependOnAny(type.FullName) + .WithoutRequiringPositiveResults(); + var typeDoesNotDependOnFalseDependency = Types() + .That() + .Are(type) + .Should() + .NotDependOnAny(NoTypeName); + var typeDependsOnFalseDependency = Types() + .That() + .Are(type) + .Should() + .DependOnAny(NoTypeName) + .WithoutRequiringPositiveResults(); Assert.True(typesDependOnOwnDependencies.HasNoViolations(Architecture)); Assert.True(typeDoesNotDependOnFalseDependency.HasNoViolations(Architecture)); @@ -164,20 +296,33 @@ public void DependOnPatternTest() //Multiple Arguments - var patternList = new List {type.FullName, NoTypeName}; - var typesDependOnOwnDependenciesMultiple = - Types().That().DependOnAny(patternList).Should().DependOnAny(patternList).WithoutRequiringPositiveResults(); - var typeDependsOnFalseDependencyMultiple = - Types().That().Are(patternList).Should().DependOnAny(NoTypeName); + var patternList = new List { type.FullName, NoTypeName }; + var typesDependOnOwnDependenciesMultiple = Types() + .That() + .DependOnAny(patternList) + .Should() + .DependOnAny(patternList) + .WithoutRequiringPositiveResults(); + var typeDependsOnFalseDependencyMultiple = Types() + .That() + .Are(patternList) + .Should() + .DependOnAny(NoTypeName); Assert.True(typesDependOnOwnDependenciesMultiple.HasNoViolations(Architecture)); Assert.False(typeDependsOnFalseDependencyMultiple.HasNoViolations(Architecture)); } - var noTypeDependsOnFalseDependency = - Types().That().DependOnAny(NoTypeName).Should().NotExist(); - var typesDoNotDependsOnFalseDependency = - Types().That().DoNotDependOnAny(NoTypeName).Should().Exist(); + var noTypeDependsOnFalseDependency = Types() + .That() + .DependOnAny(NoTypeName) + .Should() + .NotExist(); + var typesDoNotDependsOnFalseDependency = Types() + .That() + .DoNotDependOnAny(NoTypeName) + .Should() + .Exist(); Assert.True(noTypeDependsOnFalseDependency.HasNoViolations(Architecture)); Assert.True(typesDoNotDependsOnFalseDependency.HasNoViolations(Architecture)); @@ -195,53 +340,104 @@ public void DependOnTypesTest() //One Argument var typeDependencies = type.GetTypeDependencies(Architecture).ToList(); - var typesDependOnOwnDependencies = - Types().That().DependOnAny(type).Should().DependOnAnyTypesThat().Are(type).WithoutRequiringPositiveResults(); - var typeDoesNotDependOnOneFalseDependency = - Types().That().Are(type).Should().NotDependOnAnyTypesThat().Are(typeof(ClassWithNoDependencies1)); - var typeDependsOnOneFalseDependency = - Types().That().Are(type).Should().DependOnAnyTypesThat().Are(typeof(ClassWithNoDependencies1)); - var typeOnlyDependsOnOneFalseDependency = - Types().That().Are(type).Should().OnlyDependOnTypesThat().Are(typeof(ClassWithNoDependencies1)); + var typesDependOnOwnDependencies = Types() + .That() + .DependOnAny(type) + .Should() + .DependOnAnyTypesThat() + .Are(type) + .WithoutRequiringPositiveResults(); + var typeDoesNotDependOnOneFalseDependency = Types() + .That() + .Are(type) + .Should() + .NotDependOnAnyTypesThat() + .Are(typeof(ClassWithNoDependencies1)); + var typeDependsOnOneFalseDependency = Types() + .That() + .Are(type) + .Should() + .DependOnAnyTypesThat() + .Are(typeof(ClassWithNoDependencies1)); + var typeOnlyDependsOnOneFalseDependency = Types() + .That() + .Are(type) + .Should() + .OnlyDependOnTypesThat() + .Are(typeof(ClassWithNoDependencies1)); Assert.True(typesDependOnOwnDependencies.HasNoViolations(Architecture)); typeDoesNotDependOnOneFalseDependency.Check(Architecture); Assert.True(typeDoesNotDependOnOneFalseDependency.HasNoViolations(Architecture)); Assert.False(typeDependsOnOneFalseDependency.HasNoViolations(Architecture)); - Assert.Equal(typeDependencies.IsNullOrEmpty(), - typeOnlyDependsOnOneFalseDependency.HasNoViolations(Architecture)); + Assert.Equal( + typeDependencies.IsNullOrEmpty(), + typeOnlyDependsOnOneFalseDependency.HasNoViolations(Architecture) + ); //Multiple Arguments - var typeDoesNotDependOnMultipleFalseDependencies = - Types().That().Are(type).Should().NotDependOnAnyTypesThat().Are(typeof(ClassWithNoDependencies1), - typeof(ClassWithNoDependencies2)); - var typeOnlyDependsOnMultipleFalseDependencies = - Types().That().Are(type).Should().OnlyDependOnTypesThat().Are(typeof(ClassWithNoDependencies1), - typeof(ClassWithNoDependencies2)); - - Assert.True(typeDoesNotDependOnMultipleFalseDependencies.HasNoViolations(Architecture)); - Assert.Equal(typeDependencies.IsNullOrEmpty(), - typeOnlyDependsOnMultipleFalseDependencies.HasNoViolations(Architecture)); + var typeDoesNotDependOnMultipleFalseDependencies = Types() + .That() + .Are(type) + .Should() + .NotDependOnAnyTypesThat() + .Are(typeof(ClassWithNoDependencies1), typeof(ClassWithNoDependencies2)); + var typeOnlyDependsOnMultipleFalseDependencies = Types() + .That() + .Are(type) + .Should() + .OnlyDependOnTypesThat() + .Are(typeof(ClassWithNoDependencies1), typeof(ClassWithNoDependencies2)); + + Assert.True( + typeDoesNotDependOnMultipleFalseDependencies.HasNoViolations(Architecture) + ); + Assert.Equal( + typeDependencies.IsNullOrEmpty(), + typeOnlyDependsOnMultipleFalseDependencies.HasNoViolations(Architecture) + ); //Multiple Arguments as IEnumerable - var typeOnlyDependsOnOwnDependencies = - Types().That().Are(type).Should().OnlyDependOnTypesThat().Are(typeDependencies); - var typeDoesNotDependsOnOwnDependencies = - Types().That().Are(type).Should().NotDependOnAnyTypesThat().Are(typeDependencies); - var typeDoesNotDependOnListOfMultipleFalseDependencies = - Types().That().Are(type).Should().NotDependOnAnyTypesThat().Are(_falseDependencies); - var typeOnlyDependsOnListOfMultipleFalseDependencies = - Types().That().Are(type).Should().OnlyDependOnTypesThat().Are(_falseDependencies); + var typeOnlyDependsOnOwnDependencies = Types() + .That() + .Are(type) + .Should() + .OnlyDependOnTypesThat() + .Are(typeDependencies); + var typeDoesNotDependsOnOwnDependencies = Types() + .That() + .Are(type) + .Should() + .NotDependOnAnyTypesThat() + .Are(typeDependencies); + var typeDoesNotDependOnListOfMultipleFalseDependencies = Types() + .That() + .Are(type) + .Should() + .NotDependOnAnyTypesThat() + .Are(_falseDependencies); + var typeOnlyDependsOnListOfMultipleFalseDependencies = Types() + .That() + .Are(type) + .Should() + .OnlyDependOnTypesThat() + .Are(_falseDependencies); Assert.True(typeOnlyDependsOnOwnDependencies.HasNoViolations(Architecture)); - Assert.Equal(typeDependencies.IsNullOrEmpty(), - typeDoesNotDependsOnOwnDependencies.HasNoViolations(Architecture)); - Assert.True(typeDoesNotDependOnListOfMultipleFalseDependencies.HasNoViolations(Architecture)); - Assert.Equal(typeDependencies.IsNullOrEmpty(), - typeOnlyDependsOnListOfMultipleFalseDependencies.HasNoViolations(Architecture)); + Assert.Equal( + typeDependencies.IsNullOrEmpty(), + typeDoesNotDependsOnOwnDependencies.HasNoViolations(Architecture) + ); + Assert.True( + typeDoesNotDependOnListOfMultipleFalseDependencies.HasNoViolations(Architecture) + ); + Assert.Equal( + typeDependencies.IsNullOrEmpty(), + typeOnlyDependsOnListOfMultipleFalseDependencies.HasNoViolations(Architecture) + ); } } @@ -258,9 +454,16 @@ public void DependOnTypesThatTest() // ReSharper disable once ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator foreach (var dependency in type.Dependencies) { - var typeDependsOnDependency = Types().That().Are(type).Should().DependOnAny(dependency.Target); - var typeDoesNotDependOnDependency = - Types().That().Are(type).Should().NotDependOnAny(dependency.Target); + var typeDependsOnDependency = Types() + .That() + .Are(type) + .Should() + .DependOnAny(dependency.Target); + var typeDoesNotDependOnDependency = Types() + .That() + .Are(type) + .Should() + .NotDependOnAny(dependency.Target); Assert.True(typeDependsOnDependency.HasNoViolations(Architecture)); Assert.False(typeDoesNotDependOnDependency.HasNoViolations(Architecture)); @@ -270,85 +473,164 @@ public void DependOnTypesThatTest() //One Argument - var typesDependOnOwnDependencies = Types().That().DependOnAny(type).Should().DependOnAny(type).WithoutRequiringPositiveResults(); - var typeDoesNotDependOnOneFalseDependency = - Types().That().Are(type).Should().NotDependOnAny(typeof(ClassWithNoDependencies1)); - var typeDependsOnOneFalseDependency = - Types().That().Are(type).Should().DependOnAny(typeof(ClassWithNoDependencies1)); - var typeOnlyDependsOnOneFalseDependency = - Types().That().Are(type).Should().OnlyDependOn(typeof(ClassWithNoDependencies1)); + var typesDependOnOwnDependencies = Types() + .That() + .DependOnAny(type) + .Should() + .DependOnAny(type) + .WithoutRequiringPositiveResults(); + var typeDoesNotDependOnOneFalseDependency = Types() + .That() + .Are(type) + .Should() + .NotDependOnAny(typeof(ClassWithNoDependencies1)); + var typeDependsOnOneFalseDependency = Types() + .That() + .Are(type) + .Should() + .DependOnAny(typeof(ClassWithNoDependencies1)); + var typeOnlyDependsOnOneFalseDependency = Types() + .That() + .Are(type) + .Should() + .OnlyDependOn(typeof(ClassWithNoDependencies1)); Assert.True(typesDependOnOwnDependencies.HasNoViolations(Architecture)); Assert.True(typeDoesNotDependOnOneFalseDependency.HasNoViolations(Architecture)); Assert.False(typeDependsOnOneFalseDependency.HasNoViolations(Architecture)); - Assert.Equal(typeDependencies.IsNullOrEmpty(), - typeOnlyDependsOnOneFalseDependency.HasNoViolations(Architecture)); + Assert.Equal( + typeDependencies.IsNullOrEmpty(), + typeOnlyDependsOnOneFalseDependency.HasNoViolations(Architecture) + ); //Multiple Arguments - var typeDoesNotDependOnMultipleFalseDependencies = - Types().That().Are(type).Should().NotDependOnAny(typeof(ClassWithNoDependencies1), - typeof(ClassWithNoDependencies2)); - var typeOnlyDependsOnMultipleFalseDependencies = - Types().That().Are(type).Should().OnlyDependOn(typeof(ClassWithNoDependencies1), - typeof(ClassWithNoDependencies2)); - - Assert.True(typeDoesNotDependOnMultipleFalseDependencies.HasNoViolations(Architecture)); - Assert.Equal(typeDependencies.IsNullOrEmpty(), - typeOnlyDependsOnMultipleFalseDependencies.HasNoViolations(Architecture)); + var typeDoesNotDependOnMultipleFalseDependencies = Types() + .That() + .Are(type) + .Should() + .NotDependOnAny( + typeof(ClassWithNoDependencies1), + typeof(ClassWithNoDependencies2) + ); + var typeOnlyDependsOnMultipleFalseDependencies = Types() + .That() + .Are(type) + .Should() + .OnlyDependOn( + typeof(ClassWithNoDependencies1), + typeof(ClassWithNoDependencies2) + ); + + Assert.True( + typeDoesNotDependOnMultipleFalseDependencies.HasNoViolations(Architecture) + ); + Assert.Equal( + typeDependencies.IsNullOrEmpty(), + typeOnlyDependsOnMultipleFalseDependencies.HasNoViolations(Architecture) + ); //Multiple Arguments as IEnumerable - var typeOnlyDependsOnOwnDependencies = Types().That().Are(type).Should().OnlyDependOn(typeDependencies); - var typeDoesNotDependsOnOwnDependencies = - Types().That().Are(type).Should().NotDependOnAny(typeDependencies); - var typeDoesNotDependOnListOfMultipleFalseDependencies = - Types().That().Are(type).Should().NotDependOnAny(_falseDependencies); - var typeOnlyDependsOnListOfMultipleFalseDependencies = - Types().That().Are(type).Should().OnlyDependOn(_falseDependencies); + var typeOnlyDependsOnOwnDependencies = Types() + .That() + .Are(type) + .Should() + .OnlyDependOn(typeDependencies); + var typeDoesNotDependsOnOwnDependencies = Types() + .That() + .Are(type) + .Should() + .NotDependOnAny(typeDependencies); + var typeDoesNotDependOnListOfMultipleFalseDependencies = Types() + .That() + .Are(type) + .Should() + .NotDependOnAny(_falseDependencies); + var typeOnlyDependsOnListOfMultipleFalseDependencies = Types() + .That() + .Are(type) + .Should() + .OnlyDependOn(_falseDependencies); Assert.True(typeOnlyDependsOnOwnDependencies.HasNoViolations(Architecture)); - Assert.Equal(typeDependencies.IsNullOrEmpty(), - typeDoesNotDependsOnOwnDependencies.HasNoViolations(Architecture)); - Assert.True(typeDoesNotDependOnListOfMultipleFalseDependencies.HasNoViolations(Architecture)); - Assert.Equal(typeDependencies.IsNullOrEmpty(), - typeOnlyDependsOnListOfMultipleFalseDependencies.HasNoViolations(Architecture)); + Assert.Equal( + typeDependencies.IsNullOrEmpty(), + typeDoesNotDependsOnOwnDependencies.HasNoViolations(Architecture) + ); + Assert.True( + typeDoesNotDependOnListOfMultipleFalseDependencies.HasNoViolations(Architecture) + ); + Assert.Equal( + typeDependencies.IsNullOrEmpty(), + typeOnlyDependsOnListOfMultipleFalseDependencies.HasNoViolations(Architecture) + ); } - var noTypeDependsOnFalseDependency = - Types().That().DependOnAny(typeof(ClassWithNoDependencies1)).Should() - .Be(typeof(ObjectSyntaxElementsTests)); - var noTypeDependsOnMultipleFalseDependencies = - Types().That().DependOnAny(typeof(ClassWithNoDependencies1), typeof(ClassWithNoDependencies2)).Should() - .Be(typeof(ObjectSyntaxElementsTests)); - var noTypeDependsOnListOfMultipleFalseDependencies = - Types().That().DependOnAny(_falseDependencies).Should().Be(typeof(ObjectSyntaxElementsTests)); - var typesDoNotDependOnFalseDependency = - Types().That().DoNotDependOnAny(typeof(ClassWithNoDependencies1)).Should().Exist(); - var typesDoNotDependOnMultipleFalseDependencies = - Types().That().DoNotDependOnAny(typeof(ClassWithNoDependencies1), typeof(ClassWithNoDependencies2)) - .Should().Exist(); - var typeDoNotDependOnListOfMultipleFalseDependencies = - Types().That().DoNotDependOnAny(_falseDependencies).Should().Exist(); + var noTypeDependsOnFalseDependency = Types() + .That() + .DependOnAny(typeof(ClassWithNoDependencies1)) + .Should() + .Be(typeof(ObjectSyntaxElementsTests)); + var noTypeDependsOnMultipleFalseDependencies = Types() + .That() + .DependOnAny(typeof(ClassWithNoDependencies1), typeof(ClassWithNoDependencies2)) + .Should() + .Be(typeof(ObjectSyntaxElementsTests)); + var noTypeDependsOnListOfMultipleFalseDependencies = Types() + .That() + .DependOnAny(_falseDependencies) + .Should() + .Be(typeof(ObjectSyntaxElementsTests)); + var typesDoNotDependOnFalseDependency = Types() + .That() + .DoNotDependOnAny(typeof(ClassWithNoDependencies1)) + .Should() + .Exist(); + var typesDoNotDependOnMultipleFalseDependencies = Types() + .That() + .DoNotDependOnAny( + typeof(ClassWithNoDependencies1), + typeof(ClassWithNoDependencies2) + ) + .Should() + .Exist(); + var typeDoNotDependOnListOfMultipleFalseDependencies = Types() + .That() + .DoNotDependOnAny(_falseDependencies) + .Should() + .Exist(); Assert.True(noTypeDependsOnFalseDependency.HasNoViolations(Architecture)); Assert.True(noTypeDependsOnMultipleFalseDependencies.HasNoViolations(Architecture)); - Assert.True(noTypeDependsOnListOfMultipleFalseDependencies.HasNoViolations(Architecture)); + Assert.True( + noTypeDependsOnListOfMultipleFalseDependencies.HasNoViolations(Architecture) + ); Assert.True(typesDoNotDependOnFalseDependency.HasNoViolations(Architecture)); Assert.True(typesDoNotDependOnMultipleFalseDependencies.HasNoViolations(Architecture)); - Assert.True(typeDoNotDependOnListOfMultipleFalseDependencies.HasNoViolations(Architecture)); + Assert.True( + typeDoNotDependOnListOfMultipleFalseDependencies.HasNoViolations(Architecture) + ); //Fluent arguments - var typeThatDependOnTypesWithPDoNotDependOnTypesWithP = - Types().That().DependOnAny(Types().That().HaveNameStartingWith("P")).Should() - .NotDependOnAny(Types().That().HaveNameStartingWith("P")); - var typesThatDependOnFalseTypeShouldDependOnNoType = - Types().That().OnlyDependOn(Classes().That().Are(typeof(ClassWithNoDependencies1))).Should() - .NotDependOnAny(Types()); - - Assert.False(typeThatDependOnTypesWithPDoNotDependOnTypesWithP.HasNoViolations(Architecture)); - Assert.True(typesThatDependOnFalseTypeShouldDependOnNoType.HasNoViolations(Architecture)); + var typeThatDependOnTypesWithPDoNotDependOnTypesWithP = Types() + .That() + .DependOnAny(Types().That().HaveNameStartingWith("P")) + .Should() + .NotDependOnAny(Types().That().HaveNameStartingWith("P")); + var typesThatDependOnFalseTypeShouldDependOnNoType = Types() + .That() + .OnlyDependOn(Classes().That().Are(typeof(ClassWithNoDependencies1))) + .Should() + .NotDependOnAny(Types()); + + Assert.False( + typeThatDependOnTypesWithPDoNotDependOnTypesWithP.HasNoViolations(Architecture) + ); + Assert.True( + typesThatDependOnFalseTypeShouldDependOnNoType.HasNoViolations(Architecture) + ); } [Fact] @@ -375,18 +657,36 @@ public void HaveFullNameTest() { foreach (var type in _types) { - var typeHasRightFullName = - Types().That().Are(type).Should().HaveFullName(type.FullName); - var typeDoesNotHaveRightFullName = - Types().That().Are(type).Should().NotHaveFullName(type.FullName); - var typeHasFalseFullName = - Types().That().Are(type).Should().HaveFullName(NoTypeName); - var typeDoesNotHaveFalseFullName = - Types().That().Are(type).Should().NotHaveFullName(NoTypeName); - var typesWithSameFullNameAreEqual = - Types().That().HaveFullName(type.FullName).Should().Be(type); - var typesWithDifferentFullNamesAreNotEqual = Types().That() - .DoNotHaveFullName(type.FullName).Should().NotBe(type); + var typeHasRightFullName = Types() + .That() + .Are(type) + .Should() + .HaveFullName(type.FullName); + var typeDoesNotHaveRightFullName = Types() + .That() + .Are(type) + .Should() + .NotHaveFullName(type.FullName); + var typeHasFalseFullName = Types() + .That() + .Are(type) + .Should() + .HaveFullName(NoTypeName); + var typeDoesNotHaveFalseFullName = Types() + .That() + .Are(type) + .Should() + .NotHaveFullName(NoTypeName); + var typesWithSameFullNameAreEqual = Types() + .That() + .HaveFullName(type.FullName) + .Should() + .Be(type); + var typesWithDifferentFullNamesAreNotEqual = Types() + .That() + .DoNotHaveFullName(type.FullName) + .Should() + .NotBe(type); Assert.True(typeHasRightFullName.HasNoViolations(Architecture)); Assert.False(typeDoesNotHaveRightFullName.HasNoViolations(Architecture)); @@ -396,10 +696,16 @@ public void HaveFullNameTest() Assert.True(typesWithDifferentFullNamesAreNotEqual.HasNoViolations(Architecture)); } - var findNoTypesWithFalseFullName = - Types().That().HaveFullName(NoTypeName).Should().NotExist(); - var findTypesWithRightFullName = - Types().That().DoNotHaveFullName(NoTypeName).Should().Exist(); + var findNoTypesWithFalseFullName = Types() + .That() + .HaveFullName(NoTypeName) + .Should() + .NotExist(); + var findTypesWithRightFullName = Types() + .That() + .DoNotHaveFullName(NoTypeName) + .Should() + .Exist(); Assert.True(findNoTypesWithFalseFullName.HasNoViolations(Architecture)); Assert.True(findTypesWithRightFullName.HasNoViolations(Architecture)); @@ -414,30 +720,52 @@ public void HaveNameEndingWithTest() for (var i = 0; i <= name.Length; i++) { var subString = name.Substring(i); - var typeNameEndsWithSubstringOfOwnName = Types().That().Are(type).Should() + var typeNameEndsWithSubstringOfOwnName = Types() + .That() + .Are(type) + .Should() .HaveNameEndingWith(subString); - var typeNameDoesNotEndWithSubstringOfOwnName = Types().That().Are(type).Should() + var typeNameDoesNotEndWithSubstringOfOwnName = Types() + .That() + .Are(type) + .Should() .NotHaveNameEndingWith(subString); Assert.True(typeNameEndsWithSubstringOfOwnName.HasNoViolations(Architecture)); - Assert.False(typeNameDoesNotEndWithSubstringOfOwnName.HasNoViolations(Architecture)); + Assert.False( + typeNameDoesNotEndWithSubstringOfOwnName.HasNoViolations(Architecture) + ); } - var typeNameDoesNotEndWithFalseTypeName = Types().That().Are(type).Should() + var typeNameDoesNotEndWithFalseTypeName = Types() + .That() + .Are(type) + .Should() .NotHaveNameEndingWith(NoTypeName); - var typeNameEndsWithFalseTypeName = - Types().That().Are(type).Should().HaveNameEndingWith(NoTypeName); + var typeNameEndsWithFalseTypeName = Types() + .That() + .Are(type) + .Should() + .HaveNameEndingWith(NoTypeName); Assert.True(typeNameDoesNotEndWithFalseTypeName.HasNoViolations(Architecture)); Assert.False(typeNameEndsWithFalseTypeName.HasNoViolations(Architecture)); } - var findNoTypesEndingWithFalseName = - Types().That().HaveNameEndingWith(NoTypeName).Or().HaveNameContaining(NoTypeName) - .Should().NotExist(); - var findTypesStartingWithRightName = - Types().That().DoNotHaveNameStartingWith(NoTypeName).Or() - .DoNotHaveNameContaining(NoTypeName).Should().Exist(); + var findNoTypesEndingWithFalseName = Types() + .That() + .HaveNameEndingWith(NoTypeName) + .Or() + .HaveNameContaining(NoTypeName) + .Should() + .NotExist(); + var findTypesStartingWithRightName = Types() + .That() + .DoNotHaveNameStartingWith(NoTypeName) + .Or() + .DoNotHaveNameContaining(NoTypeName) + .Should() + .Exist(); Assert.True(findNoTypesEndingWithFalseName.HasNoViolations(Architecture)); Assert.True(findTypesStartingWithRightName.HasNoViolations(Architecture)); @@ -454,41 +782,90 @@ public void HaveNameStartingWithAndHaveNameContainingTest() for (var j = 1; j <= i; j++) { var subString = name.Substring(j, i - j); - var typeNameContainsSubstringOfOwnName = Types().That().Are(type).Should() + var typeNameContainsSubstringOfOwnName = Types() + .That() + .Are(type) + .Should() .HaveNameContaining(subString); - var typeNameDoesNotContainsSubstringOfOwnName = Types().That().Are(type) - .Should().NotHaveNameContaining(subString); - - Assert.True(typeNameContainsSubstringOfOwnName.HasNoViolations(Architecture)); - Assert.False(typeNameDoesNotContainsSubstringOfOwnName.HasNoViolations(Architecture)); + var typeNameDoesNotContainsSubstringOfOwnName = Types() + .That() + .Are(type) + .Should() + .NotHaveNameContaining(subString); + + Assert.True( + typeNameContainsSubstringOfOwnName.HasNoViolations(Architecture) + ); + Assert.False( + typeNameDoesNotContainsSubstringOfOwnName.HasNoViolations(Architecture) + ); } var startString = name.Substring(0, i); - var typeNameStartsWithAndContainsSubstringOfOwnName = Types().That().Are(type) - .Should().HaveNameStartingWith(startString).AndShould().HaveNameContaining(startString); - var typeNameDoesNotStartWithOrContainSubstringOfOwnName = Types().That() - .Are(type).Should().NotHaveNameStartingWith(startString).OrShould() + var typeNameStartsWithAndContainsSubstringOfOwnName = Types() + .That() + .Are(type) + .Should() + .HaveNameStartingWith(startString) + .AndShould() + .HaveNameContaining(startString); + var typeNameDoesNotStartWithOrContainSubstringOfOwnName = Types() + .That() + .Are(type) + .Should() + .NotHaveNameStartingWith(startString) + .OrShould() .NotHaveNameContaining(startString); - Assert.True(typeNameStartsWithAndContainsSubstringOfOwnName.HasNoViolations(Architecture)); - Assert.False(typeNameDoesNotStartWithOrContainSubstringOfOwnName.HasNoViolations(Architecture)); + Assert.True( + typeNameStartsWithAndContainsSubstringOfOwnName.HasNoViolations( + Architecture + ) + ); + Assert.False( + typeNameDoesNotStartWithOrContainSubstringOfOwnName.HasNoViolations( + Architecture + ) + ); } - var typeNameDoesNotStartWithOrContainFalseTypeName = Types().That().Are(type) - .Should().NotHaveNameStartingWith(NoTypeName).AndShould().NotHaveNameContaining(NoTypeName); - var typeNameStartsWithOrContainsFalseTypeName = Types().That().Are(type) - .Should().HaveNameStartingWith(NoTypeName).OrShould().HaveNameContaining(NoTypeName); - - Assert.True(typeNameDoesNotStartWithOrContainFalseTypeName.HasNoViolations(Architecture)); - Assert.False(typeNameStartsWithOrContainsFalseTypeName.HasNoViolations(Architecture)); + var typeNameDoesNotStartWithOrContainFalseTypeName = Types() + .That() + .Are(type) + .Should() + .NotHaveNameStartingWith(NoTypeName) + .AndShould() + .NotHaveNameContaining(NoTypeName); + var typeNameStartsWithOrContainsFalseTypeName = Types() + .That() + .Are(type) + .Should() + .HaveNameStartingWith(NoTypeName) + .OrShould() + .HaveNameContaining(NoTypeName); + + Assert.True( + typeNameDoesNotStartWithOrContainFalseTypeName.HasNoViolations(Architecture) + ); + Assert.False( + typeNameStartsWithOrContainsFalseTypeName.HasNoViolations(Architecture) + ); } - var findNoTypesStartingWithOrContainingFalseName = - Types().That().HaveNameStartingWith(NoTypeName).Or().HaveNameContaining(NoTypeName) - .Should().NotExist(); - var findTypesStartingWithOrContainingRightName = - Types().That().DoNotHaveNameStartingWith(NoTypeName).Or() - .DoNotHaveNameContaining(NoTypeName).Should().Exist(); + var findNoTypesStartingWithOrContainingFalseName = Types() + .That() + .HaveNameStartingWith(NoTypeName) + .Or() + .HaveNameContaining(NoTypeName) + .Should() + .NotExist(); + var findTypesStartingWithOrContainingRightName = Types() + .That() + .DoNotHaveNameStartingWith(NoTypeName) + .Or() + .DoNotHaveNameContaining(NoTypeName) + .Should() + .Exist(); Assert.True(findNoTypesStartingWithOrContainingFalseName.HasNoViolations(Architecture)); Assert.True(findTypesStartingWithOrContainingRightName.HasNoViolations(Architecture)); @@ -500,11 +877,17 @@ public void HaveNameTest() foreach (var type in _types) { var typeHasRightName = Types().That().Are(type).Should().HaveName(type.Name); - var typeDoesNotHaveRightName = - Types().That().Are(type).Should().NotHaveName(type.Name); + var typeDoesNotHaveRightName = Types() + .That() + .Are(type) + .Should() + .NotHaveName(type.Name); var typeHasFalseName = Types().That().Are(type).Should().HaveName(NoTypeName); - var typeDoesNotHaveFalseName = - Types().That().Are(type).Should().NotHaveName(NoTypeName); + var typeDoesNotHaveFalseName = Types() + .That() + .Are(type) + .Should() + .NotHaveName(NoTypeName); Assert.True(typeHasRightName.HasNoViolations(Architecture)); Assert.False(typeDoesNotHaveRightName.HasNoViolations(Architecture)); @@ -512,10 +895,8 @@ public void HaveNameTest() Assert.True(typeDoesNotHaveFalseName.HasNoViolations(Architecture)); } - var findTypesWithRightName = - Types().That().DoNotHaveName(NoTypeName).Should().Exist(); - var findNoTypesWithFalseName = - Types().That().HaveName(NoTypeName).Should().NotExist(); + var findTypesWithRightName = Types().That().DoNotHaveName(NoTypeName).Should().Exist(); + var findNoTypesWithFalseName = Types().That().HaveName(NoTypeName).Should().NotExist(); Assert.True(findTypesWithRightName.HasNoViolations(Architecture)); Assert.True(findNoTypesWithFalseName.HasNoViolations(Architecture)); @@ -532,57 +913,170 @@ public void VisibilityTest() Types().That().AreInternal().Should().BeInternal(), Types().That().AreProtectedInternal().Should().BeProtectedInternal(), Types().That().ArePrivateProtected().Should().BePrivateProtected(), - Types().That().AreNotPrivate().Should().NotBePrivate(), Types().That().AreNotPublic().Should().NotBePublic(), Types().That().AreNotProtected().Should().NotBeProtected(), Types().That().AreNotInternal().Should().NotBeInternal(), Types().That().AreNotProtectedInternal().Should().NotBeProtectedInternal(), Types().That().AreNotPrivateProtected().Should().NotBePrivateProtected(), - - Types().That().ArePrivate().Should().NotBePublic().AndShould().NotBeProtected() - .AndShould().NotBeInternal().AndShould().NotBeProtectedInternal().AndShould() + Types() + .That() + .ArePrivate() + .Should() + .NotBePublic() + .AndShould() + .NotBeProtected() + .AndShould() + .NotBeInternal() + .AndShould() + .NotBeProtectedInternal() + .AndShould() .NotBePrivateProtected(), - Types().That().ArePublic().Should().NotBePrivate().AndShould().NotBeProtected() - .AndShould().NotBeInternal().AndShould().NotBeProtectedInternal().AndShould() + Types() + .That() + .ArePublic() + .Should() + .NotBePrivate() + .AndShould() + .NotBeProtected() + .AndShould() + .NotBeInternal() + .AndShould() + .NotBeProtectedInternal() + .AndShould() .NotBePrivateProtected(), - Types().That().AreProtected().Should().NotBePublic().AndShould().NotBePrivate() - .AndShould().NotBeInternal().AndShould().NotBeProtectedInternal().AndShould() + Types() + .That() + .AreProtected() + .Should() + .NotBePublic() + .AndShould() + .NotBePrivate() + .AndShould() + .NotBeInternal() + .AndShould() + .NotBeProtectedInternal() + .AndShould() .NotBePrivateProtected(), - Types().That().AreInternal().Should().NotBePublic().AndShould().NotBeProtected() - .AndShould().NotBePrivate().AndShould().NotBeProtectedInternal().AndShould() + Types() + .That() + .AreInternal() + .Should() + .NotBePublic() + .AndShould() + .NotBeProtected() + .AndShould() + .NotBePrivate() + .AndShould() + .NotBeProtectedInternal() + .AndShould() .NotBePrivateProtected(), - Types().That().AreProtectedInternal().Should().NotBePublic().AndShould() + Types() + .That() + .AreProtectedInternal() + .Should() + .NotBePublic() + .AndShould() .NotBeProtected() - .AndShould().NotBeInternal().AndShould().NotBePrivate().AndShould() + .AndShould() + .NotBeInternal() + .AndShould() + .NotBePrivate() + .AndShould() .NotBePrivateProtected(), - Types().That().ArePrivateProtected().Should().NotBePublic().AndShould() + Types() + .That() + .ArePrivateProtected() + .Should() + .NotBePublic() + .AndShould() .NotBeProtected() - .AndShould().NotBeInternal().AndShould().NotBeProtectedInternal().AndShould() + .AndShould() + .NotBeInternal() + .AndShould() + .NotBeProtectedInternal() + .AndShould() .NotBePrivate(), - - Types().That().AreNotPrivate().Should().BePublic().OrShould().BeProtected() - .OrShould().BeInternal().OrShould().BeProtectedInternal().OrShould() + Types() + .That() + .AreNotPrivate() + .Should() + .BePublic() + .OrShould() + .BeProtected() + .OrShould() + .BeInternal() + .OrShould() + .BeProtectedInternal() + .OrShould() .BePrivateProtected(), - Types().That().AreNotPublic().Should().BePrivate().OrShould().BeProtected() - .OrShould().BeInternal().OrShould().BeProtectedInternal().OrShould() + Types() + .That() + .AreNotPublic() + .Should() + .BePrivate() + .OrShould() + .BeProtected() + .OrShould() + .BeInternal() + .OrShould() + .BeProtectedInternal() + .OrShould() .BePrivateProtected(), - Types().That().AreNotProtected().Should().BePublic().OrShould().BePrivate() - .OrShould().BeInternal().OrShould().BeProtectedInternal().OrShould() + Types() + .That() + .AreNotProtected() + .Should() + .BePublic() + .OrShould() + .BePrivate() + .OrShould() + .BeInternal() + .OrShould() + .BeProtectedInternal() + .OrShould() .BePrivateProtected(), - Types().That().AreNotInternal().Should().BePublic().OrShould().BeProtected() - .OrShould().BePrivate().OrShould().BeProtectedInternal().OrShould() + Types() + .That() + .AreNotInternal() + .Should() + .BePublic() + .OrShould() + .BeProtected() + .OrShould() + .BePrivate() + .OrShould() + .BeProtectedInternal() + .OrShould() .BePrivateProtected(), - Types().That().AreNotProtectedInternal().Should().BePublic().OrShould().BeProtected() - .OrShould().BeInternal().OrShould().BePrivate().OrShould() + Types() + .That() + .AreNotProtectedInternal() + .Should() + .BePublic() + .OrShould() + .BeProtected() + .OrShould() + .BeInternal() + .OrShould() + .BePrivate() + .OrShould() .BePrivateProtected(), - Types().That().AreNotPrivateProtected().Should().BePublic().OrShould().BeProtected() - .OrShould().BeInternal().OrShould().BeProtectedInternal().OrShould() + Types() + .That() + .AreNotPrivateProtected() + .Should() + .BePublic() + .OrShould() + .BeProtected() + .OrShould() + .BeInternal() + .OrShould() + .BeProtectedInternal() + .OrShould() .BePrivate(), - Types().That().Are(StaticTestTypes.PublicTestClass).Should().BePublic(), - Types().That().Are(StaticTestTypes.InternalTestClass).Should() - .BeInternal(), + Types().That().Are(StaticTestTypes.InternalTestClass).Should().BeInternal(), Types().That().Are(NestedPrivateTestClass).Should().BePrivate(), Types().That().Are(NestedPublicTestClass).Should().BePublic(), Types().That().Are(NestedProtectedTestClass).Should().BeProtected(), @@ -598,19 +1092,11 @@ public void VisibilityTest() } } - public class ClassWithNoDependencies1 - { - } + public class ClassWithNoDependencies1 { } - public class ClassWithNoDependencies2 - { - } + public class ClassWithNoDependencies2 { } - public interface IInterfaceWithNoDependencies1 - { - } + public interface IInterfaceWithNoDependencies1 { } - public interface IInterfaceWithNoDependencies2 - { - } -} \ No newline at end of file + public interface IInterfaceWithNoDependencies2 { } +} diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/PropertyMemberSyntaxElementsTests.cs b/ArchUnitNETTests/Fluent/Syntax/Elements/PropertyMemberSyntaxElementsTests.cs index 66ed43b86..ef86ee2a5 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/PropertyMemberSyntaxElementsTests.cs +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/PropertyMemberSyntaxElementsTests.cs @@ -1,14 +1,14 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; using ArchUnitNET.Domain; using Xunit; -using static ArchUnitNET.Fluent.ArchRuleDefinition; using static ArchUnitNET.Domain.Visibility; +using static ArchUnitNET.Fluent.ArchRuleDefinition; namespace ArchUnitNETTests.Fluent.Syntax.Elements { @@ -19,37 +19,83 @@ public PropertyMemberSyntaxElementsTests() _propertyMembers = Architecture.PropertyMembers; } - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; private readonly IEnumerable _propertyMembers; - [Fact] public void AreVirtualTest() { foreach (var propertyMember in _propertyMembers) { - var propertyMemberIsVirtual = PropertyMembers().That().Are(propertyMember).Should().BeVirtual(); - var propertyMemberIsNotVirtual = PropertyMembers().That().Are(propertyMember).Should().NotBeVirtual(); - var virtualPropertyMembersDoNotIncludeMember = - PropertyMembers().That().AreVirtual().Should().NotBe(propertyMember).OrShould().NotExist(); - var notVirtualPropertyMembersDoNotIncludeMember = - PropertyMembers().That().AreNotVirtual().Should().NotBe(propertyMember).AndShould().Exist(); - - Assert.Equal(propertyMember.IsVirtual, propertyMemberIsVirtual.HasNoViolations(Architecture)); - Assert.Equal(!propertyMember.IsVirtual, propertyMemberIsNotVirtual.HasNoViolations(Architecture)); - Assert.Equal(!propertyMember.IsVirtual, - virtualPropertyMembersDoNotIncludeMember.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.IsVirtual, - notVirtualPropertyMembersDoNotIncludeMember.HasNoViolations(Architecture)); + var propertyMemberIsVirtual = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .BeVirtual(); + var propertyMemberIsNotVirtual = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .NotBeVirtual(); + var virtualPropertyMembersDoNotIncludeMember = PropertyMembers() + .That() + .AreVirtual() + .Should() + .NotBe(propertyMember) + .OrShould() + .NotExist(); + var notVirtualPropertyMembersDoNotIncludeMember = PropertyMembers() + .That() + .AreNotVirtual() + .Should() + .NotBe(propertyMember) + .AndShould() + .Exist(); + + Assert.Equal( + propertyMember.IsVirtual, + propertyMemberIsVirtual.HasNoViolations(Architecture) + ); + Assert.Equal( + !propertyMember.IsVirtual, + propertyMemberIsNotVirtual.HasNoViolations(Architecture) + ); + Assert.Equal( + !propertyMember.IsVirtual, + virtualPropertyMembersDoNotIncludeMember.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.IsVirtual, + notVirtualPropertyMembersDoNotIncludeMember.HasNoViolations(Architecture) + ); } - var virtualPropertyMembersShouldBeVirtual = PropertyMembers().That().AreVirtual().Should().BeVirtual().WithoutRequiringPositiveResults(); - var virtualPropertyMembersAreNotVirtual = - PropertyMembers().That().AreVirtual().Should().NotBeVirtual().AndShould().Exist(); - var notVirtualPropertyMembersShouldBeVirtual = - PropertyMembers().That().AreNotVirtual().Should().BeVirtual().AndShould().Exist(); - var notVirtualPropertyMembersAreNotVirtual = - PropertyMembers().That().AreNotVirtual().Should().NotBeVirtual(); + var virtualPropertyMembersShouldBeVirtual = PropertyMembers() + .That() + .AreVirtual() + .Should() + .BeVirtual() + .WithoutRequiringPositiveResults(); + var virtualPropertyMembersAreNotVirtual = PropertyMembers() + .That() + .AreVirtual() + .Should() + .NotBeVirtual() + .AndShould() + .Exist(); + var notVirtualPropertyMembersShouldBeVirtual = PropertyMembers() + .That() + .AreNotVirtual() + .Should() + .BeVirtual() + .AndShould() + .Exist(); + var notVirtualPropertyMembersAreNotVirtual = PropertyMembers() + .That() + .AreNotVirtual() + .Should() + .NotBeVirtual(); Assert.True(virtualPropertyMembersShouldBeVirtual.HasNoViolations(Architecture)); Assert.False(virtualPropertyMembersAreNotVirtual.HasNoViolations(Architecture)); @@ -62,30 +108,73 @@ public void HaveGetterTest() { foreach (var propertyMember in _propertyMembers) { - var propertyMemberHasGetter = PropertyMembers().That().Are(propertyMember).Should().HaveGetter(); - var propertyMemberHasNoGetter = PropertyMembers().That().Are(propertyMember).Should().NotHaveGetter(); - var propertyMembersWithGetterDoNotIncludeMember = - PropertyMembers().That().HaveGetter().Should().NotBe(propertyMember).OrShould().NotExist(); - var propertyMembersWithoutGetterDoNotIncludeMember = - PropertyMembers().That().HaveNoGetter().Should().NotBe(propertyMember).AndShould().Exist(); - - Assert.Equal(propertyMember.GetterVisibility != NotAccessible, - propertyMemberHasGetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.GetterVisibility == NotAccessible, - propertyMemberHasNoGetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.GetterVisibility == NotAccessible, - propertyMembersWithGetterDoNotIncludeMember.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.GetterVisibility != NotAccessible, - propertyMembersWithoutGetterDoNotIncludeMember.HasNoViolations(Architecture)); + var propertyMemberHasGetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .HaveGetter(); + var propertyMemberHasNoGetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .NotHaveGetter(); + var propertyMembersWithGetterDoNotIncludeMember = PropertyMembers() + .That() + .HaveGetter() + .Should() + .NotBe(propertyMember) + .OrShould() + .NotExist(); + var propertyMembersWithoutGetterDoNotIncludeMember = PropertyMembers() + .That() + .HaveNoGetter() + .Should() + .NotBe(propertyMember) + .AndShould() + .Exist(); + + Assert.Equal( + propertyMember.GetterVisibility != NotAccessible, + propertyMemberHasGetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.GetterVisibility == NotAccessible, + propertyMemberHasNoGetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.GetterVisibility == NotAccessible, + propertyMembersWithGetterDoNotIncludeMember.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.GetterVisibility != NotAccessible, + propertyMembersWithoutGetterDoNotIncludeMember.HasNoViolations(Architecture) + ); } - var propertyMembersWithGetterHaveGetter = PropertyMembers().That().HaveGetter().Should().HaveGetter(); - var propertyMembersWithGetterHaveNoGetter = - PropertyMembers().That().HaveGetter().Should().NotHaveGetter().AndShould().Exist(); - var propertyMembersWithoutGetterHaveGetter = - PropertyMembers().That().HaveNoGetter().Should().HaveGetter().AndShould().Exist(); - var propertyMembersWithoutGetterHaveNoGetter = - PropertyMembers().That().HaveNoGetter().Should().NotHaveGetter(); + var propertyMembersWithGetterHaveGetter = PropertyMembers() + .That() + .HaveGetter() + .Should() + .HaveGetter(); + var propertyMembersWithGetterHaveNoGetter = PropertyMembers() + .That() + .HaveGetter() + .Should() + .NotHaveGetter() + .AndShould() + .Exist(); + var propertyMembersWithoutGetterHaveGetter = PropertyMembers() + .That() + .HaveNoGetter() + .Should() + .HaveGetter() + .AndShould() + .Exist(); + var propertyMembersWithoutGetterHaveNoGetter = PropertyMembers() + .That() + .HaveNoGetter() + .Should() + .NotHaveGetter(); Assert.True(propertyMembersWithGetterHaveGetter.HasNoViolations(Architecture)); Assert.False(propertyMembersWithGetterHaveNoGetter.HasNoViolations(Architecture)); @@ -98,39 +187,95 @@ public void HaveInternalGetterTest() { foreach (var propertyMember in _propertyMembers) { - var propertyMemberHasInternalGetter = - PropertyMembers().That().Are(propertyMember).Should().HaveInternalGetter(); - var propertyMemberDoesNotHaveInternalGetter = - PropertyMembers().That().Are(propertyMember).Should().NotHaveInternalGetter(); - var propertyMembersWithInternalGetterDoNotIncludeMember = - PropertyMembers().That().HaveInternalGetter().Should().NotBe(propertyMember).OrShould().NotExist(); - var propertyMembersWithoutInternalGetterDoNotIncludeMember = - PropertyMembers().That().DoNotHaveInternalGetter().Should().NotBe(propertyMember).AndShould() - .Exist(); - - Assert.Equal(propertyMember.GetterVisibility == Internal, - propertyMemberHasInternalGetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.GetterVisibility != Internal, - propertyMemberDoesNotHaveInternalGetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.GetterVisibility != Internal, - propertyMembersWithInternalGetterDoNotIncludeMember.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.GetterVisibility == Internal, - propertyMembersWithoutInternalGetterDoNotIncludeMember.HasNoViolations(Architecture)); + var propertyMemberHasInternalGetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .HaveInternalGetter(); + var propertyMemberDoesNotHaveInternalGetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .NotHaveInternalGetter(); + var propertyMembersWithInternalGetterDoNotIncludeMember = PropertyMembers() + .That() + .HaveInternalGetter() + .Should() + .NotBe(propertyMember) + .OrShould() + .NotExist(); + var propertyMembersWithoutInternalGetterDoNotIncludeMember = PropertyMembers() + .That() + .DoNotHaveInternalGetter() + .Should() + .NotBe(propertyMember) + .AndShould() + .Exist(); + + Assert.Equal( + propertyMember.GetterVisibility == Internal, + propertyMemberHasInternalGetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.GetterVisibility != Internal, + propertyMemberDoesNotHaveInternalGetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.GetterVisibility != Internal, + propertyMembersWithInternalGetterDoNotIncludeMember.HasNoViolations( + Architecture + ) + ); + Assert.Equal( + propertyMember.GetterVisibility == Internal, + propertyMembersWithoutInternalGetterDoNotIncludeMember.HasNoViolations( + Architecture + ) + ); } - var propertyMembersWithInternalGetterHaveInternalGetter = - PropertyMembers().That().HaveInternalGetter().Should().HaveInternalGetter().WithoutRequiringPositiveResults(); - var propertyMembersWithInternalGetterDoNotHaveInternalGetter = - PropertyMembers().That().HaveInternalGetter().Should().NotHaveInternalGetter().AndShould().Exist(); - var propertyMembersWithoutInternalGetterHaveInternalGetter = - PropertyMembers().That().DoNotHaveInternalGetter().Should().HaveInternalGetter().AndShould().Exist(); - var propertyMembersWithoutInternalGetterDoNotHaveInternalGetter = - PropertyMembers().That().DoNotHaveInternalGetter().Should().NotHaveInternalGetter(); - - Assert.True(propertyMembersWithInternalGetterHaveInternalGetter.HasNoViolations(Architecture)); - Assert.False(propertyMembersWithInternalGetterDoNotHaveInternalGetter.HasNoViolations(Architecture)); - Assert.False(propertyMembersWithoutInternalGetterHaveInternalGetter.HasNoViolations(Architecture)); - Assert.True(propertyMembersWithoutInternalGetterDoNotHaveInternalGetter.HasNoViolations(Architecture)); + var propertyMembersWithInternalGetterHaveInternalGetter = PropertyMembers() + .That() + .HaveInternalGetter() + .Should() + .HaveInternalGetter() + .WithoutRequiringPositiveResults(); + var propertyMembersWithInternalGetterDoNotHaveInternalGetter = PropertyMembers() + .That() + .HaveInternalGetter() + .Should() + .NotHaveInternalGetter() + .AndShould() + .Exist(); + var propertyMembersWithoutInternalGetterHaveInternalGetter = PropertyMembers() + .That() + .DoNotHaveInternalGetter() + .Should() + .HaveInternalGetter() + .AndShould() + .Exist(); + var propertyMembersWithoutInternalGetterDoNotHaveInternalGetter = PropertyMembers() + .That() + .DoNotHaveInternalGetter() + .Should() + .NotHaveInternalGetter(); + + Assert.True( + propertyMembersWithInternalGetterHaveInternalGetter.HasNoViolations(Architecture) + ); + Assert.False( + propertyMembersWithInternalGetterDoNotHaveInternalGetter.HasNoViolations( + Architecture + ) + ); + Assert.False( + propertyMembersWithoutInternalGetterHaveInternalGetter.HasNoViolations(Architecture) + ); + Assert.True( + propertyMembersWithoutInternalGetterDoNotHaveInternalGetter.HasNoViolations( + Architecture + ) + ); } [Fact] @@ -138,39 +283,95 @@ public void HaveInternalSetterTest() { foreach (var propertyMember in _propertyMembers) { - var propertyMemberHasInternalSetter = - PropertyMembers().That().Are(propertyMember).Should().HaveInternalSetter(); - var propertyMemberDoesNotHaveInternalSetter = - PropertyMembers().That().Are(propertyMember).Should().NotHaveInternalSetter(); - var propertyMembersWithInternalSetterDoNotIncludeMember = - PropertyMembers().That().HaveInternalSetter().Should().NotBe(propertyMember).OrShould().NotExist(); - var propertyMembersWithoutInternalSetterDoNotIncludeMember = - PropertyMembers().That().DoNotHaveInternalSetter().Should().NotBe(propertyMember).AndShould() - .Exist(); - - Assert.Equal(propertyMember.SetterVisibility == Internal, - propertyMemberHasInternalSetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.SetterVisibility != Internal, - propertyMemberDoesNotHaveInternalSetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.SetterVisibility != Internal, - propertyMembersWithInternalSetterDoNotIncludeMember.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.SetterVisibility == Internal, - propertyMembersWithoutInternalSetterDoNotIncludeMember.HasNoViolations(Architecture)); + var propertyMemberHasInternalSetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .HaveInternalSetter(); + var propertyMemberDoesNotHaveInternalSetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .NotHaveInternalSetter(); + var propertyMembersWithInternalSetterDoNotIncludeMember = PropertyMembers() + .That() + .HaveInternalSetter() + .Should() + .NotBe(propertyMember) + .OrShould() + .NotExist(); + var propertyMembersWithoutInternalSetterDoNotIncludeMember = PropertyMembers() + .That() + .DoNotHaveInternalSetter() + .Should() + .NotBe(propertyMember) + .AndShould() + .Exist(); + + Assert.Equal( + propertyMember.SetterVisibility == Internal, + propertyMemberHasInternalSetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.SetterVisibility != Internal, + propertyMemberDoesNotHaveInternalSetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.SetterVisibility != Internal, + propertyMembersWithInternalSetterDoNotIncludeMember.HasNoViolations( + Architecture + ) + ); + Assert.Equal( + propertyMember.SetterVisibility == Internal, + propertyMembersWithoutInternalSetterDoNotIncludeMember.HasNoViolations( + Architecture + ) + ); } - var propertyMembersWithInternalSetterHaveInternalSetter = - PropertyMembers().That().HaveInternalSetter().Should().HaveInternalSetter().WithoutRequiringPositiveResults(); - var propertyMembersWithInternalSetterDoNotHaveInternalSetter = - PropertyMembers().That().HaveInternalSetter().Should().NotHaveInternalSetter().AndShould().Exist(); - var propertyMembersWithoutInternalSetterHaveInternalSetter = - PropertyMembers().That().DoNotHaveInternalSetter().Should().HaveInternalSetter().AndShould().Exist(); - var propertyMembersWithoutInternalSetterDoNotHaveInternalSetter = - PropertyMembers().That().DoNotHaveInternalSetter().Should().NotHaveInternalSetter(); - - Assert.True(propertyMembersWithInternalSetterHaveInternalSetter.HasNoViolations(Architecture)); - Assert.False(propertyMembersWithInternalSetterDoNotHaveInternalSetter.HasNoViolations(Architecture)); - Assert.False(propertyMembersWithoutInternalSetterHaveInternalSetter.HasNoViolations(Architecture)); - Assert.True(propertyMembersWithoutInternalSetterDoNotHaveInternalSetter.HasNoViolations(Architecture)); + var propertyMembersWithInternalSetterHaveInternalSetter = PropertyMembers() + .That() + .HaveInternalSetter() + .Should() + .HaveInternalSetter() + .WithoutRequiringPositiveResults(); + var propertyMembersWithInternalSetterDoNotHaveInternalSetter = PropertyMembers() + .That() + .HaveInternalSetter() + .Should() + .NotHaveInternalSetter() + .AndShould() + .Exist(); + var propertyMembersWithoutInternalSetterHaveInternalSetter = PropertyMembers() + .That() + .DoNotHaveInternalSetter() + .Should() + .HaveInternalSetter() + .AndShould() + .Exist(); + var propertyMembersWithoutInternalSetterDoNotHaveInternalSetter = PropertyMembers() + .That() + .DoNotHaveInternalSetter() + .Should() + .NotHaveInternalSetter(); + + Assert.True( + propertyMembersWithInternalSetterHaveInternalSetter.HasNoViolations(Architecture) + ); + Assert.False( + propertyMembersWithInternalSetterDoNotHaveInternalSetter.HasNoViolations( + Architecture + ) + ); + Assert.False( + propertyMembersWithoutInternalSetterHaveInternalSetter.HasNoViolations(Architecture) + ); + Assert.True( + propertyMembersWithoutInternalSetterDoNotHaveInternalSetter.HasNoViolations( + Architecture + ) + ); } [Fact] @@ -178,39 +379,90 @@ public void HavePrivateGetterTest() { foreach (var propertyMember in _propertyMembers) { - var propertyMemberHasPrivateGetter = - PropertyMembers().That().Are(propertyMember).Should().HavePrivateGetter(); - var propertyMemberDoesNotHavePrivateGetter = - PropertyMembers().That().Are(propertyMember).Should().NotHavePrivateGetter(); - var propertyMembersWithPrivateGetterDoNotIncludeMember = - PropertyMembers().That().HavePrivateGetter().Should().NotBe(propertyMember).OrShould().NotExist(); - var propertyMembersWithoutPrivateGetterDoNotIncludeMember = - PropertyMembers().That().DoNotHavePrivateGetter().Should().NotBe(propertyMember).AndShould() - .Exist(); - - Assert.Equal(propertyMember.GetterVisibility == Private, - propertyMemberHasPrivateGetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.GetterVisibility != Private, - propertyMemberDoesNotHavePrivateGetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.GetterVisibility != Private, - propertyMembersWithPrivateGetterDoNotIncludeMember.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.GetterVisibility == Private, - propertyMembersWithoutPrivateGetterDoNotIncludeMember.HasNoViolations(Architecture)); + var propertyMemberHasPrivateGetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .HavePrivateGetter(); + var propertyMemberDoesNotHavePrivateGetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .NotHavePrivateGetter(); + var propertyMembersWithPrivateGetterDoNotIncludeMember = PropertyMembers() + .That() + .HavePrivateGetter() + .Should() + .NotBe(propertyMember) + .OrShould() + .NotExist(); + var propertyMembersWithoutPrivateGetterDoNotIncludeMember = PropertyMembers() + .That() + .DoNotHavePrivateGetter() + .Should() + .NotBe(propertyMember) + .AndShould() + .Exist(); + + Assert.Equal( + propertyMember.GetterVisibility == Private, + propertyMemberHasPrivateGetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.GetterVisibility != Private, + propertyMemberDoesNotHavePrivateGetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.GetterVisibility != Private, + propertyMembersWithPrivateGetterDoNotIncludeMember.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.GetterVisibility == Private, + propertyMembersWithoutPrivateGetterDoNotIncludeMember.HasNoViolations( + Architecture + ) + ); } - var propertyMembersWithPrivateGetterHavePrivateGetter = - PropertyMembers().That().HavePrivateGetter().Should().HavePrivateGetter(); - var propertyMembersWithPrivateGetterDoNotHavePrivateGetter = - PropertyMembers().That().HavePrivateGetter().Should().NotHavePrivateGetter().AndShould().Exist(); - var propertyMembersWithoutPrivateGetterHavePrivateGetter = - PropertyMembers().That().DoNotHavePrivateGetter().Should().HavePrivateGetter().AndShould().Exist(); - var propertyMembersWithoutPrivateGetterDoNotHavePrivateGetter = - PropertyMembers().That().DoNotHavePrivateGetter().Should().NotHavePrivateGetter(); - - Assert.True(propertyMembersWithPrivateGetterHavePrivateGetter.HasNoViolations(Architecture)); - Assert.False(propertyMembersWithPrivateGetterDoNotHavePrivateGetter.HasNoViolations(Architecture)); - Assert.False(propertyMembersWithoutPrivateGetterHavePrivateGetter.HasNoViolations(Architecture)); - Assert.True(propertyMembersWithoutPrivateGetterDoNotHavePrivateGetter.HasNoViolations(Architecture)); + var propertyMembersWithPrivateGetterHavePrivateGetter = PropertyMembers() + .That() + .HavePrivateGetter() + .Should() + .HavePrivateGetter(); + var propertyMembersWithPrivateGetterDoNotHavePrivateGetter = PropertyMembers() + .That() + .HavePrivateGetter() + .Should() + .NotHavePrivateGetter() + .AndShould() + .Exist(); + var propertyMembersWithoutPrivateGetterHavePrivateGetter = PropertyMembers() + .That() + .DoNotHavePrivateGetter() + .Should() + .HavePrivateGetter() + .AndShould() + .Exist(); + var propertyMembersWithoutPrivateGetterDoNotHavePrivateGetter = PropertyMembers() + .That() + .DoNotHavePrivateGetter() + .Should() + .NotHavePrivateGetter(); + + Assert.True( + propertyMembersWithPrivateGetterHavePrivateGetter.HasNoViolations(Architecture) + ); + Assert.False( + propertyMembersWithPrivateGetterDoNotHavePrivateGetter.HasNoViolations(Architecture) + ); + Assert.False( + propertyMembersWithoutPrivateGetterHavePrivateGetter.HasNoViolations(Architecture) + ); + Assert.True( + propertyMembersWithoutPrivateGetterDoNotHavePrivateGetter.HasNoViolations( + Architecture + ) + ); } [Fact] @@ -218,48 +470,104 @@ public void HavePrivateProtectedGetterTest() { foreach (var propertyMember in _propertyMembers) { - var propertyMemberHasPrivateProtectedGetter = - PropertyMembers().That().Are(propertyMember).Should().HavePrivateProtectedGetter(); - var propertyMemberDoesNotHavePrivateProtectedGetter = - PropertyMembers().That().Are(propertyMember).Should().NotHavePrivateProtectedGetter(); - var propertyMembersWithPrivateProtectedGetterDoNotIncludeMember = - PropertyMembers().That().HavePrivateProtectedGetter().Should().NotBe(propertyMember).OrShould() - .NotExist(); + var propertyMemberHasPrivateProtectedGetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .HavePrivateProtectedGetter(); + var propertyMemberDoesNotHavePrivateProtectedGetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .NotHavePrivateProtectedGetter(); + var propertyMembersWithPrivateProtectedGetterDoNotIncludeMember = PropertyMembers() + .That() + .HavePrivateProtectedGetter() + .Should() + .NotBe(propertyMember) + .OrShould() + .NotExist(); var propertyMembersWithoutPrivateProtectedGetterDoNotIncludeMember = - PropertyMembers().That().DoNotHavePrivateProtectedGetter().Should().NotBe(propertyMember) + PropertyMembers() + .That() + .DoNotHavePrivateProtectedGetter() + .Should() + .NotBe(propertyMember) .AndShould() .Exist(); - Assert.Equal(propertyMember.GetterVisibility == PrivateProtected, - propertyMemberHasPrivateProtectedGetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.GetterVisibility != PrivateProtected, - propertyMemberDoesNotHavePrivateProtectedGetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.GetterVisibility != PrivateProtected, - propertyMembersWithPrivateProtectedGetterDoNotIncludeMember.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.GetterVisibility == PrivateProtected, - propertyMembersWithoutPrivateProtectedGetterDoNotIncludeMember.HasNoViolations(Architecture)); + Assert.Equal( + propertyMember.GetterVisibility == PrivateProtected, + propertyMemberHasPrivateProtectedGetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.GetterVisibility != PrivateProtected, + propertyMemberDoesNotHavePrivateProtectedGetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.GetterVisibility != PrivateProtected, + propertyMembersWithPrivateProtectedGetterDoNotIncludeMember.HasNoViolations( + Architecture + ) + ); + Assert.Equal( + propertyMember.GetterVisibility == PrivateProtected, + propertyMembersWithoutPrivateProtectedGetterDoNotIncludeMember.HasNoViolations( + Architecture + ) + ); } var propertyMembersWithPrivateProtectedGetterHavePrivateProtectedGetter = - PropertyMembers().That().HavePrivateProtectedGetter().Should().HavePrivateProtectedGetter().WithoutRequiringPositiveResults(); + PropertyMembers() + .That() + .HavePrivateProtectedGetter() + .Should() + .HavePrivateProtectedGetter() + .WithoutRequiringPositiveResults(); var propertyMembersWithPrivateProtectedGetterDoNotHavePrivateProtectedGetter = - PropertyMembers().That().HavePrivateProtectedGetter().Should().NotHavePrivateProtectedGetter() - .AndShould().Exist(); + PropertyMembers() + .That() + .HavePrivateProtectedGetter() + .Should() + .NotHavePrivateProtectedGetter() + .AndShould() + .Exist(); var propertyMembersWithoutPrivateProtectedGetterHavePrivateProtectedGetter = - PropertyMembers().That().DoNotHavePrivateProtectedGetter().Should().HavePrivateProtectedGetter() - .AndShould().Exist(); + PropertyMembers() + .That() + .DoNotHavePrivateProtectedGetter() + .Should() + .HavePrivateProtectedGetter() + .AndShould() + .Exist(); var propertyMembersWithoutPrivateProtectedGetterDoNotHavePrivateProtectedGetter = - PropertyMembers().That().DoNotHavePrivateProtectedGetter().Should().NotHavePrivateProtectedGetter(); + PropertyMembers() + .That() + .DoNotHavePrivateProtectedGetter() + .Should() + .NotHavePrivateProtectedGetter(); Assert.True( - propertyMembersWithPrivateProtectedGetterHavePrivateProtectedGetter.HasNoViolations(Architecture)); + propertyMembersWithPrivateProtectedGetterHavePrivateProtectedGetter.HasNoViolations( + Architecture + ) + ); Assert.False( - propertyMembersWithPrivateProtectedGetterDoNotHavePrivateProtectedGetter.HasNoViolations(Architecture)); + propertyMembersWithPrivateProtectedGetterDoNotHavePrivateProtectedGetter.HasNoViolations( + Architecture + ) + ); Assert.False( - propertyMembersWithoutPrivateProtectedGetterHavePrivateProtectedGetter.HasNoViolations(Architecture)); + propertyMembersWithoutPrivateProtectedGetterHavePrivateProtectedGetter.HasNoViolations( + Architecture + ) + ); Assert.True( - propertyMembersWithoutPrivateProtectedGetterDoNotHavePrivateProtectedGetter - .HasNoViolations(Architecture)); + propertyMembersWithoutPrivateProtectedGetterDoNotHavePrivateProtectedGetter.HasNoViolations( + Architecture + ) + ); } [Fact] @@ -267,48 +575,104 @@ public void HavePrivateProtectedSetterTest() { foreach (var propertyMember in _propertyMembers) { - var propertyMemberHasPrivateProtectedSetter = - PropertyMembers().That().Are(propertyMember).Should().HavePrivateProtectedSetter(); - var propertyMemberDoesNotHavePrivateProtectedSetter = - PropertyMembers().That().Are(propertyMember).Should().NotHavePrivateProtectedSetter(); - var propertyMembersWithPrivateProtectedSetterDoNotIncludeMember = - PropertyMembers().That().HavePrivateProtectedSetter().Should().NotBe(propertyMember).OrShould() - .NotExist(); + var propertyMemberHasPrivateProtectedSetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .HavePrivateProtectedSetter(); + var propertyMemberDoesNotHavePrivateProtectedSetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .NotHavePrivateProtectedSetter(); + var propertyMembersWithPrivateProtectedSetterDoNotIncludeMember = PropertyMembers() + .That() + .HavePrivateProtectedSetter() + .Should() + .NotBe(propertyMember) + .OrShould() + .NotExist(); var propertyMembersWithoutPrivateProtectedSetterDoNotIncludeMember = - PropertyMembers().That().DoNotHavePrivateProtectedSetter().Should().NotBe(propertyMember) + PropertyMembers() + .That() + .DoNotHavePrivateProtectedSetter() + .Should() + .NotBe(propertyMember) .AndShould() .Exist(); - Assert.Equal(propertyMember.SetterVisibility == PrivateProtected, - propertyMemberHasPrivateProtectedSetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.SetterVisibility != PrivateProtected, - propertyMemberDoesNotHavePrivateProtectedSetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.SetterVisibility != PrivateProtected, - propertyMembersWithPrivateProtectedSetterDoNotIncludeMember.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.SetterVisibility == PrivateProtected, - propertyMembersWithoutPrivateProtectedSetterDoNotIncludeMember.HasNoViolations(Architecture)); + Assert.Equal( + propertyMember.SetterVisibility == PrivateProtected, + propertyMemberHasPrivateProtectedSetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.SetterVisibility != PrivateProtected, + propertyMemberDoesNotHavePrivateProtectedSetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.SetterVisibility != PrivateProtected, + propertyMembersWithPrivateProtectedSetterDoNotIncludeMember.HasNoViolations( + Architecture + ) + ); + Assert.Equal( + propertyMember.SetterVisibility == PrivateProtected, + propertyMembersWithoutPrivateProtectedSetterDoNotIncludeMember.HasNoViolations( + Architecture + ) + ); } var propertyMembersWithPrivateProtectedSetterHavePrivateProtectedSetter = - PropertyMembers().That().HavePrivateProtectedSetter().Should().HavePrivateProtectedSetter().WithoutRequiringPositiveResults(); + PropertyMembers() + .That() + .HavePrivateProtectedSetter() + .Should() + .HavePrivateProtectedSetter() + .WithoutRequiringPositiveResults(); var propertyMembersWithPrivateProtectedSetterDoNotHavePrivateProtectedSetter = - PropertyMembers().That().HavePrivateProtectedSetter().Should().NotHavePrivateProtectedSetter() - .AndShould().Exist(); + PropertyMembers() + .That() + .HavePrivateProtectedSetter() + .Should() + .NotHavePrivateProtectedSetter() + .AndShould() + .Exist(); var propertyMembersWithoutPrivateProtectedSetterHavePrivateProtectedSetter = - PropertyMembers().That().DoNotHavePrivateProtectedSetter().Should().HavePrivateProtectedSetter() - .AndShould().Exist(); + PropertyMembers() + .That() + .DoNotHavePrivateProtectedSetter() + .Should() + .HavePrivateProtectedSetter() + .AndShould() + .Exist(); var propertyMembersWithoutPrivateProtectedSetterDoNotHavePrivateProtectedSetter = - PropertyMembers().That().DoNotHavePrivateProtectedSetter().Should().NotHavePrivateProtectedSetter(); + PropertyMembers() + .That() + .DoNotHavePrivateProtectedSetter() + .Should() + .NotHavePrivateProtectedSetter(); Assert.True( - propertyMembersWithPrivateProtectedSetterHavePrivateProtectedSetter.HasNoViolations(Architecture)); + propertyMembersWithPrivateProtectedSetterHavePrivateProtectedSetter.HasNoViolations( + Architecture + ) + ); Assert.False( - propertyMembersWithPrivateProtectedSetterDoNotHavePrivateProtectedSetter.HasNoViolations(Architecture)); + propertyMembersWithPrivateProtectedSetterDoNotHavePrivateProtectedSetter.HasNoViolations( + Architecture + ) + ); Assert.False( - propertyMembersWithoutPrivateProtectedSetterHavePrivateProtectedSetter.HasNoViolations(Architecture)); + propertyMembersWithoutPrivateProtectedSetterHavePrivateProtectedSetter.HasNoViolations( + Architecture + ) + ); Assert.True( - propertyMembersWithoutPrivateProtectedSetterDoNotHavePrivateProtectedSetter - .HasNoViolations(Architecture)); + propertyMembersWithoutPrivateProtectedSetterDoNotHavePrivateProtectedSetter.HasNoViolations( + Architecture + ) + ); } [Fact] @@ -316,39 +680,90 @@ public void HavePrivateSetterTest() { foreach (var propertyMember in _propertyMembers) { - var propertyMemberHasPrivateSetter = - PropertyMembers().That().Are(propertyMember).Should().HavePrivateSetter(); - var propertyMemberDoesNotHavePrivateSetter = - PropertyMembers().That().Are(propertyMember).Should().NotHavePrivateSetter(); - var propertyMembersWithPrivateSetterDoNotIncludeMember = - PropertyMembers().That().HavePrivateSetter().Should().NotBe(propertyMember).OrShould().NotExist(); - var propertyMembersWithoutPrivateSetterDoNotIncludeMember = - PropertyMembers().That().DoNotHavePrivateSetter().Should().NotBe(propertyMember).AndShould() - .Exist(); - - Assert.Equal(propertyMember.SetterVisibility == Private, - propertyMemberHasPrivateSetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.SetterVisibility != Private, - propertyMemberDoesNotHavePrivateSetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.SetterVisibility != Private, - propertyMembersWithPrivateSetterDoNotIncludeMember.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.SetterVisibility == Private, - propertyMembersWithoutPrivateSetterDoNotIncludeMember.HasNoViolations(Architecture)); + var propertyMemberHasPrivateSetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .HavePrivateSetter(); + var propertyMemberDoesNotHavePrivateSetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .NotHavePrivateSetter(); + var propertyMembersWithPrivateSetterDoNotIncludeMember = PropertyMembers() + .That() + .HavePrivateSetter() + .Should() + .NotBe(propertyMember) + .OrShould() + .NotExist(); + var propertyMembersWithoutPrivateSetterDoNotIncludeMember = PropertyMembers() + .That() + .DoNotHavePrivateSetter() + .Should() + .NotBe(propertyMember) + .AndShould() + .Exist(); + + Assert.Equal( + propertyMember.SetterVisibility == Private, + propertyMemberHasPrivateSetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.SetterVisibility != Private, + propertyMemberDoesNotHavePrivateSetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.SetterVisibility != Private, + propertyMembersWithPrivateSetterDoNotIncludeMember.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.SetterVisibility == Private, + propertyMembersWithoutPrivateSetterDoNotIncludeMember.HasNoViolations( + Architecture + ) + ); } - var propertyMembersWithPrivateSetterHavePrivateSetter = - PropertyMembers().That().HavePrivateSetter().Should().HavePrivateSetter(); - var propertyMembersWithPrivateSetterDoNotHavePrivateSetter = - PropertyMembers().That().HavePrivateSetter().Should().NotHavePrivateSetter().AndShould().Exist(); - var propertyMembersWithoutPrivateSetterHavePrivateSetter = - PropertyMembers().That().DoNotHavePrivateSetter().Should().HavePrivateSetter().AndShould().Exist(); - var propertyMembersWithoutPrivateSetterDoNotHavePrivateSetter = - PropertyMembers().That().DoNotHavePrivateSetter().Should().NotHavePrivateSetter(); - - Assert.True(propertyMembersWithPrivateSetterHavePrivateSetter.HasNoViolations(Architecture)); - Assert.False(propertyMembersWithPrivateSetterDoNotHavePrivateSetter.HasNoViolations(Architecture)); - Assert.False(propertyMembersWithoutPrivateSetterHavePrivateSetter.HasNoViolations(Architecture)); - Assert.True(propertyMembersWithoutPrivateSetterDoNotHavePrivateSetter.HasNoViolations(Architecture)); + var propertyMembersWithPrivateSetterHavePrivateSetter = PropertyMembers() + .That() + .HavePrivateSetter() + .Should() + .HavePrivateSetter(); + var propertyMembersWithPrivateSetterDoNotHavePrivateSetter = PropertyMembers() + .That() + .HavePrivateSetter() + .Should() + .NotHavePrivateSetter() + .AndShould() + .Exist(); + var propertyMembersWithoutPrivateSetterHavePrivateSetter = PropertyMembers() + .That() + .DoNotHavePrivateSetter() + .Should() + .HavePrivateSetter() + .AndShould() + .Exist(); + var propertyMembersWithoutPrivateSetterDoNotHavePrivateSetter = PropertyMembers() + .That() + .DoNotHavePrivateSetter() + .Should() + .NotHavePrivateSetter(); + + Assert.True( + propertyMembersWithPrivateSetterHavePrivateSetter.HasNoViolations(Architecture) + ); + Assert.False( + propertyMembersWithPrivateSetterDoNotHavePrivateSetter.HasNoViolations(Architecture) + ); + Assert.False( + propertyMembersWithoutPrivateSetterHavePrivateSetter.HasNoViolations(Architecture) + ); + Assert.True( + propertyMembersWithoutPrivateSetterDoNotHavePrivateSetter.HasNoViolations( + Architecture + ) + ); } [Fact] @@ -356,39 +771,96 @@ public void HaveProtectedGetterTest() { foreach (var propertyMember in _propertyMembers) { - var propertyMemberHasProtectedGetter = - PropertyMembers().That().Are(propertyMember).Should().HaveProtectedGetter(); - var propertyMemberDoesNotHaveProtectedGetter = - PropertyMembers().That().Are(propertyMember).Should().NotHaveProtectedGetter(); - var propertyMembersWithProtectedGetterDoNotIncludeMember = - PropertyMembers().That().HaveProtectedGetter().Should().NotBe(propertyMember).OrShould().NotExist(); - var propertyMembersWithoutProtectedGetterDoNotIncludeMember = - PropertyMembers().That().DoNotHaveProtectedGetter().Should().NotBe(propertyMember).AndShould() - .Exist(); - - Assert.Equal(propertyMember.GetterVisibility == Protected, - propertyMemberHasProtectedGetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.GetterVisibility != Protected, - propertyMemberDoesNotHaveProtectedGetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.GetterVisibility != Protected, - propertyMembersWithProtectedGetterDoNotIncludeMember.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.GetterVisibility == Protected, - propertyMembersWithoutProtectedGetterDoNotIncludeMember.HasNoViolations(Architecture)); + var propertyMemberHasProtectedGetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .HaveProtectedGetter(); + var propertyMemberDoesNotHaveProtectedGetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .NotHaveProtectedGetter(); + var propertyMembersWithProtectedGetterDoNotIncludeMember = PropertyMembers() + .That() + .HaveProtectedGetter() + .Should() + .NotBe(propertyMember) + .OrShould() + .NotExist(); + var propertyMembersWithoutProtectedGetterDoNotIncludeMember = PropertyMembers() + .That() + .DoNotHaveProtectedGetter() + .Should() + .NotBe(propertyMember) + .AndShould() + .Exist(); + + Assert.Equal( + propertyMember.GetterVisibility == Protected, + propertyMemberHasProtectedGetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.GetterVisibility != Protected, + propertyMemberDoesNotHaveProtectedGetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.GetterVisibility != Protected, + propertyMembersWithProtectedGetterDoNotIncludeMember.HasNoViolations( + Architecture + ) + ); + Assert.Equal( + propertyMember.GetterVisibility == Protected, + propertyMembersWithoutProtectedGetterDoNotIncludeMember.HasNoViolations( + Architecture + ) + ); } - var propertyMembersWithProtectedGetterHaveProtectedGetter = - PropertyMembers().That().HaveProtectedGetter().Should().HaveProtectedGetter(); - var propertyMembersWithProtectedGetterDoNotHaveProtectedGetter = - PropertyMembers().That().HaveProtectedGetter().Should().NotHaveProtectedGetter().AndShould().Exist(); - var propertyMembersWithoutProtectedGetterHaveProtectedGetter = - PropertyMembers().That().DoNotHaveProtectedGetter().Should().HaveProtectedGetter().AndShould().Exist(); - var propertyMembersWithoutProtectedGetterDoNotHaveProtectedGetter = - PropertyMembers().That().DoNotHaveProtectedGetter().Should().NotHaveProtectedGetter(); - - Assert.True(propertyMembersWithProtectedGetterHaveProtectedGetter.HasNoViolations(Architecture)); - Assert.False(propertyMembersWithProtectedGetterDoNotHaveProtectedGetter.HasNoViolations(Architecture)); - Assert.False(propertyMembersWithoutProtectedGetterHaveProtectedGetter.HasNoViolations(Architecture)); - Assert.True(propertyMembersWithoutProtectedGetterDoNotHaveProtectedGetter.HasNoViolations(Architecture)); + var propertyMembersWithProtectedGetterHaveProtectedGetter = PropertyMembers() + .That() + .HaveProtectedGetter() + .Should() + .HaveProtectedGetter(); + var propertyMembersWithProtectedGetterDoNotHaveProtectedGetter = PropertyMembers() + .That() + .HaveProtectedGetter() + .Should() + .NotHaveProtectedGetter() + .AndShould() + .Exist(); + var propertyMembersWithoutProtectedGetterHaveProtectedGetter = PropertyMembers() + .That() + .DoNotHaveProtectedGetter() + .Should() + .HaveProtectedGetter() + .AndShould() + .Exist(); + var propertyMembersWithoutProtectedGetterDoNotHaveProtectedGetter = PropertyMembers() + .That() + .DoNotHaveProtectedGetter() + .Should() + .NotHaveProtectedGetter(); + + Assert.True( + propertyMembersWithProtectedGetterHaveProtectedGetter.HasNoViolations(Architecture) + ); + Assert.False( + propertyMembersWithProtectedGetterDoNotHaveProtectedGetter.HasNoViolations( + Architecture + ) + ); + Assert.False( + propertyMembersWithoutProtectedGetterHaveProtectedGetter.HasNoViolations( + Architecture + ) + ); + Assert.True( + propertyMembersWithoutProtectedGetterDoNotHaveProtectedGetter.HasNoViolations( + Architecture + ) + ); } [Fact] @@ -396,49 +868,104 @@ public void HaveProtectedInternalGetterTest() { foreach (var propertyMember in _propertyMembers) { - var propertyMemberHasProtectedInternalGetter = - PropertyMembers().That().Are(propertyMember).Should().HaveProtectedInternalGetter(); - var propertyMemberDoesNotHaveProtectedInternalGetter = - PropertyMembers().That().Are(propertyMember).Should().NotHaveProtectedInternalGetter(); - var propertyMembersWithProtectedInternalGetterDoNotIncludeMember = - PropertyMembers().That().HaveProtectedInternalGetter().Should().NotBe(propertyMember).OrShould() - .NotExist(); + var propertyMemberHasProtectedInternalGetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .HaveProtectedInternalGetter(); + var propertyMemberDoesNotHaveProtectedInternalGetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .NotHaveProtectedInternalGetter(); + var propertyMembersWithProtectedInternalGetterDoNotIncludeMember = PropertyMembers() + .That() + .HaveProtectedInternalGetter() + .Should() + .NotBe(propertyMember) + .OrShould() + .NotExist(); var propertyMembersWithoutProtectedInternalGetterDoNotIncludeMember = - PropertyMembers().That().DoNotHaveProtectedInternalGetter().Should().NotBe(propertyMember) + PropertyMembers() + .That() + .DoNotHaveProtectedInternalGetter() + .Should() + .NotBe(propertyMember) .AndShould() .Exist(); - Assert.Equal(propertyMember.GetterVisibility == ProtectedInternal, - propertyMemberHasProtectedInternalGetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.GetterVisibility != ProtectedInternal, - propertyMemberDoesNotHaveProtectedInternalGetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.GetterVisibility != ProtectedInternal, - propertyMembersWithProtectedInternalGetterDoNotIncludeMember.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.GetterVisibility == ProtectedInternal, - propertyMembersWithoutProtectedInternalGetterDoNotIncludeMember.HasNoViolations(Architecture)); + Assert.Equal( + propertyMember.GetterVisibility == ProtectedInternal, + propertyMemberHasProtectedInternalGetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.GetterVisibility != ProtectedInternal, + propertyMemberDoesNotHaveProtectedInternalGetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.GetterVisibility != ProtectedInternal, + propertyMembersWithProtectedInternalGetterDoNotIncludeMember.HasNoViolations( + Architecture + ) + ); + Assert.Equal( + propertyMember.GetterVisibility == ProtectedInternal, + propertyMembersWithoutProtectedInternalGetterDoNotIncludeMember.HasNoViolations( + Architecture + ) + ); } var propertyMembersWithProtectedInternalGetterHaveProtectedInternalGetter = - PropertyMembers().That().HaveProtectedInternalGetter().Should().HaveProtectedInternalGetter().WithoutRequiringPositiveResults(); + PropertyMembers() + .That() + .HaveProtectedInternalGetter() + .Should() + .HaveProtectedInternalGetter() + .WithoutRequiringPositiveResults(); var propertyMembersWithProtectedInternalGetterDoNotHaveProtectedInternalGetter = - PropertyMembers().That().HaveProtectedInternalGetter().Should().NotHaveProtectedInternalGetter() - .AndShould().Exist(); + PropertyMembers() + .That() + .HaveProtectedInternalGetter() + .Should() + .NotHaveProtectedInternalGetter() + .AndShould() + .Exist(); var propertyMembersWithoutProtectedInternalGetterHaveProtectedInternalGetter = - PropertyMembers().That().DoNotHaveProtectedInternalGetter().Should().HaveProtectedInternalGetter() - .AndShould().Exist(); + PropertyMembers() + .That() + .DoNotHaveProtectedInternalGetter() + .Should() + .HaveProtectedInternalGetter() + .AndShould() + .Exist(); var propertyMembersWithoutProtectedInternalGetterDoNotHaveProtectedInternalGetter = - PropertyMembers().That().DoNotHaveProtectedInternalGetter().Should().NotHaveProtectedInternalGetter(); + PropertyMembers() + .That() + .DoNotHaveProtectedInternalGetter() + .Should() + .NotHaveProtectedInternalGetter(); Assert.True( - propertyMembersWithProtectedInternalGetterHaveProtectedInternalGetter.HasNoViolations(Architecture)); + propertyMembersWithProtectedInternalGetterHaveProtectedInternalGetter.HasNoViolations( + Architecture + ) + ); Assert.False( - propertyMembersWithProtectedInternalGetterDoNotHaveProtectedInternalGetter - .HasNoViolations(Architecture)); + propertyMembersWithProtectedInternalGetterDoNotHaveProtectedInternalGetter.HasNoViolations( + Architecture + ) + ); Assert.False( - propertyMembersWithoutProtectedInternalGetterHaveProtectedInternalGetter.HasNoViolations(Architecture)); + propertyMembersWithoutProtectedInternalGetterHaveProtectedInternalGetter.HasNoViolations( + Architecture + ) + ); Assert.True( propertyMembersWithoutProtectedInternalGetterDoNotHaveProtectedInternalGetter.HasNoViolations( - Architecture)); + Architecture + ) + ); } [Fact] @@ -446,49 +973,104 @@ public void HaveProtectedInternalSetterTest() { foreach (var propertyMember in _propertyMembers) { - var propertyMemberHasProtectedInternalSetter = - PropertyMembers().That().Are(propertyMember).Should().HaveProtectedInternalSetter(); - var propertyMemberDoesNotHaveProtectedInternalSetter = - PropertyMembers().That().Are(propertyMember).Should().NotHaveProtectedInternalSetter(); - var propertyMembersWithProtectedInternalSetterDoNotIncludeMember = - PropertyMembers().That().HaveProtectedInternalSetter().Should().NotBe(propertyMember).OrShould() - .NotExist(); + var propertyMemberHasProtectedInternalSetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .HaveProtectedInternalSetter(); + var propertyMemberDoesNotHaveProtectedInternalSetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .NotHaveProtectedInternalSetter(); + var propertyMembersWithProtectedInternalSetterDoNotIncludeMember = PropertyMembers() + .That() + .HaveProtectedInternalSetter() + .Should() + .NotBe(propertyMember) + .OrShould() + .NotExist(); var propertyMembersWithoutProtectedInternalSetterDoNotIncludeMember = - PropertyMembers().That().DoNotHaveProtectedInternalSetter().Should().NotBe(propertyMember) + PropertyMembers() + .That() + .DoNotHaveProtectedInternalSetter() + .Should() + .NotBe(propertyMember) .AndShould() .Exist(); - Assert.Equal(propertyMember.SetterVisibility == ProtectedInternal, - propertyMemberHasProtectedInternalSetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.SetterVisibility != ProtectedInternal, - propertyMemberDoesNotHaveProtectedInternalSetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.SetterVisibility != ProtectedInternal, - propertyMembersWithProtectedInternalSetterDoNotIncludeMember.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.SetterVisibility == ProtectedInternal, - propertyMembersWithoutProtectedInternalSetterDoNotIncludeMember.HasNoViolations(Architecture)); + Assert.Equal( + propertyMember.SetterVisibility == ProtectedInternal, + propertyMemberHasProtectedInternalSetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.SetterVisibility != ProtectedInternal, + propertyMemberDoesNotHaveProtectedInternalSetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.SetterVisibility != ProtectedInternal, + propertyMembersWithProtectedInternalSetterDoNotIncludeMember.HasNoViolations( + Architecture + ) + ); + Assert.Equal( + propertyMember.SetterVisibility == ProtectedInternal, + propertyMembersWithoutProtectedInternalSetterDoNotIncludeMember.HasNoViolations( + Architecture + ) + ); } var propertyMembersWithProtectedInternalSetterHaveProtectedInternalSetter = - PropertyMembers().That().HaveProtectedInternalSetter().Should().HaveProtectedInternalSetter().WithoutRequiringPositiveResults(); + PropertyMembers() + .That() + .HaveProtectedInternalSetter() + .Should() + .HaveProtectedInternalSetter() + .WithoutRequiringPositiveResults(); var propertyMembersWithProtectedInternalSetterDoNotHaveProtectedInternalSetter = - PropertyMembers().That().HaveProtectedInternalSetter().Should().NotHaveProtectedInternalSetter() - .AndShould().Exist(); + PropertyMembers() + .That() + .HaveProtectedInternalSetter() + .Should() + .NotHaveProtectedInternalSetter() + .AndShould() + .Exist(); var propertyMembersWithoutProtectedInternalSetterHaveProtectedInternalSetter = - PropertyMembers().That().DoNotHaveProtectedInternalSetter().Should().HaveProtectedInternalSetter() - .AndShould().Exist(); + PropertyMembers() + .That() + .DoNotHaveProtectedInternalSetter() + .Should() + .HaveProtectedInternalSetter() + .AndShould() + .Exist(); var propertyMembersWithoutProtectedInternalSetterDoNotHaveProtectedInternalSetter = - PropertyMembers().That().DoNotHaveProtectedInternalSetter().Should().NotHaveProtectedInternalSetter(); + PropertyMembers() + .That() + .DoNotHaveProtectedInternalSetter() + .Should() + .NotHaveProtectedInternalSetter(); Assert.True( - propertyMembersWithProtectedInternalSetterHaveProtectedInternalSetter.HasNoViolations(Architecture)); + propertyMembersWithProtectedInternalSetterHaveProtectedInternalSetter.HasNoViolations( + Architecture + ) + ); Assert.False( - propertyMembersWithProtectedInternalSetterDoNotHaveProtectedInternalSetter - .HasNoViolations(Architecture)); + propertyMembersWithProtectedInternalSetterDoNotHaveProtectedInternalSetter.HasNoViolations( + Architecture + ) + ); Assert.False( - propertyMembersWithoutProtectedInternalSetterHaveProtectedInternalSetter.HasNoViolations(Architecture)); + propertyMembersWithoutProtectedInternalSetterHaveProtectedInternalSetter.HasNoViolations( + Architecture + ) + ); Assert.True( propertyMembersWithoutProtectedInternalSetterDoNotHaveProtectedInternalSetter.HasNoViolations( - Architecture)); + Architecture + ) + ); } [Fact] @@ -496,39 +1078,97 @@ public void HaveProtectedSetterTest() { foreach (var propertyMember in _propertyMembers) { - var propertyMemberHasProtectedSetter = - PropertyMembers().That().Are(propertyMember).Should().HaveProtectedSetter(); - var propertyMemberDoesNotHaveProtectedSetter = - PropertyMembers().That().Are(propertyMember).Should().NotHaveProtectedSetter(); - var propertyMembersWithProtectedSetterDoNotIncludeMember = - PropertyMembers().That().HaveProtectedSetter().Should().NotBe(propertyMember).OrShould().NotExist(); - var propertyMembersWithoutProtectedSetterDoNotIncludeMember = - PropertyMembers().That().DoNotHaveProtectedSetter().Should().NotBe(propertyMember).AndShould() - .Exist(); - - Assert.Equal(propertyMember.SetterVisibility == Protected, - propertyMemberHasProtectedSetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.SetterVisibility != Protected, - propertyMemberDoesNotHaveProtectedSetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.SetterVisibility != Protected, - propertyMembersWithProtectedSetterDoNotIncludeMember.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.SetterVisibility == Protected, - propertyMembersWithoutProtectedSetterDoNotIncludeMember.HasNoViolations(Architecture)); + var propertyMemberHasProtectedSetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .HaveProtectedSetter(); + var propertyMemberDoesNotHaveProtectedSetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .NotHaveProtectedSetter(); + var propertyMembersWithProtectedSetterDoNotIncludeMember = PropertyMembers() + .That() + .HaveProtectedSetter() + .Should() + .NotBe(propertyMember) + .OrShould() + .NotExist(); + var propertyMembersWithoutProtectedSetterDoNotIncludeMember = PropertyMembers() + .That() + .DoNotHaveProtectedSetter() + .Should() + .NotBe(propertyMember) + .AndShould() + .Exist(); + + Assert.Equal( + propertyMember.SetterVisibility == Protected, + propertyMemberHasProtectedSetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.SetterVisibility != Protected, + propertyMemberDoesNotHaveProtectedSetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.SetterVisibility != Protected, + propertyMembersWithProtectedSetterDoNotIncludeMember.HasNoViolations( + Architecture + ) + ); + Assert.Equal( + propertyMember.SetterVisibility == Protected, + propertyMembersWithoutProtectedSetterDoNotIncludeMember.HasNoViolations( + Architecture + ) + ); } - var propertyMembersWithProtectedSetterHaveProtectedSetter = - PropertyMembers().That().HaveProtectedSetter().Should().HaveProtectedSetter().WithoutRequiringPositiveResults(); - var propertyMembersWithProtectedSetterDoNotHaveProtectedSetter = - PropertyMembers().That().HaveProtectedSetter().Should().NotHaveProtectedSetter().AndShould().Exist(); - var propertyMembersWithoutProtectedSetterHaveProtectedSetter = - PropertyMembers().That().DoNotHaveProtectedSetter().Should().HaveProtectedSetter().AndShould().Exist(); - var propertyMembersWithoutProtectedSetterDoNotHaveProtectedSetter = - PropertyMembers().That().DoNotHaveProtectedSetter().Should().NotHaveProtectedSetter(); - - Assert.True(propertyMembersWithProtectedSetterHaveProtectedSetter.HasNoViolations(Architecture)); - Assert.False(propertyMembersWithProtectedSetterDoNotHaveProtectedSetter.HasNoViolations(Architecture)); - Assert.False(propertyMembersWithoutProtectedSetterHaveProtectedSetter.HasNoViolations(Architecture)); - Assert.True(propertyMembersWithoutProtectedSetterDoNotHaveProtectedSetter.HasNoViolations(Architecture)); + var propertyMembersWithProtectedSetterHaveProtectedSetter = PropertyMembers() + .That() + .HaveProtectedSetter() + .Should() + .HaveProtectedSetter() + .WithoutRequiringPositiveResults(); + var propertyMembersWithProtectedSetterDoNotHaveProtectedSetter = PropertyMembers() + .That() + .HaveProtectedSetter() + .Should() + .NotHaveProtectedSetter() + .AndShould() + .Exist(); + var propertyMembersWithoutProtectedSetterHaveProtectedSetter = PropertyMembers() + .That() + .DoNotHaveProtectedSetter() + .Should() + .HaveProtectedSetter() + .AndShould() + .Exist(); + var propertyMembersWithoutProtectedSetterDoNotHaveProtectedSetter = PropertyMembers() + .That() + .DoNotHaveProtectedSetter() + .Should() + .NotHaveProtectedSetter(); + + Assert.True( + propertyMembersWithProtectedSetterHaveProtectedSetter.HasNoViolations(Architecture) + ); + Assert.False( + propertyMembersWithProtectedSetterDoNotHaveProtectedSetter.HasNoViolations( + Architecture + ) + ); + Assert.False( + propertyMembersWithoutProtectedSetterHaveProtectedSetter.HasNoViolations( + Architecture + ) + ); + Assert.True( + propertyMembersWithoutProtectedSetterDoNotHaveProtectedSetter.HasNoViolations( + Architecture + ) + ); } [Fact] @@ -536,39 +1176,90 @@ public void HavePublicGetterTest() { foreach (var propertyMember in _propertyMembers) { - var propertyMemberHasPublicGetter = - PropertyMembers().That().Are(propertyMember).Should().HavePublicGetter(); - var propertyMemberDoesNotHavePublicGetter = - PropertyMembers().That().Are(propertyMember).Should().NotHavePublicGetter(); - var propertyMembersWithPublicGetterDoNotIncludeMember = - PropertyMembers().That().HavePublicGetter().Should().NotBe(propertyMember).OrShould().NotExist(); - var propertyMembersWithoutPublicGetterDoNotIncludeMember = - PropertyMembers().That().DoNotHavePublicGetter().Should().NotBe(propertyMember).AndShould() - .Exist(); - - Assert.Equal(propertyMember.GetterVisibility == Public, - propertyMemberHasPublicGetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.GetterVisibility != Public, - propertyMemberDoesNotHavePublicGetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.GetterVisibility != Public, - propertyMembersWithPublicGetterDoNotIncludeMember.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.GetterVisibility == Public, - propertyMembersWithoutPublicGetterDoNotIncludeMember.HasNoViolations(Architecture)); + var propertyMemberHasPublicGetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .HavePublicGetter(); + var propertyMemberDoesNotHavePublicGetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .NotHavePublicGetter(); + var propertyMembersWithPublicGetterDoNotIncludeMember = PropertyMembers() + .That() + .HavePublicGetter() + .Should() + .NotBe(propertyMember) + .OrShould() + .NotExist(); + var propertyMembersWithoutPublicGetterDoNotIncludeMember = PropertyMembers() + .That() + .DoNotHavePublicGetter() + .Should() + .NotBe(propertyMember) + .AndShould() + .Exist(); + + Assert.Equal( + propertyMember.GetterVisibility == Public, + propertyMemberHasPublicGetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.GetterVisibility != Public, + propertyMemberDoesNotHavePublicGetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.GetterVisibility != Public, + propertyMembersWithPublicGetterDoNotIncludeMember.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.GetterVisibility == Public, + propertyMembersWithoutPublicGetterDoNotIncludeMember.HasNoViolations( + Architecture + ) + ); } - var propertyMembersWithPublicGetterHavePublicGetter = - PropertyMembers().That().HavePublicGetter().Should().HavePublicGetter(); - var propertyMembersWithPublicGetterDoNotHavePublicGetter = - PropertyMembers().That().HavePublicGetter().Should().NotHavePublicGetter().AndShould().Exist(); - var propertyMembersWithoutPublicGetterHavePublicGetter = - PropertyMembers().That().DoNotHavePublicGetter().Should().HavePublicGetter().AndShould().Exist(); - var propertyMembersWithoutPublicGetterDoNotHavePublicGetter = - PropertyMembers().That().DoNotHavePublicGetter().Should().NotHavePublicGetter(); - - Assert.True(propertyMembersWithPublicGetterHavePublicGetter.HasNoViolations(Architecture)); - Assert.False(propertyMembersWithPublicGetterDoNotHavePublicGetter.HasNoViolations(Architecture)); - Assert.False(propertyMembersWithoutPublicGetterHavePublicGetter.HasNoViolations(Architecture)); - Assert.True(propertyMembersWithoutPublicGetterDoNotHavePublicGetter.HasNoViolations(Architecture)); + var propertyMembersWithPublicGetterHavePublicGetter = PropertyMembers() + .That() + .HavePublicGetter() + .Should() + .HavePublicGetter(); + var propertyMembersWithPublicGetterDoNotHavePublicGetter = PropertyMembers() + .That() + .HavePublicGetter() + .Should() + .NotHavePublicGetter() + .AndShould() + .Exist(); + var propertyMembersWithoutPublicGetterHavePublicGetter = PropertyMembers() + .That() + .DoNotHavePublicGetter() + .Should() + .HavePublicGetter() + .AndShould() + .Exist(); + var propertyMembersWithoutPublicGetterDoNotHavePublicGetter = PropertyMembers() + .That() + .DoNotHavePublicGetter() + .Should() + .NotHavePublicGetter(); + + Assert.True( + propertyMembersWithPublicGetterHavePublicGetter.HasNoViolations(Architecture) + ); + Assert.False( + propertyMembersWithPublicGetterDoNotHavePublicGetter.HasNoViolations(Architecture) + ); + Assert.False( + propertyMembersWithoutPublicGetterHavePublicGetter.HasNoViolations(Architecture) + ); + Assert.True( + propertyMembersWithoutPublicGetterDoNotHavePublicGetter.HasNoViolations( + Architecture + ) + ); } [Fact] @@ -576,39 +1267,90 @@ public void HavePublicSetterTest() { foreach (var propertyMember in _propertyMembers) { - var propertyMemberHasPublicSetter = - PropertyMembers().That().Are(propertyMember).Should().HavePublicSetter(); - var propertyMemberDoesNotHavePublicSetter = - PropertyMembers().That().Are(propertyMember).Should().NotHavePublicSetter(); - var propertyMembersWithPublicSetterDoNotIncludeMember = - PropertyMembers().That().HavePublicSetter().Should().NotBe(propertyMember).OrShould().NotExist(); - var propertyMembersWithoutPublicSetterDoNotIncludeMember = - PropertyMembers().That().DoNotHavePublicSetter().Should().NotBe(propertyMember).AndShould() - .Exist(); - - Assert.Equal(propertyMember.SetterVisibility == Public, - propertyMemberHasPublicSetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.SetterVisibility != Public, - propertyMemberDoesNotHavePublicSetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.SetterVisibility != Public, - propertyMembersWithPublicSetterDoNotIncludeMember.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.SetterVisibility == Public, - propertyMembersWithoutPublicSetterDoNotIncludeMember.HasNoViolations(Architecture)); + var propertyMemberHasPublicSetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .HavePublicSetter(); + var propertyMemberDoesNotHavePublicSetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .NotHavePublicSetter(); + var propertyMembersWithPublicSetterDoNotIncludeMember = PropertyMembers() + .That() + .HavePublicSetter() + .Should() + .NotBe(propertyMember) + .OrShould() + .NotExist(); + var propertyMembersWithoutPublicSetterDoNotIncludeMember = PropertyMembers() + .That() + .DoNotHavePublicSetter() + .Should() + .NotBe(propertyMember) + .AndShould() + .Exist(); + + Assert.Equal( + propertyMember.SetterVisibility == Public, + propertyMemberHasPublicSetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.SetterVisibility != Public, + propertyMemberDoesNotHavePublicSetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.SetterVisibility != Public, + propertyMembersWithPublicSetterDoNotIncludeMember.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.SetterVisibility == Public, + propertyMembersWithoutPublicSetterDoNotIncludeMember.HasNoViolations( + Architecture + ) + ); } - var propertyMembersWithPublicSetterHavePublicSetter = - PropertyMembers().That().HavePublicSetter().Should().HavePublicSetter(); - var propertyMembersWithPublicSetterDoNotHavePublicSetter = - PropertyMembers().That().HavePublicSetter().Should().NotHavePublicSetter().AndShould().Exist(); - var propertyMembersWithoutPublicSetterHavePublicSetter = - PropertyMembers().That().DoNotHavePublicSetter().Should().HavePublicSetter().AndShould().Exist(); - var propertyMembersWithoutPublicSetterDoNotHavePublicSetter = - PropertyMembers().That().DoNotHavePublicSetter().Should().NotHavePublicSetter(); - - Assert.True(propertyMembersWithPublicSetterHavePublicSetter.HasNoViolations(Architecture)); - Assert.False(propertyMembersWithPublicSetterDoNotHavePublicSetter.HasNoViolations(Architecture)); - Assert.False(propertyMembersWithoutPublicSetterHavePublicSetter.HasNoViolations(Architecture)); - Assert.True(propertyMembersWithoutPublicSetterDoNotHavePublicSetter.HasNoViolations(Architecture)); + var propertyMembersWithPublicSetterHavePublicSetter = PropertyMembers() + .That() + .HavePublicSetter() + .Should() + .HavePublicSetter(); + var propertyMembersWithPublicSetterDoNotHavePublicSetter = PropertyMembers() + .That() + .HavePublicSetter() + .Should() + .NotHavePublicSetter() + .AndShould() + .Exist(); + var propertyMembersWithoutPublicSetterHavePublicSetter = PropertyMembers() + .That() + .DoNotHavePublicSetter() + .Should() + .HavePublicSetter() + .AndShould() + .Exist(); + var propertyMembersWithoutPublicSetterDoNotHavePublicSetter = PropertyMembers() + .That() + .DoNotHavePublicSetter() + .Should() + .NotHavePublicSetter(); + + Assert.True( + propertyMembersWithPublicSetterHavePublicSetter.HasNoViolations(Architecture) + ); + Assert.False( + propertyMembersWithPublicSetterDoNotHavePublicSetter.HasNoViolations(Architecture) + ); + Assert.False( + propertyMembersWithoutPublicSetterHavePublicSetter.HasNoViolations(Architecture) + ); + Assert.True( + propertyMembersWithoutPublicSetterDoNotHavePublicSetter.HasNoViolations( + Architecture + ) + ); } [Fact] @@ -616,30 +1358,73 @@ public void HaveSetterTest() { foreach (var propertyMember in _propertyMembers) { - var propertyMemberHasSetter = PropertyMembers().That().Are(propertyMember).Should().HaveSetter(); - var propertyMemberHasNoSetter = PropertyMembers().That().Are(propertyMember).Should().NotHaveSetter(); - var propertyMembersWithSetterDoNotIncludeMember = - PropertyMembers().That().HaveSetter().Should().NotBe(propertyMember).OrShould().NotExist(); - var propertyMembersWithoutSetterDoNotIncludeMember = - PropertyMembers().That().HaveNoSetter().Should().NotBe(propertyMember).AndShould().Exist(); - - Assert.Equal(propertyMember.SetterVisibility != NotAccessible, - propertyMemberHasSetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.SetterVisibility == NotAccessible, - propertyMemberHasNoSetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.SetterVisibility == NotAccessible, - propertyMembersWithSetterDoNotIncludeMember.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.SetterVisibility != NotAccessible, - propertyMembersWithoutSetterDoNotIncludeMember.HasNoViolations(Architecture)); + var propertyMemberHasSetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .HaveSetter(); + var propertyMemberHasNoSetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .NotHaveSetter(); + var propertyMembersWithSetterDoNotIncludeMember = PropertyMembers() + .That() + .HaveSetter() + .Should() + .NotBe(propertyMember) + .OrShould() + .NotExist(); + var propertyMembersWithoutSetterDoNotIncludeMember = PropertyMembers() + .That() + .HaveNoSetter() + .Should() + .NotBe(propertyMember) + .AndShould() + .Exist(); + + Assert.Equal( + propertyMember.SetterVisibility != NotAccessible, + propertyMemberHasSetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.SetterVisibility == NotAccessible, + propertyMemberHasNoSetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.SetterVisibility == NotAccessible, + propertyMembersWithSetterDoNotIncludeMember.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.SetterVisibility != NotAccessible, + propertyMembersWithoutSetterDoNotIncludeMember.HasNoViolations(Architecture) + ); } - var propertyMembersWithSetterHaveSetter = PropertyMembers().That().HaveSetter().Should().HaveSetter(); - var propertyMembersWithSetterHaveNoSetter = - PropertyMembers().That().HaveSetter().Should().NotHaveSetter().AndShould().Exist(); - var propertyMembersWithoutSetterHaveSetter = - PropertyMembers().That().HaveNoSetter().Should().HaveSetter().AndShould().Exist(); - var propertyMembersWithoutSetterHaveNoSetter = - PropertyMembers().That().HaveNoSetter().Should().NotHaveSetter(); + var propertyMembersWithSetterHaveSetter = PropertyMembers() + .That() + .HaveSetter() + .Should() + .HaveSetter(); + var propertyMembersWithSetterHaveNoSetter = PropertyMembers() + .That() + .HaveSetter() + .Should() + .NotHaveSetter() + .AndShould() + .Exist(); + var propertyMembersWithoutSetterHaveSetter = PropertyMembers() + .That() + .HaveNoSetter() + .Should() + .HaveSetter() + .AndShould() + .Exist(); + var propertyMembersWithoutSetterHaveNoSetter = PropertyMembers() + .That() + .HaveNoSetter() + .Should() + .NotHaveSetter(); Assert.True(propertyMembersWithSetterHaveSetter.HasNoViolations(Architecture)); Assert.False(propertyMembersWithSetterHaveNoSetter.HasNoViolations(Architecture)); @@ -652,35 +1437,92 @@ public void HaveInitOnlySetterTest() { foreach (var propertyMember in _propertyMembers) { - var propertyMemberHasInitOnlySetter = PropertyMembers().That().Are(propertyMember).Should().HaveInitOnlySetter(); - var propertyMemberHasNoInitOnlySetter = PropertyMembers().That().Are(propertyMember).Should().NotHaveInitOnlySetter(); - var propertyMembersWithInitOnlySetterDoNotIncludeMember = - PropertyMembers().That().HaveInitOnlySetter().Should().NotBe(propertyMember).OrShould().NotExist(); - var propertyMembersWithoutInitOnlySetterDoNotIncludeMember = - PropertyMembers().That().DoNotHaveInitOnlySetter().Should().NotBe(propertyMember).AndShould().Exist(); - - Assert.Equal(propertyMember.Writability == Writability.InitOnly, - propertyMemberHasInitOnlySetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.Writability != Writability.InitOnly, - propertyMemberHasNoInitOnlySetter.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.Writability != Writability.InitOnly, - propertyMembersWithInitOnlySetterDoNotIncludeMember.HasNoViolations(Architecture)); - Assert.Equal(propertyMember.Writability == Writability.InitOnly, - propertyMembersWithoutInitOnlySetterDoNotIncludeMember.HasNoViolations(Architecture)); + var propertyMemberHasInitOnlySetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .HaveInitOnlySetter(); + var propertyMemberHasNoInitOnlySetter = PropertyMembers() + .That() + .Are(propertyMember) + .Should() + .NotHaveInitOnlySetter(); + var propertyMembersWithInitOnlySetterDoNotIncludeMember = PropertyMembers() + .That() + .HaveInitOnlySetter() + .Should() + .NotBe(propertyMember) + .OrShould() + .NotExist(); + var propertyMembersWithoutInitOnlySetterDoNotIncludeMember = PropertyMembers() + .That() + .DoNotHaveInitOnlySetter() + .Should() + .NotBe(propertyMember) + .AndShould() + .Exist(); + + Assert.Equal( + propertyMember.Writability == Writability.InitOnly, + propertyMemberHasInitOnlySetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.Writability != Writability.InitOnly, + propertyMemberHasNoInitOnlySetter.HasNoViolations(Architecture) + ); + Assert.Equal( + propertyMember.Writability != Writability.InitOnly, + propertyMembersWithInitOnlySetterDoNotIncludeMember.HasNoViolations( + Architecture + ) + ); + Assert.Equal( + propertyMember.Writability == Writability.InitOnly, + propertyMembersWithoutInitOnlySetterDoNotIncludeMember.HasNoViolations( + Architecture + ) + ); } - var propertyMembersWithInitOnlySetterHaveInitOnlySetter = PropertyMembers().That().HaveInitOnlySetter().Should().HaveInitOnlySetter(); - var propertyMembersWithInitOnlySetterHaveNoInitOnlySetter = - PropertyMembers().That().HaveInitOnlySetter().Should().NotHaveInitOnlySetter().AndShould().Exist(); - var propertyMembersWithoutInitOnlySetterHaveInitOnlySetter = - PropertyMembers().That().DoNotHaveInitOnlySetter().Should().HaveInitOnlySetter().AndShould().Exist(); - var propertyMembersWithoutInitOnlySetterHaveNoInitOnlySetter = - PropertyMembers().That().DoNotHaveInitOnlySetter().Should().NotHaveInitOnlySetter(); - - Assert.True(propertyMembersWithInitOnlySetterHaveInitOnlySetter.HasNoViolations(Architecture)); - Assert.False(propertyMembersWithInitOnlySetterHaveNoInitOnlySetter.HasNoViolations(Architecture)); - Assert.False(propertyMembersWithoutInitOnlySetterHaveInitOnlySetter.HasNoViolations(Architecture)); - Assert.True(propertyMembersWithoutInitOnlySetterHaveNoInitOnlySetter.HasNoViolations(Architecture)); + var propertyMembersWithInitOnlySetterHaveInitOnlySetter = PropertyMembers() + .That() + .HaveInitOnlySetter() + .Should() + .HaveInitOnlySetter(); + var propertyMembersWithInitOnlySetterHaveNoInitOnlySetter = PropertyMembers() + .That() + .HaveInitOnlySetter() + .Should() + .NotHaveInitOnlySetter() + .AndShould() + .Exist(); + var propertyMembersWithoutInitOnlySetterHaveInitOnlySetter = PropertyMembers() + .That() + .DoNotHaveInitOnlySetter() + .Should() + .HaveInitOnlySetter() + .AndShould() + .Exist(); + var propertyMembersWithoutInitOnlySetterHaveNoInitOnlySetter = PropertyMembers() + .That() + .DoNotHaveInitOnlySetter() + .Should() + .NotHaveInitOnlySetter(); + + Assert.True( + propertyMembersWithInitOnlySetterHaveInitOnlySetter.HasNoViolations(Architecture) + ); + Assert.False( + propertyMembersWithInitOnlySetterHaveNoInitOnlySetter.HasNoViolations(Architecture) + ); + Assert.False( + propertyMembersWithoutInitOnlySetterHaveInitOnlySetter.HasNoViolations(Architecture) + ); + Assert.True( + propertyMembersWithoutInitOnlySetterHaveNoInitOnlySetter.HasNoViolations( + Architecture + ) + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/TypeSyntaxElementsTests.cs b/ArchUnitNETTests/Fluent/Syntax/Elements/TypeSyntaxElementsTests.cs index b4351aef9..4fe457833 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/TypeSyntaxElementsTests.cs +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/TypeSyntaxElementsTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -25,7 +25,8 @@ public TypeSyntaxElementsTests() _types = Architecture.Types; } - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; private readonly IEnumerable _types; [Fact] @@ -36,12 +37,22 @@ public void AreNestedTest() var typeIsNested = Types().That().Are(type).Should().BeNested(); var typeIsNotNested = Types().That().Are(type).Should().NotBeNested(); var nestedTypesDoNotIncludeType = Types().That().AreNested().Should().NotBe(type); - var notNestedTypesDoNotIncludeType = Types().That().AreNotNested().Should().NotBe(type); + var notNestedTypesDoNotIncludeType = Types() + .That() + .AreNotNested() + .Should() + .NotBe(type); Assert.Equal(type.IsNested, typeIsNested.HasNoViolations(Architecture)); Assert.Equal(!type.IsNested, typeIsNotNested.HasNoViolations(Architecture)); - Assert.Equal(!type.IsNested, nestedTypesDoNotIncludeType.HasNoViolations(Architecture)); - Assert.Equal(type.IsNested, notNestedTypesDoNotIncludeType.HasNoViolations(Architecture)); + Assert.Equal( + !type.IsNested, + nestedTypesDoNotIncludeType.HasNoViolations(Architecture) + ); + Assert.Equal( + type.IsNested, + notNestedTypesDoNotIncludeType.HasNoViolations(Architecture) + ); } var nestedTypesAreNested = Types().That().AreNested().Should().BeNested(); @@ -60,64 +71,156 @@ public void AreTest() { //Tests with one argument - var publicTestClassIsPublic = Types().That().Are(typeof(PublicTestClass)).Should().BePublic(); - var publicTestClassIsNotPublic = Types().That().Are(typeof(PublicTestClass)).Should().NotBePublic(); - var notPublicTypesAreNotPublicTestClass = - Types().That().AreNotPublic().Should().NotBe(typeof(PublicTestClass)); - var publicTypesAreNotPublicTestClass = Types().That().ArePublic().Should().NotBe(typeof(PublicTestClass)); + var publicTestClassIsPublic = Types() + .That() + .Are(typeof(PublicTestClass)) + .Should() + .BePublic(); + var publicTestClassIsNotPublic = Types() + .That() + .Are(typeof(PublicTestClass)) + .Should() + .NotBePublic(); + var notPublicTypesAreNotPublicTestClass = Types() + .That() + .AreNotPublic() + .Should() + .NotBe(typeof(PublicTestClass)); + var publicTypesAreNotPublicTestClass = Types() + .That() + .ArePublic() + .Should() + .NotBe(typeof(PublicTestClass)); Assert.True(publicTestClassIsPublic.HasNoViolations(Architecture)); Assert.False(publicTestClassIsNotPublic.HasNoViolations(Architecture)); Assert.True(notPublicTypesAreNotPublicTestClass.HasNoViolations(Architecture)); Assert.False(publicTypesAreNotPublicTestClass.HasNoViolations(Architecture)); - //Tests with multiple arguments - var publicTestClassAndInternalTestClassIsPublicOrInternal = Types().That() - .Are(typeof(PublicTestClass), typeof(InternalTestClass)).Should().BePublic().OrShould().BeInternal(); - var publicTestClassAndInternalTestClassIsPublic = Types().That() - .Are(typeof(PublicTestClass), typeof(InternalTestClass)).Should().BePublic(); - var notPublicAndNotInternalClassesAreNotPublicTestClassOrInternalTestClass = Types().That().AreNotPublic() - .And().AreNotInternal().Should().NotBe(typeof(PublicTestClass), typeof(InternalTestClass)); - var internalTypesAreNotPublicTestClassOrInternalTestClass = Types().That().AreInternal().Should() + var publicTestClassAndInternalTestClassIsPublicOrInternal = Types() + .That() + .Are(typeof(PublicTestClass), typeof(InternalTestClass)) + .Should() + .BePublic() + .OrShould() + .BeInternal(); + var publicTestClassAndInternalTestClassIsPublic = Types() + .That() + .Are(typeof(PublicTestClass), typeof(InternalTestClass)) + .Should() + .BePublic(); + var notPublicAndNotInternalClassesAreNotPublicTestClassOrInternalTestClass = Types() + .That() + .AreNotPublic() + .And() + .AreNotInternal() + .Should() + .NotBe(typeof(PublicTestClass), typeof(InternalTestClass)); + var internalTypesAreNotPublicTestClassOrInternalTestClass = Types() + .That() + .AreInternal() + .Should() .NotBe(typeof(PublicTestClass), typeof(InternalTestClass)); - Assert.True(publicTestClassAndInternalTestClassIsPublicOrInternal.HasNoViolations(Architecture)); + Assert.True( + publicTestClassAndInternalTestClassIsPublicOrInternal.HasNoViolations(Architecture) + ); Assert.False(publicTestClassAndInternalTestClassIsPublic.HasNoViolations(Architecture)); Assert.True( - notPublicAndNotInternalClassesAreNotPublicTestClassOrInternalTestClass.HasNoViolations(Architecture)); - Assert.False(internalTypesAreNotPublicTestClassOrInternalTestClass.HasNoViolations(Architecture)); + notPublicAndNotInternalClassesAreNotPublicTestClassOrInternalTestClass.HasNoViolations( + Architecture + ) + ); + Assert.False( + internalTypesAreNotPublicTestClassOrInternalTestClass.HasNoViolations(Architecture) + ); } [Fact] public void AssignableToTest() { - var falseTypeList1 = new List {typeof(PublicTestClass), typeof(InternalTestClass)}; - var falseTypeList2 = new List {StaticTestTypes.PublicTestClass, StaticTestTypes.InternalTestClass}; + var falseTypeList1 = new List + { + typeof(PublicTestClass), + typeof(InternalTestClass) + }; + var falseTypeList2 = new List + { + StaticTestTypes.PublicTestClass, + StaticTestTypes.InternalTestClass + }; var falseTypeListPattern = new List - {StaticTestTypes.PublicTestClass.FullName, StaticTestTypes.InternalTestClass.FullName}; + { + StaticTestTypes.PublicTestClass.FullName, + StaticTestTypes.InternalTestClass.FullName + }; foreach (var type in _types) { //One Argument - var typeIsAssignableToItself = Types().That().Are(type).Should().BeAssignableTo(type); - var typeIsAssignableToItselfPattern = Types().That().Are(type).Should().BeAssignableTo(type.FullName); - var typeIsNotAssignableToItself = Types().That().Are(type).Should().NotBeAssignableTo(type); - var typeIsNotAssignableToItselfPattern = - Types().That().Are(type).Should().NotBeAssignableTo(type.FullName); - var typeIsNotAssignableToFalseType1 = Types().That().Are(type).Should() - .NotBeAssignableTo(typeof(PublicTestClass)).OrShould().Be(typeof(PublicTestClass)); - var typeIsNotAssignableToFalseType2 = Types().That().Are(type).Should() - .NotBeAssignableTo(StaticTestTypes.PublicTestClass).OrShould().Be(typeof(PublicTestClass)); - var typeIsNotAssignableToFalseTypePattern = Types().That().Are(type).Should() - .NotBeAssignableTo(StaticTestTypes.PublicTestClass.FullName).OrShould().Be(typeof(PublicTestClass)); - var typeIsAssignableToFalseType1 = Types().That().Are(type).Should() - .BeAssignableTo(typeof(PublicTestClass)).AndShould().NotBe(typeof(PublicTestClass)); - var typeIsAssignableToFalseType2 = Types().That().Are(type).Should() - .BeAssignableTo(StaticTestTypes.PublicTestClass).AndShould().NotBe(typeof(PublicTestClass)); - var typeIsAssignableToFalseTypePattern = Types().That().Are(type).Should() - .BeAssignableTo(StaticTestTypes.PublicTestClass.FullName).AndShould() + var typeIsAssignableToItself = Types() + .That() + .Are(type) + .Should() + .BeAssignableTo(type); + var typeIsAssignableToItselfPattern = Types() + .That() + .Are(type) + .Should() + .BeAssignableTo(type.FullName); + var typeIsNotAssignableToItself = Types() + .That() + .Are(type) + .Should() + .NotBeAssignableTo(type); + var typeIsNotAssignableToItselfPattern = Types() + .That() + .Are(type) + .Should() + .NotBeAssignableTo(type.FullName); + var typeIsNotAssignableToFalseType1 = Types() + .That() + .Are(type) + .Should() + .NotBeAssignableTo(typeof(PublicTestClass)) + .OrShould() + .Be(typeof(PublicTestClass)); + var typeIsNotAssignableToFalseType2 = Types() + .That() + .Are(type) + .Should() + .NotBeAssignableTo(StaticTestTypes.PublicTestClass) + .OrShould() + .Be(typeof(PublicTestClass)); + var typeIsNotAssignableToFalseTypePattern = Types() + .That() + .Are(type) + .Should() + .NotBeAssignableTo(StaticTestTypes.PublicTestClass.FullName) + .OrShould() + .Be(typeof(PublicTestClass)); + var typeIsAssignableToFalseType1 = Types() + .That() + .Are(type) + .Should() + .BeAssignableTo(typeof(PublicTestClass)) + .AndShould() + .NotBe(typeof(PublicTestClass)); + var typeIsAssignableToFalseType2 = Types() + .That() + .Are(type) + .Should() + .BeAssignableTo(StaticTestTypes.PublicTestClass) + .AndShould() + .NotBe(typeof(PublicTestClass)); + var typeIsAssignableToFalseTypePattern = Types() + .That() + .Are(type) + .Should() + .BeAssignableTo(StaticTestTypes.PublicTestClass.FullName) + .AndShould() .NotBe(typeof(PublicTestClass)); Assert.True(typeIsAssignableToItself.HasNoViolations(Architecture)); @@ -133,58 +236,144 @@ public void AssignableToTest() //Multiple Arguments - var typeIsAssignableToItselfFluent = - Types().That().Are(type).Should().BeAssignableTo(Types().That().Are(type)); - var typeIsNotAssignableToItselfFluent = - Types().That().Are(type).Should().NotBeAssignableTo(Types().That().Are(type)); - var typeIsNotAssignableToFalseTypeMultiple1 = Types().That().Are(type).Should() - .NotBeAssignableTo(falseTypeList1).OrShould().Be(falseTypeList1); - var typeIsNotAssignableToFalseTypeMultiple2 = Types().That().Are(type).Should() - .NotBeAssignableTo(falseTypeList2).OrShould().Be(falseTypeList1); - var typeIsNotAssignableToFalseTypeMultiplePattern = Types().That().Are(type).Should() - .NotBeAssignableTo(falseTypeListPattern).OrShould().Be(falseTypeList1); - var typeIsAssignableToFalseTypeMultiple1 = Types().That().Are(type).Should() - .BeAssignableTo(falseTypeList1).AndShould().NotBe(falseTypeList1); - var typeIsAssignableToFalseTypeMultiple2 = Types().That().Are(type).Should() - .BeAssignableTo(falseTypeList2).AndShould().NotBe(falseTypeList1); - var typeIsAssignableToFalseTypeMultiplePattern = Types().That().Are(type).Should() - .BeAssignableTo(falseTypeListPattern).AndShould().NotBe(falseTypeList1); + var typeIsAssignableToItselfFluent = Types() + .That() + .Are(type) + .Should() + .BeAssignableTo(Types().That().Are(type)); + var typeIsNotAssignableToItselfFluent = Types() + .That() + .Are(type) + .Should() + .NotBeAssignableTo(Types().That().Are(type)); + var typeIsNotAssignableToFalseTypeMultiple1 = Types() + .That() + .Are(type) + .Should() + .NotBeAssignableTo(falseTypeList1) + .OrShould() + .Be(falseTypeList1); + var typeIsNotAssignableToFalseTypeMultiple2 = Types() + .That() + .Are(type) + .Should() + .NotBeAssignableTo(falseTypeList2) + .OrShould() + .Be(falseTypeList1); + var typeIsNotAssignableToFalseTypeMultiplePattern = Types() + .That() + .Are(type) + .Should() + .NotBeAssignableTo(falseTypeListPattern) + .OrShould() + .Be(falseTypeList1); + var typeIsAssignableToFalseTypeMultiple1 = Types() + .That() + .Are(type) + .Should() + .BeAssignableTo(falseTypeList1) + .AndShould() + .NotBe(falseTypeList1); + var typeIsAssignableToFalseTypeMultiple2 = Types() + .That() + .Are(type) + .Should() + .BeAssignableTo(falseTypeList2) + .AndShould() + .NotBe(falseTypeList1); + var typeIsAssignableToFalseTypeMultiplePattern = Types() + .That() + .Are(type) + .Should() + .BeAssignableTo(falseTypeListPattern) + .AndShould() + .NotBe(falseTypeList1); Assert.True(typeIsAssignableToItselfFluent.HasNoViolations(Architecture)); Assert.False(typeIsNotAssignableToItselfFluent.HasNoViolations(Architecture)); Assert.True(typeIsNotAssignableToFalseTypeMultiple1.HasNoViolations(Architecture)); Assert.True(typeIsNotAssignableToFalseTypeMultiple2.HasNoViolations(Architecture)); - Assert.True(typeIsNotAssignableToFalseTypeMultiplePattern.HasNoViolations(Architecture)); + Assert.True( + typeIsNotAssignableToFalseTypeMultiplePattern.HasNoViolations(Architecture) + ); Assert.False(typeIsAssignableToFalseTypeMultiple1.HasNoViolations(Architecture)); Assert.False(typeIsAssignableToFalseTypeMultiple2.HasNoViolations(Architecture)); - Assert.False(typeIsAssignableToFalseTypeMultiplePattern.HasNoViolations(Architecture)); + Assert.False( + typeIsAssignableToFalseTypeMultiplePattern.HasNoViolations(Architecture) + ); } } [Fact] public void NestedInTest() { - Classes().That().AreNestedIn(typeof(PublicTestClass)) - .Should().Be(typeof(PublicTestClass.ChildClass)).AndShould().Exist().Check(Architecture); - - Classes().That().AreNestedIn(typeof(PublicTestClass)) - .Should().NotBe(typeof(PublicTestClass)).AndShould().Exist().Check(Architecture); - - Classes().That().AreNestedIn(StaticTestTypes.PublicTestClass) - .Should().Be(typeof(PublicTestClass.ChildClass)).AndShould().Exist().Check(Architecture); - - Classes().That().AreNestedIn(typeof(PublicTestClass.ChildClass)) - .Should().NotExist().Check(Architecture); - - Classes().That().AreNestedIn(typeof(PublicTestClass), typeof(InternalTestClass)) - .Should().Be(typeof(PublicTestClass.ChildClass)).AndShould().Exist().Check(Architecture); - - var typeList1 = new List {typeof(PublicTestClass), typeof(InternalTestClass)}; - var typeList2 = new List {StaticTestTypes.PublicTestClass, StaticTestTypes.InternalTestClass}; - - Classes().That().AreNestedIn(typeList1).Should().Be(typeof(PublicTestClass.ChildClass)).AndShould().Exist().Check(Architecture); - Classes().That().AreNestedIn(typeList2).Should().Be(typeof(PublicTestClass.ChildClass)).AndShould().Exist().Check(Architecture); - } + Classes() + .That() + .AreNestedIn(typeof(PublicTestClass)) + .Should() + .Be(typeof(PublicTestClass.ChildClass)) + .AndShould() + .Exist() + .Check(Architecture); + + Classes() + .That() + .AreNestedIn(typeof(PublicTestClass)) + .Should() + .NotBe(typeof(PublicTestClass)) + .AndShould() + .Exist() + .Check(Architecture); + + Classes() + .That() + .AreNestedIn(StaticTestTypes.PublicTestClass) + .Should() + .Be(typeof(PublicTestClass.ChildClass)) + .AndShould() + .Exist() + .Check(Architecture); + + Classes() + .That() + .AreNestedIn(typeof(PublicTestClass.ChildClass)) + .Should() + .NotExist() + .Check(Architecture); + + Classes() + .That() + .AreNestedIn(typeof(PublicTestClass), typeof(InternalTestClass)) + .Should() + .Be(typeof(PublicTestClass.ChildClass)) + .AndShould() + .Exist() + .Check(Architecture); + + var typeList1 = new List { typeof(PublicTestClass), typeof(InternalTestClass) }; + var typeList2 = new List + { + StaticTestTypes.PublicTestClass, + StaticTestTypes.InternalTestClass + }; + + Classes() + .That() + .AreNestedIn(typeList1) + .Should() + .Be(typeof(PublicTestClass.ChildClass)) + .AndShould() + .Exist() + .Check(Architecture); + Classes() + .That() + .AreNestedIn(typeList2) + .Should() + .Be(typeof(PublicTestClass.ChildClass)) + .AndShould() + .Exist() + .Check(Architecture); + } [Fact] public void HaveFieldMemberWithNameTest() @@ -193,31 +382,52 @@ public void HaveFieldMemberWithNameTest() { foreach (var fieldMember in type.GetFieldMembers()) { - var typeHasFieldMember = - Types().That().Are(type).Should().HaveFieldMemberWithName(fieldMember.Name); - var typeDoesNotHaveFieldMember = Types().That().Are(type).Should() + var typeHasFieldMember = Types() + .That() + .Are(type) + .Should() + .HaveFieldMemberWithName(fieldMember.Name); + var typeDoesNotHaveFieldMember = Types() + .That() + .Are(type) + .Should() .NotHaveFieldMemberWithName(fieldMember.Name); - var typesWithFieldMemberShouldExist = - Types().That().HaveFieldMemberWithName(fieldMember.Name).Should().Exist(); - var typesWithFieldMemberShouldBeOtherTypes = Types().That() - .HaveFieldMemberWithName(fieldMember.Name).Should().NotBe(type); + var typesWithFieldMemberShouldExist = Types() + .That() + .HaveFieldMemberWithName(fieldMember.Name) + .Should() + .Exist(); + var typesWithFieldMemberShouldBeOtherTypes = Types() + .That() + .HaveFieldMemberWithName(fieldMember.Name) + .Should() + .NotBe(type); Assert.True(typeHasFieldMember.HasNoViolations(Architecture)); Assert.False(typeDoesNotHaveFieldMember.HasNoViolations(Architecture)); Assert.True(typesWithFieldMemberShouldExist.HasNoViolations(Architecture)); - Assert.False(typesWithFieldMemberShouldBeOtherTypes.HasNoViolations(Architecture)); + Assert.False( + typesWithFieldMemberShouldBeOtherTypes.HasNoViolations(Architecture) + ); } } foreach (var fieldMember in Architecture.FieldMembers) { - var typesWithFieldMemberShouldHaveFieldMember = Types().That() - .HaveFieldMemberWithName(fieldMember.Name).Should() + var typesWithFieldMemberShouldHaveFieldMember = Types() + .That() + .HaveFieldMemberWithName(fieldMember.Name) + .Should() .HaveFieldMemberWithName(fieldMember.Name); - var typesWithFieldMemberExist = - Types().That().HaveFieldMemberWithName(fieldMember.Name).Should().Exist(); - - Assert.True(typesWithFieldMemberShouldHaveFieldMember.HasNoViolations(Architecture)); + var typesWithFieldMemberExist = Types() + .That() + .HaveFieldMemberWithName(fieldMember.Name) + .Should() + .Exist(); + + Assert.True( + typesWithFieldMemberShouldHaveFieldMember.HasNoViolations(Architecture) + ); Assert.True(typesWithFieldMemberExist.HasNoViolations(Architecture)); } } @@ -229,14 +439,26 @@ public void HaveMemberWithNameTest() { foreach (var member in type.Members) { - var typeHasMember = - Types().That().Are(type).Should().HaveMemberWithName(member.Name); - var typeDoesNotHaveMember = Types().That().Are(type).Should() + var typeHasMember = Types() + .That() + .Are(type) + .Should() + .HaveMemberWithName(member.Name); + var typeDoesNotHaveMember = Types() + .That() + .Are(type) + .Should() .NotHaveMemberWithName(member.Name); - var typesWithMemberShouldExist = - Types().That().HaveMemberWithName(member.Name).Should().Exist(); - var typesWithMemberShouldBeOtherTypes = Types().That() - .HaveMemberWithName(member.Name).Should().NotBe(type); + var typesWithMemberShouldExist = Types() + .That() + .HaveMemberWithName(member.Name) + .Should() + .Exist(); + var typesWithMemberShouldBeOtherTypes = Types() + .That() + .HaveMemberWithName(member.Name) + .Should() + .NotBe(type); Assert.True(typeHasMember.HasNoViolations(Architecture)); Assert.False(typeDoesNotHaveMember.HasNoViolations(Architecture)); @@ -247,18 +469,22 @@ public void HaveMemberWithNameTest() foreach (var member in Architecture.Members) { - var typesWithMemberShouldHaveMember = Types().That() - .HaveMemberWithName(member.Name).Should() + var typesWithMemberShouldHaveMember = Types() + .That() + .HaveMemberWithName(member.Name) + .Should() .HaveMemberWithName(member.Name); - var typesWithMemberExist = - Types().That().HaveMemberWithName(member.Name).Should().Exist(); + var typesWithMemberExist = Types() + .That() + .HaveMemberWithName(member.Name) + .Should() + .Exist(); Assert.True(typesWithMemberShouldHaveMember.HasNoViolations(Architecture)); Assert.True(typesWithMemberExist.HasNoViolations(Architecture)); } } - [Fact] public void HaveMethodMemberWithNameTest() { @@ -266,31 +492,52 @@ public void HaveMethodMemberWithNameTest() { foreach (var methodMember in type.GetMethodMembers()) { - var typeHasMethodMember = - Types().That().Are(type).Should().HaveMethodMemberWithName(methodMember.Name); - var typeDoesNotHaveMethodMember = Types().That().Are(type).Should() + var typeHasMethodMember = Types() + .That() + .Are(type) + .Should() + .HaveMethodMemberWithName(methodMember.Name); + var typeDoesNotHaveMethodMember = Types() + .That() + .Are(type) + .Should() .NotHaveMethodMemberWithName(methodMember.Name); - var typesWithMethodMemberShouldExist = - Types().That().HaveMethodMemberWithName(methodMember.Name).Should().Exist(); - var typesWithMethodMemberShouldBeOtherTypes = Types().That() - .HaveMethodMemberWithName(methodMember.Name).Should().NotBe(type); + var typesWithMethodMemberShouldExist = Types() + .That() + .HaveMethodMemberWithName(methodMember.Name) + .Should() + .Exist(); + var typesWithMethodMemberShouldBeOtherTypes = Types() + .That() + .HaveMethodMemberWithName(methodMember.Name) + .Should() + .NotBe(type); Assert.True(typeHasMethodMember.HasNoViolations(Architecture)); Assert.False(typeDoesNotHaveMethodMember.HasNoViolations(Architecture)); Assert.True(typesWithMethodMemberShouldExist.HasNoViolations(Architecture)); - Assert.False(typesWithMethodMemberShouldBeOtherTypes.HasNoViolations(Architecture)); + Assert.False( + typesWithMethodMemberShouldBeOtherTypes.HasNoViolations(Architecture) + ); } } foreach (var methodMember in Architecture.MethodMembers) { - var typesWithMethodMemberShouldHaveMethodMember = Types().That() - .HaveMethodMemberWithName(methodMember.Name).Should() + var typesWithMethodMemberShouldHaveMethodMember = Types() + .That() + .HaveMethodMemberWithName(methodMember.Name) + .Should() .HaveMethodMemberWithName(methodMember.Name); - var typesWithMethodMemberExist = - Types().That().HaveMethodMemberWithName(methodMember.Name).Should().Exist(); - - Assert.True(typesWithMethodMemberShouldHaveMethodMember.HasNoViolations(Architecture)); + var typesWithMethodMemberExist = Types() + .That() + .HaveMethodMemberWithName(methodMember.Name) + .Should() + .Exist(); + + Assert.True( + typesWithMethodMemberShouldHaveMethodMember.HasNoViolations(Architecture) + ); Assert.True(typesWithMethodMemberExist.HasNoViolations(Architecture)); } } @@ -302,88 +549,169 @@ public void HavePropertyMemberWithNameTest() { foreach (var propertyMember in type.GetPropertyMembers()) { - var typeHasPropertyMember = - Types().That().Are(type).Should().HavePropertyMemberWithName(propertyMember.Name); - var typeDoesNotHavePropertyMember = Types().That().Are(type).Should() + var typeHasPropertyMember = Types() + .That() + .Are(type) + .Should() + .HavePropertyMemberWithName(propertyMember.Name); + var typeDoesNotHavePropertyMember = Types() + .That() + .Are(type) + .Should() .NotHavePropertyMemberWithName(propertyMember.Name); - var typesWithPropertyMemberShouldExist = - Types().That().HavePropertyMemberWithName(propertyMember.Name).Should().Exist(); - var typesWithPropertyMemberShouldBeOtherTypes = Types().That() - .HavePropertyMemberWithName(propertyMember.Name).Should().NotBe(type); + var typesWithPropertyMemberShouldExist = Types() + .That() + .HavePropertyMemberWithName(propertyMember.Name) + .Should() + .Exist(); + var typesWithPropertyMemberShouldBeOtherTypes = Types() + .That() + .HavePropertyMemberWithName(propertyMember.Name) + .Should() + .NotBe(type); Assert.True(typeHasPropertyMember.HasNoViolations(Architecture)); Assert.False(typeDoesNotHavePropertyMember.HasNoViolations(Architecture)); Assert.True(typesWithPropertyMemberShouldExist.HasNoViolations(Architecture)); - Assert.False(typesWithPropertyMemberShouldBeOtherTypes.HasNoViolations(Architecture)); + Assert.False( + typesWithPropertyMemberShouldBeOtherTypes.HasNoViolations(Architecture) + ); } } foreach (var propertyMember in Architecture.PropertyMembers) { - var typesWithPropertyMemberShouldHavePropertyMember = Types().That() - .HavePropertyMemberWithName(propertyMember.Name).Should() + var typesWithPropertyMemberShouldHavePropertyMember = Types() + .That() + .HavePropertyMemberWithName(propertyMember.Name) + .Should() .HavePropertyMemberWithName(propertyMember.Name); - var typesWithPropertyMemberExist = - Types().That().HavePropertyMemberWithName(propertyMember.Name).Should().Exist(); - - Assert.True(typesWithPropertyMemberShouldHavePropertyMember.HasNoViolations(Architecture)); + var typesWithPropertyMemberExist = Types() + .That() + .HavePropertyMemberWithName(propertyMember.Name) + .Should() + .Exist(); + + Assert.True( + typesWithPropertyMemberShouldHavePropertyMember.HasNoViolations(Architecture) + ); Assert.True(typesWithPropertyMemberExist.HasNoViolations(Architecture)); } } - [Fact] public void ImplementInterfaceTest() { foreach (var intf in Architecture.Interfaces) { - var typesThatImplementInterfaceImplementInterface = Types().That() + var typesThatImplementInterfaceImplementInterface = Types() + .That() + .ImplementInterface(intf.FullName) + .Should() + .ImplementInterface(intf.FullName) + .WithoutRequiringPositiveResults(); + var typesThatImplementInterfaceDoNotImplementInterface = Types() + .That() .ImplementInterface(intf.FullName) - .Should().ImplementInterface(intf.FullName).WithoutRequiringPositiveResults(); - var typesThatImplementInterfaceDoNotImplementInterface = Types().That() - .ImplementInterface(intf.FullName).Should() - .NotImplementInterface(intf.FullName).AndShould().Exist(); - var typesThatDoNotImplementInterfaceImplementInterface = Types().That() + .Should() + .NotImplementInterface(intf.FullName) + .AndShould() + .Exist(); + var typesThatDoNotImplementInterfaceImplementInterface = Types() + .That() .DoNotImplementInterface(intf.FullName) - .Should().ImplementInterface(intf.FullName).AndShould().Exist(); - var typesThatDoNotImplementInterfaceDoNotImplementInterface = Types().That() - .DoNotImplementInterface(intf.FullName).Should() + .Should() + .ImplementInterface(intf.FullName) + .AndShould() + .Exist(); + var typesThatDoNotImplementInterfaceDoNotImplementInterface = Types() + .That() + .DoNotImplementInterface(intf.FullName) + .Should() .NotImplementInterface(intf.FullName); - var implementInterfaceIsEqualToAssignableTo = Types().That().ImplementInterface(intf.FullName).Should() - .BeAssignableTo(intf.FullName).And().Types().That().AreAssignableTo(intf.FullName).Should() - .ImplementInterface(intf.FullName).OrShould().Be(intf.FullName); - - Assert.True(typesThatImplementInterfaceImplementInterface.HasNoViolations(Architecture)); - Assert.False(typesThatImplementInterfaceDoNotImplementInterface.HasNoViolations(Architecture)); - Assert.False(typesThatDoNotImplementInterfaceImplementInterface.HasNoViolations(Architecture)); - Assert.True(typesThatDoNotImplementInterfaceDoNotImplementInterface.HasNoViolations(Architecture)); + var implementInterfaceIsEqualToAssignableTo = Types() + .That() + .ImplementInterface(intf.FullName) + .Should() + .BeAssignableTo(intf.FullName) + .And() + .Types() + .That() + .AreAssignableTo(intf.FullName) + .Should() + .ImplementInterface(intf.FullName) + .OrShould() + .Be(intf.FullName); + + Assert.True( + typesThatImplementInterfaceImplementInterface.HasNoViolations(Architecture) + ); + Assert.False( + typesThatImplementInterfaceDoNotImplementInterface.HasNoViolations(Architecture) + ); + Assert.False( + typesThatDoNotImplementInterfaceImplementInterface.HasNoViolations(Architecture) + ); + Assert.True( + typesThatDoNotImplementInterfaceDoNotImplementInterface.HasNoViolations( + Architecture + ) + ); Assert.True(implementInterfaceIsEqualToAssignableTo.HasNoViolations(Architecture)); } - var testClassThatImplementsInterfaceImplementsInterface = Classes().That() - .Are(StaticTestTypes.InheritedType).Should() + var testClassThatImplementsInterfaceImplementsInterface = Classes() + .That() + .Are(StaticTestTypes.InheritedType) + .Should() .ImplementInterface(InheritedTestInterface.FullName); - var testClassThatImplementsOtherInterfaceImplementsInterfaces = Types().That() - .Are(StaticTestTypes.InheritedType).Should() - .ImplementInterface(InheritedTestInterface.FullName).AndShould() + var testClassThatImplementsOtherInterfaceImplementsInterfaces = Types() + .That() + .Are(StaticTestTypes.InheritedType) + .Should() + .ImplementInterface(InheritedTestInterface.FullName) + .AndShould() .ImplementInterface(InheritingInterface.FullName); - var testInterfaceThatImplementsInterfaceImplementsInterface = Interfaces().That() - .Are(InheritingInterface).Should() + var testInterfaceThatImplementsInterfaceImplementsInterface = Interfaces() + .That() + .Are(InheritingInterface) + .Should() .ImplementInterface(InheritedTestInterface.FullName); - var testClassThatImplementsNoInterfaceDoesNotImplementInterface = Interfaces().That() - .Are(StaticTestTypes.PublicTestClass).Should() + var testClassThatImplementsNoInterfaceDoesNotImplementInterface = Interfaces() + .That() + .Are(StaticTestTypes.PublicTestClass) + .Should() .NotImplementInterface(InheritedTestInterface.FullName) .WithoutRequiringPositiveResults(); - var testClassThatImplementsNoInterfaceImplementsInterface = Interfaces().That() - .Are(StaticTestTypes.PublicTestClass).Should() - .ImplementInterface(InheritedTestInterface.FullName).AndShould() + var testClassThatImplementsNoInterfaceImplementsInterface = Interfaces() + .That() + .Are(StaticTestTypes.PublicTestClass) + .Should() + .ImplementInterface(InheritedTestInterface.FullName) + .AndShould() .Exist(); - Assert.True(testClassThatImplementsInterfaceImplementsInterface.HasNoViolations(Architecture)); - Assert.True(testClassThatImplementsOtherInterfaceImplementsInterfaces.HasNoViolations(Architecture)); - Assert.True(testInterfaceThatImplementsInterfaceImplementsInterface.HasNoViolations(Architecture)); - Assert.True(testClassThatImplementsNoInterfaceDoesNotImplementInterface.HasNoViolations(Architecture)); - Assert.False(testClassThatImplementsNoInterfaceImplementsInterface.HasNoViolations(Architecture)); + Assert.True( + testClassThatImplementsInterfaceImplementsInterface.HasNoViolations(Architecture) + ); + Assert.True( + testClassThatImplementsOtherInterfaceImplementsInterfaces.HasNoViolations( + Architecture + ) + ); + Assert.True( + testInterfaceThatImplementsInterfaceImplementsInterface.HasNoViolations( + Architecture + ) + ); + Assert.True( + testClassThatImplementsNoInterfaceDoesNotImplementInterface.HasNoViolations( + Architecture + ) + ); + Assert.False( + testClassThatImplementsNoInterfaceImplementsInterface.HasNoViolations(Architecture) + ); } [Fact] @@ -392,14 +720,27 @@ public void ResideInAssemblyTest() foreach (var type in _types) { { - var typeResidesInOwnAssembly = - Types().That().Are(type).Should().ResideInAssembly(type.Assembly.FullName); - var typeDoesNotResideInOwnAssembly = - Types().That().Are(type).Should().NotResideInAssembly(type.Assembly.FullName); - var thereAreTypesInOwnAssembly = - Types().That().ResideInAssembly(type.Assembly.FullName).Should().Exist(); - var typesInOtherAssemblyAreOtherTypes = - Types().That().DoNotResideInAssembly(type.Assembly.FullName).Should().NotBe(type).WithoutRequiringPositiveResults(); + var typeResidesInOwnAssembly = Types() + .That() + .Are(type) + .Should() + .ResideInAssembly(type.Assembly.FullName); + var typeDoesNotResideInOwnAssembly = Types() + .That() + .Are(type) + .Should() + .NotResideInAssembly(type.Assembly.FullName); + var thereAreTypesInOwnAssembly = Types() + .That() + .ResideInAssembly(type.Assembly.FullName) + .Should() + .Exist(); + var typesInOtherAssemblyAreOtherTypes = Types() + .That() + .DoNotResideInAssembly(type.Assembly.FullName) + .Should() + .NotBe(type) + .WithoutRequiringPositiveResults(); Assert.True(typeResidesInOwnAssembly.HasNoViolations(Architecture)); Assert.False(typeDoesNotResideInOwnAssembly.HasNoViolations(Architecture)); @@ -408,14 +749,27 @@ public void ResideInAssemblyTest() } { - var typeResidesInOwnAssembly = - Types().That().Are(type).Should().ResideInAssembly(type.Assembly); - var typeDoesNotResideInOwnAssembly = - Types().That().Are(type).Should().NotResideInAssembly(type.Assembly); - var thereAreTypesInOwnAssembly = - Types().That().ResideInAssembly(type.Assembly).Should().Exist(); - var typesInOtherAssemblyAreOtherTypes = - Types().That().DoNotResideInAssembly(type.Assembly).Should().NotBe(type).WithoutRequiringPositiveResults(); + var typeResidesInOwnAssembly = Types() + .That() + .Are(type) + .Should() + .ResideInAssembly(type.Assembly); + var typeDoesNotResideInOwnAssembly = Types() + .That() + .Are(type) + .Should() + .NotResideInAssembly(type.Assembly); + var thereAreTypesInOwnAssembly = Types() + .That() + .ResideInAssembly(type.Assembly) + .Should() + .Exist(); + var typesInOtherAssemblyAreOtherTypes = Types() + .That() + .DoNotResideInAssembly(type.Assembly) + .Should() + .NotBe(type) + .WithoutRequiringPositiveResults(); Assert.True(typeResidesInOwnAssembly.HasNoViolations(Architecture)); Assert.False(typeDoesNotResideInOwnAssembly.HasNoViolations(Architecture)); @@ -426,33 +780,55 @@ public void ResideInAssemblyTest() foreach (var assembly in Architecture.Assemblies.Select(assembly => assembly.FullName)) { - var typesInAssemblyAreInAssembly = - Types().That().ResideInAssembly(assembly).Should().ResideInAssembly(assembly); - var typesInOtherAssemblyAreInOtherAssembly = Types().That().DoNotResideInAssembly(assembly).Should() - .NotResideInAssembly(assembly).WithoutRequiringPositiveResults(); + var typesInAssemblyAreInAssembly = Types() + .That() + .ResideInAssembly(assembly) + .Should() + .ResideInAssembly(assembly); + var typesInOtherAssemblyAreInOtherAssembly = Types() + .That() + .DoNotResideInAssembly(assembly) + .Should() + .NotResideInAssembly(assembly) + .WithoutRequiringPositiveResults(); Assert.True(typesInAssemblyAreInAssembly.HasNoViolations(Architecture)); Assert.True(typesInOtherAssemblyAreInOtherAssembly.HasNoViolations(Architecture)); } - + foreach (var assembly in Architecture.Assemblies) { - var typesInAssemblyAreInAssembly = - Types().That().ResideInAssembly(assembly).Should().ResideInAssembly(assembly); - var typesInOtherAssemblyAreInOtherAssembly = Types().That().DoNotResideInAssembly(assembly).Should() - .NotResideInAssembly(assembly).WithoutRequiringPositiveResults(); + var typesInAssemblyAreInAssembly = Types() + .That() + .ResideInAssembly(assembly) + .Should() + .ResideInAssembly(assembly); + var typesInOtherAssemblyAreInOtherAssembly = Types() + .That() + .DoNotResideInAssembly(assembly) + .Should() + .NotResideInAssembly(assembly) + .WithoutRequiringPositiveResults(); Assert.True(typesInAssemblyAreInAssembly.HasNoViolations(Architecture)); Assert.True(typesInOtherAssemblyAreInOtherAssembly.HasNoViolations(Architecture)); } - var testClassIsInRightAssembly = Types().That().Are(typeof(PublicTestClass)).Should() + var testClassIsInRightAssembly = Types() + .That() + .Are(typeof(PublicTestClass)) + .Should() .ResideInAssembly(typeof(PublicTestClass).Assembly); - var testClassIsInFalseAssembly = Types().That().Are(typeof(PublicTestClass)).Should() + var testClassIsInFalseAssembly = Types() + .That() + .Are(typeof(PublicTestClass)) + .Should() .NotResideInAssembly(typeof(PublicTestClass).Assembly); - var typesInRightAssemblyDoNotContainTestClass = Types().That() + var typesInRightAssemblyDoNotContainTestClass = Types() + .That() .ResideInAssembly(typeof(PublicTestClass).Assembly) - .Should().NotBe(typeof(PublicTestClass)); + .Should() + .NotBe(typeof(PublicTestClass)); Assert.True(testClassIsInRightAssembly.HasNoViolations(Architecture)); Assert.False(testClassIsInFalseAssembly.HasNoViolations(Architecture)); @@ -464,16 +840,26 @@ public void ResideInNamespaceTest() { foreach (var type in _types) { - var typeResidesInOwnNamespace = - Types().That().Are(type).Should().ResideInNamespace(type.Namespace.FullName); - var typeDoesNotResideInOwnNamespace = - Types().That().Are(type).Should() - .NotResideInNamespace(type.Namespace.FullName); - var thereAreTypesInOwnNamespace = - Types().That().ResideInNamespace(type.Namespace.FullName).Should().Exist(); - var typesInOtherNamespaceAreOtherTypes = Types().That() + var typeResidesInOwnNamespace = Types() + .That() + .Are(type) + .Should() + .ResideInNamespace(type.Namespace.FullName); + var typeDoesNotResideInOwnNamespace = Types() + .That() + .Are(type) + .Should() + .NotResideInNamespace(type.Namespace.FullName); + var thereAreTypesInOwnNamespace = Types() + .That() + .ResideInNamespace(type.Namespace.FullName) + .Should() + .Exist(); + var typesInOtherNamespaceAreOtherTypes = Types() + .That() .DoNotResideInNamespace(type.Namespace.FullName) - .Should().NotBe(type); + .Should() + .NotBe(type); Assert.True(typeResidesInOwnNamespace.HasNoViolations(Architecture)); Assert.False(typeDoesNotResideInOwnNamespace.HasNoViolations(Architecture)); @@ -483,11 +869,15 @@ public void ResideInNamespaceTest() foreach (var namespc in Architecture.Namespaces.Select(namespc => namespc.FullName)) { - var typesInNamespaceAreInNamespace = - Types().That().ResideInNamespace(namespc).Should() - .ResideInNamespace(namespc); - var typesInOtherNamespaceAreInOtherNamespace = Types().That() - .DoNotResideInNamespace(namespc).Should() + var typesInNamespaceAreInNamespace = Types() + .That() + .ResideInNamespace(namespc) + .Should() + .ResideInNamespace(namespc); + var typesInOtherNamespaceAreInOtherNamespace = Types() + .That() + .DoNotResideInNamespace(namespc) + .Should() .NotResideInNamespace(namespc); Assert.True(typesInNamespaceAreInNamespace.HasNoViolations(Architecture)); @@ -522,7 +912,11 @@ public void AreStructsTest() var typeIsStruct = Types().That().Are(type).Should().BeStructs(); var typeIsNotStruct = Types().That().Are(type).Should().NotBeStructs(); var structsDoNotIncludeType = Types().That().AreStructs().Should().NotBe(type); - var notStructsDoNotIncludeType = Types().That().AreNotStructs().Should().NotBe(type); + var notStructsDoNotIncludeType = Types() + .That() + .AreNotStructs() + .Should() + .NotBe(type); Assert.Equal(isStruct, typeIsStruct.HasNoViolations(Architecture)); Assert.Equal(!isStruct, typeIsNotStruct.HasNoViolations(Architecture)); @@ -539,30 +933,58 @@ public void AreValueTypesTest() var isValueType = type is Struct || type is Enum; var typeIsValueType = Types().That().Are(type).Should().BeValueTypes(); var typeIsNotValueType = Types().That().Are(type).Should().NotBeValueTypes(); - var valueTypesDoNotIncludeType = Types().That().AreValueTypes().Should().NotBe(type); - var notValueTypesDoNotIncludeType = Types().That().AreNotValueTypes().Should().NotBe(type); + var valueTypesDoNotIncludeType = Types() + .That() + .AreValueTypes() + .Should() + .NotBe(type); + var notValueTypesDoNotIncludeType = Types() + .That() + .AreNotValueTypes() + .Should() + .NotBe(type); Assert.Equal(isValueType, typeIsValueType.HasNoViolations(Architecture)); Assert.Equal(!isValueType, typeIsNotValueType.HasNoViolations(Architecture)); - Assert.Equal(!isValueType, valueTypesDoNotIncludeType.HasNoViolations(Architecture)); - Assert.Equal(isValueType, notValueTypesDoNotIncludeType.HasNoViolations(Architecture)); + Assert.Equal( + !isValueType, + valueTypesDoNotIncludeType.HasNoViolations(Architecture) + ); + Assert.Equal( + isValueType, + notValueTypesDoNotIncludeType.HasNoViolations(Architecture) + ); } } [Fact] public void TypesThatAreNotNestedMustBeVisible() { - var typesThatAreNotNestedMustBeVisible = - Types().That().AreNotNested().Should().BePublic().OrShould().BeInternal(); + var typesThatAreNotNestedMustBeVisible = Types() + .That() + .AreNotNested() + .Should() + .BePublic() + .OrShould() + .BeInternal(); typesThatAreNotNestedMustBeVisible.Check(Architecture); } [Fact] public void TypesWithRestrictedVisibilityMustBeNested() { - var typesWithRestrictedVisibilityMustBeNested = Types().That().ArePrivate().Or() - .AreProtected().Or().ArePrivateProtected().Or().AreProtectedInternal().Should().BeNested(); + var typesWithRestrictedVisibilityMustBeNested = Types() + .That() + .ArePrivate() + .Or() + .AreProtected() + .Or() + .ArePrivateProtected() + .Or() + .AreProtectedInternal() + .Should() + .BeNested(); typesWithRestrictedVisibilityMustBeNested.Check(Architecture); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Loader/ArchLoaderTests.cs b/ArchUnitNETTests/Loader/ArchLoaderTests.cs index 62c8237a9..7f533a4d2 100644 --- a/ArchUnitNETTests/Loader/ArchLoaderTests.cs +++ b/ArchUnitNETTests/Loader/ArchLoaderTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Linq; @@ -28,37 +28,46 @@ public void LoadAssemblies() [Fact] public void LoadAssembliesIncludingRecursiveDependencies() { - var archUnitNetTestArchitectureWithRecursiveDependencies = - new ArchLoader().LoadAssembliesIncludingDependencies(new[] { typeof(BaseClass).Assembly }, true) - .Build(); + var archUnitNetTestArchitectureWithRecursiveDependencies = new ArchLoader() + .LoadAssembliesIncludingDependencies(new[] { typeof(BaseClass).Assembly }, true) + .Build(); - Assert.True(archUnitNetTestArchitectureWithRecursiveDependencies.Assemblies.Count() > 100); + Assert.True( + archUnitNetTestArchitectureWithRecursiveDependencies.Assemblies.Count() > 100 + ); } [Fact] public void LoadAssembliesRecursivelyWithCustomFilter() { - FilterFunc filterFunc = assembly => assembly.Name.Name.StartsWith("ArchUnit") ? FilterResult.LoadAndContinue : FilterResult.DontLoadAndStop; + FilterFunc filterFunc = assembly => + assembly.Name.Name.StartsWith("ArchUnit") + ? FilterResult.LoadAndContinue + : FilterResult.DontLoadAndStop; var loader = new ArchLoader(); - var architecture = loader.LoadAssembliesRecursively(new[] { typeof(BaseClass).Assembly }, filterFunc).Build(); - + var architecture = loader + .LoadAssembliesRecursively(new[] { typeof(BaseClass).Assembly }, filterFunc) + .Build(); + Assert.Equal(3, architecture.Assemblies.Count()); } - + [Fact] public void LoadAssembliesRecursively_NestedDependencyOnly() { FilterFunc filterFunc = assembly => - { + { if (assembly.Name.Name == "ArchUnitNet") return FilterResult.LoadAndStop; - + return FilterResult.SkipAndContinue; }; var loader = new ArchLoader(); - var architecture = loader.LoadAssembliesRecursively(new[] { typeof(BaseClass).Assembly }, filterFunc).Build(); - + var architecture = loader + .LoadAssembliesRecursively(new[] { typeof(BaseClass).Assembly }, filterFunc) + .Build(); + Assert.Equal(1, architecture.Assemblies.Count()); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Loader/AssemblyAttributesTests.cs b/ArchUnitNETTests/Loader/AssemblyAttributesTests.cs index 2b6e836e7..428d60e86 100644 --- a/ArchUnitNETTests/Loader/AssemblyAttributesTests.cs +++ b/ArchUnitNETTests/Loader/AssemblyAttributesTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Linq; using ArchUnitNET.Domain; @@ -15,7 +15,8 @@ namespace ArchUnitNETTests.Loader { public class AssemblyAttributesTests { - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestAssemblyArchitecture; private readonly Attribute _testAttribute; private const string TestParameter = "TestParameter"; @@ -37,9 +38,14 @@ public void CollectAssemblyAttributeParametersTest() { Assert.Single(Architecture.Assemblies); var assembly = Architecture.Assemblies.First(); - Assert.Contains(assembly.AttributeInstances, - instance => Equals(instance.Type, _testAttribute) && - instance.AttributeArguments.Any(arg => arg.Value is string val && val == TestParameter)); + Assert.Contains( + assembly.AttributeInstances, + instance => + Equals(instance.Type, _testAttribute) + && instance.AttributeArguments.Any(arg => + arg.Value is string val && val == TestParameter + ) + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Loader/InstructionExtensionTests.cs b/ArchUnitNETTests/Loader/InstructionExtensionTests.cs index aab59f37e..c7114c614 100644 --- a/ArchUnitNETTests/Loader/InstructionExtensionTests.cs +++ b/ArchUnitNETTests/Loader/InstructionExtensionTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -19,13 +19,19 @@ public class InstructionExtensionTests { public InstructionExtensionTests() { - var mockModuleDefinition = LoadMockModule(typeof(InstructionExtensionTests).Assembly.Location); - _nextOpNull = mockModuleDefinition.Assembly.Modules.First().Types - .First(type => type.Name == "ClassWithPropertyA").Methods.First().Body.Instructions - .First(instruction => instruction.OpCode.Equals(OpCodes.Ret)); - _nextOperandIsNotFieldReference = mockModuleDefinition.Assembly.Modules.First().Types - .First(type => type.Name == "ClassWithMethodSignatureA").Methods.First().Body.Instructions - .First(instruction => instruction.OpCode.Equals(OpCodes.Newobj)); + var mockModuleDefinition = LoadMockModule( + typeof(InstructionExtensionTests).Assembly.Location + ); + _nextOpNull = mockModuleDefinition + .Assembly.Modules.First() + .Types.First(type => type.Name == "ClassWithPropertyA") + .Methods.First() + .Body.Instructions.First(instruction => instruction.OpCode.Equals(OpCodes.Ret)); + _nextOperandIsNotFieldReference = mockModuleDefinition + .Assembly.Modules.First() + .Types.First(type => type.Name == "ClassWithMethodSignatureA") + .Methods.First() + .Body.Instructions.First(instruction => instruction.OpCode.Equals(OpCodes.Newobj)); } private readonly Instruction _nullInstruction = null; @@ -34,7 +40,9 @@ public InstructionExtensionTests() [Theory] [ClassData(typeof(InstructionExtensionBuild.InstructionExtensionTestData))] - public void InstructionExtensionMethodsProperlyHandleNullArgument(Func instructionFunc) + public void InstructionExtensionMethodsProperlyHandleNullArgument( + Func instructionFunc + ) { Assert.Throws(() => instructionFunc(_nullInstruction)); } @@ -74,30 +82,40 @@ public void GetAssigneeFieldDefinitionProperlyHandlesNextOpNull() [Fact] public void GetAssigneeFieldDefinitionProperlyHandlesNullArgument() { - Assert.Throws(() => _nullInstruction.GetAssigneeFieldDefinition()); + Assert.Throws( + () => _nullInstruction.GetAssigneeFieldDefinition() + ); } } public class InstructionExtensionBuild { - private static object[] BuildInstructionExtensionTestData(Func instructionFunc) + private static object[] BuildInstructionExtensionTestData( + Func instructionFunc + ) { - return new object[] {instructionFunc}; + return new object[] { instructionFunc }; } public class InstructionExtensionTestData : IEnumerable { private readonly List _instructionExtensionData = new List { - BuildInstructionExtensionTestData(InstructionExtensions.IsOperationForBackedProperty), + BuildInstructionExtensionTestData( + InstructionExtensions.IsOperationForBackedProperty + ), BuildInstructionExtensionTestData(InstructionExtensions.IsMethodCallAssignment), BuildInstructionExtensionTestData(InstructionExtensions.IsMethodCallOp), - BuildInstructionExtensionTestData(InstructionExtensions.IsMethodCallToSetBackingFieldDefinition), + BuildInstructionExtensionTestData( + InstructionExtensions.IsMethodCallToSetBackingFieldDefinition + ), BuildInstructionExtensionTestData(InstructionExtensions.IsReturnOp), BuildInstructionExtensionTestData(InstructionExtensions.IsNewObjectOp), BuildInstructionExtensionTestData(InstructionExtensions.IsOperandBackingField), BuildInstructionExtensionTestData(InstructionExtensions.IsSetFieldOp), - BuildInstructionExtensionTestData(InstructionExtensions.IsNewObjectToSetBackingField) + BuildInstructionExtensionTestData( + InstructionExtensions.IsNewObjectToSetBackingField + ) }; public IEnumerator GetEnumerator() @@ -111,4 +129,4 @@ IEnumerator IEnumerable.GetEnumerator() } } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Loader/NamespaceTests.cs b/ArchUnitNETTests/Loader/NamespaceTests.cs index a70cfa594..1cc317039 100644 --- a/ArchUnitNETTests/Loader/NamespaceTests.cs +++ b/ArchUnitNETTests/Loader/NamespaceTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Linq; using Xunit; @@ -17,7 +17,9 @@ public void NoNamespacesWithEmptyNameTest() { Assert.True( StaticTestArchitectures.ArchUnitNETTestArchitecture.Namespaces.All(ns => - ns.FullName != "")); + ns.FullName != "" + ) + ); //this currently fails with StaticTestArchitectures.FullArchUnitNETArchitectureWithDependencies because of some weird Interop, Guard, Consts,... types } @@ -25,8 +27,10 @@ public void NoNamespacesWithEmptyNameTest() public void NoEmptyNamespacesTest() { Assert.True( - StaticTestArchitectures.FullArchUnitNETArchitectureWithDependencies.Namespaces - .All(ns => ns.Types.Any())); + StaticTestArchitectures.FullArchUnitNETArchitectureWithDependencies.Namespaces.All( + ns => ns.Types.Any() + ) + ); } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Loader/NestedTypesTests.cs b/ArchUnitNETTests/Loader/NestedTypesTests.cs index 59745835e..d11213f81 100644 --- a/ArchUnitNETTests/Loader/NestedTypesTests.cs +++ b/ArchUnitNETTests/Loader/NestedTypesTests.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using ArchUnitNET.Domain; using ArchUnitNET.Loader; @@ -15,18 +15,42 @@ namespace ArchUnitNETTests.Loader { public class NestedTypesTests { - private static readonly Architecture Architecture = - new ArchLoader().LoadAssemblies(System.Reflection.Assembly.Load("ArchUnitNETTests")).Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssemblies(System.Reflection.Assembly.Load("ArchUnitNETTests")) + .Build(); [Fact] public void FindAllNestedTypes() { - Types().That().Are(typeof(Layer1Class.Layer2Class)).Should().Exist().Check(Architecture); - Types().That().Are(typeof(Layer1Class.Layer2Class.Layer3Class1)).Should().Exist().Check(Architecture); - Types().That().Are(typeof(Layer1Class.Layer2Class.Layer3Class1.Layer4Class1)).Should().Exist() + Types() + .That() + .Are(typeof(Layer1Class.Layer2Class)) + .Should() + .Exist() .Check(Architecture); - Types().That().Are(typeof(Layer1Class.Layer2Class.Layer3Class2)).Should().Exist().Check(Architecture); - Types().That().Are(typeof(Layer1Class.Layer2Class.Layer3Class2.Layer4Class2)).Should().Exist() + Types() + .That() + .Are(typeof(Layer1Class.Layer2Class.Layer3Class1)) + .Should() + .Exist() + .Check(Architecture); + Types() + .That() + .Are(typeof(Layer1Class.Layer2Class.Layer3Class1.Layer4Class1)) + .Should() + .Exist() + .Check(Architecture); + Types() + .That() + .Are(typeof(Layer1Class.Layer2Class.Layer3Class2)) + .Should() + .Exist() + .Check(Architecture); + Types() + .That() + .Are(typeof(Layer1Class.Layer2Class.Layer3Class2.Layer4Class2)) + .Should() + .Exist() .Check(Architecture); } } @@ -37,17 +61,13 @@ public class Layer2Class { public class Layer3Class1 { - public class Layer4Class1 - { - } + public class Layer4Class1 { } } public class Layer3Class2 { - public class Layer4Class2 - { - } + public class Layer4Class2 { } } } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Loader/RegexUtilsTests.cs b/ArchUnitNETTests/Loader/RegexUtilsTests.cs index 92002edf4..a7dfd68e0 100644 --- a/ArchUnitNETTests/Loader/RegexUtilsTests.cs +++ b/ArchUnitNETTests/Loader/RegexUtilsTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Linq; @@ -16,7 +16,8 @@ namespace ArchUnitNETTests.Loader { public class RegexUtilsTest { - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; private static readonly string _nonMatch = "Not expected to match."; private readonly PropertyMember _autoPropertyMember; private readonly string _expectedGetMethodFullName; @@ -30,11 +31,16 @@ public RegexUtilsTest() _autoPropertyMember = propertyClass.GetPropertyMembersWithName("AutoProperty").Single(); _expectedGetMethodName = BuildExpectedGetMethodName(_autoPropertyMember); _expectedGetMethodFullName = BuildExpectedGetMethodFullName(_autoPropertyMember); - _expectedSetMethodName = BuildExpectedSetMethodName(_autoPropertyMember, _autoPropertyMember.DeclaringType); + _expectedSetMethodName = BuildExpectedSetMethodName( + _autoPropertyMember, + _autoPropertyMember.DeclaringType + ); } - private static string BuildExpectedGetMethodName(PropertyMember propertyMember, - params IType[] parameterTypes) + private static string BuildExpectedGetMethodName( + PropertyMember propertyMember, + params IType[] parameterTypes + ) { var builder = new StringBuilder(); builder.Append("get_"); @@ -43,8 +49,10 @@ private static string BuildExpectedGetMethodName(PropertyMember propertyMember, return builder.ToString(); } - private static string BuildExpectedSetMethodName(PropertyMember propertyMember, - params IType[] parameterTypes) + private static string BuildExpectedSetMethodName( + PropertyMember propertyMember, + params IType[] parameterTypes + ) { var builder = new StringBuilder(); builder.Append("set_"); @@ -53,8 +61,10 @@ private static string BuildExpectedSetMethodName(PropertyMember propertyMember, return builder.ToString(); } - private static string BuildExpectedGetMethodFullName(PropertyMember propertyMember, - params IType[] parameterTypes) + private static string BuildExpectedGetMethodFullName( + PropertyMember propertyMember, + params IType[] parameterTypes + ) { var builder = new StringBuilder(); builder.Append(propertyMember.DeclaringType.FullName); @@ -66,8 +76,10 @@ private static string BuildExpectedGetMethodFullName(PropertyMember propertyMemb return builder.ToString(); } - private static StringBuilder AddParameterTypesToMethodName(StringBuilder nameBuilder, - params IType[] parameterTypeNames) + private static StringBuilder AddParameterTypesToMethodName( + StringBuilder nameBuilder, + params IType[] parameterTypeNames + ) { nameBuilder.Append("("); for (var index = 0; index < parameterTypeNames.Length; ++index) @@ -101,15 +113,19 @@ public void GetMethodNameRegexRecognizesNonMatch() [Fact] public void GetMethodPropertyMemberFullNameRegexMatchAsExpected() { - Assert.Equal(_autoPropertyMember.Name, - RegexUtils.MatchGetPropertyName(_expectedGetMethodFullName)); + Assert.Equal( + _autoPropertyMember.Name, + RegexUtils.MatchGetPropertyName(_expectedGetMethodFullName) + ); } [Fact] public void GetMethodPropertyMemberRegexMatchAsExpected() { - Assert.Equal(_autoPropertyMember.Name, - RegexUtils.MatchGetPropertyName(_expectedGetMethodName)); + Assert.Equal( + _autoPropertyMember.Name, + RegexUtils.MatchGetPropertyName(_expectedGetMethodName) + ); } [Fact] @@ -126,12 +142,13 @@ public void SetMethodNameRegexRecognizesNonMatch() Assert.Null(RegexUtils.MatchSetPropertyName(_nonMatch)); } - [Fact] public void SetMethodPropertyMemberRegexMatchAsExpected() { - Assert.Equal(_autoPropertyMember.Name, - RegexUtils.MatchSetPropertyName(_expectedSetMethodName)); + Assert.Equal( + _autoPropertyMember.Name, + RegexUtils.MatchSetPropertyName(_expectedSetMethodName) + ); } } @@ -143,9 +160,9 @@ public class BackingFieldExamples public PropertyType FieldPropertyPair { get => _fieldPropertyPair; - set => _fieldPropertyPair = (ChildField) value; + set => _fieldPropertyPair = (ChildField)value; } public PropertyType LambdaFieldPropertyPair { get; set; } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Loader/TypeTestBuild.cs b/ArchUnitNETTests/Loader/TypeTestBuild.cs index 5b94b325a..514123105 100644 --- a/ArchUnitNETTests/Loader/TypeTestBuild.cs +++ b/ArchUnitNETTests/Loader/TypeTestBuild.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System; @@ -17,34 +17,61 @@ namespace ArchUnitNETTests.Loader { public static class TypeTestBuild { - private static readonly Architecture Architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private static readonly Architecture Architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; private static object[] BuildTypeTestData(Type originType) { var clazz = Architecture.GetITypeOfType(originType); clazz.RequiredNotNull(); - var type = new ArchUnitType(clazz.FullName, clazz.Name, clazz.Assembly, clazz.Namespace, - clazz.Visibility, clazz.IsNested, clazz.IsGeneric, clazz.IsStub, clazz.IsCompilerGenerated); + var type = new ArchUnitType( + clazz.FullName, + clazz.Name, + clazz.Assembly, + clazz.Namespace, + clazz.Visibility, + clazz.IsNested, + clazz.IsGeneric, + clazz.IsStub, + clazz.IsCompilerGenerated + ); type.GenericParameters.AddRange(clazz.GenericParameters); - return new object[] {type}; + return new object[] { type }; } private static object[] BuildTypeEquivalenceTestData(Type originType) { var clazz = Architecture.GetITypeOfType(originType); clazz.RequiredNotNull(); - var type = new ArchUnitType(clazz.FullName, clazz.Name, clazz.Assembly, clazz.Namespace, - clazz.Visibility, clazz.IsNested, clazz.IsGeneric, clazz.IsStub, clazz.IsCompilerGenerated); - object duplicateType = new ArchUnitType(clazz.FullName, clazz.Name, clazz.Assembly, - clazz.Namespace, clazz.Visibility, clazz.IsNested, clazz.IsGeneric, clazz.IsStub, - clazz.IsCompilerGenerated); + var type = new ArchUnitType( + clazz.FullName, + clazz.Name, + clazz.Assembly, + clazz.Namespace, + clazz.Visibility, + clazz.IsNested, + clazz.IsGeneric, + clazz.IsStub, + clazz.IsCompilerGenerated + ); + object duplicateType = new ArchUnitType( + clazz.FullName, + clazz.Name, + clazz.Assembly, + clazz.Namespace, + clazz.Visibility, + clazz.IsNested, + clazz.IsGeneric, + clazz.IsStub, + clazz.IsCompilerGenerated + ); var typeCopy = type; object referenceCopy = type; - return new[] {type, duplicateType, typeCopy, referenceCopy}; + return new[] { type, duplicateType, typeCopy, referenceCopy }; } public class TypeModelingTestData : IEnumerable @@ -89,4 +116,4 @@ IEnumerator IEnumerable.GetEnumerator() } } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/Loader/TypeTests.cs b/ArchUnitNETTests/Loader/TypeTests.cs index f1a8c0950..763dc6870 100644 --- a/ArchUnitNETTests/Loader/TypeTests.cs +++ b/ArchUnitNETTests/Loader/TypeTests.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -17,7 +17,8 @@ namespace ArchUnitNETTests.Loader { public class TypeTests { - private readonly Architecture _architecture = StaticTestArchitectures.ArchUnitNETTestArchitecture; + private readonly Architecture _architecture = + StaticTestArchitectures.ArchUnitNETTestArchitecture; private readonly Class _expectedAttributeClass; private readonly Type _type; @@ -37,8 +38,12 @@ public void ToStringAsExpected(Type type) [Theory] [ClassData(typeof(TypeTestBuild.TypeEquivalencyModelingTestData))] - public void TypeEquivalencyTests(IType type, object duplicateType, IType typeCopy, - [CanBeNull] object referenceCopy) + public void TypeEquivalencyTests( + IType type, + object duplicateType, + IType typeCopy, + [CanBeNull] object referenceCopy + ) { DuplicateTypesAreEqual(type, duplicateType); DuplicateTypeObjectReferencesAreEqual(type, referenceCopy); @@ -47,7 +52,10 @@ public void TypeEquivalencyTests(IType type, object duplicateType, IType typeCop TypeHasConsistentHashCode(type, duplicateType); } - private static void DuplicateTypesAreEqual([NotNull] IType type, [NotNull] object duplicateType) + private static void DuplicateTypesAreEqual( + [NotNull] IType type, + [NotNull] object duplicateType + ) { type.RequiredNotNull(); duplicateType.RequiredNotNull(); @@ -55,8 +63,10 @@ private static void DuplicateTypesAreEqual([NotNull] IType type, [NotNull] objec Assert.Equal(type, duplicateType); } - private static void DuplicateTypeObjectReferencesAreEqual([NotNull] IType type, - object objectReferenceDuplicate) + private static void DuplicateTypeObjectReferencesAreEqual( + [NotNull] IType type, + object objectReferenceDuplicate + ) { type.RequiredNotNull(); objectReferenceDuplicate.RequiredNotNull(); @@ -64,8 +74,10 @@ private static void DuplicateTypeObjectReferencesAreEqual([NotNull] IType type, Assert.Equal(type, objectReferenceDuplicate); } - private static void DuplicateTypeReferencesAreEqual([NotNull] IType type, - [NotNull] IType typeReferenceDuplicate) + private static void DuplicateTypeReferencesAreEqual( + [NotNull] IType type, + [NotNull] IType typeReferenceDuplicate + ) { type.RequiredNotNull(); typeReferenceDuplicate.RequiredNotNull(); @@ -80,8 +92,10 @@ private static void TypeDoesNotEqualNull([NotNull] IType type) Assert.False(type.Equals(null)); } - private static void TypeHasConsistentHashCode([NotNull] IType type, - [NotNull] object duplicateType) + private static void TypeHasConsistentHashCode( + [NotNull] IType type, + [NotNull] object duplicateType + ) { type.RequiredNotNull(); duplicateType.RequiredNotNull(); @@ -111,11 +125,7 @@ public void NotAssignableToNull() } [Example] - public class AssignClass : IExample - { - } + public class AssignClass : IExample { } - public interface IExample - { - } -} \ No newline at end of file + public interface IExample { } +} diff --git a/ArchUnitNETTests/SkipInReleaseBuild.cs b/ArchUnitNETTests/SkipInReleaseBuild.cs index b335b493e..aba0e46c4 100644 --- a/ArchUnitNETTests/SkipInReleaseBuild.cs +++ b/ArchUnitNETTests/SkipInReleaseBuild.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using Xunit; @@ -18,4 +18,4 @@ public SkipInReleaseBuild() #endif } } -} \ No newline at end of file +} diff --git a/ArchUnitNETTests/StaticTestArchitectures.cs b/ArchUnitNETTests/StaticTestArchitectures.cs index d3fc5bbf2..687e8de59 100644 --- a/ArchUnitNETTests/StaticTestArchitectures.cs +++ b/ArchUnitNETTests/StaticTestArchitectures.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using ArchUnitNET.Domain; @@ -17,29 +17,43 @@ namespace ArchUnitNETTests { public static class StaticTestArchitectures { - public static readonly Architecture AttributeDependencyTestArchitecture = - new ArchLoader().LoadAssemblies(typeof(ClassWithExampleAttribute).Assembly, typeof(Class1).Assembly) - .Build(); + public static readonly Architecture AttributeDependencyTestArchitecture = new ArchLoader() + .LoadAssemblies(typeof(ClassWithExampleAttribute).Assembly, typeof(Class1).Assembly) + .Build(); - public static readonly Architecture ArchUnitNETTestArchitecture = - new ArchLoader().LoadAssemblies(typeof(BaseClass).Assembly).Build(); + public static readonly Architecture ArchUnitNETTestArchitecture = new ArchLoader() + .LoadAssemblies(typeof(BaseClass).Assembly) + .Build(); - public static readonly Architecture ArchUnitNETTestAssemblyArchitecture = - new ArchLoader().LoadAssemblies(typeof(Class1).Assembly).Build(); + public static readonly Architecture ArchUnitNETTestAssemblyArchitecture = new ArchLoader() + .LoadAssemblies(typeof(Class1).Assembly) + .Build(); - public static readonly Architecture FullArchUnitNETArchitecture = - new ArchLoader().LoadAssemblies(typeof(Architecture).Assembly, typeof(BaseClass).Assembly, - typeof(Class1).Assembly, typeof(FailedArchRuleException).Assembly).Build(); + public static readonly Architecture FullArchUnitNETArchitecture = new ArchLoader() + .LoadAssemblies( + typeof(Architecture).Assembly, + typeof(BaseClass).Assembly, + typeof(Class1).Assembly, + typeof(FailedArchRuleException).Assembly + ) + .Build(); public static readonly Architecture ArchUnitNETTestArchitectureWithDependencies = - new ArchLoader().LoadAssembliesIncludingDependencies(typeof(BaseClass).Assembly).Build(); + new ArchLoader() + .LoadAssembliesIncludingDependencies(typeof(BaseClass).Assembly) + .Build(); public static readonly Architecture ArchUnitNETTestAssemblyArchitectureWithDependencies = new ArchLoader().LoadAssembliesIncludingDependencies(typeof(Class1).Assembly).Build(); public static readonly Architecture FullArchUnitNETArchitectureWithDependencies = - new ArchLoader().LoadAssembliesIncludingDependencies(typeof(Architecture).Assembly, - typeof(BaseClass).Assembly, - typeof(Class1).Assembly, typeof(FailedArchRuleException).Assembly).Build(); + new ArchLoader() + .LoadAssembliesIncludingDependencies( + typeof(Architecture).Assembly, + typeof(BaseClass).Assembly, + typeof(Class1).Assembly, + typeof(FailedArchRuleException).Assembly + ) + .Build(); } -} \ No newline at end of file +} diff --git a/ExampleTest/ExampleArchUnitTest.cs b/ExampleTest/ExampleArchUnitTest.cs index 21f7472cb..4bdacc97f 100644 --- a/ExampleTest/ExampleArchUnitTest.cs +++ b/ExampleTest/ExampleArchUnitTest.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 // ReSharper disable InconsistentNaming @@ -15,52 +15,68 @@ using Xunit; using static ArchUnitNET.Fluent.ArchRuleDefinition; - namespace ExampleTest { public class ExampleArchUnitTest { // TIP: load your architecture once at the start to maximize performance of your tests - private static readonly Architecture Architecture = new ArchLoader().LoadAssemblies( - System.Reflection.Assembly.Load("TestAssembly")) + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssemblies(System.Reflection.Assembly.Load("TestAssembly")) .Build(); + // replace and with classes from the assemblies you want to test //declare variables you'll use throughout your tests up here //use As() to give them a custom description - private readonly IObjectProvider ExampleLayer = - Types().That().ResideInAssembly("ExampleAssembly").As("Example Layer"); - - private readonly IObjectProvider ExampleClasses = - Classes().That().ImplementInterface("IExampleInterface").As("Example Classes"); - - private readonly IObjectProvider ForbiddenLayer = - Types().That().ResideInNamespace("ForbiddenNamespace").As("Forbidden Layer"); - - private readonly IObjectProvider ForbiddenInterfaces = - Interfaces().That().HaveFullNameContaining("forbidden").As("Forbidden Interfaces"); - - private readonly IObjectProvider TypoLayer = - Types().That().ResideInNamespace("TypoNamespace").As("Non-existing Typo Layer"); - + private readonly IObjectProvider ExampleLayer = Types() + .That() + .ResideInAssembly("ExampleAssembly") + .As("Example Layer"); + + private readonly IObjectProvider ExampleClasses = Classes() + .That() + .ImplementInterface("IExampleInterface") + .As("Example Classes"); + + private readonly IObjectProvider ForbiddenLayer = Types() + .That() + .ResideInNamespace("ForbiddenNamespace") + .As("Forbidden Layer"); + + private readonly IObjectProvider ForbiddenInterfaces = Interfaces() + .That() + .HaveFullNameContaining("forbidden") + .As("Forbidden Interfaces"); + + private readonly IObjectProvider TypoLayer = Types() + .That() + .ResideInNamespace("TypoNamespace") + .As("Non-existing Typo Layer"); //write some tests [Fact(Skip = "This is just a syntax example, it does not actually work")] public void TypesShouldBeInCorrectLayer() { //you can use the fluent API to write your own rules - IArchRule exampleClassesShouldBeInExampleLayer = - Classes().That().Are(ExampleClasses).Should().Be(ExampleLayer); - IArchRule forbiddenInterfacesShouldBeInForbiddenLayer = - Interfaces().That().Are(ForbiddenInterfaces).Should().Be(ForbiddenLayer); + IArchRule exampleClassesShouldBeInExampleLayer = Classes() + .That() + .Are(ExampleClasses) + .Should() + .Be(ExampleLayer); + IArchRule forbiddenInterfacesShouldBeInForbiddenLayer = Interfaces() + .That() + .Are(ForbiddenInterfaces) + .Should() + .Be(ForbiddenLayer); //check if your architecture fulfils your rules exampleClassesShouldBeInExampleLayer.Check(Architecture); forbiddenInterfacesShouldBeInForbiddenLayer.Check(Architecture); //you can also combine your rules - IArchRule combinedArchRule = - exampleClassesShouldBeInExampleLayer.And(forbiddenInterfacesShouldBeInForbiddenLayer); + IArchRule combinedArchRule = exampleClassesShouldBeInExampleLayer.And( + forbiddenInterfacesShouldBeInForbiddenLayer + ); combinedArchRule.Check(Architecture); } @@ -68,8 +84,12 @@ public void TypesShouldBeInCorrectLayer() public void ExampleLayerShouldNotAccessForbiddenLayer() { //you can give your rules a custom reason, which is displayed when it fails (together with the types that failed the rule) - IArchRule exampleLayerShouldNotAccessForbiddenLayer = Types().That().Are(ExampleLayer).Should() - .NotDependOnAny(ForbiddenLayer).Because("it's forbidden"); + IArchRule exampleLayerShouldNotAccessForbiddenLayer = Types() + .That() + .Are(ExampleLayer) + .Should() + .NotDependOnAny(ForbiddenLayer) + .Because("it's forbidden"); exampleLayerShouldNotAccessForbiddenLayer.Check(Architecture); } @@ -77,21 +97,30 @@ public void ExampleLayerShouldNotAccessForbiddenLayer() public void TypoLayerShouldViolateByDefault() { // test the new default case - IArchRule typoLayerShouldFailByDefault = Types().That().Are(TypoLayer).Should() - .NotDependOnAny(ForbiddenLayer).Because("typo layer does not exist"); + IArchRule typoLayerShouldFailByDefault = Types() + .That() + .Are(TypoLayer) + .Should() + .NotDependOnAny(ForbiddenLayer) + .Because("typo layer does not exist"); Assert.False(typoLayerShouldFailByDefault.HasNoViolations(Architecture)); - // test the active assertion (with implicit exemption) - IArchRule typoLayerShouldDefinitelyNotExist = Types().That().Are(TypoLayer).Should() - .NotExist().Because("typo layer simply is not there"); - + IArchRule typoLayerShouldDefinitelyNotExist = Types() + .That() + .Are(TypoLayer) + .Should() + .NotExist() + .Because("typo layer simply is not there"); + Assert.True(typoLayerShouldDefinitelyNotExist.HasNoViolations(Architecture)); - // test the explicit exemption - IArchRule typoLayerCanCauseNoViolations = Types().That().Are(TypoLayer).Should() + IArchRule typoLayerCanCauseNoViolations = Types() + .That() + .Are(TypoLayer) + .Should() .NotDependOnAny(ForbiddenLayer) .Because("typo layer does not exist and causes no violation") .WithoutRequiringPositiveResults(); @@ -102,25 +131,33 @@ public void TypoLayerShouldViolateByDefault() [Fact(Skip = "This is just a syntax example, it does not actually work")] public void ForbiddenClassesShouldHaveCorrectName() { - Classes().That().AreAssignableTo(ForbiddenInterfaces).Should().HaveNameContaining("forbidden") + Classes() + .That() + .AreAssignableTo(ForbiddenInterfaces) + .Should() + .HaveNameContaining("forbidden") .Check(Architecture); } [Fact(Skip = "This is just a syntax example, it does not actually work")] public void ExampleClassesShouldNotCallForbiddenMethods() { - Classes().That().Are(ExampleClasses).Should().NotCallAny( - MethodMembers().That().AreDeclaredIn(ForbiddenLayer).Or().HaveNameContaining("forbidden")) + Classes() + .That() + .Are(ExampleClasses) + .Should() + .NotCallAny( + MethodMembers() + .That() + .AreDeclaredIn(ForbiddenLayer) + .Or() + .HaveNameContaining("forbidden") + ) .Check(Architecture); } } -} - - -internal class ExampleClass -{ -} - -internal class ForbiddenClass -{ -} +} + +internal class ExampleClass { } + +internal class ForbiddenClass { } diff --git a/ExampleTest/ExampleArchUnitTestCooking.cs b/ExampleTest/ExampleArchUnitTestCooking.cs index 9716a1dea..f678a6054 100644 --- a/ExampleTest/ExampleArchUnitTestCooking.cs +++ b/ExampleTest/ExampleArchUnitTestCooking.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -26,8 +26,10 @@ public ExampleArchUnitTestCooking() } // TIP: load your architecture once at the start to maximize performance of your tests - private static readonly Architecture ChefArchitecture = - new ArchLoader().LoadAssembly(typeof(FrenchChef).Assembly).Build(); + private static readonly Architecture ChefArchitecture = new ArchLoader() + .LoadAssembly(typeof(FrenchChef).Assembly) + .Build(); + // replace with a class from your architecture // declare variables you'll use throughout your tests up here @@ -41,7 +43,6 @@ public void AllChefsCook() } } - public class FrenchChef : ICook { private int _age; @@ -60,17 +61,11 @@ public void Cook() Ratatouille(); } - private static void CremeBrulee() - { - } + private static void CremeBrulee() { } - private static void Crepes() - { - } + private static void Crepes() { } - private static void Ratatouille() - { - } + private static void Ratatouille() { } } public class ItalianChef : ICook @@ -91,21 +86,15 @@ public void Cook() Lasagna(); } - private static void PizzaMargherita() - { - } + private static void PizzaMargherita() { } - private static void Tiramisu() - { - } + private static void Tiramisu() { } - private static void Lasagna() - { - } + private static void Lasagna() { } } public interface ICook { void Cook(); } -} \ No newline at end of file +} diff --git a/ExampleTest/ExampleArchUnitTestPuml.cs b/ExampleTest/ExampleArchUnitTestPuml.cs index 459791a14..f0dddb548 100644 --- a/ExampleTest/ExampleArchUnitTestPuml.cs +++ b/ExampleTest/ExampleArchUnitTestPuml.cs @@ -1,11 +1,11 @@ -using ArchUnitNET.Domain; +using System; +using System.Collections.Generic; +using System.Text; +using ArchUnitNET.Domain; using ArchUnitNET.Fluent; using ArchUnitNET.Loader; using ArchUnitNET.xUnit; using ExampleTest.PlantUml.Addresses; -using System; -using System.Collections.Generic; -using System.Text; using Xunit; using static ArchUnitNET.Fluent.ArchRuleDefinition; @@ -13,7 +13,9 @@ namespace ExampleTest { public class ExampleArchUnitTestPuml { - private static readonly Architecture Architecture = new ArchLoader().LoadNamespacesWithinAssembly(typeof(Address).Assembly, "ExampleTest.PlantUml").Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadNamespacesWithinAssembly(typeof(Address).Assembly, "ExampleTest.PlantUml") + .Build(); [Fact] public void ClassesShouldAdhereToShoppingExampleConsideringOnlyDependenciesInDiagram() diff --git a/ExampleTest/LimitationsOnReleaseTest.cs b/ExampleTest/LimitationsOnReleaseTest.cs index 0898a1680..19d410a35 100644 --- a/ExampleTest/LimitationsOnReleaseTest.cs +++ b/ExampleTest/LimitationsOnReleaseTest.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System.Linq; using ArchUnitNET.Domain; @@ -15,38 +15,56 @@ namespace ExampleTest { public class LimitationsOnReleaseTest { - private static readonly Architecture Architecture = - new ArchLoader().LoadAssembly(typeof(LimitationsOnReleaseTest).Assembly).Build(); + private static readonly Architecture Architecture = new ArchLoader() + .LoadAssembly(typeof(LimitationsOnReleaseTest).Assembly) + .Build(); private static IType _edgeCaseDataClass = Architecture.GetClassOfType(typeof(EdgeCaseData)); - private static IType _missingDependencyClass = Architecture.GetClassOfType(typeof(MissingDependencyClass)); + private static IType _missingDependencyClass = Architecture.GetClassOfType( + typeof(MissingDependencyClass) + ); [Fact] public void CastTest() { - var typeDependencies = _edgeCaseDataClass.Members - .Where(t => t.FullName.Contains(nameof(EdgeCaseData.MethodWithCastDependency))).ToList().First() - .GetTypeDependencies().ToList(); - + var typeDependencies = _edgeCaseDataClass + .Members.Where(t => + t.FullName.Contains(nameof(EdgeCaseData.MethodWithCastDependency)) + ) + .ToList() + .First() + .GetTypeDependencies() + .ToList(); + Assert.Contains(_missingDependencyClass, typeDependencies); } - + [Fact] public void NullVariableTest() { - var methodWithCastDependencyDependencies = _edgeCaseDataClass.Members - .Where(t => t.FullName.Contains(nameof(EdgeCaseData.MethodWithNullVariable))).ToList().First() - .GetTypeDependencies().ToList(); - + var methodWithCastDependencyDependencies = _edgeCaseDataClass + .Members.Where(t => + t.FullName.Contains(nameof(EdgeCaseData.MethodWithNullVariable)) + ) + .ToList() + .First() + .GetTypeDependencies() + .ToList(); + Assert.Contains(_missingDependencyClass, methodWithCastDependencyDependencies); } - + [Fact] public void TypeOfDependencyTest() { - var methodWithTypeOfDependencyDependencies = _edgeCaseDataClass.Members - .Where(t => t.FullName.Contains(nameof(EdgeCaseData.MethodWithTypeOfDependency))).ToList().First() - .GetTypeDependencies().ToList(); + var methodWithTypeOfDependencyDependencies = _edgeCaseDataClass + .Members.Where(t => + t.FullName.Contains(nameof(EdgeCaseData.MethodWithTypeOfDependency)) + ) + .ToList() + .First() + .GetTypeDependencies() + .ToList(); Assert.Contains(_missingDependencyClass, methodWithTypeOfDependencyDependencies); } @@ -59,9 +77,10 @@ public void MethodWithTypeOfDependency() { var a = typeof(MissingDependencyClass); } + public void MethodWithCastDependency() { - var a = (MissingDependencyClass) new SubClass(); + var a = (MissingDependencyClass)new SubClass(); } public void MethodWithNullVariable() @@ -69,11 +88,9 @@ public void MethodWithNullVariable() MissingDependencyClass a = null; } } - internal class MissingDependencyClass - { - } - internal class SubClass : MissingDependencyClass - { - } + + internal class MissingDependencyClass { } + + internal class SubClass : MissingDependencyClass { } } #pragma warning restore 219 diff --git a/ExampleTest/PlantUml/Addresses/Address.cs b/ExampleTest/PlantUml/Addresses/Address.cs index 580043209..4e06529d4 100644 --- a/ExampleTest/PlantUml/Addresses/Address.cs +++ b/ExampleTest/PlantUml/Addresses/Address.cs @@ -1,14 +1,14 @@ -using ExampleTest.PlantUml.Catalog; -using System; +using System; using System.Collections.Generic; using System.Text; +using ExampleTest.PlantUml.Catalog; namespace ExampleTest.PlantUml.Addresses { public class Address { - #pragma warning disable CS0169 +#pragma warning disable CS0169 private ProductCatalog productCatalog; - #pragma warning restore CS0169 +#pragma warning restore CS0169 } } diff --git a/ExampleTest/PlantUml/Catalog/ProductCatalog.cs b/ExampleTest/PlantUml/Catalog/ProductCatalog.cs index 6bc5db0df..52b1bf8e2 100644 --- a/ExampleTest/PlantUml/Catalog/ProductCatalog.cs +++ b/ExampleTest/PlantUml/Catalog/ProductCatalog.cs @@ -1,8 +1,8 @@ -using ExampleTest.PlantUml.Orders; -using ExampleTest.PlantUml.Products; -using System; +using System; using System.Collections.Generic; using System.Text; +using ExampleTest.PlantUml.Orders; +using ExampleTest.PlantUml.Products; namespace ExampleTest.PlantUml.Catalog { diff --git a/ExampleTest/PlantUml/Customers/Customer.cs b/ExampleTest/PlantUml/Customers/Customer.cs index ae94b59dd..8c32042f3 100644 --- a/ExampleTest/PlantUml/Customers/Customer.cs +++ b/ExampleTest/PlantUml/Customers/Customer.cs @@ -1,8 +1,8 @@ -using ExampleTest.PlantUml.Addresses; -using ExampleTest.PlantUml.Orders; -using System; +using System; using System.Collections.Generic; using System.Text; +using ExampleTest.PlantUml.Addresses; +using ExampleTest.PlantUml.Orders; namespace ExampleTest.PlantUml.Customers { @@ -14,7 +14,5 @@ internal void AddOrder(Order order) { // simply having such a parameter violates the specified UML diagram } - } - } diff --git a/ExampleTest/PlantUml/Importer/ProductImport.cs b/ExampleTest/PlantUml/Importer/ProductImport.cs index f91ef3c83..68324ae5d 100644 --- a/ExampleTest/PlantUml/Importer/ProductImport.cs +++ b/ExampleTest/PlantUml/Importer/ProductImport.cs @@ -1,10 +1,10 @@ -using ExampleTest.PlantUml.Catalog; +using System; +using System.Collections.Generic; +using System.Text; +using ExampleTest.PlantUml.Catalog; using ExampleTest.PlantUml.Customers; using ExampleTest.PlantUml.Xml.Processor; using ExampleTest.PlantUml.Xml.Types; -using System; -using System.Collections.Generic; -using System.Text; namespace ExampleTest.PlantUml.Importer { diff --git a/ExampleTest/PlantUml/Orders/Order.cs b/ExampleTest/PlantUml/Orders/Order.cs index 34a9987bb..db1f0c20d 100644 --- a/ExampleTest/PlantUml/Orders/Order.cs +++ b/ExampleTest/PlantUml/Orders/Order.cs @@ -1,9 +1,9 @@ -using ExampleTest.PlantUml.Addresses; -using ExampleTest.PlantUml.Customers; -using ExampleTest.PlantUml.Products; -using System; +using System; using System.Collections.Generic; using System.Text; +using ExampleTest.PlantUml.Addresses; +using ExampleTest.PlantUml.Customers; +using ExampleTest.PlantUml.Products; namespace ExampleTest.PlantUml.Orders { @@ -26,8 +26,6 @@ internal void Report() } } - private void Report(Address address) - { - } + private void Report(Address address) { } } } diff --git a/ExampleTest/PlantUml/Products/Product.cs b/ExampleTest/PlantUml/Products/Product.cs index 2fb6d3dff..c3197f754 100644 --- a/ExampleTest/PlantUml/Products/Product.cs +++ b/ExampleTest/PlantUml/Products/Product.cs @@ -1,8 +1,8 @@ -using ExampleTest.PlantUml.Customers; -using ExampleTest.PlantUml.Orders; -using System; +using System; using System.Collections.Generic; using System.Text; +using ExampleTest.PlantUml.Customers; +using ExampleTest.PlantUml.Orders; namespace ExampleTest.PlantUml.Products { @@ -18,14 +18,8 @@ internal Order Order } } + public void Register() { } - public void Register() - { - } - - public void Report() - { - } + public void Report() { } } - } diff --git a/ExampleTest/PlantUml/Xml/Processor/XmlProcessor.cs b/ExampleTest/PlantUml/Xml/Processor/XmlProcessor.cs index 9452013d4..7faddc2eb 100644 --- a/ExampleTest/PlantUml/Xml/Processor/XmlProcessor.cs +++ b/ExampleTest/PlantUml/Xml/Processor/XmlProcessor.cs @@ -4,7 +4,5 @@ namespace ExampleTest.PlantUml.Xml.Processor { - public class XmlProcessor - { - } + public class XmlProcessor { } } diff --git a/ExampleTest/PlantUml/Xml/Types/XmlTypes.cs b/ExampleTest/PlantUml/Xml/Types/XmlTypes.cs index e17f32a10..fb227081c 100644 --- a/ExampleTest/PlantUml/Xml/Types/XmlTypes.cs +++ b/ExampleTest/PlantUml/Xml/Types/XmlTypes.cs @@ -4,7 +4,5 @@ namespace ExampleTest.PlantUml.Xml.Types { - public class XmlTypes - { - } + public class XmlTypes { } } diff --git a/ExampleTest/PlantUml/Xml/Utils/XmlUtils.cs b/ExampleTest/PlantUml/Xml/Utils/XmlUtils.cs index 387361a8c..b5bee3df2 100644 --- a/ExampleTest/PlantUml/Xml/Utils/XmlUtils.cs +++ b/ExampleTest/PlantUml/Xml/Utils/XmlUtils.cs @@ -4,7 +4,5 @@ namespace ExampleTest.PlantUml.Xml.Utils { - public class XmlUtils - { - } + public class XmlUtils { } } diff --git a/ExampleTest/WebsiteDocumentationTest.cs b/ExampleTest/WebsiteDocumentationTest.cs index 03796afb9..2cc19ed52 100644 --- a/ExampleTest/WebsiteDocumentationTest.cs +++ b/ExampleTest/WebsiteDocumentationTest.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 // @@ -17,18 +17,21 @@ using static ArchUnitNET.Fluent.ArchRuleDefinition; using static ArchUnitNET.Fluent.Slices.SliceRuleDefinition; - namespace ExampleTest { public class WebsiteDocumentationTest { private static readonly Architecture Architecture = new ArchLoader() - .LoadAssembly(typeof(WebsiteDocumentationTest).Assembly).Build(); + .LoadAssembly(typeof(WebsiteDocumentationTest).Assembly) + .Build(); [Fact] public void NamespaceDependency() { - IArchRule rule = Types().That().ResideInNamespace("Model").Should() + IArchRule rule = Types() + .That() + .ResideInNamespace("Model") + .Should() .NotDependOnAny(Types().That().ResideInNamespace("Controller")); Assert.False(rule.HasNoViolations(Architecture)); //rule.Check(Architecture); @@ -37,7 +40,10 @@ public void NamespaceDependency() [Fact] public void ClassDependency() { - IArchRule rule = Classes().That().AreAssignableTo(typeof(ICar)).Should() + IArchRule rule = Classes() + .That() + .AreAssignableTo(typeof(ICar)) + .Should() .NotDependOnAny(Classes().That().AreAssignableTo(typeof(ICanvas))); Assert.False(rule.HasNoViolations(Architecture)); //rule.Check(Architecture); @@ -46,7 +52,10 @@ public void ClassDependency() [Fact] public void InheritanceNaming() { - IArchRule rule = Classes().That().AreAssignableTo(typeof(ICar)).Should() + IArchRule rule = Classes() + .That() + .AreAssignableTo(typeof(ICar)) + .Should() .HaveNameContaining("Car"); Assert.False(rule.HasNoViolations(Architecture)); //rule.Check(Architecture); @@ -55,7 +64,10 @@ public void InheritanceNaming() [Fact] public void ClassNamespaceContainment() { - IArchRule rule = Classes().That().HaveNameContaining("Canvas").Should() + IArchRule rule = Classes() + .That() + .HaveNameContaining("Canvas") + .Should() .ResideInNamespace(typeof(ICanvas).Namespace); Assert.False(rule.HasNoViolations(Architecture)); //rule.Check(Architecture); @@ -64,7 +76,10 @@ public void ClassNamespaceContainment() [Fact] public void AttributeAccess() { - IArchRule rule = Classes().That().DoNotHaveAnyAttributes(typeof(Display)).Should() + IArchRule rule = Classes() + .That() + .DoNotHaveAnyAttributes(typeof(Display)) + .Should() .NotDependOnAny(Classes().That().AreAssignableTo(typeof(ICanvas))); Assert.False(rule.HasNoViolations(Architecture)); //rule.Check(Architecture); @@ -78,4 +93,4 @@ public void Cycles() //rule.Check(Architecture); } } -} \ No newline at end of file +} diff --git a/ExampleTest/WebsiteDocumentationTestData.cs b/ExampleTest/WebsiteDocumentationTestData.cs index f1a723657..3e66942fb 100644 --- a/ExampleTest/WebsiteDocumentationTestData.cs +++ b/ExampleTest/WebsiteDocumentationTestData.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// // ReSharper disable InconsistentNaming // ReSharper disable SuggestVarOrType_SimpleTypes @@ -19,17 +19,13 @@ namespace Model { - public interface ICar - { - } + public interface ICar { } public class FastCar : ICar { private Steering _steering; - public void IllegalAccess(ICanvas canvas) - { - } + public void IllegalAccess(ICanvas canvas) { } } public class SlowCar : ICar @@ -42,24 +38,16 @@ public SlowCar(StartCanvas canvas) } } - public class SlowRocket : ICar - { - } + public class SlowRocket : ICar { } - public class StartCanvas : ICanvas - { - } + public class StartCanvas : ICanvas { } } namespace View { - public interface ICanvas - { - } + public interface ICanvas { } - internal class EndCanvas : ICanvas - { - } + internal class EndCanvas : ICanvas { } [Display] internal class StartButton @@ -82,9 +70,7 @@ public EndButton() } } - public sealed class Display : Attribute - { - } + public sealed class Display : Attribute { } } namespace Controller @@ -98,9 +84,7 @@ public Steering(ICar car) _car = car; } - public void ApplySteering() - { - } + public void ApplySteering() { } } } @@ -111,9 +95,7 @@ internal class ModuleOneClassOne private ModuleTwoClassTwo _a; } - internal class ModuleOneClassTwo - { - } + internal class ModuleOneClassTwo { } } namespace Module.Two @@ -123,9 +105,7 @@ internal class ModuleTwoClassOne private ModuleThreeClassTwo _a; } - internal class ModuleTwoClassTwo - { - } + internal class ModuleTwoClassTwo { } } namespace Module.Three @@ -135,8 +115,6 @@ internal class ModuleThreeClassOne private ModuleOneClassTwo _a; } - internal class ModuleThreeClassTwo - { - } + internal class ModuleThreeClassTwo { } } #pragma warning restore 169 diff --git a/TestAssembly/AbstractRecord.cs b/TestAssembly/AbstractRecord.cs index f4114f1de..04dc2fa7a 100644 --- a/TestAssembly/AbstractRecord.cs +++ b/TestAssembly/AbstractRecord.cs @@ -9,8 +9,6 @@ public AbstractRecord CopyWithNewProperty(string testProperty) return this with { TestProperty2 = testProperty }; } - public void TestMethod() - { - } + public void TestMethod() { } } -} \ No newline at end of file +} diff --git a/TestAssembly/AssemblyTestAttribute.cs b/TestAssembly/AssemblyTestAttribute.cs index 7fa2c64ae..da855cb3e 100644 --- a/TestAssembly/AssemblyTestAttribute.cs +++ b/TestAssembly/AssemblyTestAttribute.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System; @@ -19,4 +19,4 @@ public AssemblyTestAttribute(string testValue) _testValue = testValue; } } -} \ No newline at end of file +} diff --git a/TestAssembly/Class1.cs b/TestAssembly/Class1.cs index b152108c0..1b3b71d27 100644 --- a/TestAssembly/Class1.cs +++ b/TestAssembly/Class1.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 // ReSharper disable UnusedVariable @@ -25,4 +25,4 @@ public string AccessClass2(int intparam) return ""; } } -} \ No newline at end of file +} diff --git a/TestAssembly/Class2.cs b/TestAssembly/Class2.cs index 63d7220d2..8c77227ab 100644 --- a/TestAssembly/Class2.cs +++ b/TestAssembly/Class2.cs @@ -1,15 +1,13 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 namespace TestAssembly { public class Class2 { - public void Class2Method() - { - } + public void Class2Method() { } } } diff --git a/TestAssembly/Class3.cs b/TestAssembly/Class3.cs index 711a265f1..9c4504584 100644 --- a/TestAssembly/Class3.cs +++ b/TestAssembly/Class3.cs @@ -1,16 +1,14 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// namespace TestAssembly { public class Class3 { - public static void Class3StaticMethod() - { - } + public static void Class3StaticMethod() { } } } diff --git a/TestAssembly/ClassUsingNullableReferenceType.cs b/TestAssembly/ClassUsingNullableReferenceType.cs index 5b160162f..b4c890930 100644 --- a/TestAssembly/ClassUsingNullableReferenceType.cs +++ b/TestAssembly/ClassUsingNullableReferenceType.cs @@ -8,4 +8,4 @@ public class ClassUsingNullableReferenceType } } -#nullable disable \ No newline at end of file +#nullable disable diff --git a/TestAssembly/DependencyTargets/AttributeInTestAssembly.cs b/TestAssembly/DependencyTargets/AttributeInTestAssembly.cs index 8aa6bcf5c..886dada8e 100644 --- a/TestAssembly/DependencyTargets/AttributeInTestAssembly.cs +++ b/TestAssembly/DependencyTargets/AttributeInTestAssembly.cs @@ -1,15 +1,13 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using System; namespace TestAssembly.DependencyTargets { - public class AttributeInTestAssembly : Attribute - { - } -} \ No newline at end of file + public class AttributeInTestAssembly : Attribute { } +} diff --git a/TestAssembly/DependencyTargets/ClassInTestAssembly.cs b/TestAssembly/DependencyTargets/ClassInTestAssembly.cs index 2b80e8d01..0f253c64b 100644 --- a/TestAssembly/DependencyTargets/ClassInTestAssembly.cs +++ b/TestAssembly/DependencyTargets/ClassInTestAssembly.cs @@ -1,14 +1,14 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// namespace TestAssembly.DependencyTargets { public class ClassInTestAssembly { - public void MethodInTestAssembly(){} + public void MethodInTestAssembly() { } } -} \ No newline at end of file +} diff --git a/TestAssembly/DependencyTargets/IInterfaceInTestAssembly.cs b/TestAssembly/DependencyTargets/IInterfaceInTestAssembly.cs index 6ee3c12e2..38071ed9d 100644 --- a/TestAssembly/DependencyTargets/IInterfaceInTestAssembly.cs +++ b/TestAssembly/DependencyTargets/IInterfaceInTestAssembly.cs @@ -1,13 +1,11 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// namespace TestAssembly.DependencyTargets { - public interface IInterfaceInTestAssembly - { - } -} \ No newline at end of file + public interface IInterfaceInTestAssembly { } +} diff --git a/TestAssembly/Diagram/ConfusingNamespaceNames/FooNamespace/BarNamespace/ClassInFooAndBarNamespace.cs b/TestAssembly/Diagram/ConfusingNamespaceNames/FooNamespace/BarNamespace/ClassInFooAndBarNamespace.cs index 34d1897d5..a4905cd0a 100644 --- a/TestAssembly/Diagram/ConfusingNamespaceNames/FooNamespace/BarNamespace/ClassInFooAndBarNamespace.cs +++ b/TestAssembly/Diagram/ConfusingNamespaceNames/FooNamespace/BarNamespace/ClassInFooAndBarNamespace.cs @@ -4,7 +4,5 @@ namespace TestAssembly.Diagram.ConfusingNamespaceNames.FooNamespace.BarNamespace { - public class ClassInFooAndBarNamespace - { - } + public class ClassInFooAndBarNamespace { } } diff --git a/TestAssembly/Diagram/NoDependencies/Independent/AnotherIndependenClass.cs b/TestAssembly/Diagram/NoDependencies/Independent/AnotherIndependenClass.cs index 7305cf078..f49f8e1b2 100644 --- a/TestAssembly/Diagram/NoDependencies/Independent/AnotherIndependenClass.cs +++ b/TestAssembly/Diagram/NoDependencies/Independent/AnotherIndependenClass.cs @@ -4,7 +4,5 @@ namespace TestAssembly.Diagram.NoDependencies.Independent { - class AnotherIndependenClass - { - } + class AnotherIndependenClass { } } diff --git a/TestAssembly/Diagram/NoDependencies/Independent/IndependentClass.cs b/TestAssembly/Diagram/NoDependencies/Independent/IndependentClass.cs index 9b9955189..ccd51cf08 100644 --- a/TestAssembly/Diagram/NoDependencies/Independent/IndependentClass.cs +++ b/TestAssembly/Diagram/NoDependencies/Independent/IndependentClass.cs @@ -4,7 +4,5 @@ namespace TestAssembly.Diagram.NoDependencies.Independent { - public class IndependentClass - { - } + public class IndependentClass { } } diff --git a/TestAssembly/Diagram/NoDependencies/SomeNamespace/DependencyWithinNamespace.cs b/TestAssembly/Diagram/NoDependencies/SomeNamespace/DependencyWithinNamespace.cs index 0d7678558..f14565361 100644 --- a/TestAssembly/Diagram/NoDependencies/SomeNamespace/DependencyWithinNamespace.cs +++ b/TestAssembly/Diagram/NoDependencies/SomeNamespace/DependencyWithinNamespace.cs @@ -4,7 +4,5 @@ namespace TestAssembly.Diagram.NoDependencies.SomeNamespace { - public class DependencyWithinNamespace - { - } + public class DependencyWithinNamespace { } } diff --git a/TestAssembly/Diagram/NoDependencies/SomeNamespace/IndependentOrigin.cs b/TestAssembly/Diagram/NoDependencies/SomeNamespace/IndependentOrigin.cs index 853438da4..9175514f0 100644 --- a/TestAssembly/Diagram/NoDependencies/SomeNamespace/IndependentOrigin.cs +++ b/TestAssembly/Diagram/NoDependencies/SomeNamespace/IndependentOrigin.cs @@ -6,8 +6,8 @@ namespace TestAssembly.Diagram.NoDependencies.SomeNamespace { public class IndependentOrigin { - #pragma warning disable CS0169 +#pragma warning disable CS0169 private readonly DependencyWithinNamespace _legalField; - #pragma warning restore CS0169 +#pragma warning restore CS0169 } } diff --git a/TestAssembly/Diagram/SimpleDependency/Target/SomeTargetClass.cs b/TestAssembly/Diagram/SimpleDependency/Target/SomeTargetClass.cs index febb8f748..211ab514c 100644 --- a/TestAssembly/Diagram/SimpleDependency/Target/SomeTargetClass.cs +++ b/TestAssembly/Diagram/SimpleDependency/Target/SomeTargetClass.cs @@ -4,7 +4,5 @@ namespace TestAssembly.Diagram.SimpleDependency.Target { - class SomeTargetClass - { - } + class SomeTargetClass { } } diff --git a/TestAssembly/Domain/Entities/Entity1.cs b/TestAssembly/Domain/Entities/Entity1.cs index 914d8e04d..547383aa2 100644 --- a/TestAssembly/Domain/Entities/Entity1.cs +++ b/TestAssembly/Domain/Entities/Entity1.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using TestAssembly.Domain.Marker; @@ -16,4 +16,4 @@ public class Entity1 : IEntity { public string TestProperty { get; private set; } } -} \ No newline at end of file +} diff --git a/TestAssembly/Domain/Entities/Entity2WithDependencyToEntity1.cs b/TestAssembly/Domain/Entities/Entity2WithDependencyToEntity1.cs index 3cec55053..8cb292672 100644 --- a/TestAssembly/Domain/Entities/Entity2WithDependencyToEntity1.cs +++ b/TestAssembly/Domain/Entities/Entity2WithDependencyToEntity1.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using System.Collections.Generic; @@ -16,4 +16,4 @@ public class Entity2WithDependencyToEntity1 : IEntity public Entity1 HasEntity1; public List ManyEntity1; } -} \ No newline at end of file +} diff --git a/TestAssembly/Domain/Entities/EntityWithPublicSetters.cs b/TestAssembly/Domain/Entities/EntityWithPublicSetters.cs index 34860779a..97edad7dd 100644 --- a/TestAssembly/Domain/Entities/EntityWithPublicSetters.cs +++ b/TestAssembly/Domain/Entities/EntityWithPublicSetters.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using TestAssembly.Domain.Marker; @@ -14,4 +14,4 @@ public class EntityWithPublicSetters : IEntity { public string TestProperty { get; set; } } -} \ No newline at end of file +} diff --git a/TestAssembly/Domain/Marker/IEntity.cs b/TestAssembly/Domain/Marker/IEntity.cs index 78f4ce6ee..ab85d71e4 100644 --- a/TestAssembly/Domain/Marker/IEntity.cs +++ b/TestAssembly/Domain/Marker/IEntity.cs @@ -1,12 +1,10 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 namespace TestAssembly.Domain.Marker { - public interface IEntity - { - } -} \ No newline at end of file + public interface IEntity { } +} diff --git a/TestAssembly/Domain/Marker/IRepository.cs b/TestAssembly/Domain/Marker/IRepository.cs index 6c30f8cbf..c9cf847ba 100644 --- a/TestAssembly/Domain/Marker/IRepository.cs +++ b/TestAssembly/Domain/Marker/IRepository.cs @@ -1,12 +1,10 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 namespace TestAssembly.Domain.Marker { - public interface IRepository - { - } -} \ No newline at end of file + public interface IRepository { } +} diff --git a/TestAssembly/Domain/Marker/IService.cs b/TestAssembly/Domain/Marker/IService.cs index 1db6c7ea7..f1a18a210 100644 --- a/TestAssembly/Domain/Marker/IService.cs +++ b/TestAssembly/Domain/Marker/IService.cs @@ -1,12 +1,10 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 namespace TestAssembly.Domain.Marker { - public interface IService - { - } -} \ No newline at end of file + public interface IService { } +} diff --git a/TestAssembly/Domain/Repository/RepositoryWithDependencyToService.cs b/TestAssembly/Domain/Repository/RepositoryWithDependencyToService.cs index acef3064f..0b3c9f2a6 100644 --- a/TestAssembly/Domain/Repository/RepositoryWithDependencyToService.cs +++ b/TestAssembly/Domain/Repository/RepositoryWithDependencyToService.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using TestAssembly.Domain.Marker; @@ -16,4 +16,4 @@ public class RepositoryWithDependencyToService : IRepository { private TestService _badDependency; } -} \ No newline at end of file +} diff --git a/TestAssembly/Domain/Services/NotWellNamedService1.cs b/TestAssembly/Domain/Services/NotWellNamedService1.cs index 428a057d7..4421eaf40 100644 --- a/TestAssembly/Domain/Services/NotWellNamedService1.cs +++ b/TestAssembly/Domain/Services/NotWellNamedService1.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using TestAssembly.Domain.Marker; @@ -10,7 +10,5 @@ namespace TestAssembly.Domain.Services { - public class NotWellNamedService1 : IService - { - } -} \ No newline at end of file + public class NotWellNamedService1 : IService { } +} diff --git a/TestAssembly/Domain/Services/ServiceClassInWrongNamespace.cs b/TestAssembly/Domain/Services/ServiceClassInWrongNamespace.cs index 60410d984..4acfa83f9 100644 --- a/TestAssembly/Domain/Services/ServiceClassInWrongNamespace.cs +++ b/TestAssembly/Domain/Services/ServiceClassInWrongNamespace.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using TestAssembly.Domain.Marker; @@ -11,7 +11,5 @@ // ReSharper disable once CheckNamespace namespace TestAssembly.Domain.Services { - public class ServiceClassInWrongNamespaceService : IService - { - } -} \ No newline at end of file + public class ServiceClassInWrongNamespaceService : IService { } +} diff --git a/TestAssembly/Domain/Services/TestService.cs b/TestAssembly/Domain/Services/TestService.cs index 7c468a4ef..71e274f70 100644 --- a/TestAssembly/Domain/Services/TestService.cs +++ b/TestAssembly/Domain/Services/TestService.cs @@ -1,7 +1,7 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 using TestAssembly.Domain.Marker; @@ -10,7 +10,5 @@ namespace TestAssembly.Domain.Services { - public class TestService : IService - { - } -} \ No newline at end of file + public class TestService : IService { } +} diff --git a/TestAssembly/EmptyTestClass.cs b/TestAssembly/EmptyTestClass.cs index 2166cfdff..987d0f05a 100644 --- a/TestAssembly/EmptyTestClass.cs +++ b/TestAssembly/EmptyTestClass.cs @@ -1,14 +1,11 @@ // Copyright 2019 Florian Gather // Copyright 2019 Fritz Brandhuber // Copyright 2020 Pavel Fischer -// +// // SPDX-License-Identifier: Apache-2.0 -// +// namespace TestAssembly { - public class EmptyTestClass - { - - } -} \ No newline at end of file + public class EmptyTestClass { } +} diff --git a/TestAssembly/PlantUml/Addresses/Address.cs b/TestAssembly/PlantUml/Addresses/Address.cs index 4db7a327b..94c4b50ba 100644 --- a/TestAssembly/PlantUml/Addresses/Address.cs +++ b/TestAssembly/PlantUml/Addresses/Address.cs @@ -8,4 +8,4 @@ public class Address private ProductCatalog productCatalog; #pragma warning restore CS0169 } -} \ No newline at end of file +} diff --git a/TestAssembly/PlantUml/Catalog/ProductCatalog.cs b/TestAssembly/PlantUml/Catalog/ProductCatalog.cs index 56642c9de..a01234a49 100644 --- a/TestAssembly/PlantUml/Catalog/ProductCatalog.cs +++ b/TestAssembly/PlantUml/Catalog/ProductCatalog.cs @@ -19,4 +19,4 @@ internal void GonnaDoSomethingIllegalWithOrder() order.AddProducts(_allProducts); } } -} \ No newline at end of file +} diff --git a/TestAssembly/PlantUml/Customers/Customer.cs b/TestAssembly/PlantUml/Customers/Customer.cs index efd00e015..1cf2d14e8 100644 --- a/TestAssembly/PlantUml/Customers/Customer.cs +++ b/TestAssembly/PlantUml/Customers/Customer.cs @@ -12,4 +12,4 @@ internal void AddOrder(Order order) // simply having such a parameter violates the specified UML diagram } } -} \ No newline at end of file +} diff --git a/TestAssembly/PlantUml/Importer/ProductImport.cs b/TestAssembly/PlantUml/Importer/ProductImport.cs index 16f19d413..69c916ce0 100644 --- a/TestAssembly/PlantUml/Importer/ProductImport.cs +++ b/TestAssembly/PlantUml/Importer/ProductImport.cs @@ -18,4 +18,4 @@ private ProductCatalog Parse(byte[] xml) return new ProductCatalog(); } } -} \ No newline at end of file +} diff --git a/TestAssembly/PlantUml/Orders/Order.cs b/TestAssembly/PlantUml/Orders/Order.cs index f13a0bf16..410ea4329 100644 --- a/TestAssembly/PlantUml/Orders/Order.cs +++ b/TestAssembly/PlantUml/Orders/Order.cs @@ -24,8 +24,6 @@ internal void Report() } } - private void Report(Address address) - { - } + private void Report(Address address) { } } -} \ No newline at end of file +} diff --git a/TestAssembly/PlantUml/Products/Product.cs b/TestAssembly/PlantUml/Products/Product.cs index 1a8074e1a..701d63822 100644 --- a/TestAssembly/PlantUml/Products/Product.cs +++ b/TestAssembly/PlantUml/Products/Product.cs @@ -9,13 +9,8 @@ public class Product internal Order Order => null; // the return type violates the specified UML diagram + public void Register() { } - public void Register() - { - } - - public void Report() - { - } + public void Report() { } } -} \ No newline at end of file +} diff --git a/TestAssembly/PlantUml/Xml/Processor/XmlProcessor.cs b/TestAssembly/PlantUml/Xml/Processor/XmlProcessor.cs index d3a3648dc..7e060a534 100644 --- a/TestAssembly/PlantUml/Xml/Processor/XmlProcessor.cs +++ b/TestAssembly/PlantUml/Xml/Processor/XmlProcessor.cs @@ -1,6 +1,4 @@ namespace TestAssembly.PlantUml.Xml.Processor { - public class XmlProcessor - { - } -} \ No newline at end of file + public class XmlProcessor { } +} diff --git a/TestAssembly/PlantUml/Xml/Types/XmlTypes.cs b/TestAssembly/PlantUml/Xml/Types/XmlTypes.cs index 8575a8ce5..96678ae8d 100644 --- a/TestAssembly/PlantUml/Xml/Types/XmlTypes.cs +++ b/TestAssembly/PlantUml/Xml/Types/XmlTypes.cs @@ -1,6 +1,4 @@ namespace TestAssembly.PlantUml.Xml.Types { - public class XmlTypes - { - } -} \ No newline at end of file + public class XmlTypes { } +} diff --git a/TestAssembly/PlantUml/Xml/Utils/XmlUtils.cs b/TestAssembly/PlantUml/Xml/Utils/XmlUtils.cs index 6ce6f4988..9bffe3586 100644 --- a/TestAssembly/PlantUml/Xml/Utils/XmlUtils.cs +++ b/TestAssembly/PlantUml/Xml/Utils/XmlUtils.cs @@ -1,6 +1,4 @@ namespace TestAssembly.PlantUml.Xml.Utils { - public class XmlUtils - { - } -} \ No newline at end of file + public class XmlUtils { } +} diff --git a/TestAssembly/Record1.cs b/TestAssembly/Record1.cs index 1f558889f..ef216ce18 100644 --- a/TestAssembly/Record1.cs +++ b/TestAssembly/Record1.cs @@ -1,4 +1,5 @@ namespace TestAssembly { - public record Record1(string TestProperty1, string TestProperty2) : AbstractRecord(TestProperty1, TestProperty2); -} \ No newline at end of file + public record Record1(string TestProperty1, string TestProperty2) + : AbstractRecord(TestProperty1, TestProperty2); +} diff --git a/TestAssembly/Slices/Slice1/Service/Service1Class.cs b/TestAssembly/Slices/Slice1/Service/Service1Class.cs index 0260eb479..5f3a5c6af 100644 --- a/TestAssembly/Slices/Slice1/Service/Service1Class.cs +++ b/TestAssembly/Slices/Slice1/Service/Service1Class.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using TestAssembly.Slices.Slice2.Service; @@ -13,4 +13,4 @@ public class Service1Class { public Service2Class Reference; } -} \ No newline at end of file +} diff --git a/TestAssembly/Slices/Slice1/Slice1Class.cs b/TestAssembly/Slices/Slice1/Slice1Class.cs index 042ee6106..09c55b052 100644 --- a/TestAssembly/Slices/Slice1/Slice1Class.cs +++ b/TestAssembly/Slices/Slice1/Slice1Class.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using TestAssembly.Slices.Slice2; @@ -13,4 +13,4 @@ public class Slice1Class { public Slice2Class Reference; } -} \ No newline at end of file +} diff --git a/TestAssembly/Slices/Slice2/Service/Service2Class.cs b/TestAssembly/Slices/Slice2/Service/Service2Class.cs index 89a439f4b..ec21e9636 100644 --- a/TestAssembly/Slices/Slice2/Service/Service2Class.cs +++ b/TestAssembly/Slices/Slice2/Service/Service2Class.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using TestAssembly.Slices.Slice3; @@ -13,4 +13,4 @@ public class Service2Class { public Slice3Class Reference; } -} \ No newline at end of file +} diff --git a/TestAssembly/Slices/Slice2/Slice2Class.cs b/TestAssembly/Slices/Slice2/Slice2Class.cs index 370678454..b7bd76ee5 100644 --- a/TestAssembly/Slices/Slice2/Slice2Class.cs +++ b/TestAssembly/Slices/Slice2/Slice2Class.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using TestAssembly.Slices.Slice3; @@ -13,4 +13,4 @@ public class Slice2Class { public Slice3Class Reference; } -} \ No newline at end of file +} diff --git a/TestAssembly/Slices/Slice3/Group1/Group1Class.cs b/TestAssembly/Slices/Slice3/Group1/Group1Class.cs index b0105811c..58dc1363b 100644 --- a/TestAssembly/Slices/Slice3/Group1/Group1Class.cs +++ b/TestAssembly/Slices/Slice3/Group1/Group1Class.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 -// +// namespace TestAssembly.Slices.Slice3.Group1 { @@ -11,4 +11,4 @@ public class Group1Class { public Slice3Class Dependency; } -} \ No newline at end of file +} diff --git a/TestAssembly/Slices/Slice3/Group2/Group2Class.cs b/TestAssembly/Slices/Slice3/Group2/Group2Class.cs index 9fcdc3208..680444b73 100644 --- a/TestAssembly/Slices/Slice3/Group2/Group2Class.cs +++ b/TestAssembly/Slices/Slice3/Group2/Group2Class.cs @@ -1,13 +1,11 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 -// +// namespace TestAssembly.Slices.Slice3.Group2 { - public class Group2Class - { - } -} \ No newline at end of file + public class Group2Class { } +} diff --git a/TestAssembly/Slices/Slice3/Slice3Class.cs b/TestAssembly/Slices/Slice3/Slice3Class.cs index 340e8ad74..2c3ce17b6 100644 --- a/TestAssembly/Slices/Slice3/Slice3Class.cs +++ b/TestAssembly/Slices/Slice3/Slice3Class.cs @@ -1,9 +1,9 @@ // Copyright 2019 Florian Gather // Copyright 2019 Paula Ruiz // Copyright 2019 Fritz Brandhuber -// +// // SPDX-License-Identifier: Apache-2.0 -// +// using TestAssembly.Slices.Slice1; @@ -13,4 +13,4 @@ public class Slice3Class { public Slice1Class Reference; } -} \ No newline at end of file +}