From 9feb79eb906fda6b6af78fe973fe19832ae9183b Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 7 Oct 2020 14:38:15 +0200 Subject: [PATCH 1/9] Update nuget packages Signed-off-by: Bjarke Berg --- build/NuSpecs/UmbracoCms.Core.nuspec | 2 +- build/NuSpecs/UmbracoCms.Web.nuspec | 2 +- src/Umbraco.Examine.Lucene/Umbraco.Examine.Lucene.csproj | 2 +- src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj | 3 +-- src/Umbraco.TestData/Umbraco.TestData.csproj | 2 +- .../Config/QuickRunConfigAttribute.cs | 2 +- .../Config/QuickRunWithMemoryDiagnoserConfigAttribute.cs | 4 ++-- src/Umbraco.Tests.Benchmarks/CtorInvokeBenchmarks.cs | 4 ++-- src/Umbraco.Tests.Benchmarks/SqlTemplatesBenchmark.cs | 2 +- .../Umbraco.Tests.Benchmarks.csproj | 8 +++++++- src/Umbraco.Tests.Common/Umbraco.Tests.Common.csproj | 1 - .../Umbraco.Tests.Integration.csproj | 4 ++-- src/Umbraco.Tests/Umbraco.Tests.csproj | 4 ++-- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 2 +- src/Umbraco.Web/Umbraco.Web.csproj | 6 +++--- 15 files changed, 26 insertions(+), 22 deletions(-) diff --git a/build/NuSpecs/UmbracoCms.Core.nuspec b/build/NuSpecs/UmbracoCms.Core.nuspec index eeff783d6f..a88f260431 100644 --- a/build/NuSpecs/UmbracoCms.Core.nuspec +++ b/build/NuSpecs/UmbracoCms.Core.nuspec @@ -61,7 +61,7 @@ - + diff --git a/build/NuSpecs/UmbracoCms.Web.nuspec b/build/NuSpecs/UmbracoCms.Web.nuspec index 5d1117fada..2fea306ce0 100644 --- a/build/NuSpecs/UmbracoCms.Web.nuspec +++ b/build/NuSpecs/UmbracoCms.Web.nuspec @@ -33,7 +33,7 @@ - + diff --git a/src/Umbraco.Examine.Lucene/Umbraco.Examine.Lucene.csproj b/src/Umbraco.Examine.Lucene/Umbraco.Examine.Lucene.csproj index 932d6d318b..137d4d425c 100644 --- a/src/Umbraco.Examine.Lucene/Umbraco.Examine.Lucene.csproj +++ b/src/Umbraco.Examine.Lucene/Umbraco.Examine.Lucene.csproj @@ -40,7 +40,7 @@ - 3.4.0 + 3.5.3 runtime; build; native; contentfiles; analyzers all diff --git a/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj b/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj index 81ba8ca6cd..d8fbbd7fbd 100644 --- a/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj +++ b/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj @@ -14,8 +14,7 @@ - - + diff --git a/src/Umbraco.TestData/Umbraco.TestData.csproj b/src/Umbraco.TestData/Umbraco.TestData.csproj index 052acd64ef..a21251130e 100644 --- a/src/Umbraco.TestData/Umbraco.TestData.csproj +++ b/src/Umbraco.TestData/Umbraco.TestData.csproj @@ -66,7 +66,7 @@ - 28.4.4 + 31.0.3 5.2.7 diff --git a/src/Umbraco.Tests.Benchmarks/Config/QuickRunConfigAttribute.cs b/src/Umbraco.Tests.Benchmarks/Config/QuickRunConfigAttribute.cs index 52d670de3c..0e87bfb584 100644 --- a/src/Umbraco.Tests.Benchmarks/Config/QuickRunConfigAttribute.cs +++ b/src/Umbraco.Tests.Benchmarks/Config/QuickRunConfigAttribute.cs @@ -1,7 +1,7 @@ using System; using BenchmarkDotNet.Configs; -using BenchmarkDotNet.Horology; using BenchmarkDotNet.Jobs; +using Perfolizer.Horology; namespace Umbraco.Tests.Benchmarks.Config { diff --git a/src/Umbraco.Tests.Benchmarks/Config/QuickRunWithMemoryDiagnoserConfigAttribute.cs b/src/Umbraco.Tests.Benchmarks/Config/QuickRunWithMemoryDiagnoserConfigAttribute.cs index 381efc9139..73e4fd6de2 100644 --- a/src/Umbraco.Tests.Benchmarks/Config/QuickRunWithMemoryDiagnoserConfigAttribute.cs +++ b/src/Umbraco.Tests.Benchmarks/Config/QuickRunWithMemoryDiagnoserConfigAttribute.cs @@ -14,7 +14,7 @@ namespace Umbraco.Tests.Benchmarks.Config /// public QuickRunWithMemoryDiagnoserConfigAttribute() { - Config.Add(new MemoryDiagnoser()); + Config.Add(MemoryDiagnoser.Default); } } -} \ No newline at end of file +} diff --git a/src/Umbraco.Tests.Benchmarks/CtorInvokeBenchmarks.cs b/src/Umbraco.Tests.Benchmarks/CtorInvokeBenchmarks.cs index d63f586be3..02696b9b7b 100644 --- a/src/Umbraco.Tests.Benchmarks/CtorInvokeBenchmarks.cs +++ b/src/Umbraco.Tests.Benchmarks/CtorInvokeBenchmarks.cs @@ -5,8 +5,8 @@ using System.Reflection.Emit; using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; using BenchmarkDotNet.Diagnosers; -using BenchmarkDotNet.Horology; using BenchmarkDotNet.Jobs; +using Perfolizer.Horology; using Umbraco.Core; namespace Umbraco.Tests.Benchmarks @@ -26,7 +26,7 @@ namespace Umbraco.Tests.Benchmarks { public Config() { - Add(new MemoryDiagnoser()); + Add(MemoryDiagnoser.Default); //Add(ExecutionValidator.FailOnError); //The 'quick and dirty' settings, so it runs a little quicker diff --git a/src/Umbraco.Tests.Benchmarks/SqlTemplatesBenchmark.cs b/src/Umbraco.Tests.Benchmarks/SqlTemplatesBenchmark.cs index 0f563d826d..22912af9ff 100644 --- a/src/Umbraco.Tests.Benchmarks/SqlTemplatesBenchmark.cs +++ b/src/Umbraco.Tests.Benchmarks/SqlTemplatesBenchmark.cs @@ -31,7 +31,7 @@ namespace Umbraco.Tests.Benchmarks { public Config() { - Add(new MemoryDiagnoser()); + Add(MemoryDiagnoser.Default); } } diff --git a/src/Umbraco.Tests.Benchmarks/Umbraco.Tests.Benchmarks.csproj b/src/Umbraco.Tests.Benchmarks/Umbraco.Tests.Benchmarks.csproj index 332b93cb0b..f49367ef77 100644 --- a/src/Umbraco.Tests.Benchmarks/Umbraco.Tests.Benchmarks.csproj +++ b/src/Umbraco.Tests.Benchmarks/Umbraco.Tests.Benchmarks.csproj @@ -36,6 +36,9 @@ 7.3 + + C:\Users\Berg\.nuget\packages\perfolizer\0.2.1\lib\netstandard2.0\Perfolizer.dll + @@ -95,7 +98,7 @@ - 0.11.3 + 0.12.1 3.1.8 @@ -103,6 +106,9 @@ 3.1.8 + + 0.2.1 + \ No newline at end of file diff --git a/src/Umbraco.Tests.Common/Umbraco.Tests.Common.csproj b/src/Umbraco.Tests.Common/Umbraco.Tests.Common.csproj index 493dbd7ef0..ecb8ef2dc7 100644 --- a/src/Umbraco.Tests.Common/Umbraco.Tests.Common.csproj +++ b/src/Umbraco.Tests.Common/Umbraco.Tests.Common.csproj @@ -6,7 +6,6 @@ - diff --git a/src/Umbraco.Tests.Integration/Umbraco.Tests.Integration.csproj b/src/Umbraco.Tests.Integration/Umbraco.Tests.Integration.csproj index 4773a5b215..64ae0cf084 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Tests.Integration.csproj +++ b/src/Umbraco.Tests.Integration/Umbraco.Tests.Integration.csproj @@ -18,11 +18,11 @@ - + - + diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 8e7e38c495..5e262f768a 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -88,7 +88,7 @@ 1.11.24 - + @@ -111,7 +111,7 @@ - + diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 4317056f31..1ca65dfd66 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -102,7 +102,7 @@ - 3.4.0 + 3.5.3 runtime; build; native; contentfiles; analyzers all diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index e879f37eef..7b224c49b5 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -68,12 +68,12 @@ - 5.0.343 + 5.0.353 2.7.0.100 - + @@ -103,7 +103,7 @@ - 3.4.0 + 3.5.3 runtime; build; native; contentfiles; analyzers all From e7edbfeaa3ff5cd16314ed3a49d51398b6b10683 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 7 Oct 2020 20:23:06 +0200 Subject: [PATCH 2/9] Migrated RelationRepositoryTest.cs + Minimized how many relations we create to test the code. Signed-off-by: Bjarke Berg --- .../Repositories/RelationRepositoryTest.cs | 215 +++++++++--------- src/Umbraco.Tests/Umbraco.Tests.csproj | 1 - 2 files changed, 109 insertions(+), 107 deletions(-) rename src/{Umbraco.Tests => Umbraco.Tests.Integration}/Persistence/Repositories/RelationRepositoryTest.cs (63%) diff --git a/src/Umbraco.Tests/Persistence/Repositories/RelationRepositoryTest.cs b/src/Umbraco.Tests.Integration/Persistence/Repositories/RelationRepositoryTest.cs similarity index 63% rename from src/Umbraco.Tests/Persistence/Repositories/RelationRepositoryTest.cs rename to src/Umbraco.Tests.Integration/Persistence/Repositories/RelationRepositoryTest.cs index 9cdd0d7c4a..804c6fef90 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/RelationRepositoryTest.cs +++ b/src/Umbraco.Tests.Integration/Persistence/Repositories/RelationRepositoryTest.cs @@ -12,6 +12,8 @@ using Umbraco.Core.Persistence.Dtos; using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Persistence.Repositories.Implement; using Umbraco.Core.Scoping; +using Umbraco.Core.Services; +using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; @@ -20,37 +22,51 @@ namespace Umbraco.Tests.Persistence.Repositories { [TestFixture] [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] - public class RelationRepositoryTest : TestWithDatabaseBase + public class RelationRepositoryTest : UmbracoIntegrationTest { - public override void SetUp() - { - base.SetUp(); + private RelationType _relateContent; + private RelationType _relateContentType; + private ContentType _contentType; + private Content _textpage; + private Content _subpage; + private Content _subpage2; + private Relation _relation; + private Relation _relation2; + private IContentTypeService ContentTypeService => GetRequiredService(); + private IContentService ContentService => GetRequiredService(); + private IMediaTypeService MediaTypeService => GetRequiredService(); + private IMediaService MediaService => GetRequiredService(); + + private IMemberTypeService MemberTypeService => GetRequiredService(); + private IMemberService MemberService => GetRequiredService(); + private IRelationService RelationService => GetRequiredService(); + private IFileService FileService => GetRequiredService(); + + [SetUp] + public void SetUp() + { CreateTestData(); } private RelationRepository CreateRepository(IScopeProvider provider, out RelationTypeRepository relationTypeRepository) { - var accessor = (IScopeAccessor) provider; - relationTypeRepository = new RelationTypeRepository(accessor, AppCaches.Disabled, Mock.Of>()); - var entityRepository = new EntityRepository(accessor); - var repository = new RelationRepository(accessor, Mock.Of>(), relationTypeRepository, entityRepository); - return repository; + relationTypeRepository = (RelationTypeRepository)GetRequiredService(); + return (RelationRepository)GetRequiredService(); } [Test] public void Can_Perform_Add_On_RelationRepository() { // Arrange - var provider = TestObjects.GetScopeProvider(LoggerFactory); - using (var scope = provider.CreateScope()) + using (var scope = ScopeProvider.CreateScope()) { RelationTypeRepository repositoryType; - var repository = CreateRepository(provider, out repositoryType); + var repository = CreateRepository(ScopeProvider, out repositoryType); // Act var relationType = repositoryType.Get(1); - var relation = new Relation(NodeDto.NodeIdSeed + 2, NodeDto.NodeIdSeed + 3, relationType); + var relation = new Relation(_textpage.Id, _subpage.Id, relationType); repository.Save(relation); @@ -64,11 +80,10 @@ namespace Umbraco.Tests.Persistence.Repositories public void Can_Perform_Update_On_RelationRepository() { // Arrange - var provider = TestObjects.GetScopeProvider(LoggerFactory); - using (var scope = provider.CreateScope()) + using (var scope = ScopeProvider.CreateScope()) { RelationTypeRepository repositoryType; - var repository = CreateRepository(provider, out repositoryType); + var repository = CreateRepository(ScopeProvider, out repositoryType); // Act var relation = repository.Get(1); @@ -89,11 +104,10 @@ namespace Umbraco.Tests.Persistence.Repositories public void Can_Perform_Delete_On_RelationRepository() { // Arrange - var provider = TestObjects.GetScopeProvider(LoggerFactory); - using (var scope = provider.CreateScope()) + using (var scope = ScopeProvider.CreateScope()) { RelationTypeRepository repositoryType; - var repository = CreateRepository(provider, out repositoryType); + var repository = CreateRepository(ScopeProvider, out repositoryType); // Act var relation = repository.Get(2); @@ -111,11 +125,10 @@ namespace Umbraco.Tests.Persistence.Repositories public void Can_Perform_Get_On_RelationRepository() { // Arrange - var provider = TestObjects.GetScopeProvider(LoggerFactory); - using (var scope = provider.CreateScope()) + using (var scope = ScopeProvider.CreateScope()) { RelationTypeRepository repositoryType; - var repository = CreateRepository(provider, out repositoryType); + var repository = CreateRepository(ScopeProvider, out repositoryType); // Act var relation = repository.Get(1); @@ -123,8 +136,8 @@ namespace Umbraco.Tests.Persistence.Repositories // Assert Assert.That(relation, Is.Not.Null); Assert.That(relation.HasIdentity, Is.True); - Assert.That(relation.ChildId, Is.EqualTo(NodeDto.NodeIdSeed + 3)); - Assert.That(relation.ParentId, Is.EqualTo(NodeDto.NodeIdSeed + 2)); + Assert.That(relation.ChildId, Is.EqualTo(_subpage.Id)); + Assert.That(relation.ParentId, Is.EqualTo(_textpage.Id)); Assert.That(relation.RelationType.Alias, Is.EqualTo("relateContentOnCopy")); } } @@ -133,11 +146,10 @@ namespace Umbraco.Tests.Persistence.Repositories public void Can_Perform_GetAll_On_RelationRepository() { // Arrange - var provider = TestObjects.GetScopeProvider(LoggerFactory); - using (var scope = provider.CreateScope()) + using (var scope = ScopeProvider.CreateScope()) { RelationTypeRepository repositoryType; - var repository = CreateRepository(provider, out repositoryType); + var repository = CreateRepository(ScopeProvider, out repositoryType); // Act var relations = repository.GetMany(); @@ -154,11 +166,10 @@ namespace Umbraco.Tests.Persistence.Repositories public void Can_Perform_GetAll_With_Params_On_RelationRepository() { // Arrange - var provider = TestObjects.GetScopeProvider(LoggerFactory); - using (var scope = provider.CreateScope()) + using (var scope = ScopeProvider.CreateScope()) { RelationTypeRepository repositoryType; - var repository = CreateRepository(provider, out repositoryType); + var repository = CreateRepository(ScopeProvider, out repositoryType); // Act var relations = repository.GetMany(1, 2); @@ -176,35 +187,34 @@ namespace Umbraco.Tests.Persistence.Repositories { CreateTestDataForPagingTests(out var createdContent, out var createdMembers, out var createdMedia); - var provider = TestObjects.GetScopeProvider(LoggerFactory); - using (var scope = provider.CreateScope()) + using (var scope = ScopeProvider.CreateScope()) { - var repository = CreateRepository(provider, out var relationTypeRepository); + var repository = CreateRepository(ScopeProvider, out var relationTypeRepository); // Get parent entities for child id var parents = repository.GetPagedParentEntitiesByChildId(createdMedia[0].Id, 0, 11, out var totalRecords).ToList(); - Assert.AreEqual(20, totalRecords); - Assert.AreEqual(11, parents.Count); + Assert.AreEqual(6, totalRecords); + Assert.AreEqual(6, parents.Count); //add the next page parents.AddRange(repository.GetPagedParentEntitiesByChildId(createdMedia[0].Id, 1, 11, out totalRecords)); - Assert.AreEqual(20, totalRecords); - Assert.AreEqual(20, parents.Count); + Assert.AreEqual(6, totalRecords); + Assert.AreEqual(6, parents.Count); var contentEntities = parents.OfType().ToList(); var mediaEntities = parents.OfType().ToList(); var memberEntities = parents.OfType().ToList(); - Assert.AreEqual(10, contentEntities.Count); + Assert.AreEqual(3, contentEntities.Count); Assert.AreEqual(0, mediaEntities.Count); - Assert.AreEqual(10, memberEntities.Count); + Assert.AreEqual(3, memberEntities.Count); //only of a certain type parents.AddRange(repository.GetPagedParentEntitiesByChildId(createdMedia[0].Id, 0, 100, out totalRecords, UmbracoObjectTypes.Document.GetGuid())); - Assert.AreEqual(10, totalRecords); + Assert.AreEqual(3, totalRecords); parents.AddRange(repository.GetPagedParentEntitiesByChildId(createdMedia[0].Id, 0, 100, out totalRecords, UmbracoObjectTypes.Member.GetGuid())); - Assert.AreEqual(10, totalRecords); + Assert.AreEqual(3, totalRecords); parents.AddRange(repository.GetPagedParentEntitiesByChildId(createdMedia[0].Id, 0, 100, out totalRecords, UmbracoObjectTypes.Media.GetGuid())); Assert.AreEqual(0, totalRecords); @@ -216,16 +226,15 @@ namespace Umbraco.Tests.Persistence.Repositories { //Create a media item and create a relationship between itself (parent -> child) var imageType = MockedContentTypes.CreateImageMediaType("myImage"); - ServiceContext.MediaTypeService.Save(imageType); + MediaTypeService.Save(imageType); var media = MockedMedia.CreateMediaImage(imageType, -1); - ServiceContext.MediaService.Save(media); - var relType = ServiceContext.RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedMediaAlias); - ServiceContext.RelationService.Relate(media.Id, media.Id, relType); + MediaService.Save(media); + var relType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedMediaAlias); + RelationService.Relate(media.Id, media.Id, relType); - var provider = TestObjects.GetScopeProvider(LoggerFactory); - using (var scope = provider.CreateScope()) + using (var scope = ScopeProvider.CreateScope()) { - var repository = CreateRepository(provider, out var relationTypeRepository); + var repository = CreateRepository(ScopeProvider, out var relationTypeRepository); // Get parent entities for child id var parents = repository.GetPagedParentEntitiesByChildId(media.Id, 0, 10, out var totalRecords).ToList(); @@ -244,35 +253,34 @@ namespace Umbraco.Tests.Persistence.Repositories { CreateTestDataForPagingTests(out var createdContent, out var createdMembers, out var createdMedia); - var provider = TestObjects.GetScopeProvider(LoggerFactory); - using (var scope = provider.CreateScope()) + using (var scope = ScopeProvider.CreateScope()) { - var repository = CreateRepository(provider, out var relationTypeRepository); + var repository = CreateRepository(ScopeProvider, out var relationTypeRepository); // Get parent entities for child id var parents = repository.GetPagedChildEntitiesByParentId(createdContent[0].Id, 0, 6, out var totalRecords).ToList(); - Assert.AreEqual(10, totalRecords); - Assert.AreEqual(6, parents.Count); + Assert.AreEqual(3, totalRecords); + Assert.AreEqual(3, parents.Count); //add the next page parents.AddRange(repository.GetPagedChildEntitiesByParentId(createdContent[0].Id, 1, 6, out totalRecords)); - Assert.AreEqual(10, totalRecords); - Assert.AreEqual(10, parents.Count); + Assert.AreEqual(3, totalRecords); + Assert.AreEqual(3, parents.Count); var contentEntities = parents.OfType().ToList(); var mediaEntities = parents.OfType().ToList(); var memberEntities = parents.OfType().ToList(); Assert.AreEqual(0, contentEntities.Count); - Assert.AreEqual(10, mediaEntities.Count); + Assert.AreEqual(3, mediaEntities.Count); Assert.AreEqual(0, memberEntities.Count); //only of a certain type parents.AddRange(repository.GetPagedChildEntitiesByParentId(createdContent[0].Id, 0, 100, out totalRecords, UmbracoObjectTypes.Media.GetGuid())); - Assert.AreEqual(10, totalRecords); + Assert.AreEqual(3, totalRecords); parents.AddRange(repository.GetPagedChildEntitiesByParentId(createdMembers[0].Id, 0, 100, out totalRecords, UmbracoObjectTypes.Media.GetGuid())); - Assert.AreEqual(10, totalRecords); + Assert.AreEqual(3, totalRecords); parents.AddRange(repository.GetPagedChildEntitiesByParentId(createdContent[0].Id, 0, 100, out totalRecords, UmbracoObjectTypes.Member.GetGuid())); Assert.AreEqual(0, totalRecords); @@ -284,52 +292,51 @@ namespace Umbraco.Tests.Persistence.Repositories //Create content createdContent = new List(); var contentType = MockedContentTypes.CreateBasicContentType("blah"); - ServiceContext.ContentTypeService.Save(contentType); - for (int i = 0; i < 10; i++) + ContentTypeService.Save(contentType); + for (int i = 0; i < 3; i++) { var c1 = MockedContent.CreateBasicContent(contentType); - ServiceContext.ContentService.Save(c1); + ContentService.Save(c1); createdContent.Add(c1); } //Create media createdMedia = new List(); var imageType = MockedContentTypes.CreateImageMediaType("myImage"); - ServiceContext.MediaTypeService.Save(imageType); - for (int i = 0; i < 10; i++) + MediaTypeService.Save(imageType); + for (int i = 0; i < 3; i++) { var c1 = MockedMedia.CreateMediaImage(imageType, -1); - ServiceContext.MediaService.Save(c1); + MediaService.Save(c1); createdMedia.Add(c1); } // Create members var memberType = MockedContentTypes.CreateSimpleMemberType("simple"); - ServiceContext.MemberTypeService.Save(memberType); - createdMembers = MockedMember.CreateSimpleMember(memberType, 10).ToList(); - ServiceContext.MemberService.Save(createdMembers); + MemberTypeService.Save(memberType); + createdMembers = MockedMember.CreateSimpleMember(memberType, 3).ToList(); + MemberService.Save(createdMembers); - var relType = ServiceContext.RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedMediaAlias); + var relType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedMediaAlias); // Relate content to media foreach (var content in createdContent) foreach (var media in createdMedia) - ServiceContext.RelationService.Relate(content.Id, media.Id, relType); + RelationService.Relate(content.Id, media.Id, relType); // Relate members to media foreach (var member in createdMembers) foreach (var media in createdMedia) - ServiceContext.RelationService.Relate(member.Id, media.Id, relType); + RelationService.Relate(member.Id, media.Id, relType); } [Test] public void Can_Perform_Exists_On_RelationRepository() { // Arrange - var provider = TestObjects.GetScopeProvider(LoggerFactory); - using (var scope = provider.CreateScope()) + using (var scope = ScopeProvider.CreateScope()) { RelationTypeRepository repositoryType; - var repository = CreateRepository(provider, out repositoryType); + var repository = CreateRepository(ScopeProvider, out repositoryType); // Act var exists = repository.Exists(2); @@ -345,14 +352,13 @@ namespace Umbraco.Tests.Persistence.Repositories public void Can_Perform_Count_On_RelationRepository() { // Arrange - var provider = TestObjects.GetScopeProvider(LoggerFactory); - using (var scope = provider.CreateScope()) + using (var scope = ScopeProvider.CreateScope()) { RelationTypeRepository repositoryType; - var repository = CreateRepository(provider, out repositoryType); + var repository = CreateRepository(ScopeProvider, out repositoryType); // Act - var query = scope.SqlContext.Query().Where(x => x.ParentId == NodeDto.NodeIdSeed + 2); + var query = scope.SqlContext.Query().Where(x => x.ParentId == _textpage.Id); int count = repository.Count(query); // Assert @@ -364,14 +370,13 @@ namespace Umbraco.Tests.Persistence.Repositories public void Can_Perform_GetByQuery_On_RelationRepository() { // Arrange - var provider = TestObjects.GetScopeProvider(LoggerFactory); - using (var scope = provider.CreateScope()) + using (var scope = ScopeProvider.CreateScope()) { RelationTypeRepository repositoryType; - var repository = CreateRepository(provider, out repositoryType); + var repository = CreateRepository(ScopeProvider, out repositoryType); // Act - var query = scope.SqlContext.Query().Where(x => x.RelationTypeId == RelationTypeDto.NodeIdSeed); + var query = scope.SqlContext.Query().Where(x => x.RelationTypeId == _relateContent.Id); var relations = repository.Get(query); // Assert @@ -386,14 +391,13 @@ namespace Umbraco.Tests.Persistence.Repositories public void Can_Delete_Content_And_Verify_Relation_Is_Removed() { // Arrange - var provider = TestObjects.GetScopeProvider(LoggerFactory); - using (var scope = provider.CreateScope()) + using (var scope = ScopeProvider.CreateScope()) { RelationTypeRepository repositoryType; - var repository = CreateRepository(provider, out repositoryType); + var repository = CreateRepository(ScopeProvider, out repositoryType); - var content = ServiceContext.ContentService.GetById(NodeDto.NodeIdSeed + 3); - ServiceContext.ContentService.Delete(content, 0); + var content = ContentService.GetById(_subpage.Id); + ContentService.Delete(content, 0); // Act var shouldntExist = repository.Exists(1); @@ -413,49 +417,48 @@ namespace Umbraco.Tests.Persistence.Repositories public void CreateTestData() { - var relateContent = new RelationType( + _relateContent = new RelationType( "Relate Content on Copy", "relateContentOnCopy", true, Constants.ObjectTypes.Document, new Guid("C66BA18E-EAF3-4CFF-8A22-41B16D66A972")); - var relateContentType = new RelationType("Relate ContentType on Copy", + _relateContentType = new RelationType("Relate ContentType on Copy", "relateContentTypeOnCopy", true, Constants.ObjectTypes.DocumentType, new Guid("A2CB7800-F571-4787-9638-BC48539A0EFB")); - var provider = TestObjects.GetScopeProvider(LoggerFactory); - using (var scope = provider.CreateScope()) + using (var scope = ScopeProvider.CreateScope()) { - var accessor = (IScopeAccessor)provider; + var accessor = (IScopeAccessor)ScopeProvider; var relationTypeRepository = new RelationTypeRepository(accessor, AppCaches.Disabled, Mock.Of>()); var entityRepository = new EntityRepository(accessor); var relationRepository = new RelationRepository(accessor, Mock.Of>(), relationTypeRepository, entityRepository); - relationTypeRepository.Save(relateContent); - relationTypeRepository.Save(relateContentType); + relationTypeRepository.Save(_relateContent); + relationTypeRepository.Save(_relateContentType); //Create and Save ContentType "umbTextpage" -> (NodeDto.NodeIdSeed) - ContentType contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage", "Textpage"); - ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); // else, FK violation on contentType! - ServiceContext.ContentTypeService.Save(contentType); + _contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage", "Textpage"); + FileService.SaveTemplate(_contentType.DefaultTemplate); // else, FK violation on contentType! + ContentTypeService.Save(_contentType); //Create and Save Content "Homepage" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 1) - Content textpage = MockedContent.CreateSimpleContent(contentType); - ServiceContext.ContentService.Save(textpage, 0); + _textpage = MockedContent.CreateSimpleContent(_contentType); + ContentService.Save(_textpage, 0); //Create and Save Content "Text Page 1" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 2) - Content subpage = MockedContent.CreateSimpleContent(contentType, "Text Page 1", textpage.Id); - ServiceContext.ContentService.Save(subpage, 0); + _subpage = MockedContent.CreateSimpleContent(_contentType, "Text Page 1", _textpage.Id); + ContentService.Save(_subpage, 0); //Create and Save Content "Text Page 1" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 3) - Content subpage2 = MockedContent.CreateSimpleContent(contentType, "Text Page 2", textpage.Id); - ServiceContext.ContentService.Save(subpage2, 0); + _subpage2 = MockedContent.CreateSimpleContent(_contentType, "Text Page 2", _textpage.Id); + ContentService.Save(_subpage2, 0); - var relation = new Relation(textpage.Id, subpage.Id, relateContent) { Comment = string.Empty }; - var relation2 = new Relation(textpage.Id, subpage2.Id, relateContent) { Comment = string.Empty }; - relationRepository.Save(relation); - relationRepository.Save(relation2); + _relation = new Relation(_textpage.Id, _subpage.Id, _relateContent) { Comment = string.Empty }; + _relation2 = new Relation(_textpage.Id, _subpage2.Id, _relateContent) { Comment = string.Empty }; + relationRepository.Save(_relation); + relationRepository.Save(_relation2); scope.Complete(); } } diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 5e262f768a..87ab7e5fa1 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -310,7 +310,6 @@ - From 3171cdda702f10ae7f58b77586aa182a4fda3197 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 7 Oct 2020 21:01:28 +0200 Subject: [PATCH 3/9] Migrated RelationServiceTests.cs Signed-off-by: Bjarke Berg --- .../Implement/RelationTypeRepository.cs | 6 +- .../Services/RelationServiceTests.cs | 96 ++++++++++--------- src/Umbraco.Tests/Umbraco.Tests.csproj | 1 - 3 files changed, 55 insertions(+), 48 deletions(-) rename src/{Umbraco.Tests => Umbraco.Tests.Integration}/Services/RelationServiceTests.cs (71%) diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RelationTypeRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RelationTypeRepository.cs index bbaebbc9a9..8e40198bc5 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RelationTypeRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RelationTypeRepository.cs @@ -50,9 +50,9 @@ namespace Umbraco.Core.Persistence.Repositories.Implement { var sql = GetBaseQuery(false); - // should not happen due to the cache policy - if (ids.Any()) - throw new NotImplementedException(); + // // should not happen due to the cache policy + // if (ids.Any()) + // throw new NotImplementedException(); var dtos = Database.Fetch(sql); diff --git a/src/Umbraco.Tests/Services/RelationServiceTests.cs b/src/Umbraco.Tests.Integration/Services/RelationServiceTests.cs similarity index 71% rename from src/Umbraco.Tests/Services/RelationServiceTests.cs rename to src/Umbraco.Tests.Integration/Services/RelationServiceTests.cs index 06de405cec..0c5b3c8758 100644 --- a/src/Umbraco.Tests/Services/RelationServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/RelationServiceTests.cs @@ -5,6 +5,9 @@ using System.Threading; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Models; +using Umbraco.Core.Services; +using Umbraco.Core.Services.Implement; +using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; @@ -14,51 +17,56 @@ namespace Umbraco.Tests.Services [TestFixture] [Apartment(ApartmentState.STA)] [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] - public class RelationServiceTests : TestWithSomeContentBase + public class RelationServiceTests : UmbracoIntegrationTest { - + private IContentTypeService ContentTypeService => GetRequiredService(); + private IContentService ContentService => GetRequiredService(); + private IMediaTypeService MediaTypeService => GetRequiredService(); + private IMediaService MediaService => GetRequiredService(); + private IRelationService RelationService => GetRequiredService(); + [Test] public void Get_Paged_Relations_By_Relation_Type() { //Create content var createdContent = new List(); var contentType = MockedContentTypes.CreateBasicContentType("blah"); - ServiceContext.ContentTypeService.Save(contentType); - for (int i = 0; i < 10; i++) + ContentTypeService.Save(contentType); + for (int i = 0; i < 3; i++) { var c1 = MockedContent.CreateBasicContent(contentType); - ServiceContext.ContentService.Save(c1); + ContentService.Save(c1); createdContent.Add(c1); } //Create media var createdMedia = new List(); var imageType = MockedContentTypes.CreateImageMediaType("myImage"); - ServiceContext.MediaTypeService.Save(imageType); - for (int i = 0; i < 10; i++) + MediaTypeService.Save(imageType); + for (int i = 0; i < 3; i++) { var c1 = MockedMedia.CreateMediaImage(imageType, -1); - ServiceContext.MediaService.Save(c1); + MediaService.Save(c1); createdMedia.Add(c1); } - var relType = ServiceContext.RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedMediaAlias); + var relType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedMediaAlias); // Relate content to media foreach (var content in createdContent) foreach (var media in createdMedia) - ServiceContext.RelationService.Relate(content.Id, media.Id, relType); + RelationService.Relate(content.Id, media.Id, relType); - var paged = ServiceContext.RelationService.GetPagedByRelationTypeId(relType.Id, 0, 51, out var totalRecs).ToList(); + var paged = RelationService.GetPagedByRelationTypeId(relType.Id, 0, 4, out var totalRecs).ToList(); - Assert.AreEqual(100, totalRecs); - Assert.AreEqual(51, paged.Count); + Assert.AreEqual(9, totalRecs); + Assert.AreEqual(4, paged.Count); //next page - paged.AddRange(ServiceContext.RelationService.GetPagedByRelationTypeId(relType.Id, 1, 51, out totalRecs)); + paged.AddRange(RelationService.GetPagedByRelationTypeId(relType.Id, 1, 4, out totalRecs)); - Assert.AreEqual(100, totalRecs); - Assert.AreEqual(100, paged.Count); + Assert.AreEqual(9, totalRecs); + Assert.AreEqual(8, paged.Count); Assert.IsTrue(createdContent.Select(x => x.Id).ContainsAll(paged.Select(x => x.ParentId))); Assert.IsTrue(createdMedia.Select(x => x.Id).ContainsAll(paged.Select(x => x.ChildId))); @@ -68,13 +76,13 @@ namespace Umbraco.Tests.Services public void Return_List_Of_Content_Items_Where_Media_Item_Referenced() { var mt = MockedContentTypes.CreateSimpleMediaType("testMediaType", "Test Media Type"); - ServiceContext.MediaTypeService.Save(mt); + MediaTypeService.Save(mt); var m1 = MockedMedia.CreateSimpleMedia(mt, "hello 1", -1); - ServiceContext.MediaService.Save(m1); + MediaService.Save(m1); var ct = MockedContentTypes.CreateTextPageContentType("richTextTest"); ct.AllowedTemplates = Enumerable.Empty(); - ServiceContext.ContentTypeService.Save(ct); + ContentTypeService.Save(ct); void createContentWithMediaRefs() { @@ -83,29 +91,29 @@ namespace Umbraco.Tests.Services content.Properties["bodyText"].SetValue(@"

"); - ServiceContext.ContentService.Save(content); + ContentService.Save(content); } for (var i = 0; i < 6; i++) createContentWithMediaRefs(); //create 6 content items referencing the same media - var relations = ServiceContext.RelationService.GetByChildId(m1.Id, Constants.Conventions.RelationTypes.RelatedMediaAlias).ToList(); + var relations = RelationService.GetByChildId(m1.Id, Constants.Conventions.RelationTypes.RelatedMediaAlias).ToList(); Assert.AreEqual(6, relations.Count); - var entities = ServiceContext.RelationService.GetParentEntitiesFromRelations(relations).ToList(); + var entities = RelationService.GetParentEntitiesFromRelations(relations).ToList(); Assert.AreEqual(6, entities.Count); } [Test] public void Can_Create_RelationType_Without_Name() { - var rs = ServiceContext.RelationService; + var rs = RelationService; IRelationType rt = new RelationType("Test", "repeatedEventOccurence", false, Constants.ObjectTypes.Document, Constants.ObjectTypes.Media); Assert.DoesNotThrow(() => rs.Save(rt)); //re-get - rt = ServiceContext.RelationService.GetRelationTypeById(rt.Id); + rt = RelationService.GetRelationTypeById(rt.Id); Assert.AreEqual("Test", rt.Name); Assert.AreEqual("repeatedEventOccurence", rt.Alias); @@ -117,13 +125,13 @@ namespace Umbraco.Tests.Services [Test] public void Create_Relation_Type_Without_Object_Types() { - var rs = ServiceContext.RelationService; + var rs = RelationService; IRelationType rt = new RelationType("repeatedEventOccurence", "repeatedEventOccurence", false, null, null); Assert.DoesNotThrow(() => rs.Save(rt)); //re-get - rt = ServiceContext.RelationService.GetRelationTypeById(rt.Id); + rt = RelationService.GetRelationTypeById(rt.Id); Assert.IsNull(rt.ChildObjectType); Assert.IsNull(rt.ParentObjectType); @@ -144,7 +152,7 @@ namespace Umbraco.Tests.Services var r = CreateAndSaveRelation("Test", "test"); // re-get - r = ServiceContext.RelationService.GetById(r.Id); + r = RelationService.GetById(r.Id); Assert.AreEqual(Constants.ObjectTypes.Document, r.ParentObjectType); Assert.AreEqual(Constants.ObjectTypes.Media, r.ChildObjectType); @@ -153,13 +161,13 @@ namespace Umbraco.Tests.Services [Test] public void Insert_Bulk_Relations() { - var rs = ServiceContext.RelationService; + var rs = RelationService; var newRelations = CreateRelations(10); Assert.IsTrue(newRelations.All(x => !x.HasIdentity)); - ServiceContext.RelationService.Save(newRelations); + RelationService.Save(newRelations); Assert.IsTrue(newRelations.All(x => x.HasIdentity)); } @@ -167,7 +175,7 @@ namespace Umbraco.Tests.Services [Test] public void Update_Bulk_Relations() { - var rs = ServiceContext.RelationService; + var rs = RelationService; var date = DateTime.Now.AddDays(-10); var newRelations = CreateRelations(10); @@ -175,10 +183,10 @@ namespace Umbraco.Tests.Services { r.CreateDate = date; r.UpdateDate = date; - } + } //insert - ServiceContext.RelationService.Save(newRelations); + RelationService.Save(newRelations); Assert.IsTrue(newRelations.All(x => x.UpdateDate == date)); var newDate = DateTime.Now.AddDays(-5); @@ -186,29 +194,29 @@ namespace Umbraco.Tests.Services r.UpdateDate = newDate; //update - ServiceContext.RelationService.Save(newRelations); + RelationService.Save(newRelations); Assert.IsTrue(newRelations.All(x => x.UpdateDate == newDate)); } private IRelation CreateAndSaveRelation(string name, string alias) { - var rs = ServiceContext.RelationService; + var rs = RelationService; var rt = new RelationType(name, alias, false, null, null); rs.Save(rt); var ct = MockedContentTypes.CreateBasicContentType(); - ServiceContext.ContentTypeService.Save(ct); + ContentTypeService.Save(ct); var mt = MockedContentTypes.CreateImageMediaType("img"); - ServiceContext.MediaTypeService.Save(mt); + MediaTypeService.Save(mt); var c1 = MockedContent.CreateBasicContent(ct); var c2 = MockedMedia.CreateMediaImage(mt, -1); - ServiceContext.ContentService.Save(c1); - ServiceContext.MediaService.Save(c2); + ContentService.Save(c1); + MediaService.Save(c2); var r = new Relation(c1.Id, c2.Id, rt); - ServiceContext.RelationService.Save(r); + RelationService.Save(r); return r; } @@ -220,23 +228,23 @@ namespace Umbraco.Tests.Services /// private IEnumerable CreateRelations(int count) { - var rs = ServiceContext.RelationService; + var rs = RelationService; var rtName = Guid.NewGuid().ToString(); var rt = new RelationType(rtName, rtName, false, null, null); rs.Save(rt); var ct = MockedContentTypes.CreateBasicContentType(); - ServiceContext.ContentTypeService.Save(ct); + ContentTypeService.Save(ct); var mt = MockedContentTypes.CreateImageMediaType("img"); - ServiceContext.MediaTypeService.Save(mt); + MediaTypeService.Save(mt); return Enumerable.Range(1, count).Select(index => { var c1 = MockedContent.CreateBasicContent(ct); var c2 = MockedMedia.CreateMediaImage(mt, -1); - ServiceContext.ContentService.Save(c1); - ServiceContext.MediaService.Save(c2); + ContentService.Save(c1); + MediaService.Save(c2); return new Relation(c1.Id, c2.Id, rt); }).ToList(); diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 87ab7e5fa1..1a0b32b3bd 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -264,7 +264,6 @@ - From 55db973e82a55a986b0720fb77d150adcacdb02f Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 8 Oct 2020 14:37:17 +0200 Subject: [PATCH 4/9] Introduced IRelationRepository.SaveBulk to use internally when performance is important. Fixed issue in RelationRepository.Save not populating Ids on LocalDB/SqlServer --- src/Umbraco.Core/Models/IRelation.cs | 58 ++++++++++++++++--- .../Repositories/IRelationRepository.cs | 6 ++ .../Persistence/Factories/RelationFactory.cs | 2 +- .../Implement/ContentRepositoryBase.cs | 2 +- .../Implement/RelationRepository.cs | 43 +++++++++++++- 5 files changed, 99 insertions(+), 12 deletions(-) diff --git a/src/Umbraco.Core/Models/IRelation.cs b/src/Umbraco.Core/Models/IRelation.cs index 6bd348d72f..3cdea02e32 100644 --- a/src/Umbraco.Core/Models/IRelation.cs +++ b/src/Umbraco.Core/Models/IRelation.cs @@ -4,37 +4,81 @@ using Umbraco.Core.Models.Entities; namespace Umbraco.Core.Models { - public interface IRelation : IEntity, IRememberBeingDirty + public interface IRelation : IRememberBeingDirty, IRelationReadOnly { + + /// + /// Gets or sets the integer identifier of the entity. + /// + new int Id { get; set; } + /// /// Gets or sets the Parent Id of the Relation (Source) /// [DataMember] - int ParentId { get; set; } + new int ParentId { get; set; } [DataMember] - Guid ParentObjectType { get; set; } + new Guid ParentObjectType { get; set; } /// /// Gets or sets the Child Id of the Relation (Destination) /// [DataMember] - int ChildId { get; set; } + new int ChildId { get; set; } [DataMember] - Guid ChildObjectType { get; set; } + new Guid ChildObjectType { get; set; } /// /// Gets or sets the for the Relation /// [DataMember] - IRelationType RelationType { get; set; } + new IRelationType RelationType { get; set; } /// /// Gets or sets a comment for the Relation /// [DataMember] - string Comment { get; set; } + new string Comment { get; set; } + + /// + /// Gets the Id of the that this Relation is based on. + /// + [IgnoreDataMember] + new int RelationTypeId { get; } + } + + public interface IRelationReadOnly : IEntity + { + /// + /// Gets the integer identifier of the entity. + /// + int Id { get; } + + /// + /// Gets the Parent Id of the Relation (Source) + /// + int ParentId { get; } + + Guid ParentObjectType { get; } + + /// + /// Gets or sets the Child Id of the Relation (Destination) + /// + int ChildId { get; } + + Guid ChildObjectType { get; } + + /// + /// Gets the for the Relation + /// + IRelationType RelationType { get; } + + /// + /// Gets a comment for the Relation + /// + string Comment { get; } /// /// Gets the Id of the that this Relation is based on. diff --git a/src/Umbraco.Core/Persistence/Repositories/IRelationRepository.cs b/src/Umbraco.Core/Persistence/Repositories/IRelationRepository.cs index fc1be20e6f..8f17b5f622 100644 --- a/src/Umbraco.Core/Persistence/Repositories/IRelationRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/IRelationRepository.cs @@ -17,6 +17,12 @@ namespace Umbraco.Core.Persistence.Repositories /// void Save(IEnumerable relations); + /// + /// Persist multiple at once but Ids are not returned on created relations + /// + /// + void SaveBulk(IEnumerable relations); + /// /// Deletes all relations for a parent for any specified relation type alias /// diff --git a/src/Umbraco.Infrastructure/Persistence/Factories/RelationFactory.cs b/src/Umbraco.Infrastructure/Persistence/Factories/RelationFactory.cs index d8f100cdbe..2adfe9627c 100644 --- a/src/Umbraco.Infrastructure/Persistence/Factories/RelationFactory.cs +++ b/src/Umbraco.Infrastructure/Persistence/Factories/RelationFactory.cs @@ -28,7 +28,7 @@ namespace Umbraco.Core.Persistence.Factories } } - public static RelationDto BuildDto(IRelation entity) + public static RelationDto BuildDto(IRelationReadOnly entity) { var dto = new RelationDto { diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs index b8edbd051a..e59acb0e81 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs @@ -984,7 +984,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement }).WhereNotNull(); // Save bulk relations - RelationRepository.Save(toSave); + RelationRepository.SaveBulk(toSave); } diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RelationRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RelationRepository.cs index 3767fa354c..88231d3658 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RelationRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RelationRepository.cs @@ -235,9 +235,11 @@ namespace Umbraco.Core.Persistence.Repositories.Implement }, RelationFactory.BuildDto); // value = DTO - // Use NPoco's own InsertBulk command which will automatically re-populate the new Ids on the entities, our own - // BulkInsertRecords does not cater for this. - Database.InsertBulk(entitiesAndDtos.Values); + + foreach (var dto in entitiesAndDtos.Values) + { + Database.Insert(dto); + } // All dtos now have IDs assigned foreach (var de in entitiesAndDtos) @@ -251,6 +253,41 @@ namespace Umbraco.Core.Persistence.Repositories.Implement } } + public void SaveBulk(IEnumerable relations) + { + foreach (var hasIdentityGroup in relations.GroupBy(r => r.HasIdentity)) + { + if (hasIdentityGroup.Key) + { + // Do updates, we can't really do a bulk update so this is still a 1 by 1 operation + // however we can bulk populate the object types. It might be possible to bulk update + // with SQL but would be pretty ugly and we're not really too worried about that for perf, + // it's the bulk inserts we care about. + foreach (var relation in hasIdentityGroup) + { + relation.UpdatingEntity(); + var dto = RelationFactory.BuildDto(relation); + Database.Update(dto); + } + } + else + { + // Do bulk inserts + var entitiesAndDtos = hasIdentityGroup.ToDictionary( + r => // key = entity + { + r.AddingEntity(); + return r; + }, + RelationFactory.BuildDto); // value = DTO + + + Database.InsertBulk(entitiesAndDtos.Values); + + } + } + } + public IEnumerable GetPagedRelationsByQuery(IQuery query, long pageIndex, int pageSize, out long totalRecords, Ordering ordering) { var sql = GetBaseQuery(false); From 731a189fbef3b49a7e37eceb4bbae60c5ac8b8c5 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 8 Oct 2020 14:54:42 +0200 Subject: [PATCH 5/9] Removed uncommented code --- .../Repositories/Implement/RelationTypeRepository.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RelationTypeRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RelationTypeRepository.cs index 8e40198bc5..398dd225ba 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RelationTypeRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RelationTypeRepository.cs @@ -50,10 +50,6 @@ namespace Umbraco.Core.Persistence.Repositories.Implement { var sql = GetBaseQuery(false); - // // should not happen due to the cache policy - // if (ids.Any()) - // throw new NotImplementedException(); - var dtos = Database.Fetch(sql); return dtos.Select(x => DtoToEntity(x)); From 05d8b0aaf8c3f569d89ff2c0bf2b0891f461dcd0 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Fri, 9 Oct 2020 09:32:32 +0200 Subject: [PATCH 6/9] Changed to use a ReadOnlyRelation model --- src/Umbraco.Core/Models/IRelation.cs | 59 +++---------------- src/Umbraco.Core/Models/ReadOnlyRelation.cs | 35 +++++++++++ .../Repositories/IRelationRepository.cs | 2 +- .../Persistence/Factories/RelationFactory.cs | 19 +++++- .../Implement/ContentRepositoryBase.cs | 5 +- .../Implement/RelationRepository.cs | 14 +---- src/Umbraco.Web.UI.NetCore/appsettings.json | 4 +- 7 files changed, 69 insertions(+), 69 deletions(-) create mode 100644 src/Umbraco.Core/Models/ReadOnlyRelation.cs diff --git a/src/Umbraco.Core/Models/IRelation.cs b/src/Umbraco.Core/Models/IRelation.cs index 3cdea02e32..2b975ba3ae 100644 --- a/src/Umbraco.Core/Models/IRelation.cs +++ b/src/Umbraco.Core/Models/IRelation.cs @@ -4,81 +4,37 @@ using Umbraco.Core.Models.Entities; namespace Umbraco.Core.Models { - public interface IRelation : IRememberBeingDirty, IRelationReadOnly + public interface IRelation : IEntity, IRememberBeingDirty { - - /// - /// Gets or sets the integer identifier of the entity. - /// - new int Id { get; set; } - /// /// Gets or sets the Parent Id of the Relation (Source) /// [DataMember] - new int ParentId { get; set; } + int ParentId { get; set; } [DataMember] - new Guid ParentObjectType { get; set; } + Guid ParentObjectType { get; set; } /// /// Gets or sets the Child Id of the Relation (Destination) /// [DataMember] - new int ChildId { get; set; } + int ChildId { get; set; } [DataMember] - new Guid ChildObjectType { get; set; } + Guid ChildObjectType { get; set; } /// /// Gets or sets the for the Relation /// [DataMember] - new IRelationType RelationType { get; set; } + IRelationType RelationType { get; set; } /// /// Gets or sets a comment for the Relation /// [DataMember] - new string Comment { get; set; } - - /// - /// Gets the Id of the that this Relation is based on. - /// - [IgnoreDataMember] - new int RelationTypeId { get; } - } - - public interface IRelationReadOnly : IEntity - { - /// - /// Gets the integer identifier of the entity. - /// - int Id { get; } - - /// - /// Gets the Parent Id of the Relation (Source) - /// - int ParentId { get; } - - Guid ParentObjectType { get; } - - /// - /// Gets or sets the Child Id of the Relation (Destination) - /// - int ChildId { get; } - - Guid ChildObjectType { get; } - - /// - /// Gets the for the Relation - /// - IRelationType RelationType { get; } - - /// - /// Gets a comment for the Relation - /// - string Comment { get; } + string Comment { get; set; } /// /// Gets the Id of the that this Relation is based on. @@ -86,4 +42,5 @@ namespace Umbraco.Core.Models [IgnoreDataMember] int RelationTypeId { get; } } + } diff --git a/src/Umbraco.Core/Models/ReadOnlyRelation.cs b/src/Umbraco.Core/Models/ReadOnlyRelation.cs new file mode 100644 index 0000000000..f2801a93ec --- /dev/null +++ b/src/Umbraco.Core/Models/ReadOnlyRelation.cs @@ -0,0 +1,35 @@ +using System; + +namespace Umbraco.Core.Models +{ + /// + /// A read only relation. Can be used to bulk save witch performs better than the normal save operation, + /// but do not populate Ids back to the model + /// + public class ReadOnlyRelation + { + public ReadOnlyRelation(int id, int parentId, int childId, int relationTypeId, DateTime createDate, string comment) + { + Id = id; + ParentId = parentId; + ChildId = childId; + RelationTypeId = relationTypeId; + CreateDate = createDate; + Comment = comment; + } + + public ReadOnlyRelation(int parentId, int childId, int relationTypeId): this(0, parentId, childId, relationTypeId, DateTime.Now, string.Empty) + { + + } + + public int Id { get; } + public int ParentId { get; } + public int ChildId { get; } + public int RelationTypeId { get; } + public DateTime CreateDate { get; } + public string Comment { get; } + + public bool HasIdentity => Id != 0; + } +} diff --git a/src/Umbraco.Core/Persistence/Repositories/IRelationRepository.cs b/src/Umbraco.Core/Persistence/Repositories/IRelationRepository.cs index 8f17b5f622..ca40848138 100644 --- a/src/Umbraco.Core/Persistence/Repositories/IRelationRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/IRelationRepository.cs @@ -21,7 +21,7 @@ namespace Umbraco.Core.Persistence.Repositories /// Persist multiple at once but Ids are not returned on created relations /// /// - void SaveBulk(IEnumerable relations); + void SaveBulk(IEnumerable relations); /// /// Deletes all relations for a parent for any specified relation type alias diff --git a/src/Umbraco.Infrastructure/Persistence/Factories/RelationFactory.cs b/src/Umbraco.Infrastructure/Persistence/Factories/RelationFactory.cs index 2adfe9627c..24d29cf608 100644 --- a/src/Umbraco.Infrastructure/Persistence/Factories/RelationFactory.cs +++ b/src/Umbraco.Infrastructure/Persistence/Factories/RelationFactory.cs @@ -28,7 +28,7 @@ namespace Umbraco.Core.Persistence.Factories } } - public static RelationDto BuildDto(IRelationReadOnly entity) + public static RelationDto BuildDto(IRelation entity) { var dto = new RelationDto { @@ -44,6 +44,23 @@ namespace Umbraco.Core.Persistence.Factories return dto; } + + public static RelationDto BuildDto(ReadOnlyRelation entity) + { + var dto = new RelationDto + { + ChildId = entity.ChildId, + Comment = string.IsNullOrEmpty(entity.Comment) ? string.Empty : entity.Comment, + Datetime = entity.CreateDate, + ParentId = entity.ParentId, + RelationType = entity.RelationTypeId + }; + + if (entity.HasIdentity) + dto.Id = entity.Id; + + return dto; + } } } diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs index e59acb0e81..f544d9c99b 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs @@ -980,12 +980,11 @@ namespace Umbraco.Core.Persistence.Repositories.Implement if (!keyToIds.TryGetValue(guid, out var id)) return null; // This shouldn't happen! - return new Relation(entity.Id, id, relationType); + return new ReadOnlyRelation(entity.Id, id, relationType.Id); }).WhereNotNull(); - // Save bulk relations + // Save bulk relations< RelationRepository.SaveBulk(toSave); - } private class NodeIdKey diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RelationRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RelationRepository.cs index 88231d3658..21b4ce5911 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RelationRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RelationRepository.cs @@ -253,7 +253,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement } } - public void SaveBulk(IEnumerable relations) + public void SaveBulk(IEnumerable relations) { foreach (var hasIdentityGroup in relations.GroupBy(r => r.HasIdentity)) { @@ -265,7 +265,6 @@ namespace Umbraco.Core.Persistence.Repositories.Implement // it's the bulk inserts we care about. foreach (var relation in hasIdentityGroup) { - relation.UpdatingEntity(); var dto = RelationFactory.BuildDto(relation); Database.Update(dto); } @@ -273,16 +272,9 @@ namespace Umbraco.Core.Persistence.Repositories.Implement else { // Do bulk inserts - var entitiesAndDtos = hasIdentityGroup.ToDictionary( - r => // key = entity - { - r.AddingEntity(); - return r; - }, - RelationFactory.BuildDto); // value = DTO + var dtos = hasIdentityGroup.Select(RelationFactory.BuildDto); - - Database.InsertBulk(entitiesAndDtos.Values); + Database.InsertBulk(dtos); } } diff --git a/src/Umbraco.Web.UI.NetCore/appsettings.json b/src/Umbraco.Web.UI.NetCore/appsettings.json index 70e3d6376d..3b241a4173 100644 --- a/src/Umbraco.Web.UI.NetCore/appsettings.json +++ b/src/Umbraco.Web.UI.NetCore/appsettings.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "umbracoDbDSN": "" + "umbracoDbDSN": "Server=(LocalDB)\\Umbraco;Database=NetCore;Integrated Security=true" }, "Serilog": { "MinimumLevel": { @@ -71,4 +71,4 @@ } } } -} +} \ No newline at end of file From e69f3d02de67b270eee12711994a670217dda099 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Fri, 9 Oct 2020 09:34:44 +0200 Subject: [PATCH 7/9] Clean up --- src/Umbraco.Core/Models/IRelation.cs | 1 - .../Persistence/Factories/RelationFactory.cs | 4 ++-- src/Umbraco.Web.UI.NetCore/appsettings.json | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Core/Models/IRelation.cs b/src/Umbraco.Core/Models/IRelation.cs index 2b975ba3ae..6bd348d72f 100644 --- a/src/Umbraco.Core/Models/IRelation.cs +++ b/src/Umbraco.Core/Models/IRelation.cs @@ -42,5 +42,4 @@ namespace Umbraco.Core.Models [IgnoreDataMember] int RelationTypeId { get; } } - } diff --git a/src/Umbraco.Infrastructure/Persistence/Factories/RelationFactory.cs b/src/Umbraco.Infrastructure/Persistence/Factories/RelationFactory.cs index 24d29cf608..f4117cc358 100644 --- a/src/Umbraco.Infrastructure/Persistence/Factories/RelationFactory.cs +++ b/src/Umbraco.Infrastructure/Persistence/Factories/RelationFactory.cs @@ -28,7 +28,7 @@ namespace Umbraco.Core.Persistence.Factories } } - public static RelationDto BuildDto(IRelation entity) + public static RelationDto BuildDto(IRelation entity) { var dto = new RelationDto { @@ -44,7 +44,7 @@ namespace Umbraco.Core.Persistence.Factories return dto; } - + public static RelationDto BuildDto(ReadOnlyRelation entity) { var dto = new RelationDto diff --git a/src/Umbraco.Web.UI.NetCore/appsettings.json b/src/Umbraco.Web.UI.NetCore/appsettings.json index 3b241a4173..70e3d6376d 100644 --- a/src/Umbraco.Web.UI.NetCore/appsettings.json +++ b/src/Umbraco.Web.UI.NetCore/appsettings.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "umbracoDbDSN": "Server=(LocalDB)\\Umbraco;Database=NetCore;Integrated Security=true" + "umbracoDbDSN": "" }, "Serilog": { "MinimumLevel": { @@ -71,4 +71,4 @@ } } } -} \ No newline at end of file +} From 424c3b821e95cd207fda4e1d43ecb70237ab3bde Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Fri, 9 Oct 2020 09:35:30 +0200 Subject: [PATCH 8/9] Clean up --- .../Repositories/Implement/ContentRepositoryBase.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs index f544d9c99b..a0a26ea428 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs @@ -983,8 +983,9 @@ namespace Umbraco.Core.Persistence.Repositories.Implement return new ReadOnlyRelation(entity.Id, id, relationType.Id); }).WhereNotNull(); - // Save bulk relations< + // Save bulk relations RelationRepository.SaveBulk(toSave); + } private class NodeIdKey From 928f42be2eb9a2ae41838ec23cd695bf6c257414 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Sun, 11 Oct 2020 21:08:21 +0200 Subject: [PATCH 9/9] Updated tests after merge Signed-off-by: Bjarke Berg --- .../Builders/MediaBuilder.cs | 26 +++++++++++++++ .../Builders/MemberBuilder.cs | 27 +++++++++++++++ .../Repositories/RelationRepositoryTest.cs | 29 ++++++++-------- .../Services/RelationServiceTests.cs | 33 ++++++++++--------- 4 files changed, 86 insertions(+), 29 deletions(-) diff --git a/src/Umbraco.Tests.Common/Builders/MediaBuilder.cs b/src/Umbraco.Tests.Common/Builders/MediaBuilder.cs index 43229e7401..f7beb759bb 100644 --- a/src/Umbraco.Tests.Common/Builders/MediaBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/MediaBuilder.cs @@ -3,6 +3,7 @@ using Umbraco.Core.Models; using Umbraco.Tests.Common.Builders.Interfaces; using Umbraco.Tests.Common.Builders.Extensions; using Umbraco.Core; +using Umbraco.Tests.Testing; namespace Umbraco.Tests.Common.Builders { @@ -221,5 +222,30 @@ namespace Umbraco.Tests.Common.Builders get => _parentId; set => _parentId = value; } + + public static IMedia CreateSimpleMedia(IMediaType contentType, string name, int parentId) + { + var media = new MediaBuilder() + .WithMediaType(contentType) + .WithName(name) + .WithParentId(parentId) + .WithCreatorId(0) + .Build(); + ; + + object obj = + new + { + title = name + " Subpage", + bodyText = "This is a subpage", + author = "John Doe" + }; + + media.PropertyValues(obj); + + media.ResetDirtyProperties(false); + + return media; + } } } diff --git a/src/Umbraco.Tests.Common/Builders/MemberBuilder.cs b/src/Umbraco.Tests.Common/Builders/MemberBuilder.cs index 3ea051849b..06e94f92f2 100644 --- a/src/Umbraco.Tests.Common/Builders/MemberBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/MemberBuilder.cs @@ -178,6 +178,33 @@ namespace Umbraco.Tests.Common.Builders return member; } + public static IEnumerable CreateSimpleMembers(IMemberType memberType, int amount, Action onCreating = null) + { + var list = new List(); + + for (int i = 0; i < amount; i++) + { + var name = "Member No-" + i; + + var builder = new MemberBuilder() + .WithMemberType(memberType) + .WithName(name) + .WithEmail("test" + i + "@test.com") + .WithLogin("test" + i, "test" + i); + + + builder = builder + .AddPropertyData() + .WithKeyValue("title", name + " member" + i) + .WithKeyValue("bodyText", "This is a subpage" + i) + .WithKeyValue("author", "John Doe" + i) + .Done(); + + list.Add(builder.Build()); + } + + return list; + } public static Member CreateSimpleMember(IMemberType memberType, string name, string email, string password, string username, Guid? key = null) { var builder = new MemberBuilder() diff --git a/src/Umbraco.Tests.Integration/Persistence/Repositories/RelationRepositoryTest.cs b/src/Umbraco.Tests.Integration/Persistence/Repositories/RelationRepositoryTest.cs index 804c6fef90..63e4ada345 100644 --- a/src/Umbraco.Tests.Integration/Persistence/Repositories/RelationRepositoryTest.cs +++ b/src/Umbraco.Tests.Integration/Persistence/Repositories/RelationRepositoryTest.cs @@ -13,6 +13,7 @@ using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Persistence.Repositories.Implement; using Umbraco.Core.Scoping; using Umbraco.Core.Services; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; @@ -225,9 +226,9 @@ namespace Umbraco.Tests.Persistence.Repositories public void Get_Paged_Parent_Child_Entities_With_Same_Entity_Relation() { //Create a media item and create a relationship between itself (parent -> child) - var imageType = MockedContentTypes.CreateImageMediaType("myImage"); + var imageType = MediaTypeBuilder.CreateImageMediaType("myImage"); MediaTypeService.Save(imageType); - var media = MockedMedia.CreateMediaImage(imageType, -1); + var media = MediaBuilder.CreateMediaImage(imageType, -1); MediaService.Save(media); var relType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedMediaAlias); RelationService.Relate(media.Id, media.Id, relType); @@ -291,30 +292,30 @@ namespace Umbraco.Tests.Persistence.Repositories { //Create content createdContent = new List(); - var contentType = MockedContentTypes.CreateBasicContentType("blah"); + var contentType = ContentTypeBuilder.CreateBasicContentType("blah"); ContentTypeService.Save(contentType); for (int i = 0; i < 3; i++) { - var c1 = MockedContent.CreateBasicContent(contentType); + var c1 = ContentBuilder.CreateBasicContent(contentType); ContentService.Save(c1); createdContent.Add(c1); } //Create media createdMedia = new List(); - var imageType = MockedContentTypes.CreateImageMediaType("myImage"); + var imageType = MediaTypeBuilder.CreateImageMediaType("myImage"); MediaTypeService.Save(imageType); for (int i = 0; i < 3; i++) { - var c1 = MockedMedia.CreateMediaImage(imageType, -1); + var c1 = MediaBuilder.CreateMediaImage(imageType, -1); MediaService.Save(c1); createdMedia.Add(c1); } // Create members - var memberType = MockedContentTypes.CreateSimpleMemberType("simple"); + var memberType = MemberTypeBuilder.CreateSimpleMemberType("simple"); MemberTypeService.Save(memberType); - createdMembers = MockedMember.CreateSimpleMember(memberType, 3).ToList(); + createdMembers = MemberBuilder.CreateSimpleMembers(memberType, 3).ToList(); MemberService.Save(createdMembers); var relType = RelationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelatedMediaAlias); @@ -438,21 +439,23 @@ namespace Umbraco.Tests.Persistence.Repositories relationTypeRepository.Save(_relateContent); relationTypeRepository.Save(_relateContentType); + var template = TemplateBuilder.CreateTextPageTemplate(); + FileService.SaveTemplate(template); //Create and Save ContentType "umbTextpage" -> (NodeDto.NodeIdSeed) - _contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage", "Textpage"); - FileService.SaveTemplate(_contentType.DefaultTemplate); // else, FK violation on contentType! + _contentType = ContentTypeBuilder.CreateSimpleContentType("umbTextpage", "Textpage", defaultTemplateId: template.Id); + ContentTypeService.Save(_contentType); //Create and Save Content "Homepage" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 1) - _textpage = MockedContent.CreateSimpleContent(_contentType); + _textpage = ContentBuilder.CreateSimpleContent(_contentType); ContentService.Save(_textpage, 0); //Create and Save Content "Text Page 1" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 2) - _subpage = MockedContent.CreateSimpleContent(_contentType, "Text Page 1", _textpage.Id); + _subpage = ContentBuilder.CreateSimpleContent(_contentType, "Text Page 1", _textpage.Id); ContentService.Save(_subpage, 0); //Create and Save Content "Text Page 1" based on "umbTextpage" -> (NodeDto.NodeIdSeed + 3) - _subpage2 = MockedContent.CreateSimpleContent(_contentType, "Text Page 2", _textpage.Id); + _subpage2 = ContentBuilder.CreateSimpleContent(_contentType, "Text Page 2", _textpage.Id); ContentService.Save(_subpage2, 0); _relation = new Relation(_textpage.Id, _subpage.Id, _relateContent) { Comment = string.Empty }; diff --git a/src/Umbraco.Tests.Integration/Services/RelationServiceTests.cs b/src/Umbraco.Tests.Integration/Services/RelationServiceTests.cs index 0c5b3c8758..9fe4867fc2 100644 --- a/src/Umbraco.Tests.Integration/Services/RelationServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/RelationServiceTests.cs @@ -7,6 +7,7 @@ using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; @@ -30,22 +31,22 @@ namespace Umbraco.Tests.Services { //Create content var createdContent = new List(); - var contentType = MockedContentTypes.CreateBasicContentType("blah"); + var contentType = ContentTypeBuilder.CreateBasicContentType("blah"); ContentTypeService.Save(contentType); for (int i = 0; i < 3; i++) { - var c1 = MockedContent.CreateBasicContent(contentType); + var c1 = ContentBuilder.CreateBasicContent(contentType); ContentService.Save(c1); createdContent.Add(c1); } //Create media var createdMedia = new List(); - var imageType = MockedContentTypes.CreateImageMediaType("myImage"); + var imageType = MediaTypeBuilder.CreateImageMediaType("myImage"); MediaTypeService.Save(imageType); for (int i = 0; i < 3; i++) { - var c1 = MockedMedia.CreateMediaImage(imageType, -1); + var c1 = MediaBuilder.CreateMediaImage(imageType, -1); MediaService.Save(c1); createdMedia.Add(c1); } @@ -75,18 +76,18 @@ namespace Umbraco.Tests.Services [Test] public void Return_List_Of_Content_Items_Where_Media_Item_Referenced() { - var mt = MockedContentTypes.CreateSimpleMediaType("testMediaType", "Test Media Type"); + var mt = MediaTypeBuilder.CreateSimpleMediaType("testMediaType", "Test Media Type"); MediaTypeService.Save(mt); - var m1 = MockedMedia.CreateSimpleMedia(mt, "hello 1", -1); + var m1 = MediaBuilder.CreateSimpleMedia(mt, "hello 1", -1); MediaService.Save(m1); - var ct = MockedContentTypes.CreateTextPageContentType("richTextTest"); + var ct = ContentTypeBuilder.CreateTextPageContentType("richTextTest"); ct.AllowedTemplates = Enumerable.Empty(); ContentTypeService.Save(ct); void createContentWithMediaRefs() { - var content = MockedContent.CreateTextpageContent(ct, "my content 2", -1); + var content = ContentBuilder.CreateTextpageContent(ct, "my content 2", -1); //'bodyText' is a property with a RTE property editor which we knows automatically tracks relations content.Properties["bodyText"].SetValue(@"

@@ -204,14 +205,14 @@ namespace Umbraco.Tests.Services var rt = new RelationType(name, alias, false, null, null); rs.Save(rt); - var ct = MockedContentTypes.CreateBasicContentType(); + var ct = ContentTypeBuilder.CreateBasicContentType(); ContentTypeService.Save(ct); - var mt = MockedContentTypes.CreateImageMediaType("img"); + var mt = MediaTypeBuilder.CreateImageMediaType("img"); MediaTypeService.Save(mt); - var c1 = MockedContent.CreateBasicContent(ct); - var c2 = MockedMedia.CreateMediaImage(mt, -1); + var c1 = ContentBuilder.CreateBasicContent(ct); + var c2 = MediaBuilder.CreateMediaImage(mt, -1); ContentService.Save(c1); MediaService.Save(c2); @@ -233,16 +234,16 @@ namespace Umbraco.Tests.Services var rt = new RelationType(rtName, rtName, false, null, null); rs.Save(rt); - var ct = MockedContentTypes.CreateBasicContentType(); + var ct = ContentTypeBuilder.CreateBasicContentType(); ContentTypeService.Save(ct); - var mt = MockedContentTypes.CreateImageMediaType("img"); + var mt = MediaTypeBuilder.CreateImageMediaType("img"); MediaTypeService.Save(mt); return Enumerable.Range(1, count).Select(index => { - var c1 = MockedContent.CreateBasicContent(ct); - var c2 = MockedMedia.CreateMediaImage(mt, -1); + var c1 = ContentBuilder.CreateBasicContent(ct); + var c2 = MediaBuilder.CreateMediaImage(mt, -1); ContentService.Save(c1); MediaService.Save(c2);