Move test projects from src/ to tests/ (#11357)
* Update gitignore * Move csproj * Update project references * Update solutions * Update build scripts * Tests used to share editorconfig with projects in src * Fix broken tests. * Stop copying around .editorconfig merged root one with linting * csharp_style_expression_bodied -> suggestion * Move StyleCop rulesets to matching directories and update shared build properties * Remove legacy build files, update NuGet.cofig and solution files * Restore myget source * Clean up .gitignore * Update .gitignore * Move new test classes to tests after merge * Gitignore + nuget config * Move new test Co-authored-by: Ronald Barendse <ronald@barend.se>
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core.Configuration;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Configuration.Models.Extensions
|
||||
{
|
||||
[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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Returns_Notification_Delay_From_Default_When_Provided_Time_Too_Close_To_Current_Time()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using AutoFixture.NUnit3;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
using Umbraco.Cms.Tests.UnitTests.AutoFixture;
|
||||
using Umbraco.Cms.Web.Common.AspNetCore;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Configuration.Models
|
||||
{
|
||||
[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)
|
||||
{
|
||||
hostingSettings.CurrentValue.ApplicationVirtualPath = rootPath;
|
||||
|
||||
var globalSettings = new GlobalSettings { UmbracoPath = path };
|
||||
|
||||
Assert.AreEqual(outcome, globalSettings.GetUmbracoMvcAreaNoCache(hostingEnvironment));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
// 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 ContentSettingsValidatorTests
|
||||
{
|
||||
[Test]
|
||||
public void Returns_Success_ForValid_Configuration()
|
||||
{
|
||||
var validator = new ContentSettingsValidator();
|
||||
ContentSettings options = BuildContentSettings();
|
||||
ValidateOptionsResult result = validator.Validate("settings", options);
|
||||
Assert.True(result.Succeeded);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Returns_Fail_For_Configuration_With_Invalid_Error404Collection_Due_To_Duplicate_Id()
|
||||
{
|
||||
var validator = new ContentSettingsValidator();
|
||||
ContentSettings options = BuildContentSettings(contentXPath: "/aaa/bbb");
|
||||
ValidateOptionsResult result = validator.Validate("settings", options);
|
||||
Assert.False(result.Succeeded);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Returns_Fail_For_Configuration_With_Invalid_Error404Collection_Due_To_Empty_Culture()
|
||||
{
|
||||
var validator = new ContentSettingsValidator();
|
||||
ContentSettings options = BuildContentSettings(culture: string.Empty);
|
||||
ValidateOptionsResult result = validator.Validate("settings", options);
|
||||
Assert.False(result.Succeeded);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Returns_Fail_For_Configuration_With_Invalid_AutoFillImageProperties_Collection()
|
||||
{
|
||||
var validator = new ContentSettingsValidator();
|
||||
ContentSettings options = BuildContentSettings(culture: string.Empty);
|
||||
ValidateOptionsResult result = validator.Validate("settings", options);
|
||||
Assert.False(result.Succeeded);
|
||||
}
|
||||
|
||||
private static ContentSettings BuildContentSettings(string culture = "en-US", string contentXPath = "", string autoFillImagePropertyAlias = "testAlias") =>
|
||||
new ContentSettings
|
||||
{
|
||||
Error404Collection = new ContentErrorPage[]
|
||||
{
|
||||
new ContentErrorPage { Culture = culture, ContentId = 1, ContentXPath = contentXPath },
|
||||
},
|
||||
Imaging = new ContentImagingSettings
|
||||
{
|
||||
AutoFillImageProperties = new ImagingAutoFillUploadField[]
|
||||
{
|
||||
new ImagingAutoFillUploadField { Alias = autoFillImagePropertyAlias, WidthFieldAlias = "w", HeightFieldAlias = "h", LengthFieldAlias = "l", ExtensionFieldAlias = "e" }
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// 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 GlobalSettingsValidatorTests
|
||||
{
|
||||
[Test]
|
||||
public void Returns_Success_ForValid_Configuration()
|
||||
{
|
||||
var validator = new GlobalSettingsValidator();
|
||||
GlobalSettings options = BuildGlobalSettings();
|
||||
ValidateOptionsResult result = validator.Validate("settings", options);
|
||||
Assert.True(result.Succeeded);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Returns_Fail_For_Configuration_With_Invalid_SmtpFrom_Field()
|
||||
{
|
||||
var validator = new GlobalSettingsValidator();
|
||||
GlobalSettings options = BuildGlobalSettings(smtpEmail: "invalid");
|
||||
ValidateOptionsResult result = validator.Validate("settings", options);
|
||||
Assert.False(result.Succeeded);
|
||||
}
|
||||
|
||||
private static GlobalSettings BuildGlobalSettings(string smtpEmail = "test@test.com") =>
|
||||
new GlobalSettings
|
||||
{
|
||||
Smtp = new SmtpSettings
|
||||
{
|
||||
From = smtpEmail,
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// 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
|
||||
{
|
||||
[TestFixture]
|
||||
public class HealthChecksSettingsValidatorTests
|
||||
{
|
||||
[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),
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// 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);
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
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();
|
||||
|
||||
[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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user