From e8e965c46ae2fc8e1949a7e7345163e9ea1a3f36 Mon Sep 17 00:00:00 2001 From: Elitsa Marinovska Date: Thu, 1 Oct 2020 14:47:34 +0200 Subject: [PATCH] Makes required services private and available to all test methods --- .../Services/TagServiceTests.cs | 52 +++++++++---------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/src/Umbraco.Tests.Integration/Services/TagServiceTests.cs b/src/Umbraco.Tests.Integration/Services/TagServiceTests.cs index 09cbafd550..db2c8196e7 100644 --- a/src/Umbraco.Tests.Integration/Services/TagServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/TagServiceTests.cs @@ -22,40 +22,40 @@ namespace Umbraco.Tests.Integration.Services [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] public class TagServiceTests : UmbracoIntegrationTest { + private IContentService ContentService => GetRequiredService(); + private IContentTypeService ContentTypeService => GetRequiredService(); + private ITagService TagService => GetRequiredService(); + private IDataTypeService DataTypeService => GetRequiredService(); public PropertyEditorCollection PropertyEditorCollection => GetRequiredService(); [Test] public void TagApiConsistencyTest() { - var contentService = GetRequiredService(); - var contentTypeService = GetRequiredService(); - var tagService = GetRequiredService(); - var dataTypeService = GetRequiredService(); var contentType = MockedContentTypes.CreateSimpleContentType("umbMandatory", "Mandatory Doc Type", true); contentType.PropertyGroups.First().PropertyTypes.Add( new PropertyType(ShortStringHelper, "test", ValueStorageType.Ntext, "tags") { DataTypeId = 1041 }); - contentTypeService.Save(contentType); + ContentTypeService.Save(contentType); IContent content1 = MockedContent.CreateSimpleContent(contentType, "Tagged content 1", -1); - content1.AssignTags(PropertyEditorCollection, dataTypeService, "tags", new[] { "cow", "pig", "goat" }); - contentService.SaveAndPublish(content1); + 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" }); - contentService.SaveAndPublish(content1); + 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); - contentService.SaveAndPublish(content1); - content1.RemoveTags(PropertyEditorCollection, dataTypeService, "tags", new[] { "mouse" }); - contentService.SaveAndPublish(content1); + content1.AssignTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "mouse" }, true); + ContentService.SaveAndPublish(content1); + content1.RemoveTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "mouse" }); + ContentService.SaveAndPublish(content1); // get it back - content1 = contentService.GetById(content1.Id); + content1 = ContentService.GetById(content1.Id); var tagsValue = content1.GetValue("tags").ToString(); var tagsValues = JsonConvert.DeserializeObject(tagsValue); Assert.AreEqual(3, tagsValues.Length); @@ -63,7 +63,7 @@ namespace Umbraco.Tests.Integration.Services Assert.Contains("goat", tagsValues); Assert.Contains("elephant", tagsValues); - var tags = tagService.GetTagsForProperty(content1.Id, "tags").ToArray(); + var tags = TagService.GetTagsForProperty(content1.Id, "tags").ToArray(); Assert.IsTrue(tags.All(x => x.Group == "default")); tagsValues = tags.Select(x => x.Text).ToArray(); @@ -76,32 +76,28 @@ namespace Umbraco.Tests.Integration.Services [Test] public void TagList_Contains_NodeCount() { - var contentService = GetRequiredService(); - var contentTypeService = GetRequiredService(); - var tagService = GetRequiredService(); - var dataTypeService = GetRequiredService(); var contentType = MockedContentTypes.CreateSimpleContentType("umbMandatory", "Mandatory Doc Type", true); contentType.PropertyGroups.First().PropertyTypes.Add( new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.Tags, ValueStorageType.Ntext, "tags") { DataTypeId = Constants.DataTypes.Tags }); - contentTypeService.Save(contentType); + ContentTypeService.Save(contentType); var content1 = MockedContent.CreateSimpleContent(contentType, "Tagged content 1", -1); - content1.AssignTags(PropertyEditorCollection, dataTypeService, "tags", new[] { "cow", "pig", "goat" }); - contentService.SaveAndPublish(content1); + 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" }); - contentService.SaveAndPublish(content2); + 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" }); - contentService.SaveAndPublish(content3); + content3.AssignTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "cow" }); + ContentService.SaveAndPublish(content3); // Act - var tags = tagService.GetAllContentTags() + var tags = TagService.GetAllContentTags() .OrderByDescending(x => x.NodeCount) .ToList();