using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Infrastructure.PublishedCache;
using Umbraco.Cms.Tests.Common.Published;
using Umbraco.Cms.Tests.UnitTests.TestHelpers;
using Umbraco.Extensions;
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.PublishedCache
{
[TestFixture]
public class PublishedContentExtensionTests : PublishedSnapshotServiceTestBase
{
private const string XmlContent = @"
]>
";
[SetUp]
public override void Setup()
{
base.Setup();
IEnumerable kits = PublishedContentXmlAdapter.GetContentNodeKits(
XmlContent,
TestHelper.ShortStringHelper,
out ContentType[] contentTypes,
out DataType[] dataTypes).ToList();
// configure inheritance for content types
var baseType = new ContentType(TestHelper.ShortStringHelper, -1) { Alias = "Base" };
contentTypes[0].AddContentType(baseType);
InitializedCache(kits, contentTypes, dataTypes);
}
[Test]
public void IsDocumentType_NonRecursive_ActualType_ReturnsTrue()
{
var publishedContent = GetContent(1100);
Assert.That(publishedContent.IsDocumentType("Inherited", false));
}
[Test]
public void IsDocumentType_NonRecursive_BaseType_ReturnsFalse()
{
var publishedContent = GetContent(1100);
Assert.That(publishedContent.IsDocumentType("Base", false), Is.False);
}
[Test]
public void IsDocumentType_Recursive_ActualType_ReturnsTrue()
{
var publishedContent = GetContent(1100);
Assert.That(publishedContent.IsDocumentType("Inherited", true));
}
[Test]
public void IsDocumentType_Recursive_BaseType_ReturnsTrue()
{
var publishedContent = GetContent(1100);
Assert.That(publishedContent.IsDocumentType("Base", true));
}
[Test]
public void IsDocumentType_Recursive_InvalidBaseType_ReturnsFalse()
{
var publishedContent = GetContent(1100);
Assert.That(publishedContent.IsDocumentType("invalidbase", true), Is.False);
}
}
}