diff --git a/src/Umbraco.Core/Dynamics/CaseInsensitiveDynamicObject.cs b/src/Umbraco.Core/Dynamics/CaseInsensitiveDynamicObject.cs
deleted file mode 100644
index 43d7adc647..0000000000
--- a/src/Umbraco.Core/Dynamics/CaseInsensitiveDynamicObject.cs
+++ /dev/null
@@ -1,93 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Dynamic;
-using System.Linq;
-using System.Reflection;
-
-namespace Umbraco.Core.Dynamics
-{
- ///
- /// This will check enable dynamic access to properties and methods in a case insensitive manner
- ///
- ///
- ///
- /// This works by using reflection on the type - the reflection lookup is lazy so it will not execute unless a dynamic method needs to be accessed
- ///
- public abstract class CaseInsensitiveDynamicObject : DynamicObject
- where T: class
- {
- ///
- /// Used for dynamic access for case insensitive property access
- /// `
- private static readonly Lazy>> CaseInsensitivePropertyAccess = new Lazy>>(() =>
- {
- var props = typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public)
- .DistinctBy(x => x.Name);
- return props.Select(propInfo =>
- {
- var name = propInfo.Name.ToLowerInvariant();
- Func getVal = propInfo.GetValue;
- return new KeyValuePair>(name, getVal);
-
- }).ToDictionary(x => x.Key, x => x.Value);
- });
-
- ///
- /// Used for dynamic access for case insensitive property access
- ///
- private static readonly Lazy>>> CaseInsensitiveMethodAccess
- = new Lazy>>>(() =>
- {
- var props = typeof(T).GetMethods(BindingFlags.Instance | BindingFlags.Public)
- .Where(x => x.IsSpecialName == false && x.IsVirtual == false)
- .DistinctBy(x => x.Name);
- return props.Select(methodInfo =>
- {
- var name = methodInfo.Name.ToLowerInvariant();
- Func getVal = methodInfo.Invoke;
- var val = new Tuple>(methodInfo.GetParameters(), getVal);
- return new KeyValuePair>>(name, val);
-
- }).ToDictionary(x => x.Key, x => x.Value);
- });
-
- public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
- {
- var name = binder.Name.ToLowerInvariant();
- if (CaseInsensitiveMethodAccess.Value.ContainsKey(name) == false)
- return base.TryInvokeMember(binder, args, out result);
-
- var val = CaseInsensitiveMethodAccess.Value[name];
- var parameters = val.Item1;
- var callback = val.Item2;
- var fullArgs = new List(args);
- if (args.Length <= parameters.Length)
- {
- //need to fill them up if they're optional
- for (var i = args.Length; i < parameters.Length; i++)
- {
- if (parameters[i].IsOptional)
- {
- fullArgs.Add(parameters[i].DefaultValue);
- }
- }
- if (fullArgs.Count == parameters.Length)
- {
- result = callback((T)(object)this, fullArgs.ToArray());
- return true;
- }
- }
- return base.TryInvokeMember(binder, args, out result);
- }
-
- public override bool TryGetMember(GetMemberBinder binder, out object result)
- {
- var name = binder.Name.ToLowerInvariant();
- if (CaseInsensitivePropertyAccess.Value.ContainsKey(name) == false)
- return base.TryGetMember(binder, out result);
-
- result = CaseInsensitivePropertyAccess.Value[name]((T)(object)this);
- return true;
- }
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Dynamics/ClassFactory.cs b/src/Umbraco.Core/Dynamics/ClassFactory.cs
deleted file mode 100644
index 87f4315e76..0000000000
--- a/src/Umbraco.Core/Dynamics/ClassFactory.cs
+++ /dev/null
@@ -1,182 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-using System.Reflection.Emit;
-using System.Threading;
-
-namespace Umbraco.Core.Dynamics
-{
- internal class ClassFactory
- {
- public static readonly ClassFactory Instance = new ClassFactory();
-
- static ClassFactory() { } // Trigger lazy initialization of static fields
-
- ModuleBuilder module;
- Dictionary classes;
- int classCount;
- ReaderWriterLock rwLock;
-
- protected ClassFactory()
- {
- AssemblyName name = new AssemblyName("DynamicClasses");
- AssemblyBuilder assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.Run);
-#if ENABLE_LINQ_PARTIAL_TRUST
- new ReflectionPermission(PermissionState.Unrestricted).Assert();
-#endif
- try
- {
- module = assembly.DefineDynamicModule("Module");
- }
- finally
- {
-#if ENABLE_LINQ_PARTIAL_TRUST
- PermissionSet.RevertAssert();
-#endif
- }
- classes = new Dictionary();
- rwLock = new ReaderWriterLock();
- }
-
- public Type GetDynamicClass(IEnumerable properties)
- {
- rwLock.AcquireReaderLock(Timeout.Infinite);
- try
- {
- Signature signature = new Signature(properties);
- Type type;
- if (!classes.TryGetValue(signature, out type))
- {
- type = CreateDynamicClass(signature.Properties);
- classes.Add(signature, type);
- }
- return type;
- }
- finally
- {
- rwLock.ReleaseReaderLock();
- }
- }
-
- Type CreateDynamicClass(DynamicProperty[] properties)
- {
- LockCookie cookie = rwLock.UpgradeToWriterLock(Timeout.Infinite);
- try
- {
- string typeName = "DynamicClass" + (classCount + 1);
-#if ENABLE_LINQ_PARTIAL_TRUST
- new ReflectionPermission(PermissionState.Unrestricted).Assert();
-#endif
- try
- {
- TypeBuilder tb = this.module.DefineType(typeName, TypeAttributes.Class |
- TypeAttributes.Public, typeof(DynamicClass));
- FieldInfo[] fields = GenerateProperties(tb, properties);
- GenerateEquals(tb, fields);
- GenerateGetHashCode(tb, fields);
- Type result = tb.CreateType();
- classCount++;
- return result;
- }
- finally
- {
-#if ENABLE_LINQ_PARTIAL_TRUST
- PermissionSet.RevertAssert();
-#endif
- }
- }
- finally
- {
- rwLock.DowngradeFromWriterLock(ref cookie);
- }
- }
-
- FieldInfo[] GenerateProperties(TypeBuilder tb, DynamicProperty[] properties)
- {
- FieldInfo[] fields = new FieldBuilder[properties.Length];
- for (int i = 0; i < properties.Length; i++)
- {
- DynamicProperty dp = properties[i];
- FieldBuilder fb = tb.DefineField("_" + dp.Name, dp.Type, FieldAttributes.Private);
- PropertyBuilder pb = tb.DefineProperty(dp.Name, PropertyAttributes.HasDefault, dp.Type, null);
- MethodBuilder mbGet = tb.DefineMethod("get_" + dp.Name,
- MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig,
- dp.Type, Type.EmptyTypes);
- ILGenerator genGet = mbGet.GetILGenerator();
- genGet.Emit(OpCodes.Ldarg_0);
- genGet.Emit(OpCodes.Ldfld, fb);
- genGet.Emit(OpCodes.Ret);
- MethodBuilder mbSet = tb.DefineMethod("set_" + dp.Name,
- MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig,
- null, new Type[] { dp.Type });
- ILGenerator genSet = mbSet.GetILGenerator();
- genSet.Emit(OpCodes.Ldarg_0);
- genSet.Emit(OpCodes.Ldarg_1);
- genSet.Emit(OpCodes.Stfld, fb);
- genSet.Emit(OpCodes.Ret);
- pb.SetGetMethod(mbGet);
- pb.SetSetMethod(mbSet);
- fields[i] = fb;
- }
- return fields;
- }
-
- void GenerateEquals(TypeBuilder tb, FieldInfo[] fields)
- {
- MethodBuilder mb = tb.DefineMethod("Equals",
- MethodAttributes.Public | MethodAttributes.ReuseSlot |
- MethodAttributes.Virtual | MethodAttributes.HideBySig,
- typeof(bool), new Type[] { typeof(object) });
- ILGenerator gen = mb.GetILGenerator();
- LocalBuilder other = gen.DeclareLocal(tb);
- Label next = gen.DefineLabel();
- gen.Emit(OpCodes.Ldarg_1);
- gen.Emit(OpCodes.Isinst, tb);
- gen.Emit(OpCodes.Stloc, other);
- gen.Emit(OpCodes.Ldloc, other);
- gen.Emit(OpCodes.Brtrue_S, next);
- gen.Emit(OpCodes.Ldc_I4_0);
- gen.Emit(OpCodes.Ret);
- gen.MarkLabel(next);
- foreach (FieldInfo field in fields)
- {
- Type ft = field.FieldType;
- Type ct = typeof(EqualityComparer<>).MakeGenericType(ft);
- next = gen.DefineLabel();
- gen.EmitCall(OpCodes.Call, ct.GetMethod("get_Default"), null);
- gen.Emit(OpCodes.Ldarg_0);
- gen.Emit(OpCodes.Ldfld, field);
- gen.Emit(OpCodes.Ldloc, other);
- gen.Emit(OpCodes.Ldfld, field);
- gen.EmitCall(OpCodes.Callvirt, ct.GetMethod("Equals", new Type[] { ft, ft }), null);
- gen.Emit(OpCodes.Brtrue_S, next);
- gen.Emit(OpCodes.Ldc_I4_0);
- gen.Emit(OpCodes.Ret);
- gen.MarkLabel(next);
- }
- gen.Emit(OpCodes.Ldc_I4_1);
- gen.Emit(OpCodes.Ret);
- }
-
- void GenerateGetHashCode(TypeBuilder tb, FieldInfo[] fields)
- {
- MethodBuilder mb = tb.DefineMethod("GetHashCode",
- MethodAttributes.Public | MethodAttributes.ReuseSlot |
- MethodAttributes.Virtual | MethodAttributes.HideBySig,
- typeof(int), Type.EmptyTypes);
- ILGenerator gen = mb.GetILGenerator();
- gen.Emit(OpCodes.Ldc_I4_0);
- foreach (FieldInfo field in fields)
- {
- Type ft = field.FieldType;
- Type ct = typeof(EqualityComparer<>).MakeGenericType(ft);
- gen.EmitCall(OpCodes.Call, ct.GetMethod("get_Default"), null);
- gen.Emit(OpCodes.Ldarg_0);
- gen.Emit(OpCodes.Ldfld, field);
- gen.EmitCall(OpCodes.Callvirt, ct.GetMethod("GetHashCode", new Type[] { ft }), null);
- gen.Emit(OpCodes.Xor);
- }
- gen.Emit(OpCodes.Ret);
- }
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Dynamics/DynamicClass.cs b/src/Umbraco.Core/Dynamics/DynamicClass.cs
deleted file mode 100644
index 13914cad42..0000000000
--- a/src/Umbraco.Core/Dynamics/DynamicClass.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-using System.Reflection;
-using System.Text;
-
-namespace Umbraco.Core.Dynamics
-{
- public abstract class DynamicClass
- {
- public override string ToString()
- {
- PropertyInfo[] props = this.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
- StringBuilder sb = new StringBuilder();
- sb.Append("{");
- for (int i = 0; i < props.Length; i++)
- {
- if (i > 0) sb.Append(", ");
- sb.Append(props[i].Name);
- sb.Append("=");
- sb.Append(props[i].GetValue(this, null));
- }
- sb.Append("}");
- return sb.ToString();
- }
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Dynamics/DynamicDictionary.cs b/src/Umbraco.Core/Dynamics/DynamicDictionary.cs
deleted file mode 100644
index f3ab75413f..0000000000
--- a/src/Umbraco.Core/Dynamics/DynamicDictionary.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-using System.Collections.Generic;
-using System.Dynamic;
-
-namespace Umbraco.Core.Dynamics
-{
- public class DynamicDictionary : DynamicObject
- {
- internal readonly Dictionary SourceItems;
-
- public DynamicDictionary(Dictionary sourceItems)
- {
- SourceItems = sourceItems;
- }
- public override bool TrySetMember(SetMemberBinder binder, object value)
- {
- if (SourceItems.ContainsKey(binder.Name))
- {
- SourceItems[binder.Name.ToLower()] = value;
- }
- else
- {
- SourceItems.Add(binder.Name.ToLower(), value);
- }
- return true;
- }
- public override bool TryGetMember(GetMemberBinder binder, out object result)
- {
- if (SourceItems != null)
- {
- if (SourceItems.TryGetValue(binder.Name.ToLower(), out result))
- {
- return true;
- }
- }
- result = null;
- return true;
- }
- }
-}
diff --git a/src/Umbraco.Core/Dynamics/DynamicInstanceHelper.cs b/src/Umbraco.Core/Dynamics/DynamicInstanceHelper.cs
deleted file mode 100644
index 59f149ef09..0000000000
--- a/src/Umbraco.Core/Dynamics/DynamicInstanceHelper.cs
+++ /dev/null
@@ -1,194 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Dynamic;
-using System.Linq;
-using System.Reflection;
-using System.Text;
-using Umbraco.Core.Cache;
-using Umbraco.Core.Logging;
-
-namespace Umbraco.Core.Dynamics
-{
- ///
- /// A helper class to try invoke members, find properties, etc...
- ///
- internal class DynamicInstanceHelper
- {
-
- internal class TryInvokeMemberResult
- {
- public object ObjectResult { get; private set; }
- public TryInvokeMemberSuccessReason Reason { get; private set; }
-
- public TryInvokeMemberResult(object result, TryInvokeMemberSuccessReason reason)
- {
- ObjectResult = result;
- Reason = reason;
- }
- }
-
- internal enum TryInvokeMemberSuccessReason
- {
- FoundProperty,
- FoundMethod,
- FoundExtensionMethod
- }
-
- ///
- /// Attempts to invoke a member based on the dynamic instance
- ///
- ///
- ///
- /// The object instance to invoke the extension method for
- ///
- ///
- ///
- ///
- /// First tries to find a property with the binder name, if that fails it will try to find a static or instance method
- /// on the object that matches the binder name
- ///
- public static Attempt TryInvokeMember(IRuntimeCacheProvider runtimeCache, T thisObject, InvokeMemberBinder binder, object[] args)
- {
- return TryInvokeMember(runtimeCache, thisObject, binder, args, null);
- }
-
- ///
- /// Attempts to invoke a member based on the dynamic instance
- ///
- ///
- ///
- /// The object instance to invoke the extension method for
- ///
- ///
- /// The types to scan for extension methods
- ///
- ///
- /// First tries to find a property with the binder name, if that fails it will try to find a static or instance method
- /// on the object that matches the binder name, if that fails it will then attempt to invoke an extension method
- /// based on the binder name and the extension method types to scan.
- ///
- public static Attempt TryInvokeMember(
- IRuntimeCacheProvider runtimeCache,
- T thisObject,
- InvokeMemberBinder binder,
- object[] args,
- IEnumerable findExtensionMethodsOnTypes)
- {
- //TODO: We MUST cache the result here, it is very expensive to keep finding extension methods!
- object result;
- try
- {
- //Property?
- result = typeof(T).InvokeMember(binder.Name,
- BindingFlags.Instance |
- BindingFlags.Public |
- BindingFlags.GetProperty,
- null,
- thisObject,
- args);
- return Attempt.Succeed(new TryInvokeMemberResult(result, TryInvokeMemberSuccessReason.FoundProperty));
- }
- catch (MissingMethodException)
- {
- try
- {
- //Static or Instance Method?
- result = typeof(T).InvokeMember(binder.Name,
- BindingFlags.Instance |
- BindingFlags.Public |
- BindingFlags.Static |
- BindingFlags.InvokeMethod,
- null,
- thisObject,
- args);
- return Attempt.Succeed(new TryInvokeMemberResult(result, TryInvokeMemberSuccessReason.FoundMethod));
- }
- catch (MissingMethodException)
- {
- if (findExtensionMethodsOnTypes != null)
- {
- try
- {
- result = FindAndExecuteExtensionMethod(runtimeCache, thisObject, args, binder.Name, findExtensionMethodsOnTypes);
- return Attempt.Succeed(new TryInvokeMemberResult(result, TryInvokeMemberSuccessReason.FoundExtensionMethod));
- }
- catch (TargetInvocationException ext)
- {
- //don't log here, we return this exception because the caller may need to do something specific when
- //this exception occurs.
- var mresult = new TryInvokeMemberResult(null, TryInvokeMemberSuccessReason.FoundExtensionMethod);
- return Attempt.Fail(mresult, ext);
- }
- catch (Exception ex)
- {
- var sb = new StringBuilder();
- sb.AppendFormat("An error occurred finding and executing extension method \"{0}\" ", binder.Name);
- sb.AppendFormat("for type \"{0}\". ", typeof (T));
- sb.Append("Types searched for extension methods were ");
- sb.Append(string.Join(", ", findExtensionMethodsOnTypes));
- sb.Append(".");
- LogHelper.Error(sb.ToString(), ex);
- var mresult = new TryInvokeMemberResult(null, TryInvokeMemberSuccessReason.FoundExtensionMethod);
- return Attempt.Fail(mresult, ex);
- }
- }
- return Attempt.Fail();
- }
- }
- catch (Exception ex)
- {
- LogHelper.Error("An unhandled exception occurred in method TryInvokeMember", ex);
- return Attempt.Fail(ex);
- }
- }
-
- ///
- /// Attempts to find an extension method that matches the name and arguments based on scanning the Type's passed in
- /// to the findMethodsOnTypes parameter
- ///
- ///
- /// The instance object to execute the extension method for
- ///
- ///
- ///
- ///
- internal static object FindAndExecuteExtensionMethod(
- IRuntimeCacheProvider runtimeCache,
- T thisObject,
- object[] args,
- string name,
- IEnumerable findMethodsOnTypes)
- {
- object result = null;
-
- //find known extension methods that match the first type in the list
- MethodInfo toExecute = null;
- foreach (var t in findMethodsOnTypes)
- {
- toExecute = ExtensionMethodFinder.FindExtensionMethod(runtimeCache, t, args, name, false);
- if (toExecute != null)
- break;
- }
-
- if (toExecute != null)
- {
- var genericArgs = (new[] { (object)thisObject }).Concat(args);
-
- // else we'd get an exception w/ message "Late bound operations cannot
- // be performed on types or methods for which ContainsGenericParameters is true."
- // because MakeGenericMethod must be used to obtain an actual method that can run
- if (toExecute.ContainsGenericParameters)
- throw new InvalidOperationException("Method contains generic parameters, something's wrong.");
-
- result = toExecute.Invoke(null, genericArgs.ToArray());
- }
- else
- {
- throw new MissingMethodException(typeof(T).FullName, name);
- }
- return result;
- }
-
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Dynamics/DynamicNull.cs b/src/Umbraco.Core/Dynamics/DynamicNull.cs
deleted file mode 100644
index 593808e867..0000000000
--- a/src/Umbraco.Core/Dynamics/DynamicNull.cs
+++ /dev/null
@@ -1,119 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Collections;
-using System.Dynamic;
-using System.Web;
-
-namespace Umbraco.Core.Dynamics
-{
- //This type is used as a return type when TryGetMember fails on a DynamicNode
- //.Where explicitly checks for this type, to indicate that nothing was returned
- //Because it's IEnumerable, if the user is actually trying @Model.TextPages or similar
- //it will still return an enumerable object (assuming the call actually failed because there were no children of that type)
- //but in .Where, if they use a property that doesn't exist, the lambda will bypass this and return false
-
- // returned when TryGetMember fails on a DynamicPublishedContent
- //
- // so if user does @CurrentPage.TextPages it will get something that is enumerable (but empty)
- // note - not sure I understand the stuff about .Where, though
-
- public class DynamicNull : DynamicObject, IEnumerable, IHtmlString
- {
- public static readonly DynamicNull Null = new DynamicNull();
-
- private DynamicNull() {}
-
- public IEnumerator GetEnumerator()
- {
- return (new List()).GetEnumerator();
- }
-
- public DynamicNull Where(string predicate, params object[] values)
- {
- return this;
- }
-
- public DynamicNull OrderBy(string orderBy)
- {
- return this;
- }
-
- public DynamicNull ToContentSet()
- {
- return this;
- }
-
- public int Count()
- {
- return 0;
- }
-
- public override string ToString()
- {
- return string.Empty;
- }
-
- public override bool TryGetMember(GetMemberBinder binder, out object result)
- {
- result = this;
- return true;
- }
-
- public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
- {
- result = this;
- return true;
- }
-
- public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
- {
- result = this;
- return true;
- }
-
- public bool IsNull()
- {
- return true;
- }
-
- public bool HasValue()
- {
- return false;
- }
-
- public string Name
- {
- get { return string.Empty; }
- }
-
- public int Id
- {
- get { return 0; }
- }
-
- public static implicit operator bool(DynamicNull n)
- {
- return false;
- }
-
- public static implicit operator DateTime(DynamicNull n)
- {
- return DateTime.MinValue;
- }
-
- public static implicit operator int(DynamicNull n)
- {
- return 0;
- }
-
- public static implicit operator string(DynamicNull n)
- {
- return string.Empty;
- }
-
- public string ToHtmlString()
- {
- return string.Empty;
- }
- }
-}
diff --git a/src/Umbraco.Core/Dynamics/DynamicOrdering.cs b/src/Umbraco.Core/Dynamics/DynamicOrdering.cs
deleted file mode 100644
index b4f0bf0d3a..0000000000
--- a/src/Umbraco.Core/Dynamics/DynamicOrdering.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-using System.Linq.Expressions;
-
-namespace Umbraco.Core.Dynamics
-{
- internal class DynamicOrdering
- {
- public Expression Selector;
- public bool Ascending;
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Dynamics/DynamicProperty.cs b/src/Umbraco.Core/Dynamics/DynamicProperty.cs
deleted file mode 100644
index acb29bf387..0000000000
--- a/src/Umbraco.Core/Dynamics/DynamicProperty.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-using System;
-
-namespace Umbraco.Core.Dynamics
-{
- internal class DynamicProperty
- {
- readonly string _name;
- readonly Type _type;
-
- public DynamicProperty(string name, Type type)
- {
- if (name == null) throw new ArgumentNullException("name");
- if (type == null) throw new ArgumentNullException("type");
- this._name = name;
- this._type = type;
- }
-
- public string Name
- {
- get { return _name; }
- }
-
- public Type Type
- {
- get { return _type; }
- }
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Dynamics/DynamicQueryableGetMemberBinder.cs b/src/Umbraco.Core/Dynamics/DynamicQueryableGetMemberBinder.cs
deleted file mode 100644
index 92d7cfcdc9..0000000000
--- a/src/Umbraco.Core/Dynamics/DynamicQueryableGetMemberBinder.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using System;
-using System.Dynamic;
-
-namespace Umbraco.Core.Dynamics
-{
- internal class DynamicQueryableGetMemberBinder : GetMemberBinder
- {
- public DynamicQueryableGetMemberBinder(string name, bool ignoreCase) : base(name, ignoreCase) { }
-
- public override DynamicMetaObject FallbackGetMember(DynamicMetaObject target, DynamicMetaObject errorSuggestion)
- {
- throw new NotImplementedException();
- }
- }
-}
diff --git a/src/Umbraco.Core/Dynamics/DynamicXml.cs b/src/Umbraco.Core/Dynamics/DynamicXml.cs
deleted file mode 100644
index bedb25a69c..0000000000
--- a/src/Umbraco.Core/Dynamics/DynamicXml.cs
+++ /dev/null
@@ -1,849 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Linq;
-using System.Dynamic;
-using System.Reflection;
-using System.Xml.Linq;
-using System.Xml.XPath;
-using System.Collections;
-using System.IO;
-using System.Web;
-using Umbraco.Core;
-using Umbraco.Core.Cache;
-using Umbraco.Core.Xml;
-
-namespace Umbraco.Core.Dynamics
-{
- [TypeConverter(typeof(DynamicXmlConverter))]
- public class DynamicXml : DynamicObject, IEnumerable, IEnumerable
- {
- ///
- /// Returns the XElement used to create the DynamicXml structure
- ///
- public XElement BaseElement { get; set; }
-
- ///
- /// Returns the raw XElement used to create the DynamicXml structure if one was specified otherwise returns the
- /// same value as BaseElement.
- ///
- ///
- /// This is purely used for when an instance of DynamicXml is created with the overload that supports
- /// passing in both a raw xml version and a dash-stripped xml version. Otherwise this value is exactly the
- /// same as BaseElement.
- ///
- public XElement RawXmlElement { get; internal set; }
-
- ///
- /// Constructor
- ///
- ///
- public DynamicXml(XElement baseElement)
- {
- if (baseElement == null) return;
-
- //same
- RawXmlElement = baseElement;
- BaseElement = baseElement;
- }
-
- ///
- /// When this constructor is used the BaseElement becomes equivalent to the strippedXml structure
- ///
- ///
- ///
- internal DynamicXml(XElement strippedXml, XElement rawXml)
- {
- if (rawXml == null) return;
- if (strippedXml == null) return;
-
- RawXmlElement = rawXml;
- BaseElement = strippedXml;
- }
-
- ///
- /// When this constructor is used the BaseElement becomes equivalent to the strippedXml structure
- ///
- ///
- ///
- internal DynamicXml(string strippedXml, string rawXml)
- {
- if (rawXml == null) return;
- if (strippedXml == null) return;
-
- RawXmlElement = XElement.Parse(rawXml);
- BaseElement = XElement.Parse(strippedXml);
- }
-
- ///
- /// Constructor
- ///
- ///
- public DynamicXml(string xml)
- {
- if (xml.IsNullOrWhiteSpace()) return;
-
- var baseElement = XElement.Parse(xml);
-
- //same
- RawXmlElement = baseElement;
- BaseElement = baseElement;
- }
-
- ///
- /// Constructor
- ///
- ///
- public DynamicXml(XPathNodeIterator xpni)
- {
- if (xpni == null) return;
- if (xpni.Current == null) return;
-
- //TODO: OuterXml is really bad for performance! Should actually use the XPathNodeIterator api
- var xml = xpni.Current.OuterXml;
- var baseElement = XElement.Parse(xml);
-
- //same
- RawXmlElement = baseElement;
- BaseElement = baseElement;
- }
-
- ///
- /// Returns the InnertText based on the BaseElement object
- ///
- public string InnerText
- {
- get
- {
- return BaseElement.Value;
- }
- }
-
- ///
- /// Returns the string representation of the BaseElement object
- ///
- ///
- public string ToXml()
- {
- return BaseElement.ToString(SaveOptions.DisableFormatting);
- }
-
- ///
- /// Returns the string representation of the RawXmlElement object
- ///
- ///
- public string ToRawXml()
- {
- return RawXmlElement.ToString(SaveOptions.DisableFormatting);
- }
-
- public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
- {
- int index = 0;
- if (indexes.Length > 0)
- {
- index = (int)indexes[0];
- result = new DynamicXml(
- RawXmlElement.Elements().ElementAt(index),
- BaseElement.Elements().ElementAt(index));
- return true;
- }
- return base.TryGetIndex(binder, indexes, out result);
- }
- public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
- {
- if (args.Length == 0 && binder.Name == "ToXml")
- {
- result = BaseElement.ToString();
- return true;
- }
- if (args.Length == 1 && binder.Name == "XPath")
- {
- var elements = BaseElement.XPathSelectElements(args[0].ToString());
- HandleIEnumerableXElement(elements, out result);
- return true; //anyway
- }
-
- var runtimeCache = ApplicationContext.Current != null ? ApplicationContext.Current.ApplicationCache.RuntimeCache : new NullCacheProvider();
-
- //ok, now lets try to match by member, property, extensino method
- var attempt = DynamicInstanceHelper.TryInvokeMember(runtimeCache, this, binder, args, new[]
- {
- typeof (IEnumerable),
- typeof (IEnumerable),
- typeof (DynamicXml)
- });
-
- if (attempt.Success)
- {
- result = attempt.Result.ObjectResult;
-
- //need to check the return type and possibly cast if result is from an extension method found
- if (attempt.Result.Reason == DynamicInstanceHelper.TryInvokeMemberSuccessReason.FoundExtensionMethod)
- {
- //if the result is already a DynamicXml instance, then we do not need to cast
- if (attempt.Result.ObjectResult != null && !(attempt.Result.ObjectResult is DynamicXml))
- {
- if (attempt.Result.ObjectResult is XElement)
- {
- result = new DynamicXml((XElement)attempt.Result.ObjectResult);
- }
- else if (attempt.Result.ObjectResult is IEnumerable)
- {
- result = ((IEnumerable)attempt.Result.ObjectResult).Select(x => new DynamicXml(x));
- }
- else if (attempt.Result.ObjectResult is IEnumerable)
- {
- result = ((IEnumerable) attempt.Result.ObjectResult).Select(x => new DynamicXml(
- x.RawXmlElement,
- x.BaseElement));
- }
- }
- }
- return true;
- }
-
- //this is the result of an extension method execution gone wrong so we return dynamic null
- if (attempt.Result.Reason == DynamicInstanceHelper.TryInvokeMemberSuccessReason.FoundExtensionMethod
- && attempt.Exception != null && attempt.Exception is TargetInvocationException)
- {
- result = DynamicNull.Null;
- return true;
- }
-
- result = null;
- return false;
-
- }
- public override bool TryGetMember(GetMemberBinder binder, out object result)
- {
- if (RawXmlElement == null || binder == null)
- {
- result = null;
- return false;
- }
-
- //Check if the name matches a node based on the BaseElement (which if the correct ctor is used, will be dash stripped)
- var elementByNameAttempt = CheckNodeNameMatch(binder.Name, BaseElement);
- if (elementByNameAttempt.Success)
- {
- if (HandleIEnumerableXElement(elementByNameAttempt.Result, out result))
- {
- return true;
- }
- }
-
- //Check if the name matches a node based on the BaseElement (which if the correct ctor is used, will be dash stripped)
- var attributeByNameAttempt = CheckAttributeNameMatch(binder.Name, BaseElement);
- if (attributeByNameAttempt.Success)
- {
- if (attributeByNameAttempt.Result.Count() > 1)
- {
- //more than one attribute matched, lets return the collection
- result = attributeByNameAttempt.Result;
- }
- else
- {
- //only one attribute matched, lets just return it
- result = attributeByNameAttempt.Result.FirstOrDefault();
- }
- return true;
- }
-
-
- return base.TryGetMember(binder, out result);
- }
-
- ///
- /// Checks if the 'name' matches any attributes of xmlElement
- ///
- /// The name to match
- /// The xml element to check against
- ///
- private static Attempt> CheckAttributeNameMatch(string name, XElement xmlElement)
- {
- var attributes = xmlElement.Attributes(name).Select(attr => attr.Value).ToArray();
- if (attributes.Any())
- {
- return Attempt>.Succeed(attributes);
- }
-
- if (!attributes.Any() && xmlElement.Name == "root" && xmlElement.Elements().Count() == 1)
- {
- //no elements matched and this node is called 'root' and only has one child... lets see if it matches.
- var childElements = xmlElement.Elements().ElementAt(0).Attributes(name).Select(attr => attr.Value).ToArray();
- if (childElements.Any())
- {
- //we've found a match by the first child of an element called 'root' (strange, but sure)
- return Attempt>.Succeed(childElements);
- }
- }
-
- //no deal
- return Attempt>.Fail();
- }
-
- ///
- /// Checks if the 'name' matches any elements of xmlElement
- ///
- /// The name to match
- /// The xml element to check against
- ///
- private Attempt> CheckNodeNameMatch(string name, XElement xmlElement)
- {
- //Go ahead and try to fetch all of the elements matching the member name, and wrap them
- var elements = xmlElement.Elements(name).ToArray();
-
- //Check if we've got any matches, if so then return true
- if (elements.Any())
- {
- return Attempt>.Succeed(elements);
- }
-
- if (!elements.Any() && xmlElement.Name == "root" && xmlElement.Elements().Count() == 1)
- {
- //no elements matched and this node is called 'root' and only has one child... lets see if it matches.
- var childElements = xmlElement.Elements().ElementAt(0).Elements(name).ToArray();
- if (childElements.Any())
- {
- //we've found a match by the first child of an element called 'root' (strange, but sure)
- return Attempt>.Succeed(childElements);
- }
- }
-
- //no deal
- return Attempt>.Fail();
- }
-
- private bool HandleIEnumerableXElement(IEnumerable elements, out object result)
- {
- //Get the count now, so we don't have to call it twice
- int count = elements.Count();
- if (count > 0)
- {
- var firstElement = elements.FirstOrDefault();
- //we have a single element, does it have any children?
- if (firstElement != null && firstElement.Elements().Any() == false && firstElement.HasAttributes == false)
- {
- //no, return the text
- result = firstElement.Value;
- return true;
- }
- else
- {
- //We have more than one matching element, so let's return the collection
- //elements is IEnumerable
- //but we want to be able to re-enter this code
- var root = new XElement(XName.Get("root"));
- root.Add(elements);
- result = new DynamicXml(root);
-
- //From here, you'll either end up back here (because you have )
- //or you use [] indexing and you end up with a single element
- return true;
- }
- }
- result = null;
- return false;
- }
-
- ///
- /// Executes an XPath expression over the BaseElement object
- ///
- ///
- ///
- public DynamicXml XPath(string expression)
- {
- var matched = BaseElement.XPathSelectElements(expression);
- var root = new DynamicXml(" ");
- foreach (var element in matched)
- {
- root.BaseElement.Add(element);
- }
- return root;
- }
-
- ///
- /// Return the string version of the BaseElement object
- ///
- ///
- public override string ToString()
- {
- return ToXml();
- }
-
- public IHtmlString ToHtml()
- {
- return new HtmlString(this.ToXml());
- }
- public DynamicXml Find(string expression)
- {
- return new DynamicXml(BaseElement.XPathSelectElements(expression).FirstOrDefault());
- }
-
- public DynamicXml Find(string attributeName, object value)
- {
- string expression = string.Format("//*[{0}='{1}']", attributeName, value);
- return new DynamicXml(BaseElement.XPathSelectElements(expression).FirstOrDefault());
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return BaseElement.Elements().GetEnumerator();
- }
-
- public IEnumerator GetEnumerator()
- {
- return BaseElement.Elements().Select(e => new DynamicXml(e)).GetEnumerator();
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
-
- public int Count()
- {
- return ((IEnumerable)this).Count();
- }
-
- public bool Any()
- {
- return ((IEnumerable)this).Any();
- }
-
- public IEnumerable Take(int count)
- {
- return ((IEnumerable)this).Take(count);
- }
-
- public IEnumerable Skip(int count)
- {
- return ((IEnumerable)this).Skip(count);
- }
-
- public bool IsNull()
- {
- return false;
- }
- public bool HasValue()
- {
- return true;
- }
-
- public bool IsFirst()
- {
- return IsHelper(n => n.Index() == 0);
- }
- public HtmlString IsFirst(string valueIfTrue)
- {
- return IsHelper(n => n.Index() == 0, valueIfTrue);
- }
- public HtmlString IsFirst(string valueIfTrue, string valueIfFalse)
- {
- return IsHelper(n => n.Index() == 0, valueIfTrue, valueIfFalse);
- }
- public bool IsNotFirst()
- {
- return !IsHelper(n => n.Index() == 0);
- }
- public HtmlString IsNotFirst(string valueIfTrue)
- {
- return IsHelper(n => n.Index() != 0, valueIfTrue);
- }
- public HtmlString IsNotFirst(string valueIfTrue, string valueIfFalse)
- {
- return IsHelper(n => n.Index() != 0, valueIfTrue, valueIfFalse);
- }
- public bool IsPosition(int index)
- {
- if (BaseElement == null || BaseElement.Parent == null)
- {
- return false;
- }
- return IsHelper(n => n.Index() == index);
- }
- public HtmlString IsPosition(int index, string valueIfTrue)
- {
- if (BaseElement == null || BaseElement.Parent == null)
- {
- return new HtmlString(string.Empty);
- }
- return IsHelper(n => n.Index() == index, valueIfTrue);
- }
- public HtmlString IsPosition(int index, string valueIfTrue, string valueIfFalse)
- {
- if (BaseElement == null || BaseElement.Parent == null)
- {
- return new HtmlString(valueIfFalse);
- }
- return IsHelper(n => n.Index() == index, valueIfTrue, valueIfFalse);
- }
- public bool IsModZero(int modulus)
- {
- if (BaseElement == null || BaseElement.Parent == null)
- {
- return false;
- }
- return IsHelper(n => n.Index() % modulus == 0);
- }
- public HtmlString IsModZero(int modulus, string valueIfTrue)
- {
- if (BaseElement == null || BaseElement.Parent == null)
- {
- return new HtmlString(string.Empty);
- }
- return IsHelper(n => n.Index() % modulus == 0, valueIfTrue);
- }
- public HtmlString IsModZero(int modulus, string valueIfTrue, string valueIfFalse)
- {
- if (BaseElement == null || BaseElement.Parent == null)
- {
- return new HtmlString(valueIfFalse);
- }
- return IsHelper(n => n.Index() % modulus == 0, valueIfTrue, valueIfFalse);
- }
-
- public bool IsNotModZero(int modulus)
- {
- if (BaseElement == null || BaseElement.Parent == null)
- {
- return false;
- }
- return IsHelper(n => n.Index() % modulus != 0);
- }
- public HtmlString IsNotModZero(int modulus, string valueIfTrue)
- {
- if (BaseElement == null || this.BaseElement.Parent == null)
- {
- return new HtmlString(string.Empty);
- }
- return IsHelper(n => n.Index() % modulus != 0, valueIfTrue);
- }
- public HtmlString IsNotModZero(int modulus, string valueIfTrue, string valueIfFalse)
- {
- if (this.BaseElement == null || this.BaseElement.Parent == null)
- {
- return new HtmlString(valueIfFalse);
- }
- return IsHelper(n => n.Index() % modulus != 0, valueIfTrue, valueIfFalse);
- }
- public bool IsNotPosition(int index)
- {
- if (this.BaseElement == null || this.BaseElement.Parent == null)
- {
- return false;
- }
- return !IsHelper(n => n.Index() == index);
- }
- public HtmlString IsNotPosition(int index, string valueIfTrue)
- {
- if (this.BaseElement == null || this.BaseElement.Parent == null)
- {
- return new HtmlString(string.Empty);
- }
- return IsHelper(n => n.Index() != index, valueIfTrue);
- }
- public HtmlString IsNotPosition(int index, string valueIfTrue, string valueIfFalse)
- {
- if (this.BaseElement == null || this.BaseElement.Parent == null)
- {
- return new HtmlString(valueIfFalse);
- }
- return IsHelper(n => n.Index() != index, valueIfTrue, valueIfFalse);
- }
- public bool IsLast()
- {
- if (this.BaseElement == null || this.BaseElement.Parent == null)
- {
- return false;
- }
- int count = this.BaseElement.Parent.Elements().Count();
- return IsHelper(n => n.Index() == count - 1);
- }
- public HtmlString IsLast(string valueIfTrue)
- {
- if (this.BaseElement == null || this.BaseElement.Parent == null)
- {
- return new HtmlString(string.Empty);
- }
- int count = this.BaseElement.Parent.Elements().Count();
- return IsHelper(n => n.Index() == count - 1, valueIfTrue);
- }
- public HtmlString IsLast(string valueIfTrue, string valueIfFalse)
- {
- if (this.BaseElement == null || this.BaseElement.Parent == null)
- {
- return new HtmlString(valueIfFalse);
- }
- int count = this.BaseElement.Parent.Elements().Count();
- return IsHelper(n => n.Index() == count - 1, valueIfTrue, valueIfFalse);
- }
- public bool IsNotLast()
- {
- if (this.BaseElement == null || this.BaseElement.Parent == null)
- {
- return false;
- }
- int count = this.BaseElement.Parent.Elements().Count();
- return !IsHelper(n => n.Index() == count - 1);
- }
- public HtmlString IsNotLast(string valueIfTrue)
- {
- if (this.BaseElement == null || this.BaseElement.Parent == null)
- {
- return new HtmlString(string.Empty);
- }
- int count = this.BaseElement.Parent.Elements().Count();
- return IsHelper(n => n.Index() != count - 1, valueIfTrue);
- }
- public HtmlString IsNotLast(string valueIfTrue, string valueIfFalse)
- {
- if (this.BaseElement == null || this.BaseElement.Parent == null)
- {
- return new HtmlString(valueIfFalse);
- }
- int count = this.BaseElement.Parent.Elements().Count();
- return IsHelper(n => n.Index() != count - 1, valueIfTrue, valueIfFalse);
- }
- public bool IsEven()
- {
- return IsHelper(n => n.Index() % 2 == 0);
- }
- public HtmlString IsEven(string valueIfTrue)
- {
- return IsHelper(n => n.Index() % 2 == 0, valueIfTrue);
- }
- public HtmlString IsEven(string valueIfTrue, string valueIfFalse)
- {
- return IsHelper(n => n.Index() % 2 == 0, valueIfTrue, valueIfFalse);
- }
- public bool IsOdd()
- {
- return IsHelper(n => n.Index() % 2 == 1);
- }
- public HtmlString IsOdd(string valueIfTrue)
- {
- return IsHelper(n => n.Index() % 2 == 1, valueIfTrue);
- }
- public HtmlString IsOdd(string valueIfTrue, string valueIfFalse)
- {
- return IsHelper(n => n.Index() % 2 == 1, valueIfTrue, valueIfFalse);
- }
- public bool IsEqual(DynamicXml other)
- {
- return IsHelper(n => n.BaseElement == other.BaseElement);
- }
- public HtmlString IsEqual(DynamicXml other, string valueIfTrue)
- {
- return IsHelper(n => n.BaseElement == other.BaseElement, valueIfTrue);
- }
- public HtmlString IsEqual(DynamicXml other, string valueIfTrue, string valueIfFalse)
- {
- return IsHelper(n => n.BaseElement == other.BaseElement, valueIfTrue, valueIfFalse);
- }
- public bool IsNotEqual(DynamicXml other)
- {
- return IsHelper(n => n.BaseElement != other.BaseElement);
- }
- public HtmlString IsNotEqual(DynamicXml other, string valueIfTrue)
- {
- return IsHelper(n => n.BaseElement != other.BaseElement, valueIfTrue);
- }
- public HtmlString IsNotEqual(DynamicXml other, string valueIfTrue, string valueIfFalse)
- {
- return IsHelper(n => n.BaseElement != other.BaseElement, valueIfTrue, valueIfFalse);
- }
- public bool IsDescendant(DynamicXml other)
- {
- var ancestors = this.Ancestors();
- return IsHelper(n => ancestors.FirstOrDefault(ancestor => ancestor.BaseElement == other.BaseElement) != null);
- }
- public HtmlString IsDescendant(DynamicXml other, string valueIfTrue)
- {
- var ancestors = this.Ancestors();
- return IsHelper(n => ancestors.FirstOrDefault(ancestor => ancestor.BaseElement == other.BaseElement) != null, valueIfTrue);
- }
- public HtmlString IsDescendant(DynamicXml other, string valueIfTrue, string valueIfFalse)
- {
- var ancestors = this.Ancestors();
- return IsHelper(n => ancestors.FirstOrDefault(ancestor => ancestor.BaseElement == other.BaseElement) != null, valueIfTrue, valueIfFalse);
- }
- public bool IsDescendantOrSelf(DynamicXml other)
- {
- var ancestors = this.AncestorsOrSelf();
- return IsHelper(n => ancestors.FirstOrDefault(ancestor => ancestor.BaseElement == other.BaseElement) != null);
- }
- public HtmlString IsDescendantOrSelf(DynamicXml other, string valueIfTrue)
- {
- var ancestors = this.AncestorsOrSelf();
- return IsHelper(n => ancestors.FirstOrDefault(ancestor => ancestor.BaseElement == other.BaseElement) != null, valueIfTrue);
- }
- public HtmlString IsDescendantOrSelf(DynamicXml other, string valueIfTrue, string valueIfFalse)
- {
- var ancestors = this.AncestorsOrSelf();
- return IsHelper(n => ancestors.FirstOrDefault(ancestor => ancestor.BaseElement == other.BaseElement) != null, valueIfTrue, valueIfFalse);
- }
- public bool IsAncestor(DynamicXml other)
- {
- var descendants = this.Descendants();
- return IsHelper(n => descendants.FirstOrDefault(descendant => descendant.BaseElement == other.BaseElement) != null);
- }
- public HtmlString IsAncestor(DynamicXml other, string valueIfTrue)
- {
- var descendants = this.Descendants();
- return IsHelper(n => descendants.FirstOrDefault(descendant => descendant.BaseElement == other.BaseElement) != null, valueIfTrue);
- }
- public HtmlString IsAncestor(DynamicXml other, string valueIfTrue, string valueIfFalse)
- {
- var descendants = this.Descendants();
- return IsHelper(n => descendants.FirstOrDefault(descendant => descendant.BaseElement == other.BaseElement) != null, valueIfTrue, valueIfFalse);
- }
- public bool IsAncestorOrSelf(DynamicXml other)
- {
- var descendants = this.DescendantsOrSelf();
- return IsHelper(n => descendants.FirstOrDefault(descendant => descendant.BaseElement == other.BaseElement) != null);
- }
- public HtmlString IsAncestorOrSelf(DynamicXml other, string valueIfTrue)
- {
- var descendants = this.DescendantsOrSelf();
- return IsHelper(n => descendants.FirstOrDefault(descendant => descendant.BaseElement == other.BaseElement) != null, valueIfTrue);
- }
- public HtmlString IsAncestorOrSelf(DynamicXml other, string valueIfTrue, string valueIfFalse)
- {
- var descendants = this.DescendantsOrSelf();
- return IsHelper(n => descendants.FirstOrDefault(descendant => descendant.BaseElement == other.BaseElement) != null, valueIfTrue, valueIfFalse);
- }
- public IEnumerable Descendants()
- {
- return Descendants(n => true);
- }
- public IEnumerable Descendants(Func func)
- {
- //var flattenedNodes = this.BaseElement.Elements().Map(func, n => n.Elements());
- var flattenedNodes = this.BaseElement.Elements().SelectMany(n => n.Elements()).Where(func);
- return flattenedNodes.ToList().ConvertAll(n => new DynamicXml(n));
- }
- public IEnumerable DescendantsOrSelf()
- {
- return DescendantsOrSelf(n => true);
- }
- public IEnumerable DescendantsOrSelf(Func func)
- {
- //var flattenedNodes = this.BaseElement.Elements().Map(func, n => n.Elements());
- var flattenedNodes = this.BaseElement.Elements().SelectMany(n => n.Elements()).Where(func);
- var list = new List();
- list.Add(this);
- list.AddRange(flattenedNodes.ToList().ConvertAll(n => new DynamicXml(n)));
- return list;
- }
- public IEnumerable Ancestors()
- {
- return Ancestors(item => true);
- }
- public IEnumerable Ancestors(Func func)
- {
- var ancestorList = new List();
- var node = this.BaseElement;
- while (node != null)
- {
- if (node.Parent == null) break;
- XElement parent = node.Parent;
- if (parent != null)
- {
- if (this.BaseElement != parent)
- {
- node = parent;
- if (func(node))
- {
- ancestorList.Add(node);
- }
- }
- else
- {
- break;
- }
- }
- else
- {
- break;
- }
- }
- ancestorList.Reverse();
- return ancestorList.ConvertAll(item => new DynamicXml(item));
- }
- public IEnumerable AncestorsOrSelf()
- {
- return AncestorsOrSelf(item => true);
- }
- public IEnumerable AncestorsOrSelf(Func func)
- {
- List ancestorList = new List();
- var node = this.BaseElement;
- ancestorList.Add(node);
- while (node != null)
- {
- if (node.Parent == null) break;
- XElement parent = node.Parent;
- if (parent != null)
- {
- if (this.BaseElement != parent)
- {
- node = parent;
- if (func(node))
- {
- ancestorList.Add(node);
- }
- }
- else
- {
- break;
- }
- }
- else
- {
- break;
- }
- }
- ancestorList.Reverse();
- return ancestorList.ConvertAll(item => new DynamicXml(item));
- }
-
- public int Index()
- {
- if (this.BaseElement != null && this.BaseElement.Parent != null)
- {
- var elements = this.BaseElement.Parent.Elements();
- int index = 0;
- foreach (var element in elements)
- {
- if (element == this.BaseElement) break;
- index++;
- }
- return index;
- }
- return 0;
- }
-
- public bool IsHelper(Func test)
- {
- return test(this);
- }
- public HtmlString IsHelper(Func test, string valueIfTrue)
- {
- return IsHelper(test, valueIfTrue, string.Empty);
- }
- public HtmlString IsHelper(Func test, string valueIfTrue, string valueIfFalse)
- {
- return test(this) ? new HtmlString(valueIfTrue) : new HtmlString(valueIfFalse);
- }
-
- [Obsolete("Use XmlHelper.StripDashesInElementOrAttributeNames instead")]
- public static string StripDashesInElementOrAttributeNames(string xml)
- {
- return XmlHelper.StripDashesInElementOrAttributeNames(xml);
- }
-
-
- }
-}
diff --git a/src/Umbraco.Core/Dynamics/DynamicXmlConverter.cs b/src/Umbraco.Core/Dynamics/DynamicXmlConverter.cs
deleted file mode 100644
index 291378ad51..0000000000
--- a/src/Umbraco.Core/Dynamics/DynamicXmlConverter.cs
+++ /dev/null
@@ -1,151 +0,0 @@
-using System;
-using System.ComponentModel;
-using System.Globalization;
-using System.Linq;
-using System.Xml;
-using System.Xml.Linq;
-using Umbraco.Core.Plugins;
-
-namespace Umbraco.Core.Dynamics
-{
- ///
- /// Used to return the raw xml string value from DynamicXml when using type converters
- ///
- public class RawXmlString
- {
- public string Value { get; private set; }
-
- public RawXmlString(string value)
- {
- Value = value;
- }
- }
-
- ///
- /// Used to return the raw xml XElement value from DynamicXml when using type converters
- ///
- public class RawXElement
- {
- public XElement Value { get; private set; }
-
- public RawXElement(XElement value)
- {
- Value = value;
- }
- }
-
- ///
- /// Used to return the raw xml XElement value from DynamicXml when using type converters
- ///
- public class RawXmlElement
- {
- public XmlElement Value { get; private set; }
-
- public RawXmlElement(XmlElement value)
- {
- Value = value;
- }
- }
-
- ///
- /// Used to return the raw xml XmlDocument value from DynamicXml when using type converters
- ///
- public class RawXmlDocument
- {
- public XmlDocument Value { get; private set; }
-
- public RawXmlDocument(XmlDocument value)
- {
- Value = value;
- }
- }
-
- ///
- /// A custom type converter for DynamicXml
- ///
- public class DynamicXmlConverter : TypeConverter
- {
- public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
- {
- var convertableTypes = new[]
- {
- typeof(string),
- typeof(XElement),
- typeof(XmlElement),
- typeof(XmlDocument),
- typeof(RawXmlString),
- typeof(RawXElement),
- typeof(RawXmlElement),
- typeof(RawXmlDocument)
- };
-
- return convertableTypes.Any(x => TypeHelper.IsTypeAssignableFrom(x, destinationType))
- || base.CanConvertFrom(context, destinationType);
- }
-
- public override object ConvertTo(
- ITypeDescriptorContext context,
- CultureInfo culture,
- object value,
- Type destinationType)
- {
- var dxml = value as DynamicXml;
- if (dxml == null)
- return null;
- //string
- if (TypeHelper.IsTypeAssignableFrom(destinationType))
- {
- return value.ToString();
- }
-
- //XElement
- if (TypeHelper.IsTypeAssignableFrom(destinationType))
- {
- return dxml.BaseElement;
- }
- //XmlElement
- if (TypeHelper.IsTypeAssignableFrom(destinationType))
- {
- var xDoc = new XmlDocument();
- xDoc.LoadXml(dxml.ToString());
- return xDoc.DocumentElement;
- }
- //XmlDocument
- if (TypeHelper.IsTypeAssignableFrom(destinationType))
- {
- var xDoc = new XmlDocument();
- xDoc.LoadXml(dxml.ToString());
- return xDoc;
- }
-
- //RAW values:
- //string
- if (TypeHelper.IsTypeAssignableFrom(destinationType))
- {
- return new RawXmlString(dxml.ToRawXml());
- }
- //XElement
- if (TypeHelper.IsTypeAssignableFrom(destinationType))
- {
- return new RawXElement(dxml.RawXmlElement);
- }
- //XmlElement
- if (TypeHelper.IsTypeAssignableFrom(destinationType))
- {
- var xDoc = new XmlDocument();
- xDoc.LoadXml(dxml.ToRawXml());
- return new RawXmlElement(xDoc.DocumentElement);
- }
- //XmlDocument
- if (TypeHelper.IsTypeAssignableFrom(destinationType))
- {
- var xDoc = new XmlDocument();
- xDoc.LoadXml(dxml.ToRawXml());
- return new RawXmlDocument(xDoc);
- }
-
-
- return base.ConvertTo(context, culture, value, destinationType);
- }
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Dynamics/ExtensionMethodFinder.cs b/src/Umbraco.Core/Dynamics/ExtensionMethodFinder.cs
deleted file mode 100644
index 33a938154a..0000000000
--- a/src/Umbraco.Core/Dynamics/ExtensionMethodFinder.cs
+++ /dev/null
@@ -1,183 +0,0 @@
-using System;
-using System.Collections.Concurrent;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Linq.Expressions;
-using System.Text;
-using System.Web.Services.Description;
-using Umbraco.Core.Cache;
-using Umbraco.Core.Logging;
-using Umbraco.Core.Plugins;
-
-namespace Umbraco.Core.Dynamics
-{
- ///
- /// Utility class for finding extension methods on a type to execute
- ///
- internal static class ExtensionMethodFinder
- {
- ///
- /// The static cache for extension methods found that match the criteria that we are looking for
- ///
- private static readonly ConcurrentDictionary, MethodInfo[]> MethodCache = new ConcurrentDictionary, MethodInfo[]>();
-
- private static IEnumerable GetTypes(Assembly a)
- {
- try
- {
- return TypeFinder.GetTypesWithFormattedException(a);
- }
- catch (ReflectionTypeLoadException ex)
- {
- // is this going to flood the log?
- LogHelper.Error(typeof (ExtensionMethodFinder), "Failed to get types.", ex);
- return Enumerable.Empty();
- }
- }
-
- ///
- /// Returns the enumerable of all extension method info's in the app domain = USE SPARINGLY!!!
- ///
- ///
- ///
- /// We cache this as a sliding 5 minute exiration, in unit tests there's over 1100 methods found, surely that will eat up a bit of memory so we want
- /// to make sure we give it back.
- ///
- private static IEnumerable GetAllExtensionMethodsInAppDomain(IRuntimeCacheProvider runtimeCacheProvider)
- {
- if (runtimeCacheProvider == null) throw new ArgumentNullException("runtimeCacheProvider");
-
- return runtimeCacheProvider.GetCacheItem(typeof (ExtensionMethodFinder).Name, () => TypeFinder.GetAssembliesWithKnownExclusions()
- // assemblies that contain extension methods
- .Where(a => a.IsDefined(typeof (ExtensionAttribute), false))
- // types that contain extension methods
- .SelectMany(a => GetTypes(a)
- .Where(t => t.IsDefined(typeof (ExtensionAttribute), false) && t.IsSealed && t.IsGenericType == false && t.IsNested == false))
- // actual extension methods
- .SelectMany(t => t.GetMethods(BindingFlags.Static | BindingFlags.Public)
- .Where(m => m.IsDefined(typeof (ExtensionAttribute), false)))
- // and also IEnumerable extension methods - because the assembly is excluded
- .Concat(typeof (Enumerable).GetMethods(BindingFlags.Static | BindingFlags.Public))
- //If we don't do this then we'll be scanning all assemblies each time!
- .ToArray(),
-
- //only cache for 5 minutes
- timeout: TimeSpan.FromMinutes(5),
-
- //each time this is accessed it will be for 5 minutes longer
- isSliding:true);
- }
-
- ///
- /// Returns all extension methods found matching the definition
- ///
- ///
- /// The runtime cache is used to temporarily cache all extension methods found in the app domain so that
- /// while we search for individual extension methods, the process will be reasonably 'quick'. We then statically
- /// cache the MethodInfo's that we are looking for and then the runtime cache will expire and give back all that memory.
- ///
- ///
- ///
- ///
- /// The arguments EXCLUDING the 'this' argument in an extension method
- ///
- ///
- ///
- /// NOTE: This will be an intensive method to call! Results will be cached based on the key (args) of this method
- ///
- internal static IEnumerable GetAllExtensionMethods(IRuntimeCacheProvider runtimeCache, Type thisType, string name, int argumentCount)
- {
- var key = new Tuple(thisType, name, argumentCount);
-
- return MethodCache.GetOrAdd(key, tuple =>
- {
- var candidates = GetAllExtensionMethodsInAppDomain(runtimeCache);
-
- // filter by name
- var filtr1 = candidates.Where(m => m.Name == name);
-
- // filter by args count
- // ensure we add + 1 to the arg count because the 'this' arg is not included in the count above!
- var filtr2 = filtr1.Where(m => m.GetParameters().Length == argumentCount + 1);
-
- // filter by first parameter type (target of the extension method)
- // ie find the right overload that can take genericParameterType
- // (which will be either DynamicNodeList or List which is IEnumerable)
- var filtr3 = filtr2.Select(x =>
- {
- var t = x.GetParameters()[0].ParameterType; // exists because of +1 above
- var bindings = new Dictionary();
- if (TypeHelper.MatchType(thisType, t, bindings) == false) return null;
-
- // create the generic method if necessary
- if (x.ContainsGenericParameters == false) return x;
- var targs = t.GetGenericArguments().Select(y => bindings[y.Name]).ToArray();
- return x.MakeGenericMethod(targs);
- }).Where(x => x != null);
-
- return filtr3.ToArray();
- });
-
- }
-
- private static MethodInfo DetermineMethodFromParams(IEnumerable methods, Type genericType, IEnumerable args)
- {
- MethodInfo methodToExecute = null;
-
- //Given the args, lets get the types and compare the type sequence to try and find the correct overload
- var argTypes = args.Select(o =>
- {
- var oe = (o as Expression);
- return oe != null ? oe.Type : o.GetType();
- });
-
- var methodsWithArgTypes = methods.Select(method => new
- {
- method,
- //skip the first arg because that is the extension method type ('this') that we are looking for
- types = method.GetParameters().Select(pi => pi.ParameterType).Skip(1)
- });
-
- //This type comparer will check
- var typeComparer = new DelegateEqualityComparer(
- //Checks if the argument type passed in can be assigned from the parameter type in the method. For
- // example, if the argument type is HtmlHelper but the method parameter type is HtmlHelper then
- // it will match because the argument is assignable to that parameter type and will be able to execute
- TypeHelper.IsTypeAssignableFrom,
- //This will not ever execute but if it does we need to get the hash code of the string because the hash
- // code of a type is random
- type => type.FullName.GetHashCode());
-
- var firstMatchingOverload = methodsWithArgTypes
- .FirstOrDefault(m => m.types.SequenceEqual(argTypes, typeComparer));
-
- if (firstMatchingOverload != null)
- {
- methodToExecute = firstMatchingOverload.method;
- }
-
- return methodToExecute;
- }
-
- public static MethodInfo FindExtensionMethod(IRuntimeCacheProvider runtimeCache, Type thisType, object[] args, string name, bool argsContainsThis)
- {
- Type genericType = null;
- if (thisType.IsGenericType)
- {
- genericType = thisType.GetGenericArguments()[0];
- }
-
- args = args
- //if the args contains 'this', remove the first one since that is 'this' and we don't want to use
- //that in the method searching
- .Skip(argsContainsThis ? 1 : 0)
- .ToArray();
-
- var methods = GetAllExtensionMethods(runtimeCache, thisType, name, args.Length).ToArray();
-
- return DetermineMethodFromParams(methods, genericType, args);
- }
- }
-}
diff --git a/src/Umbraco.Core/Dynamics/ParseException.cs b/src/Umbraco.Core/Dynamics/ParseException.cs
deleted file mode 100644
index 5208644306..0000000000
--- a/src/Umbraco.Core/Dynamics/ParseException.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using System;
-
-namespace Umbraco.Core.Dynamics
-{
- internal sealed class ParseException : Exception
- {
- readonly int _position;
-
- public ParseException(string message, int position)
- : base(message)
- {
- this._position = position;
- }
-
- public int Position
- {
- get { return _position; }
- }
-
- public override string ToString()
- {
- return string.Format(Res.ParseExceptionFormat, Message, _position);
- }
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Dynamics/PropertyResult.cs b/src/Umbraco.Core/Dynamics/PropertyResult.cs
deleted file mode 100644
index 14689f653a..0000000000
--- a/src/Umbraco.Core/Dynamics/PropertyResult.cs
+++ /dev/null
@@ -1,47 +0,0 @@
-using System;
-using Umbraco.Core.Models;
-using System.Web;
-using Umbraco.Core.Models.PublishedContent;
-
-namespace Umbraco.Core.Dynamics
-{
- internal class PropertyResult : IPublishedProperty, IHtmlString
- {
- private readonly IPublishedProperty _source;
- private readonly string _alias;
- private readonly object _value;
- private readonly PropertyResultType _type;
-
- internal PropertyResult(IPublishedProperty source, PropertyResultType type)
- {
- if (source == null) throw new ArgumentNullException("source");
-
- _type = type;
- _source = source;
- }
-
- internal PropertyResult(string alias, object value, PropertyResultType type)
- {
- if (alias == null) throw new ArgumentNullException("alias");
- if (value == null) throw new ArgumentNullException("value");
-
- _type = type;
- _alias = alias;
- _value = value;
- }
-
- internal PropertyResultType PropertyType { get { return _type; } }
-
- public string PropertyTypeAlias { get { return _source == null ? _alias : _source.PropertyTypeAlias; } }
- public object SourceValue { get { return _source == null ? _value : _source.SourceValue; } }
- public bool HasValue { get { return _source == null || _source.HasValue; } }
- public object Value { get { return _source == null ? _value : _source.Value; } }
- public object XPathValue { get { return Value == null ? null : Value.ToString(); } }
-
- public string ToHtmlString()
- {
- var value = Value;
- return value == null ? string.Empty : value.ToString();
- }
- }
-}
diff --git a/src/Umbraco.Core/Dynamics/QueryableExtensions.cs b/src/Umbraco.Core/Dynamics/QueryableExtensions.cs
deleted file mode 100644
index 25c260d7ca..0000000000
--- a/src/Umbraco.Core/Dynamics/QueryableExtensions.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-using System;
-using System.Linq;
-using System.Linq.Expressions;
-using System.Reflection;
-
-namespace Umbraco.Core.Dynamics
-{
- ///
- /// Extension methods for IQueryable
- ///
- ///
- /// NOTE: Ordering code taken from: http://stackoverflow.com/questions/41244/dynamic-linq-orderby-on-ienumerablet
- ///
- /// ANOTHER NOTE: We have a bastardized version of Dynamic Linq existing at Umbraco.Web.Dynamics however it's been hacked so not
- /// sure we can use it for anything other than DynamicNode.
- ///
- internal static class QueryableExtensions
- {
- public static IOrderedQueryable OrderBy(this IQueryable source, string property)
- {
- return ApplyOrder(source, property, "OrderBy");
- }
- public static IOrderedQueryable OrderByDescending(this IQueryable source, string property)
- {
- return ApplyOrder(source, property, "OrderByDescending");
- }
- public static IOrderedQueryable ThenBy(this IOrderedQueryable source, string property)
- {
- return ApplyOrder(source, property, "ThenBy");
- }
- public static IOrderedQueryable ThenByDescending(this IOrderedQueryable source, string property)
- {
- return ApplyOrder(source, property, "ThenByDescending");
- }
- static IOrderedQueryable ApplyOrder(IQueryable source, string property, string methodName)
- {
- string[] props = property.Split('.');
- Type type = typeof(T);
- ParameterExpression arg = Expression.Parameter(type, "x");
- Expression expr = arg;
- foreach (string prop in props)
- {
- // use reflection (not ComponentModel) to mirror LINQ
- PropertyInfo pi = type.GetProperty(prop, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
- expr = Expression.Property(expr, pi);
- type = pi.PropertyType;
- }
- Type delegateType = typeof(Func<,>).MakeGenericType(typeof(T), type);
- LambdaExpression lambda = Expression.Lambda(delegateType, expr, arg);
-
- object result = typeof(Queryable).GetMethods().Single(
- method => method.Name == methodName
- && method.IsGenericMethodDefinition
- && method.GetGenericArguments().Length == 2
- && method.GetParameters().Length == 2)
- .MakeGenericMethod(typeof(T), type)
- .Invoke(null, new object[] { source, lambda });
- return (IOrderedQueryable)result;
- }
-
-
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Dynamics/Res.cs b/src/Umbraco.Core/Dynamics/Res.cs
deleted file mode 100644
index 4ea5193d68..0000000000
--- a/src/Umbraco.Core/Dynamics/Res.cs
+++ /dev/null
@@ -1,50 +0,0 @@
-namespace Umbraco.Core.Dynamics
-{
- internal static class Res
- {
- public const string DuplicateIdentifier = "The identifier '{0}' was defined more than once";
- public const string ExpressionTypeMismatch = "Expression of type '{0}' expected";
- public const string ExpressionExpected = "Expression expected";
- public const string InvalidCharacterLiteral = "Character literal must contain exactly one character";
- public const string InvalidIntegerLiteral = "Invalid integer literal '{0}'";
- public const string InvalidRealLiteral = "Invalid real literal '{0}'";
- public const string UnknownIdentifier = "Unknown identifier '{0}'";
- public const string NoItInScope = "No 'it' is in scope";
- public const string IifRequiresThreeArgs = "The 'iif' function requires three arguments";
- public const string FirstExprMustBeBool = "The first expression must be of type 'Boolean'";
- public const string BothTypesConvertToOther = "Both of the types '{0}' and '{1}' convert to the other";
- public const string NeitherTypeConvertsToOther = "Neither of the types '{0}' and '{1}' converts to the other";
- public const string MissingAsClause = "Expression is missing an 'as' clause";
- public const string ArgsIncompatibleWithLambda = "Argument list incompatible with lambda expression";
- public const string TypeHasNoNullableForm = "Type '{0}' has no nullable form";
- public const string NoMatchingConstructor = "No matching constructor in type '{0}'";
- public const string AmbiguousConstructorInvocation = "Ambiguous invocation of '{0}' constructor";
- public const string CannotConvertValue = "A value of type '{0}' cannot be converted to type '{1}'";
- public const string NoApplicableMethod = "No applicable method '{0}' exists in type '{1}'";
- public const string MethodsAreInaccessible = "Methods on type '{0}' are not accessible";
- public const string MethodIsVoid = "Method '{0}' in type '{1}' does not return a value";
- public const string AmbiguousMethodInvocation = "Ambiguous invocation of method '{0}' in type '{1}'";
- public const string UnknownPropertyOrField = "No property or field '{0}' exists in type '{1}'";
- public const string NoApplicableAggregate = "No applicable aggregate method '{0}' exists";
- public const string CannotIndexMultiDimArray = "Indexing of multi-dimensional arrays is not supported";
- public const string InvalidIndex = "Array index must be an integer expression";
- public const string NoApplicableIndexer = "No applicable indexer exists in type '{0}'";
- public const string AmbiguousIndexerInvocation = "Ambiguous invocation of indexer in type '{0}'";
- public const string IncompatibleOperand = "Operator '{0}' incompatible with operand type '{1}'";
- public const string IncompatibleOperands = "Operator '{0}' incompatible with operand types '{1}' and '{2}'";
- public const string UnterminatedStringLiteral = "Unterminated string literal";
- public const string InvalidCharacter = "Syntax error '{0}'";
- public const string DigitExpected = "Digit expected";
- public const string SyntaxError = "Syntax error";
- public const string TokenExpected = "{0} expected";
- public const string ParseExceptionFormat = "{0} (at index {1})";
- public const string ColonExpected = "':' expected";
- public const string OpenParenExpected = "'(' expected";
- public const string CloseParenOrOperatorExpected = "')' or operator expected";
- public const string CloseParenOrCommaExpected = "')' or ',' expected";
- public const string DotOrOpenParenExpected = "'.' or '(' expected";
- public const string OpenBracketExpected = "'[' expected";
- public const string CloseBracketOrCommaExpected = "']' or ',' expected";
- public const string IdentifierExpected = "Identifier expected";
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Dynamics/Signature.cs b/src/Umbraco.Core/Dynamics/Signature.cs
deleted file mode 100644
index cececc502d..0000000000
--- a/src/Umbraco.Core/Dynamics/Signature.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace Umbraco.Core.Dynamics
-{
- internal class Signature : IEquatable
- {
- public DynamicProperty[] Properties { get; set; }
- public int HashCode { get; set; }
-
- public Signature(IEnumerable properties)
- {
- this.Properties = properties.ToArray();
- HashCode = 0;
- foreach (DynamicProperty p in this.Properties)
- {
- HashCode ^= p.Name.GetHashCode() ^ p.Type.GetHashCode();
- }
- }
-
- public override int GetHashCode()
- {
- return HashCode;
- }
-
- public override bool Equals(object obj)
- {
- return obj is Signature && Equals((Signature)obj);
- }
-
- public bool Equals(Signature other)
- {
- if (Properties.Length != other.Properties.Length) return false;
- for (int i = 0; i < Properties.Length; i++)
- {
- if (Properties[i].Name != other.Properties[i].Name ||
- Properties[i].Type != other.Properties[i].Type) return false;
- }
- return true;
- }
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Models/PublishedContent/PropertyResult.cs b/src/Umbraco.Core/Models/PublishedContent/PropertyResult.cs
new file mode 100644
index 0000000000..4bf96eedea
--- /dev/null
+++ b/src/Umbraco.Core/Models/PublishedContent/PropertyResult.cs
@@ -0,0 +1,45 @@
+using System;
+using System.Web;
+
+namespace Umbraco.Core.Models.PublishedContent
+{
+ // fixme - temp
+ internal class PropertyResult : IPublishedProperty, IHtmlString
+ {
+ private readonly IPublishedProperty _source;
+ private readonly string _alias;
+ private readonly object _value;
+
+ internal PropertyResult(IPublishedProperty source, PropertyResultType type)
+ {
+ if (source == null) throw new ArgumentNullException(nameof(source));
+
+ PropertyType = type;
+ _source = source;
+ }
+
+ internal PropertyResult(string alias, object value, PropertyResultType type)
+ {
+ if (alias == null) throw new ArgumentNullException(nameof(alias));
+ if (value == null) throw new ArgumentNullException(nameof(value));
+
+ PropertyType = type;
+ _alias = alias;
+ _value = value;
+ }
+
+ internal PropertyResultType PropertyType { get; }
+
+ public string PropertyTypeAlias => _source == null ? _alias : _source.PropertyTypeAlias;
+ public object SourceValue => _source == null ? _value : _source.SourceValue;
+ public bool HasValue => _source == null || _source.HasValue;
+ public object Value => _source == null ? _value : _source.Value;
+ public object XPathValue => Value?.ToString();
+
+ public string ToHtmlString()
+ {
+ var value = Value;
+ return value?.ToString() ?? string.Empty;
+ }
+ }
+}
diff --git a/src/Umbraco.Core/Dynamics/PropertyResultType.cs b/src/Umbraco.Core/Models/PublishedContent/PropertyResultType.cs
similarity index 60%
rename from src/Umbraco.Core/Dynamics/PropertyResultType.cs
rename to src/Umbraco.Core/Models/PublishedContent/PropertyResultType.cs
index d1ab0904f5..bf045ef517 100644
--- a/src/Umbraco.Core/Dynamics/PropertyResultType.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/PropertyResultType.cs
@@ -1,23 +1,20 @@
-namespace Umbraco.Core.Dynamics
-{
- ///
- /// Currently just used for informational purposes as to where a PropertyResult object was created from.
- ///
- internal enum PropertyResultType
- {
- ///
- /// The property resolved was a normal document property
- ///
- UserProperty,
-
- ///
- /// The property resolved was a property defined as a member on the document object (IPublishedContent) itself
- ///
- ReflectedProperty,
-
- ///
- /// The property was created manually for a custom purpose
- ///
- CustomProperty
- }
-}
\ No newline at end of file
+namespace Umbraco.Core.Models.PublishedContent
+{
+ internal enum PropertyResultType
+ {
+ ///
+ /// The property resolved was a normal document property
+ ///
+ UserProperty,
+
+ ///
+ /// The property resolved was a property defined as a member on the document object (IPublishedContent) itself
+ ///
+ ReflectedProperty,
+
+ ///
+ /// The property was created manually for a custom purpose
+ ///
+ CustomProperty
+ }
+}
diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyType.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyType.cs
index 2fb88e1002..373e2be299 100644
--- a/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyType.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyType.cs
@@ -3,7 +3,6 @@ using System.Globalization;
using System.Linq;
using System.Xml.Linq;
using System.Xml.XPath;
-using Umbraco.Core.Dynamics;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Xml;
@@ -248,7 +247,7 @@ namespace Umbraco.Core.Models.PublishedContent
// use the converter else use dark (& performance-wise expensive) magic
return _converter != null
? _converter.ConvertSourceToInter(this, source, preview)
- : ConvertUsingDarkMagic(source);
+ : source;
}
// converts the inter value into the clr value
@@ -287,37 +286,6 @@ namespace Umbraco.Core.Models.PublishedContent
return inter.ToString().Trim();
}
- internal static object ConvertUsingDarkMagic(object source)
- {
- // convert to string
- var stringSource = source as string;
- if (stringSource == null) return source; // not a string => return the object
- stringSource = stringSource.Trim();
- if (stringSource.Length == 0) return null; // empty string => return null
-
- // try numbers and booleans
- // make sure we use the invariant culture ie a dot decimal point, comma is for csv
- // NOTE far from perfect: "01a" is returned as a string but "012" is returned as an integer...
- int i;
- if (int.TryParse(stringSource, NumberStyles.Integer, CultureInfo.InvariantCulture, out i))
- return i;
- float f;
- if (float.TryParse(stringSource, NumberStyles.Float, CultureInfo.InvariantCulture, out f))
- return f;
- bool b;
- if (bool.TryParse(stringSource, out b))
- return b;
-
- //TODO: We can change this just like we do for the JSON converter - but to maintain compatibility might mean this still has to remain here
-
- // try xml - that is expensive, performance-wise
- XElement elt;
- if (XmlHelper.TryCreateXElementFromPropertyValue(stringSource, out elt))
- return new DynamicXml(elt); // xml => return DynamicXml for compatiblity's sake
-
- return source;
- }
-
// gets the property CLR type
public Type ClrType
{
diff --git a/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs b/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs
index 4117685187..1db9ce88ad 100644
--- a/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs
+++ b/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs
@@ -25,7 +25,7 @@ namespace Umbraco.Core.PropertyEditors
public virtual object ConvertSourceToInter(PublishedPropertyType propertyType, object source, bool preview)
{
- return PublishedPropertyType.ConvertUsingDarkMagic(source);
+ return source;
}
public virtual object ConvertInterToObject(PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj
index 3bd5d7ed18..b01dd2e1f2 100644
--- a/src/Umbraco.Core/Umbraco.Core.csproj
+++ b/src/Umbraco.Core/Umbraco.Core.csproj
@@ -220,9 +220,6 @@
-
-
-
@@ -261,6 +258,8 @@
+
+
@@ -1040,16 +1039,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -1117,10 +1106,6 @@
-
-
-
-
@@ -1147,7 +1132,6 @@
-
diff --git a/src/Umbraco.Tests/DynamicsAndReflection/ExtensionMethodFinderTests.cs b/src/Umbraco.Tests/DynamicsAndReflection/ExtensionMethodFinderTests.cs
deleted file mode 100644
index 550310d164..0000000000
--- a/src/Umbraco.Tests/DynamicsAndReflection/ExtensionMethodFinderTests.cs
+++ /dev/null
@@ -1,395 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using System.Reflection;
-using System.Text;
-using System.Web.Mvc;
-using NUnit.Framework;
-using Umbraco.Core;
-using Umbraco.Core.Cache;
-using Umbraco.Core.Dynamics;
-
-namespace Umbraco.Tests.DynamicsAndReflection
-{
- [TestFixture]
- public class ExtensionMethodFinderTests
- {
- #region Tests Elements
-
- public class TestClass { }
- public class TestClass : TestClass { }
- public class TestClassOfInt : TestClass { }
- public class TestClassOfString : TestClass { }
-
- public void TestMethod1(int value) { }
- public void TestMethod2(T value) { }
- public void TestMethod3(T value1, T value2) { }
- public void TestMethod4(T1 value1, T2 value2) { }
- public void TestMethod5(List value) { }
- public void TestMethod6(int value) { }
- public void TestMethod6(string value) { }
- public void TestMethod7(IList value) { }
- public void TestMethod8(IDictionary value) { }
-
- public interface ITestDict : IDictionary { }
-
- #endregion
-
- #region Utilities
-
- private static readonly IRuntimeCacheProvider NullCache = new NullCacheProvider();
-
- private static MethodInfo FindExtensionMethod(Type thisType, object[] args, string name, bool argsContainsThis)
- {
- return ExtensionMethodFinder.FindExtensionMethod(NullCache, thisType, args, name, argsContainsThis);
- }
-
- #endregion
-
- #region Tests Set #1
-
- [Test]
- public void Find_Non_Overloaded_Method()
- {
- var class1 = new TestClass();
-
- var method = FindExtensionMethod(typeof(TestClass), new object[] { 1 }, "SimpleMethod", false);
- Assert.IsNotNull(method);
- method.Invoke(null, new object[] { class1, 1 });
-
- method = FindExtensionMethod(typeof(TestClass), new object[] { "x" }, "SimpleMethod", false);
- Assert.IsNull(method);
- }
-
- [Test]
- public void Find_SimpleOverloaded()
- {
- var class1 = new TestClass();
-
- var method = FindExtensionMethod(typeof(TestClass), new object[] { 1 }, "SimpleOverloadMethod", false);
- Assert.IsNotNull(method);
- method.Invoke(null, new object[] { class1, 1 });
-
- method = FindExtensionMethod(typeof(TestClass), new object[] { "x" }, "SimpleOverloadMethod", false);
- Assert.IsNotNull(method);
- method.Invoke(null, new object[] { class1, "x" });
- }
-
- [Test]
- public void Find_SimpleOverloaded_ArgsContainingThis()
- {
- var class1 = new TestClass();
-
- var method = FindExtensionMethod(typeof(TestClass), new object[] { class1, 1 }, "SimpleOverloadMethod", true);
- Assert.IsNotNull(method);
- method.Invoke(null, new object[] { class1, 1 });
-
- method = FindExtensionMethod(typeof(TestClass), new object[] { class1, "x" }, "SimpleOverloadMethod", true);
- Assert.IsNotNull(method);
- method.Invoke(null, new object[] { class1, "x" });
- }
-
- [Test]
- public void Find_NonOverloadedGenericEnumerable()
- {
- var class1 = Enumerable.Empty();
-
- var method = FindExtensionMethod(typeof(IEnumerable), new object[] { 1 }, "SimpleEnumerableGenericMethod", false);
- Assert.IsNotNull(method);
- method.Invoke(null, new object[] { class1, 1 });
-
- method = FindExtensionMethod(typeof(IEnumerable), new object[] { "x" }, "SimpleEnumerableGenericMethod", false);
- Assert.IsNull(method);
- }
-
- [Test]
- public void Find_OverloadedGenericEnumerable()
- {
- var class1 = Enumerable.Empty();
-
- var method = FindExtensionMethod(typeof(IEnumerable), new object[] { 1 }, "SimpleOverloadEnumerableGenericMethod", false);
- Assert.IsNotNull(method);
- method.Invoke(null, new object[] { class1, 1 });
-
- method = FindExtensionMethod(typeof(IEnumerable), new object[] { "x" }, "SimpleOverloadEnumerableGenericMethod", false);
- Assert.IsNotNull(method);
- method.Invoke(null, new object[] { class1, "x" });
- }
-
- [Test]
- public void Find_InheritedType()
- {
- var genericTestClass = new TestClass();
- var nonGenericTestClass = new TestClass();
-
- // not really testing "generics" here, just inheritance
-
- var method = FindExtensionMethod(typeof(TestClass), new object[] { genericTestClass }, "GenericParameterMethod", false);
- Assert.IsNotNull(method);
-
- method = FindExtensionMethod(typeof(TestClass), new object[] { nonGenericTestClass }, "GenericParameterMethod", false);
- Assert.IsNotNull(method);
- }
-
- [Test]
- public void Find_TrueGeneric()
- {
- var c = new TestClass();
-
- var method = FindExtensionMethod(c.GetType(), new object[] { }, "GenericMethod", false);
- Assert.IsNotNull(method);
- }
-
- [Test]
- public void GetMethodVsGetMethods()
- {
- Assert.Throws(() =>
- {
- var m = typeof (ExtensionMethodFinderTests).GetMethod("TestMethod6");
- });
-
- var ms = typeof (ExtensionMethodFinderTests).GetMethods().Where(x => x.Name == "TestMethod6");
- Assert.AreEqual(2, ms.Count());
- }
-
- #endregion
-
- #region Tests Set #2 - Working with Generics
-
- // To expand on Jon's answer, the reason this doesn't work is because in regular,
- // non-dynamic code extension methods work by doing a full search of all the
- // classes known to the compiler for a static class that has an extension method
- // that match. The search goes in order based on the namespace nesting and available
- // "using" directives in each namespace.
- //
- // That means that in order to get a dynamic extension method invocation resolved
- // correctly, somehow the DLR has to know at runtime what all the namespace nestings
- // and "using" directives were in your source code. We do not have a mechanism handy
- // for encoding all that information into the call site. We considered inventing
- // such a mechanism, but decided that it was too high cost and produced too much
- // schedule risk to be worth it.
- //
- // Eric Lippert, http://stackoverflow.com/questions/5311465/extension-method-and-dynamic-object-in-c-sharp
- //
- // And so...
- // Obviously MatchType is broken and incomplete, it does not handle
- // - ref & out parameters
- // - array types
- // - structs
- // - generics constraints
- // - generics variance
- // - ...
-
- [Test]
- public void Temp()
- {
- var t1 = typeof (IList);
- var t2 = typeof (IList<>);
- Assert.IsTrue(t2.IsGenericTypeDefinition);
- Assert.AreEqual(t2, t1.GetGenericTypeDefinition());
- var m = typeof (ExtensionMethodFinderTests).GetMethod("TestMethod7");
- var parms = m.GetParameters();
- Assert.AreEqual(1, parms.Length);
- var parm = parms[0];
- var t3 = parm.ParameterType; // IList
- Assert.AreEqual(t2, t3.GetGenericTypeDefinition());
-
- Assert.AreEqual(typeof (int), t1.GetGenericArguments()[0]);
- Assert.IsFalse(t1.GetGenericArguments()[0].IsGenericParameter);
- //Assert.AreEqual(???, t2.GetGenericArguments()[0]);
- Assert.IsTrue(t2.GetGenericArguments()[0].IsGenericParameter);
- Assert.AreEqual("T", t2.GetGenericArguments()[0].Name);
- Assert.IsTrue(t3.GetGenericArguments()[0].IsGenericParameter);
- Assert.AreEqual("T", t3.GetGenericArguments()[0].Name);
- }
-
-
-
- [Test]
- public void Find_Generic_Enumerable_Method()
- {
- MethodInfo method;
- var class1 = Enumerable.Empty();
-
- method = ExtensionMethodFinder.FindExtensionMethod(new NullCacheProvider(), typeof(IEnumerable), new object[] { }, "GenericMethod", false);
- Assert.IsNotNull(method);
- method.Invoke(null, new object[] { class1 });
-
- var class2 = new TestClassCollection();
-
- method = ExtensionMethodFinder.FindExtensionMethod(new NullCacheProvider(), typeof(TestClassCollection), new object[] { }, "GenericMethod", false);
- Assert.IsNotNull(method);
- method.Invoke(null, new object[] { class2 });
- }
-
- [Ignore("This is just testing the below GetMethodForArguments method - Stephen was working on this but it's not used in the core")]
- [Test]
- public void TypesTests()
- {
- Assert.IsTrue(typeof(int[]).Inherits());
- Assert.IsFalse(typeof(int[]).Inherits());
-
- var m1 = typeof(ExtensionMethodFinderTests).GetMethod("TestMethod1");
-
- var a1A = new object[] { 1 };
- var m1A = GetMethodForArguments(m1, a1A);
- Assert.IsNotNull(m1A);
- m1A.Invoke(this, a1A);
-
- var a1B = new object[] { "foo" };
- var m1B = GetMethodForArguments(m1, a1B);
- Assert.IsNull(m1B);
-
- var m2 = typeof(ExtensionMethodFinderTests).GetMethod("TestMethod2");
-
- var m2A = GetMethodForArguments(m2, a1A);
- Assert.IsNotNull(m2A);
- m2A.Invoke(this, a1A);
-
- var m2B = GetMethodForArguments(m2, a1B);
- Assert.IsNotNull(m2B);
- m2B.Invoke(this, a1B);
-
- var m3 = typeof(ExtensionMethodFinderTests).GetMethod("TestMethod3");
-
- var a3A = new object[] { 1, 2 };
- var m3A = GetMethodForArguments(m3, a3A);
- Assert.IsNotNull(m3A);
- m3A.Invoke(this, a3A);
-
- var a3B = new object[] { 1, "foo" };
- var m3B = GetMethodForArguments(m3, a3B);
- Assert.IsNull(m3B);
-
- var m4 = typeof(ExtensionMethodFinderTests).GetMethod("TestMethod4");
-
- var m4A = GetMethodForArguments(m4, a3A);
- Assert.IsNotNull(m4A);
- m4A.Invoke(this, a3A);
-
- var m4B = GetMethodForArguments(m4, a3B);
- Assert.IsNotNull(m4B);
- m4B.Invoke(this, a3B);
-
- var m5 = typeof(ExtensionMethodFinderTests).GetMethod("TestMethod5");
-
- // note - currently that fails because we can't match List with List
- var a5 = new object[] { new List() };
- var m5A = GetMethodForArguments(m5, a5);
- Assert.IsNotNull(m5A);
-
- // note - should we also handle "ref" and "out" parameters?
- // SD: NO, lets not make this more complicated than it already is
- // note - should we pay attention to array types?
- // SD: NO, lets not make this more complicated than it already is
- }
-
- // gets the method that can apply to the arguments
- // either the method itself, or a generic one
- // or null if it couldn't match
- //
- // this is a nightmare - if we want to do it right, then we have
- // to re-do the whole compiler type inference stuff by ourselves?!
- //
- static MethodInfo GetMethodForArguments(MethodInfo method, IList arguments)
- {
- var parameters = method.GetParameters();
- var genericArguments = method.GetGenericArguments();
-
- if (parameters.Length != arguments.Count) return null;
-
- var genericArgumentTypes = new Type[genericArguments.Length];
- var i = 0;
- for (; i < parameters.Length; i++)
- {
- var parameterType = parameters[i].ParameterType;
- var argumentType = arguments[i].GetType();
-
- Debug.Print("{0} / {1}", parameterType, argumentType);
-
- if (parameterType == argumentType) continue; // match
- if (parameterType.IsGenericParameter) // eg T
- {
- var pos = parameterType.GenericParameterPosition;
- if (genericArgumentTypes[pos] != null)
- {
- // note - is this OK? what about variance and such?
- // it is NOT ok, if the first pass is SomethingElse then next is Something
- // it will fail... the specs prob. indicate how it works, trying to find a common
- // type...
- if (genericArgumentTypes[pos].IsAssignableFrom(argumentType) == false)
- break;
- }
- else
- {
- genericArgumentTypes[pos] = argumentType;
- }
- }
- else if (parameterType.IsGenericType) // eg List
- {
- if (argumentType.IsGenericType == false) break;
-
- var pg = parameterType.GetGenericArguments();
- var ag = argumentType.GetGenericArguments();
-
- // then what ?!
- // should _variance_ be of some importance?
- Debug.Print("generic {0}", argumentType.IsGenericType);
- }
- else
- {
- if (parameterType.IsAssignableFrom(argumentType) == false)
- break;
- }
- }
- if (i != parameters.Length) return null;
- return genericArguments.Length == 0
- ? method
- : method.MakeGenericMethod(genericArgumentTypes);
- }
-
- #endregion
-
- public class TestClassCollection : List
- {
-
- }
-
- }
-
- #region Tests Elements
-
-
- static class ExtensionMethodFinderTestsExtensions
- {
- public static void GenericMethod(this IEnumerable source)
- { }
-
- public static void SimpleMethod(this ExtensionMethodFinderTests.TestClass source, int value)
- { }
-
- public static void SimpleOverloadMethod(this ExtensionMethodFinderTests.TestClass source, int value)
- { }
-
- public static void SimpleOverloadMethod(this ExtensionMethodFinderTests.TestClass source, string value)
- { }
-
- public static void SimpleEnumerableGenericMethod(this IEnumerable source, int value)
- { }
-
- public static void SimpleOverloadEnumerableGenericMethod(this IEnumerable source, int value)
- { }
-
- public static void SimpleOverloadEnumerableGenericMethod(this IEnumerable source, string value)
- { }
-
- public static void GenericParameterMethod(this ExtensionMethodFinderTests.TestClass source, ExtensionMethodFinderTests.TestClass value)
- { }
-
- public static void GenericMethod(this ExtensionMethodFinderTests.TestClass source)
- { }
- }
-
- #endregion
-}
diff --git a/src/Umbraco.Tests/DynamicsAndReflection/QueryableExtensionTests.cs b/src/Umbraco.Tests/DynamicsAndReflection/QueryableExtensionTests.cs
deleted file mode 100644
index c2544421a0..0000000000
--- a/src/Umbraco.Tests/DynamicsAndReflection/QueryableExtensionTests.cs
+++ /dev/null
@@ -1,158 +0,0 @@
-using System.Collections.Generic;
-using System.Linq;
-using NUnit.Framework;
-using Umbraco.Core.Dynamics;
-using Umbraco.Web.Dynamics;
-
-namespace Umbraco.Tests.DynamicsAndReflection
-{
- //NOTE: there's libraries in both Umbraco.Core.Dynamics and Umbraco.Web.Dynamics - the reason for this is that the Web.Dynamics
- // started with the razor macro implementation and is modified with hard coded references to dynamic node and dynamic null, though it seems
- // to still work for other regular classes I don't want to move it to the core without removing these references but that would require a lot of work.
-
- [TestFixture]
- public class QueryableExtensionTests
- {
-
- [Test]
- public void Order_By_Test_Int()
- {
- var items = new List
- {
- new TestModel {Age = 10, Name = "test1", Female = false},
- new TestModel {Age = 31, Name = "someguy", Female = true},
- new TestModel {Age = 11, Name = "test2", Female = true},
- new TestModel {Age = 20, Name = "anothertest", Female = false},
- new TestModel {Age = 55, Name = "blah", Female = false},
- new TestModel {Age = 12, Name = "test3", Female = false}
- };
-
- var result = items.AsQueryable().OrderBy("Age").ToArray();
-
- Assert.AreEqual(10, result.ElementAt(0).Age);
- Assert.AreEqual(11, result.ElementAt(1).Age);
- Assert.AreEqual(12, result.ElementAt(2).Age);
- Assert.AreEqual(20, result.ElementAt(3).Age);
- Assert.AreEqual(31, result.ElementAt(4).Age);
- Assert.AreEqual(55, result.ElementAt(5).Age);
-
- }
-
- [Test]
- public void Order_By_Test_String()
- {
- var items = new List
- {
- new TestModel {Age = 10, Name = "test1", Female = false},
- new TestModel {Age = 31, Name = "someguy", Female = true},
- new TestModel {Age = 11, Name = "test2", Female = true},
- new TestModel {Age = 20, Name = "anothertest", Female = false},
- new TestModel {Age = 55, Name = "blah", Female = false},
- new TestModel {Age = 12, Name = "test3", Female = false}
- };
-
- var result = items.AsQueryable().OrderBy("Name").ToArray();
-
- Assert.AreEqual("anothertest", result.ElementAt(0).Name);
- Assert.AreEqual("blah", result.ElementAt(1).Name);
- Assert.AreEqual("someguy", result.ElementAt(2).Name);
- Assert.AreEqual("test1", result.ElementAt(3).Name);
- Assert.AreEqual("test2", result.ElementAt(4).Name);
- Assert.AreEqual("test3", result.ElementAt(5).Name);
-
- }
-
- [Test]
- public void Where_Test_String()
- {
- var items = new List
- {
- new TestModel {Age = 10, Name = "test1", Female = false},
- new TestModel {Age = 31, Name = "someguy", Female = true},
- new TestModel {Age = 11, Name = "test2", Female = true},
- new TestModel {Age = 20, Name = "anothertest", Female = false},
- new TestModel {Age = 55, Name = "blah", Female = false},
- new TestModel {Age = 12, Name = "test3", Female = false}
- };
-
- var result = items.AsQueryable().Where("Name = \"test1\"").ToArray();
-
- Assert.AreEqual(1, result.Count());
- Assert.AreEqual("test1", result.ElementAt(0).Name);
-
-
- }
-
- [Test]
- public void Where_Test_String_With_Params()
- {
- var items = new List
- {
- new TestModel {Age = 10, Name = "test1", Female = false},
- new TestModel {Age = 31, Name = "someguy", Female = true},
- new TestModel {Age = 11, Name = "test2", Female = true},
- new TestModel {Age = 20, Name = "anothertest", Female = false},
- new TestModel {Age = 55, Name = "blah", Female = false},
- new TestModel {Age = 12, Name = "test3", Female = false}
- };
-
- //NOTE: Currently the object query structure is not supported
- //var result = items.AsQueryable().Where("Name = @name", new {name = "test1"}).ToArray();
- var result = items.AsQueryable().Where("Name = @Name", new Dictionary { { "Name", "test1" } }).ToArray();
-
- Assert.AreEqual(1, result.Count());
- Assert.AreEqual("test1", result.ElementAt(0).Name);
-
-
- }
-
- [Test]
- public void Where_Test_Int_With_Params()
- {
- var items = new List
- {
- new TestModel {Age = 10, Name = "test1", Female = false},
- new TestModel {Age = 31, Name = "someguy", Female = true},
- new TestModel {Age = 11, Name = "test2", Female = true},
- new TestModel {Age = 20, Name = "anothertest", Female = false},
- new TestModel {Age = 55, Name = "blah", Female = false},
- new TestModel {Age = 12, Name = "test3", Female = false}
- };
-
- var result = items.AsQueryable().Where("Age = @Age", new Dictionary { { "Age", 10 } }).ToArray();
-
- Assert.AreEqual(1, result.Count());
- Assert.AreEqual("test1", result.ElementAt(0).Name);
-
-
- }
-
- [Test]
- public void Where_Test_Bool_With_Params()
- {
- var items = new List
- {
- new TestModel {Age = 10, Name = "test1", Female = false},
- new TestModel {Age = 31, Name = "someguy", Female = true},
- new TestModel {Age = 11, Name = "test2", Female = true},
- new TestModel {Age = 20, Name = "anothertest", Female = false},
- new TestModel {Age = 55, Name = "blah", Female = false},
- new TestModel {Age = 12, Name = "test3", Female = false}
- };
-
- var result = items.AsQueryable().Where("Female = @Female", new Dictionary { { "Female", true } }).ToArray();
-
- Assert.AreEqual(2, result.Count());
-
-
- }
-
- private class TestModel
- {
- public string Name { get; set; }
- public int Age { get; set; }
- public bool Female { get; set; }
- }
-
- }
-}
diff --git a/src/Umbraco.Tests/Membership/DynamicMemberContentTests.cs b/src/Umbraco.Tests/Membership/DynamicMemberContentTests.cs
deleted file mode 100644
index a93359bd68..0000000000
--- a/src/Umbraco.Tests/Membership/DynamicMemberContentTests.cs
+++ /dev/null
@@ -1,178 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Web.Security;
-using Lucene.Net.Util;
-using Moq;
-using NUnit.Framework;
-using Umbraco.Core.Models;
-using Umbraco.Core.Models.PublishedContent;
-using Umbraco.Tests.PublishedContent;
-using Umbraco.Tests.TestHelpers;
-using Umbraco.Tests.TestHelpers.Entities;
-using Umbraco.Web;
-using Umbraco.Web.Models;
-using Umbraco.Web.PublishedCache;
-
-namespace Umbraco.Tests.Membership
-{
- [DatabaseTestBehavior(DatabaseBehavior.NoDatabasePerFixture)]
- [TestFixture]
- public class DynamicMemberContentTests : PublishedContentTestBase
- {
-
- public override void Initialize()
- {
- // required so we can access property.Value
- //PropertyValueConvertersResolver.Current = new PropertyValueConvertersResolver();
-
- base.Initialize();
-
- // need to specify a custom callback for unit tests
- // AutoPublishedContentTypes generates properties automatically
- // when they are requested, but we must declare those that we
- // explicitely want to be here...
-
- var propertyTypes = new[]
- {
- // AutoPublishedContentType will auto-generate other properties
- new PublishedPropertyType("title", 0, "?"),
- new PublishedPropertyType("bodyText", 0, "?"),
- new PublishedPropertyType("author", 0, "?")
- };
- var type = new AutoPublishedContentType(0, "anything", propertyTypes);
- ContentTypesCache.GetPublishedContentTypeByAlias = (alias) => type;
- }
-
- [Test]
- public void Can_Get_Built_In_Properties()
- {
- var date = DateTime.Now;
-
- var member = new Member("test name", "test@email.com", "test username", "test password",
- GetMemberType());
- member.Comments = "test comment";
- member.IsApproved = true;
- member.IsLockedOut = false;
- member.CreateDate = date;
- member.LastLoginDate = date.AddMinutes(1);
- member.LastLockoutDate = date.AddMinutes(2);
- //NOTE: Last activity date is always the same as last login date since we don't have a place to store that data
- //member.LastLoginDate = date.AddMinutes(3);
- member.LastPasswordChangeDate = date.AddMinutes(4);
- member.PasswordQuestion = "test question";
-
- var mpt = ContentTypesCache.Get(PublishedItemType.Member, member.ContentTypeAlias);
- var mpc = new PublishedMember(member, mpt);
-
- var d = mpc.AsDynamic();
-
- Assert.AreEqual("test comment", d.Comments);
- Assert.AreEqual(date, d.CreationDate);
- Assert.AreEqual("test@email.com", d.Email);
- Assert.AreEqual(true, d.IsApproved);
- Assert.AreEqual(false, d.IsLockedOut);
- Assert.AreEqual(date.AddMinutes(1), d.LastActivityDate);
- Assert.AreEqual(date.AddMinutes(2), d.LastLockoutDate);
- Assert.AreEqual(date.AddMinutes(1), d.LastLoginDate);
- Assert.AreEqual(date.AddMinutes(4), d.LastPasswordChangeDate);
- Assert.AreEqual("test name", d.Name);
- Assert.AreEqual("test question", d.PasswordQuestion);
- Assert.AreEqual("test username", d.UserName);
-
- }
-
- [Test]
- public void Can_Get_Built_In_Properties_Camel_Case()
- {
- var date = DateTime.Now;
-
- var member = new Member("test name", "test@email.com", "test username", "test password",
- GetMemberType());
- member.Comments = "test comment";
- member.IsApproved = true;
- member.IsLockedOut = false;
- member.CreateDate = date;
- member.LastLoginDate = date.AddMinutes(1);
- member.LastLockoutDate = date.AddMinutes(2);
- //NOTE: Last activity date is always the same as last login date since we don't have a place to store that data
- //member.LastLoginDate = date.AddMinutes(3);
- member.LastPasswordChangeDate = date.AddMinutes(4);
- member.PasswordQuestion = "test question";
-
- var mpt = ContentTypesCache.Get(PublishedItemType.Member, member.ContentTypeAlias);
- var mpc = new PublishedMember(member, mpt);
-
- var d = mpc.AsDynamic();
-
- Assert.AreEqual("test comment", d.comments);
- Assert.AreEqual(date, d.creationDate);
- Assert.AreEqual("test@email.com", d.email);
- Assert.AreEqual(true, d.isApproved);
- Assert.AreEqual(false, d.isLockedOut);
- Assert.AreEqual(date.AddMinutes(1), d.lastActivityDate);
- Assert.AreEqual(date.AddMinutes(2), d.lastLockoutDate);
- Assert.AreEqual(date.AddMinutes(1), d.lastLoginDate);
- Assert.AreEqual(date.AddMinutes(4), d.lastPasswordChangeDate);
- Assert.AreEqual("test name", d.name);
- Assert.AreEqual("test question", d.passwordQuestion);
- Assert.AreEqual("test username", d.userName);
-
- }
-
- [Test]
- public void Can_Get_Custom_Properties()
- {
- var date = DateTime.Now;
-
- var memberType = MockedContentTypes.CreateSimpleMemberType("Member", "Member");
- var member = MockedMember.CreateSimpleMember(memberType, "test name", "test@email.com", "test password", "test username");
- member.Comments = "test comment";
- member.IsApproved = true;
- member.IsLockedOut = false;
- member.CreateDate = date;
- member.LastLoginDate = date.AddMinutes(1);
- member.LastLockoutDate = date.AddMinutes(2);
- //NOTE: Last activity date is always the same as last login date since we don't have a place to store that data
- //member.LastLoginDate = date.AddMinutes(3);
- member.LastPasswordChangeDate = date.AddMinutes(4);
- member.PasswordQuestion = "test question";
-
- member.Properties["title"].Value = "Test Value 1";
- member.Properties["bodyText"].Value = "Test Value 2";
- member.Properties["author"].Value = "Test Value 3";
-
- var mpt = ContentTypesCache.Get(PublishedItemType.Member, member.ContentTypeAlias);
- var mpc = new PublishedMember(member, mpt);
-
- var d = mpc.AsDynamic();
-
- Assert.AreEqual("Test Value 1", d.title);
- Assert.AreEqual("Test Value 1", d.Title);
- Assert.AreEqual("Test Value 2", d.bodyText);
- Assert.AreEqual("Test Value 2", d.BodyText);
- Assert.AreEqual("Test Value 3", d.author);
- Assert.AreEqual("Test Value 3", d.Author);
-
-
- }
-
- private IMemberType GetMemberType()
- {
- var entity = new MemberType(-1)
- {
- Alias = "Member"
- };
-
- entity.AddPropertyGroup(Umbraco.Core.Constants.Conventions.Member.StandardPropertiesGroupName);
- var standardPropertyTypes = Umbraco.Core.Constants.Conventions.Member.GetStandardPropertyTypeStubs();
- foreach (var standardPropertyType in standardPropertyTypes)
- {
- entity.AddPropertyType(standardPropertyType.Value, Umbraco.Core.Constants.Conventions.Member.StandardPropertiesGroupName);
- }
- return entity;
- }
-
- }
-}
diff --git a/src/Umbraco.Tests/MockTests.cs b/src/Umbraco.Tests/MockTests.cs
index 275678d8da..ba9ee113e3 100644
--- a/src/Umbraco.Tests/MockTests.cs
+++ b/src/Umbraco.Tests/MockTests.cs
@@ -147,7 +147,6 @@ namespace Umbraco.Tests
var helper = new UmbracoHelper(umbCtx,
Mock.Of(),
Mock.Of(),
- Mock.Of(),
Mock.Of(),
Mock.Of(),
new UrlProvider(umbCtx, new[] {Mock.Of()}, UrlProviderMode.Auto), Mock.Of(),
@@ -184,7 +183,6 @@ namespace Umbraco.Tests
var helper = new UmbracoHelper(umbCtx,
Mock.Of(),
Mock.Of(),
- Mock.Of(),
Mock.Of(),
Mock.Of(),
new UrlProvider(umbCtx, new[]
diff --git a/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs b/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs
index 51651ad575..95857085d4 100644
--- a/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs
+++ b/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs
@@ -1,5 +1,4 @@
-using System;
-using System.Globalization;
+using System.Globalization;
using System.Linq;
using LightInject;
using Moq;
@@ -14,7 +13,6 @@ using Umbraco.Core.ObjectResolution;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Web.Models;
-using Umbraco.Web.PropertyEditors;
using Umbraco.Web;
namespace Umbraco.Tests.PropertyEditors
@@ -22,94 +20,16 @@ namespace Umbraco.Tests.PropertyEditors
[TestFixture]
public class ImageCropperTest
{
- private const string cropperJson1 = "{\"focalPoint\": {\"left\": 0.96,\"top\": 0.80827067669172936},\"src\": \"/media/1005/img_0671.jpg\",\"crops\": [{\"alias\":\"thumb\",\"width\": 100,\"height\": 100,\"coordinates\": {\"x1\": 0.58729977382575338,\"y1\": 0.055768992440203169,\"x2\": 0,\"y2\": 0.32457553600198386}}]}";
- private const string cropperJson2 = "{\"focalPoint\": {\"left\": 0.98,\"top\": 0.80827067669172936},\"src\": \"/media/1005/img_0672.jpg\",\"crops\": [{\"alias\":\"thumb\",\"width\": 100,\"height\": 100,\"coordinates\": {\"x1\": 0.58729977382575338,\"y1\": 0.055768992440203169,\"x2\": 0,\"y2\": 0.32457553600198386}}]}";
- private const string cropperJson3 = "{\"focalPoint\": {\"left\": 0.98,\"top\": 0.80827067669172936},\"src\": \"/media/1005/img_0672.jpg\",\"crops\": []}";
- private const string mediaPath = "/media/1005/img_0671.jpg";
-
- [Test]
- public void ImageCropData_Properties_As_Dynamic()
- {
- var sourceObj = cropperJson1.SerializeToCropDataSet();
- dynamic d = sourceObj;
-
- var index = 0;
- foreach (var crop in d.crops)
- {
- var realObjCrop = sourceObj.Crops.ElementAt(index);
- Assert.AreEqual(realObjCrop.Alias, crop.Alias);
- Assert.AreEqual(realObjCrop.Alias, crop.alias);
-
- Assert.AreEqual(realObjCrop.Height, crop.Height);
- Assert.AreEqual(realObjCrop.Height, crop.height);
-
- Assert.AreEqual(realObjCrop.Coordinates.X1, crop.Coordinates.X1);
- Assert.AreEqual(realObjCrop.Coordinates.X1, crop.coordinates.x1);
-
- Assert.AreEqual(realObjCrop.Coordinates.X2, crop.Coordinates.X2);
- Assert.AreEqual(realObjCrop.Coordinates.X2, crop.coordinates.x2);
-
- Assert.AreEqual(realObjCrop.Coordinates.Y1, crop.Coordinates.Y1);
- Assert.AreEqual(realObjCrop.Coordinates.Y1, crop.coordinates.y1);
-
- Assert.AreEqual(realObjCrop.Coordinates.Y2, crop.Coordinates.Y2);
- Assert.AreEqual(realObjCrop.Coordinates.Y2, crop.coordinates.y2);
- index++;
- }
-
- Assert.AreEqual(index, 1);
- }
-
- [Test]
- public void ImageCropFocalPoint_Properties_As_Dynamic()
- {
- var sourceObj = cropperJson1.SerializeToCropDataSet();
- dynamic d = sourceObj;
-
- Assert.AreEqual(sourceObj.FocalPoint.Left, d.FocalPoint.Left);
- Assert.AreEqual(sourceObj.FocalPoint.Left, d.focalPoint.left);
-
- Assert.AreEqual(sourceObj.FocalPoint.Top, d.FocalPoint.Top);
- Assert.AreEqual(sourceObj.FocalPoint.Top, d.focalPoint.top);
- }
-
- [Test]
- public void ImageCropDataSet_Properties_As_Dynamic()
- {
- var sourceObj = cropperJson1.SerializeToCropDataSet();
- dynamic d = sourceObj;
-
- Assert.AreEqual(sourceObj.Src, d.Src);
- Assert.AreEqual(sourceObj.Src, d.src);
-
- Assert.AreEqual(sourceObj.FocalPoint, d.FocalPoint);
- Assert.AreEqual(sourceObj.FocalPoint, d.focalPoint);
-
- Assert.AreEqual(sourceObj.Crops, d.Crops);
- Assert.AreEqual(sourceObj.Crops, d.crops);
- }
-
- [Test]
- public void ImageCropDataSet_Methods_As_Dynamic()
- {
- var sourceObj = cropperJson1.SerializeToCropDataSet();
- dynamic d = sourceObj;
-
- Assert.AreEqual(sourceObj.HasCrop("thumb"), d.HasCrop("thumb"));
- Assert.AreEqual(sourceObj.HasCrop("thumb"), d.hasCrop("thumb"));
-
- Assert.AreEqual(sourceObj.GetCropUrl("thumb"), d.GetCropUrl("thumb"));
- Assert.AreEqual(sourceObj.GetCropUrl("thumb"), d.getCropUrl("thumb"));
-
- Assert.AreEqual(sourceObj.HasFocalPoint(), d.HasFocalPoint());
- Assert.AreEqual(sourceObj.HasFocalPoint(), d.hasFocalPoint());
- }
+ private const string CropperJson1 = "{\"focalPoint\": {\"left\": 0.96,\"top\": 0.80827067669172936},\"src\": \"/media/1005/img_0671.jpg\",\"crops\": [{\"alias\":\"thumb\",\"width\": 100,\"height\": 100,\"coordinates\": {\"x1\": 0.58729977382575338,\"y1\": 0.055768992440203169,\"x2\": 0,\"y2\": 0.32457553600198386}}]}";
+ private const string CropperJson2 = "{\"focalPoint\": {\"left\": 0.98,\"top\": 0.80827067669172936},\"src\": \"/media/1005/img_0672.jpg\",\"crops\": [{\"alias\":\"thumb\",\"width\": 100,\"height\": 100,\"coordinates\": {\"x1\": 0.58729977382575338,\"y1\": 0.055768992440203169,\"x2\": 0,\"y2\": 0.32457553600198386}}]}";
+ private const string CropperJson3 = "{\"focalPoint\": {\"left\": 0.98,\"top\": 0.80827067669172936},\"src\": \"/media/1005/img_0672.jpg\",\"crops\": []}";
+ private const string MediaPath = "/media/1005/img_0671.jpg";
[Test]
public void CanConvertImageCropperDataSetSrcToString()
{
//cropperJson3 - has not crops
- var sourceObj = cropperJson3.SerializeToCropDataSet();
+ var sourceObj = CropperJson3.SerializeToCropDataSet();
var destObj = sourceObj.TryConvertTo();
Assert.IsTrue(destObj.Success);
Assert.AreEqual(destObj.Result, "/media/1005/img_0672.jpg");
@@ -119,7 +39,7 @@ namespace Umbraco.Tests.PropertyEditors
public void CanConvertImageCropperDataSetJObject()
{
//cropperJson3 - has not crops
- var sourceObj = cropperJson3.SerializeToCropDataSet();
+ var sourceObj = CropperJson3.SerializeToCropDataSet();
var destObj = sourceObj.TryConvertTo();
Assert.IsTrue(destObj.Success);
Assert.AreEqual(sourceObj, destObj.Result.ToObject());
@@ -128,16 +48,16 @@ namespace Umbraco.Tests.PropertyEditors
[Test]
public void CanConvertImageCropperDataSetJsonToString()
{
- var sourceObj = cropperJson1.SerializeToCropDataSet();
+ var sourceObj = CropperJson1.SerializeToCropDataSet();
var destObj = sourceObj.TryConvertTo();
Assert.IsTrue(destObj.Success);
Assert.IsTrue(destObj.Result.DetectIsJson());
- var obj = JsonConvert.DeserializeObject(cropperJson1, new JsonSerializerSettings {Culture = CultureInfo.InvariantCulture, FloatParseHandling = FloatParseHandling.Decimal});
+ var obj = JsonConvert.DeserializeObject(CropperJson1, new JsonSerializerSettings {Culture = CultureInfo.InvariantCulture, FloatParseHandling = FloatParseHandling.Decimal});
Assert.AreEqual(sourceObj, obj);
}
- [TestCase(cropperJson1, cropperJson1, true)]
- [TestCase(cropperJson1, cropperJson2, false)]
+ [TestCase(CropperJson1, CropperJson1, true)]
+ [TestCase(CropperJson1, CropperJson2, false)]
public void CanConvertImageCropperPropertyEditor(string val1, string val2, bool expected)
{
try
@@ -163,15 +83,15 @@ namespace Umbraco.Tests.PropertyEditors
}
finally
{
- PropertyValueConvertersResolver.Reset(true);
+ PropertyValueConvertersResolver.Reset(/*true*/);
}
}
[Test]
public void GetCropUrl_CropAliasTest()
{
- var urlString = mediaPath.GetCropUrl(imageCropperValue: cropperJson1, cropAlias: "Thumb", useCropDimensions: true);
- Assert.AreEqual(mediaPath + "?crop=0.58729977382575338,0.055768992440203169,0,0.32457553600198386&cropmode=percentage&width=100&height=100", urlString);
+ var urlString = MediaPath.GetCropUrl(imageCropperValue: CropperJson1, cropAlias: "Thumb", useCropDimensions: true);
+ Assert.AreEqual(MediaPath + "?crop=0.58729977382575338,0.055768992440203169,0,0.32457553600198386&cropmode=percentage&width=100&height=100", urlString);
}
///
@@ -180,29 +100,29 @@ namespace Umbraco.Tests.PropertyEditors
[Test]
public void GetCropUrl_CropAliasIgnoreWidthHeightTest()
{
- var urlString = mediaPath.GetCropUrl(imageCropperValue: cropperJson1, cropAlias: "Thumb", useCropDimensions: true, width: 50, height: 50);
- Assert.AreEqual(mediaPath + "?crop=0.58729977382575338,0.055768992440203169,0,0.32457553600198386&cropmode=percentage&width=100&height=100", urlString);
+ var urlString = MediaPath.GetCropUrl(imageCropperValue: CropperJson1, cropAlias: "Thumb", useCropDimensions: true, width: 50, height: 50);
+ Assert.AreEqual(MediaPath + "?crop=0.58729977382575338,0.055768992440203169,0,0.32457553600198386&cropmode=percentage&width=100&height=100", urlString);
}
[Test]
public void GetCropUrl_WidthHeightTest()
{
- var urlString = mediaPath.GetCropUrl(imageCropperValue: cropperJson1, width: 200, height: 300);
- Assert.AreEqual(mediaPath + "?center=0.80827067669172936,0.96&mode=crop&width=200&height=300", urlString);
+ var urlString = MediaPath.GetCropUrl(imageCropperValue: CropperJson1, width: 200, height: 300);
+ Assert.AreEqual(MediaPath + "?center=0.80827067669172936,0.96&mode=crop&width=200&height=300", urlString);
}
[Test]
public void GetCropUrl_FocalPointTest()
{
- var urlString = mediaPath.GetCropUrl(imageCropperValue: cropperJson1, cropAlias: "thumb", preferFocalPoint: true, useCropDimensions: true);
- Assert.AreEqual(mediaPath + "?center=0.80827067669172936,0.96&mode=crop&width=100&height=100", urlString);
+ var urlString = MediaPath.GetCropUrl(imageCropperValue: CropperJson1, cropAlias: "thumb", preferFocalPoint: true, useCropDimensions: true);
+ Assert.AreEqual(MediaPath + "?center=0.80827067669172936,0.96&mode=crop&width=100&height=100", urlString);
}
[Test]
public void GetCropUrlFurtherOptionsTest()
{
- var urlString = mediaPath.GetCropUrl(imageCropperValue: cropperJson1, width: 200, height: 300, furtherOptions: "&filter=comic&roundedcorners=radius-26|bgcolor-fff");
- Assert.AreEqual(mediaPath + "?center=0.80827067669172936,0.96&mode=crop&width=200&height=300&filter=comic&roundedcorners=radius-26|bgcolor-fff", urlString);
+ var urlString = MediaPath.GetCropUrl(imageCropperValue: CropperJson1, width: 200, height: 300, furtherOptions: "&filter=comic&roundedcorners=radius-26|bgcolor-fff");
+ Assert.AreEqual(MediaPath + "?center=0.80827067669172936,0.96&mode=crop&width=200&height=300&filter=comic&roundedcorners=radius-26|bgcolor-fff", urlString);
}
///
@@ -211,7 +131,7 @@ namespace Umbraco.Tests.PropertyEditors
[Test]
public void GetCropUrlNullTest()
{
- var urlString = mediaPath.GetCropUrl(imageCropperValue: cropperJson1, cropAlias: "Banner", useCropDimensions: true);
+ var urlString = MediaPath.GetCropUrl(imageCropperValue: CropperJson1, cropAlias: "Banner", useCropDimensions: true);
Assert.AreEqual(null, urlString);
}
@@ -221,7 +141,7 @@ namespace Umbraco.Tests.PropertyEditors
[Test]
public void GetBaseCropUrlFromModelTest()
{
- var cropDataSet = cropperJson1.SerializeToCropDataSet();
+ var cropDataSet = CropperJson1.SerializeToCropDataSet();
var urlString = cropDataSet.GetCropUrl("thumb");
Assert.AreEqual("?crop=0.58729977382575338,0.055768992440203169,0,0.32457553600198386&cropmode=percentage&width=100&height=100", urlString);
}
@@ -232,8 +152,8 @@ namespace Umbraco.Tests.PropertyEditors
[Test]
public void GetCropUrl_CropAliasHeightRatioModeTest()
{
- var urlString = mediaPath.GetCropUrl(imageCropperValue: cropperJson1, cropAlias: "Thumb", useCropDimensions: true, ratioMode:ImageCropRatioMode.Height);
- Assert.AreEqual(mediaPath + "?crop=0.58729977382575338,0.055768992440203169,0,0.32457553600198386&cropmode=percentage&width=100&heightratio=1", urlString);
+ var urlString = MediaPath.GetCropUrl(imageCropperValue: CropperJson1, cropAlias: "Thumb", useCropDimensions: true, ratioMode:ImageCropRatioMode.Height);
+ Assert.AreEqual(MediaPath + "?crop=0.58729977382575338,0.055768992440203169,0,0.32457553600198386&cropmode=percentage&width=100&heightratio=1", urlString);
}
///
@@ -242,8 +162,8 @@ namespace Umbraco.Tests.PropertyEditors
[Test]
public void GetCropUrl_WidthHeightRatioModeTest()
{
- var urlString = mediaPath.GetCropUrl(imageCropperValue: cropperJson1, width: 300, height: 150, ratioMode:ImageCropRatioMode.Height);
- Assert.AreEqual(mediaPath + "?center=0.80827067669172936,0.96&mode=crop&width=300&heightratio=0.5", urlString);
+ var urlString = MediaPath.GetCropUrl(imageCropperValue: CropperJson1, width: 300, height: 150, ratioMode:ImageCropRatioMode.Height);
+ Assert.AreEqual(MediaPath + "?center=0.80827067669172936,0.96&mode=crop&width=300&heightratio=0.5", urlString);
}
///
@@ -252,8 +172,8 @@ namespace Umbraco.Tests.PropertyEditors
[Test]
public void GetCropUrl_HeightWidthRatioModeTest()
{
- var urlString = mediaPath.GetCropUrl(imageCropperValue: cropperJson1, width: 300, height: 150, ratioMode: ImageCropRatioMode.Width);
- Assert.AreEqual(mediaPath + "?center=0.80827067669172936,0.96&mode=crop&height=150&widthratio=2", urlString);
+ var urlString = MediaPath.GetCropUrl(imageCropperValue: CropperJson1, width: 300, height: 150, ratioMode: ImageCropRatioMode.Width);
+ Assert.AreEqual(MediaPath + "?center=0.80827067669172936,0.96&mode=crop&height=150&widthratio=2", urlString);
}
///
@@ -262,8 +182,8 @@ namespace Umbraco.Tests.PropertyEditors
[Test]
public void GetCropUrl_SpecifiedCropModeTest()
{
- var urlString = mediaPath.GetCropUrl(imageCropperValue: cropperJson1, width: 300, height: 150, imageCropMode:ImageCropMode.Max);
- Assert.AreEqual(mediaPath + "?mode=max&width=300&height=150", urlString);
+ var urlString = MediaPath.GetCropUrl(imageCropperValue: CropperJson1, width: 300, height: 150, imageCropMode:ImageCropMode.Max);
+ Assert.AreEqual(MediaPath + "?mode=max&width=300&height=150", urlString);
}
///
@@ -272,8 +192,8 @@ namespace Umbraco.Tests.PropertyEditors
[Test]
public void GetCropUrl_UploadTypeTest()
{
- var urlString = mediaPath.GetCropUrl(width: 100, height: 270, imageCropMode: ImageCropMode.Crop, imageCropAnchor: ImageCropAnchor.Center);
- Assert.AreEqual(mediaPath + "?mode=crop&anchor=center&width=100&height=270", urlString);
+ var urlString = MediaPath.GetCropUrl(width: 100, height: 270, imageCropMode: ImageCropMode.Crop, imageCropAnchor: ImageCropAnchor.Center);
+ Assert.AreEqual(MediaPath + "?mode=crop&anchor=center&width=100&height=270", urlString);
}
///
@@ -282,10 +202,10 @@ namespace Umbraco.Tests.PropertyEditors
[Test]
public void GetCropUrl_PreferFocalPointCenter()
{
- var cropperJson = "{\"focalPoint\": {\"left\": 0.5,\"top\": 0.5},\"src\": \"/media/1005/img_0671.jpg\",\"crops\": [{\"alias\":\"thumb\",\"width\": 100,\"height\": 100,\"coordinates\": {\"x1\": 0.58729977382575338,\"y1\": 0.055768992440203169,\"x2\": 0,\"y2\": 0.32457553600198386}}]}";
+ const string cropperJson = "{\"focalPoint\": {\"left\": 0.5,\"top\": 0.5},\"src\": \"/media/1005/img_0671.jpg\",\"crops\": [{\"alias\":\"thumb\",\"width\": 100,\"height\": 100,\"coordinates\": {\"x1\": 0.58729977382575338,\"y1\": 0.055768992440203169,\"x2\": 0,\"y2\": 0.32457553600198386}}]}";
- var urlString = mediaPath.GetCropUrl(imageCropperValue: cropperJson, width: 300, height: 150, preferFocalPoint:true);
- Assert.AreEqual(mediaPath + "?anchor=center&mode=crop&width=300&height=150", urlString);
+ var urlString = MediaPath.GetCropUrl(imageCropperValue: cropperJson, width: 300, height: 150, preferFocalPoint:true);
+ Assert.AreEqual(MediaPath + "?anchor=center&mode=crop&width=300&height=150", urlString);
}
///
@@ -294,10 +214,10 @@ namespace Umbraco.Tests.PropertyEditors
[Test]
public void GetCropUrl_PreDefinedCropNoCoordinatesWithWidth()
{
- var cropperJson = "{\"focalPoint\": {\"left\": 0.5,\"top\": 0.5},\"src\": \"/media/1005/img_0671.jpg\",\"crops\": [{\"alias\": \"home\",\"width\": 270,\"height\": 161}]}";
+ const string cropperJson = "{\"focalPoint\": {\"left\": 0.5,\"top\": 0.5},\"src\": \"/media/1005/img_0671.jpg\",\"crops\": [{\"alias\": \"home\",\"width\": 270,\"height\": 161}]}";
- var urlString = mediaPath.GetCropUrl(imageCropperValue: cropperJson, cropAlias: "home", width: 200);
- Assert.AreEqual(mediaPath + "?anchor=center&mode=crop&heightratio=0.5962962962962962962962962963&width=200", urlString);
+ var urlString = MediaPath.GetCropUrl(imageCropperValue: cropperJson, cropAlias: "home", width: 200);
+ Assert.AreEqual(MediaPath + "?anchor=center&mode=crop&heightratio=0.5962962962962962962962962963&width=200", urlString);
}
///
@@ -306,10 +226,10 @@ namespace Umbraco.Tests.PropertyEditors
[Test]
public void GetCropUrl_PreDefinedCropNoCoordinatesWithWidthAndFocalPoint()
{
- var cropperJson = "{\"focalPoint\": {\"left\": 0.4275,\"top\": 0.41},\"src\": \"/media/1005/img_0671.jpg\",\"crops\": [{\"alias\": \"home\",\"width\": 270,\"height\": 161}]}";
+ const string cropperJson = "{\"focalPoint\": {\"left\": 0.4275,\"top\": 0.41},\"src\": \"/media/1005/img_0671.jpg\",\"crops\": [{\"alias\": \"home\",\"width\": 270,\"height\": 161}]}";
- var urlString = mediaPath.GetCropUrl(imageCropperValue: cropperJson, cropAlias: "home", width: 200);
- Assert.AreEqual(mediaPath + "?center=0.41,0.4275&mode=crop&heightratio=0.5962962962962962962962962963&width=200", urlString);
+ var urlString = MediaPath.GetCropUrl(imageCropperValue: cropperJson, cropAlias: "home", width: 200);
+ Assert.AreEqual(MediaPath + "?center=0.41,0.4275&mode=crop&heightratio=0.5962962962962962962962962963&width=200", urlString);
}
///
@@ -318,10 +238,10 @@ namespace Umbraco.Tests.PropertyEditors
[Test]
public void GetCropUrl_PreDefinedCropNoCoordinatesWithWidthAndFocalPointIgnore()
{
- var cropperJson = "{\"focalPoint\": {\"left\": 0.4275,\"top\": 0.41},\"src\": \"/media/1005/img_0671.jpg\",\"crops\": [{\"alias\": \"home\",\"width\": 270,\"height\": 161}]}";
+ const string cropperJson = "{\"focalPoint\": {\"left\": 0.4275,\"top\": 0.41},\"src\": \"/media/1005/img_0671.jpg\",\"crops\": [{\"alias\": \"home\",\"width\": 270,\"height\": 161}]}";
- var urlString = mediaPath.GetCropUrl(imageCropperValue: cropperJson, cropAlias: "home", width: 200, useCropDimensions: true);
- Assert.AreEqual(mediaPath + "?center=0.41,0.4275&mode=crop&width=270&height=161", urlString);
+ var urlString = MediaPath.GetCropUrl(imageCropperValue: cropperJson, cropAlias: "home", width: 200, useCropDimensions: true);
+ Assert.AreEqual(MediaPath + "?center=0.41,0.4275&mode=crop&width=270&height=161", urlString);
}
///
@@ -330,10 +250,10 @@ namespace Umbraco.Tests.PropertyEditors
[Test]
public void GetCropUrl_PreDefinedCropNoCoordinatesWithHeight()
{
- var cropperJson = "{\"focalPoint\": {\"left\": 0.5,\"top\": 0.5},\"src\": \"/media/1005/img_0671.jpg\",\"crops\": [{\"alias\": \"home\",\"width\": 270,\"height\": 161}]}";
+ const string cropperJson = "{\"focalPoint\": {\"left\": 0.5,\"top\": 0.5},\"src\": \"/media/1005/img_0671.jpg\",\"crops\": [{\"alias\": \"home\",\"width\": 270,\"height\": 161}]}";
- var urlString = mediaPath.GetCropUrl(imageCropperValue: cropperJson, cropAlias: "home", height: 200);
- Assert.AreEqual(mediaPath + "?anchor=center&mode=crop&widthratio=1.6770186335403726708074534161&height=200", urlString);
+ var urlString = MediaPath.GetCropUrl(imageCropperValue: cropperJson, cropAlias: "home", height: 200);
+ Assert.AreEqual(MediaPath + "?anchor=center&mode=crop&widthratio=1.6770186335403726708074534161&height=200", urlString);
}
///
@@ -342,10 +262,10 @@ namespace Umbraco.Tests.PropertyEditors
[Test]
public void GetCropUrl_WidthOnlyParameter()
{
- var cropperJson = "{\"focalPoint\": {\"left\": 0.5,\"top\": 0.5},\"src\": \"/media/1005/img_0671.jpg\",\"crops\": [{\"alias\": \"home\",\"width\": 270,\"height\": 161}]}";
+ const string cropperJson = "{\"focalPoint\": {\"left\": 0.5,\"top\": 0.5},\"src\": \"/media/1005/img_0671.jpg\",\"crops\": [{\"alias\": \"home\",\"width\": 270,\"height\": 161}]}";
- var urlString = mediaPath.GetCropUrl(imageCropperValue: cropperJson, width: 200);
- Assert.AreEqual(mediaPath + "?anchor=center&mode=crop&width=200", urlString);
+ var urlString = MediaPath.GetCropUrl(imageCropperValue: cropperJson, width: 200);
+ Assert.AreEqual(MediaPath + "?anchor=center&mode=crop&width=200", urlString);
}
///
@@ -354,10 +274,10 @@ namespace Umbraco.Tests.PropertyEditors
[Test]
public void GetCropUrl_HeightOnlyParameter()
{
- var cropperJson = "{\"focalPoint\": {\"left\": 0.5,\"top\": 0.5},\"src\": \"/media/1005/img_0671.jpg\",\"crops\": [{\"alias\": \"home\",\"width\": 270,\"height\": 161}]}";
+ const string cropperJson = "{\"focalPoint\": {\"left\": 0.5,\"top\": 0.5},\"src\": \"/media/1005/img_0671.jpg\",\"crops\": [{\"alias\": \"home\",\"width\": 270,\"height\": 161}]}";
- var urlString = mediaPath.GetCropUrl(imageCropperValue: cropperJson, height: 200);
- Assert.AreEqual(mediaPath + "?anchor=center&mode=crop&height=200", urlString);
+ var urlString = MediaPath.GetCropUrl(imageCropperValue: cropperJson, height: 200);
+ Assert.AreEqual(MediaPath + "?anchor=center&mode=crop&height=200", urlString);
}
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Tests/PublishedContent/DynamicDocumentTestsBase.cs b/src/Umbraco.Tests/PublishedContent/DynamicDocumentTestsBase.cs
deleted file mode 100644
index 7e4cf93980..0000000000
--- a/src/Umbraco.Tests/PublishedContent/DynamicDocumentTestsBase.cs
+++ /dev/null
@@ -1,601 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web;
-using Moq;
-using NUnit.Framework;
-using Umbraco.Core;
-using Umbraco.Core.Configuration.UmbracoSettings;
-using Umbraco.Core.Dynamics;
-using Umbraco.Core.Models.PublishedContent;
-using Umbraco.Core.Plugins;
-using Umbraco.Core.PropertyEditors;
-using Umbraco.Tests.TestHelpers;
-
-namespace Umbraco.Tests.PublishedContent
-{
- [TestFixture]
- public abstract class DynamicDocumentTestsBase : PublishedContentTestBase
- {
- private IUmbracoSettingsSection _umbracoSettings;
-
- public override void Initialize()
- {
- // required so we can access property.Value
- //PropertyValueConvertersResolver.Current = new PropertyValueConvertersResolver();
-
- base.Initialize();
-
- //generate new mock settings and assign so we can configure in individual tests
- _umbracoSettings = SettingsForTests.GenerateMockSettings();
- SettingsForTests.ConfigureSettings(_umbracoSettings);
-
- // need to specify a custom callback for unit tests
- // AutoPublishedContentTypes generates properties automatically
- // when they are requested, but we must declare those that we
- // explicitely want to be here...
-
- var propertyTypes = new[]
- {
- // AutoPublishedContentType will auto-generate other properties
- new PublishedPropertyType("umbracoNaviHide", 0, "?"),
- new PublishedPropertyType("selectedNodes", 0, "?"),
- new PublishedPropertyType("umbracoUrlAlias", 0, "?"),
- new PublishedPropertyType("content", 0, Constants.PropertyEditors.TinyMCEAlias),
- new PublishedPropertyType("testRecursive", 0, "?"),
- new PublishedPropertyType("siteTitle", 0, "?"),
- new PublishedPropertyType("creatorName", 0, "?"),
- new PublishedPropertyType("blah", 0, "?"), // ugly error when that one is missing...
- };
- var type = new AutoPublishedContentType(0, "anything", propertyTypes);
- ContentTypesCache.GetPublishedContentTypeByAlias = (alias) => type;
-
- }
-
- protected override string GetXmlContent(int templateId)
- {
- return @"
-
-
-
-
-]>
-
-
-
-
- 1
-
-
- This is some content]]>
-
-
-
-
-
-
-
-
-
-
-
- 1
-
-
-
-
-
-
-
-
-
-
-
- ";
- }
-
- ///
- /// Returns the dynamic node/document to run tests against
- ///
- ///
- ///
- 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);
- }
-
- ///
- /// Tests the internal instance level caching of returning properties
- ///
- ///
- /// http://issues.umbraco.org/issue/U4-1824
- /// http://issues.umbraco.org/issue/U4-1825
- ///
- [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);
- }
-
- [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) 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 { { "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 { { "searchId", 1111777 } };
- result = doc.Children()
- .Where("selectedNodes.ContainsValue(searchId)", paramVals)
- .FirstOrDefault();
-
- Assert.IsNotNull(result);
- Assert.IsTrue(result.GetType() == typeof (DynamicNull));
- //Assert.AreEqual(typeof(DynamicNull), result.GetType());
- }
-
- [Test]
- public void String_Contains_Method()
- {
- var doc = GetDynamicNode(1046);
-
- var paramVals = new Dictionary { { "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 { { "searchId", "1aaa173" } };
- result = doc.Children()
- .Where("selectedNodes.Contains(searchId)", paramVals)
- .FirstOrDefault();
-
- Assert.IsNotNull(result);
- Assert.IsTrue(result.GetType() == typeof (DynamicNull));
- //Assert.AreEqual(typeof (DynamicNull), result.GetType());
- }
-
- [Test]
- public void String_Split_Method()
- {
- var doc = GetDynamicNode(1046);
-
- var paramVals = new Dictionary
- {
- { "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 { { "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 Children_GroupBy_DocumentTypeAlias()
- {
- var doc = GetDynamicNode(1046);
-
- var found1 = doc.Children.GroupBy("DocumentTypeAlias");
-
- var casted = (IEnumerable>) (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) 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) 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) 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) 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) 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(asDynamic.Content.GetType()));
- Assert.AreEqual("This is some content
", asDynamic.Content.ToString());
- }
-
- [Test]
- public void Get_Children_With_Pluralized_Alias()
- {
- var asDynamic = GetDynamicNode(1173);
-
- Action doAssert = d =>
- {
- Assert.IsTrue(TypeHelper.IsTypeAssignableFrom(d));
- var casted = (IEnumerable) 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 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(children));
-
- var childrenAsList = asDynamic.ChildrenAsList; //test ChildrenAsList too
- Assert.IsTrue(TypeHelper.IsTypeAssignableFrom(childrenAsList));
-
- var castChildren = (IEnumerable) children;
- Assert.AreEqual(4, castChildren.Count());
-
- var castChildrenAsList = (IEnumerable) childrenAsList;
- Assert.AreEqual(4, castChildrenAsList.Count());
- }
-
- [Test]
- public void Ancestor_Or_Self()
- {
- var asDynamic = GetDynamicNode(1173);
-
- var result = asDynamic.AncestorOrSelf();
-
- Assert.IsNotNull(result);
-
- // ancestor-or-self has to be self!
- // but that's not what the "legacy" razor macro engine does...
- if (result is Umbraco.Web.Models.DynamicPublishedContent)
- Assert.AreEqual(1173, (int) result.Id); // that one works
- else
- Assert.AreEqual(1046, (int) result.Id); // that one still is fubar
- }
-
- [Test]
- public void Ancestors_Or_Self()
- {
- var asDynamic = GetDynamicNode(1174);
-
- var result = asDynamic.AncestorsOrSelf();
-
- Assert.IsNotNull(result);
-
- var list = (IEnumerable) 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) 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) 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) 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);
- }
- }
-
- ///
- /// Extension methods used in tests
- ///
- public static class TestExtensionMethods
- {
- public static bool ContainsValue(this string s, int val)
- {
- return s.Contains(val.ToString());
- }
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Tests/PublishedContent/DynamicPublishedContentCustomExtensionMethods.cs b/src/Umbraco.Tests/PublishedContent/DynamicPublishedContentCustomExtensionMethods.cs
deleted file mode 100644
index b2cebf3ed0..0000000000
--- a/src/Umbraco.Tests/PublishedContent/DynamicPublishedContentCustomExtensionMethods.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-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 doc, string custom, int i, bool b)
- {
- return custom + i + b;
- }
-
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Tests/PublishedContent/DynamicPublishedContentTests.cs b/src/Umbraco.Tests/PublishedContent/DynamicPublishedContentTests.cs
deleted file mode 100644
index a18215ccd0..0000000000
--- a/src/Umbraco.Tests/PublishedContent/DynamicPublishedContentTests.cs
+++ /dev/null
@@ -1,152 +0,0 @@
-using System;
-using System.IO;
-using System.Linq;
-using NUnit.Framework;
-using Umbraco.Core;
-using Umbraco.Core.Models;
-using Umbraco.Core.Models.PublishedContent;
-using Umbraco.Web;
-using Umbraco.Web.Models;
-using Umbraco.Web.PublishedCache;
-using Umbraco.Web.PublishedCache.XmlPublishedCache;
-using File = Umbraco.Core.Models.File;
-
-namespace Umbraco.Tests.PublishedContent
-{
- [TestFixture]
- public class DynamicPublishedContentTests : DynamicDocumentTestsBase
- {
- 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 FirstChild()
- {
- var content = GetDynamicNode(1173);
-
- var x = content.FirstChild();
- Assert.IsNotNull(x);
- Assert.IsInstanceOf(x);
- Assert.AreEqual(1174, x.Id);
-
- x = content.FirstChild("CustomDocument");
- Assert.IsNotNull(x);
- Assert.IsInstanceOf(x);
- Assert.AreEqual(1177, x.Id);
- }
-
- [Test]
- public void Children()
- {
- var content = GetDynamicNode(1173);
-
- var l = content.Children;
- Assert.AreEqual(4, l.Count());
-
- // works - but not by calling the extension method
- // because the binder will in fact re-route to the property first
- l = content.Children();
- Assert.AreEqual(4, l.Count());
- }
-
- [Test]
- public void ChildrenOfType()
- {
- var content = GetDynamicNode(1173);
-
- var l = content.Children;
- Assert.AreEqual(4, l.Count());
-
- // fails - because it fails to find extension methods?
- l = content.Children("CustomDocument");
- Assert.AreEqual(2, l.Count());
- }
-
- [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));
- }
-
- [Test]
- public void U4_4559()
- {
- var doc = GetDynamicNode(1174);
- var result = doc.AncestorOrSelf(1);
- Assert.IsNotNull(result);
- Assert.AreEqual(1046, result.Id);
- }
-
- ///
- /// Test class to mimic UmbracoHelper when returning docs
- ///
- public class TestHelper
- {
- private readonly DynamicPublishedContent _doc;
-
- public TestHelper(DynamicPublishedContent doc)
- {
- _doc = doc;
- }
-
- public IPublishedContent GetDoc()
- {
- return _doc;
- }
-
- public dynamic GetDocAsDynamic()
- {
- return _doc.AsDynamic();
- }
- }
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Tests/PublishedContent/DynamicXmlConverterTests.cs b/src/Umbraco.Tests/PublishedContent/DynamicXmlConverterTests.cs
deleted file mode 100644
index 5075f347e3..0000000000
--- a/src/Umbraco.Tests/PublishedContent/DynamicXmlConverterTests.cs
+++ /dev/null
@@ -1,101 +0,0 @@
-using System.Xml;
-using System.Xml.Linq;
-using NUnit.Framework;
-using Umbraco.Core;
-using Umbraco.Core.Dynamics;
-using Umbraco.Core.Xml;
-
-namespace Umbraco.Tests.PublishedContent
-{
- [TestFixture]
- public class DynamicXmlConverterTests
- {
- [Test]
- public void Convert_To_Raw_String()
- {
- var xml = "/media/54/tulips.jpg 1024 768 620888 jpg /media/41/hydrangeas.jpg 1024 768 595284 jpg ";
- var dXml = new DynamicXml(
- XmlHelper.StripDashesInElementOrAttributeNames(xml),
- xml);
- var result = dXml.TryConvertTo();
- Assert.IsTrue(result.Success);
- Assert.AreEqual(xml, result.Result.Value);
- }
-
- [Test]
- public void Convert_To_Raw_XElement()
- {
- var xml = "/media/54/tulips.jpg 1024 768 620888 jpg /media/41/hydrangeas.jpg 1024 768 595284 jpg ";
- var dXml = new DynamicXml(
- XmlHelper.StripDashesInElementOrAttributeNames(xml),
- xml);
- var result = dXml.TryConvertTo();
- Assert.IsTrue(result.Success);
- Assert.AreEqual(xml, result.Result.Value.ToString(SaveOptions.DisableFormatting));
- }
-
- [Test]
- public void Convert_To_Raw_XmlElement()
- {
- var xml = "/media/54/tulips.jpg 1024 768 620888 jpg /media/41/hydrangeas.jpg 1024 768 595284 jpg ";
- var dXml = new DynamicXml(
- XmlHelper.StripDashesInElementOrAttributeNames(xml),
- xml);
- var result = dXml.TryConvertTo();
- Assert.IsTrue(result.Success);
- Assert.AreEqual(xml, result.Result.Value.OuterXml);
- }
-
- [Test]
- public void Convert_To_Raw_XmlDocument()
- {
- var xml = "/media/54/tulips.jpg 1024 768 620888 jpg /media/41/hydrangeas.jpg 1024 768 595284 jpg ";
- var dXml = new DynamicXml(
- XmlHelper.StripDashesInElementOrAttributeNames(xml),
- xml);
- var result = dXml.TryConvertTo();
- Assert.IsTrue(result.Success);
- Assert.AreEqual(xml, result.Result.Value.InnerXml);
- }
-
- [Test]
- public void Convert_To_String()
- {
- var xml = "/media/54/tulips.jpg 1024 768 620888 jpg /media/41/hydrangeas.jpg 1024 768 595284 jpg ";
- var dXml = new DynamicXml(xml);
- var result = dXml.TryConvertTo();
- Assert.IsTrue(result.Success);
- Assert.AreEqual(xml, result.Result);
- }
-
- [Test]
- public void Convert_To_XElement()
- {
- var xml = "/media/54/tulips.jpg 1024 768 620888 jpg /media/41/hydrangeas.jpg 1024 768 595284 jpg ";
- var dXml = new DynamicXml(xml);
- var result = dXml.TryConvertTo();
- Assert.IsTrue(result.Success);
- Assert.AreEqual(xml, result.Result.ToString(SaveOptions.DisableFormatting));
- }
-
- [Test]
- public void Convert_To_XmlElement()
- {
- var xml = "/media/54/tulips.jpg 1024 768 620888 jpg /media/41/hydrangeas.jpg 1024 768 595284 jpg ";
- var dXml = new DynamicXml(xml);
- var result = dXml.TryConvertTo();
- Assert.IsTrue(result.Success);
- Assert.AreEqual(xml, result.Result.OuterXml);
- }
-
- [Test]
- public void Convert_To_XmlDocument()
- {
- var xml = "/media/54/tulips.jpg 1024 768 620888 jpg /media/41/hydrangeas.jpg 1024 768 595284 jpg ";
- var dXml = new DynamicXml(xml);
- var result = dXml.TryConvertTo();
- Assert.IsTrue(result.Success);
- Assert.AreEqual(xml, result.Result.InnerXml);
- }
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Tests/PublishedContent/DynamicXmlTests.cs b/src/Umbraco.Tests/PublishedContent/DynamicXmlTests.cs
deleted file mode 100644
index 0d83fdbf0c..0000000000
--- a/src/Umbraco.Tests/PublishedContent/DynamicXmlTests.cs
+++ /dev/null
@@ -1,121 +0,0 @@
-using System;
-using System.Diagnostics;
-using Microsoft.CSharp.RuntimeBinder;
-using NUnit.Framework;
-using Umbraco.Core;
-using Umbraco.Core.Dynamics;
-using System.Linq;
-using Umbraco.Core.Xml;
-
-namespace Umbraco.Tests.PublishedContent
-{
- [TestFixture]
- public class DynamicXmlTests
- {
- ///
- /// 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
- ///
- [Test]
- public void Deals_With_Hyphenated_Values()
- {
- var xml = @"
-
- True
- 1161
- /content/
- 12 december Zorgbeurs Care
-
- ";
-
- 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()
- {
- var xml = "/media/54/tulips.jpg 1024 768 620888 jpg /media/41/hydrangeas.jpg 1024 768 595284 jpg ";
- 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()
- {
- var xml = "/media/54/tulips.jpg 1024 768 620888 jpg /media/41/hydrangeas.jpg 1024 768 595284 jpg ";
- 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 the current Core class
- ///
- [Test]
- public void Find_Test_Core_Class()
- {
- RunFindTest(x => new DynamicXml(x));
- }
-
-
-
- private void RunFindTest(Func getDynamicXml)
- {
- var xmlstring = @"
-
-
-
- ";
-
- 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(() =>
- {
- //this will throw because result4 is not found
- var temp = result4.value;
- });
- }
-
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentDataTableTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentDataTableTests.cs
index 019f6448dd..31d2db1d89 100644
--- a/src/Umbraco.Tests/PublishedContent/PublishedContentDataTableTests.cs
+++ b/src/Umbraco.Tests/PublishedContent/PublishedContentDataTableTests.cs
@@ -4,7 +4,6 @@ using System.Collections.ObjectModel;
using System.Linq;
using NUnit.Framework;
using Umbraco.Core;
-using Umbraco.Core.Dynamics;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Tests.TestHelpers;
diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs
index 960963b265..c4a33854bd 100644
--- a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs
+++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs
@@ -124,7 +124,7 @@ namespace Umbraco.Tests.PublishedContent
{
var doc = GetNode(1173);
- var items = doc.Children.Where("Visible").ToIndexedArray();
+ var items = doc.Children.Where(x => x.IsVisible()).ToIndexedArray();
foreach (var item in items)
{
@@ -334,7 +334,7 @@ namespace Umbraco.Tests.PublishedContent
{
var doc = GetNode(1046);
- var found1 = doc.Children.GroupBy("DocumentTypeAlias").ToArray();
+ var found1 = doc.Children.GroupBy(x => x.DocumentTypeAlias).ToArray();
Assert.AreEqual(2, found1.Length);
Assert.AreEqual(2, found1.Single(x => x.Key.ToString() == "Home").Count());
@@ -346,8 +346,8 @@ namespace Umbraco.Tests.PublishedContent
{
var doc = GetNode(1046);
- var found1 = doc.Children.Where("DocumentTypeAlias == \"CustomDocument\"");
- var found2 = doc.Children.Where("DocumentTypeAlias == \"Home\"");
+ var found1 = doc.Children.Where(x => x.DocumentTypeAlias == "CustomDocument");
+ var found2 = doc.Children.Where(x => x.DocumentTypeAlias == "Home");
Assert.AreEqual(1, found1.Count());
Assert.AreEqual(2, found2.Count());
@@ -358,7 +358,7 @@ namespace Umbraco.Tests.PublishedContent
{
var doc = GetNode(1173);
- var ordered = doc.Children.OrderBy("UpdateDate");
+ var ordered = doc.Children.OrderBy(x => x.UpdateDate);
var correctOrder = new[] { 1178, 1177, 1174, 1176 };
for (var i = 0; i < correctOrder.Length; i++)
@@ -419,7 +419,7 @@ namespace Umbraco.Tests.PublishedContent
{
var doc = GetNode(1174);
- var whereVisible = doc.Ancestors().Where("Visible");
+ var whereVisible = doc.Ancestors().Where(x => x.IsVisible());
Assert.AreEqual(1, whereVisible.Count());
}
diff --git a/src/Umbraco.Tests/PublishedContent/StronglyTypedModels/UmbracoTemplatePage`T.cs b/src/Umbraco.Tests/PublishedContent/StronglyTypedModels/UmbracoTemplatePage`T.cs
deleted file mode 100644
index 1693194542..0000000000
--- a/src/Umbraco.Tests/PublishedContent/StronglyTypedModels/UmbracoTemplatePage`T.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using Umbraco.Core.Models;
-using Umbraco.Core.Models.PublishedContent;
-using Umbraco.Web.Mvc;
-
-namespace Umbraco.Tests.PublishedContent.StronglyTypedModels
-{
- ///
- /// Represents a basic extension of the UmbracoTemplatePage, which allows you to specify
- /// the type of a strongly typed model that inherits from TypedModelBase.
- /// The model is exposed as TypedModel.
- ///
- /// Type of the model to create/expose
- public abstract class UmbracoTemplatePage : UmbracoTemplatePage where T : TypedModelBase
- {
- protected override void InitializePage()
- {
- base.InitializePage();
-
- //set the model to the current node if it is not set, this is generally not the case
- if (Model != null)
- {
- //Map CurrentModel here
- var constructorInfo = typeof(T).GetConstructor(new []{typeof(IPublishedContent)});
- if (constructorInfo != null)
- {
- TypedModel = constructorInfo.Invoke(new object[]{Model.Content}) as T;
- }
- }
- }
-
- ///
- /// Returns the a strongly typed model
- ///
- public T TypedModel { get; private set; }
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj
index f2d2b369b5..c4b6f51dad 100644
--- a/src/Umbraco.Tests/Umbraco.Tests.csproj
+++ b/src/Umbraco.Tests/Umbraco.Tests.csproj
@@ -281,7 +281,6 @@
-
@@ -352,8 +351,6 @@
-
-
@@ -385,7 +382,6 @@
-
@@ -441,8 +437,6 @@
-
-
@@ -500,9 +494,6 @@
-
-
-
diff --git a/src/Umbraco.Tests/Web/Mvc/RenderModelBinderTests.cs b/src/Umbraco.Tests/Web/Mvc/RenderModelBinderTests.cs
index 6216a3acc8..a0e1bc5f9d 100644
--- a/src/Umbraco.Tests/Web/Mvc/RenderModelBinderTests.cs
+++ b/src/Umbraco.Tests/Web/Mvc/RenderModelBinderTests.cs
@@ -35,8 +35,6 @@ namespace Umbraco.Tests.Web.Mvc
Assert.IsNotNull(found);
found = binder.GetBinder(typeof(RenderModel));
Assert.IsNotNull(found);
- found = binder.GetBinder(typeof(DynamicPublishedContent));
- Assert.IsNotNull(found);
found = binder.GetBinder(typeof(MyContent));
Assert.IsNotNull(found);
found = binder.GetBinder(typeof(RenderModel));
diff --git a/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs b/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs
index e7c5a13d76..5fadc27d66 100644
--- a/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs
+++ b/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs
@@ -135,7 +135,6 @@ namespace Umbraco.Tests.Web.Mvc
Mock.Of(query => query.TypedContent(It.IsAny()) ==
//return mock of IPublishedContent for any call to GetById
Mock.Of(content => content.Id == 2)),
- Mock.Of(),
Mock.Of(),
Mock.Of