Files
Umbraco-CMS/tests/Umbraco.Tests.UnitTests/TestHelpers/Objects/TestUmbracoContextFactory.cs
Ronald Barendse 780184e553 Remove UmbracoPath setting (#16037)
* Use require modifier instead of setting null-suppressed default values

* Only remove read-only properties when IgnoreReadOnlyProperties is set

* Obsolete UmbracoPath property and remove work-around for obsolete setter

* Remove UmbracoPath setting and use constant instead

* Remove usage of GetBackOfficePath

* Add IHostingEnvironment.GetBackOfficePath() extension method

* Add Constants.System.UmbracoPathSegment constant

* Update Constants.System XML docs

* Replace StringBuilder with string interpolation

Co-authored-by: Nuklon <Nuklon@users.noreply.github.com>

* Fix syntax error

* Removed uses of obsoletes.

* Further obsolete messages.

* Cleaned up usings.

* Update src/Umbraco.Infrastructure/Install/FilePermissionHelper.cs

Co-authored-by: Ronald Barendse <ronald@barend.se>

---------

Co-authored-by: Nuklon <Nuklon@users.noreply.github.com>
Co-authored-by: Andy Butland <abutland73@gmail.com>
2025-03-03 07:38:30 +01:00

55 lines
2.0 KiB
C#

// Copyright (c) Umbraco.
// See LICENSE for more details.
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
using Moq;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.PublishedCache;
using Umbraco.Cms.Core.Routing;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Web;
using Umbraco.Cms.Tests.Common;
using Umbraco.Cms.Web.Common.AspNetCore;
using Umbraco.Cms.Web.Common.UmbracoContext;
namespace Umbraco.Cms.Tests.UnitTests.TestHelpers.Objects;
/// <summary>
/// Simplify creating test UmbracoContext's
/// </summary>
public class TestUmbracoContextFactory
{
public static IUmbracoContextFactory Create(
IUmbracoContextAccessor umbracoContextAccessor = null,
IHttpContextAccessor httpContextAccessor = null,
IPublishedUrlProvider publishedUrlProvider = null,
UmbracoRequestPathsOptions umbracoRequestPathsOptions = null)
{
umbracoContextAccessor ??= new TestUmbracoContextAccessor();
httpContextAccessor ??= Mock.Of<IHttpContextAccessor>();
publishedUrlProvider ??= Mock.Of<IPublishedUrlProvider>();
umbracoRequestPathsOptions ??= new UmbracoRequestPathsOptions();
var contentCache = new Mock<IPublishedContentCache>();
var mediaCache = new Mock<IPublishedMediaCache>();
var cacheManager = new Mock<ICacheManager>();
cacheManager.Setup(x => x.Content).Returns(contentCache.Object);
cacheManager.Setup(x => x.Media).Returns(mediaCache.Object);
var hostingEnvironment = TestHelper.GetHostingEnvironment();
var umbracoContextFactory = new UmbracoContextFactory(
umbracoContextAccessor,
new UmbracoRequestPaths(hostingEnvironment, Options.Create(umbracoRequestPathsOptions)),
hostingEnvironment,
new UriUtility(hostingEnvironment),
new AspNetCoreCookieManager(httpContextAccessor),
httpContextAccessor,
Mock.Of<IWebProfilerService>(),
cacheManager.Object);
return umbracoContextFactory;
}
}