mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
- RuleEngine implementation for widget layer rules.
- The ResultFilter uses the rule manager to filter out layers and widgets. - Added rules to default layers. - RuleManager with callback injection into the dlr scripting sandbox. - RuleProvider implementations for Url and Authenticated. Anonymous is just "not Authenticated". - RuleContext. - Renaming Layer.Rule to Layer.LayerRule. NHibernate bug for SqlCe most likely, couldn't escape "Rule" as expected. - Unit tests. --HG-- branch : dev
This commit is contained in:
@@ -63,6 +63,21 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\fluentnhibernate\FluentNHibernate.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="IronRuby, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\dlr\IronRuby.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="IronRuby.Libraries">
|
||||
<HintPath>..\..\lib\dlr\IronRuby.Libraries.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Dynamic, Version=1.1.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\dlr\Microsoft.Dynamic.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Scripting, Version=1.1.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\dlr\Microsoft.Scripting.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Moq, Version=4.0.812.4, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\moq\Moq.dll</HintPath>
|
||||
@@ -115,6 +130,7 @@
|
||||
<Compile Include="Values.cs" />
|
||||
<Compile Include="Users\Controllers\AdminControllerTests.cs" />
|
||||
<Compile Include="Users\Services\MembershipServiceTests.cs" />
|
||||
<Compile Include="Widgets\WidgetsTests.cs" />
|
||||
<Compile Include="XmlRpc\Controllers\HomeControllerTests.cs" />
|
||||
<Compile Include="XmlRpc\Services\XmlRpcReaderTests.cs" />
|
||||
<Compile Include="XmlRpc\Services\XmlRpcWriterTests.cs" />
|
||||
@@ -144,6 +160,10 @@
|
||||
<Project>{79AED36E-ABD0-4747-93D3-8722B042454B}</Project>
|
||||
<Name>Orchard.Users</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Orchard.Web\Modules\Orchard.Widgets\Orchard.Widgets.csproj">
|
||||
<Project>{194D3CCC-1153-474D-8176-FDE8D7D0D0BD}</Project>
|
||||
<Name>Orchard.Widgets</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Orchard\Orchard.Framework.csproj">
|
||||
<Project>{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}</Project>
|
||||
<Name>Orchard.Framework</Name>
|
||||
|
56
src/Orchard.Tests.Modules/Widgets/WidgetsTests.cs
Normal file
56
src/Orchard.Tests.Modules/Widgets/WidgetsTests.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Autofac;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Scripting;
|
||||
using Orchard.UI.Widgets;
|
||||
using Orchard.Widgets.RuleEngine;
|
||||
|
||||
namespace Orchard.Tests.Modules.Widgets {
|
||||
[TestFixture]
|
||||
public class WidgetsTests {
|
||||
private IContainer _container;
|
||||
private IRuleManager _ruleManager;
|
||||
|
||||
[SetUp]
|
||||
public void Init() {
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterType<ScriptingRuntime>().As<IScriptingRuntime>();
|
||||
builder.RegisterType<ScriptingManager>().As<IScriptingManager>();
|
||||
builder.RegisterType<AlwaysTrueRuleProvider>().As<IRuleProvider>();
|
||||
builder.RegisterType<RuleManager>().As<IRuleManager>();
|
||||
_container = builder.Build();
|
||||
_ruleManager = _container.Resolve<IRuleManager>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProviderGetsCalledForExpression() {
|
||||
bool result = _ruleManager.Matches("hello");
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RubyExpressionIsEvaluated() {
|
||||
bool result = _ruleManager.Matches("not hello");
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ArgumentsArePassedCorrectly() {
|
||||
bool result = _ruleManager.Matches("add(2, 3) == 5");
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
}
|
||||
|
||||
public class AlwaysTrueRuleProvider : IRuleProvider {
|
||||
public void Process(RuleContext ruleContext) {
|
||||
if (ruleContext.FunctionName == "add") {
|
||||
ruleContext.Result = Convert.ToInt32(ruleContext.Arguments[0]) + Convert.ToInt32(ruleContext.Arguments[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
ruleContext.Result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user