2020-12-20 08:36:11 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
2020-12-08 10:20:03 +11:00
|
|
|
using Microsoft.AspNetCore.Http;
|
2020-09-25 09:39:01 +02:00
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
using Moq;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
|
|
|
|
using Umbraco.Cms.Core.PublishedCache;
|
|
|
|
|
using Umbraco.Cms.Core.Routing;
|
2023-02-21 11:28:21 +01:00
|
|
|
using Umbraco.Cms.Core.Services;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Web;
|
|
|
|
|
using Umbraco.Cms.Tests.Common;
|
|
|
|
|
using Umbraco.Cms.Web.Common.AspNetCore;
|
|
|
|
|
using Umbraco.Cms.Web.Common.UmbracoContext;
|
2019-10-22 00:53:52 +11:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
namespace Umbraco.Cms.Tests.UnitTests.TestHelpers.Objects;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Simplify creating test UmbracoContext's
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class TestUmbracoContextFactory
|
2019-10-22 00:53:52 +11:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
public static IUmbracoContextFactory Create(
|
|
|
|
|
IUmbracoContextAccessor umbracoContextAccessor = null,
|
|
|
|
|
IHttpContextAccessor httpContextAccessor = null,
|
2022-11-01 11:15:31 +01:00
|
|
|
IPublishedUrlProvider publishedUrlProvider = null,
|
|
|
|
|
UmbracoRequestPathsOptions umbracoRequestPathsOptions = null)
|
2019-10-22 00:53:52 +11:00
|
|
|
{
|
2025-03-03 07:38:30 +01:00
|
|
|
umbracoContextAccessor ??= new TestUmbracoContextAccessor();
|
|
|
|
|
httpContextAccessor ??= Mock.Of<IHttpContextAccessor>();
|
|
|
|
|
publishedUrlProvider ??= Mock.Of<IPublishedUrlProvider>();
|
|
|
|
|
umbracoRequestPathsOptions ??= new UmbracoRequestPathsOptions();
|
2022-11-01 11:15:31 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var contentCache = new Mock<IPublishedContentCache>();
|
|
|
|
|
var mediaCache = new Mock<IPublishedMediaCache>();
|
2024-10-01 15:03:02 +02:00
|
|
|
var cacheManager = new Mock<ICacheManager>();
|
|
|
|
|
cacheManager.Setup(x => x.Content).Returns(contentCache.Object);
|
|
|
|
|
cacheManager.Setup(x => x.Media).Returns(mediaCache.Object);
|
2019-12-11 08:13:51 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var hostingEnvironment = TestHelper.GetHostingEnvironment();
|
2021-01-11 11:14:43 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var umbracoContextFactory = new UmbracoContextFactory(
|
|
|
|
|
umbracoContextAccessor,
|
2025-03-03 07:38:30 +01:00
|
|
|
new UmbracoRequestPaths(hostingEnvironment, Options.Create(umbracoRequestPathsOptions)),
|
2022-06-21 08:09:38 +02:00
|
|
|
hostingEnvironment,
|
|
|
|
|
new UriUtility(hostingEnvironment),
|
|
|
|
|
new AspNetCoreCookieManager(httpContextAccessor),
|
2023-02-21 11:28:21 +01:00
|
|
|
httpContextAccessor,
|
2024-10-01 15:03:02 +02:00
|
|
|
Mock.Of<IWebProfilerService>(),
|
|
|
|
|
cacheManager.Object);
|
2019-10-22 00:53:52 +11:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
return umbracoContextFactory;
|
2019-10-22 00:53:52 +11:00
|
|
|
}
|
|
|
|
|
}
|