diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/AddMemberCondition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/AddMemberCondition.cs index 65e9e358..caf1c420 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/AddMemberCondition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/AddMemberCondition.cs @@ -14,11 +14,12 @@ internal AddMemberCondition(IArchRuleCreator ruleCreator) : base(ruleCreator) { } // csharpier-ignore-start - public TNextElement BeDeclaredIn(IType firstType, params IType[] moreTypes) => CreateNextElement(MemberConditionsDefinition.BeDeclaredIn(firstType, moreTypes)); - public TNextElement BeDeclaredIn(Type firstType, params Type[] moreTypes) => CreateNextElement(MemberConditionsDefinition.BeDeclaredIn(firstType, moreTypes)); + public TNextElement BeDeclaredIn() => BeDeclaredIn(new ObjectProvider()); + public TNextElement BeDeclaredIn(params IType[] types) => BeDeclaredIn(new ObjectProvider(types)); + public TNextElement BeDeclaredIn(params Type[] types) => BeDeclaredIn(new SystemTypeObjectProvider(types)); public TNextElement BeDeclaredIn(IObjectProvider types) => CreateNextElement(MemberConditionsDefinition.BeDeclaredIn(types)); - public TNextElement BeDeclaredIn(IEnumerable types) => CreateNextElement(MemberConditionsDefinition.BeDeclaredIn(types)); - public TNextElement BeDeclaredIn(IEnumerable types) => CreateNextElement(MemberConditionsDefinition.BeDeclaredIn(types)); + public TNextElement BeDeclaredIn(IEnumerable types) => BeDeclaredIn(new ObjectProvider(types)); + public TNextElement BeDeclaredIn(IEnumerable types) => BeDeclaredIn(new SystemTypeObjectProvider(types)); public TNextElement BeStatic() => CreateNextElement(MemberConditionsDefinition.BeStatic()); public TNextElement BeReadOnly() => CreateNextElement(MemberConditionsDefinition.BeReadOnly()); @@ -30,11 +31,12 @@ internal AddMemberCondition(IArchRuleCreator ruleCreator) //Negations - public TNextElement NotBeDeclaredIn(IType firstType, params IType[] moreTypes) => CreateNextElement(MemberConditionsDefinition.NotBeDeclaredIn(firstType, moreTypes)); - public TNextElement NotBeDeclaredIn(Type firstType, params Type[] moreTypes) => CreateNextElement(MemberConditionsDefinition.NotBeDeclaredIn(firstType, moreTypes)); + public TNextElement NotBeDeclaredIn() => NotBeDeclaredIn(new ObjectProvider()); + public TNextElement NotBeDeclaredIn(params IType[] types) => NotBeDeclaredIn(new ObjectProvider(types)); + public TNextElement NotBeDeclaredIn(params Type[] types) => NotBeDeclaredIn(new SystemTypeObjectProvider(types)); public TNextElement NotBeDeclaredIn(IObjectProvider types) => CreateNextElement(MemberConditionsDefinition.NotBeDeclaredIn(types)); - public TNextElement NotBeDeclaredIn(IEnumerable types) => CreateNextElement(MemberConditionsDefinition.NotBeDeclaredIn(types)); - public TNextElement NotBeDeclaredIn(IEnumerable types) => CreateNextElement(MemberConditionsDefinition.NotBeDeclaredIn(types)); + public TNextElement NotBeDeclaredIn(IEnumerable types) => NotBeDeclaredIn(new ObjectProvider(types)); + public TNextElement NotBeDeclaredIn(IEnumerable types) => NotBeDeclaredIn(new SystemTypeObjectProvider(types)); public TNextElement NotBeStatic() => CreateNextElement(MemberConditionsDefinition.NotBeStatic()); public TNextElement NotBeReadOnly() => CreateNextElement(MemberConditionsDefinition.NotBeReadOnly()); diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/AddMemberPredicate.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/AddMemberPredicate.cs index 0e7fe295..28ea7255 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/AddMemberPredicate.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/AddMemberPredicate.cs @@ -14,11 +14,12 @@ internal AddMemberPredicate(IArchRuleCreator ruleCreator) : base(ruleCreator) { } // csharpier-ignore-start - public TNextElement AreDeclaredIn(IType firstType, params IType[] moreTypes) => CreateNextElement(MemberPredicatesDefinition.AreDeclaredIn(firstType, moreTypes)); - public TNextElement AreDeclaredIn(Type firstType, params Type[] moreTypes) => CreateNextElement(MemberPredicatesDefinition.AreDeclaredIn(firstType, moreTypes)); + public TNextElement AreDeclaredIn() => AreDeclaredIn(new ObjectProvider()); + public TNextElement AreDeclaredIn(params IType[] types) => AreDeclaredIn(new ObjectProvider(types)); + public TNextElement AreDeclaredIn(params Type[] types) => AreDeclaredIn(new SystemTypeObjectProvider(types)); public TNextElement AreDeclaredIn(IObjectProvider types) => CreateNextElement(MemberPredicatesDefinition.AreDeclaredIn(types)); - public TNextElement AreDeclaredIn(IEnumerable types) => CreateNextElement(MemberPredicatesDefinition.AreDeclaredIn(types)); - public TNextElement AreDeclaredIn(IEnumerable types) => CreateNextElement(MemberPredicatesDefinition.AreDeclaredIn(types)); + public TNextElement AreDeclaredIn(IEnumerable types) => AreDeclaredIn(new ObjectProvider(types)); + public TNextElement AreDeclaredIn(IEnumerable types) => AreDeclaredIn(new SystemTypeObjectProvider(types)); public TNextElement AreStatic() => CreateNextElement(MemberPredicatesDefinition.AreStatic()); public TNextElement AreReadOnly() => CreateNextElement(MemberPredicatesDefinition.AreReadOnly()); @@ -26,11 +27,12 @@ internal AddMemberPredicate(IArchRuleCreator ruleCreator) //Negations - public TNextElement AreNotDeclaredIn(IType firstType, params IType[] moreTypes) => CreateNextElement(MemberPredicatesDefinition.AreNotDeclaredIn(firstType, moreTypes)); - public TNextElement AreNotDeclaredIn(Type firstType, params Type[] moreTypes) => CreateNextElement(MemberPredicatesDefinition.AreNotDeclaredIn(firstType, moreTypes)); + public TNextElement AreNotDeclaredIn() => AreNotDeclaredIn(new ObjectProvider()); + public TNextElement AreNotDeclaredIn(params IType[] types) => AreNotDeclaredIn(new ObjectProvider(types)); + public TNextElement AreNotDeclaredIn(params Type[] types) => AreNotDeclaredIn(new SystemTypeObjectProvider(types)); public TNextElement AreNotDeclaredIn(IObjectProvider types) => CreateNextElement(MemberPredicatesDefinition.AreNotDeclaredIn(types)); - public TNextElement AreNotDeclaredIn(IEnumerable types) => CreateNextElement(MemberPredicatesDefinition.AreNotDeclaredIn(types)); - public TNextElement AreNotDeclaredIn(IEnumerable types) => CreateNextElement(MemberPredicatesDefinition.AreNotDeclaredIn(types)); + public TNextElement AreNotDeclaredIn(IEnumerable types) => AreNotDeclaredIn(new ObjectProvider(types)); + public TNextElement AreNotDeclaredIn(IEnumerable types) => AreNotDeclaredIn(new SystemTypeObjectProvider(types)); public TNextElement AreNotStatic() => CreateNextElement(MemberPredicatesDefinition.AreNotStatic()); public TNextElement AreNotReadOnly() => CreateNextElement(MemberPredicatesDefinition.AreNotReadOnly()); diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/IAddMemberCondition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/IAddMemberCondition.cs index bb8d18fd..ea304bdb 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/IAddMemberCondition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/IAddMemberCondition.cs @@ -9,8 +9,9 @@ public interface IAddMemberCondition : IAddObjectCondition where TRuleType : ICanBeAnalyzed { - TNextElement BeDeclaredIn(IType firstType, params IType[] moreTypes); - TNextElement BeDeclaredIn(Type firstType, params Type[] moreTypes); + TNextElement BeDeclaredIn(); + TNextElement BeDeclaredIn(params IType[] types); + TNextElement BeDeclaredIn(params Type[] types); TNextElement BeDeclaredIn(IObjectProvider types); TNextElement BeDeclaredIn(IEnumerable types); TNextElement BeDeclaredIn(IEnumerable types); @@ -20,8 +21,9 @@ public interface IAddMemberCondition TNextElement BeImmutable(); //Negations - TNextElement NotBeDeclaredIn(IType firstType, params IType[] moreTypes); - TNextElement NotBeDeclaredIn(Type firstType, params Type[] moreTypes); + TNextElement NotBeDeclaredIn(); + TNextElement NotBeDeclaredIn(params IType[] types); + TNextElement NotBeDeclaredIn(params Type[] types); TNextElement NotBeDeclaredIn(IObjectProvider types); TNextElement NotBeDeclaredIn(IEnumerable types); TNextElement NotBeDeclaredIn(IEnumerable types); diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/IAddMemberPredicate.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/IAddMemberPredicate.cs index b7a9f4ef..50a6d76d 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/IAddMemberPredicate.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/IAddMemberPredicate.cs @@ -8,8 +8,10 @@ public interface IAddMemberPredicate : IAddObjectPredicate where TRuleType : ICanBeAnalyzed { - TNextElement AreDeclaredIn(IType firstType, params IType[] moreTypes); - TNextElement AreDeclaredIn(Type firstType, params Type[] moreTypes); + // csharpier-ignore-start + TNextElement AreDeclaredIn(); + TNextElement AreDeclaredIn(params IType[] types); + TNextElement AreDeclaredIn(params Type[] types); TNextElement AreDeclaredIn(IObjectProvider types); TNextElement AreDeclaredIn(IEnumerable types); TNextElement AreDeclaredIn(IEnumerable types); @@ -18,12 +20,14 @@ public interface IAddMemberPredicate //Negations - TNextElement AreNotDeclaredIn(IType firstType, params IType[] moreTypes); - TNextElement AreNotDeclaredIn(Type firstType, params Type[] moreTypes); + TNextElement AreNotDeclaredIn(); + TNextElement AreNotDeclaredIn(params IType[] types); + TNextElement AreNotDeclaredIn(params Type[] types); TNextElement AreNotDeclaredIn(IObjectProvider types); TNextElement AreNotDeclaredIn(IEnumerable types); TNextElement AreNotDeclaredIn(IEnumerable types); TNextElement AreNotStatic(); TNextElement AreNotImmutable(); + // csharpier-ignore-end } } diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberConditionsDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberConditionsDefinition.cs index 5e6037aa..c1a89a88 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberConditionsDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberConditionsDefinition.cs @@ -1,171 +1,49 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using ArchUnitNET.Domain; -using ArchUnitNET.Domain.Exceptions; using ArchUnitNET.Domain.Extensions; using ArchUnitNET.Fluent.Conditions; +using static ArchUnitNET.Domain.Extensions.EnumerableExtensions; namespace ArchUnitNET.Fluent.Syntax.Elements.Members { public static class MemberConditionsDefinition where TRuleType : IMember { - public static IOrderedCondition BeDeclaredIn( - IType firstType, - params IType[] moreTypes - ) - { - var types = new List { firstType }; - types.AddRange(moreTypes); - return BeDeclaredIn(types); - } - - public static IOrderedCondition BeDeclaredIn( - Type firstType, - params Type[] moreTypes - ) - { - var types = new List { firstType }; - types.AddRange(moreTypes); - return BeDeclaredIn(types); - } - public static IOrderedCondition BeDeclaredIn( IObjectProvider objectProvider ) { IEnumerable Condition( - IEnumerable methods, + IEnumerable members, Architecture architecture ) { var typeList = objectProvider.GetObjects(architecture).ToList(); - var methodList = methods.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; - yield return new ConditionResult(failedObject, false, failDescription); - } - - foreach (var passedObject in passedObjects) - { - yield return new ConditionResult(passedObject, true); - } - } - - var description = "be declared in " + objectProvider.Description; - return new ArchitectureCondition( - Condition, - description - ).AsOrderedCondition(); - } - - public static IOrderedCondition BeDeclaredIn(IEnumerable types) - { - var typeList = types.ToList(); - - IEnumerable Condition(IEnumerable methods) - { - var methodList = methods.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; - yield return new ConditionResult(failedObject, false, failDescription); - } - - foreach (var passedObject in passedObjects) - { - yield return new ConditionResult(passedObject, true); - } - } - - string description; - if (typeList.IsNullOrEmpty()) - { - description = "be declared in no type (always false)"; - } - 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 + "\"" - ); - } - - return new EnumerableCondition(Condition, description).AsOrderedCondition(); - } - - public static IOrderedCondition BeDeclaredIn(IEnumerable types) - { - var typeList = types.ToList(); - - IEnumerable Condition( - IEnumerable methods, - Architecture architecture - ) - { - var archUnitTypeList = new List(); - foreach (var type in typeList) + var isExpectedType = CreateLookupFn(typeList); + foreach (var member in members) { - try + if (isExpectedType(member.DeclaringType)) { - var archUnitType = architecture.GetITypeOfType(type); - archUnitTypeList.Add(archUnitType); + yield return new ConditionResult(member, true); } - catch (TypeDoesNotExistInArchitecture) + else { - //ignore, can't have a dependency anyways + yield return new ConditionResult( + member, + false, + "is declared in " + member.DeclaringType.FullName + ); } } - - var methodList = methods.ToList(); - var passedObjects = methodList - .Where(method => archUnitTypeList.Contains(method.DeclaringType)) - .ToList(); - foreach (var failedObject in methodList.Except(passedObjects)) - { - var failDescription = "is declared in " + failedObject.DeclaringType.FullName; - yield return new ConditionResult(failedObject, false, failDescription); - } - - foreach (var passedObject in passedObjects) - { - yield return new ConditionResult(passedObject, true); - } } - string description; - if (typeList.IsNullOrEmpty()) - { - description = "be declared in no type (always false)"; - } - else - { - var firstType = typeList.First(); - description = typeList - .Where(obj => obj != firstType) - .Distinct() - .Aggregate( - "be declared in \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\"" - ); - } - - return new ArchitectureCondition( - Condition, - description - ).AsOrderedCondition(); + var description = objectProvider.FormatDescription( + "be declared in no type (always false)", + "be declared in", + "be declared in" + ); + return new OrderedArchitectureCondition(Condition, description); } public static IOrderedCondition BeStatic() @@ -208,161 +86,40 @@ public static RelationCondition BeDeclaredInTypesThat() //Negations - public static IOrderedCondition NotBeDeclaredIn( - IType firstType, - params IType[] moreTypes - ) - { - var types = new List { firstType }; - types.AddRange(moreTypes); - return NotBeDeclaredIn(types); - } - - public static IOrderedCondition NotBeDeclaredIn( - Type firstType, - params Type[] moreTypes - ) - { - var types = new List { firstType }; - types.AddRange(moreTypes); - return NotBeDeclaredIn(types); - } - public static IOrderedCondition NotBeDeclaredIn( IObjectProvider objectProvider ) { IEnumerable Condition( - IEnumerable methods, + IEnumerable members, Architecture architecture ) { var typeList = objectProvider.GetObjects(architecture).ToList(); - var methodList = methods.ToList(); - var failedObjects = methodList - .Where(method => typeList.Contains(method.DeclaringType)) - .ToList(); - foreach (var failedObject in failedObjects) - { - var failDescription = "is declared in " + failedObject.DeclaringType.FullName; - yield return new ConditionResult(failedObject, false, failDescription); - } - - foreach (var passedObject in methodList.Except(failedObjects)) - { - yield return new ConditionResult(passedObject, true); - } - } - - var description = "not be declared in " + objectProvider.Description; - return new ArchitectureCondition( - Condition, - description - ).AsOrderedCondition(); - } - - public static IOrderedCondition NotBeDeclaredIn(IEnumerable types) - { - var typeList = types.ToList(); - - IEnumerable Condition(IEnumerable methods) - { - var methodList = methods.ToList(); - var failedObjects = methodList - .Where(method => typeList.Contains(method.DeclaringType)) - .ToList(); - foreach (var failedObject in failedObjects) - { - var failDescription = "is declared in " + failedObject.DeclaringType.FullName; - yield return new ConditionResult(failedObject, false, failDescription); - } - - foreach (var passedObject in methodList.Except(failedObjects)) - { - yield return new ConditionResult(passedObject, true); - } - } - - string description; - if (typeList.IsNullOrEmpty()) - { - description = "not be declared in no type (always true)"; - } - 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 + "\"" - ); - } - - return new EnumerableCondition(Condition, description).AsOrderedCondition(); - } - - public static IOrderedCondition NotBeDeclaredIn(IEnumerable types) - { - var typeList = types.ToList(); - - IEnumerable Condition( - IEnumerable methods, - Architecture architecture - ) - { - var archUnitTypeList = new List(); - foreach (var type in typeList) + var isForbiddenType = CreateLookupFn(typeList); + foreach (var member in members) { - try + if (!isForbiddenType(member.DeclaringType)) { - var archUnitType = architecture.GetITypeOfType(type); - archUnitTypeList.Add(archUnitType); + yield return new ConditionResult(member, true); } - catch (TypeDoesNotExistInArchitecture) + else { - //ignore, can't have a dependency anyways + yield return new ConditionResult( + member, + false, + "is declared in " + member.DeclaringType.FullName + ); } } - - var methodList = methods.ToList(); - var failedObjects = methodList - .Where(method => archUnitTypeList.Contains(method.DeclaringType)) - .ToList(); - foreach (var failedObject in failedObjects) - { - var failDescription = "is declared in " + failedObject.DeclaringType.FullName; - yield return new ConditionResult(failedObject, false, failDescription); - } - - foreach (var passedObject in methodList.Except(failedObjects)) - { - yield return new ConditionResult(passedObject, true); - } } - string description; - if (typeList.IsNullOrEmpty()) - { - description = "not be declared in no type (always true)"; - } - 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 + "\"" - ); - } - - return new ArchitectureCondition( - Condition, - description - ).AsOrderedCondition(); + var description = objectProvider.FormatDescription( + "not be declared in no type (always true)", + "not be declared in", + "not be declared in" + ); + return new OrderedArchitectureCondition(Condition, description); } public static IOrderedCondition NotBeStatic() diff --git a/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberPredicatesDefinition.cs b/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberPredicatesDefinition.cs index 92ad451b..e67d333f 100644 --- a/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberPredicatesDefinition.cs +++ b/ArchUnitNET/Fluent/Syntax/Elements/Members/MemberPredicatesDefinition.cs @@ -1,8 +1,6 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using ArchUnitNET.Domain; -using ArchUnitNET.Domain.Exceptions; using ArchUnitNET.Domain.Extensions; using ArchUnitNET.Fluent.Predicates; @@ -11,103 +9,20 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Members public static class MemberPredicatesDefinition where T : IMember { - public static IPredicate AreDeclaredIn(IType firstType, params IType[] moreTypes) - { - 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 }; - types.AddRange(moreTypes); - return AreDeclaredIn(types); - } - public static IPredicate AreDeclaredIn(IObjectProvider objectProvider) { - IEnumerable Condition(IEnumerable members, Architecture architecture) + IEnumerable Filter(IEnumerable members, Architecture architecture) { var types = objectProvider.GetObjects(architecture); return members.Intersect(types.SelectMany(type => type.Members).OfType()); } - var description = "are declared in " + objectProvider.Description; - return new ArchitecturePredicate(Condition, description); - } - - public static IPredicate AreDeclaredIn(IEnumerable types) - { - var typeList = types.ToList(); - - IEnumerable Condition(IEnumerable members) - { - return members.Intersect(typeList.SelectMany(type => type.Members).OfType()); - } - - string description; - if (typeList.IsNullOrEmpty()) - { - description = "are declared in no type (always false)"; - } - 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 + "\"" - ); - } - - return new EnumerablePredicate(Condition, description); - } - - public static IPredicate AreDeclaredIn(IEnumerable types) - { - var typeList = types.ToList(); - - IEnumerable Condition(IEnumerable members, Architecture architecture) - { - var archUnitTypeList = new List(); - foreach (var type in typeList) - { - try - { - var archUnitType = architecture.GetITypeOfType(type); - archUnitTypeList.Add(archUnitType); - } - catch (TypeDoesNotExistInArchitecture) - { - //ignore, can't have a dependency anyways - } - } - return members.Intersect( - archUnitTypeList.SelectMany(type => type.Members).OfType() - ); - } - - string description; - if (typeList.IsNullOrEmpty()) - { - description = "are declared in no type (always false)"; - } - else - { - var firstType = typeList.First(); - description = typeList - .Where(obj => obj != firstType) - .Distinct() - .Aggregate( - "are declared in \"" + firstType.FullName + "\"", - (current, type) => current + " or \"" + type.FullName + "\"" - ); - } - - return new ArchitecturePredicate(Condition, description); + var description = objectProvider.FormatDescription( + "are declared in no type (always false)", + "are declared in", + "are declared in" + ); + return new ArchitecturePredicate(Filter, description); } public static IPredicate AreStatic() @@ -136,103 +51,20 @@ public static IPredicate AreImmutable() //Negations - public static IPredicate AreNotDeclaredIn(IType firstType, params IType[] moreTypes) - { - 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 }; - types.AddRange(moreTypes); - return AreNotDeclaredIn(types); - } - public static IPredicate AreNotDeclaredIn(IObjectProvider objectProvider) { - IEnumerable Condition(IEnumerable members, Architecture architecture) + IEnumerable Filter(IEnumerable members, Architecture architecture) { var types = objectProvider.GetObjects(architecture); return members.Except(types.SelectMany(type => type.Members).OfType()); } - var description = "are not declared in " + objectProvider.Description; - return new ArchitecturePredicate(Condition, description); - } - - public static IPredicate AreNotDeclaredIn(IEnumerable types) - { - var typeList = types.ToList(); - - IEnumerable Condition(IEnumerable members) - { - return members.Except(typeList.SelectMany(type => type.Members).OfType()); - } - - string description; - if (typeList.IsNullOrEmpty()) - { - description = "are declared in any type (always true)"; - } - 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 + "\"" - ); - } - - return new EnumerablePredicate(Condition, description); - } - - public static IPredicate AreNotDeclaredIn(IEnumerable types) - { - var typeList = types.ToList(); - - IEnumerable Condition(IEnumerable members, Architecture architecture) - { - var archUnitTypeList = new List(); - foreach (var type in typeList) - { - try - { - var archUnitType = architecture.GetITypeOfType(type); - archUnitTypeList.Add(archUnitType); - } - catch (TypeDoesNotExistInArchitecture) - { - //ignore, can't have a dependency anyways - } - } - return members.Except( - archUnitTypeList.SelectMany(type => type.Members).OfType() - ); - } - - string description; - if (typeList.IsNullOrEmpty()) - { - description = "are declared in any type (always true9"; - } - 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 + "\"" - ); - } - - return new ArchitecturePredicate(Condition, description); + var description = objectProvider.FormatDescription( + "are declared in any type (always true)", + "are not declared in", + "are not declared in" + ); + return new ArchitecturePredicate(Filter, description); } public static IPredicate AreNotStatic() @@ -255,7 +87,7 @@ public static IPredicate AreNotImmutable() { return new SimplePredicate( member => !member.Writability.IsImmutable(), - "are not immutablee" + "are not immutable" ); } } diff --git a/ArchUnitNET/Loader/DomainResolver.cs b/ArchUnitNET/Loader/DomainResolver.cs index 287d747a..5872974d 100644 --- a/ArchUnitNET/Loader/DomainResolver.cs +++ b/ArchUnitNET/Loader/DomainResolver.cs @@ -536,6 +536,7 @@ out var existingGenericInstance var isCompilerGenerated = methodReference.IsCompilerGenerated(); MethodForm methodForm; Visibility visibility; + bool isVirtual; bool isStub; bool? isIterator; bool? isStatic; @@ -556,6 +557,7 @@ out var existingGenericInstance methodForm = methodReference.HasConstructorName() ? MethodForm.Constructor : MethodForm.Normal; + isVirtual = false; isIterator = null; isStatic = null; isStub = true; @@ -564,6 +566,7 @@ out var existingGenericInstance { visibility = methodDefinition.GetVisibility(); methodForm = methodDefinition.GetMethodForm(); + isVirtual = methodDefinition.IsVirtual; isIterator = methodDefinition.IsIterator(); isStatic = methodDefinition.IsStatic; isStub = false; @@ -574,7 +577,7 @@ out var existingGenericInstance fullName, typeInstance.Type, visibility, - false, + isVirtual, methodForm, isGeneric, isStub, diff --git a/ArchUnitNETTests/AssemblyTestHelper/TypeAssemblyTestHelper.cs b/ArchUnitNETTests/AssemblyTestHelper/TypeAssemblyTestHelper.cs index c4135e7e..5576ed06 100644 --- a/ArchUnitNETTests/AssemblyTestHelper/TypeAssemblyTestHelper.cs +++ b/ArchUnitNETTests/AssemblyTestHelper/TypeAssemblyTestHelper.cs @@ -111,6 +111,49 @@ public class TypeAssemblyTestHelper : AssemblyTestHelper public Class OtherUnrelatedClassForAssign; public Type OtherUnrelatedClassForAssignSystemType = typeof(OtherUnrelatedClassForAssign); + // Member test classes + public Class ClassWithStaticField; + public Type ClassWithStaticFieldSystemType = typeof(ClassWithStaticField); + + public Class ClassWithNonStaticField; + public Type ClassWithNonStaticFieldSystemType = typeof(ClassWithNonStaticField); + + public Class ClassWithReadOnlyField; + public Type ClassWithReadOnlyFieldSystemType = typeof(ClassWithReadOnlyField); + + public Class ClassWithWritableProperty; + public Type ClassWithWritablePropertySystemType = typeof(ClassWithWritableProperty); + + public Class OtherClassWithWritableProperty; + public Type OtherClassWithWritablePropertySystemType = typeof(OtherClassWithWritableProperty); + + public Class ClassWithInitOnlyProperty; + public Type ClassWithInitOnlyPropertySystemType = typeof(ClassWithInitOnlyProperty); + + public Class ClassWithGetOnlyProperty; + public Type ClassWithGetOnlyPropertySystemType = typeof(ClassWithGetOnlyProperty); + + public Class OtherClassWithStaticField; + public Type OtherClassWithStaticFieldSystemType = typeof(OtherClassWithStaticField); + + public Class ClassWithStaticProperty; + public Type ClassWithStaticPropertySystemType = typeof(ClassWithStaticProperty); + + public Class ClassWithStaticMethod; + public Type ClassWithStaticMethodSystemType = typeof(ClassWithStaticMethod); + + // Individual members + public IMember StaticField; + public IMember NonStaticField; + public IMember ReadOnlyField; + public IMember WritableProperty; + public IMember OtherWritableProperty; + public IMember InitOnlyProperty; + public IMember GetOnlyProperty; + public IMember OtherStaticField; + public IMember StaticProperty; + public IMember StaticMethod; + public TypeAssemblyTestHelper() { SimpleEnum = Architecture.GetITypeOfType(typeof(SimpleEnum)); @@ -160,5 +203,43 @@ public TypeAssemblyTestHelper() OtherUnrelatedClassForAssign = Architecture.GetClassOfType( typeof(OtherUnrelatedClassForAssign) ); + + // Member test classes + ClassWithStaticField = Architecture.GetClassOfType(typeof(ClassWithStaticField)); + ClassWithNonStaticField = Architecture.GetClassOfType(typeof(ClassWithNonStaticField)); + ClassWithReadOnlyField = Architecture.GetClassOfType(typeof(ClassWithReadOnlyField)); + ClassWithWritableProperty = Architecture.GetClassOfType(typeof(ClassWithWritableProperty)); + OtherClassWithWritableProperty = Architecture.GetClassOfType( + typeof(OtherClassWithWritableProperty) + ); + ClassWithInitOnlyProperty = Architecture.GetClassOfType(typeof(ClassWithInitOnlyProperty)); + ClassWithGetOnlyProperty = Architecture.GetClassOfType(typeof(ClassWithGetOnlyProperty)); + OtherClassWithStaticField = Architecture.GetClassOfType(typeof(OtherClassWithStaticField)); + ClassWithStaticProperty = Architecture.GetClassOfType(typeof(ClassWithStaticProperty)); + ClassWithStaticMethod = Architecture.GetClassOfType(typeof(ClassWithStaticMethod)); + + // Individual members + StaticField = ClassWithStaticField.GetFieldMembersWithName("StaticField").First(); + NonStaticField = ClassWithNonStaticField.GetFieldMembersWithName("NonStaticField").First(); + ReadOnlyField = ClassWithReadOnlyField.GetFieldMembersWithName("ReadOnlyField").First(); + WritableProperty = ClassWithWritableProperty + .GetPropertyMembersWithName("WritableProperty") + .First(); + OtherWritableProperty = OtherClassWithWritableProperty + .GetPropertyMembersWithName("OtherWritableProperty") + .First(); + InitOnlyProperty = ClassWithInitOnlyProperty + .GetPropertyMembersWithName("InitOnlyProperty") + .First(); + GetOnlyProperty = ClassWithGetOnlyProperty + .GetPropertyMembersWithName("GetOnlyProperty") + .First(); + OtherStaticField = OtherClassWithStaticField + .GetFieldMembersWithName("OtherStaticField") + .First(); + StaticProperty = ClassWithStaticProperty + .GetPropertyMembersWithName("StaticProperty") + .First(); + StaticMethod = ClassWithStaticMethod.GetMethodMembersWithName("StaticMethod()").First(); } } diff --git a/ArchUnitNETTests/Fluent/NoErrorReferencingOfTypesOutsideOfArchitectureTests.cs b/ArchUnitNETTests/Fluent/NoErrorReferencingOfTypesOutsideOfArchitectureTests.cs deleted file mode 100644 index bf40b049..00000000 --- a/ArchUnitNETTests/Fluent/NoErrorReferencingOfTypesOutsideOfArchitectureTests.cs +++ /dev/null @@ -1,101 +0,0 @@ -using System; -using System.Linq; -using ArchUnitNET.Domain; -using ArchUnitNET.Domain.Exceptions; -using ArchUnitNET.Domain.Extensions; -using ArchUnitNET.Loader; -using ArchUnitNET.xUnit; -using TestAssembly; -using Xunit; -using static ArchUnitNET.Fluent.ArchRuleDefinition; - -namespace ArchUnitNETTests.Fluent -{ - public class NoErrorReferencingOfTypesOutsideOfArchitectureTests - { - private static readonly Architecture Architecture = new ArchLoader() - .LoadAssemblies(System.Reflection.Assembly.Load("TestAssembly")) - .Build(); - - private readonly System.Type _classNotInArchitecture = - typeof(NoErrorReferencingOfTypesOutsideOfArchitectureTests); - - public NoErrorReferencingOfTypesOutsideOfArchitectureTests() - { - Assert.Throws(() => - Architecture.GetClassOfType(_classNotInArchitecture) - ); - } - - private static void AssertNoException(Action action) - { - var exception = Record.Exception(action); - Assert.Null(exception); - } - - [Fact] - public void ImplementInterfaceTest() - { - var rule = Classes() - .That() - .Are(typeof(EmptyTestClass)) - .Should() - .ImplementInterface(_classNotInArchitecture); - 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) - ); - } - - [Fact] - public void DeclaredInTest() - { - var rule = Members().Should().BeDeclaredIn(_classNotInArchitecture); - var negation = Members().Should().NotBeDeclaredIn(_classNotInArchitecture); - Assert.Throws(() => rule.Check(Architecture)); - negation.Check(Architecture); - - AssertNoException(() => - Members().That().AreDeclaredIn(_classNotInArchitecture).GetObjects(Architecture) - ); - AssertNoException(() => - Members().That().AreNotDeclaredIn(_classNotInArchitecture).GetObjects(Architecture) - ); - } - - [Fact] - public void CalledByTest() - { - var rule = MethodMembers().Should().BeCalledBy(_classNotInArchitecture); - var negation = MethodMembers().Should().NotBeCalledBy(_classNotInArchitecture); - Assert.Throws(() => rule.Check(Architecture)); - negation.Check(Architecture); - - AssertNoException(() => - MethodMembers().That().AreCalledBy(_classNotInArchitecture).GetObjects(Architecture) - ); - AssertNoException(() => - MethodMembers() - .That() - .AreNotCalledBy(_classNotInArchitecture) - .GetObjects(Architecture) - ); - } - } -} diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/MemberSyntaxElementsTests.cs b/ArchUnitNETTests/Fluent/Syntax/Elements/MemberSyntaxElementsTests.cs index 7b426d19..931cb2b3 100644 --- a/ArchUnitNETTests/Fluent/Syntax/Elements/MemberSyntaxElementsTests.cs +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/MemberSyntaxElementsTests.cs @@ -1,305 +1,401 @@ -using System; using System.Collections.Generic; +using System.Threading.Tasks; using ArchUnitNET.Domain; -using ArchUnitNETTests.Domain; +using ArchUnitNET.Domain.Exceptions; +using ArchUnitNETTests.AssemblyTestHelper; +using AttributeNamespace; using Xunit; using static ArchUnitNET.Fluent.ArchRuleDefinition; namespace ArchUnitNETTests.Fluent.Syntax.Elements { + // csharpier-ignore public class MemberSyntaxElementsTests { - public MemberSyntaxElementsTests() + [Fact] + public async Task BeStaticTest() + { + var helper = new TypeAssemblyTestHelper(); + + helper.AddSnapshotHeader("No Violations"); + var should = Members().That().Are(helper.StaticField).Should(); + + helper.AddSnapshotSubHeader("Conditions"); + should.BeStatic().AssertNoViolations(helper); + + helper.AddSnapshotSubHeader("Predicates"); + should.Be(Members().That().AreStatic()).AssertNoViolations(helper); + + helper.AddSnapshotHeader("Violations"); + should = Members().That().Are(helper.NonStaticField).Should(); + + helper.AddSnapshotSubHeader("Conditions"); + should.BeStatic().AssertOnlyViolations(helper); + + helper.AddSnapshotSubHeader("Predicates"); + should.Be(Members().That().AreStatic()).AssertOnlyViolations(helper); + + helper.AddSnapshotHeader("Multiple inputs"); + Members().That().Are(helper.StaticField, helper.OtherStaticField).Should().BeStatic().AssertNoViolations(helper); + Members().That().Are(helper.StaticField, helper.NonStaticField).Should().BeStatic().AssertAnyViolations(helper); + + await helper.AssertSnapshotMatches(); + } + + [Fact] + public async Task NotBeStaticTest() + { + var helper = new TypeAssemblyTestHelper(); + + helper.AddSnapshotHeader("No Violations"); + var should = Members().That().Are(helper.NonStaticField).Should(); + + helper.AddSnapshotSubHeader("Conditions"); + should.NotBeStatic().AssertNoViolations(helper); + + helper.AddSnapshotSubHeader("Predicates"); + should.Be(Members().That().AreNotStatic()).AssertNoViolations(helper); + + helper.AddSnapshotHeader("Violations"); + should = Members().That().Are(helper.StaticField).Should(); + + helper.AddSnapshotSubHeader("Conditions"); + should.NotBeStatic().AssertOnlyViolations(helper); + + helper.AddSnapshotSubHeader("Predicates"); + should.Be(Members().That().AreNotStatic()).AssertOnlyViolations(helper); + + helper.AddSnapshotHeader("Multiple inputs"); + Members().That().Are(helper.NonStaticField, helper.ReadOnlyField).Should().NotBeStatic().AssertNoViolations(helper); + Members().That().Are(helper.NonStaticField, helper.StaticField).Should().NotBeStatic().AssertAnyViolations(helper); + + await helper.AssertSnapshotMatches(); + } + + [Fact] + public async Task BeReadOnlyTest() + { + var helper = new TypeAssemblyTestHelper(); + + helper.AddSnapshotHeader("No Violations"); + var should = Members().That().Are(helper.ReadOnlyField).Should(); + + helper.AddSnapshotSubHeader("Conditions"); + should.BeReadOnly().AssertNoViolations(helper); + + helper.AddSnapshotSubHeader("Predicates"); + should.Be(Members().That().AreReadOnly()).AssertNoViolations(helper); + + helper.AddSnapshotHeader("Violations"); + should = Members().That().Are(helper.WritableProperty).Should(); + + helper.AddSnapshotSubHeader("Conditions"); + should.BeReadOnly().AssertOnlyViolations(helper); + + helper.AddSnapshotSubHeader("Predicates"); + should.Be(Members().That().AreReadOnly()).AssertOnlyViolations(helper); + + helper.AddSnapshotHeader("Multiple inputs"); + Members().That().Are(helper.ReadOnlyField, helper.GetOnlyProperty).Should().BeReadOnly().AssertNoViolations(helper); + Members().That().Are(helper.ReadOnlyField, helper.WritableProperty).Should().BeReadOnly().AssertAnyViolations(helper); + + await helper.AssertSnapshotMatches(); + } + + [Fact] + public async Task NotBeReadOnlyTest() { - _members = Architecture.Members; - _types = Architecture.Types; + var helper = new TypeAssemblyTestHelper(); + + helper.AddSnapshotHeader("No Violations"); + var should = Members().That().Are(helper.WritableProperty).Should(); + + helper.AddSnapshotSubHeader("Conditions"); + should.NotBeReadOnly().AssertNoViolations(helper); + + helper.AddSnapshotSubHeader("Predicates"); + should.Be(Members().That().AreNotReadOnly()).AssertNoViolations(helper); + + helper.AddSnapshotHeader("Violations"); + should = Members().That().Are(helper.ReadOnlyField).Should(); + + helper.AddSnapshotSubHeader("Conditions"); + should.NotBeReadOnly().AssertOnlyViolations(helper); + + helper.AddSnapshotSubHeader("Predicates"); + should.Be(Members().That().AreNotReadOnly()).AssertOnlyViolations(helper); + + helper.AddSnapshotHeader("Multiple inputs"); + Members().That().Are(helper.WritableProperty, helper.InitOnlyProperty).Should().NotBeReadOnly().AssertNoViolations(helper); + Members().That().Are(helper.WritableProperty, helper.ReadOnlyField).Should().NotBeReadOnly().AssertAnyViolations(helper); + + await helper.AssertSnapshotMatches(); } - private static readonly Architecture Architecture = - StaticTestArchitectures.ArchUnitNETTestArchitecture; - private readonly IEnumerable _members; - private readonly IEnumerable _types; + [Fact] + public async Task BeImmutableTest() + { + var helper = new TypeAssemblyTestHelper(); + + helper.AddSnapshotHeader("No Violations"); + var should = Members().That().Are(helper.ReadOnlyField).Should(); + + helper.AddSnapshotSubHeader("Conditions"); + should.BeImmutable().AssertNoViolations(helper); + + helper.AddSnapshotSubHeader("Predicates"); + should.Be(Members().That().AreImmutable()).AssertNoViolations(helper); + + helper.AddSnapshotHeader("Violations"); + should = Members().That().Are(helper.WritableProperty).Should(); + + helper.AddSnapshotSubHeader("Conditions"); + should.BeImmutable().AssertOnlyViolations(helper); + + helper.AddSnapshotSubHeader("Predicates"); + should.Be(Members().That().AreImmutable()).AssertOnlyViolations(helper); + + helper.AddSnapshotHeader("Multiple inputs"); + Members().That().Are(helper.ReadOnlyField, helper.GetOnlyProperty).Should().BeImmutable().AssertNoViolations(helper); + Members().That().Are(helper.ReadOnlyField, helper.WritableProperty).Should().BeImmutable().AssertAnyViolations(helper); + + await helper.AssertSnapshotMatches(); + } - private readonly List _falseTypes1 = new List + [Fact] + public async Task NotBeImmutableTest() { - StaticTestTypes.PublicTestClass, - StaticTestTypes.InternalTestClass, - }; + var helper = new TypeAssemblyTestHelper(); + + helper.AddSnapshotHeader("No Violations"); + var should = Members().That().Are(helper.WritableProperty).Should(); + + helper.AddSnapshotSubHeader("Conditions"); + should.NotBeImmutable().AssertNoViolations(helper); + + helper.AddSnapshotSubHeader("Predicates"); + should.Be(Members().That().AreNotImmutable()).AssertNoViolations(helper); + + helper.AddSnapshotHeader("Violations"); + should = Members().That().Are(helper.ReadOnlyField).Should(); + + helper.AddSnapshotSubHeader("Conditions"); + should.NotBeImmutable().AssertOnlyViolations(helper); + + helper.AddSnapshotSubHeader("Predicates"); + should.Be(Members().That().AreNotImmutable()).AssertOnlyViolations(helper); - private readonly List _falseTypes2 = new List + helper.AddSnapshotHeader("Multiple inputs"); + Members().That().Are(helper.WritableProperty, helper.OtherWritableProperty).Should().NotBeImmutable().AssertNoViolations(helper); + Members().That().Are(helper.WritableProperty, helper.ReadOnlyField).Should().NotBeImmutable().AssertAnyViolations(helper); + + await helper.AssertSnapshotMatches(); + } + + [Fact] + public async Task BeDeclaredInTest() { - typeof(PublicTestClass), - typeof(InternalTestClass), - }; - - private static readonly IObjectProvider FalseTypeConstructors = - MethodMembers() - .That() - .HaveFullName("System.Void ArchUnitNETTests.Domain.PublicTestClass::.ctor()") - .Or() - .HaveFullName("System.Void ArchUnitNETTests.Domain.InternalTestClass::.ctor()"); - - private static readonly IObjectProvider PublicTestClassConstructor = - MethodMembers() - .That() - .HaveFullName("System.Void ArchUnitNETTests.Domain.PublicTestClass::.ctor()"); + var helper = new TypeAssemblyTestHelper(); + + helper.AddSnapshotHeader("No Violations"); + var should = Members().That().Are(helper.StaticField).Should(); + + helper.AddSnapshotSubHeader("Conditions"); + should.BeDeclaredIn(helper.ClassWithStaticField).AssertNoViolations(helper); + should.BeDeclaredIn(helper.ClassWithStaticFieldSystemType).AssertNoViolations(helper); + should.BeDeclaredIn(Types().That().Are(helper.ClassWithStaticField)).AssertNoViolations(helper); + should.BeDeclaredIn(new List { helper.ClassWithStaticField }).AssertNoViolations(helper); + should.BeDeclaredIn(new List { helper.ClassWithStaticFieldSystemType }).AssertNoViolations(helper); + + helper.AddSnapshotSubHeader("Predicates"); + should.Be(Members().That().AreDeclaredIn(helper.ClassWithStaticField)).AssertNoViolations(helper); + should.Be(Members().That().AreDeclaredIn(helper.ClassWithStaticFieldSystemType)).AssertNoViolations(helper); + should.Be(Members().That().AreDeclaredIn(Types().That().Are(helper.ClassWithStaticField))).AssertNoViolations(helper); + should.Be(Members().That().AreDeclaredIn(new List { helper.ClassWithStaticField })).AssertNoViolations(helper); + should.Be(Members().That().AreDeclaredIn(new List { helper.ClassWithStaticFieldSystemType })).AssertNoViolations(helper); + + helper.AddSnapshotSubHeader("Complex conditions"); + should.BeDeclaredInTypesThat().Are(helper.ClassWithStaticField).AssertNoViolations(helper); + + helper.AddSnapshotHeader("Violations"); + should = Members().That().Are(helper.StaticField).Should(); + + helper.AddSnapshotSubHeader("Conditions"); + should.BeDeclaredIn(helper.ClassWithNonStaticField).AssertOnlyViolations(helper); + should.BeDeclaredIn(helper.ClassWithNonStaticFieldSystemType).AssertOnlyViolations(helper); + should.BeDeclaredIn(Types().That().Are(helper.ClassWithNonStaticField)).AssertOnlyViolations(helper); + should.BeDeclaredIn(new List { helper.ClassWithNonStaticField }).AssertOnlyViolations(helper); + should.BeDeclaredIn(new List { helper.ClassWithNonStaticFieldSystemType }).AssertOnlyViolations(helper); + + helper.AddSnapshotSubHeader("Predicates"); + should.Be(Members().That().AreDeclaredIn(helper.ClassWithNonStaticField)).AssertOnlyViolations(helper); + should.Be(Members().That().AreDeclaredIn(helper.ClassWithNonStaticFieldSystemType)).AssertOnlyViolations(helper); + should.Be(Members().That().AreDeclaredIn(Types().That().Are(helper.ClassWithNonStaticField))).AssertOnlyViolations(helper); + should.Be(Members().That().AreDeclaredIn(new List { helper.ClassWithNonStaticField })).AssertOnlyViolations(helper); + should.Be(Members().That().AreDeclaredIn(new List { helper.ClassWithNonStaticFieldSystemType })).AssertOnlyViolations(helper); + + helper.AddSnapshotSubHeader("Complex conditions"); + should.BeDeclaredInTypesThat().Are(helper.ClassWithNonStaticField).AssertOnlyViolations(helper); + + helper.AddSnapshotHeader("Multiple arguments"); + should = Members().That().Are(helper.StaticField).Should(); + + helper.AddSnapshotSubHeader("Conditions"); + should.BeDeclaredIn(helper.ClassWithStaticField, helper.ClassWithNonStaticField).AssertNoViolations(helper); + should.BeDeclaredIn(new List { helper.ClassWithStaticField, helper.ClassWithNonStaticField }).AssertNoViolations(helper); + should.BeDeclaredIn(helper.ClassWithStaticFieldSystemType, helper.ClassWithNonStaticFieldSystemType).AssertNoViolations(helper); + should.BeDeclaredIn(new List { helper.ClassWithStaticFieldSystemType, helper.ClassWithNonStaticFieldSystemType }).AssertNoViolations(helper); + + helper.AddSnapshotSubHeader("Predicates"); + should.Be(Members().That().AreDeclaredIn(helper.ClassWithStaticField, helper.ClassWithNonStaticField)).AssertNoViolations(helper); + should.Be(Members().That().AreDeclaredIn(new List { helper.ClassWithStaticField, helper.ClassWithNonStaticField })).AssertNoViolations(helper); + should.Be(Members().That().AreDeclaredIn(helper.ClassWithStaticFieldSystemType, helper.ClassWithNonStaticFieldSystemType)).AssertNoViolations(helper); + should.Be(Members().That().AreDeclaredIn(new List { helper.ClassWithStaticFieldSystemType, helper.ClassWithNonStaticFieldSystemType })).AssertNoViolations(helper); + + helper.AddSnapshotHeader("Empty arguments"); + should = Members().That().Are(helper.StaticField).Should(); + + helper.AddSnapshotSubHeader("Conditions"); + should.BeDeclaredIn(new List()).AssertOnlyViolations(helper); + should.BeDeclaredIn(new List()).AssertOnlyViolations(helper); + + helper.AddSnapshotSubHeader("Predicates"); + should.Be(Members().That().AreDeclaredIn(new List())).AssertOnlyViolations(helper); + should.Be(Members().That().AreDeclaredIn(new List())).AssertOnlyViolations(helper); + + helper.AddSnapshotHeader("Type not in architecture"); + should = Members().That().Are(helper.StaticField).Should(); + + helper.AddSnapshotSubHeader("Conditions"); + should.BeDeclaredIn(new List { typeof(ClassWithoutAttributes) }).AssertException(helper); + + helper.AddSnapshotSubHeader("Predicates"); + should.Be(Members().That().AreDeclaredIn(new List { typeof(ClassWithoutAttributes) })).AssertException(helper); + + helper.AddSnapshotHeader("Multiple inputs"); + Members().That().Are(helper.StaticField, helper.OtherStaticField).Should().BeDeclaredIn(helper.ClassWithStaticField).AssertAnyViolations(helper); + Members().That().Are(helper.StaticField, helper.OtherStaticField).Should().BeDeclaredIn(helper.ClassWithStaticField, helper.OtherClassWithStaticField).AssertNoViolations(helper); + + await helper.AssertSnapshotMatches(); + } [Fact] - public void DeclaredInTest() + public async Task NotBeDeclaredInTest() { - foreach (var member in _members) - { - //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); - - Assert.True(declaredInRightType.HasNoViolations(Architecture)); - Assert.False(notDeclaredInRightType.HasNoViolations(Architecture)); - Assert.False(declaredInOtherType1.HasNoViolations(Architecture)); - Assert.True(notDeclaredInOtherType1.HasNoViolations(Architecture)); - Assert.False(declaredInOtherType2.HasNoViolations(Architecture)); - Assert.True(notDeclaredInOtherType2.HasNoViolations(Architecture)); - - //Multiple Arguments - - var declaredInRightTypeFluent = Members() - .That() - .Are(member) - .Should() - .BeDeclaredIn(Types().That().HaveMemberWithName(member.Name)); - 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); - - Assert.True(declaredInRightTypeFluent.HasNoViolations(Architecture)); - Assert.False(notDeclaredInRightTypeFluent.HasNoViolations(Architecture)); - Assert.False(declaredInOtherTypeMultiple1.HasNoViolations(Architecture)); - Assert.True(notDeclaredInOtherTypeMultiple1.HasNoViolations(Architecture)); - Assert.False(declaredInOtherTypeMultiple2.HasNoViolations(Architecture)); - Assert.True(notDeclaredInOtherTypeMultiple2.HasNoViolations(Architecture)); - } - - 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(); - - Assert.True(membersShouldBeDeclaredInOwnType.HasNoViolations(Architecture)); - Assert.False(membersShouldNotBeDeclaredInOwnType.HasNoViolations(Architecture)); - } - - //One Argument - - var emptyTypeHasOnlyConstructor1 = Members() - .That() - .AreDeclaredIn(typeof(PublicTestClass)) - .Should() - .Be(PublicTestClassConstructor); - var emptyTypeHasOnlyConstructor2 = Members() - .That() - .AreDeclaredIn(StaticTestTypes.PublicTestClass) - .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)); - - Assert.True(emptyTypeHasOnlyConstructor1.HasNoViolations(Architecture)); - Assert.True(emptyTypeHasOnlyConstructor2.HasNoViolations(Architecture)); - Assert.True(allMembersAreNotDeclaredInEmptyType1.HasNoViolations(Architecture)); - Assert.True(allMembersAreNotDeclaredInEmptyType2.HasNoViolations(Architecture)); - - //Multiple Arguments - - var emptyTypeHasOnlyConstructorMultiple1 = Members() - .That() - .AreDeclaredIn(_falseTypes1) - .Should() - .Be(FalseTypeConstructors); - var emptyTypeHasOnlyConstructorMultiple2 = Members() - .That() - .AreDeclaredIn(_falseTypes2) - .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)); - - Assert.True(emptyTypeHasOnlyConstructorMultiple1.HasNoViolations(Architecture)); - Assert.True(emptyTypeHasOnlyConstructorMultiple2.HasNoViolations(Architecture)); - Assert.True(allMembersAreNotDeclaredInEmptyTypeMultiple1.HasNoViolations(Architecture)); - Assert.True(allMembersAreNotDeclaredInEmptyTypeMultiple2.HasNoViolations(Architecture)); + var helper = new TypeAssemblyTestHelper(); + + helper.AddSnapshotHeader("No Violations"); + var should = Members().That().Are(helper.StaticField).Should(); + + helper.AddSnapshotSubHeader("Conditions"); + should.NotBeDeclaredIn(helper.ClassWithNonStaticField).AssertNoViolations(helper); + should.NotBeDeclaredIn(helper.ClassWithNonStaticFieldSystemType).AssertNoViolations(helper); + should.NotBeDeclaredIn(Types().That().Are(helper.ClassWithNonStaticField)).AssertNoViolations(helper); + should.NotBeDeclaredIn(new List { helper.ClassWithNonStaticField }).AssertNoViolations(helper); + should.NotBeDeclaredIn(new List { helper.ClassWithNonStaticFieldSystemType }).AssertNoViolations(helper); + + helper.AddSnapshotSubHeader("Predicates"); + should.Be(Members().That().AreNotDeclaredIn(helper.ClassWithNonStaticField)).AssertNoViolations(helper); + should.Be(Members().That().AreNotDeclaredIn(helper.ClassWithNonStaticFieldSystemType)).AssertNoViolations(helper); + should.Be(Members().That().AreNotDeclaredIn(Types().That().Are(helper.ClassWithNonStaticField))).AssertNoViolations(helper); + should.Be(Members().That().AreNotDeclaredIn(new List { helper.ClassWithNonStaticField })).AssertNoViolations(helper); + should.Be(Members().That().AreNotDeclaredIn(new List { helper.ClassWithNonStaticFieldSystemType })).AssertNoViolations(helper); + + helper.AddSnapshotSubHeader("Complex conditions"); + should.NotBeDeclaredInTypesThat().Are(helper.ClassWithNonStaticField).AssertNoViolations(helper); + + helper.AddSnapshotHeader("Violations"); + should = Members().That().Are(helper.StaticField).Should(); + + helper.AddSnapshotSubHeader("Conditions"); + should.NotBeDeclaredIn(helper.ClassWithStaticField).AssertOnlyViolations(helper); + should.NotBeDeclaredIn(helper.ClassWithStaticFieldSystemType).AssertOnlyViolations(helper); + should.NotBeDeclaredIn(Types().That().Are(helper.ClassWithStaticField)).AssertOnlyViolations(helper); + should.NotBeDeclaredIn(new List { helper.ClassWithStaticField }).AssertOnlyViolations(helper); + should.NotBeDeclaredIn(new List { helper.ClassWithStaticFieldSystemType }).AssertOnlyViolations(helper); + + helper.AddSnapshotSubHeader("Predicates"); + should.Be(Members().That().AreNotDeclaredIn(helper.ClassWithStaticField)).AssertOnlyViolations(helper); + should.Be(Members().That().AreNotDeclaredIn(helper.ClassWithStaticFieldSystemType)).AssertOnlyViolations(helper); + should.Be(Members().That().AreNotDeclaredIn(Types().That().Are(helper.ClassWithStaticField))).AssertOnlyViolations(helper); + should.Be(Members().That().AreNotDeclaredIn(new List { helper.ClassWithStaticField })).AssertOnlyViolations(helper); + should.Be(Members().That().AreNotDeclaredIn(new List { helper.ClassWithStaticFieldSystemType })).AssertOnlyViolations(helper); + + helper.AddSnapshotSubHeader("Complex conditions"); + should.NotBeDeclaredInTypesThat().Are(helper.ClassWithStaticField).AssertOnlyViolations(helper); + + helper.AddSnapshotHeader("Multiple arguments"); + should = Members().That().Are(helper.StaticField).Should(); + + helper.AddSnapshotSubHeader("Conditions"); + should.NotBeDeclaredIn(helper.ClassWithNonStaticField, helper.ClassWithReadOnlyField).AssertNoViolations(helper); + should.NotBeDeclaredIn(new List { helper.ClassWithNonStaticField, helper.ClassWithReadOnlyField }).AssertNoViolations(helper); + should.NotBeDeclaredIn(helper.ClassWithNonStaticFieldSystemType, helper.ClassWithReadOnlyFieldSystemType).AssertNoViolations(helper); + should.NotBeDeclaredIn(new List { helper.ClassWithNonStaticFieldSystemType, helper.ClassWithReadOnlyFieldSystemType }).AssertNoViolations(helper); + + helper.AddSnapshotSubHeader("Predicates"); + should.Be(Members().That().AreNotDeclaredIn(helper.ClassWithNonStaticField, helper.ClassWithReadOnlyField)).AssertNoViolations(helper); + should.Be(Members().That().AreNotDeclaredIn(new List { helper.ClassWithNonStaticField, helper.ClassWithReadOnlyField })).AssertNoViolations(helper); + should.Be(Members().That().AreNotDeclaredIn(helper.ClassWithNonStaticFieldSystemType, helper.ClassWithReadOnlyFieldSystemType)).AssertNoViolations(helper); + should.Be(Members().That().AreNotDeclaredIn(new List { helper.ClassWithNonStaticFieldSystemType, helper.ClassWithReadOnlyFieldSystemType })).AssertNoViolations(helper); + + helper.AddSnapshotHeader("Empty arguments"); + should = Members().That().Are(helper.StaticField).Should(); + + helper.AddSnapshotSubHeader("Conditions"); + should.NotBeDeclaredIn(new List()).AssertNoViolations(helper); + should.NotBeDeclaredIn(new List()).AssertNoViolations(helper); + + helper.AddSnapshotSubHeader("Predicates"); + should.Be(Members().That().AreNotDeclaredIn(new List())).AssertNoViolations(helper); + should.Be(Members().That().AreNotDeclaredIn(new List())).AssertNoViolations(helper); + + helper.AddSnapshotHeader("Type not in architecture"); + should = Members().That().Are(helper.StaticField).Should(); + + helper.AddSnapshotSubHeader("Conditions"); + should.NotBeDeclaredIn(new List { typeof(ClassWithoutAttributes) }).AssertException(helper); + + helper.AddSnapshotSubHeader("Predicates"); + should.Be(Members().That().AreNotDeclaredIn(new List { typeof(ClassWithoutAttributes) })).AssertException(helper); + + helper.AddSnapshotHeader("Multiple inputs"); + Members().That().Are(helper.StaticField, helper.NonStaticField).Should().NotBeDeclaredIn(helper.ClassWithReadOnlyField).AssertNoViolations(helper); + Members().That().Are(helper.StaticField, helper.NonStaticField).Should().NotBeDeclaredIn(helper.ClassWithStaticField).AssertAnyViolations(helper); + + await helper.AssertSnapshotMatches(); } [Fact] - public void IsStaticTest() + public async Task BeDeclaredInTypesThatTest() { - var correctIsStatic = Members().That().AreStatic().Should().BeStatic(); - var correctIsStatic2 = Members().That().AreNotStatic().Should().NotBeStatic(); - var wrongStatic = Members().That().AreStatic().Should().NotBeStatic(); - var wrongStatic2 = Members().That().AreNotStatic().Should().BeStatic(); - - Assert.True(correctIsStatic.HasNoViolations(Architecture)); - Assert.True(correctIsStatic2.HasNoViolations(Architecture)); - Assert.False(wrongStatic.HasNoViolations(Architecture)); - Assert.False(wrongStatic2.HasNoViolations(Architecture)); + var helper = new TypeAssemblyTestHelper(); + + helper.AddSnapshotHeader("No Violations"); + var should = Members().That().Are(helper.StaticField).Should(); + should.BeDeclaredInTypesThat().Are(helper.ClassWithStaticField).AssertNoViolations(helper); + + helper.AddSnapshotHeader("Violations"); + should = Members().That().Are(helper.StaticField).Should(); + should.BeDeclaredInTypesThat().Are(helper.ClassWithNonStaticField).AssertOnlyViolations(helper); + + await helper.AssertSnapshotMatches(); } [Fact] - public void AreImmutableTest() + public async Task NotBeDeclaredInTypesThatTest() { - foreach (var member in _members) - { - 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(); - - 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) - ); - } - - 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)); - Assert.False(membersThatAreNotImmutableAreImmutable.HasNoViolations(Architecture)); - Assert.True(membersThatAreNotImmutableAreNotImmutable.HasNoViolations(Architecture)); + var helper = new TypeAssemblyTestHelper(); + + helper.AddSnapshotHeader("No Violations"); + var should = Members().That().Are(helper.StaticField).Should(); + should.NotBeDeclaredInTypesThat().Are(helper.ClassWithNonStaticField).AssertNoViolations(helper); + + helper.AddSnapshotHeader("Violations"); + should = Members().That().Are(helper.StaticField).Should(); + should.NotBeDeclaredInTypesThat().Are(helper.ClassWithStaticField).AssertOnlyViolations(helper); + + await helper.AssertSnapshotMatches(); } } } diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.BeDeclaredInTest.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.BeDeclaredInTest.verified.txt new file mode 100644 index 00000000..0d107b13 --- /dev/null +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.BeDeclaredInTest.verified.txt @@ -0,0 +1,310 @@ +===== No Violations ===== + +----- Conditions ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in "TypeNamespace.ClassWithStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in "TypeNamespace.ClassWithStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in Types that are "TypeNamespace.ClassWithStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in "TypeNamespace.ClassWithStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in "TypeNamespace.ClassWithStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +----- Predicates ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are declared in "TypeNamespace.ClassWithStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are declared in "TypeNamespace.ClassWithStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are declared in Types that are "TypeNamespace.ClassWithStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are declared in "TypeNamespace.ClassWithStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are declared in "TypeNamespace.ClassWithStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +----- Complex conditions ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in types that are "TypeNamespace.ClassWithStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +===== Violations ===== + +----- Conditions ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in "TypeNamespace.ClassWithNonStaticField" +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in "TypeNamespace.ClassWithNonStaticField"" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField + + + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in "TypeNamespace.ClassWithNonStaticField" +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in "TypeNamespace.ClassWithNonStaticField"" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField + + + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in Types that are "TypeNamespace.ClassWithNonStaticField" +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in Types that are "TypeNamespace.ClassWithNonStaticField"" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField + + + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in "TypeNamespace.ClassWithNonStaticField" +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in "TypeNamespace.ClassWithNonStaticField"" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField + + + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in "TypeNamespace.ClassWithNonStaticField" +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in "TypeNamespace.ClassWithNonStaticField"" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField + + + +----- Predicates ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are declared in "TypeNamespace.ClassWithNonStaticField" +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is not Members that are declared in "TypeNamespace.ClassWithNonStaticField" +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are declared in "TypeNamespace.ClassWithNonStaticField"" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is not Members that are declared in "TypeNamespace.ClassWithNonStaticField" + + + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are declared in "TypeNamespace.ClassWithNonStaticField" +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is not Members that are declared in "TypeNamespace.ClassWithNonStaticField" +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are declared in "TypeNamespace.ClassWithNonStaticField"" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is not Members that are declared in "TypeNamespace.ClassWithNonStaticField" + + + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are declared in Types that are "TypeNamespace.ClassWithNonStaticField" +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is not Members that are declared in Types that are "TypeNamespace.ClassWithNonStaticField" +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are declared in Types that are "TypeNamespace.ClassWithNonStaticField"" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is not Members that are declared in Types that are "TypeNamespace.ClassWithNonStaticField" + + + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are declared in "TypeNamespace.ClassWithNonStaticField" +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is not Members that are declared in "TypeNamespace.ClassWithNonStaticField" +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are declared in "TypeNamespace.ClassWithNonStaticField"" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is not Members that are declared in "TypeNamespace.ClassWithNonStaticField" + + + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are declared in "TypeNamespace.ClassWithNonStaticField" +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is not Members that are declared in "TypeNamespace.ClassWithNonStaticField" +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are declared in "TypeNamespace.ClassWithNonStaticField"" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is not Members that are declared in "TypeNamespace.ClassWithNonStaticField" + + + +----- Complex conditions ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in types that are "TypeNamespace.ClassWithNonStaticField" +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in types that are "TypeNamespace.ClassWithNonStaticField"" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField + + + +===== Multiple arguments ===== + +----- Conditions ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in "TypeNamespace.ClassWithStaticField" or "TypeNamespace.ClassWithNonStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in "TypeNamespace.ClassWithStaticField" or "TypeNamespace.ClassWithNonStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in "TypeNamespace.ClassWithStaticField" or "TypeNamespace.ClassWithNonStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in "TypeNamespace.ClassWithStaticField" or "TypeNamespace.ClassWithNonStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +----- Predicates ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are declared in "TypeNamespace.ClassWithStaticField" or "TypeNamespace.ClassWithNonStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are declared in "TypeNamespace.ClassWithStaticField" or "TypeNamespace.ClassWithNonStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are declared in "TypeNamespace.ClassWithStaticField" or "TypeNamespace.ClassWithNonStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are declared in "TypeNamespace.ClassWithStaticField" or "TypeNamespace.ClassWithNonStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +===== Empty arguments ===== + +----- Conditions ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in no type (always false) +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in no type (always false)" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField + + + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in no type (always false) +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in no type (always false)" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField + + + +----- Predicates ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are declared in no type (always false) +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is not Members that are declared in no type (always false) +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are declared in no type (always false)" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is not Members that are declared in no type (always false) + + + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are declared in no type (always false) +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is not Members that are declared in no type (always false) +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are declared in no type (always false)" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is not Members that are declared in no type (always false) + + + +===== Type not in architecture ===== + +----- Conditions ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in "AttributeNamespace.ClassWithoutAttributes" +Exception: Type AttributeNamespace.ClassWithoutAttributes does not exist in provided architecture or is no class. + +----- Predicates ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are declared in "AttributeNamespace.ClassWithoutAttributes" +Exception: Type AttributeNamespace.ClassWithoutAttributes does not exist in provided architecture or is no class. + +===== Multiple inputs ===== + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" or "System.Int32 TypeNamespace.OtherClassWithStaticField::OtherStaticField" should be declared in "TypeNamespace.ClassWithStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Result: False +Description: System.Int32 TypeNamespace.OtherClassWithStaticField::OtherStaticField is declared in TypeNamespace.OtherClassWithStaticField +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" or "System.Int32 TypeNamespace.OtherClassWithStaticField::OtherStaticField" should be declared in "TypeNamespace.ClassWithStaticField"" failed: + System.Int32 TypeNamespace.OtherClassWithStaticField::OtherStaticField is declared in TypeNamespace.OtherClassWithStaticField + + + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" or "System.Int32 TypeNamespace.OtherClassWithStaticField::OtherStaticField" should be declared in "TypeNamespace.ClassWithStaticField" or "TypeNamespace.OtherClassWithStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Result: True +Description: System.Int32 TypeNamespace.OtherClassWithStaticField::OtherStaticField passed +Message: +All Evaluations passed + diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.BeDeclaredInTypesThatTest.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.BeDeclaredInTypesThatTest.verified.txt new file mode 100644 index 00000000..96fc4b46 --- /dev/null +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.BeDeclaredInTypesThatTest.verified.txt @@ -0,0 +1,19 @@ +===== No Violations ===== + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in types that are "TypeNamespace.ClassWithStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +===== Violations ===== + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in types that are "TypeNamespace.ClassWithNonStaticField" +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be declared in types that are "TypeNamespace.ClassWithNonStaticField"" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField + + + diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.BeImmutableTest.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.BeImmutableTest.verified.txt new file mode 100644 index 00000000..0b92c894 --- /dev/null +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.BeImmutableTest.verified.txt @@ -0,0 +1,63 @@ +===== No Violations ===== + +----- Conditions ----- + +Query: Members that are "System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField" should be immutable +Result: True +Description: System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField passed +Message: +All Evaluations passed + +----- Predicates ----- + +Query: Members that are "System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField" should be Members that are immutable +Result: True +Description: System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField passed +Message: +All Evaluations passed + +===== Violations ===== + +----- Conditions ----- + +Query: Members that are "System.String TypeNamespace.ClassWithWritableProperty::WritableProperty()" should be immutable +Result: False +Description: System.String TypeNamespace.ClassWithWritableProperty::WritableProperty() is not immutable +Message: +"Members that are "System.String TypeNamespace.ClassWithWritableProperty::WritableProperty()" should be immutable" failed: + System.String TypeNamespace.ClassWithWritableProperty::WritableProperty() is not immutable + + + +----- Predicates ----- + +Query: Members that are "System.String TypeNamespace.ClassWithWritableProperty::WritableProperty()" should be Members that are immutable +Result: False +Description: System.String TypeNamespace.ClassWithWritableProperty::WritableProperty() is not Members that are immutable +Message: +"Members that are "System.String TypeNamespace.ClassWithWritableProperty::WritableProperty()" should be Members that are immutable" failed: + System.String TypeNamespace.ClassWithWritableProperty::WritableProperty() is not Members that are immutable + + + +===== Multiple inputs ===== + +Query: Members that are "System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField" or "System.String TypeNamespace.ClassWithGetOnlyProperty::GetOnlyProperty()" should be immutable +Result: True +Description: System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField passed +Result: True +Description: System.String TypeNamespace.ClassWithGetOnlyProperty::GetOnlyProperty() passed +Message: +All Evaluations passed + +Query: Members that are "System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField" or "System.String TypeNamespace.ClassWithWritableProperty::WritableProperty()" should be immutable +Result: True +Description: System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField passed +Result: False +Description: System.String TypeNamespace.ClassWithWritableProperty::WritableProperty() is not immutable +Message: +"Members that are "System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField" or "System.String TypeNamespace.ClassWithWritableProperty::WritableProperty()" should be immutable" failed: + System.String TypeNamespace.ClassWithWritableProperty::WritableProperty() is not immutable + + + diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.BeReadOnlyTest.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.BeReadOnlyTest.verified.txt new file mode 100644 index 00000000..51a28661 --- /dev/null +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.BeReadOnlyTest.verified.txt @@ -0,0 +1,63 @@ +===== No Violations ===== + +----- Conditions ----- + +Query: Members that are "System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField" should be read only +Result: True +Description: System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField passed +Message: +All Evaluations passed + +----- Predicates ----- + +Query: Members that are "System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField" should be Members that are read only +Result: True +Description: System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField passed +Message: +All Evaluations passed + +===== Violations ===== + +----- Conditions ----- + +Query: Members that are "System.String TypeNamespace.ClassWithWritableProperty::WritableProperty()" should be read only +Result: False +Description: System.String TypeNamespace.ClassWithWritableProperty::WritableProperty() is not read only +Message: +"Members that are "System.String TypeNamespace.ClassWithWritableProperty::WritableProperty()" should be read only" failed: + System.String TypeNamespace.ClassWithWritableProperty::WritableProperty() is not read only + + + +----- Predicates ----- + +Query: Members that are "System.String TypeNamespace.ClassWithWritableProperty::WritableProperty()" should be Members that are read only +Result: False +Description: System.String TypeNamespace.ClassWithWritableProperty::WritableProperty() is not Members that are read only +Message: +"Members that are "System.String TypeNamespace.ClassWithWritableProperty::WritableProperty()" should be Members that are read only" failed: + System.String TypeNamespace.ClassWithWritableProperty::WritableProperty() is not Members that are read only + + + +===== Multiple inputs ===== + +Query: Members that are "System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField" or "System.String TypeNamespace.ClassWithGetOnlyProperty::GetOnlyProperty()" should be read only +Result: True +Description: System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField passed +Result: True +Description: System.String TypeNamespace.ClassWithGetOnlyProperty::GetOnlyProperty() passed +Message: +All Evaluations passed + +Query: Members that are "System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField" or "System.String TypeNamespace.ClassWithWritableProperty::WritableProperty()" should be read only +Result: True +Description: System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField passed +Result: False +Description: System.String TypeNamespace.ClassWithWritableProperty::WritableProperty() is not read only +Message: +"Members that are "System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField" or "System.String TypeNamespace.ClassWithWritableProperty::WritableProperty()" should be read only" failed: + System.String TypeNamespace.ClassWithWritableProperty::WritableProperty() is not read only + + + diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.BeStaticTest.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.BeStaticTest.verified.txt new file mode 100644 index 00000000..56c1dcf8 --- /dev/null +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.BeStaticTest.verified.txt @@ -0,0 +1,63 @@ +===== No Violations ===== + +----- Conditions ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be static +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +----- Predicates ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are static +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +===== Violations ===== + +----- Conditions ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithNonStaticField::NonStaticField" should be static +Result: False +Description: System.Int32 TypeNamespace.ClassWithNonStaticField::NonStaticField is not static +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithNonStaticField::NonStaticField" should be static" failed: + System.Int32 TypeNamespace.ClassWithNonStaticField::NonStaticField is not static + + + +----- Predicates ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithNonStaticField::NonStaticField" should be Members that are static +Result: False +Description: System.Int32 TypeNamespace.ClassWithNonStaticField::NonStaticField is not Members that are static +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithNonStaticField::NonStaticField" should be Members that are static" failed: + System.Int32 TypeNamespace.ClassWithNonStaticField::NonStaticField is not Members that are static + + + +===== Multiple inputs ===== + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" or "System.Int32 TypeNamespace.OtherClassWithStaticField::OtherStaticField" should be static +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Result: True +Description: System.Int32 TypeNamespace.OtherClassWithStaticField::OtherStaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" or "System.Int32 TypeNamespace.ClassWithNonStaticField::NonStaticField" should be static +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Result: False +Description: System.Int32 TypeNamespace.ClassWithNonStaticField::NonStaticField is not static +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" or "System.Int32 TypeNamespace.ClassWithNonStaticField::NonStaticField" should be static" failed: + System.Int32 TypeNamespace.ClassWithNonStaticField::NonStaticField is not static + + + diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.NotBeDeclaredInTest.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.NotBeDeclaredInTest.verified.txt new file mode 100644 index 00000000..a1a9ecc3 --- /dev/null +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.NotBeDeclaredInTest.verified.txt @@ -0,0 +1,298 @@ +===== No Violations ===== + +----- Conditions ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in "TypeNamespace.ClassWithNonStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in "TypeNamespace.ClassWithNonStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in Types that are "TypeNamespace.ClassWithNonStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in "TypeNamespace.ClassWithNonStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in "TypeNamespace.ClassWithNonStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +----- Predicates ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are not declared in "TypeNamespace.ClassWithNonStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are not declared in "TypeNamespace.ClassWithNonStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are not declared in Types that are "TypeNamespace.ClassWithNonStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are not declared in "TypeNamespace.ClassWithNonStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are not declared in "TypeNamespace.ClassWithNonStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +----- Complex conditions ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in types that are "TypeNamespace.ClassWithNonStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +===== Violations ===== + +----- Conditions ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in "TypeNamespace.ClassWithStaticField" +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in "TypeNamespace.ClassWithStaticField"" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField + + + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in "TypeNamespace.ClassWithStaticField" +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in "TypeNamespace.ClassWithStaticField"" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField + + + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in Types that are "TypeNamespace.ClassWithStaticField" +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in Types that are "TypeNamespace.ClassWithStaticField"" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField + + + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in "TypeNamespace.ClassWithStaticField" +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in "TypeNamespace.ClassWithStaticField"" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField + + + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in "TypeNamespace.ClassWithStaticField" +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in "TypeNamespace.ClassWithStaticField"" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField + + + +----- Predicates ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are not declared in "TypeNamespace.ClassWithStaticField" +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is not Members that are not declared in "TypeNamespace.ClassWithStaticField" +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are not declared in "TypeNamespace.ClassWithStaticField"" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is not Members that are not declared in "TypeNamespace.ClassWithStaticField" + + + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are not declared in "TypeNamespace.ClassWithStaticField" +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is not Members that are not declared in "TypeNamespace.ClassWithStaticField" +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are not declared in "TypeNamespace.ClassWithStaticField"" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is not Members that are not declared in "TypeNamespace.ClassWithStaticField" + + + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are not declared in Types that are "TypeNamespace.ClassWithStaticField" +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is not Members that are not declared in Types that are "TypeNamespace.ClassWithStaticField" +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are not declared in Types that are "TypeNamespace.ClassWithStaticField"" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is not Members that are not declared in Types that are "TypeNamespace.ClassWithStaticField" + + + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are not declared in "TypeNamespace.ClassWithStaticField" +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is not Members that are not declared in "TypeNamespace.ClassWithStaticField" +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are not declared in "TypeNamespace.ClassWithStaticField"" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is not Members that are not declared in "TypeNamespace.ClassWithStaticField" + + + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are not declared in "TypeNamespace.ClassWithStaticField" +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is not Members that are not declared in "TypeNamespace.ClassWithStaticField" +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are not declared in "TypeNamespace.ClassWithStaticField"" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is not Members that are not declared in "TypeNamespace.ClassWithStaticField" + + + +----- Complex conditions ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in types that are "TypeNamespace.ClassWithStaticField" +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in types that are "TypeNamespace.ClassWithStaticField"" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField + + + +===== Multiple arguments ===== + +----- Conditions ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in "TypeNamespace.ClassWithNonStaticField" or "TypeNamespace.ClassWithReadOnlyField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in "TypeNamespace.ClassWithNonStaticField" or "TypeNamespace.ClassWithReadOnlyField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in "TypeNamespace.ClassWithNonStaticField" or "TypeNamespace.ClassWithReadOnlyField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in "TypeNamespace.ClassWithNonStaticField" or "TypeNamespace.ClassWithReadOnlyField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +----- Predicates ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are not declared in "TypeNamespace.ClassWithNonStaticField" or "TypeNamespace.ClassWithReadOnlyField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are not declared in "TypeNamespace.ClassWithNonStaticField" or "TypeNamespace.ClassWithReadOnlyField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are not declared in "TypeNamespace.ClassWithNonStaticField" or "TypeNamespace.ClassWithReadOnlyField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are not declared in "TypeNamespace.ClassWithNonStaticField" or "TypeNamespace.ClassWithReadOnlyField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +===== Empty arguments ===== + +----- Conditions ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in no type (always true) +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in no type (always true) +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +----- Predicates ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are declared in any type (always true) +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are declared in any type (always true) +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +===== Type not in architecture ===== + +----- Conditions ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in "AttributeNamespace.ClassWithoutAttributes" +Exception: Type AttributeNamespace.ClassWithoutAttributes does not exist in provided architecture or is no class. + +----- Predicates ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are not declared in "AttributeNamespace.ClassWithoutAttributes" +Exception: Type AttributeNamespace.ClassWithoutAttributes does not exist in provided architecture or is no class. + +===== Multiple inputs ===== + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" or "System.Int32 TypeNamespace.ClassWithNonStaticField::NonStaticField" should not be declared in "TypeNamespace.ClassWithReadOnlyField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Result: True +Description: System.Int32 TypeNamespace.ClassWithNonStaticField::NonStaticField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" or "System.Int32 TypeNamespace.ClassWithNonStaticField::NonStaticField" should not be declared in "TypeNamespace.ClassWithStaticField" +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField +Result: True +Description: System.Int32 TypeNamespace.ClassWithNonStaticField::NonStaticField passed +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" or "System.Int32 TypeNamespace.ClassWithNonStaticField::NonStaticField" should not be declared in "TypeNamespace.ClassWithStaticField"" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField + + + diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.NotBeDeclaredInTypesThatTest.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.NotBeDeclaredInTypesThatTest.verified.txt new file mode 100644 index 00000000..3e66cd09 --- /dev/null +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.NotBeDeclaredInTypesThatTest.verified.txt @@ -0,0 +1,19 @@ +===== No Violations ===== + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in types that are "TypeNamespace.ClassWithNonStaticField" +Result: True +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField passed +Message: +All Evaluations passed + +===== Violations ===== + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in types that are "TypeNamespace.ClassWithStaticField" +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be declared in types that are "TypeNamespace.ClassWithStaticField"" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is declared in TypeNamespace.ClassWithStaticField + + + diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.NotBeImmutableTest.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.NotBeImmutableTest.verified.txt new file mode 100644 index 00000000..ebd0810f --- /dev/null +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.NotBeImmutableTest.verified.txt @@ -0,0 +1,63 @@ +===== No Violations ===== + +----- Conditions ----- + +Query: Members that are "System.String TypeNamespace.ClassWithWritableProperty::WritableProperty()" should not be immutable +Result: True +Description: System.String TypeNamespace.ClassWithWritableProperty::WritableProperty() passed +Message: +All Evaluations passed + +----- Predicates ----- + +Query: Members that are "System.String TypeNamespace.ClassWithWritableProperty::WritableProperty()" should be Members that are not immutable +Result: True +Description: System.String TypeNamespace.ClassWithWritableProperty::WritableProperty() passed +Message: +All Evaluations passed + +===== Violations ===== + +----- Conditions ----- + +Query: Members that are "System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField" should not be immutable +Result: False +Description: System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField is immutable +Message: +"Members that are "System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField" should not be immutable" failed: + System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField is immutable + + + +----- Predicates ----- + +Query: Members that are "System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField" should be Members that are not immutable +Result: False +Description: System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField is not Members that are not immutable +Message: +"Members that are "System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField" should be Members that are not immutable" failed: + System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField is not Members that are not immutable + + + +===== Multiple inputs ===== + +Query: Members that are "System.String TypeNamespace.ClassWithWritableProperty::WritableProperty()" or "System.String TypeNamespace.OtherClassWithWritableProperty::Oth... should not be immutable +Result: True +Description: System.String TypeNamespace.ClassWithWritableProperty::WritableProperty() passed +Result: True +Description: System.String TypeNamespace.OtherClassWithWritableProperty::OtherWritableProperty() passed +Message: +All Evaluations passed + +Query: Members that are "System.String TypeNamespace.ClassWithWritableProperty::WritableProperty()" or "System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField" should not be immutable +Result: False +Description: System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField is immutable +Result: True +Description: System.String TypeNamespace.ClassWithWritableProperty::WritableProperty() passed +Message: +"Members that are "System.String TypeNamespace.ClassWithWritableProperty::WritableProperty()" or "System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField" should not be immutable" failed: + System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField is immutable + + + diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.NotBeReadOnlyTest.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.NotBeReadOnlyTest.verified.txt new file mode 100644 index 00000000..f5982117 --- /dev/null +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.NotBeReadOnlyTest.verified.txt @@ -0,0 +1,63 @@ +===== No Violations ===== + +----- Conditions ----- + +Query: Members that are "System.String TypeNamespace.ClassWithWritableProperty::WritableProperty()" should not be read only +Result: True +Description: System.String TypeNamespace.ClassWithWritableProperty::WritableProperty() passed +Message: +All Evaluations passed + +----- Predicates ----- + +Query: Members that are "System.String TypeNamespace.ClassWithWritableProperty::WritableProperty()" should be Members that are not read only +Result: True +Description: System.String TypeNamespace.ClassWithWritableProperty::WritableProperty() passed +Message: +All Evaluations passed + +===== Violations ===== + +----- Conditions ----- + +Query: Members that are "System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField" should not be read only +Result: False +Description: System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField is read only +Message: +"Members that are "System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField" should not be read only" failed: + System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField is read only + + + +----- Predicates ----- + +Query: Members that are "System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField" should be Members that are not read only +Result: False +Description: System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField is not Members that are not read only +Message: +"Members that are "System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField" should be Members that are not read only" failed: + System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField is not Members that are not read only + + + +===== Multiple inputs ===== + +Query: Members that are "System.String TypeNamespace.ClassWithWritableProperty::WritableProperty()" or "System.String TypeNamespace.ClassWithInitOnlyProperty::InitOnly... should not be read only +Result: True +Description: System.String TypeNamespace.ClassWithWritableProperty::WritableProperty() passed +Result: True +Description: System.String TypeNamespace.ClassWithInitOnlyProperty::InitOnlyProperty() passed +Message: +All Evaluations passed + +Query: Members that are "System.String TypeNamespace.ClassWithWritableProperty::WritableProperty()" or "System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField" should not be read only +Result: False +Description: System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField is read only +Result: True +Description: System.String TypeNamespace.ClassWithWritableProperty::WritableProperty() passed +Message: +"Members that are "System.String TypeNamespace.ClassWithWritableProperty::WritableProperty()" or "System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField" should not be read only" failed: + System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField is read only + + + diff --git a/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.NotBeStaticTest.verified.txt b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.NotBeStaticTest.verified.txt new file mode 100644 index 00000000..be389526 --- /dev/null +++ b/ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/MemberSyntaxElementsTests.NotBeStaticTest.verified.txt @@ -0,0 +1,63 @@ +===== No Violations ===== + +----- Conditions ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithNonStaticField::NonStaticField" should not be static +Result: True +Description: System.Int32 TypeNamespace.ClassWithNonStaticField::NonStaticField passed +Message: +All Evaluations passed + +----- Predicates ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithNonStaticField::NonStaticField" should be Members that are not static +Result: True +Description: System.Int32 TypeNamespace.ClassWithNonStaticField::NonStaticField passed +Message: +All Evaluations passed + +===== Violations ===== + +----- Conditions ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be static +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is static +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be static" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is static + + + +----- Predicates ----- + +Query: Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are not static +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is not Members that are not static +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should be Members that are not static" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is not Members that are not static + + + +===== Multiple inputs ===== + +Query: Members that are "System.Int32 TypeNamespace.ClassWithNonStaticField::NonStaticField" or "System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField" should not be static +Result: True +Description: System.Int32 TypeNamespace.ClassWithNonStaticField::NonStaticField passed +Result: True +Description: System.String TypeNamespace.ClassWithReadOnlyField::ReadOnlyField passed +Message: +All Evaluations passed + +Query: Members that are "System.Int32 TypeNamespace.ClassWithNonStaticField::NonStaticField" or "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be static +Result: False +Description: System.Int32 TypeNamespace.ClassWithStaticField::StaticField is static +Result: True +Description: System.Int32 TypeNamespace.ClassWithNonStaticField::NonStaticField passed +Message: +"Members that are "System.Int32 TypeNamespace.ClassWithNonStaticField::NonStaticField" or "System.Int32 TypeNamespace.ClassWithStaticField::StaticField" should not be static" failed: + System.Int32 TypeNamespace.ClassWithStaticField::StaticField is static + + + diff --git a/TestAssemblies/TypeAssembly/Type.cs b/TestAssemblies/TypeAssembly/Type.cs index 8f55005d..3a6d36f9 100644 --- a/TestAssemblies/TypeAssembly/Type.cs +++ b/TestAssemblies/TypeAssembly/Type.cs @@ -101,3 +101,54 @@ public class OtherDerivedClassForAssign : BaseClassForAssign { } public class UnrelatedClassForAssign { } public class OtherUnrelatedClassForAssign { } + +// Member test classes +public class ClassWithStaticField +{ + public static int StaticField; +} + +public class ClassWithNonStaticField +{ + public int NonStaticField; +} + +public class ClassWithReadOnlyField +{ + public readonly string ReadOnlyField = ""; +} + +public class ClassWithWritableProperty +{ + public string WritableProperty { get; set; } = ""; +} + +public class OtherClassWithWritableProperty +{ + public string OtherWritableProperty { get; set; } = ""; +} + +public class ClassWithInitOnlyProperty +{ + public string InitOnlyProperty { get; init; } = ""; +} + +public class ClassWithGetOnlyProperty +{ + public string GetOnlyProperty { get; } = ""; +} + +public class OtherClassWithStaticField +{ + public static int OtherStaticField; +} + +public class ClassWithStaticProperty +{ + public static string StaticProperty { get; set; } = ""; +} + +public class ClassWithStaticMethod +{ + public static void StaticMethod() { } +}