Clean up extension methods (#17051)

Co-authored-by: Andy Butland <abutland73@gmail.com>
This commit is contained in:
Ronald Barendse
2025-05-05 14:53:26 +02:00
committed by GitHub
parent 44d9f5ac2e
commit 2dced37117
28 changed files with 187 additions and 1157 deletions

View File

@@ -88,7 +88,7 @@ public abstract class UmbracoIntegrationTest : UmbracoIntegrationTestBase
public void TearDownAsync()
{
_host.StopAsync();
Services.DisposeIfDisposable();
(Services as IDisposable)?.Dispose();
}
/// <summary>

View File

@@ -43,7 +43,7 @@ internal sealed class BackOfficeExamineSearcherTests : ExamineBaseTest
// When disposing examine, it does a final write, which ends up locking the file if the indexing is not done yet. So we have this wait to circumvent that.
Thread.Sleep(1500);
// Sometimes we do not dispose all services in time and the test fails because the log file is locked. Resulting in all other tests failing as well
Services.DisposeIfDisposable();
(Services as IDisposable)?.Dispose();
}
private IDocumentUrlService DocumentUrlService => GetRequiredService<IDocumentUrlService>();

View File

@@ -47,7 +47,7 @@ internal sealed class ExamineExternalIndexTests : ExamineBaseTest
// When disposing examine, it does a final write, which ends up locking the file if the indexing is not done yet. So we have this wait to circumvent that.
Thread.Sleep(1500);
// Sometimes we do not dispose all services in time and the test fails because the log file is locked. Resulting in all other tests failing as well
Services.DisposeIfDisposable();
(Services as IDisposable)?.Dispose();
}

View File

@@ -40,24 +40,6 @@ public class ObjectExtensionsTests
Assert.AreEqual(3, result.Result.Count());
}
[Test]
public void ObjectExtensions_Object_To_Dictionary()
{
// Arrange
var obj = new { Key1 = "value1", Key2 = "value2", Key3 = "value3" };
// Act
var d = obj.ToDictionary<string>();
// Assert
Assert.IsTrue(d.Keys.Contains("Key1"));
Assert.IsTrue(d.Keys.Contains("Key2"));
Assert.IsTrue(d.Keys.Contains("Key3"));
Assert.AreEqual(d["Key1"], "value1");
Assert.AreEqual(d["Key2"], "value2");
Assert.AreEqual(d["Key3"], "value3");
}
[Test]
public void CanConvertIntToNullableInt()
{

View File

@@ -1,46 +0,0 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.
using Lucene.Net.Index;
using NUnit.Framework;
using Umbraco.Cms.Core;
using Umbraco.Extensions;
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core;
[TestFixture]
public class DelegateExtensionsTests
{
[Test]
public void Only_Executes_Specific_Count()
{
const int maxTries = 5;
var totalTries = 0;
DelegateExtensions.RetryUntilSuccessOrMaxAttempts(
currentTry =>
{
totalTries = currentTry;
return Attempt<IndexWriter>.Fail();
},
5,
TimeSpan.FromMilliseconds(10));
Assert.AreEqual(maxTries, totalTries);
}
[Test]
public void Quits_On_Success_Count()
{
var totalTries = 0;
DelegateExtensions.RetryUntilSuccessOrMaxAttempts(
currentTry =>
{
totalTries = currentTry;
return totalTries == 2 ? Attempt<string>.Succeed() : Attempt<string>.Fail();
},
5,
TimeSpan.FromMilliseconds(10));
Assert.AreEqual(2, totalTries);
}
}

View File

@@ -1,196 +0,0 @@
// using System.Collections.Generic;
// using System.Linq;
// using Moq;
// using NUnit.Framework;
// using Umbraco.Cms.Core.Models;
// using Umbraco.Cms.Core.Routing;
// using Umbraco.Cms.Core.Services;
// using Umbraco.Cms.Infrastructure.PublishedCache;
// using Umbraco.Cms.Tests.Common.Builders;
// using Umbraco.Cms.Tests.Common.Builders.Extensions;
// using Umbraco.Cms.Tests.UnitTests.TestHelpers;
// using Umbraco.Extensions;
//
// namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.PublishedCache;
//
// FIXME: Reintroduce if relevant
// /// <summary>
// /// Unit tests for IPublishedContent and extensions
// /// </summary>
// [TestFixture]
// public class PublishedContentDataTableTests : PublishedSnapshotServiceTestBase
// {
// private readonly DataType[] _dataTypes = GetDefaultDataTypes();
//
// private static ContentType CreateContentType(string name, IDataType dataType, IReadOnlyDictionary<string, string> propertyAliasesAndNames)
// {
// var contentType = new ContentType(TestHelper.ShortStringHelper, -1)
// {
// Alias = name,
// Name = name,
// Key = Guid.NewGuid(),
// Id = name.GetHashCode(),
// };
// foreach (var prop in propertyAliasesAndNames)
// {
// contentType.AddPropertyType(new PropertyType(TestHelper.ShortStringHelper, dataType, prop.Key)
// {
// Name = prop.Value,
// });
// }
//
// return contentType;
// }
//
// private IEnumerable<ContentNodeKit> CreateCache(
// bool createChildren,
// IDataType dataType,
// out ContentType[] contentTypes)
// {
// var result = new List<ContentNodeKit>();
// var valueCounter = 1;
// var parentId = 3;
//
// var properties = new Dictionary<string, string> { ["property1"] = "Property 1", ["property2"] = "Property 2" };
//
// var parentContentType = CreateContentType(
// "Parent",
// dataType,
// new Dictionary<string, string>(properties) { ["property3"] = "Property 3" });
// var childContentType = CreateContentType(
// "Child",
// dataType,
// new Dictionary<string, string>(properties) { ["property4"] = "Property 4" });
// var child2ContentType = CreateContentType(
// "Child2",
// dataType,
// new Dictionary<string, string>(properties) { ["property4"] = "Property 4" });
//
// contentTypes = new[] { parentContentType, childContentType, child2ContentType };
//
// var parentData = new ContentDataBuilder()
// .WithName("Page" + Guid.NewGuid())
// .WithProperties(new PropertyDataBuilder()
// .WithPropertyData("property1", "value" + valueCounter)
// .WithPropertyData("property2", "value" + (valueCounter + 1))
// .WithPropertyData("property3", "value" + (valueCounter + 2))
// .Build())
// .Build();
//
// var parent = ContentNodeKitBuilder.CreateWithContent(
// parentContentType.Id,
// parentId,
// $"-1,{parentId}",
// draftData: parentData,
// publishedData: parentData);
//
// result.Add(parent);
//
// if (createChildren)
// {
// for (var i = 0; i < 3; i++)
// {
// valueCounter += 3;
// var childId = parentId + i + 1;
//
// var childData = new ContentDataBuilder()
// .WithName("Page" + Guid.NewGuid())
// .WithProperties(new PropertyDataBuilder()
// .WithPropertyData("property1", "value" + valueCounter)
// .WithPropertyData("property2", "value" + (valueCounter + 1))
// .WithPropertyData("property4", "value" + (valueCounter + 2))
// .Build())
// .Build();
//
// var child = ContentNodeKitBuilder.CreateWithContent(
// i > 0 ? childContentType.Id : child2ContentType.Id,
// childId,
// $"-1,{parentId},{childId}",
// i,
// draftData: childData,
// publishedData: childData);
//
// result.Add(child);
// }
// }
//
// return result;
// }
//
// [Test]
// public void To_DataTable()
// {
// var cache = CreateCache(true, _dataTypes[0], out var contentTypes);
// InitializedCache(cache, contentTypes, _dataTypes);
//
// var snapshot = GetPublishedSnapshot();
// var root = snapshot.Content.GetAtRoot().First();
//
// var dt = root.ChildrenAsTable(
// VariationContextAccessor,
// ContentTypeService,
// MediaTypeService,
// Mock.Of<IMemberTypeService>(),
// Mock.Of<IPublishedUrlProvider>());
//
// Assert.AreEqual(11, dt.Columns.Count);
// Assert.AreEqual(3, dt.Rows.Count);
// Assert.AreEqual("value4", dt.Rows[0]["Property 1"]);
// Assert.AreEqual("value5", dt.Rows[0]["Property 2"]);
// Assert.AreEqual("value6", dt.Rows[0]["Property 4"]);
// Assert.AreEqual("value7", dt.Rows[1]["Property 1"]);
// Assert.AreEqual("value8", dt.Rows[1]["Property 2"]);
// Assert.AreEqual("value9", dt.Rows[1]["Property 4"]);
// Assert.AreEqual("value10", dt.Rows[2]["Property 1"]);
// Assert.AreEqual("value11", dt.Rows[2]["Property 2"]);
// Assert.AreEqual("value12", dt.Rows[2]["Property 4"]);
// }
//
// [Test]
// public void To_DataTable_With_Filter()
// {
// var cache = CreateCache(true, _dataTypes[0], out var contentTypes);
// InitializedCache(cache, contentTypes, _dataTypes);
//
// var snapshot = GetPublishedSnapshot();
// var root = snapshot.Content.GetAtRoot().First();
//
// var dt = root.ChildrenAsTable(
// VariationContextAccessor,
// ContentTypeService,
// MediaTypeService,
// Mock.Of<IMemberTypeService>(),
// Mock.Of<IPublishedUrlProvider>(),
// "Child");
//
// Assert.AreEqual(11, dt.Columns.Count);
// Assert.AreEqual(2, dt.Rows.Count);
// Assert.AreEqual("value7", dt.Rows[0]["Property 1"]);
// Assert.AreEqual("value8", dt.Rows[0]["Property 2"]);
// Assert.AreEqual("value9", dt.Rows[0]["Property 4"]);
// Assert.AreEqual("value10", dt.Rows[1]["Property 1"]);
// Assert.AreEqual("value11", dt.Rows[1]["Property 2"]);
// Assert.AreEqual("value12", dt.Rows[1]["Property 4"]);
// }
//
// [Test]
// public void To_DataTable_No_Rows()
// {
// var cache = CreateCache(false, _dataTypes[0], out var contentTypes);
// InitializedCache(cache, contentTypes, _dataTypes);
//
// var snapshot = GetPublishedSnapshot();
// var root = snapshot.Content.GetAtRoot().First();
//
// var dt = root.ChildrenAsTable(
// VariationContextAccessor,
// ContentTypeService,
// MediaTypeService,
// Mock.Of<IMemberTypeService>(),
// Mock.Of<IPublishedUrlProvider>());
//
// // will return an empty data table
// Assert.AreEqual(0, dt.Columns.Count);
// Assert.AreEqual(0, dt.Rows.Count);
// }
// }