diff --git a/src/Umbraco.Core/CoreBootManager.cs b/src/Umbraco.Core/CoreBootManager.cs index 18deba3b0a..11ee5b4eab 100644 --- a/src/Umbraco.Core/CoreBootManager.cs +++ b/src/Umbraco.Core/CoreBootManager.cs @@ -196,6 +196,9 @@ namespace Umbraco.Core ServerMessengerResolver.Current = new ServerMessengerResolver( new DefaultServerMessenger()); + MappingResolver.Current = new MappingResolver( + () => PluginManager.Current.ResolveAssignedMapperTypes()); + RepositoryResolver.Current = new RepositoryResolver( new RepositoryFactory()); diff --git a/src/Umbraco.Core/Models/Content.cs b/src/Umbraco.Core/Models/Content.cs index 10c28f0329..d7a6cfd0a4 100644 --- a/src/Umbraco.Core/Models/Content.cs +++ b/src/Umbraco.Core/Models/Content.cs @@ -12,7 +12,6 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - [Mapper(typeof(ContentMapper))] public class Content : ContentBase, IContent { private IContentType _contentType; diff --git a/src/Umbraco.Core/Models/ContentType.cs b/src/Umbraco.Core/Models/ContentType.cs index 33d38fb108..f10e939489 100644 --- a/src/Umbraco.Core/Models/ContentType.cs +++ b/src/Umbraco.Core/Models/ContentType.cs @@ -12,7 +12,6 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - [Mapper(typeof(ContentTypeMapper))] public class ContentType : ContentTypeCompositionBase, IContentType { private int _defaultTemplate; diff --git a/src/Umbraco.Core/Models/DataTypeDefinition.cs b/src/Umbraco.Core/Models/DataTypeDefinition.cs index dde0f7ee84..7d42a7e6b4 100644 --- a/src/Umbraco.Core/Models/DataTypeDefinition.cs +++ b/src/Umbraco.Core/Models/DataTypeDefinition.cs @@ -15,7 +15,6 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - [Mapper(typeof(DataTypeDefinitionMapper))] public class DataTypeDefinition : Entity, IDataTypeDefinition { private int _parentId; diff --git a/src/Umbraco.Core/Models/DictionaryItem.cs b/src/Umbraco.Core/Models/DictionaryItem.cs index dd9742a485..77fda51466 100644 --- a/src/Umbraco.Core/Models/DictionaryItem.cs +++ b/src/Umbraco.Core/Models/DictionaryItem.cs @@ -12,7 +12,6 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - [Mapper(typeof(DictionaryMapper))] public class DictionaryItem : Entity, IDictionaryItem { private Guid _parentId; diff --git a/src/Umbraco.Core/Models/DictionaryTranslation.cs b/src/Umbraco.Core/Models/DictionaryTranslation.cs index 4be6ea58e6..532d762cd3 100644 --- a/src/Umbraco.Core/Models/DictionaryTranslation.cs +++ b/src/Umbraco.Core/Models/DictionaryTranslation.cs @@ -11,7 +11,6 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - [Mapper(typeof(DictionaryTranslationMapper))] public class DictionaryTranslation : Entity, IDictionaryTranslation { private ILanguage _language; diff --git a/src/Umbraco.Core/Models/IContent.cs b/src/Umbraco.Core/Models/IContent.cs index 25506b622b..c77ff8bbdb 100644 --- a/src/Umbraco.Core/Models/IContent.cs +++ b/src/Umbraco.Core/Models/IContent.cs @@ -7,7 +7,6 @@ namespace Umbraco.Core.Models /// /// Defines a Content object /// - [Mapper(typeof(ContentMapper))] public interface IContent : IContentBase { /// diff --git a/src/Umbraco.Core/Models/IContentType.cs b/src/Umbraco.Core/Models/IContentType.cs index ea084d7a40..c8cba83a37 100644 --- a/src/Umbraco.Core/Models/IContentType.cs +++ b/src/Umbraco.Core/Models/IContentType.cs @@ -6,7 +6,6 @@ namespace Umbraco.Core.Models /// /// Defines a ContentType, which Content is based on /// - [Mapper(typeof(ContentTypeMapper))] public interface IContentType : IContentTypeComposition { /// diff --git a/src/Umbraco.Core/Models/IDataTypeDefinition.cs b/src/Umbraco.Core/Models/IDataTypeDefinition.cs index 277ff4a7e3..5f0299e24b 100644 --- a/src/Umbraco.Core/Models/IDataTypeDefinition.cs +++ b/src/Umbraco.Core/Models/IDataTypeDefinition.cs @@ -4,7 +4,6 @@ using Umbraco.Core.Persistence.Mappers; namespace Umbraco.Core.Models { - [Mapper(typeof(DataTypeDefinitionMapper))] public interface IDataTypeDefinition : IUmbracoEntity { /// diff --git a/src/Umbraco.Core/Models/IDictionaryItem.cs b/src/Umbraco.Core/Models/IDictionaryItem.cs index eb2e6bd6f8..4f457e97a4 100644 --- a/src/Umbraco.Core/Models/IDictionaryItem.cs +++ b/src/Umbraco.Core/Models/IDictionaryItem.cs @@ -6,7 +6,6 @@ using Umbraco.Core.Persistence.Mappers; namespace Umbraco.Core.Models { - [Mapper(typeof(DictionaryMapper))] public interface IDictionaryItem : IAggregateRoot { /// diff --git a/src/Umbraco.Core/Models/IDictionaryTranslation.cs b/src/Umbraco.Core/Models/IDictionaryTranslation.cs index 1ae07486ea..cf813bf72f 100644 --- a/src/Umbraco.Core/Models/IDictionaryTranslation.cs +++ b/src/Umbraco.Core/Models/IDictionaryTranslation.cs @@ -4,7 +4,6 @@ using Umbraco.Core.Persistence.Mappers; namespace Umbraco.Core.Models { - [Mapper(typeof(DictionaryTranslationMapper))] public interface IDictionaryTranslation : IEntity { /// diff --git a/src/Umbraco.Core/Models/ILanguage.cs b/src/Umbraco.Core/Models/ILanguage.cs index 0b6e3cea93..cab97c7eb7 100644 --- a/src/Umbraco.Core/Models/ILanguage.cs +++ b/src/Umbraco.Core/Models/ILanguage.cs @@ -5,7 +5,6 @@ using Umbraco.Core.Persistence.Mappers; namespace Umbraco.Core.Models { - [Mapper(typeof(LanguageMapper))] public interface ILanguage : IAggregateRoot { /// diff --git a/src/Umbraco.Core/Models/IMedia.cs b/src/Umbraco.Core/Models/IMedia.cs index 7bd35d6f64..755d99eddb 100644 --- a/src/Umbraco.Core/Models/IMedia.cs +++ b/src/Umbraco.Core/Models/IMedia.cs @@ -2,7 +2,6 @@ namespace Umbraco.Core.Models { - [Mapper(typeof(MediaMapper))] public interface IMedia : IContentBase { /// diff --git a/src/Umbraco.Core/Models/IMediaType.cs b/src/Umbraco.Core/Models/IMediaType.cs index 7ec7329537..3934d7a40f 100644 --- a/src/Umbraco.Core/Models/IMediaType.cs +++ b/src/Umbraco.Core/Models/IMediaType.cs @@ -4,8 +4,7 @@ namespace Umbraco.Core.Models { /// /// Defines a ContentType, which Media is based on - /// - [Mapper(typeof(MediaTypeMapper))] + /// [Serializable] [DataContract(IsReference = true)] - [Mapper(typeof(LanguageMapper))] public class Language : Entity, ILanguage { private string _isoCode; diff --git a/src/Umbraco.Core/Models/Media.cs b/src/Umbraco.Core/Models/Media.cs index a30ec79d7c..4f922d28cf 100644 --- a/src/Umbraco.Core/Models/Media.cs +++ b/src/Umbraco.Core/Models/Media.cs @@ -9,7 +9,6 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - [Mapper(typeof(MediaMapper))] public class Media : ContentBase, IMedia { private IMediaType _contentType; diff --git a/src/Umbraco.Core/Models/MediaType.cs b/src/Umbraco.Core/Models/MediaType.cs index e505ead334..0fb4bd171b 100644 --- a/src/Umbraco.Core/Models/MediaType.cs +++ b/src/Umbraco.Core/Models/MediaType.cs @@ -9,7 +9,6 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - [Mapper(typeof(MediaTypeMapper))] public class MediaType : ContentTypeCompositionBase, IMediaType { public MediaType(int parentId) : base(parentId) diff --git a/src/Umbraco.Core/Models/Membership/IUser.cs b/src/Umbraco.Core/Models/Membership/IUser.cs index c43cd4ca59..005720007d 100644 --- a/src/Umbraco.Core/Models/Membership/IUser.cs +++ b/src/Umbraco.Core/Models/Membership/IUser.cs @@ -7,7 +7,6 @@ namespace Umbraco.Core.Models.Membership /// Defines the interface for a /// /// Will be left internal until a proper Membership implementation is part of the roadmap - [Mapper(typeof(UserMapper))] internal interface IUser : IMembershipUser { string Name { get; set; } diff --git a/src/Umbraco.Core/Models/Membership/IUserType.cs b/src/Umbraco.Core/Models/Membership/IUserType.cs index 7af8c104f7..aa837bf890 100644 --- a/src/Umbraco.Core/Models/Membership/IUserType.cs +++ b/src/Umbraco.Core/Models/Membership/IUserType.cs @@ -3,7 +3,7 @@ using Umbraco.Core.Persistence.Mappers; namespace Umbraco.Core.Models.Membership { - [Mapper(typeof(UserTypeMapper))] + internal interface IUserType : IAggregateRoot { string Alias { get; set; } diff --git a/src/Umbraco.Core/Models/Membership/User.cs b/src/Umbraco.Core/Models/Membership/User.cs index 371c621d51..95c81abdc7 100644 --- a/src/Umbraco.Core/Models/Membership/User.cs +++ b/src/Umbraco.Core/Models/Membership/User.cs @@ -16,7 +16,6 @@ namespace Umbraco.Core.Models.Membership /// [Serializable] [DataContract(IsReference = true)] - [Mapper(typeof(UserMapper))] internal class User : UserProfile, IUser { private bool _hasIdentity; diff --git a/src/Umbraco.Core/Models/Membership/UserType.cs b/src/Umbraco.Core/Models/Membership/UserType.cs index be90dfa7e8..b09a568c22 100644 --- a/src/Umbraco.Core/Models/Membership/UserType.cs +++ b/src/Umbraco.Core/Models/Membership/UserType.cs @@ -14,7 +14,6 @@ namespace Umbraco.Core.Models.Membership /// [Serializable] [DataContract(IsReference = true)] - [Mapper(typeof(UserTypeMapper))] internal class UserType : Entity, IUserType { [DataMember] diff --git a/src/Umbraco.Core/Models/Property.cs b/src/Umbraco.Core/Models/Property.cs index 62895090d2..7ac301f807 100644 --- a/src/Umbraco.Core/Models/Property.cs +++ b/src/Umbraco.Core/Models/Property.cs @@ -11,7 +11,6 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - [Mapper(typeof(PropertyMapper))] public class Property : Entity { private readonly PropertyType _propertyType; diff --git a/src/Umbraco.Core/Models/PropertyGroup.cs b/src/Umbraco.Core/Models/PropertyGroup.cs index ec78be87af..395d0b7992 100644 --- a/src/Umbraco.Core/Models/PropertyGroup.cs +++ b/src/Umbraco.Core/Models/PropertyGroup.cs @@ -12,7 +12,6 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - [Mapper(typeof(PropertyGroupMapper))] public class PropertyGroup : Entity, IEquatable { private string _name; diff --git a/src/Umbraco.Core/Models/PropertyType.cs b/src/Umbraco.Core/Models/PropertyType.cs index abb62ce54f..b670693519 100644 --- a/src/Umbraco.Core/Models/PropertyType.cs +++ b/src/Umbraco.Core/Models/PropertyType.cs @@ -12,7 +12,6 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - [Mapper(typeof(PropertyTypeMapper))] public class PropertyType : Entity, IEquatable { //private SerializationService _service; diff --git a/src/Umbraco.Core/Models/Relation.cs b/src/Umbraco.Core/Models/Relation.cs index 5ecb372c2b..2dc1bd877e 100644 --- a/src/Umbraco.Core/Models/Relation.cs +++ b/src/Umbraco.Core/Models/Relation.cs @@ -11,7 +11,6 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - [Mapper(typeof(RelationMapper))] public class Relation : Entity, IAggregateRoot { //NOTE: The datetime column from umbracoRelation is set on CreateDate on the Entity diff --git a/src/Umbraco.Core/Models/RelationType.cs b/src/Umbraco.Core/Models/RelationType.cs index bb420286dd..e7f9dcbd76 100644 --- a/src/Umbraco.Core/Models/RelationType.cs +++ b/src/Umbraco.Core/Models/RelationType.cs @@ -11,7 +11,6 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - [Mapper(typeof(RelationTypeMapper))] public class RelationType : Entity, IAggregateRoot { private string _name; diff --git a/src/Umbraco.Core/Models/ServerRegistration.cs b/src/Umbraco.Core/Models/ServerRegistration.cs index 49770485b5..32282b4f79 100644 --- a/src/Umbraco.Core/Models/ServerRegistration.cs +++ b/src/Umbraco.Core/Models/ServerRegistration.cs @@ -5,7 +5,6 @@ using Umbraco.Core.Sync; namespace Umbraco.Core.Models { - [Mapper(typeof(ServerRegistrationMapper))] internal class ServerRegistration : Entity, IServerAddress, IAggregateRoot { public ServerRegistration() diff --git a/src/Umbraco.Core/Persistence/Mappers/BaseMapper.cs b/src/Umbraco.Core/Persistence/Mappers/BaseMapper.cs index 76ac6af949..a5e1700566 100644 --- a/src/Umbraco.Core/Persistence/Mappers/BaseMapper.cs +++ b/src/Umbraco.Core/Persistence/Mappers/BaseMapper.cs @@ -5,7 +5,7 @@ using Umbraco.Core.Persistence.SqlSyntax; namespace Umbraco.Core.Persistence.Mappers { - internal abstract class BaseMapper + public abstract class BaseMapper { internal abstract void BuildMap(); diff --git a/src/Umbraco.Core/Persistence/Mappers/ContentMapper.cs b/src/Umbraco.Core/Persistence/Mappers/ContentMapper.cs index 34023400be..3c96d9d60d 100644 --- a/src/Umbraco.Core/Persistence/Mappers/ContentMapper.cs +++ b/src/Umbraco.Core/Persistence/Mappers/ContentMapper.cs @@ -10,7 +10,9 @@ namespace Umbraco.Core.Persistence.Mappers /// Represents a to DTO mapper used to translate the properties of the public api /// implementation to that of the database's DTO as sql: [tableName].[columnName]. /// - internal sealed class ContentMapper : BaseMapper + [MapperFor(typeof(Content))] + [MapperFor(typeof(IContent))] + public sealed class ContentMapper : BaseMapper { private static readonly ConcurrentDictionary PropertyInfoCache = new ConcurrentDictionary(); diff --git a/src/Umbraco.Core/Persistence/Mappers/ContentTypeMapper.cs b/src/Umbraco.Core/Persistence/Mappers/ContentTypeMapper.cs index fb1f4e89ca..c15b0a09fd 100644 --- a/src/Umbraco.Core/Persistence/Mappers/ContentTypeMapper.cs +++ b/src/Umbraco.Core/Persistence/Mappers/ContentTypeMapper.cs @@ -10,7 +10,9 @@ namespace Umbraco.Core.Persistence.Mappers /// Represents a to DTO mapper used to translate the properties of the public api /// implementation to that of the database's DTO as sql: [tableName].[columnName]. /// - internal sealed class ContentTypeMapper : BaseMapper + [MapperFor(typeof(ContentType))] + [MapperFor(typeof(IContentType))] + public sealed class ContentTypeMapper : BaseMapper { private static readonly ConcurrentDictionary PropertyInfoCache = new ConcurrentDictionary(); diff --git a/src/Umbraco.Core/Persistence/Mappers/DataTypeDefinitionMapper.cs b/src/Umbraco.Core/Persistence/Mappers/DataTypeDefinitionMapper.cs index 69bb08afb5..27cd0e08c9 100644 --- a/src/Umbraco.Core/Persistence/Mappers/DataTypeDefinitionMapper.cs +++ b/src/Umbraco.Core/Persistence/Mappers/DataTypeDefinitionMapper.cs @@ -10,7 +10,9 @@ namespace Umbraco.Core.Persistence.Mappers /// Represents a to DTO mapper used to translate the properties of the public api /// implementation to that of the database's DTO as sql: [tableName].[columnName]. /// - internal sealed class DataTypeDefinitionMapper : BaseMapper + [MapperFor(typeof(DataTypeDefinition))] + [MapperFor(typeof(IDataTypeDefinition))] + public sealed class DataTypeDefinitionMapper : BaseMapper { private static readonly ConcurrentDictionary PropertyInfoCache = new ConcurrentDictionary(); diff --git a/src/Umbraco.Core/Persistence/Mappers/DictionaryMapper.cs b/src/Umbraco.Core/Persistence/Mappers/DictionaryMapper.cs index 459704e63d..55b7246c3f 100644 --- a/src/Umbraco.Core/Persistence/Mappers/DictionaryMapper.cs +++ b/src/Umbraco.Core/Persistence/Mappers/DictionaryMapper.cs @@ -10,7 +10,9 @@ namespace Umbraco.Core.Persistence.Mappers /// Represents a to DTO mapper used to translate the properties of the public api /// implementation to that of the database's DTO as sql: [tableName].[columnName]. /// - internal sealed class DictionaryMapper : BaseMapper + [MapperFor(typeof(DictionaryItem))] + [MapperFor(typeof(IDictionaryItem))] + public sealed class DictionaryMapper : BaseMapper { private static readonly ConcurrentDictionary PropertyInfoCache = new ConcurrentDictionary(); diff --git a/src/Umbraco.Core/Persistence/Mappers/DictionaryTranslationMapper.cs b/src/Umbraco.Core/Persistence/Mappers/DictionaryTranslationMapper.cs index ef45899595..be42a5bbb2 100644 --- a/src/Umbraco.Core/Persistence/Mappers/DictionaryTranslationMapper.cs +++ b/src/Umbraco.Core/Persistence/Mappers/DictionaryTranslationMapper.cs @@ -10,7 +10,9 @@ namespace Umbraco.Core.Persistence.Mappers /// Represents a to DTO mapper used to translate the properties of the public api /// implementation to that of the database's DTO as sql: [tableName].[columnName]. /// - internal class DictionaryTranslationMapper : BaseMapper + [MapperFor(typeof(DictionaryTranslation))] + [MapperFor(typeof(IDictionaryTranslation))] + public class DictionaryTranslationMapper : BaseMapper { private static readonly ConcurrentDictionary PropertyInfoCache = new ConcurrentDictionary(); diff --git a/src/Umbraco.Core/Persistence/Mappers/LanguageMapper.cs b/src/Umbraco.Core/Persistence/Mappers/LanguageMapper.cs index 289decec4e..99ffe4fb6c 100644 --- a/src/Umbraco.Core/Persistence/Mappers/LanguageMapper.cs +++ b/src/Umbraco.Core/Persistence/Mappers/LanguageMapper.cs @@ -10,7 +10,9 @@ namespace Umbraco.Core.Persistence.Mappers /// Represents a to DTO mapper used to translate the properties of the public api /// implementation to that of the database's DTO as sql: [tableName].[columnName]. /// - internal sealed class LanguageMapper : BaseMapper + [MapperFor(typeof(ILanguage))] + [MapperFor(typeof(Language))] + public sealed class LanguageMapper : BaseMapper { private static readonly ConcurrentDictionary PropertyInfoCache = new ConcurrentDictionary(); diff --git a/src/Umbraco.Core/Persistence/Mappers/MapperForAttribute.cs b/src/Umbraco.Core/Persistence/Mappers/MapperForAttribute.cs new file mode 100644 index 0000000000..44ee135b07 --- /dev/null +++ b/src/Umbraco.Core/Persistence/Mappers/MapperForAttribute.cs @@ -0,0 +1,19 @@ +using System; + +namespace Umbraco.Core.Persistence.Mappers +{ + /// + /// An attribute used to decorate mappers to be associated with entities + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] + internal sealed class MapperForAttribute : Attribute + { + public Type EntityType { get; private set; } + + public MapperForAttribute(Type entityType) + { + EntityType = entityType; + } + } + +} \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Mappers/MappingResolver.cs b/src/Umbraco.Core/Persistence/Mappers/MappingResolver.cs index abb220a66c..9fa1846629 100644 --- a/src/Umbraco.Core/Persistence/Mappers/MappingResolver.cs +++ b/src/Umbraco.Core/Persistence/Mappers/MappingResolver.cs @@ -1,29 +1,41 @@ using System; using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.Membership; +using Umbraco.Core.ObjectResolution; namespace Umbraco.Core.Persistence.Mappers { - internal static class MappingResolver + internal class MappingResolver : LazyManyObjectsResolverBase { + /// + /// Constructor accepting a list of BaseMapper types that are attributed with the MapperFor attribute + /// + /// + public MappingResolver(Func> assignedMapperTypes) + : base(assignedMapperTypes) + { + + } + /// /// Caches the type -> mapper so that we don't have to type check each time we want one or lookup the attribute /// - private static readonly ConcurrentDictionary MapperCache = new ConcurrentDictionary(); + private readonly ConcurrentDictionary _mapperCache = new ConcurrentDictionary(); /// /// Return a mapper by type /// /// /// - internal static BaseMapper ResolveMapperByType(Type type) + internal BaseMapper ResolveMapperByType(Type type) { - return MapperCache.GetOrAdd(type, type1 => + return _mapperCache.GetOrAdd(type, type1 => { - var mappers = TypeFinder.FindClassesOfTypeWithAttribute(); - + //first check if we can resolve it by attribute var byAttribute = TryGetMapperByAttribute(type); @@ -43,30 +55,37 @@ namespace Umbraco.Core.Persistence.Mappers /// /// Check the entity type to see if it has a mapper attribute assigned and try to instantiate it /// - /// + /// /// - private static Attempt TryGetMapperByAttribute(Type type) + private Attempt TryGetMapperByAttribute(Type entityType) { - var attribute = type.GetCustomAttribute(false); - if (attribute == null) + //get all BaseMapper types that have a MapperFor attribute: + var assignedMapperTypes = InstanceTypes; + + //check if any of the mappers are assigned to this type + var mapper = assignedMapperTypes.FirstOrDefault( + x => x.GetCustomAttributes(false) + .Any(m => m.EntityType == entityType)); + + if (mapper == null) { return Attempt.False; } try { - var instance = Activator.CreateInstance(attribute.MapperType) as BaseMapper; + var instance = Activator.CreateInstance(mapper) as BaseMapper; return instance != null ? new Attempt(true, instance) : Attempt.False; } catch (Exception ex) { - LogHelper.Error(typeof(MappingResolver), "Could not instantiate mapper of type " + attribute.MapperType, ex); + LogHelper.Error(typeof(MappingResolver), "Could not instantiate mapper of type " + mapper, ex); return new Attempt(ex); } } - internal static string GetMapping(Type type, string propertyName) + internal string GetMapping(Type type, string propertyName) { var mapper = ResolveMapperByType(type); var result = mapper.Map(propertyName); @@ -75,5 +94,7 @@ namespace Umbraco.Core.Persistence.Mappers return result; } + } + } \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Mappers/MediaMapper.cs b/src/Umbraco.Core/Persistence/Mappers/MediaMapper.cs index 8f28ac1ec5..7c8612164e 100644 --- a/src/Umbraco.Core/Persistence/Mappers/MediaMapper.cs +++ b/src/Umbraco.Core/Persistence/Mappers/MediaMapper.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Concurrent; using System.Linq.Expressions; +using Umbraco.Core.Models; using Umbraco.Core.Models.Rdbms; namespace Umbraco.Core.Persistence.Mappers @@ -9,7 +10,9 @@ namespace Umbraco.Core.Persistence.Mappers /// Represents a to DTO mapper used to translate the properties of the public api /// implementation to that of the database's DTO as sql: [tableName].[columnName]. /// - internal sealed class MediaMapper : BaseMapper + [MapperFor(typeof(IMedia))] + [MapperFor(typeof(Umbraco.Core.Models.Media))] + public sealed class MediaMapper : BaseMapper { private static readonly ConcurrentDictionary PropertyInfoCache = new ConcurrentDictionary(); diff --git a/src/Umbraco.Core/Persistence/Mappers/MediaTypeMapper.cs b/src/Umbraco.Core/Persistence/Mappers/MediaTypeMapper.cs index 245d8dca76..dd412edfd0 100644 --- a/src/Umbraco.Core/Persistence/Mappers/MediaTypeMapper.cs +++ b/src/Umbraco.Core/Persistence/Mappers/MediaTypeMapper.cs @@ -10,7 +10,9 @@ namespace Umbraco.Core.Persistence.Mappers /// Represents a to DTO mapper used to translate the properties of the public api /// implementation to that of the database's DTO as sql: [tableName].[columnName]. /// - internal sealed class MediaTypeMapper : BaseMapper + [MapperFor(typeof(IMediaType))] + [MapperFor(typeof(MediaType))] + public sealed class MediaTypeMapper : BaseMapper { private static readonly ConcurrentDictionary PropertyInfoCache = new ConcurrentDictionary(); diff --git a/src/Umbraco.Core/Persistence/Mappers/PropertyGroupMapper.cs b/src/Umbraco.Core/Persistence/Mappers/PropertyGroupMapper.cs index a43de4e1c4..241da5bbe0 100644 --- a/src/Umbraco.Core/Persistence/Mappers/PropertyGroupMapper.cs +++ b/src/Umbraco.Core/Persistence/Mappers/PropertyGroupMapper.cs @@ -10,7 +10,8 @@ namespace Umbraco.Core.Persistence.Mappers /// Represents a to DTO mapper used to translate the properties of the public api /// implementation to that of the database's DTO as sql: [tableName].[columnName]. /// - internal sealed class PropertyGroupMapper : BaseMapper + [MapperFor(typeof(PropertyGroup))] + public sealed class PropertyGroupMapper : BaseMapper { private static readonly ConcurrentDictionary PropertyInfoCache = new ConcurrentDictionary(); diff --git a/src/Umbraco.Core/Persistence/Mappers/PropertyMapper.cs b/src/Umbraco.Core/Persistence/Mappers/PropertyMapper.cs index 3746fa7697..7d3d5d357c 100644 --- a/src/Umbraco.Core/Persistence/Mappers/PropertyMapper.cs +++ b/src/Umbraco.Core/Persistence/Mappers/PropertyMapper.cs @@ -6,7 +6,8 @@ using Umbraco.Core.Models.Rdbms; namespace Umbraco.Core.Persistence.Mappers { - internal sealed class PropertyMapper : BaseMapper + [MapperFor(typeof(Property))] + public sealed class PropertyMapper : BaseMapper { private static readonly ConcurrentDictionary PropertyInfoCache = new ConcurrentDictionary(); diff --git a/src/Umbraco.Core/Persistence/Mappers/PropertyTypeMapper.cs b/src/Umbraco.Core/Persistence/Mappers/PropertyTypeMapper.cs index e2ba7d93f2..99bc8a5a1a 100644 --- a/src/Umbraco.Core/Persistence/Mappers/PropertyTypeMapper.cs +++ b/src/Umbraco.Core/Persistence/Mappers/PropertyTypeMapper.cs @@ -10,7 +10,8 @@ namespace Umbraco.Core.Persistence.Mappers /// Represents a to DTO mapper used to translate the properties of the public api /// implementation to that of the database's DTO as sql: [tableName].[columnName]. /// - internal sealed class PropertyTypeMapper : BaseMapper + [MapperFor(typeof(PropertyType))] + public sealed class PropertyTypeMapper : BaseMapper { private static readonly ConcurrentDictionary PropertyInfoCache = new ConcurrentDictionary(); diff --git a/src/Umbraco.Core/Persistence/Mappers/RelationMapper.cs b/src/Umbraco.Core/Persistence/Mappers/RelationMapper.cs index 9175516599..1b211795ff 100644 --- a/src/Umbraco.Core/Persistence/Mappers/RelationMapper.cs +++ b/src/Umbraco.Core/Persistence/Mappers/RelationMapper.cs @@ -10,7 +10,8 @@ namespace Umbraco.Core.Persistence.Mappers /// Represents a to DTO mapper used to translate the properties of the public api /// implementation to that of the database's DTO as sql: [tableName].[columnName]. /// - internal sealed class RelationMapper : BaseMapper + [MapperFor(typeof(Relation))] + public sealed class RelationMapper : BaseMapper { private static readonly ConcurrentDictionary PropertyInfoCache = new ConcurrentDictionary(); diff --git a/src/Umbraco.Core/Persistence/Mappers/RelationTypeMapper.cs b/src/Umbraco.Core/Persistence/Mappers/RelationTypeMapper.cs index 8659dddbec..57461ba288 100644 --- a/src/Umbraco.Core/Persistence/Mappers/RelationTypeMapper.cs +++ b/src/Umbraco.Core/Persistence/Mappers/RelationTypeMapper.cs @@ -10,7 +10,8 @@ namespace Umbraco.Core.Persistence.Mappers /// Represents a to DTO mapper used to translate the properties of the public api /// implementation to that of the database's DTO as sql: [tableName].[columnName]. /// - internal sealed class RelationTypeMapper : BaseMapper + [MapperFor(typeof(RelationType))] + public sealed class RelationTypeMapper : BaseMapper { private static readonly ConcurrentDictionary PropertyInfoCache = new ConcurrentDictionary(); diff --git a/src/Umbraco.Core/Persistence/Mappers/ServerRegistrationMapper.cs b/src/Umbraco.Core/Persistence/Mappers/ServerRegistrationMapper.cs index 8d2a8dbf3d..8f3c465564 100644 --- a/src/Umbraco.Core/Persistence/Mappers/ServerRegistrationMapper.cs +++ b/src/Umbraco.Core/Persistence/Mappers/ServerRegistrationMapper.cs @@ -6,7 +6,8 @@ using Umbraco.Core.Models.Rdbms; namespace Umbraco.Core.Persistence.Mappers { - internal sealed class ServerRegistrationMapper : BaseMapper + [MapperFor(typeof(ServerRegistration))] + public sealed class ServerRegistrationMapper : BaseMapper { private static readonly ConcurrentDictionary PropertyInfoCache = new ConcurrentDictionary(); diff --git a/src/Umbraco.Core/Persistence/Mappers/UserMapper.cs b/src/Umbraco.Core/Persistence/Mappers/UserMapper.cs index ce750b4ed2..a8235374be 100644 --- a/src/Umbraco.Core/Persistence/Mappers/UserMapper.cs +++ b/src/Umbraco.Core/Persistence/Mappers/UserMapper.cs @@ -6,7 +6,9 @@ using Umbraco.Core.Models.Rdbms; namespace Umbraco.Core.Persistence.Mappers { - internal sealed class UserMapper : BaseMapper + [MapperFor(typeof(IUser))] + [MapperFor(typeof(User))] + public sealed class UserMapper : BaseMapper { private static readonly ConcurrentDictionary PropertyInfoCache = new ConcurrentDictionary(); diff --git a/src/Umbraco.Core/Persistence/Mappers/UserTypeMapper.cs b/src/Umbraco.Core/Persistence/Mappers/UserTypeMapper.cs index ad62bc51e0..6858ff0610 100644 --- a/src/Umbraco.Core/Persistence/Mappers/UserTypeMapper.cs +++ b/src/Umbraco.Core/Persistence/Mappers/UserTypeMapper.cs @@ -10,7 +10,9 @@ namespace Umbraco.Core.Persistence.Mappers /// Represents a to DTO mapper used to translate the properties of the public api /// implementation to that of the database's DTO as sql: [tableName].[columnName]. /// - internal sealed class UserTypeMapper : BaseMapper + [MapperFor(typeof(IUserType))] + [MapperFor(typeof(UserType))] + public sealed class UserTypeMapper : BaseMapper { private static readonly ConcurrentDictionary PropertyInfoCache = new ConcurrentDictionary(); diff --git a/src/Umbraco.Core/Persistence/Querying/ModelToSqlExpressionHelper.cs b/src/Umbraco.Core/Persistence/Querying/ModelToSqlExpressionHelper.cs index dff000acc2..254133fe8e 100644 --- a/src/Umbraco.Core/Persistence/Querying/ModelToSqlExpressionHelper.cs +++ b/src/Umbraco.Core/Persistence/Querying/ModelToSqlExpressionHelper.cs @@ -15,7 +15,7 @@ namespace Umbraco.Core.Persistence.Querying public ModelToSqlExpressionHelper() { - _mapper = MappingResolver.ResolveMapperByType(typeof(T)); + _mapper = MappingResolver.Current.ResolveMapperByType(typeof(T)); } protected internal virtual string Visit(Expression exp) diff --git a/src/Umbraco.Core/PluginManager.cs b/src/Umbraco.Core/PluginManager.cs index edf36f90f8..d75cea37fa 100644 --- a/src/Umbraco.Core/PluginManager.cs +++ b/src/Umbraco.Core/PluginManager.cs @@ -11,6 +11,7 @@ using System.Xml.Linq; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; +using Umbraco.Core.Persistence.Mappers; using Umbraco.Core.Persistence.Migrations; using Umbraco.Core.Persistence.SqlSyntax; using Umbraco.Core.PropertyEditors; @@ -495,6 +496,15 @@ namespace Umbraco.Core return ResolveTypes(); } + /// + /// Returns all mapper types that have a MapperFor attribute defined + /// + /// + internal IEnumerable ResolveAssignedMapperTypes() + { + return ResolveTypesWithAttribute(); + } + /// /// Returns all available IMigrations in application /// diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index d18045b8c7..c67b0ad5e8 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -225,7 +225,7 @@ - + diff --git a/src/Umbraco.Tests/CodeFirst/CodeFirstTests.cs b/src/Umbraco.Tests/CodeFirst/CodeFirstTests.cs index a89bd1c495..0272523fdc 100644 --- a/src/Umbraco.Tests/CodeFirst/CodeFirstTests.cs +++ b/src/Umbraco.Tests/CodeFirst/CodeFirstTests.cs @@ -26,7 +26,7 @@ namespace Umbraco.Tests.CodeFirst UmbracoSettings.SettingsFilePath = IOHelper.MapPath(SystemDirectories.Config + Path.DirectorySeparatorChar, false); //this ensures its reset - PluginManager.Current = new PluginManager(); + PluginManager.Current = new PluginManager(false); //for testing, we'll specify which assemblies are scanned for the PluginTypeResolver PluginManager.Current.AssembliesToScan = new[] diff --git a/src/Umbraco.Tests/Models/ContentXmlTest.cs b/src/Umbraco.Tests/Models/ContentXmlTest.cs index 840603ff78..da20c0a9e0 100644 --- a/src/Umbraco.Tests/Models/ContentXmlTest.cs +++ b/src/Umbraco.Tests/Models/ContentXmlTest.cs @@ -19,7 +19,7 @@ namespace Umbraco.Tests.Models public override void Initialize() { //this ensures its reset - PluginManager.Current = new PluginManager(); + PluginManager.Current = new PluginManager(false); //for testing, we'll specify which assemblies are scanned for the PluginTypeResolver PluginManager.Current.AssembliesToScan = new[] diff --git a/src/Umbraco.Tests/Models/MediaXmlTest.cs b/src/Umbraco.Tests/Models/MediaXmlTest.cs index c916dfaab8..f7ab0cd7ff 100644 --- a/src/Umbraco.Tests/Models/MediaXmlTest.cs +++ b/src/Umbraco.Tests/Models/MediaXmlTest.cs @@ -21,7 +21,7 @@ namespace Umbraco.Tests.Models Resolution.Reset(); //this ensures its reset - PluginManager.Current = new PluginManager(); + PluginManager.Current = new PluginManager(false); //for testing, we'll specify which assemblies are scanned for the PluginTypeResolver PluginManager.Current.AssembliesToScan = new[] diff --git a/src/Umbraco.Tests/Persistence/Mappers/MappingResolverTests.cs b/src/Umbraco.Tests/Persistence/Mappers/MappingResolverTests.cs index 27341ebbb3..b15da5ec1d 100644 --- a/src/Umbraco.Tests/Persistence/Mappers/MappingResolverTests.cs +++ b/src/Umbraco.Tests/Persistence/Mappers/MappingResolverTests.cs @@ -1,5 +1,7 @@ using NUnit.Framework; +using Umbraco.Core; using Umbraco.Core.Models; +using Umbraco.Core.ObjectResolution; using Umbraco.Core.Persistence.Mappers; using Umbraco.Tests.TestHelpers; @@ -8,10 +10,21 @@ namespace Umbraco.Tests.Persistence.Mappers [TestFixture] public class MappingResolverTests : BaseUsingSqlCeSyntax { + public override void Initialize() + { + base.Initialize(); + } + + public override void TearDown() + { + base.TearDown(); + } + + [Test] public void Can_Map_Id_Property_On_Content() { - var mapping = MappingResolver.GetMapping(typeof (Content), "Id"); + var mapping = MappingResolver.Current.GetMapping(typeof (Content), "Id"); Assert.That(mapping, Is.EqualTo("[umbracoNode].[id]")); } @@ -19,7 +32,7 @@ namespace Umbraco.Tests.Persistence.Mappers [Test] public void Can_Map_Alias_Property_On_ContentType() { - var mapping = MappingResolver.GetMapping(typeof(ContentType), "Alias"); + var mapping = MappingResolver.Current.GetMapping(typeof(ContentType), "Alias"); Assert.That(mapping, Is.EqualTo("[cmsContentType].[alias]")); } @@ -27,14 +40,14 @@ namespace Umbraco.Tests.Persistence.Mappers [Test] public void Can_Resolve_ContentType_Mapper() { - var mapper = MappingResolver.ResolveMapperByType(typeof (ContentType)); + var mapper = MappingResolver.Current.ResolveMapperByType(typeof(ContentType)); Assert.IsTrue(mapper is ContentTypeMapper); } [Test] public void Can_Resolve_Dictionary_Mapper() { - var mapper = MappingResolver.ResolveMapperByType(typeof(IDictionaryItem)); + var mapper = MappingResolver.Current.ResolveMapperByType(typeof(IDictionaryItem)); Assert.IsTrue(mapper is DictionaryMapper); } diff --git a/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs index 6a942594ae..e85edb33f8 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs @@ -22,7 +22,7 @@ namespace Umbraco.Tests.Persistence.Repositories { //NOTE The DataTypesResolver is only necessary because we are using the Save method in the ContentService //this ensures its reset - PluginManager.Current = new PluginManager(); + PluginManager.Current = new PluginManager(false); //for testing, we'll specify which assemblies are scanned for the PluginTypeResolver PluginManager.Current.AssembliesToScan = new[] diff --git a/src/Umbraco.Tests/Persistence/Repositories/MediaRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/MediaRepositoryTest.cs index 3708c4b98e..12f9ab5b32 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/MediaRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/MediaRepositoryTest.cs @@ -23,7 +23,7 @@ namespace Umbraco.Tests.Persistence.Repositories { //NOTE The DataTypesResolver is only necessary because we are using the Save method in the MediaService //this ensures its reset - PluginManager.Current = new PluginManager(); + PluginManager.Current = new PluginManager(false); //for testing, we'll specify which assemblies are scanned for the PluginTypeResolver PluginManager.Current.AssembliesToScan = new[] diff --git a/src/Umbraco.Tests/Persistence/Repositories/RelationRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/RelationRepositoryTest.cs index 73249bc3a1..f72b47f985 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/RelationRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/RelationRepositoryTest.cs @@ -22,7 +22,7 @@ namespace Umbraco.Tests.Persistence.Repositories { //NOTE The DataTypesResolver is only necessary because we are using the Save method in the ContentService //this ensures its reset - PluginManager.Current = new PluginManager(); + PluginManager.Current = new PluginManager(false); //for testing, we'll specify which assemblies are scanned for the PluginTypeResolver PluginManager.Current.AssembliesToScan = new[] diff --git a/src/Umbraco.Tests/PluginManagerTests.cs b/src/Umbraco.Tests/PluginManagerTests.cs index 83e950f7d2..1f6d0bdef6 100644 --- a/src/Umbraco.Tests/PluginManagerTests.cs +++ b/src/Umbraco.Tests/PluginManagerTests.cs @@ -263,6 +263,13 @@ namespace Umbraco.Tests .Count(x => x.IsTypeList(PluginManager.TypeResolutionKind.FindAllTypes))); } + [Test] + public void Resolves_Assigned_Mappers() + { + var foundTypes1 = PluginManager.Current.ResolveAssignedMapperTypes(); + Assert.AreEqual(16, foundTypes1.Count()); + } + [Test] public void Resolves_Types() { diff --git a/src/Umbraco.Tests/Publishing/PublishingStrategyTests.cs b/src/Umbraco.Tests/Publishing/PublishingStrategyTests.cs index ad7e7c1d4d..30292fb183 100644 --- a/src/Umbraco.Tests/Publishing/PublishingStrategyTests.cs +++ b/src/Umbraco.Tests/Publishing/PublishingStrategyTests.cs @@ -27,7 +27,7 @@ namespace Umbraco.Tests.Publishing UmbracoSettings.SettingsFilePath = IOHelper.MapPath(SystemDirectories.Config + Path.DirectorySeparatorChar, false); //this ensures its reset - PluginManager.Current = new PluginManager(); + PluginManager.Current = new PluginManager(false); //for testing, we'll specify which assemblies are scanned for the PluginTypeResolver PluginManager.Current.AssembliesToScan = new[] diff --git a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs index a9a1f8a881..7cb29a0ff8 100644 --- a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs +++ b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs @@ -21,7 +21,7 @@ namespace Umbraco.Tests.Routing public override void Initialize() { //this ensures its reset - PluginManager.Current = new PluginManager(); + PluginManager.Current = new PluginManager(false); SurfaceControllerResolver.Current = new SurfaceControllerResolver( PluginManager.Current.ResolveSurfaceControllers()); diff --git a/src/Umbraco.Tests/Services/BaseServiceTest.cs b/src/Umbraco.Tests/Services/BaseServiceTest.cs index 45e25210e5..799309db75 100644 --- a/src/Umbraco.Tests/Services/BaseServiceTest.cs +++ b/src/Umbraco.Tests/Services/BaseServiceTest.cs @@ -17,7 +17,7 @@ namespace Umbraco.Tests.Services { //this ensures its reset - PluginManager.Current = new PluginManager(); + PluginManager.Current = new PluginManager(false); //for testing, we'll specify which assemblies are scanned for the PluginTypeResolver PluginManager.Current.AssembliesToScan = new[] diff --git a/src/Umbraco.Tests/Services/ThreadSafetyServiceTest.cs b/src/Umbraco.Tests/Services/ThreadSafetyServiceTest.cs index dde6c5fe46..a6c2f418cc 100644 --- a/src/Umbraco.Tests/Services/ThreadSafetyServiceTest.cs +++ b/src/Umbraco.Tests/Services/ThreadSafetyServiceTest.cs @@ -29,7 +29,7 @@ namespace Umbraco.Tests.Services { //NOTE The DataTypesResolver is only necessary because we are using the Save method in the MediaService //this ensures its reset - PluginManager.Current = new PluginManager(); + PluginManager.Current = new PluginManager(false); //for testing, we'll specify which assemblies are scanned for the PluginTypeResolver PluginManager.Current.AssembliesToScan = new[] diff --git a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs index 67f769bc34..bcf51b4236 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs @@ -13,6 +13,7 @@ using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Core.ObjectResolution; using Umbraco.Core.Persistence; +using Umbraco.Core.Persistence.Mappers; using Umbraco.Core.Persistence.SqlSyntax; using Umbraco.Core.Persistence.UnitOfWork; using Umbraco.Core.Publishing; @@ -41,6 +42,8 @@ namespace Umbraco.Tests.TestHelpers string path = TestHelper.CurrentAssemblyDirectory; AppDomain.CurrentDomain.SetData("DataDirectory", path); + PluginManager.Current = new PluginManager(false); + //Ensure that any database connections from a previous test is disposed. This is really just double safety as its also done in the TearDown. if(ApplicationContext != null && DatabaseContext != null) DatabaseContext.Database.Dispose(); @@ -69,6 +72,11 @@ namespace Umbraco.Tests.TestHelpers SqlSyntaxProvidersResolver.Current = new SqlSyntaxProvidersResolver( new List{ typeof(MySqlSyntaxProvider), typeof(SqlCeSyntaxProvider), typeof(SqlServerSyntaxProvider) }) { CanResolveBeforeFrozen = true}; + var asdf = typeof (ContentMapper); + + MappingResolver.Current = new MappingResolver( + () => PluginManager.Current.ResolveAssignedMapperTypes()); + //Get the connectionstring settings from config var settings = ConfigurationManager.ConnectionStrings[Core.Configuration.GlobalSettings.UmbracoConnectionName]; ConfigurationManager.AppSettings.Set(Core.Configuration.GlobalSettings.UmbracoConnectionName, @"datalayer=SQLCE4Umbraco.SqlCEHelper,SQLCE4Umbraco;data source=|DataDirectory|\UmbracoPetaPocoTests.sdf"); @@ -117,7 +125,7 @@ namespace Umbraco.Tests.TestHelpers SqlCeContextGuardian.CloseBackgroundConnection(); ApplicationContext.Current = null; - + MappingResolver.Reset(); RepositoryResolver.Reset(); SqlSyntaxProvidersResolver.Reset(); Resolution.Reset(); diff --git a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs index 7d2e2c55f9..2af1e1bf4e 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs @@ -1,4 +1,7 @@ using NUnit.Framework; +using Umbraco.Core; +using Umbraco.Core.ObjectResolution; +using Umbraco.Core.Persistence.Mappers; using Umbraco.Core.Persistence.SqlSyntax; namespace Umbraco.Tests.TestHelpers @@ -10,7 +13,31 @@ namespace Umbraco.Tests.TestHelpers public virtual void Initialize() { SqlSyntaxContext.SqlSyntaxProvider = SqlCeSyntax.Provider; + PluginManager.Current = new PluginManager(false); + MappingResolver.Current = new MappingResolver( + () => PluginManager.Current.ResolveAssignedMapperTypes()); + //MappingResolver.Current = new MappingResolver( + // new[] + // { + // typeof(ContentMapper), + // typeof(ContentTypeMapper), + // typeof(DataTypeDefinitionMapper), + // typeof(DictionaryMapper), + // typeof(DictionaryTranslationMapper), + // typeof(LanguageMapper), + // typeof(MediaMapper), + // typeof(MediaTypeMapper), + // typeof(PropertyGroupMapper), + // typeof(PropertyMapper), + // typeof(PropertyTypeMapper), + // typeof(RelationMapper), + // typeof(RelationTypeMapper), + // typeof(ServerRegistrationMapper), + // typeof(UserMapper), + // typeof(UserTypeMapper) + // }); + Resolution.Freeze(); SetUp(); } @@ -20,7 +47,9 @@ namespace Umbraco.Tests.TestHelpers [TearDown] public virtual void TearDown() { + MappingResolver.Reset(); SqlSyntaxContext.SqlSyntaxProvider = null; + PluginManager.Current = null; } } } \ No newline at end of file