mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Fixing unit tests
Registering WorkContextModule to allow it to register the components it will use internally --HG-- branch : dev extra : rebase_source : 82c6712e0b465f57d080f751e36f5cc41a2158b9
This commit is contained in:
@@ -14,7 +14,21 @@ namespace Orchard.Tests {
|
||||
Resolve(_container);
|
||||
}
|
||||
|
||||
#if false
|
||||
// technically more accurate, and doesn't work
|
||||
[SetUp]
|
||||
public virtual void Init() {
|
||||
var hostBuilder = new ContainerBuilder();
|
||||
var hostContainer = hostBuilder.Build();
|
||||
var shellContainer = hostContainer.BeginLifetimeScope("shell", shellBuilder => Register(shellBuilder));
|
||||
var workContainer = shellContainer.BeginLifetimeScope("work");
|
||||
|
||||
_container = workContainer;
|
||||
Resolve(_container);
|
||||
}
|
||||
#endif
|
||||
|
||||
protected virtual void Register(ContainerBuilder builder) { }
|
||||
protected virtual void Resolve(IContainer container) { }
|
||||
protected virtual void Resolve(ILifetimeScope container) { }
|
||||
}
|
||||
}
|
@@ -21,7 +21,7 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
|
||||
}
|
||||
|
||||
|
||||
protected override void Resolve(IContainer container) {
|
||||
protected override void Resolve(ILifetimeScope container) {
|
||||
_parser = container.Resolve<IPlacementFileParser>();
|
||||
_folder = container.Resolve<InMemoryWebSiteFolder>();
|
||||
}
|
||||
|
@@ -39,7 +39,7 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
|
||||
builder.RegisterModule(new ShapeAttributeBindingModule());
|
||||
}
|
||||
|
||||
protected override void Resolve(IContainer container) {
|
||||
protected override void Resolve(ILifetimeScope container) {
|
||||
// implementation resorts to orchard host to resolve "current scope" services
|
||||
container.Resolve<Mock<IOrchardHostContainer>>()
|
||||
.Setup(x => x.Resolve<IComponentContext>())
|
||||
|
@@ -97,7 +97,7 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Resolve(IContainer container) {
|
||||
protected override void Resolve(ILifetimeScope container) {
|
||||
_features = new List<FeatureDescriptor>();
|
||||
|
||||
container.Resolve<Mock<IExtensionManager>>()
|
||||
|
@@ -22,11 +22,12 @@ namespace Orchard.Tests.Environment {
|
||||
}
|
||||
|
||||
protected override void Register(ContainerBuilder builder) {
|
||||
builder.RegisterModule(new WorkContextModule());
|
||||
builder.RegisterType<WorkContextAccessor>().As<IWorkContextAccessor>();
|
||||
builder.RegisterAutoMocking();
|
||||
}
|
||||
|
||||
protected override void Resolve(IContainer container) {
|
||||
protected override void Resolve(ILifetimeScope container) {
|
||||
container.Mock<IHttpContextAccessor>()
|
||||
.Setup(x => x.Current())
|
||||
.Returns(() => _httpContextCurrent);
|
||||
|
@@ -21,6 +21,7 @@ namespace Orchard.Tests.Environment.ShellBuilders {
|
||||
public void Init() {
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterType<ShellContextFactory>().As<IShellContextFactory>();
|
||||
builder.RegisterModule(new WorkContextModule());
|
||||
builder.RegisterType<WorkContextAccessor>().As<IWorkContextAccessor>();
|
||||
builder.RegisterAutoMocking(Moq.MockBehavior.Strict);
|
||||
_container = builder.Build();
|
||||
|
@@ -23,6 +23,7 @@ namespace Orchard.Tests.Environment.State {
|
||||
public void Init() {
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterType<DefaultProcessingEngine>().As<IProcessingEngine>();
|
||||
builder.RegisterModule(new WorkContextModule());
|
||||
builder.RegisterType<WorkContextAccessor>().As<IWorkContextAccessor>();
|
||||
builder.RegisterAutoMocking();
|
||||
_container = builder.Build();
|
||||
|
@@ -36,6 +36,7 @@ namespace Orchard.Tests.Mvc.Routes {
|
||||
rootBuilder.Register(ctx => _routes);
|
||||
rootBuilder.RegisterType<ShellRoute>().InstancePerDependency();
|
||||
rootBuilder.RegisterType<RunningShellTable>().As<IRunningShellTable>().SingleInstance();
|
||||
rootBuilder.RegisterModule(new WorkContextModule());
|
||||
rootBuilder.RegisterType<WorkContextAccessor>().As<IWorkContextAccessor>().InstancePerMatchingLifetimeScope("shell");
|
||||
rootBuilder.RegisterType<HttpContextAccessor>().As<IHttpContextAccessor>();
|
||||
|
||||
|
@@ -12,6 +12,7 @@ namespace Orchard.Tests.Tasks {
|
||||
public class SweepGeneratorTests : ContainerTestBase {
|
||||
protected override void Register(ContainerBuilder builder) {
|
||||
builder.RegisterAutoMocking(MockBehavior.Loose);
|
||||
builder.RegisterModule(new WorkContextModule());
|
||||
builder.RegisterType<WorkContextAccessor>().As<IWorkContextAccessor>();
|
||||
builder.RegisterType<SweepGenerator>();
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ namespace Orchard.Tests.UI {
|
||||
throw new NotImplementedException("this test fixture needs to move to modules tests now");
|
||||
}
|
||||
|
||||
protected override void Resolve(IContainer container) {
|
||||
protected override void Resolve(ILifetimeScope container) {
|
||||
_workContext = container.Resolve<IWorkContextAccessor>().CreateWorkContextScope().WorkContext;
|
||||
}
|
||||
|
||||
|
@@ -9,7 +9,7 @@ using Moq;
|
||||
|
||||
namespace Orchard.Tests.Utility {
|
||||
public static class ContainerExtensions {
|
||||
public static Mock<T> Mock<T>(this IContainer container) where T : class {
|
||||
public static Mock<T> Mock<T>(this IComponentContext container) where T : class {
|
||||
return container.Resolve<Mock<T>>();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user