mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-08-01 18:13:08 +08:00
Added unit test for CompositionStrategy.
This commit is contained in:
parent
06e4d2f7f8
commit
11f6ecc4d4
@ -0,0 +1,109 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Autofac;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Environment.ShellBuilders;
|
||||
using Orchard.Tests.Environment.TestDependencies;
|
||||
using Orchard.Utility;
|
||||
using Orchard.Utility.Extensions;
|
||||
|
||||
namespace Orchard.Tests.Environment.ShellBuilders {
|
||||
[TestFixture]
|
||||
public class CompositionStrategyTests : ContainerTestBase {
|
||||
private CompositionStrategy _compositionStrategy;
|
||||
private Mock<IExtensionManager> _extensionManager;
|
||||
|
||||
protected override void Register(ContainerBuilder builder) {
|
||||
_extensionManager = new Mock<IExtensionManager>(MockBehavior.Loose);
|
||||
|
||||
builder.RegisterType<CompositionStrategy>().AsSelf();
|
||||
builder.RegisterInstance(_extensionManager.Object);
|
||||
}
|
||||
|
||||
protected override void Resolve(ILifetimeScope container) {
|
||||
_compositionStrategy = container.Resolve<CompositionStrategy>();
|
||||
|
||||
var alphaExtension = new ExtensionDescriptor {
|
||||
Id = "Alpha",
|
||||
Name = "Alpha",
|
||||
ExtensionType = "Module"
|
||||
};
|
||||
|
||||
var alphaFeatureDescriptor = new FeatureDescriptor {
|
||||
Id = "Alpha",
|
||||
Name = "Alpha",
|
||||
Extension = alphaExtension
|
||||
};
|
||||
|
||||
var betaFeatureDescriptor = new FeatureDescriptor {
|
||||
Id = "Beta",
|
||||
Name = "Beta",
|
||||
Extension = alphaExtension,
|
||||
Dependencies = new List<string> {
|
||||
"Alpha"
|
||||
}
|
||||
};
|
||||
|
||||
alphaExtension.Features = new List<FeatureDescriptor> {
|
||||
alphaFeatureDescriptor,
|
||||
betaFeatureDescriptor
|
||||
};
|
||||
|
||||
var features = new List<Feature> {
|
||||
new Feature {
|
||||
Descriptor = alphaFeatureDescriptor,
|
||||
ExportedTypes = new List<Type> {
|
||||
typeof(AlphaDependency)
|
||||
}
|
||||
},
|
||||
new Feature {
|
||||
Descriptor = betaFeatureDescriptor,
|
||||
ExportedTypes = new List<Type> {
|
||||
typeof(BetaDependency)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_extensionManager.Setup(x => x.AvailableExtensions()).Returns(new List<ExtensionDescriptor> {
|
||||
alphaExtension
|
||||
});
|
||||
|
||||
_extensionManager.Setup(x => x.AvailableFeatures()).Returns(
|
||||
_extensionManager.Object.AvailableExtensions()
|
||||
.SelectMany(ext => ext.Features)
|
||||
.ToReadOnlyCollection());
|
||||
|
||||
_extensionManager.Setup(x => x.LoadFeatures(It.IsAny<IEnumerable<FeatureDescriptor>>())).Returns(features);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComposeReturnsBlueprintWithExpectedDependencies() {
|
||||
var shellSettings = CreateShell();
|
||||
var shellDescriptor = CreateShellDescriptor("Alpha", "Beta");
|
||||
var shellBlueprint = _compositionStrategy.Compose(shellSettings, shellDescriptor);
|
||||
|
||||
Assert.That(shellBlueprint.Dependencies.Count(x => x.Type == typeof (AlphaDependency)), Is.EqualTo(1));
|
||||
Assert.That(shellBlueprint.Dependencies.Count(x => x.Type == typeof(BetaDependency)), Is.EqualTo(1));
|
||||
}
|
||||
|
||||
private ShellSettings CreateShell() {
|
||||
return new ShellSettings();
|
||||
}
|
||||
|
||||
private ShellDescriptor CreateShellDescriptor(params string[] enabledFeatures) {
|
||||
var shellDescriptor = new ShellDescriptor {
|
||||
Features = enabledFeatures.Select(x => new ShellFeature {
|
||||
Name = x
|
||||
})
|
||||
};
|
||||
|
||||
return shellDescriptor;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
namespace Orchard.Tests.Environment.TestDependencies {
|
||||
|
||||
public interface IAlphaDependency : IDependency {
|
||||
}
|
||||
|
||||
public class AlphaDependency : IAlphaDependency {
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
namespace Orchard.Tests.Environment.TestDependencies {
|
||||
|
||||
public interface IBetaDependency : IDependency {
|
||||
}
|
||||
|
||||
public class BetaDependency : IBetaDependency {
|
||||
public IAlphaDependency Alpha { get; set; }
|
||||
|
||||
public BetaDependency(IAlphaDependency alpha) {
|
||||
Alpha = alpha;
|
||||
}
|
||||
}
|
||||
}
|
@ -243,9 +243,12 @@
|
||||
<Compile Include="Environment\Extensions\ExtensionLoaderCoordinatorTests.cs" />
|
||||
<Compile Include="Environment\Features\FeatureManagerTests.cs" />
|
||||
<Compile Include="Environment\Loaders\DynamicExtensionLoaderTests.cs" />
|
||||
<Compile Include="Environment\ShellBuilders\CompositionStrategyTests.cs" />
|
||||
<Compile Include="Environment\State\DefaultProcessingEngineTests.cs" />
|
||||
<Compile Include="Environment\RunningShellTableTests.cs" />
|
||||
<Compile Include="Environment\StubHostEnvironment.cs" />
|
||||
<Compile Include="Environment\TestDependencies\AlphaDependency.cs" />
|
||||
<Compile Include="Environment\TestDependencies\BetaDependency.cs" />
|
||||
<Compile Include="Environment\Utility\Build.cs" />
|
||||
<Compile Include="Environment\Warmup\WarmupUtilityTests.cs" />
|
||||
<Compile Include="FileSystems\AppData\AppDataFolderTests.cs" />
|
||||
|
@ -63,7 +63,7 @@ namespace Orchard.Environment.ShellBuilders {
|
||||
Records = records,
|
||||
};
|
||||
|
||||
Logger.Debug("Done composing blueprint");
|
||||
Logger.Debug("Done composing blueprint.");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user