diff --git a/src/EPiServer.Marketing.Testing.Web/Helpers/IReferenceCounter.cs b/src/EPiServer.Marketing.Testing.Web/Helpers/IReferenceCounter.cs index 35b0e9e51..336c15893 100644 --- a/src/EPiServer.Marketing.Testing.Web/Helpers/IReferenceCounter.cs +++ b/src/EPiServer.Marketing.Testing.Web/Helpers/IReferenceCounter.cs @@ -8,5 +8,6 @@ public interface IReferenceCounter void RemoveReference(object src); Boolean hasReference(object src); int getReferenceCount(object src); + bool IsNullOrEmpty(); } } diff --git a/src/EPiServer.Marketing.Testing.Web/Helpers/ReferenceCounter.cs b/src/EPiServer.Marketing.Testing.Web/Helpers/ReferenceCounter.cs index aafeddaee..e67ab3ff2 100644 --- a/src/EPiServer.Marketing.Testing.Web/Helpers/ReferenceCounter.cs +++ b/src/EPiServer.Marketing.Testing.Web/Helpers/ReferenceCounter.cs @@ -51,5 +51,9 @@ public int getReferenceCount(object src) dictionary.TryGetValue(src, out value); return value; } + + public bool IsNullOrEmpty() { + return dictionary is null || (dictionary.Count == 0); + } } } diff --git a/src/EPiServer.Marketing.Testing.Web/TestHandler/TestHandler.cs b/src/EPiServer.Marketing.Testing.Web/TestHandler/TestHandler.cs index ad0252ec9..17a88addf 100644 --- a/src/EPiServer.Marketing.Testing.Web/TestHandler/TestHandler.cs +++ b/src/EPiServer.Marketing.Testing.Web/TestHandler/TestHandler.cs @@ -667,7 +667,7 @@ internal void AddProxyEventHandler(IKpi kpi) // Add the proxyeventhandler only once, if its in our reference counter, just increment // the reference. - if (!_ReferenceCounter.hasReference(kpi.GetType())) + if (_ReferenceCounter.IsNullOrEmpty()) { kpi.EvaluateProxyEvent += ProxyEventHandler; _ReferenceCounter.AddReference(kpi.GetType()); @@ -689,7 +689,7 @@ internal void RemoveProxyEventHandler(IKpi kpi) _ReferenceCounter.RemoveReference(kpi.GetType()); // Remove the proxyeventhandler only once, when the last reference is removed. - if (!_ReferenceCounter.hasReference(kpi.GetType())) + if (_ReferenceCounter.IsNullOrEmpty()) { kpi.EvaluateProxyEvent -= ProxyEventHandler; }