private void UpdateCategories(XunitBaseElement element, IEnumerable <UnitTestElementCategory> categories)
        {
            using (UT.WriteLock())
            {
                lock (lockObject)
                {
                    var newCategories = categories.ToSet();
                    if (element.Parent != null)
                    {
                        newCategories.AddRange(element.Parent.Categories);
                    }

                    var existingCategories = element.Categories.ToSet();
                    if (newCategories.All(c => existingCategories.Contains(c)) && existingCategories.All(c => newCategories.Contains(c)))
                    {
                        return;
                    }

                    element.Categories = newCategories;

                    // Notify ReSharper that the element has changed. We only need to do this for
                    // categories, and not private data, as ReSharper caches categories
                    if (onUnitTestElementChanged != null)
                    {
                        onUnitTestElementChanged(element);
                    }
                }
            }
        }