Merge remote-tracking branch 'origin/netcore/feature/migrate-remaining-trees' into netcore/feature/contentcontroller_and_related

This commit is contained in:
Bjarke Berg
2020-06-12 10:03:37 +02:00
79 changed files with 1925 additions and 1331 deletions

View File

@@ -0,0 +1,94 @@
using System;
using System.Linq;
using System.Reflection;
using NUnit.Framework;
using Umbraco.Core.Composing;
using Umbraco.Core.Logging;
using Umbraco.Tests.TestHelpers.Stubs;
using Umbraco.Web.BackOffice.Trees;
namespace Umbraco.Tests.Composing
{
/// <summary>
/// Tests for typefinder
/// </summary>
[TestFixture]
public class TypeFinderTests
{
/// <summary>
/// List of assemblies to scan
/// </summary>
private Assembly[] _assemblies;
[SetUp]
public void Initialize()
{
_assemblies = new[]
{
this.GetType().Assembly,
typeof(System.Guid).Assembly,
typeof(NUnit.Framework.Assert).Assembly,
typeof(System.Xml.NameTable).Assembly,
typeof(System.Configuration.GenericEnumConverter).Assembly,
typeof(TypeFinder).Assembly,
};
}
[Test]
public void Find_Class_Of_Type_With_Attribute()
{
var typeFinder = new TypeFinder(GetTestProfilingLogger(), new DefaultUmbracoAssemblyProvider(GetType().Assembly), new VaryingRuntimeHash());
var typesFound = typeFinder.FindClassesOfTypeWithAttribute<TestEditor, MyTestAttribute>(_assemblies);
Assert.AreEqual(2, typesFound.Count());
}
[Test]
public void Find_Classes_With_Attribute()
{
var typeFinder = new TypeFinder(GetTestProfilingLogger(), new DefaultUmbracoAssemblyProvider(GetType().Assembly), new VaryingRuntimeHash());
var typesFound = typeFinder.FindClassesWithAttribute<TreeAttribute>(_assemblies);
Assert.AreEqual(0, typesFound.Count()); // 0 classes in _assemblies are marked with [Tree]
typesFound = typeFinder.FindClassesWithAttribute<TreeAttribute>(new[] { typeof (TreeAttribute).Assembly });
Assert.AreEqual(22, typesFound.Count()); // + classes in Umbraco.Web are marked with [Tree]
typesFound = typeFinder.FindClassesWithAttribute<TreeAttribute>();
Assert.AreEqual(22, typesFound.Count()); // + classes in Umbraco.Web are marked with [Tree]
}
private static IProfilingLogger GetTestProfilingLogger()
{
var logger = new DebugDiagnosticsLogger(new MessageTemplates());
var profiler = new TestProfiler();
return new ProfilingLogger(logger, profiler);
}
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class MyTestAttribute : Attribute
{
}
public abstract class TestEditor
{
}
[MyTest]
public class BenchmarkTestEditor : TestEditor
{
}
[MyTest]
public class MyOtherTestEditor : TestEditor
{
}
}
}

View File

@@ -15,6 +15,7 @@ using Umbraco.Tests.Testing;
using Umbraco.Web;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.Routing;
using Umbraco.Web.Security;
using Umbraco.Web.Website;
using Umbraco.Web.Website.Controllers;
@@ -50,7 +51,8 @@ namespace Umbraco.Tests.Integration
new UriUtility(hostingEnvironment),
httpContextAccessor,
Mock.Of<ICookieManager>(),
Mock.Of<IRequestAccessor>());
Mock.Of<IRequestAccessor>(),
Mock.Of<IWebSecurity>());
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext();
var umbracoContext = umbracoContextReference.UmbracoContext;
@@ -82,7 +84,8 @@ namespace Umbraco.Tests.Integration
new UriUtility(hostingEnvironment),
httpContextAccessor,
Mock.Of<ICookieManager>(),
Mock.Of<IRequestAccessor>());
Mock.Of<IRequestAccessor>(),
Mock.Of<IWebSecurity>());
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext();
var umbCtx = umbracoContextReference.UmbracoContext;
@@ -118,7 +121,8 @@ namespace Umbraco.Tests.Integration
new UriUtility(hostingEnvironment),
httpContextAccessor,
Mock.Of<ICookieManager>(),
Mock.Of<IRequestAccessor>());
Mock.Of<IRequestAccessor>(),
Mock.Of<IWebSecurity>());
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext();
var umbracoContext = umbracoContextReference.UmbracoContext;
@@ -154,7 +158,8 @@ namespace Umbraco.Tests.Integration
new UriUtility(hostingEnvironment),
httpContextAccessor,
Mock.Of<ICookieManager>(),
Mock.Of<IRequestAccessor>());
Mock.Of<IRequestAccessor>(),
Mock.Of<IWebSecurity>());
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext();
var umbracoContext = umbracoContextReference.UmbracoContext;