Cleanup
This commit is contained in:
@@ -25,9 +25,7 @@ namespace Umbraco.Core.Composing
|
||||
{
|
||||
Type type;
|
||||
|
||||
// fixme naming / container?
|
||||
|
||||
var configuredTypeName = ConfigurationManager.AppSettings["umbracoContainerType"];
|
||||
var configuredTypeName = ConfigurationManager.AppSettings["umbracoRegisterType"];
|
||||
if (configuredTypeName.IsNullOrWhiteSpace())
|
||||
{
|
||||
// try to get the web LightInject container type,
|
||||
@@ -37,20 +35,20 @@ namespace Umbraco.Core.Composing
|
||||
}
|
||||
else
|
||||
{
|
||||
// try to get the configured container type
|
||||
// try to get the configured type
|
||||
type = Type.GetType(configuredTypeName);
|
||||
}
|
||||
|
||||
if (type == null)
|
||||
throw new Exception($"Cannot find container factory class '{configuredTypeName}'.");
|
||||
throw new Exception($"Cannot find register factory class '{configuredTypeName}'.");
|
||||
|
||||
var factoryMethod = type.GetMethod("Create", BindingFlags.Public | BindingFlags.Static);
|
||||
if (factoryMethod == null)
|
||||
throw new Exception($"Container factory class '{configuredTypeName}' does not have a public static method named Create.");
|
||||
throw new Exception($"Register factory class '{configuredTypeName}' does not have a public static method named Create.");
|
||||
|
||||
var container = factoryMethod.Invoke(null, Array.Empty<object>()) as IRegister;
|
||||
if (container == null)
|
||||
throw new Exception($"Container factory '{configuredTypeName}' did not return an IRegister implementation.");
|
||||
throw new Exception($"Register factory '{configuredTypeName}' did not return an IRegister implementation.");
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace Umbraco.Core.Runtime
|
||||
composition.RegisterSingleton<PropertyEditorCollection>();
|
||||
composition.RegisterSingleton<ParameterEditorCollection>();
|
||||
|
||||
// register a server registrar, by default it's the db registrar
|
||||
// register a server registrar, by default it's the db registrar
|
||||
composition.RegisterSingleton<IServerRegistrar>(f =>
|
||||
{
|
||||
if ("true".InvariantEquals(ConfigurationManager.AppSettings["umbracoDisableElectionForSingleServer"]))
|
||||
|
||||
@@ -7,7 +7,6 @@ using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Components;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Sync;
|
||||
|
||||
@@ -25,7 +24,7 @@ namespace Umbraco.Tests.Cache.DistributedCache
|
||||
public void Setup()
|
||||
{
|
||||
var register = RegisterFactory.Create();
|
||||
Current.Factory = register.CreateFactory(); // fixme only for LightInject
|
||||
|
||||
var composition = new Composition(register, new TypeLoader(), Mock.Of<IProfilingLogger>(), RuntimeLevel.Run);
|
||||
|
||||
register.Register<IServerRegistrar>(_ => new TestServerRegistrar());
|
||||
@@ -34,6 +33,8 @@ namespace Umbraco.Tests.Cache.DistributedCache
|
||||
composition.GetCollectionBuilder<CacheRefresherCollectionBuilder>()
|
||||
.Add<TestCacheRefresher>();
|
||||
|
||||
Current.Factory = register.CreateFactory();
|
||||
|
||||
_distributedCache = new Umbraco.Web.Cache.DistributedCache();
|
||||
}
|
||||
|
||||
|
||||
@@ -4,16 +4,13 @@ using System.Linq;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Components;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Mappers;
|
||||
using Umbraco.Core.Scoping;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
|
||||
namespace Umbraco.Tests.Components
|
||||
{
|
||||
@@ -53,8 +50,6 @@ namespace Umbraco.Tests.Components
|
||||
return new TypeLoader();
|
||||
}
|
||||
|
||||
// fixme should we have Composition.Logger, which would be a profiling logger too?
|
||||
|
||||
[Test]
|
||||
public void Boot1A()
|
||||
{
|
||||
|
||||
@@ -13,8 +13,6 @@ namespace Umbraco.Tests.Composing
|
||||
[TestFixture]
|
||||
public class CollectionBuildersTests
|
||||
{
|
||||
private IRegister _register;
|
||||
private IFactory _factory;
|
||||
private Composition _composition;
|
||||
|
||||
[SetUp]
|
||||
@@ -22,19 +20,14 @@ namespace Umbraco.Tests.Composing
|
||||
{
|
||||
Current.Reset();
|
||||
|
||||
_register = RegisterFactory.Create();
|
||||
_factory = _register.CreateFactory(); // fixme only works w/LightInject - would require we reorg tests!
|
||||
Current.Factory = _factory;
|
||||
_composition = new Composition(_register, new TypeLoader(), Mock.Of<IProfilingLogger>(), RuntimeLevel.Run);
|
||||
var register = RegisterFactory.Create();
|
||||
_composition = new Composition(register, new TypeLoader(), Mock.Of<IProfilingLogger>(), RuntimeLevel.Run);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
Current.Reset();
|
||||
|
||||
_register.DisposeIfDisposable();
|
||||
_register = null;
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -49,7 +42,8 @@ namespace Umbraco.Tests.Composing
|
||||
Assert.IsFalse(builder.Has<Resolved3>());
|
||||
//Assert.IsFalse(col.ContainsType<Resolved4>()); // does not compile
|
||||
|
||||
var col = builder.CreateCollection(_factory);
|
||||
var factory = _composition.CreateFactory();
|
||||
var col = builder.CreateCollection(factory);
|
||||
AssertCollection(col, typeof(Resolved1), typeof(Resolved2));
|
||||
}
|
||||
|
||||
@@ -64,7 +58,8 @@ namespace Umbraco.Tests.Composing
|
||||
Assert.IsFalse(builder.Has<Resolved1>());
|
||||
Assert.IsFalse(builder.Has<Resolved2>());
|
||||
|
||||
var col = builder.CreateCollection(_factory);
|
||||
var factory = _composition.CreateFactory();
|
||||
var col = builder.CreateCollection(factory);
|
||||
AssertCollection(col);
|
||||
}
|
||||
|
||||
@@ -75,7 +70,8 @@ namespace Umbraco.Tests.Composing
|
||||
.Append<Resolved1>()
|
||||
.Append<Resolved2>();
|
||||
|
||||
var col = builder.CreateCollection(_factory);
|
||||
var factory = _composition.CreateFactory();
|
||||
var col = builder.CreateCollection(factory);
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() => builder.Clear());
|
||||
}
|
||||
@@ -91,7 +87,8 @@ namespace Umbraco.Tests.Composing
|
||||
Assert.IsTrue(builder.Has<Resolved2>());
|
||||
Assert.IsFalse(builder.Has<Resolved3>());
|
||||
|
||||
var col = builder.CreateCollection(_factory);
|
||||
var factory = _composition.CreateFactory();
|
||||
var col = builder.CreateCollection(factory);
|
||||
AssertCollection(col, typeof(Resolved1), typeof(Resolved2));
|
||||
}
|
||||
|
||||
@@ -100,7 +97,8 @@ namespace Umbraco.Tests.Composing
|
||||
{
|
||||
var builder = _composition.GetCollectionBuilder<TestCollectionBuilder>();
|
||||
|
||||
var col = builder.CreateCollection(_factory);
|
||||
var factory = _composition.CreateFactory();
|
||||
var col = builder.CreateCollection(factory);
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
builder.Append<Resolved1>()
|
||||
@@ -114,7 +112,9 @@ namespace Umbraco.Tests.Composing
|
||||
builder.Append<Resolved1>();
|
||||
builder.Append<Resolved1>();
|
||||
|
||||
var col = builder.CreateCollection(_factory);
|
||||
var factory = _composition.CreateFactory();
|
||||
|
||||
var col = builder.CreateCollection(factory);
|
||||
AssertCollection(col, typeof(Resolved1));
|
||||
}
|
||||
|
||||
@@ -122,6 +122,7 @@ namespace Umbraco.Tests.Composing
|
||||
public void CannotAppendInvalidTypeToBUilder()
|
||||
{
|
||||
var builder = _composition.GetCollectionBuilder<TestCollectionBuilder>();
|
||||
|
||||
//builder.Append<Resolved4>(); // does not compile
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
builder.Append(new[] { typeof (Resolved4) }) // throws
|
||||
@@ -140,7 +141,8 @@ namespace Umbraco.Tests.Composing
|
||||
Assert.IsFalse(builder.Has<Resolved2>());
|
||||
Assert.IsFalse(builder.Has<Resolved3>());
|
||||
|
||||
var col = builder.CreateCollection(_factory);
|
||||
var factory = _composition.CreateFactory();
|
||||
var col = builder.CreateCollection(factory);
|
||||
AssertCollection(col, typeof(Resolved1));
|
||||
}
|
||||
|
||||
@@ -152,7 +154,8 @@ namespace Umbraco.Tests.Composing
|
||||
.Append<Resolved2>()
|
||||
.Remove<Resolved3>();
|
||||
|
||||
var col = builder.CreateCollection(_factory);
|
||||
var factory = _composition.CreateFactory();
|
||||
var col = builder.CreateCollection(factory);
|
||||
AssertCollection(col, typeof(Resolved1), typeof(Resolved2));
|
||||
}
|
||||
|
||||
@@ -163,7 +166,8 @@ namespace Umbraco.Tests.Composing
|
||||
.Append<Resolved1>()
|
||||
.Append<Resolved2>();
|
||||
|
||||
var col = builder.CreateCollection(_factory);
|
||||
var factory = _composition.CreateFactory();
|
||||
var col = builder.CreateCollection(factory);
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
builder.Remove<Resolved2>() // throws
|
||||
);
|
||||
@@ -181,7 +185,8 @@ namespace Umbraco.Tests.Composing
|
||||
Assert.IsTrue(builder.Has<Resolved2>());
|
||||
Assert.IsTrue(builder.Has<Resolved3>());
|
||||
|
||||
var col = builder.CreateCollection(_factory);
|
||||
var factory = _composition.CreateFactory();
|
||||
var col = builder.CreateCollection(factory);
|
||||
AssertCollection(col, typeof(Resolved3), typeof(Resolved1), typeof(Resolved2));
|
||||
}
|
||||
|
||||
@@ -192,7 +197,8 @@ namespace Umbraco.Tests.Composing
|
||||
.Append<Resolved1>()
|
||||
.Append<Resolved2>();
|
||||
|
||||
var col = builder.CreateCollection(_factory);
|
||||
var factory = _composition.CreateFactory();
|
||||
var col = builder.CreateCollection(factory);
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
builder.Insert<Resolved3>() // throws
|
||||
);
|
||||
@@ -206,7 +212,8 @@ namespace Umbraco.Tests.Composing
|
||||
.Append<Resolved2>()
|
||||
.Insert<Resolved2>();
|
||||
|
||||
var col = builder.CreateCollection(_factory);
|
||||
var factory = _composition.CreateFactory();
|
||||
var col = builder.CreateCollection(factory);
|
||||
AssertCollection(col, typeof(Resolved2), typeof(Resolved1));
|
||||
}
|
||||
|
||||
@@ -216,7 +223,8 @@ namespace Umbraco.Tests.Composing
|
||||
var builder = _composition.GetCollectionBuilder<TestCollectionBuilder>();
|
||||
builder.Insert<Resolved2>();
|
||||
|
||||
var col = builder.CreateCollection(_factory);
|
||||
var factory = _composition.CreateFactory();
|
||||
var col = builder.CreateCollection(factory);
|
||||
AssertCollection(col, typeof(Resolved2));
|
||||
}
|
||||
|
||||
@@ -248,7 +256,8 @@ namespace Umbraco.Tests.Composing
|
||||
Assert.IsTrue(builder.Has<Resolved2>());
|
||||
Assert.IsTrue(builder.Has<Resolved3>());
|
||||
|
||||
var col = builder.CreateCollection(_factory);
|
||||
var factory = _composition.CreateFactory();
|
||||
var col = builder.CreateCollection(factory);
|
||||
AssertCollection(col, typeof(Resolved1), typeof(Resolved3), typeof(Resolved2));
|
||||
}
|
||||
|
||||
@@ -259,7 +268,8 @@ namespace Umbraco.Tests.Composing
|
||||
.Append<Resolved1>()
|
||||
.Append<Resolved2>();
|
||||
|
||||
var col = builder.CreateCollection(_factory);
|
||||
var factory = _composition.CreateFactory();
|
||||
var col = builder.CreateCollection(factory);
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
builder.InsertBefore<Resolved2, Resolved3>()
|
||||
);
|
||||
@@ -273,7 +283,8 @@ namespace Umbraco.Tests.Composing
|
||||
.Append<Resolved2>()
|
||||
.InsertBefore<Resolved1, Resolved2>();
|
||||
|
||||
var col = builder.CreateCollection(_factory);
|
||||
var factory = _composition.CreateFactory();
|
||||
var col = builder.CreateCollection(factory);
|
||||
AssertCollection(col, typeof(Resolved2), typeof(Resolved1));
|
||||
}
|
||||
|
||||
@@ -299,10 +310,12 @@ namespace Umbraco.Tests.Composing
|
||||
// but the container manages the scope, so to test the scope
|
||||
// the collection must come from the container
|
||||
|
||||
var col1 = _factory.GetInstance<TestCollection>();
|
||||
var factory = _composition.CreateFactory();
|
||||
|
||||
var col1 = factory.GetInstance<TestCollection>();
|
||||
AssertCollection(col1, typeof(Resolved1), typeof(Resolved2));
|
||||
|
||||
var col2 = _factory.GetInstance<TestCollection>();
|
||||
var col2 = factory.GetInstance<TestCollection>();
|
||||
AssertCollection(col2, typeof(Resolved1), typeof(Resolved2));
|
||||
|
||||
AssertSameCollection(col1, col2);
|
||||
@@ -319,10 +332,12 @@ namespace Umbraco.Tests.Composing
|
||||
// but the container manages the scope, so to test the scope
|
||||
// the collection must come from the container
|
||||
|
||||
var col1 = _factory.GetInstance<TestCollection>();
|
||||
var factory = _composition.CreateFactory();
|
||||
|
||||
var col1 = factory.GetInstance<TestCollection>();
|
||||
AssertCollection(col1, typeof(Resolved1), typeof(Resolved2));
|
||||
|
||||
var col2 = _factory.GetInstance<TestCollection>();
|
||||
var col2 = factory.GetInstance<TestCollection>();
|
||||
AssertCollection(col1, typeof(Resolved1), typeof(Resolved2));
|
||||
|
||||
AssertNotSameCollection(col1, col2);
|
||||
@@ -336,7 +351,8 @@ namespace Umbraco.Tests.Composing
|
||||
.Insert<Resolved1>()
|
||||
.InsertBefore<Resolved3, Resolved2>();
|
||||
|
||||
var col1 = builder.CreateCollection(_factory);
|
||||
var factory = _composition.CreateFactory();
|
||||
var col1 = builder.CreateCollection(factory);
|
||||
AssertCollection(col1, typeof(Resolved1), typeof(Resolved2), typeof(Resolved3));
|
||||
}
|
||||
|
||||
@@ -353,10 +369,12 @@ namespace Umbraco.Tests.Composing
|
||||
|
||||
TestCollection col1A, col1B;
|
||||
|
||||
using (_factory.BeginScope())
|
||||
var factory = _composition.CreateFactory();
|
||||
|
||||
using (factory.BeginScope())
|
||||
{
|
||||
col1A = _factory.GetInstance<TestCollection>();
|
||||
col1B = _factory.GetInstance<TestCollection>();
|
||||
col1A = factory.GetInstance<TestCollection>();
|
||||
col1B = factory.GetInstance<TestCollection>();
|
||||
}
|
||||
|
||||
AssertCollection(col1A, typeof(Resolved1), typeof(Resolved2));
|
||||
@@ -365,9 +383,9 @@ namespace Umbraco.Tests.Composing
|
||||
|
||||
TestCollection col2;
|
||||
|
||||
using (_factory.BeginScope())
|
||||
using (factory.BeginScope())
|
||||
{
|
||||
col2 = _factory.GetInstance<TestCollection>();
|
||||
col2 = factory.GetInstance<TestCollection>();
|
||||
}
|
||||
|
||||
AssertCollection(col2, typeof(Resolved1), typeof(Resolved2));
|
||||
@@ -381,7 +399,8 @@ namespace Umbraco.Tests.Composing
|
||||
.Add<Resolved1>()
|
||||
.Add<Resolved2>();
|
||||
|
||||
var col = builder.CreateCollection(_factory);
|
||||
var factory = _composition.CreateFactory();
|
||||
var col = builder.CreateCollection(factory);
|
||||
AssertCollection(col, typeof(Resolved2), typeof(Resolved1));
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ using Umbraco.Core.Composing.LightInject;
|
||||
namespace Umbraco.Tests.Composing
|
||||
{
|
||||
[TestFixture]
|
||||
public class ContainerTests
|
||||
public class ContainerConfirmingTests
|
||||
{
|
||||
// tests that a container conforms
|
||||
|
||||
@@ -212,12 +212,61 @@ namespace Umbraco.Tests.Composing
|
||||
Assert.AreEqual(2, things. Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanRegisterSingletonInterface()
|
||||
{
|
||||
var register = GetRegister();
|
||||
register.RegisterSingleton<IThing, Thing1>();
|
||||
var factory = register.CreateFactory();
|
||||
var s1 = factory.GetInstance<IThing>();
|
||||
var s2 = factory.GetInstance<IThing>();
|
||||
Assert.AreSame(s1, s2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanRegisterSingletonClass()
|
||||
{
|
||||
var register = GetRegister();
|
||||
register.RegisterSingleton<Thing1>();
|
||||
var factory = register.CreateFactory();
|
||||
var s1 = factory.GetInstance<Thing1>();
|
||||
var s2 = factory.GetInstance<Thing1>();
|
||||
Assert.AreSame(s1, s2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanReRegisterSingletonInterface()
|
||||
{
|
||||
var register = GetRegister();
|
||||
register.RegisterSingleton<IThing, Thing1>();
|
||||
register.RegisterSingleton<IThing, Thing2>();
|
||||
var factory = register.CreateFactory();
|
||||
var s = factory.GetInstance<IThing>();
|
||||
Assert.IsInstanceOf<Thing2>(s);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanRegisterSingletonWithCreate()
|
||||
{
|
||||
var register = GetRegister();
|
||||
register.RegisterSingleton(c => c.CreateInstance<Thing3>(new Thing1()));
|
||||
var factory = register.CreateFactory();
|
||||
var s1 = factory.GetInstance<Thing3>();
|
||||
var s2 = factory.GetInstance<Thing3>();
|
||||
Assert.AreSame(s1, s2);
|
||||
}
|
||||
|
||||
public interface IThing { }
|
||||
|
||||
public abstract class ThingBase : IThing { }
|
||||
public class Thing1 : ThingBase { }
|
||||
public class Thing2 : ThingBase { }
|
||||
|
||||
public class Thing3 : ThingBase
|
||||
{
|
||||
public Thing3(Thing1 thing) { }
|
||||
}
|
||||
|
||||
public class NeedThings
|
||||
{
|
||||
public NeedThings(IEnumerable<ThingBase> things)
|
||||
@@ -1,71 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Composing;
|
||||
|
||||
namespace Umbraco.Tests.Composing
|
||||
{
|
||||
// TODO
|
||||
// this class should contain everything to ensure that a container implementation
|
||||
// complies with Umbraco's requirements.
|
||||
|
||||
[TestFixture]
|
||||
public class ContainerImplementationTests // FIXME merge into ContainerTests or ContainerConformingTests
|
||||
{
|
||||
private IRegister CreateRegister() => RegisterFactory.Create();
|
||||
|
||||
[Test]
|
||||
public void CanRegisterSingletonInterface()
|
||||
{
|
||||
var register = CreateRegister();
|
||||
register.RegisterSingleton<ITestInterface, TestClass1>();
|
||||
var factory = register.CreateFactory();
|
||||
var s1 = factory.GetInstance<ITestInterface>();
|
||||
var s2 = factory.GetInstance<ITestInterface>();
|
||||
Assert.AreSame(s1, s2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanRegisterSingletonClass()
|
||||
{
|
||||
var register = CreateRegister();
|
||||
register.RegisterSingleton<TestClass1>();
|
||||
var factory = register.CreateFactory();
|
||||
var s1 = factory.GetInstance<TestClass1>();
|
||||
var s2 = factory.GetInstance<TestClass1>();
|
||||
Assert.AreSame(s1, s2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanReRegisterSingletonInterface()
|
||||
{
|
||||
var register = CreateRegister();
|
||||
register.RegisterSingleton<ITestInterface, TestClass1>();
|
||||
register.RegisterSingleton<ITestInterface, TestClass2>();
|
||||
var factory = register.CreateFactory();
|
||||
var s = factory.GetInstance<ITestInterface>();
|
||||
Assert.IsInstanceOf<TestClass2>(s);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanRegisterSingletonWithCreate()
|
||||
{
|
||||
var register = CreateRegister();
|
||||
register.RegisterSingleton(c => c.CreateInstance<TestClass3>(new TestClass1()));
|
||||
var factory = register.CreateFactory();
|
||||
var s1 = factory.GetInstance<TestClass3>();
|
||||
var s2 = factory.GetInstance<TestClass3>();
|
||||
Assert.AreSame(s1, s2);
|
||||
}
|
||||
|
||||
public interface ITestInterface{}
|
||||
|
||||
public class TestClass1 : ITestInterface{}
|
||||
|
||||
public class TestClass2 : ITestInterface{}
|
||||
|
||||
public class TestClass3
|
||||
{
|
||||
public TestClass3(TestClass1 c) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,18 +18,20 @@ namespace Umbraco.Tests.Composing
|
||||
public void PackageActionCollectionBuilderWorks()
|
||||
{
|
||||
var container = RegisterFactory.Create();
|
||||
Current.Factory = container.CreateFactory(); // fixme only for LightInject
|
||||
|
||||
var composition = new Composition(container, new TypeLoader(), Mock.Of<IProfilingLogger>(), RuntimeLevel.Run);
|
||||
|
||||
composition.GetCollectionBuilder<PackageActionCollectionBuilder>()
|
||||
.Add(() => TypeLoader.GetPackageActions());
|
||||
|
||||
Current.Factory = container.CreateFactory();
|
||||
|
||||
var actions = Current.PackageActions;
|
||||
Assert.AreEqual(2, actions.Count());
|
||||
|
||||
// order is unspecified, but both must be there
|
||||
bool hasAction1 = actions.ElementAt(0) is PackageAction1 || actions.ElementAt(1) is PackageAction1;
|
||||
bool hasAction2 = actions.ElementAt(0) is PackageAction2 || actions.ElementAt(1) is PackageAction2;
|
||||
var hasAction1 = actions.ElementAt(0) is PackageAction1 || actions.ElementAt(1) is PackageAction1;
|
||||
var hasAction2 = actions.ElementAt(0) is PackageAction2 || actions.ElementAt(1) is PackageAction2;
|
||||
Assert.IsTrue(hasAction1);
|
||||
Assert.IsTrue(hasAction2);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace Umbraco.Tests.TestHelpers
|
||||
/// <returns>A ServiceContext.</returns>
|
||||
public ServiceContext GetServiceContextMock(IFactory container = null)
|
||||
{
|
||||
// fixme - else tests break - something's wrong
|
||||
// fixme - else some tests break - figure it out
|
||||
container = null;
|
||||
|
||||
return new ServiceContext(
|
||||
|
||||
@@ -120,7 +120,8 @@ namespace Umbraco.Tests.Testing
|
||||
// get/merge the attributes marking the method and/or the classes
|
||||
Options = TestOptionAttributeBase.GetTestOptions<UmbracoTestAttribute>();
|
||||
|
||||
// fixme see CoreRuntime and align!
|
||||
// fixme - align to runtimes & components - don't redo everything here
|
||||
|
||||
var (logger, profiler) = GetLoggers(Options.Logger);
|
||||
var proflogger = new ProfilingLogger(logger, profiler);
|
||||
var cacheHelper = GetCacheHelper();
|
||||
@@ -203,8 +204,6 @@ namespace Umbraco.Tests.Testing
|
||||
|
||||
protected virtual void ComposeWeb()
|
||||
{
|
||||
//TODO: Should we 'just' register the WebRuntimeComponent?
|
||||
|
||||
// imported from TestWithSettingsBase
|
||||
// which was inherited by TestWithApplicationBase so pretty much used everywhere
|
||||
Umbraco.Web.Composing.Current.UmbracoContextAccessor = new TestUmbracoContextAccessor();
|
||||
@@ -284,7 +283,6 @@ namespace Umbraco.Tests.Testing
|
||||
|
||||
// create the file
|
||||
// create the schema
|
||||
|
||||
}
|
||||
|
||||
protected virtual void ComposeApplication(bool withApplication)
|
||||
@@ -330,7 +328,7 @@ namespace Umbraco.Tests.Testing
|
||||
Composition.RegisterSingleton<IUmbracoDatabaseFactory>(f => new UmbracoDatabaseFactory(
|
||||
Constants.System.UmbracoConnectionName,
|
||||
Logger,
|
||||
new Lazy<IMapperCollection>(() => Mock.Of<IMapperCollection>())));
|
||||
new Lazy<IMapperCollection>(Mock.Of<IMapperCollection>)));
|
||||
Composition.RegisterSingleton(f => f.TryGetInstance<IUmbracoDatabaseFactory>().SqlContext);
|
||||
|
||||
Composition.GetCollectionBuilder<UrlSegmentProviderCollectionBuilder>(); // empty
|
||||
@@ -404,7 +402,7 @@ namespace Umbraco.Tests.Testing
|
||||
// which would lock eg SqlCe .sdf files
|
||||
if (Factory?.TryGetInstance<IScopeProvider>() is ScopeProvider scopeProvider)
|
||||
{
|
||||
Core.Scoping.Scope scope;
|
||||
Scope scope;
|
||||
while ((scope = scopeProvider.AmbientScope) != null)
|
||||
{
|
||||
scope.Reset();
|
||||
@@ -412,11 +410,7 @@ namespace Umbraco.Tests.Testing
|
||||
}
|
||||
}
|
||||
|
||||
Current.Reset();
|
||||
|
||||
// fixme what should we dispose? IRegister or IFactory or?
|
||||
//Container?.Dispose();
|
||||
//Container = null;
|
||||
Current.Reset(); // disposes the factory
|
||||
|
||||
// reset all other static things that should not be static ;(
|
||||
UriUtility.ResetAppDomainAppVirtualPath();
|
||||
|
||||
@@ -116,8 +116,7 @@
|
||||
<Compile Include="Cache\SnapDictionaryTests.cs" />
|
||||
<Compile Include="Clr\ReflectionUtilitiesTests.cs" />
|
||||
<Compile Include="Collections\OrderedHashSetTests.cs" />
|
||||
<Compile Include="Composing\ContainerImplementationTests.cs" />
|
||||
<Compile Include="Composing\ContainerTests.cs" />
|
||||
<Compile Include="Composing\ContainerConfirmingTests.cs" />
|
||||
<Compile Include="CoreThings\CallContextTests.cs" />
|
||||
<Compile Include="Components\ComponentTests.cs" />
|
||||
<Compile Include="CoreXml\RenamedRootNavigatorTests.cs" />
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace Umbraco.Web.Editors
|
||||
var legacyPage = new global::umbraco.page(doc, _variationContextAccessor);
|
||||
|
||||
UmbracoContext.HttpContext.Items["pageElements"] = legacyPage.Elements;
|
||||
UmbracoContext.HttpContext.Items[global::Umbraco.Core.Constants.Conventions.Url.AltTemplate] = null;
|
||||
UmbracoContext.HttpContext.Items[Core.Constants.Conventions.Url.AltTemplate] = null;
|
||||
|
||||
var renderer = new UmbracoComponentRenderer(UmbracoContext);
|
||||
|
||||
|
||||
@@ -3,8 +3,6 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Web.Models;
|
||||
@@ -16,6 +14,13 @@ namespace Umbraco.Web.Editors
|
||||
[PluginController("UmbracoApi")]
|
||||
public class TourController : UmbracoAuthorizedJsonController
|
||||
{
|
||||
private readonly TourFilterCollection _filters;
|
||||
|
||||
public TourController(TourFilterCollection filters)
|
||||
{
|
||||
_filters = filters;
|
||||
}
|
||||
|
||||
public IEnumerable<BackOfficeTourFile> GetTours()
|
||||
{
|
||||
var result = new List<BackOfficeTourFile>();
|
||||
@@ -23,13 +28,11 @@ namespace Umbraco.Web.Editors
|
||||
if (UmbracoConfig.For.UmbracoSettings().BackOffice.Tours.EnableTours == false)
|
||||
return result;
|
||||
|
||||
var filters = Current.Factory.GetInstance<TourFilterCollection>().ToList(); // fixme inject
|
||||
|
||||
//get all filters that will be applied to all tour aliases
|
||||
var aliasOnlyFilters = filters.Where(x => x.PluginName == null && x.TourFileName == null).ToList();
|
||||
var aliasOnlyFilters = _filters.Where(x => x.PluginName == null && x.TourFileName == null).ToList();
|
||||
|
||||
//don't pass in any filters for core tours that have a plugin name assigned
|
||||
var nonPluginFilters = filters.Where(x => x.PluginName == null).ToList();
|
||||
var nonPluginFilters = _filters.Where(x => x.PluginName == null).ToList();
|
||||
|
||||
//add core tour files
|
||||
var coreToursPath = Path.Combine(IOHelper.MapPath(SystemDirectories.Config), "BackOfficeTours");
|
||||
@@ -45,7 +48,7 @@ namespace Umbraco.Web.Editors
|
||||
foreach (var plugin in Directory.EnumerateDirectories(IOHelper.MapPath(SystemDirectories.AppPlugins)))
|
||||
{
|
||||
var pluginName = Path.GetFileName(plugin.TrimEnd('\\'));
|
||||
var pluginFilters = filters.Where(x => x.PluginName != null && x.PluginName.IsMatch(pluginName)).ToList();
|
||||
var pluginFilters = _filters.Where(x => x.PluginName != null && x.PluginName.IsMatch(pluginName)).ToList();
|
||||
|
||||
//If there is any filter applied to match the plugin only (no file or tour alias) then ignore the plugin entirely
|
||||
var isPluginFiltered = pluginFilters.Any(x => x.TourFileName == null && x.TourAlias == null);
|
||||
|
||||
@@ -30,17 +30,12 @@ namespace Umbraco.Web.Mvc
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
private readonly UmbracoContext _umbracoContext;
|
||||
|
||||
// fixme - that one could / should accept a PublishedRouter (engine) to work on the PublishedRequest (published content request)
|
||||
public RenderRouteHandler(IUmbracoContextAccessor umbracoContextAccessor, IControllerFactory controllerFactory)
|
||||
{
|
||||
_umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor));
|
||||
_controllerFactory = controllerFactory ?? throw new ArgumentNullException(nameof(controllerFactory));
|
||||
}
|
||||
|
||||
// fixme - what about that one?
|
||||
// called by TemplateRenderer - which is created in
|
||||
// library - could get an engine without problem it's all ugly anyways
|
||||
// UmbracoComponentRenderer - ?? that one is not so obvious
|
||||
public RenderRouteHandler(UmbracoContext umbracoContext, IControllerFactory controllerFactory)
|
||||
{
|
||||
_umbracoContext = umbracoContext ?? throw new ArgumentNullException(nameof(umbracoContext));
|
||||
@@ -396,8 +391,6 @@ namespace Umbraco.Web.Mvc
|
||||
if ((request.HasTemplate == false && Features.Disabled.DisableTemplates == false)
|
||||
&& routeDef.HasHijackedRoute == false)
|
||||
{
|
||||
// fixme - better find a way to inject that engine? or at least Current.Engine of some sort!
|
||||
var engine = Core.Composing.Current.Factory.GetInstance<PublishedRouter>();
|
||||
request.UpdateOnMissingTemplate(); // request will go 404
|
||||
|
||||
// HandleHttpResponseStatus returns a value indicating that the request should
|
||||
@@ -426,7 +419,7 @@ namespace Umbraco.Web.Mvc
|
||||
routeDef = GetUmbracoRouteDefinition(requestContext, request);
|
||||
}
|
||||
|
||||
//no post values, just route to the controller/action requried (local)
|
||||
//no post values, just route to the controller/action required (local)
|
||||
|
||||
requestContext.RouteData.Values["controller"] = routeDef.ControllerName;
|
||||
if (string.IsNullOrWhiteSpace(routeDef.ActionName) == false)
|
||||
@@ -448,7 +441,7 @@ namespace Umbraco.Web.Mvc
|
||||
/// <returns></returns>
|
||||
internal static IHttpHandler GetWebFormsHandler()
|
||||
{
|
||||
return (global::umbraco.UmbracoDefault)BuildManager.CreateInstanceFromVirtualPath("~/default.aspx", typeof(global::umbraco.UmbracoDefault));
|
||||
return (umbraco.UmbracoDefault) BuildManager.CreateInstanceFromVirtualPath("~/default.aspx", typeof(umbraco.UmbracoDefault));
|
||||
}
|
||||
|
||||
private SessionStateBehavior GetSessionStateBehavior(RequestContext requestContext, string controllerName)
|
||||
|
||||
@@ -25,23 +25,20 @@ namespace Umbraco.Web.Templates
|
||||
/// </remarks>
|
||||
internal class TemplateRenderer
|
||||
{
|
||||
private readonly IFileService _fileService = Current.Services.FileService; // fixme inject
|
||||
private readonly UmbracoContext _umbracoContext;
|
||||
private object _oldPageId;
|
||||
private object _oldPageElements;
|
||||
private PublishedRequest _oldPublishedRequest;
|
||||
private object _oldAltTemplate;
|
||||
|
||||
public TemplateRenderer(UmbracoContext umbracoContext, int pageId, int? altTemplateId)
|
||||
{
|
||||
if (umbracoContext == null) throw new ArgumentNullException(nameof(umbracoContext));
|
||||
PageId = pageId;
|
||||
AltTemplate = altTemplateId;
|
||||
_umbracoContext = umbracoContext;
|
||||
_umbracoContext = umbracoContext ?? throw new ArgumentNullException(nameof(umbracoContext));
|
||||
}
|
||||
|
||||
// todo - inject!
|
||||
private PublishedRouter PublishedRouter => Core.Composing.Current.Factory.GetInstance<PublishedRouter>();
|
||||
private IFileService FileService => Current.Services.FileService; // fixme inject
|
||||
private PublishedRouter PublishedRouter => Core.Composing.Current.Factory.GetInstance<PublishedRouter>(); // fixme inject
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -58,10 +55,9 @@ namespace Umbraco.Web.Templates
|
||||
{
|
||||
if (writer == null) throw new ArgumentNullException(nameof(writer));
|
||||
|
||||
// instanciate a request a process
|
||||
// instantiate a request and process
|
||||
// important to use CleanedUmbracoUrl - lowercase path-only version of the current url, though this isn't going to matter
|
||||
// terribly much for this implementation since we are just creating a doc content request to modify it's properties manually.
|
||||
// fixme - previously that would create an aengine...
|
||||
var contentRequest = PublishedRouter.CreateRequest(_umbracoContext);
|
||||
|
||||
var doc = contentRequest.UmbracoContext.ContentCache.GetById(PageId);
|
||||
@@ -91,8 +87,8 @@ namespace Umbraco.Web.Templates
|
||||
contentRequest.PublishedContent = doc;
|
||||
//set the template, either based on the AltTemplate found or the standard template of the doc
|
||||
contentRequest.TemplateModel = UmbracoConfig.For.UmbracoSettings().WebRouting.DisableAlternativeTemplates || AltTemplate.HasValue == false
|
||||
? _fileService.GetTemplate(doc.TemplateId)
|
||||
: _fileService.GetTemplate(AltTemplate.Value);
|
||||
? FileService.GetTemplate(doc.TemplateId)
|
||||
: FileService.GetTemplate(AltTemplate.Value);
|
||||
|
||||
//if there is not template then exit
|
||||
if (contentRequest.HasTemplate == false)
|
||||
@@ -160,8 +156,8 @@ namespace Umbraco.Web.Templates
|
||||
break;
|
||||
case RenderingEngine.WebForms:
|
||||
default:
|
||||
var webFormshandler = (global::umbraco.UmbracoDefault)BuildManager
|
||||
.CreateInstanceFromVirtualPath("~/default.aspx", typeof(global::umbraco.UmbracoDefault));
|
||||
var webFormshandler = (UmbracoDefault) BuildManager
|
||||
.CreateInstanceFromVirtualPath("~/default.aspx", typeof(UmbracoDefault));
|
||||
//the 'true' parameter will ensure that the current query strings are carried through, we don't have
|
||||
// to build up the url again, it will just work.
|
||||
_umbracoContext.HttpContext.Server.Execute(webFormshandler, sw, true);
|
||||
@@ -213,11 +209,10 @@ namespace Umbraco.Web.Templates
|
||||
private void SaveExistingItems()
|
||||
{
|
||||
//Many objects require that these legacy items are in the http context items... before we render this template we need to first
|
||||
//save the values in them so that we can re-set them after we render so the rest of the execution works as per normal
|
||||
_oldPageId = _umbracoContext.PageId;
|
||||
//save the values in them so that we can re-set them after we render so the rest of the execution works as per normal
|
||||
_oldPageElements = _umbracoContext.HttpContext.Items["pageElements"];
|
||||
_oldPublishedRequest = _umbracoContext.PublishedRequest;
|
||||
_oldAltTemplate = _umbracoContext.HttpContext.Items[Umbraco.Core.Constants.Conventions.Url.AltTemplate];
|
||||
_oldAltTemplate = _umbracoContext.HttpContext.Items[Core.Constants.Conventions.Url.AltTemplate];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -227,7 +222,7 @@ namespace Umbraco.Web.Templates
|
||||
{
|
||||
_umbracoContext.PublishedRequest = _oldPublishedRequest;
|
||||
_umbracoContext.HttpContext.Items["pageElements"] = _oldPageElements;
|
||||
_umbracoContext.HttpContext.Items[Umbraco.Core.Constants.Conventions.Url.AltTemplate] = _oldAltTemplate;
|
||||
_umbracoContext.HttpContext.Items[Core.Constants.Conventions.Url.AltTemplate] = _oldAltTemplate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Web.Templates;
|
||||
using umbraco;
|
||||
using System.Collections.Generic;
|
||||
using umbraco.presentation.templateControls;
|
||||
using Umbraco.Core.Exceptions;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.Macros;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user