mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Fix unit tests
--HG-- branch : dev
This commit is contained in:
@@ -16,7 +16,7 @@ namespace Orchard.Specs.Bindings {
|
||||
var webApp = Binding<WebAppHosting>();
|
||||
|
||||
webApp.GivenIHaveACleanSiteWith(TableData(
|
||||
new { extension = "module", names = "Orchard.Setup, Orchard.Modules, Orchard.Themes, Orchard.Users, Orchard.Roles, Orchard.Pages, Orchard.Comments, TinyMce" },
|
||||
new { extension = "module", names = "Orchard.Setup, Orchard.Modules, Orchard.Themes, Orchard.Users, Orchard.Roles, Orchard.Pages, Orchard.Comments, Orchard.Tags, TinyMce" },
|
||||
new { extension = "core", names = "Common, Dashboard, Feeds, HomePage, Navigation, Scheduling, Settings, XmlRpc" },
|
||||
new { extension = "theme", names = "SafeMode, Classic" }));
|
||||
|
||||
|
@@ -1,16 +1,16 @@
|
||||
using Autofac;
|
||||
using NHibernate;
|
||||
using NUnit.Framework;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.MetaData.Records;
|
||||
using Orchard.ContentManagement.MetaData.Services;
|
||||
using Orchard.Data;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Records;
|
||||
using Orchard.Data;
|
||||
|
||||
|
||||
namespace Orchard.Tests.ContentManagement{
|
||||
[TestFixture]
|
||||
class ContentTypeMetaDataTests
|
||||
public class ContentTypeMetaDataTests
|
||||
{
|
||||
private IContainer _container;
|
||||
private ISessionFactory _sessionFactory;
|
||||
@@ -57,8 +57,6 @@ namespace Orchard.Tests.ContentManagement{
|
||||
Assert.IsTrue(contentTypeService.ValidateContentTypeToContentPartMapping("foo","bar"),"Content Type not successfully mapped");
|
||||
contentTypeService.UnMapContentTypeToContentPart("foo", "bar");
|
||||
Assert.IsFalse(contentTypeService.ValidateContentTypeToContentPartMapping("foo", "bar"), "Content Type mapping not successfully deleted");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -56,14 +56,6 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\fluentnhibernate\FluentNHibernate.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Machine.Migrations, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5c474de7a495cff1, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\machine.migrations\Machine.Migrations.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Machine.Migrations.NHibernate, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\machine.migrations\Machine.Migrations.NHibernate.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Moq, Version=4.0.812.4, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\moq\Moq.dll</HintPath>
|
||||
|
@@ -1,42 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.ContentManagement.MetaData.Records;
|
||||
using Orchard.ContentManagement.MetaData.Services;
|
||||
using Orchard.Data;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.ContentManagement.Records;
|
||||
|
||||
namespace Orchard.ContentManagement.MetaData
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class ContentPartHandler : ContentHandler
|
||||
{
|
||||
private readonly IEnumerable<ContentPartInfo> _contentPartInfos;
|
||||
namespace Orchard.ContentManagement.MetaData {
|
||||
public class ContentPartHandler : ContentHandler {
|
||||
private readonly IEnumerable<IContentPartDriver> _contentPartDrivers;
|
||||
private readonly IContentTypeService _contentTypeService;
|
||||
|
||||
public ContentPartHandler(IEnumerable<IContentPartDriver> contentPartDrivers, IOrchardServices orchardServices, IContentTypeService contentTypeService) {
|
||||
public ContentPartHandler(IEnumerable<IContentPartDriver> contentPartDrivers, IContentTypeService contentTypeService) {
|
||||
_contentPartDrivers = contentPartDrivers;
|
||||
_contentTypeService = contentTypeService;
|
||||
_contentPartInfos = contentPartDrivers.SelectMany<IContentPartDriver, ContentPartInfo>(cpp => cpp.GetPartInfo());
|
||||
}
|
||||
|
||||
protected override void Activating(ActivatingContentContext context) {
|
||||
var contentTypeRecord = _contentTypeService.GetContentTypeRecord(context.ContentType) ?? new ContentTypeRecord();
|
||||
var contentTypeRecord = _contentTypeService.GetContentTypeRecord(context.ContentType);
|
||||
if (contentTypeRecord == null)
|
||||
return;
|
||||
|
||||
if (contentTypeRecord.ContentParts != null){
|
||||
foreach (var contentTypePartRecord in contentTypeRecord.ContentParts){
|
||||
//var record = contentTypePartRecord;
|
||||
var contentPartInfos = _contentPartDrivers.SelectMany(cpp => cpp.GetPartInfo()).ToList();
|
||||
|
||||
var contentPart = _contentPartInfos.Single(x => x.PartName == contentTypePartRecord.PartName.PartName).Factory();
|
||||
context.Builder.Weld(contentPart);
|
||||
foreach (var contentTypePartRecord in contentTypeRecord.ContentParts) {
|
||||
// We might have a part in the database, but the corresponding feature might not
|
||||
// be enabled anymore, so we need to be resilient to that situation.
|
||||
var contentPartInfo = contentPartInfos.SingleOrDefault(x => x.PartName == contentTypePartRecord.PartName.PartName);
|
||||
if (contentPartInfo != null) {
|
||||
context.Builder.Weld(contentPartInfo.Factory());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,70 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.ContentManagement.MetaData.Records;
|
||||
using Orchard.Data;
|
||||
using System.Collections.Generic;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement.MetaData.Records;
|
||||
using Orchard.ContentManagement.Records;
|
||||
using Orchard.Data;
|
||||
|
||||
namespace Orchard.ContentManagement.MetaData.Services
|
||||
{
|
||||
namespace Orchard.ContentManagement.MetaData.Services {
|
||||
[UsedImplicitly]
|
||||
public class ContentTypeService : IContentTypeService
|
||||
{
|
||||
public class ContentTypeService : IContentTypeService {
|
||||
private readonly IRepository<ContentTypeRecord> _contentTypeRepository;
|
||||
private readonly IRepository<ContentTypePartNameRecord> _contentTypePartNameRepository;
|
||||
private readonly IRepository<ContentTypePartRecord> _contentTypePartRepository;
|
||||
|
||||
public ContentTypeService(IRepository<ContentTypePartRecord> contentTypePartRepository, IRepository<ContentTypeRecord> contentTypeRepository, IRepository<ContentTypePartNameRecord> contentTypePartNameRepository)
|
||||
{
|
||||
public ContentTypeService(IRepository<ContentTypePartRecord> contentTypePartRepository, IRepository<ContentTypeRecord> contentTypeRepository, IRepository<ContentTypePartNameRecord> contentTypePartNameRepository) {
|
||||
_contentTypeRepository = contentTypeRepository;
|
||||
_contentTypePartNameRepository = contentTypePartNameRepository;
|
||||
_contentTypePartRepository = contentTypePartRepository;
|
||||
}
|
||||
|
||||
public ContentTypeRecord GetContentTypeRecord(string contentTypeName) {
|
||||
return _contentTypeRepository.Fetch(x => x.Name == contentTypeName).SingleOrDefault();
|
||||
}
|
||||
|
||||
public ContentTypePartNameRecord GetContentPartNameRecord(string name) {
|
||||
return _contentTypePartNameRepository.Fetch(x => x.PartName == name).Single();
|
||||
return _contentTypePartNameRepository.Fetch(x => x.PartName == name).SingleOrDefault();
|
||||
}
|
||||
|
||||
public IEnumerable<ContentTypeRecord> GetContentTypes() {
|
||||
return _contentTypeRepository.Table.ToList();
|
||||
}
|
||||
|
||||
public IEnumerable<ContentTypePartNameRecord> GetContentTypePartNames() {
|
||||
return _contentTypePartNameRepository.Table.ToList();
|
||||
}
|
||||
|
||||
public void MapContentTypeToContentPart(string contentType, string contentPart) {
|
||||
var contentTypeRecord = GetContentTypeRecord(contentType) ?? new ContentTypeRecord();
|
||||
contentTypeRecord.Name = contentType;
|
||||
var contentTypePartNameRecord =
|
||||
_contentTypePartNameRepository.Fetch(x => x.PartName == contentPart).SingleOrDefault();
|
||||
if (contentTypePartNameRecord==null) {
|
||||
contentTypePartNameRecord=new ContentTypePartNameRecord(){PartName = contentPart};
|
||||
_contentTypePartNameRepository.Update(contentTypePartNameRecord);
|
||||
contentTypePartNameRecord =
|
||||
_contentTypePartNameRepository.Fetch(x => x.PartName == contentPart).SingleOrDefault();
|
||||
}
|
||||
var contentTypePartRecord = new ContentTypePartRecord() {
|
||||
PartName = contentTypePartNameRecord
|
||||
};
|
||||
if (contentTypeRecord.ContentParts==null) {
|
||||
contentTypeRecord.ContentParts = new List<ContentTypePartRecord> { contentTypePartRecord };
|
||||
}
|
||||
else {
|
||||
contentTypeRecord.ContentParts.Add(contentTypePartRecord);
|
||||
// Create content type if needed
|
||||
var contentTypeRecord = GetContentTypeRecord(contentType);
|
||||
if (contentTypeRecord == null) {
|
||||
contentTypeRecord = new ContentTypeRecord { Name = contentType };
|
||||
_contentTypeRepository.Create(contentTypeRecord);
|
||||
}
|
||||
|
||||
_contentTypeRepository.Update(contentTypeRecord);
|
||||
// Create part name if needed
|
||||
var contentTypePartNameRecord = GetContentPartNameRecord(contentPart);
|
||||
if (contentTypePartNameRecord == null) {
|
||||
contentTypePartNameRecord = new ContentTypePartNameRecord { PartName = contentPart };
|
||||
_contentTypePartNameRepository.Create(contentTypePartNameRecord);
|
||||
}
|
||||
|
||||
// Add part name to content type
|
||||
var contentTypePartRecord = new ContentTypePartRecord { PartName = contentTypePartNameRecord };
|
||||
contentTypeRecord.ContentParts.Add(contentTypePartRecord);
|
||||
}
|
||||
|
||||
public void UnMapContentTypeToContentPart(string contentType, string contentPart) {
|
||||
var contentTypeRecord = GetContentTypeRecord(contentType) ?? new ContentTypeRecord();
|
||||
var contentTypeRecord = GetContentTypeRecord(contentType);
|
||||
var contentTypePartNameRecord = _contentTypePartNameRepository.Fetch(x => x.PartName == contentPart).Single();
|
||||
|
||||
var contentTypePartRecord = contentTypeRecord.ContentParts.SingleOrDefault(x => x.PartName == contentTypePartNameRecord);
|
||||
if (contentTypePartRecord != null)
|
||||
{
|
||||
_contentTypePartRepository.Delete(contentTypePartRecord);
|
||||
contentTypeRecord.ContentParts.Remove(contentTypePartRecord);
|
||||
}
|
||||
var contentTypePartRecord = contentTypeRecord.ContentParts.Single(x => x.PartName == contentTypePartNameRecord);
|
||||
contentTypeRecord.ContentParts.Remove(contentTypePartRecord);
|
||||
}
|
||||
|
||||
public bool ValidateContentTypeToContentPartMapping(string contentType, string contentPart) {
|
||||
var contentTypeRecord = GetContentTypeRecord(contentType) ?? new ContentTypeRecord();
|
||||
if (contentTypeRecord.ContentParts.Count==0)
|
||||
if (contentTypeRecord.ContentParts.Count == 0)
|
||||
return false;
|
||||
var contentTypePart = contentTypeRecord.ContentParts.Single(x => x.PartName.PartName == contentPart);
|
||||
return contentTypePart != null;
|
||||
@@ -78,18 +77,5 @@ namespace Orchard.ContentManagement.MetaData.Services
|
||||
|
||||
_contentTypePartNameRepository.Update(contentTypePartNameRecord);
|
||||
}
|
||||
|
||||
public ContentTypeRecord GetContentTypeRecord(string contentTypeName) {
|
||||
return _contentTypeRepository.Fetch(x => x.Name == contentTypeName).SingleOrDefault();
|
||||
}
|
||||
|
||||
public IEnumerable<ContentTypeRecord> GetContentTypes() {
|
||||
return _contentTypeRepository.Table.ToList();
|
||||
}
|
||||
|
||||
public IEnumerable<ContentTypePartNameRecord> GetContentTypePartNames() {
|
||||
return _contentTypePartNameRepository.Table.ToList();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -4,6 +4,9 @@ using Orchard.Data.Conventions;
|
||||
|
||||
namespace Orchard.ContentManagement.Records {
|
||||
public class ContentTypeRecord {
|
||||
public ContentTypeRecord() {
|
||||
ContentParts = new List<ContentTypePartRecord>();
|
||||
}
|
||||
public virtual int Id { get; set; }
|
||||
public virtual string Name { get; set; }
|
||||
[CascadeAllDeleteOrphan]
|
||||
|
Reference in New Issue
Block a user