diff --git a/src/Umbraco.Infrastructure/Configuration/NCronTabParser.cs b/src/Umbraco.Infrastructure/Configuration/NCronTabParser.cs
index 5642c882e6..ca25563730 100644
--- a/src/Umbraco.Infrastructure/Configuration/NCronTabParser.cs
+++ b/src/Umbraco.Infrastructure/Configuration/NCronTabParser.cs
@@ -1,9 +1,8 @@
-using System;
+using System;
using NCrontab;
namespace Umbraco.Core.Configuration
{
-
public class NCronTabParser : ICronTabParser
{
public bool IsValidCronTab(string cronTab)
diff --git a/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs b/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs
index 365dca780c..bed11ca866 100644
--- a/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs
+++ b/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs
@@ -1,6 +1,7 @@
-using System;
-using System.Linq;
-using System.Reflection;
+// Copyright (c) Umbraco.
+// See LICENSE for more details.
+
+using System;
using AutoFixture;
using AutoFixture.AutoMoq;
using AutoFixture.Kernel;
@@ -14,7 +15,6 @@ using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.Models;
using Umbraco.Core.Hosting;
using Umbraco.Core.Security;
-using Umbraco.Tests.Common.Builders;
using Umbraco.Web.BackOffice.Controllers;
using Umbraco.Web.BackOffice.Routing;
using Umbraco.Web.Common.Install;
@@ -23,20 +23,6 @@ using Umbraco.Web.WebApi;
namespace Umbraco.Tests.UnitTests.AutoFixture
{
-
- [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor, AllowMultiple = true)]
- public class InlineAutoMoqDataAttribute : InlineAutoDataAttribute
- {
- ///
- /// Uses AutoFixture to automatically mock (using Moq) the injected types. E.g when injecting interfaces.
- /// AutoFixture is used to generate concrete types. If the concrete type required some types injected, the
- /// [Frozen] can be used to ensure the same variable is injected and available as parameter for the test
- ///
- public InlineAutoMoqDataAttribute(params object[] arguments) : base(() => AutoMoqDataAttribute.AutoMockCustomizations.Default, arguments)
- {
- }
- }
-
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor)]
public class AutoMoqDataAttribute : AutoDataAttribute
{
@@ -45,7 +31,8 @@ namespace Umbraco.Tests.UnitTests.AutoFixture
/// AutoFixture is used to generate concrete types. If the concrete type required some types injected, the
/// [Frozen] can be used to ensure the same variable is injected and available as parameter for the test
///
- public AutoMoqDataAttribute() : base(() => AutoMockCustomizations.Default)
+ public AutoMoqDataAttribute()
+ : base(() => AutoMockCustomizations.Default)
{
}
@@ -58,8 +45,8 @@ namespace Umbraco.Tests.UnitTests.AutoFixture
public void Customize(IFixture fixture)
{
fixture.Customize(
- u => u.FromFactory(
- (a,b,c) => BackOfficeIdentityUser.CreateNew(new GlobalSettings(),a,b,c)));
+ u => u.FromFactory(
+ (a, b, c) => BackOfficeIdentityUser.CreateNew(new GlobalSettings(), a, b, c)));
fixture
.Customize(new ConstructorCustomization(typeof(UsersController), new GreedyConstructorQuery()))
.Customize(new ConstructorCustomization(typeof(InstallController), new GreedyConstructorQuery()))
@@ -68,6 +55,7 @@ namespace Umbraco.Tests.UnitTests.AutoFixture
.Customize(new ConstructorCustomization(typeof(BackOfficeUserManager), new GreedyConstructorQuery()));
fixture.Customize(new AutoMoqCustomization());
+
// When requesting an IUserStore ensure we actually uses a IUserLockoutStore
fixture.Customize>(cc => cc.FromFactory(() => Mock.Of>()));
@@ -93,13 +81,11 @@ namespace Umbraco.Tests.UnitTests.AutoFixture
Mock.Of(x => x.Level == RuntimeLevel.Run))));
var connectionStrings = new ConnectionStrings();
- fixture.Customize(x => x.FromFactory(() => connectionStrings ));
-
+ fixture.Customize(x => x.FromFactory(() => connectionStrings));
var httpContextAccessor = new HttpContextAccessor { HttpContext = new DefaultHttpContext() };
fixture.Customize(x => x.FromFactory(() => httpContextAccessor.HttpContext));
fixture.Customize(x => x.FromFactory(() => httpContextAccessor));
-
}
}
}
diff --git a/src/Umbraco.Tests.UnitTests/AutoFixture/InlineAutoMoqDataAttribute.cs b/src/Umbraco.Tests.UnitTests/AutoFixture/InlineAutoMoqDataAttribute.cs
new file mode 100644
index 0000000000..0c182e6116
--- /dev/null
+++ b/src/Umbraco.Tests.UnitTests/AutoFixture/InlineAutoMoqDataAttribute.cs
@@ -0,0 +1,22 @@
+// Copyright (c) Umbraco.
+// See LICENSE for more details.
+
+using System;
+using AutoFixture.NUnit3;
+
+namespace Umbraco.Tests.UnitTests.AutoFixture
+{
+ [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor, AllowMultiple = true)]
+ public class InlineAutoMoqDataAttribute : InlineAutoDataAttribute
+ {
+ ///
+ /// Uses AutoFixture to automatically mock (using Moq) the injected types. E.g when injecting interfaces.
+ /// AutoFixture is used to generate concrete types. If the concrete type required some types injected, the
+ /// [Frozen] can be used to ensure the same variable is injected and available as parameter for the test
+ ///
+ public InlineAutoMoqDataAttribute(params object[] arguments)
+ : base(() => AutoMoqDataAttribute.AutoMockCustomizations.Default, arguments)
+ {
+ }
+ }
+}
diff --git a/src/Umbraco.Tests.UnitTests/TestHelpers/BaseUsingSqlSyntax.cs b/src/Umbraco.Tests.UnitTests/TestHelpers/BaseUsingSqlSyntax.cs
index 52bc1880a3..76f96ead05 100644
--- a/src/Umbraco.Tests.UnitTests/TestHelpers/BaseUsingSqlSyntax.cs
+++ b/src/Umbraco.Tests.UnitTests/TestHelpers/BaseUsingSqlSyntax.cs
@@ -1,3 +1,6 @@
+// Copyright (c) Umbraco.
+// See LICENSE for more details.
+
using System;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@@ -5,14 +8,12 @@ using Moq;
using NPoco;
using NUnit.Framework;
using Umbraco.Core;
-using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
-using Umbraco.Core.Logging;
+using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Mappers;
using Umbraco.Core.Persistence.SqlSyntax;
using Umbraco.Tests.UnitTests.TestHelpers;
-using Umbraco.Core.DependencyInjection;
namespace Umbraco.Tests.TestHelpers
{
@@ -23,26 +24,22 @@ namespace Umbraco.Tests.TestHelpers
protected ISqlContext SqlContext { get; private set; }
- protected Sql Sql()
- {
- return NPoco.Sql.BuilderFor(SqlContext);
- }
+ protected Sql Sql() => NPoco.Sql.BuilderFor(SqlContext);
[SetUp]
public virtual void Setup()
{
- var container = TestHelper.GetServiceCollection();
- var typeLoader = TestHelper.GetMockedTypeLoader();
+ IServiceCollection container = TestHelper.GetServiceCollection();
+ TypeLoader typeLoader = TestHelper.GetMockedTypeLoader();
var composition = new UmbracoBuilder(container, Mock.Of(), TestHelper.GetMockedTypeLoader());
-
composition.WithCollectionBuilder()
.AddCoreMappers();
- composition.Services.AddUnique(_ => SqlContext);
+ composition.Services.AddUnique(_ => SqlContext);
- var factory = composition.CreateServiceProvider();
+ IServiceProvider factory = composition.CreateServiceProvider();
var pocoMappers = new NPoco.MapperCollection { new PocoMapper() };
var pocoDataFactory = new FluentPocoDataFactory((type, iPocoDataFactory) => new PocoDataBuilder(type, pocoMappers).Init());
var sqlSyntax = new SqlServerSyntaxProvider();
diff --git a/src/Umbraco.Tests.UnitTests/TestHelpers/CompositionExtensions.cs b/src/Umbraco.Tests.UnitTests/TestHelpers/CompositionExtensions.cs
index 5481bfcd76..806878fcc3 100644
--- a/src/Umbraco.Tests.UnitTests/TestHelpers/CompositionExtensions.cs
+++ b/src/Umbraco.Tests.UnitTests/TestHelpers/CompositionExtensions.cs
@@ -1,7 +1,9 @@
-using System;
+// Copyright (c) Umbraco.
+// See LICENSE for more details.
+
+using System;
using Microsoft.Extensions.DependencyInjection;
using Umbraco.Core.DependencyInjection;
-using Umbraco.Core.Composing;
namespace Umbraco.Tests.UnitTests.TestHelpers
{
diff --git a/src/Umbraco.Tests.UnitTests/TestHelpers/Objects/TestUmbracoContextFactory.cs b/src/Umbraco.Tests.UnitTests/TestHelpers/Objects/TestUmbracoContextFactory.cs
index 7889d49192..91d05ba0df 100644
--- a/src/Umbraco.Tests.UnitTests/TestHelpers/Objects/TestUmbracoContextFactory.cs
+++ b/src/Umbraco.Tests.UnitTests/TestHelpers/Objects/TestUmbracoContextFactory.cs
@@ -1,16 +1,17 @@
+// Copyright (c) Umbraco.
+// See LICENSE for more details.
+
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
using Moq;
using Umbraco.Core.Configuration.Models;
using Umbraco.Core.Hosting;
using Umbraco.Core.Security;
-using Umbraco.Core.Services;
using Umbraco.Tests.Common;
using Umbraco.Web;
using Umbraco.Web.Common.AspNetCore;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.Routing;
-using Umbraco.Web.Security;
namespace Umbraco.Tests.UnitTests.TestHelpers.Objects
{
@@ -19,15 +20,31 @@ namespace Umbraco.Tests.UnitTests.TestHelpers.Objects
///
public class TestUmbracoContextFactory
{
- public static IUmbracoContextFactory Create(GlobalSettings globalSettings = null,
+ public static IUmbracoContextFactory Create(
+ GlobalSettings globalSettings = null,
IUmbracoContextAccessor umbracoContextAccessor = null,
IHttpContextAccessor httpContextAccessor = null,
IPublishedUrlProvider publishedUrlProvider = null)
{
- if (globalSettings == null) globalSettings = new GlobalSettings();
- if (umbracoContextAccessor == null) umbracoContextAccessor = new TestUmbracoContextAccessor();
- if (httpContextAccessor == null) httpContextAccessor = Mock.Of();
- if (publishedUrlProvider == null) publishedUrlProvider = Mock.Of();
+ if (globalSettings == null)
+ {
+ globalSettings = new GlobalSettings();
+ }
+
+ if (umbracoContextAccessor == null)
+ {
+ umbracoContextAccessor = new TestUmbracoContextAccessor();
+ }
+
+ if (httpContextAccessor == null)
+ {
+ httpContextAccessor = Mock.Of();
+ }
+
+ if (publishedUrlProvider == null)
+ {
+ publishedUrlProvider = Mock.Of();
+ }
var contentCache = new Mock();
var mediaCache = new Mock();
@@ -37,11 +54,10 @@ namespace Umbraco.Tests.UnitTests.TestHelpers.Objects
var snapshotService = new Mock();
snapshotService.Setup(x => x.CreatePublishedSnapshot(It.IsAny())).Returns(snapshot.Object);
- var hostingEnvironment = Mock.Of();
+ IHostingEnvironment hostingEnvironment = Mock.Of();
var backofficeSecurityAccessorMock = new Mock();
backofficeSecurityAccessorMock.Setup(x => x.BackOfficeSecurity).Returns(Mock.Of());
-
-
+
var umbracoContextFactory = new UmbracoContextFactory(
umbracoContextAccessor,
snapshotService.Object,
@@ -52,8 +68,7 @@ namespace Umbraco.Tests.UnitTests.TestHelpers.Objects
new UriUtility(hostingEnvironment),
new AspNetCoreCookieManager(httpContextAccessor),
Mock.Of(),
- backofficeSecurityAccessorMock.Object
- );
+ backofficeSecurityAccessorMock.Object);
return umbracoContextFactory;
}
diff --git a/src/Umbraco.Tests.UnitTests/TestHelpers/TestHelper.cs b/src/Umbraco.Tests.UnitTests/TestHelpers/TestHelper.cs
index e7d6eec391..0b0f3120d0 100644
--- a/src/Umbraco.Tests.UnitTests/TestHelpers/TestHelper.cs
+++ b/src/Umbraco.Tests.UnitTests/TestHelpers/TestHelper.cs
@@ -1,20 +1,23 @@
-using System;
+// Copyright (c) Umbraco.
+// See LICENSE for more details.
+
+using System;
using System.Collections;
-using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reflection;
-using System.Threading;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Options;
using Moq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration;
+using Umbraco.Core.Configuration.Models;
using Umbraco.Core.Diagnostics;
using Umbraco.Core.Hosting;
using Umbraco.Core.IO;
@@ -22,21 +25,19 @@ using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Entities;
using Umbraco.Core.Models.PublishedContent;
-using Umbraco.Net;
using Umbraco.Core.Persistence;
+using Umbraco.Core.Persistence.SqlSyntax;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Serialization;
using Umbraco.Core.Strings;
+using Umbraco.Infrastructure.Persistence.Mappers;
+using Umbraco.Net;
using Umbraco.Tests.Common;
using Umbraco.Web;
+using Umbraco.Web.Common.AspNetCore;
using Umbraco.Web.Routing;
using File = System.IO.File;
-using Microsoft.Extensions.Options;
-using Umbraco.Core.Configuration.Models;
-using Umbraco.Core.Persistence.SqlSyntax;
-using Umbraco.Web.Common.AspNetCore;
using IHostingEnvironment = Umbraco.Core.Hosting.IHostingEnvironment;
-using Umbraco.Infrastructure.Persistence.Mappers;
namespace Umbraco.Tests.TestHelpers
{
@@ -45,14 +46,13 @@ namespace Umbraco.Tests.TestHelpers
///
public static class TestHelper
{
- private static readonly TestHelperInternal _testHelperInternal = new TestHelperInternal();
- private static IEmailSender _emailSender;
+ private static readonly TestHelperInternal s_testHelperInternal = new TestHelperInternal();
private class TestHelperInternal : TestHelperBase
{
- public TestHelperInternal() : base(typeof(TestHelperInternal).Assembly)
+ public TestHelperInternal()
+ : base(typeof(TestHelperInternal).Assembly)
{
-
}
public override IDbProviderFactoryCreator DbProviderFactoryCreator { get; } = Mock.Of();
@@ -68,9 +68,9 @@ namespace Umbraco.Tests.TestHelpers
{
var testPath = TestContext.CurrentContext.TestDirectory.Split("bin")[0];
return new AspNetCoreHostingEnvironment(
- Mock.Of>(x=>x.CurrentValue == new HostingSettings()),
+ Mock.Of>(x => x.CurrentValue == new HostingSettings()),
Mock.Of(
- x=>
+ x =>
x.WebRootPath == "/" &&
x.ContentRootPath == testPath));
}
@@ -82,13 +82,13 @@ namespace Umbraco.Tests.TestHelpers
=> Mock.Of();
}
- public static ITypeFinder GetTypeFinder() => _testHelperInternal.GetTypeFinder();
+ public static ITypeFinder GetTypeFinder() => s_testHelperInternal.GetTypeFinder();
- public static TypeLoader GetMockedTypeLoader() => _testHelperInternal.GetMockedTypeLoader();
+ public static TypeLoader GetMockedTypeLoader() => s_testHelperInternal.GetMockedTypeLoader();
public static Lazy GetMockSqlContext()
{
- var sqlContext = Mock.Of();
+ ISqlContext sqlContext = Mock.Of();
var syntax = new SqlServerSyntaxProvider();
Mock.Get(sqlContext).Setup(x => x.SqlSyntax).Returns(syntax);
return new Lazy(() => sqlContext);
@@ -97,50 +97,48 @@ namespace Umbraco.Tests.TestHelpers
public static MapperConfigurationStore CreateMaps()
=> new MapperConfigurationStore();
- //public static Configs GetConfigs() => _testHelperInternal.GetConfigs();
+ //// public static Configs GetConfigs() => _testHelperInternal.GetConfigs();
- public static IBackOfficeInfo GetBackOfficeInfo() => _testHelperInternal.GetBackOfficeInfo();
+ public static IBackOfficeInfo GetBackOfficeInfo() => s_testHelperInternal.GetBackOfficeInfo();
- // public static IConfigsFactory GetConfigsFactory() => _testHelperInternal.GetConfigsFactory();
+ //// public static IConfigsFactory GetConfigsFactory() => _testHelperInternal.GetConfigsFactory();
///
/// Gets the working directory of the test project.
///
/// The assembly directory.
- public static string WorkingDirectory => _testHelperInternal.WorkingDirectory;
+ public static string WorkingDirectory => s_testHelperInternal.WorkingDirectory;
- public static IShortStringHelper ShortStringHelper => _testHelperInternal.ShortStringHelper;
- public static IJsonSerializer JsonSerializer => _testHelperInternal.JsonSerializer;
- public static IVariationContextAccessor VariationContextAccessor => _testHelperInternal.VariationContextAccessor;
- public static IDbProviderFactoryCreator DbProviderFactoryCreator => _testHelperInternal.DbProviderFactoryCreator;
- public static IBulkSqlInsertProvider BulkSqlInsertProvider => _testHelperInternal.BulkSqlInsertProvider;
- public static IMarchal Marchal => _testHelperInternal.Marchal;
- public static CoreDebugSettings CoreDebugSettings => _testHelperInternal.CoreDebugSettings;
+ public static IShortStringHelper ShortStringHelper => s_testHelperInternal.ShortStringHelper;
+ public static IJsonSerializer JsonSerializer => s_testHelperInternal.JsonSerializer;
- public static IIOHelper IOHelper => _testHelperInternal.IOHelper;
- public static IMainDom MainDom => _testHelperInternal.MainDom;
- public static UriUtility UriUtility => _testHelperInternal.UriUtility;
+ public static IVariationContextAccessor VariationContextAccessor => s_testHelperInternal.VariationContextAccessor;
+
+ public static IDbProviderFactoryCreator DbProviderFactoryCreator => s_testHelperInternal.DbProviderFactoryCreator;
+
+ public static IBulkSqlInsertProvider BulkSqlInsertProvider => s_testHelperInternal.BulkSqlInsertProvider;
+
+ public static IMarchal Marchal => s_testHelperInternal.Marchal;
+
+ public static CoreDebugSettings CoreDebugSettings => s_testHelperInternal.CoreDebugSettings;
+
+ public static IIOHelper IOHelper => s_testHelperInternal.IOHelper;
+
+ public static IMainDom MainDom => s_testHelperInternal.MainDom;
+
+ public static UriUtility UriUtility => s_testHelperInternal.UriUtility;
public static IEmailSender EmailSender { get; } = new EmailSender(Options.Create(new GlobalSettings()));
-
///
/// Some test files are copied to the /bin (/bin/debug) on build, this is a utility to return their physical path based on a virtual path name
///
- ///
- ///
- public static string MapPathForTestFiles(string relativePath) => _testHelperInternal.MapPathForTestFiles(relativePath);
+ public static string MapPathForTestFiles(string relativePath) => s_testHelperInternal.MapPathForTestFiles(relativePath);
- public static void InitializeContentDirectories()
- {
- CreateDirectories(new[] { Constants.SystemDirectories.MvcViews, new GlobalSettings().UmbracoMediaPath, Constants.SystemDirectories.AppPlugins });
- }
+ public static void InitializeContentDirectories() => CreateDirectories(new[] { Constants.SystemDirectories.MvcViews, new GlobalSettings().UmbracoMediaPath, Constants.SystemDirectories.AppPlugins });
- public static void CleanContentDirectories()
- {
- CleanDirectories(new[] { Constants.SystemDirectories.MvcViews, new GlobalSettings().UmbracoMediaPath });
- }
+ public static void CleanContentDirectories() => CleanDirectories(new[] { Constants.SystemDirectories.MvcViews, new GlobalSettings().UmbracoMediaPath });
public static void CreateDirectories(string[] directories)
{
@@ -148,7 +146,9 @@ namespace Umbraco.Tests.TestHelpers
{
var directoryInfo = new DirectoryInfo(IOHelper.MapPath(directory));
if (directoryInfo.Exists == false)
+ {
Directory.CreateDirectory(IOHelper.MapPath(directory));
+ }
}
}
@@ -156,15 +156,20 @@ namespace Umbraco.Tests.TestHelpers
{
var preserves = new Dictionary
{
- { Constants.SystemDirectories.MvcViews, new[] {"dummy.txt"} }
+ { Constants.SystemDirectories.MvcViews, new[] { "dummy.txt" } }
};
+
foreach (var directory in directories)
{
var directoryInfo = new DirectoryInfo(IOHelper.MapPath(directory));
var preserve = preserves.ContainsKey(directory) ? preserves[directory] : null;
if (directoryInfo.Exists)
- foreach (var x in directoryInfo.GetFiles().Where(x => preserve == null || preserve.Contains(x.Name) == false))
- x.Delete();
+ {
+ foreach (FileInfo fileInfo in directoryInfo.GetFiles().Where(x => preserve == null || preserve.Contains(x.Name) == false))
+ {
+ fileInfo.Delete();
+ }
+ }
}
}
@@ -174,7 +179,9 @@ namespace Umbraco.Tests.TestHelpers
var umbracoSettingsFile = Path.Combine(currDir.Parent.Parent.FullName, "config", "umbracoSettings.config");
if (File.Exists(umbracoSettingsFile))
+ {
File.Delete(umbracoSettingsFile);
+ }
}
// TODO: Move to Assertions or AssertHelper
@@ -183,17 +190,21 @@ namespace Umbraco.Tests.TestHelpers
{
const int dateDeltaMilliseconds = 500; // .5s
- var properties = expected.GetType().GetProperties();
- foreach (var property in properties)
+ PropertyInfo[] properties = expected.GetType().GetProperties();
+ foreach (PropertyInfo property in properties)
{
// ignore properties that are attributed with EditorBrowsableState.Never
- var att = property.GetCustomAttribute(false);
+ EditorBrowsableAttribute att = property.GetCustomAttribute(false);
if (att != null && att.State == EditorBrowsableState.Never)
+ {
continue;
+ }
// ignore explicitely ignored properties
if (ignoreProperties != null && ignoreProperties.Contains(property.Name))
+ {
continue;
+ }
var actualValue = property.GetValue(actual, null);
var expectedValue = property.GetValue(expected, null);
@@ -204,31 +215,36 @@ namespace Umbraco.Tests.TestHelpers
private static void AssertAreEqual(PropertyInfo property, object expected, object actual, Func sorter = null, int dateDeltaMilliseconds = 0)
{
- if (!(expected is string) && expected is IEnumerable)
+ if (!(expected is string) && expected is IEnumerable enumerable)
{
// sort property collection by alias, not by property ids
// on members, built-in properties don't have ids (always zero)
if (expected is PropertyCollection)
- sorter = e => ((PropertyCollection) e).OrderBy(x => x.Alias);
+ {
+ sorter = e => ((PropertyCollection)e).OrderBy(x => x.Alias);
+ }
// compare lists
- AssertListsAreEqual(property, (IEnumerable) actual, (IEnumerable) expected, sorter, dateDeltaMilliseconds);
+ AssertListsAreEqual(property, (IEnumerable)actual, enumerable, sorter, dateDeltaMilliseconds);
}
else if (expected is DateTime expectedDateTime)
{
// compare date & time with delta
- var actualDateTime = (DateTime) actual;
+ var actualDateTime = (DateTime)actual;
var delta = (actualDateTime - expectedDateTime).TotalMilliseconds;
Assert.IsTrue(Math.Abs(delta) <= dateDeltaMilliseconds, "Property {0}.{1} does not match. Expected: {2} but was: {3}", property.DeclaringType.Name, property.Name, expected, actual);
}
else if (expected is Property expectedProperty)
{
// compare values
- var actualProperty = (Property) actual;
- var expectedPropertyValues = expectedProperty.Values.OrderBy(x => x.Culture).ThenBy(x => x.Segment).ToArray();
- var actualPropertyValues = actualProperty.Values.OrderBy(x => x.Culture).ThenBy(x => x.Segment).ToArray();
+ var actualProperty = (Property)actual;
+ IPropertyValue[] expectedPropertyValues = expectedProperty.Values.OrderBy(x => x.Culture).ThenBy(x => x.Segment).ToArray();
+ IPropertyValue[] actualPropertyValues = actualProperty.Values.OrderBy(x => x.Culture).ThenBy(x => x.Segment).ToArray();
if (expectedPropertyValues.Length != actualPropertyValues.Length)
+ {
Assert.Fail($"{property.DeclaringType.Name}.{property.Name}: Expected {expectedPropertyValues.Length} but got {actualPropertyValues.Length}.");
+ }
+
for (var i = 0; i < expectedPropertyValues.Length; i++)
{
Assert.AreEqual(expectedPropertyValues[i].EditedValue, actualPropertyValues[i].EditedValue, $"{property.DeclaringType.Name}.{property.Name}: Expected draft value \"{expectedPropertyValues[i].EditedValue}\" but got \"{actualPropertyValues[i].EditedValue}\".");
@@ -238,22 +254,27 @@ namespace Umbraco.Tests.TestHelpers
else if (expected is IDataEditor expectedEditor)
{
Assert.IsInstanceOf(actual);
- var actualEditor = (IDataEditor) actual;
+ var actualEditor = (IDataEditor)actual;
Assert.AreEqual(expectedEditor.Alias, actualEditor.Alias);
+
// what else shall we test?
}
else
{
// directly compare values
- Assert.AreEqual(expected, actual, "Property {0}.{1} does not match. Expected: {2} but was: {3}", property.DeclaringType.Name, property.Name,
- expected?.ToString() ?? "", actual?.ToString() ?? "");
+ Assert.AreEqual(
+ expected,
+ actual,
+ "Property {0}.{1} does not match. Expected: {2} but was: {3}",
+ property.DeclaringType.Name,
+ property.Name,
+ expected?.ToString() ?? "",
+ actual?.ToString() ?? "");
}
}
private static void AssertListsAreEqual(PropertyInfo property, IEnumerable expected, IEnumerable actual, Func sorter = null, int dateDeltaMilliseconds = 0)
{
-
-
if (sorter == null)
{
// this is pretty hackerific but saves us some code to write
@@ -261,7 +282,7 @@ namespace Umbraco.Tests.TestHelpers
{
// semi-generic way of ensuring any collection of IEntity are sorted by Ids for comparison
var entities = enumerable.OfType().ToList();
- return entities.Count > 0 ? (IEnumerable) entities.OrderBy(x => x.Id) : entities;
+ return entities.Count > 0 ? (IEnumerable)entities.OrderBy(x => x.Id) : entities;
};
}
@@ -269,28 +290,30 @@ namespace Umbraco.Tests.TestHelpers
var actualListEx = sorter(actual).Cast