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:
Louis DeJardin
2010-12-02 12:42:12 -08:00
parent 4762b1d3f6
commit fb82b122f8
11 changed files with 26 additions and 7 deletions

View File

@@ -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) { }
}
}

View File

@@ -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>();
}

View File

@@ -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>())

View File

@@ -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>>()

View File

@@ -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);

View File

@@ -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();

View File

@@ -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();

View File

@@ -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>();

View File

@@ -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>();
}

View File

@@ -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;
}

View File

@@ -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>>();
}