Added unit test for tags NodeCount property

This commit is contained in:
AndyButland
2014-08-06 22:38:46 +02:00
parent 5efabee0bd
commit 8f2f4b579e
2 changed files with 77 additions and 0 deletions

View File

@@ -0,0 +1,73 @@
using System.Linq;
using NUnit.Framework;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Entities;
namespace Umbraco.Tests.Services
{
/// <summary>
/// Tests covering methods in the TagService class.
/// This is more of an integration test as it involves multiple layers
/// as well as configuration.
/// </summary>
[DatabaseTestBehavior(DatabaseBehavior.NewDbFileAndSchemaPerTest)]
[TestFixture, RequiresSTA]
public class TagServiceTests : BaseServiceTest
{
[SetUp]
public override void Initialize()
{
base.Initialize();
}
[TearDown]
public override void TearDown()
{
base.TearDown();
}
[Test]
public void TagList_Contains_NodeCount()
{
var contentService = ServiceContext.ContentService;
var contentTypeService = ServiceContext.ContentTypeService;
var tagService = ServiceContext.TagService;
var contentType = MockedContentTypes.CreateSimpleContentType("umbMandatory", "Mandatory Doc Type", true);
contentType.PropertyGroups.First().PropertyTypes.Add(
new PropertyType("test", DataTypeDatabaseType.Ntext)
{
Alias = "tags",
DataTypeDefinitionId = 1041
});
contentTypeService.Save(contentType);
var content1 = MockedContent.CreateSimpleContent(contentType, "Tagged content 1", -1);
content1.SetTags("tags", new[] { "cow", "pig", "goat" }, true);
contentService.Publish(content1);
var content2 = MockedContent.CreateSimpleContent(contentType, "Tagged content 2", -1);
content2.SetTags("tags", new[] { "cow", "pig" }, true);
contentService.Publish(content2);
var content3 = MockedContent.CreateSimpleContent(contentType, "Tagged content 3", -1);
content3.SetTags("tags", new[] { "cow" }, true);
contentService.Publish(content3);
// Act
var tags = tagService.GetAllContentTags()
.OrderByDescending(x => x.NodeCount)
.ToList();
// Assert
Assert.AreEqual(3, tags.Count());
Assert.AreEqual("cow", tags[0].Text);
Assert.AreEqual(3, tags[0].NodeCount);
Assert.AreEqual("pig", tags[1].Text);
Assert.AreEqual(2, tags[1].NodeCount);
Assert.AreEqual("goat", tags[2].Text);
Assert.AreEqual(1, tags[2].NodeCount);
}
}
}

View File

@@ -311,6 +311,7 @@
<Compile Include="PublishedContent\StronglyTypedModels\Textpage.cs" />
<Compile Include="PublishedContent\StronglyTypedModels\TypedModelBase.cs" />
<Compile Include="PublishedContent\StronglyTypedModels\UmbracoTemplatePage`T.cs" />
<Compile Include="Services\TagServiceTests.cs" />
<Compile Include="Services\LocalizationServiceTests.cs" />
<Compile Include="Resolvers\XsltExtensionsResolverTests.cs" />
<Compile Include="Services\MemberServiceTests.cs" />
@@ -698,6 +699,9 @@
<ItemGroup>
<Folder Include="Install\" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>xcopy "$(ProjectDir)"..\packages\SqlServerCE.4.0.0.0\amd64\*.* "$(TargetDir)amd64\" /Y /F /E /D