Refactor and fix tests

This commit is contained in:
Stephan
2017-09-20 20:06:46 +02:00
parent bcf3916e54
commit dca3b74542
61 changed files with 924 additions and 719 deletions

View File

@@ -7,20 +7,20 @@ namespace Umbraco.Web.DI
{
public void Compose(IServiceRegistry container)
{
container.Register<ContentProfile>();
container.Register<ContentPropertyProfile>();
container.Register<ContentTypeProfile>();
container.Register<DataTypeProfile>();
container.Register<EntityProfile>();
container.Register<MacroProfile>();
container.Register<MediaProfile>();
container.Register<MemberProfile>();
container.Register<RelationProfile>();
container.Register<SectionProfile>();
container.Register<TabProfile>();
container.Register<UserProfile>();
container.Register<DashboardProfile>();
container.Register<TemplateProfile>();
container.Register<ContentMapperProfile>();
container.Register<ContentPropertyMapperProfile>();
container.Register<ContentTypeMapperProfile>();
container.Register<DataTypeMapperProfile>();
container.Register<EntityMapperProfile>();
container.Register<MacroMapperProfile>();
container.Register<MediaMapperProfile>();
container.Register<MemberMapperProfile>();
container.Register<RelationMapperProfile>();
container.Register<SectionMapperProfile>();
container.Register<TagMapperProfile>();
container.Register<UserMapperProfile>();
container.Register<DashboardMapperProfile>();
container.Register<TemplateMapperProfile>();
}
}
}

View File

@@ -4,9 +4,9 @@ using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
public class CodeFileProfile : Profile
public class CodeFileMapperProfile : Profile
{
public CodeFileProfile()
public CodeFileMapperProfile()
{
CreateMap<IPartialView, CodeFileDisplay>()
.ForMember(dest => dest.FileType, opt => opt.Ignore())

View File

@@ -19,9 +19,9 @@ namespace Umbraco.Web.Models.Mapping
/// <summary>
/// Declares how model mappings for content
/// </summary>
internal class ContentProfile : Profile
internal class ContentMapperProfile : Profile
{
public ContentProfile(IUserService userService, ILocalizedTextService textService, IContentService contentService, IContentTypeService contentTypeService, IDataTypeService dataTypeService)
public ContentMapperProfile(IUserService userService, ILocalizedTextService textService, IContentService contentService, IContentTypeService contentTypeService, IDataTypeService dataTypeService)
{
// create, capture, cache
var contentOwnerResolver = new OwnerResolver<IContent>(userService);

View File

@@ -10,11 +10,11 @@ namespace Umbraco.Web.Models.Mapping
/// A mapper which declares how to map content properties. These mappings are shared among media (and probably members) which is
/// why they are in their own mapper
/// </summary>
internal class ContentPropertyProfile : Profile
internal class ContentPropertyMapperProfile : Profile
{
private readonly IDataTypeService _dataTypeService;
public ContentPropertyProfile(IDataTypeService dataTypeService)
public ContentPropertyMapperProfile(IDataTypeService dataTypeService)
{
_dataTypeService = dataTypeService;

View File

@@ -12,7 +12,7 @@ namespace Umbraco.Web.Models.Mapping
/// <summary>
/// Defines mappings for content/media/members type mappings
/// </summary>
internal class ContentTypeProfile : Profile
internal class ContentTypeMapperProfile : Profile
{
private readonly PropertyEditorCollection _propertyEditors;
private readonly IDataTypeService _dataTypeService;
@@ -20,7 +20,7 @@ namespace Umbraco.Web.Models.Mapping
private readonly IContentTypeService _contentTypeService;
private readonly IMediaTypeService _mediaTypeService;
public ContentTypeProfile(PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IFileService fileService, IContentTypeService contentTypeService, IMediaTypeService mediaTypeService)
public ContentTypeMapperProfile(PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IFileService fileService, IContentTypeService contentTypeService, IMediaTypeService mediaTypeService)
{
_propertyEditors = propertyEditors;
_dataTypeService = dataTypeService;

View File

@@ -2,7 +2,6 @@
using Umbraco.Core.Models;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Services;
using Umbraco.Web.Models.ContentEditing;
using UserProfile = Umbraco.Web.Models.ContentEditing.UserProfile;
namespace Umbraco.Web.Models.Mapping

View File

@@ -7,9 +7,9 @@ namespace Umbraco.Web.Models.Mapping
/// <summary>
/// A model mapper used to map models for the various dashboards
/// </summary>
internal class DashboardProfile : Profile
internal class DashboardMapperProfile : Profile
{
public DashboardProfile()
public DashboardMapperProfile()
{
CreateMap<IRedirectUrl, ContentRedirectUrl>()
.ForMember(x => x.OriginalUrl, expression => expression.MapFrom(item => UmbracoContext.Current.UrlProvider.GetUrlFromRoute(item.ContentId, item.Url)))

View File

@@ -15,9 +15,9 @@ namespace Umbraco.Web.Models.Mapping
/// <summary>
/// Configure's model mappings for Data types
/// </summary>
internal class DataTypeProfile : Profile
internal class DataTypeMapperProfile : Profile
{
public DataTypeProfile(IDataTypeService dataTypeService)
public DataTypeMapperProfile(IDataTypeService dataTypeService)
{
var lazyDataTypeService = new Lazy<IDataTypeService>(() => dataTypeService);

View File

@@ -13,9 +13,9 @@ using Umbraco.Examine;
namespace Umbraco.Web.Models.Mapping
{
internal class EntityProfile : Profile
internal class EntityMapperProfile : Profile
{
public EntityProfile()
public EntityMapperProfile()
{
// create, capture, cache
var contentTypeUdiResolver = new ContentTypeUdiResolver();

View File

@@ -12,9 +12,9 @@ namespace Umbraco.Web.Models.Mapping
/// <summary>
/// Declares model mappings for macros.
/// </summary>
internal class MacroProfile : Profile
internal class MacroMapperProfile : Profile
{
public MacroProfile()
public MacroMapperProfile()
{
//FROM IMacro TO EntityBasic
CreateMap<IMacro, EntityBasic>()
@@ -41,7 +41,7 @@ namespace Umbraco.Web.Models.Mapping
{
//we'll just map this to a text box
paramEditor = Current.ParameterEditors[Constants.PropertyEditors.TextboxAlias];
Current.Logger.Warn<MacroProfile>("Could not resolve a parameter editor with alias " + property.EditorAlias + ", a textbox will be rendered in it's place");
Current.Logger.Warn<MacroMapperProfile>("Could not resolve a parameter editor with alias " + property.EditorAlias + ", a textbox will be rendered in it's place");
}
parameter.View = paramEditor.ValueEditor.View;

View File

@@ -17,9 +17,9 @@ namespace Umbraco.Web.Models.Mapping
/// <summary>
/// Declares model mappings for media.
/// </summary>
internal class MediaProfile : Profile
internal class MediaMapperProfile : Profile
{
public MediaProfile(IUserService userService, ILocalizedTextService textService, IDataTypeService dataTypeService, IMediaService mediaService, ILogger logger)
public MediaMapperProfile(IUserService userService, ILocalizedTextService textService, IDataTypeService dataTypeService, IMediaService mediaService, ILogger logger)
{
// create, capture, cache
var mediaOwnerResolver = new OwnerResolver<IMedia>(userService);

View File

@@ -19,9 +19,9 @@ namespace Umbraco.Web.Models.Mapping
/// <summary>
/// Declares model mappings for members.
/// </summary>
internal class MemberProfile : Profile
internal class MemberMapperProfile : Profile
{
public MemberProfile(IUserService userService, ILocalizedTextService textService, IMemberTypeService memberTypeService, IMemberService memberService)
public MemberMapperProfile(IUserService userService, ILocalizedTextService textService, IMemberTypeService memberTypeService, IMemberService memberService)
{
// create, capture, cache
var memberOwnerResolver = new OwnerResolver<IMember>(userService);

View File

@@ -2,7 +2,6 @@
using Umbraco.Core.Models;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Services;
using Umbraco.Web.Models.ContentEditing;
using UserProfile = Umbraco.Web.Models.ContentEditing.UserProfile;
namespace Umbraco.Web.Models.Mapping

View File

@@ -5,9 +5,9 @@ using RelationType = Umbraco.Web.Models.ContentEditing.RelationType;
namespace Umbraco.Web.Models.Mapping
{
internal class RelationProfile : Profile
internal class RelationMapperProfile : Profile
{
public RelationProfile()
public RelationMapperProfile()
{
//FROM IRelationType TO RelationType
CreateMap<IRelationType, RelationType>();

View File

@@ -5,17 +5,13 @@ using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
internal class SectionProfile : Profile
internal class SectionMapperProfile : Profile
{
private readonly ILocalizedTextService _textService;
public SectionProfile(ILocalizedTextService textService)
public SectionMapperProfile(ILocalizedTextService textService)
{
_textService = textService;
CreateMap<Core.Models.Section, Section>()
.ForMember(dest => dest.RoutePath, opt => opt.Ignore())
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => _textService.Localize("sections/" + src.Alias, (IDictionary<string, string>)null)))
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => textService.Localize("sections/" + src.Alias, (IDictionary<string, string>)null)))
.ReverseMap(); //backwards too!
}
}

View File

@@ -3,9 +3,9 @@ using Umbraco.Core.Models;
namespace Umbraco.Web.Models.Mapping
{
internal class TabProfile : Profile
internal class TagMapperProfile : Profile
{
public TabProfile()
public TagMapperProfile()
{
CreateMap<ITag, TagModel>();
}

View File

@@ -4,9 +4,9 @@ using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
internal class TemplateProfile : Profile
internal class TemplateMapperProfile : Profile
{
public TemplateProfile()
public TemplateMapperProfile()
{
CreateMap<ITemplate, TemplateDisplay>()
.ForMember(dest => dest.Notifications, opt => opt.Ignore());

View File

@@ -14,9 +14,9 @@ using Umbraco.Web._Legacy.Actions;
namespace Umbraco.Web.Models.Mapping
{
internal class UserProfile : Profile
internal class UserMapperProfile : Profile
{
public UserProfile(ILocalizedTextService textService, IUserService userService, IEntityService entityService, ISectionService sectionService,
public UserMapperProfile(ILocalizedTextService textService, IUserService userService, IEntityService entityService, ISectionService sectionService,
IRuntimeCacheProvider runtimeCache,
ActionCollection actions)
{

View File

@@ -18,7 +18,7 @@ namespace Umbraco.Web.PropertyEditors
[PropertyEditor(Constants.PropertyEditors.NestedContentAlias, "Nested Content", "nestedcontent", ValueType = "JSON", Group = "lists", Icon = "icon-thumbnail-list")]
public class NestedContentPropertyEditor : PropertyEditor
{
private readonly PropertyEditorCollection _propertyEditors;
private readonly Lazy<PropertyEditorCollection> _propertyEditors;
internal const string ContentTypeAliasPropertyKey = "ncContentTypeAlias";
@@ -29,7 +29,7 @@ namespace Umbraco.Web.PropertyEditors
set => _defaultPreValues = value;
}
public NestedContentPropertyEditor(ILogger logger, PropertyEditorCollection propertyEditors)
public NestedContentPropertyEditor(ILogger logger, Lazy<PropertyEditorCollection> propertyEditors)
: base (logger)
{
_propertyEditors = propertyEditors;
@@ -45,6 +45,9 @@ namespace Umbraco.Web.PropertyEditors
};
}
// has to be lazy else circular dep in ctor
private PropertyEditorCollection PropertyEditors => _propertyEditors.Value;
#region Pre Value Editor
protected override PreValueEditor CreatePreValueEditor()
@@ -89,7 +92,7 @@ namespace Umbraco.Web.PropertyEditors
protected override PropertyValueEditor CreateValueEditor()
{
return new NestedContentPropertyValueEditor(base.CreateValueEditor(), _propertyEditors);
return new NestedContentPropertyValueEditor(base.CreateValueEditor(), PropertyEditors);
}
internal class NestedContentPropertyValueEditor : PropertyValueEditorWrapper

View File

@@ -1,14 +1,8 @@
using System.Collections.Specialized;
using System.ComponentModel.DataAnnotations;
using System.Configuration.Provider;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.Hosting;
using System.Web.Security;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.EntityBase;
using Umbraco.Core.Security;
using Umbraco.Core.Services;
using Umbraco.Core.Models.Membership;
@@ -23,8 +17,7 @@ namespace Umbraco.Web.Security.Providers
{
public MembersMembershipProvider()
: this(Current.Services.MemberService, Current.Services.MemberTypeService)
{
}
{ }
public MembersMembershipProvider(IMembershipMemberService<IMember> memberService, IMemberTypeService memberTypeService)
: base(memberService)
@@ -43,29 +36,26 @@ namespace Umbraco.Web.Security.Providers
private readonly IMemberTypeService _memberTypeService;
private string _defaultMemberTypeAlias = "Member";
private volatile bool _hasDefaultMember = false;
private volatile bool _hasDefaultMember;
private static readonly object Locker = new object();
private bool _providerKeyAsGuid = false;
private bool _providerKeyAsGuid;
public override string ProviderName
{
get { return "MembersMembershipProvider"; }
}
public override string ProviderName => "MembersMembershipProvider";
protected override MembershipUser ConvertToMembershipUser(IMember entity)
{
return entity.AsConcreteMembershipUser(Name, _providerKeyAsGuid);
}
public string LockPropertyTypeAlias { get; private set; }
public string LastLockedOutPropertyTypeAlias { get; private set; }
public string FailedPasswordAttemptsPropertyTypeAlias { get; private set; }
public string ApprovedPropertyTypeAlias { get; private set; }
public string CommentPropertyTypeAlias { get; private set; }
public string LastLoginPropertyTypeAlias { get; private set; }
public string LastPasswordChangedPropertyTypeAlias { get; private set; }
public string PasswordRetrievalQuestionPropertyTypeAlias { get; private set; }
public string PasswordRetrievalAnswerPropertyTypeAlias { get; private set; }
public string LockPropertyTypeAlias { get; }
public string LastLockedOutPropertyTypeAlias { get; }
public string FailedPasswordAttemptsPropertyTypeAlias { get; }
public string ApprovedPropertyTypeAlias { get; }
public string CommentPropertyTypeAlias { get; }
public string LastLoginPropertyTypeAlias { get; }
public string LastPasswordChangedPropertyTypeAlias { get; }
public string PasswordRetrievalQuestionPropertyTypeAlias { get; }
public string PasswordRetrievalAnswerPropertyTypeAlias { get; }
public override void Initialize(string name, NameValueCollection config)
{
@@ -94,7 +84,7 @@ namespace Umbraco.Web.Security.Providers
protected override Attempt<string> GetRawPassword(string username)
{
var found = MemberService.GetByUsername(username);
var found = MemberService.GetByUsername(username);
if (found == null) return Attempt<string>.Fail();
return Attempt.Succeed(found.RawPasswordValue);
}

View File

@@ -222,14 +222,14 @@
<Compile Include="Models\DetachedPublishedContent.cs" />
<Compile Include="Models\DetachedPublishedProperty.cs" />
<Compile Include="Models\Mapping\ActionButtonsResolver.cs" />
<Compile Include="Models\Mapping\CodeFileProfile.cs" />
<Compile Include="Models\Mapping\CodeFileMapperProfile.cs" />
<Compile Include="Models\Mapping\ContentTypeUdiResolver.cs" />
<Compile Include="Models\Mapping\EntityProfileExtensions.cs" />
<Compile Include="Models\Mapping\MemberDtoPropertiesResolver.cs" />
<Compile Include="Models\Mapping\MemberProviderFieldResolver.cs" />
<Compile Include="Models\Mapping\MembershipScenarioResolver.cs" />
<Compile Include="Models\Mapping\MemberTabsAndPropertiesResolver.cs" />
<Compile Include="Models\Mapping\TemplateProfile.cs" />
<Compile Include="Models\Mapping\TemplateMapperProfile.cs" />
<Compile Include="Models\Mapping\UserGroupDefaultPermissionsResolver.cs" />
<Compile Include="Models\RelatedLink.cs" />
<Compile Include="Models\RelatedLinkBase.cs" />
@@ -477,7 +477,7 @@
<Compile Include="Models\ContentExtensions.cs" />
<Compile Include="ITagQuery.cs" />
<Compile Include="IUmbracoComponentRenderer.cs" />
<Compile Include="Models\Mapping\RelationProfile.cs" />
<Compile Include="Models\Mapping\RelationMapperProfile.cs" />
<Compile Include="Mvc\DisableClientCacheAttribute.cs" />
<Compile Include="Models\UnLinkLoginModel.cs" />
<Compile Include="Mvc\MvcVersionCheck.cs" />
@@ -619,10 +619,10 @@
<Compile Include="Models\ContentEditing\RichTextEditorPlugin.cs" />
<Compile Include="Models\ContentEditing\StylesheetRule.cs" />
<Compile Include="Models\ContentEditing\UmbracoEntityTypes.cs" />
<Compile Include="Models\Mapping\DashboardProfile.cs" />
<Compile Include="Models\Mapping\MacroProfile.cs" />
<Compile Include="Models\Mapping\MemberProfile.cs" />
<Compile Include="Models\Mapping\TabProfile.cs" />
<Compile Include="Models\Mapping\DashboardMapperProfile.cs" />
<Compile Include="Models\Mapping\MacroMapperProfile.cs" />
<Compile Include="Models\Mapping\MemberMapperProfile.cs" />
<Compile Include="Models\Mapping\TagMapperProfile.cs" />
<Compile Include="Models\TagModel.cs" />
<Compile Include="Models\UpgradeCheckResponse.cs" />
<Compile Include="Models\PasswordChangedModel.cs" />
@@ -662,8 +662,8 @@
<Compile Include="Models\ContentEditing\PropertyEditorBasic.cs" />
<Compile Include="Models\Mapping\AvailablePropertyEditorsResolver.cs" />
<Compile Include="Models\Mapping\DatabaseTypeResolver.cs" />
<Compile Include="Models\Mapping\DataTypeProfile.cs" />
<Compile Include="Models\Mapping\EntityProfile.cs" />
<Compile Include="Models\Mapping\DataTypeMapperProfile.cs" />
<Compile Include="Models\Mapping\EntityMapperProfile.cs" />
<Compile Include="Models\Mapping\PreValueDisplayResolver.cs" />
<Compile Include="PropertyEditors\CheckBoxListPropertyEditor.cs" />
<Compile Include="PropertyEditors\ColorPickerPropertyEditor.cs" />
@@ -813,15 +813,15 @@
<Compile Include="Models\Mapping\ContentPropertyBasicConverter.cs" />
<Compile Include="Models\Mapping\ContentPropertyDisplayConverter.cs" />
<Compile Include="Models\Mapping\ContentPropertyDtoConverter.cs" />
<Compile Include="Models\Mapping\ContentPropertyProfile.cs" />
<Compile Include="Models\Mapping\ContentPropertyMapperProfile.cs" />
<Compile Include="Models\Mapping\CreatorResolver.cs" />
<Compile Include="Models\Mapping\MediaProfile.cs" />
<Compile Include="Models\Mapping\ContentTypeProfile.cs" />
<Compile Include="Models\Mapping\ContentProfile.cs" />
<Compile Include="Models\Mapping\MediaMapperProfile.cs" />
<Compile Include="Models\Mapping\ContentTypeMapperProfile.cs" />
<Compile Include="Models\Mapping\ContentMapperProfile.cs" />
<Compile Include="Models\Mapping\OwnerResolver.cs" />
<Compile Include="Models\Mapping\SectionProfile.cs" />
<Compile Include="Models\Mapping\SectionMapperProfile.cs" />
<Compile Include="Models\Mapping\TabsAndPropertiesResolver.cs" />
<Compile Include="Models\Mapping\UserProfile.cs" />
<Compile Include="Models\Mapping\UserMapperProfile.cs" />
<Compile Include="PropertyEditors\ContentPickerPropertyEditor.cs" />
<Compile Include="PropertyEditors\FileUploadPropertyEditor.cs" />
<Compile Include="PropertyEditors\FileUploadPropertyValueEditor.cs" />

View File

@@ -119,7 +119,7 @@ namespace Umbraco.Web
// set the default RenderMvcController
Current.DefaultRenderMvcControllerType = typeof(RenderMvcController); // fixme WRONG!
ActionCollectionBuilder.Register(composition.Container)
composition.Container.RegisterCollectionBuilder<ActionCollectionBuilder>()
.SetProducer(() => typeLoader.GetActions());
var surfaceControllerTypes = new SurfaceControllerTypeCollection(typeLoader.GetSurfaceControllers());

View File

@@ -10,15 +10,13 @@ namespace Umbraco.Web._Legacy.Actions
{
private static Func<IEnumerable<Type>> _producer;
public static ActionCollectionBuilder Register(IServiceContainer container)
{
// register the builder - per container
var builderLifetime = new PerContainerLifetime();
container.Register<ActionCollectionBuilder>(builderLifetime);
// for tests only - does not register the collection
public ActionCollectionBuilder()
{ }
// get the builder, get the collection lifetime
var builder = container.GetInstance<ActionCollectionBuilder>();
var collectionLifetime = builder.CollectionLifetime;
public ActionCollectionBuilder(IServiceContainer container)
{
var collectionLifetime = CollectionLifetime;
// register the collection - special lifetime
// the lifetime here is custom ResettablePerContainerLifetime which will manage one
@@ -29,8 +27,6 @@ namespace Umbraco.Web._Legacy.Actions
// had frozen. This has been replaced by the possibility here to set the producer at any
// time - but the builder is internal - and all this will be gone eventually.
container.Register(factory => factory.GetInstance<ActionCollectionBuilder>().CreateCollection(), collectionLifetime);
return builder;
}
public ActionCollection CreateCollection()