diff --git a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTestWithContent.cs b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTestWithContent.cs index ecfc829427..2feccbcccb 100644 --- a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTestWithContent.cs +++ b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTestWithContent.cs @@ -1,4 +1,4 @@ -using System; +using System; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Services; @@ -10,17 +10,17 @@ namespace Umbraco.Tests.Integration.Testing public abstract class UmbracoIntegrationTestWithContent : UmbracoIntegrationTest { protected IContentTypeService ContentTypeService => GetRequiredService(); + protected IFileService FileService => GetRequiredService(); + protected ContentService ContentService => (ContentService)GetRequiredService(); [SetUp] - public void Setup(){ - CreateTestData(); - } + public void Setup() => CreateTestData(); public virtual void CreateTestData() { - //NOTE Maybe not the best way to create/save test data as we are using the services, which are being tested. + // NOTE Maybe not the best way to create/save test data as we are using the services, which are being tested. var template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); diff --git a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopedRepositoryTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopedRepositoryTests.cs index f5301fb7f6..11f4095f53 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopedRepositoryTests.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopedRepositoryTests.cs @@ -14,6 +14,7 @@ using Umbraco.Core.Scoping; using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; using Umbraco.Core.Sync; +using Umbraco.Infrastructure.PublishedCache.DependencyInjection; using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.Testing; using Umbraco.Web; @@ -33,7 +34,10 @@ namespace Umbraco.Tests.Integration.Umbraco.Infrastructure.Scoping private CacheRefresherCollection CacheRefresherCollection => GetRequiredService(); protected override void CustomTestSetup(IUmbracoBuilder builder) - => builder.Services.Replace(ServiceDescriptor.Singleton(typeof(IServerMessenger), typeof(LocalServerMessenger))); + { + builder.AddNuCache(); + builder.Services.Replace(ServiceDescriptor.Singleton(typeof(IServerMessenger), typeof(LocalServerMessenger))); + } protected override AppCaches GetAppCaches() { diff --git a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTests.cs index 837536d362..c9f8dc5391 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTests.cs @@ -22,45 +22,50 @@ using Umbraco.Tests.Testing; namespace Umbraco.Tests.Integration.Umbraco.Infrastructure.Services { + /// /// Tests covering all methods in the ContentService class. /// [TestFixture] - [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, + [UmbracoTest( + Database = UmbracoTestOptions.Database.NewSchemaPerTest, PublishedRepositoryEvents = true, WithApplication = true)] public class ContentServiceTests : UmbracoIntegrationTestWithContent { // TODO: Add test to verify there is only ONE newest document/content in {Constants.DatabaseSchema.Tables.Document} table after updating. // TODO: Add test to delete specific version (with and without deleting prior versions) and versions by date. - - private IMediaTypeService MediaTypeService => GetRequiredService(); - private MediaService MediaService => (MediaService)GetRequiredService(); private IDataTypeService DataTypeService => GetRequiredService(); + private ILocalizationService LocalizationService => GetRequiredService(); + private IAuditService AuditService => GetRequiredService(); + private IUserService UserService => GetRequiredService(); + private IRelationService RelationService => GetRequiredService(); + private ILocalizedTextService TextService => GetRequiredService(); + private ITagService TagService => GetRequiredService(); + private IPublicAccessService PublicAccessService => GetRequiredService(); + private IDomainService DomainService => GetRequiredService(); + private INotificationService NotificationService => GetRequiredService(); + private PropertyEditorCollection PropertyEditorCollection => GetRequiredService(); + private IDocumentRepository DocumentRepository => GetRequiredService(); + private IJsonSerializer Serializer => GetRequiredService(); [SetUp] - public void Setup() - { - ContentRepositoryBase.ThrowOnWarning = true; - } + public void Setup() => ContentRepositoryBase.ThrowOnWarning = true; [TearDown] - public void Teardown() - { - ContentRepositoryBase.ThrowOnWarning = false; - } + public void Teardown() => ContentRepositoryBase.ThrowOnWarning = false; [Test] public void Create_Blueprint() @@ -444,54 +449,6 @@ namespace Umbraco.Tests.Integration.Umbraco.Infrastructure.Services Assert.That(content.HasIdentity, Is.False); } - [Test] - [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, - PublishedRepositoryEvents = true, - WithApplication = true, - Boot = true)] - public void Automatically_Track_Relations() - { - var mt = MediaTypeBuilder.CreateSimpleMediaType("testMediaType", "Test Media Type"); - MediaTypeService.Save(mt); - var m1 = MediaBuilder.CreateSimpleMedia(mt, "hello 1", -1); - var m2 = MediaBuilder.CreateSimpleMedia(mt, "hello 1", -1); - MediaService.Save(m1); - MediaService.Save(m2); - - var template = TemplateBuilder.CreateTextPageTemplate(); - FileService.SaveTemplate(template); - - var ct = ContentTypeBuilder.CreateTextPageContentType("richTextTest", defaultTemplateId: template.Id); - ct.AllowedTemplates = Enumerable.Empty(); - - ContentTypeService.Save(ct); - - var c1 = ContentBuilder.CreateTextpageContent(ct, "my content 1", -1); - ContentService.Save(c1); - - var c2 = ContentBuilder.CreateTextpageContent(ct, "my content 2", -1); - - //'bodyText' is a property with a RTE property editor which we knows tracks relations - c2.Properties["bodyText"].SetValue(@"

- -

-

-

- hello -

"); - - ContentService.Save(c2); - - var relations = RelationService.GetByParentId(c2.Id).ToList(); - Assert.AreEqual(3, relations.Count); - Assert.AreEqual(Constants.Conventions.RelationTypes.RelatedMediaAlias, relations[0].RelationType.Alias); - Assert.AreEqual(m1.Id, relations[0].ChildId); - Assert.AreEqual(Constants.Conventions.RelationTypes.RelatedMediaAlias, relations[1].RelationType.Alias); - Assert.AreEqual(m2.Id, relations[1].ChildId); - Assert.AreEqual(Constants.Conventions.RelationTypes.RelatedDocumentAlias, relations[2].RelationType.Alias); - Assert.AreEqual(c1.Id, relations[2].ChildId); - } - [Test] public void Can_Create_Content_Without_Explicitly_Set_User() { diff --git a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/TrackRelationsTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/TrackRelationsTests.cs new file mode 100644 index 0000000000..e4095c1d33 --- /dev/null +++ b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/TrackRelationsTests.cs @@ -0,0 +1,74 @@ +using System.Linq; +using NUnit.Framework; +using Umbraco.Core; +using Umbraco.Core.DependencyInjection; +using Umbraco.Core.Models; +using Umbraco.Core.Services; +using Umbraco.Core.Services.Implement; +using Umbraco.Infrastructure.PublishedCache.DependencyInjection; +using Umbraco.Tests.Common.Builders; +using Umbraco.Tests.Integration.Testing; +using Umbraco.Tests.Testing; + +namespace Umbraco.Tests.Integration.Umbraco.Infrastructure.Services +{ + [UmbracoTest( + Database = UmbracoTestOptions.Database.NewSchemaPerTest, + PublishedRepositoryEvents = true, + WithApplication = true, + Boot = true)] + public class TrackRelationsTests : UmbracoIntegrationTestWithContent + { + protected override void CustomTestSetup(IUmbracoBuilder builder) => builder.AddNuCache(); + + private IMediaTypeService MediaTypeService => GetRequiredService(); + + private IMediaService MediaService => GetRequiredService(); + + private IRelationService RelationService => GetRequiredService(); + + [Test] + public void Automatically_Track_Relations() + { + var mt = MediaTypeBuilder.CreateSimpleMediaType("testMediaType", "Test Media Type"); + MediaTypeService.Save(mt); + var m1 = MediaBuilder.CreateSimpleMedia(mt, "hello 1", -1); + var m2 = MediaBuilder.CreateSimpleMedia(mt, "hello 1", -1); + MediaService.Save(m1); + MediaService.Save(m2); + + var template = TemplateBuilder.CreateTextPageTemplate(); + FileService.SaveTemplate(template); + + var ct = ContentTypeBuilder.CreateTextPageContentType("richTextTest", defaultTemplateId: template.Id); + ct.AllowedTemplates = Enumerable.Empty(); + + ContentTypeService.Save(ct); + + var c1 = ContentBuilder.CreateTextpageContent(ct, "my content 1", -1); + ContentService.Save(c1); + + var c2 = ContentBuilder.CreateTextpageContent(ct, "my content 2", -1); + + // 'bodyText' is a property with a RTE property editor which we knows tracks relations + c2.Properties["bodyText"].SetValue(@"

+ +

+

+

+ hello +

"); + + ContentService.Save(c2); + + var relations = RelationService.GetByParentId(c2.Id).ToList(); + Assert.AreEqual(3, relations.Count); + Assert.AreEqual(Constants.Conventions.RelationTypes.RelatedMediaAlias, relations[0].RelationType.Alias); + Assert.AreEqual(m1.Id, relations[0].ChildId); + Assert.AreEqual(Constants.Conventions.RelationTypes.RelatedMediaAlias, relations[1].RelationType.Alias); + Assert.AreEqual(m2.Id, relations[1].ChildId); + Assert.AreEqual(Constants.Conventions.RelationTypes.RelatedDocumentAlias, relations[2].RelationType.Alias); + Assert.AreEqual(c1.Id, relations[2].ChildId); + } + } +}