V10: fix build warnings in test projects (#12509)
* Run code cleanup * Dotnet format benchmarks project * Fix up Test.Common * Run dotnet format + manual cleanup * Run code cleanup for unit tests * Run dotnet format * Fix up errors * Manual cleanup of Unit test project * Update tests/Umbraco.Tests.Benchmarks/HexStringBenchmarks.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Testing/TestDbMeta.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Benchmarks/TypeFinderBenchmarks.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Umbraco.Core/Events/EventAggregatorTests.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Fix according to review * Fix after merge * Fix errors Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk> Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> Co-authored-by: Zeegaan <nge@umbraco.dk>
This commit is contained in:
@@ -83,7 +83,8 @@ public class ConfigureConnectionStringsTests
|
||||
AppDomain.CurrentDomain.SetData("DataDirectory", aDataDirectory);
|
||||
var config = new Dictionary<string, string>
|
||||
{
|
||||
[$"ConnectionStrings:{UmbracoDbDsn}"] = $"{ConnectionStrings.DataDirectoryPlaceholder}/{aConnectionString}",
|
||||
[$"ConnectionStrings:{UmbracoDbDsn}"] =
|
||||
$"{ConnectionStrings.DataDirectoryPlaceholder}/{aConnectionString}",
|
||||
[$"ConnectionStrings:{UmbracoDbDsn}_ProviderName"] = aProviderName,
|
||||
};
|
||||
|
||||
|
||||
@@ -7,45 +7,38 @@ using Umbraco.Cms.Core.Configuration;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Configuration.Models.Extensions
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Configuration.Models.Extensions;
|
||||
|
||||
[TestFixture]
|
||||
public class HealthCheckSettingsExtensionsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class HealthCheckSettingsExtensionsTests
|
||||
private ICronTabParser CronTabParser => new NCronTabParser();
|
||||
|
||||
[TestCase("30 12 * * *", 30)]
|
||||
[TestCase("15 18 * * *", (60 * 6) + 15)]
|
||||
[TestCase("0 3 * * *", 60 * 15)]
|
||||
[TestCase("0 3 2 * *", (24 * 60 * 1) + (60 * 15))]
|
||||
[TestCase("0 6 * * 3", (24 * 60 * 3) + (60 * 18))]
|
||||
public void Returns_Notification_Delay_From_Provided_Time(string firstRunTimeCronExpression, int expectedDelayInMinutes)
|
||||
{
|
||||
private ICronTabParser CronTabParser => new NCronTabParser();
|
||||
|
||||
[TestCase("30 12 * * *", 30)]
|
||||
[TestCase("15 18 * * *", (60 * 6) + 15)]
|
||||
[TestCase("0 3 * * *", 60 * 15)]
|
||||
[TestCase("0 3 2 * *", (24 * 60 * 1) + (60 * 15))]
|
||||
[TestCase("0 6 * * 3", (24 * 60 * 3) + (60 * 18))]
|
||||
public void Returns_Notification_Delay_From_Provided_Time(string firstRunTimeCronExpression, int expectedDelayInMinutes)
|
||||
var settings = new HealthChecksSettings
|
||||
{
|
||||
var settings = new HealthChecksSettings
|
||||
{
|
||||
Notification = new HealthChecksNotificationSettings
|
||||
{
|
||||
FirstRunTime = firstRunTimeCronExpression,
|
||||
}
|
||||
};
|
||||
var now = new DateTime(2020, 10, 31, 12, 0, 0);
|
||||
TimeSpan result = settings.GetNotificationDelay(CronTabParser, now, TimeSpan.Zero);
|
||||
Assert.AreEqual(expectedDelayInMinutes, result.TotalMinutes);
|
||||
}
|
||||
Notification = new HealthChecksNotificationSettings { FirstRunTime = firstRunTimeCronExpression },
|
||||
};
|
||||
var now = new DateTime(2020, 10, 31, 12, 0, 0);
|
||||
var result = settings.GetNotificationDelay(CronTabParser, now, TimeSpan.Zero);
|
||||
Assert.AreEqual(expectedDelayInMinutes, result.TotalMinutes);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Returns_Notification_Delay_From_Default_When_Provided_Time_Too_Close_To_Current_Time()
|
||||
[Test]
|
||||
public void Returns_Notification_Delay_From_Default_When_Provided_Time_Too_Close_To_Current_Time()
|
||||
{
|
||||
var settings = new HealthChecksSettings
|
||||
{
|
||||
var settings = new HealthChecksSettings
|
||||
{
|
||||
Notification = new HealthChecksNotificationSettings
|
||||
{
|
||||
FirstRunTime = "30 12 * * *",
|
||||
}
|
||||
};
|
||||
var now = new DateTime(2020, 10, 31, 12, 25, 0);
|
||||
TimeSpan result = settings.GetNotificationDelay(CronTabParser, now, TimeSpan.FromMinutes(10));
|
||||
Assert.AreEqual(10, result.TotalMinutes);
|
||||
}
|
||||
Notification = new HealthChecksNotificationSettings { FirstRunTime = "30 12 * * *" },
|
||||
};
|
||||
var now = new DateTime(2020, 10, 31, 12, 25, 0);
|
||||
var result = settings.GetNotificationDelay(CronTabParser, now, TimeSpan.FromMinutes(10));
|
||||
Assert.AreEqual(10, result.TotalMinutes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,28 +9,27 @@ using Umbraco.Cms.Tests.UnitTests.AutoFixture;
|
||||
using Umbraco.Cms.Web.Common.AspNetCore;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Configuration.Models
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Configuration.Models;
|
||||
|
||||
[TestFixture]
|
||||
public class GlobalSettingsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class GlobalSettingsTests
|
||||
[InlineAutoMoqData("~/umbraco", "/", "umbraco")]
|
||||
[InlineAutoMoqData("~/umbraco", "/MyVirtualDir", "umbraco")]
|
||||
[InlineAutoMoqData("~/customPath", "/MyVirtualDir/", "custompath")]
|
||||
[InlineAutoMoqData("~/some-wacky/nestedPath", "/MyVirtualDir", "some-wacky-nestedpath")]
|
||||
[InlineAutoMoqData("~/some-wacky/nestedPath", "/MyVirtualDir/NestedVDir/", "some-wacky-nestedpath")]
|
||||
public void Umbraco_Mvc_Area(
|
||||
string path,
|
||||
string rootPath,
|
||||
string outcome,
|
||||
[Frozen] IOptionsMonitor<HostingSettings> hostingSettings,
|
||||
AspNetCoreHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
[InlineAutoMoqData("~/umbraco", "/", "umbraco")]
|
||||
[InlineAutoMoqData("~/umbraco", "/MyVirtualDir", "umbraco")]
|
||||
[InlineAutoMoqData("~/customPath", "/MyVirtualDir/", "custompath")]
|
||||
[InlineAutoMoqData("~/some-wacky/nestedPath", "/MyVirtualDir", "some-wacky-nestedpath")]
|
||||
[InlineAutoMoqData("~/some-wacky/nestedPath", "/MyVirtualDir/NestedVDir/", "some-wacky-nestedpath")]
|
||||
public void Umbraco_Mvc_Area(
|
||||
string path,
|
||||
string rootPath,
|
||||
string outcome,
|
||||
[Frozen] IOptionsMonitor<HostingSettings> hostingSettings,
|
||||
AspNetCoreHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
hostingSettings.CurrentValue.ApplicationVirtualPath = rootPath;
|
||||
hostingSettings.CurrentValue.ApplicationVirtualPath = rootPath;
|
||||
|
||||
var globalSettings = new GlobalSettings { UmbracoPath = path };
|
||||
var globalSettings = new GlobalSettings { UmbracoPath = path };
|
||||
|
||||
Assert.AreEqual(outcome, globalSettings.GetUmbracoMvcAreaNoCache(hostingEnvironment));
|
||||
}
|
||||
Assert.AreEqual(outcome, globalSettings.GetUmbracoMvcAreaNoCache(hostingEnvironment));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,88 +3,90 @@ using NUnit.Framework;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Configuration.Models
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Configuration.Models;
|
||||
|
||||
[TestFixture]
|
||||
public class RequestHandlerSettingsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class RequestHandlerSettingsTests
|
||||
[Test]
|
||||
public void Given_CharCollection_With_DefaultEnabled_MergesCollection()
|
||||
{
|
||||
[Test]
|
||||
public void Given_CharCollection_With_DefaultEnabled_MergesCollection()
|
||||
var userCollection = new CharItem[]
|
||||
{
|
||||
var userCollection = new CharItem[]
|
||||
{
|
||||
new () { Char = "test", Replacement = "replace" },
|
||||
new () { Char = "test2", Replacement = "replace2" }
|
||||
};
|
||||
new() { Char = "test", Replacement = "replace" },
|
||||
new() { Char = "test2", Replacement = "replace2" },
|
||||
};
|
||||
|
||||
var settings = new RequestHandlerSettings { UserDefinedCharCollection = userCollection };
|
||||
var actual = settings.GetCharReplacements().ToList();
|
||||
|
||||
var settings = new RequestHandlerSettings { UserDefinedCharCollection = userCollection };
|
||||
var actual = settings.GetCharReplacements().ToList();
|
||||
var expectedCollection = RequestHandlerSettings.DefaultCharCollection.ToList();
|
||||
expectedCollection.AddRange(userCollection);
|
||||
|
||||
var expectedCollection = RequestHandlerSettings.DefaultCharCollection.ToList();
|
||||
expectedCollection.AddRange(userCollection);
|
||||
Assert.AreEqual(expectedCollection.Count, actual.Count);
|
||||
Assert.That(actual, Is.EquivalentTo(expectedCollection));
|
||||
}
|
||||
|
||||
Assert.AreEqual(expectedCollection.Count, actual.Count);
|
||||
Assert.That(actual, Is.EquivalentTo(expectedCollection));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Given_CharCollection_With_DefaultDisabled_ReturnsUserCollection()
|
||||
[Test]
|
||||
public void Given_CharCollection_With_DefaultDisabled_ReturnsUserCollection()
|
||||
{
|
||||
var userCollection = new CharItem[]
|
||||
{
|
||||
var userCollection = new CharItem[]
|
||||
{
|
||||
new () { Char = "test", Replacement = "replace" },
|
||||
new () { Char = "test2", Replacement = "replace2" }
|
||||
};
|
||||
new() { Char = "test", Replacement = "replace" },
|
||||
new() { Char = "test2", Replacement = "replace2" },
|
||||
};
|
||||
|
||||
var settings = new RequestHandlerSettings { UserDefinedCharCollection = userCollection, EnableDefaultCharReplacements = false };
|
||||
var actual = settings.GetCharReplacements().ToList();
|
||||
|
||||
Assert.AreEqual(userCollection.Length, actual.Count);
|
||||
Assert.That(actual, Is.EquivalentTo(userCollection));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Given_CharCollection_That_OverridesDefaultValues_ReturnsReplacements()
|
||||
var settings = new RequestHandlerSettings
|
||||
{
|
||||
var userCollection = new CharItem[]
|
||||
{
|
||||
new () { Char = "%", Replacement = "percent" },
|
||||
new () { Char = ".", Replacement = "dot" }
|
||||
};
|
||||
UserDefinedCharCollection = userCollection,
|
||||
EnableDefaultCharReplacements = false,
|
||||
};
|
||||
var actual = settings.GetCharReplacements().ToList();
|
||||
|
||||
var settings = new RequestHandlerSettings { UserDefinedCharCollection = userCollection };
|
||||
var actual = settings.GetCharReplacements().ToList();
|
||||
Assert.AreEqual(userCollection.Length, actual.Count);
|
||||
Assert.That(actual, Is.EquivalentTo(userCollection));
|
||||
}
|
||||
|
||||
Assert.AreEqual(RequestHandlerSettings.DefaultCharCollection.Length, actual.Count);
|
||||
|
||||
Assert.That(actual, Has.Exactly(1).Matches<CharItem>(x => x.Char == "%" && x.Replacement == "percent"));
|
||||
Assert.That(actual, Has.Exactly(1).Matches<CharItem>(x => x.Char == "." && x.Replacement == "dot"));
|
||||
Assert.That(actual, Has.Exactly(0).Matches<CharItem>(x => x.Char == "%" && x.Replacement == string.Empty));
|
||||
Assert.That(actual, Has.Exactly(0).Matches<CharItem>(x => x.Char == "." && x.Replacement == string.Empty));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Given_CharCollection_That_OverridesDefaultValues_And_ContainsNew_ReturnsMergedWithReplacements()
|
||||
[Test]
|
||||
public void Given_CharCollection_That_OverridesDefaultValues_ReturnsReplacements()
|
||||
{
|
||||
var userCollection = new CharItem[]
|
||||
{
|
||||
var userCollection = new CharItem[]
|
||||
{
|
||||
new () { Char = "%", Replacement = "percent" },
|
||||
new () { Char = ".", Replacement = "dot" },
|
||||
new () { Char = "new", Replacement = "new" }
|
||||
};
|
||||
new() { Char = "%", Replacement = "percent" },
|
||||
new() { Char = ".", Replacement = "dot" },
|
||||
};
|
||||
|
||||
var settings = new RequestHandlerSettings { UserDefinedCharCollection = userCollection };
|
||||
var actual = settings.GetCharReplacements().ToList();
|
||||
var settings = new RequestHandlerSettings { UserDefinedCharCollection = userCollection };
|
||||
var actual = settings.GetCharReplacements().ToList();
|
||||
|
||||
// Add 1 to the length, because we're expecting to only add one new one
|
||||
Assert.AreEqual(RequestHandlerSettings.DefaultCharCollection.Length + 1, actual.Count);
|
||||
Assert.AreEqual(RequestHandlerSettings.DefaultCharCollection.Length, actual.Count);
|
||||
|
||||
Assert.That(actual, Has.Exactly(1).Matches<CharItem>(x => x.Char == "%" && x.Replacement == "percent"));
|
||||
Assert.That(actual, Has.Exactly(1).Matches<CharItem>(x => x.Char == "." && x.Replacement == "dot"));
|
||||
Assert.That(actual, Has.Exactly(1).Matches<CharItem>(x => x.Char == "new" && x.Replacement == "new"));
|
||||
Assert.That(actual, Has.Exactly(0).Matches<CharItem>(x => x.Char == "%" && x.Replacement == string.Empty));
|
||||
Assert.That(actual, Has.Exactly(0).Matches<CharItem>(x => x.Char == "." && x.Replacement == string.Empty));
|
||||
}
|
||||
Assert.That(actual, Has.Exactly(1).Matches<CharItem>(x => x.Char == "%" && x.Replacement == "percent"));
|
||||
Assert.That(actual, Has.Exactly(1).Matches<CharItem>(x => x.Char == "." && x.Replacement == "dot"));
|
||||
Assert.That(actual, Has.Exactly(0).Matches<CharItem>(x => x.Char == "%" && x.Replacement == string.Empty));
|
||||
Assert.That(actual, Has.Exactly(0).Matches<CharItem>(x => x.Char == "." && x.Replacement == string.Empty));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Given_CharCollection_That_OverridesDefaultValues_And_ContainsNew_ReturnsMergedWithReplacements()
|
||||
{
|
||||
var userCollection = new CharItem[]
|
||||
{
|
||||
new() { Char = "%", Replacement = "percent" },
|
||||
new() { Char = ".", Replacement = "dot" },
|
||||
new() { Char = "new", Replacement = "new" },
|
||||
};
|
||||
|
||||
var settings = new RequestHandlerSettings { UserDefinedCharCollection = userCollection };
|
||||
var actual = settings.GetCharReplacements().ToList();
|
||||
|
||||
// Add 1 to the length, because we're expecting to only add one new one
|
||||
Assert.AreEqual(RequestHandlerSettings.DefaultCharCollection.Length + 1, actual.Count);
|
||||
|
||||
Assert.That(actual, Has.Exactly(1).Matches<CharItem>(x => x.Char == "%" && x.Replacement == "percent"));
|
||||
Assert.That(actual, Has.Exactly(1).Matches<CharItem>(x => x.Char == "." && x.Replacement == "dot"));
|
||||
Assert.That(actual, Has.Exactly(1).Matches<CharItem>(x => x.Char == "new" && x.Replacement == "new"));
|
||||
Assert.That(actual, Has.Exactly(0).Matches<CharItem>(x => x.Char == "%" && x.Replacement == string.Empty));
|
||||
Assert.That(actual, Has.Exactly(0).Matches<CharItem>(x => x.Char == "." && x.Replacement == string.Empty));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,15 +52,15 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Configuration.Models.Validati
|
||||
{
|
||||
Error404Collection = new ContentErrorPage[]
|
||||
{
|
||||
new ContentErrorPage { Culture = culture, ContentId = 1, ContentXPath = contentXPath },
|
||||
new() { Culture = culture, ContentId = 1, ContentXPath = contentXPath },
|
||||
},
|
||||
Imaging = new ContentImagingSettings
|
||||
{
|
||||
AutoFillImageProperties = new ImagingAutoFillUploadField[]
|
||||
{
|
||||
new ImagingAutoFillUploadField { Alias = autoFillImagePropertyAlias, WidthFieldAlias = "w", HeightFieldAlias = "h", LengthFieldAlias = "l", ExtensionFieldAlias = "e" }
|
||||
}
|
||||
}
|
||||
new() { Alias = autoFillImagePropertyAlias, WidthFieldAlias = "w", HeightFieldAlias = "h", LengthFieldAlias = "l", ExtensionFieldAlias = "e" },
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,78 +2,61 @@
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
using Umbraco.Cms.Core.Configuration.Models.Validation;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Configuration.Models.Validation
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Configuration.Models.Validation;
|
||||
|
||||
[TestFixture]
|
||||
public class GlobalSettingsValidatorTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class GlobalSettingsValidatorTests
|
||||
[Test]
|
||||
public void Returns_Success_ForValid_Configuration()
|
||||
{
|
||||
[Test]
|
||||
public void Returns_Success_ForValid_Configuration()
|
||||
{
|
||||
var validator = new GlobalSettingsValidator();
|
||||
var options = new GlobalSettings();
|
||||
ValidateOptionsResult result = validator.Validate("settings", options);
|
||||
Assert.True(result.Succeeded);
|
||||
}
|
||||
var validator = new GlobalSettingsValidator();
|
||||
var options = new GlobalSettings();
|
||||
var result = validator.Validate("settings", options);
|
||||
Assert.True(result.Succeeded);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Returns_Fail_For_Configuration_With_Invalid_SmtpFrom_Field()
|
||||
{
|
||||
var validator = new GlobalSettingsValidator();
|
||||
var options = new GlobalSettings
|
||||
{
|
||||
Smtp = new SmtpSettings
|
||||
{
|
||||
From = "invalid",
|
||||
}
|
||||
};
|
||||
[Test]
|
||||
public void Returns_Fail_For_Configuration_With_Invalid_SmtpFrom_Field()
|
||||
{
|
||||
var validator = new GlobalSettingsValidator();
|
||||
var options = new GlobalSettings { Smtp = new SmtpSettings { From = "invalid" } };
|
||||
|
||||
ValidateOptionsResult result = validator.Validate("settings", options);
|
||||
Assert.False(result.Succeeded);
|
||||
}
|
||||
var result = validator.Validate("settings", options);
|
||||
Assert.False(result.Succeeded);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Returns_Fail_For_Configuration_With_Insufficient_SqlWriteLockTimeOut()
|
||||
{
|
||||
var validator = new GlobalSettingsValidator();
|
||||
var options = new GlobalSettings
|
||||
{
|
||||
DistributedLockingWriteLockDefaultTimeout = TimeSpan.Parse("00:00:00.099")
|
||||
};
|
||||
[Test]
|
||||
public void Returns_Fail_For_Configuration_With_Insufficient_SqlWriteLockTimeOut()
|
||||
{
|
||||
var validator = new GlobalSettingsValidator();
|
||||
var options = new GlobalSettings { DistributedLockingWriteLockDefaultTimeout = TimeSpan.Parse("00:00:00.099") };
|
||||
|
||||
ValidateOptionsResult result = validator.Validate("settings", options);
|
||||
Assert.False(result.Succeeded);
|
||||
}
|
||||
var result = validator.Validate("settings", options);
|
||||
Assert.False(result.Succeeded);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Returns_Fail_For_Configuration_With_Excessive_SqlWriteLockTimeOut()
|
||||
{
|
||||
var validator = new GlobalSettingsValidator();
|
||||
var options = new GlobalSettings
|
||||
{
|
||||
DistributedLockingWriteLockDefaultTimeout = TimeSpan.Parse("00:00:21")
|
||||
};
|
||||
[Test]
|
||||
public void Returns_Fail_For_Configuration_With_Excessive_SqlWriteLockTimeOut()
|
||||
{
|
||||
var validator = new GlobalSettingsValidator();
|
||||
var options = new GlobalSettings { DistributedLockingWriteLockDefaultTimeout = TimeSpan.Parse("00:00:21") };
|
||||
|
||||
ValidateOptionsResult result = validator.Validate("settings", options);
|
||||
Assert.False(result.Succeeded);
|
||||
}
|
||||
var result = validator.Validate("settings", options);
|
||||
Assert.False(result.Succeeded);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Returns_Success_For_Configuration_With_Valid_SqlWriteLockTimeOut()
|
||||
{
|
||||
var validator = new GlobalSettingsValidator();
|
||||
var options = new GlobalSettings
|
||||
{
|
||||
DistributedLockingWriteLockDefaultTimeout = TimeSpan.Parse("00:00:20")
|
||||
};
|
||||
[Test]
|
||||
public void Returns_Success_For_Configuration_With_Valid_SqlWriteLockTimeOut()
|
||||
{
|
||||
var validator = new GlobalSettingsValidator();
|
||||
var options = new GlobalSettings { DistributedLockingWriteLockDefaultTimeout = TimeSpan.Parse("00:00:20") };
|
||||
|
||||
ValidateOptionsResult result = validator.Validate("settings", options);
|
||||
Assert.True(result.Succeeded);
|
||||
}
|
||||
var result = validator.Validate("settings", options);
|
||||
Assert.True(result.Succeeded);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,44 +2,42 @@
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core.Configuration;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
using Umbraco.Cms.Core.Configuration.Models.Validation;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Configuration.Models.Validation
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Configuration.Models.Validation;
|
||||
|
||||
[TestFixture]
|
||||
public class HealthChecksSettingsValidatorTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class HealthChecksSettingsValidatorTests
|
||||
[Test]
|
||||
public void Returns_Success_ForValid_Configuration()
|
||||
{
|
||||
[Test]
|
||||
public void Returns_Success_ForValid_Configuration()
|
||||
{
|
||||
var validator = new HealthChecksSettingsValidator(new NCronTabParser());
|
||||
HealthChecksSettings options = BuildHealthChecksSettings();
|
||||
ValidateOptionsResult result = validator.Validate("settings", options);
|
||||
Assert.True(result.Succeeded);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Returns_Fail_For_Configuration_With_Invalid_Notification_FirstRunTime()
|
||||
{
|
||||
var validator = new HealthChecksSettingsValidator(new NCronTabParser());
|
||||
HealthChecksSettings options = BuildHealthChecksSettings(firstRunTime: "0 3 *");
|
||||
ValidateOptionsResult result = validator.Validate("settings", options);
|
||||
Assert.False(result.Succeeded);
|
||||
}
|
||||
|
||||
private static HealthChecksSettings BuildHealthChecksSettings(string firstRunTime = "0 3 * * *") =>
|
||||
new HealthChecksSettings
|
||||
{
|
||||
Notification = new HealthChecksNotificationSettings
|
||||
{
|
||||
Enabled = true,
|
||||
FirstRunTime = firstRunTime,
|
||||
Period = TimeSpan.FromHours(1),
|
||||
}
|
||||
};
|
||||
var validator = new HealthChecksSettingsValidator(new NCronTabParser());
|
||||
var options = BuildHealthChecksSettings();
|
||||
var result = validator.Validate("settings", options);
|
||||
Assert.True(result.Succeeded);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Returns_Fail_For_Configuration_With_Invalid_Notification_FirstRunTime()
|
||||
{
|
||||
var validator = new HealthChecksSettingsValidator(new NCronTabParser());
|
||||
var options = BuildHealthChecksSettings("0 3 *");
|
||||
var result = validator.Validate("settings", options);
|
||||
Assert.False(result.Succeeded);
|
||||
}
|
||||
|
||||
private static HealthChecksSettings BuildHealthChecksSettings(string firstRunTime = "0 3 * * *") =>
|
||||
new()
|
||||
{
|
||||
Notification = new HealthChecksNotificationSettings
|
||||
{
|
||||
Enabled = true,
|
||||
FirstRunTime = firstRunTime,
|
||||
Period = TimeSpan.FromHours(1),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,32 +1,30 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using Microsoft.Extensions.Options;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
using Umbraco.Cms.Core.Configuration.Models.Validation;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Configuration.Models.Validation
|
||||
{
|
||||
[TestFixture]
|
||||
public class RequestHandlerSettingsValidatorTests
|
||||
{
|
||||
[Test]
|
||||
public void Returns_Success_ForValid_Configuration()
|
||||
{
|
||||
var validator = new RequestHandlerSettingsValidator();
|
||||
var options = new RequestHandlerSettings();
|
||||
ValidateOptionsResult result = validator.Validate("settings", options);
|
||||
Assert.True(result.Succeeded);
|
||||
}
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Configuration.Models.Validation;
|
||||
|
||||
[Test]
|
||||
public void Returns_Fail_For_Configuration_With_Invalid_ConvertUrlsToAscii_Field()
|
||||
{
|
||||
var validator = new RequestHandlerSettingsValidator();
|
||||
var options = new RequestHandlerSettings { ConvertUrlsToAscii = "invalid" };
|
||||
ValidateOptionsResult result = validator.Validate("settings", options);
|
||||
Assert.False(result.Succeeded);
|
||||
}
|
||||
[TestFixture]
|
||||
public class RequestHandlerSettingsValidatorTests
|
||||
{
|
||||
[Test]
|
||||
public void Returns_Success_ForValid_Configuration()
|
||||
{
|
||||
var validator = new RequestHandlerSettingsValidator();
|
||||
var options = new RequestHandlerSettings();
|
||||
var result = validator.Validate("settings", options);
|
||||
Assert.True(result.Succeeded);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Returns_Fail_For_Configuration_With_Invalid_ConvertUrlsToAscii_Field()
|
||||
{
|
||||
var validator = new RequestHandlerSettingsValidator();
|
||||
var options = new RequestHandlerSettings { ConvertUrlsToAscii = "invalid" };
|
||||
var result = validator.Validate("settings", options);
|
||||
Assert.False(result.Succeeded);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,32 +4,28 @@
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core.Configuration;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Configuration
|
||||
{
|
||||
[TestFixture]
|
||||
public class NCronTabParserTests
|
||||
{
|
||||
private ICronTabParser Sut => new NCronTabParser();
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Configuration;
|
||||
|
||||
[TestCase("", ExpectedResult = false)]
|
||||
[TestCase("* * * * 1", ExpectedResult = true)]
|
||||
[TestCase("* * * * * 1", ExpectedResult = false)]
|
||||
[TestCase("* * * 1", ExpectedResult = false)]
|
||||
[TestCase("Invalid", ExpectedResult = false)]
|
||||
[TestCase("I n v a l", ExpectedResult = false)]
|
||||
[TestCase("23 0-20/2 * * *", ExpectedResult = true)]
|
||||
[TestCase("5 4 * * sun", ExpectedResult = true)]
|
||||
[TestCase("0 0,12 1 */2 *", ExpectedResult = true)]
|
||||
[TestCase("0 0 1,15 * 3", ExpectedResult = true)]
|
||||
[TestCase("5 0 * 8 *", ExpectedResult = true)]
|
||||
[TestCase("22 * * 1-5 *", ExpectedResult = true)]
|
||||
[TestCase("23 0-20/2 * * *", ExpectedResult = true)]
|
||||
[TestCase("23 0-20/2 * * sun-sat", ExpectedResult = true)]
|
||||
[TestCase("23 0-20/2 * jan-dec sun-sat", ExpectedResult = true)]
|
||||
[TestCase("* * 32 * *", ExpectedResult = false)]
|
||||
public bool IsValidCronTab(string input)
|
||||
{
|
||||
return Sut.IsValidCronTab(input);
|
||||
}
|
||||
}
|
||||
[TestFixture]
|
||||
public class NCronTabParserTests
|
||||
{
|
||||
private ICronTabParser Sut => new NCronTabParser();
|
||||
|
||||
[TestCase("", ExpectedResult = false)]
|
||||
[TestCase("* * * * 1", ExpectedResult = true)]
|
||||
[TestCase("* * * * * 1", ExpectedResult = false)]
|
||||
[TestCase("* * * 1", ExpectedResult = false)]
|
||||
[TestCase("Invalid", ExpectedResult = false)]
|
||||
[TestCase("I n v a l", ExpectedResult = false)]
|
||||
[TestCase("23 0-20/2 * * *", ExpectedResult = true)]
|
||||
[TestCase("5 4 * * sun", ExpectedResult = true)]
|
||||
[TestCase("0 0,12 1 */2 *", ExpectedResult = true)]
|
||||
[TestCase("0 0 1,15 * 3", ExpectedResult = true)]
|
||||
[TestCase("5 0 * 8 *", ExpectedResult = true)]
|
||||
[TestCase("22 * * 1-5 *", ExpectedResult = true)]
|
||||
[TestCase("23 0-20/2 * * *", ExpectedResult = true)]
|
||||
[TestCase("23 0-20/2 * * sun-sat", ExpectedResult = true)]
|
||||
[TestCase("23 0-20/2 * jan-dec sun-sat", ExpectedResult = true)]
|
||||
[TestCase("* * 32 * *", ExpectedResult = false)]
|
||||
public bool IsValidCronTab(string input) => Sut.IsValidCronTab(input);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user