Code cleanup - removing all internal code related to Macros, which was created for v6 but left out for backwards compatibility.
This commit is contained in:
@@ -223,9 +223,6 @@ namespace Umbraco.Core
|
||||
ActionsResolver.Current = new ActionsResolver(
|
||||
() => PluginManager.Current.ResolveActions());
|
||||
|
||||
MacroPropertyTypeResolver.Current = new MacroPropertyTypeResolver(
|
||||
PluginManager.Current.ResolveMacroPropertyTypes());
|
||||
|
||||
//the database migration objects
|
||||
MigrationResolver.Current = new MigrationResolver(
|
||||
() => PluginManager.Current.ResolveMigrationTypes());
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// A resolver to return all <see cref="IMacroPropertyType"/> objects
|
||||
/// </summary>
|
||||
internal sealed class MacroPropertyTypeResolver : ManyObjectsResolverBase<MacroPropertyTypeResolver, IMacroPropertyType>
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="macroPropertyTypes"></param>
|
||||
internal MacroPropertyTypeResolver(IEnumerable<Type> macroPropertyTypes)
|
||||
: base(macroPropertyTypes)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IMacroPropertyType"/> implementations.
|
||||
/// </summary>
|
||||
public IEnumerable<IMacroPropertyType> MacroPropertyTypes
|
||||
{
|
||||
get
|
||||
{
|
||||
return Values;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Macros.PropertyTypes
|
||||
{
|
||||
internal class ContentAll : IMacroPropertyType
|
||||
{
|
||||
public string Alias
|
||||
{
|
||||
get { return "contentAll"; }
|
||||
}
|
||||
|
||||
public string RenderingAssembly
|
||||
{
|
||||
get { return "umbraco.macroRenderings"; }
|
||||
}
|
||||
|
||||
public string RenderingType
|
||||
{
|
||||
get { return "content"; }
|
||||
}
|
||||
|
||||
public MacroPropertyTypeBaseTypes BaseType
|
||||
{
|
||||
get { return MacroPropertyTypeBaseTypes.Int32; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Macros.PropertyTypes
|
||||
{
|
||||
internal class ContentPicker : IMacroPropertyType
|
||||
{
|
||||
public string Alias
|
||||
{
|
||||
get { return "contentPicker"; }
|
||||
}
|
||||
|
||||
public string RenderingAssembly
|
||||
{
|
||||
get { return "umbraco.macroRenderings"; }
|
||||
}
|
||||
|
||||
public string RenderingType
|
||||
{
|
||||
get { return "content"; }
|
||||
}
|
||||
|
||||
public MacroPropertyTypeBaseTypes BaseType
|
||||
{
|
||||
get { return MacroPropertyTypeBaseTypes.Int32; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Macros.PropertyTypes
|
||||
{
|
||||
internal class ContentRandom : IMacroPropertyType
|
||||
{
|
||||
public string Alias
|
||||
{
|
||||
get { return "contentRandom"; }
|
||||
}
|
||||
|
||||
public string RenderingAssembly
|
||||
{
|
||||
get { return "umbraco.macroRenderings"; }
|
||||
}
|
||||
|
||||
public string RenderingType
|
||||
{
|
||||
get { return "content"; }
|
||||
}
|
||||
|
||||
public MacroPropertyTypeBaseTypes BaseType
|
||||
{
|
||||
get { return MacroPropertyTypeBaseTypes.Int32; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Macros.PropertyTypes
|
||||
{
|
||||
internal class ContentStubs : IMacroPropertyType
|
||||
{
|
||||
public string Alias
|
||||
{
|
||||
get { return "contentStubs"; }
|
||||
}
|
||||
|
||||
public string RenderingAssembly
|
||||
{
|
||||
get { return "umbraco.macroRenderings"; }
|
||||
}
|
||||
|
||||
public string RenderingType
|
||||
{
|
||||
get { return "content"; }
|
||||
}
|
||||
|
||||
public MacroPropertyTypeBaseTypes BaseType
|
||||
{
|
||||
get { return MacroPropertyTypeBaseTypes.Int32; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Macros.PropertyTypes
|
||||
{
|
||||
internal class ContentTree : IMacroPropertyType
|
||||
{
|
||||
public string Alias
|
||||
{
|
||||
get { return "contentTree"; }
|
||||
}
|
||||
|
||||
public string RenderingAssembly
|
||||
{
|
||||
get { return "umbraco.macroRenderings"; }
|
||||
}
|
||||
|
||||
public string RenderingType
|
||||
{
|
||||
get { return "content"; }
|
||||
}
|
||||
|
||||
public MacroPropertyTypeBaseTypes BaseType
|
||||
{
|
||||
get { return MacroPropertyTypeBaseTypes.Int32; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Macros.PropertyTypes
|
||||
{
|
||||
internal class ContentType : IMacroPropertyType
|
||||
{
|
||||
public string Alias
|
||||
{
|
||||
get { return "contentType"; }
|
||||
}
|
||||
|
||||
public string RenderingAssembly
|
||||
{
|
||||
get { return "umbraco.macroRenderings"; }
|
||||
}
|
||||
|
||||
public string RenderingType
|
||||
{
|
||||
get { return "contentTypeSingle"; }
|
||||
}
|
||||
|
||||
public MacroPropertyTypeBaseTypes BaseType
|
||||
{
|
||||
get { return MacroPropertyTypeBaseTypes.Int32; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Macros.PropertyTypes
|
||||
{
|
||||
internal class ContentTypeMultiple : IMacroPropertyType
|
||||
{
|
||||
public string Alias
|
||||
{
|
||||
get { return "contentTypeMultiple"; }
|
||||
}
|
||||
|
||||
public string RenderingAssembly
|
||||
{
|
||||
get { return "umbraco.macroRenderings"; }
|
||||
}
|
||||
|
||||
public string RenderingType
|
||||
{
|
||||
get { return "contentTypeMultiple"; }
|
||||
}
|
||||
|
||||
public MacroPropertyTypeBaseTypes BaseType
|
||||
{
|
||||
get { return MacroPropertyTypeBaseTypes.Int32; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Macros.PropertyTypes
|
||||
{
|
||||
internal class MediaCurrent : IMacroPropertyType
|
||||
{
|
||||
public string Alias
|
||||
{
|
||||
get { return "mediaCurrent"; }
|
||||
}
|
||||
|
||||
public string RenderingAssembly
|
||||
{
|
||||
get { return "umbraco.macroRenderings"; }
|
||||
}
|
||||
|
||||
public string RenderingType
|
||||
{
|
||||
get { return "media"; }
|
||||
}
|
||||
|
||||
public MacroPropertyTypeBaseTypes BaseType
|
||||
{
|
||||
get { return MacroPropertyTypeBaseTypes.Int32; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Macros.PropertyTypes
|
||||
{
|
||||
internal class Number : IMacroPropertyType
|
||||
{
|
||||
public string Alias
|
||||
{
|
||||
get { return "number"; }
|
||||
}
|
||||
|
||||
public string RenderingAssembly
|
||||
{
|
||||
get { return "umbraco.macroRenderings"; }
|
||||
}
|
||||
|
||||
public string RenderingType
|
||||
{
|
||||
get { return "numeric"; }
|
||||
}
|
||||
|
||||
public MacroPropertyTypeBaseTypes BaseType
|
||||
{
|
||||
get { return MacroPropertyTypeBaseTypes.Int32; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Macros.PropertyTypes
|
||||
{
|
||||
internal class PropertyTypePicker : IMacroPropertyType
|
||||
{
|
||||
public string Alias
|
||||
{
|
||||
get { return "propertyTypePicker"; }
|
||||
}
|
||||
|
||||
public string RenderingAssembly
|
||||
{
|
||||
get { return "umbraco.macroRenderings"; }
|
||||
}
|
||||
|
||||
public string RenderingType
|
||||
{
|
||||
get { return "propertyTypePicker"; }
|
||||
}
|
||||
|
||||
public MacroPropertyTypeBaseTypes BaseType
|
||||
{
|
||||
get { return MacroPropertyTypeBaseTypes.String; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Macros.PropertyTypes
|
||||
{
|
||||
internal class PropertyTypePickerMultiple : IMacroPropertyType
|
||||
{
|
||||
public string Alias
|
||||
{
|
||||
get { return "propertyTypePickerMultiple"; }
|
||||
}
|
||||
|
||||
public string RenderingAssembly
|
||||
{
|
||||
get { return "umbraco.macroRenderings"; }
|
||||
}
|
||||
|
||||
public string RenderingType
|
||||
{
|
||||
get { return "propertyTypePickerMultiple"; }
|
||||
}
|
||||
|
||||
public MacroPropertyTypeBaseTypes BaseType
|
||||
{
|
||||
get { return MacroPropertyTypeBaseTypes.String; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Macros.PropertyTypes
|
||||
{
|
||||
internal class TabPicker : IMacroPropertyType
|
||||
{
|
||||
public string Alias
|
||||
{
|
||||
get { return "tabPicker"; }
|
||||
}
|
||||
|
||||
public string RenderingAssembly
|
||||
{
|
||||
get { return "umbraco.macroRenderings"; }
|
||||
}
|
||||
|
||||
public string RenderingType
|
||||
{
|
||||
get { return "tabPicker"; }
|
||||
}
|
||||
|
||||
public MacroPropertyTypeBaseTypes BaseType
|
||||
{
|
||||
get { return MacroPropertyTypeBaseTypes.String; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Macros.PropertyTypes
|
||||
{
|
||||
internal class TabPickerMultiple : IMacroPropertyType
|
||||
{
|
||||
public string Alias
|
||||
{
|
||||
get { return "tabPickerMultiple"; }
|
||||
}
|
||||
|
||||
public string RenderingAssembly
|
||||
{
|
||||
get { return "umbraco.macroRenderings"; }
|
||||
}
|
||||
|
||||
public string RenderingType
|
||||
{
|
||||
get { return "tabPickerMultiple"; }
|
||||
}
|
||||
|
||||
public MacroPropertyTypeBaseTypes BaseType
|
||||
{
|
||||
get { return MacroPropertyTypeBaseTypes.String; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Macros.PropertyTypes
|
||||
{
|
||||
internal class Text : IMacroPropertyType
|
||||
{
|
||||
public string Alias
|
||||
{
|
||||
get { return "text"; }
|
||||
}
|
||||
|
||||
public string RenderingAssembly
|
||||
{
|
||||
get { return "umbraco.macroRenderings"; }
|
||||
}
|
||||
|
||||
public string RenderingType
|
||||
{
|
||||
get { return "text"; }
|
||||
}
|
||||
|
||||
public MacroPropertyTypeBaseTypes BaseType
|
||||
{
|
||||
get { return MacroPropertyTypeBaseTypes.String; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Macros.PropertyTypes
|
||||
{
|
||||
internal class TextMultiLine : IMacroPropertyType
|
||||
{
|
||||
public string Alias
|
||||
{
|
||||
get { return "textMultiLine"; }
|
||||
}
|
||||
|
||||
public string RenderingAssembly
|
||||
{
|
||||
get { return "umbraco.macroRenderings"; }
|
||||
}
|
||||
|
||||
public string RenderingType
|
||||
{
|
||||
get { return "textMultiple"; }
|
||||
}
|
||||
|
||||
public MacroPropertyTypeBaseTypes BaseType
|
||||
{
|
||||
get { return MacroPropertyTypeBaseTypes.String; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Macros.PropertyTypes
|
||||
{
|
||||
internal class YesNoBool : IMacroPropertyType
|
||||
{
|
||||
public string Alias
|
||||
{
|
||||
get { return "bool"; }
|
||||
}
|
||||
|
||||
public string RenderingAssembly
|
||||
{
|
||||
get { return "umbraco.macroRenderings"; }
|
||||
}
|
||||
|
||||
public string RenderingType
|
||||
{
|
||||
get { return "yesNo"; }
|
||||
}
|
||||
|
||||
public MacroPropertyTypeBaseTypes BaseType
|
||||
{
|
||||
get { return MacroPropertyTypeBaseTypes.Boolean; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a Macro
|
||||
/// </summary>
|
||||
internal interface IMacro : IAggregateRoot
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the alias of the Macro
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
string Alias { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the Macro
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a boolean indicating whether the Macro can be used in an Editor
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
bool UseInEditor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Cache Duration for the Macro
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
int CacheDuration { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a boolean indicating whether the Macro should be Cached by Page
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
bool CacheByPage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a boolean indicating whether the Macro should be Cached Personally
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
bool CacheByMember { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a boolean indicating whether the Macro should be rendered in an Editor
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
bool DontRender { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path to the script file in use
|
||||
/// </summary>
|
||||
/// <remarks>Optional: Can only be one of three Script, Python or Xslt</remarks>
|
||||
[DataMember]
|
||||
string ScriptFile { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the assembly, which should be used by the Macro
|
||||
/// </summary>
|
||||
/// <remarks>Will usually only be filled if the ScriptFile is a Usercontrol</remarks>
|
||||
[DataMember]
|
||||
string ScriptAssembly { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or set the path to the Python file in use
|
||||
/// </summary>
|
||||
/// <remarks>Optional: Can only be one of three Script, Python or Xslt</remarks>
|
||||
[DataMember]
|
||||
string Python { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path to the Xslt file in use
|
||||
/// </summary>
|
||||
/// <remarks>Optional: Can only be one of three Script, Python or Xslt</remarks>
|
||||
[DataMember]
|
||||
string Xslt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a list of Macro Properties
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
List<IMacroProperty> Properties { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enum <see cref="MacroTypes"/> based on the properties on the Macro
|
||||
/// </summary>
|
||||
/// <returns><see cref="MacroTypes"/></returns>
|
||||
MacroTypes MacroType();
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
using System.Runtime.Serialization;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a Property for a Macro
|
||||
/// </summary>
|
||||
internal interface IMacroProperty : IValueObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the Alias of the Property
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
string Alias { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Name of the Property
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Sort Order of the Property
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
int SortOrder { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Type for this Property
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The MacroPropertyTypes acts as a plugin for Macros.
|
||||
/// All types was previously contained in the database, but has been ported to code.
|
||||
/// </remarks>
|
||||
[DataMember]
|
||||
IMacroPropertyType PropertyType { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a PropertyType (plugin) for a Macro
|
||||
/// </summary>
|
||||
internal interface IMacroPropertyType
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the unique Alias of the Property Type
|
||||
/// </summary>
|
||||
string Alias { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the Assembly used to render the Property Type
|
||||
/// </summary>
|
||||
string RenderingAssembly { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the Type used to render the Property Type
|
||||
/// </summary>
|
||||
string RenderingType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Base Type for storing the PropertyType (Int32, String, Boolean)
|
||||
/// </summary>
|
||||
MacroPropertyTypeBaseTypes BaseType { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,290 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a Macro
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[DataContract(IsReference = true)]
|
||||
internal class Macro : Entity, IMacro
|
||||
{
|
||||
private string _alias;
|
||||
private string _name;
|
||||
private bool _useInEditor;
|
||||
private int _cacheDuration;
|
||||
private bool _cacheByPage;
|
||||
private bool _cacheByMember;
|
||||
private bool _dontRender;
|
||||
private string _scriptFile;
|
||||
private string _scriptAssembly;
|
||||
private string _python;
|
||||
private string _xslt;
|
||||
private List<IMacroProperty> _properties;
|
||||
|
||||
private static readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo<Macro, string>(x => x.Alias);
|
||||
private static readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo<Macro, string>(x => x.Name);
|
||||
private static readonly PropertyInfo UseInEditorSelector = ExpressionHelper.GetPropertyInfo<Macro, bool>(x => x.UseInEditor);
|
||||
private static readonly PropertyInfo CacheDurationSelector = ExpressionHelper.GetPropertyInfo<Macro, int>(x => x.CacheDuration);
|
||||
private static readonly PropertyInfo CacheByPageSelector = ExpressionHelper.GetPropertyInfo<Macro, bool>(x => x.CacheByPage);
|
||||
private static readonly PropertyInfo CacheByMemberSelector = ExpressionHelper.GetPropertyInfo<Macro, bool>(x => x.CacheByMember);
|
||||
private static readonly PropertyInfo DontRenderSelector = ExpressionHelper.GetPropertyInfo<Macro, bool>(x => x.DontRender);
|
||||
private static readonly PropertyInfo ScriptFileSelector = ExpressionHelper.GetPropertyInfo<Macro, string>(x => x.ScriptFile);
|
||||
private static readonly PropertyInfo ScriptAssemblySelector = ExpressionHelper.GetPropertyInfo<Macro, string>(x => x.ScriptAssembly);
|
||||
private static readonly PropertyInfo PythonSelector = ExpressionHelper.GetPropertyInfo<Macro, string>(x => x.Python);
|
||||
private static readonly PropertyInfo XsltSelector = ExpressionHelper.GetPropertyInfo<Macro, string>(x => x.Xslt);
|
||||
private static readonly PropertyInfo PropertiesSelector = ExpressionHelper.GetPropertyInfo<Macro, List<IMacroProperty>>(x => x.Properties);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the alias of the Macro
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public string Alias
|
||||
{
|
||||
get { return _alias; }
|
||||
set
|
||||
{
|
||||
SetPropertyValueAndDetectChanges(o =>
|
||||
{
|
||||
_alias = value;
|
||||
return _alias;
|
||||
}, _alias, AliasSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the Macro
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set
|
||||
{
|
||||
SetPropertyValueAndDetectChanges(o =>
|
||||
{
|
||||
_name = value;
|
||||
return _name;
|
||||
}, _name, NameSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a boolean indicating whether the Macro can be used in an Editor
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public bool UseInEditor
|
||||
{
|
||||
get { return _useInEditor; }
|
||||
set
|
||||
{
|
||||
SetPropertyValueAndDetectChanges(o =>
|
||||
{
|
||||
_useInEditor = value;
|
||||
return _useInEditor;
|
||||
}, _useInEditor, UseInEditorSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Cache Duration for the Macro
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public int CacheDuration
|
||||
{
|
||||
get { return _cacheDuration; }
|
||||
set
|
||||
{
|
||||
SetPropertyValueAndDetectChanges(o =>
|
||||
{
|
||||
_cacheDuration = value;
|
||||
return _cacheDuration;
|
||||
}, _cacheDuration, CacheDurationSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a boolean indicating whether the Macro should be Cached by Page
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public bool CacheByPage
|
||||
{
|
||||
get { return _cacheByPage; }
|
||||
set
|
||||
{
|
||||
SetPropertyValueAndDetectChanges(o =>
|
||||
{
|
||||
_cacheByPage = value;
|
||||
return _cacheByPage;
|
||||
}, _cacheByPage, CacheByPageSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a boolean indicating whether the Macro should be Cached Personally
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public bool CacheByMember
|
||||
{
|
||||
get { return _cacheByMember; }
|
||||
set
|
||||
{
|
||||
SetPropertyValueAndDetectChanges(o =>
|
||||
{
|
||||
_cacheByMember = value;
|
||||
return _cacheByMember;
|
||||
}, _cacheByMember, CacheByMemberSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a boolean indicating whether the Macro should be rendered in an Editor
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public bool DontRender
|
||||
{
|
||||
get { return _dontRender; }
|
||||
set
|
||||
{
|
||||
SetPropertyValueAndDetectChanges(o =>
|
||||
{
|
||||
_dontRender = value;
|
||||
return _dontRender;
|
||||
}, _dontRender, DontRenderSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path to the script file in use
|
||||
/// </summary>
|
||||
/// <remarks>Optional: Can only be one of three Script, Python or Xslt</remarks>
|
||||
[DataMember]
|
||||
public string ScriptFile
|
||||
{
|
||||
get { return _scriptFile; }
|
||||
set
|
||||
{
|
||||
SetPropertyValueAndDetectChanges(o =>
|
||||
{
|
||||
_scriptFile = value;
|
||||
return _scriptFile;
|
||||
}, _scriptFile, ScriptFileSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the assembly, which should be used by the Macro
|
||||
/// </summary>
|
||||
/// <remarks>Will usually only be filled if the ScriptFile is a Usercontrol</remarks>
|
||||
[DataMember]
|
||||
public string ScriptAssembly
|
||||
{
|
||||
get { return _scriptAssembly; }
|
||||
set
|
||||
{
|
||||
SetPropertyValueAndDetectChanges(o =>
|
||||
{
|
||||
_scriptAssembly = value;
|
||||
return _scriptAssembly;
|
||||
}, _scriptAssembly, ScriptAssemblySelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or set the path to the Python file in use
|
||||
/// </summary>
|
||||
/// <remarks>Optional: Can only be one of three Script, Python or Xslt</remarks>
|
||||
[DataMember]
|
||||
public string Python
|
||||
{
|
||||
get { return _python; }
|
||||
set
|
||||
{
|
||||
SetPropertyValueAndDetectChanges(o =>
|
||||
{
|
||||
_python = value;
|
||||
return _python;
|
||||
}, _python, PythonSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path to the Xslt file in use
|
||||
/// </summary>
|
||||
/// <remarks>Optional: Can only be one of three Script, Python or Xslt</remarks>
|
||||
[DataMember]
|
||||
public string Xslt
|
||||
{
|
||||
get { return _xslt; }
|
||||
set
|
||||
{
|
||||
SetPropertyValueAndDetectChanges(o =>
|
||||
{
|
||||
_xslt = value;
|
||||
return _xslt;
|
||||
}, _xslt, XsltSelector);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: This needs to be changed to a custom collection class so we can track the dirtyness of each property!
|
||||
/// <summary>
|
||||
/// Gets or sets a list of Macro Properties
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public List<IMacroProperty> Properties
|
||||
{
|
||||
get { return _properties; }
|
||||
set
|
||||
{
|
||||
SetPropertyValueAndDetectChanges(o =>
|
||||
{
|
||||
_properties = value;
|
||||
return _properties;
|
||||
}, _properties, PropertiesSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overridden this method in order to set a random Id
|
||||
/// </summary>
|
||||
internal override void AddingEntity()
|
||||
{
|
||||
base.AddingEntity();
|
||||
|
||||
var random = new Random();
|
||||
Id = random.Next(10000, int.MaxValue);
|
||||
|
||||
Key = Alias.EncodeAsGuid();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enum <see cref="MacroTypes"/> based on the properties on the Macro
|
||||
/// </summary>
|
||||
/// <returns><see cref="MacroTypes"/></returns>
|
||||
public MacroTypes MacroType()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Xslt))
|
||||
return MacroTypes.Xslt;
|
||||
|
||||
if (!string.IsNullOrEmpty(Python))
|
||||
return MacroTypes.Python;
|
||||
|
||||
if (!string.IsNullOrEmpty(ScriptFile))
|
||||
return MacroTypes.Script;
|
||||
|
||||
if (!string.IsNullOrEmpty(ScriptFile) && ScriptFile.ToLower().IndexOf(".ascx", StringComparison.InvariantCultureIgnoreCase) > -1)
|
||||
{
|
||||
return MacroTypes.UserControl;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(ScriptFile) && !string.IsNullOrEmpty(ScriptAssembly))
|
||||
return MacroTypes.CustomControl;
|
||||
|
||||
return MacroTypes.Unknown;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a Macro Property
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[DataContract(IsReference = true)]
|
||||
internal class MacroProperty : TracksChangesEntityBase, IMacroProperty, IRememberBeingDirty
|
||||
{
|
||||
private string _alias;
|
||||
private string _name;
|
||||
private int _sortOrder;
|
||||
private IMacroPropertyType _propertyType;
|
||||
|
||||
private static readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo<MacroProperty, string>(x => x.Alias);
|
||||
private static readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo<MacroProperty, string>(x => x.Name);
|
||||
private static readonly PropertyInfo SortOrderSelector = ExpressionHelper.GetPropertyInfo<MacroProperty, int>(x => x.SortOrder);
|
||||
private static readonly PropertyInfo PropertyTypeSelector = ExpressionHelper.GetPropertyInfo<MacroProperty, IMacroPropertyType>(x => x.PropertyType);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Alias of the Property
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public string Alias
|
||||
{
|
||||
get { return _alias; }
|
||||
set
|
||||
{
|
||||
SetPropertyValueAndDetectChanges(o =>
|
||||
{
|
||||
_alias = value;
|
||||
return _alias;
|
||||
}, _alias, AliasSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Name of the Property
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set
|
||||
{
|
||||
SetPropertyValueAndDetectChanges(o =>
|
||||
{
|
||||
_name = value;
|
||||
return _name;
|
||||
}, _name, NameSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Sort Order of the Property
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public int SortOrder
|
||||
{
|
||||
get { return _sortOrder; }
|
||||
set
|
||||
{
|
||||
SetPropertyValueAndDetectChanges(o =>
|
||||
{
|
||||
_sortOrder = value;
|
||||
return _sortOrder;
|
||||
}, _sortOrder, SortOrderSelector);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Type for this Property
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The MacroPropertyTypes acts as a plugin for Macros.
|
||||
/// All types was previously contained in the database, but has been ported to code.
|
||||
/// </remarks>
|
||||
[DataMember]
|
||||
public IMacroPropertyType PropertyType
|
||||
|
||||
{
|
||||
get { return _propertyType; }
|
||||
set
|
||||
{
|
||||
SetPropertyValueAndDetectChanges(o =>
|
||||
{
|
||||
_propertyType = value;
|
||||
return _propertyType;
|
||||
}, _propertyType, PropertyTypeSelector);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Enum for the three allowed BaseTypes
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[DataContract(IsReference = true)]
|
||||
internal enum MacroPropertyTypeBaseTypes
|
||||
{
|
||||
[EnumMember]
|
||||
Int32,
|
||||
[EnumMember]
|
||||
Boolean,
|
||||
[EnumMember]
|
||||
String
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Enum for the various types of Macros
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[DataContract(IsReference = true)]
|
||||
internal enum MacroTypes
|
||||
{
|
||||
[EnumMember]
|
||||
Xslt = 1,
|
||||
[EnumMember]
|
||||
CustomControl = 2,
|
||||
[EnumMember]
|
||||
UserControl = 3,
|
||||
[EnumMember]
|
||||
Unknown = 4,
|
||||
[EnumMember]
|
||||
Python = 5,
|
||||
[EnumMember]
|
||||
Script = 6
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the Macro Repository, which exposes CRUD operations for <see cref="IMacro"/>
|
||||
/// </summary>
|
||||
/// <remarks>Uses string Alias as the Id type</remarks>
|
||||
internal interface IMacroRepository : IRepositoryQueryable<string, IMacro>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,132 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
using Umbraco.Core.Persistence.Caching;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
using Umbraco.Core.Serialization;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the Macro Repository
|
||||
/// </summary>
|
||||
internal class MacroRepository : RepositoryBase<string, IMacro>, IMacroRepository
|
||||
{
|
||||
private IFileSystem _fileSystem;
|
||||
private SerializationService _serializationService;
|
||||
|
||||
public MacroRepository(IUnitOfWork work)
|
||||
: base(work)
|
||||
{
|
||||
EnsureDependencies();
|
||||
}
|
||||
|
||||
public MacroRepository(IUnitOfWork work, IRepositoryCacheProvider cache)
|
||||
: base(work, cache)
|
||||
{
|
||||
EnsureDependencies();
|
||||
}
|
||||
|
||||
private void EnsureDependencies()
|
||||
{
|
||||
_fileSystem = new PhysicalFileSystem("~/App_Data/Macros");
|
||||
var jsonSerializer = new JsonNetSerializer();
|
||||
_serializationService = new SerializationService(jsonSerializer);
|
||||
}
|
||||
|
||||
#region Overrides of RepositoryBase<string,IMacro>
|
||||
|
||||
protected override IMacro PerformGet(string id)
|
||||
{
|
||||
var name = string.Concat(id, ".macro");
|
||||
Stream file = _fileSystem.OpenFile(name);
|
||||
var o = _serializationService.FromStream(file, typeof(Macro));
|
||||
var macro = o as IMacro;
|
||||
|
||||
//on initial construction we don't want to have dirty properties tracked
|
||||
// http://issues.umbraco.org/issue/U4-1946
|
||||
if(macro != null)
|
||||
((Entity)macro).ResetDirtyProperties(false);
|
||||
|
||||
return macro;
|
||||
}
|
||||
|
||||
protected override IEnumerable<IMacro> PerformGetAll(params string[] ids)
|
||||
{
|
||||
if (ids.Any())
|
||||
{
|
||||
foreach (var id in ids)
|
||||
{
|
||||
yield return Get(id);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var files = _fileSystem.GetFiles("", "*.macro");
|
||||
foreach (var file in files)
|
||||
{
|
||||
yield return Get(file.Replace(".macro", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override IEnumerable<IMacro> PerformGetByQuery(IQuery<IMacro> query)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override bool PerformExists(string id)
|
||||
{
|
||||
var name = string.Concat(id, ".macro");
|
||||
return _fileSystem.FileExists(name);
|
||||
}
|
||||
|
||||
protected override int PerformCount(IQuery<IMacro> query)
|
||||
{
|
||||
var files = _fileSystem.GetFiles("", "*.macro");
|
||||
return files.Count();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides of IUnitOfWorkRepository
|
||||
|
||||
protected override void PersistNewItem(IMacro entity)
|
||||
{
|
||||
((Macro)entity).AddingEntity();
|
||||
|
||||
var name = string.Concat(entity.Alias, ".macro");
|
||||
var json = _serializationService.ToStream(entity);
|
||||
_fileSystem.AddFile(name, json.ResultStream, true);
|
||||
|
||||
((ICanBeDirty)entity).ResetDirtyProperties();
|
||||
}
|
||||
|
||||
protected override void PersistUpdatedItem(IMacro entity)
|
||||
{
|
||||
((Macro)entity).UpdatingEntity();
|
||||
|
||||
var name = string.Concat(entity.Alias, ".macro");
|
||||
var json = _serializationService.ToStream(entity);
|
||||
_fileSystem.AddFile(name, json.ResultStream, true);
|
||||
|
||||
((ICanBeDirty)entity).ResetDirtyProperties();
|
||||
}
|
||||
|
||||
protected override void PersistDeletedItem(IMacro entity)
|
||||
{
|
||||
var name = string.Concat(entity.Alias, ".macro");
|
||||
if (_fileSystem.FileExists(name))
|
||||
{
|
||||
_fileSystem.DeleteFile(name);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -76,13 +76,6 @@ namespace Umbraco.Core.Persistence
|
||||
InMemoryCacheProvider.Current);
|
||||
}
|
||||
|
||||
internal virtual IMacroRepository CreateMacroRepository(IUnitOfWork uow)
|
||||
{
|
||||
return new MacroRepository(
|
||||
uow,
|
||||
InMemoryCacheProvider.Current);
|
||||
}
|
||||
|
||||
public virtual IMediaRepository CreateMediaRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return new MediaRepository(
|
||||
|
||||
@@ -487,15 +487,6 @@ namespace Umbraco.Core
|
||||
return ResolveTypes<IAction>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all available IMacroPropertyTypes in application
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal IEnumerable<Type> ResolveMacroPropertyTypes()
|
||||
{
|
||||
return ResolveTypes<IMacroPropertyType>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all mapper types that have a MapperFor attribute defined
|
||||
/// </summary>
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the ContentService, which is an easy access to operations involving <see cref="IMacro"/>
|
||||
/// </summary>
|
||||
internal interface IMacroService : IService
|
||||
{
|
||||
//TODO Possibly create import macro method and ToXml?
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="IMacro"/> object by its alias
|
||||
/// </summary>
|
||||
/// <param name="alias">Alias to retrieve an <see cref="IMacro"/> for</param>
|
||||
/// <returns>An <see cref="IMacro"/> object</returns>
|
||||
IMacro GetByAlias(string alias);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list all available <see cref="IMacro"/> objects
|
||||
/// </summary>
|
||||
/// <param name="aliases">Optional array of aliases to limit the results</param>
|
||||
/// <returns>An enumerable list of <see cref="IMacro"/> objects</returns>
|
||||
IEnumerable<IMacro> GetAll(params string[] aliases);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes an <see cref="IMacro"/>
|
||||
/// </summary>
|
||||
/// <param name="macro"><see cref="IMacro"/> to delete</param>
|
||||
/// <param name="userId">Optional id of the user deleting the macro</param>
|
||||
void Delete(IMacro macro, int userId = 0);
|
||||
|
||||
/// <summary>
|
||||
/// Saves an <see cref="IMacro"/>
|
||||
/// </summary>
|
||||
/// <param name="macro"><see cref="IMacro"/> to save</param>
|
||||
/// <param name="userId">Optional id of the user saving the macro</param>
|
||||
void Save(IMacro macro, int userId = 0);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list all available <see cref="IMacroPropertyType"/> plugins
|
||||
/// </summary>
|
||||
/// <returns>An enumerable list of <see cref="IMacroPropertyType"/> objects</returns>
|
||||
IEnumerable<IMacroPropertyType> GetMacroPropertyTypes();
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="IMacroPropertyType"/> by its alias
|
||||
/// </summary>
|
||||
/// <param name="alias">Alias to retrieve an <see cref="IMacroPropertyType"/> for</param>
|
||||
/// <returns>An <see cref="IMacroPropertyType"/> object</returns>
|
||||
IMacroPropertyType GetMacroPropertyTypeByAlias(string alias);
|
||||
}
|
||||
}
|
||||
@@ -1,168 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Auditing;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the Macro Service, which is an easy access to operations involving <see cref="IMacro"/>
|
||||
/// </summary>
|
||||
internal class MacroService : IMacroService
|
||||
{
|
||||
private readonly RepositoryFactory _repositoryFactory;
|
||||
private readonly IUnitOfWorkProvider _uowProvider;
|
||||
|
||||
public MacroService()
|
||||
: this(new RepositoryFactory())
|
||||
{
|
||||
}
|
||||
|
||||
public MacroService(RepositoryFactory repositoryFactory)
|
||||
: this(new FileUnitOfWorkProvider(), repositoryFactory)
|
||||
{
|
||||
}
|
||||
|
||||
public MacroService(IUnitOfWorkProvider provider)
|
||||
: this(provider, new RepositoryFactory())
|
||||
{
|
||||
}
|
||||
|
||||
public MacroService(IUnitOfWorkProvider provider, RepositoryFactory repositoryFactory) : this(provider, repositoryFactory, false)
|
||||
{
|
||||
}
|
||||
|
||||
public MacroService(IUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, bool ensureCachedMacros)
|
||||
{
|
||||
_uowProvider = provider;
|
||||
_repositoryFactory = repositoryFactory;
|
||||
|
||||
if(ensureCachedMacros)
|
||||
EnsureMacroCache();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensures the macro cache by getting all macros
|
||||
/// from the repository and thus caching them.
|
||||
/// </summary>
|
||||
private void EnsureMacroCache()
|
||||
{
|
||||
IEnumerable<IMacro> macros = GetAll();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="IMacro"/> object by its alias
|
||||
/// </summary>
|
||||
/// <param name="alias">Alias to retrieve an <see cref="IMacro"/> for</param>
|
||||
/// <returns>An <see cref="IMacro"/> object</returns>
|
||||
public IMacro GetByAlias(string alias)
|
||||
{
|
||||
using (var repository = _repositoryFactory.CreateMacroRepository(_uowProvider.GetUnitOfWork()))
|
||||
{
|
||||
return repository.Get(alias);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list all available <see cref="IMacro"/> objects
|
||||
/// </summary>
|
||||
/// <param name="aliases">Optional array of aliases to limit the results</param>
|
||||
/// <returns>An enumerable list of <see cref="IMacro"/> objects</returns>
|
||||
public IEnumerable<IMacro> GetAll(params string[] aliases)
|
||||
{
|
||||
using (var repository = _repositoryFactory.CreateMacroRepository(_uowProvider.GetUnitOfWork()))
|
||||
{
|
||||
return repository.GetAll(aliases);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes an <see cref="IMacro"/>
|
||||
/// </summary>
|
||||
/// <param name="macro"><see cref="IMacro"/> to delete</param>
|
||||
/// <param name="userId">Optional id of the user deleting the macro</param>
|
||||
public void Delete(IMacro macro, int userId = 0)
|
||||
{
|
||||
if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs<IMacro>(macro), this))
|
||||
return;
|
||||
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateMacroRepository(uow))
|
||||
{
|
||||
repository.Delete(macro);
|
||||
uow.Commit();
|
||||
|
||||
Deleted.RaiseEvent(new DeleteEventArgs<IMacro>(macro, false), this);
|
||||
}
|
||||
|
||||
Audit.Add(AuditTypes.Delete, "Delete Macro performed by user", userId, -1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves an <see cref="IMacro"/>
|
||||
/// </summary>
|
||||
/// <param name="macro"><see cref="IMacro"/> to save</param>
|
||||
/// <param name="userId">Optional Id of the user deleting the macro</param>
|
||||
public void Save(IMacro macro, int userId = 0)
|
||||
{
|
||||
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IMacro>(macro), this))
|
||||
return;
|
||||
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateMacroRepository(uow))
|
||||
{
|
||||
repository.AddOrUpdate(macro);
|
||||
uow.Commit();
|
||||
|
||||
Saved.RaiseEvent(new SaveEventArgs<IMacro>(macro, false), this);
|
||||
}
|
||||
|
||||
Audit.Add(AuditTypes.Save, "Save Macro performed by user", userId, -1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list all available <see cref="IMacroPropertyType"/> plugins
|
||||
/// </summary>
|
||||
/// <returns>An enumerable list of <see cref="IMacroPropertyType"/> objects</returns>
|
||||
public IEnumerable<IMacroPropertyType> GetMacroPropertyTypes()
|
||||
{
|
||||
return MacroPropertyTypeResolver.Current.MacroPropertyTypes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="IMacroPropertyType"/> by its alias
|
||||
/// </summary>
|
||||
/// <param name="alias">Alias to retrieve an <see cref="IMacroPropertyType"/> for</param>
|
||||
/// <returns>An <see cref="IMacroPropertyType"/> object</returns>
|
||||
public IMacroPropertyType GetMacroPropertyTypeByAlias(string alias)
|
||||
{
|
||||
return MacroPropertyTypeResolver.Current.MacroPropertyTypes.FirstOrDefault(x => x.Alias == alias);
|
||||
}
|
||||
|
||||
#region Event Handlers
|
||||
/// <summary>
|
||||
/// Occurs before Delete
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IMacroService, DeleteEventArgs<IMacro>> Deleting;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs after Delete
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IMacroService, DeleteEventArgs<IMacro>> Deleted;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs before Save
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IMacroService, SaveEventArgs<IMacro>> Saving;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs after Save
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IMacroService, SaveEventArgs<IMacro>> Saved;
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,6 @@ namespace Umbraco.Core.Services
|
||||
private Lazy<ContentService> _contentService;
|
||||
private Lazy<UserService> _userService;
|
||||
private Lazy<MediaService> _mediaService;
|
||||
private Lazy<MacroService> _macroService;
|
||||
private Lazy<ContentTypeService> _contentTypeService;
|
||||
private Lazy<DataTypeService> _dataTypeService;
|
||||
private Lazy<FileService> _fileService;
|
||||
@@ -62,9 +61,6 @@ namespace Umbraco.Core.Services
|
||||
if(_mediaService == null)
|
||||
_mediaService = new Lazy<MediaService>(() => new MediaService(provider, repositoryFactory.Value));
|
||||
|
||||
if(_macroService == null)
|
||||
_macroService = new Lazy<MacroService>(() => new MacroService(fileProvider, repositoryFactory.Value));
|
||||
|
||||
if(_contentTypeService == null)
|
||||
_contentTypeService = new Lazy<ContentTypeService>(() => new ContentTypeService(provider, repositoryFactory.Value, _contentService.Value, _mediaService.Value));
|
||||
|
||||
@@ -156,14 +152,6 @@ namespace Umbraco.Core.Services
|
||||
get { return _packagingService.Value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IMacroService"/>
|
||||
/// </summary>
|
||||
internal IMacroService MacroService
|
||||
{
|
||||
get { return _macroService.Value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IMacroService"/>
|
||||
/// </summary>
|
||||
|
||||
@@ -157,7 +157,6 @@
|
||||
<Compile Include="Events\SaveEventArgs.cs" />
|
||||
<Compile Include="Events\SendToPublishEventArgs.cs" />
|
||||
<Compile Include="IApplicationEventHandler.cs" />
|
||||
<Compile Include="MacroPropertyTypeResolver.cs" />
|
||||
<Compile Include="Media\MediaSubfolderCounter.cs" />
|
||||
<Compile Include="Models\ContentBase.cs" />
|
||||
<Compile Include="Models\ContentExtensions.cs" />
|
||||
@@ -468,7 +467,6 @@
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IDataTypeDefinitionRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IDictionaryRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\ILanguageRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IMacroRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IMediaRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IMediaTypeRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IRelationRepository.cs" />
|
||||
@@ -483,7 +481,6 @@
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IUserRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IUserTypeRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\LanguageRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\MacroRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\MediaRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\MediaTypeRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\PetaPocoRepositoryBase.cs" />
|
||||
@@ -547,23 +544,7 @@
|
||||
<Compile Include="IO\FileSystemProviderAttribute.cs" />
|
||||
<Compile Include="IO\FileSystemExtensions.cs" />
|
||||
<Compile Include="IO\MediaFileSystem.cs" />
|
||||
<Compile Include="Macros\PropertyTypes\ContentAll.cs" />
|
||||
<Compile Include="Macros\PropertyTypes\ContentPicker.cs" />
|
||||
<Compile Include="Macros\PropertyTypes\ContentRandom.cs" />
|
||||
<Compile Include="Macros\PropertyTypes\ContentStubs.cs" />
|
||||
<Compile Include="Macros\PropertyTypes\ContentTree.cs" />
|
||||
<Compile Include="Macros\PropertyTypes\ContentType.cs" />
|
||||
<Compile Include="Macros\PropertyTypes\ContentTypeMultiple.cs" />
|
||||
<Compile Include="Macros\PropertyTypes\MediaCurrent.cs" />
|
||||
<Compile Include="Macros\PropertyTypes\Number.cs" />
|
||||
<Compile Include="Macros\PropertyTypes\PropertyTypePicker.cs" />
|
||||
<Compile Include="Macros\PropertyTypes\PropertyTypePickerMultiple.cs" />
|
||||
<Compile Include="Macros\PropertyTypes\TabPicker.cs" />
|
||||
<Compile Include="Macros\PropertyTypes\TabPickerMultiple.cs" />
|
||||
<Compile Include="Macros\PropertyTypes\Text.cs" />
|
||||
<Compile Include="Macros\PropertyTypes\TextMultiLine.cs" />
|
||||
<Compile Include="Macros\MacroTagParser.cs" />
|
||||
<Compile Include="Macros\PropertyTypes\YesNoBool.cs" />
|
||||
<Compile Include="Mandate.cs" />
|
||||
<Compile Include="Models\Content.cs" />
|
||||
<Compile Include="Models\ContentStatus.cs" />
|
||||
@@ -580,15 +561,8 @@
|
||||
<Compile Include="Models\IContentType.cs" />
|
||||
<Compile Include="Models\IContentTypeBase.cs" />
|
||||
<Compile Include="Models\IContentTypeComposition.cs" />
|
||||
<Compile Include="Models\IMacro.cs" />
|
||||
<Compile Include="Models\IMacroProperty.cs" />
|
||||
<Compile Include="Models\IMacroPropertyType.cs" />
|
||||
<Compile Include="Models\IMedia.cs" />
|
||||
<Compile Include="Models\IMediaType.cs" />
|
||||
<Compile Include="Models\Macro.cs" />
|
||||
<Compile Include="Models\MacroProperty.cs" />
|
||||
<Compile Include="Models\MacroPropertyTypeBaseTypes.cs" />
|
||||
<Compile Include="Models\MacroTypes.cs" />
|
||||
<Compile Include="Models\Property.cs" />
|
||||
<Compile Include="Models\PropertyCollection.cs" />
|
||||
<Compile Include="Models\PropertyGroup.cs" />
|
||||
@@ -702,12 +676,10 @@
|
||||
<Compile Include="Services\IDataTypeService.cs" />
|
||||
<Compile Include="Services\IFileService.cs" />
|
||||
<Compile Include="Services\ILocalizationService.cs" />
|
||||
<Compile Include="Services\IMacroService.cs" />
|
||||
<Compile Include="Services\IMediaService.cs" />
|
||||
<Compile Include="Services\IService.cs" />
|
||||
<Compile Include="Services\IUserService.cs" />
|
||||
<Compile Include="Services\LocalizationService.cs" />
|
||||
<Compile Include="Services\MacroService.cs" />
|
||||
<Compile Include="Services\MediaService.cs" />
|
||||
<Compile Include="Services\ServerRegistrationService.cs" />
|
||||
<Compile Include="Services\PackagingService.cs" />
|
||||
|
||||
@@ -1,166 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Serialization;
|
||||
|
||||
namespace Umbraco.Tests.Models
|
||||
{
|
||||
[TestFixture, Ignore]
|
||||
public class MacroTests
|
||||
{
|
||||
[Test]
|
||||
public void Can_Create_And_Serialize_Macro()
|
||||
{
|
||||
// Arrange
|
||||
var jsonNetSerializer = new JsonNetSerializer();
|
||||
var serializationService = new SerializationService(jsonNetSerializer);
|
||||
|
||||
var macro = new Macro
|
||||
{
|
||||
Alias = "test",
|
||||
CacheByPage = false,
|
||||
CacheByMember = false,
|
||||
DontRender = true,
|
||||
Name = "Test",
|
||||
Xslt = "/xslt/testMacro.xslt",
|
||||
UseInEditor = false
|
||||
};
|
||||
|
||||
macro.Properties = new List<IMacroProperty>();
|
||||
macro.Properties.Add(new MacroProperty { Alias = "level", Name = "Level", SortOrder = 0, PropertyType = new Umbraco.Core.Macros.PropertyTypes.Number() });
|
||||
macro.Properties.Add(new MacroProperty { Alias = "fixedTitle", Name = "Fixed Title", SortOrder = 1, PropertyType = new Umbraco.Core.Macros.PropertyTypes.Text() });
|
||||
|
||||
// Act
|
||||
var json = serializationService.ToStream(macro);
|
||||
string jsonString = json.ResultStream.ToJsonString();
|
||||
|
||||
// Assert
|
||||
Assert.That(json, Is.Not.Null);
|
||||
Assert.That(json.Success, Is.True);
|
||||
Assert.That(jsonString, Is.Not.Empty);
|
||||
Assert.That(jsonString.StartsWith("{"), Is.True);
|
||||
Assert.That(jsonString.EndsWith("}"), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Create_And_Serialize_Then_Deserialize_Macro()
|
||||
{
|
||||
// Arrange
|
||||
var jsonNetSerializer = new JsonNetSerializer();
|
||||
var serializationService = new SerializationService(jsonNetSerializer);
|
||||
|
||||
var macro = new Macro
|
||||
{
|
||||
Alias = "test",
|
||||
CacheByPage = false,
|
||||
CacheByMember = false,
|
||||
DontRender = true,
|
||||
Name = "Test",
|
||||
Xslt = "/xslt/testMacro.xslt",
|
||||
UseInEditor = false
|
||||
};
|
||||
|
||||
macro.Properties = new List<IMacroProperty>();
|
||||
macro.Properties.Add(new MacroProperty { Alias = "level", Name = "Level", SortOrder = 0, PropertyType = new Umbraco.Core.Macros.PropertyTypes.Number() });
|
||||
macro.Properties.Add(new MacroProperty { Alias = "fixedTitle", Name = "Fixed Title", SortOrder = 1, PropertyType = new Umbraco.Core.Macros.PropertyTypes.Text() });
|
||||
|
||||
// Act
|
||||
var json = serializationService.ToStream(macro);
|
||||
string jsonString = json.ResultStream.ToJsonString();
|
||||
|
||||
var deserialized = serializationService.FromJson<Macro>(jsonString);
|
||||
|
||||
var stream = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
|
||||
object o = serializationService.FromStream(stream, typeof (Macro));
|
||||
var deserialized2 = o as IMacro;
|
||||
|
||||
// Assert
|
||||
Assert.That(json.Success, Is.True);
|
||||
Assert.That(jsonString, Is.Not.Empty);
|
||||
Assert.That(deserialized, Is.Not.Null);
|
||||
Assert.That(deserialized2, Is.Not.Null);
|
||||
Assert.That(deserialized.Name, Is.EqualTo(macro.Name));
|
||||
Assert.That(deserialized.Alias, Is.EqualTo(macro.Alias));
|
||||
Assert.That(deserialized2.Name, Is.EqualTo(macro.Name));
|
||||
Assert.That(deserialized2.Alias, Is.EqualTo(macro.Alias));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Write_Serialized_Macro_To_Disc()
|
||||
{
|
||||
// Arrange
|
||||
var jsonNetSerializer = new JsonNetSerializer();
|
||||
var serializationService = new SerializationService(jsonNetSerializer);
|
||||
var fileSystem = new PhysicalFileSystem("~/App_Data/Macros");
|
||||
|
||||
var macro = new Macro
|
||||
{
|
||||
Alias = "test",
|
||||
CacheByPage = false,
|
||||
CacheByMember = false,
|
||||
DontRender = true,
|
||||
Name = "Test",
|
||||
Xslt = "/xslt/testMacro.xslt",
|
||||
UseInEditor = false
|
||||
};
|
||||
|
||||
macro.Properties = new List<IMacroProperty>();
|
||||
macro.Properties.Add(new MacroProperty { Alias = "level", Name = "Level", SortOrder = 0, PropertyType = new Umbraco.Core.Macros.PropertyTypes.Number() });
|
||||
macro.Properties.Add(new MacroProperty { Alias = "fixedTitle", Name = "Fixed Title", SortOrder = 1, PropertyType = new Umbraco.Core.Macros.PropertyTypes.Text() });
|
||||
|
||||
// Act
|
||||
var json = serializationService.ToStream(macro);
|
||||
string jsonString = json.ResultStream.ToJsonString();
|
||||
fileSystem.AddFile("test-serialized-Macro.macro", json.ResultStream, true);
|
||||
|
||||
// Assert
|
||||
Assert.That(json.Success, Is.True);
|
||||
Assert.That(jsonString, Is.Not.Empty);
|
||||
Assert.That(fileSystem.FileExists("test-serialized-Macro.macro"), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Read_And_Deserialize_Macro_From_Disc()
|
||||
{
|
||||
// Arrange
|
||||
var jsonNetSerializer = new JsonNetSerializer();
|
||||
var serializationService = new SerializationService(jsonNetSerializer);
|
||||
var fileSystem = new PhysicalFileSystem("~/App_Data/Macros");
|
||||
|
||||
var macro = new Macro
|
||||
{
|
||||
Alias = "test",
|
||||
CacheByPage = false,
|
||||
CacheByMember = false,
|
||||
DontRender = true,
|
||||
Name = "Test",
|
||||
Xslt = "/xslt/testMacro.xslt",
|
||||
UseInEditor = false
|
||||
};
|
||||
|
||||
macro.Properties = new List<IMacroProperty>();
|
||||
macro.Properties.Add(new MacroProperty { Alias = "level", Name = "Level", SortOrder = 0, PropertyType = new Umbraco.Core.Macros.PropertyTypes.Number() });
|
||||
macro.Properties.Add(new MacroProperty { Alias = "fixedTitle", Name = "Fixed Title", SortOrder = 1, PropertyType = new Umbraco.Core.Macros.PropertyTypes.Text() });
|
||||
|
||||
// Act
|
||||
var json = serializationService.ToStream(macro);
|
||||
string jsonString = json.ResultStream.ToJsonString();
|
||||
fileSystem.AddFile("test-serialized-Macro.macro", json.ResultStream, true);
|
||||
|
||||
Stream stream = fileSystem.OpenFile("test-serialized-Macro.macro");
|
||||
object o = serializationService.FromStream(stream, typeof(Macro));
|
||||
var deserialized = o as IMacro;
|
||||
|
||||
// Assert
|
||||
Assert.That(json.Success, Is.True);
|
||||
Assert.That(jsonString, Is.Not.Empty);
|
||||
Assert.That(fileSystem.FileExists("test-serialized-Macro.macro"), Is.True);
|
||||
Assert.That(deserialized, Is.Not.Null);
|
||||
Assert.That(deserialized.Name, Is.EqualTo(macro.Name));
|
||||
Assert.That(deserialized.Alias, Is.EqualTo(macro.Alias));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,190 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Caching;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
[TestFixture, Ignore]
|
||||
public class MacroRepositoryTest
|
||||
{
|
||||
[Test]
|
||||
public void Can_Instantiate_Repository()
|
||||
{
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
|
||||
// Act
|
||||
var repository = new MacroRepository(unitOfWork, NullCacheProvider.Current);
|
||||
|
||||
// Assert
|
||||
Assert.That(repository, Is.Not.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Cant_Find_Macro_File()
|
||||
{
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
var repository = new MacroRepository(unitOfWork, NullCacheProvider.Current);
|
||||
|
||||
// Act
|
||||
bool exists = repository.Exists("commentList");
|
||||
|
||||
// Assert
|
||||
Assert.That(exists, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Verify_Macro_File_Exists()
|
||||
{
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
var repository = new MacroRepository(unitOfWork, NullCacheProvider.Current);
|
||||
|
||||
// Act
|
||||
bool exists = repository.Exists("testMacro");
|
||||
|
||||
// Assert
|
||||
Assert.That(exists, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Perform_Add_On_MacroRepository()
|
||||
{
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
var repository = new MacroRepository(unitOfWork, NullCacheProvider.Current);
|
||||
|
||||
// Act
|
||||
var macro = new Macro { Alias = "testMacro", CacheByPage = false, CacheByMember = false, DontRender = true, Name = "Test Macro", Xslt = "/xslt/testMacro.xslt", UseInEditor = false };
|
||||
macro.Properties = new List<IMacroProperty>();
|
||||
macro.Properties.Add(new MacroProperty { Alias = "level", Name = "Level", SortOrder = 0, PropertyType = new Umbraco.Core.Macros.PropertyTypes.Number() });
|
||||
|
||||
repository.AddOrUpdate(macro);
|
||||
unitOfWork.Commit();
|
||||
|
||||
// Assert
|
||||
Assert.That(macro.CreateDate, Is.GreaterThan(DateTime.MinValue));
|
||||
Assert.That(macro.UpdateDate, Is.GreaterThan(DateTime.MinValue));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Perform_Update_On_MacroRepository()
|
||||
{
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
var repository = new MacroRepository(unitOfWork, NullCacheProvider.Current);
|
||||
var macro = CreateMacro("updateMacro", "Update Macro");
|
||||
repository.AddOrUpdate(macro);
|
||||
unitOfWork.Commit();
|
||||
|
||||
// Act
|
||||
var macro1 = repository.Get("updateMacro");
|
||||
macro1.Xslt = "/xslt/updateTestMacro.xslt";
|
||||
repository.AddOrUpdate(macro1);
|
||||
unitOfWork.Commit();
|
||||
|
||||
var macro2 = repository.Get("updateMacro");
|
||||
|
||||
// Assert
|
||||
Assert.That(macro2.CreateDate, Is.EqualTo(macro.CreateDate));
|
||||
//Assert.That(macro2.ModifiedDate, Is.GreaterThan(macro.ModifiedDate));
|
||||
Assert.That(macro2.Xslt, Is.EqualTo("/xslt/updateTestMacro.xslt"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Perform_Delete_On_MacroRepository()
|
||||
{
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
var repository = new MacroRepository(unitOfWork, NullCacheProvider.Current);
|
||||
var macro = CreateMacro("deleteMacro", "Delete Macro");
|
||||
repository.AddOrUpdate(macro);
|
||||
unitOfWork.Commit();
|
||||
|
||||
// Act
|
||||
repository.Delete(macro);
|
||||
unitOfWork.Commit();
|
||||
var exists = repository.Exists("deleteMacro");
|
||||
|
||||
// Assert
|
||||
Assert.That(exists, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Perform_Get_On_MacroRepository()
|
||||
{
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
var repository = new MacroRepository(unitOfWork, NullCacheProvider.Current);
|
||||
var macro = CreateMacro("getMacro", "Get Macro");
|
||||
repository.AddOrUpdate(macro);
|
||||
unitOfWork.Commit();
|
||||
|
||||
// Act
|
||||
var unitOfWork2 = provider.GetUnitOfWork();
|
||||
var repository2 = new MacroRepository(unitOfWork2, NullCacheProvider.Current);
|
||||
var macro1 = repository2.Get("getMacro");
|
||||
|
||||
// Assert
|
||||
Assert.That(macro1.CreateDate, Is.GreaterThan(DateTime.MinValue));
|
||||
Assert.That(macro1.UpdateDate, Is.GreaterThan(DateTime.MinValue));
|
||||
Assert.That(macro1.Name, Is.EqualTo("Get Macro"));
|
||||
Assert.That(macro1.Properties.Any(), Is.True);
|
||||
Assert.That(macro1.Properties.Count, Is.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Perform_GetAll_On_MacroRepository()
|
||||
{
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.GetUnitOfWork();
|
||||
var repository = new MacroRepository(unitOfWork, NullCacheProvider.Current);
|
||||
|
||||
// Act
|
||||
var macros = repository.GetAll();
|
||||
var list = macros.ToList();
|
||||
|
||||
// Assert
|
||||
Assert.That(list.Any(), Is.True);
|
||||
Assert.That(list.Any(x => x == null), Is.False);
|
||||
Assert.That(list.Count(), Is.GreaterThan(1));
|
||||
Assert.That(list.Any(x => x.Alias == "getMacro"), Is.True);
|
||||
Assert.That(list.Any(x => x.Alias == "testMacro"), Is.True);
|
||||
}
|
||||
|
||||
private IMacro CreateMacro(string alias, string name)
|
||||
{
|
||||
var macro = new Macro
|
||||
{
|
||||
Alias = alias,
|
||||
CacheByPage = false,
|
||||
CacheByMember = false,
|
||||
DontRender = true,
|
||||
Name = name,
|
||||
Xslt = "/xslt/testMacro.xslt",
|
||||
UseInEditor = false
|
||||
};
|
||||
|
||||
macro.Properties = new List<IMacroProperty>();
|
||||
macro.Properties.Add(new MacroProperty { Alias = "level", Name = "Level", SortOrder = 0, PropertyType = new Umbraco.Core.Macros.PropertyTypes.Number() });
|
||||
macro.Properties.Add(new MacroProperty { Alias = "fixedTitle", Name = "Fixed Title", SortOrder = 1, PropertyType = new Umbraco.Core.Macros.PropertyTypes.Text() });
|
||||
|
||||
return macro;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,699 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Dynamics;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
|
||||
namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
[TestFixture]
|
||||
public abstract class DynamicDocumentTestsBase<TDocument, TDocumentList> : PublishedContentTestBase
|
||||
{
|
||||
protected override DatabaseBehavior DatabaseTestBehavior
|
||||
{
|
||||
get { return DatabaseBehavior.NoDatabasePerFixture; }
|
||||
}
|
||||
|
||||
protected override string GetXmlContent(int templateId)
|
||||
{
|
||||
return @"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<!DOCTYPE root[
|
||||
<!ELEMENT Home ANY>
|
||||
<!ATTLIST Home id ID #REQUIRED>
|
||||
<!ELEMENT CustomDocument ANY>
|
||||
<!ATTLIST CustomDocument id ID #REQUIRED>
|
||||
]>
|
||||
<root id=""-1"">
|
||||
<Home id=""1046"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Home"" urlName=""home"" writerName=""admin"" creatorName=""admin"" path=""-1,1046"" isDoc="""">
|
||||
<content><![CDATA[]]></content>
|
||||
<umbracoUrlAlias><![CDATA[this/is/my/alias, anotheralias]]></umbracoUrlAlias>
|
||||
<umbracoNaviHide>1</umbracoNaviHide>
|
||||
<siteTitle><![CDATA[This is my site]]></siteTitle>
|
||||
<Home id=""1173"" parentID=""1046"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-20T18:06:45"" updateDate=""2012-07-20T19:07:31"" nodeName=""Sub1"" urlName=""sub1"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173"" isDoc="""">
|
||||
<content><![CDATA[<div>This is some content</div>]]></content>
|
||||
<umbracoUrlAlias><![CDATA[page2/alias, 2ndpagealias]]></umbracoUrlAlias>
|
||||
<Home id=""1174"" parentID=""1173"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-20T18:07:54"" updateDate=""2012-07-20T19:10:27"" nodeName=""Sub2"" urlName=""sub2"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1174"" isDoc="""">
|
||||
<content><![CDATA[]]></content>
|
||||
<umbracoUrlAlias><![CDATA[only/one/alias]]></umbracoUrlAlias>
|
||||
<creatorName><![CDATA[Custom data with same property name as the member name]]></creatorName>
|
||||
</Home>
|
||||
<CustomDocument id=""1177"" parentID=""1173"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1234"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-16T15:26:59"" updateDate=""2012-07-18T14:23:35"" nodeName=""custom sub 1"" urlName=""custom-sub-1"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1177"" isDoc="""" />
|
||||
<CustomDocument id=""1178"" parentID=""1173"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1234"" template=""" + templateId + @""" sortOrder=""3"" createDate=""2012-07-16T15:26:59"" updateDate=""2012-07-16T14:23:35"" nodeName=""custom sub 2"" urlName=""custom-sub-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1178"" isDoc="""" />
|
||||
<Home id=""1176"" parentID=""1173"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""4"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
|
||||
<content><![CDATA[some content]]></content>
|
||||
<blah><![CDATA[some content]]></blah>
|
||||
<umbracoNaviHide>1</umbracoNaviHide>
|
||||
</Home>
|
||||
</Home>
|
||||
<Home id=""1175"" parentID=""1046"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""3"" createDate=""2012-07-20T18:08:01"" updateDate=""2012-07-20T18:49:32"" nodeName=""Sub 2"" urlName=""sub-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1175"" isDoc=""""><content><![CDATA[]]></content>
|
||||
</Home>
|
||||
<CustomDocument id=""4444"" parentID=""1046"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1234"" template=""" + templateId + @""" sortOrder=""4"" createDate=""2012-07-16T15:26:59"" updateDate=""2012-07-18T14:23:35"" nodeName=""Test"" urlName=""test-page"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,4444"" isDoc="""">
|
||||
<selectedNodes><![CDATA[1172,1176,1173]]></selectedNodes>
|
||||
<CustomDocument id=""5555"" parentID=""1046"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1234"" template=""" + templateId + @""" sortOrder=""0"" createDate=""2012-07-16T15:26:59"" updateDate=""2012-07-18T14:23:35"" nodeName=""Test"" urlName=""test-page"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,4444,5555"" isDoc="""">
|
||||
</CustomDocument>
|
||||
</CustomDocument>
|
||||
</Home>
|
||||
<CustomDocument id=""1172"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1234"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-16T15:26:59"" updateDate=""2012-07-18T14:23:35"" nodeName=""Test"" urlName=""test-page"" writerName=""admin"" creatorName=""admin"" path=""-1,1172"" isDoc="""" />
|
||||
</root>";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the dynamic node/document to run tests against
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
protected abstract dynamic GetDynamicNode(int id);
|
||||
|
||||
[Test]
|
||||
public void Recursive_Property()
|
||||
{
|
||||
var doc = GetDynamicNode(1174);
|
||||
var prop = doc.GetProperty("siteTitle", true);
|
||||
Assert.IsNotNull(prop);
|
||||
Assert.AreEqual("This is my site", prop.Value);
|
||||
prop = doc.GetProperty("_siteTitle"); //test with underscore prefix
|
||||
Assert.IsNotNull(prop);
|
||||
Assert.AreEqual("This is my site", prop.Value);
|
||||
Assert.AreEqual("This is my site", doc._siteTitle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the internal instance level caching of returning properties
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://issues.umbraco.org/issue/U4-1824
|
||||
/// http://issues.umbraco.org/issue/U4-1825
|
||||
/// </remarks>
|
||||
[Test]
|
||||
public void Can_Return_Property_And_Value()
|
||||
{
|
||||
var doc = GetDynamicNode(1173);
|
||||
|
||||
Assert.IsTrue(doc.HasProperty(Constants.Conventions.Content.UrlAlias));
|
||||
var prop = doc.GetProperty(Constants.Conventions.Content.UrlAlias);
|
||||
Assert.IsNotNull(prop);
|
||||
Assert.AreEqual("page2/alias, 2ndpagealias", prop.Value);
|
||||
Assert.AreEqual("page2/alias, 2ndpagealias", doc.umbracoUrlAlias);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the IsLast method with the result set from a Where statement
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Is_Last_From_Where_Filter()
|
||||
{
|
||||
var doc = GetDynamicNode(1173);
|
||||
|
||||
foreach (var d in doc.Children.Where("Visible"))
|
||||
{
|
||||
if (d.Id != 1178)
|
||||
{
|
||||
Assert.IsFalse(d.IsLast());
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsTrue(d.IsLast());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Single()
|
||||
{
|
||||
var doc = GetDynamicNode(4444);
|
||||
|
||||
var result = doc.Children().Single();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual(5555, result.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Single_With_Query()
|
||||
{
|
||||
var doc = GetDynamicNode(1046);
|
||||
|
||||
var result = doc.Children().Single("id==1175");
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual(1175, result.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void First()
|
||||
{
|
||||
var doc = GetDynamicNode(1173);
|
||||
|
||||
var result = doc.Children().First();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual(1174, result.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void First_With_Query()
|
||||
{
|
||||
var doc = GetDynamicNode(1173);
|
||||
|
||||
var result = doc.Children().First("blah==\"some content\"");
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual(1176, result.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Where_User_Property_Value()
|
||||
{
|
||||
var doc = GetDynamicNode(1173);
|
||||
|
||||
var result = (IEnumerable<dynamic>)doc.Children().Where("blah==\"some content\"");
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual(1, result.Count());
|
||||
Assert.AreEqual(1176, result.Single().Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void String_ContainsValue_Extension_Method()
|
||||
{
|
||||
var doc = GetDynamicNode(1046);
|
||||
|
||||
var paramVals = new Dictionary<string, object> { { "searchId", 1173 } }; //this is an integer value
|
||||
var result = doc.Children()
|
||||
.Where("selectedNodes.ContainsValue(searchId)", paramVals) //call an extension method
|
||||
.FirstOrDefault();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual(4444, result.Id);
|
||||
|
||||
//don't find!
|
||||
paramVals = new Dictionary<string, object> { { "searchId", 1111777 } };
|
||||
result = doc.Children()
|
||||
.Where("selectedNodes.ContainsValue(searchId)", paramVals)
|
||||
.FirstOrDefault();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
Assert.IsTrue(result.GetType() == typeof(DynamicNull) || result.GetType() == typeof(umbraco.MacroEngines.DynamicNull));
|
||||
//Assert.AreEqual(typeof(DynamicNull), result.GetType());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void String_Contains_Method()
|
||||
{
|
||||
var doc = GetDynamicNode(1046);
|
||||
|
||||
var paramVals = new Dictionary<string, object> { { "searchId", "1173" } };
|
||||
var result = doc.Children()
|
||||
.Where("selectedNodes.Contains(searchId)", paramVals)
|
||||
.FirstOrDefault();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual(4444, result.Id);
|
||||
|
||||
//don't find!
|
||||
paramVals = new Dictionary<string, object> { { "searchId", "1aaa173" } };
|
||||
result = doc.Children()
|
||||
.Where("selectedNodes.Contains(searchId)", paramVals)
|
||||
.FirstOrDefault();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
Assert.IsTrue(result.GetType() == typeof (DynamicNull) || result.GetType() == typeof (umbraco.MacroEngines.DynamicNull));
|
||||
//Assert.AreEqual(typeof (DynamicNull), result.GetType());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void String_Split_Method()
|
||||
{
|
||||
var doc = GetDynamicNode(1046);
|
||||
|
||||
var paramVals = new Dictionary<string, object>
|
||||
{
|
||||
{ "splitTerm", new char[] { ',' } },
|
||||
{ "splitOptions", StringSplitOptions.RemoveEmptyEntries }
|
||||
};
|
||||
var result = doc.Children()
|
||||
.Where("selectedNodes.Split(splitTerm, splitOptions).Length == 3", paramVals)
|
||||
.FirstOrDefault();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual(4444, result.Id);
|
||||
}
|
||||
|
||||
[Ignore("We are ignoring this test because currently our ExpressionParser class cannot deal with this... it needs some serious TLC but it is very complex.")]
|
||||
[Test]
|
||||
public void Complex_Linq()
|
||||
{
|
||||
var doc = GetDynamicNode(1173);
|
||||
|
||||
var paramVals = new Dictionary<string, object> {{"splitTerm", new char[] {','}}, {"searchId", "1173"}};
|
||||
var result = doc.Ancestors().OrderBy("level")
|
||||
.Single()
|
||||
.Descendants()
|
||||
.Where("selectedNodes != null && selectedNodes != String.Empty && selectedNodes.Split(splitTerm).Contains(searchId)", paramVals)
|
||||
.FirstOrDefault();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual(4444, result.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Index()
|
||||
{
|
||||
var doc = GetDynamicNode(1173);
|
||||
Assert.AreEqual(0, doc.Index());
|
||||
doc = GetDynamicNode(1176);
|
||||
Assert.AreEqual(3, doc.Index());
|
||||
doc = GetDynamicNode(1177);
|
||||
Assert.AreEqual(1, doc.Index());
|
||||
doc = GetDynamicNode(1178);
|
||||
Assert.AreEqual(2, doc.Index());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public virtual void Is_First_Root_Nodes()
|
||||
{
|
||||
var doc = GetDynamicNode(1046); //test root nodes
|
||||
Assert.IsTrue(doc.IsFirst());
|
||||
doc = GetDynamicNode(1172);
|
||||
Assert.IsFalse(doc.IsFirst());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Is_First()
|
||||
{
|
||||
var doc = GetDynamicNode(1173); //test normal nodes
|
||||
Assert.IsTrue(doc.IsFirst());
|
||||
doc = GetDynamicNode(1175);
|
||||
Assert.IsFalse(doc.IsFirst());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public virtual void Is_Not_First_Root_Nodes()
|
||||
{
|
||||
var doc = GetDynamicNode(1046); //test root nodes
|
||||
Assert.IsFalse(doc.IsNotFirst());
|
||||
doc = GetDynamicNode(1172);
|
||||
Assert.IsTrue(doc.IsNotFirst());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Is_Not_First()
|
||||
{
|
||||
var doc = GetDynamicNode(1173); //test normal nodes
|
||||
Assert.IsFalse(doc.IsNotFirst());
|
||||
doc = GetDynamicNode(1175);
|
||||
Assert.IsTrue(doc.IsNotFirst());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public virtual void Is_Position_Root_Nodes()
|
||||
{
|
||||
var doc = GetDynamicNode(1046); //test root nodes
|
||||
Assert.IsTrue(doc.IsPosition(0));
|
||||
doc = GetDynamicNode(1172);
|
||||
Assert.IsTrue(doc.IsPosition(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Is_Position()
|
||||
{
|
||||
var doc = GetDynamicNode(1173); //test normal nodes
|
||||
Assert.IsTrue(doc.IsPosition(0));
|
||||
doc = GetDynamicNode(1175);
|
||||
Assert.IsTrue(doc.IsPosition(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Children_GroupBy_DocumentTypeAlias()
|
||||
{
|
||||
var doc = GetDynamicNode(1046);
|
||||
|
||||
var found1 = doc.Children.GroupBy("DocumentTypeAlias");
|
||||
|
||||
var casted = (IEnumerable<IGrouping<object, dynamic>>)(found1);
|
||||
Assert.AreEqual(2, casted.Count());
|
||||
Assert.AreEqual(2, casted.Single(x => x.Key.ToString() == "Home").Count());
|
||||
Assert.AreEqual(1, casted.Single(x => x.Key.ToString() == "CustomDocument").Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Children_Where_DocumentTypeAlias()
|
||||
{
|
||||
var doc = GetDynamicNode(1046);
|
||||
|
||||
var found1 = doc.Children.Where("DocumentTypeAlias == \"CustomDocument\"");
|
||||
var found2 = doc.Children.Where("DocumentTypeAlias == \"Home\"");
|
||||
|
||||
Assert.AreEqual(1, found1.Count());
|
||||
Assert.AreEqual(2, found2.Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Children_Where_NodeTypeAlias()
|
||||
{
|
||||
var doc = GetDynamicNode(1046);
|
||||
|
||||
var found1 = doc.Children.Where("NodeTypeAlias == \"CustomDocument\"");
|
||||
var found2 = doc.Children.Where("NodeTypeAlias == \"Home\"");
|
||||
|
||||
Assert.AreEqual(1, found1.Count());
|
||||
Assert.AreEqual(2, found2.Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Children_Order_By_Update_Date()
|
||||
{
|
||||
var asDynamic = GetDynamicNode(1173);
|
||||
|
||||
var ordered = asDynamic.Children.OrderBy("UpdateDate");
|
||||
var casted = (IEnumerable<TDocument>)ordered;
|
||||
|
||||
var correctOrder = new[] { 1178, 1177, 1174, 1176 };
|
||||
for (var i = 0; i < correctOrder.Length ;i++)
|
||||
{
|
||||
Assert.AreEqual(correctOrder[i], ((dynamic)casted.ElementAt(i)).Id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Children_Order_By_Update_Date_Descending()
|
||||
{
|
||||
var asDynamic = GetDynamicNode(1173);
|
||||
|
||||
var ordered = asDynamic.Children.OrderBy("UpdateDate desc");
|
||||
var casted = (IEnumerable<TDocument>)ordered;
|
||||
|
||||
var correctOrder = new[] { 1176, 1174, 1177, 1178 };
|
||||
for (var i = 0; i < correctOrder.Length; i++)
|
||||
{
|
||||
Assert.AreEqual(correctOrder[i], ((dynamic)casted.ElementAt(i)).Id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HasProperty()
|
||||
{
|
||||
var asDynamic = GetDynamicNode(1173);
|
||||
|
||||
var hasProp = asDynamic.HasProperty(Constants.Conventions.Content.UrlAlias);
|
||||
|
||||
Assert.AreEqual(true, (bool)hasProp);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Skip()
|
||||
{
|
||||
var asDynamic = GetDynamicNode(1173);
|
||||
|
||||
var skip = asDynamic.Children.Skip(2);
|
||||
var casted = (IEnumerable<TDocument>)skip;
|
||||
|
||||
Assert.AreEqual(2, casted.Count());
|
||||
Assert.IsTrue(casted.Select(x => ((dynamic) x).Id).ContainsAll(new dynamic[] {1178, 1176}));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HasValue()
|
||||
{
|
||||
var asDynamic = GetDynamicNode(1173);
|
||||
|
||||
var hasValue = asDynamic.HasValue(Constants.Conventions.Content.UrlAlias);
|
||||
var noValue = asDynamic.HasValue("blahblahblah");
|
||||
|
||||
Assert.IsTrue(hasValue);
|
||||
Assert.IsFalse(noValue);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Take()
|
||||
{
|
||||
var asDynamic = GetDynamicNode(1173);
|
||||
|
||||
var take = asDynamic.Children.Take(2);
|
||||
var casted = (IEnumerable<TDocument>)take;
|
||||
|
||||
Assert.AreEqual(2, casted.Count());
|
||||
Assert.IsTrue(casted.Select(x => ((dynamic)x).Id).ContainsAll(new dynamic[] { 1174, 1177 }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Ancestors_Where_Visible()
|
||||
{
|
||||
var asDynamic = GetDynamicNode(1174);
|
||||
|
||||
var whereVisible = asDynamic.Ancestors().Where("Visible");
|
||||
var casted = (IEnumerable<TDocument>)whereVisible;
|
||||
|
||||
Assert.AreEqual(1, casted.Count());
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Visible()
|
||||
{
|
||||
var asDynamicHidden = GetDynamicNode(1046);
|
||||
var asDynamicVisible = GetDynamicNode(1173);
|
||||
|
||||
Assert.IsFalse(asDynamicHidden.Visible);
|
||||
Assert.IsTrue(asDynamicVisible.Visible);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Ensure_TinyMCE_Converted_Type_User_Property()
|
||||
{
|
||||
var asDynamic = GetDynamicNode(1173);
|
||||
|
||||
Assert.IsTrue(TypeHelper.IsTypeAssignableFrom<IHtmlString>(asDynamic.Content.GetType()));
|
||||
Assert.AreEqual("<div>This is some content</div>", asDynamic.Content.ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_Children_With_Pluralized_Alias()
|
||||
{
|
||||
var asDynamic = GetDynamicNode(1173);
|
||||
|
||||
Action<object> doAssert = d =>
|
||||
{
|
||||
Assert.IsTrue(TypeHelper.IsTypeAssignableFrom<IEnumerable>(d));
|
||||
var casted = (IEnumerable<TDocument>)d;
|
||||
Assert.AreEqual(2, casted.Count());
|
||||
};
|
||||
|
||||
doAssert(asDynamic.Homes); //pluralized alias
|
||||
doAssert(asDynamic.homes); //pluralized alias
|
||||
doAssert(asDynamic.CustomDocuments); //pluralized alias
|
||||
doAssert(asDynamic.customDocuments); //pluralized alias
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetPropertyValue_Non_Reflected()
|
||||
{
|
||||
var asDynamic = GetDynamicNode(1174);
|
||||
|
||||
Assert.AreEqual("Custom data with same property name as the member name", asDynamic.GetPropertyValue("creatorName"));
|
||||
Assert.AreEqual("Custom data with same property name as the member name", asDynamic.GetPropertyValue("CreatorName"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetPropertyValue_Reflected()
|
||||
{
|
||||
var asDynamic = GetDynamicNode(1174);
|
||||
|
||||
Assert.AreEqual("admin", asDynamic.GetPropertyValue("@creatorName"));
|
||||
Assert.AreEqual("admin", asDynamic.GetPropertyValue("@CreatorName"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_User_Property_With_Same_Name_As_Member_Property()
|
||||
{
|
||||
var asDynamic = GetDynamicNode(1174);
|
||||
|
||||
Assert.AreEqual("Custom data with same property name as the member name", asDynamic.creatorName);
|
||||
|
||||
//because CreatorName is defined on DynamicNode, it will not return the user defined property
|
||||
Assert.AreEqual("admin", asDynamic.CreatorName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_Member_Property()
|
||||
{
|
||||
var asDynamic = GetDynamicNode(1173);
|
||||
|
||||
Assert.AreEqual((int) 2, (int) asDynamic.Level);
|
||||
Assert.AreEqual((int) 2, (int) asDynamic.level);
|
||||
|
||||
Assert.AreEqual((int) 1046, (int) asDynamic.ParentId);
|
||||
Assert.AreEqual((int) 1046, (int) asDynamic.parentId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_Children()
|
||||
{
|
||||
var asDynamic = GetDynamicNode(1173);
|
||||
|
||||
var children = asDynamic.Children;
|
||||
Assert.IsTrue(TypeHelper.IsTypeAssignableFrom<IEnumerable>(children));
|
||||
|
||||
var childrenAsList = asDynamic.ChildrenAsList; //test ChildrenAsList too
|
||||
Assert.IsTrue(TypeHelper.IsTypeAssignableFrom<IEnumerable>(childrenAsList));
|
||||
|
||||
var castChildren = (IEnumerable<TDocument>)children;
|
||||
Assert.AreEqual(4, castChildren.Count());
|
||||
|
||||
var castChildrenAsList = (IEnumerable<TDocument>)childrenAsList;
|
||||
Assert.AreEqual(4, castChildrenAsList.Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Ancestor_Or_Self()
|
||||
{
|
||||
var asDynamic = GetDynamicNode(1173);
|
||||
|
||||
var result = asDynamic.AncestorOrSelf();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
|
||||
Assert.AreEqual((int) 1046, (int) result.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Ancestors_Or_Self()
|
||||
{
|
||||
var asDynamic = GetDynamicNode(1174);
|
||||
|
||||
var result = asDynamic.AncestorsOrSelf();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
|
||||
var list = (IEnumerable<TDocument>)result;
|
||||
Assert.AreEqual(3, list.Count());
|
||||
Assert.IsTrue(list.Select(x => ((dynamic)x).Id).ContainsAll(new dynamic[] { 1174, 1173, 1046 }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Ancestors()
|
||||
{
|
||||
var asDynamic = GetDynamicNode(1174);
|
||||
|
||||
var result = asDynamic.Ancestors();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
|
||||
var list = (IEnumerable<TDocument>)result;
|
||||
Assert.AreEqual(2, list.Count());
|
||||
Assert.IsTrue(list.Select(x => ((dynamic)x).Id).ContainsAll(new dynamic[] { 1173, 1046 }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Descendants_Or_Self()
|
||||
{
|
||||
var asDynamic = GetDynamicNode(1046);
|
||||
|
||||
var result = asDynamic.DescendantsOrSelf();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
|
||||
var list = (IEnumerable<TDocument>)result;
|
||||
Assert.AreEqual(9, list.Count());
|
||||
Assert.IsTrue(list.Select(x => ((dynamic)x).Id).ContainsAll(new dynamic[] { 1046, 1173, 1174, 1176, 1175, 4444 }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Descendants()
|
||||
{
|
||||
var asDynamic = GetDynamicNode(1046);
|
||||
|
||||
var result = asDynamic.Descendants();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
|
||||
var list = (IEnumerable<TDocument>)result;
|
||||
Assert.AreEqual(8, list.Count());
|
||||
Assert.IsTrue(list.Select(x => ((dynamic)x).Id).ContainsAll(new dynamic[] { 1173, 1174, 1176, 1175, 4444 }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Up()
|
||||
{
|
||||
var asDynamic = GetDynamicNode(1173);
|
||||
|
||||
var result = asDynamic.Up();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
|
||||
Assert.AreEqual((int) 1046, (int) result.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Down()
|
||||
{
|
||||
var asDynamic = GetDynamicNode(1173);
|
||||
|
||||
var result = asDynamic.Down();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
|
||||
Assert.AreEqual((int) 1174, (int) result.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Next()
|
||||
{
|
||||
var asDynamic = GetDynamicNode(1173);
|
||||
|
||||
var result = asDynamic.Next();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
|
||||
Assert.AreEqual((int) 1175, (int) result.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Next_Without_Sibling()
|
||||
{
|
||||
var asDynamic = GetDynamicNode(1176);
|
||||
|
||||
Assert.IsNull(asDynamic.Next());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Previous_Without_Sibling()
|
||||
{
|
||||
var asDynamic = GetDynamicNode(1173);
|
||||
|
||||
Assert.IsNull(asDynamic.Previous());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Previous()
|
||||
{
|
||||
var asDynamic = GetDynamicNode(1176);
|
||||
|
||||
var result = asDynamic.Previous();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
|
||||
Assert.AreEqual((int)1178, (int)result.Id);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods used in tests
|
||||
/// </summary>
|
||||
public static class TestExtensionMethods
|
||||
{
|
||||
public static bool ContainsValue(this string s, int val)
|
||||
{
|
||||
return s.Contains(val.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.PublishedCache.XmlPublishedCache;
|
||||
using umbraco.MacroEngines;
|
||||
using umbraco.NodeFactory;
|
||||
using System.Linq;
|
||||
|
||||
namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
[TestFixture]
|
||||
public class DynamicNodeTests : DynamicDocumentTestsBase<DynamicNode, DynamicNodeList>
|
||||
{
|
||||
/// <summary>
|
||||
/// We only need a new schema per fixture... speeds up testing
|
||||
/// </summary>
|
||||
protected override DatabaseBehavior DatabaseTestBehavior
|
||||
{
|
||||
get { return DatabaseBehavior.NewSchemaPerFixture; }
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
//copy the umbraco settings file over
|
||||
var currDir = new DirectoryInfo(TestHelper.CurrentAssemblyDirectory);
|
||||
File.Copy(
|
||||
currDir.Parent.Parent.Parent.GetDirectories("Umbraco.Web.UI")
|
||||
.First()
|
||||
.GetDirectories("config").First()
|
||||
.GetFiles("umbracoSettings.Release.config").First().FullName,
|
||||
Path.Combine(currDir.Parent.Parent.FullName, "config", "umbracoSettings.config"),
|
||||
true);
|
||||
|
||||
UmbracoSettings.SettingsFilePath = IOHelper.MapPath(SystemDirectories.Config + Path.DirectorySeparatorChar, false);
|
||||
|
||||
//need to specify a custom callback for unit tests
|
||||
DynamicNode.GetDataTypeCallback = (docTypeAlias, propertyAlias) =>
|
||||
{
|
||||
if (propertyAlias == "content")
|
||||
{
|
||||
//return the rte type id
|
||||
return Guid.Parse(Constants.PropertyEditors.TinyMCEv3);
|
||||
}
|
||||
return Guid.Empty;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("This test will never work unless DynamicNode is refactored a lot in order to get a list of root nodes since root nodes don't have a parent to look up")]
|
||||
public override void Is_First_Root_Nodes()
|
||||
{
|
||||
base.Is_First_Root_Nodes();
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("This test will never work unless DynamicNode is refactored a lot in order to get a list of root nodes since root nodes don't have a parent to look up")]
|
||||
public override void Is_Not_First_Root_Nodes()
|
||||
{
|
||||
base.Is_Not_First_Root_Nodes();
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("This test will never work unless DynamicNode is refactored a lot in order to get a list of root nodes since root nodes don't have a parent to look up")]
|
||||
public override void Is_Position_Root_Nodes()
|
||||
{
|
||||
base.Is_Position_Root_Nodes();
|
||||
}
|
||||
|
||||
public override void TearDown()
|
||||
{
|
||||
base.TearDown();
|
||||
}
|
||||
|
||||
protected override dynamic GetDynamicNode(int id)
|
||||
{
|
||||
//var template = Template.MakeNew("test", new User(0));
|
||||
//var ctx = GetUmbracoContext("/test", template.Id);
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
|
||||
var cache = ctx.ContentCache.InnerCache as PublishedContentCache;
|
||||
if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the legacy one is supported.");
|
||||
|
||||
var node = new DynamicNode(
|
||||
new DynamicBackingItem(
|
||||
new Node(cache.GetXml(ctx).SelectSingleNode("//*[@id='" + id + "' and @isDoc]"))));
|
||||
Assert.IsNotNull(node);
|
||||
return (dynamic)node;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Web.Models;
|
||||
|
||||
namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
public static class DynamicPublishedContentCustomExtensionMethods
|
||||
{
|
||||
|
||||
public static string DynamicDocumentNoParameters(this DynamicPublishedContent doc)
|
||||
{
|
||||
return "Hello world";
|
||||
}
|
||||
|
||||
public static string DynamicDocumentCustomString(this DynamicPublishedContent doc, string custom)
|
||||
{
|
||||
return custom;
|
||||
}
|
||||
|
||||
public static string DynamicDocumentMultiParam(this DynamicPublishedContent doc, string custom, int i, bool b)
|
||||
{
|
||||
return custom + i + b;
|
||||
}
|
||||
|
||||
public static string DynamicDocumentListMultiParam(this DynamicPublishedContentList doc, string custom, int i, bool b)
|
||||
{
|
||||
return custom + i + b;
|
||||
}
|
||||
|
||||
public static string DynamicDocumentEnumerableMultiParam(this IEnumerable<DynamicPublishedContent> doc, string custom, int i, bool b)
|
||||
{
|
||||
return custom + i + b;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.PublishedCache.XmlPublishedCache;
|
||||
|
||||
namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
[TestFixture]
|
||||
public class DynamicPublishedContentTests : DynamicDocumentTestsBase<DynamicPublishedContent, DynamicPublishedContentList>
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
}
|
||||
|
||||
public override void TearDown()
|
||||
{
|
||||
base.TearDown();
|
||||
}
|
||||
|
||||
internal DynamicPublishedContent GetNode(int id)
|
||||
{
|
||||
//var template = Template.MakeNew("test", new User(0));
|
||||
//var ctx = GetUmbracoContext("/test", template.Id);
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
var doc = ctx.ContentCache.GetById(id);
|
||||
Assert.IsNotNull(doc);
|
||||
var dynamicNode = new DynamicPublishedContent(doc);
|
||||
Assert.IsNotNull(dynamicNode);
|
||||
return dynamicNode;
|
||||
}
|
||||
|
||||
protected override dynamic GetDynamicNode(int id)
|
||||
{
|
||||
return GetNode(id).AsDynamic();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Custom_Extension_Methods()
|
||||
{
|
||||
var asDynamic = GetDynamicNode(1173);
|
||||
|
||||
Assert.AreEqual("Hello world", asDynamic.DynamicDocumentNoParameters());
|
||||
Assert.AreEqual("Hello world!", asDynamic.DynamicDocumentCustomString("Hello world!"));
|
||||
Assert.AreEqual("Hello world!" + 123 + false, asDynamic.DynamicDocumentMultiParam("Hello world!", 123, false));
|
||||
Assert.AreEqual("Hello world!" + 123 + false, asDynamic.Children.DynamicDocumentListMultiParam("Hello world!", 123, false));
|
||||
Assert.AreEqual("Hello world!" + 123 + false, asDynamic.Children.DynamicDocumentEnumerableMultiParam("Hello world!", 123, false));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Returns_IDocument_Object()
|
||||
{
|
||||
var helper = new TestHelper(GetNode(1173));
|
||||
var doc = helper.GetDoc();
|
||||
//HasProperty is only a prop on DynamicPublishedContent, NOT IPublishedContent
|
||||
Assert.IsFalse(doc.GetType().GetProperties().Any(x => x.Name == "HasProperty"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Returns_DynamicDocument_Object()
|
||||
{
|
||||
var helper = new TestHelper(GetNode(1173));
|
||||
var doc = helper.GetDocAsDynamic();
|
||||
//HasProperty is only a prop on DynamicPublishedContent, NOT IPublishedContent
|
||||
Assert.IsTrue(doc.HasProperty(Constants.Conventions.Content.UrlAlias));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Returns_DynamicDocument_Object_After_Casting()
|
||||
{
|
||||
var helper = new TestHelper(GetNode(1173));
|
||||
var doc = helper.GetDoc();
|
||||
var ddoc = (dynamic) doc;
|
||||
//HasProperty is only a prop on DynamicPublishedContent, NOT IPublishedContent
|
||||
Assert.IsTrue(ddoc.HasProperty(Constants.Conventions.Content.UrlAlias));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test class to mimic UmbracoHelper when returning docs
|
||||
/// </summary>
|
||||
public class TestHelper
|
||||
{
|
||||
private readonly DynamicPublishedContent _doc;
|
||||
|
||||
public TestHelper(DynamicPublishedContent doc)
|
||||
{
|
||||
_doc = doc;
|
||||
}
|
||||
|
||||
public IPublishedContent GetDoc()
|
||||
{
|
||||
return _doc;
|
||||
}
|
||||
|
||||
public dynamic GetDocAsDynamic()
|
||||
{
|
||||
return _doc.AsDynamic();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Dynamics;
|
||||
using Umbraco.Tests.PartialTrust;
|
||||
|
||||
namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
[TestFixture]
|
||||
public class DynamicXmlConverterTests : AbstractPartialTrustFixture<DynamicXmlConverterTests>
|
||||
{
|
||||
[Test]
|
||||
public void Convert_To_Raw_String()
|
||||
{
|
||||
var xml = "<DAMP fullMedia=\"\" test-attribute=\"someValue\"><mediaItem><Image id=\"1057\" version=\"d58d5c16-153e-4896-892f-a722e45a69af\" parentID=\"-1\" level=\"1\" writerID=\"0\" nodeType=\"1032\" template=\"0\" sortOrder=\"1\" createDate=\"2012-11-05T16:55:29\" updateDate=\"2012-11-05T16:55:44\" nodeName=\"test12\" urlName=\"test12\" writerName=\"admin\" nodeTypeAlias=\"Image\" path=\"-1,1057\"><umbracoFile>/media/54/tulips.jpg</umbracoFile><umbracoWidth>1024</umbracoWidth><umbracoHeight>768</umbracoHeight><umbracoBytes>620888</umbracoBytes><umbracoExtension>jpg</umbracoExtension><newsCrops><crops date=\"2012-11-05T16:55:34\"><crop name=\"thumbCrop\" x=\"154\" y=\"1\" x2=\"922\" y2=\"768\" url=\"/media/54/tulips_thumbCrop.jpg\" /></crops></newsCrops></Image></mediaItem><mediaItem><Image id=\"1055\" version=\"4df1f08a-3552-45f2-b4bf-fa980c762f4a\" parentID=\"-1\" level=\"1\" writerID=\"0\" nodeType=\"1032\" template=\"0\" sortOrder=\"1\" createDate=\"2012-11-05T16:29:58\" updateDate=\"2012-11-05T16:30:27\" nodeName=\"Test\" urlName=\"test\" writerName=\"admin\" nodeTypeAlias=\"Image\" path=\"-1,1055\"><umbracoFile>/media/41/hydrangeas.jpg</umbracoFile><umbracoWidth>1024</umbracoWidth><umbracoHeight>768</umbracoHeight><umbracoBytes>595284</umbracoBytes><umbracoExtension>jpg</umbracoExtension><newsCrops><crops date=\"2012-11-05T16:30:18\"><crop name=\"thumbCrop\" x=\"133\" y=\"0\" x2=\"902\" y2=\"768\" url=\"/media/41/hydrangeas_thumbCrop.jpg\" /></crops></newsCrops></Image></mediaItem></DAMP>";
|
||||
var dXml = new DynamicXml(
|
||||
XmlHelper.StripDashesInElementOrAttributeNames(xml),
|
||||
xml);
|
||||
var result = dXml.TryConvertTo<RawXmlString>();
|
||||
Assert.IsTrue(result.Success);
|
||||
Assert.AreEqual(xml, result.Result.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Convert_To_Raw_XElement()
|
||||
{
|
||||
var xml = "<DAMP fullMedia=\"\" test-attribute=\"someValue\"><mediaItem><Image id=\"1057\" version=\"d58d5c16-153e-4896-892f-a722e45a69af\" parentID=\"-1\" level=\"1\" writerID=\"0\" nodeType=\"1032\" template=\"0\" sortOrder=\"1\" createDate=\"2012-11-05T16:55:29\" updateDate=\"2012-11-05T16:55:44\" nodeName=\"test12\" urlName=\"test12\" writerName=\"admin\" nodeTypeAlias=\"Image\" path=\"-1,1057\"><umbracoFile>/media/54/tulips.jpg</umbracoFile><umbracoWidth>1024</umbracoWidth><umbracoHeight>768</umbracoHeight><umbracoBytes>620888</umbracoBytes><umbracoExtension>jpg</umbracoExtension><newsCrops><crops date=\"2012-11-05T16:55:34\"><crop name=\"thumbCrop\" x=\"154\" y=\"1\" x2=\"922\" y2=\"768\" url=\"/media/54/tulips_thumbCrop.jpg\" /></crops></newsCrops></Image></mediaItem><mediaItem><Image id=\"1055\" version=\"4df1f08a-3552-45f2-b4bf-fa980c762f4a\" parentID=\"-1\" level=\"1\" writerID=\"0\" nodeType=\"1032\" template=\"0\" sortOrder=\"1\" createDate=\"2012-11-05T16:29:58\" updateDate=\"2012-11-05T16:30:27\" nodeName=\"Test\" urlName=\"test\" writerName=\"admin\" nodeTypeAlias=\"Image\" path=\"-1,1055\"><umbracoFile>/media/41/hydrangeas.jpg</umbracoFile><umbracoWidth>1024</umbracoWidth><umbracoHeight>768</umbracoHeight><umbracoBytes>595284</umbracoBytes><umbracoExtension>jpg</umbracoExtension><newsCrops><crops date=\"2012-11-05T16:30:18\"><crop name=\"thumbCrop\" x=\"133\" y=\"0\" x2=\"902\" y2=\"768\" url=\"/media/41/hydrangeas_thumbCrop.jpg\" /></crops></newsCrops></Image></mediaItem></DAMP>";
|
||||
var dXml = new DynamicXml(
|
||||
XmlHelper.StripDashesInElementOrAttributeNames(xml),
|
||||
xml);
|
||||
var result = dXml.TryConvertTo<RawXElement>();
|
||||
Assert.IsTrue(result.Success);
|
||||
Assert.AreEqual(xml, result.Result.Value.ToString(SaveOptions.DisableFormatting));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Convert_To_Raw_XmlElement()
|
||||
{
|
||||
var xml = "<DAMP fullMedia=\"\" test-attribute=\"someValue\"><mediaItem><Image id=\"1057\" version=\"d58d5c16-153e-4896-892f-a722e45a69af\" parentID=\"-1\" level=\"1\" writerID=\"0\" nodeType=\"1032\" template=\"0\" sortOrder=\"1\" createDate=\"2012-11-05T16:55:29\" updateDate=\"2012-11-05T16:55:44\" nodeName=\"test12\" urlName=\"test12\" writerName=\"admin\" nodeTypeAlias=\"Image\" path=\"-1,1057\"><umbracoFile>/media/54/tulips.jpg</umbracoFile><umbracoWidth>1024</umbracoWidth><umbracoHeight>768</umbracoHeight><umbracoBytes>620888</umbracoBytes><umbracoExtension>jpg</umbracoExtension><newsCrops><crops date=\"2012-11-05T16:55:34\"><crop name=\"thumbCrop\" x=\"154\" y=\"1\" x2=\"922\" y2=\"768\" url=\"/media/54/tulips_thumbCrop.jpg\" /></crops></newsCrops></Image></mediaItem><mediaItem><Image id=\"1055\" version=\"4df1f08a-3552-45f2-b4bf-fa980c762f4a\" parentID=\"-1\" level=\"1\" writerID=\"0\" nodeType=\"1032\" template=\"0\" sortOrder=\"1\" createDate=\"2012-11-05T16:29:58\" updateDate=\"2012-11-05T16:30:27\" nodeName=\"Test\" urlName=\"test\" writerName=\"admin\" nodeTypeAlias=\"Image\" path=\"-1,1055\"><umbracoFile>/media/41/hydrangeas.jpg</umbracoFile><umbracoWidth>1024</umbracoWidth><umbracoHeight>768</umbracoHeight><umbracoBytes>595284</umbracoBytes><umbracoExtension>jpg</umbracoExtension><newsCrops><crops date=\"2012-11-05T16:30:18\"><crop name=\"thumbCrop\" x=\"133\" y=\"0\" x2=\"902\" y2=\"768\" url=\"/media/41/hydrangeas_thumbCrop.jpg\" /></crops></newsCrops></Image></mediaItem></DAMP>";
|
||||
var dXml = new DynamicXml(
|
||||
XmlHelper.StripDashesInElementOrAttributeNames(xml),
|
||||
xml);
|
||||
var result = dXml.TryConvertTo<RawXmlElement>();
|
||||
Assert.IsTrue(result.Success);
|
||||
Assert.AreEqual(xml, result.Result.Value.OuterXml);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Convert_To_Raw_XmlDocument()
|
||||
{
|
||||
var xml = "<DAMP fullMedia=\"\" test-attribute=\"someValue\"><mediaItem><Image id=\"1057\" version=\"d58d5c16-153e-4896-892f-a722e45a69af\" parentID=\"-1\" level=\"1\" writerID=\"0\" nodeType=\"1032\" template=\"0\" sortOrder=\"1\" createDate=\"2012-11-05T16:55:29\" updateDate=\"2012-11-05T16:55:44\" nodeName=\"test12\" urlName=\"test12\" writerName=\"admin\" nodeTypeAlias=\"Image\" path=\"-1,1057\"><umbracoFile>/media/54/tulips.jpg</umbracoFile><umbracoWidth>1024</umbracoWidth><umbracoHeight>768</umbracoHeight><umbracoBytes>620888</umbracoBytes><umbracoExtension>jpg</umbracoExtension><newsCrops><crops date=\"2012-11-05T16:55:34\"><crop name=\"thumbCrop\" x=\"154\" y=\"1\" x2=\"922\" y2=\"768\" url=\"/media/54/tulips_thumbCrop.jpg\" /></crops></newsCrops></Image></mediaItem><mediaItem><Image id=\"1055\" version=\"4df1f08a-3552-45f2-b4bf-fa980c762f4a\" parentID=\"-1\" level=\"1\" writerID=\"0\" nodeType=\"1032\" template=\"0\" sortOrder=\"1\" createDate=\"2012-11-05T16:29:58\" updateDate=\"2012-11-05T16:30:27\" nodeName=\"Test\" urlName=\"test\" writerName=\"admin\" nodeTypeAlias=\"Image\" path=\"-1,1055\"><umbracoFile>/media/41/hydrangeas.jpg</umbracoFile><umbracoWidth>1024</umbracoWidth><umbracoHeight>768</umbracoHeight><umbracoBytes>595284</umbracoBytes><umbracoExtension>jpg</umbracoExtension><newsCrops><crops date=\"2012-11-05T16:30:18\"><crop name=\"thumbCrop\" x=\"133\" y=\"0\" x2=\"902\" y2=\"768\" url=\"/media/41/hydrangeas_thumbCrop.jpg\" /></crops></newsCrops></Image></mediaItem></DAMP>";
|
||||
var dXml = new DynamicXml(
|
||||
XmlHelper.StripDashesInElementOrAttributeNames(xml),
|
||||
xml);
|
||||
var result = dXml.TryConvertTo<RawXmlDocument>();
|
||||
Assert.IsTrue(result.Success);
|
||||
Assert.AreEqual(xml, result.Result.Value.InnerXml);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Convert_To_String()
|
||||
{
|
||||
var xml = "<DAMP fullMedia=\"\" test-attribute=\"someValue\"><mediaItem><Image id=\"1057\" version=\"d58d5c16-153e-4896-892f-a722e45a69af\" parentID=\"-1\" level=\"1\" writerID=\"0\" nodeType=\"1032\" template=\"0\" sortOrder=\"1\" createDate=\"2012-11-05T16:55:29\" updateDate=\"2012-11-05T16:55:44\" nodeName=\"test12\" urlName=\"test12\" writerName=\"admin\" nodeTypeAlias=\"Image\" path=\"-1,1057\"><umbracoFile>/media/54/tulips.jpg</umbracoFile><umbracoWidth>1024</umbracoWidth><umbracoHeight>768</umbracoHeight><umbracoBytes>620888</umbracoBytes><umbracoExtension>jpg</umbracoExtension><newsCrops><crops date=\"2012-11-05T16:55:34\"><crop name=\"thumbCrop\" x=\"154\" y=\"1\" x2=\"922\" y2=\"768\" url=\"/media/54/tulips_thumbCrop.jpg\" /></crops></newsCrops></Image></mediaItem><mediaItem><Image id=\"1055\" version=\"4df1f08a-3552-45f2-b4bf-fa980c762f4a\" parentID=\"-1\" level=\"1\" writerID=\"0\" nodeType=\"1032\" template=\"0\" sortOrder=\"1\" createDate=\"2012-11-05T16:29:58\" updateDate=\"2012-11-05T16:30:27\" nodeName=\"Test\" urlName=\"test\" writerName=\"admin\" nodeTypeAlias=\"Image\" path=\"-1,1055\"><umbracoFile>/media/41/hydrangeas.jpg</umbracoFile><umbracoWidth>1024</umbracoWidth><umbracoHeight>768</umbracoHeight><umbracoBytes>595284</umbracoBytes><umbracoExtension>jpg</umbracoExtension><newsCrops><crops date=\"2012-11-05T16:30:18\"><crop name=\"thumbCrop\" x=\"133\" y=\"0\" x2=\"902\" y2=\"768\" url=\"/media/41/hydrangeas_thumbCrop.jpg\" /></crops></newsCrops></Image></mediaItem></DAMP>";
|
||||
var dXml = new DynamicXml(xml);
|
||||
var result = dXml.TryConvertTo<string>();
|
||||
Assert.IsTrue(result.Success);
|
||||
Assert.AreEqual(xml, result.Result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Convert_To_XElement()
|
||||
{
|
||||
var xml = "<DAMP fullMedia=\"\" test-attribute=\"someValue\"><mediaItem><Image id=\"1057\" version=\"d58d5c16-153e-4896-892f-a722e45a69af\" parentID=\"-1\" level=\"1\" writerID=\"0\" nodeType=\"1032\" template=\"0\" sortOrder=\"1\" createDate=\"2012-11-05T16:55:29\" updateDate=\"2012-11-05T16:55:44\" nodeName=\"test12\" urlName=\"test12\" writerName=\"admin\" nodeTypeAlias=\"Image\" path=\"-1,1057\"><umbracoFile>/media/54/tulips.jpg</umbracoFile><umbracoWidth>1024</umbracoWidth><umbracoHeight>768</umbracoHeight><umbracoBytes>620888</umbracoBytes><umbracoExtension>jpg</umbracoExtension><newsCrops><crops date=\"2012-11-05T16:55:34\"><crop name=\"thumbCrop\" x=\"154\" y=\"1\" x2=\"922\" y2=\"768\" url=\"/media/54/tulips_thumbCrop.jpg\" /></crops></newsCrops></Image></mediaItem><mediaItem><Image id=\"1055\" version=\"4df1f08a-3552-45f2-b4bf-fa980c762f4a\" parentID=\"-1\" level=\"1\" writerID=\"0\" nodeType=\"1032\" template=\"0\" sortOrder=\"1\" createDate=\"2012-11-05T16:29:58\" updateDate=\"2012-11-05T16:30:27\" nodeName=\"Test\" urlName=\"test\" writerName=\"admin\" nodeTypeAlias=\"Image\" path=\"-1,1055\"><umbracoFile>/media/41/hydrangeas.jpg</umbracoFile><umbracoWidth>1024</umbracoWidth><umbracoHeight>768</umbracoHeight><umbracoBytes>595284</umbracoBytes><umbracoExtension>jpg</umbracoExtension><newsCrops><crops date=\"2012-11-05T16:30:18\"><crop name=\"thumbCrop\" x=\"133\" y=\"0\" x2=\"902\" y2=\"768\" url=\"/media/41/hydrangeas_thumbCrop.jpg\" /></crops></newsCrops></Image></mediaItem></DAMP>";
|
||||
var dXml = new DynamicXml(xml);
|
||||
var result = dXml.TryConvertTo<XElement>();
|
||||
Assert.IsTrue(result.Success);
|
||||
Assert.AreEqual(xml, result.Result.ToString(SaveOptions.DisableFormatting));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Convert_To_XmlElement()
|
||||
{
|
||||
var xml = "<DAMP fullMedia=\"\" test-attribute=\"someValue\"><mediaItem><Image id=\"1057\" version=\"d58d5c16-153e-4896-892f-a722e45a69af\" parentID=\"-1\" level=\"1\" writerID=\"0\" nodeType=\"1032\" template=\"0\" sortOrder=\"1\" createDate=\"2012-11-05T16:55:29\" updateDate=\"2012-11-05T16:55:44\" nodeName=\"test12\" urlName=\"test12\" writerName=\"admin\" nodeTypeAlias=\"Image\" path=\"-1,1057\"><umbracoFile>/media/54/tulips.jpg</umbracoFile><umbracoWidth>1024</umbracoWidth><umbracoHeight>768</umbracoHeight><umbracoBytes>620888</umbracoBytes><umbracoExtension>jpg</umbracoExtension><newsCrops><crops date=\"2012-11-05T16:55:34\"><crop name=\"thumbCrop\" x=\"154\" y=\"1\" x2=\"922\" y2=\"768\" url=\"/media/54/tulips_thumbCrop.jpg\" /></crops></newsCrops></Image></mediaItem><mediaItem><Image id=\"1055\" version=\"4df1f08a-3552-45f2-b4bf-fa980c762f4a\" parentID=\"-1\" level=\"1\" writerID=\"0\" nodeType=\"1032\" template=\"0\" sortOrder=\"1\" createDate=\"2012-11-05T16:29:58\" updateDate=\"2012-11-05T16:30:27\" nodeName=\"Test\" urlName=\"test\" writerName=\"admin\" nodeTypeAlias=\"Image\" path=\"-1,1055\"><umbracoFile>/media/41/hydrangeas.jpg</umbracoFile><umbracoWidth>1024</umbracoWidth><umbracoHeight>768</umbracoHeight><umbracoBytes>595284</umbracoBytes><umbracoExtension>jpg</umbracoExtension><newsCrops><crops date=\"2012-11-05T16:30:18\"><crop name=\"thumbCrop\" x=\"133\" y=\"0\" x2=\"902\" y2=\"768\" url=\"/media/41/hydrangeas_thumbCrop.jpg\" /></crops></newsCrops></Image></mediaItem></DAMP>";
|
||||
var dXml = new DynamicXml(xml);
|
||||
var result = dXml.TryConvertTo<XmlElement>();
|
||||
Assert.IsTrue(result.Success);
|
||||
Assert.AreEqual(xml, result.Result.OuterXml);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Convert_To_XmlDocument()
|
||||
{
|
||||
var xml = "<DAMP fullMedia=\"\" test-attribute=\"someValue\"><mediaItem><Image id=\"1057\" version=\"d58d5c16-153e-4896-892f-a722e45a69af\" parentID=\"-1\" level=\"1\" writerID=\"0\" nodeType=\"1032\" template=\"0\" sortOrder=\"1\" createDate=\"2012-11-05T16:55:29\" updateDate=\"2012-11-05T16:55:44\" nodeName=\"test12\" urlName=\"test12\" writerName=\"admin\" nodeTypeAlias=\"Image\" path=\"-1,1057\"><umbracoFile>/media/54/tulips.jpg</umbracoFile><umbracoWidth>1024</umbracoWidth><umbracoHeight>768</umbracoHeight><umbracoBytes>620888</umbracoBytes><umbracoExtension>jpg</umbracoExtension><newsCrops><crops date=\"2012-11-05T16:55:34\"><crop name=\"thumbCrop\" x=\"154\" y=\"1\" x2=\"922\" y2=\"768\" url=\"/media/54/tulips_thumbCrop.jpg\" /></crops></newsCrops></Image></mediaItem><mediaItem><Image id=\"1055\" version=\"4df1f08a-3552-45f2-b4bf-fa980c762f4a\" parentID=\"-1\" level=\"1\" writerID=\"0\" nodeType=\"1032\" template=\"0\" sortOrder=\"1\" createDate=\"2012-11-05T16:29:58\" updateDate=\"2012-11-05T16:30:27\" nodeName=\"Test\" urlName=\"test\" writerName=\"admin\" nodeTypeAlias=\"Image\" path=\"-1,1055\"><umbracoFile>/media/41/hydrangeas.jpg</umbracoFile><umbracoWidth>1024</umbracoWidth><umbracoHeight>768</umbracoHeight><umbracoBytes>595284</umbracoBytes><umbracoExtension>jpg</umbracoExtension><newsCrops><crops date=\"2012-11-05T16:30:18\"><crop name=\"thumbCrop\" x=\"133\" y=\"0\" x2=\"902\" y2=\"768\" url=\"/media/41/hydrangeas_thumbCrop.jpg\" /></crops></newsCrops></Image></mediaItem></DAMP>";
|
||||
var dXml = new DynamicXml(xml);
|
||||
var result = dXml.TryConvertTo<XmlDocument>();
|
||||
Assert.IsTrue(result.Success);
|
||||
Assert.AreEqual(xml, result.Result.InnerXml);
|
||||
}
|
||||
|
||||
public override void TestSetup()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void TestTearDown()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.CSharp.RuntimeBinder;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Dynamics;
|
||||
using System.Linq;
|
||||
|
||||
namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
[TestFixture]
|
||||
public class DynamicXmlTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Ensures that when we return the xml structure we get the real structure, not the replaced hyphen structure
|
||||
/// see: http://issues.umbraco.org/issue/U4-1405#comment=67-5113
|
||||
/// http://issues.umbraco.org/issue/U4-1636
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Deals_With_Hyphenated_Values()
|
||||
{
|
||||
var xml = @"<banner1Link>
|
||||
<url-picker some-attribute='Content'>
|
||||
<new-window>True</new-window>
|
||||
<node-id>1161</node-id>
|
||||
<url>/content/</url>
|
||||
<link-title>12 december Zorgbeurs Care</link-title>
|
||||
</url-picker>
|
||||
</banner1Link>";
|
||||
|
||||
var typedXml = new DynamicXml(
|
||||
XmlHelper.StripDashesInElementOrAttributeNames(xml),
|
||||
xml);
|
||||
dynamic dynamicXml = typedXml;
|
||||
|
||||
var typedElement = typedXml.RawXmlElement.Element("url-picker");
|
||||
var dynamicElementByCleanedName = dynamicXml.urlpicker;
|
||||
|
||||
Assert.IsNotNull(typedElement);
|
||||
Assert.IsNotNull(dynamicElementByCleanedName);
|
||||
|
||||
Assert.AreEqual(
|
||||
typedElement.Attribute("some-attribute").Value,
|
||||
dynamicElementByCleanedName.someattribute);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Custom_Extension_Method_Legacy()
|
||||
{
|
||||
var xml = "<DAMP fullMedia=\"\"><mediaItem><Image id=\"1057\" version=\"d58d5c16-153e-4896-892f-a722e45a69af\" parentID=\"-1\" level=\"1\" writerID=\"0\" nodeType=\"1032\" template=\"0\" sortOrder=\"1\" createDate=\"2012-11-05T16:55:29\" updateDate=\"2012-11-05T16:55:44\" nodeName=\"test12\" urlName=\"test12\" writerName=\"admin\" nodeTypeAlias=\"Image\" path=\"-1,1057\"><umbracoFile>/media/54/tulips.jpg</umbracoFile><umbracoWidth>1024</umbracoWidth><umbracoHeight>768</umbracoHeight><umbracoBytes>620888</umbracoBytes><umbracoExtension>jpg</umbracoExtension><newsCrops><crops date=\"2012-11-05T16:55:34\"><crop name=\"thumbCrop\" x=\"154\" y=\"1\" x2=\"922\" y2=\"768\" url=\"/media/54/tulips_thumbCrop.jpg\" /></crops></newsCrops></Image></mediaItem><mediaItem><Image id=\"1055\" version=\"4df1f08a-3552-45f2-b4bf-fa980c762f4a\" parentID=\"-1\" level=\"1\" writerID=\"0\" nodeType=\"1032\" template=\"0\" sortOrder=\"1\" createDate=\"2012-11-05T16:29:58\" updateDate=\"2012-11-05T16:30:27\" nodeName=\"Test\" urlName=\"test\" writerName=\"admin\" nodeTypeAlias=\"Image\" path=\"-1,1055\"><umbracoFile>/media/41/hydrangeas.jpg</umbracoFile><umbracoWidth>1024</umbracoWidth><umbracoHeight>768</umbracoHeight><umbracoBytes>595284</umbracoBytes><umbracoExtension>jpg</umbracoExtension><newsCrops><crops date=\"2012-11-05T16:30:18\"><crop name=\"thumbCrop\" x=\"133\" y=\"0\" x2=\"902\" y2=\"768\" url=\"/media/41/hydrangeas_thumbCrop.jpg\" /></crops></newsCrops></Image></mediaItem></DAMP>";
|
||||
var typedXml = new global::umbraco.MacroEngines.DynamicXml(xml);
|
||||
dynamic dynamicXml = typedXml;
|
||||
|
||||
//we haven't explicitly defined ElementAt so this will dynamically invoke this method
|
||||
var element = dynamicXml.ElementAt(0);
|
||||
|
||||
Assert.AreEqual("1057", Enumerable.First(element.BaseElement.Elements()).Attribute("id").Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Custom_Extension_Method()
|
||||
{
|
||||
var xml = "<DAMP fullMedia=\"\"><mediaItem><Image id=\"1057\" version=\"d58d5c16-153e-4896-892f-a722e45a69af\" parentID=\"-1\" level=\"1\" writerID=\"0\" nodeType=\"1032\" template=\"0\" sortOrder=\"1\" createDate=\"2012-11-05T16:55:29\" updateDate=\"2012-11-05T16:55:44\" nodeName=\"test12\" urlName=\"test12\" writerName=\"admin\" nodeTypeAlias=\"Image\" path=\"-1,1057\"><umbracoFile>/media/54/tulips.jpg</umbracoFile><umbracoWidth>1024</umbracoWidth><umbracoHeight>768</umbracoHeight><umbracoBytes>620888</umbracoBytes><umbracoExtension>jpg</umbracoExtension><newsCrops><crops date=\"2012-11-05T16:55:34\"><crop name=\"thumbCrop\" x=\"154\" y=\"1\" x2=\"922\" y2=\"768\" url=\"/media/54/tulips_thumbCrop.jpg\" /></crops></newsCrops></Image></mediaItem><mediaItem><Image id=\"1055\" version=\"4df1f08a-3552-45f2-b4bf-fa980c762f4a\" parentID=\"-1\" level=\"1\" writerID=\"0\" nodeType=\"1032\" template=\"0\" sortOrder=\"1\" createDate=\"2012-11-05T16:29:58\" updateDate=\"2012-11-05T16:30:27\" nodeName=\"Test\" urlName=\"test\" writerName=\"admin\" nodeTypeAlias=\"Image\" path=\"-1,1055\"><umbracoFile>/media/41/hydrangeas.jpg</umbracoFile><umbracoWidth>1024</umbracoWidth><umbracoHeight>768</umbracoHeight><umbracoBytes>595284</umbracoBytes><umbracoExtension>jpg</umbracoExtension><newsCrops><crops date=\"2012-11-05T16:30:18\"><crop name=\"thumbCrop\" x=\"133\" y=\"0\" x2=\"902\" y2=\"768\" url=\"/media/41/hydrangeas_thumbCrop.jpg\" /></crops></newsCrops></Image></mediaItem></DAMP>";
|
||||
var typedXml = new DynamicXml(xml);
|
||||
|
||||
dynamic dynamicXml = typedXml;
|
||||
|
||||
//we haven't explicitly defined ElementAt so this will dynamically invoke this method
|
||||
var element = dynamicXml.ElementAt(0);
|
||||
|
||||
Assert.AreEqual("1057", Enumerable.First(element.BaseElement.Elements()).Attribute("id").Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Take_Legacy()
|
||||
{
|
||||
var xml = "<DAMP fullMedia=\"\"><mediaItem><Image id=\"1057\" version=\"d58d5c16-153e-4896-892f-a722e45a69af\" parentID=\"-1\" level=\"1\" writerID=\"0\" nodeType=\"1032\" template=\"0\" sortOrder=\"1\" createDate=\"2012-11-05T16:55:29\" updateDate=\"2012-11-05T16:55:44\" nodeName=\"test12\" urlName=\"test12\" writerName=\"admin\" nodeTypeAlias=\"Image\" path=\"-1,1057\"><umbracoFile>/media/54/tulips.jpg</umbracoFile><umbracoWidth>1024</umbracoWidth><umbracoHeight>768</umbracoHeight><umbracoBytes>620888</umbracoBytes><umbracoExtension>jpg</umbracoExtension><newsCrops><crops date=\"2012-11-05T16:55:34\"><crop name=\"thumbCrop\" x=\"154\" y=\"1\" x2=\"922\" y2=\"768\" url=\"/media/54/tulips_thumbCrop.jpg\" /></crops></newsCrops></Image></mediaItem><mediaItem><Image id=\"1055\" version=\"4df1f08a-3552-45f2-b4bf-fa980c762f4a\" parentID=\"-1\" level=\"1\" writerID=\"0\" nodeType=\"1032\" template=\"0\" sortOrder=\"1\" createDate=\"2012-11-05T16:29:58\" updateDate=\"2012-11-05T16:30:27\" nodeName=\"Test\" urlName=\"test\" writerName=\"admin\" nodeTypeAlias=\"Image\" path=\"-1,1055\"><umbracoFile>/media/41/hydrangeas.jpg</umbracoFile><umbracoWidth>1024</umbracoWidth><umbracoHeight>768</umbracoHeight><umbracoBytes>595284</umbracoBytes><umbracoExtension>jpg</umbracoExtension><newsCrops><crops date=\"2012-11-05T16:30:18\"><crop name=\"thumbCrop\" x=\"133\" y=\"0\" x2=\"902\" y2=\"768\" url=\"/media/41/hydrangeas_thumbCrop.jpg\" /></crops></newsCrops></Image></mediaItem></DAMP>";
|
||||
var typedXml = new global::umbraco.MacroEngines.DynamicXml(xml);
|
||||
dynamic dynamicXml = typedXml;
|
||||
var typedTaken = typedXml.Take(1);
|
||||
var dynamicTaken = dynamicXml.Take(1);
|
||||
|
||||
Assert.AreEqual(1, typedTaken.Count());
|
||||
Assert.AreEqual(1, Enumerable.Count(dynamicTaken));
|
||||
|
||||
Assert.AreEqual("1057", typedTaken.ElementAt(0).BaseElement.Elements().First().Attribute("id").Value);
|
||||
Assert.AreEqual("1057", Enumerable.First(Enumerable.ElementAt(dynamicTaken, 0).BaseElement.Elements()).Attribute("id").Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Take()
|
||||
{
|
||||
var xml = "<DAMP fullMedia=\"\"><mediaItem><Image id=\"1057\" version=\"d58d5c16-153e-4896-892f-a722e45a69af\" parentID=\"-1\" level=\"1\" writerID=\"0\" nodeType=\"1032\" template=\"0\" sortOrder=\"1\" createDate=\"2012-11-05T16:55:29\" updateDate=\"2012-11-05T16:55:44\" nodeName=\"test12\" urlName=\"test12\" writerName=\"admin\" nodeTypeAlias=\"Image\" path=\"-1,1057\"><umbracoFile>/media/54/tulips.jpg</umbracoFile><umbracoWidth>1024</umbracoWidth><umbracoHeight>768</umbracoHeight><umbracoBytes>620888</umbracoBytes><umbracoExtension>jpg</umbracoExtension><newsCrops><crops date=\"2012-11-05T16:55:34\"><crop name=\"thumbCrop\" x=\"154\" y=\"1\" x2=\"922\" y2=\"768\" url=\"/media/54/tulips_thumbCrop.jpg\" /></crops></newsCrops></Image></mediaItem><mediaItem><Image id=\"1055\" version=\"4df1f08a-3552-45f2-b4bf-fa980c762f4a\" parentID=\"-1\" level=\"1\" writerID=\"0\" nodeType=\"1032\" template=\"0\" sortOrder=\"1\" createDate=\"2012-11-05T16:29:58\" updateDate=\"2012-11-05T16:30:27\" nodeName=\"Test\" urlName=\"test\" writerName=\"admin\" nodeTypeAlias=\"Image\" path=\"-1,1055\"><umbracoFile>/media/41/hydrangeas.jpg</umbracoFile><umbracoWidth>1024</umbracoWidth><umbracoHeight>768</umbracoHeight><umbracoBytes>595284</umbracoBytes><umbracoExtension>jpg</umbracoExtension><newsCrops><crops date=\"2012-11-05T16:30:18\"><crop name=\"thumbCrop\" x=\"133\" y=\"0\" x2=\"902\" y2=\"768\" url=\"/media/41/hydrangeas_thumbCrop.jpg\" /></crops></newsCrops></Image></mediaItem></DAMP>";
|
||||
var typedXml = new DynamicXml(xml);
|
||||
dynamic dynamicXml = typedXml;
|
||||
var typedTaken = typedXml.Take(1);
|
||||
var dynamicTaken = dynamicXml.Take(1);
|
||||
|
||||
Assert.AreEqual(1, typedTaken.Count());
|
||||
Assert.AreEqual(1, Enumerable.Count(dynamicTaken));
|
||||
|
||||
Assert.AreEqual("1057", typedTaken.ElementAt(0).BaseElement.Elements().First().Attribute("id").Value);
|
||||
Assert.AreEqual("1057", Enumerable.First(Enumerable.ElementAt(dynamicTaken, 0).BaseElement.Elements()).Attribute("id").Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Ensure_Legacy_Objects_Are_Returned()
|
||||
{
|
||||
var xml = "<DAMP fullMedia=\"\"><mediaItem><Image id=\"1057\" version=\"d58d5c16-153e-4896-892f-a722e45a69af\" parentID=\"-1\" level=\"1\" writerID=\"0\" nodeType=\"1032\" template=\"0\" sortOrder=\"1\" createDate=\"2012-11-05T16:55:29\" updateDate=\"2012-11-05T16:55:44\" nodeName=\"test12\" urlName=\"test12\" writerName=\"admin\" nodeTypeAlias=\"Image\" path=\"-1,1057\"><umbracoFile>/media/54/tulips.jpg</umbracoFile><umbracoWidth>1024</umbracoWidth><umbracoHeight>768</umbracoHeight><umbracoBytes>620888</umbracoBytes><umbracoExtension>jpg</umbracoExtension><newsCrops><crops date=\"2012-11-05T16:55:34\"><crop name=\"thumbCrop\" x=\"154\" y=\"1\" x2=\"922\" y2=\"768\" url=\"/media/54/tulips_thumbCrop.jpg\" /></crops></newsCrops></Image></mediaItem><mediaItem><Image id=\"1055\" version=\"4df1f08a-3552-45f2-b4bf-fa980c762f4a\" parentID=\"-1\" level=\"1\" writerID=\"0\" nodeType=\"1032\" template=\"0\" sortOrder=\"1\" createDate=\"2012-11-05T16:29:58\" updateDate=\"2012-11-05T16:30:27\" nodeName=\"Test\" urlName=\"test\" writerName=\"admin\" nodeTypeAlias=\"Image\" path=\"-1,1055\"><umbracoFile>/media/41/hydrangeas.jpg</umbracoFile><umbracoWidth>1024</umbracoWidth><umbracoHeight>768</umbracoHeight><umbracoBytes>595284</umbracoBytes><umbracoExtension>jpg</umbracoExtension><newsCrops><crops date=\"2012-11-05T16:30:18\"><crop name=\"thumbCrop\" x=\"133\" y=\"0\" x2=\"902\" y2=\"768\" url=\"/media/41/hydrangeas_thumbCrop.jpg\" /></crops></newsCrops></Image></mediaItem></DAMP>";
|
||||
var mediaItems = new global::umbraco.MacroEngines.DynamicXml(xml);
|
||||
//Debug.WriteLine("full xml = {0}", mediaItems.ToXml());
|
||||
|
||||
if (mediaItems.Count() != 0)
|
||||
{
|
||||
foreach (dynamic item in mediaItems)
|
||||
{
|
||||
Type itemType = item.GetType();
|
||||
Debug.WriteLine("item type = {0}", itemType);
|
||||
dynamic image = item.Image;
|
||||
|
||||
Type imageType = image.GetType();
|
||||
Debug.WriteLine("image type = {0}", imageType);
|
||||
|
||||
//ensure they are the same
|
||||
Assert.AreEqual(itemType, imageType);
|
||||
|
||||
//ensure they are legacy
|
||||
Assert.AreEqual(typeof(global::umbraco.MacroEngines.DynamicXml), itemType);
|
||||
Assert.AreEqual(typeof(global::umbraco.MacroEngines.DynamicXml), imageType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test the current Core class
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Find_Test_Core_Class()
|
||||
{
|
||||
RunFindTest(x => new DynamicXml(x));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the macroEngines legacy class
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Find_Test_Legacy_Class()
|
||||
{
|
||||
RunFindTest(x => new global::umbraco.MacroEngines.DynamicXml(x));
|
||||
}
|
||||
|
||||
private void RunFindTest(Func<string, dynamic> getDynamicXml)
|
||||
{
|
||||
var xmlstring = @"<test>
|
||||
<item id='1' name='test 1' value='found 1'/>
|
||||
<item id='2' name='test 2' value='found 2'/>
|
||||
<item id='3' name='test 3' value='found 3'/>
|
||||
</test>";
|
||||
|
||||
dynamic dXml = getDynamicXml(xmlstring);
|
||||
|
||||
var result1 = dXml.Find("@name", "test 1");
|
||||
var result2 = dXml.Find("@name", "test 2");
|
||||
var result3 = dXml.Find("@name", "test 3");
|
||||
var result4 = dXml.Find("@name", "dont find");
|
||||
|
||||
Assert.AreEqual("found 1", result1.value);
|
||||
Assert.AreEqual("found 2", result2.value);
|
||||
Assert.AreEqual("found 3", result3.value);
|
||||
Assert.Throws<RuntimeBinderException>(() =>
|
||||
{
|
||||
//this will throw because result4 is not found
|
||||
var temp = result4.value;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Lucene.Net.Documents;
|
||||
using Lucene.Net.Store;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Tests.UmbracoExamine;
|
||||
using umbraco.MacroEngines;
|
||||
|
||||
namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
public class LegacyExamineBackedMediaTests : ExamineBaseTest<LegacyExamineBackedMediaTests>
|
||||
{
|
||||
public override void TestSetup()
|
||||
{
|
||||
base.TestSetup();
|
||||
UmbracoSettings.ForceSafeAliases = true;
|
||||
UmbracoSettings.UmbracoLibraryCacheDuration = 1800;
|
||||
UmbracoSettings.ForceSafeAliases = true;
|
||||
}
|
||||
|
||||
public override void TestTearDown()
|
||||
{
|
||||
base.TestTearDown();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Ensure_Children_Are_Sorted()
|
||||
{
|
||||
using (var luceneDir = new RAMDirectory())
|
||||
{
|
||||
var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
|
||||
indexer.RebuildIndex();
|
||||
|
||||
var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
|
||||
var result = searcher.Search(searcher.CreateSearchCriteria().Id(1111).Compile());
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual(1, result.TotalItemCount);
|
||||
|
||||
var searchItem = result.First();
|
||||
var backedMedia = new ExamineBackedMedia(searchItem, indexer, searcher);
|
||||
var children = backedMedia.ChildrenAsList.Value;
|
||||
|
||||
var currSort = 0;
|
||||
for (var i = 0; i < children.Count(); i++)
|
||||
{
|
||||
Assert.GreaterOrEqual(children[i].SortOrder, currSort);
|
||||
currSort = children[i].SortOrder;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Ensure_Result_Has_All_Values()
|
||||
{
|
||||
using (var luceneDir = new RAMDirectory())
|
||||
{
|
||||
var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
|
||||
indexer.RebuildIndex();
|
||||
|
||||
var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
|
||||
var result = searcher.Search(searcher.CreateSearchCriteria().Id(1111).Compile());
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual(1, result.TotalItemCount);
|
||||
|
||||
var searchItem = result.First();
|
||||
var backedMedia = new ExamineBackedMedia(searchItem, indexer, searcher);
|
||||
|
||||
Assert.AreEqual(searchItem.Id, backedMedia.Id);
|
||||
Assert.AreEqual(searchItem.Fields["sortOrder"], backedMedia.SortOrder.ToString());
|
||||
Assert.AreEqual(searchItem.Fields["urlName"], backedMedia.UrlName);
|
||||
Assert.AreEqual(DateTools.StringToDate(searchItem.Fields["createDate"]), backedMedia.CreateDate);
|
||||
Assert.AreEqual(DateTools.StringToDate(searchItem.Fields["updateDate"]), backedMedia.UpdateDate);
|
||||
Assert.AreEqual(Guid.Parse(searchItem.Fields["version"]), backedMedia.Version);
|
||||
Assert.AreEqual(searchItem.Fields["level"], backedMedia.Level.ToString());
|
||||
Assert.AreEqual(searchItem.Fields["writerID"], backedMedia.WriterID.ToString());
|
||||
Assert.AreEqual(searchItem.Fields["writerID"], backedMedia.CreatorID.ToString()); //there's only writerId in the xml
|
||||
Assert.AreEqual(searchItem.Fields["writerName"], backedMedia.CreatorName);
|
||||
Assert.AreEqual(searchItem.Fields["writerName"], backedMedia.WriterName); //tehre's only writer name in the xml
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Dynamics;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web;
|
||||
|
||||
namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
/// <summary>
|
||||
/// Unit tests for IPublishedContent and extensions
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public class PublishedContentDataTableTests : BaseRoutingTest
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
//need to specify a different callback for testing
|
||||
Umbraco.Web.PublishedContentExtensions.GetPropertyAliasesAndNames = s =>
|
||||
{
|
||||
var userFields = new Dictionary<string, string>()
|
||||
{
|
||||
{"property1", "Property 1"},
|
||||
{"property2", "Property 2"}
|
||||
};
|
||||
if (s == "Child")
|
||||
{
|
||||
userFields.Add("property4", "Property 4");
|
||||
}
|
||||
else
|
||||
{
|
||||
userFields.Add("property3", "Property 3");
|
||||
}
|
||||
|
||||
//ensure the standard fields are there
|
||||
var allFields = new Dictionary<string, string>()
|
||||
{
|
||||
{"Id", "Id"},
|
||||
{"NodeName", "NodeName"},
|
||||
{"NodeTypeAlias", "NodeTypeAlias"},
|
||||
{"CreateDate", "CreateDate"},
|
||||
{"UpdateDate", "UpdateDate"},
|
||||
{"CreatorName", "CreatorName"},
|
||||
{"WriterName", "WriterName"},
|
||||
{"Url", "Url"}
|
||||
};
|
||||
foreach (var f in userFields.Where(f => !allFields.ContainsKey(f.Key)))
|
||||
{
|
||||
allFields.Add(f.Key, f.Value);
|
||||
}
|
||||
return allFields;
|
||||
};
|
||||
var routingContext = GetRoutingContext("/test");
|
||||
|
||||
//set the UmbracoContext.Current since the extension methods rely on it
|
||||
UmbracoContext.Current = routingContext.UmbracoContext;
|
||||
}
|
||||
|
||||
public override void TearDown()
|
||||
{
|
||||
base.TearDown();
|
||||
Umbraco.Web.PublishedContentExtensions.GetPropertyAliasesAndNames = null;
|
||||
UmbracoContext.Current = null;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void To_DataTable()
|
||||
{
|
||||
var doc = GetContent(true, 1);
|
||||
var dt = doc.ChildrenAsTable();
|
||||
|
||||
Assert.AreEqual(11, dt.Columns.Count);
|
||||
Assert.AreEqual(3, dt.Rows.Count);
|
||||
Assert.AreEqual("value4", dt.Rows[0]["Property 1"]);
|
||||
Assert.AreEqual("value5", dt.Rows[0]["Property 2"]);
|
||||
Assert.AreEqual("value6", dt.Rows[0]["Property 4"]);
|
||||
Assert.AreEqual("value7", dt.Rows[1]["Property 1"]);
|
||||
Assert.AreEqual("value8", dt.Rows[1]["Property 2"]);
|
||||
Assert.AreEqual("value9", dt.Rows[1]["Property 4"]);
|
||||
Assert.AreEqual("value10", dt.Rows[2]["Property 1"]);
|
||||
Assert.AreEqual("value11", dt.Rows[2]["Property 2"]);
|
||||
Assert.AreEqual("value12", dt.Rows[2]["Property 4"]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void To_DataTable_With_Filter()
|
||||
{
|
||||
var doc = GetContent(true, 1);
|
||||
//change a doc type alias
|
||||
((TestPublishedContent) doc.Children.ElementAt(0)).DocumentTypeAlias = "DontMatch";
|
||||
|
||||
var dt = doc.ChildrenAsTable("Child");
|
||||
|
||||
Assert.AreEqual(11, dt.Columns.Count);
|
||||
Assert.AreEqual(2, dt.Rows.Count);
|
||||
Assert.AreEqual("value7", dt.Rows[0]["Property 1"]);
|
||||
Assert.AreEqual("value8", dt.Rows[0]["Property 2"]);
|
||||
Assert.AreEqual("value9", dt.Rows[0]["Property 4"]);
|
||||
Assert.AreEqual("value10", dt.Rows[1]["Property 1"]);
|
||||
Assert.AreEqual("value11", dt.Rows[1]["Property 2"]);
|
||||
Assert.AreEqual("value12", dt.Rows[1]["Property 4"]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void To_DataTable_No_Rows()
|
||||
{
|
||||
var doc = GetContent(false, 1);
|
||||
var dt = doc.ChildrenAsTable();
|
||||
//will return an empty data table
|
||||
Assert.AreEqual(0, dt.Columns.Count);
|
||||
Assert.AreEqual(0, dt.Rows.Count);
|
||||
}
|
||||
|
||||
private IPublishedContent GetContent(bool createChildren, int indexVals)
|
||||
{
|
||||
var d = new TestPublishedContent
|
||||
{
|
||||
CreateDate = DateTime.Now,
|
||||
CreatorId = 1,
|
||||
CreatorName = "Shannon",
|
||||
DocumentTypeAlias = createChildren? "Parent" : "Child",
|
||||
DocumentTypeId = 2,
|
||||
Id = 3,
|
||||
SortOrder = 4,
|
||||
TemplateId = 5,
|
||||
UpdateDate = DateTime.Now,
|
||||
Path = "-1,3",
|
||||
UrlName = "home-page",
|
||||
Name = "Page" + Guid.NewGuid().ToString(),
|
||||
Version = Guid.NewGuid(),
|
||||
WriterId = 1,
|
||||
WriterName = "Shannon",
|
||||
Parent = null,
|
||||
Level = 1,
|
||||
Properties = new Collection<IPublishedContentProperty>(
|
||||
new List<IPublishedContentProperty>()
|
||||
{
|
||||
new PropertyResult("property1", "value" + indexVals, Guid.NewGuid(), PropertyResultType.UserProperty),
|
||||
new PropertyResult("property2", "value" + (indexVals + 1), Guid.NewGuid(), PropertyResultType.UserProperty)
|
||||
}),
|
||||
Children = new List<IPublishedContent>()
|
||||
};
|
||||
if (createChildren)
|
||||
{
|
||||
d.Children = new List<IPublishedContent>()
|
||||
{
|
||||
GetContent(false, indexVals + 3),
|
||||
GetContent(false, indexVals + 6),
|
||||
GetContent(false, indexVals + 9)
|
||||
};
|
||||
}
|
||||
if (!createChildren)
|
||||
{
|
||||
//create additional columns, used to test the different columns for child nodes
|
||||
d.Properties.Add(new PropertyResult("property4", "value" + (indexVals + 2), Guid.NewGuid(), PropertyResultType.UserProperty));
|
||||
}
|
||||
else
|
||||
{
|
||||
d.Properties.Add(new PropertyResult("property3", "value" + (indexVals + 2), Guid.NewGuid(), PropertyResultType.UserProperty));
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
private class TestPublishedContent : IPublishedContent
|
||||
{
|
||||
public string Url { get; set; }
|
||||
public PublishedItemType ItemType { get; set; }
|
||||
|
||||
IPublishedContent IPublishedContent.Parent
|
||||
{
|
||||
get { return Parent; }
|
||||
}
|
||||
IEnumerable<IPublishedContent> IPublishedContent.Children
|
||||
{
|
||||
get { return Children; }
|
||||
}
|
||||
public IPublishedContent Parent { get; set; }
|
||||
public int Id { get; set; }
|
||||
public int TemplateId { get; set; }
|
||||
public int SortOrder { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string UrlName { get; set; }
|
||||
public string DocumentTypeAlias { get; set; }
|
||||
public int DocumentTypeId { 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 ICollection<IPublishedContentProperty> Properties { get; set; }
|
||||
|
||||
public object this[string propertyAlias]
|
||||
{
|
||||
get { return GetProperty(propertyAlias).Value; }
|
||||
}
|
||||
|
||||
public IEnumerable<IPublishedContent> Children { get; set; }
|
||||
public IPublishedContentProperty GetProperty(string alias)
|
||||
{
|
||||
return Properties.FirstOrDefault(x => x.Alias.InvariantEquals(alias));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.PublishedCache.XmlPublishedCache;
|
||||
|
||||
namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
/// <summary>
|
||||
/// Abstract base class for tests for published content and published media
|
||||
/// </summary>
|
||||
public abstract class PublishedContentTestBase : BaseRoutingTest
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
UmbracoSettings.SettingsFilePath = Core.IO.IOHelper.MapPath(Core.IO.SystemDirectories.Config + Path.DirectorySeparatorChar, false);
|
||||
|
||||
//need to specify a custom callback for unit tests
|
||||
PublishedContentHelper.GetDataTypeCallback = (docTypeAlias, propertyAlias) =>
|
||||
{
|
||||
if (propertyAlias == "content")
|
||||
{
|
||||
//return the rte type id
|
||||
return Guid.Parse(Constants.PropertyEditors.TinyMCEv3);
|
||||
}
|
||||
return Guid.Empty;
|
||||
};
|
||||
|
||||
var rCtx = GetRoutingContext("/test", 1234);
|
||||
UmbracoContext.Current = rCtx.UmbracoContext;
|
||||
|
||||
}
|
||||
|
||||
protected override void FreezeResolution()
|
||||
{
|
||||
PropertyEditorValueConvertersResolver.Current = new PropertyEditorValueConvertersResolver(
|
||||
new[]
|
||||
{
|
||||
typeof(DatePickerPropertyEditorValueConverter),
|
||||
typeof(TinyMcePropertyEditorValueConverter),
|
||||
typeof(YesNoPropertyEditorValueConverter)
|
||||
});
|
||||
|
||||
PublishedContentCacheResolver.Current = new PublishedContentCacheResolver(new PublishedContentCache());
|
||||
PublishedMediaCacheResolver.Current = new PublishedMediaCacheResolver(new PublishedMediaCache());
|
||||
|
||||
base.FreezeResolution();
|
||||
}
|
||||
|
||||
public override void TearDown()
|
||||
{
|
||||
base.TearDown();
|
||||
|
||||
UmbracoContext.Current = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,491 @@
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web;
|
||||
|
||||
namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests the methods on IPublishedContent using the DefaultPublishedContentStore
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public class PublishedContentTests : PublishedContentTestBase
|
||||
{
|
||||
protected override DatabaseBehavior DatabaseTestBehavior
|
||||
{
|
||||
get { return DatabaseBehavior.NoDatabasePerFixture; }
|
||||
}
|
||||
|
||||
protected override string GetXmlContent(int templateId)
|
||||
{
|
||||
return @"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<!DOCTYPE root[
|
||||
<!ELEMENT Home ANY>
|
||||
<!ATTLIST Home id ID #REQUIRED>
|
||||
<!ELEMENT CustomDocument ANY>
|
||||
<!ATTLIST CustomDocument id ID #REQUIRED>
|
||||
]>
|
||||
<root id=""-1"">
|
||||
<Home id=""1046"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Home"" urlName=""home"" writerName=""admin"" creatorName=""admin"" path=""-1,1046"" isDoc="""">
|
||||
<content><![CDATA[]]></content>
|
||||
<umbracoUrlAlias><![CDATA[this/is/my/alias, anotheralias]]></umbracoUrlAlias>
|
||||
<umbracoNaviHide>1</umbracoNaviHide>
|
||||
<testRecursive><![CDATA[This is the recursive val]]></testRecursive>
|
||||
<Home id=""1173"" parentID=""1046"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-20T18:06:45"" updateDate=""2012-07-20T19:07:31"" nodeName=""Sub1"" urlName=""sub1"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173"" isDoc="""">
|
||||
<content><![CDATA[<div>This is some content</div>]]></content>
|
||||
<umbracoUrlAlias><![CDATA[page2/alias, 2ndpagealias]]></umbracoUrlAlias>
|
||||
<testRecursive><![CDATA[]]></testRecursive>
|
||||
<Home id=""1174"" parentID=""1173"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-20T18:07:54"" updateDate=""2012-07-20T19:10:27"" nodeName=""Sub2"" urlName=""sub2"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1174"" isDoc="""">
|
||||
<content><![CDATA[]]></content>
|
||||
<umbracoUrlAlias><![CDATA[only/one/alias]]></umbracoUrlAlias>
|
||||
<creatorName><![CDATA[Custom data with same property name as the member name]]></creatorName>
|
||||
<testRecursive><![CDATA[]]></testRecursive>
|
||||
</Home>
|
||||
<CustomDocument id=""1177"" parentID=""1173"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1234"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-16T15:26:59"" updateDate=""2012-07-18T14:23:35"" nodeName=""custom sub 1"" urlName=""custom-sub-1"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1177"" isDoc="""" />
|
||||
<CustomDocument id=""1178"" parentID=""1173"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1234"" template=""" + templateId + @""" sortOrder=""3"" createDate=""2012-07-16T15:26:59"" updateDate=""2012-07-16T14:23:35"" nodeName=""custom sub 2"" urlName=""custom-sub-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1178"" isDoc="""" />
|
||||
<Home id=""1176"" parentID=""1173"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""4"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc="""">
|
||||
<content><![CDATA[]]></content>
|
||||
<umbracoNaviHide>1</umbracoNaviHide>
|
||||
</Home>
|
||||
</Home>
|
||||
<Home id=""1175"" parentID=""1046"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-20T18:08:01"" updateDate=""2012-07-20T18:49:32"" nodeName=""Sub 2"" urlName=""sub-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1175"" isDoc=""""><content><![CDATA[]]></content>
|
||||
</Home>
|
||||
<CustomDocument id=""4444"" parentID=""1046"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1234"" template=""" + templateId + @""" sortOrder=""3"" createDate=""2012-07-16T15:26:59"" updateDate=""2012-07-18T14:23:35"" nodeName=""Test"" urlName=""test-page"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,4444"" isDoc="""">
|
||||
<selectedNodes><![CDATA[1172,1176,1173]]></selectedNodes>
|
||||
</CustomDocument>
|
||||
</Home>
|
||||
<CustomDocument id=""1172"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1234"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-16T15:26:59"" updateDate=""2012-07-18T14:23:35"" nodeName=""Test"" urlName=""test-page"" writerName=""admin"" creatorName=""admin"" path=""-1,1172"" isDoc="""" />
|
||||
</root>";
|
||||
}
|
||||
|
||||
internal IPublishedContent GetNode(int id)
|
||||
{
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
var doc = ctx.ContentCache.GetById(id);
|
||||
Assert.IsNotNull(doc);
|
||||
return doc;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Is_Last_From_Where_Filter_Dynamic_Linq()
|
||||
{
|
||||
var doc = GetNode(1173);
|
||||
|
||||
foreach (var d in doc.Children.Where("Visible"))
|
||||
{
|
||||
if (d.Id != 1178)
|
||||
{
|
||||
Assert.IsFalse(d.IsLast());
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsTrue(d.IsLast());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Is_Last_From_Where_Filter()
|
||||
{
|
||||
var doc = GetNode(1173);
|
||||
|
||||
foreach (var d in doc.Children.Where(x => x.IsVisible()))
|
||||
{
|
||||
if (d.Id != 1178)
|
||||
{
|
||||
Assert.IsFalse(d.IsLast());
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsTrue(d.IsLast());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Is_Last_From_Take()
|
||||
{
|
||||
var doc = GetNode(1173);
|
||||
|
||||
foreach (var d in doc.Children.Take(3))
|
||||
{
|
||||
if (d.Id != 1178)
|
||||
{
|
||||
Assert.IsFalse(d.IsLast());
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsTrue(d.IsLast());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Is_Last_From_Skip()
|
||||
{
|
||||
var doc = GetNode(1173);
|
||||
|
||||
foreach (var d in doc.Children.Skip(1))
|
||||
{
|
||||
if (d.Id != 1176)
|
||||
{
|
||||
Assert.IsFalse(d.IsLast());
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsTrue(d.IsLast());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Is_Last_From_Concat()
|
||||
{
|
||||
var doc = GetNode(1173);
|
||||
|
||||
|
||||
foreach (var d in doc.Children.Concat(new[] { GetNode(1175), GetNode(4444) }))
|
||||
{
|
||||
if (d.Id != 4444)
|
||||
{
|
||||
Assert.IsFalse(d.IsLast());
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsTrue(d.IsLast());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Descendants_Ordered_Properly()
|
||||
{
|
||||
var doc = GetNode(1046);
|
||||
|
||||
var currentLevel = 0;
|
||||
var lastSortOrder = 0;
|
||||
var levelChangesAt = new[] { 1046, 1173, 1174 };
|
||||
|
||||
foreach (var d in doc.DescendantsOrSelf())
|
||||
{
|
||||
if (levelChangesAt.Contains(d.Id))
|
||||
{
|
||||
Assert.Greater(d.Level, currentLevel);
|
||||
currentLevel = d.Level;
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.AreEqual(currentLevel, d.Level);
|
||||
Assert.Greater(d.SortOrder, lastSortOrder);
|
||||
}
|
||||
lastSortOrder = d.SortOrder;
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_Get_Recursive_Val()
|
||||
{
|
||||
var doc = GetNode(1174);
|
||||
var rVal = doc.GetRecursiveValue("testRecursive");
|
||||
var nullVal = doc.GetRecursiveValue("DoNotFindThis");
|
||||
Assert.AreEqual("This is the recursive val", rVal);
|
||||
Assert.AreEqual("", nullVal);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_Property_Value_Uses_Converter()
|
||||
{
|
||||
var doc = GetNode(1173);
|
||||
|
||||
var propVal = doc.GetPropertyValue("content");
|
||||
Assert.IsTrue(TypeHelper.IsTypeAssignableFrom<IHtmlString>(propVal.GetType()));
|
||||
Assert.AreEqual("<div>This is some content</div>", propVal.ToString());
|
||||
|
||||
var propVal2 = doc.GetPropertyValue<IHtmlString>("content");
|
||||
Assert.IsTrue(TypeHelper.IsTypeAssignableFrom<IHtmlString>(propVal2.GetType()));
|
||||
Assert.AreEqual("<div>This is some content</div>", propVal2.ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Complex_Linq()
|
||||
{
|
||||
var doc = GetNode(1173);
|
||||
|
||||
var result = doc.Ancestors().OrderBy(x => x.Level)
|
||||
.Single()
|
||||
.Descendants()
|
||||
.FirstOrDefault(x => x.GetPropertyValue<string>("selectedNodes", "").Split(',').Contains("1173"));
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Index()
|
||||
{
|
||||
var doc = GetNode(1173);
|
||||
Assert.AreEqual(0, doc.Index());
|
||||
doc = GetNode(1176);
|
||||
Assert.AreEqual(3, doc.Index());
|
||||
doc = GetNode(1177);
|
||||
Assert.AreEqual(1, doc.Index());
|
||||
doc = GetNode(1178);
|
||||
Assert.AreEqual(2, doc.Index());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Is_First()
|
||||
{
|
||||
var doc = GetNode(1046); //test root nodes
|
||||
Assert.IsTrue(doc.IsFirst());
|
||||
doc = GetNode(1172);
|
||||
Assert.IsFalse(doc.IsFirst());
|
||||
doc = GetNode(1173); //test normal nodes
|
||||
Assert.IsTrue(doc.IsFirst());
|
||||
doc = GetNode(1175);
|
||||
Assert.IsFalse(doc.IsFirst());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Is_Not_First()
|
||||
{
|
||||
var doc = GetNode(1046); //test root nodes
|
||||
Assert.IsFalse(doc.IsNotFirst());
|
||||
doc = GetNode(1172);
|
||||
Assert.IsTrue(doc.IsNotFirst());
|
||||
doc = GetNode(1173); //test normal nodes
|
||||
Assert.IsFalse(doc.IsNotFirst());
|
||||
doc = GetNode(1175);
|
||||
Assert.IsTrue(doc.IsNotFirst());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Is_Position()
|
||||
{
|
||||
var doc = GetNode(1046); //test root nodes
|
||||
Assert.IsTrue(doc.IsPosition(0));
|
||||
doc = GetNode(1172);
|
||||
Assert.IsTrue(doc.IsPosition(1));
|
||||
doc = GetNode(1173); //test normal nodes
|
||||
Assert.IsTrue(doc.IsPosition(0));
|
||||
doc = GetNode(1175);
|
||||
Assert.IsTrue(doc.IsPosition(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Children_GroupBy_DocumentTypeAlias()
|
||||
{
|
||||
var doc = GetNode(1046);
|
||||
|
||||
var found1 = doc.Children.GroupBy("DocumentTypeAlias");
|
||||
|
||||
Assert.AreEqual(2, found1.Count());
|
||||
Assert.AreEqual(2, found1.Single(x => x.Key.ToString() == "Home").Count());
|
||||
Assert.AreEqual(1, found1.Single(x => x.Key.ToString() == "CustomDocument").Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Children_Where_DocumentTypeAlias()
|
||||
{
|
||||
var doc = GetNode(1046);
|
||||
|
||||
var found1 = doc.Children.Where("DocumentTypeAlias == \"CustomDocument\"");
|
||||
var found2 = doc.Children.Where("DocumentTypeAlias == \"Home\"");
|
||||
|
||||
Assert.AreEqual(1, found1.Count());
|
||||
Assert.AreEqual(2, found2.Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Children_Order_By_Update_Date()
|
||||
{
|
||||
var doc = GetNode(1173);
|
||||
|
||||
var ordered = doc.Children.OrderBy("UpdateDate");
|
||||
|
||||
var correctOrder = new[] { 1178, 1177, 1174, 1176 };
|
||||
for (var i = 0; i < correctOrder.Length; i++)
|
||||
{
|
||||
Assert.AreEqual(correctOrder[i], ordered.ElementAt(i).Id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HasProperty()
|
||||
{
|
||||
var doc = GetNode(1173);
|
||||
|
||||
var hasProp = doc.HasProperty(Constants.Conventions.Content.UrlAlias);
|
||||
|
||||
Assert.AreEqual(true, (bool)hasProp);
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void HasValue()
|
||||
{
|
||||
var doc = GetNode(1173);
|
||||
|
||||
var hasValue = doc.HasValue(Constants.Conventions.Content.UrlAlias);
|
||||
var noValue = doc.HasValue("blahblahblah");
|
||||
|
||||
Assert.IsTrue(hasValue);
|
||||
Assert.IsFalse(noValue);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Ancestors_Where_Visible()
|
||||
{
|
||||
var doc = GetNode(1174);
|
||||
|
||||
var whereVisible = doc.Ancestors().Where("Visible");
|
||||
|
||||
Assert.AreEqual(1, whereVisible.Count());
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Visible()
|
||||
{
|
||||
var hidden = GetNode(1046);
|
||||
var visible = GetNode(1173);
|
||||
|
||||
Assert.IsFalse(hidden.IsVisible());
|
||||
Assert.IsTrue(visible.IsVisible());
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Ancestor_Or_Self()
|
||||
{
|
||||
var doc = GetNode(1173);
|
||||
|
||||
var result = doc.AncestorOrSelf();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
|
||||
Assert.AreEqual((int)1046, (int)result.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Ancestors_Or_Self()
|
||||
{
|
||||
var doc = GetNode(1174);
|
||||
|
||||
var result = doc.AncestorsOrSelf();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
|
||||
Assert.AreEqual(3, result.Count());
|
||||
Assert.IsTrue(result.Select(x => ((dynamic)x).Id).ContainsAll(new dynamic[] { 1174, 1173, 1046 }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Ancestors()
|
||||
{
|
||||
var doc = GetNode(1174);
|
||||
|
||||
var result = doc.Ancestors();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
|
||||
Assert.AreEqual(2, result.Count());
|
||||
Assert.IsTrue(result.Select(x => ((dynamic)x).Id).ContainsAll(new dynamic[] { 1173, 1046 }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Descendants_Or_Self()
|
||||
{
|
||||
var doc = GetNode(1046);
|
||||
|
||||
var result = doc.DescendantsOrSelf();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
|
||||
Assert.AreEqual(8, result.Count());
|
||||
Assert.IsTrue(result.Select(x => ((dynamic)x).Id).ContainsAll(new dynamic[] { 1046, 1173, 1174, 1176, 1175 }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Descendants()
|
||||
{
|
||||
var doc = GetNode(1046);
|
||||
|
||||
var result = doc.Descendants();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
|
||||
Assert.AreEqual(7, result.Count());
|
||||
Assert.IsTrue(result.Select(x => ((dynamic)x).Id).ContainsAll(new dynamic[] { 1173, 1174, 1176, 1175, 4444 }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Up()
|
||||
{
|
||||
var doc = GetNode(1173);
|
||||
|
||||
var result = doc.Up();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
|
||||
Assert.AreEqual((int)1046, (int)result.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Down()
|
||||
{
|
||||
var doc = GetNode(1173);
|
||||
|
||||
var result = doc.Down();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
|
||||
Assert.AreEqual((int)1174, (int)result.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Next()
|
||||
{
|
||||
var doc = GetNode(1173);
|
||||
|
||||
var result = doc.Next();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
|
||||
Assert.AreEqual((int)1175, (int)result.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Next_Without_Sibling()
|
||||
{
|
||||
var doc = GetNode(1176);
|
||||
|
||||
Assert.IsNull(doc.Next());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Previous_Without_Sibling()
|
||||
{
|
||||
var doc = GetNode(1173);
|
||||
|
||||
Assert.IsNull(doc.Previous());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Previous()
|
||||
{
|
||||
var doc = GetNode(1176);
|
||||
|
||||
var result = doc.Previous();
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
|
||||
Assert.AreEqual((int)1178, (int)result.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,387 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml.Linq;
|
||||
using System.Xml.XPath;
|
||||
using Examine;
|
||||
using Examine.LuceneEngine;
|
||||
using Examine.LuceneEngine.Providers;
|
||||
using Lucene.Net.Analysis.Standard;
|
||||
using Lucene.Net.Store;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.UmbracoExamine;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.PublishedCache.XmlPublishedCache;
|
||||
using UmbracoExamine;
|
||||
using UmbracoExamine.DataServices;
|
||||
using umbraco.BusinessLogic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests the typed extension methods on IPublishedContent using the DefaultPublishedMediaStore
|
||||
/// </summary>
|
||||
[TestFixture, RequiresSTA]
|
||||
public class PublishedMediaTests : PublishedContentTestBase
|
||||
{
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
UmbracoExamineSearcher.DisableInitializationCheck = true;
|
||||
BaseUmbracoIndexer.DisableInitializationCheck = true;
|
||||
UmbracoSettings.ForceSafeAliases = true;
|
||||
UmbracoSettings.UmbracoLibraryCacheDuration = 1800;
|
||||
UmbracoSettings.ForceSafeAliases = true;
|
||||
}
|
||||
|
||||
public override void TearDown()
|
||||
{
|
||||
base.TearDown();
|
||||
UmbracoExamineSearcher.DisableInitializationCheck = null;
|
||||
BaseUmbracoIndexer.DisableInitializationCheck = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shared with PublishMediaStoreTests
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="umbracoContext"></param>
|
||||
/// <returns></returns>
|
||||
internal static IPublishedContent GetNode(int id, UmbracoContext umbracoContext)
|
||||
{
|
||||
var ctx = umbracoContext;
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(), ctx);
|
||||
var doc = cache.GetById(id);
|
||||
Assert.IsNotNull(doc);
|
||||
return doc;
|
||||
}
|
||||
|
||||
private IPublishedContent GetNode(int id)
|
||||
{
|
||||
return GetNode(id, GetUmbracoContext("/test", 1234));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Ensure_Children_Sorted_With_Examine()
|
||||
{
|
||||
using (var luceneDir = new RAMDirectory())
|
||||
{
|
||||
var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
|
||||
indexer.RebuildIndex();
|
||||
var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);
|
||||
|
||||
//we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
|
||||
var publishedMedia = cache.GetById(1111);
|
||||
var rootChildren = publishedMedia.Children().ToArray();
|
||||
var currSort = 0;
|
||||
for (var i = 0; i < rootChildren.Count(); i++)
|
||||
{
|
||||
Assert.GreaterOrEqual(rootChildren[i].SortOrder, currSort);
|
||||
currSort = rootChildren[i].SortOrder;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Do_Not_Find_In_Recycle_Bin()
|
||||
{
|
||||
using (var luceneDir = new RAMDirectory())
|
||||
{
|
||||
var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
|
||||
indexer.RebuildIndex();
|
||||
var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);
|
||||
|
||||
//ensure it is found
|
||||
var publishedMedia = cache.GetById(3113);
|
||||
Assert.IsNotNull(publishedMedia);
|
||||
|
||||
//move item to recycle bin
|
||||
var newXml = XElement.Parse(@"<node id='3113' version='5b3e46ab-3e37-4cfa-ab70-014234b5bd33' parentID='-21' level='1' writerID='0' nodeType='1032' template='0' sortOrder='2' createDate='2010-05-19T17:32:46' updateDate='2010-05-19T17:32:46' nodeName='Another Umbraco Image' urlName='acnestressscrub' writerName='Administrator' nodeTypeAlias='Image' path='-1,-21,3113'>
|
||||
<data alias='umbracoFile'><![CDATA[/media/1234/blah.pdf]]></data>
|
||||
<data alias='umbracoWidth'>115</data>
|
||||
<data alias='umbracoHeight'>268</data>
|
||||
<data alias='umbracoBytes'>10726</data>
|
||||
<data alias='umbracoExtension'>jpg</data>
|
||||
</node>");
|
||||
indexer.ReIndexNode(newXml, "media");
|
||||
|
||||
//ensure it still exists in the index (raw examine search)
|
||||
var criteria = searcher.CreateSearchCriteria();
|
||||
var filter = criteria.Id(3113);
|
||||
var found = searcher.Search(filter.Compile());
|
||||
Assert.IsNotNull(found);
|
||||
Assert.AreEqual(1, found.TotalItemCount);
|
||||
|
||||
//ensure it does not show up in the published media store
|
||||
var recycledMedia = cache.GetById(3113);
|
||||
Assert.IsNull(recycledMedia);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Children_With_Examine()
|
||||
{
|
||||
using (var luceneDir = new RAMDirectory())
|
||||
{
|
||||
var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
|
||||
indexer.RebuildIndex();
|
||||
var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);
|
||||
|
||||
//we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
|
||||
var publishedMedia = cache.GetById(1111);
|
||||
var rootChildren = publishedMedia.Children();
|
||||
Assert.IsTrue(rootChildren.Select(x => x.Id).ContainsAll(new[] { 2222, 1113, 1114, 1115, 1116 }));
|
||||
|
||||
var publishedChild1 = cache.GetById(2222);
|
||||
var subChildren = publishedChild1.Children();
|
||||
Assert.IsTrue(subChildren.Select(x => x.Id).ContainsAll(new[] { 2112 }));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Descendants_With_Examine()
|
||||
{
|
||||
using (var luceneDir = new RAMDirectory())
|
||||
{
|
||||
var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
|
||||
indexer.RebuildIndex();
|
||||
var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);
|
||||
|
||||
//we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
|
||||
var publishedMedia = cache.GetById(1111);
|
||||
var rootDescendants = publishedMedia.Descendants();
|
||||
Assert.IsTrue(rootDescendants.Select(x => x.Id).ContainsAll(new[] { 2112, 2222, 1113, 1114, 1115, 1116 }));
|
||||
|
||||
var publishedChild1 = cache.GetById(2222);
|
||||
var subDescendants = publishedChild1.Descendants();
|
||||
Assert.IsTrue(subDescendants.Select(x => x.Id).ContainsAll(new[] { 2112, 3113 }));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DescendantsOrSelf_With_Examine()
|
||||
{
|
||||
using (var luceneDir = new RAMDirectory())
|
||||
{
|
||||
var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
|
||||
indexer.RebuildIndex();
|
||||
var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);
|
||||
|
||||
//we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
|
||||
var publishedMedia = cache.GetById(1111);
|
||||
var rootDescendants = publishedMedia.DescendantsOrSelf();
|
||||
Assert.IsTrue(rootDescendants.Select(x => x.Id).ContainsAll(new[] { 1111, 2112, 2222, 1113, 1114, 1115, 1116 }));
|
||||
|
||||
var publishedChild1 = cache.GetById(2222);
|
||||
var subDescendants = publishedChild1.DescendantsOrSelf();
|
||||
Assert.IsTrue(subDescendants.Select(x => x.Id).ContainsAll(new[] { 2222, 2112, 3113 }));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Ancestors_With_Examine()
|
||||
{
|
||||
using (var luceneDir = new RAMDirectory())
|
||||
{
|
||||
var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
|
||||
indexer.RebuildIndex();
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);
|
||||
|
||||
//we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
|
||||
var publishedMedia = cache.GetById(3113);
|
||||
var ancestors = publishedMedia.Ancestors();
|
||||
Assert.IsTrue(ancestors.Select(x => x.Id).ContainsAll(new[] { 2112, 2222, 1111 }));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AncestorsOrSelf_With_Examine()
|
||||
{
|
||||
using (var luceneDir = new RAMDirectory())
|
||||
{
|
||||
var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
|
||||
indexer.RebuildIndex();
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);
|
||||
|
||||
//we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
|
||||
var publishedMedia = cache.GetById(3113);
|
||||
var ancestors = publishedMedia.AncestorsOrSelf();
|
||||
Assert.IsTrue(ancestors.Select(x => x.Id).ContainsAll(new[] { 3113, 2112, 2222, 1111 }));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Children_Without_Examine()
|
||||
{
|
||||
var user = new User(0);
|
||||
var mType = global::umbraco.cms.businesslogic.media.MediaType.MakeNew(user, "TestMediaType");
|
||||
var mRoot = global::umbraco.cms.businesslogic.media.Media.MakeNew("MediaRoot", mType, user, -1);
|
||||
|
||||
var mChild1 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child1", mType, user, mRoot.Id);
|
||||
var mChild2 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child2", mType, user, mRoot.Id);
|
||||
var mChild3 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child3", mType, user, mRoot.Id);
|
||||
|
||||
var mSubChild1 = global::umbraco.cms.businesslogic.media.Media.MakeNew("SubChild1", mType, user, mChild1.Id);
|
||||
var mSubChild2 = global::umbraco.cms.businesslogic.media.Media.MakeNew("SubChild2", mType, user, mChild1.Id);
|
||||
var mSubChild3 = global::umbraco.cms.businesslogic.media.Media.MakeNew("SubChild3", mType, user, mChild1.Id);
|
||||
|
||||
var publishedMedia = GetNode(mRoot.Id);
|
||||
var rootChildren = publishedMedia.Children();
|
||||
Assert.IsTrue(rootChildren.Select(x => x.Id).ContainsAll(new[] { mChild1.Id, mChild2.Id, mChild3.Id }));
|
||||
|
||||
var publishedChild1 = GetNode(mChild1.Id);
|
||||
var subChildren = publishedChild1.Children();
|
||||
Assert.IsTrue(subChildren.Select(x => x.Id).ContainsAll(new[] { mSubChild1.Id, mSubChild2.Id, mSubChild3.Id }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Descendants_Without_Examine()
|
||||
{
|
||||
var user = new User(0);
|
||||
var mType = global::umbraco.cms.businesslogic.media.MediaType.MakeNew(user, "TestMediaType");
|
||||
var mRoot = global::umbraco.cms.businesslogic.media.Media.MakeNew("MediaRoot", mType, user, -1);
|
||||
|
||||
var mChild1 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child1", mType, user, mRoot.Id);
|
||||
var mChild2 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child2", mType, user, mRoot.Id);
|
||||
var mChild3 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child3", mType, user, mRoot.Id);
|
||||
|
||||
var mSubChild1 = global::umbraco.cms.businesslogic.media.Media.MakeNew("SubChild1", mType, user, mChild1.Id);
|
||||
var mSubChild2 = global::umbraco.cms.businesslogic.media.Media.MakeNew("SubChild2", mType, user, mChild1.Id);
|
||||
var mSubChild3 = global::umbraco.cms.businesslogic.media.Media.MakeNew("SubChild3", mType, user, mChild1.Id);
|
||||
|
||||
var publishedMedia = GetNode(mRoot.Id);
|
||||
var rootDescendants = publishedMedia.Descendants();
|
||||
Assert.IsTrue(rootDescendants.Select(x => x.Id).ContainsAll(new[] { mChild1.Id, mChild2.Id, mChild3.Id, mSubChild1.Id, mSubChild2.Id, mSubChild3.Id }));
|
||||
|
||||
var publishedChild1 = GetNode(mChild1.Id);
|
||||
var subDescendants = publishedChild1.Descendants();
|
||||
Assert.IsTrue(subDescendants.Select(x => x.Id).ContainsAll(new[] { mSubChild1.Id, mSubChild2.Id, mSubChild3.Id }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DescendantsOrSelf_Without_Examine()
|
||||
{
|
||||
var user = new User(0);
|
||||
var mType = global::umbraco.cms.businesslogic.media.MediaType.MakeNew(user, "TestMediaType");
|
||||
var mRoot = global::umbraco.cms.businesslogic.media.Media.MakeNew("MediaRoot", mType, user, -1);
|
||||
|
||||
var mChild1 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child1", mType, user, mRoot.Id);
|
||||
var mChild2 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child2", mType, user, mRoot.Id);
|
||||
var mChild3 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child3", mType, user, mRoot.Id);
|
||||
|
||||
var mSubChild1 = global::umbraco.cms.businesslogic.media.Media.MakeNew("SubChild1", mType, user, mChild1.Id);
|
||||
var mSubChild2 = global::umbraco.cms.businesslogic.media.Media.MakeNew("SubChild2", mType, user, mChild1.Id);
|
||||
var mSubChild3 = global::umbraco.cms.businesslogic.media.Media.MakeNew("SubChild3", mType, user, mChild1.Id);
|
||||
|
||||
var publishedMedia = GetNode(mRoot.Id);
|
||||
var rootDescendantsOrSelf = publishedMedia.DescendantsOrSelf();
|
||||
Assert.IsTrue(rootDescendantsOrSelf.Select(x => x.Id).ContainsAll(
|
||||
new[] { mRoot.Id, mChild1.Id, mChild2.Id, mChild3.Id, mSubChild1.Id, mSubChild2.Id, mSubChild3.Id }));
|
||||
|
||||
var publishedChild1 = GetNode(mChild1.Id);
|
||||
var subDescendantsOrSelf = publishedChild1.DescendantsOrSelf();
|
||||
Assert.IsTrue(subDescendantsOrSelf.Select(x => x.Id).ContainsAll(
|
||||
new[] { mChild1.Id, mSubChild1.Id, mSubChild2.Id, mSubChild3.Id }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Parent_Without_Examine()
|
||||
{
|
||||
var user = new User(0);
|
||||
var mType = global::umbraco.cms.businesslogic.media.MediaType.MakeNew(user, "TestMediaType");
|
||||
var mRoot = global::umbraco.cms.businesslogic.media.Media.MakeNew("MediaRoot", mType, user, -1);
|
||||
|
||||
var mChild1 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child1", mType, user, mRoot.Id);
|
||||
var mChild2 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child2", mType, user, mRoot.Id);
|
||||
var mChild3 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child3", mType, user, mRoot.Id);
|
||||
|
||||
var mSubChild1 = global::umbraco.cms.businesslogic.media.Media.MakeNew("SubChild1", mType, user, mChild1.Id);
|
||||
var mSubChild2 = global::umbraco.cms.businesslogic.media.Media.MakeNew("SubChild2", mType, user, mChild1.Id);
|
||||
var mSubChild3 = global::umbraco.cms.businesslogic.media.Media.MakeNew("SubChild3", mType, user, mChild1.Id);
|
||||
|
||||
var publishedRoot = GetNode(mRoot.Id);
|
||||
Assert.AreEqual(null, publishedRoot.Parent);
|
||||
|
||||
var publishedChild1 = GetNode(mChild1.Id);
|
||||
Assert.AreEqual(mRoot.Id, publishedChild1.Parent.Id);
|
||||
|
||||
var publishedSubChild1 = GetNode(mSubChild1.Id);
|
||||
Assert.AreEqual(mChild1.Id, publishedSubChild1.Parent.Id);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Ancestors_Without_Examine()
|
||||
{
|
||||
var user = new User(0);
|
||||
var mType = global::umbraco.cms.businesslogic.media.MediaType.MakeNew(user, "TestMediaType");
|
||||
var mRoot = global::umbraco.cms.businesslogic.media.Media.MakeNew("MediaRoot", mType, user, -1);
|
||||
|
||||
var mChild1 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child1", mType, user, mRoot.Id);
|
||||
var mChild2 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child2", mType, user, mRoot.Id);
|
||||
var mChild3 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child3", mType, user, mRoot.Id);
|
||||
|
||||
var mSubChild1 = global::umbraco.cms.businesslogic.media.Media.MakeNew("SubChild1", mType, user, mChild1.Id);
|
||||
var mSubChild2 = global::umbraco.cms.businesslogic.media.Media.MakeNew("SubChild2", mType, user, mChild1.Id);
|
||||
var mSubChild3 = global::umbraco.cms.businesslogic.media.Media.MakeNew("SubChild3", mType, user, mChild1.Id);
|
||||
|
||||
var publishedSubChild1 = GetNode(mSubChild1.Id);
|
||||
Assert.IsTrue(publishedSubChild1.Ancestors().Select(x => x.Id).ContainsAll(new[] { mChild1.Id, mRoot.Id }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AncestorsOrSelf_Without_Examine()
|
||||
{
|
||||
var user = new User(0);
|
||||
var mType = global::umbraco.cms.businesslogic.media.MediaType.MakeNew(user, "TestMediaType");
|
||||
var mRoot = global::umbraco.cms.businesslogic.media.Media.MakeNew("MediaRoot", mType, user, -1);
|
||||
|
||||
var mChild1 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child1", mType, user, mRoot.Id);
|
||||
var mChild2 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child2", mType, user, mRoot.Id);
|
||||
var mChild3 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child3", mType, user, mRoot.Id);
|
||||
|
||||
var mSubChild1 = global::umbraco.cms.businesslogic.media.Media.MakeNew("SubChild1", mType, user, mChild1.Id);
|
||||
var mSubChild2 = global::umbraco.cms.businesslogic.media.Media.MakeNew("SubChild2", mType, user, mChild1.Id);
|
||||
var mSubChild3 = global::umbraco.cms.businesslogic.media.Media.MakeNew("SubChild3", mType, user, mChild1.Id);
|
||||
|
||||
var publishedSubChild1 = GetNode(mSubChild1.Id);
|
||||
Assert.IsTrue(publishedSubChild1.AncestorsOrSelf().Select(x => x.Id).ContainsAll(
|
||||
new[] { mSubChild1.Id, mChild1.Id, mRoot.Id }));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,432 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.PublishedCache.XmlPublishedCache;
|
||||
|
||||
namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
[TestFixture]
|
||||
public class StronglyTypedQueryTests : PublishedContentTestBase
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
}
|
||||
|
||||
public override void TearDown()
|
||||
{
|
||||
base.TearDown();
|
||||
}
|
||||
|
||||
protected override DatabaseBehavior DatabaseTestBehavior
|
||||
{
|
||||
get { return DatabaseBehavior.NoDatabasePerFixture; }
|
||||
}
|
||||
|
||||
protected override string GetXmlContent(int templateId)
|
||||
{
|
||||
return @"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<!DOCTYPE root[
|
||||
<!ELEMENT Home ANY>
|
||||
<!ATTLIST Home id ID #REQUIRED>
|
||||
<!ELEMENT NewsArticle ANY>
|
||||
<!ATTLIST NewsArticle id ID #REQUIRED>
|
||||
<!ELEMENT NewsLandingPage ANY>
|
||||
<!ATTLIST NewsLandingPage id ID #REQUIRED>
|
||||
<!ELEMENT ContentPage ANY>
|
||||
<!ATTLIST ContentPage id ID #REQUIRED>
|
||||
]>
|
||||
<root id=""-1"">
|
||||
<Home id=""1"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""10"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Home"" urlName=""home"" writerName=""admin"" creatorName=""admin"" path=""-1,1"" isDoc="""">
|
||||
<siteName><![CDATA[Test site]]></siteName>
|
||||
<siteDescription><![CDATA[this is a test site]]></siteDescription>
|
||||
<bodyContent><![CDATA[This is some body content on the home page]]></bodyContent>
|
||||
<NewsLandingPage id=""2"" parentID=""1"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""11"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-20T18:06:45"" updateDate=""2012-07-20T19:07:31"" nodeName=""news"" urlName=""news"" writerName=""admin"" creatorName=""admin"" path=""-1,1,2"" isDoc="""">
|
||||
<bodyContent><![CDATA[This is some body content on the news landing page]]></bodyContent>
|
||||
<pageTitle><![CDATA[page2/alias, 2ndpagealias]]></pageTitle>
|
||||
<NewsArticle id=""3"" parentID=""2"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""12"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-20T18:07:54"" updateDate=""2012-07-20T19:10:27"" nodeName=""Something happened"" urlName=""something-happened"" writerName=""admin"" creatorName=""admin"" path=""-1,1,2,3"" isDoc="""">
|
||||
<articleContent><![CDATA[Some cool stuff happened today]]></articleContent>
|
||||
<articleDate><![CDATA[2012-01-02 12:33:44]]></articleDate>
|
||||
<articleAuthor><![CDATA[John doe]]></articleAuthor>
|
||||
</NewsArticle>
|
||||
<NewsArticle id=""4"" parentID=""2"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""12"" template=""" + templateId + @""" sortOrder=""3"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Then another thing"" urlName=""then-another-thing"" writerName=""admin"" creatorName=""admin"" path=""-1,1,2,4"" isDoc="""">
|
||||
<articleContent><![CDATA[Today, other cool things occurred]]></articleContent>
|
||||
<articleDate><![CDATA[2012-01-03 15:33:44]]></articleDate>
|
||||
<articleAuthor><![CDATA[John Smith]]></articleAuthor>
|
||||
</NewsArticle>
|
||||
</NewsLandingPage>
|
||||
<ContentPage id=""5"" parentID=""1"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""13"" template=""" + templateId + @""" sortOrder=""4"" createDate=""2012-07-16T15:26:59"" updateDate=""2012-07-18T14:23:35"" nodeName=""First Content Page"" urlName=""content-page-1"" writerName=""admin"" creatorName=""admin"" path=""-1,1,5"" isDoc="""">
|
||||
<bodyContent><![CDATA[This is some body content on the first content page]]></bodyContent>
|
||||
</ContentPage>
|
||||
<ContentPage id=""6"" parentID=""1"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""13"" template=""" + templateId + @""" sortOrder=""4"" createDate=""2012-07-16T15:26:59"" updateDate=""2012-07-16T14:23:35"" nodeName=""Second Content Page"" urlName=""content-page-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1,6"" isDoc="""">
|
||||
<bodyContent><![CDATA[This is some body content on the second content page]]></bodyContent>
|
||||
</ContentPage>
|
||||
</Home>
|
||||
</root>";
|
||||
}
|
||||
|
||||
internal IPublishedContent GetNode(int id)
|
||||
{
|
||||
var ctx = UmbracoContext.Current;
|
||||
var doc = ctx.ContentCache.GetById(id);
|
||||
Assert.IsNotNull(doc);
|
||||
return doc;
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Type_Test()
|
||||
{
|
||||
var doc = GetNode(1);
|
||||
var result = doc.NewsArticles(TraversalType.Descendants).ToArray();
|
||||
Assert.AreEqual("John doe", result[0].ArticleAuthor);
|
||||
Assert.AreEqual("John Smith", result[1].ArticleAuthor);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void As_Test()
|
||||
{
|
||||
var doc = GetNode(1);
|
||||
var result = doc.AsHome();
|
||||
Assert.AreEqual("Test site", result.SiteName);
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() => doc.AsContentPage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//NOTE: Some of these class will be moved in to the core once all this is working the way we want
|
||||
|
||||
#region Gen classes & supporting classes
|
||||
|
||||
//TOOD: SD: This class could be the way that the UmbracoHelper deals with looking things up in the background, we might not
|
||||
// even expose it publicly but it could handle any caching (per request) that might be required when looking up any objects...
|
||||
// though we might not need it at all, not sure yet.
|
||||
// However, what we need to do is implement the GetDocumentsByType method of the IPublishedStore, see the TODO there.
|
||||
// It might be nicer to have a QueryContext on the UmbracoHelper (we can still keep the Content and TypedContent, etc...
|
||||
// methods, but these would just wrap the QueryContext attached to it. Other methods on the QueryContext will be
|
||||
// ContentByType, TypedContentByType, etc... then we can also have extension methods like below for strongly typed
|
||||
// access like: GetAllHomes, GetAllNewsArticles, etc...
|
||||
|
||||
//public class QueryDataContext
|
||||
//{
|
||||
// private readonly IPublishedContentStore _contentStore;
|
||||
// private readonly UmbracoContext _umbracoContext;
|
||||
|
||||
// internal QueryDataContext(IPublishedContentStore contentStore, UmbracoContext umbracoContext)
|
||||
// {
|
||||
// _contentStore = contentStore;
|
||||
// _umbracoContext = umbracoContext;
|
||||
// }
|
||||
|
||||
// public IPublishedContent GetDocumentById(int id)
|
||||
// {
|
||||
// return _contentStore.GetDocumentById(_umbracoContext, id);
|
||||
// }
|
||||
|
||||
// public IEnumerable<IPublishedContent> GetByDocumentType(string alias)
|
||||
// {
|
||||
|
||||
// }
|
||||
//}
|
||||
|
||||
public enum TraversalType
|
||||
{
|
||||
Children,
|
||||
Ancestors,
|
||||
AncestorsOrSelf,
|
||||
Descendants,
|
||||
DescendantsOrSelf
|
||||
}
|
||||
|
||||
public static class StronglyTypedQueryExtensions
|
||||
{
|
||||
private static IEnumerable<IPublishedContent> GetEnumerable(this IPublishedContent content, string docTypeAlias, TraversalType traversalType = TraversalType.Children)
|
||||
{
|
||||
switch (traversalType)
|
||||
{
|
||||
case TraversalType.Children:
|
||||
return content.Children.Where(x => x.DocumentTypeAlias == docTypeAlias);
|
||||
case TraversalType.Ancestors:
|
||||
return content.Ancestors().Where(x => x.DocumentTypeAlias == docTypeAlias);
|
||||
case TraversalType.AncestorsOrSelf:
|
||||
return content.AncestorsOrSelf().Where(x => x.DocumentTypeAlias == docTypeAlias);
|
||||
case TraversalType.Descendants:
|
||||
return content.Descendants().Where(x => x.DocumentTypeAlias == docTypeAlias);
|
||||
case TraversalType.DescendantsOrSelf:
|
||||
return content.DescendantsOrSelf().Where(x => x.DocumentTypeAlias == docTypeAlias);
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException("traversalType");
|
||||
}
|
||||
}
|
||||
|
||||
private static T AsDocumentType<T>(this IPublishedContent content, string alias, Func<IPublishedContent, T> creator)
|
||||
{
|
||||
if (content.DocumentTypeAlias == alias) return creator(content);
|
||||
throw new InvalidOperationException("The content type cannot be cast to " + typeof(T).FullName + " since it is type: " + content.DocumentTypeAlias);
|
||||
}
|
||||
|
||||
public static HomeContentItem AsHome(this IPublishedContent content)
|
||||
{
|
||||
return content.AsDocumentType("Home", x => new HomeContentItem(x));
|
||||
}
|
||||
|
||||
public static IEnumerable<HomeContentItem> Homes(this IPublishedContent content, TraversalType traversalType = TraversalType.Children)
|
||||
{
|
||||
return content.GetEnumerable("Home", traversalType).Select(x => new HomeContentItem(x));
|
||||
}
|
||||
|
||||
public static NewsArticleContentItem AsNewsArticle(this IPublishedContent content)
|
||||
{
|
||||
return content.AsDocumentType("NewsArticle", x => new NewsArticleContentItem(x));
|
||||
}
|
||||
|
||||
public static IEnumerable<NewsArticleContentItem> NewsArticles(this IPublishedContent content, TraversalType traversalType = TraversalType.Children)
|
||||
{
|
||||
return content.GetEnumerable("NewsArticle", traversalType).Select(x => new NewsArticleContentItem(x));
|
||||
}
|
||||
|
||||
public static NewsLandingPageContentItem AsNewsLandingPage(this IPublishedContent content)
|
||||
{
|
||||
return content.AsDocumentType("NewsLandingPage", x => new NewsLandingPageContentItem(x));
|
||||
}
|
||||
|
||||
public static IEnumerable<NewsLandingPageContentItem> NewsLandingPages(this IPublishedContent content, TraversalType traversalType = TraversalType.Children)
|
||||
{
|
||||
return content.GetEnumerable("NewsLandingPage", traversalType).Select(x => new NewsLandingPageContentItem(x));
|
||||
}
|
||||
|
||||
public static ContentPageContentItem AsContentPage(this IPublishedContent content)
|
||||
{
|
||||
return content.AsDocumentType("ContentPage", x => new ContentPageContentItem(x));
|
||||
}
|
||||
|
||||
public static IEnumerable<ContentPageContentItem> ContentPages(this IPublishedContent content, TraversalType traversalType = TraversalType.Children)
|
||||
{
|
||||
return content.GetEnumerable("ContentPage", traversalType).Select(x => new ContentPageContentItem(x));
|
||||
}
|
||||
}
|
||||
|
||||
public class PublishedContentWrapper : IPublishedContent, IOwnerCollectionAware<IPublishedContent>
|
||||
{
|
||||
protected IPublishedContent WrappedContent { get; private set; }
|
||||
|
||||
public PublishedContentWrapper(IPublishedContent content)
|
||||
{
|
||||
WrappedContent = content;
|
||||
}
|
||||
|
||||
public string Url
|
||||
{
|
||||
get { return WrappedContent.Url; }
|
||||
}
|
||||
|
||||
public PublishedItemType ItemType
|
||||
{
|
||||
get { return WrappedContent.ItemType; }
|
||||
}
|
||||
|
||||
public IPublishedContent Parent
|
||||
{
|
||||
get { return WrappedContent.Parent; }
|
||||
}
|
||||
|
||||
public int Id
|
||||
{
|
||||
get { return WrappedContent.Id; }
|
||||
}
|
||||
public int TemplateId
|
||||
{
|
||||
get { return WrappedContent.TemplateId; }
|
||||
}
|
||||
public int SortOrder
|
||||
{
|
||||
get { return WrappedContent.SortOrder; }
|
||||
}
|
||||
public string Name
|
||||
{
|
||||
get { return WrappedContent.Name; }
|
||||
}
|
||||
public string UrlName
|
||||
{
|
||||
get { return WrappedContent.UrlName; }
|
||||
}
|
||||
public string DocumentTypeAlias
|
||||
{
|
||||
get { return WrappedContent.DocumentTypeAlias; }
|
||||
}
|
||||
public int DocumentTypeId
|
||||
{
|
||||
get { return WrappedContent.DocumentTypeId; }
|
||||
}
|
||||
public string WriterName
|
||||
{
|
||||
get { return WrappedContent.WriterName; }
|
||||
}
|
||||
public string CreatorName
|
||||
{
|
||||
get { return WrappedContent.CreatorName; }
|
||||
}
|
||||
public int WriterId
|
||||
{
|
||||
get { return WrappedContent.WriterId; }
|
||||
}
|
||||
public int CreatorId
|
||||
{
|
||||
get { return WrappedContent.CreatorId; }
|
||||
}
|
||||
public string Path
|
||||
{
|
||||
get { return WrappedContent.Path; }
|
||||
}
|
||||
public DateTime CreateDate
|
||||
{
|
||||
get { return WrappedContent.CreateDate; }
|
||||
}
|
||||
public DateTime UpdateDate
|
||||
{
|
||||
get { return WrappedContent.UpdateDate; }
|
||||
}
|
||||
public Guid Version
|
||||
{
|
||||
get { return WrappedContent.Version; }
|
||||
}
|
||||
public int Level
|
||||
{
|
||||
get { return WrappedContent.Level; }
|
||||
}
|
||||
public ICollection<IPublishedContentProperty> Properties
|
||||
{
|
||||
get { return WrappedContent.Properties; }
|
||||
}
|
||||
|
||||
public object this[string propertyAlias]
|
||||
{
|
||||
get { return GetProperty(propertyAlias).Value; }
|
||||
}
|
||||
|
||||
public IEnumerable<IPublishedContent> Children
|
||||
{
|
||||
get { return WrappedContent.Children; }
|
||||
}
|
||||
public IPublishedContentProperty GetProperty(string alias)
|
||||
{
|
||||
return WrappedContent.GetProperty(alias);
|
||||
}
|
||||
|
||||
private IEnumerable<IPublishedContent> _ownersCollection;
|
||||
|
||||
/// <summary>
|
||||
/// Need to get/set the owner collection when an item is returned from the result set of a query
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Based on this issue here: http://issues.umbraco.org/issue/U4-1797
|
||||
/// </remarks>
|
||||
IEnumerable<IPublishedContent> IOwnerCollectionAware<IPublishedContent>.OwnersCollection
|
||||
{
|
||||
get
|
||||
{
|
||||
var publishedContentBase = WrappedContent as IOwnerCollectionAware<IPublishedContent>;
|
||||
if (publishedContentBase != null)
|
||||
{
|
||||
return publishedContentBase.OwnersCollection;
|
||||
}
|
||||
|
||||
//if the owners collection is null, we'll default to it's siblings
|
||||
if (_ownersCollection == null)
|
||||
{
|
||||
//get the root docs if parent is null
|
||||
_ownersCollection = this.Siblings();
|
||||
}
|
||||
return _ownersCollection;
|
||||
}
|
||||
set
|
||||
{
|
||||
var publishedContentBase = WrappedContent as IOwnerCollectionAware<IPublishedContent>;
|
||||
if (publishedContentBase != null)
|
||||
{
|
||||
publishedContentBase.OwnersCollection = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
_ownersCollection = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public partial class HomeContentItem : ContentPageContentItem
|
||||
{
|
||||
public HomeContentItem(IPublishedContent content)
|
||||
: base(content)
|
||||
{
|
||||
}
|
||||
|
||||
public string SiteName
|
||||
{
|
||||
get { return WrappedContent.GetPropertyValue<string>("siteName"); }
|
||||
}
|
||||
public string SiteDescription
|
||||
{
|
||||
get { return WrappedContent.GetPropertyValue<string>("siteDescription"); }
|
||||
}
|
||||
}
|
||||
|
||||
public partial class NewsLandingPageContentItem : ContentPageContentItem
|
||||
{
|
||||
public NewsLandingPageContentItem(IPublishedContent content)
|
||||
: base(content)
|
||||
{
|
||||
}
|
||||
|
||||
public string PageTitle
|
||||
{
|
||||
get { return WrappedContent.GetPropertyValue<string>("pageTitle"); }
|
||||
}
|
||||
}
|
||||
|
||||
public partial class NewsArticleContentItem : PublishedContentWrapper
|
||||
{
|
||||
public NewsArticleContentItem(IPublishedContent content)
|
||||
: base(content)
|
||||
{
|
||||
}
|
||||
|
||||
public string ArticleContent
|
||||
{
|
||||
get { return WrappedContent.GetPropertyValue<string>("articleContent"); }
|
||||
}
|
||||
public DateTime ArticleDate
|
||||
{
|
||||
get { return WrappedContent.GetPropertyValue<DateTime>("articleDate"); }
|
||||
}
|
||||
public string ArticleAuthor
|
||||
{
|
||||
get { return WrappedContent.GetPropertyValue<string>("articleAuthor"); }
|
||||
}
|
||||
}
|
||||
|
||||
public partial class ContentPageContentItem : PublishedContentWrapper
|
||||
{
|
||||
public ContentPageContentItem(IPublishedContent content)
|
||||
: base(content)
|
||||
{
|
||||
}
|
||||
|
||||
public string BodyContent
|
||||
{
|
||||
get { return WrappedContent.GetPropertyValue<string>("bodyContent"); }
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -230,7 +230,6 @@
|
||||
<Compile Include="PropertyEditors\PropertyEditorValueConverterTests.cs" />
|
||||
<Compile Include="Models\ContentTests.cs" />
|
||||
<Compile Include="Models\ContentXmlTest.cs" />
|
||||
<Compile Include="Models\MacroTests.cs" />
|
||||
<Compile Include="Models\StylesheetTests.cs" />
|
||||
<Compile Include="Persistence\BaseTableByTableTest.cs" />
|
||||
<Compile Include="Persistence\Caching\InMemoryCacheProviderTest.cs" />
|
||||
@@ -256,7 +255,6 @@
|
||||
<Compile Include="Persistence\Repositories\DataTypeDefinitionRepositoryTest.cs" />
|
||||
<Compile Include="Persistence\Repositories\DictionaryRepositoryTest.cs" />
|
||||
<Compile Include="Persistence\Repositories\LanguageRepositoryTest.cs" />
|
||||
<Compile Include="Persistence\Repositories\MacroRepositoryTest.cs" />
|
||||
<Compile Include="Persistence\Repositories\MediaRepositoryTest.cs" />
|
||||
<Compile Include="Persistence\Repositories\MediaTypeRepositoryTest.cs" />
|
||||
<Compile Include="Persistence\Repositories\RelationRepositoryTest.cs" />
|
||||
|
||||
Reference in New Issue
Block a user