diff --git a/src/Umbraco.Core/Models/IPublishedContent.cs b/src/Umbraco.Core/Models/IPublishedContent.cs
index 4f563d0e7c..89fdaeed99 100644
--- a/src/Umbraco.Core/Models/IPublishedContent.cs
+++ b/src/Umbraco.Core/Models/IPublishedContent.cs
@@ -16,21 +16,6 @@ namespace Umbraco.Core.Models
///
public interface IPublishedContent
{
- #region ContentSet
-
- // Because of http://issues.umbraco.org/issue/U4-1797 and in order to implement
- // Index() and methods that derive from it such as IsFirst(), IsLast(), etc... all
- // content items must know about their containing content set.
-
- ///
- /// Gets the content set to which the content belongs.
- ///
- /// The default set consists in the siblings of the content (including the content
- /// itself) ordered by sortOrder.
- IEnumerable ContentSet { get; }
-
- #endregion
-
#region ContentType
///
@@ -73,12 +58,6 @@ namespace Umbraco.Core.Models
/// have a published version, or not.
bool IsDraft { get; }
- ///
- /// Gets the index of the published content within its current owning content set.
- ///
- /// The index of the published content within its current owning content set.
- int GetIndex();
-
#endregion
#region Tree
diff --git a/src/Umbraco.Core/Models/PublishedContent/IPublishedContentExtended.cs b/src/Umbraco.Core/Models/PublishedContent/IPublishedContentExtended.cs
index 4446a21329..524ef969b3 100644
--- a/src/Umbraco.Core/Models/PublishedContent/IPublishedContentExtended.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/IPublishedContentExtended.cs
@@ -1,9 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace Umbraco.Core.Models.PublishedContent
+namespace Umbraco.Core.Models.PublishedContent
{
///
/// Provides methods to handle extended content.
@@ -20,27 +15,5 @@ namespace Umbraco.Core.Models.PublishedContent
/// Gets a value indicating whether properties were added to the extended content.
///
bool HasAddedProperties { get; }
-
- ///
- /// Sets the content set of the extended content.
- ///
- ///
- void SetContentSet(IEnumerable contentSet);
-
- ///
- /// Resets the content set of the extended content.
- ///
- void ClearContentSet();
-
- ///
- /// Sets the index of the extended content.
- ///
- /// The index value.
- void SetIndex(int value);
-
- ///
- /// Resets the index of the extended content.
- ///
- void ClearIndex();
}
}
diff --git a/src/Umbraco.Core/Models/PublishedContent/IndexedArrayItem.cs b/src/Umbraco.Core/Models/PublishedContent/IndexedArrayItem.cs
new file mode 100644
index 0000000000..0349807e27
--- /dev/null
+++ b/src/Umbraco.Core/Models/PublishedContent/IndexedArrayItem.cs
@@ -0,0 +1,172 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+
+namespace Umbraco.Core.Models.PublishedContent
+{
+ public class IndexedArrayItem
+ {
+ public IndexedArrayItem(TContent content, int index)
+ {
+ Content = content;
+ Index = index;
+ }
+
+ public TContent Content { get; }
+
+ public int Index { get; }
+
+ public int TotalCount { get; internal set; }
+
+ public bool IsFirst()
+ {
+ return Index == 0;
+ }
+
+ public HtmlString IsFirst(string valueIfTrue)
+ {
+ return IsFirst(valueIfTrue, string.Empty);
+ }
+
+ public HtmlString IsFirst(string valueIfTrue, string valueIfFalse)
+ {
+ return new HtmlString(IsFirst() ? valueIfTrue : valueIfFalse);
+ }
+
+ public bool IsNotFirst()
+ {
+ return IsFirst() == false;
+ }
+
+ public HtmlString IsNotFirst(string valueIfTrue)
+ {
+ return IsNotFirst(valueIfTrue, string.Empty);
+ }
+
+ public HtmlString IsNotFirst(string valueIfTrue, string valueIfFalse)
+ {
+ return new HtmlString(IsNotFirst() ? valueIfTrue : valueIfFalse);
+ }
+
+ public bool IsIndex(int index)
+ {
+ return Index == index;
+ }
+
+ public HtmlString IsIndex(int index, string valueIfTrue)
+ {
+ return IsIndex(index, valueIfTrue, string.Empty);
+ }
+
+ public HtmlString IsIndex(int index, string valueIfTrue, string valueIfFalse)
+ {
+ return new HtmlString(IsIndex(index) ? valueIfTrue : valueIfFalse);
+ }
+
+ public bool IsModZero(int modulus)
+ {
+ return Index % modulus == 0;
+ }
+
+ public HtmlString IsModZero(int modulus, string valueIfTrue)
+ {
+ return IsModZero(modulus, valueIfTrue, string.Empty);
+ }
+
+ public HtmlString IsModZero(int modulus, string valueIfTrue, string valueIfFalse)
+ {
+ return new HtmlString(IsModZero(modulus) ? valueIfTrue : valueIfFalse);
+ }
+
+ public bool IsNotModZero(int modulus)
+ {
+ return IsModZero(modulus) == false;
+ }
+
+ public HtmlString IsNotModZero(int modulus, string valueIfTrue)
+ {
+ return IsNotModZero(modulus, valueIfTrue, string.Empty);
+ }
+
+ public HtmlString IsNotModZero(int modulus, string valueIfTrue, string valueIfFalse)
+ {
+ return new HtmlString(IsNotModZero(modulus) ? valueIfTrue : valueIfFalse);
+ }
+
+ public bool IsNotIndex(int index)
+ {
+ return IsIndex(index) == false;
+ }
+
+ public HtmlString IsNotIndex(int index, string valueIfTrue)
+ {
+ return IsNotIndex(index, valueIfTrue, string.Empty);
+ }
+
+ public HtmlString IsNotIndex(int index, string valueIfTrue, string valueIfFalse)
+ {
+ return new HtmlString(IsNotIndex(index) ? valueIfTrue : valueIfFalse);
+ }
+
+ public bool IsLast()
+ {
+ return Index == TotalCount - 1;
+ }
+
+ public HtmlString IsLast(string valueIfTrue)
+ {
+ return IsLast(valueIfTrue, string.Empty);
+ }
+
+ public HtmlString IsLast(string valueIfTrue, string valueIfFalse)
+ {
+ return new HtmlString(IsLast() ? valueIfTrue : valueIfFalse);
+ }
+
+ public bool IsNotLast()
+ {
+ return IsLast() == false;
+ }
+
+ public HtmlString IsNotLast(string valueIfTrue)
+ {
+ return IsNotLast(valueIfTrue, string.Empty);
+ }
+
+ public HtmlString IsNotLast(string valueIfTrue, string valueIfFalse)
+ {
+ return new HtmlString(IsNotLast() ? valueIfTrue : valueIfFalse);
+ }
+
+ public bool IsEven()
+ {
+ return Index % 2 == 0;
+ }
+
+ public HtmlString IsEven(string valueIfTrue)
+ {
+ return IsEven(valueIfTrue, string.Empty);
+ }
+
+ public HtmlString IsEven(string valueIfTrue, string valueIfFalse)
+ {
+ return new HtmlString(IsEven() ? valueIfTrue : valueIfFalse);
+ }
+
+ public bool IsOdd()
+ {
+ return Index % 2 == 1;
+ }
+
+ public HtmlString IsOdd(string valueIfTrue)
+ {
+ return IsOdd(valueIfTrue, string.Empty);
+ }
+
+ public HtmlString IsOdd(string valueIfTrue, string valueIfFalse)
+ {
+ return new HtmlString(IsOdd() ? valueIfTrue : valueIfFalse);
+ }
+ }
+}
diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentExtended.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentExtended.cs
index d9c3829d6d..6309b6e8b7 100644
--- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentExtended.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentExtended.cs
@@ -17,31 +17,9 @@ namespace Umbraco.Core.Models.PublishedContent
#endregion
- #region Index
-
- private int? _index;
-
- public override int GetIndex()
- {
- // fast
- if (_index.HasValue) return _index.Value;
-
- // slow -- and don't cache, not in a set
- if (_contentSet == null) return Content.GetIndex();
-
- // slow -- but cache for next time
- var index = _contentSet.FindIndex(x => x.Id == Id);
- if (index < 0)
- throw new IndexOutOfRangeException("Could not find content in the content set.");
- _index = index;
- return index;
- }
-
- #endregion
-
#region Extend
- internal static IPublishedContentExtended Extend(IPublishedContent content, IEnumerable contentSet)
+ internal static IPublishedContentExtended Extend(IPublishedContent content)
{
// first unwrap content down to the lowest possible level, ie either the deepest inner
// IPublishedContent or the first extended that has added properties. this is to avoid
@@ -95,7 +73,6 @@ namespace Umbraco.Core.Models.PublishedContent
var extended2 = extended as IPublishedContentExtended;
if (extended2 == null)
throw new Exception("Extended does not implement IPublishedContentExtended.");
- extended2.SetContentSet(contentSet);
return extended2;
}
@@ -115,37 +92,6 @@ namespace Umbraco.Core.Models.PublishedContent
get { return _properties != null; }
}
- void IPublishedContentExtended.SetContentSet(IEnumerable contentSet)
- {
- _contentSet = contentSet;
- }
-
- void IPublishedContentExtended.ClearContentSet()
- {
- _contentSet = null;
- }
-
- void IPublishedContentExtended.SetIndex(int value)
- {
- _index = value;
- }
-
- void IPublishedContentExtended.ClearIndex()
- {
- _index = null;
- }
-
- #endregion
-
- #region Content set
-
- private IEnumerable _contentSet;
-
- public override IEnumerable ContentSet
- {
- get { return _contentSet ?? Content.ContentSet; }
- }
-
#endregion
#region Properties
diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentOrderedSet.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentOrderedSet.cs
deleted file mode 100644
index 25956aa3d4..0000000000
--- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentOrderedSet.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace Umbraco.Core.Models.PublishedContent
-{
- ///
- /// Represents an ordered set of .
- ///
- /// The type of content.
- public class PublishedContentOrderedSet : PublishedContentSet, IOrderedEnumerable
- where T : class, IPublishedContent
- {
-// ReSharper disable ParameterTypeCanBeEnumerable.Local
- internal PublishedContentOrderedSet(IOrderedEnumerable content)
-// ReSharper restore ParameterTypeCanBeEnumerable.Local
- : base(content)
- { }
-
- // note: because we implement IOrderedEnumerable, we don't need to implement the ThenBy nor
- // ThenByDescending methods here, only CreateOrderedEnumerable and that does it.
-
- #region IOrderedEnumerable
-
- public IOrderedEnumerable CreateOrderedEnumerable(Func keySelector, IComparer comparer, bool descending)
- {
- return new PublishedContentOrderedSet(((IOrderedEnumerable)Source).CreateOrderedEnumerable(keySelector, comparer, descending));
- }
-
- #endregion
- }
-}
diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentSet.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentSet.cs
deleted file mode 100644
index 369a554674..0000000000
--- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentSet.cs
+++ /dev/null
@@ -1,234 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace Umbraco.Core.Models.PublishedContent
-{
- ///
- /// Represents a set of .
- ///
- /// The type of content.
- ///
- /// A ContentSet{T} is created from an IEnumerable{T} using the ToContentSet
- /// extension method.
- /// The content set source is enumerated only once. Same as what you get
- /// when you call ToList on an IEnumerable. Only, ToList enumerates its source when
- /// created, whereas a content set enumerates its source only when the content set itself
- /// is enumerated.
- ///
- public class PublishedContentSet : IEnumerable
- where T : class, IPublishedContent
- {
- // used by ToContentSet extension method to initialize a new set from an IEnumerable.
- internal PublishedContentSet(IEnumerable source)
- {
- if (source == null)
- throw new ArgumentNullException("source");
- Source = source;
- }
-
- #region Source
-
- protected readonly IEnumerable Source;
-
- #endregion
-
- #region Enumerated
-
- // cache the enumeration so we don't enumerate more than once. Same as what you get
- // when you call ToList on an IEnumerable. Only, ToList enumerates its source when
- // created, whereas a content set enumerates its source only when the content set itself
- // is enumerated.
-
- // cache the wrapped items so if we reset the enumeration, we do not re-wrap everything (only new items).
-
- private T[] _enumerated;
- private readonly Dictionary _xContent = new Dictionary();
-
- // wrap an item, ie create the actual clone for this set
- private T MapContentAsT(T t)
- {
- return MapContent(t) as T;
- }
-
- internal IPublishedContentExtended MapContent(T t)
- {
- IPublishedContentExtended extend;
- if (_xContent.TryGetValue(t, out extend)) return extend;
-
- extend = PublishedContentExtended.Extend(t, this);
- var asT = extend as T;
- if (asT == null)
- throw new InvalidOperationException(string.Format("Failed extend a published content of type {0}."
- + "Got {1} when expecting {2}.", t.GetType().FullName, extend.GetType().FullName, typeof(T).FullName));
- _xContent[t] = extend;
- return extend;
- }
-
- private T[] Enumerated
- {
- get
- {
- // enumerate the source and cache the result
- // tell clones about their index within the set (for perfs purposes)
- var index = 0;
- return _enumerated ?? (_enumerated = Source.Select(t =>
- {
- var extend = MapContent(t);
- extend.SetIndex(index++);
- return extend as T;
- }).ToArray());
- }
- }
-
- // indicates that the source has changed
- // so the set can clear its inner caches
- // should only be used by DynamicPublishedContentList
- internal void SourceChanged()
- {
- // reset the cached enumeration so it's enumerated again
- if (_enumerated == null) return;
- _enumerated = null;
-
- foreach (var item in _xContent.Values)
- item.ClearIndex();
-
- var removed = _xContent.Keys.Except(Source);
- foreach (var content in removed)
- {
- _xContent[content].ClearContentSet();
- _xContent.Remove(content);
- }
- }
-
- ///
- /// Gets the number of items in the set.
- ///
- /// The number of items in the set.
- /// Will cause the set to be enumerated if it hasn't been already.
- public virtual int Count
- {
- get { return Enumerated.Length; }
- }
- #endregion
-
- #region IEnumerable
-
- public IEnumerator GetEnumerator()
- {
- return ((IEnumerable)Enumerated).GetEnumerator();
- }
-
- System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
-
- #endregion
-
- #region Wrap methods returning T
-
- public T ElementAt(int index)
- {
- return MapContentAsT(Source.ElementAt(index));
- }
-
- public T ElementAtOrDefault(int index)
- {
- var element = Source.ElementAtOrDefault(index);
- return element == null ? null : MapContentAsT(element);
- }
-
- public T First()
- {
- return MapContentAsT(Source.First());
- }
-
- public T First(Func predicate)
- {
- return MapContentAsT(Source.First(predicate));
- }
-
- public T FirstOrDefault()
- {
- var first = Source.FirstOrDefault();
- return first == null ? null : MapContentAsT(first);
- }
-
- public T FirstOrDefault(Func predicate)
- {
- var first = Source.FirstOrDefault(predicate);
- return first == null ? null : MapContentAsT(first);
- }
-
- public T Last()
- {
- return MapContentAsT(Source.Last());
- }
-
- public T Last(Func predicate)
- {
- return MapContentAsT(Source.Last(predicate));
- }
-
- public T LastOrDefault()
- {
- var last = Source.LastOrDefault();
- return last == null ? null : MapContentAsT(last);
- }
-
- public T LastOrDefault(Func predicate)
- {
- var last = Source.LastOrDefault(predicate);
- return last == null ? null : MapContentAsT(last);
- }
-
- public T Single()
- {
- return MapContentAsT(Source.Single());
- }
-
- public T Single(Func predicate)
- {
- return MapContentAsT(Source.Single(predicate));
- }
-
- public T SingleOrDefault()
- {
- var single = Source.SingleOrDefault();
- return single == null ? null : MapContentAsT(single);
- }
-
- public T SingleOrDefault(Func predicate)
- {
- var single = Source.SingleOrDefault(predicate);
- return single == null ? null : MapContentAsT(single);
- }
-
- #endregion
-
- #region Wrap methods returning IOrderedEnumerable
-
- public PublishedContentOrderedSet OrderBy(Func keySelector)
- {
- return new PublishedContentOrderedSet(Source.OrderBy(keySelector));
- }
-
- public PublishedContentOrderedSet OrderBy(Func keySelector, IComparer comparer)
- {
- return new PublishedContentOrderedSet(Source.OrderBy(keySelector, comparer));
- }
-
- public PublishedContentOrderedSet OrderByDescending(Func keySelector)
- {
- return new PublishedContentOrderedSet(Source.OrderByDescending(keySelector));
- }
-
- public PublishedContentOrderedSet OrderByDescending(Func keySelector, IComparer comparer)
- {
- return new PublishedContentOrderedSet(Source.OrderByDescending(keySelector, comparer));
- }
-
- #endregion
- }
-}
diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentWrapped.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentWrapped.cs
index 059979ed66..19f3ac28dd 100644
--- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentWrapped.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentWrapped.cs
@@ -48,12 +48,6 @@ namespace Umbraco.Core.Models.PublishedContent
return Content;
}
- #region ContentSet
-
- public virtual IEnumerable ContentSet => Content.ContentSet;
-
- #endregion
-
#region ContentType
public virtual PublishedContentType ContentType => Content.ContentType;
@@ -102,11 +96,6 @@ namespace Umbraco.Core.Models.PublishedContent
public virtual bool IsDraft => Content.IsDraft;
- public virtual int GetIndex()
- {
- return Content.GetIndex();
- }
-
#endregion
#region Tree
diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj
index 623ec0e4d6..3ea3d79581 100644
--- a/src/Umbraco.Core/Umbraco.Core.csproj
+++ b/src/Umbraco.Core/Umbraco.Core.csproj
@@ -627,8 +627,7 @@
-
-
+
diff --git a/src/Umbraco.Tests/PublishedContent/DynamicDocumentTestsBase.cs b/src/Umbraco.Tests/PublishedContent/DynamicDocumentTestsBase.cs
index 613ada78d8..7e4cf93980 100644
--- a/src/Umbraco.Tests/PublishedContent/DynamicDocumentTestsBase.cs
+++ b/src/Umbraco.Tests/PublishedContent/DynamicDocumentTestsBase.cs
@@ -15,9 +15,9 @@ using Umbraco.Tests.TestHelpers;
namespace Umbraco.Tests.PublishedContent
{
- [TestFixture]
+ [TestFixture]
public abstract class DynamicDocumentTestsBase : PublishedContentTestBase
- {
+ {
private IUmbracoSettingsSection _umbracoSettings;
public override void Initialize()
@@ -37,25 +37,25 @@ namespace Umbraco.Tests.PublishedContent
// 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...
- };
+ {
+ // 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 @"
+ {
+ return @"
@@ -94,14 +94,14 @@ namespace Umbraco.Tests.PublishedContent
";
- }
+ }
- ///
- /// Returns the dynamic node/document to run tests against
- ///
- ///
- ///
- protected abstract dynamic GetDynamicNode(int id);
+ ///
+ /// Returns the dynamic node/document to run tests against
+ ///
+ ///
+ ///
+ protected abstract dynamic GetDynamicNode(int id);
[Test]
public void Recursive_Property()
@@ -135,589 +135,460 @@ namespace Umbraco.Tests.PublishedContent
Assert.AreEqual("page2/alias, 2ndpagealias", doc.umbracoUrlAlias);
}
- ///
- /// Tests the IsLast method with the result set from a Where statement
- ///
[Test]
- public void Is_Last_From_Where_Filter()
+ 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);
- foreach (var d in doc.Children.Where("Visible"))
+ 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
{
- if (d.Id != 1178)
- {
- Assert.IsFalse(d.IsLast());
- }
- else
- {
- Assert.IsTrue(d.IsLast());
- }
+ { "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 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 Index()
- {
- var doc = GetDynamicNode(1173);
- Assert.AreEqual(0, doc.Index());
- doc = GetDynamicNode(1176);
- Assert.AreEqual(3, doc.Index());
- doc = GetDynamicNode(1177);
- Assert.AreEqual(1, doc.Index());
- doc = GetDynamicNode(1178);
- Assert.AreEqual(2, doc.Index());
- }
-
- [Test]
- public virtual void Is_First_Root_Nodes()
- {
- var doc = GetDynamicNode(1046); //test root nodes
- Assert.IsTrue(doc.IsFirst());
- doc = GetDynamicNode(1172);
- Assert.IsFalse(doc.IsFirst());
- }
-
[Test]
- public void Is_First()
+ public void Children_Order_By_Update_Date_Descending()
{
- var doc = GetDynamicNode(1173); //test normal nodes
- Assert.IsTrue(doc.IsFirst());
- doc = GetDynamicNode(1175);
- Assert.IsFalse(doc.IsFirst());
+ 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 virtual void Is_Not_First_Root_Nodes()
+ public void HasProperty()
{
- var doc = GetDynamicNode(1046); //test root nodes
- Assert.IsFalse(doc.IsNotFirst());
- doc = GetDynamicNode(1172);
- Assert.IsTrue(doc.IsNotFirst());
- }
+ var asDynamic = GetDynamicNode(1173);
- [Test]
- public void Is_Not_First()
- {
- var doc = GetDynamicNode(1173); //test normal nodes
- Assert.IsFalse(doc.IsNotFirst());
- doc = GetDynamicNode(1175);
- Assert.IsTrue(doc.IsNotFirst());
- }
+ var hasProp = asDynamic.HasProperty(Constants.Conventions.Content.UrlAlias);
+
+ Assert.AreEqual(true, (bool) hasProp);
+
+ }
[Test]
- public virtual void Is_Position_Root_Nodes()
+ public void Skip()
{
- var doc = GetDynamicNode(1046); //test root nodes
- Assert.IsTrue(doc.IsPosition(0));
- doc = GetDynamicNode(1172);
- Assert.IsTrue(doc.IsPosition(1));
+ 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 Is_Position()
- {
- var doc = GetDynamicNode(1173); //test normal nodes
- Assert.IsTrue(doc.IsPosition(0));
- doc = GetDynamicNode(1175);
- Assert.IsTrue(doc.IsPosition(1));
- }
+ [Test]
+ public void HasValue()
+ {
+ var asDynamic = GetDynamicNode(1173);
- [Test]
- public void Children_GroupBy_DocumentTypeAlias()
- {
- var doc = GetDynamicNode(1046);
+ var hasValue = asDynamic.HasValue(Constants.Conventions.Content.UrlAlias);
+ var noValue = asDynamic.HasValue("blahblahblah");
- var found1 = doc.Children.GroupBy("DocumentTypeAlias");
+ Assert.IsTrue(hasValue);
+ Assert.IsFalse(noValue);
+ }
- 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 Take()
+ {
+ var asDynamic = GetDynamicNode(1173);
- [Test]
- public void Children_Where_DocumentTypeAlias()
- {
- var doc = GetDynamicNode(1046);
+ var take = asDynamic.Children.Take(2);
+ var casted = (IEnumerable) take;
- var found1 = doc.Children.Where("DocumentTypeAlias == \"CustomDocument\"");
- var found2 = doc.Children.Where("DocumentTypeAlias == \"Home\"");
+ Assert.AreEqual(2, casted.Count());
+ Assert.IsTrue(casted.Select(x => ((dynamic) x).Id).ContainsAll(new dynamic[] { 1174, 1177 }));
+ }
- Assert.AreEqual(1, found1.Count());
- Assert.AreEqual(2, found2.Count());
- }
+ [Test]
+ public void Ancestors_Where_Visible()
+ {
+ var asDynamic = GetDynamicNode(1174);
- [Test]
- public void Children_Where_NodeTypeAlias()
- {
- var doc = GetDynamicNode(1046);
+ var whereVisible = asDynamic.Ancestors().Where("Visible");
+ var casted = (IEnumerable) whereVisible;
- var found1 = doc.Children.Where("NodeTypeAlias == \"CustomDocument\"");
- var found2 = doc.Children.Where("NodeTypeAlias == \"Home\"");
+ Assert.AreEqual(1, casted.Count());
- Assert.AreEqual(1, found1.Count());
- Assert.AreEqual(2, found2.Count());
- }
+ }
- [Test]
- public void Children_Order_By_Update_Date()
- {
- var asDynamic = GetDynamicNode(1173);
+ [Test]
+ public void Visible()
+ {
+ var asDynamicHidden = GetDynamicNode(1046);
+ var asDynamicVisible = GetDynamicNode(1173);
- var ordered = asDynamic.Children.OrderBy("UpdateDate");
- var casted = (IEnumerable)ordered;
+ Assert.IsFalse(asDynamicHidden.Visible);
+ Assert.IsTrue(asDynamicVisible.Visible);
+ }
- 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 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 Children_Order_By_Update_Date_Descending()
- {
- var asDynamic = GetDynamicNode(1173);
+ [Test]
+ public void Get_Children_With_Pluralized_Alias()
+ {
+ var asDynamic = GetDynamicNode(1173);
- var ordered = asDynamic.Children.OrderBy("UpdateDate desc");
- var casted = (IEnumerable)ordered;
+ Action