using System; using System.Collections.Generic; using System.Linq; using System.Text; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Tests.TestHelpers; using Umbraco.Web; namespace Umbraco.Tests.PublishedContent { [DatabaseTestBehavior(DatabaseBehavior.NewDbFileAndSchemaPerFixture)] [TestFixture] public class PublishedContentExtensionTests : PublishedContentTestBase { private UmbracoContext ctx; private string xmlContent = ""; private bool createContentTypes = true; public override void Initialize() { base.Initialize(); // make sure we get them from the content service PublishedContentType.GetPublishedContentTypeCallback = null; } protected override string GetXmlContent(int templateId) { return xmlContent; } [Test] public void IsDocumentType_NonRecursive_ActualType_ReturnsTrue() { InitializeInheritedContentTypes(); var publishedContent = ctx.ContentCache.GetById(1100); Assert.That(publishedContent.IsDocumentType("inherited", false)); } [Test] public void IsDocumentType_NonRecursive_BaseType_ReturnsFalse() { InitializeInheritedContentTypes(); var publishedContent = ctx.ContentCache.GetById(1100); Assert.That(publishedContent.IsDocumentType("base", false), Is.False); } [Test] public void IsDocumentType_Recursive_ActualType_ReturnsTrue() { InitializeInheritedContentTypes(); var publishedContent = ctx.ContentCache.GetById(1100); Assert.That(publishedContent.IsDocumentType("inherited", true)); } [Test] public void IsDocumentType_Recursive_BaseType_ReturnsTrue() { InitializeInheritedContentTypes(); var publishedContent = ctx.ContentCache.GetById(1100); Assert.That(publishedContent.IsDocumentType("base", true)); } [Test] public void IsDocumentType_Recursive_InvalidBaseType_ReturnsFalse() { InitializeInheritedContentTypes(); var publishedContent = ctx.ContentCache.GetById(1100); Assert.That(publishedContent.IsDocumentType("invalidbase", true), Is.False); } private void InitializeInheritedContentTypes() { ctx = GetUmbracoContext("/", 1, null, true); if (createContentTypes) { var contentTypeService = ctx.Application.Services.ContentTypeService; var baseType = new ContentType(-1) { Alias = "base", Name = "Base" }; const string contentTypeAlias = "inherited"; var inheritedType = new ContentType(baseType, contentTypeAlias) { Alias = contentTypeAlias, Name = "Inherited" }; contentTypeService.Save(baseType); contentTypeService.Save(inheritedType); createContentTypes = false; } xmlContent = @" ]> "; } } }