Fixing broken UT.

--HG--
branch : 1.x
This commit is contained in:
Andre Rodrigues
2011-06-01 01:12:01 -07:00
parent 07dbc2b136
commit e353220ecf
2 changed files with 64 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Routing;
using Autofac;
using JetBrains.Annotations;
@@ -23,13 +24,17 @@ using Orchard.Core.Scheduling.Models;
using Orchard.Core.Scheduling.Services;
using Orchard.DisplayManagement;
using Orchard.DisplayManagement.Descriptors;
using Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy;
using Orchard.DisplayManagement.Descriptors.ShapePlacementStrategy;
using Orchard.DisplayManagement.Implementation;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
using Orchard.FileSystems.VirtualPath;
using Orchard.Localization;
using Orchard.Security;
using Orchard.Tasks.Scheduling;
using Orchard.Tests.DisplayManagement.Descriptors;
using Orchard.Tests.Modules;
using Orchard.Core.Common.ViewModels;
using System.Web.Mvc;
using Orchard.Tests.Stubs;
using Orchard.Themes;
@@ -48,20 +53,32 @@ namespace Orchard.Core.Tests.Common.Providers {
builder.RegisterType<TestHandler>().As<IContentHandler>();
builder.RegisterType<CommonPartHandler>().As<IContentHandler>();
builder.RegisterType<CommonPartDriver>().As<IContentPartDriver>();
builder.RegisterType<OwnerEditorDriver>().As<IContentPartDriver>();
builder.RegisterType<ContentPartDriverCoordinator>().As<IContentHandler>();
builder.RegisterType<CommonService>().As<ICommonService>();
builder.RegisterType<ScheduledTaskManager>().As<IScheduledTaskManager>();
builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
builder.RegisterInstance(new Mock<IThemeManager>().Object);
builder.RegisterType<StubThemeService>().As<IThemeManager>();
builder.RegisterInstance(new Mock<IOrchardServices>().Object);
builder.RegisterInstance(new Mock<RequestContext>().Object);
builder.RegisterInstance(new RequestContext(new StubHttpContext(), new RouteData()));
builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();
DefaultShapeTableManagerTests.TestShapeProvider.FeatureShapes = new Dictionary<Feature, IEnumerable<string>> {
{ TestFeature(), new[] { "Parts_Common_Owner_Edit" } }
};
builder.RegisterType<DefaultShapeTableManagerTests.TestShapeProvider>().As<IShapeTableProvider>()
.As<DefaultShapeTableManagerTests.TestShapeProvider>()
.InstancePerLifetimeScope();
builder.RegisterInstance(new RouteCollection());
builder.RegisterModule(new ShapeAttributeBindingModule());
_authn = new Mock<IAuthenticationService>();
_authz = new Mock<IAuthorizationService>();
_membership = new Mock<IMembershipService>();
@@ -71,6 +88,24 @@ namespace Orchard.Core.Tests.Common.Providers {
builder.RegisterInstance(_authz.Object);
builder.RegisterInstance(_membership.Object);
builder.RegisterInstance(_contentDefinitionManager.Object);
var virtualPathProviderMock = new Mock<IVirtualPathProvider>();
virtualPathProviderMock.Setup(a => a.ToAppRelative(It.IsAny<string>())).Returns("~/yadda");
builder.RegisterInstance(virtualPathProviderMock.Object);
}
static Feature TestFeature() {
return new Feature {
Descriptor = new FeatureDescriptor {
Id = "Testing",
Dependencies = Enumerable.Empty<string>(),
Extension = new ExtensionDescriptor {
Id = "Testing",
ExtensionType = DefaultExtensionTypes.Module,
}
}
};
}
protected override IEnumerable<Type> DatabaseTypes {
@@ -119,9 +154,8 @@ namespace Orchard.Core.Tests.Common.Providers {
var user = contentManager.New<IUser>("User");
_authn.Setup(x => x.GetAuthenticatedUser()).Returns(user);
var createUtc = _clock.UtcNow;
var item = contentManager.Create<ICommonPart>("test-item", VersionOptions.Draft, init => { });
var viewModel = new OwnerEditorViewModel() { Owner = "User" };
var viewModel = new OwnerEditorViewModel { Owner = "User" };
updateModel.Setup(x => x.TryUpdateModel(viewModel, "", null, null)).Returns(true);
contentManager.UpdateEditor(item.ContentItem, updateModel.Object);
}
@@ -146,6 +180,16 @@ namespace Orchard.Core.Tests.Common.Providers {
}
}
class StubThemeService : IThemeManager {
private readonly ExtensionDescriptor _theme = new ExtensionDescriptor {
Id = "SafeMode",
Name = "SafeMode",
Location = "~/Themes",
};
public ExtensionDescriptor GetRequestTheme(RequestContext requestContext) { return _theme; }
}
[Test]
public void PublishingShouldNotThrowExceptionIfOwnerIsNull() {
var contentManager = _container.Resolve<IContentManager>();
@@ -177,9 +221,13 @@ namespace Orchard.Core.Tests.Common.Providers {
var updater = new UpdatModelStub() { Owner = "" };
_container.Resolve<DefaultShapeTableManagerTests.TestShapeProvider>().Discover =
b => b.Describe("Parts_Common_Owner_Edit").From(TestFeature())
.Placement(ShapePlacementParsingStrategy.BuildPredicate(c => true, new KeyValuePair<string, string>("Path", "~/yadda")), new PlacementInfo { Location = "Match" });
contentManager.UpdateEditor(item.ContentItem, updater);
Assert.That(updater.ModelErrors.ContainsKey("CommonPart.Owner"), Is.True);
Assert.That(updater.ModelErrors.ContainsKey("OwnerEditor.Owner"), Is.True);
}
[Test]

View File

@@ -6,6 +6,7 @@ using ClaySharp.Implementation;
using Orchard.ContentManagement.Handlers;
using Orchard.DisplayManagement;
using Orchard.DisplayManagement.Descriptors;
using Orchard.FileSystems.VirtualPath;
using Orchard.Logging;
using Orchard.Themes;
using Orchard.UI.Zones;
@@ -17,18 +18,23 @@ namespace Orchard.ContentManagement {
private readonly IShapeTableManager _shapeTableManager;
private readonly Lazy<IThemeManager> _themeService;
private readonly RequestContext _requestContext;
private readonly IVirtualPathProvider _virtualPathProvider;
public DefaultContentDisplay(
Lazy<IEnumerable<IContentHandler>> handlers,
IShapeFactory shapeFactory,
IShapeTableManager shapeTableManager,
Lazy<IThemeManager> themeService,
RequestContext requestContext) {
RequestContext requestContext,
IVirtualPathProvider virtualPathProvider) {
_handlers = handlers;
_shapeFactory = shapeFactory;
_shapeTableManager = shapeTableManager;
_themeService = themeService;
_requestContext = requestContext;
_virtualPathProvider = virtualPathProvider;
Logger = NullLogger.Instance;
}
@@ -111,11 +117,11 @@ namespace Orchard.ContentManagement {
Stereotype = stereotype,
DisplayType = displayType,
Differentiator = differentiator,
Path = VirtualPathUtility.AppendTrailingSlash(VirtualPathUtility.ToAppRelative(request.Path)) // get the current app-relative path, i.e. ~/my-blog/foo
Path = VirtualPathUtility.AppendTrailingSlash(_virtualPathProvider.ToAppRelative(request.Path)) // get the current app-relative path, i.e. ~/my-blog/foo
};
var placement = descriptor.Placement(placementContext);
if(placement != null) {
if (placement != null) {
placement.Source = placementContext.Source;
return placement;
}