2018-07-11 22:15:58 +01:00
|
|
|
|
using System;
|
2019-11-11 18:56:14 +11:00
|
|
|
|
using System.IO;
|
2018-07-11 22:15:58 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Web.Routing;
|
2020-10-30 11:16:17 +00:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2020-09-28 08:26:21 +02:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2020-09-18 14:37:19 +02:00
|
|
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
2018-07-11 22:15:58 +01:00
|
|
|
|
using Moq;
|
2021-02-09 10:22:42 +01:00
|
|
|
|
using Umbraco.Cms.Core.Cache;
|
|
|
|
|
|
using Umbraco.Cms.Core.Composing;
|
|
|
|
|
|
using Umbraco.Cms.Core.Hosting;
|
|
|
|
|
|
using Umbraco.Cms.Core.IO;
|
|
|
|
|
|
using Umbraco.Cms.Core.Logging;
|
|
|
|
|
|
using Umbraco.Cms.Core.Models;
|
|
|
|
|
|
using Umbraco.Cms.Core.Models.PublishedContent;
|
|
|
|
|
|
using Umbraco.Cms.Core.PropertyEditors;
|
|
|
|
|
|
using Umbraco.Cms.Core.PublishedCache;
|
|
|
|
|
|
using Umbraco.Cms.Core.Security;
|
|
|
|
|
|
using Umbraco.Cms.Core.Services;
|
|
|
|
|
|
using Umbraco.Cms.Core.Strings;
|
|
|
|
|
|
using Umbraco.Cms.Core.Web;
|
2021-02-15 12:42:26 +01:00
|
|
|
|
using Umbraco.Cms.Infrastructure.Serialization;
|
2021-02-10 14:45:44 +01:00
|
|
|
|
using Umbraco.Cms.Tests.Common;
|
2021-02-09 13:32:34 +01:00
|
|
|
|
using Umbraco.Extensions;
|
2020-12-04 19:01:52 +01:00
|
|
|
|
using Umbraco.Tests.TestHelpers;
|
|
|
|
|
|
using Umbraco.Web;
|
2018-07-11 22:15:58 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Tests.PublishedContent
|
|
|
|
|
|
{
|
|
|
|
|
|
public abstract class PublishedContentSnapshotTestBase : PublishedContentTestBase
|
|
|
|
|
|
{
|
|
|
|
|
|
// read http://stackoverflow.com/questions/7713326/extension-method-that-works-on-ienumerablet-and-iqueryablet
|
|
|
|
|
|
// and http://msmvps.com/blogs/jon_skeet/archive/2010/10/28/overloading-and-generic-constraints.aspx
|
|
|
|
|
|
// and http://blogs.msdn.com/b/ericlippert/archive/2009/12/10/constraints-are-not-part-of-the-signature.aspx
|
|
|
|
|
|
|
|
|
|
|
|
public override void SetUp()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.SetUp();
|
|
|
|
|
|
|
|
|
|
|
|
var umbracoContext = GetUmbracoContext();
|
|
|
|
|
|
Umbraco.Web.Composing.Current.UmbracoContextAccessor.UmbracoContext = umbracoContext;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void Compose()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Compose();
|
|
|
|
|
|
|
2020-11-18 17:40:23 +00:00
|
|
|
|
Builder.Services.AddUnique<IPublishedModelFactory>(f => new PublishedModelFactory(f.GetRequiredService<TypeLoader>().GetTypes<PublishedContentModel>(), f.GetRequiredService<IPublishedValueFallback>()));
|
2018-07-11 22:15:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-29 10:42:06 +02:00
|
|
|
|
protected override TypeLoader CreateTypeLoader(IIOHelper ioHelper, ITypeFinder typeFinder, IAppPolicyCache runtimeCache, ILogger<TypeLoader> logger, IProfilingLogger profilingLogger , IHostingEnvironment hostingEnvironment)
|
2018-07-11 22:15:58 +01:00
|
|
|
|
{
|
2020-09-29 10:42:06 +02:00
|
|
|
|
var baseLoader = base.CreateTypeLoader(ioHelper, typeFinder, runtimeCache, logger, profilingLogger , hostingEnvironment);
|
2018-07-11 22:15:58 +01:00
|
|
|
|
|
2020-09-29 10:42:06 +02:00
|
|
|
|
return new TypeLoader(typeFinder, runtimeCache, new DirectoryInfo(hostingEnvironment.LocalTempPath), logger, profilingLogger , false,
|
2019-11-11 18:56:14 +11:00
|
|
|
|
// this is so the model factory looks into the test assembly
|
|
|
|
|
|
baseLoader.AssembliesToScan
|
|
|
|
|
|
.Union(new[] {typeof(PublishedContentMoreTests).Assembly})
|
|
|
|
|
|
.ToList());
|
2018-07-11 22:15:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-09 18:53:37 +01:00
|
|
|
|
private IUmbracoContext GetUmbracoContext()
|
2018-07-11 22:15:58 +01:00
|
|
|
|
{
|
|
|
|
|
|
RouteData routeData = null;
|
|
|
|
|
|
|
|
|
|
|
|
var publishedSnapshot = CreatePublishedSnapshot();
|
|
|
|
|
|
|
|
|
|
|
|
var publishedSnapshotService = new Mock<IPublishedSnapshotService>();
|
|
|
|
|
|
publishedSnapshotService.Setup(x => x.CreatePublishedSnapshot(It.IsAny<string>())).Returns(publishedSnapshot);
|
|
|
|
|
|
|
|
|
|
|
|
var globalSettings = TestObjects.GetGlobalSettings();
|
|
|
|
|
|
|
|
|
|
|
|
var httpContext = GetHttpContextFactory("http://umbraco.local/", routeData).HttpContext;
|
2020-02-13 12:29:08 +01:00
|
|
|
|
|
2020-02-13 13:57:39 +01:00
|
|
|
|
var httpContextAccessor = TestHelper.GetHttpContextAccessor(httpContext);
|
2018-07-11 22:15:58 +01:00
|
|
|
|
var umbracoContext = new UmbracoContext(
|
2020-02-13 13:57:39 +01:00
|
|
|
|
httpContextAccessor,
|
2018-07-11 22:15:58 +01:00
|
|
|
|
publishedSnapshotService.Object,
|
2020-10-21 16:51:00 +11:00
|
|
|
|
Mock.Of<IBackOfficeSecurity>(),
|
2018-07-11 22:15:58 +01:00
|
|
|
|
globalSettings,
|
2020-04-03 11:03:06 +11:00
|
|
|
|
HostingEnvironment,
|
2019-12-04 14:03:39 +01:00
|
|
|
|
new TestVariationContextAccessor(),
|
2020-02-19 09:26:51 +01:00
|
|
|
|
UriUtility,
|
|
|
|
|
|
new AspNetCookieManager(httpContextAccessor));
|
2018-07-11 22:15:58 +01:00
|
|
|
|
|
|
|
|
|
|
return umbracoContext;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private SolidPublishedSnapshot CreatePublishedSnapshot()
|
|
|
|
|
|
{
|
2020-11-17 20:27:10 +01:00
|
|
|
|
var serializer = new ConfigurationEditorJsonSerializer();
|
2018-07-11 22:15:58 +01:00
|
|
|
|
var dataTypeService = new TestObjects.TestDataTypeService(
|
2021-05-18 12:40:24 +02:00
|
|
|
|
new DataType(new VoidEditor(DataValueEditorFactory), serializer) { Id = 1 });
|
2018-07-11 22:15:58 +01:00
|
|
|
|
|
|
|
|
|
|
var factory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), new PropertyValueConverterCollection(Array.Empty<IPropertyValueConverter>()), dataTypeService);
|
|
|
|
|
|
var caches = new SolidPublishedSnapshot();
|
|
|
|
|
|
var cache = caches.InnerContentCache;
|
|
|
|
|
|
PopulateCache(factory, cache);
|
|
|
|
|
|
return caches;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
internal abstract void PopulateCache(PublishedContentTypeFactory factory, SolidPublishedContentCache cache);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|