From d6a601680159903590d3a35ca76580901c7c1b27 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 24 Jun 2021 10:25:23 -0600 Subject: [PATCH] implement noop published snapshot service, splits tests models for published content, fixes sqlce image mapper to not have circular ref. --- .../Configuration/Models/NuCacheSettings.cs | 2 + .../DependencyInjection/UmbracoBuilder.cs | 5 + .../Internal/InternalPublishedContent.cs | 104 +++++ .../Internal/InternalPublishedContentCache.cs | 62 +++ .../Internal/InternalPublishedProperty.cs | 27 ++ .../Internal/InternalPublishedSnapshot.cs | 33 ++ .../InternalPublishedSnapshotService.cs | 60 +++ .../SqlCeImageMapper.cs | 19 +- .../AutoPublishedContentType.cs | 67 +++ .../PublishedContent/ContentType2.cs | 20 + .../PublishedContent/ContentType2Sub.cs | 16 + ...alPublishedPropertyWithLanguageVariants.cs | 84 ++++ .../PublishedContentStrong1.cs | 19 + .../PublishedContentStrong1Sub.cs | 19 + .../PublishedContentStrong2.cs | 19 + .../TestHelpers/SolidPublishedSnapshot.cs | 398 ------------------ .../ComponentRuntimeTests.cs | 1 - .../PropertyEditors/ConvertersTests.cs | 9 +- .../Umbraco.Core/Published/ConvertersTests.cs | 3 +- .../Published/NestedContentTests.cs | 5 +- 20 files changed, 560 insertions(+), 412 deletions(-) create mode 100644 src/Umbraco.Core/PublishedCache/Internal/InternalPublishedContent.cs create mode 100644 src/Umbraco.Core/PublishedCache/Internal/InternalPublishedContentCache.cs create mode 100644 src/Umbraco.Core/PublishedCache/Internal/InternalPublishedProperty.cs create mode 100644 src/Umbraco.Core/PublishedCache/Internal/InternalPublishedSnapshot.cs create mode 100644 src/Umbraco.Core/PublishedCache/Internal/InternalPublishedSnapshotService.cs create mode 100644 src/Umbraco.Tests.Common/TestHelpers/PublishedContent/AutoPublishedContentType.cs create mode 100644 src/Umbraco.Tests.Common/TestHelpers/PublishedContent/ContentType2.cs create mode 100644 src/Umbraco.Tests.Common/TestHelpers/PublishedContent/ContentType2Sub.cs create mode 100644 src/Umbraco.Tests.Common/TestHelpers/PublishedContent/InternalPublishedPropertyWithLanguageVariants.cs create mode 100644 src/Umbraco.Tests.Common/TestHelpers/PublishedContent/PublishedContentStrong1.cs create mode 100644 src/Umbraco.Tests.Common/TestHelpers/PublishedContent/PublishedContentStrong1Sub.cs create mode 100644 src/Umbraco.Tests.Common/TestHelpers/PublishedContent/PublishedContentStrong2.cs delete mode 100644 src/Umbraco.Tests.Common/TestHelpers/SolidPublishedSnapshot.cs diff --git a/src/Umbraco.Core/Configuration/Models/NuCacheSettings.cs b/src/Umbraco.Core/Configuration/Models/NuCacheSettings.cs index 865d50afbc..024e533fb3 100644 --- a/src/Umbraco.Core/Configuration/Models/NuCacheSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/NuCacheSettings.cs @@ -13,6 +13,8 @@ namespace Umbraco.Cms.Core.Configuration.Models /// public int? BTreeBlockSize { get; set; } + // TODO: Set default to MessagePack + /// /// The serializer type that nucache uses to persist documents in the database. /// diff --git a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs index c513e9910b..f9fde4c47e 100644 --- a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs +++ b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs @@ -29,6 +29,8 @@ using Umbraco.Cms.Core.Manifest; using Umbraco.Cms.Core.Models.PublishedContent; using Umbraco.Cms.Core.Notifications; using Umbraco.Cms.Core.PropertyEditors; +using Umbraco.Cms.Core.PublishedCache; +using Umbraco.Cms.Core.PublishedCache.Internal; using Umbraco.Cms.Core.Routing; using Umbraco.Cms.Core.Runtime; using Umbraco.Cms.Core.Security; @@ -229,6 +231,9 @@ namespace Umbraco.Cms.Core.DependencyInjection .AddNotificationHandler(); Services.AddSingleton(); + + // register a basic/noop published snapshot service to be replaced + Services.AddSingleton(); } } } diff --git a/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedContent.cs b/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedContent.cs new file mode 100644 index 0000000000..34152ebc0f --- /dev/null +++ b/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedContent.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Umbraco.Cms.Core.Models.PublishedContent; +using Umbraco.Extensions; + +namespace Umbraco.Cms.Core.PublishedCache.Internal +{ + + public sealed class InternalPublishedContent : IPublishedContent + { + public InternalPublishedContent(IPublishedContentType contentType) + { + // initialize boring stuff + TemplateId = 0; + WriterId = CreatorId = 0; + CreateDate = UpdateDate = DateTime.Now; + Version = Guid.Empty; + + ContentType = contentType; + } + + private Dictionary _cultures; + + private Dictionary GetCultures() => new Dictionary { { string.Empty, new PublishedCultureInfo(string.Empty, Name, UrlSegment, UpdateDate) } }; + + public int Id { get; set; } + + public Guid Key { get; set; } + + public int? TemplateId { get; set; } + + public int SortOrder { get; set; } + + public string Name { get; set; } + + public IReadOnlyDictionary Cultures => _cultures ??= GetCultures(); + + public string UrlSegment { get; set; } + + public int WriterId { get; set; } + + public int CreatorId { get; set; } + + public string Path { get; set; } + + public DateTime CreateDate { get; set; } + + public DateTime UpdateDate { get; set; } + + public Guid Version { get; set; } + + public int Level { get; set; } + + public PublishedItemType ItemType => PublishedItemType.Content; + + public bool IsDraft(string culture = null) => false; + + public bool IsPublished(string culture = null) => true; + + public int ParentId { get; set; } + + public IEnumerable ChildIds { get; set; } + + public IPublishedContent Parent { get; set; } + + public IEnumerable Children { get; set; } + + public IEnumerable ChildrenForAllCultures => Children; + + public IPublishedContentType ContentType { get; set; } + + public IEnumerable Properties { get; set; } + + public IPublishedProperty GetProperty(string alias) => Properties.FirstOrDefault(p => p.Alias.InvariantEquals(alias)); + + public IPublishedProperty GetProperty(string alias, bool recurse) + { + IPublishedProperty property = GetProperty(alias); + if (recurse == false) + { + return property; + } + + IPublishedContent content = this; + while (content != null && (property == null || property.HasValue() == false)) + { + content = content.Parent; + property = content?.GetProperty(alias); + } + + return property; + } + + public object this[string alias] + { + get + { + var property = GetProperty(alias); + return property == null || property.HasValue() == false ? null : property.GetValue(); + } + } + } +} diff --git a/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedContentCache.cs b/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedContentCache.cs new file mode 100644 index 0000000000..2a197affff --- /dev/null +++ b/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedContentCache.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Umbraco.Cms.Core.Models.PublishedContent; +using Umbraco.Cms.Core.Xml; + +namespace Umbraco.Cms.Core.PublishedCache.Internal +{ + public sealed class InternalPublishedContentCache : PublishedCacheBase, IPublishedContentCache, IPublishedMediaCache + { + private readonly Dictionary _content = new Dictionary(); + + public InternalPublishedContentCache() + : base(false) + { + } + + //public void Add(InternalPublishedContent content) => _content[content.Id] = content.CreateModel(Mock.Of()); + + public void Clear() => _content.Clear(); + + public IPublishedContent GetByRoute(bool preview, string route, bool? hideTopLevelNode = null, string culture = null) => throw new NotImplementedException(); + + public IPublishedContent GetByRoute(string route, bool? hideTopLevelNode = null, string culture = null) => throw new NotImplementedException(); + + public string GetRouteById(bool preview, int contentId, string culture = null) => throw new NotImplementedException(); + + public string GetRouteById(int contentId, string culture = null) => throw new NotImplementedException(); + + public override IPublishedContent GetById(bool preview, int contentId) => _content.ContainsKey(contentId) ? _content[contentId] : null; + + public override IPublishedContent GetById(bool preview, Guid contentId) => throw new NotImplementedException(); + + public override IPublishedContent GetById(bool preview, Udi nodeId) => throw new NotSupportedException(); + + public override bool HasById(bool preview, int contentId) => _content.ContainsKey(contentId); + + public override IEnumerable GetAtRoot(bool preview, string culture = null) => _content.Values.Where(x => x.Parent == null); + + public override IPublishedContent GetSingleByXPath(bool preview, string xpath, XPathVariable[] vars) => throw new NotImplementedException(); + + public override IPublishedContent GetSingleByXPath(bool preview, System.Xml.XPath.XPathExpression xpath, XPathVariable[] vars) => throw new NotImplementedException(); + + public override IEnumerable GetByXPath(bool preview, string xpath, XPathVariable[] vars) => throw new NotImplementedException(); + + public override IEnumerable GetByXPath(bool preview, System.Xml.XPath.XPathExpression xpath, XPathVariable[] vars) => throw new NotImplementedException(); + + public override System.Xml.XPath.XPathNavigator CreateNavigator(bool preview) => throw new NotImplementedException(); + + public override System.Xml.XPath.XPathNavigator CreateNodeNavigator(int id, bool preview) => throw new NotImplementedException(); + + public override bool HasContent(bool preview) => _content.Count > 0; + + public override IPublishedContentType GetContentType(int id) => throw new NotImplementedException(); + + public override IPublishedContentType GetContentType(string alias) => throw new NotImplementedException(); + + public override IPublishedContentType GetContentType(Guid key) => throw new NotImplementedException(); + + public override IEnumerable GetByContentType(IPublishedContentType contentType) => throw new NotImplementedException(); + } +} diff --git a/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedProperty.cs b/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedProperty.cs new file mode 100644 index 0000000000..a98eff6484 --- /dev/null +++ b/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedProperty.cs @@ -0,0 +1,27 @@ +using Umbraco.Cms.Core.Models.PublishedContent; + +namespace Umbraco.Cms.Core.PublishedCache.Internal +{ + public class InternalPublishedProperty : IPublishedProperty + { + public IPublishedPropertyType PropertyType { get; set; } + + public string Alias { get; set; } + + public object SolidSourceValue { get; set; } + + public object SolidValue { get; set; } + + public bool SolidHasValue { get; set; } + + public object SolidXPathValue { get; set; } + + public virtual object GetSourceValue(string culture = null, string segment = null) => SolidSourceValue; + + public virtual object GetValue(string culture = null, string segment = null) => SolidValue; + + public virtual object GetXPathValue(string culture = null, string segment = null) => SolidXPathValue; + + public virtual bool HasValue(string culture = null, string segment = null) => SolidHasValue; + } +} diff --git a/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedSnapshot.cs b/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedSnapshot.cs new file mode 100644 index 0000000000..c73b6cef76 --- /dev/null +++ b/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedSnapshot.cs @@ -0,0 +1,33 @@ +using System; +using Umbraco.Cms.Core.Cache; + +namespace Umbraco.Cms.Core.PublishedCache.Internal +{ + public sealed class InternalPublishedSnapshot : IPublishedSnapshot + { + public InternalPublishedContentCache InnerContentCache { get; } = new InternalPublishedContentCache(); + public InternalPublishedContentCache InnerMediaCache { get; } = new InternalPublishedContentCache(); + + public IPublishedContentCache Content => InnerContentCache; + + public IPublishedMediaCache Media => InnerMediaCache; + + public IPublishedMemberCache Members => null; + + public IDomainCache Domains => null; + + public IDisposable ForcedPreview(bool forcedPreview, Action callback = null) => throw new NotImplementedException(); + + public void Resync() + { + } + + public IAppCache SnapshotCache => null; + + public IAppCache ElementsCache => null; + + public void Dispose() + { + } + } +} diff --git a/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedSnapshotService.cs b/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedSnapshotService.cs new file mode 100644 index 0000000000..5dcdc5189f --- /dev/null +++ b/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedSnapshotService.cs @@ -0,0 +1,60 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Umbraco.Cms.Core.Cache; +using Umbraco.Extensions; + +namespace Umbraco.Cms.Core.PublishedCache.Internal +{ + public class InternalPublishedSnapshotService : IPublishedSnapshotService + { + private InternalPublishedSnapshot _snapshot; + private InternalPublishedSnapshot _previewSnapshot; + + public Task CollectAsync() => Task.CompletedTask; + + public IPublishedSnapshot CreatePublishedSnapshot(string previewToken) + { + if (previewToken.IsNullOrWhiteSpace()) + { + return _snapshot ??= new InternalPublishedSnapshot(); + } + else + { + return _previewSnapshot ??= new InternalPublishedSnapshot(); + } + } + + public void Dispose() + { + _snapshot?.Dispose(); + _previewSnapshot?.Dispose(); + } + + public void Notify(ContentCacheRefresher.JsonPayload[] payloads, out bool draftChanged, out bool publishedChanged) + { + draftChanged = false; + publishedChanged = false; + } + + public void Notify(MediaCacheRefresher.JsonPayload[] payloads, out bool anythingChanged) + { + anythingChanged = false; + } + + public void Notify(ContentTypeCacheRefresher.JsonPayload[] payloads) + { + } + + public void Notify(DataTypeCacheRefresher.JsonPayload[] payloads) + { + } + + public void Notify(DomainCacheRefresher.JsonPayload[] payloads) + { + } + + public void Rebuild(IReadOnlyCollection contentTypeIds = null, IReadOnlyCollection mediaTypeIds = null, IReadOnlyCollection memberTypeIds = null) + { + } + } +} diff --git a/src/Umbraco.Persistence.SqlCe/SqlCeImageMapper.cs b/src/Umbraco.Persistence.SqlCe/SqlCeImageMapper.cs index 28b2d6a185..8349056440 100644 --- a/src/Umbraco.Persistence.SqlCe/SqlCeImageMapper.cs +++ b/src/Umbraco.Persistence.SqlCe/SqlCeImageMapper.cs @@ -17,9 +17,9 @@ namespace Umbraco.Cms.Persistence.SqlCe /// public class SqlCeImageMapper : DefaultMapper { - private readonly IUmbracoDatabaseFactory _dbFactory; + //private readonly IUmbracoDatabaseFactory _dbFactory; - public SqlCeImageMapper(IUmbracoDatabaseFactory dbFactory) => _dbFactory = dbFactory; + //public SqlCeImageMapper(IUmbracoDatabaseFactory dbFactory) => _dbFactory = dbFactory; public override Func GetToDbConverter(Type destType, MemberInfo sourceMemberInfo) { @@ -27,10 +27,17 @@ namespace Umbraco.Cms.Persistence.SqlCe { return x => { - var pd = _dbFactory.SqlContext.PocoDataFactory.ForType(sourceMemberInfo.DeclaringType); - if (pd == null) return null; - var col = pd.AllColumns.FirstOrDefault(x => x.MemberInfoData.MemberInfo == sourceMemberInfo); - if (col == null) return null; + //PocoData pd = _dbFactory.SqlContext.PocoDataFactory.ForType(sourceMemberInfo.DeclaringType); + //if (pd == null) + //{ + // return null; + //} + + //PocoColumn col = pd.AllColumns.FirstOrDefault(x => x.MemberInfoData.MemberInfo == sourceMemberInfo); + //if (col == null) + //{ + // return null; + //} return new SqlCeParameter { diff --git a/src/Umbraco.Tests.Common/TestHelpers/PublishedContent/AutoPublishedContentType.cs b/src/Umbraco.Tests.Common/TestHelpers/PublishedContent/AutoPublishedContentType.cs new file mode 100644 index 0000000000..5d546cb8d5 --- /dev/null +++ b/src/Umbraco.Tests.Common/TestHelpers/PublishedContent/AutoPublishedContentType.cs @@ -0,0 +1,67 @@ +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using System; +using System.Collections.Generic; +using System.Linq; +using Moq; +using Umbraco.Cms.Core.Models; +using Umbraco.Cms.Core.Models.PublishedContent; +using Umbraco.Cms.Core.PropertyEditors; +using Umbraco.Cms.Core.Services; +using Umbraco.Cms.Infrastructure.Serialization; +using Umbraco.Extensions; + +namespace Umbraco.Cms.Tests.Common.TestHelpers.PublishedContent +{ + + public class AutoPublishedContentType : PublishedContentType + { + private static readonly IPublishedPropertyType Default; + + static AutoPublishedContentType() + { + var configurationEditorJsonSerializer = new ConfigurationEditorJsonSerializer(); + var jsonSerializer = new JsonNetSerializer(); + var dataTypeServiceMock = new Mock(); + + var dataType = new DataType( + new VoidEditor( + Mock.Of()), + configurationEditorJsonSerializer) + { + Id = 666 + }; + dataTypeServiceMock.Setup(x => x.GetAll()).Returns(dataType.Yield); + + var factory = new PublishedContentTypeFactory(Mock.Of(), new PropertyValueConverterCollection(Array.Empty()), dataTypeServiceMock.Object); + Default = factory.CreatePropertyType("*", 666); + } + + public AutoPublishedContentType(Guid key, int id, string alias, IEnumerable propertyTypes) + : base(key, id, alias, PublishedItemType.Content, Enumerable.Empty(), propertyTypes, ContentVariation.Nothing) + { + } + + public AutoPublishedContentType(Guid key, int id, string alias, Func> propertyTypes) + : base(key, id, alias, PublishedItemType.Content, Enumerable.Empty(), propertyTypes, ContentVariation.Nothing) + { + } + + public AutoPublishedContentType(Guid key, int id, string alias, IEnumerable compositionAliases, IEnumerable propertyTypes) + : base(key, id, alias, PublishedItemType.Content, compositionAliases, propertyTypes, ContentVariation.Nothing) + { + } + + public AutoPublishedContentType(Guid key, int id, string alias, IEnumerable compositionAliases, Func> propertyTypes) + : base(key, id, alias, PublishedItemType.Content, compositionAliases, propertyTypes, ContentVariation.Nothing) + { + } + + public override IPublishedPropertyType GetPropertyType(string alias) + { + IPublishedPropertyType propertyType = base.GetPropertyType(alias); + return propertyType ?? Default; + } + } +} diff --git a/src/Umbraco.Tests.Common/TestHelpers/PublishedContent/ContentType2.cs b/src/Umbraco.Tests.Common/TestHelpers/PublishedContent/ContentType2.cs new file mode 100644 index 0000000000..37d2bb6949 --- /dev/null +++ b/src/Umbraco.Tests.Common/TestHelpers/PublishedContent/ContentType2.cs @@ -0,0 +1,20 @@ +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using Moq; +using Umbraco.Cms.Core.Models.PublishedContent; +using Umbraco.Extensions; + +namespace Umbraco.Cms.Tests.Common.TestHelpers.PublishedContent +{ + [PublishedModel("ContentType2")] + public class ContentType2 : PublishedContentModel + { + public ContentType2(IPublishedContent content, IPublishedValueFallback fallback) + : base(content, fallback) + { + } + + public int Prop1 => this.Value(Mock.Of(), "prop1"); + } +} diff --git a/src/Umbraco.Tests.Common/TestHelpers/PublishedContent/ContentType2Sub.cs b/src/Umbraco.Tests.Common/TestHelpers/PublishedContent/ContentType2Sub.cs new file mode 100644 index 0000000000..0e2d6f9f16 --- /dev/null +++ b/src/Umbraco.Tests.Common/TestHelpers/PublishedContent/ContentType2Sub.cs @@ -0,0 +1,16 @@ +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using Umbraco.Cms.Core.Models.PublishedContent; + +namespace Umbraco.Cms.Tests.Common.TestHelpers.PublishedContent +{ + [PublishedModel("ContentType2Sub")] + public class ContentType2Sub : ContentType2 + { + public ContentType2Sub(IPublishedContent content, IPublishedValueFallback fallback) + : base(content, fallback) + { + } + } +} diff --git a/src/Umbraco.Tests.Common/TestHelpers/PublishedContent/InternalPublishedPropertyWithLanguageVariants.cs b/src/Umbraco.Tests.Common/TestHelpers/PublishedContent/InternalPublishedPropertyWithLanguageVariants.cs new file mode 100644 index 0000000000..842cba6061 --- /dev/null +++ b/src/Umbraco.Tests.Common/TestHelpers/PublishedContent/InternalPublishedPropertyWithLanguageVariants.cs @@ -0,0 +1,84 @@ +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using System.Collections.Generic; +using Umbraco.Cms.Core.PublishedCache.Internal; + +namespace Umbraco.Cms.Tests.Common.TestHelpers.PublishedContent +{ + public class InternalPublishedPropertyWithLanguageVariants : InternalPublishedProperty + { + private readonly IDictionary _solidSourceValues = new Dictionary(); + private readonly IDictionary _solidValues = new Dictionary(); + private readonly IDictionary _solidXPathValues = new Dictionary(); + + public override object GetSourceValue(string culture = null, string segment = null) + { + if (string.IsNullOrEmpty(culture)) + { + return base.GetSourceValue(culture, segment); + } + + return _solidSourceValues.ContainsKey(culture) ? _solidSourceValues[culture] : null; + } + + public override object GetValue(string culture = null, string segment = null) + { + if (string.IsNullOrEmpty(culture)) + { + return base.GetValue(culture, segment); + } + + return _solidValues.ContainsKey(culture) ? _solidValues[culture] : null; + } + + public override object GetXPathValue(string culture = null, string segment = null) + { + if (string.IsNullOrEmpty(culture)) + { + return base.GetXPathValue(culture, segment); + } + + return _solidXPathValues.ContainsKey(culture) ? _solidXPathValues[culture] : null; + } + + public override bool HasValue(string culture = null, string segment = null) + { + if (string.IsNullOrEmpty(culture)) + { + return base.HasValue(culture, segment); + } + + return _solidSourceValues.ContainsKey(culture); + } + + public void SetSourceValue(string culture, object value, bool defaultValue = false) + { + _solidSourceValues.Add(culture, value); + if (defaultValue) + { + SolidSourceValue = value; + SolidHasValue = true; + } + } + + public void SetValue(string culture, object value, bool defaultValue = false) + { + _solidValues.Add(culture, value); + if (defaultValue) + { + SolidValue = value; + SolidHasValue = true; + } + } + + public void SetXPathValue(string culture, object value, bool defaultValue = false) + { + _solidXPathValues.Add(culture, value); + if (defaultValue) + { + SolidXPathValue = value; + } + } + } +} diff --git a/src/Umbraco.Tests.Common/TestHelpers/PublishedContent/PublishedContentStrong1.cs b/src/Umbraco.Tests.Common/TestHelpers/PublishedContent/PublishedContentStrong1.cs new file mode 100644 index 0000000000..8c2d501d3e --- /dev/null +++ b/src/Umbraco.Tests.Common/TestHelpers/PublishedContent/PublishedContentStrong1.cs @@ -0,0 +1,19 @@ +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using Moq; +using Umbraco.Cms.Core.Models.PublishedContent; +using Umbraco.Extensions; + +namespace Umbraco.Cms.Tests.Common.TestHelpers.PublishedContent +{ + public class PublishedContentStrong1 : PublishedContentModel + { + public PublishedContentStrong1(IPublishedContent content, IPublishedValueFallback fallback) + : base(content, fallback) + { + } + + public int StrongValue => this.Value(Mock.Of(), "strongValue"); + } +} diff --git a/src/Umbraco.Tests.Common/TestHelpers/PublishedContent/PublishedContentStrong1Sub.cs b/src/Umbraco.Tests.Common/TestHelpers/PublishedContent/PublishedContentStrong1Sub.cs new file mode 100644 index 0000000000..96748b4136 --- /dev/null +++ b/src/Umbraco.Tests.Common/TestHelpers/PublishedContent/PublishedContentStrong1Sub.cs @@ -0,0 +1,19 @@ +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using Moq; +using Umbraco.Cms.Core.Models.PublishedContent; +using Umbraco.Extensions; + +namespace Umbraco.Cms.Tests.Common.TestHelpers.PublishedContent +{ + public class PublishedContentStrong1Sub : PublishedContentStrong1 + { + public PublishedContentStrong1Sub(IPublishedContent content, IPublishedValueFallback fallback) + : base(content, fallback) + { + } + + public int AnotherValue => this.Value(Mock.Of(), "anotherValue"); + } +} diff --git a/src/Umbraco.Tests.Common/TestHelpers/PublishedContent/PublishedContentStrong2.cs b/src/Umbraco.Tests.Common/TestHelpers/PublishedContent/PublishedContentStrong2.cs new file mode 100644 index 0000000000..0b88c56eaa --- /dev/null +++ b/src/Umbraco.Tests.Common/TestHelpers/PublishedContent/PublishedContentStrong2.cs @@ -0,0 +1,19 @@ +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using Moq; +using Umbraco.Cms.Core.Models.PublishedContent; +using Umbraco.Extensions; + +namespace Umbraco.Cms.Tests.Common.TestHelpers.PublishedContent +{ + public class PublishedContentStrong2 : PublishedContentModel + { + public PublishedContentStrong2(IPublishedContent content, IPublishedValueFallback fallback) + : base(content, fallback) + { + } + + public int StrongValue => this.Value(Mock.Of(), "strongValue"); + } +} diff --git a/src/Umbraco.Tests.Common/TestHelpers/SolidPublishedSnapshot.cs b/src/Umbraco.Tests.Common/TestHelpers/SolidPublishedSnapshot.cs deleted file mode 100644 index 17d167bf0d..0000000000 --- a/src/Umbraco.Tests.Common/TestHelpers/SolidPublishedSnapshot.cs +++ /dev/null @@ -1,398 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.Extensions.Logging; -using Moq; -using Umbraco.Cms.Core; -using Umbraco.Cms.Core.Cache; -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.Services; -using Umbraco.Cms.Core.Strings; -using Umbraco.Cms.Core.Xml; -using Umbraco.Cms.Infrastructure.Serialization; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Tests.Common.TestHelpers -{ - public class SolidPublishedSnapshot : IPublishedSnapshot - { - public readonly SolidPublishedContentCache InnerContentCache = new SolidPublishedContentCache(); - public readonly SolidPublishedContentCache InnerMediaCache = new SolidPublishedContentCache(); - - public IPublishedContentCache Content => InnerContentCache; - - public IPublishedMediaCache Media => InnerMediaCache; - - public IPublishedMemberCache Members => null; - - public IDomainCache Domains => null; - - public IDisposable ForcedPreview(bool forcedPreview, Action callback = null) => throw new NotImplementedException(); - - public void Resync() - { - } - - public IAppCache SnapshotCache => null; - - public IAppCache ElementsCache => null; - - public void Dispose() - { - } - } - - public class SolidPublishedContentCache : PublishedCacheBase, IPublishedContentCache, IPublishedMediaCache - { - private readonly Dictionary _content = new Dictionary(); - - public SolidPublishedContentCache() - : base(false) - { - } - - public void Add(SolidPublishedContent content) => _content[content.Id] = content.CreateModel(Mock.Of()); - - public void Clear() => _content.Clear(); - - public IPublishedContent GetByRoute(bool preview, string route, bool? hideTopLevelNode = null, string culture = null) => throw new NotImplementedException(); - - public IPublishedContent GetByRoute(string route, bool? hideTopLevelNode = null, string culture = null) => throw new NotImplementedException(); - - public string GetRouteById(bool preview, int contentId, string culture = null) => throw new NotImplementedException(); - - public string GetRouteById(int contentId, string culture = null) => throw new NotImplementedException(); - - public override IPublishedContent GetById(bool preview, int contentId) => _content.ContainsKey(contentId) ? _content[contentId] : null; - - public override IPublishedContent GetById(bool preview, Guid contentId) => throw new NotImplementedException(); - - public override IPublishedContent GetById(bool preview, Udi nodeId) => throw new NotSupportedException(); - - public override bool HasById(bool preview, int contentId) => _content.ContainsKey(contentId); - - public override IEnumerable GetAtRoot(bool preview, string culture = null) => _content.Values.Where(x => x.Parent == null); - - public override IPublishedContent GetSingleByXPath(bool preview, string xpath, XPathVariable[] vars) => throw new NotImplementedException(); - - public override IPublishedContent GetSingleByXPath(bool preview, System.Xml.XPath.XPathExpression xpath, XPathVariable[] vars) => throw new NotImplementedException(); - - public override IEnumerable GetByXPath(bool preview, string xpath, XPathVariable[] vars) => throw new NotImplementedException(); - - public override IEnumerable GetByXPath(bool preview, System.Xml.XPath.XPathExpression xpath, XPathVariable[] vars) => throw new NotImplementedException(); - - public override System.Xml.XPath.XPathNavigator CreateNavigator(bool preview) => throw new NotImplementedException(); - - public override System.Xml.XPath.XPathNavigator CreateNodeNavigator(int id, bool preview) => throw new NotImplementedException(); - - public override bool HasContent(bool preview) => _content.Count > 0; - - public override IPublishedContentType GetContentType(int id) => throw new NotImplementedException(); - - public override IPublishedContentType GetContentType(string alias) => throw new NotImplementedException(); - - public override IPublishedContentType GetContentType(Guid key) => throw new NotImplementedException(); - - public override IEnumerable GetByContentType(IPublishedContentType contentType) => throw new NotImplementedException(); - } - - public class SolidPublishedContent : IPublishedContent - { - public SolidPublishedContent(IPublishedContentType contentType) - { - // initialize boring stuff - TemplateId = 0; - WriterId = CreatorId = 0; - CreateDate = UpdateDate = DateTime.Now; - Version = Guid.Empty; - - ContentType = contentType; - } - - private Dictionary _cultures; - - private Dictionary GetCultures() => new Dictionary { { string.Empty, new PublishedCultureInfo(string.Empty, Name, UrlSegment, UpdateDate) } }; - - public int Id { get; set; } - - public Guid Key { get; set; } - - public int? TemplateId { get; set; } - - public int SortOrder { get; set; } - - public string Name { get; set; } - - public IReadOnlyDictionary Cultures => _cultures ?? (_cultures = GetCultures()); - - public string UrlSegment { get; set; } - - public int WriterId { get; set; } - - public int CreatorId { get; set; } - - public string Path { get; set; } - - public DateTime CreateDate { get; set; } - - public DateTime UpdateDate { get; set; } - - public Guid Version { get; set; } - - public int Level { get; set; } - - public PublishedItemType ItemType => PublishedItemType.Content; - - public bool IsDraft(string culture = null) => false; - - public bool IsPublished(string culture = null) => true; - - public int ParentId { get; set; } - - public IEnumerable ChildIds { get; set; } - - public IPublishedContent Parent { get; set; } - - public IEnumerable Children { get; set; } - - public IEnumerable ChildrenForAllCultures => Children; - - public IPublishedContentType ContentType { get; set; } - - public IEnumerable Properties { get; set; } - - public IPublishedProperty GetProperty(string alias) => Properties.FirstOrDefault(p => p.Alias.InvariantEquals(alias)); - - public IPublishedProperty GetProperty(string alias, bool recurse) - { - IPublishedProperty property = GetProperty(alias); - if (recurse == false) - { - return property; - } - - IPublishedContent content = this; - while (content != null && (property == null || property.HasValue() == false)) - { - content = content.Parent; - property = content?.GetProperty(alias); - } - - return property; - } - - public object this[string alias] - { - get - { - var property = GetProperty(alias); - return property == null || property.HasValue() == false ? null : property.GetValue(); - } - } - } - - public class SolidPublishedProperty : IPublishedProperty - { - public IPublishedPropertyType PropertyType { get; set; } - - public string Alias { get; set; } - - public object SolidSourceValue { get; set; } - - public object SolidValue { get; set; } - - public bool SolidHasValue { get; set; } - - public object SolidXPathValue { get; set; } - - public virtual object GetSourceValue(string culture = null, string segment = null) => SolidSourceValue; - - public virtual object GetValue(string culture = null, string segment = null) => SolidValue; - - public virtual object GetXPathValue(string culture = null, string segment = null) => SolidXPathValue; - - public virtual bool HasValue(string culture = null, string segment = null) => SolidHasValue; - } - - public class SolidPublishedPropertyWithLanguageVariants : SolidPublishedProperty - { - private readonly IDictionary _solidSourceValues = new Dictionary(); - private readonly IDictionary _solidValues = new Dictionary(); - private readonly IDictionary _solidXPathValues = new Dictionary(); - - public override object GetSourceValue(string culture = null, string segment = null) - { - if (string.IsNullOrEmpty(culture)) - { - return base.GetSourceValue(culture, segment); - } - - return _solidSourceValues.ContainsKey(culture) ? _solidSourceValues[culture] : null; - } - - public override object GetValue(string culture = null, string segment = null) - { - if (string.IsNullOrEmpty(culture)) - { - return base.GetValue(culture, segment); - } - - return _solidValues.ContainsKey(culture) ? _solidValues[culture] : null; - } - - public override object GetXPathValue(string culture = null, string segment = null) - { - if (string.IsNullOrEmpty(culture)) - { - return base.GetXPathValue(culture, segment); - } - - return _solidXPathValues.ContainsKey(culture) ? _solidXPathValues[culture] : null; - } - - public override bool HasValue(string culture = null, string segment = null) - { - if (string.IsNullOrEmpty(culture)) - { - return base.HasValue(culture, segment); - } - - return _solidSourceValues.ContainsKey(culture); - } - - public void SetSourceValue(string culture, object value, bool defaultValue = false) - { - _solidSourceValues.Add(culture, value); - if (defaultValue) - { - SolidSourceValue = value; - SolidHasValue = true; - } - } - - public void SetValue(string culture, object value, bool defaultValue = false) - { - _solidValues.Add(culture, value); - if (defaultValue) - { - SolidValue = value; - SolidHasValue = true; - } - } - - public void SetXPathValue(string culture, object value, bool defaultValue = false) - { - _solidXPathValues.Add(culture, value); - if (defaultValue) - { - SolidXPathValue = value; - } - } - } - - [PublishedModel("ContentType2")] - public class ContentType2 : PublishedContentModel - { - public ContentType2(IPublishedContent content, IPublishedValueFallback fallback) - : base(content, fallback) - { - } - - public int Prop1 => this.Value(Mock.Of(), "prop1"); - } - - [PublishedModel("ContentType2Sub")] - public class ContentType2Sub : ContentType2 - { - public ContentType2Sub(IPublishedContent content, IPublishedValueFallback fallback) - : base(content, fallback) - { - } - } - - public class PublishedContentStrong1 : PublishedContentModel - { - public PublishedContentStrong1(IPublishedContent content, IPublishedValueFallback fallback) - : base(content, fallback) - { - } - - public int StrongValue => this.Value(Mock.Of(), "strongValue"); - } - - public class PublishedContentStrong1Sub : PublishedContentStrong1 - { - public PublishedContentStrong1Sub(IPublishedContent content, IPublishedValueFallback fallback) - : base(content, fallback) - { - } - - public int AnotherValue => this.Value(Mock.Of(), "anotherValue"); - } - - public class PublishedContentStrong2 : PublishedContentModel - { - public PublishedContentStrong2(IPublishedContent content, IPublishedValueFallback fallback) - : base(content, fallback) - { - } - - public int StrongValue => this.Value(Mock.Of(), "strongValue"); - } - - public class AutoPublishedContentType : PublishedContentType - { - private static readonly IPublishedPropertyType Default; - - static AutoPublishedContentType() - { - var configurationEditorJsonSerializer = new ConfigurationEditorJsonSerializer(); - var jsonSerializer = new JsonNetSerializer(); - var dataTypeServiceMock = new Mock(); - - var dataType = new DataType( - new VoidEditor( - Mock.Of()), - configurationEditorJsonSerializer) - { - Id = 666 - }; - dataTypeServiceMock.Setup(x => x.GetAll()).Returns(dataType.Yield); - - var factory = new PublishedContentTypeFactory(Mock.Of(), new PropertyValueConverterCollection(Array.Empty()), dataTypeServiceMock.Object); - Default = factory.CreatePropertyType("*", 666); - } - - public AutoPublishedContentType(Guid key, int id, string alias, IEnumerable propertyTypes) - : base(key, id, alias, PublishedItemType.Content, Enumerable.Empty(), propertyTypes, ContentVariation.Nothing) - { - } - - public AutoPublishedContentType(Guid key, int id, string alias, Func> propertyTypes) - : base(key, id, alias, PublishedItemType.Content, Enumerable.Empty(), propertyTypes, ContentVariation.Nothing) - { - } - - public AutoPublishedContentType(Guid key, int id, string alias, IEnumerable compositionAliases, IEnumerable propertyTypes) - : base(key, id, alias, PublishedItemType.Content, compositionAliases, propertyTypes, ContentVariation.Nothing) - { - } - - public AutoPublishedContentType(Guid key, int id, string alias, IEnumerable compositionAliases, Func> propertyTypes) - : base(key, id, alias, PublishedItemType.Content, compositionAliases, propertyTypes, ContentVariation.Nothing) - { - } - - public override IPublishedPropertyType GetPropertyType(string alias) - { - IPublishedPropertyType propertyType = base.GetPropertyType(alias); - return propertyType ?? Default; - } - } -} diff --git a/src/Umbraco.Tests.Integration/ComponentRuntimeTests.cs b/src/Umbraco.Tests.Integration/ComponentRuntimeTests.cs index baa194b17e..2331e5079f 100644 --- a/src/Umbraco.Tests.Integration/ComponentRuntimeTests.cs +++ b/src/Umbraco.Tests.Integration/ComponentRuntimeTests.cs @@ -21,7 +21,6 @@ namespace Umbraco.Cms.Tests.Integration // ensure composers are added protected override void CustomTestSetup(IUmbracoBuilder builder) { - builder.AddNuCache(); builder.AddComposers(); } diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/ConvertersTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/ConvertersTests.cs index ae37b0b3ff..2dfc925502 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/ConvertersTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/ConvertersTests.cs @@ -14,6 +14,7 @@ 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.PublishedCache.Internal; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Strings; using Umbraco.Cms.Infrastructure.Serialization; @@ -102,20 +103,20 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.PropertyEditors Guid.NewGuid(), new Dictionary { { "prop2", "1003" } }, false); - var cnt1 = new SolidPublishedContent(contentType1) + var cnt1 = new InternalPublishedContent(contentType1) { Id = 1003, Properties = new[] { - new SolidPublishedProperty { Alias = "prop1", SolidHasValue = true, SolidValue = "val1" } + new InternalPublishedProperty { Alias = "prop1", SolidHasValue = true, SolidValue = "val1" } } }; - var cnt2 = new SolidPublishedContent(contentType1) + var cnt2 = new InternalPublishedContent(contentType1) { Id = 1004, Properties = new[] { - new SolidPublishedProperty { Alias = "prop2", SolidHasValue = true, SolidValue = "1003" } + new InternalPublishedProperty { Alias = "prop2", SolidHasValue = true, SolidValue = "1003" } } }; diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Published/ConvertersTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Published/ConvertersTests.cs index 9437dc09af..e73d29f251 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Published/ConvertersTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Published/ConvertersTests.cs @@ -11,6 +11,7 @@ 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.PublishedCache.Internal; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Strings; using Umbraco.Cms.Infrastructure.Serialization; @@ -131,7 +132,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Published var element1 = new PublishedElement(elementType1, Guid.NewGuid(), new Dictionary { { "prop1", "1234" } }, false); IPublishedContentType cntType1 = contentTypeFactory.CreateContentType(Guid.NewGuid(), 1001, "cnt1", t => Enumerable.Empty()); - var cnt1 = new SolidPublishedContent(cntType1) { Id = 1234 }; + var cnt1 = new InternalPublishedContent(cntType1) { Id = 1234 }; cacheContent[cnt1.Id] = cnt1; Assert.AreSame(cnt1, element1.Value(Mock.Of(), "prop1")); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Published/NestedContentTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Published/NestedContentTests.cs index 0e31f82390..daa3dbdab2 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Published/NestedContentTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Published/NestedContentTests.cs @@ -16,6 +16,7 @@ using Umbraco.Cms.Core.Models.PublishedContent; using Umbraco.Cms.Core.PropertyEditors; using Umbraco.Cms.Core.PropertyEditors.ValueConverters; using Umbraco.Cms.Core.PublishedCache; +using Umbraco.Cms.Core.PublishedCache.Internal; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Strings; using Umbraco.Cms.Infrastructure.Serialization; @@ -179,7 +180,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Published var key = Guid.NewGuid(); var keyA = Guid.NewGuid(); - var content = new SolidPublishedContent(contentType1) + var content = new InternalPublishedContent(contentType1) { Key = key, Properties = new[] @@ -211,7 +212,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Published var key = Guid.NewGuid(); var keyA = Guid.NewGuid(); var keyB = Guid.NewGuid(); - var content = new SolidPublishedContent(contentType2) + var content = new InternalPublishedContent(contentType2) { Key = key, Properties = new[]