mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Fixing some ignored UT. Adding comments. Welding content item parts conditionally.
--HG-- branch : 1.x
This commit is contained in:
@@ -532,13 +532,13 @@ namespace Orchard.Tests.ContentManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Test, Ignore("Fix pending")]
|
[Test]
|
||||||
public void ExistingTypeAndPartDefinitionShouldBeUsed() {
|
public void ExistingTypeAndPartDefinitionShouldBeUsed() {
|
||||||
var alphaType = new ContentTypeDefinitionBuilder()
|
var alphaType = new ContentTypeDefinitionBuilder()
|
||||||
.Named(DefaultAlphaName)
|
.Named(DefaultAlphaName)
|
||||||
.WithSetting("x", "1")
|
.WithSetting("x", "1")
|
||||||
.WithPart("foo")
|
.WithPart("foo")
|
||||||
.WithPart("Flavored", part => part.WithSetting("spin", "clockwise"))
|
.WithPart("FlavoredPart", part => part.WithSetting("spin", "clockwise"))
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
_contentDefinitionManager
|
_contentDefinitionManager
|
||||||
|
@@ -25,7 +25,6 @@ namespace Orchard.Tests.DisplayManagement {
|
|||||||
CurrentTheme = new ExtensionDescriptor { Id = "Hello" }
|
CurrentTheme = new ExtensionDescriptor { Id = "Hello" }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
builder.RegisterType<DefaultDisplayManager>().As<IDisplayManager>();
|
builder.RegisterType<DefaultDisplayManager>().As<IDisplayManager>();
|
||||||
builder.RegisterType<TestShapeTableManager>().As<IShapeTableManager>();
|
builder.RegisterType<TestShapeTableManager>().As<IShapeTableManager>();
|
||||||
builder.RegisterType<TestWorkContextAccessor>().As<IWorkContextAccessor>();
|
builder.RegisterType<TestWorkContextAccessor>().As<IWorkContextAccessor>();
|
||||||
|
@@ -309,10 +309,12 @@ Features:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test, Ignore("This assertion appears to be inconsistent with the comment in extension manager - an empty feature is returned")]
|
[Test]
|
||||||
public void ExtensionManagerShouldThrowIfFeatureDoesNotExist() {
|
public void ExtensionManagerShouldReturnEmptyFeatureIfFeatureDoesNotExist() {
|
||||||
var featureDescriptor = new FeatureDescriptor { Id = "NoSuchFeature", Extension = new ExtensionDescriptor { Name = "NoSuchFeature" } };
|
var featureDescriptor = new FeatureDescriptor { Id = "NoSuchFeature", Extension = new ExtensionDescriptor { Id = "NoSuchFeature" } };
|
||||||
Assert.Throws<ArgumentException>(() => _manager.LoadFeatures(new[] { featureDescriptor }));
|
Feature feature = _manager.LoadFeatures(new[] { featureDescriptor }).First();
|
||||||
|
Assert.AreEqual(featureDescriptor, feature.Descriptor);
|
||||||
|
Assert.AreEqual(0, feature.ExportedTypes.Count());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@@ -25,6 +25,7 @@ namespace Orchard.Tests.Mvc {
|
|||||||
.Keyed<IController>(typeof(FooController))
|
.Keyed<IController>(typeof(FooController))
|
||||||
.WithMetadata("ControllerType", typeof(FooController))
|
.WithMetadata("ControllerType", typeof(FooController))
|
||||||
.InstancePerDependency();
|
.InstancePerDependency();
|
||||||
|
|
||||||
builder.RegisterType<BarController>()
|
builder.RegisterType<BarController>()
|
||||||
.Keyed<IController>("/bar")
|
.Keyed<IController>("/bar")
|
||||||
.Keyed<IController>(typeof(BarController))
|
.Keyed<IController>(typeof(BarController))
|
||||||
@@ -59,8 +60,7 @@ namespace Orchard.Tests.Mvc {
|
|||||||
Assert.That(controller, Is.TypeOf<ReplacementFooController>());
|
Assert.That(controller, Is.TypeOf<ReplacementFooController>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test, Ignore("OrchardControllerFactory depends on metadata, calling base when no context is causing errors.")]
|
||||||
[Ignore("OrchardControllerFactory depends on metadata, calling base when no context is causing errors.")]
|
|
||||||
public void WhenNullOrMissingContainerNormalControllerFactoryRulesShouldBeUsedAsFallback() {
|
public void WhenNullOrMissingContainerNormalControllerFactoryRulesShouldBeUsedAsFallback() {
|
||||||
var requestContext = GetRequestContext(null);
|
var requestContext = GetRequestContext(null);
|
||||||
var controller = _controllerFactory.CreateController(requestContext, "foo");
|
var controller = _controllerFactory.CreateController(requestContext, "foo");
|
||||||
|
@@ -2,6 +2,10 @@ using System;
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
namespace Orchard.Caching {
|
namespace Orchard.Caching {
|
||||||
|
/// <summary>
|
||||||
|
/// Provides the default implementation for a cache holder.
|
||||||
|
/// The cache holder is responsible for actually storing the references to cached entities.
|
||||||
|
/// </summary>
|
||||||
public class DefaultCacheHolder : ICacheHolder {
|
public class DefaultCacheHolder : ICacheHolder {
|
||||||
private readonly ConcurrentDictionary<CacheKey, object> _caches = new ConcurrentDictionary<CacheKey, object>();
|
private readonly ConcurrentDictionary<CacheKey, object> _caches = new ConcurrentDictionary<CacheKey, object>();
|
||||||
|
|
||||||
@@ -11,6 +15,13 @@ namespace Orchard.Caching {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a Cache entry from the cache. If none is found, an empty one is created and returned.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TKey">The type of the key within the component.</typeparam>
|
||||||
|
/// <typeparam name="TResult">The type of the result.</typeparam>
|
||||||
|
/// <param name="component">The component context.</param>
|
||||||
|
/// <returns>An entry from the cache, or a new, empty one, if none is found.</returns>
|
||||||
public ICache<TKey, TResult> GetCache<TKey, TResult>(Type component) {
|
public ICache<TKey, TResult> GetCache<TKey, TResult>(Type component) {
|
||||||
var cacheKey = new CacheKey(component, typeof(TKey), typeof(TResult));
|
var cacheKey = new CacheKey(component, typeof(TKey), typeof(TResult));
|
||||||
var result = _caches.GetOrAdd(cacheKey, k => new Cache<TKey, TResult>());
|
var result = _caches.GetOrAdd(cacheKey, k => new Cache<TKey, TResult>());
|
||||||
|
@@ -1,15 +1,30 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Orchard.Caching {
|
namespace Orchard.Caching {
|
||||||
|
/// <summary>
|
||||||
|
/// Provides the default implementation for a cache manager.
|
||||||
|
/// The cache manager provides an abstraction over the cache holder allowing it to be easily swaped and isolating it within a component context.
|
||||||
|
/// </summary>
|
||||||
public class DefaultCacheManager : ICacheManager {
|
public class DefaultCacheManager : ICacheManager {
|
||||||
private readonly Type _component;
|
private readonly Type _component;
|
||||||
private readonly ICacheHolder _cacheHolder;
|
private readonly ICacheHolder _cacheHolder;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructs a new cache manager for a given component type and with a specific cache holder implementation.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="component">The component to which the cache applies (context).</param>
|
||||||
|
/// <param name="cacheHolder">The cache holder that contains the entities cached.</param>
|
||||||
public DefaultCacheManager(Type component, ICacheHolder cacheHolder) {
|
public DefaultCacheManager(Type component, ICacheHolder cacheHolder) {
|
||||||
_component = component;
|
_component = component;
|
||||||
_cacheHolder = cacheHolder;
|
_cacheHolder = cacheHolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a cache entry from the cache holder.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TKey">The type of the key to be used to fetch the cache entry.</typeparam>
|
||||||
|
/// <typeparam name="TResult">The type of the entry to be obtained from the cache.</typeparam>
|
||||||
|
/// <returns>The entry from the cache.</returns>
|
||||||
public ICache<TKey, TResult> GetCache<TKey, TResult>() {
|
public ICache<TKey, TResult> GetCache<TKey, TResult>() {
|
||||||
return _cacheHolder.GetCache<TKey, TResult>(_component);
|
return _cacheHolder.GetCache<TKey, TResult>(_component);
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,6 @@ namespace Orchard.ContentManagement {
|
|||||||
_parts = new List<ContentPart>();
|
_parts = new List<ContentPart>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private readonly IList<ContentPart> _parts;
|
private readonly IList<ContentPart> _parts;
|
||||||
ContentItem IContent.ContentItem { get { return this; } }
|
ContentItem IContent.ContentItem { get { return this; } }
|
||||||
|
|
||||||
|
@@ -128,7 +128,6 @@ namespace Orchard.ContentManagement {
|
|||||||
return contentItem;
|
return contentItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// allocate instance and set record property
|
// allocate instance and set record property
|
||||||
contentItem = New(versionRecord.ContentItemRecord.ContentType.Name);
|
contentItem = New(versionRecord.ContentItemRecord.ContentType.Name);
|
||||||
contentItem.VersionRecord = versionRecord;
|
contentItem.VersionRecord = versionRecord;
|
||||||
@@ -398,13 +397,8 @@ namespace Orchard.ContentManagement {
|
|||||||
|
|
||||||
Handlers.Invoke(handler => handler.Indexed(indexContentContext), Logger);
|
Handlers.Invoke(handler => handler.Indexed(indexContentContext), Logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
//public ISearchBuilder Search() {
|
|
||||||
// return _indexManager.HasIndexProvider()
|
|
||||||
// ? _indexManager.GetSearchIndexProvider().CreateSearchBuilder("Search")
|
|
||||||
// : new NullSearchBuilder();
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class CallSiteCollection : ConcurrentDictionary<string, CallSite<Func<CallSite, object, object>>> {
|
class CallSiteCollection : ConcurrentDictionary<string, CallSite<Func<CallSite, object, object>>> {
|
||||||
readonly Func<string, CallSite<Func<CallSite, object, object>>> _valueFactory;
|
readonly Func<string, CallSite<Func<CallSite, object, object>>> _valueFactory;
|
||||||
|
|
||||||
|
@@ -2,12 +2,21 @@
|
|||||||
using Orchard.ContentManagement.MetaData.Models;
|
using Orchard.ContentManagement.MetaData.Models;
|
||||||
|
|
||||||
namespace Orchard.ContentManagement.Handlers {
|
namespace Orchard.ContentManagement.Handlers {
|
||||||
|
/// <summary>
|
||||||
|
/// Builds a contentitem based on its the type definition (<seealso cref="ContentTypeDefinition"/>).
|
||||||
|
/// </summary>
|
||||||
public class ContentItemBuilder {
|
public class ContentItemBuilder {
|
||||||
private readonly ContentTypeDefinition _definition;
|
private readonly ContentTypeDefinition _definition;
|
||||||
private readonly ContentItem _item;
|
private readonly ContentItem _item;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructs a new Content Item Builder instance.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="definition">The definition for the content item to be built.</param>
|
||||||
public ContentItemBuilder(ContentTypeDefinition definition) {
|
public ContentItemBuilder(ContentTypeDefinition definition) {
|
||||||
_definition = definition;
|
_definition = definition;
|
||||||
|
|
||||||
|
// TODO: could / should be done on the build method ?
|
||||||
_item = new ContentItem {
|
_item = new ContentItem {
|
||||||
ContentType = definition.Name,
|
ContentType = definition.Name,
|
||||||
TypeDefinition = definition
|
TypeDefinition = definition
|
||||||
@@ -18,23 +27,37 @@ namespace Orchard.ContentManagement.Handlers {
|
|||||||
return _item;
|
return _item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Welds a new part to the content item. If a part of the same type is already welded nothing is done.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TPart">The type of the part to be welded.</typeparam>
|
||||||
|
/// <returns>A new Content Item Builder with the item having the new part welded.</returns>
|
||||||
public ContentItemBuilder Weld<TPart>() where TPart : ContentPart, new() {
|
public ContentItemBuilder Weld<TPart>() where TPart : ContentPart, new() {
|
||||||
|
|
||||||
|
// if the part hasn't be weld yet
|
||||||
|
if (_item.Parts.FirstOrDefault(part => part.GetType().Equals(typeof(TPart))) == null) {
|
||||||
var partName = typeof(TPart).Name;
|
var partName = typeof(TPart).Name;
|
||||||
|
|
||||||
|
// obtain the type definition for the part
|
||||||
var typePartDefinition = _definition.Parts.FirstOrDefault(p => p.PartDefinition.Name == partName);
|
var typePartDefinition = _definition.Parts.FirstOrDefault(p => p.PartDefinition.Name == partName);
|
||||||
if (typePartDefinition == null) {
|
if (typePartDefinition == null) {
|
||||||
|
// If the content item's type definition does not define the part; use an empty type definition.
|
||||||
typePartDefinition = new ContentTypePartDefinition(
|
typePartDefinition = new ContentTypePartDefinition(
|
||||||
new ContentPartDefinition(partName),
|
new ContentPartDefinition(partName),
|
||||||
new SettingsDictionary());
|
new SettingsDictionary());
|
||||||
|
}
|
||||||
|
|
||||||
var part = new TPart {
|
// build and weld the part
|
||||||
TypePartDefinition = typePartDefinition
|
var part = new TPart { TypePartDefinition = typePartDefinition };
|
||||||
};
|
|
||||||
_item.Weld(part);
|
_item.Weld(part);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Welds a part to the content item.
|
||||||
|
/// </summary>
|
||||||
public ContentItemBuilder Weld(ContentPart contentPart) {
|
public ContentItemBuilder Weld(ContentPart contentPart) {
|
||||||
_item.Weld(contentPart);
|
_item.Weld(contentPart);
|
||||||
return this;
|
return this;
|
||||||
|
@@ -27,10 +27,6 @@ namespace Orchard.ContentManagement.MetaData.Builders {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Init(ContentTypeDefinition existing) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContentTypeDefinition Build() {
|
public ContentTypeDefinition Build() {
|
||||||
return new ContentTypeDefinition(_name, _displayName, _parts, _settings);
|
return new ContentTypeDefinition(_name, _displayName, _parts, _settings);
|
||||||
}
|
}
|
||||||
@@ -92,6 +88,5 @@ namespace Orchard.ContentManagement.MetaData.Builders {
|
|||||||
return new ContentTypePartDefinition(_partDefinition, _settings);
|
return new ContentTypePartDefinition(_partDefinition, _settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -73,7 +73,6 @@ namespace Orchard.Environment.Extensions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Feature LoadFeature(FeatureDescriptor featureDescriptor) {
|
private Feature LoadFeature(FeatureDescriptor featureDescriptor) {
|
||||||
|
|
||||||
var extensionDescriptor = featureDescriptor.Extension;
|
var extensionDescriptor = featureDescriptor.Extension;
|
||||||
var featureId = featureDescriptor.Id;
|
var featureId = featureDescriptor.Id;
|
||||||
var extensionId = extensionDescriptor.Id;
|
var extensionId = extensionDescriptor.Id;
|
||||||
@@ -94,6 +93,7 @@ namespace Orchard.Environment.Extensions {
|
|||||||
Logger.Error(ex, "Error loading extension '{0}'", extensionId);
|
Logger.Error(ex, "Error loading extension '{0}'", extensionId);
|
||||||
throw new OrchardException(T("Error while loading extension '{0}'.", extensionId), ex);
|
throw new OrchardException(T("Error while loading extension '{0}'.", extensionId), ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extensionEntry == null) {
|
if (extensionEntry == null) {
|
||||||
// If the feature could not be compiled for some reason,
|
// If the feature could not be compiled for some reason,
|
||||||
// return a "null" feature, i.e. a feature with no exported types.
|
// return a "null" feature, i.e. a feature with no exported types.
|
||||||
|
@@ -42,6 +42,7 @@ namespace Orchard.Mvc {
|
|||||||
return (Type) info.Metadata["ControllerType"];
|
return (Type) info.Metadata["ControllerType"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fail as appropriate for MVC's expectations
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,6 +53,7 @@ namespace Orchard.Mvc {
|
|||||||
return controller;
|
return controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fail as appropriate for MVC's expectations
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user