Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendy committed Jan 15, 2019
2 parents 82d3d6b + 036981f commit c1ad3eb
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 56 deletions.
2 changes: 1 addition & 1 deletion build/Package.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>Our.Umbraco.Look</id>
<version>0.18.0</version>
<version>0.19.0</version>
<authors>Hendy Racher</authors>
<owners>Hendy Racher</owners>
<licenseUrl>https://github.com/Hendy/umbraco-look/blob/master/LICENSE</licenseUrl>
Expand Down
55 changes: 55 additions & 0 deletions src/Our.Umbraco.Look.Tests/ModelTests/TagQueryComparrisonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,33 @@ public void Null_Tags()
var tagQuery2 = new TagQuery() { All = TagQuery.MakeTags("tag1", "tag2") };

Assert.AreNotEqual(tagQuery1, tagQuery2);
}

[TestMethod]
public void Same_Tags_Both_Empty()
{
var tagQuery1 = new TagQuery() { All = new LookTag[] { } };
var tagQuery2 = new TagQuery() { All = new LookTag[] { } };

Assert.AreEqual(tagQuery1, tagQuery2);
}

[TestMethod]
public void Different_Tags_First_Empty()
{
var tagQuery1 = new TagQuery() { All = new LookTag[] { } };
var tagQuery2 = new TagQuery() { All = TagQuery.MakeTags("tag1") };

Assert.AreNotEqual(tagQuery1, tagQuery2);
}

[TestMethod]
public void Different_Tags_Second_Empty()
{
var tagQuery1 = new TagQuery() { All = TagQuery.MakeTags("tag1") };
var tagQuery2 = new TagQuery() { All = new LookTag[] { } };

Assert.AreNotEqual(tagQuery1, tagQuery2);
}

[TestMethod]
Expand Down Expand Up @@ -113,5 +139,34 @@ public void Different_Tag_Collection_Of_Collections()

Assert.AreNotEqual(tagQuery1, tagQuery2);
}

[TestMethod]
public void Same_Tag_Collection_Of_Collections_Both_Empty()
{
var tagQuery1 = new TagQuery() { Any = new LookTag[][] { } };
var tagQuery2 = new TagQuery() { Any = new LookTag[][] { } };

Assert.AreEqual(tagQuery1, tagQuery2);
}

[TestMethod]
public void Different_Tag_Collection_Of_Collections_First_Empty()
{
var tagQuery1 = new TagQuery() { Any = new LookTag[][] { } };
var tagQuery2 = new TagQuery() { Any = new LookTag[][] { TagQuery.MakeTags("tag1", "tag2") } };

Assert.AreNotEqual(tagQuery1, tagQuery2);
}


[TestMethod]
public void Different_Tag_Collection_Of_Collections_Second_Empty()
{
var tagQuery1 = new TagQuery() { Any = new LookTag[][] { TagQuery.MakeTags("tag1", "tag2") } };
var tagQuery2 = new TagQuery() { Any = new LookTag[][] { } };

Assert.AreNotEqual(tagQuery1, tagQuery2);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System.Collections.Generic;
using System.Linq;

namespace Our.Umbraco.Look.Extensions
{
internal static partial class IEnumerableExtensions
{
/// <summary>
/// Returns true if both are null, or both collections of collections have the same elements in each regardless of sequence
/// </summary>
/// <typeparam name="TSource"></typeparam>
/// <param name="first"></param>
/// <param name="second"></param>
/// <returns></returns>
internal static bool BothNullOrElementCollectionsEqual<TSource>(this IEnumerable<IEnumerable<TSource>> first, IEnumerable<IEnumerable<TSource>> second)
{
if (first == null && second == null) return true;

if (first == null || second == null) return false;

if (first.Count() != second.Count()) return false;

var areEqual = true;

if (first.Any())
{
var firstStack = new Stack<IEnumerable<TSource>>(first);
var secondList = new List<IEnumerable<TSource>>(second);

do
{
var firstCollection = firstStack.Pop();

var matchingCollectionFound = false;

var secondStack = new Stack<IEnumerable<TSource>>(secondList);

do
{
var secondCollection = secondStack.Pop();

matchingCollectionFound = firstCollection.BothNullOrElementsEqual(secondCollection);

if (matchingCollectionFound)
{
secondList.Remove(secondCollection);
}
}
while (!matchingCollectionFound && secondStack.Any());

areEqual = matchingCollectionFound;
}
while (areEqual && firstStack.Any());
}

return areEqual;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,28 @@ internal static bool BothNullOrElementsEqual<TSource>(this IEnumerable<TSource>

if (first.Count() != second.Count()) return false;

Stack<TSource> stack = new Stack<TSource>(first);
List<TSource> list = new List<TSource>(second);

var areEqual = true;

do
if (first.Any())
{
var element = stack.Pop();
Stack<TSource> stack = new Stack<TSource>(first);
List<TSource> list = new List<TSource>(second);

if (!list.Contains(element))
{
areEqual = false;
}
else
do
{
list.Remove(element);
var element = stack.Pop();

if (!list.Contains(element))
{
areEqual = false;
}
else
{
list.Remove(element);
}
}
while (areEqual && stack.Any());
}
while (areEqual && stack.Any());

return areEqual;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Our.Umbraco.Look/LookIndexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ internal void Index(IPublishedContent[] nodes)

indexWriter.AddDocument(document);

foreach (var detachedContent in node.GetFlatDetachedDescendants())
foreach (var detachedNode in node.GetFlatDetachedDescendants())
{
indexingContext = new IndexingContext(node, detachedContent, this.Name);
indexingContext = new IndexingContext(node, detachedNode, this.Name);

document = new Document();

Expand Down
1 change: 1 addition & 0 deletions src/Our.Umbraco.Look/Our.Umbraco.Look.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@
<Compile Include="Events\LookIndexing.cs" />
<Compile Include="Events\HookIndexing.cs" />
<Compile Include="Extensions\GuidExtensions\GuidToLuceneString.cs" />
<Compile Include="Extensions\IEnumerableExtensions\BothNullOrElementCollectionsEqual.cs" />
<Compile Include="Extensions\IEnumerableExtensions\BothNullOrElementsEqual.cs" />
<Compile Include="Extensions\IPublishedContentExtensions\GetFlatDetachedDescendants.cs" />
<Compile Include="Extensions\IPublishedContentExtensions\GetGuidKey.cs" />
Expand Down
4 changes: 2 additions & 2 deletions src/Our.Umbraco.Look/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.18.0.0")]
[assembly: AssemblyFileVersion("0.18.0.0")]
[assembly: AssemblyVersion("0.19.0.0")]
[assembly: AssemblyFileVersion("0.19.0.0")]

[assembly:InternalsVisibleTo("Our.Umbraco.Look.Tests")]
42 changes: 3 additions & 39 deletions src/Our.Umbraco.Look/TagQuery.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Our.Umbraco.Look.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;

Expand All @@ -16,7 +15,7 @@ public class TagQuery
public LookTag[] All { get; set; }

/// <summary>
/// Must have at least one tag from each collection.
/// Must have at least one tag from each collection
/// </summary>
public LookTag[][] Any { get; set; }

Expand Down Expand Up @@ -65,46 +64,11 @@ public override bool Equals(object obj)
{
var tagQuery = obj as TagQuery;

var anyQueryEqual = new Func<LookTag[][], LookTag[][], bool>((first, second) =>
{
if (first == null && second == null) return true;

if (first == null || second == null) return false;

if (first.Count() != second.Count()) return false;

var firstStack = new Stack<LookTag[]>(first);

var areEqual = true;

do
{
var firstCollection = firstStack.Pop();

var matchingCollectionFound = false;

var secondStack = new Stack<LookTag[]>(second);

do
{
var secondCollection = secondStack.Pop();

matchingCollectionFound = firstCollection.BothNullOrElementsEqual(secondCollection);
}
while (!matchingCollectionFound && secondStack.Any());

areEqual = matchingCollectionFound;
}
while (areEqual && firstStack.Any());

return areEqual;
});

return tagQuery != null
&& tagQuery.All.BothNullOrElementsEqual(this.All)
&& tagQuery.All.BothNullOrElementsEqual(this.All)
&& tagQuery.None.BothNullOrElementsEqual(this.None)
&& tagQuery.FacetOn.BothNullOrEquals(this.FacetOn)
&& anyQueryEqual(tagQuery.Any, this.Any); // potentially the slowest of all clauses, so last
&& tagQuery.Any.BothNullOrElementCollectionsEqual(this.Any); // potentially the slowest of all clauses, so last
}

internal TagQuery Clone()
Expand Down

0 comments on commit c1ad3eb

Please sign in to comment.