using System; 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.MetaData; using Orchard.ContentManagement.Records; using Orchard.Core.Common.Handlers; using Orchard.Core.Common.Models; using Orchard.Data; using Orchard.DisplayManagement; using Orchard.DisplayManagement.Descriptors; using Orchard.DisplayManagement.Implementation; using Orchard.Environment; using Orchard.Environment.Extensions; using Orchard.Security; using Orchard.Tests.Modules; using Orchard.Tests.Stubs; using Orchard.UI.Notify; namespace Orchard.Core.Tests.Body { [TestFixture] public class BodyPartTests : DatabaseEnabledTestsBase { public override void Register(ContainerBuilder builder) { builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterInstance(new Mock().Object); builder.RegisterInstance(new Mock().Object); builder.RegisterInstance(new Mock().Object); builder.RegisterInstance(new Mock().Object); builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterType().As(); } [Test] public void BodyCanHandleLongText() { var contentManager = _container.Resolve(); contentManager.Create(ThingDriver.ContentTypeName, t => { t.As().Record = new BodyPartRecord(); t.Text = new String('x', 10000); }); var bodies = contentManager.Query().List(); Assert.That(bodies, Is.Not.Null); Assert.That(bodies.Any(), Is.True); Assert.That(bodies.First().Text, Is.EqualTo(new String('x', 10000))); } protected override IEnumerable DatabaseTypes { get { return new[] { typeof(BodyPartRecord), typeof(ContentTypeRecord), typeof(ContentItemRecord), typeof(ContentItemVersionRecord), typeof(CommonPartRecord), typeof(CommonPartVersionRecord), }; } } [UsedImplicitly] public class ThingHandler : ContentHandler { public ThingHandler() { Filters.Add(new ActivatingFilter(ThingDriver.ContentTypeName)); Filters.Add(new ActivatingFilter>(ThingDriver.ContentTypeName)); Filters.Add(new ActivatingFilter(ThingDriver.ContentTypeName)); Filters.Add(new ActivatingFilter(ThingDriver.ContentTypeName)); } } public class Thing : ContentPart { public string Text { get { return this.As().Text; } set { this.As().Text = value; } } } public class ThingDriver : ContentPartDriver { public static readonly string ContentTypeName = "thing"; } } }