Exemplo n.º 1
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.");
            }
        }
 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();
 }
        public GenericMethodTests()
        {
            var intf = Architecture.GetInterfaceOfType(typeof(IInterfaceWithGenericMethodsWithSameName));

            _oneGenericArgumentMethod = intf.GetMethodMembers()
                                        .First(member => member.GenericParameters.Count == 1);
            _twoGenericArgumentsMethod = intf.GetMethodMembers()
                                         .First(member => member.GenericParameters.Count == 2);
        }
Exemplo n.º 4
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.º 5
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.º 6
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.º 7
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.º 8
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 void FoundCorrectInterfaceInArchitecture()
 {
     Assert.Equal(_architecture.Interfaces
                  .SingleOrDefault(archClass => archClass.Name == nameof(IEntity)),
                  _architecture.GetInterfaceOfType(typeof(IEntity)));
 }
Exemplo n.º 10
0
 public GenericInterfaceTests()
 {
     _genericInterface = _architecture.GetInterfaceOfType(typeof(IGenericInterface <>));
     _genericInterfaceImplementation = _architecture.GetClassOfType(typeof(GenericInterfaceImplementation));
     _genericType = _architecture.GetClassOfType(typeof(GenericType));
 }
Exemplo n.º 11
0
 public void Setup()
 {
     _baseInterface = Architecture.GetInterfaceOfType(typeof(Contracts.IBaseInterface));
 }