mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Fixed unit tests.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Web;
|
||||
using Autofac;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Mvc;
|
||||
@@ -27,6 +28,13 @@ namespace Orchard.Tests.Environment {
|
||||
container.Mock<IHttpContextAccessor>()
|
||||
.Setup(x => x.Current())
|
||||
.Returns(() => _httpContextCurrent);
|
||||
|
||||
container.Mock<IHttpContextAccessor>()
|
||||
.Setup(x => x.CreateContext(It.IsAny<ILifetimeScope>()))
|
||||
.Returns(() => new StubHttpContext());
|
||||
|
||||
container.Mock<IWorkContextEvents>()
|
||||
.Setup(x => x.Started());
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -9,6 +9,7 @@ using Orchard.Environment.Descriptor;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Environment.ShellBuilders.Models;
|
||||
using Orchard.Mvc;
|
||||
using Orchard.Tests.Stubs;
|
||||
using Orchard.Tests.Utility;
|
||||
|
||||
namespace Orchard.Tests.Environment.ShellBuilders {
|
||||
@@ -32,6 +33,7 @@ namespace Orchard.Tests.Environment.ShellBuilders {
|
||||
var descriptor = new ShellDescriptor { SerialNumber = 6655321 };
|
||||
var blueprint = new ShellBlueprint();
|
||||
var shellLifetimeScope = _container.BeginLifetimeScope("shell");
|
||||
var httpContext = new StubHttpContext();
|
||||
|
||||
_container.Mock<IShellDescriptorCache>()
|
||||
.Setup(x => x.Fetch(ShellSettings.DefaultName))
|
||||
@@ -49,9 +51,16 @@ namespace Orchard.Tests.Environment.ShellBuilders {
|
||||
.Setup(x => x.GetShellDescriptor())
|
||||
.Returns(descriptor);
|
||||
|
||||
_container.Mock<IWorkContextEvents>()
|
||||
.Setup(x => x.Started());
|
||||
|
||||
_container.Mock<IHttpContextAccessor>()
|
||||
.Setup(x => x.Current())
|
||||
.Returns(default(HttpContextBase));
|
||||
.Returns(httpContext);
|
||||
|
||||
_container.Mock<IHttpContextAccessor>()
|
||||
.Setup(x => x.CreateContext(It.IsAny<ILifetimeScope>()))
|
||||
.Returns(httpContext);
|
||||
|
||||
var factory = _container.Resolve<IShellContextFactory>();
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ using Orchard.Environment.State;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Events;
|
||||
using Orchard.Mvc;
|
||||
using Orchard.Tests.Stubs;
|
||||
using Orchard.Tests.Utility;
|
||||
|
||||
namespace Orchard.Tests.Environment.State {
|
||||
@@ -34,12 +35,17 @@ namespace Orchard.Tests.Environment.State {
|
||||
LifetimeScope = _container.BeginLifetimeScope(),
|
||||
};
|
||||
|
||||
var httpContext = new StubHttpContext();
|
||||
|
||||
_container.Mock<IShellContextFactory>()
|
||||
.Setup(x => x.CreateDescribedContext(_shellContext.Settings, _shellContext.Descriptor))
|
||||
.Returns(_shellContext);
|
||||
_container.Mock<IHttpContextAccessor>()
|
||||
.Setup(x=>x.Current())
|
||||
.Returns(default(HttpContextBase));
|
||||
.Returns(httpContext);
|
||||
_container.Mock<IHttpContextAccessor>()
|
||||
.Setup(x => x.CreateContext(It.IsAny<ILifetimeScope>()))
|
||||
.Returns(httpContext);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,9 @@ using Autofac;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Mvc;
|
||||
using Orchard.Tasks;
|
||||
using Orchard.Tests.Stubs;
|
||||
using Orchard.Tests.Utility;
|
||||
|
||||
namespace Orchard.Tests.Tasks {
|
||||
@@ -16,6 +18,19 @@ namespace Orchard.Tests.Tasks {
|
||||
builder.RegisterType<SweepGenerator>();
|
||||
}
|
||||
|
||||
protected override void Resolve(ILifetimeScope container) {
|
||||
container.Mock<IHttpContextAccessor>()
|
||||
.Setup(x => x.Current())
|
||||
.Returns(() => null);
|
||||
|
||||
container.Mock<IHttpContextAccessor>()
|
||||
.Setup(x => x.CreateContext(It.IsAny<ILifetimeScope>()))
|
||||
.Returns(() => new StubHttpContext());
|
||||
|
||||
container.Mock<IWorkContextEvents>()
|
||||
.Setup(x => x.Started());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DoWorkShouldSendHeartbeatToTaskManager() {
|
||||
var heartbeatSource = _container.Resolve<SweepGenerator>();
|
||||
|
||||
Reference in New Issue
Block a user