diff --git a/build/NuSpecs/UmbracoCms.nuspec b/build/NuSpecs/UmbracoCms.nuspec
index 5cdacca419..0d18ac59fa 100644
--- a/build/NuSpecs/UmbracoCms.nuspec
+++ b/build/NuSpecs/UmbracoCms.nuspec
@@ -25,7 +25,7 @@
not want this to happen as the alpha of the next major is, really, the next major already.
-->
-
+
diff --git a/src/Umbraco.Core/ContentVariationExtensions.cs b/src/Umbraco.Core/ContentVariationExtensions.cs
index d25997b5f0..9fdc5f0b90 100644
--- a/src/Umbraco.Core/ContentVariationExtensions.cs
+++ b/src/Umbraco.Core/ContentVariationExtensions.cs
@@ -66,44 +66,44 @@ namespace Umbraco.Core
///
/// Determines whether the content type is invariant.
///
- public static bool VariesByNothing(this PublishedContentType contentType) => contentType.Variations.VariesByNothing();
+ public static bool VariesByNothing(this IPublishedContentType contentType) => contentType.Variations.VariesByNothing();
///
/// Determines whether the content type varies by culture.
///
/// And then it could also vary by segment.
- public static bool VariesByCulture(this PublishedContentType contentType) => contentType.Variations.VariesByCulture();
+ public static bool VariesByCulture(this IPublishedContentType contentType) => contentType.Variations.VariesByCulture();
///
/// Determines whether the content type varies by segment.
///
/// And then it could also vary by culture.
- public static bool VariesBySegment(this PublishedContentType contentType) => contentType.Variations.VariesBySegment();
+ public static bool VariesBySegment(this IPublishedContentType contentType) => contentType.Variations.VariesBySegment();
///
/// Determines whether the content type varies by culture and segment.
///
- public static bool VariesByCultureAndSegment(this PublishedContentType contentType) => contentType.Variations.VariesByCultureAndSegment();
+ public static bool VariesByCultureAndSegment(this IPublishedContentType contentType) => contentType.Variations.VariesByCultureAndSegment();
///
/// Determines whether the property type is invariant.
///
- public static bool VariesByNothing(this PublishedPropertyType propertyType) => propertyType.Variations.VariesByNothing();
+ public static bool VariesByNothing(this IPublishedPropertyType propertyType) => propertyType.Variations.VariesByNothing();
///
/// Determines whether the property type varies by culture.
///
- public static bool VariesByCulture(this PublishedPropertyType propertyType) => propertyType.Variations.VariesByCulture();
+ public static bool VariesByCulture(this IPublishedPropertyType propertyType) => propertyType.Variations.VariesByCulture();
///
/// Determines whether the property type varies by segment.
///
- public static bool VariesBySegment(this PublishedPropertyType propertyType) => propertyType.Variations.VariesBySegment();
+ public static bool VariesBySegment(this IPublishedPropertyType propertyType) => propertyType.Variations.VariesBySegment();
///
/// Determines whether the property type varies by culture and segment.
///
- public static bool VariesByCultureAndSegment(this PublishedPropertyType propertyType) => propertyType.Variations.VariesByCultureAndSegment();
+ public static bool VariesByCultureAndSegment(this IPublishedPropertyType propertyType) => propertyType.Variations.VariesByCultureAndSegment();
///
/// Determines whether a variation is invariant.
diff --git a/src/Umbraco.Core/Mapping/UmbracoMapper.cs b/src/Umbraco.Core/Mapping/UmbracoMapper.cs
index 2d495b38b5..8915ebcf74 100644
--- a/src/Umbraco.Core/Mapping/UmbracoMapper.cs
+++ b/src/Umbraco.Core/Mapping/UmbracoMapper.cs
@@ -191,7 +191,7 @@ namespace Umbraco.Core.Mapping
private TTarget Map(object source, Type sourceType, MapperContext context)
{
if (source == null)
- throw new ArgumentNullException(nameof(source));
+ return default;
var targetType = typeof(TTarget);
diff --git a/src/Umbraco.Core/Models/PublishedContent/IPublishedContent.cs b/src/Umbraco.Core/Models/PublishedContent/IPublishedContent.cs
index d38c8eb721..1c0d39a8b8 100644
--- a/src/Umbraco.Core/Models/PublishedContent/IPublishedContent.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/IPublishedContent.cs
@@ -3,7 +3,6 @@ using System.Collections.Generic;
namespace Umbraco.Core.Models.PublishedContent
{
-
///
///
/// Represents a published content item.
@@ -27,21 +26,13 @@ namespace Umbraco.Core.Models.PublishedContent
int Id { get; }
///
- /// Gets the name of the content item.
+ /// Gets the name of the content item for the current culture.
///
- ///
- /// The value of this property is contextual. When the content type is multi-lingual,
- /// this is the name for the 'current' culture. Otherwise, it is the invariant name.
- ///
string Name { get; }
///
- /// Gets the url segment of the content item.
+ /// Gets the url segment of the content item for the current culture.
///
- ///
- /// The value of this property is contextual. When the content type is multi-lingual,
- /// this is the name for the 'current' culture. Otherwise, it is the invariant url segment.
- ///
string UrlSegment { get; }
///
@@ -94,43 +85,28 @@ namespace Umbraco.Core.Models.PublishedContent
///
///
/// For published content items, this is also the date the item was published.
- /// This date is always global to the content item, see GetCulture().Date for the
+ /// This date is always global to the content item, see CultureDate() for the
/// date each culture was published.
///
DateTime UpdateDate { get; }
///
- /// Gets the url of the content item.
+ /// Gets the url of the content item for the current culture.
///
///
/// The value of this property is contextual. It depends on the 'current' request uri,
- /// if any. In addition, when the content type is multi-lingual, this is the url for the
- /// 'current' culture. Otherwise, it is the invariant url.
+ /// if any.
///
string Url { get; }
///
- /// Gets the url of the content item.
- ///
- ///
- /// The value of this property is contextual. It depends on the 'current' request uri,
- /// if any. In addition, when the content type is multi-lingual, this is the url for the
- /// specified culture. Otherwise, it is the invariant url.
- ///
- string GetUrl(string culture = null);
-
- ///
- /// Gets culture infos for a culture.
- ///
- PublishedCultureInfo GetCulture(string culture = null);
-
- ///
- /// Gets culture infos.
+ /// Gets available culture infos.
///
///
/// Contains only those culture that are available. For a published content, these are
/// the cultures that are published. For a draft content, those that are 'available' ie
/// have a non-empty content name.
+ /// Does not contain the invariant culture. // fixme?
///
IReadOnlyDictionary Cultures { get; }
@@ -178,11 +154,15 @@ namespace Umbraco.Core.Models.PublishedContent
IPublishedContent Parent { get; }
///
- /// Gets the children of the content item.
+ /// Gets the children of the content item that are available for the current culture.
///
- /// Children are sorted by their sortOrder.
IEnumerable Children { get; }
+ ///
+ /// Gets all the children of the content item, regardless of whether they are available for the current culture.
+ ///
+ IEnumerable ChildrenForAllCultures { get; }
+
#endregion
}
}
diff --git a/src/Umbraco.Core/Models/PublishedContent/IPublishedContentType.cs b/src/Umbraco.Core/Models/PublishedContent/IPublishedContentType.cs
new file mode 100644
index 0000000000..ab6920377c
--- /dev/null
+++ b/src/Umbraco.Core/Models/PublishedContent/IPublishedContentType.cs
@@ -0,0 +1,63 @@
+using System.Collections.Generic;
+
+namespace Umbraco.Core.Models.PublishedContent
+{
+ ///
+ /// Represents an type.
+ ///
+ /// Instances implementing the interface should be
+ /// immutable, ie if the content type changes, then a new instance needs to be created.
+ public interface IPublishedContentType
+ {
+ ///
+ /// Gets the content type identifier.
+ ///
+ int Id { get; }
+
+ ///
+ /// Gets the content type alias.
+ ///
+ string Alias { get; }
+
+ ///
+ /// Gets the content item type.
+ ///
+ PublishedItemType ItemType { get; }
+
+ ///
+ /// Gets the aliases of the content types participating in the composition.
+ ///
+ HashSet CompositionAliases { get; }
+
+ ///
+ /// Gets the content variations of the content type.
+ ///
+ ContentVariation Variations { get; }
+
+ ///
+ /// Gets a value indicating whether this content type is for an element.
+ ///
+ bool IsElement { get; }
+
+ ///
+ /// Gets the content type properties.
+ ///
+ IEnumerable PropertyTypes { get; }
+
+ ///
+ /// Gets a property type index.
+ ///
+ /// The alias is case-insensitive. This is the only place where alias strings are compared.
+ int GetPropertyIndex(string alias);
+
+ ///
+ /// Gets a property type.
+ ///
+ IPublishedPropertyType GetPropertyType(string alias);
+
+ ///
+ /// Gets a property type.
+ ///
+ IPublishedPropertyType GetPropertyType(int index);
+ }
+}
diff --git a/src/Umbraco.Core/Models/PublishedContent/IPublishedContentTypeFactory.cs b/src/Umbraco.Core/Models/PublishedContent/IPublishedContentTypeFactory.cs
index e75e8a4eb9..816bfdbb01 100644
--- a/src/Umbraco.Core/Models/PublishedContent/IPublishedContentTypeFactory.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/IPublishedContentTypeFactory.cs
@@ -10,7 +10,7 @@
///
/// An content type.
/// A published content type corresponding to the item type and content type.
- PublishedContentType CreateContentType(IContentTypeComposition contentType);
+ IPublishedContentType CreateContentType(IContentTypeComposition contentType);
///
/// Creates a published property type.
@@ -18,7 +18,7 @@
/// The published content type owning the property.
/// A property type.
/// Is used by constructor to create property types.
- PublishedPropertyType CreatePropertyType(PublishedContentType contentType, PropertyType propertyType);
+ IPublishedPropertyType CreatePropertyType(IPublishedContentType contentType, PropertyType propertyType);
///
/// Creates a published property type.
@@ -28,7 +28,7 @@
/// The datatype identifier.
/// The variations.
/// Is used by constructor to create special property types.
- PublishedPropertyType CreatePropertyType(PublishedContentType contentType, string propertyTypeAlias, int dataTypeId, ContentVariation variations);
+ IPublishedPropertyType CreatePropertyType(IPublishedContentType contentType, string propertyTypeAlias, int dataTypeId, ContentVariation variations);
///
/// Gets a published datatype.
diff --git a/src/Umbraco.Core/Models/PublishedContent/IPublishedElement.cs b/src/Umbraco.Core/Models/PublishedContent/IPublishedElement.cs
index 4b579d824b..4c72dc914a 100644
--- a/src/Umbraco.Core/Models/PublishedContent/IPublishedElement.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/IPublishedElement.cs
@@ -13,7 +13,7 @@ namespace Umbraco.Core.Models.PublishedContent
///
/// Gets the content type.
///
- PublishedContentType ContentType { get; }
+ IPublishedContentType ContentType { get; }
#endregion
diff --git a/src/Umbraco.Core/Models/PublishedContent/IPublishedProperty.cs b/src/Umbraco.Core/Models/PublishedContent/IPublishedProperty.cs
index 9a00e94d3e..2ee7dcb28f 100644
--- a/src/Umbraco.Core/Models/PublishedContent/IPublishedProperty.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/IPublishedProperty.cs
@@ -5,7 +5,7 @@
///
public interface IPublishedProperty
{
- PublishedPropertyType PropertyType { get; }
+ IPublishedPropertyType PropertyType { get; }
///
/// Gets the alias of the property.
diff --git a/src/Umbraco.Core/Models/PublishedContent/IPublishedPropertyType.cs b/src/Umbraco.Core/Models/PublishedContent/IPublishedPropertyType.cs
new file mode 100644
index 0000000000..40f2bf3df2
--- /dev/null
+++ b/src/Umbraco.Core/Models/PublishedContent/IPublishedPropertyType.cs
@@ -0,0 +1,108 @@
+using System;
+using Umbraco.Core.PropertyEditors;
+
+namespace Umbraco.Core.Models.PublishedContent
+{
+ ///
+ /// Represents a published property type.
+ ///
+ /// Instances implementing the interface should be
+ /// immutable, ie if the property type changes, then a new instance needs to be created.
+ public interface IPublishedPropertyType
+ {
+ ///
+ /// Gets the published content type containing the property type.
+ ///
+ IPublishedContentType ContentType { get; }
+
+ ///
+ /// Gets the data type.
+ ///
+ PublishedDataType DataType { get; }
+
+ ///
+ /// Gets property type alias.
+ ///
+ string Alias { get; }
+
+ ///
+ /// Gets the property editor alias.
+ ///
+ string EditorAlias { get; }
+
+ ///
+ /// Gets a value indicating whether the property is a user content property.
+ ///
+ /// A non-user content property is a property that has been added to a
+ /// published content type by Umbraco but does not corresponds to a user-defined
+ /// published property.
+ bool IsUserProperty { get; }
+
+ ///
+ /// Gets the content variations of the property type.
+ ///
+ ContentVariation Variations { get; }
+
+ ///
+ /// Determines whether a value is an actual value, or not a value.
+ ///
+ /// Used by property.HasValue and, for instance, in fallback scenarios.
+ bool? IsValue(object value, PropertyValueLevel level);
+
+ ///
+ /// Gets the property cache level.
+ ///
+ PropertyCacheLevel CacheLevel { get; }
+
+ ///
+ /// Converts the source value into the intermediate value.
+ ///
+ /// The published element owning the property.
+ /// The source value.
+ /// A value indicating whether content should be considered draft.
+ /// The intermediate value.
+ object ConvertSourceToInter(IPublishedElement owner, object source, bool preview);
+
+ ///
+ /// Converts the intermediate value into the object value.
+ ///
+ /// The published element owning the property.
+ /// The reference cache level.
+ /// The intermediate value.
+ /// A value indicating whether content should be considered draft.
+ /// The object value.
+ object ConvertInterToObject(IPublishedElement owner, PropertyCacheLevel referenceCacheLevel, object inter, bool preview);
+
+ ///
+ /// Converts the intermediate value into the XPath value.
+ ///
+ /// The published element owning the property.
+ /// The reference cache level.
+ /// The intermediate value.
+ /// A value indicating whether content should be considered draft.
+ /// The XPath value.
+ ///
+ /// The XPath value can be either a string or an XPathNavigator.
+ ///
+ object ConvertInterToXPath(IPublishedElement owner, PropertyCacheLevel referenceCacheLevel, object inter, bool preview);
+
+ ///
+ /// Gets the property model CLR type.
+ ///
+ ///
+ /// The model CLR type may be a type, or may contain types.
+ /// For the actual CLR type, see .
+ ///
+ Type ModelClrType { get; }
+
+ ///
+ /// Gets the property CLR type.
+ ///
+ ///
+ /// Returns the actual CLR type which does not contain types.
+ /// Mapping from may throw if some instances
+ /// could not be mapped to actual CLR types.
+ ///
+ Type ClrType { get; }
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs
index 0798e9a4e0..3b03cfc9ea 100644
--- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs
@@ -5,13 +5,13 @@ using System.Linq;
namespace Umbraco.Core.Models.PublishedContent
{
///
- /// Represents an type.
+ /// Represents an type.
///
/// Instances of the class are immutable, ie
/// if the content type changes, then a new class needs to be created.
- public class PublishedContentType
+ public class PublishedContentType : IPublishedContentType
{
- private readonly PublishedPropertyType[] _propertyTypes;
+ private readonly IPublishedPropertyType[] _propertyTypes;
// fast alias-to-index xref containing both the raw alias and its lowercase version
private readonly Dictionary _indexes = new Dictionary();
@@ -35,11 +35,10 @@ namespace Umbraco.Core.Models.PublishedContent
}
///
- /// Initializes a new instance of the with specific values.
+ /// This constructor is for tests and is not intended to be used directly from application code.
///
///
- /// This constructor is for tests and is not intended to be used directly from application code.
- /// Values are assumed to be consisted and are not checked.
+ /// Values are assumed to be consistent and are not checked.
///
public PublishedContentType(int id, string alias, PublishedItemType itemType, IEnumerable compositionAliases, IEnumerable propertyTypes, ContentVariation variations, bool isElement = false)
: this (id, alias, itemType, compositionAliases, variations, isElement)
@@ -52,6 +51,20 @@ namespace Umbraco.Core.Models.PublishedContent
InitializeIndexes();
}
+ ///
+ /// This constructor is for tests and is not intended to be used directly from application code.
+ ///
+ ///
+ /// Values are assumed to be consistent and are not checked.
+ ///
+ public PublishedContentType(int id, string alias, PublishedItemType itemType, IEnumerable compositionAliases, Func> propertyTypes, ContentVariation variations, bool isElement = false)
+ : this(id, alias, itemType, compositionAliases, variations, isElement)
+ {
+ _propertyTypes = propertyTypes(this).ToArray();
+
+ InitializeIndexes();
+ }
+
private PublishedContentType(int id, string alias, PublishedItemType itemType, IEnumerable compositionAliases, ContentVariation variations, bool isElement)
{
Id = id;
@@ -75,7 +88,7 @@ namespace Umbraco.Core.Models.PublishedContent
// Members have properties such as IMember LastLoginDate which are plain C# properties and not content
// properties; they are exposed as pseudo content properties, as long as a content property with the
// same alias does not exist already.
- private void EnsureMemberProperties(List propertyTypes, IPublishedContentTypeFactory factory)
+ private void EnsureMemberProperties(List propertyTypes, IPublishedContentTypeFactory factory)
{
var aliases = new HashSet(propertyTypes.Select(x => x.Alias), StringComparer.OrdinalIgnoreCase);
@@ -103,44 +116,29 @@ namespace Umbraco.Core.Models.PublishedContent
#region Content type
- ///
- /// Gets the content type identifier.
- ///
+ ///
public int Id { get; }
- ///
- /// Gets the content type alias.
- ///
+ ///
public string Alias { get; }
- ///
- /// Gets the content item type.
- ///
+ ///
public PublishedItemType ItemType { get; }
- ///
- /// Gets the aliases of the content types participating in the composition.
- ///
+ ///
public HashSet CompositionAliases { get; }
- ///
- /// Gets the content variations of the content type.
- ///
+ ///
public ContentVariation Variations { get; }
#endregion
#region Properties
- ///
- /// Gets the content type properties.
- ///
- public IEnumerable PropertyTypes => _propertyTypes;
+ ///
+ public IEnumerable PropertyTypes => _propertyTypes;
- ///
- /// Gets a property type index.
- ///
- /// The alias is case-insensitive. This is the only place where alias strings are compared.
+ ///
public int GetPropertyIndex(string alias)
{
if (_indexes.TryGetValue(alias, out var index)) return index; // fastest
@@ -150,10 +148,8 @@ namespace Umbraco.Core.Models.PublishedContent
// virtual for unit tests
// TODO: explain why
- ///
- /// Gets a property type.
- ///
- public virtual PublishedPropertyType GetPropertyType(string alias)
+ ///
+ public virtual IPublishedPropertyType GetPropertyType(string alias)
{
var index = GetPropertyIndex(alias);
return GetPropertyType(index);
@@ -161,17 +157,13 @@ namespace Umbraco.Core.Models.PublishedContent
// virtual for unit tests
// TODO: explain why
- ///
- /// Gets a property type.
- ///
- public virtual PublishedPropertyType GetPropertyType(int index)
+ ///
+ public virtual IPublishedPropertyType GetPropertyType(int index)
{
return index >= 0 && index < _propertyTypes.Length ? _propertyTypes[index] : null;
}
- ///
- /// Gets a value indicating whether this content type is for an element.
- ///
+ ///
public bool IsElement { get; }
#endregion
diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentTypeFactory.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentTypeFactory.cs
index 2ca3593b55..17a15a2536 100644
--- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentTypeFactory.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentTypeFactory.cs
@@ -26,37 +26,46 @@ namespace Umbraco.Core.Models.PublishedContent
}
///
- public PublishedContentType CreateContentType(IContentTypeComposition contentType)
+ public IPublishedContentType CreateContentType(IContentTypeComposition contentType)
{
return new PublishedContentType(contentType, this);
}
- // for tests
- internal PublishedContentType CreateContentType(int id, string alias, IEnumerable propertyTypes, ContentVariation variations = ContentVariation.Nothing, bool isElement = false)
+ ///
+ /// This method is for tests and is not intended to be used directly from application code.
+ ///
+ /// Values are assumed to be consisted and are not checked.
+ internal IPublishedContentType CreateContentType(int id, string alias, Func> propertyTypes, ContentVariation variations = ContentVariation.Nothing, bool isElement = false)
{
return new PublishedContentType(id, alias, PublishedItemType.Content, Enumerable.Empty(), propertyTypes, variations, isElement);
}
- // for tests
- internal PublishedContentType CreateContentType(int id, string alias, IEnumerable compositionAliases, IEnumerable propertyTypes, ContentVariation variations = ContentVariation.Nothing, bool isElement = false)
+ ///
+ /// This method is for tests and is not intended to be used directly from application code.
+ ///
+ /// Values are assumed to be consisted and are not checked.
+ internal IPublishedContentType CreateContentType(int id, string alias, IEnumerable compositionAliases, Func> propertyTypes, ContentVariation variations = ContentVariation.Nothing, bool isElement = false)
{
return new PublishedContentType(id, alias, PublishedItemType.Content, compositionAliases, propertyTypes, variations, isElement);
}
///
- public PublishedPropertyType CreatePropertyType(PublishedContentType contentType, PropertyType propertyType)
+ public IPublishedPropertyType CreatePropertyType(IPublishedContentType contentType, PropertyType propertyType)
{
return new PublishedPropertyType(contentType, propertyType, _propertyValueConverters, _publishedModelFactory, this);
}
///
- public PublishedPropertyType CreatePropertyType(PublishedContentType contentType, string propertyTypeAlias, int dataTypeId, ContentVariation variations = ContentVariation.Nothing)
+ public IPublishedPropertyType CreatePropertyType(IPublishedContentType contentType, string propertyTypeAlias, int dataTypeId, ContentVariation variations = ContentVariation.Nothing)
{
return new PublishedPropertyType(contentType, propertyTypeAlias, dataTypeId, true, variations, _propertyValueConverters, _publishedModelFactory, this);
}
- // for tests
- internal PublishedPropertyType CreatePropertyType(string propertyTypeAlias, int dataTypeId, bool umbraco = false, ContentVariation variations = ContentVariation.Nothing)
+ ///
+ /// This method is for tests and is not intended to be used directly from application code.
+ ///
+ /// Values are assumed to be consisted and are not checked.
+ internal IPublishedPropertyType CreatePropertyType(string propertyTypeAlias, int dataTypeId, bool umbraco = false, ContentVariation variations = ContentVariation.Nothing)
{
return new PublishedPropertyType(propertyTypeAlias, dataTypeId, umbraco, variations, _propertyValueConverters, _publishedModelFactory, this);
}
diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentWrapped.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentWrapped.cs
index 8bf8cec244..fb41c95419 100644
--- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentWrapped.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentWrapped.cs
@@ -41,7 +41,7 @@ namespace Umbraco.Core.Models.PublishedContent
#region ContentType
///
- public virtual PublishedContentType ContentType => _content.ContentType;
+ public virtual IPublishedContentType ContentType => _content.ContentType;
#endregion
@@ -96,12 +96,6 @@ namespace Umbraco.Core.Models.PublishedContent
///
public virtual string Url => _content.Url;
- ///
- public virtual string GetUrl(string culture = null) => _content.GetUrl(culture);
-
- ///
- public PublishedCultureInfo GetCulture(string culture = null) => _content.GetCulture(culture);
-
///
public IReadOnlyDictionary Cultures => _content.Cultures;
@@ -124,6 +118,9 @@ namespace Umbraco.Core.Models.PublishedContent
///
public virtual IEnumerable Children => _content.Children;
+ ///
+ public virtual IEnumerable ChildrenForAllCultures => _content.ChildrenForAllCultures;
+
#endregion
#region Properties
diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedCultureInfos.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedCultureInfos.cs
index 749b37a41a..d5096158a7 100644
--- a/src/Umbraco.Core/Models/PublishedContent/PublishedCultureInfos.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/PublishedCultureInfos.cs
@@ -13,10 +13,9 @@ namespace Umbraco.Core.Models.PublishedContent
///
public PublishedCultureInfo(string culture, string name, string urlSegment, DateTime date)
{
- if (string.IsNullOrWhiteSpace(culture)) throw new ArgumentNullOrEmptyException(nameof(culture));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
- Culture = culture;
+ Culture = culture ?? throw new ArgumentNullException(nameof(culture));
Name = name;
UrlSegment = urlSegment;
Date = date;
@@ -30,12 +29,12 @@ namespace Umbraco.Core.Models.PublishedContent
///
/// Gets the name of the item.
///
- public string Name { get; }
+ internal string Name { get; }
///
/// Gets the url segment of the item.
///
- public string UrlSegment { get; }
+ internal string UrlSegment { get; }
///
/// Gets the date associated with the culture.
diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedElementWrapped.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedElementWrapped.cs
index 1989ac2caf..481b9bd5d2 100644
--- a/src/Umbraco.Core/Models/PublishedContent/PublishedElementWrapped.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/PublishedElementWrapped.cs
@@ -28,7 +28,7 @@ namespace Umbraco.Core.Models.PublishedContent
public IPublishedElement Unwrap() => _content;
///
- public PublishedContentType ContentType => _content.ContentType;
+ public IPublishedContentType ContentType => _content.ContentType;
///
public Guid Key => _content.Key;
diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyBase.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyBase.cs
index 5f374f8bc8..e11d2391ec 100644
--- a/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyBase.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyBase.cs
@@ -12,7 +12,7 @@ namespace Umbraco.Core.Models.PublishedContent
///
/// Initializes a new instance of the class.
///
- protected PublishedPropertyBase(PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel)
+ protected PublishedPropertyBase(IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel)
{
PropertyType = propertyType ?? throw new ArgumentNullException(nameof(propertyType));
ReferenceCacheLevel = referenceCacheLevel;
@@ -42,7 +42,7 @@ namespace Umbraco.Core.Models.PublishedContent
///
/// Gets the property type.
///
- public PublishedPropertyType PropertyType { get; }
+ public IPublishedPropertyType PropertyType { get; }
///
/// Gets the property reference cache level.
diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyType.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyType.cs
index 68892fd79a..0c2e62770e 100644
--- a/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyType.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyType.cs
@@ -10,10 +10,8 @@ namespace Umbraco.Core.Models.PublishedContent
///
/// Instances of the class are immutable, ie
/// if the property type changes, then a new class needs to be created.
- public class PublishedPropertyType
+ public class PublishedPropertyType : IPublishedPropertyType
{
- // TODO: API design review, should this be an interface?
-
private readonly IPublishedModelFactory _publishedModelFactory;
private readonly PropertyValueConverterCollection _propertyValueConverters;
private readonly object _locker = new object();
@@ -32,7 +30,7 @@ namespace Umbraco.Core.Models.PublishedContent
///
/// The new published property type belongs to the published content type.
///
- public PublishedPropertyType(PublishedContentType contentType, PropertyType propertyType, PropertyValueConverterCollection propertyValueConverters, IPublishedModelFactory publishedModelFactory, IPublishedContentTypeFactory factory)
+ public PublishedPropertyType(IPublishedContentType contentType, PropertyType propertyType, PropertyValueConverterCollection propertyValueConverters, IPublishedModelFactory publishedModelFactory, IPublishedContentTypeFactory factory)
: this(propertyType.Alias, propertyType.DataTypeId, true, propertyType.Variations, propertyValueConverters, publishedModelFactory, factory)
{
ContentType = contentType ?? throw new ArgumentNullException(nameof(contentType));
@@ -45,7 +43,7 @@ namespace Umbraco.Core.Models.PublishedContent
/// Values are assumed to be consisted and are not checked.
/// The new published property type belongs to the published content type.
///
- public PublishedPropertyType(PublishedContentType contentType, string propertyTypeAlias, int dataTypeId, bool isUserProperty, ContentVariation variations, PropertyValueConverterCollection propertyValueConverters, IPublishedModelFactory publishedModelFactory, IPublishedContentTypeFactory factory)
+ public PublishedPropertyType(IPublishedContentType contentType, string propertyTypeAlias, int dataTypeId, bool isUserProperty, ContentVariation variations, PropertyValueConverterCollection propertyValueConverters, IPublishedModelFactory publishedModelFactory, IPublishedContentTypeFactory factory)
: this(propertyTypeAlias, dataTypeId, isUserProperty, variations, propertyValueConverters, publishedModelFactory, factory)
{
ContentType = contentType ?? throw new ArgumentNullException(nameof(contentType));
@@ -75,37 +73,22 @@ namespace Umbraco.Core.Models.PublishedContent
#region Property type
- ///
- /// Gets the published content type containing the property type.
- ///
- public PublishedContentType ContentType { get; internal set; } // internally set by PublishedContentType constructor
+ ///
+ public IPublishedContentType ContentType { get; internal set; } // internally set by PublishedContentType constructor
- ///
- /// Gets the data type.
- ///
+ ///
public PublishedDataType DataType { get; }
- ///
- /// Gets property type alias.
- ///
+ ///
public string Alias { get; }
- ///
- /// Gets the property editor alias.
- ///
+ ///
public string EditorAlias => DataType.EditorAlias;
- ///
- /// Gets a value indicating whether the property is a user content property.
- ///
- /// A non-user content property is a property that has been added to a
- /// published content type by Umbraco but does not corresponds to a user-defined
- /// published property.
+ ///
public bool IsUserProperty { get; }
- ///
- /// Gets the content variations of the property type.
- ///
+ ///
public ContentVariation Variations { get; }
#endregion
@@ -193,10 +176,7 @@ namespace Umbraco.Core.Models.PublishedContent
_modelClrType = _converter == null ? typeof (object) : _converter.GetPropertyValueType(this);
}
- ///
- /// Determines whether a value is an actual value, or not a value.
- ///
- /// Used by property.HasValue and, for instance, in fallback scenarios.
+ ///
public bool? IsValue(object value, PropertyValueLevel level)
{
if (!_initialized) Initialize();
@@ -209,9 +189,7 @@ namespace Umbraco.Core.Models.PublishedContent
return value != null && (!(value is string) || string.IsNullOrWhiteSpace((string) value) == false);
}
- ///
- /// Gets the property cache level.
- ///
+ ///
public PropertyCacheLevel CacheLevel
{
get
@@ -221,13 +199,7 @@ namespace Umbraco.Core.Models.PublishedContent
}
}
- ///
- /// Converts the source value into the intermediate value.
- ///
- /// The published element owning the property.
- /// The source value.
- /// A value indicating whether content should be considered draft.
- /// The intermediate value.
+ ///
public object ConvertSourceToInter(IPublishedElement owner, object source, bool preview)
{
if (!_initialized) Initialize();
@@ -238,14 +210,7 @@ namespace Umbraco.Core.Models.PublishedContent
: source;
}
- ///
- /// Converts the intermediate value into the object value.
- ///
- /// The published element owning the property.
- /// The reference cache level.
- /// The intermediate value.
- /// A value indicating whether content should be considered draft.
- /// The object value.
+ ///
public object ConvertInterToObject(IPublishedElement owner, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
if (!_initialized) Initialize();
@@ -256,17 +221,7 @@ namespace Umbraco.Core.Models.PublishedContent
: inter;
}
- ///
- /// Converts the intermediate value into the XPath value.
- ///
- /// The published element owning the property.
- /// The reference cache level.
- /// The intermediate value.
- /// A value indicating whether content should be considered draft.
- /// The XPath value.
- ///
- /// The XPath value can be either a string or an XPathNavigator.
- ///
+ ///
public object ConvertInterToXPath(IPublishedElement owner, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
if (!_initialized) Initialize();
@@ -282,13 +237,7 @@ namespace Umbraco.Core.Models.PublishedContent
return inter.ToString().Trim();
}
- ///
- /// Gets the property model CLR type.
- ///
- ///
- /// The model CLR type may be a type, or may contain types.
- /// For the actual CLR type, see .
- ///
+ ///
public Type ModelClrType
{
get
@@ -298,14 +247,7 @@ namespace Umbraco.Core.Models.PublishedContent
}
}
- ///
- /// Gets the property CLR type.
- ///
- ///
- /// Returns the actual CLR type which does not contain types.
- /// Mapping from may throw if some instances
- /// could not be mapped to actual CLR types.
- ///
+ ///
public Type ClrType
{
get
diff --git a/src/Umbraco.Core/Models/PublishedContent/RawValueProperty.cs b/src/Umbraco.Core/Models/PublishedContent/RawValueProperty.cs
index 7469222ab0..10f999532f 100644
--- a/src/Umbraco.Core/Models/PublishedContent/RawValueProperty.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/RawValueProperty.cs
@@ -38,7 +38,7 @@ namespace Umbraco.Core.Models.PublishedContent
public override object GetXPathValue(string culture = null, string segment = null)
=> string.IsNullOrEmpty(culture) & string.IsNullOrEmpty(segment) ? _xpathValue.Value : null;
- public RawValueProperty(PublishedPropertyType propertyType, IPublishedElement content, object sourceValue, bool isPreviewing = false)
+ public RawValueProperty(IPublishedPropertyType propertyType, IPublishedElement content, object sourceValue, bool isPreviewing = false)
: base(propertyType, PropertyCacheLevel.Unknown) // cache level is ignored
{
if (propertyType.Variations != ContentVariation.Nothing)
diff --git a/src/Umbraco.Web/Routing/UrlProviderMode.cs b/src/Umbraco.Core/Models/PublishedContent/UrlMode.cs
similarity index 63%
rename from src/Umbraco.Web/Routing/UrlProviderMode.cs
rename to src/Umbraco.Core/Models/PublishedContent/UrlMode.cs
index ac29aed3fb..4cd6a680f4 100644
--- a/src/Umbraco.Web/Routing/UrlProviderMode.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/UrlMode.cs
@@ -1,14 +1,14 @@
-namespace Umbraco.Web.Routing
+namespace Umbraco.Core.Models.PublishedContent
{
///
- /// Specifies the type of urls that the url provider should produce, Auto is the default
+ /// Specifies the type of urls that the url provider should produce, Auto is the default.
///
- ///
- /// The Relative option can lead to invalid results when combined with hostnames, but it is the only way to reproduce
- /// the true, pre-4.10, always-relative behavior of Umbraco.
- ///
- public enum UrlProviderMode
+ public enum UrlMode
{
+ ///
+ /// Indicates that the url provider should do what it has been configured to do.
+ ///
+ Default = 0,
///
/// Indicates that the url provider should produce relative urls exclusively.
diff --git a/src/Umbraco.Core/PropertyEditors/IPropertyValueConverter.cs b/src/Umbraco.Core/PropertyEditors/IPropertyValueConverter.cs
index f6a7cbf32f..0a9cf632bc 100644
--- a/src/Umbraco.Core/PropertyEditors/IPropertyValueConverter.cs
+++ b/src/Umbraco.Core/PropertyEditors/IPropertyValueConverter.cs
@@ -15,7 +15,7 @@ namespace Umbraco.Core.PropertyEditors
///
/// The property type.
/// A value indicating whether the converter supports a property type.
- bool IsConverter(PublishedPropertyType propertyType);
+ bool IsConverter(IPublishedPropertyType propertyType);
///
/// Determines whether a value is an actual value, or not a value.
@@ -36,14 +36,14 @@ namespace Umbraco.Core.PropertyEditors
/// The CLR type of values returned by the converter.
/// Some of the CLR types may be generated, therefore this method cannot directly return
/// a Type object (which may not exist yet). In which case it needs to return a ModelType instance.
- Type GetPropertyValueType(PublishedPropertyType propertyType);
+ Type GetPropertyValueType(IPublishedPropertyType propertyType);
///
/// Gets the property cache level.
///
/// The property type.
/// The property cache level.
- PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType);
+ PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType);
///
/// Converts a property source value to an intermediate value.
@@ -64,7 +64,7 @@ namespace Umbraco.Core.PropertyEditors
/// strings, and xml-whitespace strings appropriately, ie it should know whether to preserve
/// white spaces.
///
- object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview);
+ object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview);
///
/// Converts a property intermediate value to an Object value.
@@ -83,7 +83,7 @@ namespace Umbraco.Core.PropertyEditors
/// passed to eg a PublishedFragment constructor. It is used by the fragment and the properties to manage
/// the cache levels of property values. It is not meant to be used by the converter.
///
- object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview);
+ object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview);
///
/// Converts a property intermediate value to an XPath value.
@@ -107,6 +107,6 @@ namespace Umbraco.Core.PropertyEditors
/// passed to eg a PublishedFragment constructor. It is used by the fragment and the properties to manage
/// the cache levels of property values. It is not meant to be used by the converter.
///
- object ConvertIntermediateToXPath(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview);
+ object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview);
}
}
diff --git a/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs b/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs
index 48bfc49ed9..3b6ebc610c 100644
--- a/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs
+++ b/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs
@@ -8,7 +8,7 @@ namespace Umbraco.Core.PropertyEditors
///
public abstract class PropertyValueConverterBase : IPropertyValueConverter
{
- public virtual bool IsConverter(PublishedPropertyType propertyType)
+ public virtual bool IsConverter(IPublishedPropertyType propertyType)
=> false;
public virtual bool? IsValue(object value, PropertyValueLevel level)
@@ -30,19 +30,19 @@ namespace Umbraco.Core.PropertyEditors
return value != null && (!(value is string) || string.IsNullOrWhiteSpace((string) value) == false);
}
- public virtual Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public virtual Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (object);
- public virtual PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public virtual PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Snapshot;
- public virtual object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
+ public virtual object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
=> source;
- public virtual object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
+ public virtual object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
=> inter;
- public virtual object ConvertIntermediateToXPath(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
+ public virtual object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
=> inter?.ToString() ?? string.Empty;
}
}
diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/CheckboxListValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/CheckboxListValueConverter.cs
index 3d69c37b8b..dd2dfb49e7 100644
--- a/src/Umbraco.Core/PropertyEditors/ValueConverters/CheckboxListValueConverter.cs
+++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/CheckboxListValueConverter.cs
@@ -9,16 +9,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class CheckboxListValueConverter : PropertyValueConverterBase
{
- public override bool IsConverter(PublishedPropertyType propertyType)
+ public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.CheckBoxList);
- public override Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (IEnumerable);
- public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
- public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object source, bool preview)
+ public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object source, bool preview)
{
var sourceString = source?.ToString() ?? string.Empty;
diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/ColorPickerValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/ColorPickerValueConverter.cs
index 9f260fc973..46dae3e4f0 100644
--- a/src/Umbraco.Core/PropertyEditors/ValueConverters/ColorPickerValueConverter.cs
+++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/ColorPickerValueConverter.cs
@@ -8,16 +8,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class ColorPickerValueConverter : PropertyValueConverterBase
{
- public override bool IsConverter(PublishedPropertyType propertyType)
+ public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.ColorPicker);
- public override Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> UseLabel(propertyType) ? typeof(PickedColor) : typeof(string);
- public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
- public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
+ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
var useLabel = UseLabel(propertyType);
@@ -39,7 +39,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
return ssource;
}
- private bool UseLabel(PublishedPropertyType propertyType)
+ private bool UseLabel(IPublishedPropertyType propertyType)
{
return ConfigurationEditor.ConfigurationAs(propertyType.DataType.Configuration).UseLabel;
}
diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/DatePickerValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/DatePickerValueConverter.cs
index ffe9feb653..0206528bf7 100644
--- a/src/Umbraco.Core/PropertyEditors/ValueConverters/DatePickerValueConverter.cs
+++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/DatePickerValueConverter.cs
@@ -8,16 +8,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class DatePickerValueConverter : PropertyValueConverterBase
{
- public override bool IsConverter(PublishedPropertyType propertyType)
+ public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.DateTime);
- public override Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (DateTime);
- public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
- public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
+ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
if (source == null) return DateTime.MinValue;
@@ -39,7 +39,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
// default ConvertSourceToObject just returns source ie a DateTime value
- public override object ConvertIntermediateToXPath(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
+ public override object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
// source should come from ConvertSource and be a DateTime already
return XmlConvert.ToString((DateTime) inter, XmlDateTimeSerializationMode.Unspecified);
diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/DecimalValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/DecimalValueConverter.cs
index 6f7888aee3..7d6e7c0ce9 100644
--- a/src/Umbraco.Core/PropertyEditors/ValueConverters/DecimalValueConverter.cs
+++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/DecimalValueConverter.cs
@@ -7,16 +7,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class DecimalValueConverter : PropertyValueConverterBase
{
- public override bool IsConverter(PublishedPropertyType propertyType)
+ public override bool IsConverter(IPublishedPropertyType propertyType)
=> Constants.PropertyEditors.Aliases.Decimal.Equals(propertyType.EditorAlias);
- public override Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (decimal);
- public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
- public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
+ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
if (source == null)
{
diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/EmailAddressValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/EmailAddressValueConverter.cs
index e4ef3a50a3..88061a559e 100644
--- a/src/Umbraco.Core/PropertyEditors/ValueConverters/EmailAddressValueConverter.cs
+++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/EmailAddressValueConverter.cs
@@ -6,16 +6,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class EmailAddressValueConverter : PropertyValueConverterBase
{
- public override bool IsConverter(PublishedPropertyType propertyType)
+ public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.EmailAddress);
- public override Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (string);
- public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
- public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object source, bool preview)
+ public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object source, bool preview)
{
return source?.ToString() ?? string.Empty;
}
diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/GridValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/GridValueConverter.cs
index 29f6de0271..b3685457ec 100644
--- a/src/Umbraco.Core/PropertyEditors/ValueConverters/GridValueConverter.cs
+++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/GridValueConverter.cs
@@ -28,16 +28,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
_config = config;
}
- public override bool IsConverter(PublishedPropertyType propertyType)
+ public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.Grid);
- public override Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (JToken);
- public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
- public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
+ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
if (source == null) return null;
var sourceString = source.ToString();
diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/ImageCropperValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/ImageCropperValueConverter.cs
index 79cb748960..6f5bd571b7 100644
--- a/src/Umbraco.Core/PropertyEditors/ValueConverters/ImageCropperValueConverter.cs
+++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/ImageCropperValueConverter.cs
@@ -14,19 +14,19 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
public class ImageCropperValueConverter : PropertyValueConverterBase
{
///
- public override bool IsConverter(PublishedPropertyType propertyType)
+ public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.ImageCropper);
///
- public override Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (ImageCropperValue);
///
- public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
///
- public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
+ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
if (source == null) return null;
var sourceString = source.ToString();
diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/IntegerValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/IntegerValueConverter.cs
index e0abf17a7e..ca8f23bca2 100644
--- a/src/Umbraco.Core/PropertyEditors/ValueConverters/IntegerValueConverter.cs
+++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/IntegerValueConverter.cs
@@ -6,16 +6,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class IntegerValueConverter : PropertyValueConverterBase
{
- public override bool IsConverter(PublishedPropertyType propertyType)
+ public override bool IsConverter(IPublishedPropertyType propertyType)
=> Constants.PropertyEditors.Aliases.Integer.Equals(propertyType.EditorAlias);
- public override Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (int);
- public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
- public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
+ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
return source.TryConvertTo().Result;
}
diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/JsonValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/JsonValueConverter.cs
index e04893716a..12e6238705 100644
--- a/src/Umbraco.Core/PropertyEditors/ValueConverters/JsonValueConverter.cs
+++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/JsonValueConverter.cs
@@ -31,19 +31,19 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
///
///
///
- public override bool IsConverter(PublishedPropertyType propertyType)
+ public override bool IsConverter(IPublishedPropertyType propertyType)
{
return _propertyEditors.TryGet(propertyType.EditorAlias, out var editor)
&& editor.GetValueEditor().ValueType.InvariantEquals(ValueTypes.Json);
}
- public override Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (JToken);
- public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
- public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
+ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
if (source == null) return null;
var sourceString = source.ToString();
diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/LabelValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/LabelValueConverter.cs
index 05a5f15aaf..84baf226cf 100644
--- a/src/Umbraco.Core/PropertyEditors/ValueConverters/LabelValueConverter.cs
+++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/LabelValueConverter.cs
@@ -16,10 +16,10 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class LabelValueConverter : PropertyValueConverterBase
{
- public override bool IsConverter(PublishedPropertyType propertyType)
+ public override bool IsConverter(IPublishedPropertyType propertyType)
=> Constants.PropertyEditors.Aliases.Label.Equals(propertyType.EditorAlias);
- public override Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
{
var valueType = ConfigurationEditor.ConfigurationAs(propertyType.DataType.Configuration);
switch (valueType.ValueType)
@@ -40,10 +40,10 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
}
}
- public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
- public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
+ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
var valueType = ConfigurationEditor.ConfigurationAs(propertyType.DataType.Configuration);
switch (valueType.ValueType)
diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/MarkdownEditorValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/MarkdownEditorValueConverter.cs
index aeacf33eef..a062561ab1 100644
--- a/src/Umbraco.Core/PropertyEditors/ValueConverters/MarkdownEditorValueConverter.cs
+++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/MarkdownEditorValueConverter.cs
@@ -7,17 +7,17 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class MarkdownEditorValueConverter : PropertyValueConverterBase
{
- public override bool IsConverter(PublishedPropertyType propertyType)
+ public override bool IsConverter(IPublishedPropertyType propertyType)
=> Constants.PropertyEditors.Aliases.MarkdownEditor.Equals(propertyType.EditorAlias);
- public override Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (IHtmlString);
// PropertyCacheLevel.Content is ok here because that converter does not parse {locallink} nor executes macros
- public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
- public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
+ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
// in xml a string is: string
// in the database a string is: string
@@ -25,13 +25,13 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
return source;
}
- public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
+ public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
// source should come from ConvertSource and be a string (or null) already
return new HtmlString(inter == null ? string.Empty : (string) inter);
}
- public override object ConvertIntermediateToXPath(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
+ public override object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
// source should come from ConvertSource and be a string (or null) already
return inter?.ToString() ?? string.Empty;
diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/MemberGroupPickerValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/MemberGroupPickerValueConverter.cs
index bdd09ea33b..cd7f48f510 100644
--- a/src/Umbraco.Core/PropertyEditors/ValueConverters/MemberGroupPickerValueConverter.cs
+++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/MemberGroupPickerValueConverter.cs
@@ -6,16 +6,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class MemberGroupPickerValueConverter : PropertyValueConverterBase
{
- public override bool IsConverter(PublishedPropertyType propertyType)
+ public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.MemberGroupPicker);
- public override Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (string);
- public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
- public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
+ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
return source?.ToString() ?? string.Empty;
}
diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/MultipleTextStringValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/MultipleTextStringValueConverter.cs
index 1d5f0b1ca3..15e7ce4caf 100644
--- a/src/Umbraco.Core/PropertyEditors/ValueConverters/MultipleTextStringValueConverter.cs
+++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/MultipleTextStringValueConverter.cs
@@ -9,18 +9,18 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class MultipleTextStringValueConverter : PropertyValueConverterBase
{
- public override bool IsConverter(PublishedPropertyType propertyType)
+ public override bool IsConverter(IPublishedPropertyType propertyType)
=> Constants.PropertyEditors.Aliases.MultipleTextstring.Equals(propertyType.EditorAlias);
- public override Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (IEnumerable);
- public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
private static readonly string[] NewLineDelimiters = { "\r\n", "\r", "\n" };
- public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
+ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
// data is (both in database and xml):
//
@@ -58,7 +58,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
: values.ToArray();
}
- public override object ConvertIntermediateToXPath(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
+ public override object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
var d = new XmlDocument();
var e = d.CreateElement("values");
diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/MustBeStringValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/MustBeStringValueConverter.cs
index c9528c3e8b..b9c61bb169 100644
--- a/src/Umbraco.Core/PropertyEditors/ValueConverters/MustBeStringValueConverter.cs
+++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/MustBeStringValueConverter.cs
@@ -22,16 +22,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
Constants.PropertyEditors.Aliases.MultiNodeTreePicker
};
- public override bool IsConverter(PublishedPropertyType propertyType)
+ public override bool IsConverter(IPublishedPropertyType propertyType)
=> Aliases.Contains(propertyType.EditorAlias);
- public override Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (string);
- public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
- public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
+ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
return source?.ToString();
}
diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/RadioButtonListValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/RadioButtonListValueConverter.cs
index b99cc7e0e3..61adc9a93e 100644
--- a/src/Umbraco.Core/PropertyEditors/ValueConverters/RadioButtonListValueConverter.cs
+++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/RadioButtonListValueConverter.cs
@@ -6,16 +6,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class RadioButtonListValueConverter : PropertyValueConverterBase
{
- public override bool IsConverter(PublishedPropertyType propertyType)
+ public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.RadioButtonList);
- public override Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (string);
- public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
- public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
+ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
var attempt = source.TryConvertTo();
diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/SliderValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/SliderValueConverter.cs
index 31ab47223f..11502687b7 100644
--- a/src/Umbraco.Core/PropertyEditors/ValueConverters/SliderValueConverter.cs
+++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/SliderValueConverter.cs
@@ -18,16 +18,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
_dataTypeService = dataTypeService ?? throw new ArgumentNullException(nameof(dataTypeService));
}
- public override bool IsConverter(PublishedPropertyType propertyType)
+ public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.Slider);
- public override Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> IsRangeDataType(propertyType.DataType.Id) ? typeof (Range) : typeof (decimal);
- public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
- public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object source, bool preview)
+ public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object source, bool preview)
{
if (source == null)
return null;
diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/TagsValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/TagsValueConverter.cs
index 9b857c2dff..b54c693c14 100644
--- a/src/Umbraco.Core/PropertyEditors/ValueConverters/TagsValueConverter.cs
+++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/TagsValueConverter.cs
@@ -19,16 +19,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
_dataTypeService = dataTypeService ?? throw new ArgumentNullException(nameof(dataTypeService));
}
- public override bool IsConverter(PublishedPropertyType propertyType)
+ public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.Tags);
- public override Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (IEnumerable);
- public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
- public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
+ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
if (source == null) return Array.Empty();
@@ -43,7 +43,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
return source.ToString().Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
}
- public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object source, bool preview)
+ public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object source, bool preview)
{
return (string[]) source;
}
diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/TextStringValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/TextStringValueConverter.cs
index 2368a1d034..7caa9a90cc 100644
--- a/src/Umbraco.Core/PropertyEditors/ValueConverters/TextStringValueConverter.cs
+++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/TextStringValueConverter.cs
@@ -13,16 +13,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
Constants.PropertyEditors.Aliases.TextArea
};
- public override bool IsConverter(PublishedPropertyType propertyType)
+ public override bool IsConverter(IPublishedPropertyType propertyType)
=> PropertyTypeAliases.Contains(propertyType.EditorAlias);
- public override Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (string);
- public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
- public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
+ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
// in xml a string is: string
// in the database a string is: string
@@ -30,13 +30,13 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
return source;
}
- public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
+ public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
// source should come from ConvertSource and be a string (or null) already
return inter ?? string.Empty;
}
- public override object ConvertIntermediateToXPath(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
+ public override object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
// source should come from ConvertSource and be a string (or null) already
return inter;
diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/TinyMceValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/TinyMceValueConverter.cs
index 46f660d829..9938af671d 100644
--- a/src/Umbraco.Core/PropertyEditors/ValueConverters/TinyMceValueConverter.cs
+++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/TinyMceValueConverter.cs
@@ -10,17 +10,17 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class TinyMceValueConverter : PropertyValueConverterBase
{
- public override bool IsConverter(PublishedPropertyType propertyType)
+ public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias == Constants.PropertyEditors.Aliases.TinyMce;
- public override Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (IHtmlString);
// PropertyCacheLevel.Content is ok here because that converter does not parse {locallink} nor executes macros
- public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
- public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
+ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
// in xml a string is: string
// in the database a string is: string
@@ -28,13 +28,13 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
return source;
}
- public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
+ public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
// source should come from ConvertSource and be a string (or null) already
return new HtmlString(inter == null ? string.Empty : (string)inter);
}
- public override object ConvertIntermediateToXPath(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
+ public override object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
// source should come from ConvertSource and be a string (or null) already
return inter;
diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/UploadPropertyConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/UploadPropertyConverter.cs
index cfa247edaa..407ed13ddf 100644
--- a/src/Umbraco.Core/PropertyEditors/ValueConverters/UploadPropertyConverter.cs
+++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/UploadPropertyConverter.cs
@@ -9,16 +9,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class UploadPropertyConverter : PropertyValueConverterBase
{
- public override bool IsConverter(PublishedPropertyType propertyType)
+ public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.Equals(Constants.PropertyEditors.Aliases.UploadField);
- public override Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (string);
- public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
- public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object source, bool preview)
+ public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object source, bool preview)
{
return source?.ToString() ?? "";
}
diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/YesNoValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/YesNoValueConverter.cs
index 8ad09733f8..153462ccf5 100644
--- a/src/Umbraco.Core/PropertyEditors/ValueConverters/YesNoValueConverter.cs
+++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/YesNoValueConverter.cs
@@ -6,16 +6,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class YesNoValueConverter : PropertyValueConverterBase
{
- public override bool IsConverter(PublishedPropertyType propertyType)
+ public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias == Constants.PropertyEditors.Aliases.Boolean;
- public override Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (bool);
- public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
- public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
+ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
// in xml a boolean is: string
// in the database a boolean is: string "1" or "0" or empty
@@ -49,7 +49,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
// default ConvertSourceToObject just returns source ie a boolean value
- public override object ConvertIntermediateToXPath(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
+ public override object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
// source should come from ConvertSource and be a boolean already
return (bool)inter ? "1" : "0";
diff --git a/src/Umbraco.Core/PublishedContentExtensions.cs b/src/Umbraco.Core/PublishedContentExtensions.cs
new file mode 100644
index 0000000000..f220f307d6
--- /dev/null
+++ b/src/Umbraco.Core/PublishedContentExtensions.cs
@@ -0,0 +1,128 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Umbraco.Core.Composing;
+using Umbraco.Core.Models.PublishedContent;
+
+namespace Umbraco.Core
+{
+ public static class PublishedContentExtensions
+ {
+ private static IVariationContextAccessor VariationContextAccessor => Current.VariationContextAccessor;
+
+ ///
+ /// Determines whether the content has a culture.
+ ///
+ /// Culture is case-insensitive.
+ public static bool HasCulture(this IPublishedContent content, string culture)
+ => content.Cultures.ContainsKey(culture ?? string.Empty);
+
+ ///
+ /// Determines whether the content is invariant, or has a culture.
+ ///
+ /// Culture is case-insensitive.
+ public static bool IsInvariantOrHasCulture(this IPublishedContent content, string culture)
+ => !content.ContentType.VariesByCulture() || content.Cultures.ContainsKey(culture ?? "");
+
+ ///
+ /// Filters a sequence of to return invariant items, and items that are published for the specified culture.
+ ///
+ /// The content items.
+ /// The specific culture to filter for. If null is used the current culture is used. (Default is null).
+ internal static IEnumerable WhereIsInvariantOrHasCulture(this IEnumerable contents, string culture = null)
+ where T : class, IPublishedContent
+ {
+ if (contents == null) throw new ArgumentNullException(nameof(contents));
+
+ culture = culture ?? Current.VariationContextAccessor.VariationContext?.Culture ?? "";
+
+ // either does not vary by culture, or has the specified culture
+ return contents.Where(x => !x.ContentType.VariesByCulture() || HasCulture(x, culture));
+ }
+
+ ///
+ /// Gets the name of the content item.
+ ///
+ /// The content item.
+ /// The specific culture to get the name for. If null is used the current culture is used (Default is null).
+ public static string Name(this IPublishedContent content, string culture = null)
+ {
+ // invariant has invariant value (whatever the requested culture)
+ if (!content.ContentType.VariesByCulture())
+ return content.Cultures.TryGetValue("", out var invariantInfos) ? invariantInfos.Name : null;
+
+ // handle context culture for variant
+ if (culture == null)
+ culture = VariationContextAccessor?.VariationContext?.Culture ?? "";
+
+ // get
+ return culture != "" && content.Cultures.TryGetValue(culture, out var infos) ? infos.Name : null;
+ }
+
+
+ ///
+ /// Gets the url segment of the content item.
+ ///
+ /// The content item.
+ /// The specific culture to get the url segment for. If null is used the current culture is used (Default is null).
+ public static string UrlSegment(this IPublishedContent content, string culture = null)
+ {
+ // invariant has invariant value (whatever the requested culture)
+ if (!content.ContentType.VariesByCulture())
+ return content.Cultures.TryGetValue("", out var invariantInfos) ? invariantInfos.UrlSegment : null;
+
+ // handle context culture for variant
+ if (culture == null)
+ culture = VariationContextAccessor?.VariationContext?.Culture ?? "";
+
+ // get
+ return culture != "" && content.Cultures.TryGetValue(culture, out var infos) ? infos.UrlSegment : null;
+ }
+
+ ///
+ /// Gets the culture date of the content item.
+ ///
+ /// The content item.
+ /// The specific culture to get the name for. If null is used the current culture is used (Default is null).
+ public static DateTime CultureDate(this IPublishedContent content, string culture = null)
+ {
+ // invariant has invariant value (whatever the requested culture)
+ if (!content.ContentType.VariesByCulture())
+ return content.UpdateDate;
+
+ // handle context culture for variant
+ if (culture == null)
+ culture = VariationContextAccessor?.VariationContext?.Culture ?? "";
+
+ // get
+ return culture != "" && content.Cultures.TryGetValue(culture, out var infos) ? infos.Date : DateTime.MinValue;
+ }
+
+
+ ///
+ /// Gets the children of the content item.
+ ///
+ /// The content item.
+ /// The specific culture to get the url children for. If null is used the current culture is used (Default is null).
+ ///
+ /// Gets children that are available for the specified culture.
+ /// Children are sorted by their sortOrder.
+ /// The '*' culture and supported and returns everything.
+ ///
+ public static IEnumerable Children(this IPublishedContent content, string culture = null)
+ {
+ // invariant has invariant value (whatever the requested culture)
+ if (!content.ContentType.VariesByCulture() && culture != "*")
+ culture = "";
+
+ // handle context culture for variant
+ if (culture == null)
+ culture = VariationContextAccessor?.VariationContext?.Culture ?? "";
+
+ var children = content.ChildrenForAllCultures;
+ return culture == "*"
+ ? children
+ : children.Where(x => x.IsInvariantOrHasCulture(culture));
+ }
+ }
+}
diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj
index cbd372cfb6..1c80d6fcc4 100755
--- a/src/Umbraco.Core/Umbraco.Core.csproj
+++ b/src/Umbraco.Core/Umbraco.Core.csproj
@@ -254,6 +254,10 @@
+
+
+
+
diff --git a/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs b/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs
index fbf828ad20..be160a483c 100644
--- a/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs
+++ b/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs
@@ -68,9 +68,9 @@ namespace Umbraco.Tests.Cache.PublishedCache
var appCache = new DictionaryAppCache();
var domainCache = new DomainCache(ServiceContext.DomainService, DefaultCultureAccessor);
var publishedShapshot = new PublishedSnapshot(
- new PublishedContentCache(xmlStore, domainCache, appCache, globalSettings, new SiteDomainHelper(), umbracoContextAccessor, ContentTypesCache, null, null),
+ new PublishedContentCache(xmlStore, domainCache, appCache, globalSettings, ContentTypesCache, null, null),
new PublishedMediaCache(xmlStore, ServiceContext.MediaService, ServiceContext.UserService, appCache, ContentTypesCache, Factory.GetInstance(), umbracoContextAccessor),
- new PublishedMemberCache(null, appCache, Current.Services.MemberService, ContentTypesCache, umbracoContextAccessor),
+ new PublishedMemberCache(null, appCache, Current.Services.MemberService, ContentTypesCache),
domainCache);
var publishedSnapshotService = new Mock();
publishedSnapshotService.Setup(x => x.CreatePublishedSnapshot(It.IsAny())).Returns(publishedShapshot);
@@ -85,7 +85,7 @@ namespace Umbraco.Tests.Cache.PublishedCache
globalSettings,
new TestVariationContextAccessor());
- _cache = _umbracoContext.ContentCache;
+ _cache = _umbracoContext.Content;
}
[Test]
diff --git a/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs b/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs
index 08eeb8ef4d..f3d9f895ef 100644
--- a/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs
+++ b/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs
@@ -323,8 +323,7 @@ namespace Umbraco.Tests.Cache.PublishedCache
// no xpath
null,
// not from examine
- false,
- _umbracoContextAccessor),
+ false),
//callback to get the children
(dd, n) => children,
// callback to get a property
@@ -334,8 +333,7 @@ namespace Umbraco.Tests.Cache.PublishedCache
// no xpath
null,
// not from examine
- false,
- _umbracoContextAccessor);
+ false);
return dicDoc;
}
diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/DictionaryPublishedContent.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/DictionaryPublishedContent.cs
index d3cbf1f183..db8dc38d6d 100644
--- a/src/Umbraco.Tests/LegacyXmlPublishedCache/DictionaryPublishedContent.cs
+++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/DictionaryPublishedContent.cs
@@ -8,7 +8,6 @@ using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Logging;
using Umbraco.Core.Models.PublishedContent;
-using Umbraco.Web;
using Umbraco.Web.Composing;
using Umbraco.Web.Models;
using Umbraco.Web.PublishedCache;
@@ -40,9 +39,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
IAppCache appCache,
PublishedContentTypeCache contentTypeCache,
XPathNavigator nav,
- bool fromExamine,
- IUmbracoContextAccessor umbracoContextAccessor)
- :base(umbracoContextAccessor)
+ bool fromExamine)
{
if (valueDictionary == null) throw new ArgumentNullException(nameof(valueDictionary));
if (getParent == null) throw new ArgumentNullException(nameof(getParent));
@@ -158,8 +155,6 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
public override string Name => _name;
- public override PublishedCultureInfo GetCulture(string culture = null) => null;
-
private static readonly Lazy> NoCultures = new Lazy>(() => new Dictionary());
public override IReadOnlyDictionary Cultures => NoCultures.Value;
@@ -189,12 +184,14 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
public override IEnumerable Children => _getChildren.Value;
+ public override IEnumerable ChildrenForAllCultures => Children;
+
public override IPublishedProperty GetProperty(string alias)
{
return _getProperty(this, alias);
}
- public override PublishedContentType ContentType => _contentType;
+ public override IPublishedContentType ContentType => _contentType;
private readonly List _keysAdded = new List();
private int _id;
@@ -215,7 +212,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
//private Guid _version;
private int _level;
private readonly ICollection _properties;
- private readonly PublishedContentType _contentType;
+ private readonly IPublishedContentType _contentType;
private void ValidateAndSetProperty(IReadOnlyDictionary valueDictionary, Action setProperty, params string[] potentialKeys)
{
diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/DomainCache.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/DomainCache.cs
index cde2077551..abaa239598 100644
--- a/src/Umbraco.Tests/LegacyXmlPublishedCache/DomainCache.cs
+++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/DomainCache.cs
@@ -27,13 +27,18 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
}
///
- public IEnumerable GetAssigned(int contentId, bool includeWildcards)
+ public IEnumerable GetAssigned(int documentId, bool includeWildcards = false)
{
- return _domainService.GetAssignedDomains(contentId, includeWildcards)
+ return _domainService.GetAssignedDomains(documentId, includeWildcards)
.Where(x => x.RootContentId.HasValue && x.LanguageIsoCode.IsNullOrWhiteSpace() == false)
.Select(x => new Domain(x.Id, x.DomainName, x.RootContentId.Value, CultureInfo.GetCultureInfo(x.LanguageIsoCode), x.IsWildcard));
}
+ ///
+ public bool HasAssigned(int documentId, bool includeWildcards = false)
+ => documentId > 0 && GetAssigned(documentId, includeWildcards).Any();
+
+ ///
public string DefaultCulture { get; }
}
}
diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedContentCache.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedContentCache.cs
index 2a144f3aaa..8ce6b10983 100644
--- a/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedContentCache.cs
+++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedContentCache.cs
@@ -9,7 +9,6 @@ using Umbraco.Core.Cache;
using Umbraco.Core.Configuration;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Xml;
-using Umbraco.Web;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.Routing;
@@ -19,10 +18,8 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
{
private readonly IAppCache _appCache;
private readonly IGlobalSettings _globalSettings;
- private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly RoutesCache _routesCache;
private readonly IDomainCache _domainCache;
- private readonly DomainHelper _domainHelper;
private readonly PublishedContentTypeCache _contentTypeCache;
// initialize a PublishedContentCache instance with
@@ -35,8 +32,6 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
IDomainCache domainCache, // an IDomainCache implementation
IAppCache appCache, // an IAppCache that should be at request-level
IGlobalSettings globalSettings,
- ISiteDomainHelper siteDomainHelper,
- IUmbracoContextAccessor umbracoContextAccessor,
PublishedContentTypeCache contentTypeCache, // a PublishedContentType cache
RoutesCache routesCache, // a RoutesCache
string previewToken) // a preview token string (or null if not previewing)
@@ -44,11 +39,9 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
{
_appCache = appCache;
_globalSettings = globalSettings;
- _umbracoContextAccessor = umbracoContextAccessor;
_routesCache = routesCache; // may be null for unit-testing
_contentTypeCache = contentTypeCache;
_domainCache = domainCache;
- _domainHelper = new DomainHelper(_domainCache, siteDomainHelper);
_xmlStore = xmlStore;
_xml = _xmlStore.Xml; // capture - because the cache has to remain consistent
@@ -107,7 +100,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
// that would be returned - the "deepest" route - and that is the route we want to cache, *not* the
// longer one - so make sure we don't cache the wrong route
- var deepest = DomainHelper.ExistsDomainInPath(_domainCache.GetAll(false), content.Path, domainRootNodeId) == false;
+ var deepest = DomainUtilities.ExistsDomainInPath(_domainCache.GetAll(false), content.Path, domainRootNodeId) == false;
if (deepest)
_routesCache.Store(content.Id, route, true); // trusted route
@@ -267,16 +260,16 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
// or we reach the content root, collecting urls in the way
var pathParts = new List();
var n = node;
- var hasDomains = _domainHelper.NodeHasDomains(n.Id);
+ var hasDomains = _domainCache.HasAssigned(n.Id);
while (hasDomains == false && n != null) // n is null at root
{
// get the url
- var urlName = n.UrlSegment;
+ var urlName = n.UrlSegment();
pathParts.Add(urlName);
// move to parent node
n = n.Parent;
- hasDomains = n != null && _domainHelper.NodeHasDomains(n.Id);
+ hasDomains = n != null && _domainCache.HasAssigned(n.Id);
}
// no domain, respect HideTopLevelNodeFromPath for legacy purposes
@@ -320,13 +313,13 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
private IPublishedContent ConvertToDocument(XmlNode xmlNode, bool isPreviewing)
{
- return xmlNode == null ? null : XmlPublishedContent.Get(xmlNode, isPreviewing, _appCache, _contentTypeCache,_umbracoContextAccessor);
+ return xmlNode == null ? null : XmlPublishedContent.Get(xmlNode, isPreviewing, _appCache, _contentTypeCache);
}
private IEnumerable ConvertToDocuments(XmlNodeList xmlNodes, bool isPreviewing)
{
return xmlNodes.Cast()
- .Select(xmlNode => XmlPublishedContent.Get(xmlNode, isPreviewing, _appCache, _contentTypeCache, _umbracoContextAccessor));
+ .Select(xmlNode => XmlPublishedContent.Get(xmlNode, isPreviewing, _appCache, _contentTypeCache));
}
#endregion
@@ -389,7 +382,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
return GetXml(preview).CreateNavigator().MoveToId(contentId.ToString(CultureInfo.InvariantCulture));
}
- public override IEnumerable GetAtRoot(bool preview)
+ public override IEnumerable GetAtRoot(bool preview, string culture = null)
{
return ConvertToDocuments(GetXml(preview).SelectNodes(XPathStrings.RootDocuments), preview);
}
@@ -539,12 +532,12 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
#region Content types
- public override PublishedContentType GetContentType(int id)
+ public override IPublishedContentType GetContentType(int id)
{
return _contentTypeCache.Get(PublishedItemType.Content, id);
}
- public override PublishedContentType GetContentType(string alias)
+ public override IPublishedContentType GetContentType(string alias)
{
return _contentTypeCache.Get(PublishedItemType.Content, alias);
}
diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedMediaCache.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedMediaCache.cs
index 0c7ee98c6d..999d7f040d 100644
--- a/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedMediaCache.cs
+++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedMediaCache.cs
@@ -105,7 +105,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
return GetUmbracoMedia(contentId) != null;
}
- public override IEnumerable GetAtRoot(bool preview)
+ public override IEnumerable GetAtRoot(bool preview, string culture = null)
{
var searchProvider = GetSearchProviderSafe();
@@ -612,17 +612,17 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
#region Content types
- public override PublishedContentType GetContentType(int id)
+ public override IPublishedContentType GetContentType(int id)
{
return _contentTypeCache.Get(PublishedItemType.Media, id);
}
- public override PublishedContentType GetContentType(string alias)
+ public override IPublishedContentType GetContentType(string alias)
{
return _contentTypeCache.Get(PublishedItemType.Media, alias);
}
- public override IEnumerable GetByContentType(PublishedContentType contentType)
+ public override IEnumerable GetByContentType(IPublishedContentType contentType)
{
throw new NotSupportedException();
}
@@ -674,8 +674,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
_appCache,
_contentTypeCache,
cacheValues.XPath, // though, outside of tests, that should be null
- cacheValues.FromExamine,
- _umbracoContextAccessor
+ cacheValues.FromExamine
);
return content.CreateModel();
}
diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedMemberCache.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedMemberCache.cs
index c882488f20..19328c241e 100644
--- a/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedMemberCache.cs
+++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedMemberCache.cs
@@ -6,7 +6,6 @@ using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Security;
using Umbraco.Core.Services;
-using Umbraco.Web;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.Security;
@@ -18,16 +17,13 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
private readonly IAppCache _requestCache;
private readonly XmlStore _xmlStore;
private readonly PublishedContentTypeCache _contentTypeCache;
- private readonly IUmbracoContextAccessor _umbracoContextAccessor;
- public PublishedMemberCache(XmlStore xmlStore, IAppCache requestCache, IMemberService memberService,
- PublishedContentTypeCache contentTypeCache, IUmbracoContextAccessor umbracoContextAccessor)
+ public PublishedMemberCache(XmlStore xmlStore, IAppCache requestCache, IMemberService memberService, PublishedContentTypeCache contentTypeCache)
{
_requestCache = requestCache;
_memberService = memberService;
_xmlStore = xmlStore;
_contentTypeCache = contentTypeCache;
- _umbracoContextAccessor = umbracoContextAccessor;
}
public IPublishedContent GetByProviderKey(object key)
@@ -44,7 +40,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
var result = _memberService.GetByProviderKey(key);
if (result == null) return null;
var type = _contentTypeCache.Get(PublishedItemType.Member, result.ContentTypeId);
- return new PublishedMember(result, type, _umbracoContextAccessor).CreateModel();
+ return new PublishedMember(result, type).CreateModel();
});
}
@@ -62,7 +58,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
var result = _memberService.GetById(memberId);
if (result == null) return null;
var type = _contentTypeCache.Get(PublishedItemType.Member, result.ContentTypeId);
- return new PublishedMember(result, type, _umbracoContextAccessor).CreateModel();
+ return new PublishedMember(result, type).CreateModel();
});
}
@@ -80,7 +76,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
var result = _memberService.GetByUsername(username);
if (result == null) return null;
var type = _contentTypeCache.Get(PublishedItemType.Member, result.ContentTypeId);
- return new PublishedMember(result, type, _umbracoContextAccessor).CreateModel();
+ return new PublishedMember(result, type).CreateModel();
});
}
@@ -98,14 +94,14 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
var result = _memberService.GetByEmail(email);
if (result == null) return null;
var type = _contentTypeCache.Get(PublishedItemType.Member, result.ContentTypeId);
- return new PublishedMember(result, type, _umbracoContextAccessor).CreateModel();
+ return new PublishedMember(result, type).CreateModel();
});
}
public IPublishedContent GetByMember(IMember member)
{
var type = _contentTypeCache.Get(PublishedItemType.Member, member.ContentTypeId);
- return new PublishedMember(member, type, _umbracoContextAccessor).CreateModel();
+ return new PublishedMember(member, type).CreateModel();
}
public XPathNavigator CreateNavigator()
@@ -138,12 +134,12 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
#region Content types
- public PublishedContentType GetContentType(int id)
+ public IPublishedContentType GetContentType(int id)
{
return _contentTypeCache.Get(PublishedItemType.Member, id);
}
- public PublishedContentType GetContentType(string alias)
+ public IPublishedContentType GetContentType(string alias)
{
return _contentTypeCache.Get(PublishedItemType.Member, alias);
}
diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedSnapshotService.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedSnapshotService.cs
index 4a201ae44c..394a33d777 100644
--- a/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedSnapshotService.cs
+++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedSnapshotService.cs
@@ -145,9 +145,9 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
var domainCache = new DomainCache(_domainService, _defaultCultureAccessor);
return new PublishedSnapshot(
- new PublishedContentCache(_xmlStore, domainCache, _requestCache, _globalSettings, _siteDomainHelper,_umbracoContextAccessor, _contentTypeCache, _routesCache, previewToken),
+ new PublishedContentCache(_xmlStore, domainCache, _requestCache, _globalSettings, _contentTypeCache, _routesCache, previewToken),
new PublishedMediaCache(_xmlStore, _mediaService, _userService, _requestCache, _contentTypeCache, _entitySerializer, _umbracoContextAccessor),
- new PublishedMemberCache(_xmlStore, _requestCache, _memberService, _contentTypeCache, _umbracoContextAccessor),
+ new PublishedMemberCache(_xmlStore, _requestCache, _memberService, _contentTypeCache),
domainCache);
}
diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedContent.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedContent.cs
index e1819bf0be..3697863cb4 100644
--- a/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedContent.cs
+++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedContent.cs
@@ -26,23 +26,19 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
XmlNode xmlNode,
bool isPreviewing,
IAppCache appCache,
- PublishedContentTypeCache contentTypeCache,
- IUmbracoContextAccessor umbracoContextAccessor)
- :base(umbracoContextAccessor)
+ PublishedContentTypeCache contentTypeCache)
{
_xmlNode = xmlNode;
_isPreviewing = isPreviewing;
_appCache = appCache;
_contentTypeCache = contentTypeCache;
- _umbracoContextAccessor = umbracoContextAccessor;
}
private readonly XmlNode _xmlNode;
private readonly bool _isPreviewing;
private readonly IAppCache _appCache; // at snapshot/request level (see PublishedContentCache)
private readonly PublishedContentTypeCache _contentTypeCache;
- private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly object _initializeLock = new object();
@@ -53,7 +49,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
private IEnumerable _children = Enumerable.Empty();
private IPublishedContent _parent;
- private PublishedContentType _contentType;
+ private IPublishedContentType _contentType;
private Dictionary _properties;
private int _id;
@@ -84,6 +80,8 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
}
}
+ public override IEnumerable ChildrenForAllCultures => Children;
+
public override IPublishedProperty GetProperty(string alias)
{
EnsureNodeInitialized();
@@ -147,10 +145,15 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
}
}
- public override PublishedCultureInfo GetCulture(string culture = null) => null;
+ private Dictionary _cultures;
- private static readonly Lazy> NoCultures = new Lazy>(() => new Dictionary());
- public override IReadOnlyDictionary Cultures => NoCultures.Value;
+ private Dictionary GetCultures()
+ {
+ EnsureNodeInitialized();
+ return new Dictionary { { "", new PublishedCultureInfo("", _name, _urlName, _updateDate) } };
+ }
+
+ public override IReadOnlyDictionary Cultures => _cultures ?? (_cultures = GetCultures());
public override string WriterName
{
@@ -254,7 +257,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
}
}
- public override PublishedContentType ContentType
+ public override IPublishedContentType ContentType
{
get
{
@@ -269,7 +272,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
if (parent == null) return;
if (parent.Attributes?.GetNamedItem("isDoc") != null)
- _parent = Get(parent, _isPreviewing, _appCache, _contentTypeCache, _umbracoContextAccessor);
+ _parent = Get(parent, _isPreviewing, _appCache, _contentTypeCache);
_parentInitialized = true;
}
@@ -308,8 +311,8 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
out int id, out Guid key, out int template, out int sortOrder, out string name, out string writerName, out string urlName,
out string creatorName, out int creatorId, out int writerId, out string docTypeAlias, out int docTypeId, out string path,
out DateTime createDate, out DateTime updateDate, out int level, out bool isDraft,
- out PublishedContentType contentType, out Dictionary properties,
- Func getPublishedContentType)
+ out IPublishedContentType contentType, out Dictionary properties,
+ Func getPublishedContentType)
{
//initialize the out params with defaults:
writerName = null;
@@ -426,7 +429,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
var iterator = nav.Select(expr);
_children = iterator.Cast()
- .Select(n => Get(((IHasXmlNode) n).GetNode(), _isPreviewing, _appCache, _contentTypeCache, _umbracoContextAccessor))
+ .Select(n => Get(((IHasXmlNode) n).GetNode(), _isPreviewing, _appCache, _contentTypeCache))
.OrderBy(x => x.SortOrder)
.ToList();
@@ -446,7 +449,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
/// sure that we create only one instance of each for the duration of a request. The
/// returned IPublishedContent is a model, if models are enabled.
public static IPublishedContent Get(XmlNode node, bool isPreviewing, IAppCache appCache,
- PublishedContentTypeCache contentTypeCache, IUmbracoContextAccessor umbracoContextAccessor)
+ PublishedContentTypeCache contentTypeCache)
{
// only 1 per request
@@ -454,7 +457,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
var id = attrs?.GetNamedItem("id").Value;
if (id.IsNullOrWhiteSpace()) throw new InvalidOperationException("Node has no ID attribute.");
var key = CacheKeyPrefix + id; // dont bother with preview, wont change during request in Xml cache
- return (IPublishedContent) appCache.Get(key, () => (new XmlPublishedContent(node, isPreviewing, appCache, contentTypeCache, umbracoContextAccessor)).CreateModel());
+ return (IPublishedContent) appCache.Get(key, () => (new XmlPublishedContent(node, isPreviewing, appCache, contentTypeCache)).CreateModel());
}
public static void ClearRequest()
diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedProperty.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedProperty.cs
index 0c90c8d1ff..7d2fa74aa6 100644
--- a/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedProperty.cs
+++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedProperty.cs
@@ -50,7 +50,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
public override object GetXPathValue(string culture = null, string segment = null) { throw new NotImplementedException(); }
- public XmlPublishedProperty(PublishedPropertyType propertyType, IPublishedContent content, bool isPreviewing, XmlNode propertyXmlData)
+ public XmlPublishedProperty(IPublishedPropertyType propertyType, IPublishedContent content, bool isPreviewing, XmlNode propertyXmlData)
: this(propertyType, content, isPreviewing)
{
if (propertyXmlData == null)
@@ -58,7 +58,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
_sourceValue = XmlHelper.GetNodeValue(propertyXmlData);
}
- public XmlPublishedProperty(PublishedPropertyType propertyType, IPublishedContent content, bool isPreviewing, string propertyData)
+ public XmlPublishedProperty(IPublishedPropertyType propertyType, IPublishedContent content, bool isPreviewing, string propertyData)
: this(propertyType, content, isPreviewing)
{
if (propertyData == null)
@@ -66,7 +66,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
_sourceValue = propertyData;
}
- public XmlPublishedProperty(PublishedPropertyType propertyType, IPublishedContent content, bool isPreviewing)
+ public XmlPublishedProperty(IPublishedPropertyType propertyType, IPublishedContent content, bool isPreviewing)
: base(propertyType, PropertyCacheLevel.Unknown) // cache level is ignored
{
_sourceValue = string.Empty;
diff --git a/src/Umbraco.Tests/Mapping/MappingTests.cs b/src/Umbraco.Tests/Mapping/MappingTests.cs
index 79d383857a..e6a382692c 100644
--- a/src/Umbraco.Tests/Mapping/MappingTests.cs
+++ b/src/Umbraco.Tests/Mapping/MappingTests.cs
@@ -172,6 +172,48 @@ namespace Umbraco.Tests.Mapping
}
}
+ [Test]
+ public void EnumMap()
+ {
+ var definitions = new MapDefinitionCollection(new IMapDefinition[]
+ {
+ new MapperDefinition4(),
+ });
+ var mapper = new UmbracoMapper(definitions);
+
+ var thing5 = new Thing5()
+ {
+ Fruit1 = Thing5Enum.Apple,
+ Fruit2 = Thing5Enum.Banana,
+ Fruit3= Thing5Enum.Cherry
+ };
+
+ var thing6 = mapper.Map(thing5);
+
+ Assert.IsNotNull(thing6);
+ Assert.AreEqual(Thing6Enum.Apple, thing6.Fruit1);
+ Assert.AreEqual(Thing6Enum.Banana, thing6.Fruit2);
+ Assert.AreEqual(Thing6Enum.Cherry, thing6.Fruit3);
+ }
+
+ [Test]
+ public void NullPropertyMap()
+ {
+ var definitions = new MapDefinitionCollection(new IMapDefinition[]
+ {
+ new MapperDefinition5(),
+ });
+ var mapper = new UmbracoMapper(definitions);
+
+ var thing7 = new Thing7();
+
+ var thing8 = mapper.Map(thing7);
+
+ Assert.IsNotNull(thing8);
+ Assert.IsNull(thing8.Things);
+ }
+
+
private class Thing1
{
public string Value { get; set; }
@@ -188,6 +230,44 @@ namespace Umbraco.Tests.Mapping
private class Thing4
{ }
+ private class Thing5
+ {
+ public Thing5Enum Fruit1 { get; set; }
+ public Thing5Enum Fruit2 { get; set; }
+ public Thing5Enum Fruit3 { get; set; }
+ }
+
+ private enum Thing5Enum
+ {
+ Apple = 0,
+ Banana = 1,
+ Cherry = 2
+ }
+
+ private class Thing6
+ {
+ public Thing6Enum Fruit1 { get; set; }
+ public Thing6Enum Fruit2 { get; set; }
+ public Thing6Enum Fruit3 { get; set; }
+ }
+
+ private enum Thing6Enum
+ {
+ Apple = 0,
+ Banana = 1,
+ Cherry = 2
+ }
+
+ private class Thing7
+ {
+ public IEnumerable Things { get; set; }
+ }
+
+ private class Thing8
+ {
+ public IEnumerable Things { get; set; }
+ }
+
private class MapperDefinition1 : IMapDefinition
{
public void DefineMaps(UmbracoMapper mapper)
@@ -224,5 +304,41 @@ namespace Umbraco.Tests.Mapping
mapper.Define();
}
}
+
+ private class MapperDefinition4 : IMapDefinition
+ {
+ public void DefineMaps(UmbracoMapper mapper)
+ {
+ mapper.Define((source, context) => new Thing6(), Map);
+ mapper.Define(
+ (source, context) => (Thing6Enum)source);
+ }
+
+ private void Map(Thing5 source, Thing6 target, MapperContext context)
+ {
+ target.Fruit1 = context.Map(source.Fruit1);
+ target.Fruit2 = context.Map(source.Fruit2);
+ target.Fruit3 = context.Map(source.Fruit3);
+ }
+ }
+
+ private class MapperDefinition5 : IMapDefinition
+ {
+ public void DefineMaps(UmbracoMapper mapper)
+ {
+ mapper.Define((source, context) => new Thing2(), Map1);
+ mapper.Define((source, context) => new Thing8(), Map2);
+ }
+
+ private void Map1(Thing1 source, Thing2 target, MapperContext context)
+ {
+ target.Value = source.Value;
+ }
+
+ private void Map2(Thing7 source, Thing8 target, MapperContext context)
+ {
+ target.Things = context.Map>(source.Things);
+ }
+ }
}
}
diff --git a/src/Umbraco.Tests/Published/ConvertersTests.cs b/src/Umbraco.Tests/Published/ConvertersTests.cs
index 0fce8ebfc3..671129848c 100644
--- a/src/Umbraco.Tests/Published/ConvertersTests.cs
+++ b/src/Umbraco.Tests/Published/ConvertersTests.cs
@@ -4,16 +4,14 @@ using System.Linq;
using Moq;
using NUnit.Framework;
using Umbraco.Core;
-using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
-using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Tests.Components;
+using Umbraco.Tests.PublishedContent;
using Umbraco.Tests.TestHelpers;
-using Umbraco.Tests.TestHelpers.Stubs;
using Umbraco.Web;
using Umbraco.Web.PublishedCache;
@@ -37,10 +35,12 @@ namespace Umbraco.Tests.Published
var contentTypeFactory = new PublishedContentTypeFactory(Mock.Of(), converters, dataTypeService);
- var elementType1 = contentTypeFactory.CreateContentType(1000, "element1", new[]
+ IEnumerable CreatePropertyTypes(IPublishedContentType contentType)
{
- contentTypeFactory.CreatePropertyType("prop1", 1),
- });
+ yield return contentTypeFactory.CreatePropertyType(contentType, "prop1", 1);
+ }
+
+ var elementType1 = contentTypeFactory.CreateContentType(1000, "element1", CreatePropertyTypes);
var element1 = new PublishedElement(elementType1, Guid.NewGuid(), new Dictionary { { "prop1", "1234" } }, false);
@@ -70,22 +70,22 @@ namespace Umbraco.Tests.Published
}
}
- public bool IsConverter(PublishedPropertyType propertyType)
+ public bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals("Umbraco.Void");
- public Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (int);
- public PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
- public object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
+ public object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
=> int.TryParse(source as string, out int i) ? i : 0;
- public object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
+ public object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
=> (int) inter;
- public object ConvertIntermediateToXPath(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
+ public object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
=> ((int) inter).ToString();
}
@@ -115,15 +115,17 @@ namespace Umbraco.Tests.Published
var contentTypeFactory = new PublishedContentTypeFactory(Mock.Of(), converters, dataTypeService);
- var elementType1 = contentTypeFactory.CreateContentType(1000, "element1", new[]
+ IEnumerable CreatePropertyTypes(IPublishedContentType contentType)
{
- contentTypeFactory.CreatePropertyType("prop1", 1),
- });
+ yield return contentTypeFactory.CreatePropertyType(contentType, "prop1", 1);
+ }
+
+ var elementType1 = contentTypeFactory.CreateContentType(1000, "element1", CreatePropertyTypes);
var element1 = new PublishedElement(elementType1, Guid.NewGuid(), new Dictionary { { "prop1", "1234" } }, false);
- var cntType1 = contentTypeFactory.CreateContentType(1001, "cnt1", Array.Empty());
- var cnt1 = new TestPublishedContent(cntType1, 1234, Guid.NewGuid(), new Dictionary(), false);
+ var cntType1 = contentTypeFactory.CreateContentType(1001, "cnt1", t => Enumerable.Empty());
+ var cnt1 = new SolidPublishedContent(cntType1) { Id = 1234 };
cacheContent[cnt1.Id] = cnt1;
Assert.AreSame(cnt1, element1.Value("prop1"));
@@ -143,26 +145,26 @@ namespace Umbraco.Tests.Published
public bool? IsValue(object value, PropertyValueLevel level)
=> value != null && (!(value is string) || string.IsNullOrWhiteSpace((string) value) == false);
- public bool IsConverter(PublishedPropertyType propertyType)
+ public bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals("Umbraco.Void");
- public Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public Type GetPropertyValueType(IPublishedPropertyType propertyType)
// the first version would be the "generic" version, but say we want to be more precise
// and return: whatever Clr type is generated for content type with alias "cnt1" -- which
// we cannot really typeof() at the moment because it has not been generated, hence ModelType.
// => typeof (IPublishedContent);
=> ModelType.For("cnt1");
- public PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> _cacheLevel;
- public object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
+ public object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
=> int.TryParse(source as string, out int i) ? i : -1;
- public object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
+ public object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
=> _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById((int) inter);
- public object ConvertIntermediateToXPath(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
+ public object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
=> ((int) inter).ToString();
}
@@ -208,30 +210,28 @@ namespace Umbraco.Tests.Published
var contentTypeFactory = new PublishedContentTypeFactory(factory, converters, dataTypeService);
- var elementType1 = contentTypeFactory.CreateContentType(1000, "element1", new[]
+ IEnumerable CreatePropertyTypes(IPublishedContentType contentType, int i)
{
- contentTypeFactory.CreatePropertyType("prop1", 1),
- });
+ yield return contentTypeFactory.CreatePropertyType(contentType, "prop" + i, i);
+ }
- var elementType2 = contentTypeFactory.CreateContentType(1001, "element2", new[]
- {
- contentTypeFactory.CreatePropertyType("prop2", 2),
- });
-
- var contentType1 = contentTypeFactory.CreateContentType(1002, "content1", new[]
- {
- contentTypeFactory.CreatePropertyType("prop1", 1),
- });
-
- var contentType2 = contentTypeFactory.CreateContentType(1003, "content2", new[]
- {
- contentTypeFactory.CreatePropertyType("prop2", 2),
- });
+ var elementType1 = contentTypeFactory.CreateContentType(1000, "element1", t => CreatePropertyTypes(t, 1));
+ var elementType2 = contentTypeFactory.CreateContentType(1001, "element2", t => CreatePropertyTypes(t, 2));
+ var contentType1 = contentTypeFactory.CreateContentType(1002, "content1", t => CreatePropertyTypes(t, 1));
+ var contentType2 = contentTypeFactory.CreateContentType(1003, "content2", t => CreatePropertyTypes(t, 2));
var element1 = new PublishedElement(elementType1, Guid.NewGuid(), new Dictionary { { "prop1", "val1" } }, false);
var element2 = new PublishedElement(elementType2, Guid.NewGuid(), new Dictionary { { "prop2", "1003" } }, false);
- var cnt1 = new TestPublishedContent(contentType1, 1003, Guid.NewGuid(), new Dictionary { { "prop1", "val1" } }, false);
- var cnt2 = new TestPublishedContent(contentType2, 1004, Guid.NewGuid(), new Dictionary { { "prop2", "1003" } }, false);
+ var cnt1 = new SolidPublishedContent(contentType1)
+ {
+ Id = 1003,
+ Properties = new[] { new SolidPublishedProperty { Alias = "prop1", SolidHasValue = true, SolidValue = "val1" } }
+ };
+ var cnt2 = new SolidPublishedContent(contentType1)
+ {
+ Id = 1004,
+ Properties = new[] { new SolidPublishedProperty { Alias = "prop2", SolidHasValue = true, SolidValue = "1003" } }
+ };
cacheContent[cnt1.Id] = cnt1.CreateModel();
cacheContent[cnt2.Id] = cnt2.CreateModel();
@@ -267,13 +267,13 @@ namespace Umbraco.Tests.Published
public class SimpleConverter3A : PropertyValueConverterBase
{
- public override bool IsConverter(PublishedPropertyType propertyType)
+ public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias == "Umbraco.Void";
- public override Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (string);
- public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
}
@@ -286,22 +286,22 @@ namespace Umbraco.Tests.Published
_publishedSnapshotAccessor = publishedSnapshotAccessor;
}
- public override bool IsConverter(PublishedPropertyType propertyType)
+ public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias == "Umbraco.Void.2";
- public override Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (IEnumerable<>).MakeGenericType(ModelType.For("content1"));
- public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Elements;
- public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
+ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
var s = source as string;
return s?.Split(',').Select(int.Parse).ToArray() ?? Array.Empty();
}
- public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
+ public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
return ((int[]) inter).Select(x => (PublishedSnapshotTestObjects.TestContentModel1) _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById(x)).ToArray();
}
diff --git a/src/Umbraco.Tests/Published/NestedContentTests.cs b/src/Umbraco.Tests/Published/NestedContentTests.cs
index 8f3b9a1df9..9385b8955a 100644
--- a/src/Umbraco.Tests/Published/NestedContentTests.cs
+++ b/src/Umbraco.Tests/Published/NestedContentTests.cs
@@ -11,6 +11,7 @@ using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
+using Umbraco.Tests.PublishedContent;
using Umbraco.Tests.TestHelpers;
using Umbraco.Web;
using Umbraco.Web.Models;
@@ -23,7 +24,7 @@ namespace Umbraco.Tests.Published
[TestFixture]
public class NestedContentTests
{
- private (PublishedContentType, PublishedContentType) CreateContentTypes()
+ private (IPublishedContentType, IPublishedContentType) CreateContentTypes()
{
Current.Reset();
@@ -125,13 +126,24 @@ namespace Umbraco.Tests.Published
var factory = new PublishedContentTypeFactory(publishedModelFactory.Object, converters, dataTypeService);
- var propertyType1 = factory.CreatePropertyType("property1", 1);
- var propertyType2 = factory.CreatePropertyType("property2", 2);
- var propertyTypeN1 = factory.CreatePropertyType("propertyN1", 3);
+ IEnumerable CreatePropertyTypes1(IPublishedContentType contentType)
+ {
+ yield return factory.CreatePropertyType(contentType, "property1", 1);
+ }
- var contentType1 = factory.CreateContentType(1, "content1", new[] { propertyType1 });
- var contentType2 = factory.CreateContentType(2, "content2", new[] { propertyType2 });
- var contentTypeN1 = factory.CreateContentType(2, "contentN1", new[] { propertyTypeN1 }, isElement: true);
+ IEnumerable CreatePropertyTypes2(IPublishedContentType contentType)
+ {
+ yield return factory.CreatePropertyType(contentType, "property2", 2);
+ }
+
+ IEnumerable CreatePropertyTypesN1(IPublishedContentType contentType)
+ {
+ yield return factory.CreatePropertyType(contentType, "propertyN1", 3);
+ }
+
+ var contentType1 = factory.CreateContentType(1, "content1", CreatePropertyTypes1);
+ var contentType2 = factory.CreateContentType(2, "content2", CreatePropertyTypes2);
+ var contentTypeN1 = factory.CreateContentType(2, "contentN1", CreatePropertyTypesN1, isElement: true);
// mocked content cache returns content types
contentCache
@@ -156,12 +168,16 @@ namespace Umbraco.Tests.Published
var key = Guid.NewGuid();
var keyA = Guid.NewGuid();
- var content = new TestPublishedContent(contentType1, key, new[]
+ var content = new SolidPublishedContent(contentType1)
{
- new TestPublishedProperty(contentType1.GetPropertyType("property1"), $@"[
+ Key = key,
+ Properties = new []
+ {
+ new TestPublishedProperty(contentType1.GetPropertyType("property1"), $@"[
{{ ""key"": ""{keyA}"", ""propertyN1"": ""foo"", ""ncContentTypeAlias"": ""contentN1"" }}
]")
- }, Mock.Of());
+ }
+ };
var value = content.Value("property1");
// nested single converter returns proper TestModel value
@@ -183,14 +199,17 @@ namespace Umbraco.Tests.Published
var key = Guid.NewGuid();
var keyA = Guid.NewGuid();
var keyB = Guid.NewGuid();
- var content = new TestPublishedContent(contentType2, key, new[]
+ var content = new SolidPublishedContent(contentType2)
{
- new TestPublishedProperty(contentType2.GetPropertyType("property2"), $@"[
+ Key = key,
+ Properties = new[]
+ {
+ new TestPublishedProperty(contentType2.GetPropertyType("property2"), $@"[
{{ ""key"": ""{keyA}"", ""propertyN1"": ""foo"", ""ncContentTypeAlias"": ""contentN1"" }},
{{ ""key"": ""{keyB}"", ""propertyN1"": ""bar"", ""ncContentTypeAlias"": ""contentN1"" }}
]")
- },
- Mock.Of());
+ }
+ };
var value = content.Value("property2");
// nested many converter returns proper IEnumerable value
@@ -219,14 +238,14 @@ namespace Umbraco.Tests.Published
private readonly bool _hasValue;
private IPublishedElement _owner;
- public TestPublishedProperty(PublishedPropertyType propertyType, object source)
+ public TestPublishedProperty(IPublishedPropertyType propertyType, object source)
: base(propertyType, PropertyCacheLevel.Element) // initial reference cache level always is .Content
{
_sourceValue = source;
_hasValue = source != null && (!(source is string ssource) || !string.IsNullOrWhiteSpace(ssource));
}
- public TestPublishedProperty(PublishedPropertyType propertyType, IPublishedElement element, bool preview, PropertyCacheLevel referenceCacheLevel, object source)
+ public TestPublishedProperty(IPublishedPropertyType propertyType, IPublishedElement element, bool preview, PropertyCacheLevel referenceCacheLevel, object source)
: base(propertyType, referenceCacheLevel)
{
_sourceValue = source;
@@ -247,52 +266,5 @@ namespace Umbraco.Tests.Published
public override object GetValue(string culture = null, string segment = null) => PropertyType.ConvertInterToObject(_owner, ReferenceCacheLevel, InterValue, _preview);
public override object GetXPathValue(string culture = null, string segment = null) => throw new WontImplementException();
}
-
- class TestPublishedContent : PublishedContentBase
- {
- public TestPublishedContent(PublishedContentType contentType, Guid key, IEnumerable properties, IUmbracoContextAccessor umbracoContextAccessor): base(umbracoContextAccessor)
- {
- ContentType = contentType;
- Key = key;
- var propertiesA = properties.ToArray();
- Properties = propertiesA;
- foreach (var property in propertiesA)
- property.SetOwner(this);
- }
-
- // ReSharper disable UnassignedGetOnlyAutoProperty
- public override PublishedItemType ItemType { get; }
- public override bool IsDraft(string culture = null) => false;
- public override bool IsPublished(string culture = null) => true;
- public override IPublishedContent Parent { get; }
- public override IEnumerable Children { get; }
- public override PublishedContentType ContentType { get; }
- // ReSharper restore UnassignedGetOnlyAutoProperty
-
- // ReSharper disable UnassignedGetOnlyAutoProperty
- public override int Id { get; }
- public override int? TemplateId { get; }
- public override int SortOrder { get; }
- public override string Name { get; }
- public override PublishedCultureInfo GetCulture(string culture = ".") => throw new NotSupportedException();
- public override IReadOnlyDictionary Cultures => throw new NotSupportedException();
- public override string UrlSegment { get; }
- public override string WriterName { get; }
- public override string CreatorName { get; }
- public override int WriterId { get; }
- public override int CreatorId { get; }
- public override string Path { get; }
- public override DateTime CreateDate { get; }
- public override DateTime UpdateDate { get; }
- public override int Level { get; }
- public override Guid Key { get; }
- // ReSharper restore UnassignedGetOnlyAutoProperty
-
- public override IEnumerable Properties { get; }
- public override IPublishedProperty GetProperty(string alias)
- {
- return Properties.FirstOrDefault(x => x.Alias.InvariantEquals(alias));
- }
- }
}
}
diff --git a/src/Umbraco.Tests/Published/PropertyCacheLevelTests.cs b/src/Umbraco.Tests/Published/PropertyCacheLevelTests.cs
index 76fdd81ec2..9db539d142 100644
--- a/src/Umbraco.Tests/Published/PropertyCacheLevelTests.cs
+++ b/src/Umbraco.Tests/Published/PropertyCacheLevelTests.cs
@@ -35,10 +35,13 @@ namespace Umbraco.Tests.Published
new DataType(new VoidEditor(Mock.Of())) { Id = 1 });
var publishedContentTypeFactory = new PublishedContentTypeFactory(Mock.Of(), converters, dataTypeService);
- var setType1 = publishedContentTypeFactory.CreateContentType(1000, "set1", new[]
+
+ IEnumerable CreatePropertyTypes(IPublishedContentType contentType)
{
- publishedContentTypeFactory.CreatePropertyType("prop1", 1),
- });
+ yield return publishedContentTypeFactory.CreatePropertyType(contentType, "prop1", 1);
+ }
+
+ var setType1 = publishedContentTypeFactory.CreateContentType(1000, "set1", CreatePropertyTypes);
// PublishedElementPropertyBase.GetCacheLevels:
//
@@ -113,10 +116,13 @@ namespace Umbraco.Tests.Published
new DataType(new VoidEditor(Mock.Of())) { Id = 1 });
var publishedContentTypeFactory = new PublishedContentTypeFactory(Mock.Of(), converters, dataTypeService);
- var setType1 = publishedContentTypeFactory.CreateContentType(1000, "set1", new[]
+
+ IEnumerable CreatePropertyTypes(IPublishedContentType contentType)
{
- publishedContentTypeFactory.CreatePropertyType("prop1", 1),
- });
+ yield return publishedContentTypeFactory.CreatePropertyType(contentType, "prop1", 1);
+ }
+
+ var setType1 = publishedContentTypeFactory.CreateContentType(1000, "set1", CreatePropertyTypes);
var elementsCache = new FastDictionaryAppCache();
var snapshotCache = new FastDictionaryAppCache();
@@ -187,10 +193,13 @@ namespace Umbraco.Tests.Published
new DataType(new VoidEditor(Mock.Of())) { Id = 1 });
var publishedContentTypeFactory = new PublishedContentTypeFactory(Mock.Of(), converters, dataTypeService);
- var setType1 = publishedContentTypeFactory.CreateContentType(1000, "set1", new[]
+
+ IEnumerable CreatePropertyTypes(IPublishedContentType contentType)
{
- publishedContentTypeFactory.CreatePropertyType("prop1", 1),
- });
+ yield return publishedContentTypeFactory.CreatePropertyType(contentType, "prop1", 1);
+ }
+
+ var setType1 = publishedContentTypeFactory.CreateContentType(1000, "set1", CreatePropertyTypes);
Assert.Throws(() =>
{
@@ -213,28 +222,28 @@ namespace Umbraco.Tests.Published
public bool? IsValue(object value, PropertyValueLevel level)
=> value != null && (!(value is string) || string.IsNullOrWhiteSpace((string) value) == false);
- public bool IsConverter(PublishedPropertyType propertyType)
+ public bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals("Umbraco.Void");
- public Type GetPropertyValueType(PublishedPropertyType propertyType)
+ public Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof(int);
- public PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
+ public PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> _cacheLevel;
- public object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
+ public object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
SourceConverts++;
return int.TryParse(source as string, out int i) ? i : 0;
}
- public object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
+ public object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
InterConverts++;
return (int) inter;
}
- public object ConvertIntermediateToXPath(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
+ public object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
=> ((int) inter).ToString();
}
}
diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs
new file mode 100644
index 0000000000..f3a520ead1
--- /dev/null
+++ b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs
@@ -0,0 +1,851 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Linq;
+using Moq;
+using NUnit.Framework;
+using Umbraco.Core;
+using Umbraco.Core.Composing;
+using Umbraco.Core.Configuration;
+using Umbraco.Core.Events;
+using Umbraco.Core.Logging;
+using Umbraco.Core.Models;
+using Umbraco.Core.Models.PublishedContent;
+using Umbraco.Core.Persistence.Repositories;
+using Umbraco.Core.PropertyEditors;
+using Umbraco.Core.Scoping;
+using Umbraco.Core.Services;
+using Umbraco.Core.Services.Changes;
+using Umbraco.Core.Strings;
+using Umbraco.Tests.TestHelpers;
+using Umbraco.Tests.Testing.Objects;
+using Umbraco.Tests.Testing.Objects.Accessors;
+using Umbraco.Web;
+using Umbraco.Web.Cache;
+using Umbraco.Web.PublishedCache;
+using Umbraco.Web.PublishedCache.NuCache;
+using Umbraco.Web.PublishedCache.NuCache.DataSource;
+
+namespace Umbraco.Tests.PublishedContent
+{
+ [TestFixture]
+ public class NuCacheChildrenTests
+ {
+ private IPublishedSnapshotService _snapshotService;
+ private IVariationContextAccessor _variationAccesor;
+ private IPublishedSnapshotAccessor _snapshotAccessor;
+ private ContentType _contentTypeInvariant;
+ private ContentType _contentTypeVariant;
+ private TestDataSource _source;
+
+ private void Init(IEnumerable kits)
+ {
+ Current.Reset();
+
+ var factory = Mock.Of();
+ Current.Factory = factory;
+
+ var configs = new Configs();
+ Mock.Get(factory).Setup(x => x.GetInstance(typeof(Configs))).Returns(configs);
+ var globalSettings = new GlobalSettings();
+ configs.Add(SettingsForTests.GenerateMockUmbracoSettings);
+ configs.Add(() => globalSettings);
+
+ var publishedModelFactory = new NoopPublishedModelFactory();
+ Mock.Get(factory).Setup(x => x.GetInstance(typeof(IPublishedModelFactory))).Returns(publishedModelFactory);
+
+ var runtime = Mock.Of();
+ Mock.Get(runtime).Setup(x => x.Level).Returns(RuntimeLevel.Run);
+
+ // create data types, property types and content types
+ var dataType = new DataType(new VoidEditor("Editor", Mock.Of())) { Id = 3 };
+
+ var dataTypes = new[]
+ {
+ dataType
+ };
+
+ var propertyType = new PropertyType("Umbraco.Void.Editor", ValueStorageType.Nvarchar) { Alias = "prop", DataTypeId = 3, Variations = ContentVariation.Nothing };
+ _contentTypeInvariant = new ContentType(-1) { Id = 2, Alias = "itype", Variations = ContentVariation.Nothing };
+ _contentTypeInvariant.AddPropertyType(propertyType);
+
+ propertyType = new PropertyType("Umbraco.Void.Editor", ValueStorageType.Nvarchar) { Alias = "prop", DataTypeId = 3, Variations = ContentVariation.Culture };
+ _contentTypeVariant = new ContentType(-1) { Id = 3, Alias = "vtype", Variations = ContentVariation.Culture };
+ _contentTypeVariant.AddPropertyType(propertyType);
+
+ var contentTypes = new[]
+ {
+ _contentTypeInvariant,
+ _contentTypeVariant
+ };
+
+ var contentTypeService = Mock.Of();
+ Mock.Get(contentTypeService).Setup(x => x.GetAll()).Returns(contentTypes);
+ Mock.Get(contentTypeService).Setup(x => x.GetAll(It.IsAny())).Returns(contentTypes);
+
+ var contentTypeServiceBaseFactory = Mock.Of();
+ Mock.Get(contentTypeServiceBaseFactory).Setup(x => x.For(It.IsAny())).Returns(contentTypeService);
+
+ var dataTypeService = Mock.Of();
+ Mock.Get(dataTypeService).Setup(x => x.GetAll()).Returns(dataTypes);
+
+ // create a service context
+ var serviceContext = ServiceContext.CreatePartial(
+ dataTypeService: dataTypeService,
+ memberTypeService: Mock.Of(),
+ memberService: Mock.Of(),
+ contentTypeService: contentTypeService,
+ localizationService: Mock.Of()
+ );
+
+ // create a scope provider
+ var scopeProvider = Mock.Of();
+ Mock.Get(scopeProvider)
+ .Setup(x => x.CreateScope(
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny(),
+ It.IsAny()))
+ .Returns(Mock.Of);
+
+ // create a published content type factory
+ var contentTypeFactory = new PublishedContentTypeFactory(
+ Mock.Of(),
+ new PropertyValueConverterCollection(Array.Empty()),
+ dataTypeService);
+
+ // create accessors
+ _variationAccesor = new TestVariationContextAccessor();
+ _snapshotAccessor = new TestPublishedSnapshotAccessor();
+
+ // create a data source for NuCache
+ _source = new TestDataSource(kits);
+
+ // at last, create the complete NuCache snapshot service!
+ var options = new PublishedSnapshotService.Options { IgnoreLocalDb = true };
+ _snapshotService = new PublishedSnapshotService(options,
+ null,
+ runtime,
+ serviceContext,
+ contentTypeFactory,
+ null,
+ _snapshotAccessor,
+ _variationAccesor,
+ Mock.Of(),
+ scopeProvider,
+ Mock.Of(),
+ Mock.Of(),
+ Mock.Of(),
+ new TestDefaultCultureAccessor(),
+ _source,
+ globalSettings,
+ Mock.Of(),
+ Mock.Of(),
+ new UrlSegmentProviderCollection(new[] { new DefaultUrlSegmentProvider() }));
+
+ // invariant is the current default
+ _variationAccesor.VariationContext = new VariationContext();
+
+ Mock.Get(factory).Setup(x => x.GetInstance(typeof(IVariationContextAccessor))).Returns(_variationAccesor);
+ }
+
+ private IEnumerable GetInvariantKits()
+ {
+ var paths = new Dictionary { { -1, "-1" } };
+
+ ContentNodeKit CreateKit(int id, int parentId, int sortOrder)
+ {
+ if (!paths.TryGetValue(parentId, out var parentPath))
+ throw new Exception("Unknown parent.");
+
+ var path = paths[id] = parentPath + "," + id;
+ var level = path.Count(x => x == ',');
+ var now = DateTime.Now;
+
+ return new ContentNodeKit
+ {
+ ContentTypeId = _contentTypeInvariant.Id,
+ Node = new ContentNode(id, Guid.NewGuid(), level, path, sortOrder, parentId, DateTime.Now, 0),
+ DraftData = null,
+ PublishedData = new ContentData
+ {
+ Name = "N" + id,
+ Published = true,
+ TemplateId = 0,
+ VersionId = 1,
+ VersionDate = now,
+ WriterId = 0,
+ Properties = new Dictionary(),
+ CultureInfos = new Dictionary()
+ }
+ };
+ }
+
+ yield return CreateKit(1, -1, 1);
+ yield return CreateKit(2, -1, 2);
+ yield return CreateKit(3, -1, 3);
+
+ yield return CreateKit(4, 1, 1);
+ yield return CreateKit(5, 1, 2);
+ yield return CreateKit(6, 1, 3);
+
+ yield return CreateKit(7, 2, 3);
+ yield return CreateKit(8, 2, 2);
+ yield return CreateKit(9, 2, 1);
+
+ yield return CreateKit(10, 3, 1);
+
+ yield return CreateKit(11, 4, 1);
+ yield return CreateKit(12, 4, 2);
+ }
+
+ private IEnumerable GetVariantKits()
+ {
+ var paths = new Dictionary { { -1, "-1" } };
+
+ Dictionary GetCultureInfos(int id, DateTime now)
+ {
+ var en = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
+ var fr = new[] { 1, 3, 4, 6, 7, 9, 10, 12 };
+
+ var infos = new Dictionary();
+ if (en.Contains(id))
+ infos["en-US"] = new CultureVariation { Name = "N" + id + "-" + "en-US", Date = now, IsDraft = false };
+ if (fr.Contains(id))
+ infos["fr-FR"] = new CultureVariation { Name = "N" + id + "-" + "fr-FR", Date = now, IsDraft = false };
+ return infos;
+ }
+
+ ContentNodeKit CreateKit(int id, int parentId, int sortOrder)
+ {
+ if (!paths.TryGetValue(parentId, out var parentPath))
+ throw new Exception("Unknown parent.");
+
+ var path = paths[id] = parentPath + "," + id;
+ var level = path.Count(x => x == ',');
+ var now = DateTime.Now;
+
+ return new ContentNodeKit
+ {
+ ContentTypeId = _contentTypeVariant.Id,
+ Node = new ContentNode(id, Guid.NewGuid(), level, path, sortOrder, parentId, DateTime.Now, 0),
+ DraftData = null,
+ PublishedData = new ContentData
+ {
+ Name = "N" + id,
+ Published = true,
+ TemplateId = 0,
+ VersionId = 1,
+ VersionDate = now,
+ WriterId = 0,
+ Properties = new Dictionary(),
+ CultureInfos = GetCultureInfos(id, now)
+ }
+ };
+ }
+
+ yield return CreateKit(1, -1, 1);
+ yield return CreateKit(2, -1, 2);
+ yield return CreateKit(3, -1, 3);
+
+ yield return CreateKit(4, 1, 1);
+ yield return CreateKit(5, 1, 2);
+ yield return CreateKit(6, 1, 3);
+
+ yield return CreateKit(7, 2, 3);
+ yield return CreateKit(8, 2, 2);
+ yield return CreateKit(9, 2, 1);
+
+ yield return CreateKit(10, 3, 1);
+
+ yield return CreateKit(11, 4, 1);
+ yield return CreateKit(12, 4, 2);
+ }
+
+ private IEnumerable GetVariantWithDraftKits()
+ {
+ var paths = new Dictionary { { -1, "-1" } };
+
+ Dictionary GetCultureInfos(int id, DateTime now)
+ {
+ var en = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
+ var fr = new[] { 1, 3, 4, 6, 7, 9, 10, 12 };
+
+ var infos = new Dictionary();
+ if (en.Contains(id))
+ infos["en-US"] = new CultureVariation { Name = "N" + id + "-" + "en-US", Date = now, IsDraft = false };
+ if (fr.Contains(id))
+ infos["fr-FR"] = new CultureVariation { Name = "N" + id + "-" + "fr-FR", Date = now, IsDraft = false };
+ return infos;
+ }
+
+ ContentNodeKit CreateKit(int id, int parentId, int sortOrder)
+ {
+ if (!paths.TryGetValue(parentId, out var parentPath))
+ throw new Exception("Unknown parent.");
+
+ var path = paths[id] = parentPath + "," + id;
+ var level = path.Count(x => x == ',');
+ var now = DateTime.Now;
+
+ ContentData CreateContentData(bool published) => new ContentData
+ {
+ Name = "N" + id,
+ Published = published,
+ TemplateId = 0,
+ VersionId = 1,
+ VersionDate = now,
+ WriterId = 0,
+ Properties = new Dictionary(),
+ CultureInfos = GetCultureInfos(id, now)
+ };
+
+ var withDraft = id%2==0;
+ var withPublished = !withDraft;
+
+ return new ContentNodeKit
+ {
+ ContentTypeId = _contentTypeVariant.Id,
+ Node = new ContentNode(id, Guid.NewGuid(), level, path, sortOrder, parentId, DateTime.Now, 0),
+ DraftData = withDraft ? CreateContentData(false) : null,
+ PublishedData = withPublished ? CreateContentData(true) : null
+ };
+ }
+
+ yield return CreateKit(1, -1, 1);
+ yield return CreateKit(2, -1, 2);
+ yield return CreateKit(3, -1, 3);
+
+ yield return CreateKit(4, 1, 1);
+ yield return CreateKit(5, 1, 2);
+ yield return CreateKit(6, 1, 3);
+
+ yield return CreateKit(7, 2, 3);
+ yield return CreateKit(8, 2, 2);
+ yield return CreateKit(9, 2, 1);
+
+ yield return CreateKit(10, 3, 1);
+
+ yield return CreateKit(11, 4, 1);
+ yield return CreateKit(12, 4, 2);
+ }
+
+ [Test]
+ public void EmptyTest()
+ {
+ Init(Enumerable.Empty());
+
+ var snapshot = _snapshotService.CreatePublishedSnapshot(previewToken: null);
+ _snapshotAccessor.PublishedSnapshot = snapshot;
+
+ var documents = snapshot.Content.GetAtRoot().ToArray();
+ Assert.AreEqual(0, documents.Length);
+ }
+
+ [Test]
+ public void ChildrenTest()
+ {
+ Init(GetInvariantKits());
+
+ var snapshot = _snapshotService.CreatePublishedSnapshot(previewToken: null);
+ _snapshotAccessor.PublishedSnapshot = snapshot;
+
+ var documents = snapshot.Content.GetAtRoot().ToArray();
+ AssertDocuments(documents, "N1", "N2", "N3");
+
+ documents = snapshot.Content.GetById(1).Children().ToArray();
+ AssertDocuments(documents, "N4", "N5", "N6");
+
+ documents = snapshot.Content.GetById(2).Children().ToArray();
+ AssertDocuments(documents, "N9", "N8", "N7");
+
+ documents = snapshot.Content.GetById(3).Children().ToArray();
+ AssertDocuments(documents, "N10");
+
+ documents = snapshot.Content.GetById(4).Children().ToArray();
+ AssertDocuments(documents, "N11", "N12");
+
+ documents = snapshot.Content.GetById(10).Children().ToArray();
+ AssertDocuments(documents);
+ }
+
+ [Test]
+ public void ParentTest()
+ {
+ Init(GetInvariantKits());
+
+ var snapshot = _snapshotService.CreatePublishedSnapshot(previewToken: null);
+ _snapshotAccessor.PublishedSnapshot = snapshot;
+
+ Assert.IsNull(snapshot.Content.GetById(1).Parent);
+ Assert.IsNull(snapshot.Content.GetById(2).Parent);
+ Assert.IsNull(snapshot.Content.GetById(3).Parent);
+
+ Assert.AreEqual(1, snapshot.Content.GetById(4).Parent?.Id);
+ Assert.AreEqual(1, snapshot.Content.GetById(5).Parent?.Id);
+ Assert.AreEqual(1, snapshot.Content.GetById(6).Parent?.Id);
+
+ Assert.AreEqual(2, snapshot.Content.GetById(7).Parent?.Id);
+ Assert.AreEqual(2, snapshot.Content.GetById(8).Parent?.Id);
+ Assert.AreEqual(2, snapshot.Content.GetById(9).Parent?.Id);
+
+ Assert.AreEqual(3, snapshot.Content.GetById(10).Parent?.Id);
+
+ Assert.AreEqual(4, snapshot.Content.GetById(11).Parent?.Id);
+ Assert.AreEqual(4, snapshot.Content.GetById(12).Parent?.Id);
+ }
+
+ [Test]
+ public void MoveToRootTest()
+ {
+ Init(GetInvariantKits());
+
+ // get snapshot
+ var snapshot = _snapshotService.CreatePublishedSnapshot(previewToken: null);
+ _snapshotAccessor.PublishedSnapshot = snapshot;
+
+ // do some changes
+ var kit = _source.Kits[10];
+ _source.Kits[10] = new ContentNodeKit
+ {
+ ContentTypeId = 2,
+ Node = new ContentNode(kit.Node.Id, Guid.NewGuid(), 1, "-1,10", 4, -1, DateTime.Now, 0),
+ DraftData = null,
+ PublishedData = new ContentData
+ {
+ Name = kit.PublishedData.Name,
+ Published = true,
+ TemplateId = 0,
+ VersionId = 1,
+ VersionDate = DateTime.Now,
+ WriterId = 0,
+ Properties = new Dictionary(),
+ CultureInfos = new Dictionary()
+ }
+ };
+
+ // notify
+ _snapshotService.Notify(new[] { new ContentCacheRefresher.JsonPayload(10, TreeChangeTypes.RefreshBranch) }, out _, out _);
+
+ // changes that *I* make are immediately visible on the current snapshot
+ var documents = snapshot.Content.GetAtRoot().ToArray();
+ AssertDocuments(documents, "N1", "N2", "N3", "N10");
+
+ documents = snapshot.Content.GetById(3).Children().ToArray();
+ AssertDocuments(documents);
+
+ Assert.IsNull(snapshot.Content.GetById(10).Parent);
+ }
+
+ [Test]
+ public void MoveFromRootTest()
+ {
+ Init(GetInvariantKits());
+
+ // get snapshot
+ var snapshot = _snapshotService.CreatePublishedSnapshot(previewToken: null);
+ _snapshotAccessor.PublishedSnapshot = snapshot;
+
+ // do some changes
+ var kit = _source.Kits[1];
+ _source.Kits[1] = new ContentNodeKit
+ {
+ ContentTypeId = 2,
+ Node = new ContentNode(kit.Node.Id, Guid.NewGuid(), 1, "-1,3,10,1", 1, 10, DateTime.Now, 0),
+ DraftData = null,
+ PublishedData = new ContentData
+ {
+ Name = kit.PublishedData.Name,
+ Published = true,
+ TemplateId = 0,
+ VersionId = 1,
+ VersionDate = DateTime.Now,
+ WriterId = 0,
+ Properties = new Dictionary(),
+ CultureInfos = new Dictionary()
+ }
+ };
+
+ // notify
+ _snapshotService.Notify(new[] { new ContentCacheRefresher.JsonPayload(1, TreeChangeTypes.RefreshBranch) }, out _, out _);
+
+ // changes that *I* make are immediately visible on the current snapshot
+ var documents = snapshot.Content.GetAtRoot().ToArray();
+ AssertDocuments(documents, "N2", "N3");
+
+ documents = snapshot.Content.GetById(10).Children().ToArray();
+ AssertDocuments(documents, "N1");
+
+ Assert.AreEqual(10, snapshot.Content.GetById(1).Parent?.Id);
+ }
+
+ [Test]
+ public void ReOrderTest()
+ {
+ Init(GetInvariantKits());
+
+ // get snapshot
+ var snapshot = _snapshotService.CreatePublishedSnapshot(previewToken: null);
+ _snapshotAccessor.PublishedSnapshot = snapshot;
+
+ // do some changes
+ var kit = _source.Kits[7];
+ _source.Kits[7] = new ContentNodeKit
+ {
+ ContentTypeId = 2,
+ Node = new ContentNode(kit.Node.Id, Guid.NewGuid(), kit.Node.Level, kit.Node.Path, 1, kit.Node.ParentContentId, DateTime.Now, 0),
+ DraftData = null,
+ PublishedData = new ContentData
+ {
+ Name = kit.PublishedData.Name,
+ Published = true,
+ TemplateId = 0,
+ VersionId = 1,
+ VersionDate = DateTime.Now,
+ WriterId = 0,
+ Properties = new Dictionary(),
+ CultureInfos = new Dictionary()
+ }
+ };
+
+ kit = _source.Kits[8];
+ _source.Kits[8] = new ContentNodeKit
+ {
+ ContentTypeId = 2,
+ Node = new ContentNode(kit.Node.Id, Guid.NewGuid(), kit.Node.Level, kit.Node.Path, 3, kit.Node.ParentContentId, DateTime.Now, 0),
+ DraftData = null,
+ PublishedData = new ContentData
+ {
+ Name = kit.PublishedData.Name,
+ Published = true,
+ TemplateId = 0,
+ VersionId = 1,
+ VersionDate = DateTime.Now,
+ WriterId = 0,
+ Properties = new Dictionary(),
+ CultureInfos = new Dictionary()
+ }
+ };
+
+ kit = _source.Kits[9];
+ _source.Kits[9] = new ContentNodeKit
+ {
+ ContentTypeId = 2,
+ Node = new ContentNode(kit.Node.Id, Guid.NewGuid(), kit.Node.Level, kit.Node.Path, 2, kit.Node.ParentContentId, DateTime.Now, 0),
+ DraftData = null,
+ PublishedData = new ContentData
+ {
+ Name = kit.PublishedData.Name,
+ Published = true,
+ TemplateId = 0,
+ VersionId = 1,
+ VersionDate = DateTime.Now,
+ WriterId = 0,
+ Properties = new Dictionary(),
+ CultureInfos = new Dictionary()
+ }
+ };
+
+ // notify
+ _snapshotService.Notify(new[] { new ContentCacheRefresher.JsonPayload(kit.Node.ParentContentId, TreeChangeTypes.RefreshBranch) }, out _, out _);
+
+ // changes that *I* make are immediately visible on the current snapshot
+ var documents = snapshot.Content.GetById(kit.Node.ParentContentId).Children().ToArray();
+ AssertDocuments(documents, "N7", "N9", "N8");
+ }
+
+ [Test]
+ public void MoveTest()
+ {
+ Init(GetInvariantKits());
+
+ // get snapshot
+ var snapshot = _snapshotService.CreatePublishedSnapshot(previewToken: null);
+ _snapshotAccessor.PublishedSnapshot = snapshot;
+
+ // do some changes
+ var kit = _source.Kits[4];
+ _source.Kits[4] = new ContentNodeKit
+ {
+ ContentTypeId = 2,
+ Node = new ContentNode(kit.Node.Id, Guid.NewGuid(), kit.Node.Level, kit.Node.Path, 2, kit.Node.ParentContentId, DateTime.Now, 0),
+ DraftData = null,
+ PublishedData = new ContentData
+ {
+ Name = kit.PublishedData.Name,
+ Published = true,
+ TemplateId = 0,
+ VersionId = 1,
+ VersionDate = DateTime.Now,
+ WriterId = 0,
+ Properties = new Dictionary(),
+ CultureInfos = new Dictionary()
+ }
+ };
+
+ kit = _source.Kits[5];
+ _source.Kits[5] = new ContentNodeKit
+ {
+ ContentTypeId = 2,
+ Node = new ContentNode(kit.Node.Id, Guid.NewGuid(), kit.Node.Level, kit.Node.Path, 3, kit.Node.ParentContentId, DateTime.Now, 0),
+ DraftData = null,
+ PublishedData = new ContentData
+ {
+ Name = kit.PublishedData.Name,
+ Published = true,
+ TemplateId = 0,
+ VersionId = 1,
+ VersionDate = DateTime.Now,
+ WriterId = 0,
+ Properties = new Dictionary(),
+ CultureInfos = new Dictionary()
+ }
+ };
+
+ kit = _source.Kits[6];
+ _source.Kits[6] = new ContentNodeKit
+ {
+ ContentTypeId = 2,
+ Node = new ContentNode(kit.Node.Id, Guid.NewGuid(), kit.Node.Level, kit.Node.Path, 4, kit.Node.ParentContentId, DateTime.Now, 0),
+ DraftData = null,
+ PublishedData = new ContentData
+ {
+ Name = kit.PublishedData.Name,
+ Published = true,
+ TemplateId = 0,
+ VersionId = 1,
+ VersionDate = DateTime.Now,
+ WriterId = 0,
+ Properties = new Dictionary(),
+ CultureInfos = new Dictionary()
+ }
+ };
+
+ kit = _source.Kits[7];
+ _source.Kits[7] = new ContentNodeKit
+ {
+ ContentTypeId = 2,
+ Node = new ContentNode(kit.Node.Id, Guid.NewGuid(), kit.Node.Level, "-1,1,7", 1, 1, DateTime.Now, 0),
+ DraftData = null,
+ PublishedData = new ContentData
+ {
+ Name = kit.PublishedData.Name,
+ Published = true,
+ TemplateId = 0,
+ VersionId = 1,
+ VersionDate = DateTime.Now,
+ WriterId = 0,
+ Properties = new Dictionary(),
+ CultureInfos = new Dictionary()
+ }
+ };
+
+ // notify
+ _snapshotService.Notify(new[]
+ {
+ // removal must come first
+ new ContentCacheRefresher.JsonPayload(2, TreeChangeTypes.RefreshBranch),
+ new ContentCacheRefresher.JsonPayload(1, TreeChangeTypes.RefreshBranch)
+ }, out _, out _);
+
+ // changes that *I* make are immediately visible on the current snapshot
+ var documents = snapshot.Content.GetById(1).Children().ToArray();
+ AssertDocuments(documents, "N7", "N4", "N5", "N6");
+
+ documents = snapshot.Content.GetById(2).Children().ToArray();
+ AssertDocuments(documents, "N9", "N8");
+
+ Assert.AreEqual(1, snapshot.Content.GetById(7).Parent?.Id);
+ }
+
+ [Test]
+ public void VariantChildrenTest()
+ {
+ Init(GetVariantKits());
+
+ var snapshot = _snapshotService.CreatePublishedSnapshot(previewToken: null);
+ _snapshotAccessor.PublishedSnapshot = snapshot;
+
+ _variationAccesor.VariationContext = new VariationContext("en-US");
+
+ var documents = snapshot.Content.GetAtRoot().ToArray();
+ AssertDocuments(documents, "N1-en-US", "N2-en-US", "N3-en-US");
+
+ documents = snapshot.Content.GetById(1).Children().ToArray();
+ AssertDocuments(documents, "N4-en-US", "N5-en-US", "N6-en-US");
+
+ documents = snapshot.Content.GetById(2).Children().ToArray();
+ AssertDocuments(documents, "N9-en-US", "N8-en-US", "N7-en-US");
+
+ documents = snapshot.Content.GetById(3).Children().ToArray();
+ AssertDocuments(documents, "N10-en-US");
+
+ documents = snapshot.Content.GetById(4).Children().ToArray();
+ AssertDocuments(documents, "N11-en-US", "N12-en-US");
+
+ documents = snapshot.Content.GetById(10).Children().ToArray();
+ AssertDocuments(documents);
+
+
+ _variationAccesor.VariationContext = new VariationContext("fr-FR");
+
+ documents = snapshot.Content.GetAtRoot().ToArray();
+ AssertDocuments(documents, "N1-fr-FR", "N3-fr-FR");
+
+ documents = snapshot.Content.GetById(1).Children().ToArray();
+ AssertDocuments(documents, "N4-fr-FR", "N6-fr-FR");
+
+ documents = snapshot.Content.GetById(2).Children().ToArray();
+ AssertDocuments(documents, "N9-fr-FR", "N7-fr-FR");
+
+ documents = snapshot.Content.GetById(3).Children().ToArray();
+ AssertDocuments(documents, "N10-fr-FR");
+
+ documents = snapshot.Content.GetById(4).Children().ToArray();
+ AssertDocuments(documents, "N12-fr-FR");
+
+ documents = snapshot.Content.GetById(10).Children().ToArray();
+ AssertDocuments(documents);
+
+ documents = snapshot.Content.GetById(1).Children("*").ToArray();
+ AssertDocuments(documents, "N4-fr-FR", null, "N6-fr-FR");
+ AssertDocuments("en-US", documents, "N4-en-US", "N5-en-US", "N6-en-US");
+
+ documents = snapshot.Content.GetById(1).Children("en-US").ToArray();
+ AssertDocuments(documents, "N4-fr-FR", null, "N6-fr-FR");
+ AssertDocuments("en-US", documents, "N4-en-US", "N5-en-US", "N6-en-US");
+
+ documents = snapshot.Content.GetById(1).ChildrenForAllCultures.ToArray();
+ AssertDocuments(documents, "N4-fr-FR", null, "N6-fr-FR");
+ AssertDocuments("en-US", documents, "N4-en-US", "N5-en-US", "N6-en-US");
+
+
+ documents = snapshot.Content.GetAtRoot("*").ToArray();
+ AssertDocuments(documents, "N1-fr-FR", null, "N3-fr-FR");
+
+ documents = snapshot.Content.GetById(1).DescendantsOrSelf().ToArray();
+ AssertDocuments(documents, "N1-fr-FR", "N4-fr-FR", "N12-fr-FR", "N6-fr-FR");
+
+ documents = snapshot.Content.GetById(1).DescendantsOrSelf("*").ToArray();
+ AssertDocuments(documents, "N1-fr-FR", "N4-fr-FR", null /*11*/, "N12-fr-FR", null /*5*/, "N6-fr-FR");
+ }
+
+ [Test]
+ public void RemoveTest()
+ {
+ Init(GetInvariantKits());
+
+ var snapshot = _snapshotService.CreatePublishedSnapshot(previewToken: null);
+ _snapshotAccessor.PublishedSnapshot = snapshot;
+
+ var documents = snapshot.Content.GetAtRoot().ToArray();
+ AssertDocuments(documents, "N1", "N2", "N3");
+
+ documents = snapshot.Content.GetById(1).Children().ToArray();
+ AssertDocuments(documents, "N4", "N5", "N6");
+
+ documents = snapshot.Content.GetById(2).Children().ToArray();
+ AssertDocuments(documents, "N9", "N8", "N7");
+
+ // notify
+ _snapshotService.Notify(new[]
+ {
+ new ContentCacheRefresher.JsonPayload(3, TreeChangeTypes.Remove), // remove last
+ new ContentCacheRefresher.JsonPayload(5, TreeChangeTypes.Remove), // remove middle
+ new ContentCacheRefresher.JsonPayload(9, TreeChangeTypes.Remove), // remove first
+ }, out _, out _);
+
+ documents = snapshot.Content.GetAtRoot().ToArray();
+ AssertDocuments(documents, "N1", "N2");
+
+ documents = snapshot.Content.GetById(1).Children().ToArray();
+ AssertDocuments(documents, "N4", "N6");
+
+ documents = snapshot.Content.GetById(2).Children().ToArray();
+ AssertDocuments(documents, "N8", "N7");
+
+ // notify
+ _snapshotService.Notify(new[]
+ {
+ new ContentCacheRefresher.JsonPayload(1, TreeChangeTypes.Remove), // remove first
+ new ContentCacheRefresher.JsonPayload(8, TreeChangeTypes.Remove), // remove
+ new ContentCacheRefresher.JsonPayload(7, TreeChangeTypes.Remove), // remove
+ }, out _, out _);
+
+ documents = snapshot.Content.GetAtRoot().ToArray();
+ AssertDocuments(documents, "N2");
+
+ documents = snapshot.Content.GetById(2).Children().ToArray();
+ AssertDocuments(documents);
+ }
+
+ [Test]
+ public void UpdateTest()
+ {
+ Init(GetInvariantKits());
+
+ var snapshot = _snapshotService.CreatePublishedSnapshot(previewToken: null);
+ _snapshotAccessor.PublishedSnapshot = snapshot;
+
+ var documents = snapshot.Content.GetAtRoot().ToArray();
+ AssertDocuments(documents, "N1", "N2", "N3");
+
+ documents = snapshot.Content.GetById(1).Children().ToArray();
+ AssertDocuments(documents, "N4", "N5", "N6");
+
+ documents = snapshot.Content.GetById(2).Children().ToArray();
+ AssertDocuments(documents, "N9", "N8", "N7");
+
+ // notify
+ _snapshotService.Notify(new[]
+ {
+ new ContentCacheRefresher.JsonPayload(1, TreeChangeTypes.RefreshBranch),
+ new ContentCacheRefresher.JsonPayload(2, TreeChangeTypes.RefreshNode),
+ }, out _, out _);
+
+ documents = snapshot.Content.GetAtRoot().ToArray();
+ AssertDocuments(documents, "N1", "N2", "N3");
+
+ documents = snapshot.Content.GetById(1).Children().ToArray();
+ AssertDocuments(documents, "N4", "N5", "N6");
+
+ documents = snapshot.Content.GetById(2).Children().ToArray();
+ AssertDocuments(documents, "N9", "N8", "N7");
+ }
+
+ [Test]
+ public void AtRootTest()
+ {
+ Init(GetVariantWithDraftKits());
+
+ var snapshot = _snapshotService.CreatePublishedSnapshot(previewToken: null);
+ _snapshotAccessor.PublishedSnapshot = snapshot;
+
+ _variationAccesor.VariationContext = new VariationContext("en-US");
+
+ // N2 is draft only
+
+ var documents = snapshot.Content.GetAtRoot().ToArray();
+ AssertDocuments(documents, "N1-en-US", /*"N2-en-US",*/ "N3-en-US");
+
+ documents = snapshot.Content.GetAtRoot(true).ToArray();
+ AssertDocuments(documents, "N1-en-US", "N2-en-US", "N3-en-US");
+ }
+
+ private void AssertDocuments(IPublishedContent[] documents, params string[] names)
+ {
+ Assert.AreEqual(names.Length, documents.Length);
+ for (var i = 0; i < names.Length; i++)
+ Assert.AreEqual(names[i], documents[i].Name);
+ }
+
+ private void AssertDocuments(string culture, IPublishedContent[] documents, params string[] names)
+ {
+ Assert.AreEqual(names.Length, documents.Length);
+ for (var i = 0; i < names.Length; i++)
+ Assert.AreEqual(names[i], documents[i].Name(culture));
+ }
+ }
+}
diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs
index ad2b0220bb..b66404c954 100644
--- a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs
+++ b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs
@@ -24,7 +24,6 @@ using Umbraco.Web.Cache;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.PublishedCache.NuCache;
using Umbraco.Web.PublishedCache.NuCache.DataSource;
-using Umbraco.Web.Routing;
namespace Umbraco.Tests.PublishedContent
{
@@ -39,10 +38,18 @@ namespace Umbraco.Tests.PublishedContent
private void Init()
{
Current.Reset();
- Current.UnlockConfigs();
- Current.Configs.Add(SettingsForTests.GenerateMockUmbracoSettings);
- Current.Configs.Add(() => new GlobalSettings());
- var globalSettings = Current.Configs.Global();
+
+ var factory = Mock.Of();
+ Current.Factory = factory;
+
+ var configs = new Configs();
+ Mock.Get(factory).Setup(x => x.GetInstance(typeof(Configs))).Returns(configs);
+ var globalSettings = new GlobalSettings();
+ configs.Add(SettingsForTests.GenerateMockUmbracoSettings);
+ configs.Add(() => globalSettings);
+
+ var publishedModelFactory = new NoopPublishedModelFactory();
+ Mock.Get(factory).Setup(x => x.GetInstance(typeof(IPublishedModelFactory))).Returns(publishedModelFactory);
// create a content node kit
var kit = new ContentNodeKit
@@ -171,7 +178,6 @@ namespace Umbraco.Tests.PublishedContent
null,
new TestPublishedSnapshotAccessor(),
_variationAccesor,
- Mock.Of(),
Mock.Of(),
scopeProvider,
Mock.Of(),
@@ -180,13 +186,14 @@ namespace Umbraco.Tests.PublishedContent
new TestDefaultCultureAccessor(),
dataSource,
globalSettings,
- new SiteDomainHelper(),
Mock.Of(),
Mock.Of(),
new UrlSegmentProviderCollection(new[] { new DefaultUrlSegmentProvider() }));
// invariant is the current default
_variationAccesor.VariationContext = new VariationContext();
+
+ Mock.Get(factory).Setup(x => x.GetInstance(typeof(IVariationContextAccessor))).Returns(_variationAccesor);
}
[Test]
@@ -202,36 +209,34 @@ namespace Umbraco.Tests.PublishedContent
var publishedContent = snapshot.Content.GetById(1);
Assert.IsNotNull(publishedContent);
- Assert.AreEqual("It Works1!", publishedContent.Name);
Assert.AreEqual("val1", publishedContent.Value("prop"));
Assert.AreEqual("val-fr1", publishedContent.Value("prop", "fr-FR"));
Assert.AreEqual("val-uk1", publishedContent.Value("prop", "en-UK"));
- Assert.AreEqual("name-fr1", publishedContent.GetCulture("fr-FR").Name);
- Assert.AreEqual("name-uk1", publishedContent.GetCulture("en-UK").Name);
+ Assert.IsNull(publishedContent.Name()); // no invariant name for varying content
+ Assert.AreEqual("name-fr1", publishedContent.Name("fr-FR"));
+ Assert.AreEqual("name-uk1", publishedContent.Name("en-UK"));
var draftContent = snapshot.Content.GetById(true, 1);
- Assert.AreEqual("It Works2!", draftContent.Name);
Assert.AreEqual("val2", draftContent.Value("prop"));
Assert.AreEqual("val-fr2", draftContent.Value("prop", "fr-FR"));
Assert.AreEqual("val-uk2", draftContent.Value("prop", "en-UK"));
- Assert.AreEqual("name-fr2", draftContent.GetCulture("fr-FR").Name);
- Assert.AreEqual("name-uk2", draftContent.GetCulture("en-UK").Name);
+ Assert.IsNull(draftContent.Name()); // no invariant name for varying content
+ Assert.AreEqual("name-fr2", draftContent.Name("fr-FR"));
+ Assert.AreEqual("name-uk2", draftContent.Name("en-UK"));
// now french is default
_variationAccesor.VariationContext = new VariationContext("fr-FR");
Assert.AreEqual("val-fr1", publishedContent.Value("prop"));
- Assert.AreEqual("name-fr1", publishedContent.GetCulture().Name);
- Assert.AreEqual("name-fr1", publishedContent.Name);
- Assert.AreEqual(new DateTime(2018, 01, 01, 01, 00, 00), publishedContent.GetCulture().Date);
+ Assert.AreEqual("name-fr1", publishedContent.Name());
+ Assert.AreEqual(new DateTime(2018, 01, 01, 01, 00, 00), publishedContent.CultureDate());
// now uk is default
_variationAccesor.VariationContext = new VariationContext("en-UK");
Assert.AreEqual("val-uk1", publishedContent.Value("prop"));
- Assert.AreEqual("name-uk1", publishedContent.GetCulture().Name);
- Assert.AreEqual("name-uk1", publishedContent.Name);
- Assert.AreEqual(new DateTime(2018, 01, 02, 01, 00, 00), publishedContent.GetCulture().Date);
+ Assert.AreEqual("name-uk1", publishedContent.Name());
+ Assert.AreEqual(new DateTime(2018, 01, 02, 01, 00, 00), publishedContent.CultureDate());
// invariant needs to be retrieved explicitly, when it's not default
Assert.AreEqual("val1", publishedContent.Value("prop", culture: ""));
@@ -251,7 +256,7 @@ namespace Umbraco.Tests.PublishedContent
Assert.AreEqual(ContentVariation.Nothing, againContent.ContentType.GetPropertyType("prop").Variations);
// now, "no culture" means "invariant"
- Assert.AreEqual("It Works1!", againContent.Name);
+ Assert.AreEqual("It Works1!", againContent.Name());
Assert.AreEqual("val1", againContent.Value("prop"));
}
diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentDataTableTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentDataTableTests.cs
index 283ed1edd9..cc455b8e5d 100644
--- a/src/Umbraco.Tests/PublishedContent/PublishedContentDataTableTests.cs
+++ b/src/Umbraco.Tests/PublishedContent/PublishedContentDataTableTests.cs
@@ -10,9 +10,9 @@ using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
-using Umbraco.Core.Services;
using Umbraco.Tests.TestHelpers;
using Umbraco.Web;
+using PublishedContentExtensions = Umbraco.Web.PublishedContentExtensions;
namespace Umbraco.Tests.PublishedContent
{
@@ -97,7 +97,7 @@ namespace Umbraco.Tests.PublishedContent
{
var doc = GetContent(true, 1);
//change a doc type alias
- var c = (TestPublishedContent)doc.Children.ElementAt(0);
+ var c = (SolidPublishedContent)doc.Children.ElementAt(0);
c.ContentType = new PublishedContentType(22, "DontMatch", PublishedItemType.Content, Enumerable.Empty(), Enumerable.Empty(), ContentVariation.Nothing);
var dt = doc.ChildrenAsTable(Current.Services, "Child");
@@ -129,7 +129,8 @@ namespace Umbraco.Tests.PublishedContent
var factory = new PublishedContentTypeFactory(Mock.Of(), new PropertyValueConverterCollection(Array.Empty()), dataTypeService);
var contentTypeAlias = createChildren ? "Parent" : "Child";
- var d = new TestPublishedContent
+ var contentType = new PublishedContentType(22, contentTypeAlias, PublishedItemType.Content, Enumerable.Empty(), Enumerable.Empty(), ContentVariation.Nothing);
+ var d = new SolidPublishedContent(contentType)
{
CreateDate = DateTime.Now,
CreatorId = 1,
@@ -140,7 +141,7 @@ namespace Umbraco.Tests.PublishedContent
UpdateDate = DateTime.Now,
Path = "-1,3",
UrlSegment = "home-page",
- Name = "Page" + Guid.NewGuid().ToString(),
+ Name = "Page" + Guid.NewGuid(),
Version = Guid.NewGuid(),
WriterId = 1,
WriterName = "Shannon",
@@ -175,75 +176,7 @@ namespace Umbraco.Tests.PublishedContent
new RawValueProperty(factory.CreatePropertyType("property3", 1), d, "value" + (indexVals + 2)));
}
- d.ContentType = new PublishedContentType(22, contentTypeAlias, PublishedItemType.Content, Enumerable.Empty(), Enumerable.Empty(), ContentVariation.Nothing);
return d;
}
-
- // note - could probably rewrite those tests using SolidPublishedContentCache
- // l8tr...
- private class TestPublishedContent : IPublishedContent
- {
- public string Url { get; set; }
- public string GetUrl(string culture = null) => throw new NotSupportedException();
-
- public PublishedItemType ItemType { get; set; }
-
- IPublishedContent IPublishedContent.Parent
- {
- get { return Parent; }
- }
-
- IEnumerable IPublishedContent.Children
- {
- get { return Children; }
- }
-
- public IPublishedContent Parent { get; set; }
- 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 PublishedCultureInfo GetCulture(string culture = null) => throw new NotSupportedException();
- public IReadOnlyDictionary Cultures => throw new NotSupportedException();
- public string UrlSegment { get; set; }
- public string WriterName { get; set; }
- public string CreatorName { 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 bool IsDraft(string culture = null) => false;
- public bool IsPublished(string culture = null) => true;
-
- public IEnumerable Properties { get; set; }
-
- public IEnumerable Children { get; set; }
-
- public IPublishedProperty GetProperty(string alias)
- {
- return Properties.FirstOrDefault(x => x.Alias.InvariantEquals(alias));
- }
-
- public IPublishedProperty GetProperty(string alias, bool recurse)
- {
- var property = GetProperty(alias);
- if (recurse == false) return property;
-
- IPublishedContent content = this;
- while (content != null && (property == null || property.HasValue() == false))
- {
- content = content.Parent;
- property = content == null ? null : content.GetProperty(alias);
- }
-
- return property;
- }
-
- public PublishedContentType ContentType { get; set; }
- }
}
}
diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentExtensionTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentExtensionTests.cs
index acbad002ee..ced4c012f8 100644
--- a/src/Umbraco.Tests/PublishedContent/PublishedContentExtensionTests.cs
+++ b/src/Umbraco.Tests/PublishedContent/PublishedContentExtensionTests.cs
@@ -27,7 +27,7 @@ namespace Umbraco.Tests.PublishedContent
{
InitializeInheritedContentTypes();
- var publishedContent = _ctx.ContentCache.GetById(1100);
+ var publishedContent = _ctx.Content.GetById(1100);
Assert.That(publishedContent.IsDocumentType("inherited", false));
}
@@ -36,7 +36,7 @@ namespace Umbraco.Tests.PublishedContent
{
InitializeInheritedContentTypes();
- var publishedContent = _ctx.ContentCache.GetById(1100);
+ var publishedContent = _ctx.Content.GetById(1100);
Assert.That(publishedContent.IsDocumentType("base", false), Is.False);
}
@@ -45,7 +45,7 @@ namespace Umbraco.Tests.PublishedContent
{
InitializeInheritedContentTypes();
- var publishedContent = _ctx.ContentCache.GetById(1100);
+ var publishedContent = _ctx.Content.GetById(1100);
Assert.That(publishedContent.IsDocumentType("inherited", true));
}
@@ -55,7 +55,7 @@ namespace Umbraco.Tests.PublishedContent
InitializeInheritedContentTypes();
ContentTypesCache.GetPublishedContentTypeByAlias = null;
- var publishedContent = _ctx.ContentCache.GetById(1100);
+ var publishedContent = _ctx.Content.GetById(1100);
Assert.That(publishedContent.IsDocumentType("base", true));
}
@@ -64,7 +64,7 @@ namespace Umbraco.Tests.PublishedContent
{
InitializeInheritedContentTypes();
- var publishedContent = _ctx.ContentCache.GetById(1100);
+ var publishedContent = _ctx.Content.GetById(1100);
Assert.That(publishedContent.IsDocumentType("invalidbase", true), Is.False);
}
diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentLanguageVariantTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentLanguageVariantTests.cs
index 108bfb9f18..62447742ff 100644
--- a/src/Umbraco.Tests/PublishedContent/PublishedContentLanguageVariantTests.cs
+++ b/src/Umbraco.Tests/PublishedContent/PublishedContentLanguageVariantTests.cs
@@ -65,17 +65,22 @@ namespace Umbraco.Tests.PublishedContent
var welcome2Type = factory.CreatePropertyType("welcomeText2", 1, variations: ContentVariation.Culture);
var nopropType = factory.CreatePropertyType("noprop", 1, variations: ContentVariation.Culture);
- var props = new[]
- {
- prop1Type,
- welcomeType,
- welcome2Type,
- nopropType
- };
- var contentType1 = factory.CreateContentType(1, "ContentType1", Enumerable.Empty(), props);
+ IEnumerable CreatePropertyTypes1(IPublishedContentType contentType)
+ {
+ yield return factory.CreatePropertyType(contentType, "prop1", 1, variations: ContentVariation.Culture);
+ yield return factory.CreatePropertyType(contentType, "welcomeText", 1, variations: ContentVariation.Culture);
+ yield return factory.CreatePropertyType(contentType, "welcomeText2", 1, variations: ContentVariation.Culture);
+ yield return factory.CreatePropertyType(contentType, "noprop", 1, variations: ContentVariation.Culture);
+ }
- var prop3Type = factory.CreatePropertyType("prop3", 1, variations: ContentVariation.Culture);
- var contentType2 = factory.CreateContentType(2, "contentType2", Enumerable.Empty(), new[] { prop3Type });
+ var contentType1 = factory.CreateContentType(1, "ContentType1", Enumerable.Empty(), CreatePropertyTypes1);
+
+ IEnumerable CreatePropertyTypes2(IPublishedContentType contentType)
+ {
+ yield return factory.CreatePropertyType(contentType, "prop3", 1, variations: ContentVariation.Culture);
+ }
+
+ var contentType2 = factory.CreateContentType(2, "contentType2", Enumerable.Empty(), CreatePropertyTypes2);
var prop1 = new SolidPublishedPropertyWithLanguageVariants
{
@@ -150,7 +155,7 @@ namespace Umbraco.Tests.PublishedContent
var prop4 = new SolidPublishedPropertyWithLanguageVariants
{
Alias = "prop3",
- PropertyType = prop3Type
+ PropertyType = contentType2.GetPropertyType("prop3")
};
prop4.SetSourceValue("en-US", "Oxxo", true);
prop4.SetValue("en-US", "Oxxo", true);
@@ -186,7 +191,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void Can_Get_Content_For_Populated_Requested_Language()
{
- var content = Current.UmbracoContext.ContentCache.GetAtRoot().First();
+ var content = Current.UmbracoContext.Content.GetAtRoot().First();
var value = content.Value("welcomeText", "en-US");
Assert.AreEqual("Welcome", value);
}
@@ -194,7 +199,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void Can_Get_Content_For_Populated_Requested_Non_Default_Language()
{
- var content = Current.UmbracoContext.ContentCache.GetAtRoot().First();
+ var content = Current.UmbracoContext.Content.GetAtRoot().First();
var value = content.Value("welcomeText", "de");
Assert.AreEqual("Willkommen", value);
}
@@ -202,7 +207,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void Do_Not_Get_Content_For_Unpopulated_Requested_Language_Without_Fallback()
{
- var content = Current.UmbracoContext.ContentCache.GetAtRoot().First();
+ var content = Current.UmbracoContext.Content.GetAtRoot().First();
var value = content.Value("welcomeText", "fr");
Assert.IsNull(value);
}
@@ -210,7 +215,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void Do_Not_Get_Content_For_Unpopulated_Requested_Language_With_Fallback_Unless_Requested()
{
- var content = Current.UmbracoContext.ContentCache.GetAtRoot().First();
+ var content = Current.UmbracoContext.Content.GetAtRoot().First();
var value = content.Value("welcomeText", "es");
Assert.IsNull(value);
}
@@ -218,7 +223,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void Can_Get_Content_For_Unpopulated_Requested_Language_With_Fallback()
{
- var content = Current.UmbracoContext.ContentCache.GetAtRoot().First();
+ var content = Current.UmbracoContext.Content.GetAtRoot().First();
var value = content.Value("welcomeText", "es", fallback: Fallback.ToLanguage);
Assert.AreEqual("Welcome", value);
}
@@ -226,7 +231,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void Can_Get_Content_For_Unpopulated_Requested_Language_With_Fallback_Over_Two_Levels()
{
- var content = Current.UmbracoContext.ContentCache.GetAtRoot().First();
+ var content = Current.UmbracoContext.Content.GetAtRoot().First();
var value = content.Value("welcomeText", "it", fallback: Fallback.To(Fallback.Language, Fallback.Ancestors));
Assert.AreEqual("Welcome", value);
}
@@ -234,7 +239,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void Do_Not_GetContent_For_Unpopulated_Requested_Language_With_Fallback_Over_That_Loops()
{
- var content = Current.UmbracoContext.ContentCache.GetAtRoot().First();
+ var content = Current.UmbracoContext.Content.GetAtRoot().First();
var value = content.Value("welcomeText", "no", fallback: Fallback.ToLanguage);
Assert.IsNull(value);
}
@@ -242,7 +247,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void Do_Not_Get_Content_Recursively_Unless_Requested()
{
- var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First();
+ var content = Current.UmbracoContext.Content.GetAtRoot().First().Children.First();
var value = content.Value("welcomeText2");
Assert.IsNull(value);
}
@@ -250,7 +255,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void Can_Get_Content_Recursively()
{
- var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First();
+ var content = Current.UmbracoContext.Content.GetAtRoot().First().Children.First();
var value = content.Value("welcomeText2", fallback: Fallback.ToAncestors);
Assert.AreEqual("Welcome", value);
}
@@ -258,7 +263,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void Do_Not_Get_Content_Recursively_Unless_Requested2()
{
- var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First().Children().First();
+ var content = Current.UmbracoContext.Content.GetAtRoot().First().Children.First().Children.First();
Assert.IsNull(content.GetProperty("welcomeText2"));
var value = content.Value("welcomeText2");
Assert.IsNull(value);
@@ -267,7 +272,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void Can_Get_Content_Recursively2()
{
- var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First().Children().First();
+ var content = Current.UmbracoContext.Content.GetAtRoot().First().Children.First().Children.First();
Assert.IsNull(content.GetProperty("welcomeText2"));
var value = content.Value("welcomeText2", fallback: Fallback.ToAncestors);
Assert.AreEqual("Welcome", value);
@@ -276,7 +281,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void Can_Get_Content_Recursively3()
{
- var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First().Children().First();
+ var content = Current.UmbracoContext.Content.GetAtRoot().First().Children.First().Children.First();
Assert.IsNull(content.GetProperty("noprop"));
var value = content.Value("noprop", fallback: Fallback.ToAncestors);
// property has no value but we still get the value (ie, the converter would do something)
@@ -287,7 +292,7 @@ namespace Umbraco.Tests.PublishedContent
public void Can_Get_Content_With_Recursive_Priority()
{
Current.VariationContextAccessor.VariationContext = new VariationContext("nl");
- var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First();
+ var content = Current.UmbracoContext.Content.GetAtRoot().First().Children.First();
var value = content.Value("welcomeText", "nl", fallback: Fallback.To(Fallback.Ancestors, Fallback.Language));
@@ -298,7 +303,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void Can_Get_Content_With_Fallback_Language_Priority()
{
- var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First();
+ var content = Current.UmbracoContext.Content.GetAtRoot().First().Children.First();
var value = content.Value("welcomeText", "nl", fallback: Fallback.ToLanguage);
// No Dutch value is directly assigned. Check has fallen back to English value from language variant.
@@ -308,14 +313,14 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void Throws_For_Non_Supported_Fallback()
{
- var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First();
+ var content = Current.UmbracoContext.Content.GetAtRoot().First().Children.First();
Assert.Throws(() => content.Value("welcomeText", "nl", fallback: Fallback.To(999)));
}
[Test]
public void Can_Fallback_To_Default_Value()
{
- var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First();
+ var content = Current.UmbracoContext.Content.GetAtRoot().First().Children.First();
// no Dutch value is assigned, so getting null
var value = content.Value("welcomeText", "nl");
@@ -333,7 +338,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void Can_Have_Custom_Default_Value()
{
- var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First();
+ var content = Current.UmbracoContext.Content.GetAtRoot().First().Children.First();
// HACK: the value, pretend the converter would return something
var prop = content.GetProperty("welcomeText") as SolidPublishedPropertyWithLanguageVariants;
diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs
index b2f1f311c3..440474ae74 100644
--- a/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs
+++ b/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs
@@ -1,4 +1,5 @@
-using System.Collections.ObjectModel;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
using System.Linq;
using NUnit.Framework;
using Umbraco.Core.Models.PublishedContent;
@@ -15,15 +16,16 @@ namespace Umbraco.Tests.PublishedContent
{
internal override void PopulateCache(PublishedContentTypeFactory factory, SolidPublishedContentCache cache)
{
- var props = new[]
- {
- factory.CreatePropertyType("prop1", 1),
- };
- var contentType1 = factory.CreateContentType(1, "ContentType1", Enumerable.Empty(), props);
- var contentType2 = factory.CreateContentType(2, "ContentType2", Enumerable.Empty(), props);
- var contentType2Sub = factory.CreateContentType(3, "ContentType2Sub", Enumerable.Empty(), props);
+ IEnumerable CreatePropertyTypes(IPublishedContentType contentType)
+ {
+ yield return factory.CreatePropertyType(contentType, "prop1", 1);
+ }
- cache.Add(new SolidPublishedContent(contentType1)
+ var contentType1 = factory.CreateContentType(1, "ContentType1", Enumerable.Empty(), CreatePropertyTypes);
+ var contentType2 = factory.CreateContentType(2, "ContentType2", Enumerable.Empty(), CreatePropertyTypes);
+ var contentType2Sub = factory.CreateContentType(3, "ContentType2Sub", Enumerable.Empty(), CreatePropertyTypes);
+
+ var content = new SolidPublishedContent(contentType1)
{
Id = 1,
SortOrder = 0,
@@ -35,18 +37,19 @@ namespace Umbraco.Tests.PublishedContent
ParentId = -1,
ChildIds = new int[] { },
Properties = new Collection
+ {
+ new SolidPublishedProperty
{
- new SolidPublishedProperty
- {
- Alias = "prop1",
- SolidHasValue = true,
- SolidValue = 1234,
- SolidSourceValue = "1234"
- }
+ Alias = "prop1",
+ SolidHasValue = true,
+ SolidValue = 1234,
+ SolidSourceValue = "1234"
}
- });
+ }
+ };
+ cache.Add(content);
- cache.Add(new SolidPublishedContent(contentType2)
+ content = new SolidPublishedContent(contentType2)
{
Id = 2,
SortOrder = 1,
@@ -58,18 +61,19 @@ namespace Umbraco.Tests.PublishedContent
ParentId = -1,
ChildIds = new int[] { },
Properties = new Collection
+ {
+ new SolidPublishedProperty
{
- new SolidPublishedProperty
- {
- Alias = "prop1",
- SolidHasValue = true,
- SolidValue = 1234,
- SolidSourceValue = "1234"
- }
+ Alias = "prop1",
+ SolidHasValue = true,
+ SolidValue = 1234,
+ SolidSourceValue = "1234"
}
- });
+ }
+ };
+ cache.Add(content);
- cache.Add(new SolidPublishedContent(contentType2Sub)
+ content = new SolidPublishedContent(contentType2Sub)
{
Id = 3,
SortOrder = 2,
@@ -90,20 +94,21 @@ namespace Umbraco.Tests.PublishedContent
SolidSourceValue = "1234"
}
}
- });
+ };
+ cache.Add(content);
}
[Test]
public void First()
{
- var content = Current.UmbracoContext.ContentCache.GetAtRoot().First();
- Assert.AreEqual("Content 1", content.Name);
+ var content = Current.UmbracoContext.Content.GetAtRoot().First();
+ Assert.AreEqual("Content 1", content.Name());
}
[Test]
public void Distinct()
{
- var items = Current.UmbracoContext.ContentCache.GetAtRoot()
+ var items = Current.UmbracoContext.Content.GetAtRoot()
.Distinct()
.Distinct()
.ToIndexedArray();
@@ -127,7 +132,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void OfType1()
{
- var items = Current.UmbracoContext.ContentCache.GetAtRoot()
+ var items = Current.UmbracoContext.Content.GetAtRoot()
.OfType()
.Distinct()
.ToIndexedArray();
@@ -138,7 +143,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void OfType2()
{
- var content = Current.UmbracoContext.ContentCache.GetAtRoot()
+ var content = Current.UmbracoContext.Content.GetAtRoot()
.OfType()
.Distinct()
.ToIndexedArray();
@@ -149,7 +154,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void OfType()
{
- var content = Current.UmbracoContext.ContentCache.GetAtRoot()
+ var content = Current.UmbracoContext.Content.GetAtRoot()
.OfType()
.First(x => x.Prop1 == 1234);
Assert.AreEqual("Content 2", content.Name);
@@ -159,7 +164,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void Position()
{
- var items = Current.UmbracoContext.ContentCache.GetAtRoot()
+ var items = Current.UmbracoContext.Content.GetAtRoot()
.Where(x => x.Value("prop1") == 1234)
.ToIndexedArray();
@@ -174,7 +179,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void Issue()
{
- var content = Current.UmbracoContext.ContentCache.GetAtRoot()
+ var content = Current.UmbracoContext.Content.GetAtRoot()
.Distinct()
.OfType();
@@ -182,12 +187,12 @@ namespace Umbraco.Tests.PublishedContent
var first = where.First();
Assert.AreEqual(1234, first.Prop1);
- var content2 = Current.UmbracoContext.ContentCache.GetAtRoot()
+ var content2 = Current.UmbracoContext.Content.GetAtRoot()
.OfType()
.First(x => x.Prop1 == 1234);
Assert.AreEqual(1234, content2.Prop1);
- var content3 = Current.UmbracoContext.ContentCache.GetAtRoot()
+ var content3 = Current.UmbracoContext.Content.GetAtRoot()
.OfType()
.First();
Assert.AreEqual(1234, content3.Prop1);
diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs
index c5bcd29589..6907f6936c 100644
--- a/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs
+++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs
@@ -1,4 +1,5 @@
-using Umbraco.Core;
+using System.Collections.Generic;
+using Umbraco.Core;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.PropertyEditors.ValueConverters;
@@ -41,13 +42,12 @@ namespace Umbraco.Tests.PublishedContent
var publishedContentTypeFactory = new PublishedContentTypeFactory(Mock.Of(), converters, dataTypeService);
- // need to specify a custom callback for unit tests
- var propertyTypes = new[]
+ IEnumerable CreatePropertyTypes(IPublishedContentType contentType)
{
- // AutoPublishedContentType will auto-generate other properties
- publishedContentTypeFactory.CreatePropertyType("content", 1),
- };
- var type = new AutoPublishedContentType(0, "anything", propertyTypes);
+ yield return publishedContentTypeFactory.CreatePropertyType(contentType, "content", 1);
+ }
+
+ var type = new AutoPublishedContentType(0, "anything", CreatePropertyTypes);
ContentTypesCache.GetPublishedContentTypeByAlias = alias => type;
var umbracoContext = GetUmbracoContext("/test");
diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs
index de641a99a2..f54971a197 100644
--- a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs
+++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
@@ -62,18 +63,19 @@ namespace Umbraco.Tests.PublishedContent
// when they are requested, but we must declare those that we
// explicitely want to be here...
- var propertyTypes = new[]
+ IEnumerable CreatePropertyTypes(IPublishedContentType contentType)
{
// AutoPublishedContentType will auto-generate other properties
- factory.CreatePropertyType("umbracoNaviHide", 1001),
- factory.CreatePropertyType("selectedNodes", 1),
- factory.CreatePropertyType("umbracoUrlAlias", 1),
- factory.CreatePropertyType("content", 1002),
- factory.CreatePropertyType("testRecursive", 1),
- };
+ yield return factory.CreatePropertyType(contentType, "umbracoNaviHide", 1001);
+ yield return factory.CreatePropertyType(contentType, "selectedNodes", 1);
+ yield return factory.CreatePropertyType(contentType, "umbracoUrlAlias", 1);
+ yield return factory.CreatePropertyType(contentType, "content", 1002);
+ yield return factory.CreatePropertyType(contentType, "testRecursive", 1);
+ }
+
var compositionAliases = new[] { "MyCompositionAlias" };
- var anythingType = new AutoPublishedContentType(0, "anything", compositionAliases, propertyTypes);
- var homeType = new AutoPublishedContentType(0, "home", compositionAliases, propertyTypes);
+ var anythingType = new AutoPublishedContentType(0, "anything", compositionAliases, CreatePropertyTypes);
+ var homeType = new AutoPublishedContentType(0, "home", compositionAliases, CreatePropertyTypes);
ContentTypesCache.GetPublishedContentTypeByAlias = alias => alias.InvariantEquals("home") ? homeType : anythingType;
}
@@ -140,7 +142,7 @@ namespace Umbraco.Tests.PublishedContent
internal IPublishedContent GetNode(int id)
{
var ctx = GetUmbracoContext("/test");
- var doc = ctx.ContentCache.GetById(id);
+ var doc = ctx.Content.GetById(id);
Assert.IsNotNull(doc);
return doc;
}
@@ -149,16 +151,16 @@ namespace Umbraco.Tests.PublishedContent
public void GetNodeByIds()
{
var ctx = GetUmbracoContext("/test");
- var contentById = ctx.ContentCache.GetById(1173);
+ var contentById = ctx.Content.GetById(1173);
Assert.IsNotNull(contentById);
- var contentByGuid = ctx.ContentCache.GetById(_node1173Guid);
+ var contentByGuid = ctx.Content.GetById(_node1173Guid);
Assert.IsNotNull(contentByGuid);
Assert.AreEqual(contentById.Id, contentByGuid.Id);
Assert.AreEqual(contentById.Key, contentByGuid.Key);
- contentById = ctx.ContentCache.GetById(666);
+ contentById = ctx.Content.GetById(666);
Assert.IsNull(contentById);
- contentByGuid = ctx.ContentCache.GetById(Guid.NewGuid());
+ contentByGuid = ctx.Content.GetById(Guid.NewGuid());
Assert.IsNull(contentByGuid);
}
@@ -167,7 +169,7 @@ namespace Umbraco.Tests.PublishedContent
{
var doc = GetNode(1173);
- var items = doc.Children.Where(x => x.IsVisible()).ToIndexedArray();
+ var items = doc.Children().Where(x => x.IsVisible()).ToIndexedArray();
foreach (var item in items)
{
@@ -188,7 +190,7 @@ namespace Umbraco.Tests.PublishedContent
var doc = GetNode(1173);
var items = doc
- .Children
+ .Children()
.Where(x => x.IsVisible())
.ToIndexedArray();
@@ -243,7 +245,7 @@ namespace Umbraco.Tests.PublishedContent
var doc = GetNode(1173);
var ct = doc.ContentType;
- var items = doc.Children
+ var items = doc.Children()
.Select(x => x.CreateModel()) // linq, returns IEnumerable
// only way around this is to make sure every IEnumerable extension
@@ -275,7 +277,7 @@ namespace Umbraco.Tests.PublishedContent
{
var doc = GetNode(1173);
- var items = doc.Children.Take(4).ToIndexedArray();
+ var items = doc.Children().Take(4).ToIndexedArray();
foreach (var item in items)
{
@@ -295,7 +297,7 @@ namespace Umbraco.Tests.PublishedContent
{
var doc = GetNode(1173);
- foreach (var d in doc.Children.Skip(1).ToIndexedArray())
+ foreach (var d in doc.Children().Skip(1).ToIndexedArray())
{
if (d.Content.Id != 1176)
{
@@ -313,7 +315,7 @@ namespace Umbraco.Tests.PublishedContent
{
var doc = GetNode(1173);
- var items = doc.Children
+ var items = doc.Children()
.Concat(new[] { GetNode(1175), GetNode(4444) })
.ToIndexedArray();
@@ -398,7 +400,7 @@ namespace Umbraco.Tests.PublishedContent
var doc = GetNode(1046);
- var found1 = doc.Children.GroupBy(x => x.ContentType.Alias).ToArray();
+ var found1 = doc.Children().GroupBy(x => x.ContentType.Alias).ToArray();
Assert.AreEqual(2, found1.Length);
Assert.AreEqual(2, found1.Single(x => x.Key.ToString() == "Home").Count());
@@ -419,8 +421,8 @@ namespace Umbraco.Tests.PublishedContent
var doc = GetNode(1046);
- var found1 = doc.Children.Where(x => x.ContentType.Alias == "CustomDocument");
- var found2 = doc.Children.Where(x => x.ContentType.Alias == "Home");
+ var found1 = doc.Children().Where(x => x.ContentType.Alias == "CustomDocument");
+ var found2 = doc.Children().Where(x => x.ContentType.Alias == "Home");
Assert.AreEqual(1, found1.Count());
Assert.AreEqual(2, found2.Count());
@@ -431,7 +433,7 @@ namespace Umbraco.Tests.PublishedContent
{
var doc = GetNode(1173);
- var ordered = doc.Children.OrderBy(x => x.UpdateDate);
+ var ordered = doc.Children().OrderBy(x => x.UpdateDate);
var correctOrder = new[] { 1178, 1177, 1174, 1176 };
for (var i = 0; i < correctOrder.Length; i++)
@@ -819,7 +821,7 @@ namespace Umbraco.Tests.PublishedContent
var level1_2 = GetNode(1175);
var level1_3 = GetNode(4444);
- _publishedSnapshotAccessorMock.Setup(x => x.PublishedSnapshot.Content.GetAtRoot()).Returns(new []{root});
+ _publishedSnapshotAccessorMock.Setup(x => x.PublishedSnapshot.Content.GetAtRoot(It.IsAny())).Returns(new []{root});
CollectionAssertAreEqual(new []{root}, root.SiblingsAndSelf());
@@ -858,7 +860,7 @@ namespace Umbraco.Tests.PublishedContent
var level1_2 = GetNode(1175);
var level1_3 = GetNode(4444);
- _publishedSnapshotAccessorMock.Setup(x => x.PublishedSnapshot.Content.GetAtRoot()).Returns(new []{root});
+ _publishedSnapshotAccessorMock.Setup(x => x.PublishedSnapshot.Content.GetAtRoot(It.IsAny())).Returns(new []{root});
CollectionAssertAreEqual(new IPublishedContent[0], root.Siblings());
@@ -887,8 +889,13 @@ namespace Umbraco.Tests.PublishedContent
{
var factory = Factory.GetInstance() as PublishedContentTypeFactory;
- var pt = factory.CreatePropertyType("detached", 1003);
- var ct = factory.CreateContentType(0, "alias", new[] { pt });
+ IEnumerable CreatePropertyTypes(IPublishedContentType contentType)
+ {
+ yield return factory.CreatePropertyType(contentType, "detached", 1003);
+ }
+
+ var ct = factory.CreateContentType(0, "alias", CreatePropertyTypes);
+ var pt = ct.GetPropertyType("detached");
var prop = new PublishedElementPropertyBase(pt, null, false, PropertyCacheLevel.None, 5548);
Assert.IsInstanceOf(prop.GetValue());
Assert.AreEqual(5548, prop.GetValue());
@@ -906,16 +913,20 @@ namespace Umbraco.Tests.PublishedContent
{
var factory = Factory.GetInstance() as PublishedContentTypeFactory;
- var pt1 = factory.CreatePropertyType("legend", 1004);
- var pt2 = factory.CreatePropertyType("image", 1005);
- var pt3 = factory.CreatePropertyType("size", 1003);
+ IEnumerable CreatePropertyTypes(IPublishedContentType contentType)
+ {
+ yield return factory.CreatePropertyType(contentType, "legend", 1004);
+ yield return factory.CreatePropertyType(contentType, "image", 1005);
+ yield return factory.CreatePropertyType(contentType, "size", 1003);
+ }
+
const string val1 = "boom bam";
const int val2 = 0;
const int val3 = 666;
var guid = Guid.NewGuid();
- var ct = factory.CreateContentType(0, "alias", new[] { pt1, pt2, pt3 });
+ var ct = factory.CreateContentType(0, "alias", CreatePropertyTypes);
var c = new ImageWithLegendModel(ct, guid, new Dictionary
{
@@ -930,7 +941,7 @@ namespace Umbraco.Tests.PublishedContent
class ImageWithLegendModel : PublishedElement
{
- public ImageWithLegendModel(PublishedContentType contentType, Guid fragmentKey, Dictionary values, bool previewing)
+ public ImageWithLegendModel(IPublishedContentType contentType, Guid fragmentKey, Dictionary values, bool previewing)
: base(contentType, fragmentKey, values, previewing)
{ }
diff --git a/src/Umbraco.Tests/PublishedContent/RootNodeTests.cs b/src/Umbraco.Tests/PublishedContent/RootNodeTests.cs
index 77eab1dbb7..4aad3d0acb 100644
--- a/src/Umbraco.Tests/PublishedContent/RootNodeTests.cs
+++ b/src/Umbraco.Tests/PublishedContent/RootNodeTests.cs
@@ -13,17 +13,17 @@ namespace Umbraco.Tests.PublishedContent
var ctx = GetUmbracoContext("/test");
// there is no content node with ID -1
- var content = ctx.ContentCache.GetById(-1);
+ var content = ctx.Content.GetById(-1);
Assert.IsNull(content);
// content at root has null parent
- content = ctx.ContentCache.GetById(1046);
+ content = ctx.Content.GetById(1046);
Assert.IsNotNull(content);
Assert.AreEqual(1, content.Level);
Assert.IsNull(content.Parent);
// non-existing content is null
- content = ctx.ContentCache.GetById(666);
+ content = ctx.Content.GetById(666);
Assert.IsNull(content);
}
diff --git a/src/Umbraco.Tests/PublishedContent/SolidPublishedSnapshot.cs b/src/Umbraco.Tests/PublishedContent/SolidPublishedSnapshot.cs
index 9828a14597..860b9b9179 100644
--- a/src/Umbraco.Tests/PublishedContent/SolidPublishedSnapshot.cs
+++ b/src/Umbraco.Tests/PublishedContent/SolidPublishedSnapshot.cs
@@ -100,7 +100,7 @@ namespace Umbraco.Tests.PublishedContent
return _content.ContainsKey(contentId);
}
- public override IEnumerable GetAtRoot(bool preview)
+ public override IEnumerable GetAtRoot(bool preview, string culture = null)
{
return _content.Values.Where(x => x.Parent == null);
}
@@ -140,27 +140,27 @@ namespace Umbraco.Tests.PublishedContent
return _content.Count > 0;
}
- public override PublishedContentType GetContentType(int id)
+ public override IPublishedContentType GetContentType(int id)
{
throw new NotImplementedException();
}
- public override PublishedContentType GetContentType(string alias)
+ public override IPublishedContentType GetContentType(string alias)
{
throw new NotImplementedException();
}
- public override IEnumerable GetByContentType(PublishedContentType contentType)
+ public override IEnumerable GetByContentType(IPublishedContentType contentType)
{
throw new NotImplementedException();
}
}
- class SolidPublishedContent : IPublishedContent
+ internal class SolidPublishedContent : IPublishedContent
{
#region Constructor
- public SolidPublishedContent(PublishedContentType contentType)
+ public SolidPublishedContent(IPublishedContentType contentType)
{
// initialize boring stuff
TemplateId = 0;
@@ -176,13 +176,19 @@ namespace Umbraco.Tests.PublishedContent
#region Content
+ private Dictionary _cultures;
+
+ private Dictionary GetCultures()
+ {
+ return new Dictionary { { "", new PublishedCultureInfo("", 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 PublishedCultureInfo GetCulture(string culture = null) => throw new NotSupportedException();
- public IReadOnlyDictionary Cultures => throw new NotSupportedException();
+ public IReadOnlyDictionary Cultures => _cultures ?? (_cultures = GetCultures());
public string UrlSegment { get; set; }
public string WriterName { get; set; }
public string CreatorName { get; set; }
@@ -194,9 +200,8 @@ namespace Umbraco.Tests.PublishedContent
public Guid Version { get; set; }
public int Level { get; set; }
public string Url { get; set; }
- public string GetUrl(string culture = null) => throw new NotSupportedException();
- public PublishedItemType ItemType { get { return PublishedItemType.Content; } }
+ public PublishedItemType ItemType => PublishedItemType.Content;
public bool IsDraft(string culture = null) => false;
public bool IsPublished(string culture = null) => true;
@@ -209,12 +214,13 @@ namespace Umbraco.Tests.PublishedContent
public IPublishedContent Parent { get; set; }
public IEnumerable Children { get; set; }
+ public IEnumerable ChildrenForAllCultures => Children;
#endregion
#region ContentType
- public PublishedContentType ContentType { get; private set; }
+ public IPublishedContentType ContentType { get; set; }
#endregion
@@ -236,7 +242,7 @@ namespace Umbraco.Tests.PublishedContent
while (content != null && (property == null || property.HasValue() == false))
{
content = content.Parent;
- property = content == null ? null : content.GetProperty(alias);
+ property = content?.GetProperty(alias);
}
return property;
@@ -256,7 +262,7 @@ namespace Umbraco.Tests.PublishedContent
internal class SolidPublishedProperty : IPublishedProperty
{
- public PublishedPropertyType PropertyType { get; set; }
+ public IPublishedPropertyType PropertyType { get; set; }
public string Alias { get; set; }
public object SolidSourceValue { get; set; }
public object SolidValue { get; set; }
@@ -400,7 +406,7 @@ namespace Umbraco.Tests.PublishedContent
class AutoPublishedContentType : PublishedContentType
{
- private static readonly PublishedPropertyType Default;
+ private static readonly IPublishedPropertyType Default;
static AutoPublishedContentType()
{
@@ -415,11 +421,19 @@ namespace Umbraco.Tests.PublishedContent
: base(id, alias, PublishedItemType.Content, Enumerable.Empty(), propertyTypes, ContentVariation.Nothing)
{ }
+ public AutoPublishedContentType(int id, string alias, Func> propertyTypes)
+ : base(id, alias, PublishedItemType.Content, Enumerable.Empty(), propertyTypes, ContentVariation.Nothing)
+ { }
+
public AutoPublishedContentType(int id, string alias, IEnumerable compositionAliases, IEnumerable