2009-11-18 22:19:54 +00:00
|
|
|
using NUnit.Framework;
|
|
|
|
using Orchard.Models;
|
|
|
|
using Orchard.Models.Driver;
|
|
|
|
|
|
|
|
namespace Orchard.Tests.Models.Drivers {
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
public class ModelDriverTests {
|
|
|
|
[Test]
|
|
|
|
public void ModelDriverShouldUsePersistenceFilterToDelegateCreateAndLoad() {
|
2009-11-19 05:40:38 +00:00
|
|
|
var modelDriver = new TestModelHandler();
|
2009-11-18 22:19:54 +00:00
|
|
|
|
2009-11-19 05:17:02 +00:00
|
|
|
var contentItem = new ContentItem();
|
2009-11-18 22:19:54 +00:00
|
|
|
var part = new TestModelPart();
|
2009-11-19 05:17:02 +00:00
|
|
|
contentItem.Weld(part);
|
|
|
|
|
2009-11-19 05:31:39 +00:00
|
|
|
((IContentHandler)modelDriver).Creating(new CreateContentContext { ContentItem = contentItem });
|
2009-11-18 22:19:54 +00:00
|
|
|
Assert.That(part.CreatingCalled, Is.True);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void PartShouldBeAddedBasedOnSimplePredicate() {
|
2009-11-19 05:40:38 +00:00
|
|
|
var modelDriver = new TestModelHandler();
|
2009-11-18 22:19:54 +00:00
|
|
|
|
2009-11-19 05:17:02 +00:00
|
|
|
var builder = new ContentItemBuilder("testing");
|
2009-11-19 05:31:39 +00:00
|
|
|
((IContentHandler)modelDriver).Activating(new ActivatingContentContext { Builder = builder, ContentType = "testing" });
|
2009-11-18 22:19:54 +00:00
|
|
|
var model = builder.Build();
|
|
|
|
Assert.That(model.Is<TestModelPart>(), Is.True);
|
|
|
|
Assert.That(model.As<TestModelPart>(), Is.Not.Null);
|
|
|
|
}
|
|
|
|
|
2009-11-19 05:17:02 +00:00
|
|
|
public class TestModelPart : ContentItemPart {
|
2009-11-18 22:19:54 +00:00
|
|
|
public bool CreatingCalled { get; set; }
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-19 05:40:38 +00:00
|
|
|
public class TestModelHandler : ContentHandler {
|
|
|
|
public TestModelHandler() {
|
2009-11-18 22:19:54 +00:00
|
|
|
Filters.Add(new ActivatingFilter<TestModelPart>(x => x == "testing"));
|
|
|
|
Filters.Add(new TestModelStorageFilter());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class TestModelStorageFilter : StorageFilterBase<TestModelPart> {
|
2009-11-19 05:31:39 +00:00
|
|
|
protected override void Creating(CreateContentContext context, TestModelPart instance) {
|
2009-11-18 22:19:54 +00:00
|
|
|
instance.CreatingCalled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|