mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 19:04:51 +08:00
Building out composition strategy
Four main component types are populated from topology Additional information for table/area/controller name populated Some core types for records added automatically --HG-- branch : dev
This commit is contained in:
@@ -48,7 +48,7 @@ namespace Orchard.Tests.Data.Builders {
|
||||
[Test]
|
||||
public void SQLiteSchemaShouldBeGeneratedAndUsable() {
|
||||
var recordDescriptors = new[] {
|
||||
new RecordDescriptor {Prefix = "Hello", Type = typeof (Foo)}
|
||||
new RecordDescriptor_Obsolete {Prefix = "Hello", Type = typeof (FooRecord)}
|
||||
};
|
||||
var manager = (ISessionFactoryBuilder)new SessionFactoryBuilder();
|
||||
var sessionFactory = manager.BuildSessionFactory(new SessionFactoryParameters {
|
||||
@@ -60,7 +60,7 @@ namespace Orchard.Tests.Data.Builders {
|
||||
|
||||
|
||||
var session = sessionFactory.OpenSession();
|
||||
var foo = new Foo { Name = "hi there" };
|
||||
var foo = new FooRecord { Name = "hi there" };
|
||||
session.Save(foo);
|
||||
session.Flush();
|
||||
session.Close();
|
||||
@@ -77,7 +77,7 @@ namespace Orchard.Tests.Data.Builders {
|
||||
CreateSqlServerDatabase(databasePath);
|
||||
|
||||
var recordDescriptors = new[] {
|
||||
new RecordDescriptor {Prefix = "Hello", Type = typeof (Foo)}
|
||||
new RecordDescriptor_Obsolete {Prefix = "Hello", Type = typeof (FooRecord)}
|
||||
};
|
||||
|
||||
var manager = (ISessionFactoryBuilder)new SessionFactoryBuilder();
|
||||
@@ -92,7 +92,7 @@ namespace Orchard.Tests.Data.Builders {
|
||||
|
||||
|
||||
var session = sessionFactory.OpenSession();
|
||||
var foo = new Foo { Name = "hi there" };
|
||||
var foo = new FooRecord { Name = "hi there" };
|
||||
session.Save(foo);
|
||||
session.Flush();
|
||||
session.Close();
|
||||
|
@@ -19,9 +19,9 @@ namespace Orchard.Tests.Data {
|
||||
|
||||
[SetUp]
|
||||
public void Init() {
|
||||
_sessionFactory = DataUtility.CreateSessionFactory(_databaseFilePath, typeof(Foo));
|
||||
_sessionFactory = DataUtility.CreateSessionFactory(_databaseFilePath, typeof(FooRecord));
|
||||
_session = _sessionFactory.OpenSession();
|
||||
_fooRepos = new Repository<Foo>(new StubLocator(_session));
|
||||
_fooRepos = new Repository<FooRecord>(new StubLocator(_session));
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
@@ -36,15 +36,15 @@ namespace Orchard.Tests.Data {
|
||||
|
||||
#endregion
|
||||
|
||||
private IRepository<Foo> _fooRepos;
|
||||
private IRepository<FooRecord> _fooRepos;
|
||||
private ISession _session;
|
||||
private string _databaseFilePath;
|
||||
private ISessionFactory _sessionFactory;
|
||||
|
||||
private void CreateThreeFoos() {
|
||||
_fooRepos.Create(new Foo { Name = "one" });
|
||||
_fooRepos.Create(new Foo { Name = "two" });
|
||||
_fooRepos.Create(new Foo { Name = "three" });
|
||||
_fooRepos.Create(new FooRecord { Name = "one" });
|
||||
_fooRepos.Create(new FooRecord { Name = "two" });
|
||||
_fooRepos.Create(new FooRecord { Name = "three" });
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -121,7 +121,7 @@ namespace Orchard.Tests.Data {
|
||||
|
||||
// If look at the "LinqOrderByCanBeUsedToControlResults", you will see this query
|
||||
// works fine is the static type of "foos" is "IEnumerable<Foo>"...
|
||||
IOrderedQueryable<Foo> foos =
|
||||
IOrderedQueryable<FooRecord> foos =
|
||||
from f in _fooRepos.Table
|
||||
where f.Name == "two" || f.Name == "three"
|
||||
orderby f.Name, f.Id ascending
|
||||
@@ -138,7 +138,7 @@ namespace Orchard.Tests.Data {
|
||||
public void LinqOrderByCanBeUsedToControlResults() {
|
||||
CreateThreeFoos();
|
||||
|
||||
IEnumerable<Foo> foos =
|
||||
IEnumerable<FooRecord> foos =
|
||||
from f in _fooRepos.Table
|
||||
where f.Name == "two" || f.Name == "three"
|
||||
orderby f.Name, f.Id ascending
|
||||
@@ -152,7 +152,7 @@ namespace Orchard.Tests.Data {
|
||||
[Test]
|
||||
public void RangeShouldSliceResults() {
|
||||
for (var x = 0; x != 40; ++x) {
|
||||
_fooRepos.Create(new Foo { Name = x.ToString().PadLeft(8, '0') });
|
||||
_fooRepos.Create(new FooRecord { Name = x.ToString().PadLeft(8, '0') });
|
||||
}
|
||||
|
||||
var foos = _fooRepos.Fetch(
|
||||
@@ -167,7 +167,7 @@ namespace Orchard.Tests.Data {
|
||||
|
||||
[Test]
|
||||
public void RepositoryCanCreateFetchAndDelete() {
|
||||
var foo1 = new Foo { Name = "yadda" };
|
||||
var foo1 = new FooRecord { Name = "yadda" };
|
||||
_fooRepos.Create(foo1);
|
||||
|
||||
var foo2 = _fooRepos.Get(foo1.Id);
|
||||
|
@@ -19,7 +19,7 @@ namespace Orchard.Tests {
|
||||
//var persistenceModel = AutoMap.Source(new Types(types))
|
||||
// .Alterations(alt => AddAlterations(alt, types))
|
||||
// .Conventions.AddFromAssemblyOf<DataModule>();
|
||||
var persistenceModel = AbstractBuilder.CreatePersistenceModel(types.Select(t => new RecordDescriptor { Prefix = "Test", Type = t }));
|
||||
var persistenceModel = AbstractBuilder.CreatePersistenceModel(types.Select(t => new RecordDescriptor_Obsolete { Prefix = "Test", Type = t }));
|
||||
|
||||
return Fluently.Configure()
|
||||
.Database(SQLiteConfiguration.Standard.UsingFile(fileName).ShowSql())
|
||||
|
@@ -7,11 +7,13 @@ using Autofac;
|
||||
using Autofac.Core;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Orchard.ContentManagement.Records;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Environment.Topology;
|
||||
using Orchard.Environment.Topology.Models;
|
||||
using Orchard.Tests.Environment.Utility;
|
||||
using Orchard.Tests.Records;
|
||||
using Orchard.Tests.Utility;
|
||||
|
||||
namespace Orchard.Tests.Environment {
|
||||
@@ -45,7 +47,7 @@ namespace Orchard.Tests.Environment {
|
||||
|
||||
private IEnumerable<Feature> StubLoadFeatures(IEnumerable<FeatureDescriptor> featureDescriptors) {
|
||||
return featureDescriptors.Select(featureDescriptor => new Feature {
|
||||
FeatureDescriptor = featureDescriptor,
|
||||
Descriptor = featureDescriptor,
|
||||
ExportedTypes = _featureTypes[featureDescriptor.Name]
|
||||
});
|
||||
}
|
||||
@@ -80,11 +82,11 @@ namespace Orchard.Tests.Environment {
|
||||
|
||||
var foo = topology.Dependencies.SingleOrDefault(t => t.Type == typeof(FooService1));
|
||||
Assert.That(foo, Is.Not.Null);
|
||||
Assert.That(foo.Feature.FeatureDescriptor.Name, Is.EqualTo("Foo"));
|
||||
Assert.That(foo.Feature.Descriptor.Name, Is.EqualTo("Foo"));
|
||||
|
||||
var bar = topology.Dependencies.SingleOrDefault(t => t.Type == typeof(BarService1));
|
||||
Assert.That(bar, Is.Not.Null);
|
||||
Assert.That(bar.Feature.FeatureDescriptor.Name, Is.EqualTo("Bar"));
|
||||
Assert.That(bar.Feature.Descriptor.Name, Is.EqualTo("Bar"));
|
||||
}
|
||||
|
||||
public interface IFooService : IDependency {
|
||||
@@ -141,8 +143,8 @@ namespace Orchard.Tests.Environment {
|
||||
var alpha = topology.Modules.Single(x => x.Type == typeof (AlphaModule));
|
||||
var beta = topology.Modules.Single(x => x.Type == typeof (BetaModule));
|
||||
|
||||
Assert.That(alpha.Feature.FeatureDescriptor.Name, Is.EqualTo("Foo"));
|
||||
Assert.That(beta.Feature.FeatureDescriptor.Name, Is.EqualTo("Bar"));
|
||||
Assert.That(alpha.Feature.Descriptor.Name, Is.EqualTo("Foo"));
|
||||
Assert.That(beta.Feature.Descriptor.Name, Is.EqualTo("Bar"));
|
||||
}
|
||||
|
||||
public class AlphaModule : Module {
|
||||
@@ -155,11 +157,11 @@ namespace Orchard.Tests.Environment {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ControllersArePutIntoTopology() {
|
||||
public void ControllersArePutIntoTopologyWithAreaAndControllerName() {
|
||||
var descriptor = Build.TopologyDescriptor().WithFeatures("Foo Plus", "Bar Minus");
|
||||
|
||||
_extensionDescriptors = new[] {
|
||||
Build.ExtensionDescriptor("Foo").WithFeatures("Foo", "Foo Plus"),
|
||||
Build.ExtensionDescriptor("MyCompany.Foo", "Foo").WithFeatures("Foo", "Foo Plus"),
|
||||
Build.ExtensionDescriptor("Bar").WithFeatures("Bar", "Bar Minus"),
|
||||
};
|
||||
|
||||
@@ -175,15 +177,15 @@ namespace Orchard.Tests.Environment {
|
||||
var delta = topology.Controllers.Single(x => x.Type == typeof (DeltaController));
|
||||
var epsilon = topology.Controllers.Single(x => x.Type == typeof (EpsilonController));
|
||||
|
||||
Assert.That(gamma.Feature.FeatureDescriptor.Name, Is.EqualTo("Foo Plus"));
|
||||
Assert.That(gamma.AreaName, Is.EqualTo("Foo"));
|
||||
Assert.That(gamma.Feature.Descriptor.Name, Is.EqualTo("Foo Plus"));
|
||||
Assert.That(gamma.AreaName, Is.EqualTo("MyCompany.Foo"));
|
||||
Assert.That(gamma.ControllerName, Is.EqualTo("Gamma"));
|
||||
|
||||
Assert.That(delta.Feature.FeatureDescriptor.Name, Is.EqualTo("Bar Minus"));
|
||||
Assert.That(delta.Feature.Descriptor.Name, Is.EqualTo("Bar Minus"));
|
||||
Assert.That(delta.AreaName, Is.EqualTo("Bar"));
|
||||
Assert.That(delta.ControllerName, Is.EqualTo("Delta"));
|
||||
|
||||
Assert.That(epsilon.Feature.FeatureDescriptor.Name, Is.EqualTo("Bar Minus"));
|
||||
Assert.That(epsilon.Feature.Descriptor.Name, Is.EqualTo("Bar Minus"));
|
||||
Assert.That(epsilon.AreaName, Is.EqualTo("Bar"));
|
||||
Assert.That(epsilon.ControllerName, Is.EqualTo("Epsilon"));
|
||||
}
|
||||
@@ -203,47 +205,54 @@ namespace Orchard.Tests.Environment {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void RecordsArePutIntoTopologyWithTableName() {
|
||||
var descriptor = Build.TopologyDescriptor().WithFeatures("Foo Plus", "Bar", "Bar Minus");
|
||||
|
||||
static class Build {
|
||||
|
||||
public static ShellTopologyDescriptor TopologyDescriptor() {
|
||||
var descriptor = new ShellTopologyDescriptor {
|
||||
EnabledFeatures = Enumerable.Empty<TopologyFeature>(),
|
||||
Parameters = Enumerable.Empty<TopologyParameter>(),
|
||||
_extensionDescriptors = new[] {
|
||||
Build.ExtensionDescriptor("MyCompany.Foo", "Foo").WithFeatures("Foo", "Foo Plus"),
|
||||
Build.ExtensionDescriptor("Bar").WithFeatures("Bar", "Bar Minus"),
|
||||
};
|
||||
return descriptor;
|
||||
|
||||
_featureTypes["Foo"] = Enumerable.Empty<Type>();
|
||||
_featureTypes["Foo Plus"] = new[] { typeof(FooRecord) };
|
||||
_featureTypes["Bar"] = new[] { typeof(BarRecord) };
|
||||
_featureTypes["Bar Minus"] = Enumerable.Empty<Type>();
|
||||
|
||||
var compositionStrategy = _container.Resolve<ICompositionStrategy>();
|
||||
var topology = compositionStrategy.Compose(descriptor);
|
||||
|
||||
var foo = topology.Records.Single(x => x.Type == typeof (FooRecord));
|
||||
var bar = topology.Records.Single(x => x.Type == typeof (BarRecord));
|
||||
|
||||
Assert.That(foo.Feature.Descriptor.Name, Is.EqualTo("Foo Plus"));
|
||||
Assert.That(foo.TableName, Is.EqualTo("MyCompany_Foo_FooRecord"));
|
||||
|
||||
Assert.That(bar.Feature.Descriptor.Name, Is.EqualTo("Bar"));
|
||||
Assert.That(bar.TableName, Is.EqualTo("Bar_BarRecord"));
|
||||
}
|
||||
|
||||
public static ShellTopologyDescriptor WithFeatures(this ShellTopologyDescriptor descriptor, params string[] names) {
|
||||
descriptor.EnabledFeatures = descriptor.EnabledFeatures.Concat(
|
||||
names.Select(name => new TopologyFeature { Name = name }));
|
||||
[Test]
|
||||
public void CoreRecordsAreAddedAutomatically() {
|
||||
var descriptor = Build.TopologyDescriptor();
|
||||
|
||||
var compositionStrategy = _container.Resolve<ICompositionStrategy>();
|
||||
var topology = compositionStrategy.Compose(descriptor);
|
||||
|
||||
return descriptor;
|
||||
}
|
||||
var ct = topology.Records.Single(x => x.Type == typeof (ContentTypeRecord));
|
||||
var ci = topology.Records.Single(x => x.Type == typeof (ContentItemRecord));
|
||||
var civ = topology.Records.Single(x => x.Type == typeof (ContentItemVersionRecord));
|
||||
|
||||
Assert.That(ct.Feature.Descriptor.Name, Is.EqualTo("Core"));
|
||||
Assert.That(ct.TableName, Is.EqualTo("Core_ContentTypeRecord"));
|
||||
|
||||
public static ShellTopologyDescriptor WithParameter<TComponent>(this ShellTopologyDescriptor descriptor, string name, string value) {
|
||||
descriptor.Parameters = descriptor.Parameters.Concat(
|
||||
new[] { new TopologyParameter { Component = typeof(TComponent).FullName, Name = name, Value = value } });
|
||||
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
public static ExtensionDescriptor ExtensionDescriptor(string name) {
|
||||
var descriptor = new ExtensionDescriptor {
|
||||
Name = name,
|
||||
DisplayName = name,
|
||||
Features = Enumerable.Empty<FeatureDescriptor>(),
|
||||
};
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
public static ExtensionDescriptor WithFeatures(this ExtensionDescriptor descriptor, params string[] names) {
|
||||
descriptor.Features = descriptor.Features.Concat(
|
||||
names.Select(name => new FeatureDescriptor() { Name = name }));
|
||||
|
||||
return descriptor;
|
||||
}
|
||||
Assert.That(ci.Feature.Descriptor.Name, Is.EqualTo("Core"));
|
||||
Assert.That(ci.TableName, Is.EqualTo("Core_ContentItemRecord"));
|
||||
|
||||
Assert.That(civ.Feature.Descriptor.Name, Is.EqualTo("Core"));
|
||||
Assert.That(civ.TableName, Is.EqualTo("Core_ContentItemVersionRecord"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -118,8 +118,8 @@ namespace Orchard.Tests.Environment {
|
||||
}
|
||||
|
||||
public class StubCompositionStrategy : ICompositionStrategy_Obsolete, ICompositionStrategy {
|
||||
public IEnumerable<RecordDescriptor> GetRecordDescriptors() {
|
||||
return Enumerable.Empty<RecordDescriptor>();
|
||||
public IEnumerable<RecordDescriptor_Obsolete> GetRecordDescriptors_Obsolete() {
|
||||
return Enumerable.Empty<RecordDescriptor_Obsolete>();
|
||||
}
|
||||
|
||||
public ShellTopology Compose(ShellTopologyDescriptor descriptor) {
|
||||
|
@@ -44,10 +44,10 @@ namespace Orchard.Tests.Environment.Extensions {
|
||||
var stream = parser.ParseYamlStream(new TextInput(Manifests[name]), out success);
|
||||
if (success) {
|
||||
return new ParseResult {
|
||||
Location = "~/InMemory",
|
||||
Name = name,
|
||||
YamlDocument = stream.Documents.Single()
|
||||
};
|
||||
Location = "~/InMemory",
|
||||
Name = name,
|
||||
YamlDocument = stream.Documents.Single()
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -113,14 +113,14 @@ features:
|
||||
Assert.That(descriptor.OrchardVersion, Is.EqualTo("1"));
|
||||
Assert.That(descriptor.Features.Count(), Is.EqualTo(1));
|
||||
Assert.That(descriptor.Features.First().Name, Is.EqualTo("SuperWiki"));
|
||||
Assert.That(descriptor.Features.First().ExtensionName, Is.EqualTo("SuperWiki"));
|
||||
Assert.That(descriptor.Features.First().Extension.Name, Is.EqualTo("SuperWiki"));
|
||||
Assert.That(descriptor.Features.First().Description, Is.EqualTo("My super wiki module for Orchard."));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExtensionDescriptorsShouldBeParsedForCompleteModuleTxt() {
|
||||
|
||||
_folders.Manifests.Add("AnotherWiki", @"
|
||||
_folders.Manifests.Add("MyCompany.AnotherWiki", @"
|
||||
name: AnotherWiki
|
||||
author: Coder Notaprogrammer
|
||||
website: http://anotherwiki.codeplex.com
|
||||
@@ -146,7 +146,8 @@ features:
|
||||
");
|
||||
|
||||
var descriptor = _manager.AvailableExtensions().Single();
|
||||
Assert.That(descriptor.Name, Is.EqualTo("AnotherWiki"));
|
||||
Assert.That(descriptor.Name, Is.EqualTo("MyCompany.AnotherWiki"));
|
||||
Assert.That(descriptor.DisplayName, Is.EqualTo("AnotherWiki"));
|
||||
Assert.That(descriptor.Author, Is.EqualTo("Coder Notaprogrammer"));
|
||||
Assert.That(descriptor.WebSite, Is.EqualTo("http://anotherwiki.codeplex.com"));
|
||||
Assert.That(descriptor.Version, Is.EqualTo("1.2.3"));
|
||||
@@ -155,7 +156,7 @@ features:
|
||||
foreach (var featureDescriptor in descriptor.Features) {
|
||||
switch (featureDescriptor.Name) {
|
||||
case "AnotherWiki":
|
||||
Assert.That(featureDescriptor.ExtensionName, Is.EqualTo("AnotherWiki"));
|
||||
Assert.That(featureDescriptor.Extension, Is.SameAs(descriptor));
|
||||
Assert.That(featureDescriptor.Description, Is.EqualTo("My super wiki module for Orchard."));
|
||||
Assert.That(featureDescriptor.Category, Is.EqualTo("Content types"));
|
||||
Assert.That(featureDescriptor.Dependencies.Count(), Is.EqualTo(2));
|
||||
@@ -163,7 +164,7 @@ features:
|
||||
Assert.That(featureDescriptor.Dependencies.Contains("Search"));
|
||||
break;
|
||||
case "AnotherWiki Editor":
|
||||
Assert.That(featureDescriptor.ExtensionName, Is.EqualTo("AnotherWiki"));
|
||||
Assert.That(featureDescriptor.Extension, Is.SameAs(descriptor));
|
||||
Assert.That(featureDescriptor.Description, Is.EqualTo("A rich editor for wiki contents."));
|
||||
Assert.That(featureDescriptor.Category, Is.EqualTo("Input methods"));
|
||||
Assert.That(featureDescriptor.Dependencies.Count(), Is.EqualTo(2));
|
||||
@@ -171,7 +172,7 @@ features:
|
||||
Assert.That(featureDescriptor.Dependencies.Contains("AnotherWiki"));
|
||||
break;
|
||||
case "AnotherWiki DistributionList":
|
||||
Assert.That(featureDescriptor.ExtensionName, Is.EqualTo("AnotherWiki"));
|
||||
Assert.That(featureDescriptor.Extension, Is.SameAs(descriptor));
|
||||
Assert.That(featureDescriptor.Description, Is.EqualTo("Sends e-mail alerts when wiki contents gets published."));
|
||||
Assert.That(featureDescriptor.Category, Is.EqualTo("Email"));
|
||||
Assert.That(featureDescriptor.Dependencies.Count(), Is.EqualTo(2));
|
||||
@@ -179,7 +180,7 @@ features:
|
||||
Assert.That(featureDescriptor.Dependencies.Contains("Email Subscriptions"));
|
||||
break;
|
||||
case "AnotherWiki Captcha":
|
||||
Assert.That(featureDescriptor.ExtensionName, Is.EqualTo("AnotherWiki"));
|
||||
Assert.That(featureDescriptor.Extension, Is.SameAs(descriptor));
|
||||
Assert.That(featureDescriptor.Description, Is.EqualTo("Kills spam. Or makes it zombie-like."));
|
||||
Assert.That(featureDescriptor.Category, Is.EqualTo("Spam"));
|
||||
Assert.That(featureDescriptor.Dependencies.Count(), Is.EqualTo(2));
|
||||
@@ -223,16 +224,17 @@ features:
|
||||
[Test]
|
||||
public void ExtensionManagerTestFeatureAttribute() {
|
||||
var extensionManager = new Moq.Mock<IExtensionManager>();
|
||||
extensionManager.Setup(x => x.ActiveExtensions_Obsolete()).Returns(new[] {
|
||||
new ExtensionEntry {
|
||||
Descriptor = new ExtensionDescriptor {
|
||||
Name = "Module",
|
||||
Features = new[] {
|
||||
new FeatureDescriptor { Name = "Module", ExtensionName = "Module" },
|
||||
new FeatureDescriptor { Name = "TestFeature", ExtensionName = "Module" }
|
||||
}},
|
||||
ExportedTypes = new[] { typeof(Alpha), typeof(Beta), typeof(Phi) }
|
||||
}});
|
||||
var extensionEntry = new ExtensionEntry {
|
||||
Descriptor = new ExtensionDescriptor { Name = "Module"},
|
||||
ExportedTypes = new[] { typeof(Alpha), typeof(Beta), typeof(Phi) }
|
||||
};
|
||||
extensionEntry.Descriptor.Features = new[] {
|
||||
new FeatureDescriptor
|
||||
{Name = "Module", Extension = extensionEntry.Descriptor},
|
||||
new FeatureDescriptor
|
||||
{Name = "TestFeature", Extension = extensionEntry.Descriptor}
|
||||
};
|
||||
extensionManager.Setup(x => x.ActiveExtensions_Obsolete()).Returns(new[] {extensionEntry});
|
||||
|
||||
foreach (var type in extensionManager.Object.ActiveExtensions_Obsolete().SelectMany(x => x.ExportedTypes)) {
|
||||
foreach (OrchardFeatureAttribute featureAttribute in type.GetCustomAttributes(typeof(OrchardFeatureAttribute), false)) {
|
||||
|
50
src/Orchard.Tests/Environment/Utility/Build.cs
Normal file
50
src/Orchard.Tests/Environment/Utility/Build.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System.Linq;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Environment.Topology.Models;
|
||||
|
||||
namespace Orchard.Tests.Environment.Utility {
|
||||
static class Build {
|
||||
|
||||
public static ShellTopologyDescriptor TopologyDescriptor() {
|
||||
var descriptor = new ShellTopologyDescriptor {
|
||||
EnabledFeatures = Enumerable.Empty<TopologyFeature>(),
|
||||
Parameters = Enumerable.Empty<TopologyParameter>(),
|
||||
};
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
public static ShellTopologyDescriptor WithFeatures(this ShellTopologyDescriptor descriptor, params string[] names) {
|
||||
descriptor.EnabledFeatures = descriptor.EnabledFeatures.Concat(
|
||||
names.Select(name => new TopologyFeature { Name = name }));
|
||||
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
public static ShellTopologyDescriptor WithParameter<TComponent>(this ShellTopologyDescriptor descriptor, string name, string value) {
|
||||
descriptor.Parameters = descriptor.Parameters.Concat(
|
||||
new[] { new TopologyParameter { Component = typeof(TComponent).FullName, Name = name, Value = value } });
|
||||
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
public static ExtensionDescriptor ExtensionDescriptor(string name, string displayName) {
|
||||
var descriptor = new ExtensionDescriptor {
|
||||
Name = name,
|
||||
DisplayName = displayName,
|
||||
Features = Enumerable.Empty<FeatureDescriptor>(),
|
||||
};
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
public static ExtensionDescriptor ExtensionDescriptor(string name) {
|
||||
return ExtensionDescriptor(name, name);
|
||||
}
|
||||
|
||||
public static ExtensionDescriptor WithFeatures(this ExtensionDescriptor descriptor, params string[] names) {
|
||||
descriptor.Features = descriptor.Features.Concat(
|
||||
names.Select(name => new FeatureDescriptor { Extension=descriptor , Name = name, }));
|
||||
|
||||
return descriptor;
|
||||
}
|
||||
}
|
||||
}
|
@@ -32,7 +32,7 @@ namespace Orchard.Tests {
|
||||
|
||||
[Test]
|
||||
public void CreatingSchemaForStatedClassesInTempFile() {
|
||||
var types = new Types(typeof (Foo), typeof (Bar));
|
||||
var types = new Types(typeof (FooRecord), typeof (BarRecord));
|
||||
|
||||
var sessionFactory = Fluently.Configure()
|
||||
.Database(SQLiteConfiguration.Standard.UsingFile("temp"))
|
||||
@@ -41,12 +41,12 @@ namespace Orchard.Tests {
|
||||
.BuildSessionFactory();
|
||||
|
||||
var session = sessionFactory.OpenSession();
|
||||
session.Save(new Foo {Name = "Hello"});
|
||||
session.Save(new Bar {Height = 3, Width = 4.5m});
|
||||
session.Save(new FooRecord {Name = "Hello"});
|
||||
session.Save(new BarRecord {Height = 3, Width = 4.5m});
|
||||
session.Close();
|
||||
|
||||
session = sessionFactory.OpenSession();
|
||||
var foos = session.CreateCriteria<Foo>().List();
|
||||
var foos = session.CreateCriteria<FooRecord>().List();
|
||||
Assert.That(foos.Count, Is.EqualTo(1));
|
||||
Assert.That(foos, Has.All.Property("Name").EqualTo("Hello"));
|
||||
session.Close();
|
||||
@@ -64,17 +64,17 @@ namespace Orchard.Tests {
|
||||
|
||||
[Test]
|
||||
public void UsingDataUtilityToBuildSessionFactory() {
|
||||
var factory = DataUtility.CreateSessionFactory(typeof (Foo), typeof (Bar));
|
||||
var factory = DataUtility.CreateSessionFactory(typeof (FooRecord), typeof (BarRecord));
|
||||
|
||||
var session = factory.OpenSession();
|
||||
var foo1 = new Foo {Name = "world"};
|
||||
var foo1 = new FooRecord {Name = "world"};
|
||||
session.Save(foo1);
|
||||
session.Close();
|
||||
|
||||
session = factory.OpenSession();
|
||||
var foo2 = session.CreateCriteria<Foo>()
|
||||
var foo2 = session.CreateCriteria<FooRecord>()
|
||||
.Add(Restrictions.Eq("Name", "world"))
|
||||
.List<Foo>().Single();
|
||||
.List<FooRecord>().Single();
|
||||
session.Close();
|
||||
|
||||
Assert.That(foo1, Is.Not.SameAs(foo2));
|
||||
|
@@ -11,11 +11,11 @@ namespace Orchard.Tests {
|
||||
|
||||
[SetUp]
|
||||
public void Init() {
|
||||
var sessionFactory = DataUtility.CreateSessionFactory(typeof (Foo));
|
||||
var sessionFactory = DataUtility.CreateSessionFactory(typeof (FooRecord));
|
||||
using (var session = sessionFactory.OpenSession()) {
|
||||
session.Save(new Foo {Name = "one"});
|
||||
session.Save(new Foo {Name = "two"});
|
||||
session.Save(new Foo {Name = "three"});
|
||||
session.Save(new FooRecord {Name = "one"});
|
||||
session.Save(new FooRecord {Name = "two"});
|
||||
session.Save(new FooRecord {Name = "three"});
|
||||
}
|
||||
_session = sessionFactory.OpenSession();
|
||||
}
|
||||
@@ -31,7 +31,7 @@ namespace Orchard.Tests {
|
||||
|
||||
[Test]
|
||||
public void WhereClauseShouldLimitResults() {
|
||||
var foos = from f in _session.Linq<Foo>() where f.Name == "two" || f.Name == "one" select f;
|
||||
var foos = from f in _session.Linq<FooRecord>() where f.Name == "two" || f.Name == "one" select f;
|
||||
|
||||
Assert.That(foos.Count(), Is.EqualTo(2));
|
||||
Assert.That(foos, Has.Some.Property("Name").EqualTo("one"));
|
||||
|
@@ -157,6 +157,7 @@
|
||||
<Compile Include="Data\RepositoryTests.cs" />
|
||||
<Compile Include="Data\StubLocator.cs" />
|
||||
<Compile Include="Environment\AutofacUtil\DynamicProxy2\DynamicProxyTests.cs" />
|
||||
<Compile Include="Environment\Utility\Build.cs" />
|
||||
<Compile Include="Environment\Configuration\AppDataFolderTests.cs" />
|
||||
<Compile Include="Environment\Configuration\DefaultTenantManagerTests.cs" />
|
||||
<Compile Include="Environment\DefaultCompositionStrategyTests.cs" />
|
||||
@@ -194,8 +195,8 @@
|
||||
<Compile Include="FakeTests.cs" />
|
||||
<Compile Include="FluentDbTests.cs" />
|
||||
<Compile Include="LinqToNHibernateTests.cs" />
|
||||
<Compile Include="Records\Bar.cs" />
|
||||
<Compile Include="Records\Foo.cs" />
|
||||
<Compile Include="Records\BarRecord.cs" />
|
||||
<Compile Include="Records\FooRecord.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Stubs\StubHttpContext.cs" />
|
||||
<Compile Include="UI\Navigation\MenuItemComparerTests.cs" />
|
||||
|
@@ -1,5 +1,5 @@
|
||||
namespace Orchard.Tests.Records {
|
||||
public class Bar {
|
||||
public class BarRecord {
|
||||
public virtual int Id { get; set; }
|
||||
public virtual decimal Height { get; set; }
|
||||
public virtual decimal Width { get; set; }
|
@@ -1,5 +1,5 @@
|
||||
namespace Orchard.Tests.Records {
|
||||
public class Foo {
|
||||
public class FooRecord {
|
||||
public virtual int Id { get; set; }
|
||||
public virtual string Name { get; set; }
|
||||
}
|
@@ -12,14 +12,14 @@ using Orchard.Environment;
|
||||
|
||||
namespace Orchard.ContentManagement.Records {
|
||||
class ContentItemAlteration : IAutoMappingAlteration {
|
||||
private readonly IEnumerable<RecordDescriptor> _recordDescriptors;
|
||||
private readonly IEnumerable<RecordDescriptor_Obsolete> _recordDescriptors;
|
||||
|
||||
[UsedImplicitly]
|
||||
public ContentItemAlteration() {
|
||||
_recordDescriptors = Enumerable.Empty<RecordDescriptor>();
|
||||
_recordDescriptors = Enumerable.Empty<RecordDescriptor_Obsolete>();
|
||||
}
|
||||
|
||||
public ContentItemAlteration(IEnumerable<RecordDescriptor> recordDescriptors) {
|
||||
public ContentItemAlteration(IEnumerable<RecordDescriptor_Obsolete> recordDescriptors) {
|
||||
_recordDescriptors = recordDescriptors;
|
||||
}
|
||||
|
||||
|
@@ -41,7 +41,7 @@ namespace Orchard.Data.Builders {
|
||||
}
|
||||
}
|
||||
|
||||
public static AutoPersistenceModel CreatePersistenceModel(IEnumerable<RecordDescriptor> recordDescriptors) {
|
||||
public static AutoPersistenceModel CreatePersistenceModel(IEnumerable<RecordDescriptor_Obsolete> recordDescriptors) {
|
||||
return AutoMap.Source(new TypeSource(recordDescriptors))
|
||||
// Ensure that namespaces of types are never auto-imported, so that
|
||||
// identical type names from different namespaces can be mapped without ambiguity
|
||||
@@ -58,9 +58,9 @@ namespace Orchard.Data.Builders {
|
||||
}
|
||||
|
||||
class TypeSource : ITypeSource {
|
||||
private readonly IEnumerable<RecordDescriptor> _recordDescriptors;
|
||||
private readonly IEnumerable<RecordDescriptor_Obsolete> _recordDescriptors;
|
||||
|
||||
public TypeSource(IEnumerable<RecordDescriptor> recordDescriptors) { _recordDescriptors = recordDescriptors; }
|
||||
public TypeSource(IEnumerable<RecordDescriptor_Obsolete> recordDescriptors) { _recordDescriptors = recordDescriptors; }
|
||||
|
||||
public IEnumerable<Type> GetTypes() { return _recordDescriptors.Select(descriptor => descriptor.Type); }
|
||||
}
|
||||
|
@@ -16,6 +16,6 @@ namespace Orchard.Data.Builders {
|
||||
public bool CreateDatabase { get; set; }
|
||||
public bool UpdateSchema { get; set; }
|
||||
|
||||
public IEnumerable<RecordDescriptor> RecordDescriptors { get; set; }
|
||||
public IEnumerable<RecordDescriptor_Obsolete> RecordDescriptors { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -6,9 +6,9 @@ using Orchard.Environment;
|
||||
|
||||
namespace Orchard.Data.Conventions {
|
||||
public class RecordTableNameConvention : IClassConvention {
|
||||
private readonly IEnumerable<RecordDescriptor> _descriptors;
|
||||
private readonly IEnumerable<RecordDescriptor_Obsolete> _descriptors;
|
||||
|
||||
public RecordTableNameConvention(IEnumerable<RecordDescriptor> descriptors) {
|
||||
public RecordTableNameConvention(IEnumerable<RecordDescriptor_Obsolete> descriptors) {
|
||||
_descriptors = descriptors;
|
||||
}
|
||||
|
||||
|
@@ -77,7 +77,7 @@ namespace Orchard.Data {
|
||||
ConnectionString = _shellSettings.DataConnectionString,
|
||||
CreateDatabase = createDatabase,
|
||||
UpdateSchema = updateSchema,
|
||||
RecordDescriptors = _compositionStrategy.GetRecordDescriptors(),
|
||||
RecordDescriptors = _compositionStrategy.GetRecordDescriptors_Obsolete(),
|
||||
});
|
||||
|
||||
return sessionFactory;
|
||||
|
@@ -8,7 +8,6 @@ using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Records;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Environment.Extensions.Records;
|
||||
using Orchard.Environment.Topology;
|
||||
using Orchard.Environment.Topology.Models;
|
||||
using Orchard.Utility.Extensions;
|
||||
@@ -17,10 +16,10 @@ namespace Orchard.Environment {
|
||||
//TEMP: This will be replaced by packaging system
|
||||
|
||||
public interface ICompositionStrategy_Obsolete {
|
||||
IEnumerable<RecordDescriptor> GetRecordDescriptors();
|
||||
IEnumerable<RecordDescriptor_Obsolete> GetRecordDescriptors_Obsolete();
|
||||
}
|
||||
|
||||
public class RecordDescriptor {
|
||||
public class RecordDescriptor_Obsolete {
|
||||
public Type Type { get; set; }
|
||||
public string Prefix { get; set; }
|
||||
}
|
||||
@@ -33,12 +32,11 @@ namespace Orchard.Environment {
|
||||
}
|
||||
|
||||
public ShellTopology Compose(ShellTopologyDescriptor topologyDescriptor) {
|
||||
|
||||
var featureDescriptors = _extensionManager.AvailableExtensions()
|
||||
.SelectMany(extensionDescriptor => extensionDescriptor.Features)
|
||||
.Where(featureDescriptor => IsFeatureEnabledInTopology(featureDescriptor, topologyDescriptor));
|
||||
|
||||
var features = _extensionManager.LoadFeatures(featureDescriptors);
|
||||
var features = _extensionManager.LoadFeatures(featureDescriptors).Concat(CoreFeatures());
|
||||
|
||||
return new ShellTopology {
|
||||
Modules = BuildTopology<ModuleTopology>(features, IsModule, BuildModule),
|
||||
@@ -48,6 +46,25 @@ namespace Orchard.Environment {
|
||||
};
|
||||
}
|
||||
|
||||
private static IEnumerable<Feature> CoreFeatures() {
|
||||
var core = new Feature {
|
||||
Descriptor = new FeatureDescriptor {
|
||||
Name = "Core",
|
||||
Extension = new ExtensionDescriptor {
|
||||
Name = "Core",
|
||||
DisplayName = "Core",
|
||||
AntiForgery = "enabled",
|
||||
},
|
||||
},
|
||||
ExportedTypes = new[] {
|
||||
typeof (ContentTypeRecord),
|
||||
typeof (ContentItemRecord),
|
||||
typeof (ContentItemVersionRecord),
|
||||
},
|
||||
};
|
||||
return new[] { core };
|
||||
}
|
||||
|
||||
|
||||
private static bool IsFeatureEnabledInTopology(FeatureDescriptor featureDescriptor, ShellTopologyDescriptor topologyDescriptor) {
|
||||
return topologyDescriptor.EnabledFeatures.Any(topologyFeature => topologyFeature.Name == featureDescriptor.Name);
|
||||
@@ -89,7 +106,7 @@ namespace Orchard.Environment {
|
||||
}
|
||||
|
||||
private static ControllerTopology BuildController(Type type, Feature feature) {
|
||||
var areaName = feature.FeatureDescriptor.ExtensionName;
|
||||
var areaName = feature.Descriptor.Extension.Name;
|
||||
|
||||
var controllerName = type.Name;
|
||||
if (controllerName.EndsWith("Controller"))
|
||||
@@ -113,16 +130,22 @@ namespace Orchard.Environment {
|
||||
}
|
||||
|
||||
private static RecordTopology BuildRecord(Type type, Feature feature) {
|
||||
return new RecordTopology { Type = type, Feature = feature };
|
||||
var extensionDescriptor = feature.Descriptor.Extension;
|
||||
var extensionName = extensionDescriptor.Name.Replace('.', '_');
|
||||
|
||||
return new RecordTopology {
|
||||
Type = type,
|
||||
Feature = feature,
|
||||
TableName = extensionName + '_' + type.Name,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public IEnumerable<RecordDescriptor> GetRecordDescriptors() {
|
||||
var descriptors = new List<RecordDescriptor>{
|
||||
new RecordDescriptor { Prefix = "Core", Type = typeof (ContentTypeRecord)},
|
||||
new RecordDescriptor { Prefix = "Core", Type = typeof (ContentItemRecord)},
|
||||
new RecordDescriptor { Prefix = "Core", Type = typeof (ContentItemVersionRecord)},
|
||||
new RecordDescriptor { Prefix = "Core", Type = typeof (ExtensionRecord)},
|
||||
public IEnumerable<RecordDescriptor_Obsolete> GetRecordDescriptors_Obsolete() {
|
||||
var descriptors = new List<RecordDescriptor_Obsolete>{
|
||||
new RecordDescriptor_Obsolete { Prefix = "Core", Type = typeof (ContentTypeRecord)},
|
||||
new RecordDescriptor_Obsolete { Prefix = "Core", Type = typeof (ContentItemRecord)},
|
||||
new RecordDescriptor_Obsolete { Prefix = "Core", Type = typeof (ContentItemVersionRecord)},
|
||||
};
|
||||
|
||||
foreach (var extension in _extensionManager.ActiveExtensions_Obsolete()) {
|
||||
@@ -133,7 +156,7 @@ namespace Orchard.Environment {
|
||||
var recordDescriptors = extension
|
||||
.ExportedTypes
|
||||
.Where(IsRecordType)
|
||||
.Select(type => new RecordDescriptor { Prefix = prefix, Type = type });
|
||||
.Select(type => new RecordDescriptor_Obsolete { Prefix = prefix, Type = type });
|
||||
|
||||
descriptors.AddRange(recordDescriptors);
|
||||
}
|
||||
|
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Autofac;
|
||||
@@ -7,8 +6,6 @@ using System.Collections.Generic;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.ShellBuilders;
|
||||
using Orchard.Environment.Topology;
|
||||
using Orchard.Environment.Topology.Models;
|
||||
using Orchard.Mvc;
|
||||
using Orchard.Mvc.ViewEngines;
|
||||
using Orchard.Utility.Extensions;
|
||||
|
@@ -69,30 +69,31 @@ namespace Orchard.Environment.Extensions {
|
||||
.Where(x => x.Key is Scalar)
|
||||
.ToDictionary(x => ((Scalar)x.Key).Text, x => x.Value);
|
||||
|
||||
return new ExtensionDescriptor {
|
||||
Location = parseResult.Location,
|
||||
Name = name,
|
||||
ExtensionType = extensionType,
|
||||
DisplayName = GetValue(fields, "name"),
|
||||
Description = GetValue(fields, "description"),
|
||||
Version = GetValue(fields, "version"),
|
||||
OrchardVersion = GetValue(fields, "orchardversion"),
|
||||
Author = GetValue(fields, "author"),
|
||||
WebSite = GetValue(fields, "website"),
|
||||
Tags = GetValue(fields, "tags"),
|
||||
AntiForgery = GetValue(fields, "antiforgery"),
|
||||
Features = GetFeaturesForExtension(GetMapping(fields, "features"), name),
|
||||
};
|
||||
var extensionDescriptor = new ExtensionDescriptor {
|
||||
Location = parseResult.Location,
|
||||
Name = name,
|
||||
ExtensionType = extensionType,
|
||||
DisplayName = GetValue(fields, "name") ?? name,
|
||||
Description = GetValue(fields, "description"),
|
||||
Version = GetValue(fields, "version"),
|
||||
OrchardVersion = GetValue(fields, "orchardversion"),
|
||||
Author = GetValue(fields, "author"),
|
||||
WebSite = GetValue(fields, "website"),
|
||||
Tags = GetValue(fields, "tags"),
|
||||
AntiForgery = GetValue(fields, "antiforgery"),
|
||||
};
|
||||
extensionDescriptor.Features = GetFeaturesForExtension(GetMapping(fields, "features"), extensionDescriptor);
|
||||
return extensionDescriptor;
|
||||
}
|
||||
|
||||
private static IEnumerable<FeatureDescriptor> GetFeaturesForExtension(Mapping features, string name) {
|
||||
private static IEnumerable<FeatureDescriptor> GetFeaturesForExtension(Mapping features, ExtensionDescriptor extensionDescriptor) {
|
||||
List<FeatureDescriptor> featureDescriptors = new List<FeatureDescriptor>();
|
||||
if (features == null) return featureDescriptors;
|
||||
foreach (var entity in features.Entities) {
|
||||
FeatureDescriptor featureDescriptor = new FeatureDescriptor {
|
||||
ExtensionName = name,
|
||||
Name = entity.Key.ToString(),
|
||||
};
|
||||
Extension = extensionDescriptor,
|
||||
Name = entity.Key.ToString(),
|
||||
};
|
||||
Mapping featureMapping = (Mapping)entity.Value;
|
||||
foreach (var featureEntity in featureMapping.Entities) {
|
||||
if (String.Equals(featureEntity.Key.ToString(), "description", StringComparison.OrdinalIgnoreCase)) {
|
||||
@@ -135,9 +136,9 @@ namespace Orchard.Environment.Extensions {
|
||||
}
|
||||
|
||||
return new Feature {
|
||||
FeatureDescriptor = featureDescriptor,
|
||||
ExportedTypes = featureTypes
|
||||
};
|
||||
Descriptor = featureDescriptor,
|
||||
ExportedTypes = featureTypes
|
||||
};
|
||||
}
|
||||
|
||||
private static string GetSourceFeatureNameForType(Type type, string extensionName) {
|
||||
|
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace Orchard.Environment.Extensions.Models {
|
||||
public class Feature {
|
||||
public FeatureDescriptor FeatureDescriptor { get; set; }
|
||||
public FeatureDescriptor Descriptor { get; set; }
|
||||
public IEnumerable<Type> ExportedTypes { get; set; }
|
||||
}
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
namespace Orchard.Environment.Extensions.Models {
|
||||
public class FeatureDescriptor {
|
||||
public string ExtensionName { get; set; }
|
||||
public ExtensionDescriptor Extension { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Category { get; set; }
|
||||
|
@@ -1,13 +0,0 @@
|
||||
namespace Orchard.Environment.Extensions.Records {
|
||||
public class ExtensionRecord {
|
||||
public ExtensionRecord() {
|
||||
// ReSharper disable DoNotCallOverridableMethodsInConstructor
|
||||
Enabled = true;
|
||||
// ReSharper restore DoNotCallOverridableMethodsInConstructor
|
||||
}
|
||||
|
||||
public virtual int Id { get; set; }
|
||||
public virtual string Name { get; set; }
|
||||
public virtual bool Enabled { get; set; }
|
||||
}
|
||||
}
|
@@ -194,7 +194,6 @@
|
||||
<Compile Include="Environment\Extensions\Models\Feature.cs" />
|
||||
<Compile Include="Environment\Extensions\Models\FeatureDescriptor.cs" />
|
||||
<Compile Include="Environment\Extensions\OrchardFeatureAttribute.cs" />
|
||||
<Compile Include="Environment\Extensions\Records\ExtensionRecord.cs" />
|
||||
<Compile Include="Environment\Extensions\ShellTopology.cs" />
|
||||
<Compile Include="Mvc\AntiForgery\ValidateAntiForgeryTokenOrchardAttribute.cs" />
|
||||
<Compile Include="Mvc\Extensions\ControllerExtensions.cs" />
|
||||
|
Reference in New Issue
Block a user