Migrating TagServiceTests

This commit is contained in:
Elitsa Marinovska
2020-10-01 14:23:17 +02:00
parent 2e28061fd4
commit 8dfa73be4c
3 changed files with 20 additions and 21 deletions

View File

@@ -2,16 +2,15 @@
using System.Threading;
using Newtonsoft.Json;
using NUnit.Framework;
using NUnit.Framework.Internal;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.Integration.Testing;
using Umbraco.Tests.TestHelpers.Entities;
using Umbraco.Tests.Testing;
namespace Umbraco.Tests.Services
namespace Umbraco.Tests.Integration.Services
{
/// <summary>
/// Tests covering methods in the TagService class.
@@ -21,16 +20,17 @@ namespace Umbraco.Tests.Services
[TestFixture]
[Apartment(ApartmentState.STA)]
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
public class TagServiceTests : TestWithSomeContentBase
public class TagServiceTests : UmbracoIntegrationTest
{
public PropertyEditorCollection PropertyEditorCollection => Factory.GetInstance<PropertyEditorCollection>();
public PropertyEditorCollection PropertyEditorCollection => GetRequiredService<PropertyEditorCollection>();
[Test]
public void TagApiConsistencyTest()
{
var contentService = ServiceContext.ContentService;
var contentTypeService = ServiceContext.ContentTypeService;
var tagService = ServiceContext.TagService;
var contentService = GetRequiredService<IContentService>();
var contentTypeService = GetRequiredService<IContentTypeService>();
var tagService = GetRequiredService<ITagService>();
var dataTypeService = GetRequiredService<IDataTypeService>();
var contentType = MockedContentTypes.CreateSimpleContentType("umbMandatory", "Mandatory Doc Type", true);
contentType.PropertyGroups.First().PropertyTypes.Add(
new PropertyType(ShortStringHelper, "test", ValueStorageType.Ntext, "tags")
@@ -40,18 +40,18 @@ namespace Umbraco.Tests.Services
contentTypeService.Save(contentType);
IContent content1 = MockedContent.CreateSimpleContent(contentType, "Tagged content 1", -1);
content1.AssignTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "cow", "pig", "goat" });
content1.AssignTags(PropertyEditorCollection, dataTypeService, "tags", new[] { "cow", "pig", "goat" });
contentService.SaveAndPublish(content1);
// change
content1.AssignTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "elephant" }, true);
content1.RemoveTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "cow" });
content1.AssignTags(PropertyEditorCollection, dataTypeService, "tags", new[] { "elephant" }, true);
content1.RemoveTags(PropertyEditorCollection, dataTypeService, "tags", new[] { "cow" });
contentService.SaveAndPublish(content1);
// more changes
content1.AssignTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "mouse" }, true);
content1.AssignTags(PropertyEditorCollection, dataTypeService, "tags", new[] { "mouse" }, true);
contentService.SaveAndPublish(content1);
content1.RemoveTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "mouse" });
content1.RemoveTags(PropertyEditorCollection, dataTypeService, "tags", new[] { "mouse" });
contentService.SaveAndPublish(content1);
// get it back
@@ -76,9 +76,10 @@ namespace Umbraco.Tests.Services
[Test]
public void TagList_Contains_NodeCount()
{
var contentService = ServiceContext.ContentService;
var contentTypeService = ServiceContext.ContentTypeService;
var tagService = ServiceContext.TagService;
var contentService = GetRequiredService<IContentService>();
var contentTypeService = GetRequiredService<IContentTypeService>();
var tagService = GetRequiredService<ITagService>();
var dataTypeService = GetRequiredService<IDataTypeService>();
var contentType = MockedContentTypes.CreateSimpleContentType("umbMandatory", "Mandatory Doc Type", true);
contentType.PropertyGroups.First().PropertyTypes.Add(
new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.Tags, ValueStorageType.Ntext, "tags")
@@ -88,15 +89,15 @@ namespace Umbraco.Tests.Services
contentTypeService.Save(contentType);
var content1 = MockedContent.CreateSimpleContent(contentType, "Tagged content 1", -1);
content1.AssignTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "cow", "pig", "goat" });
content1.AssignTags(PropertyEditorCollection, dataTypeService, "tags", new[] { "cow", "pig", "goat" });
contentService.SaveAndPublish(content1);
var content2 = MockedContent.CreateSimpleContent(contentType, "Tagged content 2", -1);
content2.AssignTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "cow", "pig" });
content2.AssignTags(PropertyEditorCollection, dataTypeService, "tags", new[] { "cow", "pig" });
contentService.SaveAndPublish(content2);
var content3 = MockedContent.CreateSimpleContent(contentType, "Tagged content 3", -1);
content3.AssignTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "cow" });
content3.AssignTags(PropertyEditorCollection, dataTypeService, "tags", new[] { "cow" });
contentService.SaveAndPublish(content3);
// Act

View File

@@ -24,7 +24,6 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="Moq" Version="4.14.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0">
<PrivateAssets>all</PrivateAssets>

View File

@@ -268,7 +268,6 @@
<Compile Include="Scheduling\BackgroundTaskRunnerTests.cs" />
<Compile Include="Services\FileServiceTests.cs" />
<Compile Include="Services\LocalizedTextServiceTests.cs" />
<Compile Include="Services\TagServiceTests.cs" />
<Compile Include="Services\LocalizationServiceTests.cs" />
<Compile Include="Services\MemberServiceTests.cs" />
<Compile Include="Services\MediaServiceTests.cs" />