Esempio n. 1
0
        public void CanFindClassesWithDataTransferObjectAttribute()
        {
            var typesWithDtoAttribute =
                _resolver.GetTypesWithDataTransferObjectAttribute(Assembly.GetExecutingAssembly());

            typesWithDtoAttribute.Should()
            .Contain(new[] { typeof(ClassC <>), typeof(ClassB) })
            .And.NotContain(typeof(ClassA));
        }
        /// <summary>
        /// Mappings between api response DTOs and domain objects.
        /// We use reflection based on class attribute to map them.
        /// </summary>
        /// <param name="dtoResolver"></param>
        public DtoMappingProfile(IDataTransferObjectResolver dtoResolver)
        {
            var domainObjects = dtoResolver
                                .GetTypesWithDataTransferObjectAttribute(Assembly.GetExecutingAssembly());

            foreach (var domainObject in domainObjects)
            {
                var dtoType = dtoResolver.GetDataTransferObject(domainObject);
                CreateMap(dtoType, domainObject)
                .ConstructUsingServiceLocator();
                CreateMap(domainObject, dtoType);
            }
        }