Compare commits

..

10 Commits
dev-old ... 1.2

Author SHA1 Message Date
Sebastien Ros
faa551cd0b Applying security fix
http://docs.orchardproject.net/Documentation/Patch-20150519
2015-06-30 11:24:58 -07:00
Renaud Paquay
d6748006a6 Added tag 1.2 for changeset 2ca8b2e7914c 2011-06-13 12:35:05 -07:00
Renaud Paquay
c258f1ec58 Set build version (1.2.41) for v1.2. 2011-06-13 12:34:42 -07:00
Renaud Paquay
03005603e7 Merge integration => default 2011-06-13 12:33:03 -07:00
Renaud Paquay
fcc36c10ae Merge 1.x => integration
--HG--
branch : integration
2011-06-13 12:32:07 -07:00
Nathan Heskew
e206772e82 Upgrading TinyMCE to 3.4.3 (from 3.4.2)
--HG--
branch : 1.x
2011-06-13 12:18:58 -07:00
Renaud Paquay
ab13087349 Added tag 1.2 for changeset e1ec47d08d85 2011-06-10 18:55:57 -07:00
Renaud Paquay
835d1fd3ae Set version 2011-06-10 18:55:06 -07:00
Renaud Paquay
0bc2d36d58 Merge integration => default 2011-06-10 18:47:42 -07:00
Renaud Paquay
d955399702 Merge 1.x => integration
--HG--
branch : integration
2011-06-09 22:26:49 -07:00
781 changed files with 6956 additions and 7541 deletions

View File

@@ -18,3 +18,6 @@ d2cca954cbf94750946a6325e5ec23e267430bd2 perf snapshot 1
48aedbdcebb174eb37534df9c7401fa35da22bbd 1.1
48aedbdcebb174eb37534df9c7401fa35da22bbd 1.1
97186e9f4536562febcdecf3da481231d375b0c7 1.1
e1ec47d08d85c6da922fc6fe74bb663264fd20fc 1.2
e1ec47d08d85c6da922fc6fe74bb663264fd20fc 1.2
2ca8b2e7914c82faa4e05eb11a99a21feded85a0 1.2

Binary file not shown.

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("1.2.0")]
[assembly: AssemblyFileVersion("1.2.0")]
[assembly: AssemblyVersion("1.2.41")]
[assembly: AssemblyFileVersion("1.2.41")]

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("1.2.0")]
[assembly: AssemblyFileVersion("1.2.0")]
[assembly: AssemblyVersion("1.2.41")]
[assembly: AssemblyFileVersion("1.2.41")]

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("1.2.0")]
[assembly: AssemblyFileVersion("1.2.0")]
[assembly: AssemblyVersion("1.2.41")]
[assembly: AssemblyFileVersion("1.2.41")]

View File

@@ -2,12 +2,13 @@
using System.Collections.Generic;
using System.Linq;
using Autofac;
using JetBrains.Annotations;
using Moq;
using NUnit.Framework;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.Definition;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.Records;
using Orchard.Core.Common.Handlers;
using Orchard.Core.Common.Models;
@@ -75,6 +76,7 @@ namespace Orchard.Core.Tests.Body {
}
}
[UsedImplicitly]
public class ThingHandler : ContentHandler {
public ThingHandler() {
Filters.Add(new ActivatingFilter<Thing>(ThingDriver.ContentTypeName));

View File

@@ -4,14 +4,14 @@ using System.Linq;
using System.Web;
using System.Web.Routing;
using Autofac;
using JetBrains.Annotations;
using Moq;
using NUnit.Framework;
using Orchard.AspNet.Abstractions;
using Orchard.Caching;
using Orchard.ContentManagement.Parts;
using Orchard.ContentManagement.Aspects;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Drivers.Coordinators;
using Orchard.ContentManagement.Definition;
using Orchard.ContentManagement.MetaData;
using Orchard.Core.Common.Drivers;
using Orchard.Core.Common.Handlers;
using Orchard.Core.Common.Models;
@@ -29,6 +29,7 @@ using Orchard.DisplayManagement.Descriptors.ShapePlacementStrategy;
using Orchard.DisplayManagement.Implementation;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
using Orchard.FileSystems.VirtualPath;
using Orchard.Localization;
using Orchard.Security;
using Orchard.Tasks.Scheduling;
@@ -121,6 +122,7 @@ namespace Orchard.Core.Tests.Common.Providers {
}
}
[UsedImplicitly]
class TestHandler : ContentHandler {
public TestHandler() {
Filters.Add(new ActivatingFilter<CommonPart>("test-item"));
@@ -156,7 +158,7 @@ namespace Orchard.Core.Tests.Common.Providers {
var item = contentManager.Create<ICommonPart>("test-item", VersionOptions.Draft, init => { });
var viewModel = new OwnerEditorViewModel { Owner = "User" };
updateModel.Setup(x => x.TryUpdateModel(viewModel, "", null, null)).Returns(true);
contentManager.UpdateEditor(item.ContentItem, new EditorOptions { Updater = updateModel.Object });
contentManager.UpdateEditor(item.ContentItem, updateModel.Object);
}
class UpdatModelStub : IUpdateModel {
@@ -203,7 +205,7 @@ namespace Orchard.Core.Tests.Common.Providers {
var updater = new UpdatModelStub() { Owner = null };
contentManager.UpdateEditor(item.ContentItem, new EditorOptions { Updater = updater });
contentManager.UpdateEditor(item.ContentItem, updater);
}
[Test]
@@ -224,7 +226,7 @@ namespace Orchard.Core.Tests.Common.Providers {
b => b.Describe("Parts_Common_Owner_Edit").From(TestFeature())
.Placement(ShapePlacementParsingStrategy.BuildPredicate(c => true, new KeyValuePair<string, string>("Path", "~/yadda")), new PlacementInfo { Location = "Match" });
contentManager.UpdateEditor(item.ContentItem, new EditorOptions { Updater = updater });
contentManager.UpdateEditor(item.ContentItem, updater);
Assert.That(updater.ModelErrors.ContainsKey("OwnerEditor.Owner"), Is.True);
}
@@ -336,8 +338,8 @@ namespace Orchard.Core.Tests.Common.Providers {
_clock.Advance(TimeSpan.FromMinutes(1));
var editUtc = _clock.UtcNow;
var updater = new UpdatModelStub { Owner = "" };
contentManager.UpdateEditor(item.ContentItem, new EditorOptions { Updater = updater });
var updater = new UpdatModelStub() { Owner = "" };
contentManager.UpdateEditor(item.ContentItem, updater);
Assert.That(item.CreatedUtc, Is.EqualTo(createUtc));
Assert.That(item.ModifiedUtc, Is.EqualTo(editUtc));

View File

@@ -9,7 +9,7 @@ using Moq;
using NUnit.Framework;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.Definition.Builders;
using Orchard.ContentManagement.MetaData.Builders;
using Orchard.Core.Common.Models;
using Orchard.Core.Feeds;
using Orchard.Core.Feeds.Controllers;

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("1.2.0")]
[assembly: AssemblyFileVersion("1.2.0")]
[assembly: AssemblyVersion("1.2.41")]
[assembly: AssemblyFileVersion("1.2.41")]

View File

@@ -1,12 +1,13 @@
using System;
using System.Collections.Generic;
using Autofac;
using JetBrains.Annotations;
using Moq;
using NUnit.Framework;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Parts;
using Orchard.ContentManagement.Aspects;
using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.Definition;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.Records;
using Orchard.Core.Common.Models;
using Orchard.Core.Routable;
@@ -260,6 +261,7 @@ namespace Orchard.Core.Tests.Routable.Services {
}
}
[UsedImplicitly]
public class ThingHandler : ContentHandler {
public ThingHandler() {
Filters.Add(new ActivatingFilter<Thing>("thing"));
@@ -281,6 +283,7 @@ namespace Orchard.Core.Tests.Routable.Services {
}
}
[UsedImplicitly]
public class StuffHandler : ContentHandler {
public StuffHandler() {
Filters.Add(new ActivatingFilter<Stuff>("stuff"));

View File

@@ -4,7 +4,7 @@ using Autofac;
using Moq;
using NUnit.Framework;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Definition;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.Records;
using Orchard.Core.Scheduling.Models;
using Orchard.Core.Scheduling.Services;

View File

@@ -5,7 +5,7 @@ using Autofac;
using Moq;
using NUnit.Framework;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Definition;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.Records;
using Orchard.Core.Scheduling.Models;
using Orchard.Core.Scheduling.Services;

View File

@@ -1,14 +1,16 @@
using System;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using Autofac;
using Moq;
using NHibernate;
using NUnit.Framework;
using Orchard.Caching;
using Orchard.ContentManagement.Definition;
using Orchard.ContentManagement.Definition.Builders;
using Orchard.ContentManagement.Definition.Services;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Builders;
using Orchard.ContentManagement.MetaData.Models;
using Orchard.ContentManagement.MetaData.Services;
using Orchard.Core.Settings.Metadata;
using Orchard.Core.Settings.Metadata.Records;
using Orchard.Data;
@@ -43,7 +45,9 @@ namespace Orchard.Core.Tests.Settings.Metadata {
builder.RegisterAutoMocking();
builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
builder.RegisterType(typeof(SettingsFormatter)).As(typeof(ISettingsFormatter));
builder.RegisterType(typeof(SettingsFormatter))
.As(typeof(IMapper<XElement, SettingsDictionary>))
.As(typeof(IMapper<SettingsDictionary, XElement>));
builder.RegisterType<Signals>().As<ISignals>();
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
builder.RegisterType<StubParallelCacheContext>().As<IParallelCacheContext>();
@@ -204,7 +208,7 @@ namespace Orchard.Core.Tests.Settings.Metadata {
var type = _container.Resolve<IContentDefinitionManager>().GetTypeDefinition(typeName);
Assert.That(type, Is.Not.Null);
Assert.That(type.Parts.Count(), Is.EqualTo(partNames.Count()));
foreach (var partName in partNames) {
foreach(var partName in partNames) {
Assert.That(type.Parts.Select(p=>p.PartDefinition.Name), Has.Some.EqualTo(partName));
}
}

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("1.2.0")]
[assembly: AssemblyFileVersion("1.2.0")]
[assembly: AssemblyVersion("1.2.41")]
[assembly: AssemblyFileVersion("1.2.41")]

View File

@@ -1,7 +1,7 @@
using System;
using NUnit.Framework;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Parts;
using Orchard.ContentManagement.Aspects;
using Orchard.Core.Contents;
using Orchard.Data;
using Orchard.Roles.Models;

View File

@@ -1,6 +1,6 @@
using System.Linq;
using Orchard.ContentManagement.Definition;
using Orchard.ContentManagement.Definition.Models;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Models;
using Orchard.Core.Contents.Extensions;
using Orchard.Environment.Configuration;
using Orchard.Environment.Descriptor;

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("1.2.0")]
[assembly: AssemblyFileVersion("1.2.0")]
[assembly: AssemblyVersion("1.2.41")]
[assembly: AssemblyFileVersion("1.2.41")]

View File

@@ -32,8 +32,8 @@ using System.Security;
// 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("1.2.0")]
[assembly: AssemblyFileVersion("1.2.0")]
[assembly: AssemblyVersion("1.2.41")]
[assembly: AssemblyFileVersion("1.2.41")]
// Enable web application to call this assembly in Full Trust
[assembly: AllowPartiallyTrustedCallers]

View File

@@ -60,14 +60,14 @@ namespace Orchard.Tests.Modules.CodeGeneration.Commands {
}
[Test]
[ExpectedException(typeof(OrchardException))]
public void CreateDataMigrationTestNonExistentFeature() {
CodeGenerationCommands codeGenerationCommands = new CodeGenerationCommands(_extensionManager,
_schemaCommandGenerator);
var textWriterOutput = new StringWriter();
TextWriter textWriterOutput = new StringWriter();
codeGenerationCommands.Context = new CommandContext { Output = textWriterOutput };
codeGenerationCommands.CreateDataMigration("feature");
Assert.That(textWriterOutput.ToString().Contains("Creating data migration failed: target Feature feature could not be found."));
}
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Autofac;
using JetBrains.Annotations;
using Moq;
using NUnit.Framework;
using Orchard.Comments.Handlers;
@@ -9,7 +10,7 @@ using Orchard.Comments.Services;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.Definition;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.Records;
using Orchard.Core.Common.Handlers;
using Orchard.Core.Common.Models;
@@ -186,6 +187,7 @@ namespace Orchard.Tests.Modules.Comments.Services {
}
}
[UsedImplicitly]
public class CommentedItemHandler : ContentHandler {
public CommentedItemHandler() {
Filters.Add(new ActivatingFilter<CommentedItem>("commentedItem"));

View File

@@ -10,7 +10,6 @@ using Orchard.Data;
using Orchard.Services;
using Orchard.Tests.Data;
using Orchard.Tests.Stubs;
using Orchard.Time;
namespace Orchard.Tests.Modules {
public abstract class DatabaseEnabledTestsBase {

View File

@@ -7,16 +7,16 @@ using NHibernate;
using NUnit.Framework;
using Orchard.Caching;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Definition;
using Orchard.ContentManagement.Definition.Models;
using Orchard.ContentManagement.Definition.Services;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Models;
using Orchard.ContentManagement.MetaData.Services;
using Orchard.ContentManagement.Records;
using Orchard.Core.Settings.Metadata;
using Orchard.Data;
using Orchard.Environment.Compilation.Loaders;
using Orchard.Environment.Descriptor;
using Orchard.Environment.Descriptor.Models;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Loaders;
using Orchard.FileSystems.AppData;
using Orchard.FileSystems.WebSite;
using Orchard.ImportExport.Services;
@@ -27,7 +27,6 @@ using Orchard.Tests.Environment.Extensions;
using Orchard.Tests.Modules.Recipes.Services;
using Orchard.Tests.Stubs;
using Orchard.Tests.UI.Navigation;
using Orchard.Time;
namespace Orchard.Tests.Modules.ImportExport.Services {
[TestFixture]
@@ -73,7 +72,8 @@ namespace Orchard.Tests.Modules.ImportExport.Services {
builder.RegisterType<StubAppDataFolder>().As<IAppDataFolder>();
builder.RegisterType<Signals>().As<ISignals>();
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
builder.RegisterInstance(new Mock<ISettingsFormatter>().Object);
builder.RegisterInstance(new Mock<IMapper<SettingsDictionary, XElement>>().Object);
builder.RegisterInstance(new Mock<IMapper<XElement, SettingsDictionary>>().Object);
_session = _sessionFactory.OpenSession();
builder.RegisterInstance(new DefaultContentManagerTests.TestSessionLocator(_session)).As<ISessionLocator>();

View File

@@ -8,8 +8,8 @@ using NUnit.Framework;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.Definition;
using Orchard.ContentManagement.Definition.Builders;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Builders;
using Orchard.ContentManagement.Records;
using Orchard.Core.Common.Handlers;
using Orchard.Core.Common.Models;
@@ -18,11 +18,11 @@ using Orchard.Environment;
using Orchard.Environment.Configuration;
using Orchard.Environment.Extensions;
using Orchard.FileSystems.AppData;
using Orchard.FileSystems.LockFile;
using Orchard.Indexing;
using Orchard.Indexing.Handlers;
using Orchard.Indexing.Models;
using Orchard.Indexing.Services;
using Orchard.Locking;
using Orchard.Logging;
using Orchard.Security;
using Orchard.Tasks.Indexing;
@@ -38,7 +38,7 @@ namespace Orchard.Tests.Modules.Indexing {
private IContentManager _contentManager;
private Mock<IContentDefinitionManager> _contentDefinitionManager;
private StubLogger _logger;
private ILockManager _lockManager;
private ILockFileManager _lockFileManager;
private const string IndexName = "Search";
private readonly string _basePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
@@ -81,7 +81,7 @@ namespace Orchard.Tests.Modules.Indexing {
builder.RegisterType<BodyPartHandler>().As<IContentHandler>();
builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
builder.RegisterType<DefaultLockManager>().As<ILockManager>();
builder.RegisterType<DefaultLockFileManager>().As<ILockFileManager>();
// setting up a ShellSettings instance
_shellSettings = new ShellSettings { Name = "My Site" };
@@ -103,7 +103,7 @@ namespace Orchard.Tests.Modules.Indexing {
public override void Init() {
base.Init();
_lockManager = _container.Resolve<ILockManager>();
_lockFileManager = _container.Resolve<ILockFileManager>();
_provider = _container.Resolve<IIndexProvider>();
_indexTaskExecutor = _container.Resolve<IIndexingTaskExecutor>();
_contentManager = _container.Resolve<IContentManager>();
@@ -184,9 +184,9 @@ namespace Orchard.Tests.Modules.Indexing {
[Test]
public void IndexingTaskExecutorShouldNotBeReEntrant() {
var @lock = _lockManager.TryLock(IndexName);
using (@lock) {
ILockFile lockFile = null;
_lockFileManager.TryAcquireLock("Sites/My Site/Search.settings.xml.lock", ref lockFile);
using (lockFile) {
while (_indexTaskExecutor.UpdateIndexBatch(IndexName)) {}
Assert.That(_logger.LogEntries.Count, Is.EqualTo(1));
Assert.That(_logger.LogEntries, Has.Some.Matches<LogEntry>(entry => entry.LogFormat == "Index was requested but is already running"));

View File

@@ -7,6 +7,7 @@ using NUnit.Framework;
using Orchard.Environment.Configuration;
using Orchard.FileSystems.AppData;
using Orchard.Indexing;
using Orchard.Indexing.Services;
using Orchard.Tests.FileSystems.AppData;
namespace Orchard.Tests.Modules.Indexing {
@@ -45,7 +46,7 @@ namespace Orchard.Tests.Modules.Indexing {
_provider = _container.Resolve<IIndexProvider>();
}
private ISearchBuilder SearchBuilder { get { return _provider.CreateSearchBuilder("default"); } }
private ISearchBuilder _searchBuilder { get { return _provider.CreateSearchBuilder("default"); } }
[Test]
public void SearchTermsShouldBeFoundInMultipleFields() {
@@ -73,9 +74,9 @@ namespace Orchard.Tests.Modules.Indexing {
_provider.Store("default", _provider.New(3));
Assert.That(SearchBuilder.Get(1).ContentItemId, Is.EqualTo(1));
Assert.That(SearchBuilder.Get(2).ContentItemId, Is.EqualTo(2));
Assert.That(SearchBuilder.Get(3).ContentItemId, Is.EqualTo(3));
Assert.That(_searchBuilder.Get(1).ContentItemId, Is.EqualTo(1));
Assert.That(_searchBuilder.Get(2).ContentItemId, Is.EqualTo(2));
Assert.That(_searchBuilder.Get(3).ContentItemId, Is.EqualTo(3));
}
[Test]
@@ -86,93 +87,11 @@ namespace Orchard.Tests.Modules.Indexing {
_provider.Store("default", _provider.New(3).Add("title", "cat"));
Assert.That(SearchBuilder.WithField("title", "cat").Search().Count(), Is.EqualTo(2));
Assert.That(SearchBuilder.WithField("title", "cat").Search().Any(hit => new[] { 1, 3 }.Contains(hit.ContentItemId)), Is.True);
Assert.That(_searchBuilder.WithField("title", "cat").Search().Count(), Is.EqualTo(2));
Assert.That(_searchBuilder.WithField("title", "cat").Search().Any(hit => new[] { 1, 3 }.Contains(hit.ContentItemId)), Is.True);
}
[Test]
public void ShouldSearchByBooleanWhateverIndexingScheme() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("foo", true));
_provider.Store("default", _provider.New(2).Add("foo", true).Store());
_provider.Store("default", _provider.New(3).Add("foo", true).Analyze());
_provider.Store("default", _provider.New(4).Add("foo", true).Store().Analyze());
_provider.Store("default", _provider.New(5).Add("foo", false));
_provider.Store("default", _provider.New(6).Add("foo", false).Store());
_provider.Store("default", _provider.New(7).Add("foo", false).Analyze());
_provider.Store("default", _provider.New(8).Add("foo", false).Store().Analyze());
Assert.That(SearchBuilder.WithField("foo", false).Search().Count(), Is.EqualTo(4));
Assert.That(SearchBuilder.WithField("foo", true).Search().Count(), Is.EqualTo(4));
}
[Test]
public void ShouldSearchByStringWhateverIndexingScheme() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("foo", "abc"));
_provider.Store("default", _provider.New(2).Add("foo", "abc").Store());
_provider.Store("default", _provider.New(3).Add("foo", "abc").Analyze());
_provider.Store("default", _provider.New(4).Add("foo", "abc").Store().Analyze());
_provider.Store("default", _provider.New(5).Add("foo", "def"));
_provider.Store("default", _provider.New(6).Add("foo", "def").Store());
_provider.Store("default", _provider.New(7).Add("foo", "def").Analyze());
_provider.Store("default", _provider.New(8).Add("foo", "def").Store().Analyze());
Assert.That(SearchBuilder.WithField("foo", "abc").Search().Count(), Is.EqualTo(4));
Assert.That(SearchBuilder.WithField("foo", "def").Search().Count(), Is.EqualTo(4));
}
[Test]
public void ShouldSearchByIntegerWhateverIndexingScheme() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("foo", 1));
_provider.Store("default", _provider.New(2).Add("foo", 1).Store());
_provider.Store("default", _provider.New(3).Add("foo", 1).Analyze());
_provider.Store("default", _provider.New(4).Add("foo", 1).Store().Analyze());
_provider.Store("default", _provider.New(5).Add("foo", 2));
_provider.Store("default", _provider.New(6).Add("foo", 2).Store());
_provider.Store("default", _provider.New(7).Add("foo", 2).Analyze());
_provider.Store("default", _provider.New(8).Add("foo", 2).Store().Analyze());
Assert.That(SearchBuilder.WithField("foo", 1).Search().Count(), Is.EqualTo(4));
Assert.That(SearchBuilder.WithField("foo", 2).Search().Count(), Is.EqualTo(4));
}
[Test]
public void ShouldSearchByFloatWhateverIndexingScheme() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("foo", 1.1));
_provider.Store("default", _provider.New(2).Add("foo", 1.1).Store());
_provider.Store("default", _provider.New(3).Add("foo", 1.1).Analyze());
_provider.Store("default", _provider.New(4).Add("foo", 1.1).Store().Analyze());
_provider.Store("default", _provider.New(5).Add("foo", 2.1));
_provider.Store("default", _provider.New(6).Add("foo", 2.1).Store());
_provider.Store("default", _provider.New(7).Add("foo", 2.1).Analyze());
_provider.Store("default", _provider.New(8).Add("foo", 2.1).Store().Analyze());
Assert.That(SearchBuilder.WithField("foo", 1.1).Search().Count(), Is.EqualTo(4));
Assert.That(SearchBuilder.WithField("foo", 2.1).Search().Count(), Is.EqualTo(4));
}
[Test]
public void ShouldSearchByDateTimeWhateverIndexingScheme() {
var date1 = DateTime.Today;
var date2 = DateTime.Today.AddDays(1);
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("foo", date1));
_provider.Store("default", _provider.New(2).Add("foo", date1).Store());
_provider.Store("default", _provider.New(3).Add("foo", date1).Analyze());
_provider.Store("default", _provider.New(4).Add("foo", date1).Store().Analyze());
_provider.Store("default", _provider.New(5).Add("foo", date2));
_provider.Store("default", _provider.New(6).Add("foo", date2).Store());
_provider.Store("default", _provider.New(7).Add("foo", date2).Analyze());
_provider.Store("default", _provider.New(8).Add("foo", date2).Store().Analyze());
Assert.That(SearchBuilder.WithField("foo", date1).Search().Count(), Is.EqualTo(4));
Assert.That(SearchBuilder.WithField("foo", date2).Search().Count(), Is.EqualTo(4));
}
[Test]
public void ShouldCountResultsOnly() {
_provider.CreateIndex("default");
@@ -180,8 +99,8 @@ namespace Orchard.Tests.Modules.Indexing {
_provider.Store("default", _provider.New(2).Add("title", "dog"));
_provider.Store("default", _provider.New(3).Add("title", "cat"));
Assert.That(SearchBuilder.WithField("title", "dog").Count(), Is.EqualTo(1));
Assert.That(SearchBuilder.WithField("title", "cat").Count(), Is.EqualTo(2));
Assert.That(_searchBuilder.WithField("title", "dog").Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("title", "cat").Count(), Is.EqualTo(2));
}
[Test]
@@ -191,12 +110,12 @@ namespace Orchard.Tests.Modules.Indexing {
_provider.Store("default", _provider.New(2).Add("date", new DateTime(2010, 05, 28, 12, 30, 30)));
_provider.Store("default", _provider.New(3).Add("date", new DateTime(2010, 05, 28, 12, 30, 45)));
Assert.That(SearchBuilder.WithinRange("date", new DateTime(2010, 05, 28, 12, 30, 15), DateTime.MaxValue).Count(), Is.EqualTo(3));
Assert.That(SearchBuilder.WithinRange("date", DateTime.MinValue, new DateTime(2010, 05, 28, 12, 30, 45)).Count(), Is.EqualTo(3));
Assert.That(SearchBuilder.WithinRange("date", new DateTime(2010, 05, 28, 12, 30, 15), new DateTime(2010, 05, 28, 12, 30, 45)).Count(), Is.EqualTo(3));
Assert.That(SearchBuilder.WithinRange("date", new DateTime(2010, 05, 28, 12, 30, 16), new DateTime(2010, 05, 28, 12, 30, 44)).Count(), Is.EqualTo(1));
Assert.That(SearchBuilder.WithinRange("date", new DateTime(2010, 05, 28, 12, 30, 46), DateTime.MaxValue).Count(), Is.EqualTo(0));
Assert.That(SearchBuilder.WithinRange("date", DateTime.MinValue, new DateTime(2010, 05, 28, 12, 30, 1)).Count(), Is.EqualTo(0));
Assert.That(_searchBuilder.WithinRange("date", new DateTime(2010, 05, 28, 12, 30, 15), DateTime.MaxValue).Count(), Is.EqualTo(3));
Assert.That(_searchBuilder.WithinRange("date", DateTime.MinValue, new DateTime(2010, 05, 28, 12, 30, 45)).Count(), Is.EqualTo(3));
Assert.That(_searchBuilder.WithinRange("date", new DateTime(2010, 05, 28, 12, 30, 15), new DateTime(2010, 05, 28, 12, 30, 45)).Count(), Is.EqualTo(3));
Assert.That(_searchBuilder.WithinRange("date", new DateTime(2010, 05, 28, 12, 30, 16), new DateTime(2010, 05, 28, 12, 30, 44)).Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithinRange("date", new DateTime(2010, 05, 28, 12, 30, 46), DateTime.MaxValue).Count(), Is.EqualTo(0));
Assert.That(_searchBuilder.WithinRange("date", DateTime.MinValue, new DateTime(2010, 05, 28, 12, 30, 1)).Count(), Is.EqualTo(0));
}
[Test]
@@ -209,16 +128,16 @@ namespace Orchard.Tests.Modules.Indexing {
_provider.Store("default", _provider.New(55555));
Assert.That(SearchBuilder.Count(), Is.EqualTo(5));
Assert.That(SearchBuilder.Slice(0, 3).Count(), Is.EqualTo(3));
Assert.That(SearchBuilder.Slice(1, 3).Count(), Is.EqualTo(3));
Assert.That(SearchBuilder.Slice(3, 3).Count(), Is.EqualTo(2));
Assert.That(_searchBuilder.Count(), Is.EqualTo(5));
Assert.That(_searchBuilder.Slice(0, 3).Count(), Is.EqualTo(3));
Assert.That(_searchBuilder.Slice(1, 3).Count(), Is.EqualTo(3));
Assert.That(_searchBuilder.Slice(3, 3).Count(), Is.EqualTo(2));
// Count() and Search() should return the same results
Assert.That(SearchBuilder.Search().Count(), Is.EqualTo(5));
Assert.That(SearchBuilder.Slice(0, 3).Search().Count(), Is.EqualTo(3));
Assert.That(SearchBuilder.Slice(1, 3).Search().Count(), Is.EqualTo(3));
Assert.That(SearchBuilder.Slice(3, 3).Search().Count(), Is.EqualTo(2));
Assert.That(_searchBuilder.Search().Count(), Is.EqualTo(5));
Assert.That(_searchBuilder.Slice(0, 3).Search().Count(), Is.EqualTo(3));
Assert.That(_searchBuilder.Slice(1, 3).Search().Count(), Is.EqualTo(3));
Assert.That(_searchBuilder.Slice(3, 3).Search().Count(), Is.EqualTo(2));
}
[Test]
@@ -230,12 +149,12 @@ namespace Orchard.Tests.Modules.Indexing {
_provider.Store("default", _provider.New(4).Add("body", "a dog is pursuing a cat").Analyze());
_provider.Store("default", _provider.New(5).Add("body", "the elephant can't catch up the dog").Analyze());
var michael = SearchBuilder.WithField("body", "michael").Search().ToList();
var michael = _searchBuilder.WithField("body", "michael").Search().ToList();
Assert.That(michael.Count(), Is.EqualTo(2));
Assert.That(michael[0].Score >= michael[1].Score, Is.True);
// Sorting on score is always descending
michael = SearchBuilder.WithField("body", "michael").Ascending().Search().ToList();
michael = _searchBuilder.WithField("body", "michael").Ascending().Search().ToList();
Assert.That(michael.Count(), Is.EqualTo(2));
Assert.That(michael[0].Score >= michael[1].Score, Is.True);
}
@@ -243,77 +162,37 @@ namespace Orchard.Tests.Modules.Indexing {
[Test]
public void ShouldSortByDate() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("date", new DateTime(2010, 05, 28, 12, 30, 30)));
_provider.Store("default", _provider.New(2).Add("date", DateTime.MinValue));
_provider.Store("default", _provider.New(3).Add("date", DateTime.MaxValue));
_provider.Store("default", _provider.New(1).Add("date", new DateTime(2010, 05, 28, 12, 30, 15)).Store());
_provider.Store("default", _provider.New(2).Add("date", new DateTime(2010, 05, 28, 12, 30, 30)).Store());
_provider.Store("default", _provider.New(3).Add("date", new DateTime(2010, 05, 28, 12, 30, 45)).Store());
var date = SearchBuilder.SortByDateTime("date").Search().ToList();
var date = _searchBuilder.SortByDateTime("date").Search().ToList();
Assert.That(date.Count(), Is.EqualTo(3));
Assert.That(date[0].ContentItemId, Is.EqualTo(3));
Assert.That(date[1].ContentItemId, Is.EqualTo(1));
Assert.That(date[2].ContentItemId, Is.EqualTo(2));
Assert.That(date[0].GetDateTime("date") > date[1].GetDateTime("date"), Is.True);
Assert.That(date[1].GetDateTime("date") > date[2].GetDateTime("date"), Is.True);
date = SearchBuilder.SortByDateTime("date").Ascending().Search().ToList();
Assert.That(date[0].ContentItemId, Is.EqualTo(2));
Assert.That(date[1].ContentItemId, Is.EqualTo(1));
Assert.That(date[2].ContentItemId, Is.EqualTo(3));
date = _searchBuilder.SortByDateTime("date").Ascending().Search().ToList();
Assert.That(date.Count(), Is.EqualTo(3));
Assert.That(date[0].GetDateTime("date") < date[1].GetDateTime("date"), Is.True);
Assert.That(date[1].GetDateTime("date") < date[2].GetDateTime("date"), Is.True);
}
[Test]
public void ShouldSortByNumber() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("downloads", 111));
_provider.Store("default", _provider.New(2).Add("downloads", int.MaxValue));
_provider.Store("default", _provider.New(3).Add("downloads", int.MinValue));
_provider.Store("default", _provider.New(1).Add("downloads", 111).Store());
_provider.Store("default", _provider.New(2).Add("downloads", 2222).Store());
_provider.Store("default", _provider.New(3).Add("downloads", 3).Store());
var number = SearchBuilder.SortByInteger("downloads").Search().ToList();
var number = _searchBuilder.SortByInteger("downloads").Search().ToList();
Assert.That(number.Count(), Is.EqualTo(3));
Assert.That(number[0].ContentItemId, Is.EqualTo(2));
Assert.That(number[1].ContentItemId, Is.EqualTo(1));
Assert.That(number[2].ContentItemId, Is.EqualTo(3));
Assert.That(number[0].GetInt("downloads") > number[1].GetInt("downloads"), Is.True);
Assert.That(number[1].GetInt("downloads") > number[2].GetInt("downloads"), Is.True);
number = SearchBuilder.SortByInteger("downloads").Ascending().Search().ToList();
number = _searchBuilder.SortByInteger("downloads").Ascending().Search().ToList();
Assert.That(number.Count(), Is.EqualTo(3));
Assert.That(number[0].ContentItemId, Is.EqualTo(3));
Assert.That(number[1].ContentItemId, Is.EqualTo(1));
Assert.That(number[2].ContentItemId, Is.EqualTo(2));
}
[Test]
public void ShouldSortByBoolean() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("active", true));
_provider.Store("default", _provider.New(2).Add("active", false));
var number = SearchBuilder.SortByBoolean("active").Search().ToList();
Assert.That(number.Count(), Is.EqualTo(2));
Assert.That(number[0].ContentItemId, Is.EqualTo(1));
Assert.That(number[1].ContentItemId, Is.EqualTo(2));
number = SearchBuilder.SortByBoolean("active").Ascending().Search().ToList();
Assert.That(number.Count(), Is.EqualTo(2));
Assert.That(number[0].ContentItemId, Is.EqualTo(2));
Assert.That(number[1].ContentItemId, Is.EqualTo(1));
}
[Test]
public void ShouldSortByDouble() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("rating", 111.111));
_provider.Store("default", _provider.New(2).Add("rating", double.MaxValue));
_provider.Store("default", _provider.New(3).Add("rating", double.MinValue));
var number = SearchBuilder.SortByDouble("rating").Search().ToList();
Assert.That(number.Count(), Is.EqualTo(3));
Assert.That(number[0].ContentItemId, Is.EqualTo(2));
Assert.That(number[1].ContentItemId, Is.EqualTo(1));
Assert.That(number[2].ContentItemId, Is.EqualTo(3));
number = SearchBuilder.SortByDouble("rating").Ascending().Search().ToList();
Assert.That(number.Count(), Is.EqualTo(3));
Assert.That(number[0].ContentItemId, Is.EqualTo(3));
Assert.That(number[1].ContentItemId, Is.EqualTo(1));
Assert.That(number[2].ContentItemId, Is.EqualTo(2));
Assert.That(number[0].GetInt("downloads") < number[1].GetInt("downloads"), Is.True);
Assert.That(number[1].GetInt("downloads") < number[2].GetInt("downloads"), Is.True);
}
[Test]
@@ -322,10 +201,10 @@ namespace Orchard.Tests.Modules.Indexing {
_provider.Store("default", _provider.New(1).Add("body", "Orchard has been developped in C#").Analyze());
_provider.Store("default", _provider.New(2).Add("body", "Windows has been developped in C++").Analyze());
var cs = SearchBuilder.Parse("body", "C#").Search().ToList();
var cs = _searchBuilder.Parse("body", "C#").Search().ToList();
Assert.That(cs.Count(), Is.EqualTo(2));
var cpp = SearchBuilder.Parse("body", "C++").Search().ToList();
var cpp = _searchBuilder.Parse("body", "C++").Search().ToList();
Assert.That(cpp.Count(), Is.EqualTo(2));
}
@@ -336,10 +215,10 @@ namespace Orchard.Tests.Modules.Indexing {
_provider.Store("default", _provider.New(1).Add("body", "Orchard has been developped in C#").Analyze());
_provider.Store("default", _provider.New(2).Add("body", "Windows has been developped in C++").Analyze());
Assert.That(SearchBuilder.WithField("body", "develop").Search().ToList().Count(), Is.EqualTo(2));
Assert.That(SearchBuilder.WithField("body", "develop").WithField("body", "Orchard").Search().ToList().Count(), Is.EqualTo(2));
Assert.That(SearchBuilder.WithField("body", "develop").WithField("body", "Orchard").Mandatory().Search().ToList().Count(), Is.EqualTo(1));
Assert.That(SearchBuilder.WithField("body", "develop").WithField("body", "Orchard").Mandatory().Search().First().ContentItemId, Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("body", "develop").Search().ToList().Count(), Is.EqualTo(2));
Assert.That(_searchBuilder.WithField("body", "develop").WithField("body", "Orchard").Search().ToList().Count(), Is.EqualTo(2));
Assert.That(_searchBuilder.WithField("body", "develop").WithField("body", "Orchard").Mandatory().Search().ToList().Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("body", "develop").WithField("body", "Orchard").Mandatory().Search().First().ContentItemId, Is.EqualTo(1));
}
[Test]
@@ -348,10 +227,10 @@ namespace Orchard.Tests.Modules.Indexing {
_provider.Store("default", _provider.New(1).Add("body", "Orchard has been developped in C#").Analyze());
_provider.Store("default", _provider.New(2).Add("body", "Windows has been developped in C++").Analyze());
Assert.That(SearchBuilder.WithField("body", "developped").Search().ToList().Count(), Is.EqualTo(2));
Assert.That(SearchBuilder.WithField("body", "developped").WithField("body", "Orchard").Search().ToList().Count(), Is.EqualTo(2));
Assert.That(SearchBuilder.WithField("body", "developped").WithField("body", "Orchard").Forbidden().Search().ToList().Count(), Is.EqualTo(1));
Assert.That(SearchBuilder.WithField("body", "developped").WithField("body", "Orchard").Forbidden().Search().First().ContentItemId, Is.EqualTo(2));
Assert.That(_searchBuilder.WithField("body", "developped").Search().ToList().Count(), Is.EqualTo(2));
Assert.That(_searchBuilder.WithField("body", "developped").WithField("body", "Orchard").Search().ToList().Count(), Is.EqualTo(2));
Assert.That(_searchBuilder.WithField("body", "developped").WithField("body", "Orchard").Forbidden().Search().ToList().Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("body", "developped").WithField("body", "Orchard").Forbidden().Search().First().ContentItemId, Is.EqualTo(2));
}
[Test]
@@ -360,7 +239,7 @@ namespace Orchard.Tests.Modules.Indexing {
_provider.Store("default", _provider.New(1).Add("body", "Orchard has been developped in C#").Analyze());
_provider.Store("default", _provider.New(2).Add("body", "Windows has been developped in C++").Analyze());
Assert.That(SearchBuilder.WithField("body", "developped").WithField("body", "Orchard").Weighted(2).Search().First().ContentItemId, Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("body", "developped").WithField("body", "Orchard").Weighted(2).Search().First().ContentItemId, Is.EqualTo(1));
}
[Test]
@@ -370,14 +249,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", 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));
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]
@@ -388,11 +267,11 @@ namespace Orchard.Tests.Modules.Indexing {
_provider.Store("default", _provider.New(3).Add("body", "Bertrand is a little bit jealous.").Analyze().Add("title", "Soap opera").Analyze());
// specifying a field to match
Assert.That(SearchBuilder.Parse(new[] { "body" }, "title:bradley", false).Search().Count(), Is.EqualTo(0));
Assert.That(SearchBuilder.Parse(new[] { "body" }, "title:s*", false).Search().Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.Parse(new[] { "body" }, "title:bradley", false).Search().Count(), Is.EqualTo(0));
Assert.That(_searchBuilder.Parse(new[] { "body" }, "title:s*", false).Search().Count(), Is.EqualTo(1));
// checking terms fall back to the default fields
Assert.That(SearchBuilder.Parse(new[] { "body" }, "title:bradley bradley", false).Search().Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.Parse(new[] { "body" }, "title:bradley bradley", false).Search().Count(), Is.EqualTo(1));
}
[Test]
@@ -402,13 +281,13 @@ namespace Orchard.Tests.Modules.Indexing {
_provider.Store("default", _provider.New(2).Add("field", 22));
_provider.Store("default", _provider.New(3).Add("field", 333));
Assert.That(SearchBuilder.WithField("field", 1).ExactMatch().Count(), Is.EqualTo(1));
Assert.That(SearchBuilder.WithField("field", 22).ExactMatch().Count(), Is.EqualTo(1));
Assert.That(SearchBuilder.WithField("field", 333).ExactMatch().Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("field", 1).ExactMatch().Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("field", 22).ExactMatch().Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("field", 333).ExactMatch().Count(), Is.EqualTo(1));
Assert.That(SearchBuilder.WithField("field", 0).ExactMatch().Count(), Is.EqualTo(0));
Assert.That(SearchBuilder.WithField("field", 2).ExactMatch().Count(), Is.EqualTo(0));
Assert.That(SearchBuilder.WithField("field", 3).ExactMatch().Count(), Is.EqualTo(0));
Assert.That(_searchBuilder.WithField("field", 0).ExactMatch().Count(), Is.EqualTo(0));
Assert.That(_searchBuilder.WithField("field", 2).ExactMatch().Count(), Is.EqualTo(0));
Assert.That(_searchBuilder.WithField("field", 3).ExactMatch().Count(), Is.EqualTo(0));
}
[Test]
@@ -418,13 +297,13 @@ namespace Orchard.Tests.Modules.Indexing {
_provider.Store("default", _provider.New(2).Add("field", 22).Store());
_provider.Store("default", _provider.New(3).Add("field", 333).Store());
Assert.That(SearchBuilder.WithField("field", 1).ExactMatch().Count(), Is.EqualTo(1));
Assert.That(SearchBuilder.WithField("field", 22).ExactMatch().Count(), Is.EqualTo(1));
Assert.That(SearchBuilder.WithField("field", 333).ExactMatch().Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("field", 1).ExactMatch().Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("field", 22).ExactMatch().Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("field", 333).ExactMatch().Count(), Is.EqualTo(1));
Assert.That(SearchBuilder.WithField("field", 0).ExactMatch().Count(), Is.EqualTo(0));
Assert.That(SearchBuilder.WithField("field", 2).ExactMatch().Count(), Is.EqualTo(0));
Assert.That(SearchBuilder.WithField("field", 3).ExactMatch().Count(), Is.EqualTo(0));
Assert.That(_searchBuilder.WithField("field", 0).ExactMatch().Count(), Is.EqualTo(0));
Assert.That(_searchBuilder.WithField("field", 2).ExactMatch().Count(), Is.EqualTo(0));
Assert.That(_searchBuilder.WithField("field", 3).ExactMatch().Count(), Is.EqualTo(0));
}
[Test]
@@ -445,21 +324,21 @@ namespace Orchard.Tests.Modules.Indexing {
_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", "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", "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));
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));
Assert.That(SearchBuilder.WithField("culture", 1033).Count(), Is.EqualTo(2));
Assert.That(SearchBuilder.WithField("culture", 1033).AsFilter().Count(), Is.EqualTo(2));
Assert.That(_searchBuilder.WithField("culture", 1033).Count(), Is.EqualTo(2));
Assert.That(_searchBuilder.WithField("culture", 1033).AsFilter().Count(), Is.EqualTo(2));
Assert.That(SearchBuilder.WithField("body", "blabla").WithField("culture", 1033).Count(), Is.EqualTo(2));
Assert.That(SearchBuilder.WithField("body", "blabla").WithField("culture", 1033).AsFilter().Count(), Is.EqualTo(0));
Assert.That(_searchBuilder.WithField("body", "blabla").WithField("culture", 1033).Count(), Is.EqualTo(2));
Assert.That(_searchBuilder.WithField("body", "blabla").WithField("culture", 1033).AsFilter().Count(), Is.EqualTo(0));
Assert.That(SearchBuilder.Parse("title", "home").Count(), Is.EqualTo(1));
Assert.That(SearchBuilder.Parse("title", "home").WithField("culture", 1033).AsFilter().Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.Parse("title", "home").Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.Parse("title", "home").WithField("culture", 1033).AsFilter().Count(), Is.EqualTo(1));
}
[Test]
@@ -467,7 +346,7 @@ namespace Orchard.Tests.Modules.Indexing {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("body", "foo.bar").Analyze());
Assert.That(SearchBuilder.Parse("body", "*@!woo*@!").Count(), Is.EqualTo(0));
Assert.That(_searchBuilder.Parse("body", "*@!woo*@!").Count(), Is.EqualTo(0));
}
[Test]
@@ -483,17 +362,17 @@ namespace Orchard.Tests.Modules.Indexing {
_provider.Store("default", documentIndex);
Assert.That(SearchBuilder.WithField("tag-id", 0).Count(), Is.EqualTo(0));
Assert.That(SearchBuilder.WithField("tag-id", 1).Count(), Is.EqualTo(1));
Assert.That(SearchBuilder.WithField("tag-id", 2).Count(), Is.EqualTo(1));
Assert.That(SearchBuilder.WithField("tag-id", 3).Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("tag-id", 0).Count(), Is.EqualTo(0));
Assert.That(_searchBuilder.WithField("tag-id", 1).Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("tag-id", 2).Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("tag-id", 3).Count(), Is.EqualTo(1));
Assert.That(SearchBuilder.WithField("tag-value", "tag").ExactMatch().Count(), Is.EqualTo(0));
Assert.That(SearchBuilder.WithField("tag-value", "tag1").ExactMatch().Count(), Is.EqualTo(1));
Assert.That(SearchBuilder.WithField("tag-value", "tag2").ExactMatch().Count(), Is.EqualTo(1));
Assert.That(SearchBuilder.WithField("tag-value", "tag3").ExactMatch().Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("tag-value", "tag").ExactMatch().Count(), Is.EqualTo(0));
Assert.That(_searchBuilder.WithField("tag-value", "tag1").ExactMatch().Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("tag-value", "tag2").ExactMatch().Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("tag-value", "tag3").ExactMatch().Count(), Is.EqualTo(1));
Assert.That(SearchBuilder.WithField("tag-value", "tag").Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("tag-value", "tag").Count(), Is.EqualTo(1));
}
[Test]
@@ -506,12 +385,12 @@ namespace Orchard.Tests.Modules.Indexing {
_provider.Store("default", documentIndex);
// trying in prefix mode
Assert.That(SearchBuilder.WithField("tag-value", "tag").Count(), Is.EqualTo(1));
Assert.That(SearchBuilder.WithField("tag-value", "Tag").Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("tag-value", "tag").Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("tag-value", "Tag").Count(), Is.EqualTo(1));
// trying in full word match mode
Assert.That(SearchBuilder.WithField("tag-value", "tag1").ExactMatch().Count(), Is.EqualTo(1));
Assert.That(SearchBuilder.WithField("tag-value", "Tag1").ExactMatch().Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("tag-value", "tag1").ExactMatch().Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("tag-value", "Tag1").ExactMatch().Count(), Is.EqualTo(1));
}
[Test]
@@ -525,12 +404,12 @@ namespace Orchard.Tests.Modules.Indexing {
_provider.Store("default", documentIndex);
// a value which is not analyzed, is not lowered cased in the index
Assert.That(SearchBuilder.WithField("tag-valueL", "tag").Count(), Is.EqualTo(1));
Assert.That(SearchBuilder.WithField("tag-valueU", "tag").Count(), Is.EqualTo(0));
Assert.That(SearchBuilder.WithField("tag-valueL", "Tag").Count(), Is.EqualTo(1)); // queried term is lower cased
Assert.That(SearchBuilder.WithField("tag-valueU", "Tag").Count(), Is.EqualTo(0)); // queried term is lower cased
Assert.That(SearchBuilder.WithField("tag-valueL", "tag1").ExactMatch().Count(), Is.EqualTo(1));
Assert.That(SearchBuilder.WithField("tag-valueU", "tag1").ExactMatch().Count(), Is.EqualTo(0));
Assert.That(_searchBuilder.WithField("tag-valueL", "tag").Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("tag-valueU", "tag").Count(), Is.EqualTo(0));
Assert.That(_searchBuilder.WithField("tag-valueL", "Tag").Count(), Is.EqualTo(1)); // queried term is lower cased
Assert.That(_searchBuilder.WithField("tag-valueU", "Tag").Count(), Is.EqualTo(0)); // queried term is lower cased
Assert.That(_searchBuilder.WithField("tag-valueL", "tag1").ExactMatch().Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("tag-valueU", "tag1").ExactMatch().Count(), Is.EqualTo(0));
}
[Test]
@@ -540,7 +419,7 @@ namespace Orchard.Tests.Modules.Indexing {
_provider.Store("default", _provider.New(i).Add("term-id", i).Store());
}
Assert.That(SearchBuilder.Count(), Is.EqualTo(99));
Assert.That(_searchBuilder.Count(), Is.EqualTo(99));
}
[Test]
@@ -550,12 +429,12 @@ namespace Orchard.Tests.Modules.Indexing {
_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));
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));
}
[Test]
@@ -583,10 +462,10 @@ namespace Orchard.Tests.Modules.Indexing {
);
Assert.That(SearchBuilder.WithField("field1", 0).Mandatory().Count(), Is.EqualTo(0));
Assert.That(SearchBuilder.WithField("field1", 1).Mandatory().Count(), Is.EqualTo(3));
Assert.That(SearchBuilder.WithField("field1", 1).Mandatory().WithField("field2", 2).Mandatory().Count(), Is.EqualTo(2));
Assert.That(SearchBuilder.WithField("field1", 1).Mandatory().WithField("field2", 2).Mandatory().WithField("field3", 3).Mandatory().Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("field1", 0).Mandatory().Count(), Is.EqualTo(0));
Assert.That(_searchBuilder.WithField("field1", 1).Mandatory().Count(), Is.EqualTo(3));
Assert.That(_searchBuilder.WithField("field1", 1).Mandatory().WithField("field2", 2).Mandatory().Count(), Is.EqualTo(2));
Assert.That(_searchBuilder.WithField("field1", 1).Mandatory().WithField("field2", 2).Mandatory().WithField("field3", 3).Mandatory().Count(), Is.EqualTo(1));
}
[Test]
@@ -613,18 +492,9 @@ namespace Orchard.Tests.Modules.Indexing {
.Add("field3", 3)
);
Assert.That(SearchBuilder.WithField("field1", 1).Count(), Is.EqualTo(3));
Assert.That(SearchBuilder
.WithField("field1", 1)
.WithField("field2", 2).AsFilter()
.Count(), Is.EqualTo(2));
Assert.That(SearchBuilder
.WithField("field1", 1)
.WithField("field2", 2).Mandatory().AsFilter()
.WithField("field3", 3).Mandatory().AsFilter()
.Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("field1", 1).Count(), Is.EqualTo(3));
Assert.That(_searchBuilder.WithField("field1", 1).WithField("field2", 2).AsFilter().Count(), Is.EqualTo(2));
Assert.That(_searchBuilder.WithField("field1", 1).WithField("field2", 2).Mandatory().AsFilter().WithField("field3", 3).Mandatory().AsFilter().Count(), Is.EqualTo(1));
}
}
}

View File

@@ -17,15 +17,15 @@ using Orchard.Data.Conventions;
using Orchard.Data.Migration.Generator;
using Orchard.Data.Migration.Interpreters;
using Orchard.Data.Migration.Schema;
using Orchard.Environment.Compilation.Dependencies;
using Orchard.Environment.Compilation.Loaders;
using Orchard.Environment.Configuration;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Folders;
using Orchard.Environment.Extensions.Loaders;
using Orchard.Environment.Extensions.Models;
using Orchard.Environment.ShellBuilders;
using Orchard.Environment.ShellBuilders.Models;
using Orchard.FileSystems.AppData;
using Orchard.FileSystems.Dependencies;
using Orchard.Tests.ContentManagement;
using Orchard.Data.Providers;
using Orchard.Tests.DataMigration.Utilities;

View File

@@ -3,11 +3,11 @@ using Autofac;
using Moq;
using NuGet;
using NUnit.Framework;
using Orchard.AspNet.Abstractions;
using Orchard.Caching;
using Orchard.Environment;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
using Orchard.FileSystems.VirtualPath;
using Orchard.FileSystems.WebSite;
using Orchard.Packaging.Services;
using Orchard.Tests.Stubs;

View File

@@ -3,9 +3,9 @@ using System.IO;
using System.IO.Packaging;
using Autofac;
using NUnit.Framework;
using Orchard.AspNet.Abstractions;
using Orchard.Environment;
using Orchard.Environment.Extensions.Models;
using Orchard.FileSystems.VirtualPath;
using Orchard.FileSystems.WebSite;
using Orchard.Packaging.Services;
using Orchard.Tests.Stubs;

View File

@@ -3,11 +3,11 @@ using Autofac;
using Moq;
using NuGet;
using NUnit.Framework;
using Orchard.AspNet.Abstractions;
using Orchard.Caching;
using Orchard.Environment;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
using Orchard.FileSystems.VirtualPath;
using Orchard.FileSystems.WebSite;
using Orchard.Packaging.Services;
using Orchard.Tests.Stubs;

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("1.2.0")]
[assembly: AssemblyFileVersion("1.2.0")]
[assembly: AssemblyVersion("1.2.41")]
[assembly: AssemblyFileVersion("1.2.41")]

View File

@@ -5,7 +5,6 @@ using System.Web.Hosting;
using System.Xml.Linq;
using Autofac;
using NUnit.Framework;
using Orchard.AspNet.Abstractions;
using Orchard.Caching;
using Orchard.Core.Settings.Descriptor;
using Orchard.Core.Settings.Descriptor.Records;
@@ -19,7 +18,7 @@ using Orchard.Environment.Extensions.Models;
using Orchard.Environment.Features;
using Orchard.Environment.State;
using Orchard.Events;
using Orchard.FileSystems.WebSite;
using Orchard.FileSystems.VirtualPath;
using Orchard.Packaging.Services;
using Orchard.Recipes.Models;
using Orchard.Recipes.RecipeHandlers;
@@ -62,8 +61,6 @@ namespace Orchard.Tests.Modules.Recipes.RecipeHandlers {
builder.RegisterType<ModuleRecipeHandlerTest.StubPackageManager>().As<IPackageManager>();
builder.RegisterType<ShellStateManager>().As<IShellStateManager>().SingleInstance();
builder.RegisterInstance(_testVirtualPathProvider).As<IVirtualPathProvider>();
builder.RegisterType<WebSiteFolder>().As<IWebSiteFolder>();
builder.RegisterType<DefaultVirtualPathMonitor>().As<IVirtualPathMonitor>();
builder.RegisterType<StubEventBus>().As<IEventBus>().SingleInstance();
builder.RegisterType<ThemeService>().As<IThemeService>();
builder.RegisterType<StubOrchardServices>().As<IOrchardServices>();

View File

@@ -3,6 +3,6 @@ Author: Bertrand Le Roy
Description:
This plug-in replaces
'the' with 'le'
Version: 1.2.0
Version: 1.2.41
Tags: plug-in, français, the, le
homepage: http://weblogs.asp.net/bleroy

View File

@@ -5,15 +5,15 @@ using System.Xml;
using Autofac;
using NUnit.Framework;
using Orchard.Caching;
using Orchard.Environment.Compilation.Loaders;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Folders;
using Orchard.Environment.Extensions.Loaders;
using Orchard.FileSystems.AppData;
using Orchard.FileSystems.WebSite;
using Orchard.Recipes.Models;
using Orchard.Recipes.Services;
using Orchard.Services;
using Orchard.Tests.Stubs;
using Orchard.Time;
namespace Orchard.Tests.Modules.Recipes.Services {
[TestFixture]
@@ -107,7 +107,7 @@ namespace Orchard.Tests.Modules.Recipes.Services {
}
[Test]
public void ParseRecipeLoadsRecipeMetadataIntoModel() {
public void ParseRecipeLoadsRecipeMetaDataIntoModel() {
var recipes = (List<Recipe>) _recipeHarvester.HarvestRecipes("Sample1");
Assert.That(recipes.Count, Is.EqualTo(1));

View File

@@ -10,9 +10,9 @@ using NUnit.Framework;
using Orchard.Caching;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.Definition;
using Orchard.ContentManagement.Definition.Models;
using Orchard.ContentManagement.Definition.Services;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Models;
using Orchard.ContentManagement.MetaData.Services;
using Orchard.ContentManagement.Records;
using Orchard.Core.Settings.Descriptor.Records;
using Orchard.Core.Settings.Handlers;

View File

@@ -8,9 +8,9 @@ using Autofac;
using Moq;
using NUnit.Framework;
using Orchard.Caching;
using Orchard.ContentManagement.Definition;
using Orchard.ContentManagement.Definition.Models;
using Orchard.ContentManagement.Definition.Services;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Models;
using Orchard.ContentManagement.MetaData.Services;
using Orchard.Core.Settings.Metadata;
using Orchard.Data;
using Orchard.DisplayManagement;
@@ -53,7 +53,9 @@ namespace Orchard.Tests.Modules.Users.Controllers {
builder.RegisterType<AccountController>().SingleInstance();
builder.RegisterType<SiteService>().As<ISiteService>();
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
builder.RegisterType(typeof(SettingsFormatter)).As<ISettingsFormatter>();
builder.RegisterType(typeof(SettingsFormatter))
.As(typeof(IMapper<XElement, SettingsDictionary>))
.As(typeof(IMapper<SettingsDictionary, XElement>));
builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
builder.RegisterType<DefaultContentQuery>().As<IContentQuery>().InstancePerDependency();

View File

@@ -5,9 +5,9 @@ using Autofac;
using Moq;
using NHibernate;
using NUnit.Framework;
using Orchard.ContentManagement.Definition;
using Orchard.ContentManagement.Definition.Models;
using Orchard.ContentManagement.Definition.Services;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Models;
using Orchard.ContentManagement.MetaData.Services;
using Orchard.Core.Settings.Metadata;
using Orchard.Data;
using Orchard.ContentManagement;
@@ -71,7 +71,9 @@ namespace Orchard.Tests.Modules.Users.Services {
builder.RegisterType<MembershipService>().As<IMembershipService>();
builder.RegisterType<DefaultContentQuery>().As<IContentQuery>();
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
builder.RegisterType(typeof(SettingsFormatter)).As<ISettingsFormatter>();
builder.RegisterType(typeof(SettingsFormatter))
.As(typeof(IMapper<XElement, SettingsDictionary>))
.As(typeof(IMapper<SettingsDictionary, XElement>));
builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
builder.RegisterType<UserPartHandler>().As<IContentHandler>();

View File

@@ -6,9 +6,9 @@ using Autofac;
using Moq;
using NHibernate;
using NUnit.Framework;
using Orchard.ContentManagement.Definition;
using Orchard.ContentManagement.Definition.Models;
using Orchard.ContentManagement.Definition.Services;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Models;
using Orchard.ContentManagement.MetaData.Services;
using Orchard.Core.Settings.Metadata;
using Orchard.Data;
using Orchard.ContentManagement;
@@ -25,7 +25,6 @@ using Orchard.Security;
using Orchard.Security.Providers;
using Orchard.Tests.Stubs;
using Orchard.Tests.Utility;
using Orchard.Time;
using Orchard.Users.Handlers;
using Orchard.Users.Models;
using Orchard.Users.Services;
@@ -77,13 +76,15 @@ namespace Orchard.Tests.Modules.Users.Services {
[SetUp]
public void Init() {
var builder = new ContainerBuilder();
//builder.RegisterModule(new ImplicitCollectionSupportModule());
builder.RegisterType<MembershipService>().As<IMembershipService>();
builder.RegisterType<UserService>().As<IUserService>();
builder.RegisterInstance(_clock = new StubClock()).As<IClock>();
builder.RegisterType<DefaultContentQuery>().As<IContentQuery>();
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
builder.RegisterType(typeof(SettingsFormatter)).As<ISettingsFormatter>();
builder.RegisterType(typeof(SettingsFormatter))
.As(typeof(IMapper<XElement, SettingsDictionary>))
.As(typeof(IMapper<SettingsDictionary, XElement>));
builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
builder.RegisterType<UserPartHandler>().As<IContentHandler>();

View File

@@ -1,5 +1,6 @@
using System.Security.Cryptography;
using Orchard.Environment.Configuration;
using Orchard.Utility.Extensions;
namespace Orchard.Tests.Modules.Users {
public class ShellSettingsUtility {

View File

@@ -9,12 +9,11 @@ using NUnit.Framework;
using Orchard.Environment.Configuration;
using Orchard.Environment.Warmup;
using Orchard.FileSystems.AppData;
using Orchard.Locking;
using Orchard.FileSystems.LockFile;
using Orchard.Services;
using Orchard.Tests.FileSystems.AppData;
using Orchard.Tests.Stubs;
using Orchard.Tests.UI.Navigation;
using Orchard.Time;
using Orchard.Warmup.Models;
using Orchard.Warmup.Services;
@@ -23,7 +22,7 @@ namespace Orchard.Tests.Modules.Warmup {
protected IContainer _container;
private IWarmupUpdater _warmupUpdater;
private IAppDataFolder _appDataFolder;
private ILockManager _lockManager;
private ILockFileManager _lockFileManager;
private StubClock _clock;
private Mock<IWebDownloader> _webDownloader;
private IOrchardServices _orchardServices;
@@ -61,7 +60,7 @@ namespace Orchard.Tests.Modules.Warmup {
var builder = new ContainerBuilder();
builder.RegisterInstance(_appDataFolder).As<IAppDataFolder>();
builder.RegisterInstance(_orchardServices).As<IOrchardServices>();
builder.RegisterType<DefaultLockManager>().As<ILockManager>();
builder.RegisterType<DefaultLockFileManager>().As<ILockFileManager>();
builder.RegisterType<WarmupUpdater>().As<IWarmupUpdater>();
builder.RegisterType<StubClock>().As<IClock>();
builder.RegisterType<WarmupReportManager>().As<IWarmupReportManager>();
@@ -70,7 +69,7 @@ namespace Orchard.Tests.Modules.Warmup {
builder.RegisterInstance(_webDownloader.Object).As<IWebDownloader>();
_container = builder.Build();
_lockManager = _container.Resolve<ILockManager>();
_lockFileManager = _container.Resolve<ILockFileManager>();
_warmupUpdater = _container.Resolve<IWarmupUpdater>();
_reportManager = _container.Resolve<IWarmupReportManager>();
@@ -86,17 +85,17 @@ namespace Orchard.Tests.Modules.Warmup {
[Test]
public void StampFileShouldBeDeletedToForceAnUpdate() {
_appDataFolder.StoreFile(_warmupFilename, "");
_appDataFolder.CreateFile(_warmupFilename, "");
_warmupUpdater.Generate();
Assert.That(_appDataFolder.ListFiles(WarmupFolder).Count(), Is.EqualTo(0));
}
[Test]
public void GenerateShouldNotRunIfLocked() {
_appDataFolder.StoreFile(_warmupFilename, "");
var @lock = _lockManager.TryLock(_lockFilename);
using (@lock) {
_appDataFolder.CreateFile(_warmupFilename, "");
ILockFile lockFile = null;
_lockFileManager.TryAcquireLock(_lockFilename, ref lockFile);
using(lockFile) {
_warmupUpdater.Generate();
Assert.That(_appDataFolder.ListFiles(WarmupFolder).Count(), Is.EqualTo(0));
}
@@ -326,7 +325,7 @@ namespace Orchard.Tests.Modules.Warmup {
.Returns(new DownloadResult { Content = "Bar", StatusCode = HttpStatusCode.OK });
// Create a static file in the warmup folder
_appDataFolder.StoreFile(_appDataFolder.Combine(WarmupFolder, "foo.txt"), "Foo");
_appDataFolder.CreateFile(_appDataFolder.Combine(WarmupFolder, "foo.txt"), "Foo");
_warmupUpdater.Generate();
var files = _appDataFolder.ListFiles(WarmupFolder).ToList();

View File

@@ -6,7 +6,7 @@ using Moq;
using NUnit.Framework;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.Definition;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.Records;
using Orchard.Core.Common.Models;
using Orchard.Core.Settings.Metadata.Records;

View File

@@ -17,8 +17,8 @@ namespace Orchard.Tests.Modules.XmlRpc.Controllers {
var builder = new ContainerBuilder();
//builder.RegisterModule(new ImplicitCollectionSupportModule());
builder.RegisterType<HomeController>();
builder.RegisterType<XmlRpcReader>().As<IXmlRpcReader>();
builder.RegisterType<XmlRpcWriter>().As<IXmlRpcWriter>();
builder.RegisterType<XmlRpcReader>().As<IMapper<XElement, XRpcMethodCall>>();
builder.RegisterType<XmlRpcWriter>().As<IMapper<XRpcMethodResponse, XElement>>();
builder.RegisterInstance(thing1).As<IXmlRpcHandler>();
builder.RegisterInstance(thing2).As<IXmlRpcHandler>();

View File

@@ -17,8 +17,8 @@ namespace Orchard.Tests.Modules.XmlRpc.Controllers {
var builder = new ContainerBuilder();
builder.RegisterType<LiveWriterController>();
builder.RegisterType<XmlRpcReader>().As<IXmlRpcReader>();
builder.RegisterType<XmlRpcWriter>().As<IXmlRpcWriter>();
builder.RegisterType<XmlRpcReader>().As<IMapper<XElement, XRpcMethodCall>>();
builder.RegisterType<XmlRpcWriter>().As<IMapper<XRpcMethodResponse, XElement>>();
builder.RegisterInstance(thing).As<IXmlRpcHandler>();
builder.RegisterInstance(thingToo).As<IXmlRpcHandler>();

View File

@@ -1,16 +1,22 @@
using System;
using System.Xml.Linq;
using NUnit.Framework;
using Orchard.Core.XmlRpc.Models;
using Orchard.Core.XmlRpc.Services;
namespace Orchard.Tests.Modules.XmlRpc.Services {
[TestFixture]
public class XmlRpcReaderTests {
private IXmlRpcReader _xmlRpcReader;
private IMapper<XElement, XRpcMethodCall> _methodCallMapper;
private IMapper<XElement, XRpcStruct> _structMapper;
private IMapper<XElement, XRpcArray> _arrayMapper;
[SetUp]
public void Init() {
_xmlRpcReader = new XmlRpcReader();
var mapper = new XmlRpcReader();
_methodCallMapper = mapper;
_structMapper = mapper;
_arrayMapper = mapper;
}
[Test]
@@ -20,7 +26,7 @@ namespace Orchard.Tests.Modules.XmlRpc.Services {
<methodName>hello world</methodName>
</methodCall>");
var methodCall = _xmlRpcReader.MapToMethodCall(source);
var methodCall = _methodCallMapper.Map(source);
Assert.That(methodCall, Is.Not.Null);
Assert.That(methodCall.MethodName, Is.EqualTo("hello world"));
}
@@ -42,7 +48,7 @@ namespace Orchard.Tests.Modules.XmlRpc.Services {
</params>
</methodCall>");
var methodCall = _xmlRpcReader.MapToMethodCall(source);
var methodCall = _methodCallMapper.Map(source);
Assert.That(methodCall, Is.Not.Null);
Assert.That(methodCall.Params, Has.Count.EqualTo(8));
Assert.That(methodCall.Params[0].Value, Is.EqualTo(-12));
@@ -51,7 +57,7 @@ namespace Orchard.Tests.Modules.XmlRpc.Services {
Assert.That(methodCall.Params[3].Value, Is.EqualTo(false));
Assert.That(methodCall.Params[4].Value, Is.EqualTo("hello world"));
Assert.That(methodCall.Params[5].Value, Is.EqualTo(-12.214));
Assert.That(methodCall.Params[6].Value, Is.EqualTo(new DateTime(1998, 7, 17, 14, 8, 55)));
Assert.That(methodCall.Params[6].Value, Is.EqualTo(new DateTime(1998,7,17,14,8,55)));
Assert.That(methodCall.Params[7].Value, Is.EqualTo(Convert.FromBase64String("eW91IGNhbid0IHJlYWQgdGhpcyE=")));
}
@@ -69,7 +75,7 @@ namespace Orchard.Tests.Modules.XmlRpc.Services {
<member><name>eight</name><value><base64>eW91IGNhbid0IHJlYWQgdGhpcyE=</base64></value></member>
</struct>");
var xmlStruct = _xmlRpcReader.MapToStruct(source);
var xmlStruct = _structMapper.Map(source);
Assert.That(xmlStruct["one"], Is.EqualTo(-12));
Assert.That(xmlStruct["two"], Is.EqualTo(42));
Assert.That(xmlStruct["three"], Is.EqualTo(true));
@@ -88,7 +94,7 @@ namespace Orchard.Tests.Modules.XmlRpc.Services {
<member><name>seven</name><value><dateTime.iso8601>FOO</dateTime.iso8601></value></member>
</struct>");
var xmlStruct = _xmlRpcReader.MapToStruct(source);
var xmlStruct = _structMapper.Map(source);
Assert.That(xmlStruct["seven"], Is.GreaterThan(DateTime.Now.AddSeconds(-1)));
Assert.That(xmlStruct["seven"], Is.LessThan(DateTime.Now.AddSeconds(1)));
}
@@ -106,7 +112,7 @@ namespace Orchard.Tests.Modules.XmlRpc.Services {
</array>
");
var xmlArray = _xmlRpcReader.MapToArray(source);
var xmlArray = _arrayMapper.Map(source);
Assert.That(xmlArray.Data, Has.Count.EqualTo(4));
Assert.That(xmlArray[0], Is.EqualTo(12));
Assert.That(xmlArray[1], Is.EqualTo("Egypt"));

View File

@@ -9,10 +9,11 @@ namespace Orchard.Tests.Modules.XmlRpc.Services {
[Test]
public void MethodResponseWriterShouldSendParametersWithValues() {
var mapper = new XmlRpcWriter();
IMapper<XRpcMethodResponse, XElement> resposeMapper = mapper;
var response = new XRpcMethodResponse();
response.Params.Add(new XRpcData<int> { Value = 42 });
var element = mapper.MapMethodResponse(response);
var element = resposeMapper.Map(response);
Assert.That(NoSpace(element.ToString()), Is.EqualTo("<methodResponse><params><param><value><int>42</int></value></param></params></methodResponse>"));
}
@@ -20,6 +21,7 @@ namespace Orchard.Tests.Modules.XmlRpc.Services {
[Test]
public void ArrayAndStructShouldWorkAsExpected() {
var mapper = new XmlRpcWriter();
IMapper<XRpcArray, XElement> arrayMapper = mapper;
var arr = new XRpcArray();
var structParam = XRpcData.For(new XRpcStruct());
@@ -29,7 +31,7 @@ namespace Orchard.Tests.Modules.XmlRpc.Services {
structParam.Value.Members.Add("Hello", XRpcData.For("world"));
var element = mapper.MapArray(arr);
var element = arrayMapper.Map(arr);
Assert.That(NoSpace(element.ToString()), Is.EqualTo(NoSpace(@"
<array><data>

View File

@@ -5,7 +5,6 @@ using Autofac;
using Orchard.FileSystems.AppData;
using Orchard.FileSystems.WebSite;
using Orchard.Services;
using Orchard.Time;
namespace Orchard.Tests.Caching {
[TestFixture]

View File

@@ -4,7 +4,6 @@ using NUnit.Framework;
using Orchard.Caching;
using Orchard.Services;
using Orchard.Tests.Stubs;
using Orchard.Time;
namespace Orchard.Tests.Caching {
[TestFixture]

View File

@@ -3,7 +3,7 @@ using Autofac;
using Moq;
using NHibernate;
using NUnit.Framework;
using Orchard.ContentManagement.Definition;
using Orchard.ContentManagement.MetaData;
using Orchard.Data;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;

View File

@@ -5,8 +5,9 @@ using Autofac;
using Moq;
using NHibernate;
using NUnit.Framework;
using Orchard.ContentManagement.Definition;
using Orchard.ContentManagement.Definition.Builders;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Builders;
using Orchard.ContentManagement.MetaData.Models;
using Orchard.Data;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
@@ -18,6 +19,7 @@ using Orchard.Tests.ContentManagement.Models;
using Orchard.DisplayManagement.Descriptors;
using Orchard.DisplayManagement.Implementation;
using Orchard.DisplayManagement;
using System.Collections.Generic;
using Orchard.Tests.Stubs;
namespace Orchard.Tests.ContentManagement {
@@ -175,6 +177,41 @@ namespace Orchard.Tests.ContentManagement {
Assert.That(modelRecord.ContentType.Name, Is.EqualTo(DefaultBetaName));
}
/// <summary>
/// Tests that the GetContentTypeDefinitions returns only the registered types.
/// </summary>
[Test]
public void GetContentTypesShouldReturnAllTypes() {
// Register the types and obtain them
ContentTypeDefinition alphaType = new ContentTypeDefinitionBuilder()
.Named(DefaultAlphaName)
.Build();
ContentTypeDefinition betaType = new ContentTypeDefinitionBuilder()
.Named(DefaultBetaName)
.Build();
ContentTypeDefinition gammaType = new ContentTypeDefinitionBuilder()
.Named(DefaultGammaName)
.Build();
ContentTypeDefinition deltaType = new ContentTypeDefinitionBuilder()
.Named(DefaultDeltaName)
.Build();
_contentDefinitionManager.Setup(contentDefinitionManager => contentDefinitionManager.ListTypeDefinitions())
.Returns(new List<ContentTypeDefinition> { alphaType, betaType, gammaType, deltaType });
var types = _manager.GetContentTypeDefinitions();
// Validate that the expected types were obtained
Assert.That(types.Count(), Is.EqualTo(4));
Assert.That(types, Has.Some.With.Property("Name").EqualTo(DefaultAlphaName));
Assert.That(types, Has.Some.With.Property("Name").EqualTo(DefaultBetaName));
Assert.That(types, Has.Some.With.Property("Name").EqualTo(DefaultGammaName));
Assert.That(types, Has.Some.With.Property("Name").EqualTo(DefaultDeltaName));
}
[Test]
public void BigStringsShouldNotBeTruncated() {
var megaRepository = _container.Resolve<IRepository<MegaRecord>>();

View File

@@ -5,8 +5,8 @@ using NUnit.Framework;
using Orchard.ContentManagement;
using Orchard.ContentManagement.FieldStorage;
using Orchard.ContentManagement.FieldStorage.InfosetStorage;
using Orchard.ContentManagement.Definition.Builders;
using Orchard.ContentManagement.Definition.Models;
using Orchard.ContentManagement.MetaData.Builders;
using Orchard.ContentManagement.MetaData.Models;
namespace Orchard.Tests.ContentManagement.Drivers.FieldStorage {
[TestFixture]

View File

@@ -4,8 +4,8 @@ using NUnit.Framework;
using Orchard.ContentManagement;
using Orchard.ContentManagement.FieldStorage;
using Orchard.ContentManagement.FieldStorage.InfosetStorage;
using Orchard.ContentManagement.Definition.Builders;
using Orchard.ContentManagement.Definition.Models;
using Orchard.ContentManagement.MetaData.Builders;
using Orchard.ContentManagement.MetaData.Models;
using Orchard.ContentManagement.Records;
namespace Orchard.Tests.ContentManagement.Drivers.FieldStorage {

View File

@@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using NUnit.Framework;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Definition.Models;
using Orchard.ContentManagement.MetaData.Models;
namespace Orchard.Tests.ContentManagement {
[TestFixture]

View File

@@ -1,7 +1,7 @@
using NUnit.Framework;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.Definition.Builders;
using Orchard.ContentManagement.MetaData.Builders;
namespace Orchard.Tests.ContentManagement.Handlers {

View File

@@ -7,7 +7,7 @@ using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Drivers.Coordinators;
using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.Definition;
using Orchard.ContentManagement.MetaData;
using Orchard.DisplayManagement;
using Orchard.DisplayManagement.Implementation;

View File

@@ -1,7 +1,7 @@
using NUnit.Framework;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.Definition.Builders;
using Orchard.ContentManagement.MetaData.Builders;
using Orchard.Tests.ContentManagement.Models;
namespace Orchard.Tests.ContentManagement.Handlers {

View File

@@ -1,8 +1,8 @@
using System.Linq;
using NUnit.Framework;
using Orchard.ContentManagement.Definition.Builders;
using Orchard.ContentManagement.MetaData.Builders;
namespace Orchard.Tests.ContentManagement.Metadata.Builders {
namespace Orchard.Tests.ContentManagement.MetaData.Builders {
[TestFixture]
public class ContentTypeDefinitionBuilderTests {
[Test]

View File

@@ -1,10 +1,11 @@
using System.Linq;
using System.Xml.Linq;
using NUnit.Framework;
using Orchard.ContentManagement.Definition.Builders;
using Orchard.ContentManagement.Definition.Services;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Builders;
using Orchard.ContentManagement.MetaData.Services;
namespace Orchard.Tests.ContentManagement.Metadata.Services {
namespace Orchard.Tests.ContentManagement.MetaData.Services {
[TestFixture]
public class ContentDefinitionReaderTests {
private IContentDefinitionReader _reader;

View File

@@ -2,10 +2,10 @@
using System.Xml;
using System.Xml.Linq;
using NUnit.Framework;
using Orchard.ContentManagement.Definition.Builders;
using Orchard.ContentManagement.Definition.Services;
using Orchard.ContentManagement.MetaData.Builders;
using Orchard.ContentManagement.MetaData.Services;
namespace Orchard.Tests.ContentManagement.Metadata.Services {
namespace Orchard.Tests.ContentManagement.MetaData.Services {
[TestFixture]
public class ContentDefinitionWriterTests {
private ContentDefinitionWriter _writer;

View File

@@ -1,5 +1,5 @@
using Orchard.ContentManagement;
using Orchard.ContentManagement.Definition.Models;
using Orchard.ContentManagement.MetaData.Models;
namespace Orchard.Tests.ContentManagement.Models {
public class Phi : ContentField {

View File

@@ -81,7 +81,7 @@ namespace Orchard.Tests.Data {
public void LinqCanBeUsedToSelectObjects() {
CreateThreeFoos();
var foos = from f in _fooRepos.Fetch()
var foos = from f in _fooRepos.Table
where f.Name == "one" || f.Name == "two"
select f;
@@ -94,7 +94,7 @@ namespace Orchard.Tests.Data {
public void LinqExtensionMethodsCanAlsoBeUsedToSelectObjects() {
CreateThreeFoos();
var foos = _fooRepos.Fetch()
var foos = _fooRepos.Table
.Where(f => f.Name == "one" || f.Name == "two");
Assert.That(foos.Count(), Is.EqualTo(2));
@@ -115,12 +115,31 @@ namespace Orchard.Tests.Data {
Assert.That(foos.Skip(1).First().Name, Is.EqualTo("two"));
}
[Test]
public void LinqOrderByCanBeUsedToControlResultsBug() {
CreateThreeFoos();
// If look at the "LinqOrderByCanBeUsedToControlResults", you will see this query
// works fine is the static type of "foos" is "IEnumerable<Foo>"...
IOrderedQueryable<FooRecord> foos =
from f in _fooRepos.Table
where f.Name == "two" || f.Name == "three"
orderby f.Name, f.Id ascending
select f;
Assert.That(foos.Count(), Is.EqualTo(2));
Assert.That(foos.First().Name, Is.EqualTo("three"));
// Looks like a bug in NHib implementation of IOrderedQueryable<T>
Assert.Throws<AssertionException>(() => Assert.That(foos.Skip(1).First().Name, Is.EqualTo("two")));
}
[Test]
public void LinqOrderByCanBeUsedToControlResults() {
CreateThreeFoos();
IEnumerable<FooRecord> foos =
from f in _fooRepos.Fetch()
from f in _fooRepos.Table
where f.Name == "two" || f.Name == "three"
orderby f.Name, f.Id ascending
select f;

View File

@@ -7,7 +7,7 @@ using Moq;
using NHibernate;
using NUnit.Framework;
using Orchard.Caching;
using Orchard.ContentManagement.Definition;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.Records;
using Orchard.Data;
using Orchard.Data.Migration;
@@ -241,7 +241,7 @@ Features:
");
_dataMigrationManager.Update("Feature1");
Assert.That(_repository.Fetch().Count(), Is.EqualTo(0));
Assert.That(_repository.Table.Count(), Is.EqualTo(0));
}
[Test]
@@ -258,7 +258,7 @@ Features:
");
_dataMigrationManager.Update("Feature1");
Assert.That(_repository.Fetch().Count(), Is.EqualTo(0));
Assert.That(_repository.Table.Count(), Is.EqualTo(0));
}
[Test]
@@ -275,9 +275,9 @@ Features:
");
_dataMigrationManager.Update("Feature1");
Assert.That(_repository.Fetch().Count(), Is.EqualTo(1));
Assert.That(_repository.Fetch().First().Version, Is.EqualTo(999));
Assert.That(_repository.Fetch().First().DataMigrationClass, Is.EqualTo("Orchard.Tests.DataMigration.DataMigrationTests+DataMigration11Create"));
Assert.That(_repository.Table.Count(), Is.EqualTo(1));
Assert.That(_repository.Table.First().Version, Is.EqualTo(999));
Assert.That(_repository.Table.First().DataMigrationClass, Is.EqualTo("Orchard.Tests.DataMigration.DataMigrationTests+DataMigration11Create"));
}
[Test]
@@ -294,8 +294,8 @@ Features:
");
_dataMigrationManager.Update("Feature1");
Assert.That(_repository.Fetch().Count(), Is.EqualTo(1));
Assert.That(_repository.Fetch().First().Version, Is.EqualTo(666));
Assert.That(_repository.Table.Count(), Is.EqualTo(1));
Assert.That(_repository.Table.First().Version, Is.EqualTo(666));
}
[Test]
@@ -316,8 +316,8 @@ Features:
});
_dataMigrationManager.Update("Feature1");
Assert.That(_repository.Fetch().Count(), Is.EqualTo(1));
Assert.That(_repository.Fetch().First().Version, Is.EqualTo(999));
Assert.That(_repository.Table.Count(), Is.EqualTo(1));
Assert.That(_repository.Table.First().Version, Is.EqualTo(999));
}
[Test]
@@ -344,7 +344,7 @@ Features:
Description: Feature
");
_dataMigrationManager.Update("Feature1");
Assert.That(_repository.Fetch().Count(), Is.EqualTo(2));
Assert.That(_repository.Table.Count(), Is.EqualTo(2));
Assert.That(_repository.Fetch(d => d.Version == 999).Count(), Is.EqualTo(2));
Assert.That(_repository.Fetch(d => d.DataMigrationClass == "Orchard.Tests.DataMigration.DataMigrationTests+DataMigrationDependenciesModule1").Count(), Is.EqualTo(1));
Assert.That(_repository.Fetch(d => d.DataMigrationClass == "Orchard.Tests.DataMigration.DataMigrationTests+DataMigrationDependenciesModule2").Count(), Is.EqualTo(1));
@@ -364,7 +364,7 @@ Features:
");
_dataMigrationManager.Update("Feature1");
Assert.That(_repository.Fetch().Count(), Is.EqualTo(1));
Assert.That(_repository.Table.Count(), Is.EqualTo(1));
}
[Test]

View File

@@ -10,7 +10,6 @@ using Orchard.Data;
using Orchard.Services;
using Orchard.Tests.Data;
using Orchard.Tests.Stubs;
using Orchard.Time;
namespace Orchard.Tests {
public abstract class DatabaseEnabledTestsBase {

View File

@@ -48,13 +48,5 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
public class Token : IVolatileToken {
public bool IsCurrent { get; set; }
}
public DateTime GetFileLastWriteTimeUtc(string virtualPath) {
throw new NotImplementedException();
}
public bool TryFileExists(string virtualPath) {
throw new NotImplementedException();
}
}
}

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Web.Routing;
using Autofac;
using JetBrains.Annotations;
using Moq;
using NUnit.Framework;
using Orchard.DisplayManagement;
@@ -18,7 +19,7 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
public class ShapeAttributeBindingStrategyTests : ContainerTestBase {
private Feature _testFeature;
protected override void Register(ContainerBuilder builder) {
protected override void Register([NotNull] ContainerBuilder builder) {
if (builder == null) {
throw new ArgumentNullException("builder");
}

View File

@@ -5,13 +5,13 @@ using System.Linq;
using Autofac;
using Moq;
using NUnit.Framework;
using Orchard.AspNet.Abstractions;
using Orchard.Caching;
using Orchard.DisplayManagement.Descriptors;
using Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy;
using Orchard.Environment.Descriptor.Models;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
using Orchard.FileSystems.VirtualPath;
using Orchard.Tests.Stubs;
namespace Orchard.Tests.DisplayManagement.Descriptors {
@@ -49,10 +49,6 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
}
public class TestVirtualPathProvider : IVirtualPathProvider {
public IEnumerable<string> ListFiles(string path) {
return new List<string> {"~/Modules/Alpha/Views/AlphaShape.blah"};
}
public string Combine(params string[] paths) {
throw new NotImplementedException();
}
@@ -61,34 +57,14 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
throw new NotImplementedException();
}
public string ToAbsolute(string virtualPath) {
throw new NotImplementedException();
}
public string MapPath(string virtualPath) {
throw new NotImplementedException();
}
public string Combine(string basePath, string relativePath) {
throw new NotImplementedException();
}
public bool IsAppRelative(string virtualPath) {
throw new NotImplementedException();
}
public bool IsAbsolute(string virtualPath) {
throw new NotImplementedException();
}
public bool FileExists(string virtualPath) {
throw new NotImplementedException();
}
public bool TryFileExists(string virtualPath) {
throw new NotImplementedException();
}
public Stream OpenFile(string virtualPath) {
throw new NotImplementedException();
}
@@ -125,9 +101,17 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
throw new NotImplementedException();
}
public IEnumerable<string> ListFiles(string path) {
return new List<string> {"~/Modules/Alpha/Views/AlphaShape.blah"};
}
public IEnumerable<string> ListDirectories(string path) {
throw new NotImplementedException();
}
public bool TryFileExists(string virtualPath) {
throw new NotImplementedException();
}
}
protected override void Resolve(ILifetimeScope container) {

View File

@@ -5,13 +5,13 @@ using System.Linq;
using Autofac;
using Moq;
using NUnit.Framework;
using Orchard.AspNet.Abstractions;
using Orchard.DisplayManagement.Descriptors;
using Orchard.DisplayManagement.Descriptors.ResourceBindingStrategy;
using Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy;
using Orchard.Environment.Descriptor.Models;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
using Orchard.FileSystems.VirtualPath;
namespace Orchard.Tests.DisplayManagement.Descriptors {
[TestFixture]
@@ -109,23 +109,6 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
public bool TryFileExists(string virtualPath) {
throw new NotImplementedException();
}
public string ToAbsolute(string virtualPath) {
throw new NotImplementedException();
}
public string Combine(string basePath, string relativePath) {
throw new NotImplementedException();
}
public bool IsAppRelative(string virtualPath) {
throw new NotImplementedException();
}
public bool IsAbsolute(string virtualPath) {
throw new NotImplementedException();
}
}
protected override void Resolve(ILifetimeScope container) {

View File

@@ -19,7 +19,7 @@ namespace Orchard.Tests.Environment.Configuration {
[Test]
public void SingleSettingsFileShouldComeBackAsExpected() {
_appDataFolder.StoreFile("Sites\\Default\\Settings.txt", "Name: Default\r\nDataProvider: SqlCe\r\nDataConnectionString: something else");
_appDataFolder.CreateFile("Sites\\Default\\Settings.txt", "Name: Default\r\nDataProvider: SqlCe\r\nDataConnectionString: something else");
IShellSettingsManager loader = new ShellSettingsManager(_appDataFolder, new Mock<IShellSettingsManagerEventHandler>().Object);
var settings = loader.LoadSettings().Single();
@@ -33,8 +33,8 @@ namespace Orchard.Tests.Environment.Configuration {
[Test]
public void MultipleFilesCanBeDetected() {
_appDataFolder.StoreFile("Sites\\Default\\Settings.txt", "Name: Default\r\nDataProvider: SqlCe\r\nDataConnectionString: something else");
_appDataFolder.StoreFile("Sites\\Another\\Settings.txt", "Name: Another\r\nDataProvider: SqlCe2\r\nDataConnectionString: something else2");
_appDataFolder.CreateFile("Sites\\Default\\Settings.txt", "Name: Default\r\nDataProvider: SqlCe\r\nDataConnectionString: something else");
_appDataFolder.CreateFile("Sites\\Another\\Settings.txt", "Name: Another\r\nDataProvider: SqlCe2\r\nDataConnectionString: something else2");
IShellSettingsManager loader = new ShellSettingsManager(_appDataFolder, new Mock<IShellSettingsManagerEventHandler>().Object);
var settings = loader.LoadSettings();
@@ -53,7 +53,7 @@ namespace Orchard.Tests.Environment.Configuration {
[Test]
public void NewSettingsCanBeStored() {
_appDataFolder.StoreFile("Sites\\Default\\Settings.txt", "Name: Default\r\nDataProvider: SqlCe\r\nDataConnectionString: something else");
_appDataFolder.CreateFile("Sites\\Default\\Settings.txt", "Name: Default\r\nDataProvider: SqlCe\r\nDataConnectionString: something else");
IShellSettingsManager loader = new ShellSettingsManager(_appDataFolder, new Mock<IShellSettingsManagerEventHandler>().Object);
var foo = new ShellSettings {Name = "Foo", DataProvider = "Bar", DataConnectionString = "Quux"};

View File

@@ -6,7 +6,6 @@ using System.Web.Routing;
using Autofac;
using Autofac.Integration.Web;
using NUnit.Framework;
using Orchard.AspNet.Abstractions;
using Orchard.Caching;
using Orchard.Environment;
using Orchard.Environment.Configuration;
@@ -17,6 +16,7 @@ using Orchard.Environment.ShellBuilders;
using Orchard.Environment.Descriptor;
using Orchard.Environment.Descriptor.Models;
using Orchard.FileSystems.AppData;
using Orchard.FileSystems.VirtualPath;
using Orchard.Mvc.ModelBinders;
using Orchard.Mvc.Routes;
using Orchard.Tests.Environment.TestDependencies;

View File

@@ -5,11 +5,11 @@ using System.Reflection;
using Autofac;
using NUnit.Framework;
using Orchard.Caching;
using Orchard.Environment.Compilation.Dependencies;
using Orchard.Environment.Compilation.Loaders;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Folders;
using Orchard.Environment.Extensions.Loaders;
using Orchard.Environment.Extensions.Models;
using Orchard.FileSystems.Dependencies;
using Orchard.Tests.Extensions.ExtensionTypes;
using Orchard.Tests.Stubs;

View File

@@ -6,11 +6,11 @@ using System.Reflection;
using Autofac;
using NUnit.Framework;
using Orchard.Caching;
using Orchard.Environment.Compilation.Dependencies;
using Orchard.Environment.Compilation.Loaders;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Folders;
using Orchard.Environment.Extensions.Loaders;
using Orchard.Environment.Extensions.Models;
using Orchard.FileSystems.Dependencies;
using Orchard.Tests.Extensions.ExtensionTypes;
using Orchard.Tests.Stubs;

View File

@@ -3,6 +3,6 @@ Author: Bertrand Le Roy
Description:
This plug-in replaces
'the' with 'le'
Version: 1.2.0
Version: 1.2.41
Tags: plug-in, français, the, le
homepage: http://weblogs.asp.net/bleroy

View File

@@ -1,25 +1,25 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Autofac;
using Moq;
using NUnit.Framework;
using Orchard.AspNet.Abstractions;
using Orchard.Caching;
using Orchard.Environment;
using Orchard.Environment.Compilation.Compilers;
using Orchard.Environment.Compilation.Dependencies;
using Orchard.Environment.Compilation.Loaders;
using Orchard.Environment.Extensions.Compilers;
using Orchard.Environment.Extensions.Loaders;
using Orchard.FileSystems.AppData;
using Orchard.FileSystems.Dependencies;
using Orchard.FileSystems.VirtualPath;
using Orchard.Services;
using Orchard.Tests.Stubs;
using Orchard.Time;
namespace Orchard.Tests.Environment.Compilation.Loaders {
namespace Orchard.Tests.Environment.Loaders {
[TestFixture]
public class DynamicExtensionLoaderTests {
private IContainer _container;
private Mock<IProjectFileParser> _mockedStubProjectFileParser;
private Mock<IDependencyDescriptorManager> _mockedDependenciesFolder;
private Mock<IDependenciesFolder> _mockedDependenciesFolder;
[SetUp]
public void Init() {
@@ -40,8 +40,8 @@ namespace Orchard.Tests.Environment.Compilation.Loaders {
builder.RegisterInstance(_mockedStubProjectFileParser.Object).As<IProjectFileParser>();
builder.RegisterInstance(new StubFileSystem(new StubClock())).As<StubFileSystem>();
_mockedDependenciesFolder = new Mock<IDependencyDescriptorManager>();
builder.RegisterInstance(_mockedDependenciesFolder.Object).As<IDependencyDescriptorManager>();
_mockedDependenciesFolder = new Mock<IDependenciesFolder>();
builder.RegisterInstance(_mockedDependenciesFolder.Object).As<IDependenciesFolder>();
_container = builder.Build();
}
@@ -150,7 +150,7 @@ namespace Orchard.Tests.Environment.Compilation.Loaders {
IVirtualPathMonitor virtualPathMonitor,
IHostEnvironment hostEnvironment,
IAssemblyProbingFolder assemblyProbingFolder,
IDependencyDescriptorManager dependenciesFolder,
IDependenciesFolder dependenciesFolder,
IProjectFileParser projectFileParser)
: base(buildManager, virtualPathProvider, virtualPathMonitor, hostEnvironment, assemblyProbingFolder, dependenciesFolder, projectFileParser) {}

View File

@@ -4,7 +4,6 @@ using Autofac;
using NUnit.Framework;
using Orchard.Events;
using System;
using Orchard.Exceptions;
namespace Orchard.Tests.Events {
[TestFixture]
@@ -19,7 +18,6 @@ namespace Orchard.Tests.Events {
var builder = new ContainerBuilder();
builder.RegisterType<DefaultOrchardEventBus>().As<IEventBus>();
builder.RegisterType<StubExceptionPolicy>().As<IExceptionPolicy>();
builder.RegisterType<StubEventHandler2>().As<IEventHandler>();
builder.RegisterInstance(_eventHandler).As<IEventHandler>();
@@ -231,10 +229,4 @@ namespace Orchard.Tests.Events {
}
}
}
class StubExceptionPolicy : IExceptionPolicy {
public bool HandleException(object sender, Exception exception) {
return true;
}
}
}

View File

@@ -82,14 +82,14 @@ namespace Orchard.Tests.FileSystems.AppData {
[Test]
public void CreateFileWillCauseDirectoryToBeCreated() {
Assert.That(Directory.Exists(Path.Combine(_tempFolder, "alpha\\omega\\foo")), Is.False);
_appDataFolder.StoreFile("alpha\\omega\\foo\\bar.txt", "quux");
_appDataFolder.CreateFile("alpha\\omega\\foo\\bar.txt", "quux");
Assert.That(Directory.Exists(Path.Combine(_tempFolder, "alpha\\omega\\foo")), Is.True);
}
[Test]
public void FilesCanBeReadBack() {
_appDataFolder.StoreFile("alpha\\gamma\\foo\\bar.txt", @"
public void FilesCanBeReadBack() {
_appDataFolder.CreateFile("alpha\\gamma\\foo\\bar.txt", @"
this is
a
test");
@@ -99,5 +99,16 @@ this is
a
test"));
}
[Test]
public void FileExistsReturnsFalseForNonExistingFile() {
Assert.That(_appDataFolder.FileExists("notexisting"), Is.False);
}
[Test]
public void FileExistsReturnsTrueForExistingFile() {
_appDataFolder.CreateFile("alpha\\foo\\bar.txt", "");
Assert.That(_appDataFolder.FileExists("alpha\\foo\\bar.txt"), Is.True);
}
}
}

View File

@@ -1,10 +1,10 @@
using System.Linq;
using NUnit.Framework;
using Orchard.Environment;
using Orchard.Environment.Compilation.Dependencies;
using Orchard.FileSystems.Dependencies;
using Orchard.Tests.Stubs;
namespace Orchard.Tests.Environment.Compilation.Dependencies {
namespace Orchard.Tests.FileSystems.Dependencies {
[TestFixture]
public class AssemblyProbingFolderTests {

View File

@@ -4,28 +4,27 @@ using System.Linq;
using Autofac;
using NUnit.Framework;
using Orchard.Caching;
using Orchard.Environment.Compilation.Dependencies;
using Orchard.FileSystems.AppData;
using Orchard.FileSystems.Dependencies;
using Orchard.Services;
using Orchard.Tests.Stubs;
using Orchard.Time;
namespace Orchard.Tests.Environment.Compilation.Dependencies {
namespace Orchard.Tests.FileSystems.Dependencies {
[TestFixture]
public class DependencyDescriptorManagerTests {
public class DependenciesFolderTests {
public IContainer BuildContainer() {
var builder = new ContainerBuilder();
builder.RegisterType<StubClock>().As<IClock>().SingleInstance();
builder.RegisterType<StubAppDataFolder>().As<IAppDataFolder>().SingleInstance();
builder.RegisterType<StubCacheManager>().As<ICacheManager>().SingleInstance();
builder.RegisterType<StubParallelCacheContext>().As<IParallelCacheContext>();
builder.RegisterType<DefaultDependencyDescriptorManager>().As<IDependencyDescriptorManager>();
builder.RegisterType<DefaultDependenciesFolder>().As<IDependenciesFolder>();
return builder.Build();
}
[Test]
public void LoadDescriptorsShouldReturnEmptyList() {
var dependenciesFolder = BuildContainer().Resolve<IDependencyDescriptorManager>();
var dependenciesFolder = BuildContainer().Resolve<IDependenciesFolder>();
var e = dependenciesFolder.LoadDescriptors();
Assert.That(e, Is.Empty);
@@ -33,7 +32,7 @@ namespace Orchard.Tests.Environment.Compilation.Dependencies {
[Test]
public void StoreDescriptorsShouldWork() {
var dependenciesFolder = BuildContainer().Resolve<IDependencyDescriptorManager>();
var dependenciesFolder = BuildContainer().Resolve<IDependenciesFolder>();
var d = new DependencyDescriptor {
Name = "name",
@@ -54,7 +53,7 @@ namespace Orchard.Tests.Environment.Compilation.Dependencies {
var container = BuildContainer();
var clock = (StubClock)container.Resolve<IClock>();
var appDataFolder = (StubAppDataFolder)container.Resolve<IAppDataFolder>();
var dependenciesFolder = container.Resolve<IDependencyDescriptorManager>();
var dependenciesFolder = container.Resolve<IDependenciesFolder>();
var d1 = new DependencyDescriptor {
Name = "name1",
@@ -69,11 +68,11 @@ namespace Orchard.Tests.Environment.Compilation.Dependencies {
};
dependenciesFolder.StoreDescriptors(new[] { d1, d2 });
var dateTime1 = appDataFolder.GetLastWriteTimeUtc(appDataFolder.MapPath(Path.Combine("Dependencies", "Dependencies.xml")));
var dateTime1 = appDataFolder.GetLastWriteTimeUtc(Path.Combine("Dependencies", "Dependencies.xml"));
clock.Advance(TimeSpan.FromMinutes(1));
dependenciesFolder.StoreDescriptors(new[] { d2, d1 });
var dateTime2 = appDataFolder.GetLastWriteTimeUtc(appDataFolder.MapPath(Path.Combine("Dependencies", "Dependencies.xml")));
var dateTime2 = appDataFolder.GetLastWriteTimeUtc(Path.Combine("Dependencies", "Dependencies.xml"));
Assert.That(dateTime1, Is.EqualTo(dateTime2));
}
@@ -82,7 +81,7 @@ namespace Orchard.Tests.Environment.Compilation.Dependencies {
var container = BuildContainer();
var clock = (StubClock)container.Resolve<IClock>();
var appDataFolder = (StubAppDataFolder)container.Resolve<IAppDataFolder>();
var dependenciesFolder = container.Resolve<IDependencyDescriptorManager>();
var dependenciesFolder = container.Resolve<IDependenciesFolder>();
var d1 = new DependencyDescriptor {
Name = "name1",
@@ -97,13 +96,13 @@ namespace Orchard.Tests.Environment.Compilation.Dependencies {
};
dependenciesFolder.StoreDescriptors(new[] { d1, d2 });
var dateTime1 = appDataFolder.GetLastWriteTimeUtc(appDataFolder.MapPath(Path.Combine("Dependencies", "Dependencies.xml")));
var dateTime1 = appDataFolder.GetLastWriteTimeUtc(Path.Combine("Dependencies", "Dependencies.xml"));
clock.Advance(TimeSpan.FromMinutes(1));
d1.LoaderName = "bar";
dependenciesFolder.StoreDescriptors(new[] { d2, d1 });
var dateTime2 = appDataFolder.GetLastWriteTimeUtc(appDataFolder.MapPath(Path.Combine("Dependencies", "Dependencies.xml")));
var dateTime2 = appDataFolder.GetLastWriteTimeUtc(Path.Combine("Dependencies", "Dependencies.xml"));
Assert.That(dateTime1 + TimeSpan.FromMinutes(1), Is.EqualTo(dateTime2));
}
@@ -112,7 +111,7 @@ namespace Orchard.Tests.Environment.Compilation.Dependencies {
var container = BuildContainer();
var clock = (StubClock)container.Resolve<IClock>();
var appDataFolder = (StubAppDataFolder)container.Resolve<IAppDataFolder>();
var dependenciesFolder = container.Resolve<IDependencyDescriptorManager>();
var dependenciesFolder = container.Resolve<IDependenciesFolder>();
var d1 = new DependencyDescriptor {
Name = "name1",
@@ -129,7 +128,7 @@ namespace Orchard.Tests.Environment.Compilation.Dependencies {
dependenciesFolder.StoreDescriptors(new[] { d1, d2 });
// Create a new instance over the same appDataFolder
var dependenciesFolder2 = container.Resolve<IDependencyDescriptorManager>();
var dependenciesFolder2 = container.Resolve<IDependenciesFolder>();
Assert.That(dependenciesFolder2, Is.Not.SameAs(dependenciesFolder));
// Ensure descriptors were persisted properly

View File

@@ -0,0 +1,223 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using NUnit.Framework;
using Orchard.FileSystems.AppData;
using Orchard.FileSystems.LockFile;
using Orchard.Tests.Stubs;
namespace Orchard.Tests.FileSystems.LockFile {
[TestFixture]
public class LockFileManagerTests {
private string _tempFolder;
private IAppDataFolder _appDataFolder;
private ILockFileManager _lockFileManager;
private StubClock _clock;
public class StubAppDataFolderRoot : IAppDataFolderRoot {
public string RootPath { get; set; }
public string RootFolder { get; set; }
}
public static IAppDataFolder CreateAppDataFolder(string tempFolder) {
var folderRoot = new StubAppDataFolderRoot {RootPath = "~/App_Data", RootFolder = tempFolder};
var monitor = new StubVirtualPathMonitor();
return new AppDataFolder(folderRoot, monitor);
}
[SetUp]
public void Init() {
_tempFolder = Path.GetTempFileName();
File.Delete(_tempFolder);
_appDataFolder = CreateAppDataFolder(_tempFolder);
_clock = new StubClock();
_lockFileManager = new DefaultLockFileManager(_appDataFolder, _clock);
}
[TearDown]
public void Term() {
Directory.Delete(_tempFolder, true);
}
[Test]
public void LockShouldBeGrantedWhenDoesNotExist() {
ILockFile lockFile = null;
var granted = _lockFileManager.TryAcquireLock("foo.txt.lock", ref lockFile);
Assert.That(granted, Is.True);
Assert.That(lockFile, Is.Not.Null);
Assert.That(_lockFileManager.IsLocked("foo.txt.lock"), Is.True);
Assert.That(_appDataFolder.ListFiles("").Count(), Is.EqualTo(1));
}
[Test]
public void ExistingLockFileShouldPreventGrants() {
ILockFile lockFile = null;
_lockFileManager.TryAcquireLock("foo.txt.lock", ref lockFile);
Assert.That(_lockFileManager.TryAcquireLock("foo.txt.lock", ref lockFile), Is.False);
Assert.That(_lockFileManager.IsLocked("foo.txt.lock"), Is.True);
Assert.That(_appDataFolder.ListFiles("").Count(), Is.EqualTo(1));
}
[Test]
public void ReleasingALockShouldAllowGranting() {
ILockFile lockFile = null;
_lockFileManager.TryAcquireLock("foo.txt.lock", ref lockFile);
using (lockFile) {
Assert.That(_lockFileManager.IsLocked("foo.txt.lock"), Is.True);
Assert.That(_appDataFolder.ListFiles("").Count(), Is.EqualTo(1));
}
Assert.That(_lockFileManager.IsLocked("foo.txt.lock"), Is.False);
Assert.That(_appDataFolder.ListFiles("").Count(), Is.EqualTo(0));
}
[Test]
public void ReleasingAReleasedLockShouldWork() {
ILockFile lockFile = null;
_lockFileManager.TryAcquireLock("foo.txt.lock", ref lockFile);
Assert.That(_lockFileManager.IsLocked("foo.txt.lock"), Is.True);
Assert.That(_appDataFolder.ListFiles("").Count(), Is.EqualTo(1));
lockFile.Release();
Assert.That(_lockFileManager.IsLocked("foo.txt.lock"), Is.False);
Assert.That(_appDataFolder.ListFiles("").Count(), Is.EqualTo(0));
lockFile.Release();
Assert.That(_lockFileManager.IsLocked("foo.txt.lock"), Is.False);
Assert.That(_appDataFolder.ListFiles("").Count(), Is.EqualTo(0));
}
[Test]
public void DisposingLockShouldReleaseIt() {
ILockFile lockFile = null;
_lockFileManager.TryAcquireLock("foo.txt.lock", ref lockFile);
using (lockFile) {
Assert.That(_lockFileManager.IsLocked("foo.txt.lock"), Is.True);
Assert.That(_appDataFolder.ListFiles("").Count(), Is.EqualTo(1));
}
Assert.That(_lockFileManager.IsLocked("foo.txt.lock"), Is.False);
Assert.That(_appDataFolder.ListFiles("").Count(), Is.EqualTo(0));
}
[Test]
public void ExpiredLockShouldBeAvailable() {
ILockFile lockFile = null;
_lockFileManager.TryAcquireLock("foo.txt.lock", ref lockFile);
_clock.Advance(DefaultLockFileManager.Expiration);
Assert.That(_lockFileManager.IsLocked("foo.txt.lock"), Is.False);
Assert.That(_appDataFolder.ListFiles("").Count(), Is.EqualTo(1));
}
[Test]
public void ShouldGrantExpiredLock() {
ILockFile lockFile = null;
_lockFileManager.TryAcquireLock("foo.txt.lock", ref lockFile);
_clock.Advance(DefaultLockFileManager.Expiration);
var granted = _lockFileManager.TryAcquireLock("foo.txt.lock", ref lockFile);
Assert.That(granted, Is.True);
Assert.That(_appDataFolder.ListFiles("").Count(), Is.EqualTo(1));
}
private static int _lockCount;
private static readonly object _synLock = new object();
[Test]
public void AcquiringLockShouldBeThreadSafe() {
var threads = new List<Thread>();
for(var i=0; i<10; i++) {
var t = new Thread(PlayWithAcquire);
t.Start();
threads.Add(t);
}
threads.ForEach(t => t.Join());
Assert.That(_lockCount, Is.EqualTo(0));
}
[Test]
public void IsLockedShouldBeThreadSafe() {
var threads = new List<Thread>();
for (var i = 0; i < 10; i++)
{
var t = new Thread(PlayWithIsLocked);
t.Start();
threads.Add(t);
}
threads.ForEach(t => t.Join());
Assert.That(_lockCount, Is.EqualTo(0));
}
private void PlayWithAcquire() {
var r = new Random(DateTime.Now.Millisecond);
ILockFile lockFile = null;
// loop until the lock has been acquired
for (;;) {
if (!_lockFileManager.TryAcquireLock("foo.txt.lock", ref lockFile)) {
continue;
}
lock (_synLock) {
_lockCount++;
Assert.That(_lockCount, Is.EqualTo(1));
}
// keep the lock for a certain time
Thread.Sleep(r.Next(200));
lock (_synLock) {
_lockCount--;
Assert.That(_lockCount, Is.EqualTo(0));
}
lockFile.Release();
return;
}
}
private void PlayWithIsLocked() {
var r = new Random(DateTime.Now.Millisecond);
ILockFile lockFile = null;
const string path = "foo.txt.lock";
// loop until the lock has been acquired
for (;;) {
if(_lockFileManager.IsLocked(path)) {
continue;
}
if (!_lockFileManager.TryAcquireLock(path, ref lockFile)) {
continue;
}
lock (_synLock) {
_lockCount++;
Assert.That(_lockCount, Is.EqualTo(1));
}
// keep the lock for a certain time
Thread.Sleep(r.Next(200));
lock (_synLock) {
_lockCount--;
Assert.That(_lockCount, Is.EqualTo(0));
}
lockFile.Release();
return;
}
}
}
}

View File

@@ -1,6 +1,6 @@
using Moq;
using NUnit.Framework;
using Orchard.AspNet.Abstractions;
using Orchard.FileSystems.VirtualPath;
namespace Orchard.Tests.FileSystems.VirtualPath {
[TestFixture]

View File

@@ -9,7 +9,7 @@ using NHibernate;
using NUnit.Framework;
using Orchard.Caching;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Definition;
using Orchard.ContentManagement.MetaData;
using Orchard.Data;
using Orchard.DisplayManagement;
using Orchard.DisplayManagement.Descriptors;

View File

@@ -1,187 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using NUnit.Framework;
using Orchard.Environment.Configuration;
using Orchard.FileSystems.AppData;
using Orchard.Locking;
using Orchard.Tests.Stubs;
namespace Orchard.Tests.Locking {
[TestFixture]
public class LockManagerTests {
private string _tempFolder;
private IAppDataFolder _appDataFolder;
private ILockManager _lockFileManager;
private StubClock _clock;
public class StubAppDataFolderRoot : IAppDataFolderRoot {
public string RootPath { get; set; }
public string RootFolder { get; set; }
}
public static IAppDataFolder CreateAppDataFolder(string tempFolder) {
var folderRoot = new StubAppDataFolderRoot {RootPath = "~/App_Data", RootFolder = tempFolder};
var monitor = new StubVirtualPathMonitor();
return new AppDataFolder(folderRoot, monitor);
}
[SetUp]
public void Init() {
_tempFolder = Path.GetTempFileName();
File.Delete(_tempFolder);
_appDataFolder = CreateAppDataFolder(_tempFolder);
_clock = new StubClock();
_lockFileManager = new DefaultLockManager(_appDataFolder, _clock, new ShellSettings { Name = "Foo" });
}
[TearDown]
public void Term() {
Directory.Delete(_tempFolder, true);
}
private int LockFilesCount() {
return _appDataFolder.ListFiles("Sites/Foo").Where(f => f.EndsWith(".lock")).Count();
}
[Test]
public void LockShouldBeGrantedWhenDoesNotExist() {
var @lock = _lockFileManager.TryLock("foo.txt");
Assert.That(@lock, Is.Not.Null);
Assert.That(_lockFileManager.TryLock("foo.txt"), Is.Null);
Assert.That(LockFilesCount(), Is.EqualTo(1));
}
[Test]
public void ExistingLockFileShouldPreventGrants() {
_lockFileManager.TryLock("foo.txt");
Assert.That(_lockFileManager.TryLock("foo.txt"), Is.Null);
Assert.That(LockFilesCount(), Is.EqualTo(1));
}
[Test]
public void ReleasingALockShouldAllowGranting() {
var @lock = _lockFileManager.TryLock("foo.txt");
using (@lock) {
Assert.That(_lockFileManager.TryLock("foo.txt"), Is.Null);
Assert.That(LockFilesCount(), Is.EqualTo(1));
}
@lock = _lockFileManager.TryLock("foo.txt");
Assert.That(@lock, Is.Not.Null);
@lock.Dispose();
Assert.That(LockFilesCount(), Is.EqualTo(0));
}
[Test]
public void ReleasingAReleasedLockShouldWork() {
var @lock = _lockFileManager.TryLock("foo.txt");
Assert.That(_lockFileManager.TryLock("foo.txt"), Is.Null);
Assert.That(LockFilesCount(), Is.EqualTo(1));
@lock.Dispose();
@lock = _lockFileManager.TryLock("foo.txt");
Assert.That(@lock, Is.Not.Null);
Assert.That(LockFilesCount(), Is.EqualTo(1));
@lock.Dispose();
@lock.Dispose();
@lock = _lockFileManager.TryLock("foo.txt");
Assert.That(@lock, Is.Not.Null);
Assert.That(LockFilesCount(), Is.EqualTo(1));
@lock.Dispose();
Assert.That(LockFilesCount(), Is.EqualTo(0));
}
[Test]
public void DisposingLockShouldReleaseIt() {
var @lock = _lockFileManager.TryLock("foo.txt");
using (@lock) {
Assert.That(_lockFileManager.TryLock("foo.txt"), Is.Null);
Assert.That(LockFilesCount(), Is.EqualTo(1));
}
@lock = _lockFileManager.TryLock("foo.txt");
Assert.That(@lock, Is.Not.Null);
@lock.Dispose();
Assert.That(LockFilesCount(), Is.EqualTo(0));
}
[Test]
public void ExpiredLockShouldBeAvailable() {
_lockFileManager.TryLock("foo.txt");
_clock.Advance(DefaultLockManager.Expiration);
Assert.That(_lockFileManager.TryLock("foo.txt"), Is.Not.Null);
Assert.That(LockFilesCount(), Is.EqualTo(1));
}
[Test]
public void ShouldGrantExpiredLock() {
_lockFileManager.TryLock("foo.txt");
_clock.Advance(DefaultLockManager.Expiration);
var @lock = _lockFileManager.TryLock("foo.txt");
Assert.That(@lock, Is.Not.Null);
Assert.That(LockFilesCount(), Is.EqualTo(1));
}
private static int _lockCount;
private static readonly object _synLock = new object();
[Test]
public void AcquiringLockShouldBeThreadSafe() {
// A number of threads will try to acquire a lock and keep it for
// some random time. Each of them stops when it has acquired the lock once.
var threads = new List<Thread>();
for(var i=0; i<10; i++) {
var t = new Thread(PlayWithAcquire);
t.Start();
threads.Add(t);
}
threads.ForEach(t => t.Join());
Assert.That(_lockCount, Is.EqualTo(0));
}
private void PlayWithAcquire() {
var r = new Random(DateTime.Now.Millisecond);
IDisposable @lock;
// loop until the lock has been acquired
for (;;) {
if (null == (@lock = _lockFileManager.TryLock("foo.txt"))) {
continue;
}
lock (_synLock) {
_lockCount++;
Assert.That(_lockCount, Is.EqualTo(1));
}
// keep the lock for a certain time
Thread.Sleep(r.Next(200));
lock (_synLock) {
_lockCount--;
Assert.That(_lockCount, Is.EqualTo(0));
}
@lock.Dispose();
return;
}
}
}
}

View File

@@ -8,6 +8,118 @@ using System.Collections.Generic;
namespace Orchard.Tests.Mvc.Html {
[TestFixture]
public class HtmlHelperExtensionsTests {
[Test]
public void LinkReturnsIHtmlString() {
//arrange
var viewContext = new ViewContext();
var viewDataContainer = new Mock<IViewDataContainer>();
var html = new HtmlHelper(viewContext, viewDataContainer.Object);
//act
var result = html.Link("test", "http://example.com") as IHtmlString;
//assert
Assert.IsNotNull(result);
}
[Test]
public void LinkHtmlEncodesLinkText() {
//arrange
var viewContext = new ViewContext();
var viewDataContainer = new Mock<IViewDataContainer>();
var html = new HtmlHelper(viewContext, viewDataContainer.Object);
//act
var result = html.Link("<br />", "http://example.com");
//assert
Assert.AreEqual(@"<a href=""http://example.com"">&lt;br /&gt;</a>", result.ToString());
}
[Test]
public void LinkHtmlAttributeEncodesHref() {
//arrange
var viewContext = new ViewContext();
var viewDataContainer = new Mock<IViewDataContainer>();
var html = new HtmlHelper(viewContext, viewDataContainer.Object);
//act
var result = html.Link("test", "<br />");
//assert
Assert.AreEqual(@"<a href=""&lt;br />"">test</a>", result.ToString());
}
[Test]
public void LinkHtmlAttributeEncodesAttributes() {
//arrange
var viewContext = new ViewContext();
var viewDataContainer = new Mock<IViewDataContainer>();
var html = new HtmlHelper(viewContext, viewDataContainer.Object);
//act
var result = html.Link("linkText", "http://example.com", new { title = "<br />" });
//assert
Assert.AreEqual(@"<a href=""http://example.com"" title=""&lt;br />"">linkText</a>", result.ToString());
}
[Test]
public void LinkOrDefaultReturnsIHtmlString() {
//arrange
var viewContext = new ViewContext();
var viewDataContainer = new Mock<IViewDataContainer>();
var html = new HtmlHelper(viewContext, viewDataContainer.Object);
//act
var result = html.LinkOrDefault("test", "http://example.com") as IHtmlString;
//assert
Assert.IsNotNull(result);
}
[Test]
public void LinkOrDefaultHtmlEncodesLinkText() {
//arrange
var viewContext = new ViewContext();
var viewDataContainer = new Mock<IViewDataContainer>();
var html = new HtmlHelper(viewContext, viewDataContainer.Object);
//act
var result = html.LinkOrDefault("<br />", "http://example.com");
//assert
Assert.AreEqual(@"<a href=""http://example.com"">&lt;br /&gt;</a>", result.ToString());
}
[Test]
public void LinkOrDefaultWithoutHrefHtmlEncodesLinkText() {
//arrange
var viewContext = new ViewContext();
var viewDataContainer = new Mock<IViewDataContainer>();
var html = new HtmlHelper(viewContext, viewDataContainer.Object);
//act
var result = html.LinkOrDefault("<br />", null);
//assert
Assert.AreEqual(@"&lt;br /&gt;", result.ToString());
}
[Test]
public void LinkOrDefaultWithHrefHtmlAttributeEncodesHref() {
//arrange
var viewContext = new ViewContext();
var viewDataContainer = new Mock<IViewDataContainer>();
var html = new HtmlHelper(viewContext, viewDataContainer.Object);
//act
var result = html.LinkOrDefault("test", "<br />");
//assert
Assert.AreEqual(@"<a href=""&lt;br />"">test</a>", result.ToString());
}
[Test]
public void SelectOptionHtmlEncodesText() {
//arrange
@@ -21,5 +133,33 @@ namespace Orchard.Tests.Mvc.Html {
//assert
Assert.AreEqual(@"<option value=""value"">&lt;br /&gt;</option>", result.ToString());
}
[Test]
public void UnorderedListWithNullItemsReturnsEmptyHtmlString() {
//arrange
var viewContext = new ViewContext();
var viewDataContainer = new Mock<IViewDataContainer>();
var html = new HtmlHelper(viewContext, viewDataContainer.Object);
//act
var result = html.UnorderedList((IEnumerable<string>)null, (a, b) => MvcHtmlString.Create(""), "test");
//assert
Assert.AreEqual(string.Empty, result.ToString());
}
[Test]
public void UnorderedListWithEmptyItemsReturnsEmptyHtmlString() {
//arrange
var viewContext = new ViewContext();
var viewDataContainer = new Mock<IViewDataContainer>();
var html = new HtmlHelper(viewContext, viewDataContainer.Object);
//act
var result = html.UnorderedList(new string[] { }, (a, b) => MvcHtmlString.Create(""), "test");
//assert
Assert.AreEqual(string.Empty, result.ToString());
}
}
}

View File

@@ -180,9 +180,9 @@
<Compile Include="ContentManagement\Handlers\EpsilonPartHandler.cs" />
<Compile Include="ContentManagement\Handlers\GammaPartHandler.cs" />
<Compile Include="ContentManagement\Handlers\ModelBuilderTests.cs" />
<Compile Include="ContentManagement\Metadata\Builders\ContentTypeDefinitionBuilderTests.cs" />
<Compile Include="ContentManagement\Metadata\Services\ContentDefinitionReaderTests.cs" />
<Compile Include="ContentManagement\Metadata\Services\ContentDefinitionWriterTests.cs" />
<Compile Include="ContentManagement\MetaData\Builders\ContentTypeDefinitionBuilderTests.cs" />
<Compile Include="ContentManagement\MetaData\Services\ContentDefinitionReaderTests.cs" />
<Compile Include="ContentManagement\MetaData\Services\ContentDefinitionWriterTests.cs" />
<Compile Include="ContentManagement\Models\AlphaPart.cs" />
<Compile Include="ContentManagement\Handlers\AlphaPartHandler.cs" />
<Compile Include="ContentManagement\Models\BetaPart.cs" />
@@ -236,7 +236,7 @@
<Compile Include="Environment\DefaultWorkContextAccessorTests.cs" />
<Compile Include="Environment\Extensions\ExtensionLoaderCoordinatorTests.cs" />
<Compile Include="Environment\Features\FeatureManagerTests.cs" />
<Compile Include="Environment\Compilation\Loaders\DynamicExtensionLoaderTests.cs" />
<Compile Include="Environment\Loaders\DynamicExtensionLoaderTests.cs" />
<Compile Include="Environment\State\DefaultProcessingEngineTests.cs" />
<Compile Include="Environment\RunningShellTableTests.cs" />
<Compile Include="Environment\StubHostEnvironment.cs" />
@@ -250,9 +250,9 @@
<Compile Include="Environment\OrchardStarterTests.cs" />
<Compile Include="Environment\ShellBuilders\DefaultShellContainerFactoryTests.cs" />
<Compile Include="Environment\ShellBuilders\DefaultShellContextFactoryTests.cs" />
<Compile Include="Locking\LockManagerTests.cs" />
<Compile Include="Environment\Compilation\Dependencies\AssemblyProbingFolderTests.cs" />
<Compile Include="Environment\Compilation\Dependencies\DependencyDescriptorManagerTests.cs" />
<Compile Include="FileSystems\LockFile\LockFileManagerTests.cs" />
<Compile Include="FileSystems\Dependencies\AssemblyProbingFolderTests.cs" />
<Compile Include="FileSystems\Dependencies\DependenciesFolderTests.cs" />
<Compile Include="FileSystems\VirtualPath\DefaultVirtualPathProviderTests.cs" />
<Compile Include="Localization\CultureManagerTests.cs" />
<Compile Include="Logging\OrchardFileAppenderTests.cs" />
@@ -274,7 +274,6 @@
<Compile Include="Stubs\StubVirtualPathMonitor.cs" />
<Compile Include="Stubs\StubCacheManager.cs" />
<Compile Include="Stubs\StubWebSiteFolder.cs" />
<Compile Include="Time\TimeZoneSelectorTests.cs" />
<Compile Include="UI\Resources\ResourceManagerTests.cs" />
<Compile Include="UI\ShapeTests.cs" />
<Compile Include="Utility\ContainerExtensions.cs" />
@@ -310,6 +309,8 @@
<Compile Include="UI\Navigation\NavigationManagerTests.cs" />
<Compile Include="UI\Navigation\PositionComparerTests.cs" />
<Compile Include="Utility\Extensions\StringExtensionsTests.cs" />
<Compile Include="Utility\ReflectOnTests.cs" />
<Compile Include="Utility\ReflectTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Orchard.Web\Core\Orchard.Core.csproj">

View File

@@ -34,5 +34,5 @@ using System.Runtime.InteropServices;
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0")]
[assembly: AssemblyFileVersion("1.2.0")]
[assembly: AssemblyVersion("1.2.41")]
[assembly: AssemblyFileVersion("1.2.41")]

View File

@@ -6,6 +6,7 @@ using NUnit.Framework;
using Orchard.Environment.Configuration;
using Orchard.Security;
using Orchard.Security.Providers;
using Orchard.Utility.Extensions;
namespace Orchard.Tests.Security {
[TestFixture]

View File

@@ -53,13 +53,5 @@ namespace Orchard.Tests.Stubs {
public IVolatileToken WhenPathChanges(string virtualPath) {
throw new NotImplementedException();
}
public DateTime GetFileLastWriteTimeUtc(string virtualPath) {
throw new NotImplementedException();
}
public bool TryFileExists(string virtualPath) {
throw new NotImplementedException();
}
}
}

View File

@@ -5,7 +5,6 @@ using System.Linq;
using Orchard.Caching;
using Orchard.FileSystems.AppData;
using Orchard.Services;
using Orchard.Time;
namespace Orchard.Tests.Stubs {
public class StubAppDataFolder : IAppDataFolder {
@@ -37,45 +36,77 @@ namespace Orchard.Tests.Stubs {
return entry.Entries.Where(e => e is StubFileSystem.DirectoryEntry).Select(e => Combine(path, e.Name));
}
public bool FileExists(string path) {
return _fileSystem.GetFileEntry(path) != null;
}
public string Combine(params string[] paths) {
return Path.Combine(paths).Replace(Path.DirectorySeparatorChar, '/');
}
public void StoreFile(string path, string content) {
using (var stream = _fileSystem.CreateFile(path)) {
public void CreateFile(string path, string content) {
using (var stream = CreateFile(path)) {
using (var writer = new StreamWriter(stream)) {
writer.Write(content);
}
}
}
public Stream CreateFile(string path) {
return _fileSystem.CreateFile(path);
}
public string ReadFile(string path) {
try {
using (var stream = OpenFile(path)) {
using (var reader = new StreamReader(stream)) {
return reader.ReadToEnd();
}
using (var stream = OpenFile(path)) {
using (var reader = new StreamReader(stream)) {
return reader.ReadToEnd();
}
}
catch (InvalidOperationException) {
return null;
}
}
public Stream OpenFile(string path) {
return _fileSystem.OpenFile(path);
}
public void StoreFile(string sourceFileName, string destinationPath) {
using (var inputStream = File.OpenRead(sourceFileName)) {
using (var outputStream = _fileSystem.CreateFile(destinationPath)) {
byte[] buffer = new byte[1024];
for (; ; ) {
var count = inputStream.Read(buffer, 0, buffer.Length);
if (count == 0)
break;
outputStream.Write(buffer, 0, count);
}
}
}
}
public void DeleteFile(string path) {
_fileSystem.DeleteFile(path);
}
public DateTime GetFileLastWriteTimeUtc(string path) {
var entry = _fileSystem.GetFileEntry(path);
if (entry == null)
throw new ArgumentException();
return entry.LastWriteTimeUtc;
}
public void CreateDirectory(string path) {
_fileSystem.CreateDirectoryEntry(path);
}
public bool DirectoryExists(string path) {
return _fileSystem.GetDirectoryEntry(path) != null;
}
public IVolatileToken WhenPathChanges(string path) {
return _fileSystem.WhenPathChanges(path);
}
public string MapPath(string path) {
return path;
throw new NotImplementedException();
}
public string GetVirtualPath(string path) {

View File

@@ -1,7 +1,6 @@
using System;
using Orchard.Caching;
using Orchard.Services;
using Orchard.Time;
namespace Orchard.Tests.Stubs {
public class StubClock : IClock {

View File

@@ -5,7 +5,6 @@ using System.IO;
using System.Linq;
using Orchard.Caching;
using Orchard.Services;
using Orchard.Time;
namespace Orchard.Tests.Stubs {
public class StubFileSystem {

View File

@@ -1,5 +1,5 @@
using Orchard.AspNet.Abstractions;
using Orchard.Caching;
using Orchard.Caching;
using Orchard.FileSystems.VirtualPath;
namespace Orchard.Tests.Stubs {
public class StubVirtualPathMonitor : IVirtualPathMonitor {

View File

@@ -2,8 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using Orchard.AspNet.Abstractions;
using Orchard.FileSystems.VirtualPath;
namespace Orchard.Tests.Stubs {
public class StubVirtualPathProvider : IVirtualPathProvider {
@@ -111,18 +110,5 @@ namespace Orchard.Tests.Stubs {
return false;
}
}
public string ToAbsolute(string virtualPath) {
throw new NotImplementedException();
}
public bool IsAppRelative(string virtualPath) {
return !string.IsNullOrEmpty(virtualPath) && virtualPath.StartsWith("~");
}
public bool IsAbsolute(string virtualPath) {
return !string.IsNullOrEmpty(virtualPath) && virtualPath.StartsWith("/");
}
}
}

View File

@@ -51,13 +51,5 @@ namespace Orchard.Tests.Stubs {
public class Token : IVolatileToken {
public bool IsCurrent { get; set; }
}
public DateTime GetFileLastWriteTimeUtc(string virtualPath) {
throw new NotImplementedException();
}
public bool TryFileExists(string virtualPath) {
throw new NotImplementedException();
}
}
}

View File

@@ -77,11 +77,6 @@ namespace Orchard.Tests.Stubs {
}
public string BaseUrl { get; set;}
public string SiteTimeZone {
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
}
public class StubUser : IUser {

View File

@@ -1,79 +0,0 @@
using System;
using System.Web;
using Autofac;
using NUnit.Framework;
using Orchard.Time;
namespace Orchard.Tests.Time {
[TestFixture]
public class TimeZoneProviderTests {
private IContainer _container;
private IWorkContextStateProvider _workContextStateProvider;
private TestTimeZoneSelector _timeZoneSelector;
[SetUp]
public void Init() {
var builder = new ContainerBuilder();
builder.RegisterInstance(_timeZoneSelector = new TestTimeZoneSelector()).As<ITimeZoneSelector>();
builder.RegisterType<CurrentTimeZoneWorkContext>().As<IWorkContextStateProvider>();
_container = builder.Build();
_workContextStateProvider = _container.Resolve<IWorkContextStateProvider>();
}
[Test]
public void ShouldProvideCurrentTimeZoneOnly() {
_timeZoneSelector.TimeZone = null;
var timeZone = _workContextStateProvider.Get<TimeZoneInfo>("Foo");
Assert.That(timeZone, Is.Null);
}
[Test]
public void DefaultTimeZoneIsUtc() {
_timeZoneSelector.TimeZone = null;
var timeZone = _workContextStateProvider.Get<TimeZoneInfo>("CurrentTimeZone");
Assert.That(timeZone(new StubWorkContext()), Is.EqualTo(TimeZoneInfo.Utc));
}
[Test]
public void TimeZoneProviderReturnsTimeZoneFromSelector() {
_timeZoneSelector.TimeZone = TimeZoneInfo.Local;
var timeZone = _workContextStateProvider.Get<TimeZoneInfo>("CurrentTimeZone");
Assert.That(timeZone(new StubWorkContext()), Is.EqualTo(TimeZoneInfo.Local));
}
}
public class TestTimeZoneSelector : ITimeZoneSelector {
public TimeZoneInfo TimeZone { get; set; }
public int Priority { get; set; }
public TimeZoneSelectorResult GetTimeZone(HttpContextBase context) {
return new TimeZoneSelectorResult {
Priority = Priority,
TimeZone= TimeZone
};
}
}
public class StubWorkContext : WorkContext {
public override T Resolve<T>() {
throw new NotImplementedException();
}
public override bool TryResolve<T>(out T service) {
throw new NotImplementedException();
}
public override T GetState<T>(string name) {
return default(T);
}
public override void SetState<T>(string name, T value) {
}
}
}

View File

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using NUnit.Framework;
using Orchard.UI;
@@ -11,7 +10,7 @@ namespace Orchard.Tests.UI.Navigation {
[SetUp]
public void Init() {
_comparer = new PositionComparer();
_comparer = new FlatPositionComparer();
}
@@ -24,43 +23,12 @@ namespace Orchard.Tests.UI.Navigation {
Assert.That(greaterThan, Is.GreaterThan(0));
}
[Test]
public void AfterIsAlwaysAfter() {
AssertMore("after", null);
AssertMore("after", "");
AssertMore("after", "0");
AssertMore("after", "-1");
AssertMore("after", "foo");
AssertMore("after", int.MaxValue.ToString());
AssertMore("after", "before");
AssertSame("after", "after");
AssertLess("after", "after.");
AssertLess("after", "after.-10");
AssertLess("after", "after.10");
}
[Test]
public void BeforeIsAlways() {
AssertLess("before", null);
AssertLess("before", "");
AssertLess("before", "0");
AssertLess("before", "-1");
AssertLess("before", "foo");
AssertLess("before", int.MaxValue.ToString());
AssertSame("before", "before");
AssertLess("before", "after");
AssertLess("before", "before.");
AssertLess("before", "before.-10");
AssertLess("before", "before.10");
}
[Test]
public void NullIsLessThanEmptyAndEmptyIsLessThanNonEmpty() {
Assert.That(_comparer.Compare(null, ""), Is.LessThan(0));
Assert.That(_comparer.Compare("", "5"), Is.LessThan(0));
Assert.That(_comparer.Compare(null, "5"), Is.LessThan(0));
Assert.That(_comparer.Compare(null, "0"), Is.LessThan(0));
Assert.That(_comparer.Compare("", null), Is.GreaterThan(0));
Assert.That(_comparer.Compare("5", ""), Is.GreaterThan(0));
@@ -68,7 +36,6 @@ namespace Orchard.Tests.UI.Navigation {
Assert.That(_comparer.Compare(null, null), Is.EqualTo(0));
Assert.That(_comparer.Compare("", ""), Is.EqualTo(0));
Assert.That(_comparer.Compare("", "0"), Is.LessThan(0));
}
[Test]
@@ -120,12 +87,6 @@ namespace Orchard.Tests.UI.Navigation {
[Test]
public void NonNumericValuesCompareOrdinallyAndIgnoreCase() {
AssertLess("a", "c");
AssertLess("1", "x");
AssertLess("10", "x");
AssertLess("10", "bar");
AssertLess(int.MaxValue.ToString(), "bar");
AssertSame("x", "X");
AssertLess("rt675x", "rt685x");
AssertMore("ru675x", "rt675x");
@@ -145,9 +106,6 @@ namespace Orchard.Tests.UI.Navigation {
AssertLess("1.rt675x", "1.rt685x");
AssertMore("1.ru675x", "1.rt675x");
AssertLess("1.rt675x", "1.rt675y");
AssertSame("before", "Before");
AssertSame("after", "After");
}
[Test]
@@ -155,6 +113,7 @@ namespace Orchard.Tests.UI.Navigation {
AssertLess("rt675x", "rt675xx");
}
[Test]
public void EmptyBitsAreSafeAndShouldComeFirst() {
AssertSame("1.2.3", "1.2.3");
@@ -173,111 +132,24 @@ namespace Orchard.Tests.UI.Navigation {
[Test]
public void AdditionalNonEmptySegmentsShouldComeLater() {
AssertLess("1.2", "1.2.3");
AssertLess("1.2", "1.2.");
AssertSame("1.2", "1.2.");
AssertLess("a.b", "a.b.c");
AssertLess("a.b", "a.b.");
AssertSame("a.b", "a.b.");
AssertLess("a.b", "a.b.-1");
AssertLess("a.b", "a.b.before");
AssertLess("a.b", "a.b.after");
}
[Test]
public void AfterShouldReturnGreaterValues() {
AssertMore(PositionComparer.After(null), null);
AssertMore(PositionComparer.After(""), "");
AssertMore(PositionComparer.After("-1"), "-1");
AssertMore(PositionComparer.After("before"), "before");
AssertSame(PositionComparer.After("after"), "after");
AssertMore(PositionComparer.After("42"), "42");
AssertMore(PositionComparer.After("foo"), "foo");
AssertMore(PositionComparer.After("a.b"), "a.b");
AssertMore(PositionComparer.After("1.2"), "1.2");
AssertMore(PositionComparer.After("1."), "1.");
AssertMore(PositionComparer.After("-0"), "-0");
}
[Test]
public void BeforeShouldReturnLowerValues() {
AssertLess(PositionComparer.Before(null), null);
AssertLess(PositionComparer.Before(""), "");
AssertLess(PositionComparer.Before("-1"), "-1");
AssertSame(PositionComparer.Before("before"), "before");
AssertLess(PositionComparer.Before("after"), "after");
AssertLess(PositionComparer.Before("42"), "42");
AssertLess(PositionComparer.Before("foo"), "foo");
AssertLess(PositionComparer.Before("a.b"), "a.b");
AssertLess(PositionComparer.Before("1.2"), "1.2");
AssertLess(PositionComparer.Before("1."), "1.");
AssertLess(PositionComparer.Before("-0"), "-0");
}
[Test]
public void MaxShouldReturnTheGreaterValue() {
Assert.That(PositionComparer.Max("1", "2"), Is.EqualTo("2"));
Assert.That(PositionComparer.Max("a", "c"), Is.EqualTo("c"));
}
[Test]
public void MinShouldReturnTheLowerValue() {
Assert.That(PositionComparer.Min("1", "2"), Is.EqualTo("1"));
Assert.That(PositionComparer.Min("a", "c"), Is.EqualTo("a"));
}
[Test]
public void EqualValuesShouldReturnFirstParameter() {
Assert.That(PositionComparer.Between("1.01", "1.001"), Is.EqualTo("1.01"));
Assert.That(PositionComparer.Between("before", "before"), Is.EqualTo("before"));
Assert.That(PositionComparer.Between("before.1", "before.1"), Is.EqualTo("before.1"));
}
[Test]
public void ShouldComputeAverageValues() {
Assert.That(PositionComparer.Between("1", "3"), Is.EqualTo("2"));
Assert.That(PositionComparer.Between("-5", "0005"), Is.EqualTo("0"));
AssertBetween("a", "c");
AssertBetween("-10", "10");
AssertBetween("foo", "bar");
AssertBetween("-10", "bar");
AssertBetween("10", "bar");
AssertBetween("10", "before");
AssertBetween("10", "after");
AssertBetween("after", "before");
// adjacent cases
AssertBetween("1", "2");
AssertBetween("1.1", "1.2");
AssertBetween("ae", "bb");
}
[DebuggerStepThrough]
void AssertLess(string x, string y) {
Assert.That(_comparer.Compare(x, y), Is.LessThan(0));
Assert.That(_comparer.Compare(y, x), Is.GreaterThan(0));
}
[DebuggerStepThrough]
void AssertMore(string x, string y) {
Assert.That(_comparer.Compare(x, y), Is.GreaterThan(0));
Assert.That(_comparer.Compare(y, x), Is.LessThan(0));
}
[DebuggerStepThrough]
void AssertSame(string x, string y) {
Assert.That(_comparer.Compare(x, y), Is.EqualTo(0));
Assert.That(_comparer.Compare(y, x), Is.EqualTo(0));
}
void AssertBetween(string x, string y) {
var min = PositionComparer.Min(x, y);
var max = PositionComparer.Max(x, y);
var mean = PositionComparer.Between(x, y);
AssertLess(mean, max);
AssertMore(mean, min);
}
}
}

View File

@@ -3,7 +3,6 @@ using System.Linq;
using System.Collections.Generic;
using Autofac;
using NUnit.Framework;
using Orchard.AspNet.Abstractions;
using Orchard.DisplayManagement.Implementation;
using Orchard.Tests.Stubs;
using Orchard.UI.Admin;
@@ -43,8 +42,6 @@ namespace Orchard.Tests.UI.Resources {
var builder = new ContainerBuilder();
builder.RegisterType<ResourceManager>().As<IResourceManager>();
builder.RegisterType<TestManifestProvider>().As<IResourceManifestProvider>().SingleInstance();
var stubVpp = new StubVirtualPathProvider(null);
builder.RegisterInstance(stubVpp).As<IVirtualPathProvider>();
_container = builder.Build();
_resourceManager = _container.Resolve<IResourceManager>();
_testManifest = _container.Resolve<IResourceManifestProvider>() as TestManifestProvider;

View File

@@ -69,7 +69,7 @@ namespace Orchard.Tests.Utility.Extensions {
}
[Test]
public void HtmlClassify_SimpleStringReturnsSimpleClassName() {
const string toClassify = ".this is something";
const string toClassify = "this is something";
Assert.That(toClassify.HtmlClassify(), Is.StringMatching("this-is-something"));
}
[Test]
@@ -145,5 +145,26 @@ namespace Orchard.Tests.Utility.Extensions {
const string fullOfTags = null;
Assert.That(fullOfTags.RemoveTags(), Is.StringMatching(""));
}
[Test]
public void ReplaceNewLinesWith_ReplaceCRLFWithHtmlBR() {
const string lotsOfLineFeeds = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\r\nMaecenas sed purus quis purus orci aliquam.";
Assert.That(lotsOfLineFeeds.ReplaceNewLinesWith("<br />"), Is.StringMatching("Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br />Maecenas sed purus quis purus orci aliquam."));
}
[Test]
public void ReplaceNewLinesWith_ReplaceCRLFWithHtmlPsAndCRLF() {
const string lotsOfLineFeeds = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\r\nMaecenas sed purus quis purus orci aliquam.";
Assert.That(lotsOfLineFeeds.ReplaceNewLinesWith(@"</p>$1<p>"), Is.StringMatching("Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>\r\n<p>Maecenas sed purus quis purus orci aliquam."));
}
[Test]
public void ReplaceNewLinesWith_EmptyStringReturnsEmptyString() {
const string lotsOfLineFeeds = "";
Assert.That(lotsOfLineFeeds.ReplaceNewLinesWith("<br />"), Is.StringMatching(""));
}
[Test]
public void ReplaceNewLinesWith_NullValueReturnsEmptyString() {
const string lotsOfLineFeeds = null;
Assert.That(lotsOfLineFeeds.ReplaceNewLinesWith("<br />"), Is.StringMatching(""));
}
}
}

View File

@@ -0,0 +1,62 @@
using NUnit.Framework;
using Orchard.Utility;
namespace Orchard.Tests.Utility {
[TestFixture]
public class ReflectOnTests {
private class TestClass {
public int MyField;
public int MyField2;
public int MyProperty { get { MyField = 5; return MyField; } }
public int MyProperty2 { get { MyField2 = 5; return MyField2; } }
public void MyMethod(int i) { }
public int MyMethod(string s) { return 5; }
public void MyMethod2(int i) { }
public int MyMethod2(string s) { return 5; }
public TestClass MyTestClass { get { return null; } }
public TestClass this[int i] { get { return null; } }
}
[Test]
public void ReflectOnGetMemberShouldReturnCorrectMemberInfo() {
Assert.That(ReflectOn<TestClass>.GetMember(p => p.MyField).Name, Is.EqualTo("MyField"));
Assert.That(ReflectOn<TestClass>.GetMember(p => p.MyMethod(5)).Name, Is.EqualTo("MyMethod"));
}
[Test]
public void ReflectOnShouldWorkOnFields() {
Assert.That(ReflectOn<TestClass>.GetField(p => p.MyField).Name, Is.EqualTo("MyField"));
Assert.That(ReflectOn<TestClass>.GetField(p => p.MyField2).Name, Is.EqualTo("MyField2"));
}
[Test]
public void ReflectOnShouldWorkOnProperties() {
Assert.That(ReflectOn<TestClass>.GetProperty(p => p.MyProperty).Name, Is.EqualTo("MyProperty"));
Assert.That(ReflectOn<TestClass>.GetProperty(p => p.MyProperty2).Name, Is.EqualTo("MyProperty2"));
}
[Test]
public void ReflectOnShouldWorkOnMethods() {
Assert.That(ReflectOn<TestClass>.GetMethod(p => p.MyMethod(5)).Name, Is.EqualTo("MyMethod"));
Assert.That(ReflectOn<TestClass>.GetMethod(p => p.MyMethod("")).Name, Is.EqualTo("MyMethod"));
Assert.That(ReflectOn<TestClass>.GetMethod(p => p.MyMethod("")).ReturnType, Is.EqualTo(typeof(int)));
Assert.That(ReflectOn<TestClass>.GetMethod(p => p.MyMethod2(5)).Name, Is.EqualTo("MyMethod2"));
Assert.That(ReflectOn<TestClass>.GetMethod(p => p.MyMethod2("")).Name, Is.EqualTo("MyMethod2"));
Assert.That(ReflectOn<TestClass>.GetMethod(p => p.MyMethod2("")).ReturnType, Is.EqualTo(typeof(int)));
}
[Test]
public void ReflectOnShouldWorkOnDottedProperties() {
Assert.That(ReflectOn<TestClass>.NameOf(p => p.MyTestClass.MyTestClass.MyProperty), Is.EqualTo("MyTestClass.MyTestClass.MyProperty"));
}
[Test]
public void ReflectOnShouldWorkOnIndexers() {
Assert.That(ReflectOn<TestClass>.NameOf(p => p[0].MyTestClass[1].MyProperty), Is.EqualTo("[0].MyTestClass[1].MyProperty"));
int j = 5;
int index = j;
Assert.That(ReflectOn<TestClass>.NameOf(p => p.MyTestClass[index].MyProperty), Is.EqualTo("MyTestClass[5].MyProperty"));
}
}
}

View File

@@ -0,0 +1,47 @@
using NUnit.Framework;
using Orchard.Utility;
namespace Orchard.Tests.Utility {
[TestFixture]
public class ReflectTests {
private class TestClass {
public static int MyField;
public static int MyField2;
public static int MyProperty { get { MyField = 5; return MyField; } }
public static int MyProperty2 { get { MyField2 = 5; return MyField2; } }
public static void MyMethod(int i) { }
public static int MyMethod(string s) { return 5; }
public static void MyMethod2(int i) { }
public static int MyMethod2(string s) { return 5; }
}
[Test]
public void ReflectGetMemberShouldReturnCorrectMemberInfo() {
Assert.That(Reflect.GetMember(() => TestClass.MyField).Name, Is.EqualTo("MyField"));
Assert.That(Reflect.GetMember(() => TestClass.MyMethod(5)).Name, Is.EqualTo("MyMethod"));
}
[Test]
public void ReflectShouldWorkOnFields() {
Assert.That(Reflect.GetField(() => TestClass.MyField).Name, Is.EqualTo("MyField"));
Assert.That(Reflect.GetField(() => TestClass.MyField2).Name, Is.EqualTo("MyField2"));
}
[Test]
public void ReflectShouldWorkOnProperties() {
Assert.That(Reflect.GetProperty(() => TestClass.MyProperty).Name, Is.EqualTo("MyProperty"));
Assert.That(Reflect.GetProperty(() => TestClass.MyProperty2).Name, Is.EqualTo("MyProperty2"));
}
[Test]
public void ReflectShouldWorkOnMethods() {
Assert.That(Reflect.GetMethod(() => TestClass.MyMethod(5)).Name, Is.EqualTo("MyMethod"));
Assert.That(Reflect.GetMethod(() => TestClass.MyMethod("")).Name, Is.EqualTo("MyMethod"));
Assert.That(Reflect.GetMethod(() => TestClass.MyMethod("")).ReturnType, Is.EqualTo(typeof(int)));
Assert.That(Reflect.GetMethod(() => TestClass.MyMethod2(5)).Name, Is.EqualTo("MyMethod2"));
Assert.That(Reflect.GetMethod(() => TestClass.MyMethod2("")).Name, Is.EqualTo("MyMethod2"));
Assert.That(Reflect.GetMethod(() => TestClass.MyMethod2("")).ReturnType, Is.EqualTo(typeof(int)));
}
}
}

View File

@@ -33,5 +33,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("1.2.0")]
[assembly: AssemblyFileVersion("1.2.0")]
[assembly: AssemblyVersion("1.2.41")]
[assembly: AssemblyFileVersion("1.2.41")]

View File

@@ -1,7 +1,9 @@
using JetBrains.Annotations;
using Orchard.Core.Common.Models;
using Orchard.ContentManagement.Handlers;
namespace Orchard.Core.Common.DateEditor {
[UsedImplicitly]
public class DateEditorHandler : ContentHandler {
public DateEditorHandler() {
OnPublished<CommonPart>((context, part) => {

View File

@@ -1,8 +1,8 @@
using System.Collections.Generic;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Definition;
using Orchard.ContentManagement.Definition.Builders;
using Orchard.ContentManagement.Definition.Models;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Builders;
using Orchard.ContentManagement.MetaData.Models;
using Orchard.ContentManagement.ViewModels;
namespace Orchard.Core.Common.DateEditor {

View File

@@ -1,9 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using JetBrains.Annotations;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Parts;
using Orchard.ContentManagement.Aspects;
using Orchard.ContentManagement.Drivers;
using Orchard.Core.Common.Models;
using Orchard.Core.Common.Settings;
@@ -12,6 +12,7 @@ using Orchard.Core.Routable.Models;
using Orchard.Services;
namespace Orchard.Core.Common.Drivers {
[UsedImplicitly]
public class BodyPartDriver : ContentPartDriver<BodyPart> {
private readonly IEnumerable<IHtmlFilter> _htmlFilters;
@@ -71,7 +72,8 @@ namespace Orchard.Core.Common.Drivers {
private static BodyEditorViewModel BuildEditorViewModel(BodyPart part) {
return new BodyEditorViewModel {
BodyPart = part,
EditorFlavor = GetFlavor(part)
EditorFlavor = GetFlavor(part),
AddMediaPath = new PathBuilder(part).AddContentType().AddContainerSlug().AddSlug().ToString()
};
}
@@ -81,5 +83,55 @@ namespace Orchard.Core.Common.Drivers {
? typePartSettings.Flavor
: part.PartDefinition.Settings.GetModel<BodyPartSettings>().FlavorDefault;
}
class PathBuilder {
private readonly IContent _content;
private string _path;
public PathBuilder(IContent content) {
_content = content;
_path = "";
}
public override string ToString() {
return _path;
}
public PathBuilder AddContentType() {
Add(_content.ContentItem.ContentType);
return this;
}
public PathBuilder AddContainerSlug() {
var common = _content.As<ICommonPart>();
if (common == null)
return this;
var routable = common.Container.As<RoutePart>();
if (routable == null)
return this;
Add(routable.Slug);
return this;
}
public PathBuilder AddSlug() {
var routable = _content.As<RoutePart>();
if (routable == null)
return this;
Add(routable.Slug);
return this;
}
private void Add(string segment) {
if (string.IsNullOrEmpty(segment))
return;
if (string.IsNullOrEmpty(_path))
_path = segment;
else
_path = _path + "/" + segment;
}
}
}
}

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