Exemplo n.º 1
0
 public ArrayTests()
 {
     _bool = Architecture.GetClassOfType(typeof(bool));
     _int  = Architecture.GetClassOfType(typeof(int));
     _classWithBoolArrayFields = Architecture.GetClassOfType(typeof(ClassWithBoolArrayFields));
     _classWithArrayMethod     = Architecture.GetClassOfType(typeof(ClassWithArrayMethod));
 }
 public KeepDependenciesInAnonymousTypesTests()
 {
     _class1WithAnonymous = Architecture.GetClassOfType(typeof(Class1WithAnonymousType));
     _class2WithAnonymous = Architecture.GetClassOfType(typeof(Class2WithAnonymousType));
     _instantiatedType    = Architecture.GetClassOfType(typeof(InstantiatedType));
     _castType            = Architecture.GetClassOfType(typeof(CastType));
 }
 public PropertyDependencyTests()
 {
     _dependOnClass            = Architecture.GetClassOfType(typeof(PropertyDependOnClass));
     _propertyTestDataClass    = Architecture.GetClassOfType(typeof(PropertyTestDataClass));
     _testStringProperty       = _propertyTestDataClass.GetPropertyMembersWithName("TestStringProperty").ToList().First();
     _testStringPropertyGetter =
         _propertyTestDataClass.GetMethodMembersWithName("get_TestStringProperty()").First();
 }
 public MethodCallDependencyTests()
 {
     _classWithConstructors = _architecture.GetClassOfType(typeof(ClassWithConstructors));
     _methodAMember         = _architecture.GetClassOfType(typeof(ClassWithMethodA))
                              .GetMethodMembersWithName(nameof(ClassWithMethodA.MethodA).BuildMethodMemberName()).FirstOrDefault();
     _methodBMember = _architecture.GetClassOfType(typeof(ClassWithMethodB))
                      .GetMethodMembersWithName(nameof(ClassWithMethodB.MethodB).BuildMethodMemberName()).FirstOrDefault();
 }
 public CastDependenciesTest()
 {
     _castClassA               = Architecture.GetClassOfType(typeof(CastClassA));
     _castClassB               = Architecture.GetClassOfType(typeof(CastClassB));
     _castInterfaceA           = Architecture.GetInterfaceOfType(typeof(ICastInterfaceA));
     _classWithCastDependency  = Architecture.GetClassOfType(typeof(ClassWithCastDependency));
     _methodWithCastDependency = (MethodMember)_classWithCastDependency.Members
                                 .WhereNameIs("MethodWithCastDependencies(ArchUnitNETTests.Dependencies.CastClassA)").ToList().First();
 }
Exemplo n.º 6
0
        public AccessFieldDependenciesTests()
        {
            _classWithNonStaticFields = Architecture.GetClassOfType(typeof(ClassWithNonStaticFields));
            _classWithStaticFields    = Architecture.GetClassOfType(typeof(ClassWithStaticFields));
            _accessingClass           = Architecture.GetClassOfType(typeof(ClassAccessingFields));


            _nonStaticFieldMember = _classWithNonStaticFields.GetFieldMembersWithName("NonStaticField").First();
            _staticFieldMember    = _classWithStaticFields.GetFieldMembersWithName("StaticField").First();
        }
Exemplo n.º 7
0
 public GeneratorDependenciesTests()
 {
     _accessedClass               = Architecture.GetClassOfType(typeof(AccessedClass));
     _accessedStaticField         = _accessedClass.GetFieldMembersWithName(nameof(AccessedClass.StringField)).First();
     _accessedBoolField           = _accessedClass.GetFieldMembersWithName(nameof(AccessedClass.BoolField)).First();
     _accessedStaticMethodAsField =
         _accessedClass.GetFieldMembersWithName(nameof(AccessedClass.StaticMethodAsField)).First();
     _accessedConstructor          = _accessedClass.Constructors.First();
     _accessedStaticMethodWithBody = _accessedClass
                                     .GetMethodMembersWithName(nameof(AccessedClass.StaticMethodWithBody) + "(System.Int32)").First();
 }
        public GenericClassTests()
        {
            _classWithGenericParameters = Architecture.GetClassOfType(typeof(ClassWithGenericParameters <>));
            var invokesGenericClass = Architecture.GetClassOfType(typeof(InvokesGenericClass));

            _genericallyTypedField = invokesGenericClass
                                     .GetFieldMembersWithName(nameof(InvokesGenericClass.GuidGenericArgument)).SingleOrDefault();
            var guidMock = new Type(SystemGuidFullName, GuidClassName,
                                    _classWithGenericParameters.Assembly,
                                    new Namespace(StaticConstants.SystemNamespace, new List <IType>()), Public, false, false, true, false);

            _expectedGenericArgument = new Class(guidMock, false, true, true, false);
        }
 public DependenciesToStaticMethodsTests()
 {
     _accessingClass = Architecture.GetClassOfType(typeof(ClassAccessingStaticMethod));
     _classAccessingStaticMethodInGenerator =
         Architecture.GetClassOfType(typeof(ClassAccessingStaticMethodInGenerator));
     _classAccessingStaticMethodWithoutGenerator =
         Architecture.GetClassOfType(typeof(ClassAccessingStaticMethodWithoutGenerator));
     _classWithStaticMethod      = Architecture.GetClassOfType(typeof(ClassWithStaticMethods));
     _staticMethodMemberWithBody = _classWithStaticMethod
                                   .GetMethodMembersWithName(nameof(ClassWithStaticMethods.StaticMethodWithBody) + "(System.Int32)").First();
     _staticMethodMemberAsField = _classWithStaticMethod
                                  .GetFieldMembersWithName(nameof(ClassWithStaticMethods.StaticMethodAsField)).First();
 }
Exemplo n.º 10
0
        public TypeTests()
        {
            _type = _architecture.GetClassOfType(typeof(AssignClass)).CreateShallowStubType();
            _type.RequiredNotNull();

            _duplicateType = _architecture.GetClassOfType(typeof(AssignClass)).CreateShallowStubType();
            _duplicateType.RequiredNotNull();

            _duplicateReference = _type;

            _exampleInterface = _architecture.GetInterfaceOfType(typeof(IExample));
            _exampleInterface.RequiredNotNull();
            _expectedAttributeClass = _architecture.GetClassOfType(typeof(ExampleAttribute));
        }
Exemplo n.º 11
0
            public MemberEquivalencyTestData([NotNull] Type originType, [NotNull] string originMemberName)
            {
                var methodOriginClass = Architecture.GetClassOfType(originType);

                OriginMember    = methodOriginClass.GetMembersWithName(originMemberName).SingleOrDefault();
                DuplicateMember = methodOriginClass.GetMembersWithName(originMemberName).SingleOrDefault();
            }
Exemplo n.º 12
0
 public ClassEquivalencyTestData([NotNull] System.Type originType)
 {
     OriginClass              = Architecture.GetClassOfType(originType).RequiredNotNull();
     DuplicateClass           = Architecture.GetClassOfType(originType).RequiredNotNull();
     ClassReferenceDuplicate  = OriginClass;
     ObjectReferenceDuplicate = OriginClass;
 }
Exemplo n.º 13
0
        public static IType GetITypeOfType([NotNull] this Architecture architecture, [NotNull] Type type)
        {
            if (type.IsClass)
            {
                return(architecture.GetClassOfType(type));
            }

            if (type.IsInterface)
            {
                return(architecture.GetInterfaceOfType(type));
            }

            try
            {
                var foundType = architecture.Types.WhereFullNameIs(type.FullName);
                if (foundType != null)
                {
                    return(foundType);
                }

                throw new TypeDoesNotExistInArchitecture(
                          $"Type {type.FullName} does not exist in provided architecture.");
            }
            catch (MultipleOccurrencesInSequenceException)
            {
                throw new NotSupportedException(
                          $"Type {type.FullName} found multiple times in provided architecture. Please use extern "
                          + "alias to reference assemblies that have the same fully-qualified type names.");
            }
        }
Exemplo n.º 14
0
 public AttributeEquivalencyTestData([NotNull] System.Type originType)
 {
     OriginAttribute    = new Attribute(Architecture.GetClassOfType(originType));
     DuplicateAttribute =
         new Attribute(Architecture.GetClassOfType(originType));
     AttributeReferenceDuplicate = OriginAttribute;
     ObjectReferenceDuplicate    = OriginAttribute;
 }
Exemplo n.º 15
0
        public RegexUtilsTest()
        {
            var propertyClass = Architecture.GetClassOfType(typeof(BackingFieldExamples));

            _autoPropertyMember        = propertyClass.GetPropertyMembersWithName("AutoProperty").Single();
            _expectedGetMethodName     = BuildExpectedGetMethodName(_autoPropertyMember);
            _expectedGetMethodFullName = BuildExpectedGetMethodFullName(_autoPropertyMember);
            _expectedSetMethodName     = BuildExpectedSetMethodName(_autoPropertyMember, _autoPropertyMember.DeclaringType);
        }
        public GetterSetterMethodDependencyTests()
        {
            var getterExampleClass = _architecture.GetClassOfType(typeof(GetterMethodDependencyExamples));

            getterExampleClass.RequiredNotNull();
            _acceptedCaseProperty         = getterExampleClass.GetPropertyMembersWithName("AcceptedCase").First();
            _firstUnacceptedCaseProperty  = getterExampleClass.GetPropertyMembersWithName("FirstUnacceptedCase").First();
            _secondUnacceptedCaseProperty = getterExampleClass.GetPropertyMembersWithName("SecondUnacceptedCase")
                                            .First();
        }
Exemplo n.º 17
0
        public AttributeDependencyTests()
        {
            var eventHandler = Architecture.GetInterfaceOfType(typeof(IEventHandler <>));

            _eventHandlerImplementClasses = Architecture.Classes.Where(cls => cls.ImplementsInterface(eventHandler));
            _originClass = Architecture.GetClassOfType(typeof(ClassWithInnerAttributeDependency));
            _hello       = Architecture.GetClassOfType(typeof(Hello));
            _helloEvent  = Architecture.GetClassOfType(typeof(HelloEvent));

            _class1             = Architecture.GetClassOfType(typeof(Class1));
            _class2             = Architecture.GetClassOfType(typeof(Class2));
            _classWithAttribute = Architecture.GetClassOfType(typeof(ClassWithExampleAttribute));
            _classWithBodyTypeA = Architecture.GetClassOfType(typeof(ClassWithBodyTypeA));
        }
Exemplo n.º 18
0
        public MemberListTests()
        {
            _fieldA = Architecture.GetClassOfType(typeof(ClassWithFieldA))
                      .GetFieldMembersWithName(nameof(ClassWithFieldA.FieldA)).SingleOrDefault();
            _propertyA = Architecture.GetClassOfType(typeof(ClassWithPropertyA))
                         .GetPropertyMembersWithName(nameof(ClassWithPropertyA.PropertyA)).SingleOrDefault();
            _methodA = Architecture.GetClassOfType(typeof(ClassWithMethodA))
                       .GetMethodMembersWithName(nameof(ClassWithMethodA.MethodA).BuildMethodMemberName()).SingleOrDefault();

            _memberList    = new MemberList();
            _listOfMembers = new List <IMember> {
                _fieldA, _propertyA, _methodA
            };
        }
Exemplo n.º 19
0
        public TypeExtensionTests()
        {
            _methodOriginClass = Architecture.GetClassOfType(typeof(ClassWithMethodA));
            _methodMember      = _methodOriginClass
                                 .GetMembersWithName(nameof(ClassWithMethodA.MethodA).BuildMethodMemberName()).SingleOrDefault();
            _fieldOriginClass    = Architecture.GetClassOfType(typeof(ClassWithFieldA));
            _fieldMember         = _fieldOriginClass.GetMembersWithName(nameof(ClassWithFieldA.FieldA)).SingleOrDefault();
            _propertyOriginClass = Architecture.GetClassOfType(typeof(ClassWithPropertyA));
            _propertyMember      = _propertyOriginClass.GetMembersWithName(nameof(ClassWithPropertyA.PropertyA))
                                   .SingleOrDefault();

            _exampleAttribute = Architecture.GetClassOfType(typeof(ExampleAttribute));
            _regexUtilsTests  = Architecture.GetClassOfType(typeof(RegexUtilsTest));
        }
 public KeepDependenciesInCompilerGeneratedTypesTests()
 {
     _classWithProperty    = Architecture.GetClassOfType(typeof(ClassWithPropertyDependency));
     _classWithLambda      = Architecture.GetClassOfType(typeof(ClassWithLambdaDependency));
     _classWithIndexing    = Architecture.GetClassOfType(typeof(ClassWithIndexingDependency));
     _returnedClass        = Architecture.GetClassOfType(typeof(ReturnedClass));
     _argumentClass        = Architecture.GetClassOfType(typeof(ArgumentClass));
     _genericArgumentClass = Architecture.GetClassOfType(typeof(GenericArgumentClass));
 }
        public void GetNamespaceIdentifierAssociatedWithClass()
        {
            using (MemoryStream memoryStream = new MemoryStream())
            {
                string expectedNamespaceIdentifier = typeof(SomeOriginClass).Namespace;
                ClassDiagramAssociation classDiagramAssociation = CreateAssociation(TestDiagram.From(memoryStream)
                                                                                    .Component("A").WithStereoTypes(expectedNamespaceIdentifier)
                                                                                    .Component("B").WithStereoTypes(".*.Noclasshere")
                                                                                    .Write());

                Class clazz = Architecture.GetClassOfType(typeof(SomeOriginClass));
                Assert.Equal(expectedNamespaceIdentifier, classDiagramAssociation.GetNamespaceIdentifiersFromComponentOf(clazz).Single());
            }
        }
Exemplo n.º 22
0
        public ClassTests()
        {
            _baseClass           = Architecture.GetClassOfType(typeof(BaseClass));
            _childClass          = Architecture.GetClassOfType(typeof(ChildClass));
            _duplicateChildClass = _baseClass;
            var backingType = Architecture.GetITypeOfType(typeof(PropertyType));

            _misMatchType =
                new Type(backingType.FullName, backingType.Name, backingType.Assembly, backingType.Namespace,
                         backingType.Visibility, backingType.IsNested);

            _implementsInterface  = Architecture.GetClassOfType(typeof(InheritingType));
            _implementedInterface = Architecture.GetInterfaceOfType(typeof(IInheritingInterface));
            _chainedInterface     = Architecture.GetInterfaceOfType(typeof(IInheritedTestInterface));

            _classEquivalencyTestData = new ClassEquivalencyTestData(typeof(ClassWithConstructors));
        }
Exemplo n.º 23
0
            public void IncludeReferencedTypesTest()
            {
                var classInTestAssembly = Architecture.GetClassOfType(typeof(ClassInTestAssembly));

                Assert.Contains(classInTestAssembly, Types(true).GetObjects(Architecture));
                Assert.Contains(classInTestAssembly, Classes(true).GetObjects(Architecture));

                var attributeInTestAssembly = Architecture.GetAttributeOfType(typeof(AttributeInTestAssembly));

                Assert.Contains(attributeInTestAssembly, Types(true).GetObjects(Architecture));
                Assert.Contains(attributeInTestAssembly, Attributes(true).GetObjects(Architecture));

                var interfaceInTestAssembly = Architecture.GetInterfaceOfType(typeof(IInterfaceInTestAssembly));

                Assert.Contains(interfaceInTestAssembly, Types(true).GetObjects(Architecture));
                Assert.Contains(interfaceInTestAssembly, Interfaces(true).GetObjects(Architecture));
            }
Exemplo n.º 24
0
 public AttributeTests()
 {
     _developerAttributePair       = new AttributeOriginClassPair(typeof(CountryAttributeWithParameters));
     _abstractAttributePair        = new AttributeOriginClassPair(typeof(ExampleAbstractAttribute));
     _attributeEquivalencyTestData = new AttributeEquivalencyTestData(typeof(CountryAttributeWithParameters));
     _iAttribute = Architecture.GetInterfaceOfType(typeof(IAttribute));
     _interfaceImplementingAttributePair = new AttributeOriginClassPair(typeof(InterfaceImplementingAttribute));
     _implementsAbstractAttribute        = new Attribute(Architecture.GetClassOfType(typeof(ChildOfAbstractAttribute)));
     _unrelatedType = new Type(_abstractAttributePair.OriginClass.Name,
                               _abstractAttributePair.OriginClass.FullName, _abstractAttributePair.OriginClass.Assembly,
                               _abstractAttributePair.OriginClass.Namespace, _abstractAttributePair.OriginClass.Visibility,
                               _abstractAttributePair.OriginClass.IsNested);
     _propertyMember = _implementsAbstractAttribute
                       .GetPropertyMembersWithName(nameof(ChildOfAbstractAttribute.Property)).SingleOrDefault();
     _inheritedFieldMember = _abstractAttributePair.Attribute
                             .GetFieldMembersWithName("_fieldType").SingleOrDefault();
     _constructorAttributePair    = new AttributeOriginClassPair(typeof(ConstructorAttribute));
     _attributeWithAttributesPair = new AttributeOriginClassPair(typeof(AttributeWithAttributes));
 }
 public DependenciesToStaticMethodsTests()
 {
     _accessingClass        = Architecture.GetClassOfType(typeof(ClassAccessingStaticMethod));
     _classWithStaticMethod = Architecture.GetClassOfType(typeof(ClassWithStaticMethod));
     _staticMethodMember    = _classWithStaticMethod.GetMethodMembersWithName("StaticMethod(System.Int32)").First();
 }
 public BaseClassTest()
 {
     _baseClass  = _architecture.GetClassOfType(typeof(BaseClass));
     _childClass = _architecture.GetClassOfType(typeof(ChildClass));
 }
Exemplo n.º 27
0
 public AttributeOriginClassPair(System.Type originType)
 {
     OriginClass = Architecture.GetClassOfType(originType);
     Attribute   = Architecture.GetAttributeOfType(originType);
 }
 public TypeCheckDependenciesTests()
 {
     _classWithTypeDepencency = Architecture.GetClassOfType(typeof(ClassWithTypeDependency));
     _dependingClass          = Architecture.GetClassOfType(typeof(DependingClass));
 }
        public GetterSetterMethodDependencyTests()
        {
            var getterExampleClass = _architecture.GetClassOfType(typeof(GetterMethodDependencyExamples));

            getterExampleClass.RequiredNotNull();
        }
 public void FoundCorrectClassInArchitecture()
 {
     Assert.Equal(_architecture.Classes.SingleOrDefault(archClass => archClass.Name == nameof(Class1)),
                  _architecture.GetClassOfType(typeof(Class1)));
 }