Adjustments for Forms and Deploy
This commit is contained in:
@@ -4,10 +4,7 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using Umbraco.Core.Collections;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Exceptions;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Scoping;
|
||||
|
||||
namespace Umbraco.Core.Components
|
||||
{
|
||||
@@ -16,7 +13,7 @@ namespace Umbraco.Core.Components
|
||||
/// <summary>
|
||||
/// Handles the composers.
|
||||
/// </summary>
|
||||
internal class Composers
|
||||
public class Composers
|
||||
{
|
||||
private readonly Composition _composition;
|
||||
private readonly IProfilingLogger _logger;
|
||||
|
||||
@@ -38,7 +38,6 @@ namespace Umbraco.Core.Services
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ServiceContext"/> class with lazy services.
|
||||
/// </summary>
|
||||
/// <remarks>Used by IoC. Note that LightInject will favor lazy args when picking a constructor.</remarks>
|
||||
public ServiceContext(Lazy<IPublicAccessService> publicAccessService, Lazy<IDomainService> domainService, Lazy<IAuditService> auditService, Lazy<ILocalizedTextService> localizedTextService, Lazy<ITagService> tagService, Lazy<IContentService> contentService, Lazy<IUserService> userService, Lazy<IMemberService> memberService, Lazy<IMediaService> mediaService, Lazy<IContentTypeService> contentTypeService, Lazy<IMediaTypeService> mediaTypeService, Lazy<IDataTypeService> dataTypeService, Lazy<IFileService> fileService, Lazy<ILocalizationService> localizationService, Lazy<IPackagingService> packagingService, Lazy<IServerRegistrationService> serverRegistrationService, Lazy<IEntityService> entityService, Lazy<IRelationService> relationService, Lazy<IApplicationTreeService> treeService, Lazy<ISectionService> sectionService, Lazy<IMacroService> macroService, Lazy<IMemberTypeService> memberTypeService, Lazy<IMemberGroupService> memberGroupService, Lazy<INotificationService> notificationService, Lazy<IExternalLoginService> externalLoginService, Lazy<IRedirectUrlService> redirectUrlService, Lazy<IConsentService> consentService)
|
||||
{
|
||||
_publicAccessService = publicAccessService;
|
||||
@@ -71,10 +70,13 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ServiceContext"/> class with services.
|
||||
/// Creates a partial service context with only some services (for tests).
|
||||
/// </summary>
|
||||
/// <remarks>Used in tests. All items are optional and remain null if not specified.</remarks>
|
||||
internal ServiceContext(IContentService contentService = null,
|
||||
/// <remarks>
|
||||
/// <para>Using a true constructor for this confuses DI containers.</para>
|
||||
/// </remarks>
|
||||
public static ServiceContext CreatePartial(
|
||||
IContentService contentService = null,
|
||||
IMediaService mediaService = null,
|
||||
IContentTypeService contentTypeService = null,
|
||||
IMediaTypeService mediaTypeService = null,
|
||||
@@ -102,40 +104,43 @@ namespace Umbraco.Core.Services
|
||||
IRedirectUrlService redirectUrlService = null,
|
||||
IConsentService consentService = null)
|
||||
{
|
||||
if (serverRegistrationService != null) _serverRegistrationService = new Lazy<IServerRegistrationService>(() => serverRegistrationService);
|
||||
if (externalLoginService != null) _externalLoginService = new Lazy<IExternalLoginService>(() => externalLoginService);
|
||||
if (auditService != null) _auditService = new Lazy<IAuditService>(() => auditService);
|
||||
if (localizedTextService != null) _localizedTextService = new Lazy<ILocalizedTextService>(() => localizedTextService);
|
||||
if (tagService != null) _tagService = new Lazy<ITagService>(() => tagService);
|
||||
if (contentService != null) _contentService = new Lazy<IContentService>(() => contentService);
|
||||
if (mediaService != null) _mediaService = new Lazy<IMediaService>(() => mediaService);
|
||||
if (contentTypeService != null) _contentTypeService = new Lazy<IContentTypeService>(() => contentTypeService);
|
||||
if (mediaTypeService != null) _mediaTypeService = new Lazy<IMediaTypeService>(() => mediaTypeService);
|
||||
if (dataTypeService != null) _dataTypeService = new Lazy<IDataTypeService>(() => dataTypeService);
|
||||
if (fileService != null) _fileService = new Lazy<IFileService>(() => fileService);
|
||||
if (localizationService != null) _localizationService = new Lazy<ILocalizationService>(() => localizationService);
|
||||
if (packagingService != null) _packagingService = new Lazy<IPackagingService>(() => packagingService);
|
||||
if (entityService != null) _entityService = new Lazy<IEntityService>(() => entityService);
|
||||
if (relationService != null) _relationService = new Lazy<IRelationService>(() => relationService);
|
||||
if (sectionService != null) _sectionService = new Lazy<ISectionService>(() => sectionService);
|
||||
if (memberGroupService != null) _memberGroupService = new Lazy<IMemberGroupService>(() => memberGroupService);
|
||||
if (memberTypeService != null) _memberTypeService = new Lazy<IMemberTypeService>(() => memberTypeService);
|
||||
if (treeService != null) _treeService = new Lazy<IApplicationTreeService>(() => treeService);
|
||||
if (memberService != null) _memberService = new Lazy<IMemberService>(() => memberService);
|
||||
if (userService != null) _userService = new Lazy<IUserService>(() => userService);
|
||||
if (notificationService != null) _notificationService = new Lazy<INotificationService>(() => notificationService);
|
||||
if (domainService != null) _domainService = new Lazy<IDomainService>(() => domainService);
|
||||
if (macroService != null) _macroService = new Lazy<IMacroService>(() => macroService);
|
||||
if (publicAccessService != null) _publicAccessService = new Lazy<IPublicAccessService>(() => publicAccessService);
|
||||
if (redirectUrlService != null) _redirectUrlService = new Lazy<IRedirectUrlService>(() => redirectUrlService);
|
||||
if (consentService != null) _consentService = new Lazy<IConsentService>(() => consentService);
|
||||
Lazy<T> Lazy<T>(T service) => service == null ? null : new Lazy<T>(() => service);
|
||||
|
||||
return new ServiceContext(
|
||||
Lazy(publicAccessService),
|
||||
Lazy(domainService),
|
||||
Lazy(auditService),
|
||||
Lazy(localizedTextService),
|
||||
Lazy(tagService),
|
||||
Lazy(contentService),
|
||||
Lazy(userService),
|
||||
Lazy(memberService),
|
||||
Lazy(mediaService),
|
||||
Lazy(contentTypeService),
|
||||
Lazy(mediaTypeService),
|
||||
Lazy(dataTypeService),
|
||||
Lazy(fileService),
|
||||
Lazy(localizationService),
|
||||
Lazy(packagingService),
|
||||
Lazy(serverRegistrationService),
|
||||
Lazy(entityService),
|
||||
Lazy(relationService),
|
||||
Lazy(treeService),
|
||||
Lazy(sectionService),
|
||||
Lazy(macroService),
|
||||
Lazy(memberTypeService),
|
||||
Lazy(memberGroupService),
|
||||
Lazy(notificationService),
|
||||
Lazy(externalLoginService),
|
||||
Lazy(redirectUrlService),
|
||||
Lazy(consentService));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IPublicAccessService"/>
|
||||
/// </summary>
|
||||
public IPublicAccessService PublicAccessService => _publicAccessService.Value;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IDomainService"/>
|
||||
/// </summary>
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Umbraco.Tests.Manifest
|
||||
var factory = Mock.Of<IFactory>();
|
||||
Current.Factory = factory;
|
||||
|
||||
var serviceContext = new ServiceContext(
|
||||
var serviceContext = ServiceContext.CreatePartial(
|
||||
localizedTextService: Mock.Of<ILocalizedTextService>());
|
||||
|
||||
Mock.Get(factory)
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Umbraco.Tests.Models
|
||||
.Setup(x => x.GetDataType(It.IsAny<int>()))
|
||||
.Returns<int>(x => dataType);
|
||||
|
||||
var serviceContext = new ServiceContext(
|
||||
var serviceContext = ServiceContext.CreatePartial(
|
||||
dataTypeService: dataTypeService,
|
||||
localizedTextService: Mock.Of<ILocalizedTextService>());
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
Mock.Get(dataTypeService).Setup(x => x.GetAll()).Returns(dataTypes);
|
||||
|
||||
// create a service context
|
||||
var serviceContext = new ServiceContext(
|
||||
var serviceContext = ServiceContext.CreatePartial(
|
||||
dataTypeService : dataTypeService,
|
||||
memberTypeService: Mock.Of<IMemberTypeService>(),
|
||||
memberService: Mock.Of<IMemberService>(),
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace Umbraco.Tests.TestHelpers
|
||||
contentFinders ?? new ContentFinderCollection(Enumerable.Empty<IContentFinder>()),
|
||||
new TestLastChanceFinder(),
|
||||
new TestVariationContextAccessor(),
|
||||
container?.TryGetInstance<ServiceContext>() ?? new ServiceContext(),
|
||||
container?.TryGetInstance<ServiceContext>() ?? ServiceContext.CreatePartial(),
|
||||
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace Umbraco.Tests.TestHelpers.ControllerTesting
|
||||
var mockedDataTypeService = Mock.Of<IDataTypeService>();
|
||||
var mockedContentTypeService = Mock.Of<IContentTypeService>();
|
||||
|
||||
var serviceContext = new ServiceContext(
|
||||
var serviceContext = ServiceContext.CreatePartial(
|
||||
userService: mockedUserService,
|
||||
contentService: mockedContentService,
|
||||
mediaService: mockedMediaService,
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace Umbraco.Tests.TestHelpers
|
||||
// fixme - else some tests break - figure it out
|
||||
container = null;
|
||||
|
||||
return new ServiceContext(
|
||||
return ServiceContext.CreatePartial(
|
||||
MockService<IContentService>(container),
|
||||
MockService<IMediaService>(container),
|
||||
MockService<IContentTypeService>(container),
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace Umbraco.Tests.Testing.TestingTests
|
||||
Mock.Of<ICultureDictionary>(),
|
||||
Mock.Of<IUmbracoComponentRenderer>(),
|
||||
new MembershipHelper(new TestUmbracoContextAccessor(umbracoContext), Mock.Of<MembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IUserService>(), Mock.Of<IPublicAccessService>(), null, Mock.Of<CacheHelper>(), Mock.Of<ILogger>()),
|
||||
new ServiceContext());
|
||||
ServiceContext.CreatePartial());
|
||||
Assert.Pass();
|
||||
}
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
Mock.Of<ICultureDictionary>(),
|
||||
Mock.Of<IUmbracoComponentRenderer>(),
|
||||
new MembershipHelper(new TestUmbracoContextAccessor(umbracoContext), Mock.Of<MembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IUserService>(), Mock.Of<IPublicAccessService>(), null, Mock.Of<CacheHelper>(), Mock.Of<ILogger>()),
|
||||
new ServiceContext());
|
||||
ServiceContext.CreatePartial());
|
||||
|
||||
var ctrl = new TestSurfaceController(umbracoContext, helper);
|
||||
var result = ctrl.GetContent(2) as PublishedContentResult;
|
||||
@@ -185,7 +185,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
public class TestSurfaceController : SurfaceController
|
||||
{
|
||||
public TestSurfaceController(UmbracoContext ctx, UmbracoHelper helper = null)
|
||||
: base(ctx, null, new ServiceContext(), Mock.Of<CacheHelper>(), null, null)
|
||||
: base(ctx, null, ServiceContext.CreatePartial(), Mock.Of<CacheHelper>(), null, null)
|
||||
{
|
||||
if (helper != null)
|
||||
{
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Umbraco.Tests.Web
|
||||
// should not depend on more than IdkMap maybe - fix this!
|
||||
var entityService = new Mock<IEntityService>();
|
||||
entityService.Setup(x => x.GetId(It.IsAny<Guid>(), It.IsAny<UmbracoObjectTypes>())).Returns(Attempt<int>.Fail());
|
||||
var serviceContext = new ServiceContext(entityService: entityService.Object);
|
||||
var serviceContext = ServiceContext.CreatePartial(entityService: entityService.Object);
|
||||
|
||||
// fixme - bad in a unit test - but Udi has a static ctor that wants it?!
|
||||
var container = new Mock<IFactory>();
|
||||
|
||||
Reference in New Issue
Block a user