From d64fa7f92d89143a8763f1a871145b993ace59a2 Mon Sep 17 00:00:00 2001 From: Shannon Date: Sun, 30 Apr 2017 19:14:36 +1000 Subject: [PATCH] Fixes tests, ensures we null check when generating hashes for items in a collection --- src/Umbraco.Core/HashCodeHelper.cs | 3 +++ src/Umbraco.Tests/Cache/CacheRefresherEventHandlerTests.cs | 3 ++- src/Umbraco.Tests/Scoping/ScopedXmlTests.cs | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Core/HashCodeHelper.cs b/src/Umbraco.Core/HashCodeHelper.cs index a3cedbdbb5..f0f281056d 100644 --- a/src/Umbraco.Core/HashCodeHelper.cs +++ b/src/Umbraco.Core/HashCodeHelper.cs @@ -44,6 +44,7 @@ namespace Umbraco.Core int hash = 0; foreach (var item in list) { + if (item == null) continue; hash = 31 * hash + item.GetHashCode(); } return hash; @@ -57,6 +58,7 @@ namespace Umbraco.Core int hash = 0; foreach (var item in list) { + if (item == null) continue; hash = 31 * hash + item.GetHashCode(); } return hash; @@ -77,6 +79,7 @@ namespace Umbraco.Core int count = 0; foreach (var item in list) { + if (item == null) continue; hash += item.GetHashCode(); count++; } diff --git a/src/Umbraco.Tests/Cache/CacheRefresherEventHandlerTests.cs b/src/Umbraco.Tests/Cache/CacheRefresherEventHandlerTests.cs index 3aa1db675f..8816896975 100644 --- a/src/Umbraco.Tests/Cache/CacheRefresherEventHandlerTests.cs +++ b/src/Umbraco.Tests/Cache/CacheRefresherEventHandlerTests.cs @@ -7,6 +7,7 @@ using Umbraco.Core.Models.Membership; using Umbraco.Core.Services; using Umbraco.Tests.TestHelpers; using Umbraco.Web.Cache; +using System.Linq; namespace Umbraco.Tests.Cache { @@ -31,7 +32,7 @@ namespace Umbraco.Tests.Cache new EventDefinition(null, ServiceContext.SectionService, new EventArgs(), "Deleted"), new EventDefinition(null, ServiceContext.SectionService, new EventArgs(), "New"), - new EventDefinition>(null, ServiceContext.UserService, new SaveEventArgs((IUserType) null)), + new EventDefinition>(null, ServiceContext.UserService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, ServiceContext.UserService, new DeleteEventArgs((IUserType) null)), new EventDefinition>(null, ServiceContext.UserService, new SaveEventArgs((IUser) null)), diff --git a/src/Umbraco.Tests/Scoping/ScopedXmlTests.cs b/src/Umbraco.Tests/Scoping/ScopedXmlTests.cs index 6652c3f2a2..ff45a3c17c 100644 --- a/src/Umbraco.Tests/Scoping/ScopedXmlTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopedXmlTests.cs @@ -179,7 +179,9 @@ namespace Umbraco.Tests.Scoping scope.Complete(); } - Assert.AreEqual(complete ? 2 : 0, evented); + //The reason why there is only 1 event occuring is because we are publishing twice for the same event for the same + //object and the scope deduplicates the events (uses the latest) + Assert.AreEqual(complete ? 1 : 0, evented); // this should never change Assert.AreEqual(beforeOuterXml, beforeXml.OuterXml);