Merge 1.x => default

This commit is contained in:
Renaud Paquay
2011-01-17 15:15:21 -08:00
326 changed files with 4675 additions and 2395 deletions

View File

@@ -8,3 +8,6 @@ a6b8d094848d4efee67c787e52e5f7d358e3f0c1 0.5
083d09cd94a7c9175272fba453a156673be9db78 0.8
523f3564d2c053ff068970eab8c64eaf74e3dcec perf baseline
d2cca954cbf94750946a6325e5ec23e267430bd2 perf snapshot 1
83536b451ffe01a2d94867894f2b284cea2e68aa 1.0
83536b451ffe01a2d94867894f2b284cea2e68aa 1.0
5cc01ad95f11fcd241163685effaf01ef4b6cb02 1.0

View File

@@ -124,21 +124,19 @@
</Target>
<Target Name="Package-SqlCe">
<ItemGroup>
<SqlCeBinariesx86 Include="$(LibFolder)\sqlce\x86\*.*" />
<SqlCeBinariesx64 Include="$(LibFolder)\sqlce\amd64\*.*" />
<ItemGroup>
<SqlCeBinariesx86 Include="$(LibFolder)\sqlce\x86\**\*" />
<SqlCeBinariesx64 Include="$(LibFolder)\sqlce\amd64\**\*" />
</ItemGroup>
<Copy SourceFiles="@(SqlCeBinariesx86)" DestinationFolder="$(CloudRootFolder)\bin\x86" SkipUnchangedFiles="true" />
<Copy SourceFiles="@(SqlCeBinariesx64)" DestinationFolder="$(CloudRootFolder)\bin\amd64" SkipUnchangedFiles="true" />
<Copy SourceFiles="@(SqlCeBinariesx86)" DestinationFolder="$(CloudRootFolder)\bin\x86\%(RecursiveDir)" SkipUnchangedFiles="true" />
<Copy SourceFiles="@(SqlCeBinariesx64)" DestinationFolder="$(CloudRootFolder)\bin\amd64\%(RecursiveDir)" SkipUnchangedFiles="true" />
</Target>
<Target Name="Package-Stage">
<Exec
Command="&quot;$(ServiceHostingSDKBinDir)cspack&quot; &quot;$(ServiceFolder)\ServiceDefinition.build.csdef&quot; /role:Orchard.Azure.Web;&quot;$(CloudRootFolder)&quot;;Orchard.Azure.Web.dll /rolePropertiesFile:Orchard.Azure.Web;&quot;$(ServiceFolder)\Properties.txt&quot; /out:&quot;$(StageFolder)\Orchard.Azure.Web.cspkg&quot;"
WorkingDirectory="$(CloudRootFolder)"
/>
<Exec
Command="&quot;$(ServiceHostingSDKBinDir)cspack&quot; &quot;$(SrcFolder)\Orchard.Azure\Orchard.Azure.CloudService\ServiceDefinition.build.csdef&quot; /role:Orchard.Azure.Web;&quot;$(CloudRootFolder)&quot;;Orchard.Azure.Web.dll /sites:Orchard.Azure.Web;Web;&quot;$(CloudRootFolder)&quot; /rolePropertiesFile:Orchard.Azure.Web;&quot;$(ServiceFolder)\Properties.txt&quot; /out:&quot;$(StageFolder)\Orchard.Azure.Web.cspkg&quot;"
WorkingDirectory="$(CloudRootFolder)"
/>
</Target>
<Target Name="Package-Zip">

View File

@@ -1,9 +1,9 @@
Orchard Project
ASP.NET Open Source Gallery at CodePlex Foundation
Copyright 2009 CodePlex Foundation
ASP.NET Open Source Gallery at Outercurve Foundation
Copyright 2009-2011 Outercurve Foundation
This product includes software developed at
The CodePlex Foundation (http://www.codeplex.org/).
The Outercurve Foundation (http://www.outercurve.org/).
Orchard includes or is derivative of works distributed under the licenses listed below. The full text for most of the licenses listed below can be found in the LICENSE.txt file accompanying each work. The original copyright notices have been preserved within the respective files and or packages. Please refer to the specific files and/or packages for more detailed information about the authors, copyright notices, and licenses.
@@ -22,9 +22,9 @@ License: New BSD
ASP.NET MVC
-----
Website: http://aspnet.codeplex.com/wikipage?title=MVC&referringTitle=Home
Copyright: Copyright (c) 2008-2009 Microsoft Corporation
License: Microsoft Source License for ASP.NET pre-release components
http://aspnet.codeplex.com/license
Copyright: Copyright (c) 2008-2011 Microsoft Corporation
License: MICROSOFT ASP.NET MODEL VIEW CONTROLLER 3 EULA
http://go.microsoft.com/fwlink/?LinkID=207621
Autofac
-----
@@ -45,6 +45,18 @@ Website: http://www.castleproject.org/container/index.html
Copyright: Copyright (c) 2004-2009 Castle Project
License: Apache Software Foundation License 2.0
Clay
----
Website: http://clay.codeplex.com/
Copyright: Copyright (c) 2010 Louis Dejardin
License: MS-PL
DLR
---
Website: http://dlr.codeplex.com
Copyright: Copyright (c) Microsoft Corporation
License: Apache Software Foundation License 2.0
Eric Meyer's Reset CSS
-----
Website: http://meyerweb.com/eric/tools/css/reset/
@@ -66,7 +78,7 @@ License: New BSD
FluentPath
-----
Website: http://fluentpath.codeplex.com/
Copyright: Copyright (c) 2010 Bertrand Le Roy
Copyright: Copyright (c) 2011 Bertrand Le Roy
License: MS-PL
Html Agility Pack
@@ -137,8 +149,8 @@ License: LGPL 2.1
NuGet
-----
Website: http://www.nuget.org/nuget.codeplex.com
Copyright: Copyright 2010 Outercurve Foundation
Website: http://nuget.codeplex.com
Copyright: Copyright 2010-2011 Outercurve Foundation
License: Apache Software Foundation License 2.0
nUnit
@@ -160,11 +172,11 @@ Website: http://www.specflow.org/
Copyright: Copyright (c) 2009 TechTalk
License: New BSD
SQLite
Microsoft SQL Server Compact 4.0
-----
Website: http://www.sqlite.org
Copyright: Public domain http://www.sqlite.org/copyright.html
License: Public domain
Website: http://www.microsoft.com
Copyright: Copyright (c) 2011 Microsoft Corporation
License: Custom EULA - http://www.microsoft.com/web/webpi/eula/SQLCE_EULA_ENU.rtf
TinyMCE
-----
@@ -178,12 +190,6 @@ WebSite: http://www.iis.net/community/default.aspx?tabid=34&i=1466&g=6
Copyright: Copyright (c) 2007 Microsoft
License: "Free"
Yamlnet
-----
Website: http://code.google.com/p/yamlnet/
Copyright: Copyright (c) 2009, apolanski
License: Apache Software Foundation License 2.0
YUI
-----
Website: http://developer.yahoo.com/yui/

View File

@@ -141,8 +141,8 @@
<CallTarget Targets="ValidateProjectFiles"/>
<ItemGroup>
<SqlCe-Native-Binaries-x86 Include="$(SqlCeFolder)\x86\*"/>
<SqlCe-Native-Binaries-amd64 Include="$(SqlCeFolder)\amd64\*"/>
<SqlCe-Native-Binaries-x86 Include="$(SqlCeFolder)\x86\**\*"/>
<SqlCe-Native-Binaries-amd64 Include="$(SqlCeFolder)\amd64\**\*"/>
<Stage-Orchard-Web-Bins Include="$(WebSitesFolder)\Orchard.Web\bin\*"/>
<Stage-Bin-Exclude Include="$(WebSitesFolder)\**\bin\**\*" />
<Stage-Web Include="$(WebSitesFolder)\Orchard.Web\**\*;$(SrcFolder)\Orchard.Web\*.csproj;" />
@@ -183,8 +183,8 @@
<Copy SourceFiles="@(Stage-Web);@(Stage-Web-Config);@(Stage-License)" DestinationFolder="$(StageFolder)\%(RecursiveDir)"/>
<Copy SourceFiles="@(Stage-Media)" DestinationFolder="$(StageFolder)\Media"/>
<Copy SourceFiles="@(Stage-PoFiles)" DestinationFolder="$(StageFolder)\%(RecursiveDir)"/>
<Copy SourceFiles="@(SqlCe-Native-Binaries-x86)" DestinationFolder="$(StageFolder)\bin\x86"/>
<Copy SourceFiles="@(SqlCe-Native-Binaries-amd64)" DestinationFolder="$(StageFolder)\bin\amd64"/>
<Copy SourceFiles="@(SqlCe-Native-Binaries-x86)" DestinationFolder="$(StageFolder)\bin\x86\%(RecursiveDir)"/>
<Copy SourceFiles="@(SqlCe-Native-Binaries-amd64)" DestinationFolder="$(StageFolder)\bin\amd64\%(RecursiveDir)"/>
<Copy SourceFiles="@(Stage-Core)" DestinationFolder="$(StageFolder)\Core\%(RecursiveDir)"/>
<Copy SourceFiles="@(Stage-Modules)" DestinationFolder="$(StageFolder)\Modules\%(RecursiveDir)"/>
<Copy SourceFiles="@(Stage-Modules-Sources)" DestinationFolder="$(StageFolder)\Modules\%(RecursiveDir)"/>

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

View File

@@ -2,7 +2,5 @@
<iisapp path="Orchard" managedRuntimeVersion="v4.0" />
<setAcl path="Orchard/App_Data" setAclAccess="Modify" />
<setAcl path="Orchard/Media" setAclAccess="Modify" />
<setAcl path="Orchard/Modules" setAclAccess="Modify" />
<setAcl path="Orchard/Themes" setAclAccess="Modify" />
<dbFullSql path="install.sql" />
</MSDeploy.iisApp>

View File

@@ -1,4 +1,4 @@
<parameters>
<parameters>
<!-- Prompts where to copy the content files and takes a web site path (such as "contoso.com/app") -->
<parameter name="Application Path" description="Full site path where you would like to install your application (i.e., Default Web Site/orchard)" defaultValue="Default Web Site/orchard" tags="iisapp">
<parameterEntry type="ProviderPath" scope="iisapp" match="Orchard" />
@@ -13,15 +13,7 @@
<parameterEntry type="ProviderPath" scope="setAcl" match="Orchard/Media" />
</parameter>
<parameter name="SetAclParameter3" description="Hidden - automatically sets write access for the app" defaultValue="{Application Path}/Modules" tags="Hidden">
<parameterEntry type="ProviderPath" scope="setAcl" match="Orchard/Modules" />
</parameter>
<parameter name="SetAclParameter4" description="Hidden - automatically sets write access for the app" defaultValue="{Application Path}/Themes" tags="Hidden">
<parameterEntry type="ProviderPath" scope="setAcl" match="Orchard/Themes" />
</parameter>
<!-- Prompts for database server name, this is used in the connection string parameter later -->
<!-- Prompts for database server name, this is used in the connection string parameter later -->
<parameter name="Database Server" description="Location of your database server (i.e. server name, IP address, or server\instance)" defaultValue=".\SQLEXPRESS" tags="SQL, dbServer">
</parameter>
@@ -30,13 +22,13 @@
<parameterEntry type="TextFile" scope="install.sql" match="PlaceHolderForDb" />
</parameter>
<!-- Prompts for the database username and fills it into the database scripts.
<!-- Prompts for the database username and fills it into the database scripts.
The SQL tag indicates it is a parameter required for SQL, the DbUsername tag indicates this is a Db username -->
<parameter name="Database Username" description="User name to access you application database." defaultValue="orcharduser" tags="SQL, DbUsername">
<parameterEntry type="TextFile" scope="install.sql" match="PlaceHolderForUser" />
</parameter>
<!-- Prompts for the database password and fills it into the database scripts.
<!-- Prompts for the database password and fills it into the database scripts.
The SQL tag indicates it is a parameter required for SQL, the DbUserPassword tag indicates this is a Db password -->
<parameter name="Database Password" description="Password for the Database Username." tags="New, Password, SQL, DbUserPassword">
<parameterEntry type="TextFile" scope="install.sql" match="PlaceHolderForPassword" />
@@ -54,24 +46,18 @@
<parameter name="Database Administrator Password" description="Password for the database administrator account." tags="New, Password, SQL, dbAdminPassword">
</parameter>
<!-- This is the hidden admin connection string used to run the database scripts -->
<parameter name="Connection String" description="Automatically sets the connection string for the connection request." defaultValue="Server={Database Server};Database={Database Name};uid={Database Administrator};Pwd={Database Administrator Password};" tags="Hidden, SQL">
<parameterEntry type="ProviderPath" scope="dbfullsql" match="install.sql" />
<parameter name="Admin Connection String SqlServer"
tags="SQLConnectionString, AdminConnectionString, Hidden, Validate" description="Automatically sets the connection string for the connection request."
defaultValue="Data Source={Database Server};Initial Catalog={Database Name};User Id={Database Administrator};Password={Database Administrator Password}">
<parameterEntry type="ProviderPath" scope="dbfullsql" match="install.sql" />
</parameter>
<parameter name="Settings Data Provider for SQL" description="Orchard SQL Data Provider Setting" defaultValue="DataProvider: SqlServer" tags="Hidden, SQL">
<parameterEntry kind="TextFile" scope="\\Settings\.txt$" match="DataProvider\s*:[^\r\n]*" />
</parameter>
<parameter name="Settings Data Connection String for SQL" description="Orchard SQL Data Connection String Setting" defaultValue="DataConnectionString: Server={Database Server};Database={Database Name};uid={Database Administrator};Pwd={Database Administrator Password};" tags="Hidden, SQL">
<parameterEntry kind="TextFile" scope="\\Settings\.txt$" match="DataConnectionString\s*:[^\r\n]*" />
</parameter>
<parameter name="Settings Data Provider for SQLCE" description="Orchard SQLCE Data Provider Setting" defaultValue="DataProvider: SqlCe" tags="Hidden, SQLCE, NoStore">
<parameterEntry kind="TextFile" scope="\\Settings\.txt$" match="DataProvider\s*:[^\r\n]*" />
</parameter>
<parameter name="Settings Data Connection String for SQLCE" description="Orchard SQLCE Data Connection String Setting" defaultValue="DataConnectionString: " tags="Hidden, SQLCE, NoStore">
<parameterEntry kind="TextFile" scope="\\Settings\.txt$" match="DataConnectionString\s*:[^\r\n]*" />
</parameter>
<parameter name="Non-Admin Connection String SqlServer"
tags="SQLConnectionString, UserConnectionString, Hidden" description="Automatically sets the connection string for the connection request."
defaultValue="Data Source={Database Server};Initial Catalog={Database Name};User Id={Database Username};Password={Database Password}">
</parameter>
<parameter name="Orchard Connection String" friendlyName="Orchard Connection String" description="Orchard SQL Data Connection String Setting" defaultValue="" tags="Sql, SqlCE, SingleLineConnectionString, Hidden">
<parameterEntry kind="TextFile" scope="\\Settings\.txt$" match="(?&lt;=\s*DataConnectionString:\s+)[^\s].*[^\r\n]" />
</parameter>
</parameters>

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<noInheritable></noInheritable>
<assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.30729.4148" processorArchitecture="amd64" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
<file name="msvcr90.dll" hashalg="SHA1" hash="1b065fdf0cb8516b0553128eae4af39c5f8eeb46"><asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"><dsig:Transforms><dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"></dsig:Transform></dsig:Transforms><dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></dsig:DigestMethod><dsig:DigestValue>Vy8CgQgbu3qH5JHTK0op4kR8114=</dsig:DigestValue></asmv2:hash></file> <file name="msvcp90.dll" hashalg="SHA1" hash="45d3027d87eade77317e92994790598c755b3920"><asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"><dsig:Transforms><dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"></dsig:Transform></dsig:Transforms><dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></dsig:DigestMethod><dsig:DigestValue>QTJu3Gttpt8hhCktGelNeXj4Yp8=</dsig:DigestValue></asmv2:hash></file> <file name="msvcm90.dll" hashalg="SHA1" hash="e77fd69f7c88f34329d8a95c3179f67ead330217"><asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"><dsig:Transforms><dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"></dsig:Transform></dsig:Transforms><dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></dsig:DigestMethod><dsig:DigestValue>1ruqF7/L+m1tqnJVscaOtNRNHIE=</dsig:DigestValue></asmv2:hash></file>
</assembly>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<noInheritable></noInheritable>
<assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.30729.4148" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
<file name="msvcr90.dll" hashalg="SHA1" hash="98e8006e0a4542e69f1a3555b927758bd76ca07d"><asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"><dsig:Transforms><dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"></dsig:Transform></dsig:Transforms><dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></dsig:DigestMethod><dsig:DigestValue>+CXED+6HzJlSphyMNOn27ujadC0=</dsig:DigestValue></asmv2:hash></file> <file name="msvcp90.dll" hashalg="SHA1" hash="3aec3be680024a46813dee891a753bd58b3f3b12"><asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"><dsig:Transforms><dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"></dsig:Transform></dsig:Transforms><dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></dsig:DigestMethod><dsig:DigestValue>MyKED+9DyS+1XcMeaC0Zlw2vFZ0=</dsig:DigestValue></asmv2:hash></file> <file name="msvcm90.dll" hashalg="SHA1" hash="0195dd0896d74b62531e4f3c771904a3d996450e"><asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"><dsig:Transforms><dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"></dsig:Transform></dsig:Transforms><dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></dsig:DigestMethod><dsig:DigestValue>EeyDE7og6WoPd2oBhYbMEnpFHhY=</dsig:DigestValue></asmv2:hash></file>
</assembly>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -76,5 +76,13 @@ namespace Orchard.Azure.Tests.Environment.Configuration {
Assert.That(foo.DataProvider, Is.StringContaining("Bar"));
Assert.That(foo.DataConnectionString, Is.StringContaining("Quux"));
}
[Test]
public void SettingsCanContainSeparatorChar() {
ShellSettingsManager.SaveSettings(new ShellSettings { Name = "Default", DataProvider = "SQLite", DataConnectionString = "Server=tcp:tjyptm5sfc.database.windows.net;Database=orchard;User ID=foo@bar;Password=foo;Trusted_Connection=False;Encrypt=True;" });
var settings = ShellSettingsManager.LoadSettings().Where(s => s.Name == "Default").Single();
Assert.That(settings.DataConnectionString, Is.EqualTo("Server=tcp:tjyptm5sfc.database.windows.net;Database=orchard;User ID=foo@bar;Password=foo;Trusted_Connection=False;Encrypt=True;"));
}
}
}

View File

@@ -165,6 +165,21 @@ namespace Orchard.Azure.Tests.FileSystems.Media {
Assert.AreEqual(1, _azureBlobStorageProvider.ListFiles("folder1/folder4/folder3").Count());
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void CannotCreateAlreadyExistingFolders()
{
_azureBlobStorageProvider.CreateFile("folder1/foo.txt");
_azureBlobStorageProvider.CreateFolder("folder1");
}
[Test]
public void CanCreateAlreadyExistingFolder()
{
_azureBlobStorageProvider.CreateFile("folder1/foo.txt");
_azureBlobStorageProvider.TryCreateFolder("folder1");
}
[Test]
public void ShouldReadWriteFiles() {
const string teststring = "This is a test string.";

View File

@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.9.0")]
[assembly: AssemblyFileVersion("0.9.0")]
[assembly: AssemblyVersion("1.0.20")]
[assembly: AssemblyFileVersion("1.0.20")]

View File

@@ -156,7 +156,13 @@ namespace Orchard.Azure {
public void TryCreateFolder(string path) {
EnsurePathIsRelative(path);
CreateFile(Combine(path, FolderEntry));
using (new HttpContextWeaver()) {
if (Container.DirectoryExists(String.Concat(_root, path))) {
return;
}
CreateFile(Combine(path, FolderEntry));
}
}
public void CreateFolder(string path) {

View File

@@ -5,19 +5,18 @@ using System.Linq;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.ServiceRuntime;
using Orchard.Environment.Configuration;
using Orchard.Localization;
namespace Orchard.Azure.Environment.Configuration {
public class AzureShellSettingsManager : IShellSettingsManager {
public const string ContainerName = "sites"; // container names must be lower cased
public const string SettingsFilename = "Settings.txt";
public const char Separator = ':';
public const string EmptyValue = "null";
private readonly IShellSettingsManagerEventHandler _events;
private readonly AzureFileSystem _fileSystem;
Localizer T { get; set; }
public AzureShellSettingsManager(IShellSettingsManagerEventHandler events)
: this(CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("DataConnectionString")), events) {}
@@ -33,7 +32,7 @@ namespace Orchard.Azure.Environment.Configuration {
void IShellSettingsManager.SaveSettings(ShellSettings settings) {
var content = ComposeSettings(settings);
var filePath = String.Concat(settings.Name, "/", SettingsFilename);
var filePath = _fileSystem.Combine(settings.Name, SettingsFilename);
var file = _fileSystem.CreateFile(filePath);
using (var stream = file.OpenWrite()) {
@@ -62,50 +61,54 @@ namespace Orchard.Azure.Environment.Configuration {
if (String.IsNullOrEmpty(text))
return shellSettings;
string[] settings = text.Split(new[] {"\r\n"}, StringSplitOptions.RemoveEmptyEntries);
var settings = text.Split(new[] {"\r\n"}, StringSplitOptions.RemoveEmptyEntries);
foreach (var setting in settings) {
string[] settingFields = setting.Split(new[] {":"}, StringSplitOptions.RemoveEmptyEntries);
int fieldsLength = settingFields.Length;
if (fieldsLength != 2)
var separatorIndex = setting.IndexOf(Separator);
if(separatorIndex == -1) {
continue;
for (int i = 0; i < fieldsLength; i++) {
settingFields[i] = settingFields[i].Trim();
}
if (settingFields[1] != "null") {
switch (settingFields[0]) {
string key = setting.Substring(0, separatorIndex).Trim();
string value = setting.Substring(separatorIndex + 1).Trim();
if (value != EmptyValue) {
switch (key) {
case "Name":
shellSettings.Name = settingFields[1];
shellSettings.Name = value;
break;
case "DataProvider":
shellSettings.DataProvider = settingFields[1];
shellSettings.DataProvider = value;
break;
case "State":
shellSettings.State = new TenantState(settingFields[1]);
shellSettings.State = new TenantState(value);
break;
case "DataConnectionString":
shellSettings.DataConnectionString = settingFields[1];
shellSettings.DataConnectionString = value;
break;
case "DataPrefix":
shellSettings.DataTablePrefix = settingFields[1];
shellSettings.DataTablePrefix = value;
break;
case "RequestUrlHost":
shellSettings.RequestUrlHost = settingFields[1];
shellSettings.RequestUrlHost = value;
break;
case "RequestUrlPrefix":
shellSettings.RequestUrlPrefix = settingFields[1];
shellSettings.RequestUrlPrefix = value;
break;
case "EncryptionAlgorithm":
shellSettings.EncryptionAlgorithm = settingFields[1];
shellSettings.EncryptionAlgorithm = value;
break;
case "EncryptionKey":
shellSettings.EncryptionKey = settingFields[1];
shellSettings.EncryptionKey = value;
break;
case "EncryptionIV":
shellSettings.EncryptionIV = settingFields[1];
case "HashAlgorithm":
shellSettings.HashAlgorithm = value;
break;
case "HashKey":
shellSettings.HashKey = value;
break;
}
}
}
return shellSettings;
}
@@ -113,17 +116,18 @@ namespace Orchard.Azure.Environment.Configuration {
if (settings == null)
return "";
return string.Format("Name: {0}\r\nDataProvider: {1}\r\nDataConnectionString: {2}\r\nDataPrefix: {3}\r\nRequestUrlHost: {4}\r\nRequestUrlPrefix: {5}\r\nState: {6}\r\nEncryptionAlgorithm: {7}\r\nEncryptionKey: {8}\r\nEncryptionIV: {9}\r\n",
return string.Format("Name: {0}\r\nDataProvider: {1}\r\nDataConnectionString: {2}\r\nDataPrefix: {3}\r\nRequestUrlHost: {4}\r\nRequestUrlPrefix: {5}\r\nState: {6}\r\nEncryptionAlgorithm: {7}\r\nEncryptionKey: {8}\r\nHashAlgorithm: {9}\r\nHashKey: {10}\r\n",
settings.Name,
settings.DataProvider,
settings.DataConnectionString ?? "null",
settings.DataTablePrefix ?? "null",
settings.RequestUrlHost ?? "null",
settings.RequestUrlPrefix ?? "null",
settings.DataConnectionString ?? EmptyValue,
settings.DataTablePrefix ?? EmptyValue,
settings.RequestUrlHost ?? EmptyValue,
settings.RequestUrlPrefix ?? EmptyValue,
settings.State != null ? settings.State.ToString() : String.Empty,
settings.EncryptionAlgorithm ?? "null",
settings.EncryptionKey ?? "null",
settings.EncryptionIV ?? "null"
settings.EncryptionAlgorithm ?? EmptyValue,
settings.EncryptionKey ?? EmptyValue,
settings.HashAlgorithm ?? EmptyValue,
settings.HashKey ?? EmptyValue
);
}
}

View File

@@ -118,6 +118,10 @@
<Reference Include="System.Web.WebPages">
<HintPath>..\..\..\lib\aspnetmvc\System.Web.WebPages.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages.Deployment, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\lib\aspnetmvc\System.Web.WebPages.Deployment.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages.Razor">
<HintPath>..\..\..\lib\aspnetmvc\System.Web.WebPages.Razor.dll</HintPath>
</Reference>

View File

@@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("0.9.0")]
[assembly: AssemblyFileVersion("0.9.0")]
[assembly: AssemblyVersion("1.0.20")]
[assembly: AssemblyFileVersion("1.0.20")]

View File

@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.9.0")]
[assembly: AssemblyFileVersion("0.9.0")]
[assembly: AssemblyVersion("1.0.20")]
[assembly: AssemblyFileVersion("1.0.20")]

View File

@@ -11,7 +11,6 @@ using Orchard.ContentManagement.Aspects;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Drivers.Coordinators;
using Orchard.ContentManagement.MetaData;
using Orchard.Core.Common;
using Orchard.Core.Common.Drivers;
using Orchard.Core.Common.Handlers;
using Orchard.Core.Common.Models;
@@ -97,7 +96,7 @@ namespace Orchard.Core.Tests.Common.Providers {
class TestUser : ContentPart, IUser {
public new int Id { get { return 6655321; } }
public string UserName {get { return "x"; }}
public string UserName { get { return "x"; } }
public string Email { get { return "y"; } }
}
@@ -112,8 +111,7 @@ namespace Orchard.Core.Tests.Common.Providers {
}
[Test]
public void PublishingShouldFailIfOwnerIsUnknown()
{
public void PublishingShouldFailIfOwnerIsUnknown() {
var contentManager = _container.Resolve<IContentManager>();
var updateModel = new Mock<IUpdateModel>();
@@ -131,13 +129,12 @@ namespace Orchard.Core.Tests.Common.Providers {
ModelStateDictionary _modelState = new ModelStateDictionary();
public ModelStateDictionary ModelErrors
{
public ModelStateDictionary ModelErrors {
get { return _modelState; }
}
public string Owner { get; set; }
public bool TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) where TModel : class {
(model as OwnerEditorViewModel).Owner = Owner;
return true;
@@ -149,8 +146,7 @@ namespace Orchard.Core.Tests.Common.Providers {
}
[Test]
public void PublishingShouldNotThrowExceptionIfOwnerIsNull()
{
public void PublishingShouldNotThrowExceptionIfOwnerIsNull() {
var contentManager = _container.Resolve<IContentManager>();
var item = contentManager.Create<ICommonPart>("test-item", VersionOptions.Draft, init => { });
@@ -167,19 +163,18 @@ namespace Orchard.Core.Tests.Common.Providers {
}
[Test]
public void PublishingShouldFailIfOwnerIsEmpty()
{
public void PublishingShouldFailIfOwnerIsEmpty() {
var contentManager = _container.Resolve<IContentManager>();
var item = contentManager.Create<ICommonPart>("test-item", VersionOptions.Draft, init => { });
var user = contentManager.New<IUser>("User");
_authn.Setup(x => x.GetAuthenticatedUser()).Returns(user);
_authz.Setup(x => x.TryCheckAccess(StandardPermissions.SiteOwner, user, item)).Returns(true);
item.Owner = user;
var updater = new UpdatModelStub() {Owner = ""};
var updater = new UpdatModelStub() { Owner = "" };
contentManager.UpdateEditor(item.ContentItem, updater);
@@ -187,14 +182,26 @@ namespace Orchard.Core.Tests.Common.Providers {
}
[Test]
public void PublishingShouldSetPublishUtc()
{
public void CreatingShouldSetCreatedAndModifiedUtc() {
var contentManager = _container.Resolve<IContentManager>();
var createUtc = _clock.UtcNow;
var item = contentManager.Create<ICommonPart>("test-item", VersionOptions.Draft, init => { });
Assert.That(item.CreatedUtc, Is.EqualTo(createUtc));
Assert.That(item.ModifiedUtc, Is.EqualTo(createUtc));
Assert.That(item.PublishedUtc, Is.Null);
}
[Test]
public void PublishingShouldSetPublishUtcAndShouldNotChangeModifiedUtc() {
var contentManager = _container.Resolve<IContentManager>();
var createUtc = _clock.UtcNow;
var item = contentManager.Create<ICommonPart>("test-item", VersionOptions.Draft, init => { });
Assert.That(item.CreatedUtc, Is.EqualTo(createUtc));
Assert.That(item.ModifiedUtc, Is.EqualTo(createUtc));
Assert.That(item.PublishedUtc, Is.Null);
_clock.Advance(TimeSpan.FromMinutes(1));
@@ -203,9 +210,92 @@ namespace Orchard.Core.Tests.Common.Providers {
contentManager.Publish(item.ContentItem);
Assert.That(item.CreatedUtc, Is.EqualTo(createUtc));
Assert.That(item.ModifiedUtc, Is.EqualTo(createUtc));
Assert.That(item.PublishedUtc, Is.EqualTo(publishUtc));
}
[Test]
public void PublishingTwiceShouldKeepSettingPublishUtcAndShouldNotChangeModifiedUtc() {
var contentManager = _container.Resolve<IContentManager>();
var createUtc = _clock.UtcNow;
var item = contentManager.Create<ICommonPart>("test-item", VersionOptions.Draft, init => { });
Assert.That(item.CreatedUtc, Is.EqualTo(createUtc));
Assert.That(item.ModifiedUtc, Is.EqualTo(createUtc));
Assert.That(item.PublishedUtc, Is.Null);
_clock.Advance(TimeSpan.FromMinutes(1));
var publishUtc1 = _clock.UtcNow;
contentManager.Publish(item.ContentItem);
Assert.That(item.CreatedUtc, Is.EqualTo(createUtc));
Assert.That(item.ModifiedUtc, Is.EqualTo(createUtc));
Assert.That(item.PublishedUtc, Is.EqualTo(publishUtc1));
contentManager.Unpublish(item.ContentItem);
_clock.Advance(TimeSpan.FromMinutes(1));
var publishUtc2 = _clock.UtcNow;
contentManager.Publish(item.ContentItem);
Assert.That(item.CreatedUtc, Is.EqualTo(createUtc));
Assert.That(item.ModifiedUtc, Is.EqualTo(createUtc));
Assert.That(item.PublishedUtc, Is.EqualTo(publishUtc2));
}
[Test]
public void UnpublishingShouldNotChangePublishUtcAndModifiedUtc() {
var contentManager = _container.Resolve<IContentManager>();
var createUtc = _clock.UtcNow;
var item = contentManager.Create<ICommonPart>("test-item", VersionOptions.Draft, init => { });
Assert.That(item.CreatedUtc, Is.EqualTo(createUtc));
Assert.That(item.ModifiedUtc, Is.EqualTo(createUtc));
Assert.That(item.PublishedUtc, Is.Null);
_clock.Advance(TimeSpan.FromMinutes(1));
var publishUtc = _clock.UtcNow;
contentManager.Publish(item.ContentItem);
Assert.That(item.CreatedUtc, Is.EqualTo(createUtc));
Assert.That(item.ModifiedUtc, Is.EqualTo(createUtc));
Assert.That(item.PublishedUtc, Is.EqualTo(publishUtc));
contentManager.Unpublish(item.ContentItem);
Assert.That(item.CreatedUtc, Is.EqualTo(createUtc));
Assert.That(item.ModifiedUtc, Is.EqualTo(createUtc));
Assert.That(item.PublishedUtc, Is.EqualTo(publishUtc));
}
[Test]
public void EditingShouldSetModifiedUtc() {
var contentManager = _container.Resolve<IContentManager>();
var createUtc = _clock.UtcNow;
var item = contentManager.Create<ICommonPart>("test-item", VersionOptions.Draft, init => { });
contentManager.Publish(item.ContentItem);
Assert.That(item.CreatedUtc, Is.EqualTo(createUtc));
Assert.That(item.ModifiedUtc, Is.EqualTo(createUtc));
Assert.That(item.PublishedUtc, Is.EqualTo(createUtc));
_clock.Advance(TimeSpan.FromMinutes(1));
var editUtc = _clock.UtcNow;
var updater = new UpdatModelStub() { Owner = "" };
contentManager.UpdateEditor(item.ContentItem, updater);
Assert.That(item.CreatedUtc, Is.EqualTo(createUtc));
Assert.That(item.ModifiedUtc, Is.EqualTo(editUtc));
Assert.That(item.PublishedUtc, Is.EqualTo(createUtc));
Assert.That(updater.ModelErrors.Count, Is.EqualTo(0));
}
[Test]
public void VersioningItemShouldCreatedAndPublishedUtcValuesPerVersion() {
@@ -236,9 +326,9 @@ namespace Orchard.Core.Tests.Common.Providers {
Assert.That(item1.CreatedUtc, Is.EqualTo(createUtc));
Assert.That(item2.CreatedUtc, Is.EqualTo(createUtc));
// both instances non-versioned dates show the earliest publish date
Assert.That(item1.PublishedUtc, Is.EqualTo(publish1Utc));
Assert.That(item2.PublishedUtc, Is.EqualTo(publish1Utc));
// both instances non-versioned dates show the most recent publish
Assert.That(item1.PublishedUtc, Is.EqualTo(publish2Utc));
Assert.That(item2.PublishedUtc, Is.EqualTo(publish2Utc));
// version1 versioned dates show create was upfront and publish was oldest
Assert.That(item1.VersionCreatedUtc, Is.EqualTo(createUtc));
@@ -271,8 +361,7 @@ namespace Orchard.Core.Tests.Common.Providers {
contentManager.Unpublish(item.ContentItem);
// db records need to be updated before seeking by published flags
_session.Flush();
_session.Clear();
ClearSession();
var publishedItem = contentManager.Get<ICommonPart>(item.ContentItem.Id, VersionOptions.Published);
var latestItem = contentManager.Get<ICommonPart>(item.ContentItem.Id, VersionOptions.Latest);

View File

@@ -156,11 +156,11 @@
-->
<Target Name="CopySqlCeBinaries">
<ItemGroup>
<SqlCeBinariesx86 Include="$(ProjectDir)..\..\lib\sqlce\x86\*.*" />
<SqlCeBinariesx64 Include="$(ProjectDir)..\..\lib\sqlce\amd64\*.*" />
<SqlCeBinariesx86 Include="$(ProjectDir)..\..\lib\sqlce\x86\**\*" />
<SqlCeBinariesx64 Include="$(ProjectDir)..\..\lib\sqlce\amd64\**\*" />
</ItemGroup>
<Copy SourceFiles="@(SqlCeBinariesx86)" DestinationFolder="$(OutputPath)\x86" SkipUnchangedFiles="true" />
<Copy SourceFiles="@(SqlCeBinariesx64)" DestinationFolder="$(OutputPath)\amd64" SkipUnchangedFiles="true" />
<Copy SourceFiles="@(SqlCeBinariesx86)" DestinationFolder="$(OutputPath)\x86\%(RecursiveDir)" SkipUnchangedFiles="true" />
<Copy SourceFiles="@(SqlCeBinariesx64)" DestinationFolder="$(OutputPath)\amd64\%(RecursiveDir)" SkipUnchangedFiles="true" />
</Target>
<Target Name="AfterBuild">
<CallTarget Targets="CopySqlCeBinaries" />

View File

@@ -30,5 +30,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.9.0")]
[assembly: AssemblyFileVersion("0.9.0")]
[assembly: AssemblyVersion("1.0.20")]
[assembly: AssemblyFileVersion("1.0.20")]

View File

@@ -30,5 +30,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.9.0")]
[assembly: AssemblyFileVersion("0.9.0")]
[assembly: AssemblyVersion("1.0.20")]
[assembly: AssemblyFileVersion("1.0.20")]

View File

@@ -15,41 +15,6 @@ namespace Orchard.Specs.Bindings {
[Binding]
public class ContentRights : BindingBase {
[When(@"I have a role ""(.*)\"" with permissions ""(.*)\""")]
public void WhenIHaveARoleWithPermissions(string roleName, string permissions) {
var webApp = Binding<WebAppHosting>();
webApp.Host.Execute(() => {
using ( var environment = MvcApplication.CreateStandaloneEnvironment("Default") ) {
var roleService = environment.Resolve<IRoleService>();
roleService.CreateRole(roleName);
foreach ( var permissionName in permissions.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries) ) {
roleService.CreatePermissionForRole(roleName, permissionName);
}
}
});
}
[When(@"I have a user ""(.*)\"" with roles ""(.*)\""")]
public void GivenIHaveCreatedAUser(string username, string roles) {
var webApp = Binding<WebAppHosting>();
webApp.Host.Execute(() => {
using ( var environment = MvcApplication.CreateStandaloneEnvironment("Default") ) {
var memberShipService = environment.Resolve<IMembershipService>();
var roleService = environment.Resolve<IRoleService>();
var userRoleRepository = environment.Resolve<IRepository<UserRolesPartRecord>>();
var user = memberShipService.CreateUser(new CreateUserParams(username, "qwerty123!", username + "@foo.com", "", "", true));
foreach ( var roleName in roles.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries) ) {
var role = roleService.GetRoleByName(roleName);
userRoleRepository.Create(new UserRolesPartRecord { UserId = user.Id, Role = role });
}
}
});
}
[Then(@"""(.*)\"" should be able to ""(.*)\"" a ""(.*)\"" owned by ""(.*)\""")]
public void UserShouldBeAbleToForOthers(string username, string action, string contentType, string otherName) {
@@ -94,11 +59,11 @@ namespace Orchard.Specs.Bindings {
private static Permission GetPermissionForAction(string action) {
switch ( action ) {
case "publish":
return Permissions.PublishOthersContent;
return Permissions.PublishContent;
case "edit":
return Permissions.EditOthersContent;
return Permissions.EditContent;
case "delete":
return Permissions.DeleteOthersContent;
return Permissions.DeleteContent;
default:
return null;
}

View File

@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Orchard.Data;
using Orchard.Roles.Models;
using Orchard.Roles.Services;
using Orchard.Security;
using Orchard.Specs.Hosting.Orchard.Web;
using TechTalk.SpecFlow;
namespace Orchard.Specs.Bindings {
[Binding]
public class UsersPermissionsAndRoles : BindingBase {
[When(@"I have a role ""(.*)\"" with permissions ""(.*)\""")]
public void WhenIHaveARoleWithPermissions(string roleName, string permissions) {
var webApp = Binding<WebAppHosting>();
webApp.Host.Execute(() => {
using (var environment = MvcApplication.CreateStandaloneEnvironment("Default")) {
var roleService = environment.Resolve<IRoleService>();
roleService.CreateRole(roleName);
foreach (var permissionName in permissions.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)) {
roleService.CreatePermissionForRole(roleName, permissionName);
}
}
});
}
[When(@"I have a user ""(.*)\"" with roles ""(.*)\""")]
public void GivenIHaveCreatedAUser(string username, string roles) {
var webApp = Binding<WebAppHosting>();
webApp.Host.Execute(() => {
using (var environment = MvcApplication.CreateStandaloneEnvironment("Default")) {
var memberShipService = environment.Resolve<IMembershipService>();
var roleService = environment.Resolve<IRoleService>();
var userRoleRepository = environment.Resolve<IRepository<UserRolesPartRecord>>();
var user = memberShipService.CreateUser(new CreateUserParams(username, "qwerty123!", username + "@foo.com", "", "", true));
foreach (var roleName in roles.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)) {
var role = roleService.GetRoleByName(roleName);
userRoleRepository.Create(new UserRolesPartRecord { UserId = user.Id, Role = role });
}
}
});
}
[Given(@"I have a user ""(.*)"" with permissions ""(.*)""")]
public void GivenIHaveAUserWithPermissions(string username, string permissions) {
var roleName = Guid.NewGuid().ToString("n");
WhenIHaveARoleWithPermissions(roleName, permissions);
GivenIHaveCreatedAUser(username, roleName);
}
[When(@"I sign in as ""(.*)""")]
public void WhenISignInAs(string username) {
var webApp = Binding<WebAppHosting>();
var logonForm = TableData(
new { name = "userNameOrEmail", value = username },
new { name = "password", value = "qwerty123!" });
webApp.WhenIGoTo("/users/account/logoff");
webApp.WhenIGoTo("/users/account/logon");
webApp.WhenIFillIn(logonForm);
webApp.WhenIHit("Sign In");
webApp.WhenIAmRedirected();
}
}
}

View File

@@ -308,6 +308,13 @@ namespace Orchard.Specs.Bindings {
public void ThenTheTitleContainsText(string text) {
ScenarioContext.Current.Pending();
}
[Then(@"I should be denied access when I go to ""(.*)""")]
public void ThenIShouldBeDeniedAccessWhenIGoTo(string urlPath) {
WhenIGoTo(urlPath);
WhenIAmRedirected();
ThenIShouldSee("Access Denied");
}
}
public class Form {

View File

@@ -11,7 +11,7 @@ Scenario: Administrators can manage a Page
Scenario: Users can't create a Page if they don't have the PublishContent permission
Given I have installed Orchard
When I have a role "CustomRole" with permissions "EditOthersContent, DeleteOthersContent"
When I have a role "CustomRole" with permissions "EditContent, DeleteContent"
And I have a user "user1" with roles "CustomRole"
Then "user1" should not be able to "publish" a "Page" owned by "user1"
And "user1" should be able to "edit" a "Page" owned by "user1"
@@ -19,7 +19,7 @@ Scenario: Users can't create a Page if they don't have the PublishContent permis
Scenario: Users can create a Page of others if they have PublishContent permission
Given I have installed Orchard
When I have a role "CustomRole" with permissions "PublishOthersContent"
When I have a role "CustomRole" with permissions "PublishContent"
And I have a user "user1" with roles "CustomRole"
And I have a user "user2" with roles "Administrator"
Then "user1" should be able to "publish" a "Page" owned by "user2"
@@ -44,7 +44,7 @@ Scenario: Users can create and edit a Page even if they only have the PublishOwn
Scenario: Users can't edit a Page if they don't have the EditContent permission
Given I have installed Orchard
When I have a role "CustomRole" with permissions "DeleteOthersContent"
When I have a role "CustomRole" with permissions "DeleteContent"
And I have a user "user1" with roles "CustomRole"
Then "user1" should not be able to "publish" a "Page" owned by "user1"
And "user1" should not be able to "edit" a "Page" owned by "user1"

View File

@@ -82,7 +82,7 @@ this.ScenarioSetup(scenarioInfo);
#line 13
testRunner.Given("I have installed Orchard");
#line 14
testRunner.When("I have a role \"CustomRole\" with permissions \"EditOthersContent, DeleteOthersConte" +
testRunner.When("I have a role \"CustomRole\" with permissions \"EditContent, DeleteConte" +
"nt\"");
#line 15
testRunner.And("I have a user \"user1\" with roles \"CustomRole\"");
@@ -106,7 +106,7 @@ this.ScenarioSetup(scenarioInfo);
#line 21
testRunner.Given("I have installed Orchard");
#line 22
testRunner.When("I have a role \"CustomRole\" with permissions \"PublishOthersContent\"");
testRunner.When("I have a role \"CustomRole\" with permissions \"PublishContent\"");
#line 23
testRunner.And("I have a user \"user1\" with roles \"CustomRole\"");
#line 24
@@ -179,7 +179,7 @@ this.ScenarioSetup(scenarioInfo);
#line 46
testRunner.Given("I have installed Orchard");
#line 47
testRunner.When("I have a role \"CustomRole\" with permissions \"DeleteOthersContent\"");
testRunner.When("I have a role \"CustomRole\" with permissions \"DeleteContent\"");
#line 48
testRunner.And("I have a user \"user1\" with roles \"CustomRole\"");
#line 49

View File

@@ -23,9 +23,15 @@ namespace Orchard.Specs.Hosting {
var details = new RequestDetails {
HostName = webHost.HostName,
UrlPath = urlPath,
Page = (isHomepage ? "" : physicalPath.Combine(urlPath.TrimStart('/', '\\')).GetRelativePath(physicalPath).ToString())
};
int queryIndex = urlPath.IndexOf('?');
if (queryIndex >= 0) {
details.UrlPath = urlPath.Substring(0, queryIndex);
details.Query = HttpUtility.UrlDecode(urlPath.Substring(queryIndex + 1));
}
details.Page = (isHomepage ? "" : physicalPath.Combine(details.UrlPath.TrimStart('/', '\\')).GetRelativePath(physicalPath).ToString());
if (!string.IsNullOrEmpty(webHost.Cookies)) {
details.RequestHeaders.Add("Cookie", webHost.Cookies);
}
@@ -123,7 +129,7 @@ namespace Orchard.Specs.Hosting {
if (_details.RequestHeaders.TryGetValue("Cookie", out value))
return value;
}
else if (index==HeaderHost) {
else if (index == HeaderHost) {
return _details.HostName;
}
return base.GetKnownRequestHeader(index);

View File

@@ -78,17 +78,15 @@ namespace Orchard.Specs.Hosting {
.ShallowCopy("*.dll", _tempSite.Combine("bin"))
.ShallowCopy("*.pdb", _tempSite.Combine("bin"));
Log("Copy SqlCe binaries");
Log("Copy SqlCe native binaries");
if (_orchardWebPath.Combine("bin").Combine("x86").IsDirectory) {
_orchardWebPath.Combine("bin").Combine("x86")
.ShallowCopy("*.dll", _tempSite.Combine("bin").Combine("x86"))
.ShallowCopy("*.pdb", _tempSite.Combine("bin").Combine("x86"));
.DeepCopy("*.*", _tempSite.Combine("bin").Combine("x86"));
}
if (_orchardWebPath.Combine("bin").Combine("amd64").IsDirectory) {
_orchardWebPath.Combine("bin").Combine("amd64")
.ShallowCopy("*.dll", _tempSite.Combine("bin").Combine("amd64"))
.ShallowCopy("*.pdb", _tempSite.Combine("bin").Combine("amd64"));
.DeepCopy("*.*", _tempSite.Combine("bin").Combine("amd64"));
}
// Copy binaries of this project, so that remote execution of lambda

View File

@@ -132,6 +132,7 @@
<Compile Include="Bindings\CommandLine.cs" />
<Compile Include="Bindings\ContentRights.cs" />
<Compile Include="Bindings\OrchardSiteFactory.cs" />
<Compile Include="Bindings\UsersPermissionsAndRoles.cs" />
<Compile Include="Blogs.feature.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
@@ -180,6 +181,11 @@
<DesignTime>True</DesignTime>
<DependentUpon>Pages.feature</DependentUpon>
</Compile>
<Compile Include="PermissionModel.feature.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>PermissionModel.feature</DependentUpon>
</Compile>
<Compile Include="Setup.feature.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
@@ -249,6 +255,10 @@
<Generator>SpecFlowSingleFileGenerator</Generator>
<LastGenOutput>ContentTypes.feature.cs</LastGenOutput>
</None>
<None Include="PermissionModel.feature">
<Generator>SpecFlowSingleFileGenerator</Generator>
<LastGenOutput>PermissionModel.feature.cs</LastGenOutput>
</None>
<Content Include="Hosting\TemplateConfigs\DisableDynamicCompilation.HostComponents.config">
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>

View File

@@ -0,0 +1,29 @@
Feature: Addition
In order to prevent security model regressions
As a user with specific permissions
I should to be granted or denied access to various actions
@security
Scenario: Login can be automated
Given I have installed Orchard
And I have a user "bob" with permissions "AccessFrontEnd"
When I go to "users/account/logoff"
And I go to "users/account/logon"
And I fill in
| name | value |
| userNameOrEmail | bob |
| password | qwerty123! |
And I hit "Sign In"
And I am redirected
Then I should see "Welcome"
And I should see "bob"
@security
Scenario: Anonymous user can see the home page but not the dashboard
Given I have installed Orchard
And I have a user "bob" with permissions "AccessFrontEnd"
When I sign in as "bob"
And I go to "/"
Then I should see "this is the homepage of your new site"
And I should be denied access when I go to "admin"

View File

@@ -0,0 +1,123 @@
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by SpecFlow (http://www.specflow.org/).
// SpecFlow Version:1.5.0.0
// Runtime Version:4.0.30319.1
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
// ------------------------------------------------------------------------------
#region Designer generated code
namespace Orchard.Specs
{
using TechTalk.SpecFlow;
[System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.5.0.0")]
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[NUnit.Framework.TestFixtureAttribute()]
[NUnit.Framework.DescriptionAttribute("Addition")]
public partial class AdditionFeature
{
private static TechTalk.SpecFlow.ITestRunner testRunner;
#line 1 "PermissionModel.feature"
#line hidden
[NUnit.Framework.TestFixtureSetUpAttribute()]
public virtual void FeatureSetup()
{
testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner();
TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Addition", "In order to prevent security model regressions\r\nAs a user with specific permissio" +
"ns\r\nI should to be granted or denied access to various actions", GenerationTargetLanguage.CSharp, ((string[])(null)));
testRunner.OnFeatureStart(featureInfo);
}
[NUnit.Framework.TestFixtureTearDownAttribute()]
public virtual void FeatureTearDown()
{
testRunner.OnFeatureEnd();
testRunner = null;
}
public virtual void ScenarioSetup(TechTalk.SpecFlow.ScenarioInfo scenarioInfo)
{
testRunner.OnScenarioStart(scenarioInfo);
}
[NUnit.Framework.TearDownAttribute()]
public virtual void ScenarioTearDown()
{
testRunner.OnScenarioEnd();
}
[NUnit.Framework.TestAttribute()]
[NUnit.Framework.DescriptionAttribute("Login can be automated")]
[NUnit.Framework.CategoryAttribute("security")]
public virtual void LoginCanBeAutomated()
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Login can be automated", new string[] {
"security"});
#line 7
this.ScenarioSetup(scenarioInfo);
#line 8
testRunner.Given("I have installed Orchard");
#line 9
testRunner.And("I have a user \"bob\" with permissions \"AccessFrontEnd\"");
#line 10
testRunner.When("I go to \"users/account/logoff\"");
#line 11
testRunner.And("I go to \"users/account/logon\"");
#line hidden
TechTalk.SpecFlow.Table table1 = new TechTalk.SpecFlow.Table(new string[] {
"name",
"value"});
table1.AddRow(new string[] {
"userNameOrEmail",
"bob"});
table1.AddRow(new string[] {
"password",
"qwerty123!"});
#line 12
testRunner.And("I fill in", ((string)(null)), table1);
#line 16
testRunner.And("I hit \"Sign In\"");
#line 17
testRunner.And("I am redirected");
#line 18
testRunner.Then("I should see \"Welcome\"");
#line 19
testRunner.And("I should see \"bob\"");
#line hidden
testRunner.CollectScenarioErrors();
}
[NUnit.Framework.TestAttribute()]
[NUnit.Framework.DescriptionAttribute("Anonymous user can see the home page but not the dashboard")]
[NUnit.Framework.CategoryAttribute("security")]
public virtual void AnonymousUserCanSeeTheHomePageButNotTheDashboard()
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Anonymous user can see the home page but not the dashboard", new string[] {
"security"});
#line 22
this.ScenarioSetup(scenarioInfo);
#line 23
testRunner.Given("I have installed Orchard");
#line 24
testRunner.And("I have a user \"bob\" with permissions \"AccessFrontEnd\"");
#line 25
testRunner.When("I sign in as \"bob\"");
#line 26
testRunner.And("I go to \"/\"");
#line 27
testRunner.Then("I should see \"this is the homepage of your new site\"");
#line 28
testRunner.And("I should be denied access when I go to \"admin\"");
#line hidden
testRunner.CollectScenarioErrors();
}
}
}
#endregion

View File

@@ -30,5 +30,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.9.0")]
[assembly: AssemblyFileVersion("0.9.0")]
[assembly: AssemblyVersion("1.0.20")]
[assembly: AssemblyFileVersion("1.0.20")]

View File

@@ -51,4 +51,4 @@ Scenario: Calling setup on a brand new install
And I hit "Finish Setup"
And I go to "/"
Then I should see "My Site"
And I should see "Welcome, <strong>admin</strong>!"
And I should see "Welcome, <strong><a href="/Users/Account/ChangePassword">admin</a></strong>!"

View File

@@ -1,7 +1,7 @@
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by SpecFlow (http://www.specflow.org/).
// SpecFlow Version:1.4.0.0
// SpecFlow Version:1.5.0.0
// Runtime Version:4.0.30319.1
//
// Changes to this file may cause incorrect behavior and will be lost if
@@ -14,7 +14,7 @@ namespace Orchard.Specs
using TechTalk.SpecFlow;
[System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.4.0.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.5.0.0")]
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[NUnit.Framework.TestFixtureAttribute()]
[NUnit.Framework.DescriptionAttribute("Setup")]
@@ -212,7 +212,8 @@ this.ScenarioSetup(scenarioInfo);
#line 53
testRunner.Then("I should see \"My Site\"");
#line 54
testRunner.And("I should see \"Welcome, <strong>admin</strong>!\"");
testRunner.And("I should see \"Welcome, <strong><a href=\"/Users/Account/ChangePassword\">admin</a><" +
"/strong>!\"");
#line hidden
testRunner.CollectScenarioErrors();
}

View File

@@ -231,14 +231,14 @@ namespace Orchard.Tests.Modules.Indexing {
_provider.Store("default", _provider.New(2).Add("body", "Renaud is also in the kitchen.").Analyze().Add("title", "A love affair").Analyze());
_provider.Store("default", _provider.New(3).Add("body", "Bertrand is a little bit jealous.").Analyze().Add("title", "Soap opera").Analyze());
Assert.That(_searchBuilder.Parse(new[] { "body" }, "kitchen").Count(), Is.EqualTo(2));
Assert.That(_searchBuilder.Parse(new[] { "body" }, "kitchen bertrand").Count(), Is.EqualTo(3));
Assert.That(_searchBuilder.Parse(new[] { "body" }, "kitchen +bertrand").Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.Parse(new[] { "body" }, "+kitchen +bertrand").Count(), Is.EqualTo(0));
Assert.That(_searchBuilder.Parse(new[] { "body" }, "kit").Count(), Is.EqualTo(0));
Assert.That(_searchBuilder.Parse(new[] { "body" }, "kit*").Count(), Is.EqualTo(2));
Assert.That(_searchBuilder.Parse(new[] { "body", "title" }, "bradley love^3 soap").Count(), Is.EqualTo(3));
Assert.That(_searchBuilder.Parse(new[] { "body", "title" }, "bradley love^3 soap").Search().First().ContentItemId, Is.EqualTo(2));
Assert.That(_searchBuilder.Parse(new[] { "body" }, "kitchen", false).Count(), Is.EqualTo(2));
Assert.That(_searchBuilder.Parse(new[] { "body" }, "kitchen bertrand", false).Count(), Is.EqualTo(3));
Assert.That(_searchBuilder.Parse(new[] { "body" }, "kitchen +bertrand", false).Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.Parse(new[] { "body" }, "+kitchen +bertrand", false).Count(), Is.EqualTo(0));
Assert.That(_searchBuilder.Parse(new[] { "body" }, "kit", false).Count(), Is.EqualTo(0));
Assert.That(_searchBuilder.Parse(new[] { "body" }, "kit*", false).Count(), Is.EqualTo(2));
Assert.That(_searchBuilder.Parse(new[] { "body", "title" }, "bradley love^3 soap", false).Count(), Is.EqualTo(3));
Assert.That(_searchBuilder.Parse(new[] { "body", "title" }, "bradley love^3 soap", false).Search().First().ContentItemId, Is.EqualTo(2));
}
[Test]
@@ -287,13 +287,13 @@ namespace Orchard.Tests.Modules.Indexing {
[Test]
public void FiltersShouldNotAlterResults() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("body", "Orchard has been developped by Mirosoft in C#").Analyze().Add("culture", 1033));
_provider.Store("default", _provider.New(2).Add("body", "Windows a été développé par Mirosoft en C++").Analyze().Add("culture", 1036));
_provider.Store("default", _provider.New(1).Add("body", "Orchard has been developped by Microsoft in C#").Analyze().Add("culture", 1033));
_provider.Store("default", _provider.New(2).Add("body", "Windows a été développé par Microsoft en C++").Analyze().Add("culture", 1036));
_provider.Store("default", _provider.New(3).Add("title", "Home").Analyze().Add("culture", 1033));
Assert.That(_searchBuilder.WithField("body", "Mirosoft").Count(), Is.EqualTo(2));
Assert.That(_searchBuilder.WithField("body", "Mirosoft").WithField("culture", 1033).Count(), Is.EqualTo(3));
Assert.That(_searchBuilder.WithField("body", "Mirosoft").WithField("culture", 1033).AsFilter().Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("body", "Microsoft").Count(), Is.EqualTo(2));
Assert.That(_searchBuilder.WithField("body", "Microsoft").WithField("culture", 1033).Count(), Is.EqualTo(3));
Assert.That(_searchBuilder.WithField("body", "Microsoft").WithField("culture", 1033).AsFilter().Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("body", "Orchard").WithField("culture", 1036).Count(), Is.EqualTo(2));
Assert.That(_searchBuilder.WithField("body", "Orchard").WithField("culture", 1036).AsFilter().Count(), Is.EqualTo(0));
@@ -308,6 +308,14 @@ namespace Orchard.Tests.Modules.Indexing {
Assert.That(_searchBuilder.Parse("title", "home").WithField("culture", 1033).AsFilter().Count(), Is.EqualTo(1));
}
[Test]
public void ParsedTextShouldBeEscapedByDefault() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("body", "foo.bar").Analyze());
Assert.That(_searchBuilder.Parse("body", "*@!woo*@!").Count(), Is.EqualTo(0));
}
[Test]
public void FieldsCanContainMultipleValue() {
_provider.CreateIndex("default");
@@ -333,5 +341,32 @@ namespace Orchard.Tests.Modules.Indexing {
Assert.That(_searchBuilder.WithField("tag-value", "tag").Count(), Is.EqualTo(1));
}
[Test]
public void ShouldReturnAllDocuments() {
_provider.CreateIndex("default");
for(var i = 1; i<100;i++) {
_provider.Store("default", _provider.New(i).Add("term-id", i).Store());
}
Assert.That(_searchBuilder.Count(), Is.EqualTo(99));
}
[Test]
public void NoClauseButAFilter() {
_provider.CreateIndex("default");
for (var i = 1; i < 50; i++) {
_provider.Store("default", _provider.New(i).Add("term-id", i / 10).Store());
}
Assert.That(_searchBuilder.Count(), Is.EqualTo(49));
Assert.That(_searchBuilder.WithField("term-id", 0).ExactMatch().AsFilter().Count(), Is.EqualTo(9));
Assert.That(_searchBuilder.WithField("term-id", 1).ExactMatch().AsFilter().Count(), Is.EqualTo(10));
Assert.That(_searchBuilder.WithField("term-id", 2).ExactMatch().AsFilter().Count(), Is.EqualTo(10));
Assert.That(_searchBuilder.WithField("term-id", 3).ExactMatch().AsFilter().Count(), Is.EqualTo(10));
Assert.That(_searchBuilder.WithField("term-id", 4).ExactMatch().AsFilter().Count(), Is.EqualTo(10));
}
}
}

View File

@@ -138,6 +138,8 @@
<Compile Include="Comments\Services\CommentServiceTests.cs" />
<Compile Include="Indexing\LuceneIndexProviderTests.cs" />
<Compile Include="Indexing\LuceneSearchBuilderTests.cs" />
<Compile Include="Scripting.Dlr\EvaluatorTests.cs" />
<Compile Include="Scripting\EvaluatorTestsBase.cs" />
<Compile Include="Scripting\EvaluatorTests.cs" />
<Compile Include="Scripting\ParserTests.cs" />
<Compile Include="Scripting\TokenizerTests.cs" />
@@ -276,11 +278,11 @@
-->
<Target Name="CopySqlCeBinaries">
<ItemGroup>
<SqlCeBinariesx86 Include="$(ProjectDir)..\..\lib\sqlce\x86\*.*" />
<SqlCeBinariesx64 Include="$(ProjectDir)..\..\lib\sqlce\amd64\*.*" />
<SqlCeBinariesx86 Include="$(ProjectDir)..\..\lib\sqlce\x86\**\*" />
<SqlCeBinariesx64 Include="$(ProjectDir)..\..\lib\sqlce\amd64\**\*" />
</ItemGroup>
<Copy SourceFiles="@(SqlCeBinariesx86)" DestinationFolder="$(OutputPath)\x86" SkipUnchangedFiles="true" />
<Copy SourceFiles="@(SqlCeBinariesx64)" DestinationFolder="$(OutputPath)\amd64" SkipUnchangedFiles="true" />
<Copy SourceFiles="@(SqlCeBinariesx86)" DestinationFolder="$(OutputPath)\x86\%(RecursiveDir)" SkipUnchangedFiles="true" />
<Copy SourceFiles="@(SqlCeBinariesx64)" DestinationFolder="$(OutputPath)\amd64\%(RecursiveDir)" SkipUnchangedFiles="true" />
</Target>
<Target Name="AfterBuild">
<CallTarget Targets="CopySqlCeBinaries" />

View File

@@ -11,6 +11,8 @@ using Orchard.Tests.Stubs;
namespace Orchard.Tests.Modules.Packaging {
[TestFixture]
public class PackageBuilderTests : ContainerTestBase {
private const string PackageIdentifier = "Hello.World";
protected override void Register(Autofac.ContainerBuilder builder) {
builder.RegisterType<PackageBuilder>().As<IPackageBuilder>();
builder.RegisterType<InMemoryWebSiteFolder>().As<IWebSiteFolder>()
@@ -27,7 +29,7 @@ namespace Orchard.Tests.Modules.Packaging {
return packageBuilder.BuildPackage(new ExtensionDescriptor {
ExtensionType = DefaultExtensionTypes.Module,
Id = "Hello.World",
Id = PackageIdentifier,
Version = "1.0",
Description = "a",
Author = "b"
@@ -41,7 +43,7 @@ namespace Orchard.Tests.Modules.Packaging {
var package = Package.Open(stream);
Assert.That(package, Is.Not.Null);
Assert.That(package.PackageProperties.Identifier, Is.EqualTo("Orchard.Module.Hello.World"));
Assert.That(package.PackageProperties.Identifier, Is.EqualTo(PackageBuilder.BuildPackageId(PackageIdentifier, DefaultExtensionTypes.Module)));
}
[Test]

View File

@@ -30,5 +30,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.9.0")]
[assembly: AssemblyFileVersion("0.9.0")]
[assembly: AssemblyVersion("1.0.20")]
[assembly: AssemblyFileVersion("1.0.20")]

View File

@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Autofac;
using NUnit.Framework;
using Orchard.Scripting;
using Orchard.Scripting.Compiler;
using Orchard.Scripting.Dlr.Services;
using Orchard.Tests.Stubs;
namespace Orchard.Tests.Modules.Scripting.Dlr {
[TestFixture]
public class EvaluatorTests : EvaluatorTestsBase {
private IContainer _container;
private IScriptingManager _scriptingManager;
[SetUp]
public void Init() {
var builder = new ContainerBuilder();
builder.RegisterType<RubyScriptingRuntime>().As<IScriptingRuntime>();
builder.RegisterType<ScriptingManager>().As<IScriptingManager>();
_container = builder.Build();
_scriptingManager = _container.Resolve<IScriptingManager>();
}
protected override EvaluationResult EvaluateSimpleExpression(string expression, Func<string, IList<object>, object> methodInvocationCallback) {
var evaluator = new RubyScriptExpressionEvaluator(_scriptingManager, new StubCacheManager());
try {
var value = evaluator.Evaluate(expression, new[] { new GlobalMethodProvider(methodInvocationCallback) });
return new EvaluationResult(value);
}
catch (Exception e) {
Trace.WriteLine(string.Format("Error during evaluation of '{0}': {1}", expression, e.Message));
return new EvaluationResult(new Error { Message = e.Message, Exception = e });
}
}
private class GlobalMethodProvider : IGlobalMethodProvider {
private readonly Func<string, IList<object>, object> _methodInvocationCallback;
public GlobalMethodProvider(Func<string, IList<object>, object> methodInvocationCallback) {
_methodInvocationCallback = methodInvocationCallback;
}
public void Process(GlobalMethodContext context) {
context.Result = _methodInvocationCallback(context.FunctionName, context.Arguments);
}
}
}
}

View File

@@ -7,146 +7,17 @@ using Orchard.Scripting.Compiler;
namespace Orchard.Tests.Modules.Scripting {
[TestFixture]
public class EvaluatorTests {
[Test]
public void EvaluateSimpleConstant() {
var result = EvaluateSimpleExpression("true and true");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateInvalidBooleanExpression() {
var result = EvaluateSimpleExpression("true and 1");
Assert.That(result.IsError, Is.True);
}
[Test]
public void EvaluateBooleanExpression() {
var result = EvaluateSimpleExpression("not true");
Assert.That(result.IsError, Is.False);
Assert.That(result.BoolValue, Is.EqualTo(false));
}
[Test]
public void EvaluateSimpleArithmetic() {
var result = EvaluateSimpleExpression("1 + 2 * 3 - 6 / 2");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(4));
}
[Test]
public void EvaluateRelationalOperators() {
var result = EvaluateSimpleExpression("1 < 2");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateRelationalOperators2() {
var result = EvaluateSimpleExpression("2 <= 2");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateRelationalOperators3() {
var result = EvaluateSimpleExpression("1 < 2 or 2 > 3 and !false");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateRelationalOperators4() {
var result = EvaluateSimpleExpression("1 > 2 or 2 > 3 and !false");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(false));
}
[Test]
public void EvaluateRelationalOperators5() {
var result = EvaluateSimpleExpression("1 > 2 or 4 > 3 and !false");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateRelationalOperators6() {
var result = EvaluateSimpleExpression("!false");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateEqualityOperators() {
var result = EvaluateSimpleExpression("1 == 2");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(false));
}
[Test]
public void EvaluateEqualityOperators2() {
var result = EvaluateSimpleExpression("1 != 2");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateSimpleMethodCall() {
var result = EvaluateSimpleExpression("print 1 + 2 * 3 - 6 / 2",
(m, args) => (m == "print") ? (int)args[0] * 2 : 0);
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(4 * 2));
}
[Test]
public void EvaluateSimpleMethodCall2() {
var result = EvaluateSimpleExpression("foo 1 + bar 3",
(m, args) =>
(m == "foo") ? (int)args[0] * 2 :
(m == "bar") ? (int)args[0] : 0);
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(2 * (1 + 3)));
}
[Test]
public void EvaluateSimpleMethodCall3() {
var result = EvaluateSimpleExpression("foo(1) + bar(3)",
(m, args) =>
(m == "foo") ? (int)args[0] * 2 :
(m == "bar") ? (int)args[0] : 0);
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(2 + 3));
}
[Test]
public void EvaluateSimpleMethodCall4() {
var result = EvaluateSimpleExpression("foo",
(m, args) => (m == "foo") ? true : false);
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateSimpleMethodCall5() {
var result = EvaluateSimpleExpression("foo()",
(m, args) => (m == "foo") ? true : false);
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
private EvaluationResult EvaluateSimpleExpression(string expression) {
return EvaluateSimpleExpression(expression, (m, args) => null);
}
private EvaluationResult EvaluateSimpleExpression(
string expression, Func<string, IList<object>, object> methodInvocationCallback) {
public class EvaluatorTests : EvaluatorTestsBase {
protected override EvaluationResult EvaluateSimpleExpression(string expression, Func<string, IList<object>, object> methodInvocationCallback) {
var ast = new Parser(expression).Parse();
foreach(var error in ast.GetErrors()) {
foreach (var error in ast.GetErrors()) {
Trace.WriteLine(string.Format("Error during parsing of '{0}': {1}", expression, error.Message));
}
Assert.That(ast.GetErrors().Any(), Is.False);
if (ast.GetErrors().Any()) {
return new EvaluationResult(new Error { Message = ast.GetErrors().First().Message });
}
var result = new Interpreter().Evalutate(new EvaluationContext {
Tree = ast,
MethodInvocationCallback = methodInvocationCallback
@@ -155,4 +26,4 @@ namespace Orchard.Tests.Modules.Scripting {
return result;
}
}
}
}

View File

@@ -0,0 +1,526 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using Orchard.Scripting.Compiler;
namespace Orchard.Tests.Modules.Scripting {
public abstract class EvaluatorTestsBase {
[Test]
public void EvaluateSimpleConstant() {
var result = EvaluateSimpleExpression("true and true");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateSimpleConstant0() {
var result = EvaluateSimpleExpression("true && true");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateConvertingBooleanExpression() {
var result = EvaluateSimpleExpression("true and 1");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(1));
}
[Test]
public void EvaluateConvertingBooleanExpression1() {
var result = EvaluateSimpleExpression("true && 1");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(1));
}
[Test]
public void EvaluateConvertingBooleanExpression2() {
var result = EvaluateSimpleExpression("true and 0");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(0));
}
[Test]
public void EvaluateConvertingBooleanExpression3() {
var result = EvaluateSimpleExpression("true && 0");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(0));
}
[Test]
public void EvaluateConvertingBooleanExpression4() {
var result = EvaluateSimpleExpression("1 and true");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateConvertingBooleanExpression5() {
var result = EvaluateSimpleExpression("0 and true");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateConvertingBooleanExpression6() {
var result = EvaluateSimpleExpression("1 && true");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateConvertingBooleanExpression7() {
var result = EvaluateSimpleExpression("true and 'boo'");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo("boo"));
}
[Test]
public void EvaluateConvertingBooleanExpression8() {
var result = EvaluateSimpleExpression("true && 'boo'");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo("boo"));
}
[Test]
public void EvaluateConvertingBooleanExpression9() {
var result = EvaluateSimpleExpression("'boo' and true");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateConvertingBooleanExpression10() {
var result = EvaluateSimpleExpression("'boo' && true");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateConvertingBooleanExpression11() {
var result = EvaluateSimpleExpression("true or 1");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateConvertingBooleanExpression12() {
var result = EvaluateSimpleExpression("true || 1");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateConvertingBooleanExpression13() {
var result = EvaluateSimpleExpression("1 or true");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(1));
}
[Test]
public void EvaluateConvertingBooleanExpression14() {
var result = EvaluateSimpleExpression("1 || true");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(1));
}
[Test]
public void EvaluateConvertingBooleanExpression15() {
var result = EvaluateSimpleExpression("true or 'boo'");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateConvertingBooleanExpression16() {
var result = EvaluateSimpleExpression("false or 'boo'");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo("boo"));
}
[Test]
public void EvaluateConvertingBooleanExpression17() {
var result = EvaluateSimpleExpression("nil or 'boo'");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo("boo"));
}
[Test]
public void EvaluateConvertingBooleanExpression18() {
var result = EvaluateSimpleExpression("'boo' or nil");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo("boo"));
}
[Test]
public void EvaluateConvertingBooleanExpression19() {
var result = EvaluateSimpleExpression("true || 'boo'");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateConvertingBooleanExpression20() {
var result = EvaluateSimpleExpression("'boo' or true");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo("boo"));
}
[Test]
public void EvaluateConvertingBooleanExpression21() {
var result = EvaluateSimpleExpression("'boo' || true");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo("boo"));
}
[Test]
public void EvaluateConvertingBooleanExpression22() {
var result = EvaluateSimpleExpression("1 and 2");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(2));
}
[Test]
public void EvaluateConvertingBooleanExpression23() {
var result = EvaluateSimpleExpression("false and 2");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(false));
}
[Test]
public void EvaluateConvertingBooleanExpression24() {
var result = EvaluateSimpleExpression("nil and 2");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(null));
}
[Test]
public void EvaluateConvertingBooleanExpression25() {
var result = EvaluateSimpleExpression("nil and false");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(null));
}
[Test]
public void EvaluateConvertingBooleanExpression26() {
var result = EvaluateSimpleExpression("nil and true");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(null));
}
[Test]
public void EvaluateBooleanExpression() {
var result = EvaluateSimpleExpression("not true");
Assert.That(result.IsError, Is.False);
Assert.That(result.BoolValue, Is.EqualTo(false));
}
[Test]
public void EvaluateBooleanExpression0() {
var result = EvaluateSimpleExpression("!true");
Assert.That(result.IsError, Is.False);
Assert.That(result.BoolValue, Is.EqualTo(false));
}
[Test]
public void EvaluateSimpleArithmetic() {
var result = EvaluateSimpleExpression("1 + 2 * 3 - 6 / 2");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(4));
}
[Test]
public void EvaluateRelationalOperators() {
var result = EvaluateSimpleExpression("1 < 2");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateRelationalOperators2() {
var result = EvaluateSimpleExpression("2 <= 2");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateRelationalOperators3() {
var result = EvaluateSimpleExpression("1 < 2 or 2 > 3 and !false");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateRelationalOperators4() {
var result = EvaluateSimpleExpression("1 > 2 or 2 > 3 and !false");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(false));
}
[Test]
public void EvaluateRelationalOperators5() {
var result = EvaluateSimpleExpression("1 > 2 or 4 > 3 and !false");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateRelationalOperators6() {
var result = EvaluateSimpleExpression("!false");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateRelationalOperators7() {
var result = EvaluateSimpleExpression("5 || 10 && nil");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(5));
}
[Test]
public void EvaluateRelationalOperators8() {
var result = EvaluateSimpleExpression("true or false and nil");
Assert.That(result.IsError, Is.False);
Assert.That(result.IsNull, Is.True);
}
[Test]
public void EvaluateRelationalOperators9() {
var result = EvaluateSimpleExpression("true and nil");
Assert.That(result.IsError, Is.False);
Assert.That(result.IsNull, Is.True);
}
[Test]
public void EvaluateRelationalOperators10() {
var result = EvaluateSimpleExpression("5 and nil");
Assert.That(result.IsError, Is.False);
Assert.That(result.IsNull, Is.True);
}
[Test]
public void EvaluateEqualityOperators() {
var result = EvaluateSimpleExpression("1 == 2");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(false));
}
[Test]
public void EvaluateEqualityOperators2() {
var result = EvaluateSimpleExpression("1 != 2");
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateSimpleMethodCall() {
var result = EvaluateSimpleExpression("printtoto 1 + 2 * 3 - 6 / 2",
(m, args) => (m == "printtoto") ? (int)args[0] * 2 : 0);
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(4 * 2));
}
[Test]
public void EvaluateSimpleMethodCall2() {
var result = EvaluateSimpleExpression("printtoto(1 + 2 * 3 - 6 / 2)",
(m, args) => (m == "printtoto") ? (int)args[0] * 2 : 0);
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(4 * 2));
}
[Test]
public void EvaluateSimpleMethodCall3() {
var result = EvaluateSimpleExpression("foo 1 + bar 3",
(m, args) =>
(m == "foo") ? (int)args[0] * 2 :
(m == "bar") ? (int)args[0] : 0);
Assert.That(result.IsError, Is.True);
}
[Test]
public void EvaluateSimpleMethodCall4() {
var result = EvaluateSimpleExpression("foo(1 + bar 3)",
(m, args) =>
(m == "foo") ? (int)args[0] * 2 :
(m == "bar") ? (int)args[0] : 0);
Assert.That(result.IsError, Is.True);
}
[Test]
public void EvaluateSimpleMethodCall5() {
var result = EvaluateSimpleExpression("foo 1 + bar(3)",
(m, args) =>
(m == "foo") ? (int)args[0] * 2 :
(m == "bar") ? (int)args[0] : 0);
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(2 * (1 + 3)));
}
[Test]
public void EvaluateSimpleMethodCall6() {
var result = EvaluateSimpleExpression("foo(1) + bar(3)",
(m, args) =>
(m == "foo") ? (int)args[0] * 2 :
(m == "bar") ? (int)args[0] : 0);
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(2 + 3));
}
[Test]
public void EvaluateSimpleMethodCall7() {
var result = EvaluateSimpleExpression("foo",
(m, args) => (m == "foo") ? true : false);
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateSimpleMethodCall8() {
var result = EvaluateSimpleExpression("foo()",
(m, args) => (m == "foo") ? true : false);
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateSimpleMethodCall9() {
#if false
var result = EvaluateSimpleExpression("1 + bar 3",
(m, args) =>
(m == "bar") ? (int)args[0] : 0);
Assert.That(result.IsError, Is.True);
#endif
}
[Test]
public void EvaluateSimpleMethodCall10() {
#if false
var result = EvaluateSimpleExpression("1 || bar 3",
(m, args) =>
(m == "bar") ? (int)args[0] : 0);
Assert.That(result.IsError, Is.True);
#endif
}
[Test]
public void EvaluateSimpleMethodCall11() {
#if false
var result = EvaluateSimpleExpression("1 * bar 3",
(m, args) =>
(m == "bar") ? (int)args[0] : 0);
Assert.That(result.IsError, Is.True);
#endif
}
[Test]
public void EvaluateSimpleMethodCall12() {
#if false
var result = EvaluateSimpleExpression("1 && bar 3",
(m, args) =>
(m == "bar") ? (int)args[0] : 0);
Assert.That(result.IsError, Is.True);
#endif
}
[Test]
public void EvaluateSimpleMethodCall13() {
#if false
var result = EvaluateSimpleExpression("(1 + bar 3)",
(m, args) =>
(m == "bar") ? (int)args[0] : 0);
Assert.That(result.IsError, Is.True);
#endif
}
[Test]
public void EvaluateSimpleMethodCall14() {
var result = EvaluateSimpleExpression("1 + bar(3)",
(m, args) =>
(m == "bar") ? (int)args[0] : 0);
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(1 + 3));
}
[Test]
public void EvaluateSimpleMethodCall15() {
var result = EvaluateSimpleExpression("1 + (bar 3)",
(m, args) =>
(m == "bar") ? (int)args[0] : 0);
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(1 + 3));
}
[Test]
public void EvaluateSimpleMethodCall16() {
var result = EvaluateSimpleExpression("1 and bar 3",
(m, args) =>
(m == "bar") ? (int)args[0] : 0);
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(3));
}
[Test]
public void EvaluateSimpleMethodCall17() {
var result = EvaluateSimpleExpression("1 or bar 3",
(m, args) =>
(m == "bar") ? (int)args[0] : 0);
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(1));
}
[Test]
public void EvaluateComplexMethodCall() {
var result = EvaluateSimpleExpression("authenticated and url \"~/boo*\"",
(m, args) => (m == "authenticated") ? true : (m == "url") ? (string)args[0] == "~/boo*" : false);
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateComplexMethodCall2() {
var result = EvaluateSimpleExpression("(authenticated) and (url \"~/boo*\")",
(m, args) => (m == "authenticated") ? true : (m == "url") ? (string)args[0] == "~/boo*" : false);
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateComplexMethodCall3() {
var result = EvaluateSimpleExpression("(authenticated and url \"~/boo*\")",
(m, args) => (m == "authenticated") ? true : (m == "url") ? (string)args[0] == "~/boo*" : false);
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateComplexMethodCall4() {
var result = EvaluateSimpleExpression("(authenticated) and url \"~/boo*\"",
(m, args) => (m == "authenticated") ? true : (m == "url") ? (string)args[0] == "~/boo*" : false);
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateComplexMethodCall5() {
var result = EvaluateSimpleExpression("(authenticated()) and (url \"~/boo*\")",
(m, args) => (m == "authenticated") ? true : (m == "url") ? (string)args[0] == "~/boo*" : false);
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
[Test]
public void EvaluateComplexMethodCall6() {
var result = EvaluateSimpleExpression("authenticated() and url(\"~/boo*\")",
(m, args) => (m == "authenticated") ? true : (m == "url") ? (string)args[0] == "~/boo*" : false);
Assert.That(result.IsError, Is.False);
Assert.That(result.Value, Is.EqualTo(true));
}
private EvaluationResult EvaluateSimpleExpression(string expression) {
return EvaluateSimpleExpression(expression, (m, args) => null);
}
protected abstract EvaluationResult EvaluateSimpleExpression(string expression, Func<string, IList<object>, object> methodInvocationCallback);
}
}

View File

@@ -110,6 +110,30 @@ namespace Orchard.Tests.Modules.Scripting {
});
}
[Test]
public void ParserShouldUnderstandOperatorPrecedence5() {
var tree = new Parser("1+2+3").Parse();
CheckTree(tree, new object[] {
"binop", TokenKind.Plus,
"binop", TokenKind.Plus,
"const", 1,
"const", 2,
"const", 3,
});
}
[Test]
public void ParserShouldUnderstandOperatorPrecedence6() {
var tree = new Parser("1+2-3").Parse();
CheckTree(tree, new object[] {
"binop", TokenKind.Minus,
"binop", TokenKind.Plus,
"const", 1,
"const", 2,
"const", 3,
});
}
[Test]
public void ParserShouldUnderstandRelationalOperators() {
var tree = new Parser("true == true").Parse();
@@ -184,14 +208,14 @@ namespace Orchard.Tests.Modules.Scripting {
public void ParserShouldUnderstandRelationalOperatorPrecedence() {
var tree = new Parser("1 < 2 or 2 > 3 and !false").Parse();
CheckTree(tree, new object[] {
"binop", TokenKind.Or,
"binop", TokenKind.LessThan,
"const", 1,
"const", 2,
"binop", TokenKind.And,
"binop", TokenKind.GreaterThan,
"const", 2,
"const", 3,
"binop", TokenKind.Or,
"binop", TokenKind.LessThan,
"const", 1,
"const", 2,
"binop", TokenKind.GreaterThan,
"const", 2,
"const", 3,
"unop", TokenKind.NotSign,
"const", false,
});
@@ -201,14 +225,14 @@ namespace Orchard.Tests.Modules.Scripting {
public void ParserShouldUnderstandRelationalOperatorPrecedence2() {
var tree = new Parser("1 < 2 and 2 > 3 or !false").Parse();
CheckTree(tree, new object[] {
"binop", TokenKind.And,
"binop", TokenKind.LessThan,
"const", 1,
"const", 2,
"binop", TokenKind.Or,
"binop", TokenKind.GreaterThan,
"const", 2,
"const", 3,
"binop", TokenKind.Or,
"binop", TokenKind.And,
"binop", TokenKind.LessThan,
"const", 1,
"const", 2,
"binop", TokenKind.GreaterThan,
"const", 2,
"const", 3,
"unop", TokenKind.NotSign,
"const", false,
});
@@ -234,11 +258,11 @@ namespace Orchard.Tests.Modules.Scripting {
"binop", TokenKind.Mul,
"const", 1,
"binop", TokenKind.Plus,
"binop", TokenKind.Div,
"const", 2,
"binop", TokenKind.Mul,
"binop", TokenKind.Mul,
"binop", TokenKind.Div,
"const", 2,
"const", 4,
"const", 6,
"const", 6,
"const", 3,
});
}
@@ -246,6 +270,14 @@ namespace Orchard.Tests.Modules.Scripting {
[Test]
public void ParserShouldContainErrorExpressions() {
var tree = new Parser("1 + not 3").Parse();
CheckTree(tree, new object[] {
"error",
});
}
[Test]
public void ParserShouldContainErrorExpressions2() {
var tree = new Parser("1 +").Parse();
CheckTree(tree, new object[] {
"binop", TokenKind.Plus,
"const", 1,

View File

@@ -5,22 +5,20 @@ using Orchard.Utility.Extensions;
namespace Orchard.Tests.Modules.Users {
public class ShellSettingsUtility {
public static ShellSettings CreateEncryptionEnabled() {
// generate random keys for encryption
var key = new byte[32];
var iv = new byte[16];
using ( var random = new RNGCryptoServiceProvider() ) {
random.GetBytes(key);
random.GetBytes(iv);
}
const string encryptionAlgorithm = "AES";
const string hashAlgorithm = "HMACSHA256";
return new ShellSettings {
Name = "Alpha",
RequestUrlHost = "wiki.example.com",
RequestUrlPrefix = "~/foo",
EncryptionAlgorithm = "AES",
EncryptionKey = key.ToHexString(),
EncryptionIV = iv.ToHexString()
EncryptionAlgorithm = encryptionAlgorithm,
EncryptionKey = SymmetricAlgorithm.Create(encryptionAlgorithm).Key.ToHexString(),
HashAlgorithm = hashAlgorithm,
HashKey = HMAC.Create(hashAlgorithm).Key.ToHexString()
};
}
}
}

View File

@@ -11,6 +11,7 @@ using Orchard.ContentManagement.Records;
using Orchard.DisplayManagement;
using Orchard.DisplayManagement.Descriptors;
using Orchard.Environment.Extensions;
using Orchard.Tests.ContentManagement.Handlers;
using Orchard.Tests.ContentManagement.Records;
using Orchard.Tests.ContentManagement.Models;
using Orchard.DisplayManagement.Implementation;
@@ -37,30 +38,23 @@ namespace Orchard.Tests.ContentManagement {
typeof(ContentTypeRecord));
}
[TestFixtureTearDown]
public void TermFixture() {
}
[SetUp]
public void Init() {
var builder = new ContainerBuilder();
// builder.RegisterModule(new ImplicitCollectionSupportModule());
builder.RegisterModule(new ContentModule());
builder.RegisterType<DefaultContentManager>().As<IContentManager>().SingleInstance();
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
builder.RegisterInstance(new Mock<IContentDefinitionManager>().Object);
builder.RegisterInstance(new Mock<IContentDisplay>().Object);
builder.RegisterType<AlphaHandler>().As<IContentHandler>();
builder.RegisterType<BetaHandler>().As<IContentHandler>();
builder.RegisterType<GammaHandler>().As<IContentHandler>();
builder.RegisterType<DeltaHandler>().As<IContentHandler>();
builder.RegisterType<EpsilonHandler>().As<IContentHandler>();
builder.RegisterType<FlavoredHandler>().As<IContentHandler>();
builder.RegisterType<StyledHandler>().As<IContentHandler>();
builder.RegisterType<AlphaPartHandler>().As<IContentHandler>();
builder.RegisterType<BetaPartHandler>().As<IContentHandler>();
builder.RegisterType<GammaPartHandler>().As<IContentHandler>();
builder.RegisterType<DeltaPartHandler>().As<IContentHandler>();
builder.RegisterType<EpsilonPartHandler>().As<IContentHandler>();
builder.RegisterType<FlavoredPartHandler>().As<IContentHandler>();
builder.RegisterType<StyledHandler>().As<IContentHandler>();
builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
@@ -87,10 +81,10 @@ namespace Orchard.Tests.ContentManagement {
}
private void AddSampleData() {
_manager.Create<Alpha>("alpha", init => { });
_manager.Create<Beta>("beta", init => { });
_manager.Create<Gamma>("gamma", init => { init.Record.Frap = "the frap value"; });
_manager.Create<Delta>("delta", init => { init.Record.Quux = "the quux value"; });
_manager.Create<AlphaPart>("alpha", init => { });
_manager.Create<BetaPart>("beta", init => { });
_manager.Create<GammaPart>("gamma", init => { init.Record.Frap = "the frap value"; });
_manager.Create<DeltaPart>("delta", init => { init.Record.Quux = "the quux value"; });
_session.Flush();
}
@@ -136,10 +130,10 @@ namespace Orchard.Tests.ContentManagement {
var allItems = _manager.Query().List();
Assert.That(allItems.Count(), Is.EqualTo(4));
Assert.That(allItems.Count(x => x.Has<Alpha>()), Is.EqualTo(1));
Assert.That(allItems.Count(x => x.Has<Beta>()), Is.EqualTo(1));
Assert.That(allItems.Count(x => x.Has<Gamma>()), Is.EqualTo(1));
Assert.That(allItems.Count(x => x.Has<Delta>()), Is.EqualTo(1));
Assert.That(allItems.Count(x => x.Has<AlphaPart>()), Is.EqualTo(1));
Assert.That(allItems.Count(x => x.Has<BetaPart>()), Is.EqualTo(1));
Assert.That(allItems.Count(x => x.Has<GammaPart>()), Is.EqualTo(1));
Assert.That(allItems.Count(x => x.Has<DeltaPart>()), Is.EqualTo(1));
}
[Test]
@@ -149,37 +143,37 @@ namespace Orchard.Tests.ContentManagement {
var alphaBeta = _manager.Query().ForType("alpha", "beta").List();
Assert.That(alphaBeta.Count(), Is.EqualTo(2));
Assert.That(alphaBeta.Count(x => x.Has<Alpha>()), Is.EqualTo(1));
Assert.That(alphaBeta.Count(x => x.Has<Beta>()), Is.EqualTo(1));
Assert.That(alphaBeta.Count(x => x.Has<Gamma>()), Is.EqualTo(0));
Assert.That(alphaBeta.Count(x => x.Has<Delta>()), Is.EqualTo(0));
Assert.That(alphaBeta.Count(x => x.Has<AlphaPart>()), Is.EqualTo(1));
Assert.That(alphaBeta.Count(x => x.Has<BetaPart>()), Is.EqualTo(1));
Assert.That(alphaBeta.Count(x => x.Has<GammaPart>()), Is.EqualTo(0));
Assert.That(alphaBeta.Count(x => x.Has<DeltaPart>()), Is.EqualTo(0));
var gammaDelta = _manager.Query().ForType("gamma", "delta").List();
Assert.That(gammaDelta.Count(), Is.EqualTo(2));
Assert.That(gammaDelta.Count(x => x.Has<Alpha>()), Is.EqualTo(0));
Assert.That(gammaDelta.Count(x => x.Has<Beta>()), Is.EqualTo(0));
Assert.That(gammaDelta.Count(x => x.Has<Gamma>()), Is.EqualTo(1));
Assert.That(gammaDelta.Count(x => x.Has<Delta>()), Is.EqualTo(1));
Assert.That(gammaDelta.Count(x => x.Has<AlphaPart>()), Is.EqualTo(0));
Assert.That(gammaDelta.Count(x => x.Has<BetaPart>()), Is.EqualTo(0));
Assert.That(gammaDelta.Count(x => x.Has<GammaPart>()), Is.EqualTo(1));
Assert.That(gammaDelta.Count(x => x.Has<DeltaPart>()), Is.EqualTo(1));
}
[Test]
public void WherePredicateRestrictsResults() {
AddSampleData();
_manager.Create<Gamma>("gamma", init => { init.Record.Frap = "one"; });
_manager.Create<Gamma>("gamma", init => { init.Record.Frap = "two"; });
_manager.Create<Gamma>("gamma", init => { init.Record.Frap = "three"; });
_manager.Create<Gamma>("gamma", init => { init.Record.Frap = "four"; });
_manager.Create<GammaPart>("gamma", init => { init.Record.Frap = "one"; });
_manager.Create<GammaPart>("gamma", init => { init.Record.Frap = "two"; });
_manager.Create<GammaPart>("gamma", init => { init.Record.Frap = "three"; });
_manager.Create<GammaPart>("gamma", init => { init.Record.Frap = "four"; });
_session.Flush();
var twoOrFour = _manager.Query<Gamma, GammaRecord>()
var twoOrFour = _manager.Query<GammaPart, GammaRecord>()
.Where(x => x.Frap == "one" || x.Frap == "four")
.List();
Assert.That(twoOrFour.Count(), Is.EqualTo(2));
Assert.That(twoOrFour.Count(x => x.Has<Gamma>()), Is.EqualTo(2));
Assert.That(twoOrFour.Count(x => x.Get<Gamma>().Record.Frap == "one"), Is.EqualTo(1));
Assert.That(twoOrFour.Count(x => x.Get<Gamma>().Record.Frap == "four"), Is.EqualTo(1));
Assert.That(twoOrFour.Count(x => x.Has<GammaPart>()), Is.EqualTo(2));
Assert.That(twoOrFour.Count(x => x.Get<GammaPart>().Record.Frap == "one"), Is.EqualTo(1));
Assert.That(twoOrFour.Count(x => x.Get<GammaPart>().Record.Frap == "four"), Is.EqualTo(1));
}
@@ -191,23 +185,23 @@ namespace Orchard.Tests.ContentManagement {
Assert.That(gammas.Count(), Is.EqualTo(1));
Assert.That(deltas.Count(), Is.EqualTo(1));
Assert.That(gammas.AsPart<Gamma>().Single().Record.Frap, Is.EqualTo("the frap value"));
Assert.That(deltas.AsPart<Delta>().Single().Record.Quux, Is.EqualTo("the quux value"));
Assert.That(gammas.AsPart<GammaPart>().Single().Record.Frap, Is.EqualTo("the frap value"));
Assert.That(deltas.AsPart<DeltaPart>().Single().Record.Quux, Is.EqualTo("the quux value"));
}
[Test]
public void OrderMaySortOnJoinedRecord() {
AddSampleData();
_manager.Create<Gamma>("gamma", init => { init.Record.Frap = "one"; });
_manager.Create<Gamma>("gamma", init => { init.Record.Frap = "two"; });
_manager.Create<Gamma>("gamma", init => { init.Record.Frap = "three"; });
_manager.Create<Gamma>("gamma", init => { init.Record.Frap = "four"; });
_manager.Create<GammaPart>("gamma", init => { init.Record.Frap = "one"; });
_manager.Create<GammaPart>("gamma", init => { init.Record.Frap = "two"; });
_manager.Create<GammaPart>("gamma", init => { init.Record.Frap = "three"; });
_manager.Create<GammaPart>("gamma", init => { init.Record.Frap = "four"; });
_session.Flush();
_session.Clear();
var ascending = _manager.Query("gamma")
.OrderBy<GammaRecord, string>(x => x.Frap)
.List<Gamma>().ToList();
.List<GammaPart>().ToList();
Assert.That(ascending.Count(), Is.EqualTo(5));
Assert.That(ascending.First().Record.Frap, Is.EqualTo("four"));
@@ -215,7 +209,7 @@ namespace Orchard.Tests.ContentManagement {
_session.Clear();
var descending = _manager.Query<Gamma, GammaRecord>()
var descending = _manager.Query<GammaPart, GammaRecord>()
.OrderByDescending(x => x.Frap)
.List().ToList();
@@ -227,10 +221,10 @@ namespace Orchard.Tests.ContentManagement {
[Test]
public void SkipAndTakeProvidePagination() {
AddSampleData();
_manager.Create<Gamma>("gamma", init => { init.Record.Frap = "one"; });
_manager.Create<Gamma>("gamma", init => { init.Record.Frap = "two"; });
_manager.Create<Gamma>("gamma", init => { init.Record.Frap = "three"; });
_manager.Create<Gamma>("gamma", init => { init.Record.Frap = "four"; });
_manager.Create<GammaPart>("gamma", init => { init.Record.Frap = "one"; });
_manager.Create<GammaPart>("gamma", init => { init.Record.Frap = "two"; });
_manager.Create<GammaPart>("gamma", init => { init.Record.Frap = "three"; });
_manager.Create<GammaPart>("gamma", init => { init.Record.Frap = "four"; });
_session.Flush();
var reverseById = _manager.Query()
@@ -261,26 +255,26 @@ namespace Orchard.Tests.ContentManagement {
[Test]
public void QueryShouldJoinVersionedRecords() {
AddSampleData();
_manager.Create<Gamma>("gamma", init => {
_manager.Create<GammaPart>("gamma", init => {
init.Record.Frap = "one";
init.As<Epsilon>().Record.Quad = "1";
init.As<EpsilonPart>().Record.Quad = "1";
});
_manager.Create<Gamma>("gamma", init => {
_manager.Create<GammaPart>("gamma", init => {
init.Record.Frap = "two";
init.As<Epsilon>().Record.Quad = "2";
init.As<EpsilonPart>().Record.Quad = "2";
});
_manager.Create<Gamma>("gamma", init => {
_manager.Create<GammaPart>("gamma", init => {
init.Record.Frap = "three";
init.As<Epsilon>().Record.Quad = "3";
init.As<EpsilonPart>().Record.Quad = "3";
});
_manager.Create<Gamma>("gamma", init => {
_manager.Create<GammaPart>("gamma", init => {
init.Record.Frap = "four";
init.As<Epsilon>().Record.Quad = "4";
init.As<EpsilonPart>().Record.Quad = "4";
});
_session.Flush();
_session.Clear();
var results = _manager.Query<Epsilon, EpsilonRecord>()
var results = _manager.Query<EpsilonPart, EpsilonRecord>()
.Where(x => x.Quad == "2" || x.Quad == "3")
.OrderByDescending(x => x.Quad)
.List();
@@ -293,21 +287,21 @@ namespace Orchard.Tests.ContentManagement {
private void AddGammaVersions() {
var gamma1 = _manager.Create<ContentItem>("gamma", init => {
init.As<Gamma>().Record.Frap = "one";
init.As<Epsilon>().Record.Quad = "v1";
init.As<GammaPart>().Record.Frap = "one";
init.As<EpsilonPart>().Record.Quad = "v1";
});
_session.Flush();
_session.Clear();
var gamma2 = _manager.Get(gamma1.Id, VersionOptions.DraftRequired);
gamma2.As<Gamma>().Record.Frap = "two";
gamma2.As<Epsilon>().Record.Quad = "v2";
gamma2.As<GammaPart>().Record.Frap = "two";
gamma2.As<EpsilonPart>().Record.Quad = "v2";
_session.Flush();
_session.Clear();
var gamma3 = _manager.Create<ContentItem>("gamma", init => {
init.As<Gamma>().Record.Frap = "three";
init.As<Epsilon>().Record.Quad = "v3";
init.As<GammaPart>().Record.Frap = "three";
init.As<EpsilonPart>().Record.Quad = "v3";
});
_session.Flush();
_session.Clear();
@@ -317,27 +311,27 @@ namespace Orchard.Tests.ContentManagement {
public void QueryShouldOnlyReturnPublishedByDefault() {
AddGammaVersions();
var list1 = _manager.Query<Gamma>()
var list1 = _manager.Query<GammaPart>()
.Where<EpsilonRecord>(x => x.Quad == "v1")
.List();
var list2 = _manager.Query<Gamma>()
var list2 = _manager.Query<GammaPart>()
.Where<EpsilonRecord>(x => x.Quad == "v2")
.List();
var list3 = _manager.Query<Gamma>()
var list3 = _manager.Query<GammaPart>()
.Where<EpsilonRecord>(x => x.Quad == "v3")
.List();
var listOne = _manager.Query<Gamma>()
var listOne = _manager.Query<GammaPart>()
.Where<GammaRecord>(x => x.Frap == "one")
.List();
var listTwo = _manager.Query<Gamma>()
var listTwo = _manager.Query<GammaPart>()
.Where<GammaRecord>(x => x.Frap == "two")
.List();
var listThree = _manager.Query<Gamma>()
var listThree = _manager.Query<GammaPart>()
.Where<GammaRecord>(x => x.Frap == "three")
.List();
@@ -353,27 +347,27 @@ namespace Orchard.Tests.ContentManagement {
public void QueryForLatestShouldNotReturnEarlierVersions() {
AddGammaVersions();
var list1 = _manager.Query<Gamma>(VersionOptions.Latest)
var list1 = _manager.Query<GammaPart>(VersionOptions.Latest)
.Where<EpsilonRecord>(x => x.Quad == "v1")
.List();
var list2 = _manager.Query<Gamma>(VersionOptions.Latest)
var list2 = _manager.Query<GammaPart>(VersionOptions.Latest)
.Where<EpsilonRecord>(x => x.Quad == "v2")
.List();
var list3 = _manager.Query<Gamma>(VersionOptions.Latest)
var list3 = _manager.Query<GammaPart>(VersionOptions.Latest)
.Where<EpsilonRecord>(x => x.Quad == "v3")
.List();
var listOne = _manager.Query<Gamma>(VersionOptions.Latest)
var listOne = _manager.Query<GammaPart>(VersionOptions.Latest)
.Where<GammaRecord>(x => x.Frap == "one")
.List();
var listTwo = _manager.Query<Gamma>(VersionOptions.Latest)
var listTwo = _manager.Query<GammaPart>(VersionOptions.Latest)
.Where<GammaRecord>(x => x.Frap == "two")
.List();
var listThree = _manager.Query<Gamma>(VersionOptions.Latest)
var listThree = _manager.Query<GammaPart>(VersionOptions.Latest)
.Where<GammaRecord>(x => x.Frap == "three")
.List();
@@ -389,27 +383,27 @@ namespace Orchard.Tests.ContentManagement {
public void QueryForDraftShouldOnlyReturnLatestThatIsNotPublished() {
AddGammaVersions();
var list1 = _manager.Query<Gamma>(VersionOptions.Draft)
var list1 = _manager.Query<GammaPart>(VersionOptions.Draft)
.Where<EpsilonRecord>(x => x.Quad == "v1")
.List();
var list2 = _manager.Query<Gamma>(VersionOptions.Draft)
var list2 = _manager.Query<GammaPart>(VersionOptions.Draft)
.Where<EpsilonRecord>(x => x.Quad == "v2")
.List();
var list3 = _manager.Query<Gamma>(VersionOptions.Draft)
var list3 = _manager.Query<GammaPart>(VersionOptions.Draft)
.Where<EpsilonRecord>(x => x.Quad == "v3")
.List();
var listOne = _manager.Query<Gamma>(VersionOptions.Draft)
var listOne = _manager.Query<GammaPart>(VersionOptions.Draft)
.Where<GammaRecord>(x => x.Frap == "one")
.List();
var listTwo = _manager.Query<Gamma>(VersionOptions.Draft)
var listTwo = _manager.Query<GammaPart>(VersionOptions.Draft)
.Where<GammaRecord>(x => x.Frap == "two")
.List();
var listThree = _manager.Query<Gamma>(VersionOptions.Draft)
var listThree = _manager.Query<GammaPart>(VersionOptions.Draft)
.Where<GammaRecord>(x => x.Frap == "three")
.List();
@@ -425,27 +419,27 @@ namespace Orchard.Tests.ContentManagement {
public void QueryForAllShouldReturnMultipleQualifiedVersions() {
AddGammaVersions();
var list1 = _manager.Query<Gamma>(VersionOptions.AllVersions)
var list1 = _manager.Query<GammaPart>(VersionOptions.AllVersions)
.Where<EpsilonRecord>(x => x.Quad == "v1")
.List();
var list2 = _manager.Query<Gamma>(VersionOptions.AllVersions)
var list2 = _manager.Query<GammaPart>(VersionOptions.AllVersions)
.Where<EpsilonRecord>(x => x.Quad == "v2")
.List();
var list3 = _manager.Query<Gamma>(VersionOptions.AllVersions)
var list3 = _manager.Query<GammaPart>(VersionOptions.AllVersions)
.Where<EpsilonRecord>(x => x.Quad == "v3")
.List();
var listOne = _manager.Query<Gamma>(VersionOptions.AllVersions)
var listOne = _manager.Query<GammaPart>(VersionOptions.AllVersions)
.Where<GammaRecord>(x => x.Frap == "one")
.List();
var listTwo = _manager.Query<Gamma>(VersionOptions.AllVersions)
var listTwo = _manager.Query<GammaPart>(VersionOptions.AllVersions)
.Where<GammaRecord>(x => x.Frap == "two")
.List();
var listThree = _manager.Query<Gamma>(VersionOptions.AllVersions)
var listThree = _manager.Query<GammaPart>(VersionOptions.AllVersions)
.Where<GammaRecord>(x => x.Frap == "three")
.List();

View File

@@ -13,6 +13,7 @@ using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.Records;
using Orchard.Environment.Extensions;
using Orchard.Tests.ContentManagement.Handlers;
using Orchard.Tests.ContentManagement.Records;
using Orchard.Tests.ContentManagement.Models;
using Orchard.DisplayManagement.Descriptors;
@@ -49,11 +50,6 @@ namespace Orchard.Tests.ContentManagement {
typeof(MegaRecord));
}
[TestFixtureTearDown]
public void TermFixture() {
}
[SetUp]
public void Init() {
_contentDefinitionManager = new Mock<IContentDefinitionManager>();
@@ -64,12 +60,12 @@ namespace Orchard.Tests.ContentManagement {
builder.RegisterInstance(_contentDefinitionManager.Object);
builder.RegisterInstance(new Mock<IContentDisplay>().Object);
builder.RegisterType<AlphaHandler>().As<IContentHandler>();
builder.RegisterType<BetaHandler>().As<IContentHandler>();
builder.RegisterType<GammaHandler>().As<IContentHandler>();
builder.RegisterType<DeltaHandler>().As<IContentHandler>();
builder.RegisterType<EpsilonHandler>().As<IContentHandler>();
builder.RegisterType<FlavoredHandler>().As<IContentHandler>();
builder.RegisterType<AlphaPartHandler>().As<IContentHandler>();
builder.RegisterType<BetaPartHandler>().As<IContentHandler>();
builder.RegisterType<GammaPartHandler>().As<IContentHandler>();
builder.RegisterType<DeltaPartHandler>().As<IContentHandler>();
builder.RegisterType<EpsilonPartHandler>().As<IContentHandler>();
builder.RegisterType<FlavoredPartHandler>().As<IContentHandler>();
builder.RegisterType<StyledHandler>().As<IContentHandler>();
builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
@@ -102,33 +98,33 @@ namespace Orchard.Tests.ContentManagement {
public void AlphaDriverShouldWeldItsPart() {
var foo = _manager.New(DefaultAlphaName);
Assert.That(foo.Is<Alpha>(), Is.True);
Assert.That(foo.As<Alpha>(), Is.Not.Null);
Assert.That(foo.Is<Beta>(), Is.False);
Assert.That(foo.As<Beta>(), Is.Null);
Assert.That(foo.Is<AlphaPart>(), Is.True);
Assert.That(foo.As<AlphaPart>(), Is.Not.Null);
Assert.That(foo.Is<BetaPart>(), Is.False);
Assert.That(foo.As<BetaPart>(), Is.Null);
}
[Test]
public void StronglyTypedNewShouldTypeCast() {
var foo = _manager.New<Alpha>(DefaultAlphaName);
var foo = _manager.New<AlphaPart>(DefaultAlphaName);
Assert.That(foo, Is.Not.Null);
Assert.That(foo.GetType(), Is.EqualTo(typeof(Alpha)));
Assert.That(foo.GetType(), Is.EqualTo(typeof(AlphaPart)));
}
[Test, ExpectedException(typeof(InvalidCastException))]
public void StronglyTypedNewShouldThrowCastExceptionIfNull() {
_manager.New<Beta>(DefaultAlphaName);
_manager.New<BetaPart>(DefaultAlphaName);
}
[Test]
public void AlphaIsFlavoredAndStyledAndBetaIsFlavoredOnly() {
var alpha = _manager.New<Alpha>(DefaultAlphaName);
var beta = _manager.New<Beta>(DefaultBetaName);
var alpha = _manager.New<AlphaPart>(DefaultAlphaName);
var beta = _manager.New<BetaPart>(DefaultBetaName);
Assert.That(alpha.Is<Flavored>(), Is.True);
Assert.That(alpha.Is<Styled>(), Is.True);
Assert.That(beta.Is<Flavored>(), Is.True);
Assert.That(beta.Is<Styled>(), Is.False);
Assert.That(alpha.Is<FlavoredPart>(), Is.True);
Assert.That(alpha.Is<StyledPart>(), Is.True);
Assert.That(beta.Is<FlavoredPart>(), Is.True);
Assert.That(beta.Is<StyledPart>(), Is.False);
}
[Test]
@@ -165,9 +161,9 @@ namespace Orchard.Tests.ContentManagement {
Assert.That(model.ContentType, Is.EqualTo(DefaultGammaName));
Assert.That(model.Id, Is.EqualTo(modelRecord.Id));
Assert.That(model.Is<Gamma>(), Is.True);
Assert.That(model.As<Gamma>().Record, Is.Not.Null);
Assert.That(model.As<Gamma>().Record.ContentItemRecord.Id, Is.EqualTo(model.Id));
Assert.That(model.Is<GammaPart>(), Is.True);
Assert.That(model.As<GammaPart>().Record, Is.Not.Null);
Assert.That(model.As<GammaPart>().Record.ContentItemRecord.Id, Is.EqualTo(model.Id));
}
@@ -253,7 +249,7 @@ namespace Orchard.Tests.ContentManagement {
[Test]
public void InitialVersionShouldBeOne() {
var gamma1 = _manager.Create<Gamma>(DefaultGammaName);
var gamma1 = _manager.Create<GammaPart>(DefaultGammaName);
Assert.That(gamma1.ContentItem.Record, Is.Not.Null);
Assert.That(gamma1.ContentItem.VersionRecord, Is.Not.Null);
Assert.That(gamma1.ContentItem.Version, Is.EqualTo(1));
@@ -263,7 +259,7 @@ namespace Orchard.Tests.ContentManagement {
_session.Clear();
Trace.WriteLine("session flushed");
var gamma2 = _manager.Get<Gamma>(gamma1.ContentItem.Id);
var gamma2 = _manager.Get<GammaPart>(gamma1.ContentItem.Id);
Assert.That(gamma2.ContentItem.Record, Is.Not.Null);
Assert.That(gamma2.ContentItem.VersionRecord, Is.Not.Null);
Assert.That(gamma2.ContentItem.Version, Is.EqualTo(1));
@@ -279,7 +275,7 @@ namespace Orchard.Tests.ContentManagement {
[Test]
public void InitialVersionCanBeSpecifiedAndIsPublished() {
var gamma1 = _manager.Create<Gamma>(DefaultGammaName, VersionOptions.Number(4));
var gamma1 = _manager.Create<GammaPart>(DefaultGammaName, VersionOptions.Number(4));
Assert.That(gamma1.ContentItem.Version, Is.EqualTo(4));
Assert.That(gamma1.ContentItem.VersionRecord.Published, Is.True);
@@ -406,9 +402,9 @@ namespace Orchard.Tests.ContentManagement {
[Test]
public void NonVersionedPartsAreBoundToSameRecord() {
Trace.WriteLine("gamma1");
var gamma1 = _manager.Create<Gamma>(DefaultGammaName, VersionOptions.Published, init => init.Record.Frap = "version one");
var gamma1 = _manager.Create<GammaPart>(DefaultGammaName, VersionOptions.Published, init => init.Record.Frap = "version one");
Trace.WriteLine("gamma2");
var gamma2 = _manager.Get<Gamma>(gamma1.ContentItem.Id, VersionOptions.DraftRequired);
var gamma2 = _manager.Get<GammaPart>(gamma1.ContentItem.Id, VersionOptions.DraftRequired);
Assert.That(gamma1.Record.Frap, Is.EqualTo("version one"));
Assert.That(gamma2.Record.Frap, Is.EqualTo("version one"));
gamma2.Record.Frap = "version two";
@@ -420,9 +416,9 @@ namespace Orchard.Tests.ContentManagement {
_session.Clear();
Trace.WriteLine("gamma1B");
var gamma1B = _manager.Get<Gamma>(gamma1.ContentItem.Id, VersionOptions.Published);
var gamma1B = _manager.Get<GammaPart>(gamma1.ContentItem.Id, VersionOptions.Published);
Trace.WriteLine("gamma2B");
var gamma2B = _manager.Get<Gamma>(gamma1.ContentItem.Id, VersionOptions.Draft);
var gamma2B = _manager.Get<GammaPart>(gamma1.ContentItem.Id, VersionOptions.Draft);
Assert.That(gamma1B.Record, Is.SameAs(gamma2B.Record));
Assert.That(gamma1B.Record.Frap, Is.EqualTo("version two"));
Assert.That(gamma2B.Record.Frap, Is.EqualTo("version two"));
@@ -441,12 +437,12 @@ namespace Orchard.Tests.ContentManagement {
[Test]
public void VersionedPartsShouldBeDifferentRecordsWithClonedData() {
var gamma1 = _manager.Create<Gamma>(DefaultGammaName, VersionOptions.Published, init => init.Record.Frap = "version one");
var epsilon1 = gamma1.As<Epsilon>();
var gamma1 = _manager.Create<GammaPart>(DefaultGammaName, VersionOptions.Published, init => init.Record.Frap = "version one");
var epsilon1 = gamma1.As<EpsilonPart>();
epsilon1.Record.Quad = "epsilon one";
var gamma2 = _manager.Get<Gamma>(gamma1.ContentItem.Id, VersionOptions.DraftRequired);
var epsilon2 = gamma2.As<Epsilon>();
var gamma2 = _manager.Get<GammaPart>(gamma1.ContentItem.Id, VersionOptions.DraftRequired);
var epsilon2 = gamma2.As<EpsilonPart>();
Assert.That(epsilon1.Record.Quad, Is.EqualTo("epsilon one"));
Assert.That(epsilon2.Record.Quad, Is.EqualTo("epsilon one"));
@@ -458,10 +454,10 @@ namespace Orchard.Tests.ContentManagement {
_session.Flush();
_session.Clear();
var gamma1B = _manager.Get<Gamma>(gamma1.ContentItem.Id, VersionOptions.Published);
var epsilon1B = gamma1B.As<Epsilon>();
var gamma2B = _manager.Get<Gamma>(gamma1.ContentItem.Id, VersionOptions.Draft);
var epsilon2B = gamma2B.As<Epsilon>();
var gamma1B = _manager.Get<GammaPart>(gamma1.ContentItem.Id, VersionOptions.Published);
var epsilon1B = gamma1B.As<EpsilonPart>();
var gamma2B = _manager.Get<GammaPart>(gamma1.ContentItem.Id, VersionOptions.Draft);
var epsilon2B = gamma2B.As<EpsilonPart>();
Assert.That(gamma1B.Record, Is.SameAs(gamma2B.Record));
Assert.That(epsilon1B.Record, Is.Not.SameAs(epsilon2B.Record));
Assert.That(epsilon1B.Record.Quad, Is.EqualTo("epsilon one"));
@@ -536,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
@@ -554,7 +550,7 @@ namespace Orchard.Tests.ContentManagement {
Assert.That(contentItem.TypeDefinition, Is.Not.Null);
Assert.That(contentItem.TypeDefinition, Is.SameAs(alphaType));
var flavored = contentItem.As<Flavored>();
var flavored = contentItem.As<FlavoredPart>();
Assert.That(flavored, Is.Not.Null);
Assert.That(flavored.TypePartDefinition, Is.Not.Null);
Assert.That(flavored.TypePartDefinition.Settings["spin"], Is.EqualTo("clockwise"));
@@ -563,7 +559,7 @@ namespace Orchard.Tests.ContentManagement {
[Test]
public void FieldsCanBeWeldIntoParts() {
var contentItem = _manager.New(DefaultAlphaName);
var part = contentItem.As<Flavored>();
var part = contentItem.As<FlavoredPart>();
var field = new Phi();
part.Weld(field);
Assert.That(part.Has(typeof(Phi), "Phi"));
@@ -572,7 +568,7 @@ namespace Orchard.Tests.ContentManagement {
[Test]
public void PartGetReturnsFieldWithName() {
var contentItem = _manager.New(DefaultAlphaName);
var part = contentItem.As<Flavored>();
var part = contentItem.As<FlavoredPart>();
var field = new Phi();
part.Weld(field);
var phi = part.Get(typeof(Phi), "Phi");

View File

@@ -0,0 +1,12 @@
using Orchard.ContentManagement.Handlers;
using Orchard.Tests.ContentManagement.Models;
namespace Orchard.Tests.ContentManagement.Handlers {
public class AlphaPartHandler : ContentHandler {
public AlphaPartHandler() {
Filters.Add(new ActivatingFilter<AlphaPart>("alpha"));
OnGetDisplayShape<AlphaPart>((ctx, part) => ctx.Shape.Zones["Main"].Add(part, "3"));
}
}
}

View File

@@ -0,0 +1,10 @@
using Orchard.ContentManagement.Handlers;
using Orchard.Tests.ContentManagement.Models;
namespace Orchard.Tests.ContentManagement.Handlers {
public class BetaPartHandler : ContentHandler {
public BetaPartHandler() {
Filters.Add(new ActivatingFilter<BetaPart>("beta"));
}
}
}

View File

@@ -0,0 +1,13 @@
using Orchard.ContentManagement.Handlers;
using Orchard.Data;
using Orchard.Tests.ContentManagement.Models;
using Orchard.Tests.ContentManagement.Records;
namespace Orchard.Tests.ContentManagement.Handlers {
public class DeltaPartHandler : ContentHandler {
public DeltaPartHandler(IRepository<DeltaRecord> repository) {
Filters.Add(new ActivatingFilter<DeltaPart>("delta"));
Filters.Add(StorageFilter.For(repository));
}
}
}

View File

@@ -0,0 +1,12 @@
using Orchard.ContentManagement.Handlers;
using Orchard.Data;
using Orchard.Tests.ContentManagement.Models;
namespace Orchard.Tests.ContentManagement.Handlers {
public class EpsilonPartHandler : ContentHandler {
public EpsilonPartHandler(IRepository<EpsilonRecord> repository) {
Filters.Add(new ActivatingFilter<EpsilonPart>("gamma"));
Filters.Add(StorageFilter.For(repository));
}
}
}

View File

@@ -0,0 +1,13 @@
using Orchard.ContentManagement.Handlers;
using Orchard.Tests.ContentManagement.Models;
namespace Orchard.Tests.ContentManagement.Handlers {
public class FlavoredPartHandler : ContentHandler {
public FlavoredPartHandler() {
Filters.Add(new ActivatingFilter<FlavoredPart>("alpha"));
Filters.Add(new ActivatingFilter<FlavoredPart>("beta"));
OnGetDisplayShape<FlavoredPart>((ctx, part) => ctx.Shape.Zones["Main"].Add(part));
}
}
}

View File

@@ -0,0 +1,13 @@
using Orchard.ContentManagement.Handlers;
using Orchard.Data;
using Orchard.Tests.ContentManagement.Models;
using Orchard.Tests.ContentManagement.Records;
namespace Orchard.Tests.ContentManagement.Handlers {
class GammaPartHandler : ContentHandler {
public GammaPartHandler(IRepository<GammaRecord> repository) {
Filters.Add(new ActivatingFilter<GammaPart>("gamma"));
Filters.Add(StorageFilter.For(repository));
}
}
}

View File

@@ -24,13 +24,13 @@ namespace Orchard.Tests.ContentManagement.Handlers {
[Test]
public void WeldShouldAddPartToModel() {
var builder = new ContentItemBuilder(new ContentTypeDefinitionBuilder().Named("foo").Build());
builder.Weld<Alpha>();
builder.Weld<AlphaPart>();
var model = builder.Build();
Assert.That(model.Is<Alpha>(), Is.True);
Assert.That(model.As<Alpha>(), Is.Not.Null);
Assert.That(model.Is<Beta>(), Is.False);
Assert.That(model.As<Beta>(), Is.Null);
Assert.That(model.Is<AlphaPart>(), Is.True);
Assert.That(model.As<AlphaPart>(), Is.Not.Null);
Assert.That(model.Is<BetaPart>(), Is.False);
Assert.That(model.As<BetaPart>(), Is.Null);
}
}
}

View File

@@ -23,7 +23,6 @@ namespace Orchard.Tests.ContentManagement.MetaData.Services {
Assert.That(type.Name, Is.EqualTo("foo"));
}
[Test]
public void AttributesAreAppliedAsSettings() {
var builder = new ContentTypeDefinitionBuilder();
@@ -41,9 +40,18 @@ namespace Orchard.Tests.ContentManagement.MetaData.Services {
Assert.That(type.Parts.Single().Settings["y"], Is.EqualTo("2"));
}
[Test, Ignore("Parts can be removed by name")]
[Test]
public void PartsCanBeRemovedByNameWhenImporting() {
Assert.Fail();
const string partToBeRemoved = "alpha";
var builder = new ContentTypeDefinitionBuilder();
_reader.Merge(new XElement("foo",
new XElement(partToBeRemoved),
new XElement("remove", new XAttribute("name", partToBeRemoved))
), builder);
var type = builder.Build();
Assert.That(type.Parts.FirstOrDefault(part => part.PartDefinition.Name == partToBeRemoved), Is.Null);
}
}
}

View File

@@ -1,15 +0,0 @@
using Orchard.ContentManagement.Handlers;
namespace Orchard.Tests.ContentManagement.Models {
public class AlphaHandler : ContentHandler {
public AlphaHandler() {
OnGetDisplayShape<Alpha>((ctx, part) => ctx.Shape.Zones["Main"].Add(part, "3"));
}
protected override void Activating(ActivatingContentContext context) {
if (context.ContentType == "alpha") {
context.Builder.Weld<Alpha>();
}
}
}
}

View File

@@ -1,6 +1,6 @@
using Orchard.ContentManagement;
namespace Orchard.Tests.ContentManagement.Models {
public class Alpha : ContentPart {
public class AlphaPart : ContentPart {
}
}

View File

@@ -1,11 +0,0 @@
using Orchard.ContentManagement.Handlers;
namespace Orchard.Tests.ContentManagement.Models {
public class BetaHandler : ContentHandler {
protected override void Activating(ActivatingContentContext context) {
if (context.ContentType == "beta") {
context.Builder.Weld<Beta>();
}
}
}
}

View File

@@ -1,6 +1,6 @@
using Orchard.ContentManagement;
namespace Orchard.Tests.ContentManagement.Models {
public class Beta : ContentPart {
public class BetaPart : ContentPart {
}
}

View File

@@ -1,18 +0,0 @@
using Orchard.Data;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.Tests.ContentManagement.Records;
namespace Orchard.Tests.ContentManagement.Models {
public class Delta : ContentPart<DeltaRecord> {
}
public class DeltaHandler : ContentHandler {
public DeltaHandler(IRepository<DeltaRecord> repository) {
Filters.Add(new ActivatingFilter<Delta>(x => x == "delta"));
Filters.Add(StorageFilter.For(repository));
}
}
}

View File

@@ -0,0 +1,7 @@
using Orchard.ContentManagement;
using Orchard.Tests.ContentManagement.Records;
namespace Orchard.Tests.ContentManagement.Models {
public class DeltaPart : ContentPart<DeltaRecord> {
}
}

View File

@@ -1,18 +0,0 @@
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.Data;
namespace Orchard.Tests.ContentManagement.Models {
public class Epsilon : ContentPart<EpsilonRecord> {
}
public class EpsilonHandler : ContentHandler {
public EpsilonHandler(IRepository<EpsilonRecord> repository) {
Filters.Add(new ActivatingFilter<Epsilon>(x => x == "gamma"));
Filters.Add(StorageFilter.For(repository));
}
}
}

View File

@@ -0,0 +1,6 @@
using Orchard.ContentManagement;
namespace Orchard.Tests.ContentManagement.Models {
public class EpsilonPart : ContentPart<EpsilonRecord> {
}
}

View File

@@ -1,14 +0,0 @@
using Orchard.ContentManagement.Handlers;
namespace Orchard.Tests.ContentManagement.Models {
public class FlavoredHandler : ContentHandler {
public FlavoredHandler() {
OnGetDisplayShape<Flavored>((ctx, part) => ctx.Shape.Zones["Main"].Add(part));
}
protected override void Activating(ActivatingContentContext context) {
if (context.ContentType == "beta" || context.ContentType == "alpha") {
context.Builder.Weld<Flavored>();
}
}
}
}

View File

@@ -1,6 +1,6 @@
using Orchard.ContentManagement;
namespace Orchard.Tests.ContentManagement.Models {
public class Styled : ContentPart {
public class FlavoredPart : ContentPart {
}
}

View File

@@ -1,19 +0,0 @@
using Orchard.Data;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.Tests.ContentManagement.Records;
namespace Orchard.Tests.ContentManagement.Models {
public class Gamma : ContentPart<GammaRecord> {
}
public class GammaHandler : ContentHandler {
public GammaHandler(IRepository<GammaRecord> repository) {
Filters.Add(new ActivatingFilter<Gamma>(x => x == "gamma"));
Filters.Add(StorageFilter.For(repository));
}
}
}

View File

@@ -0,0 +1,7 @@
using Orchard.ContentManagement;
using Orchard.Tests.ContentManagement.Records;
namespace Orchard.Tests.ContentManagement.Models {
public class GammaPart : ContentPart<GammaRecord> {
}
}

View File

@@ -3,12 +3,12 @@
namespace Orchard.Tests.ContentManagement.Models {
public class StyledHandler : ContentHandler {
public StyledHandler() {
OnGetDisplayShape<Styled>((ctx, part) => ctx.Shape.Zones["Main"].Add(part, "10"));
OnGetDisplayShape<StyledPart>((ctx, part) => ctx.Shape.Zones["Main"].Add(part, "10"));
}
protected override void Activating(ActivatingContentContext context) {
if (context.ContentType == "alpha") {
context.Builder.Weld<Styled>();
context.Builder.Weld<StyledPart>();
}
}
}

View File

@@ -1,6 +1,6 @@
using Orchard.ContentManagement;
namespace Orchard.Tests.ContentManagement.Models {
class Flavored : ContentPart {
public class StyledPart : ContentPart {
}
}

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

@@ -70,7 +70,7 @@ namespace Orchard.Tests.Environment.Configuration {
[Test]
public void EncryptionSettingsAreStoredAndReadable() {
IShellSettingsManager loader = new ShellSettingsManager(_appDataFolder, new Mock<IShellSettingsManagerEventHandler>().Object);
var foo = new ShellSettings { Name = "Foo", DataProvider = "Bar", DataConnectionString = "Quux", EncryptionAlgorithm = "AES", EncryptionKey = "ABCDEFG", EncryptionIV= "HIJKL" };
var foo = new ShellSettings { Name = "Foo", DataProvider = "Bar", DataConnectionString = "Quux", EncryptionAlgorithm = "AES", EncryptionKey = "ABCDEFG", HashAlgorithm = "HMACSHA256", HashKey = "HIJKLMN" };
loader.SaveSettings(foo);
Assert.That(loader.LoadSettings().Count(), Is.EqualTo(1));
@@ -78,7 +78,8 @@ namespace Orchard.Tests.Environment.Configuration {
Assert.That(settings.EncryptionAlgorithm, Is.EqualTo("AES"));
Assert.That(settings.EncryptionKey, Is.EqualTo("ABCDEFG"));
Assert.That(settings.EncryptionIV, Is.EqualTo("HIJKL"));
Assert.That(settings.HashAlgorithm, Is.EqualTo("HMACSHA256"));
Assert.That(settings.HashKey, Is.EqualTo("HIJKLMN"));
}
}
}

Some files were not shown because too many files have changed in this diff Show More