Fixing some ignored UT. Adding comments. Welding content item parts conditionally.

--HG--
branch : 1.x
This commit is contained in:
andrerod
2010-12-28 19:44:14 +00:00
parent 7055183bf4
commit a1ea9c307c
14 changed files with 75 additions and 35 deletions

View File

@@ -532,13 +532,13 @@ namespace Orchard.Tests.ContentManagement {
}
[Test, Ignore("Fix pending")]
[Test]
public void ExistingTypeAndPartDefinitionShouldBeUsed() {
var alphaType = new ContentTypeDefinitionBuilder()
.Named(DefaultAlphaName)
.WithSetting("x", "1")
.WithPart("foo")
.WithPart("Flavored", part => part.WithSetting("spin", "clockwise"))
.WithPart("FlavoredPart", part => part.WithSetting("spin", "clockwise"))
.Build();
_contentDefinitionManager

View File

@@ -25,7 +25,6 @@ namespace Orchard.Tests.DisplayManagement {
CurrentTheme = new ExtensionDescriptor { Id = "Hello" }
};
builder.RegisterType<DefaultDisplayManager>().As<IDisplayManager>();
builder.RegisterType<TestShapeTableManager>().As<IShapeTableManager>();
builder.RegisterType<TestWorkContextAccessor>().As<IWorkContextAccessor>();

View File

@@ -309,10 +309,12 @@ Features:
}
}
[Test, Ignore("This assertion appears to be inconsistent with the comment in extension manager - an empty feature is returned")]
public void ExtensionManagerShouldThrowIfFeatureDoesNotExist() {
var featureDescriptor = new FeatureDescriptor { Id = "NoSuchFeature", Extension = new ExtensionDescriptor { Name = "NoSuchFeature" } };
Assert.Throws<ArgumentException>(() => _manager.LoadFeatures(new[] { featureDescriptor }));
[Test]
public void ExtensionManagerShouldReturnEmptyFeatureIfFeatureDoesNotExist() {
var featureDescriptor = new FeatureDescriptor { Id = "NoSuchFeature", Extension = new ExtensionDescriptor { Id = "NoSuchFeature" } };
Feature feature = _manager.LoadFeatures(new[] { featureDescriptor }).First();
Assert.AreEqual(featureDescriptor, feature.Descriptor);
Assert.AreEqual(0, feature.ExportedTypes.Count());
}
[Test]

View File

@@ -25,6 +25,7 @@ namespace Orchard.Tests.Mvc {
.Keyed<IController>(typeof(FooController))
.WithMetadata("ControllerType", typeof(FooController))
.InstancePerDependency();
builder.RegisterType<BarController>()
.Keyed<IController>("/bar")
.Keyed<IController>(typeof(BarController))
@@ -59,8 +60,7 @@ namespace Orchard.Tests.Mvc {
Assert.That(controller, Is.TypeOf<ReplacementFooController>());
}
[Test]
[Ignore("OrchardControllerFactory depends on metadata, calling base when no context is causing errors.")]
[Test, Ignore("OrchardControllerFactory depends on metadata, calling base when no context is causing errors.")]
public void WhenNullOrMissingContainerNormalControllerFactoryRulesShouldBeUsedAsFallback() {
var requestContext = GetRequestContext(null);
var controller = _controllerFactory.CreateController(requestContext, "foo");

View File

@@ -16,4 +16,4 @@ namespace Orchard.Tests.Stubs {
return _defaultCacheManager.GetCache<TKey, TResult>();
}
}
}
}

View File

@@ -2,6 +2,10 @@ using System;
using System.Collections.Concurrent;
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 {
private readonly ConcurrentDictionary<CacheKey, object> _caches = new ConcurrentDictionary<CacheKey, object>();
@@ -11,10 +15,17 @@ 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) {
var cacheKey = new CacheKey(component, typeof(TKey), typeof(TResult));
var result = _caches.GetOrAdd(cacheKey, k => new Cache<TKey, TResult>());
return (Cache<TKey, TResult>)result;
}
}
}
}

View File

@@ -1,15 +1,30 @@
using System;
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 {
private readonly Type _component;
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) {
_component = component;
_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>() {
return _cacheHolder.GetCache<TKey, TResult>(_component);
}

View File

@@ -10,7 +10,6 @@ namespace Orchard.ContentManagement {
_parts = new List<ContentPart>();
}
private readonly IList<ContentPart> _parts;
ContentItem IContent.ContentItem { get { return this; } }

View File

@@ -128,7 +128,6 @@ namespace Orchard.ContentManagement {
return contentItem;
}
// allocate instance and set record property
contentItem = New(versionRecord.ContentItemRecord.ContentType.Name);
contentItem.VersionRecord = versionRecord;
@@ -398,13 +397,8 @@ namespace Orchard.ContentManagement {
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>>> {
readonly Func<string, CallSite<Func<CallSite, object, object>>> _valueFactory;

View File

@@ -2,12 +2,21 @@
using Orchard.ContentManagement.MetaData.Models;
namespace Orchard.ContentManagement.Handlers {
/// <summary>
/// Builds a contentitem based on its the type definition (<seealso cref="ContentTypeDefinition"/>).
/// </summary>
public class ContentItemBuilder {
private readonly ContentTypeDefinition _definition;
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) {
_definition = definition;
// TODO: could / should be done on the build method ?
_item = new ContentItem {
ContentType = definition.Name,
TypeDefinition = definition
@@ -18,23 +27,37 @@ namespace Orchard.ContentManagement.Handlers {
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() {
var partName = typeof(TPart).Name;
var typePartDefinition = _definition.Parts.FirstOrDefault(p => p.PartDefinition.Name == partName);
if (typePartDefinition == null) {
typePartDefinition = new ContentTypePartDefinition(
new ContentPartDefinition(partName),
new SettingsDictionary());
// 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 part = new TPart {
TypePartDefinition = typePartDefinition
};
// obtain the type definition for the part
var typePartDefinition = _definition.Parts.FirstOrDefault(p => p.PartDefinition.Name == partName);
if (typePartDefinition == null) {
// If the content item's type definition does not define the part; use an empty type definition.
typePartDefinition = new ContentTypePartDefinition(
new ContentPartDefinition(partName),
new SettingsDictionary());
}
// build and weld the part
var part = new TPart { TypePartDefinition = typePartDefinition };
_item.Weld(part);
}
return this;
}
/// <summary>
/// Welds a part to the content item.
/// </summary>
public ContentItemBuilder Weld(ContentPart contentPart) {
_item.Weld(contentPart);
return this;

View File

@@ -27,10 +27,6 @@ namespace Orchard.ContentManagement.MetaData.Builders {
}
}
private void Init(ContentTypeDefinition existing) {
}
public ContentTypeDefinition Build() {
return new ContentTypeDefinition(_name, _displayName, _parts, _settings);
}
@@ -92,6 +88,5 @@ namespace Orchard.ContentManagement.MetaData.Builders {
return new ContentTypePartDefinition(_partDefinition, _settings);
}
}
}
}

View File

@@ -17,4 +17,4 @@ namespace Orchard.ContentManagement.MetaData.Builders {
return this;
}
}
}
}

View File

@@ -73,7 +73,6 @@ namespace Orchard.Environment.Extensions {
}
private Feature LoadFeature(FeatureDescriptor featureDescriptor) {
var extensionDescriptor = featureDescriptor.Extension;
var featureId = featureDescriptor.Id;
var extensionId = extensionDescriptor.Id;
@@ -94,6 +93,7 @@ namespace Orchard.Environment.Extensions {
Logger.Error(ex, "Error loading extension '{0}'", extensionId);
throw new OrchardException(T("Error while loading extension '{0}'.", extensionId), ex);
}
if (extensionEntry == null) {
// If the feature could not be compiled for some reason,
// return a "null" feature, i.e. a feature with no exported types.

View File

@@ -42,6 +42,7 @@ namespace Orchard.Mvc {
return (Type) info.Metadata["ControllerType"];
}
// fail as appropriate for MVC's expectations
return null;
}
@@ -52,6 +53,7 @@ namespace Orchard.Mvc {
return controller;
}
// fail as appropriate for MVC's expectations
return null;
}