2020-12-20 08:36:11 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
2020-12-03 13:32:04 +00:00
|
|
|
using System;
|
2016-08-25 15:09:51 +02:00
|
|
|
using System.Collections.Generic;
|
2019-11-11 18:56:14 +11:00
|
|
|
using System.IO;
|
2016-12-15 08:57:23 +01:00
|
|
|
using System.Linq;
|
2020-11-18 17:40:23 +00:00
|
|
|
using Microsoft.Extensions.Configuration;
|
2020-10-27 10:53:01 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2020-09-16 15:17:42 +02:00
|
|
|
using Microsoft.Extensions.Logging;
|
2020-09-17 11:35:29 +02:00
|
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
2020-12-03 13:32:04 +00:00
|
|
|
using Microsoft.Extensions.Options;
|
2016-08-25 15:09:51 +02:00
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Umbraco.Cms.Core.Cache;
|
|
|
|
|
using Umbraco.Cms.Core.Composing;
|
|
|
|
|
using Umbraco.Cms.Core.Configuration;
|
|
|
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
|
|
|
|
using Umbraco.Cms.Core.DependencyInjection;
|
|
|
|
|
using Umbraco.Cms.Core.Hosting;
|
|
|
|
|
using Umbraco.Cms.Core.IO;
|
|
|
|
|
using Umbraco.Cms.Core.Logging;
|
2021-02-15 11:41:12 +01:00
|
|
|
using Umbraco.Cms.Core.Scoping;
|
2021-02-12 12:40:08 +01:00
|
|
|
using Umbraco.Cms.Infrastructure.Migrations.Install;
|
2021-02-12 13:36:50 +01:00
|
|
|
using Umbraco.Cms.Infrastructure.Persistence;
|
|
|
|
|
using Umbraco.Cms.Infrastructure.Persistence.Mappers;
|
2021-02-10 14:58:22 +01:00
|
|
|
using Umbraco.Cms.Tests.UnitTests.TestHelpers;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Constants = Umbraco.Cms.Core.Constants;
|
2016-08-25 15:09:51 +02:00
|
|
|
|
2021-02-10 14:58:22 +01:00
|
|
|
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Components
|
2016-08-25 15:09:51 +02:00
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2016-11-05 19:23:55 +01:00
|
|
|
public class ComponentTests
|
2016-08-25 15:09:51 +02:00
|
|
|
{
|
|
|
|
|
private static readonly List<Type> Composed = new List<Type>();
|
2020-09-28 15:43:28 +02:00
|
|
|
private static readonly IIOHelper IOHelper = TestHelper.IOHelper;
|
2019-01-07 09:30:47 +01:00
|
|
|
private static readonly List<Type> Initialized = new List<Type>();
|
|
|
|
|
private static readonly List<Type> Terminated = new List<Type>();
|
2016-08-25 15:09:51 +02:00
|
|
|
|
2020-10-30 11:16:17 +00:00
|
|
|
private static IServiceProvider MockFactory(Action<Mock<IServiceProvider>> setup = null)
|
2016-11-05 19:23:55 +01:00
|
|
|
{
|
2019-01-27 01:17:32 -05:00
|
|
|
// FIXME: use IUmbracoDatabaseFactory vs UmbracoDatabaseFactory, clean it all up!
|
2020-10-30 11:16:17 +00:00
|
|
|
var mock = new Mock<IServiceProvider>();
|
2020-12-20 08:36:11 +01:00
|
|
|
NullLoggerFactory loggerFactory = NullLoggerFactory.Instance;
|
|
|
|
|
ILogger logger = loggerFactory.CreateLogger("GenericLogger");
|
2020-09-21 21:06:24 +02:00
|
|
|
var globalSettings = new GlobalSettings();
|
|
|
|
|
var connectionStrings = new ConnectionStrings();
|
2021-01-18 15:40:22 +01:00
|
|
|
var f = new UmbracoDatabaseFactory(loggerFactory.CreateLogger<UmbracoDatabaseFactory>(), loggerFactory, Options.Create(globalSettings), Options.Create(connectionStrings), new Lazy<IMapperCollection>(() => new MapperCollection(Enumerable.Empty<BaseMapper>())), TestHelper.DbProviderFactoryCreator,
|
|
|
|
|
new DatabaseSchemaCreatorFactory(loggerFactory.CreateLogger<DatabaseSchemaCreator>(), loggerFactory, new UmbracoVersion()));
|
2020-09-29 08:58:24 +02:00
|
|
|
var fs = new FileSystems(mock.Object, loggerFactory.CreateLogger<FileSystems>(), loggerFactory, IOHelper, Options.Create(globalSettings), Mock.Of<IHostingEnvironment>());
|
2020-09-21 21:06:24 +02:00
|
|
|
var coreDebug = new CoreDebugSettings();
|
2020-12-20 08:36:11 +01:00
|
|
|
IMediaFileSystem mediaFileSystem = Mock.Of<IMediaFileSystem>();
|
2020-12-10 18:09:32 +11:00
|
|
|
var p = new ScopeProvider(f, fs, Options.Create(coreDebug), mediaFileSystem, loggerFactory.CreateLogger<ScopeProvider>(), loggerFactory, NoAppCache.Instance);
|
2016-12-15 08:57:23 +01:00
|
|
|
|
2020-12-03 13:32:04 +00:00
|
|
|
mock.Setup(x => x.GetService(typeof(ILogger))).Returns(logger);
|
2020-10-30 11:16:17 +00:00
|
|
|
mock.Setup(x => x.GetService(typeof(ILogger<ComponentCollection>))).Returns(loggerFactory.CreateLogger<ComponentCollection>);
|
|
|
|
|
mock.Setup(x => x.GetService(typeof(ILoggerFactory))).Returns(loggerFactory);
|
2020-12-03 13:32:04 +00:00
|
|
|
mock.Setup(x => x.GetService(typeof(IProfilingLogger))).Returns(new ProfilingLogger(loggerFactory.CreateLogger<ProfilingLogger>(), Mock.Of<IProfiler>()));
|
|
|
|
|
mock.Setup(x => x.GetService(typeof(IUmbracoDatabaseFactory))).Returns(f);
|
|
|
|
|
mock.Setup(x => x.GetService(typeof(IScopeProvider))).Returns(p);
|
2018-09-03 00:16:38 +02:00
|
|
|
|
2016-11-05 19:23:55 +01:00
|
|
|
setup?.Invoke(mock);
|
|
|
|
|
return mock.Object;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
private static IServiceCollection MockRegister() => new ServiceCollection();
|
2020-09-28 15:43:28 +02:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
private static TypeLoader MockTypeLoader() => new TypeLoader(Mock.Of<ITypeFinder>(), Mock.Of<IAppPolicyCache>(), new DirectoryInfo(TestHelper.GetHostingEnvironment().MapPathContentRoot(Constants.SystemDirectories.TempData)), Mock.Of<ILogger<TypeLoader>>(), Mock.Of<IProfilingLogger>());
|
2018-12-12 14:28:57 +01:00
|
|
|
|
2016-08-25 15:09:51 +02:00
|
|
|
[Test]
|
2018-06-20 11:33:42 +02:00
|
|
|
public void Boot1A()
|
2016-08-25 15:09:51 +02:00
|
|
|
{
|
2020-12-20 08:36:11 +01:00
|
|
|
IServiceCollection register = MockRegister();
|
2020-11-20 11:48:32 +00:00
|
|
|
var composition = new UmbracoBuilder(register, Mock.Of<IConfiguration>(), TestHelper.GetMockedTypeLoader());
|
2016-08-25 15:09:51 +02:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
Type[] types = TypeArray<Composer1, Composer2, Composer4>();
|
2020-11-19 16:20:39 +00:00
|
|
|
var composers = new Composers(composition, types, Enumerable.Empty<Attribute>(), Mock.Of<ILogger<Composers>>());
|
2016-08-25 15:09:51 +02:00
|
|
|
Composed.Clear();
|
2020-12-20 08:36:11 +01:00
|
|
|
|
2016-12-15 13:15:49 +01:00
|
|
|
// 2 is Core and requires 4
|
2020-12-02 08:27:37 +01:00
|
|
|
// 3 is User
|
2016-12-15 13:15:49 +01:00
|
|
|
// => reorder components accordingly
|
2019-01-07 09:30:47 +01:00
|
|
|
composers.Compose();
|
2019-01-03 21:00:28 +01:00
|
|
|
AssertTypeArray(TypeArray<Composer1, Composer4, Composer2>(), Composed);
|
2019-01-07 09:30:47 +01:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
IServiceProvider factory = MockFactory(m =>
|
2019-01-07 09:30:47 +01:00
|
|
|
{
|
2020-10-27 10:53:01 +00:00
|
|
|
m.Setup(x => x.GetService(It.Is<Type>(t => t == typeof(ISomeResource)))).Returns(() => new SomeResource());
|
2020-10-30 11:16:17 +00:00
|
|
|
m.Setup(x => x.GetService(It.IsAny<Type>())).Returns<Type>((type) =>
|
2019-01-07 09:30:47 +01:00
|
|
|
{
|
2020-12-03 13:32:04 +00:00
|
|
|
if (type == typeof(Composer1))
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
2020-12-03 13:32:04 +00:00
|
|
|
return new Composer1();
|
2020-12-20 08:36:11 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-03 13:32:04 +00:00
|
|
|
if (type == typeof(Composer5))
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
2020-12-03 13:32:04 +00:00
|
|
|
return new Composer5();
|
2020-12-20 08:36:11 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-03 13:32:04 +00:00
|
|
|
if (type == typeof(Component5))
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
2020-12-03 13:32:04 +00:00
|
|
|
return new Component5(new SomeResource());
|
2020-12-20 08:36:11 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-03 13:32:04 +00:00
|
|
|
if (type == typeof(IProfilingLogger))
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
2020-12-03 13:32:04 +00:00
|
|
|
return new ProfilingLogger(Mock.Of<ILogger<ProfilingLogger>>(), Mock.Of<IProfiler>());
|
2020-12-20 08:36:11 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-03 13:32:04 +00:00
|
|
|
if (type == typeof(ILogger<ComponentCollection>))
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
2020-12-03 13:32:04 +00:00
|
|
|
return Mock.Of<ILogger<ComponentCollection>>();
|
2020-12-20 08:36:11 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-07 09:30:47 +01:00
|
|
|
throw new NotSupportedException(type.FullName);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
ComponentCollectionBuilder builder = composition.WithCollectionBuilder<ComponentCollectionBuilder>();
|
2020-10-30 11:16:17 +00:00
|
|
|
builder.RegisterWith(register);
|
2020-12-20 08:36:11 +01:00
|
|
|
ComponentCollection components = builder.CreateCollection(factory);
|
2019-01-07 09:30:47 +01:00
|
|
|
|
|
|
|
|
Assert.IsEmpty(components);
|
|
|
|
|
components.Initialize();
|
|
|
|
|
Assert.IsEmpty(Initialized);
|
|
|
|
|
components.Terminate();
|
|
|
|
|
Assert.IsEmpty(Terminated);
|
2018-06-20 11:33:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Boot1B()
|
|
|
|
|
{
|
2020-12-20 08:36:11 +01:00
|
|
|
IServiceCollection register = MockRegister();
|
2020-11-20 11:48:32 +00:00
|
|
|
var composition = new UmbracoBuilder(register, Mock.Of<IConfiguration>(), TestHelper.GetMockedTypeLoader());
|
2018-06-20 11:33:42 +02:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
Type[] types = TypeArray<Composer1, Composer2, Composer3, Composer4>();
|
2020-11-19 16:20:39 +00:00
|
|
|
var composers = new Composers(composition, types, Enumerable.Empty<Attribute>(), Mock.Of<ILogger<Composers>>());
|
2018-06-20 11:33:42 +02:00
|
|
|
Composed.Clear();
|
2020-12-20 08:36:11 +01:00
|
|
|
|
2018-06-20 11:33:42 +02:00
|
|
|
// 2 is Core and requires 4
|
|
|
|
|
// 3 is User - stays with RuntimeLevel.Run
|
|
|
|
|
// => reorder components accordingly
|
2019-02-14 10:39:27 +01:00
|
|
|
composers.Compose();
|
2019-01-03 21:00:28 +01:00
|
|
|
AssertTypeArray(TypeArray<Composer1, Composer4, Composer2, Composer3>(), Composed);
|
2016-12-15 13:15:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Boot2()
|
|
|
|
|
{
|
2020-12-20 08:36:11 +01:00
|
|
|
IServiceCollection register = MockRegister();
|
2020-11-20 11:48:32 +00:00
|
|
|
var composition = new UmbracoBuilder(register, Mock.Of<IConfiguration>(), TestHelper.GetMockedTypeLoader());
|
2016-12-15 13:15:49 +01:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
Type[] types = TypeArray<Composer20, Composer21>();
|
2020-11-19 16:20:39 +00:00
|
|
|
var composers = new Composers(composition, types, Enumerable.Empty<Attribute>(), Mock.Of<ILogger<Composers>>());
|
2016-12-15 13:15:49 +01:00
|
|
|
Composed.Clear();
|
2020-12-20 08:36:11 +01:00
|
|
|
|
2016-12-15 13:15:49 +01:00
|
|
|
// 21 is required by 20
|
|
|
|
|
// => reorder components accordingly
|
2019-02-14 10:39:27 +01:00
|
|
|
composers.Compose();
|
2019-01-03 21:00:28 +01:00
|
|
|
AssertTypeArray(TypeArray<Composer21, Composer20>(), Composed);
|
2016-08-25 15:09:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2016-12-15 13:15:49 +01:00
|
|
|
public void Boot3()
|
|
|
|
|
{
|
2020-12-20 08:36:11 +01:00
|
|
|
IServiceCollection register = MockRegister();
|
2020-11-20 11:48:32 +00:00
|
|
|
var composition = new UmbracoBuilder(register, Mock.Of<IConfiguration>(), TestHelper.GetMockedTypeLoader());
|
2016-12-15 13:15:49 +01:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
Type[] types = TypeArray<Composer22, Composer24, Composer25>();
|
2020-11-19 16:20:39 +00:00
|
|
|
var composers = new Composers(composition, types, Enumerable.Empty<Attribute>(), Mock.Of<ILogger<Composers>>());
|
2016-12-15 13:15:49 +01:00
|
|
|
Composed.Clear();
|
2020-12-20 08:36:11 +01:00
|
|
|
|
2016-12-15 13:15:49 +01:00
|
|
|
// i23 requires 22
|
|
|
|
|
// 24, 25 implement i23
|
|
|
|
|
// 25 required by i23
|
|
|
|
|
// => reorder components accordingly
|
2019-02-14 10:39:27 +01:00
|
|
|
composers.Compose();
|
2019-01-03 21:00:28 +01:00
|
|
|
AssertTypeArray(TypeArray<Composer22, Composer25, Composer24>(), Composed);
|
2016-12-15 13:15:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void BrokenRequire()
|
2016-08-25 15:09:51 +02:00
|
|
|
{
|
2020-12-20 08:36:11 +01:00
|
|
|
IServiceCollection register = MockRegister();
|
2020-11-20 11:48:32 +00:00
|
|
|
var composition = new UmbracoBuilder(register, Mock.Of<IConfiguration>(), TestHelper.GetMockedTypeLoader());
|
2016-08-25 15:09:51 +02:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
Type[] types = TypeArray<Composer1, Composer2, Composer3>();
|
2020-11-19 16:20:39 +00:00
|
|
|
var composers = new Composers(composition, types, Enumerable.Empty<Attribute>(), Mock.Of<ILogger<Composers>>());
|
2016-08-25 15:09:51 +02:00
|
|
|
Composed.Clear();
|
|
|
|
|
try
|
|
|
|
|
{
|
2016-12-15 13:15:49 +01:00
|
|
|
// 2 is Core and requires 4
|
|
|
|
|
// 4 is missing
|
|
|
|
|
// => throw
|
2019-02-14 10:39:27 +01:00
|
|
|
composers.Compose();
|
2016-08-25 15:09:51 +02:00
|
|
|
Assert.Fail("Expected exception.");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2021-02-10 14:58:22 +01:00
|
|
|
Assert.AreEqual("Broken composer dependency: Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Components.ComponentTests+Composer2 -> Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Components.ComponentTests+Composer4.", e.Message);
|
2016-08-25 15:09:51 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-15 13:15:49 +01:00
|
|
|
[Test]
|
|
|
|
|
public void BrokenRequired()
|
|
|
|
|
{
|
2020-12-20 08:36:11 +01:00
|
|
|
IServiceCollection register = MockRegister();
|
2020-11-20 11:48:32 +00:00
|
|
|
var composition = new UmbracoBuilder(register, Mock.Of<IConfiguration>(), TestHelper.GetMockedTypeLoader());
|
2016-12-15 13:15:49 +01:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
Type[] types = TypeArray<Composer2, Composer4, Composer13>();
|
2020-11-19 16:20:39 +00:00
|
|
|
var composers = new Composers(composition, types, Enumerable.Empty<Attribute>(), Mock.Of<ILogger<Composers>>());
|
2016-12-15 13:15:49 +01:00
|
|
|
Composed.Clear();
|
2020-12-20 08:36:11 +01:00
|
|
|
|
2016-12-15 13:15:49 +01:00
|
|
|
// 2 is Core and requires 4
|
|
|
|
|
// 13 is required by 1
|
|
|
|
|
// 1 is missing
|
|
|
|
|
// => reorder components accordingly
|
2019-02-14 10:39:27 +01:00
|
|
|
composers.Compose();
|
2019-01-03 21:00:28 +01:00
|
|
|
AssertTypeArray(TypeArray<Composer4, Composer2, Composer13>(), Composed);
|
2016-12-15 13:15:49 +01:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 15:09:51 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Initialize()
|
|
|
|
|
{
|
2019-01-07 09:30:47 +01:00
|
|
|
Composed.Clear();
|
|
|
|
|
Initialized.Clear();
|
|
|
|
|
Terminated.Clear();
|
|
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
IServiceCollection register = MockRegister();
|
|
|
|
|
TypeLoader typeLoader = MockTypeLoader();
|
|
|
|
|
IServiceProvider factory = MockFactory(m =>
|
2016-11-05 19:23:55 +01:00
|
|
|
{
|
2020-12-03 13:32:04 +00:00
|
|
|
m.Setup(x => x.GetService(It.Is<Type>(t => t == typeof(ISomeResource)))).Returns(() => new SomeResource());
|
2020-10-30 11:16:17 +00:00
|
|
|
m.Setup(x => x.GetService(It.IsAny<Type>())).Returns<Type>((type) =>
|
2019-01-03 21:00:28 +01:00
|
|
|
{
|
2020-12-03 13:32:04 +00:00
|
|
|
if (type == typeof(Composer1))
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
2020-12-03 13:32:04 +00:00
|
|
|
return new Composer1();
|
2020-12-20 08:36:11 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-03 13:32:04 +00:00
|
|
|
if (type == typeof(Composer5))
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
2020-12-03 13:32:04 +00:00
|
|
|
return new Composer5();
|
2020-12-20 08:36:11 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-03 13:32:04 +00:00
|
|
|
if (type == typeof(Composer5a))
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
2020-12-03 13:32:04 +00:00
|
|
|
return new Composer5a();
|
2020-12-20 08:36:11 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-03 13:32:04 +00:00
|
|
|
if (type == typeof(Component5))
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
2020-12-03 13:32:04 +00:00
|
|
|
return new Component5(new SomeResource());
|
2020-12-20 08:36:11 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-03 13:32:04 +00:00
|
|
|
if (type == typeof(Component5a))
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
2020-12-03 13:32:04 +00:00
|
|
|
return new Component5a();
|
2020-12-20 08:36:11 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-03 13:32:04 +00:00
|
|
|
if (type == typeof(IProfilingLogger))
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
2020-12-03 13:32:04 +00:00
|
|
|
return new ProfilingLogger(Mock.Of<ILogger<ProfilingLogger>>(), Mock.Of<IProfiler>());
|
2020-12-20 08:36:11 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-03 13:32:04 +00:00
|
|
|
if (type == typeof(ILogger<ComponentCollection>))
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
2020-12-03 13:32:04 +00:00
|
|
|
return Mock.Of<ILogger<ComponentCollection>>();
|
2020-12-20 08:36:11 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-03 21:00:28 +01:00
|
|
|
throw new NotSupportedException(type.FullName);
|
|
|
|
|
});
|
2016-11-05 19:23:55 +01:00
|
|
|
});
|
2020-11-20 11:48:32 +00:00
|
|
|
var composition = new UmbracoBuilder(register, Mock.Of<IConfiguration>(), TestHelper.GetMockedTypeLoader());
|
2016-08-25 15:09:51 +02:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
Type[] types = new[] { typeof(Composer1), typeof(Composer5), typeof(Composer5a) };
|
2020-11-19 16:20:39 +00:00
|
|
|
var composers = new Composers(composition, types, Enumerable.Empty<Attribute>(), Mock.Of<ILogger<Composers>>());
|
2019-01-07 09:30:47 +01:00
|
|
|
|
|
|
|
|
Assert.IsEmpty(Composed);
|
2019-01-03 21:00:28 +01:00
|
|
|
composers.Compose();
|
2019-02-14 10:39:27 +01:00
|
|
|
AssertTypeArray(TypeArray<Composer1, Composer5, Composer5a>(), Composed);
|
2019-01-07 09:30:47 +01:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
ComponentCollectionBuilder builder = composition.WithCollectionBuilder<ComponentCollectionBuilder>();
|
2020-10-30 11:16:17 +00:00
|
|
|
builder.RegisterWith(register);
|
2020-12-20 08:36:11 +01:00
|
|
|
ComponentCollection components = builder.CreateCollection(factory);
|
2019-01-07 09:30:47 +01:00
|
|
|
|
|
|
|
|
Assert.IsEmpty(Initialized);
|
|
|
|
|
components.Initialize();
|
2019-02-14 10:39:27 +01:00
|
|
|
AssertTypeArray(TypeArray<Component5, Component5a>(), Initialized);
|
2019-01-07 09:30:47 +01:00
|
|
|
|
|
|
|
|
Assert.IsEmpty(Terminated);
|
|
|
|
|
components.Terminate();
|
2019-02-14 10:39:27 +01:00
|
|
|
AssertTypeArray(TypeArray<Component5a, Component5>(), Terminated);
|
2016-08-25 15:09:51 +02:00
|
|
|
}
|
|
|
|
|
|
2016-08-31 18:25:18 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Requires1()
|
2016-08-25 15:09:51 +02:00
|
|
|
{
|
2020-12-20 08:36:11 +01:00
|
|
|
IServiceCollection register = MockRegister();
|
2020-11-20 11:48:32 +00:00
|
|
|
var composition = new UmbracoBuilder(register, Mock.Of<IConfiguration>(), TestHelper.GetMockedTypeLoader());
|
2016-08-31 18:25:18 +02:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
Type[] types = new[] { typeof(Composer6), typeof(Composer7), typeof(Composer8) };
|
2020-11-19 16:20:39 +00:00
|
|
|
var composers = new Composers(composition, types, Enumerable.Empty<Attribute>(), Mock.Of<ILogger<Composers>>());
|
2016-08-31 18:25:18 +02:00
|
|
|
Composed.Clear();
|
2019-02-14 10:39:27 +01:00
|
|
|
composers.Compose();
|
2016-08-31 18:25:18 +02:00
|
|
|
Assert.AreEqual(2, Composed.Count);
|
2019-01-03 21:00:28 +01:00
|
|
|
Assert.AreEqual(typeof(Composer6), Composed[0]);
|
|
|
|
|
Assert.AreEqual(typeof(Composer8), Composed[1]);
|
2016-08-25 15:09:51 +02:00
|
|
|
}
|
|
|
|
|
|
2016-08-31 18:25:18 +02:00
|
|
|
[Test]
|
2018-06-20 11:33:42 +02:00
|
|
|
public void Requires2A()
|
2016-08-25 15:09:51 +02:00
|
|
|
{
|
2020-12-20 08:36:11 +01:00
|
|
|
IServiceCollection register = MockRegister();
|
2020-11-20 11:48:32 +00:00
|
|
|
var composition = new UmbracoBuilder(register, Mock.Of<IConfiguration>(), TestHelper.GetMockedTypeLoader());
|
2016-08-31 18:25:18 +02:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
Type[] types = new[] { typeof(Composer9), typeof(Composer2), typeof(Composer4) };
|
2020-11-19 16:20:39 +00:00
|
|
|
var composers = new Composers(composition, types, Enumerable.Empty<Attribute>(), Mock.Of<ILogger<Composers>>());
|
2016-08-31 18:25:18 +02:00
|
|
|
Composed.Clear();
|
2019-02-14 10:39:27 +01:00
|
|
|
composers.Compose();
|
2020-11-17 07:56:04 +00:00
|
|
|
Assert.AreEqual(3, Composed.Count);
|
2019-01-03 21:00:28 +01:00
|
|
|
Assert.AreEqual(typeof(Composer4), Composed[0]);
|
|
|
|
|
Assert.AreEqual(typeof(Composer2), Composed[1]);
|
2018-06-20 11:33:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Requires2B()
|
|
|
|
|
{
|
2020-12-20 08:36:11 +01:00
|
|
|
IServiceCollection register = MockRegister();
|
|
|
|
|
TypeLoader typeLoader = MockTypeLoader();
|
|
|
|
|
IServiceProvider factory = MockFactory();
|
2020-11-20 11:48:32 +00:00
|
|
|
var composition = new UmbracoBuilder(register, Mock.Of<IConfiguration>(), TestHelper.GetMockedTypeLoader());
|
2018-06-20 11:33:42 +02:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
Type[] types = new[] { typeof(Composer9), typeof(Composer2), typeof(Composer4) };
|
2020-11-19 16:20:39 +00:00
|
|
|
var composers = new Composers(composition, types, Enumerable.Empty<Attribute>(), Mock.Of<ILogger<Composers>>());
|
2018-06-20 11:33:42 +02:00
|
|
|
Composed.Clear();
|
2019-01-03 21:00:28 +01:00
|
|
|
composers.Compose();
|
2020-12-20 08:36:11 +01:00
|
|
|
ComponentCollectionBuilder builder = composition.WithCollectionBuilder<ComponentCollectionBuilder>();
|
2020-10-30 11:16:17 +00:00
|
|
|
builder.RegisterWith(register);
|
2020-12-20 08:36:11 +01:00
|
|
|
ComponentCollection components = builder.CreateCollection(factory);
|
2016-08-31 18:25:18 +02:00
|
|
|
Assert.AreEqual(3, Composed.Count);
|
2019-01-03 21:00:28 +01:00
|
|
|
Assert.AreEqual(typeof(Composer4), Composed[0]);
|
|
|
|
|
Assert.AreEqual(typeof(Composer2), Composed[1]);
|
|
|
|
|
Assert.AreEqual(typeof(Composer9), Composed[2]);
|
2016-08-25 15:09:51 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-01 11:25:00 +02:00
|
|
|
[Test]
|
|
|
|
|
public void WeakDependencies()
|
|
|
|
|
{
|
2020-12-20 08:36:11 +01:00
|
|
|
IServiceCollection register = MockRegister();
|
2020-11-20 11:48:32 +00:00
|
|
|
var composition = new UmbracoBuilder(register, Mock.Of<IConfiguration>(), TestHelper.GetMockedTypeLoader());
|
2016-09-01 11:25:00 +02:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
Type[] types = new[] { typeof(Composer10) };
|
2020-11-19 16:20:39 +00:00
|
|
|
var composers = new Composers(composition, types, Enumerable.Empty<Attribute>(), Mock.Of<ILogger<Composers>>());
|
2016-09-01 11:25:00 +02:00
|
|
|
Composed.Clear();
|
2019-02-14 10:39:27 +01:00
|
|
|
composers.Compose();
|
2016-09-01 11:25:00 +02:00
|
|
|
Assert.AreEqual(1, Composed.Count);
|
2019-01-03 21:00:28 +01:00
|
|
|
Assert.AreEqual(typeof(Composer10), Composed[0]);
|
2016-09-01 11:25:00 +02:00
|
|
|
|
2019-01-03 21:00:28 +01:00
|
|
|
types = new[] { typeof(Composer11) };
|
2020-11-19 16:20:39 +00:00
|
|
|
composers = new Composers(composition, types, Enumerable.Empty<Attribute>(), Mock.Of<ILogger<Composers>>());
|
2016-09-01 11:25:00 +02:00
|
|
|
Composed.Clear();
|
2019-02-14 10:39:27 +01:00
|
|
|
Assert.Throws<Exception>(() => composers.Compose());
|
2019-04-05 19:00:34 +02:00
|
|
|
Console.WriteLine("throws:");
|
2020-11-19 16:20:39 +00:00
|
|
|
composers = new Composers(composition, types, Enumerable.Empty<Attribute>(), Mock.Of<ILogger<Composers>>());
|
2020-12-20 08:36:11 +01:00
|
|
|
Dictionary<Type, List<Type>> requirements = composers.GetRequirements(false);
|
2019-04-05 19:00:34 +02:00
|
|
|
Console.WriteLine(Composers.GetComposersReport(requirements));
|
2016-09-01 11:25:00 +02:00
|
|
|
|
2019-01-03 21:00:28 +01:00
|
|
|
types = new[] { typeof(Composer2) };
|
2020-11-19 16:20:39 +00:00
|
|
|
composers = new Composers(composition, types, Enumerable.Empty<Attribute>(), Mock.Of<ILogger<Composers>>());
|
2016-09-01 11:25:00 +02:00
|
|
|
Composed.Clear();
|
2019-02-14 10:39:27 +01:00
|
|
|
Assert.Throws<Exception>(() => composers.Compose());
|
2019-04-05 19:00:34 +02:00
|
|
|
Console.WriteLine("throws:");
|
2020-11-19 16:20:39 +00:00
|
|
|
composers = new Composers(composition, types, Enumerable.Empty<Attribute>(), Mock.Of<ILogger<Composers>>());
|
2019-04-05 19:00:34 +02:00
|
|
|
requirements = composers.GetRequirements(false);
|
|
|
|
|
Console.WriteLine(Composers.GetComposersReport(requirements));
|
2016-09-01 11:25:00 +02:00
|
|
|
|
2019-01-03 21:00:28 +01:00
|
|
|
types = new[] { typeof(Composer12) };
|
2020-11-19 16:20:39 +00:00
|
|
|
composers = new Composers(composition, types, Enumerable.Empty<Attribute>(), Mock.Of<ILogger<Composers>>());
|
2016-09-01 11:25:00 +02:00
|
|
|
Composed.Clear();
|
2019-02-14 10:39:27 +01:00
|
|
|
composers.Compose();
|
2016-09-01 11:25:00 +02:00
|
|
|
Assert.AreEqual(1, Composed.Count);
|
2019-01-03 21:00:28 +01:00
|
|
|
Assert.AreEqual(typeof(Composer12), Composed[0]);
|
2016-09-01 11:25:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void DisableMissing()
|
|
|
|
|
{
|
2020-12-20 08:36:11 +01:00
|
|
|
IServiceCollection register = MockRegister();
|
2020-11-20 11:48:32 +00:00
|
|
|
var composition = new UmbracoBuilder(register, Mock.Of<IConfiguration>(), TestHelper.GetMockedTypeLoader());
|
2016-09-01 11:25:00 +02:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
Type[] types = new[] { typeof(Composer6), typeof(Composer8) }; // 8 disables 7 which is not in the list
|
2020-11-19 16:20:39 +00:00
|
|
|
var composers = new Composers(composition, types, Enumerable.Empty<Attribute>(), Mock.Of<ILogger<Composers>>());
|
2016-09-01 11:25:00 +02:00
|
|
|
Composed.Clear();
|
2019-02-14 10:39:27 +01:00
|
|
|
composers.Compose();
|
2016-09-01 11:25:00 +02:00
|
|
|
Assert.AreEqual(2, Composed.Count);
|
2019-01-03 21:00:28 +01:00
|
|
|
Assert.AreEqual(typeof(Composer6), Composed[0]);
|
|
|
|
|
Assert.AreEqual(typeof(Composer8), Composed[1]);
|
2016-09-01 11:25:00 +02:00
|
|
|
}
|
|
|
|
|
|
2019-02-04 18:49:56 +01:00
|
|
|
[Test]
|
|
|
|
|
public void AttributesPriorities()
|
|
|
|
|
{
|
2020-12-20 08:36:11 +01:00
|
|
|
IServiceCollection register = MockRegister();
|
2020-11-20 11:48:32 +00:00
|
|
|
var composition = new UmbracoBuilder(register, Mock.Of<IConfiguration>(), TestHelper.GetMockedTypeLoader());
|
2019-02-04 18:49:56 +01:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
Type[] types = new[] { typeof(Composer26) };
|
|
|
|
|
DisableComposerAttribute[] enableDisableAttributes = new[] { new DisableComposerAttribute(typeof(Composer26)) };
|
2020-11-19 16:20:39 +00:00
|
|
|
var composers = new Composers(composition, types, enableDisableAttributes, Mock.Of<ILogger<Composers>>());
|
2019-02-04 18:49:56 +01:00
|
|
|
Composed.Clear();
|
2019-02-14 10:39:27 +01:00
|
|
|
composers.Compose();
|
2019-02-04 18:49:56 +01:00
|
|
|
Assert.AreEqual(0, Composed.Count); // 26 gone
|
|
|
|
|
|
|
|
|
|
types = new[] { typeof(Composer26), typeof(Composer27) }; // 26 disabled by assembly attribute, enabled by 27
|
2020-11-19 16:20:39 +00:00
|
|
|
composers = new Composers(composition, types, enableDisableAttributes, Mock.Of<ILogger<Composers>>());
|
2019-02-04 18:49:56 +01:00
|
|
|
Composed.Clear();
|
2019-02-14 10:39:27 +01:00
|
|
|
composers.Compose();
|
2019-02-04 18:49:56 +01:00
|
|
|
Assert.AreEqual(2, Composed.Count); // both
|
|
|
|
|
Assert.AreEqual(typeof(Composer26), Composed[0]);
|
|
|
|
|
Assert.AreEqual(typeof(Composer27), Composed[1]);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-05 19:00:34 +02:00
|
|
|
[Test]
|
|
|
|
|
public void AllComposers()
|
|
|
|
|
{
|
2020-12-20 08:36:11 +01:00
|
|
|
ITypeFinder typeFinder = TestHelper.GetTypeFinder();
|
2020-12-08 10:42:26 +11:00
|
|
|
var typeLoader = new TypeLoader(typeFinder, AppCaches.Disabled.RuntimeCache, new DirectoryInfo(TestHelper.GetHostingEnvironment().MapPathContentRoot(Constants.SystemDirectories.TempData)), Mock.Of<ILogger<TypeLoader>>(), Mock.Of<IProfilingLogger>());
|
2019-04-05 19:00:34 +02:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
IServiceCollection register = MockRegister();
|
2020-11-20 11:48:32 +00:00
|
|
|
var builder = new UmbracoBuilder(register, Mock.Of<IConfiguration>(), TestHelper.GetMockedTypeLoader());
|
2020-12-02 08:27:37 +01:00
|
|
|
|
2020-03-09 21:23:38 +11:00
|
|
|
var allComposers = typeLoader.GetTypes<IComposer>().ToList();
|
|
|
|
|
var types = allComposers.Where(x => x.FullName.StartsWith("Umbraco.Core.") || x.FullName.StartsWith("Umbraco.Web")).ToList();
|
2020-11-19 16:20:39 +00:00
|
|
|
var composers = new Composers(builder, types, Enumerable.Empty<Attribute>(), Mock.Of<ILogger<Composers>>());
|
2020-12-20 08:36:11 +01:00
|
|
|
Dictionary<Type, List<Type>> requirements = composers.GetRequirements();
|
|
|
|
|
string report = Composers.GetComposersReport(requirements);
|
2019-04-05 19:00:34 +02:00
|
|
|
Console.WriteLine(report);
|
2020-12-20 08:36:11 +01:00
|
|
|
IEnumerable<Type> composerTypes = composers.SortComposers(requirements);
|
2019-04-05 19:00:34 +02:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
foreach (Type type in composerTypes)
|
|
|
|
|
{
|
2019-04-05 19:00:34 +02:00
|
|
|
Console.WriteLine(type);
|
2020-12-20 08:36:11 +01:00
|
|
|
}
|
2019-04-05 19:00:34 +02:00
|
|
|
}
|
|
|
|
|
|
2019-01-03 21:00:28 +01:00
|
|
|
public class TestComposerBase : IComposer
|
2016-08-25 15:09:51 +02:00
|
|
|
{
|
2020-12-20 08:36:11 +01:00
|
|
|
public virtual void Compose(IUmbracoBuilder builder) => Composed.Add(GetType());
|
2016-08-25 15:09:51 +02:00
|
|
|
}
|
|
|
|
|
|
2019-01-03 21:00:28 +01:00
|
|
|
public class Composer1 : TestComposerBase
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
|
|
|
|
}
|
2016-08-31 18:25:18 +02:00
|
|
|
|
2019-01-04 10:29:29 +01:00
|
|
|
[ComposeAfter(typeof(Composer4))]
|
2019-01-03 21:00:28 +01:00
|
|
|
public class Composer2 : TestComposerBase, ICoreComposer
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
|
|
|
|
}
|
2016-08-25 15:09:51 +02:00
|
|
|
|
2019-01-03 21:00:28 +01:00
|
|
|
public class Composer3 : TestComposerBase, IUserComposer
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
|
|
|
|
}
|
2016-08-31 18:25:18 +02:00
|
|
|
|
2019-01-03 21:00:28 +01:00
|
|
|
public class Composer4 : TestComposerBase
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
|
|
|
|
}
|
2019-01-03 21:00:28 +01:00
|
|
|
|
|
|
|
|
public class Composer5 : TestComposerBase
|
|
|
|
|
{
|
2020-11-21 15:43:01 +00:00
|
|
|
public override void Compose(IUmbracoBuilder builder)
|
2019-01-03 21:00:28 +01:00
|
|
|
{
|
2020-11-21 15:43:01 +00:00
|
|
|
base.Compose(builder);
|
|
|
|
|
builder.Components().Append<Component5>();
|
2019-01-03 21:00:28 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-14 10:39:27 +01:00
|
|
|
[ComposeAfter(typeof(Composer5))]
|
|
|
|
|
public class Composer5a : TestComposerBase
|
|
|
|
|
{
|
2020-11-18 17:40:23 +00:00
|
|
|
public override void Compose(IUmbracoBuilder builder)
|
2019-02-14 10:39:27 +01:00
|
|
|
{
|
2020-11-18 17:40:23 +00:00
|
|
|
base.Compose(builder);
|
|
|
|
|
builder.Components().Append<Component5a>();
|
2019-02-14 10:39:27 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-07 09:30:47 +01:00
|
|
|
public class TestComponentBase : IComponent
|
2016-08-31 18:25:18 +02:00
|
|
|
{
|
2020-12-20 08:36:11 +01:00
|
|
|
public virtual void Initialize() => Initialized.Add(GetType());
|
2019-01-07 09:30:47 +01:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
public virtual void Terminate() => Terminated.Add(GetType());
|
2019-01-07 09:30:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class Component5 : TestComponentBase
|
|
|
|
|
{
|
|
|
|
|
private readonly ISomeResource _resource;
|
|
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
public Component5(ISomeResource resource) => _resource = resource;
|
2016-08-25 15:09:51 +02:00
|
|
|
}
|
|
|
|
|
|
2019-02-14 10:39:27 +01:00
|
|
|
public class Component5a : TestComponentBase
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
|
|
|
|
}
|
2019-02-14 10:39:27 +01:00
|
|
|
|
2019-01-03 21:00:28 +01:00
|
|
|
[Disable]
|
|
|
|
|
public class Composer6 : TestComposerBase
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
|
|
|
|
}
|
2016-08-31 18:25:18 +02:00
|
|
|
|
2019-01-03 21:00:28 +01:00
|
|
|
public class Composer7 : TestComposerBase
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
|
|
|
|
}
|
2016-08-31 18:25:18 +02:00
|
|
|
|
2019-01-03 21:00:28 +01:00
|
|
|
[Disable(typeof(Composer7))]
|
|
|
|
|
[Enable(typeof(Composer6))]
|
|
|
|
|
public class Composer8 : TestComposerBase
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
|
|
|
|
}
|
2016-08-31 18:25:18 +02:00
|
|
|
|
2019-01-03 21:00:28 +01:00
|
|
|
public interface ITestComposer : IUserComposer
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
|
|
|
|
}
|
2016-08-31 18:25:18 +02:00
|
|
|
|
2019-01-03 21:00:28 +01:00
|
|
|
public class Composer9 : TestComposerBase, ITestComposer
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
|
|
|
|
}
|
2016-08-31 18:25:18 +02:00
|
|
|
|
2019-01-04 10:29:29 +01:00
|
|
|
[ComposeAfter(typeof(ITestComposer))]
|
2019-01-03 21:00:28 +01:00
|
|
|
public class Composer10 : TestComposerBase
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
|
|
|
|
}
|
2016-09-01 11:25:00 +02:00
|
|
|
|
2019-01-04 10:29:29 +01:00
|
|
|
[ComposeAfter(typeof(ITestComposer), false)]
|
2019-01-03 21:00:28 +01:00
|
|
|
public class Composer11 : TestComposerBase
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
|
|
|
|
}
|
2016-09-01 11:25:00 +02:00
|
|
|
|
2019-01-04 10:29:29 +01:00
|
|
|
[ComposeAfter(typeof(Composer4), true)]
|
2019-01-03 21:00:28 +01:00
|
|
|
public class Composer12 : TestComposerBase, ICoreComposer
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
|
|
|
|
}
|
2016-09-01 11:25:00 +02:00
|
|
|
|
2019-01-04 10:29:29 +01:00
|
|
|
[ComposeBefore(typeof(Composer1))]
|
2019-01-03 21:00:28 +01:00
|
|
|
public class Composer13 : TestComposerBase
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
|
|
|
|
}
|
2016-12-15 13:15:49 +01:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
public interface ISomeResource
|
|
|
|
|
{
|
|
|
|
|
}
|
2016-08-25 15:09:51 +02:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
public class SomeResource : ISomeResource
|
|
|
|
|
{
|
|
|
|
|
}
|
2016-12-15 13:15:49 +01:00
|
|
|
|
2019-01-03 21:00:28 +01:00
|
|
|
public class Composer20 : TestComposerBase
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
|
|
|
|
}
|
2016-12-15 13:15:49 +01:00
|
|
|
|
2019-01-04 10:29:29 +01:00
|
|
|
[ComposeBefore(typeof(Composer20))]
|
2019-01-03 21:00:28 +01:00
|
|
|
public class Composer21 : TestComposerBase
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
|
|
|
|
}
|
2016-12-15 13:15:49 +01:00
|
|
|
|
2019-01-03 21:00:28 +01:00
|
|
|
public class Composer22 : TestComposerBase
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
|
|
|
|
}
|
2016-12-15 13:15:49 +01:00
|
|
|
|
2019-01-04 10:29:29 +01:00
|
|
|
[ComposeAfter(typeof(Composer22))]
|
2019-01-03 21:00:28 +01:00
|
|
|
public interface IComposer23 : IComposer
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
|
|
|
|
}
|
2016-12-15 13:15:49 +01:00
|
|
|
|
2019-01-03 21:00:28 +01:00
|
|
|
public class Composer24 : TestComposerBase, IComposer23
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
|
|
|
|
}
|
2016-12-15 13:15:49 +01:00
|
|
|
|
|
|
|
|
// should insert itself between 22 and anything i23
|
2019-01-04 10:29:29 +01:00
|
|
|
[ComposeBefore(typeof(IComposer23))]
|
2020-12-20 08:36:11 +01:00
|
|
|
////[RequireComponent(typeof(Component22))] - not needed, implement i23
|
2019-01-03 21:00:28 +01:00
|
|
|
public class Composer25 : TestComposerBase, IComposer23
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
|
|
|
|
}
|
2016-12-15 13:15:49 +01:00
|
|
|
|
2019-02-04 18:49:56 +01:00
|
|
|
public class Composer26 : TestComposerBase
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
|
|
|
|
}
|
2019-02-04 18:49:56 +01:00
|
|
|
|
|
|
|
|
[Enable(typeof(Composer26))]
|
|
|
|
|
public class Composer27 : TestComposerBase
|
2016-12-15 13:15:49 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
// FIXME: move to Testing
|
|
|
|
|
private static Type[] TypeArray<T1>() => new[] { typeof(T1) };
|
2016-12-15 13:15:49 +01:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
private static Type[] TypeArray<T1, T2>() => new[] { typeof(T1), typeof(T2) };
|
2016-12-15 13:15:49 +01:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
private static Type[] TypeArray<T1, T2, T3>() => new[] { typeof(T1), typeof(T2), typeof(T3) };
|
2016-12-15 13:15:49 +01:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
private static Type[] TypeArray<T1, T2, T3, T4>() => new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4) };
|
2016-12-15 13:15:49 +01:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
private static Type[] TypeArray<T1, T2, T3, T4, T5>() => new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5) };
|
2016-12-15 13:15:49 +01:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
private static Type[] TypeArray<T1, T2, T3, T4, T5, T6>() => new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6) };
|
2016-12-15 13:15:49 +01:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
private static Type[] TypeArray<T1, T2, T3, T4, T5, T6, T7>() => new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7) };
|
|
|
|
|
|
|
|
|
|
private static Type[] TypeArray<T1, T2, T3, T4, T5, T6, T7, T8>() => new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8) };
|
2016-12-15 13:15:49 +01:00
|
|
|
|
|
|
|
|
private static void AssertTypeArray(IReadOnlyList<Type> expected, IReadOnlyList<Type> test)
|
|
|
|
|
{
|
|
|
|
|
Assert.AreEqual(expected.Count, test.Count);
|
2020-12-20 08:36:11 +01:00
|
|
|
for (int i = 0; i < expected.Count; i++)
|
|
|
|
|
{
|
2016-12-15 13:15:49 +01:00
|
|
|
Assert.AreEqual(expected[i], test[i]);
|
2020-12-20 08:36:11 +01:00
|
|
|
}
|
2016-12-15 13:15:49 +01:00
|
|
|
}
|
2016-08-25 15:09:51 +02:00
|
|
|
}
|
|
|
|
|
}
|