U4-6674 - Kill ToContentSet, becomes ToIndexedArray

This commit is contained in:
Stephan
2016-06-09 20:13:20 +02:00
parent cfa91f000b
commit be2d81154b
18 changed files with 626 additions and 1826 deletions

View File

@@ -91,75 +91,39 @@ namespace Umbraco.Tests.PublishedContent
Assert.AreEqual("Content 1", content.Name);
}
[Test]
public void DefaultContentSetIsSiblings()
{
var content = UmbracoContext.Current.ContentCache.GetAtRoot().First();
Assert.AreEqual(0, content.Index());
Assert.IsTrue(content.IsFirst());
}
[Test]
public void RunOnLatestContentSet()
{
// get first content
var content = UmbracoContext.Current.ContentCache.GetAtRoot().First();
var id = content.Id;
Assert.IsTrue(content.IsFirst());
// reverse => should be last, but set has not changed => still first
content = UmbracoContext.Current.ContentCache.GetAtRoot().Reverse().First(x => x.Id == id);
Assert.IsTrue(content.IsFirst());
Assert.IsFalse(content.IsLast());
// reverse + new set => now it's last
content = UmbracoContext.Current.ContentCache.GetAtRoot().Reverse().ToContentSet().First(x => x.Id == id);
Assert.IsFalse(content.IsFirst());
Assert.IsTrue(content.IsLast());
// reverse that set => should be first, but no new set => still last
content = UmbracoContext.Current.ContentCache.GetAtRoot().Reverse().ToContentSet().Reverse().First(x => x.Id == id);
Assert.IsFalse(content.IsFirst());
Assert.IsTrue(content.IsLast());
}
[Test]
public void Distinct()
{
var content = UmbracoContext.Current.ContentCache.GetAtRoot()
var items = UmbracoContext.Current.ContentCache.GetAtRoot()
.Distinct()
.Distinct()
.ToContentSet()
.First();
.ToIndexedArray();
Assert.AreEqual("Content 1", content.Name);
Assert.IsTrue(content.IsFirst());
Assert.IsFalse(content.IsLast());
var item = items[0];
Assert.AreEqual("Content 1", item.Content.Name);
Assert.IsTrue(item.IsFirst());
Assert.IsFalse(item.IsLast());
content = content.Next();
Assert.AreEqual("Content 2", content.Name);
Assert.IsFalse(content.IsFirst());
Assert.IsFalse(content.IsLast());
item = items[1];
Assert.AreEqual("Content 2", item.Content.Name);
Assert.IsFalse(item.IsFirst());
Assert.IsFalse(item.IsLast());
content = content.Next();
Assert.AreEqual("Content 2Sub", content.Name);
Assert.IsFalse(content.IsFirst());
Assert.IsTrue(content.IsLast());
item = items[2];
Assert.AreEqual("Content 2Sub", item.Content.Name);
Assert.IsFalse(item.IsFirst());
Assert.IsTrue(item.IsLast());
}
[Test]
public void OfType1()
{
var content = UmbracoContext.Current.ContentCache.GetAtRoot()
var items = UmbracoContext.Current.ContentCache.GetAtRoot()
.OfType<ContentType2>()
.Distinct()
.ToArray();
Assert.AreEqual(2, content.Count());
Assert.IsInstanceOf<ContentType2>(content.First());
var set = content.ToContentSet();
Assert.IsInstanceOf<ContentType2>(set.First());
Assert.AreSame(set, set.First().ContentSet);
Assert.IsInstanceOf<ContentType2Sub>(set.First().Next());
.ToIndexedArray();
Assert.AreEqual(2, items.Length);
Assert.IsInstanceOf<ContentType2>(items.First().Content);
}
[Test]
@@ -168,11 +132,9 @@ namespace Umbraco.Tests.PublishedContent
var content = UmbracoContext.Current.ContentCache.GetAtRoot()
.OfType<ContentType2Sub>()
.Distinct()
.ToArray();
Assert.AreEqual(1, content.Count());
Assert.IsInstanceOf<ContentType2Sub>(content.First());
var set = content.ToContentSet();
Assert.IsInstanceOf<ContentType2Sub>(set.First());
.ToIndexedArray();
Assert.AreEqual(1, content.Length);
Assert.IsInstanceOf<ContentType2Sub>(content.First().Content);
}
[Test]
@@ -188,17 +150,16 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void Position()
{
var content = UmbracoContext.Current.ContentCache.GetAtRoot()
var items = UmbracoContext.Current.ContentCache.GetAtRoot()
.Where(x => x.GetPropertyValue<int>("prop1") == 1234)
.ToContentSet()
.ToArray();
.ToIndexedArray();
Assert.IsTrue(content.First().IsFirst());
Assert.IsFalse(content.First().IsLast());
Assert.IsFalse(content.First().Next().IsFirst());
Assert.IsFalse(content.First().Next().IsLast());
Assert.IsFalse(content.First().Next().Next().IsFirst());
Assert.IsTrue(content.First().Next().Next().IsLast());
Assert.IsTrue(items.First().IsFirst());
Assert.IsFalse(items.First().IsLast());
Assert.IsFalse(items.Skip(1).First().IsFirst());
Assert.IsFalse(items.Skip(1).First().IsLast());
Assert.IsFalse(items.Skip(2).First().IsFirst());
Assert.IsTrue(items.Skip(2).First().IsLast());
}
[Test]

View File

@@ -199,14 +199,6 @@ namespace Umbraco.Tests.PublishedContent
public PublishedItemType ItemType { get { return PublishedItemType.Content; } }
public bool IsDraft { get; set; }
public int GetIndex()
{
var index = this.Siblings().FindIndex(x => x.Id == Id);
if (index < 0)
throw new IndexOutOfRangeException("Failed to find content in its siblings collection?!");
return index;
}
#endregion
#region Tree
@@ -219,12 +211,6 @@ namespace Umbraco.Tests.PublishedContent
#endregion
#region ContentSet
public IEnumerable<IPublishedContent> ContentSet { get { return this.Siblings(); } }
#endregion
#region ContentType
public PublishedContentType ContentType { get; private set; }

View File

@@ -118,49 +118,16 @@ namespace Umbraco.Tests.PublishedContent
return doc;
}
[Test]
[Ignore("IPublishedContent currently (6.1 as of april 25, 2013) has bugs")]
public void Fails()
{
var content = GetNode(1173);
var c1 = content.Children.First(x => x.Id == 1177);
Assert.IsFalse(c1.IsFirst());
var c2 = content.Children.Where(x => x.DocumentTypeAlias == "CustomDocument").First(x => x.Id == 1177);
Assert.IsTrue(c2.IsFirst());
// First is not implemented
var c2a = content.Children.First(x => x.DocumentTypeAlias == "CustomDocument" && x.Id == 1177);
Assert.IsTrue(c2a.IsFirst()); // so here it's luck
c1 = content.Children.First(x => x.Id == 1177);
Assert.IsFalse(c1.IsFirst()); // and here it fails
// but even using supported (where) method...
// do not replace by First(x => ...) here since it's not supported at the moment
c1 = content.Children.Where(x => x.Id == 1177).First();
c2 = content.Children.Where(x => x.DocumentTypeAlias == "CustomDocument" && x.Id == 1177).First();
Assert.IsFalse(c1.IsFirst()); // here it fails because c2 has corrupted it
// so there's only 1 IPublishedContent instance
// which keeps changing collection, ie being modified
// which is *bad* from a cache point of vue
// and from a consistency point of vue...
// => we want clones!
}
[Test]
public void Is_Last_From_Where_Filter_Dynamic_Linq()
{
var doc = GetNode(1173);
var items = doc.Children.Where("Visible").ToContentSet();
var items = doc.Children.Where("Visible").ToIndexedArray();
foreach (var item in items)
{
if (item.Id != 1178)
if (item.Content.Id != 1178)
{
Assert.IsFalse(item.IsLast());
}
@@ -179,13 +146,13 @@ namespace Umbraco.Tests.PublishedContent
var items = doc
.Children
.Where(x => x.IsVisible())
.ToContentSet();
.ToIndexedArray();
Assert.AreEqual(3, items.Count());
Assert.AreEqual(3, items.Length);
foreach (var d in items)
{
switch (d.Id)
switch (d.Content.Id)
{
case 1174:
Assert.IsTrue(d.IsFirst());
@@ -228,14 +195,13 @@ namespace Umbraco.Tests.PublishedContent
.OfType<Home>() // ours, return IEnumerable<Home> (actually a PublishedContentSet<Home>)
.Where(x => x.IsVisible()) // so, here it's linq again :-(
.ToContentSet() // so, we need that one for the test to pass
.ToArray();
.ToIndexedArray(); // so, we need that one for the test to pass
Assert.AreEqual(1, items.Count());
foreach (var d in items)
{
switch (d.Id)
switch (d.Content.Id)
{
case 1174:
Assert.IsTrue(d.IsFirst());
@@ -253,11 +219,11 @@ namespace Umbraco.Tests.PublishedContent
{
var doc = GetNode(1173);
var items = doc.Children.Take(3).ToContentSet();
var items = doc.Children.Take(3).ToIndexedArray();
foreach (var item in items)
{
if (item.Id != 1178)
if (item.Content.Id != 1178)
{
Assert.IsFalse(item.IsLast());
}
@@ -273,9 +239,9 @@ namespace Umbraco.Tests.PublishedContent
{
var doc = GetNode(1173);
foreach (var d in doc.Children.Skip(1))
foreach (var d in doc.Children.Skip(1).ToIndexedArray())
{
if (d.Id != 1176)
if (d.Content.Id != 1176)
{
Assert.IsFalse(d.IsLast());
}
@@ -293,11 +259,11 @@ namespace Umbraco.Tests.PublishedContent
var items = doc.Children
.Concat(new[] { GetNode(1175), GetNode(4444) })
.ToContentSet();
.ToIndexedArray();
foreach (var item in items)
{
if (item.Id != 4444)
if (item.Content.Id != 4444)
{
Assert.IsFalse(item.IsLast());
}
@@ -362,58 +328,6 @@ namespace Umbraco.Tests.PublishedContent
Assert.IsNotNull(result);
}
[Test]
public void Index()
{
var doc = GetNode(1173);
Assert.AreEqual(0, doc.Index());
doc = GetNode(1176);
Assert.AreEqual(3, doc.Index());
doc = GetNode(1177);
Assert.AreEqual(1, doc.Index());
doc = GetNode(1178);
Assert.AreEqual(2, doc.Index());
}
[Test]
public void Is_First()
{
var doc = GetNode(1046); //test root nodes
Assert.IsTrue(doc.IsFirst());
doc = GetNode(1172);
Assert.IsFalse(doc.IsFirst());
doc = GetNode(1173); //test normal nodes
Assert.IsTrue(doc.IsFirst());
doc = GetNode(1175);
Assert.IsFalse(doc.IsFirst());
}
[Test]
public void Is_Not_First()
{
var doc = GetNode(1046); //test root nodes
Assert.IsFalse(doc.IsNotFirst());
doc = GetNode(1172);
Assert.IsTrue(doc.IsNotFirst());
doc = GetNode(1173); //test normal nodes
Assert.IsFalse(doc.IsNotFirst());
doc = GetNode(1175);
Assert.IsTrue(doc.IsNotFirst());
}
[Test]
public void Is_Position()
{
var doc = GetNode(1046); //test root nodes
Assert.IsTrue(doc.IsPosition(0));
doc = GetNode(1172);
Assert.IsTrue(doc.IsPosition(1));
doc = GetNode(1173); //test normal nodes
Assert.IsTrue(doc.IsPosition(0));
doc = GetNode(1175);
Assert.IsTrue(doc.IsPosition(1));
}
[Test]
public void Children_GroupBy_DocumentTypeAlias()
{
@@ -617,46 +531,6 @@ namespace Umbraco.Tests.PublishedContent
Assert.AreEqual((int)1174, (int)result.Id);
}
[Test]
public void Next()
{
var doc = GetNode(1173);
var result = doc.Next();
Assert.IsNotNull(result);
Assert.AreEqual((int)1175, (int)result.Id);
}
[Test]
public void Next_Without_Sibling()
{
var doc = GetNode(1176);
Assert.IsNull(doc.Next());
}
[Test]
public void Previous_Without_Sibling()
{
var doc = GetNode(1173);
Assert.IsNull(doc.Previous());
}
[Test]
public void Previous()
{
var doc = GetNode(1176);
var result = doc.Previous();
Assert.IsNotNull(result);
Assert.AreEqual((int)1178, (int)result.Id);
}
[Test]
public void DetachedProperty1()
{

View File

@@ -22,10 +22,6 @@ namespace Umbraco.Tests.PublishedContent
Assert.AreEqual(1, content.Level);
Assert.IsNull(content.Parent);
// and yet is has siblings, etc.
var siblings = content.Siblings();
Assert.AreEqual(2, siblings.Count());
// non-existing content is null
content = ctx.ContentCache.GetById(666);
Assert.IsNull(content);