- Cleaning up/refactoring/removing some obsolete classes/flagged code.

--HG--
branch : dev
This commit is contained in:
Suha Can
2010-10-18 14:56:17 -07:00
parent c9b2e70563
commit 92916c66dd
30 changed files with 8 additions and 1346 deletions

View File

@@ -1,296 +0,0 @@
using System;
using System.IO;
using System.Linq;
using Autofac;
using Lucene.Services;
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 {
public class LuceneIndexProviderTests {
private IContainer _container;
private IIndexProvider _provider;
private IAppDataFolder _appDataFolder;
private ShellSettings _shellSettings;
private readonly string _basePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
[TestFixtureTearDown]
public void Clean() {
if (Directory.Exists(_basePath)) {
Directory.Delete(_basePath, true);
}
}
[SetUp]
public void Setup() {
if (Directory.Exists(_basePath)) {
Directory.Delete(_basePath, true);
}
Directory.CreateDirectory(_basePath);
_appDataFolder = AppDataFolderTests.CreateAppDataFolder(_basePath);
var builder = new ContainerBuilder();
builder.RegisterType<LuceneIndexProvider>().As<IIndexProvider>();
builder.RegisterInstance(_appDataFolder).As<IAppDataFolder>();
// setting up a ShellSettings instance
_shellSettings = new ShellSettings { Name = "My Site" };
builder.RegisterInstance(_shellSettings).As<ShellSettings>();
_container = builder.Build();
_provider = _container.Resolve<IIndexProvider>();
}
private string[] Indexes() {
return new DirectoryInfo(Path.Combine(_basePath, "Sites", "My Site", "Indexes")).GetDirectories().Select(d => d.Name).ToArray();
}
[Test]
public void IndexProviderShouldCreateNewIndex() {
Assert.That(Indexes().Length, Is.EqualTo(0));
_provider.CreateIndex("default");
Assert.That(Indexes().Length, Is.EqualTo(1));
}
[Test]
public void IndexProviderShouldOverwriteAlreadyExistingIndex() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("body", null));
Assert.That(_provider.IsEmpty("default"), Is.False);
_provider.CreateIndex("default");
Assert.That(_provider.IsEmpty("default"), Is.True);
}
[Test]
public void IndexProviderShouldDeleteExistingIndex() {
Assert.That(Indexes().Length, Is.EqualTo(0));
_provider.CreateIndex("default");
Assert.That(Indexes().Length, Is.EqualTo(1));
_provider.DeleteIndex("default");
Assert.That(Indexes().Length, Is.EqualTo(0));
}
[Test]
public void IndexProviderShouldListExistingIndexes() {
Assert.That(Indexes().Length, Is.EqualTo(0));
_provider.CreateIndex("default");
Assert.That(Indexes().Length, Is.EqualTo(1));
Assert.That(Indexes()[0], Is.EqualTo("default"));
_provider.CreateIndex("foo");
Assert.That(Indexes().Length, Is.EqualTo(2));
}
[Test]
public void ANewIndexShouldBeEmpty() {
_provider.CreateIndex("default");
var searchBuilder = _provider.CreateSearchBuilder("default");
var hits = searchBuilder.Search();
Assert.That(hits.Count(), Is.EqualTo(0));
}
[Test]
public void DocumentsShouldBeSearchableById() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(42));
var searchBuilder = _provider.CreateSearchBuilder("default");
var hit = searchBuilder.Get(42);
Assert.IsNotNull(hit);
Assert.That(hit.ContentItemId, Is.EqualTo(42));
hit = searchBuilder.Get(1);
Assert.IsNull(hit);
}
[Test]
public void PropertiesShouldNotBeLost() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(42).Add("prop1", "value1").Store());
var hit = _provider.CreateSearchBuilder("default").Get(42);
Assert.IsNotNull(hit);
Assert.That(hit.ContentItemId, Is.EqualTo(42));
Assert.That(hit.GetString("prop1"), Is.EqualTo("value1"));
}
[Test]
public void ShouldHandleMultipleIndexes() {
_provider.CreateIndex("default1");
_provider.Store("default1", _provider.New(1));
_provider.CreateIndex("default2");
_provider.Store("default2", _provider.New(2));
_provider.CreateIndex("default3");
_provider.Store("default3", _provider.New(3));
Assert.IsNotNull(_provider.CreateSearchBuilder("default1").Get(1));
Assert.IsNotNull(_provider.CreateSearchBuilder("default2").Get(2));
Assert.IsNotNull(_provider.CreateSearchBuilder("default3").Get(3));
Assert.IsNull(_provider.CreateSearchBuilder("default1").Get(2));
Assert.IsNull(_provider.CreateSearchBuilder("default2").Get(3));
Assert.IsNull(_provider.CreateSearchBuilder("default3").Get(1));
}
[Test]
public void IdentifierShouldNotCollide() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("field", "value1"));
_provider.Store("default", _provider.New(11).Add("field", "value11"));
_provider.Store("default", _provider.New(111).Add("field", "value111"));
var searchBuilder = _provider.CreateSearchBuilder("default");
Assert.That(searchBuilder.Get(1).ContentItemId, Is.EqualTo(1));
Assert.That(searchBuilder.Get(11).ContentItemId, Is.EqualTo(11));
Assert.That(searchBuilder.Get(111).ContentItemId, Is.EqualTo(111));
}
[Test]
public void TagsShouldBeRemoved() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("body", "<hr>some content</hr>").Analyze());
_provider.Store("default", _provider.New(2).Add("body", "<hr>some content</hr>").RemoveTags().Analyze());
var searchBuilder = _provider.CreateSearchBuilder("default");
Assert.That(searchBuilder.WithField("body", "hr").Search().Count(), Is.EqualTo(1));
Assert.That(searchBuilder.WithField("body", "hr").Search().First().ContentItemId, Is.EqualTo(1));
}
[Test] public void ShouldAllowNullOrEmptyStrings() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("body", null));
_provider.Store("default", _provider.New(2).Add("body", ""));
_provider.Store("default", _provider.New(3).Add("body", "<hr></hr>").RemoveTags());
var searchBuilder = _provider.CreateSearchBuilder("default");
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]
public void ProviderShouldStoreSettings() {
_provider.CreateIndex("default");
Assert.That(_provider.GetLastIndexUtc("default"), Is.Null);
_provider.SetLastIndexUtc("default", new DateTime(2010, 1, 1, 1, 1, 1, 1));
Assert.That(_provider.GetLastIndexUtc("default"), Is.EqualTo(new DateTime(2010, 1, 1, 1, 1, 1, 0)));
_provider.SetLastIndexUtc("default", new DateTime(1901, 1, 1, 1, 1, 1, 1));
Assert.That(_provider.GetLastIndexUtc("default"), Is.EqualTo(LuceneIndexProvider.DefaultMinDateTime));
}
[Test]
public void IsEmptyShouldBeTrueForNoneExistingIndexes() {
_provider.IsEmpty("dummy");
Assert.That(_provider.IsEmpty("default"), Is.True);
}
[Test]
public void IsEmptyShouldBeTrueForJustNewIndexes() {
_provider.CreateIndex("default");
Assert.That(_provider.IsEmpty("default"), Is.True);
}
[Test]
public void IsEmptyShouldBeFalseWhenThereIsADocument() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("body", null));
Assert.That(_provider.IsEmpty("default"), Is.False);
}
[Test]
public void IsDirtyShouldBeFalseForNewDocuments() {
IDocumentIndex doc = _provider.New(1);
Assert.That(doc.IsDirty, Is.False);
}
[Test]
public void IsDirtyShouldBeTrueWhenIndexIsModified() {
IDocumentIndex doc;
doc = _provider.New(1);
doc.Add("foo", "value");
Assert.That(doc.IsDirty, Is.True);
doc = _provider.New(1);
doc.Add("foo", false);
Assert.That(doc.IsDirty, Is.True);
doc = _provider.New(1);
doc.Add("foo", (float)1.0);
Assert.That(doc.IsDirty, Is.True);
doc = _provider.New(1);
doc.Add("foo", 1);
Assert.That(doc.IsDirty, Is.True);
doc = _provider.New(1);
doc.Add("foo", DateTime.Now);
Assert.That(doc.IsDirty, Is.True);
}
[Test]
public void DocumentsShouldBeDeleted() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("field", "value1"));
_provider.Store("default", _provider.New(11).Add("field", "value11"));
_provider.Store("default", _provider.New(111).Add("field", "value111"));
var searchBuilder = _provider.CreateSearchBuilder("default");
Assert.That(searchBuilder.Get(1).ContentItemId, Is.EqualTo(1));
Assert.That(searchBuilder.Get(11).ContentItemId, Is.EqualTo(11));
Assert.That(searchBuilder.Get(111).ContentItemId, Is.EqualTo(111));
_provider.Delete("default", 1);
Assert.That(searchBuilder.Get(1), Is.Null);
Assert.That(searchBuilder.Get(11).ContentItemId, Is.EqualTo(11));
Assert.That(searchBuilder.Get(111).ContentItemId, Is.EqualTo(111));
_provider.Delete("default", new int[] {1, 11, 111 });
Assert.That(searchBuilder.Get(1), Is.Null);
Assert.That(searchBuilder.Get(11), Is.Null);
Assert.That(searchBuilder.Get(111), Is.Null);
}
[Test]
public void SameContentItemShouldNotBeIndexedTwice() {
_provider.CreateIndex("default");
var searchBuilder = _provider.CreateSearchBuilder("default");
_provider.Store("default", _provider.New(1).Add("field", "value1"));
Assert.That(searchBuilder.WithField("id", "1").Count(), Is.EqualTo(1));
_provider.Store("default", _provider.New(1).Add("field", "value2"));
Assert.That(searchBuilder.WithField("id", "1").Count(), Is.EqualTo(1));
}
}
}

View File

@@ -1,312 +0,0 @@
using System;
using System.IO;
using System.Linq;
using Autofac;
using Lucene.Services;
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 {
public class LuceneSearchBuilderTests {
private IContainer _container;
private IIndexProvider _provider;
private IAppDataFolder _appDataFolder;
private ShellSettings _shellSettings;
private readonly string _basePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
[TestFixtureTearDown]
public void Clean() {
if (Directory.Exists(_basePath)) {
Directory.Delete(_basePath, true);
}
}
[SetUp]
public void Setup() {
if (Directory.Exists(_basePath)) {
Directory.Delete(_basePath, true);
}
Directory.CreateDirectory(_basePath);
_appDataFolder = AppDataFolderTests.CreateAppDataFolder(_basePath);
var builder = new ContainerBuilder();
builder.RegisterType<LuceneIndexProvider>().As<IIndexProvider>();
builder.RegisterInstance(_appDataFolder).As<IAppDataFolder>();
// setting up a ShellSettings instance
_shellSettings = new ShellSettings { Name = "My Site" };
builder.RegisterInstance(_shellSettings).As<ShellSettings>();
_container = builder.Build();
_provider = _container.Resolve<IIndexProvider>();
}
private ISearchBuilder _searchBuilder { get { return _provider.CreateSearchBuilder("default"); } }
[Test]
public void SearchTermsShouldBeFoundInMultipleFields() {
_provider.CreateIndex("default");
_provider.Store("default",
_provider.New(42)
.Add("title", "title1 title2 title3").Analyze()
.Add("date", new DateTime(2010, 05, 28, 14, 13, 56, 123))
);
Assert.IsNotNull(_provider.CreateSearchBuilder("default").Get(42));
Assert.IsNotNull(_provider.CreateSearchBuilder("default").WithField("title", "title1").Search().FirstOrDefault());
Assert.IsNotNull(_provider.CreateSearchBuilder("default").WithField("title", "title2").Search().FirstOrDefault());
Assert.IsNotNull(_provider.CreateSearchBuilder("default").WithField("title", "title3").Search().FirstOrDefault());
Assert.IsNull(_provider.CreateSearchBuilder("default").WithField("title", "title4").Search().FirstOrDefault());
}
[Test]
public void ShouldSearchById() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1));
_provider.Store("default", _provider.New(2));
_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));
}
[Test]
public void ShouldSearchWithField() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("title", "cat"));
_provider.Store("default", _provider.New(2).Add("title", "dog"));
_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);
}
[Test]
public void ShouldCountResultsOnly() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("title", "cat"));
_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));
}
[Test]
public void ShouldFilterByDate() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("date", new DateTime(2010, 05, 28, 12, 30, 15)));
_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));
}
[Test]
public void ShouldSliceResults() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1));
_provider.Store("default", _provider.New(22));
_provider.Store("default", _provider.New(333));
_provider.Store("default", _provider.New(4444));
_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));
// 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));
}
[Test]
public void ShouldSortByRelevance() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("body", "michael is in the kitchen").Analyze());
_provider.Store("default", _provider.New(2).Add("body", "michael as a cousin named michel").Analyze());
_provider.Store("default", _provider.New(3).Add("body", "speak inside the mic").Analyze());
_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();
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();
Assert.That(michael.Count(), Is.EqualTo(2));
Assert.That(michael[0].Score >= michael[1].Score, Is.True);
}
[Test]
public void ShouldSortByDate() {
_provider.CreateIndex("default");
_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.SortBy("date").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);
date = _searchBuilder.SortBy("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 ShouldEscapeSpecialChars() {
_provider.CreateIndex("default");
_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();
Assert.That(cs.Count(), Is.EqualTo(2));
var cpp = _searchBuilder.Parse("body", "C++").Search().ToList();
Assert.That(cpp.Count(), Is.EqualTo(2));
}
[Test]
public void ShouldHandleMandatoryFields() {
_provider.CreateIndex("default");
_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));
}
[Test]
public void ShouldHandleForbiddenFields() {
_provider.CreateIndex("default");
_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));
}
[Test]
public void ShouldHandleWeight() {
_provider.CreateIndex("default");
_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));
}
[Test]
public void ShouldParseLuceneQueries() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("body", "Bradley is in the kitchen.").Analyze().Add("title", "Beer and takos").Analyze());
_provider.Store("default", _provider.New(2).Add("body", "Renaud is also in the kitchen.").Analyze().Add("title", "A love affair").Analyze());
_provider.Store("default", _provider.New(3).Add("body", "Bertrand is a little bit jealous.").Analyze().Add("title", "Soap opera").Analyze());
Assert.That(_searchBuilder.Parse(new[] { "body" }, "kitchen").Count(), Is.EqualTo(2));
Assert.That(_searchBuilder.Parse(new[] { "body" }, "kitchen bertrand").Count(), Is.EqualTo(3));
Assert.That(_searchBuilder.Parse(new[] { "body" }, "kitchen +bertrand").Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.Parse(new[] { "body" }, "+kitchen +bertrand").Count(), Is.EqualTo(0));
Assert.That(_searchBuilder.Parse(new[] { "body" }, "kit").Count(), Is.EqualTo(0));
Assert.That(_searchBuilder.Parse(new[] { "body" }, "kit*").Count(), Is.EqualTo(2));
Assert.That(_searchBuilder.Parse(new[] { "body", "title" }, "bradley love^3 soap").Count(), Is.EqualTo(3));
Assert.That(_searchBuilder.Parse(new[] { "body", "title" }, "bradley love^3 soap").Search().First().ContentItemId, Is.EqualTo(2));
}
[Test]
public void ShouldFilterIntValues() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("field", 1));
_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", 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]
public void ShouldFilterStoredIntValues() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("field", 1).Store());
_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", 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]
public void ShouldProvideAvailableFields() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("a", "Home").Analyze());
_provider.Store("default", _provider.New(2).Add("b", DateTime.Now).Store());
_provider.Store("default", _provider.New(3).Add("c", 333));
Assert.That(_provider.GetFields("default").Count(), Is.EqualTo(4));
Assert.That(_provider.GetFields("default").OrderBy(s => s).ToArray(), Is.EqualTo(new [] { "a", "b", "c", "id"}));
}
[Test]
public void FiltersShouldNotAlterResults() {
_provider.CreateIndex("default");
_provider.Store("default", _provider.New(1).Add("body", "Orchard has been developped by Mirosoft in C#").Analyze().Add("culture", 1033));
_provider.Store("default", _provider.New(2).Add("body", "Windows a été développé par Mirosoft en C++").Analyze().Add("culture", 1036));
_provider.Store("default", _provider.New(3).Add("title", "Home").Analyze().Add("culture", 1033));
Assert.That(_searchBuilder.WithField("body", "Mirosoft").Count(), Is.EqualTo(2));
Assert.That(_searchBuilder.WithField("body", "Mirosoft").WithField("culture", 1033).Count(), Is.EqualTo(3));
Assert.That(_searchBuilder.WithField("body", "Mirosoft").WithField("culture", 1033).AsFilter().Count(), Is.EqualTo(1));
Assert.That(_searchBuilder.WithField("body", "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("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));
}
}
}

View File

@@ -1,6 +1,4 @@
#if REFACTORING
#error This must move to the Modules tests to accomodate Orchard.Experimental assembly reference
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
@@ -12,13 +10,13 @@ using Autofac.Features.Metadata;
using NHibernate;
using NUnit.Framework;
using Orchard.Caching;
using Orchard.CodeGeneration.Services;
using Orchard.ContentManagement.Records;
using Orchard.Data;
using Orchard.Data.Conventions;
using Orchard.Data.Migration.Generator;
using Orchard.Data.Migration.Interpreters;
using Orchard.Data.Migration.Schema;
using Orchard.DevTools.Services;
using Orchard.Environment.Configuration;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Folders;
@@ -30,10 +28,10 @@ using Orchard.FileSystems.AppData;
using Orchard.FileSystems.Dependencies;
using Orchard.Tests.ContentManagement;
using Orchard.Data.Providers;
using Orchard.Tests.DataMigration.Orchard.Tests.DataMigration.Records;
using Orchard.Tests.FileSystems.AppData;
using Orchard.Tests.Modules.Migrations.Orchard.Tests.DataMigration.Records;
namespace Orchard.Tests.DataMigration {
namespace Orchard.Tests.Modules.Migrations {
[TestFixture]
public class SchemaCommandGeneratorTests {
private IContainer _container;
@@ -217,7 +215,7 @@ Features:
Assert.That(commands.Count(), Is.EqualTo(3));
var sw = new StringWriter();
var interpreter = new ScaffoldingCommandInterpreter(sw);
var interpreter = new CodeGenerationCommandInterpreter(sw);
var blogRecord = commands.Where(c => c.Name == "TEST_Feature1_BlogRecord").First();
var blogArchiveRecord = commands.Where(c => c.Name == "TEST_Feature1_BlogArchiveRecord").First();
@@ -273,4 +271,3 @@ Features:
}
}
}
#endif

View File

@@ -97,6 +97,7 @@
<HintPath>..\..\lib\nunit\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
@@ -128,6 +129,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Roles\Controllers\AdminControllerTests.cs" />
<Compile Include="Roles\Services\RoleServiceTests.cs" />
<Compile Include="Migrations\SchemaCommandGeneratorTests.cs" />
<Compile Include="Settings\Blueprint\ShellDescriptorManagerTests.cs" />
<Compile Include="Themes\Services\ThemeServiceTests.cs" />
<Compile Include="Values.cs" />
@@ -198,9 +200,7 @@
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Folder Include="Indexing\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View File

@@ -201,7 +201,6 @@
<Compile Include="ContentManagement\Records\GammaRecord.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="DataMigration\SchemaCommandGeneratorTests.cs" />
<Compile Include="DataMigration\SchemaBuilderTests.cs" />
<Compile Include="DataMigration\DataMigrationTests.cs" />
<Compile Include="DataMigration\Utilities\NullInterpreter.cs" />

View File

@@ -43,46 +43,6 @@ namespace Orchard.Tests.UI.Navigation {
var main = GetNavigationManager().Object.BuildMenu("main");
Assert.That(main.Count(), Is.EqualTo(1));
}
#if REFACTORING
[Test]
public void MainMenuShouldBeCalledNormally() {
Mock<INavigationManager> navigationManager = GetNavigationManager();
var authorizationContext = GetAuthorizationContext<NormalController>();
var adminFilter = new AdminFilter(GetAuthorizer(true));
adminFilter.OnAuthorization(authorizationContext);
var viewModel = new BaseViewModel();
var resultExecutingContext = new ResultExecutingContext(
authorizationContext,
new ViewResult { ViewData = new ViewDataDictionary<BaseViewModel>(viewModel) });
var menuFilter = new MenuFilter(navigationManager.Object);
menuFilter.OnResultExecuting(resultExecutingContext);
Assert.That(viewModel.Menu, Is.Not.Null);
Assert.That(viewModel.Menu.Single().Text, Is.SameAs("The Main Menu"));
}
[Test]
public void AdminMenuShouldHaveDifferentNavigation() {
Mock<INavigationManager> navigationManager = GetNavigationManager();
var authorizationContext = GetAuthorizationContext<AdminController>();
var adminFilter = new AdminFilter(GetAuthorizer(true));
adminFilter.OnAuthorization(authorizationContext);
var viewModel = new BaseViewModel();
var resultExecutingContext = new ResultExecutingContext(
authorizationContext,
new ViewResult { ViewData = new ViewDataDictionary<BaseViewModel>(viewModel) });
var menuFilter = new MenuFilter(navigationManager.Object);
menuFilter.OnResultExecuting(resultExecutingContext);
Assert.That(viewModel.Menu, Is.Not.Null);
Assert.That(viewModel.Menu.Single().Text, Is.SameAs("The Admin Menu"));
}
#endif
}

View File

@@ -2,9 +2,7 @@
using System.Web.Routing;
using Moq;
using NUnit.Framework;
using Orchard.Localization;
using Orchard.Tests.Stubs;
using Orchard.UI.Notify;
namespace Orchard.Tests.UI.Notify {
[TestFixture]
@@ -17,72 +15,5 @@ namespace Orchard.Tests.UI.Notify {
var actionDescriptor = new Mock<ActionDescriptor>().Object;
return new ActionExecutedContext(controllerContext, actionDescriptor, false/*cancelled*/, null/*exception*/);
}
#if REFACTORING
[Test]
public void AfterActionExecutedMessagesShouldAppearInTempData() {
var sink = new Notifier();
var filter = new NotifyFilter(sink);
var T = NullLocalizer.Instance;
sink.Information(T("Hello world"));
var executedContext = BuildContext();
filter.OnActionExecuted(executedContext);
Assert.That(executedContext.Controller.TempData.ContainsKey("messages"));
Assert.That(executedContext.Controller.TempData["messages"], Is.StringContaining("Hello world"));
}
[Test]
public void ExistingTempDataIsntModified() {
var sink = new Notifier();
var filter = new NotifyFilter(sink);
var executedContext = BuildContext();
executedContext.Controller.TempData.Add("messages", "dont-destroy");
filter.OnActionExecuted(executedContext);
Assert.That(executedContext.Controller.TempData["messages"], Is.EqualTo("dont-destroy"));
}
[Test]
public void NewMessagesAreConcatinated() {
var sink = new Notifier();
var filter = new NotifyFilter(sink);
var T = NullLocalizer.Instance;
sink.Error(T("Boom"));
var executedContext = BuildContext();
executedContext.Controller.TempData.Add("messages", "dont-destroy");
filter.OnActionExecuted(executedContext);
Assert.That(executedContext.Controller.TempData["messages"], Is.StringContaining("dont-destroy"));
Assert.That(executedContext.Controller.TempData["messages"], Is.StringContaining("dont-destroy"));
}
[Test]
public void TempDataBuildsMessagesWhenResultExecutingIsBaseViewModel() {
var sink = new Notifier();
var filter = new NotifyFilter(sink);
var T = NullLocalizer.Instance;
sink.Information(T("Working"));
var model = new BaseViewModel();
var context = BuildContext();
context.Controller.TempData.Add("messages", "dont-destroy" + System.Environment.NewLine + "-" + System.Environment.NewLine);
context.Result = new ViewResult {
ViewData = new ViewDataDictionary<BaseViewModel>(model),
TempData = context.Controller.TempData
};
filter.OnActionExecuted(context);
filter.OnResultExecuting(new ResultExecutingContext(context, context.Result));
Assert.That(model.Messages, Is.Not.Null);
Assert.That(model.Messages, Has.Count.EqualTo(2));
Assert.That(model.Messages, Has.Some.Property("Message").EqualTo(T("dont-destroy")));
Assert.That(model.Messages, Has.Some.Property("Message").EqualTo(T("Working")));
}
#endif
}
}

View File

@@ -16,20 +16,7 @@ namespace Orchard.Experimental.ViewModels {
public IEnumerable<TemplateViewModel> Editors {
get {
#if REFACTORING
return EditorModel.Zones
.SelectMany(z => z.Value.Items
.OfType<ContentPartEditorZoneItem>()
.Select(x => new { ZoneName = z.Key, Item = x }))
.Select(x => new TemplateViewModel(x.Item.Model, x.Item.Prefix) {
Model = x.Item.Model,
TemplateName = x.Item.TemplateName,
WasUsed = x.Item.WasExecuted,
ZoneName = x.ZoneName,
});
#else
return new List<TemplateViewModel>();
#endif
}
}

View File

@@ -1,87 +0,0 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web.Mvc.Html;
using Orchard.Environment.Descriptor;
using Orchard.Localization;
using Orchard.Security;
using Orchard.Services;
using Orchard.UI.Zones;
namespace Orchard.Themes.DesignerNotes {
#if REFACTORING
public class ZoneManagerEvents : IZoneManagerEvents {
private readonly IThemeService _themeService;
private readonly IAuthorizationService _authorizationService;
private readonly IShellDescriptorManager _shellDescriptorManager;
private readonly IEnumerable<IHtmlFilter> _htmlFilters;
public ZoneManagerEvents(IThemeService themeService,
IAuthorizationService authorizationService,
IShellDescriptorManager shellDescriptorManager,
IEnumerable<IHtmlFilter> htmlFilters) {
_themeService = themeService;
_authorizationService = authorizationService;
_shellDescriptorManager = shellDescriptorManager;
_htmlFilters = htmlFilters;
T = NullLocalizer.Instance;
}
public virtual IUser CurrentUser { get; set; }
public Localizer T { get; set; }
public void ZoneRendering(ZoneRenderContext context) {
if (context.RenderingItems.Any())
return;
var requestContext = context.Html.ViewContext.RequestContext;
var theme = _themeService.GetRequestTheme(requestContext);
var virtualPath = "~/Themes/" + theme.ThemeName + "/Zones/" + context.ZoneName + ".html";
var physicalPath = requestContext.HttpContext.Server.MapPath(virtualPath);
if (!File.Exists(physicalPath))
return;
var accessAdminPanel = _authorizationService.TryCheckAccess(
StandardPermissions.AccessAdminPanel, CurrentUser, null);
if (accessAdminPanel) {
//Temporary: Don't show "edit" button if "Orchard.Widgets" is not enabled.
accessAdminPanel = _shellDescriptorManager
.GetShellDescriptor()
.Features
.Any(f => f.Name == "Orchard.Widgets");
}
var writer = context.Html.ViewContext.Writer;
if (accessAdminPanel) {
writer.Write("<div class=\"managewrapper\"><div class=\"manage\">");
writer.Write(context.Html.ActionLink(T("Edit").ToString(), "AddWidget", new {
Area = "Orchard.Widgets",
Controller = "Admin",
context.ZoneName,
theme.ThemeName,
ReturnUrl = requestContext.HttpContext.Request.RawUrl,
}));
writer.Write("</div>");
}
var fileText = _htmlFilters
.Aggregate(File.ReadAllText(physicalPath), (text, filter) => filter.ProcessContent(text));
writer.Write(fileText);
if (accessAdminPanel) {
writer.Write("</div>");
}
}
public void ZoneItemRendering(ZoneRenderContext context, ZoneItem item) {
}
public void ZoneItemRendered(ZoneRenderContext context, ZoneItem item) {
}
public void ZoneRendered(ZoneRenderContext context) {
}
}
#endif
}

View File

@@ -74,7 +74,6 @@
<Compile Include="ResourceManifest.cs" />
<Compile Include="Controllers\AdminController.cs" />
<Compile Include="Migrations.cs" />
<Compile Include="DesignerNotes\ZoneManagerEvents.cs" />
<Compile Include="Handlers\ThemeSiteSettingsPartHandler.cs" />
<Compile Include="Models\Theme.cs" />
<Compile Include="Models\ThemeSiteSettingsPart.cs" />
@@ -88,7 +87,6 @@
<Compile Include="Services\SafeModeThemeSelector.cs" />
<Compile Include="Services\SiteThemeSelector.cs" />
<Compile Include="Services\ThemeService.cs" />
<Compile Include="Services\ThemeZoneManagerEvents.cs" />
<Compile Include="ViewModels\ThemesIndexViewModel.cs" />
</ItemGroup>
<ItemGroup>

View File

@@ -1,52 +0,0 @@
using Orchard.Localization;
using Orchard.UI.Zones;
namespace Orchard.Themes.Services {
#if REFACTORING
public class ThemeZoneManagerEvents : IZoneManagerEvents {
public ThemeZoneManagerEvents() {
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
public void ZoneRendering(ZoneRenderContext context) {
#if DEBUG
context.Html.ViewContext.Writer.WriteLine(T("<!-- begin zone: {0} -->", LocalizedString.TextOrDefault(context.ZoneName, T("etc. (ZonesAny)"))));
#endif
}
public void ZoneItemRendering(ZoneRenderContext context, ZoneItem item) {
#if DEBUG
//info: doesn't cover all ZoneItem types
var writer = context.Html.ViewContext.Writer;
if (item is RenderPartialZoneItem)
writer.WriteLine(T("<!-- begin: {0} -->", (item as RenderPartialZoneItem).TemplateName));
else if (item is ContentPartDisplayZoneItem)
writer.WriteLine(T("<!-- begin: {0} -->", (item as ContentPartDisplayZoneItem).TemplateName));
else if (item is ContentPartEditorZoneItem)
writer.WriteLine(T("<!-- begin: {0} -->", (item as ContentPartEditorZoneItem).TemplateName));
#endif
}
public void ZoneItemRendered(ZoneRenderContext context, ZoneItem item) {
#if DEBUG
//info: doesn't cover all ZoneItem types
var writer = context.Html.ViewContext.Writer;
if (item is RenderPartialZoneItem)
writer.WriteLine(T("<!-- end: {0} -->", (item as RenderPartialZoneItem).TemplateName));
else if (item is ContentPartDisplayZoneItem)
writer.WriteLine(T("<!-- end: {0} -->", (item as ContentPartDisplayZoneItem).TemplateName));
else if (item is ContentPartEditorZoneItem)
writer.WriteLine(T("<!-- end: {0} -->", (item as ContentPartEditorZoneItem).TemplateName));
#endif
}
public void ZoneRendered(ZoneRenderContext context) {
#if DEBUG
context.Html.ViewContext.Writer.WriteLine(T("<!-- end zone: {0} -->", LocalizedString.TextOrDefault(context.ZoneName, T("etc. (ZonesAny)"))));
#endif
}
}
#endif
}

View File

@@ -11,36 +11,9 @@ namespace Orchard.ContentManagement.Drivers {
public string TemplateName { get; set; }
public override void Apply(BuildDisplayContext context) {
#if REFACTORING
//todo: (heskew)evaluate - for lack of having access to the full context in a driver to conditionally return results (e.g. BlogDriver item display is otherwise being overriden by the ContentPartDriver)
if (!string.IsNullOrWhiteSpace(context.ViewModel.TemplateName)
&& context.ViewModel.GetType() != typeof(ContentItemViewModel<TContent>))
return;
context.ViewModel.TemplateName = TemplateName;
if (context.ViewModel.GetType() != typeof(ContentItemViewModel<TContent>)) {
context.ViewModel.Adaptor = (html, viewModel) => {
return new HtmlHelper<ContentItemViewModel<TContent>>(
html.ViewContext,
new ViewDataContainer { ViewData = new ViewDataDictionary(new ContentItemViewModel<TContent>(viewModel)) },
html.RouteCollection);
};
}
#endif
}
public override void Apply(BuildEditorContext context) {
#if REFACTORING
context.ViewModel.TemplateName = TemplateName;
if (context.ViewModel.GetType() != typeof(ContentItemViewModel<TContent>)) {
context.ViewModel.Adaptor = (html, viewModel) => {
return new HtmlHelper<ContentItemViewModel<TContent>>(
html.ViewContext,
new ViewDataContainer { ViewData = new ViewDataDictionary(new ContentItemViewModel<TContent>(viewModel)) },
html.RouteCollection);
};
}
#endif
}
class ViewDataContainer : IViewDataContainer {

View File

@@ -22,23 +22,6 @@ namespace Orchard.ContentManagement.Handlers {
}
protected override void BuildDisplayShape(BuildDisplayContext context, TContent instance) {
#if REFACTORING
context.ViewModel.TemplateName = _templateName;
var longestMatch = LongestMatch(context.DisplayType);
if (!string.IsNullOrEmpty(longestMatch))
context.ViewModel.TemplateName += "." + longestMatch;
context.ViewModel.Prefix = _prefix;
if (context.ViewModel.GetType() != typeof(ContentItemViewModel<TContent>)) {
context.ViewModel.Adaptor = (html, viewModel) => {
return new HtmlHelper<ContentItemViewModel<TContent>>(
html.ViewContext,
new ViewDataContainer { ViewData = new ViewDataDictionary(new ContentItemViewModel<TContent>(viewModel)) },
html.RouteCollection);
};
}
#endif
}
class ViewDataContainer : IViewDataContainer {
@@ -56,29 +39,9 @@ namespace Orchard.ContentManagement.Handlers {
}
protected override void BuildEditorShape(BuildEditorContext context, TContent instance) {
#if REFACTORING
context.ViewModel.TemplateName = _templateName;
context.ViewModel.Prefix = _prefix;
if (context.ViewModel.GetType() != typeof(ContentItemViewModel<TContent>)) {
context.ViewModel.Adaptor = (html, viewModel) => {
return new HtmlHelper<ContentItemViewModel<TContent>>(
html.ViewContext,
new ViewDataContainer { ViewData = new ViewDataDictionary(new ContentItemViewModel<TContent>(viewModel)) },
html.RouteCollection);
};
}
#endif
}
protected override void UpdateEditorShape(UpdateEditorContext context, TContent instance) {
#if REFACTORING
if (context.ViewModel is ContentItemViewModel<TContent>)
_updater(context, (ContentItemViewModel<TContent>)context.ViewModel);
else
_updater(context, new ContentItemViewModel<TContent>(context.ViewModel));
context.ViewModel.TemplateName = _templateName;
context.ViewModel.Prefix = _prefix;
#endif
}
public void Updater(Action<UpdateEditorContext, IContent> updater) {

View File

@@ -30,49 +30,6 @@ namespace Orchard.Mvc.ViewEngines.ThemeAwareness {
}
viewResultBase.ViewEngineCollection = new ViewEngineCollection(new[] { _layoutAwareViewEngine });
#if REFACTORING
var viewResultBase = filterContext.Result as ViewResultBase;
if (viewResultBase == null) {
return;
}
//TODO: factor out into a service apart from the filter
//TODO: add layout engine first
var requestTheme = _themeService.GetRequestTheme(filterContext.RequestContext);
var themeViewEngines = Enumerable.Empty<IViewEngine>();
// todo: refactor. also this will probably result in the "SafeMode" theme being used so dump some debug info
// into the context for the theme to use for displaying why the expected theme isn't being used
if (requestTheme != null) {
var themeLocation = _extensionManager.GetThemeLocation(requestTheme);
themeViewEngines = _viewEngineProviders
.Select(x => x.CreateThemeViewEngine(new CreateThemeViewEngineParams { VirtualPath = themeLocation }));
//Logger.Debug("Theme location:\r\n\t-{0}", themeLocation);
}
var modules = _extensionManager.AvailableExtensions()
.Where(x => x.ExtensionType == "Module");
var moduleLocations = modules.Select(x => Path.Combine(x.Location, x.Name));
var moduleViewEngines = _viewEngineProviders
.Select(x => x.CreateModulesViewEngine(new CreateModulesViewEngineParams { VirtualPaths = moduleLocations }));
//Logger.Debug("Module locations:\r\n\t-{0}", string.Join("\r\n\t-", moduleLocations.ToArray()));
var requestViewEngines = new ViewEngineCollection(
themeViewEngines
.Concat(moduleViewEngines)
.Concat(_viewEngines.Where(ViewEngineIsForwarded))
.ToArray());
var layoutViewEngine = new LayoutViewEngine(requestViewEngines);
viewResultBase.ViewEngineCollection = new ViewEngineCollection(_viewEngines.ToList());
viewResultBase.ViewEngineCollection.Insert(0, layoutViewEngine);
#endif
}
public void OnResultExecuted(ResultExecutedContext filterContext) {

View File

@@ -769,16 +769,6 @@
<Compile Include="UI\Resources\LinkEntry.cs" />
<Compile Include="UI\Resources\ResourceFilter.cs" />
<Compile Include="UI\Resources\ResourceManager.cs" />
<Compile Include="UI\Zones\Obsolete\DelegateZoneItem.cs" />
<Compile Include="UI\Zones\Obsolete\IZoneManager.cs" />
<Compile Include="UI\Zones\Obsolete\ContentPartDisplayZoneItem.cs" />
<Compile Include="UI\Zones\Obsolete\ContentPartEditorZoneItem.cs" />
<Compile Include="UI\Zones\Obsolete\IZoneManagerEvents.cs" />
<Compile Include="UI\Zones\Obsolete\RenderActionZoneItem.cs" />
<Compile Include="UI\Zones\Obsolete\RenderPartialZoneItem.cs" />
<Compile Include="UI\Zones\Obsolete\RenderStaticZoneItem.cs" />
<Compile Include="UI\Zones\Obsolete\ZoneEntry.cs" />
<Compile Include="UI\Zones\Obsolete\ZoneItem.cs" />
<Compile Include="Mvc\ViewPage.cs">
<SubType>ASPXCodeBehind</SubType>
</Compile>
@@ -820,7 +810,6 @@
<Compile Include="FileSystems\Media\IStorageFile.cs" />
<Compile Include="FileSystems\Media\IStorageFolder.cs" />
<Compile Include="FileSystems\Media\IStorageProvider.cs" />
<Compile Include="UI\Zones\Obsolete\ZoneManager.cs" />
<Compile Include="Utility\Extensions\ReadOnlyCollectionExtensions.cs" />
<Compile Include="Utility\Extensions\RouteValueDictionaryExtensions.cs" />
<Compile Include="Utility\Extensions\StringExtensions.cs" />

View File

@@ -12,8 +12,6 @@ namespace Orchard.Security {
public ILogger Logger { get; set; }
#if REFACTORING
#endif
public void OnException(ExceptionContext filterContext) {
if (!(filterContext.Exception is OrchardSecurityException))
return;

View File

@@ -15,13 +15,6 @@ namespace Orchard.Themes {
public void OnActionExecuted(ActionExecutedContext filterContext) {}
public void OnResultExecuting(ResultExecutingContext filterContext) {
#if REFACTORING
var viewResult = filterContext.Result as ViewResult;
if (viewResult == null)
return;
Apply(filterContext.RequestContext);
#endif
}
public void OnResultExecuted(ResultExecutedContext filterContext) {}

View File

@@ -1,16 +0,0 @@
using System.Web.Mvc;
using Orchard.Mvc.Html;
using Orchard.Mvc.ViewModels;
namespace Orchard.UI.Zones {
#if REFACTORING
public class ContentItemDisplayZoneItem : ZoneItem {
public ContentItemViewModel ViewModel { get; set; }
public override void Execute<TModel>(HtmlHelper<TModel> html) {
var htmlString = html.DisplayForItem(ViewModel);
html.ViewContext.Writer.Write(htmlString);
}
}
#endif
}

View File

@@ -1,17 +0,0 @@
using System.Web.Mvc;
using System.Web.Mvc.Html;
namespace Orchard.UI.Zones {
#if REFACTORING
public class ContentPartDisplayZoneItem : ZoneItem {
public object Model { get; set; }
public string TemplateName { get; set; }
public string Prefix { get; set; }
public override void Execute<TModel>(HtmlHelper<TModel> html) {
var htmlString = html.DisplayFor(m => Model, TemplateName, Prefix);
html.ViewContext.Writer.Write(htmlString);
}
}
#endif
}

View File

@@ -1,17 +0,0 @@
using System.Web.Mvc;
using System.Web.Mvc.Html;
namespace Orchard.UI.Zones {
#if REFACTORING
public class ContentPartEditorZoneItem : ZoneItem {
public object Model { get; set; }
public string TemplateName { get; set; }
public string Prefix { get; set; }
public override void Execute<TModel>(HtmlHelper<TModel> html) {
html.ViewContext.Writer.Write(
html.EditorFor(m => Model, TemplateName, Prefix));
}
}
#endif
}

View File

@@ -1,14 +0,0 @@
using System;
using System.Web.Mvc;
namespace Orchard.UI.Zones {
#if REFACTORING
public class DelegateZoneItem : ZoneItem {
public Action<HtmlHelper> Action { get; set; }
public override void Execute<TModel>(HtmlHelper<TModel> html) {
Action(html);
}
}
#endif
}

View File

@@ -1,9 +0,0 @@
using System.Web.Mvc;
namespace Orchard.UI.Zones {
#if REFACTORING
public interface IZoneManager : IDependency {
void Render<TModel>(HtmlHelper<TModel> html, ZoneCollection zones, string zoneName, string partitions, string[] except);
}
#endif
}

View File

@@ -1,20 +0,0 @@
using System.Collections.Generic;
using System.Web.Mvc;
using Orchard.Events;
namespace Orchard.UI.Zones {
#if REFACTORING
public interface IZoneManagerEvents : IEventHandler {
void ZoneRendering(ZoneRenderContext context);
void ZoneItemRendering(ZoneRenderContext context, ZoneItem item);
void ZoneItemRendered(ZoneRenderContext context, ZoneItem item);
void ZoneRendered(ZoneRenderContext context);
}
public class ZoneRenderContext {
public HtmlHelper Html { get; set; }
public ZoneCollection Zones { get; set; }
public string ZoneName { get; set; }
public IEnumerable<ZoneItem> RenderingItems { get; set; }
}
#endif
}

View File

@@ -1,15 +0,0 @@
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Web.Routing;
namespace Orchard.UI.Zones {
public class RenderActionZoneItem : ZoneItem {
public string ActionName { get; set; }
public string ControllerName { get; set; }
public RouteValueDictionary RouteValues { get; set; }
public override void Execute<TModel>(HtmlHelper<TModel> html) {
html.RenderAction(ActionName, ControllerName, RouteValues);
}
}
}

View File

@@ -1,13 +0,0 @@
using System.Web.Mvc;
using System.Web.Mvc.Html;
namespace Orchard.UI.Zones {
public class RenderPartialZoneItem : ZoneItem {
public object Model { get; set; }
public string TemplateName { get; set; }
public override void Execute<TModel>(HtmlHelper<TModel> html) {
html.RenderPartial(TemplateName, Model);
}
}
}

View File

@@ -1,13 +0,0 @@
using System.Web.Mvc;
using System.Web.Mvc.Html;
namespace Orchard.UI.Zones {
public class RenderStaticZoneItem : ZoneItem {
public object Model { get; set; }
public string TemplateName { get; set; }
public override void Execute<TModel>(HtmlHelper<TModel> html) {
html.RenderPartial(TemplateName, Model);
}
}
}

View File

@@ -1,81 +0,0 @@
using System;
using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Routing;
using Orchard.Mvc.ViewModels;
namespace Orchard.UI.Zones {
#if REFACTORING
public interface IZoneContainer {
ZoneCollection Zones { get; }
}
public class ZoneCollection : Dictionary<string, ZoneEntry> {
public void AddAction(string location, Action<HtmlHelper> action) {
AddZoneItem(location, new DelegateZoneItem { Action = action });
}
public void AddRenderPartial(string location, string templateName, object model) {
AddZoneItem(location, new RenderPartialZoneItem { Model = model, TemplateName = templateName });
}
public void AddRenderStatic(string location, string templateName, object model) {
AddZoneItem(location, new RenderStaticZoneItem { Model = model, TemplateName = templateName });
}
public void AddDisplayItem(string location, ContentItemViewModel viewModel) {
AddZoneItem(location, new ContentItemDisplayZoneItem { ViewModel = viewModel });
}
public void AddDisplayPart(string location, object model, string templateName, string prefix) {
AddZoneItem(location, new ContentPartDisplayZoneItem { Model = model, TemplateName = templateName, Prefix = prefix });
}
public void AddEditorPart(string location, object model, string templateName, string prefix) {
AddZoneItem(location, new ContentPartEditorZoneItem { Model = model, TemplateName = templateName, Prefix = prefix });
}
public void AddRenderAction(string location, string actionName) {
AddZoneItem(location, new RenderActionZoneItem { ActionName = actionName });
}
public void AddRenderAction(string location, string actionName, object routeValues) {
AddZoneItem(location, new RenderActionZoneItem { ActionName = actionName, RouteValues = new RouteValueDictionary(routeValues) });
}
public void AddRenderAction(string location, string actionName, RouteValueDictionary routeValues) {
AddZoneItem(location, new RenderActionZoneItem { ActionName = actionName, RouteValues = routeValues });
}
public void AddRenderAction(string location, string actionName, string controllerName) {
AddZoneItem(location, new RenderActionZoneItem { ActionName = actionName, ControllerName = controllerName });
}
public void AddRenderAction(string location, string actionName, string controllerName, object routeValues) {
AddZoneItem(location, new RenderActionZoneItem { ActionName = actionName, ControllerName = controllerName, RouteValues = new RouteValueDictionary(routeValues) });
}
public void AddRenderAction(string location, string actionName, string controllerName, RouteValueDictionary routeValues) {
AddZoneItem(location, new RenderActionZoneItem { ActionName = actionName, ControllerName = controllerName, RouteValues = routeValues });
}
private void AddZoneItem(string location, ZoneItem item) {
string zoneName;
var position = string.Empty;
var colonIndex = location.IndexOf(':');
if (colonIndex == -1) {
zoneName = location.Trim();
}
else {
zoneName = location.Substring(0, colonIndex).Trim();
position = location.Substring(colonIndex + 1).Trim();
}
item.Position = position;
ZoneEntry entry;
if (TryGetValue(zoneName, out entry)) {
entry.Items.Add(item);
}
else {
entry = new ZoneEntry { ZoneName = zoneName, Items = new List<ZoneItem>() };
Add(zoneName, entry);
entry.Items.Add(item);
}
}
}
#endif
}

View File

@@ -1,12 +0,0 @@
using System.Collections.Generic;
namespace Orchard.UI.Zones {
public class ZoneEntry {
public ZoneEntry() {
Items = new List<ZoneItem>();
}
public string ZoneName { get; set; }
public IList<ZoneItem> Items { get; set; }
}
}

View File

@@ -1,10 +0,0 @@
using System.Web.Mvc;
namespace Orchard.UI.Zones {
public abstract class ZoneItem {
public string Position { get; set; }
public bool WasExecuted { get; set; }
public abstract void Execute<TModel>(HtmlHelper<TModel> html);
}
}

View File

@@ -1,99 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Orchard.Logging;
using Orchard.UI.Navigation;
namespace Orchard.UI.Zones {
#if REFACTORING
public class ZoneManager : IZoneManager {
private readonly IEnumerable<IZoneManagerEvents> _zoneManagerEventHandler;
public ZoneManager(IEnumerable<IZoneManagerEvents> eventHandler) {
_zoneManagerEventHandler = eventHandler;
Logger = NullLogger.Instance;
}
public void Render<TModel>(HtmlHelper<TModel> html, ZoneCollection zones, string zoneName, string partitions, string[] exclude) {
IEnumerable<Group> groups;
if (string.IsNullOrEmpty(zoneName)) {
var entries = zones.Values.Where(z => !exclude.Contains(z.ZoneName));
groups = BuildGroups(partitions, entries);
}
else {
ZoneEntry entry;
if (zones.TryGetValue(zoneName, out entry)) {
groups = BuildGroups(partitions, new[] { entry });
}
else {
groups = Enumerable.Empty<Group>();
}
}
var context = new ZoneRenderContext {
Html = html,
Zones = zones,
ZoneName = zoneName,
RenderingItems = groups.SelectMany(x => x.Items).ToList()
};
foreach (var zoneManagerEventHandler in _zoneManagerEventHandler) {
zoneManagerEventHandler.ZoneRendering(context);
}
foreach (var item in context.RenderingItems) {
var zoneItem = item;
foreach (var zoneManagerEventHandler in _zoneManagerEventHandler) {
zoneManagerEventHandler.ZoneItemRendering(context, zoneItem);
}
zoneItem.WasExecuted = true;
zoneItem.Execute(html);
foreach (var zoneManagerEventHandler in _zoneManagerEventHandler) {
zoneManagerEventHandler.ZoneItemRendered(context, zoneItem);
}
}
foreach (var zoneManagerEventHandler in _zoneManagerEventHandler) {
zoneManagerEventHandler.ZoneRendered(context);
}
}
protected ILogger Logger { get; set; }
private IEnumerable<Group> BuildGroups(string partitions, IEnumerable<ZoneEntry> zones) {
var partitionCodes = (":before " + partitions + " :* :after").Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
var itemsRemaining = zones.SelectMany(zone => zone.Items.Where(x => x.WasExecuted == false));
Group catchAllItem = null;
var positionComparer = new PositionComparer();
var results = new List<Group>();
foreach (var code in partitionCodes) {
if (code == ":*") {
catchAllItem = new Group();
results.Add(catchAllItem);
}
else {
var value = code;
var items = itemsRemaining
.Where(x => (":" + x.Position).StartsWith(value))
.OrderBy(x => x.Position, positionComparer);
results.Add(new Group { Items = items.ToArray() });
itemsRemaining = itemsRemaining.Except(items).ToArray();
}
}
if (catchAllItem != null) {
catchAllItem.Items = itemsRemaining
.OrderBy(x => x.Position, positionComparer)
.ToArray();
}
return results;
}
class Group {
public IEnumerable<ZoneItem> Items { get; set; }
}
}
#endif
}