From 7e77feab1e0ed9b0716f79bd26a241f733fcbf3a Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 21 Oct 2020 13:47:52 +0200 Subject: [PATCH] Migrated ContentTypeServiceVariantsTests.cs --- .../ContentTypeServiceVariantsTests.cs | 456 ++++++++---------- src/Umbraco.Tests/Umbraco.Tests.csproj | 4 - 2 files changed, 196 insertions(+), 264 deletions(-) rename src/{Umbraco.Tests => Umbraco.Tests.Integration/Umbraco.Infrastructure}/Services/ContentTypeServiceVariantsTests.cs (76%) diff --git a/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentTypeServiceVariantsTests.cs similarity index 76% rename from src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs rename to src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentTypeServiceVariantsTests.cs index 30d68d92e0..7552ff4c41 100644 --- a/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentTypeServiceVariantsTests.cs @@ -2,99 +2,31 @@ using System.Collections.Generic; using System.Linq; using System.Threading; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; -using Moq; using NUnit.Framework; -using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration.Models; -using Umbraco.Core.Hosting; using Umbraco.Core.Models; -using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Dtos; -using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Services; -using Umbraco.Core.Strings; using Umbraco.Core.Sync; -using Umbraco.Tests.TestHelpers; -using Umbraco.Tests.TestHelpers.Entities; +using Umbraco.Tests.Common.Builders; +using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.Testing; using Umbraco.Web.PublishedCache; -using Umbraco.Web.PublishedCache.NuCache; -using Umbraco.Web.PublishedCache.NuCache.DataSource; namespace Umbraco.Tests.Services { [TestFixture] [Apartment(ApartmentState.STA)] - [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, PublishedRepositoryEvents = true, WithApplication = true)] - public class ContentTypeServiceVariantsTests : TestWithSomeContentBase + [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, PublishedRepositoryEvents = true)] + public class ContentTypeServiceVariantsTests : UmbracoIntegrationTest { - protected override void Compose() - { - base.Compose(); - - // pfew - see note in ScopedNuCacheTests? - Composition.RegisterUnique(); - Composition.RegisterUnique(f => Mock.Of()); - Composition.WithCollectionBuilder() - .Add(() => Composition.TypeLoader.GetCacheRefreshers()); - } - - protected override IPublishedSnapshotService CreatePublishedSnapshotService(GlobalSettings globalSettings = null) - { - var options = new PublishedSnapshotServiceOptions { IgnoreLocalDb = true }; - var publishedSnapshotAccessor = new UmbracoContextPublishedSnapshotAccessor(Umbraco.Web.Composing.Current.UmbracoContextAccessor); - var runtimeStateMock = new Mock(); - runtimeStateMock.Setup(x => x.Level).Returns(() => RuntimeLevel.Run); - - var contentTypeFactory = Factory.GetInstance(); - var documentRepository = Factory.GetInstance(); - var mediaRepository = Mock.Of(); - var memberRepository = Mock.Of(); - var hostingEnvironment = Mock.Of(); - - var typeFinder = TestHelper.GetTypeFinder(); - - var nuCacheSettings = new NuCacheSettings(); - - return new PublishedSnapshotService( - options, - null, - runtimeStateMock.Object, - ServiceContext, - contentTypeFactory, - publishedSnapshotAccessor, - Mock.Of(), - ProfilingLogger, - NullLoggerFactory.Instance, - ScopeProvider, - documentRepository, mediaRepository, memberRepository, - DefaultCultureAccessor, - new DatabaseDataSource(Mock.Of>()), - Microsoft.Extensions.Options.Options.Create(globalSettings ?? new GlobalSettings()), - Factory.GetInstance(), - Mock.Of(), - new UrlSegmentProviderCollection(new[] { new DefaultUrlSegmentProvider(ShortStringHelper) }), - hostingEnvironment, - Mock.Of(), - IOHelper, - Microsoft.Extensions.Options.Options.Create(nuCacheSettings)); - } - - public class LocalServerMessenger : ServerMessengerBase - { - public LocalServerMessenger() - : base(false) - { } - - protected override void DeliverRemote(ICacheRefresher refresher, MessageType messageType, IEnumerable ids = null, string json = null) - { - throw new NotImplementedException(); - } - } + private ISqlContext SqlContext => GetRequiredService(); + private IContentService ContentService => GetRequiredService(); + private IContentTypeService ContentTypeService => GetRequiredService(); + private IRedirectUrlService RedirectUrlService => GetRequiredService(); + private ILocalizationService LocalizationService => GetRequiredService(); private void AssertJsonStartsWith(int id, string expected) { @@ -134,38 +66,38 @@ namespace Umbraco.Tests.Services [TestCase(ContentVariation.CultureAndSegment, ContentVariation.CultureAndSegment, false)] public void Change_Content_Type_Variation_Clears_Redirects(ContentVariation startingContentTypeVariation, ContentVariation changedContentTypeVariation, bool shouldUrlRedirectsBeCleared) { - var contentType = MockedContentTypes.CreateBasicContentType(); + var contentType = ContentTypeBuilder.CreateBasicContentType(); contentType.Variations = startingContentTypeVariation; - ServiceContext.ContentTypeService.Save(contentType); - var contentType2 = MockedContentTypes.CreateBasicContentType("test"); - ServiceContext.ContentTypeService.Save(contentType2); + ContentTypeService.Save(contentType); + var contentType2 = ContentTypeBuilder.CreateBasicContentType("test"); + ContentTypeService.Save(contentType2); //create some content of this content type - IContent doc = MockedContent.CreateBasicContent(contentType); + IContent doc = ContentBuilder.CreateBasicContent(contentType); doc.Name = "Hello1"; if(startingContentTypeVariation.HasFlag(ContentVariation.Culture)) { doc.SetCultureName(doc.Name, "en-US"); } - ServiceContext.ContentService.Save(doc); + ContentService.Save(doc); - IContent doc2 = MockedContent.CreateBasicContent(contentType2); - ServiceContext.ContentService.Save(doc2); + IContent doc2 = ContentBuilder.CreateBasicContent(contentType2); + ContentService.Save(doc2); - ServiceContext.RedirectUrlService.Register("hello/world", doc.Key); - ServiceContext.RedirectUrlService.Register("hello2/world2", doc2.Key); + RedirectUrlService.Register("hello/world", doc.Key); + RedirectUrlService.Register("hello2/world2", doc2.Key); // These 2 assertions should probably be moved to a test for the Register() method? - Assert.AreEqual(1, ServiceContext.RedirectUrlService.GetContentRedirectUrls(doc.Key).Count()); - Assert.AreEqual(1, ServiceContext.RedirectUrlService.GetContentRedirectUrls(doc2.Key).Count()); + Assert.AreEqual(1, RedirectUrlService.GetContentRedirectUrls(doc.Key).Count()); + Assert.AreEqual(1, RedirectUrlService.GetContentRedirectUrls(doc2.Key).Count()); //change variation contentType.Variations = changedContentTypeVariation; - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); var expectedRedirectUrlCount = shouldUrlRedirectsBeCleared ? 0 : 1; - Assert.AreEqual(expectedRedirectUrlCount, ServiceContext.RedirectUrlService.GetContentRedirectUrls(doc.Key).Count()); - Assert.AreEqual(1, ServiceContext.RedirectUrlService.GetContentRedirectUrls(doc2.Key).Count()); + Assert.AreEqual(expectedRedirectUrlCount, RedirectUrlService.GetContentRedirectUrls(doc.Key).Count()); + Assert.AreEqual(1, RedirectUrlService.GetContentRedirectUrls(doc2.Key).Count()); } [TestCase(ContentVariation.Nothing, ContentVariation.Culture)] @@ -174,19 +106,19 @@ namespace Umbraco.Tests.Services [TestCase(ContentVariation.Segment, ContentVariation.CultureAndSegment)] public void Change_Content_Type_From_No_Culture_To_Culture(ContentVariation from, ContentVariation to) { - var contentType = MockedContentTypes.CreateBasicContentType(); + var contentType = ContentTypeBuilder.CreateBasicContentType(); contentType.Variations = from; var properties = CreatePropertyCollection(("title", from)); contentType.PropertyGroups.Add(new PropertyGroup(properties) { Name = "Content" }); - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); //create some content of this content type - IContent doc = MockedContent.CreateBasicContent(contentType); + IContent doc = ContentBuilder.CreateBasicContent(contentType); doc.Name = "Hello1"; doc.SetValue("title", "hello world"); - ServiceContext.ContentService.Save(doc); + ContentService.Save(doc); - doc = ServiceContext.ContentService.GetById(doc.Id); //re-get + doc = ContentService.GetById(doc.Id); //re-get Assert.AreEqual("Hello1", doc.Name); Assert.AreEqual("hello world", doc.GetValue("title")); @@ -195,10 +127,10 @@ namespace Umbraco.Tests.Services //change the content type to be variant, we will also update the name here to detect the copy changes doc.Name = "Hello2"; - ServiceContext.ContentService.Save(doc); + ContentService.Save(doc); contentType.Variations = to; - ServiceContext.ContentTypeService.Save(contentType); - doc = ServiceContext.ContentService.GetById(doc.Id); //re-get + ContentTypeService.Save(contentType); + doc = ContentService.GetById(doc.Id); //re-get Assert.AreEqual("Hello2", doc.GetCultureName("en-US")); Assert.AreEqual("hello world", doc.GetValue("title")); //We are not checking against en-US here because properties will remain invariant @@ -207,10 +139,10 @@ namespace Umbraco.Tests.Services //change back property type to be invariant, we will also update the name here to detect the copy changes doc.SetCultureName("Hello3", "en-US"); - ServiceContext.ContentService.Save(doc); + ContentService.Save(doc); contentType.Variations = from; - ServiceContext.ContentTypeService.Save(contentType); - doc = ServiceContext.ContentService.GetById(doc.Id); //re-get + ContentTypeService.Save(contentType); + doc = ContentService.GetById(doc.Id); //re-get Assert.AreEqual("Hello3", doc.Name); Assert.AreEqual("hello world", doc.GetValue("title")); @@ -224,19 +156,19 @@ namespace Umbraco.Tests.Services [TestCase(ContentVariation.CultureAndSegment, ContentVariation.Segment)] public void Change_Content_Type_From_Culture_To_No_Culture(ContentVariation startingContentTypeVariation, ContentVariation changeContentTypeVariationTo) { - var contentType = MockedContentTypes.CreateBasicContentType(); + var contentType = ContentTypeBuilder.CreateBasicContentType(); contentType.Variations = startingContentTypeVariation; var properties = CreatePropertyCollection(("title", startingContentTypeVariation)); contentType.PropertyGroups.Add(new PropertyGroup(properties) { Name = "Content" }); - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); //create some content of this content type - IContent doc = MockedContent.CreateBasicContent(contentType); + IContent doc = ContentBuilder.CreateBasicContent(contentType); doc.SetCultureName("Hello1", "en-US"); doc.SetValue("title", "hello world", "en-US"); - ServiceContext.ContentService.Save(doc); + ContentService.Save(doc); - doc = ServiceContext.ContentService.GetById(doc.Id); //re-get + doc = ContentService.GetById(doc.Id); //re-get Assert.AreEqual("Hello1", doc.GetCultureName("en-US")); Assert.AreEqual("hello world", doc.GetValue("title", "en-US")); Assert.IsTrue(doc.Edited); @@ -244,10 +176,10 @@ namespace Umbraco.Tests.Services //change the content type to be invariant, we will also update the name here to detect the copy changes doc.SetCultureName("Hello2", "en-US"); - ServiceContext.ContentService.Save(doc); + ContentService.Save(doc); contentType.Variations = changeContentTypeVariationTo; - ServiceContext.ContentTypeService.Save(contentType); - doc = ServiceContext.ContentService.GetById(doc.Id); //re-get + ContentTypeService.Save(contentType); + doc = ContentService.GetById(doc.Id); //re-get Assert.AreEqual("Hello2", doc.Name); Assert.AreEqual("hello world", doc.GetValue("title")); @@ -256,10 +188,10 @@ namespace Umbraco.Tests.Services //change back property type to be variant, we will also update the name here to detect the copy changes doc.Name = "Hello3"; - ServiceContext.ContentService.Save(doc); + ContentService.Save(doc); contentType.Variations = startingContentTypeVariation; - ServiceContext.ContentTypeService.Save(contentType); - doc = ServiceContext.ContentService.GetById(doc.Id); //re-get + ContentTypeService.Save(contentType); + doc = ContentService.GetById(doc.Id); //re-get //at this stage all property types were switched to invariant so even though the variant value //exists it will not be returned because the property type is invariant, @@ -271,8 +203,8 @@ namespace Umbraco.Tests.Services //we can now switch the property type to be variant and the value can be returned again contentType.PropertyTypes.First().Variations = startingContentTypeVariation; - ServiceContext.ContentTypeService.Save(contentType); - doc = ServiceContext.ContentService.GetById(doc.Id); //re-get + ContentTypeService.Save(contentType); + doc = ContentService.GetById(doc.Id); //re-get Assert.AreEqual("Hello3", doc.GetCultureName("en-US")); Assert.AreEqual("hello world", doc.GetValue("title", "en-US")); @@ -298,9 +230,9 @@ namespace Umbraco.Tests.Services [TestCase(ContentVariation.CultureAndSegment, ContentVariation.CultureAndSegment)] public void Preserve_Content_Name_After_Content_Type_Variation_Change(ContentVariation contentTypeVariationFrom, ContentVariation contentTypeVariationTo) { - var contentType = MockedContentTypes.CreateBasicContentType(); + var contentType = ContentTypeBuilder.CreateBasicContentType(); contentType.Variations = contentTypeVariationFrom; - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); var invariantContentName = "Content Invariant"; @@ -312,12 +244,12 @@ namespace Umbraco.Tests.Services var globalSettings = new GlobalSettings(); - ServiceContext.LocalizationService.Save(new Language(globalSettings, nlCulture)); + LocalizationService.Save(new Language(globalSettings, nlCulture)); var includeCultureNames = contentType.Variations.HasFlag(ContentVariation.Culture); // Create some content of this content type - IContent doc = MockedContent.CreateBasicContent(contentType); + IContent doc = ContentBuilder.CreateBasicContent(contentType); doc.Name = invariantContentName; if (includeCultureNames) @@ -330,15 +262,15 @@ namespace Umbraco.Tests.Services Assert.Throws(() => doc.SetCultureName(nlContentName, nlCulture)); } - ServiceContext.ContentService.Save(doc); - doc = ServiceContext.ContentService.GetById(doc.Id); + ContentService.Save(doc); + doc = ContentService.GetById(doc.Id); AssertAll(); // Change variation contentType.Variations = contentTypeVariationTo; - ServiceContext.ContentService.Save(doc); - doc = ServiceContext.ContentService.GetById(doc.Id); + ContentService.Save(doc); + doc = ContentService.GetById(doc.Id); AssertAll(); @@ -378,16 +310,16 @@ namespace Umbraco.Tests.Services [TestCase(ContentVariation.CultureAndSegment, ContentVariation.CultureAndSegment)] public void Verify_If_Property_Type_Variation_Is_Correctly_Corrected_When_Content_Type_Is_Updated(ContentVariation contentTypeVariation, ContentVariation propertyTypeVariation) { - var contentType = MockedContentTypes.CreateBasicContentType(); + var contentType = ContentTypeBuilder.CreateBasicContentType(); // We test an updated content type so it has to be saved first. - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); // Update it contentType.Variations = contentTypeVariation; var properties = CreatePropertyCollection(("title", propertyTypeVariation)); contentType.PropertyGroups.Add(new PropertyGroup(properties) { Name = "Content" }); - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); // Check if property type variations have been updated correctly Assert.AreEqual(properties.First().Variations, contentTypeVariation & propertyTypeVariation); @@ -399,28 +331,28 @@ namespace Umbraco.Tests.Services [TestCase(ContentVariation.Segment, ContentVariation.CultureAndSegment)] public void Change_Property_Type_From_Invariant_Variant(ContentVariation invariant, ContentVariation variant) { - var contentType = MockedContentTypes.CreateBasicContentType(); + var contentType = ContentTypeBuilder.CreateBasicContentType(); // content type supports all variations contentType.Variations = ContentVariation.Culture | ContentVariation.Segment; var properties = CreatePropertyCollection(("title", invariant)); contentType.PropertyGroups.Add(new PropertyGroup(properties) { Name = "Content" }); - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); //create some content of this content type - IContent doc = MockedContent.CreateBasicContent(contentType); + IContent doc = ContentBuilder.CreateBasicContent(contentType); doc.SetCultureName("Home", "en-US"); doc.SetValue("title", "hello world"); - ServiceContext.ContentService.Save(doc); + ContentService.Save(doc); - doc = ServiceContext.ContentService.GetById(doc.Id); //re-get + doc = ContentService.GetById(doc.Id); //re-get Assert.AreEqual("hello world", doc.GetValue("title")); Assert.IsTrue(doc.IsCultureEdited("en-US")); //invariant prop changes show up on default lang Assert.IsTrue(doc.Edited); //change the property type to be variant contentType.PropertyTypes.First().Variations = variant; - ServiceContext.ContentTypeService.Save(contentType); - doc = ServiceContext.ContentService.GetById(doc.Id); //re-get + ContentTypeService.Save(contentType); + doc = ContentService.GetById(doc.Id); //re-get Assert.AreEqual("hello world", doc.GetValue("title", "en-US")); Assert.IsTrue(doc.IsCultureEdited("en-US")); @@ -428,8 +360,8 @@ namespace Umbraco.Tests.Services //change back property type to be invariant contentType.PropertyTypes.First().Variations = invariant; - ServiceContext.ContentTypeService.Save(contentType); - doc = ServiceContext.ContentService.GetById(doc.Id); //re-get + ContentTypeService.Save(contentType); + doc = ContentService.GetById(doc.Id); //re-get Assert.AreEqual("hello world", doc.GetValue("title")); Assert.IsTrue(doc.IsCultureEdited("en-US")); //invariant prop changes show up on default lang @@ -443,32 +375,32 @@ namespace Umbraco.Tests.Services public void Change_Property_Type_From_Variant_Invariant(ContentVariation variant, ContentVariation invariant) { //create content type with a property type that varies by culture - var contentType = MockedContentTypes.CreateBasicContentType(); + var contentType = ContentTypeBuilder.CreateBasicContentType(); // content type supports all variations contentType.Variations = ContentVariation.Culture | ContentVariation.Segment; var properties = CreatePropertyCollection(("title", variant)); contentType.PropertyGroups.Add(new PropertyGroup(properties) { Name = "Content" }); - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); //create some content of this content type - IContent doc = MockedContent.CreateBasicContent(contentType); + IContent doc = ContentBuilder.CreateBasicContent(contentType); doc.SetCultureName("Home", "en-US"); doc.SetValue("title", "hello world", "en-US"); - ServiceContext.ContentService.Save(doc); + ContentService.Save(doc); Assert.AreEqual("hello world", doc.GetValue("title", "en-US")); //change the property type to be invariant contentType.PropertyTypes.First().Variations = invariant; - ServiceContext.ContentTypeService.Save(contentType); - doc = ServiceContext.ContentService.GetById(doc.Id); //re-get + ContentTypeService.Save(contentType); + doc = ContentService.GetById(doc.Id); //re-get Assert.AreEqual("hello world", doc.GetValue("title")); //change back property type to be variant contentType.PropertyTypes.First().Variations = variant; - ServiceContext.ContentTypeService.Save(contentType); - doc = ServiceContext.ContentService.GetById(doc.Id); //re-get + ContentTypeService.Save(contentType); + doc = ContentService.GetById(doc.Id); //re-get Assert.AreEqual("hello world", doc.GetValue("title", "en-US")); } @@ -480,44 +412,44 @@ namespace Umbraco.Tests.Services public void Change_Property_Type_From_Variant_Invariant_On_A_Composition(ContentVariation variant, ContentVariation invariant) { //create content type with a property type that varies by culture - var contentType = MockedContentTypes.CreateBasicContentType(); + var contentType = ContentTypeBuilder.CreateBasicContentType(); // content type supports all variations contentType.Variations = ContentVariation.Culture | ContentVariation.Segment; var properties = CreatePropertyCollection(("title", variant)); contentType.PropertyGroups.Add(new PropertyGroup(properties) { Name = "Content" }); - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); //compose this from the other one - var contentType2 = MockedContentTypes.CreateBasicContentType("test"); + var contentType2 = ContentTypeBuilder.CreateBasicContentType("test"); contentType2.Variations = contentType.Variations; contentType2.AddContentType(contentType); - ServiceContext.ContentTypeService.Save(contentType2); + ContentTypeService.Save(contentType2); //create some content of this content type - IContent doc = MockedContent.CreateBasicContent(contentType); + IContent doc = ContentBuilder.CreateBasicContent(contentType); doc.SetCultureName("Home", "en-US"); doc.SetValue("title", "hello world", "en-US"); - ServiceContext.ContentService.Save(doc); + ContentService.Save(doc); - IContent doc2 = MockedContent.CreateBasicContent(contentType2); + IContent doc2 = ContentBuilder.CreateBasicContent(contentType2); doc2.SetCultureName("Home", "en-US"); doc2.SetValue("title", "hello world", "en-US"); - ServiceContext.ContentService.Save(doc2); + ContentService.Save(doc2); //change the property type to be invariant contentType.PropertyTypes.First().Variations = invariant; - ServiceContext.ContentTypeService.Save(contentType); - doc = ServiceContext.ContentService.GetById(doc.Id); //re-get - doc2 = ServiceContext.ContentService.GetById(doc2.Id); //re-get + ContentTypeService.Save(contentType); + doc = ContentService.GetById(doc.Id); //re-get + doc2 = ContentService.GetById(doc2.Id); //re-get Assert.AreEqual("hello world", doc.GetValue("title")); Assert.AreEqual("hello world", doc2.GetValue("title")); //change back property type to be variant contentType.PropertyTypes.First().Variations = variant; - ServiceContext.ContentTypeService.Save(contentType); - doc = ServiceContext.ContentService.GetById(doc.Id); //re-get - doc2 = ServiceContext.ContentService.GetById(doc2.Id); //re-get + ContentTypeService.Save(contentType); + doc = ContentService.GetById(doc.Id); //re-get + doc2 = ContentService.GetById(doc2.Id); //re-get Assert.AreEqual("hello world", doc.GetValue("title", "en-US")); Assert.AreEqual("hello world", doc2.GetValue("title", "en-US")); @@ -530,43 +462,43 @@ namespace Umbraco.Tests.Services public void Change_Content_Type_From_Variant_Invariant_On_A_Composition(ContentVariation variant, ContentVariation invariant) { //create content type with a property type that varies by culture - var contentType = MockedContentTypes.CreateBasicContentType(); + var contentType = ContentTypeBuilder.CreateBasicContentType(); contentType.Variations = variant; var properties = CreatePropertyCollection(("title", ContentVariation.Culture)); contentType.PropertyGroups.Add(new PropertyGroup(properties) { Name = "Content" }); - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); //compose this from the other one - var contentType2 = MockedContentTypes.CreateBasicContentType("test"); + var contentType2 = ContentTypeBuilder.CreateBasicContentType("test"); contentType2.Variations = contentType.Variations; contentType2.AddContentType(contentType); - ServiceContext.ContentTypeService.Save(contentType2); + ContentTypeService.Save(contentType2); //create some content of this content type - IContent doc = MockedContent.CreateBasicContent(contentType); + IContent doc = ContentBuilder.CreateBasicContent(contentType); doc.SetCultureName("Home", "en-US"); doc.SetValue("title", "hello world", "en-US"); - ServiceContext.ContentService.Save(doc); + ContentService.Save(doc); - IContent doc2 = MockedContent.CreateBasicContent(contentType2); + IContent doc2 = ContentBuilder.CreateBasicContent(contentType2); doc2.SetCultureName("Home", "en-US"); doc2.SetValue("title", "hello world", "en-US"); - ServiceContext.ContentService.Save(doc2); + ContentService.Save(doc2); //change the content type to be invariant contentType.Variations = invariant; - ServiceContext.ContentTypeService.Save(contentType); - doc = ServiceContext.ContentService.GetById(doc.Id); //re-get - doc2 = ServiceContext.ContentService.GetById(doc2.Id); //re-get + ContentTypeService.Save(contentType); + doc = ContentService.GetById(doc.Id); //re-get + doc2 = ContentService.GetById(doc2.Id); //re-get Assert.AreEqual("hello world", doc.GetValue("title")); Assert.AreEqual("hello world", doc2.GetValue("title")); //change back content type to be variant contentType.Variations = variant; - ServiceContext.ContentTypeService.Save(contentType); - doc = ServiceContext.ContentService.GetById(doc.Id); //re-get - doc2 = ServiceContext.ContentService.GetById(doc2.Id); //re-get + ContentTypeService.Save(contentType); + doc = ContentService.GetById(doc.Id); //re-get + doc2 = ContentService.GetById(doc2.Id); //re-get //this will be null because the doc type was changed back to variant but it's property types don't get changed back Assert.IsNull(doc.GetValue("title", "en-US")); @@ -578,7 +510,7 @@ namespace Umbraco.Tests.Services { // one simple content type, variant, with both variant and invariant properties // can change it to invariant and back - + GetRequiredService(); //hack to ensure events are initialized CreateFrenchAndEnglishLangs(); var contentType = CreateContentType(ContentVariation.Culture); @@ -588,7 +520,7 @@ namespace Umbraco.Tests.Services ("value2", ContentVariation.Nothing)); contentType.PropertyGroups.Add(new PropertyGroup(properties) { Name = "Content" }); - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); var document = (IContent)new Content("document", -1, contentType); document.SetCultureName("doc1en", "en"); @@ -596,9 +528,9 @@ namespace Umbraco.Tests.Services document.SetValue("value1", "v1en", "en"); document.SetValue("value1", "v1fr", "fr"); document.SetValue("value2", "v2"); - ServiceContext.ContentService.Save(document); + ContentService.Save(document); - document = ServiceContext.ContentService.GetById(document.Id); + document = ContentService.GetById(document.Id); Assert.AreEqual("doc1en", document.Name); Assert.AreEqual("doc1en", document.GetCultureName("en")); Assert.AreEqual("doc1fr", document.GetCultureName("fr")); @@ -612,9 +544,9 @@ namespace Umbraco.Tests.Services // switch content type to Nothing contentType.Variations = ContentVariation.Nothing; - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); - document = ServiceContext.ContentService.GetById(document.Id); + document = ContentService.GetById(document.Id); Assert.AreEqual("doc1en", document.Name); Assert.IsNull(document.GetCultureName("en")); Assert.IsNull(document.GetCultureName("fr")); @@ -629,9 +561,9 @@ namespace Umbraco.Tests.Services // switch content back to Culture contentType.Variations = ContentVariation.Culture; - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); - document = ServiceContext.ContentService.GetById(document.Id); + document = ContentService.GetById(document.Id); Assert.AreEqual("doc1en", document.Name); Assert.AreEqual("doc1en", document.GetCultureName("en")); Assert.AreEqual("doc1fr", document.GetCultureName("fr")); @@ -646,9 +578,9 @@ namespace Umbraco.Tests.Services // switch property back to Culture contentType.PropertyTypes.First(x => x.Alias == "value1").Variations = ContentVariation.Culture; - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); - document = ServiceContext.ContentService.GetById(document.Id); + document = ContentService.GetById(document.Id); Assert.AreEqual("doc1en", document.Name); Assert.AreEqual("doc1en", document.GetCultureName("en")); Assert.AreEqual("doc1fr", document.GetCultureName("fr")); @@ -658,7 +590,7 @@ namespace Umbraco.Tests.Services Console.WriteLine(GetJson(document.Id)); AssertJsonStartsWith(document.Id, - "{'pd':{'value1':[{'c':'en','v':'v1en'},{'c':'fr','v':'v1fr'}],'value2':[{'v':'v2'}]},'cd':"); + "{'pd':{'value1':[{'c':'fr','v':'v1fr'},{'c':'en','v':'v1en'}],'value2':[{'v':'v2'}]},'cd':"); } [Test] @@ -667,13 +599,14 @@ namespace Umbraco.Tests.Services // one simple content type, invariant // can change it to variant and back // can then switch one property to variant + GetRequiredService(); //hack to ensure events are initialized var globalSettings = new GlobalSettings(); var languageEn = new Language(globalSettings, "en") { IsDefault = true }; - ServiceContext.LocalizationService.Save(languageEn); + LocalizationService.Save(languageEn); var languageFr = new Language(globalSettings, "fr"); - ServiceContext.LocalizationService.Save(languageFr); + LocalizationService.Save(languageFr); var contentType = CreateContentType(ContentVariation.Nothing); @@ -682,15 +615,15 @@ namespace Umbraco.Tests.Services ("value2", ContentVariation.Nothing)); contentType.PropertyGroups.Add(new PropertyGroup(properties) { Name = "Content" }); - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); var document = (IContent) new Content("document", -1, contentType); document.Name = "doc1"; document.SetValue("value1", "v1"); document.SetValue("value2", "v2"); - ServiceContext.ContentService.Save(document); + ContentService.Save(document); - document = ServiceContext.ContentService.GetById(document.Id); + document = ContentService.GetById(document.Id); Assert.AreEqual("doc1", document.Name); Assert.IsNull(document.GetCultureName("en")); Assert.IsNull(document.GetCultureName("fr")); @@ -705,9 +638,9 @@ namespace Umbraco.Tests.Services // switch content type to Culture contentType.Variations = ContentVariation.Culture; - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); - document = ServiceContext.ContentService.GetById(document.Id); + document = ContentService.GetById(document.Id); Assert.AreEqual("doc1", document.GetCultureName("en")); Assert.IsNull(document.GetCultureName("fr")); Assert.IsNull(document.GetValue("value1", "en")); @@ -721,9 +654,9 @@ namespace Umbraco.Tests.Services // switch property to Culture contentType.PropertyTypes.First(x => x.Alias == "value1").Variations = ContentVariation.Culture; - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); - document = ServiceContext.ContentService.GetById(document.Id); + document = ContentService.GetById(document.Id); Assert.AreEqual("doc1", document.GetCultureName("en")); Assert.IsNull(document.GetCultureName("fr")); Assert.AreEqual("v1", document.GetValue("value1", "en")); @@ -736,9 +669,9 @@ namespace Umbraco.Tests.Services // switch content back to Nothing contentType.Variations = ContentVariation.Nothing; - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); - document = ServiceContext.ContentService.GetById(document.Id); + document = ContentService.GetById(document.Id); Assert.AreEqual("doc1", document.Name); Assert.IsNull(document.GetCultureName("en")); Assert.IsNull(document.GetCultureName("fr")); @@ -757,7 +690,7 @@ namespace Umbraco.Tests.Services { // one simple content type, variant, with both variant and invariant properties // can change an invariant property to variant and back - + GetRequiredService(); //hack to ensure events are initialized CreateFrenchAndEnglishLangs(); var contentType = CreateContentType(ContentVariation.Culture); @@ -767,7 +700,7 @@ namespace Umbraco.Tests.Services ("value2", ContentVariation.Nothing)); contentType.PropertyGroups.Add(new PropertyGroup(properties) { Name = "Content" }); - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); var document = (IContent)new Content("document", -1, contentType); document.SetCultureName("doc1en", "en"); @@ -775,9 +708,9 @@ namespace Umbraco.Tests.Services document.SetValue("value1", "v1en", "en"); document.SetValue("value1", "v1fr", "fr"); document.SetValue("value2", "v2"); - ServiceContext.ContentService.Save(document); + ContentService.Save(document); - document = ServiceContext.ContentService.GetById(document.Id); + document = ContentService.GetById(document.Id); Assert.AreEqual("doc1en", document.Name); Assert.AreEqual("doc1en", document.GetCultureName("en")); Assert.AreEqual("doc1fr", document.GetCultureName("fr")); @@ -791,9 +724,9 @@ namespace Umbraco.Tests.Services // switch property type to Nothing contentType.PropertyTypes.First(x => x.Alias == "value1").Variations = ContentVariation.Nothing; - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); - document = ServiceContext.ContentService.GetById(document.Id); + document = ContentService.GetById(document.Id); Assert.AreEqual("doc1en", document.Name); Assert.AreEqual("doc1en", document.GetCultureName("en")); Assert.AreEqual("doc1fr", document.GetCultureName("fr")); @@ -808,9 +741,9 @@ namespace Umbraco.Tests.Services // switch property back to Culture contentType.PropertyTypes.First(x => x.Alias == "value1").Variations = ContentVariation.Culture; - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); - document = ServiceContext.ContentService.GetById(document.Id); + document = ContentService.GetById(document.Id); Assert.AreEqual("doc1en", document.Name); Assert.AreEqual("doc1en", document.GetCultureName("en")); Assert.AreEqual("doc1fr", document.GetCultureName("fr")); @@ -820,13 +753,13 @@ namespace Umbraco.Tests.Services Console.WriteLine(GetJson(document.Id)); AssertJsonStartsWith(document.Id, - "{'pd':{'value1':[{'c':'en','v':'v1en'},{'c':'fr','v':'v1fr'}],'value2':[{'v':'v2'}]},'cd':"); + "{'pd':{'value1':[{'c':'fr','v':'v1fr'},{'c':'en','v':'v1en'}],'value2':[{'v':'v2'}]},'cd':"); // switch other property to Culture contentType.PropertyTypes.First(x => x.Alias == "value2").Variations = ContentVariation.Culture; - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); - document = ServiceContext.ContentService.GetById(document.Id); + document = ContentService.GetById(document.Id); Assert.AreEqual("doc1en", document.Name); Assert.AreEqual("doc1en", document.GetCultureName("en")); Assert.AreEqual("doc1fr", document.GetCultureName("fr")); @@ -838,7 +771,7 @@ namespace Umbraco.Tests.Services Console.WriteLine(GetJson(document.Id)); AssertJsonStartsWith(document.Id, - "{'pd':{'value1':[{'c':'en','v':'v1en'},{'c':'fr','v':'v1fr'}],'value2':[{'c':'en','v':'v2'}]},'cd':"); + "{'pd':{'value1':[{'c':'fr','v':'v1fr'},{'c':'en','v':'v1en'}],'value2':[{'c':'en','v':'v2'}]},'cd':"); } [TestCase(ContentVariation.Culture, ContentVariation.Nothing)] @@ -857,25 +790,25 @@ namespace Umbraco.Tests.Services var properties = CreatePropertyCollection(("value1", variant)); contentType.PropertyGroups.Add(new PropertyGroup(properties) { Name = "Content" }); - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); IContent document = new Content("document", -1, contentType); document.SetCultureName("doc1en", "en"); document.SetCultureName("doc1fr", "fr"); document.SetValue("value1", "v1en-init", "en"); document.SetValue("value1", "v1fr-init", "fr"); - ServiceContext.ContentService.SaveAndPublish(document); //all values are published which means the document is not 'edited' + ContentService.SaveAndPublish(document); //all values are published which means the document is not 'edited' - document = ServiceContext.ContentService.GetById(document.Id); + document = ContentService.GetById(document.Id); Assert.IsFalse(document.IsCultureEdited("en")); Assert.IsFalse(document.IsCultureEdited("fr")); Assert.IsFalse(document.Edited); document.SetValue("value1", "v1en", "en"); //change the property culture value, so now this culture will be edited document.SetValue("value1", "v1fr", "fr"); //change the property culture value, so now this culture will be edited - ServiceContext.ContentService.Save(document); + ContentService.Save(document); - document = ServiceContext.ContentService.GetById(document.Id); + document = ContentService.GetById(document.Id); Assert.AreEqual("doc1en", document.Name); Assert.AreEqual("doc1en", document.GetCultureName("en")); Assert.AreEqual("doc1fr", document.GetCultureName("fr")); @@ -889,18 +822,18 @@ namespace Umbraco.Tests.Services // switch property type to Invariant contentType.PropertyTypes.First(x => x.Alias == "value1").Variations = invariant; - ServiceContext.ContentTypeService.Save(contentType); //This is going to have to re-normalize the "Edited" flag + ContentTypeService.Save(contentType); //This is going to have to re-normalize the "Edited" flag - document = ServiceContext.ContentService.GetById(document.Id); + document = ContentService.GetById(document.Id); Assert.IsTrue(document.IsCultureEdited("en")); //This will remain true because there is now a pending change for the invariant property data which is flagged under the default lang Assert.IsFalse(document.IsCultureEdited("fr")); //This will be false because nothing has changed for this culture and the property no longer reflects variant changes Assert.IsTrue(document.Edited); //update the invariant value and publish document.SetValue("value1", "v1inv"); - ServiceContext.ContentService.SaveAndPublish(document); + ContentService.SaveAndPublish(document); - document = ServiceContext.ContentService.GetById(document.Id); + document = ContentService.GetById(document.Id); Assert.AreEqual("doc1en", document.Name); Assert.AreEqual("doc1en", document.GetCultureName("en")); Assert.AreEqual("doc1fr", document.GetCultureName("fr")); @@ -916,9 +849,9 @@ namespace Umbraco.Tests.Services // switch property back to Culture contentType.PropertyTypes.First(x => x.Alias == "value1").Variations = variant; - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); - document = ServiceContext.ContentService.GetById(document.Id); + document = ContentService.GetById(document.Id); Assert.AreEqual("v1inv", document.GetValue("value1", "en")); //The invariant property value gets copied over to the default language Assert.AreEqual("v1inv", document.GetValue("value1", "en", published: true)); Assert.AreEqual("v1fr", document.GetValue("value1", "fr")); //values are still retained @@ -930,9 +863,9 @@ namespace Umbraco.Tests.Services // publish again document.SetValue("value1", "v1en2", "en"); //update the value now that it's variant again document.SetValue("value1", "v1fr2", "fr"); //update the value now that it's variant again - ServiceContext.ContentService.SaveAndPublish(document); + ContentService.SaveAndPublish(document); - document = ServiceContext.ContentService.GetById(document.Id); + document = ContentService.GetById(document.Id); Assert.AreEqual("doc1en", document.Name); Assert.AreEqual("doc1en", document.GetCultureName("en")); Assert.AreEqual("doc1fr", document.GetCultureName("fr")); @@ -960,23 +893,23 @@ namespace Umbraco.Tests.Services var properties = CreatePropertyCollection(("value1", invariant)); contentType.PropertyGroups.Add(new PropertyGroup(properties) { Name = "Content" }); - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); var document = (IContent)new Content("document", -1, contentType); document.SetCultureName("doc1en", "en"); document.SetCultureName("doc1fr", "fr"); document.SetValue("value1", "v1en-init"); - ServiceContext.ContentService.SaveAndPublish(document); //all values are published which means the document is not 'edited' + ContentService.SaveAndPublish(document); //all values are published which means the document is not 'edited' - document = ServiceContext.ContentService.GetById(document.Id); + document = ContentService.GetById(document.Id); Assert.IsFalse(document.IsCultureEdited("en")); Assert.IsFalse(document.IsCultureEdited("fr")); Assert.IsFalse(document.Edited); document.SetValue("value1", "v1en"); //change the property value, so now the invariant (default) culture will be edited - ServiceContext.ContentService.Save(document); + ContentService.Save(document); - document = ServiceContext.ContentService.GetById(document.Id); + document = ContentService.GetById(document.Id); Assert.AreEqual("doc1en", document.Name); Assert.AreEqual("doc1en", document.GetCultureName("en")); Assert.AreEqual("doc1fr", document.GetCultureName("fr")); @@ -988,18 +921,18 @@ namespace Umbraco.Tests.Services // switch property type to Culture contentType.PropertyTypes.First(x => x.Alias == "value1").Variations = variant; - ServiceContext.ContentTypeService.Save(contentType); //This is going to have to re-normalize the "Edited" flag + ContentTypeService.Save(contentType); //This is going to have to re-normalize the "Edited" flag - document = ServiceContext.ContentService.GetById(document.Id); + document = ContentService.GetById(document.Id); Assert.IsTrue(document.IsCultureEdited("en")); //Remains true Assert.IsFalse(document.IsCultureEdited("fr")); //False because no french property has ever been edited Assert.IsTrue(document.Edited); //update the culture value and publish document.SetValue("value1", "v1en2", "en"); - ServiceContext.ContentService.SaveAndPublish(document); + ContentService.SaveAndPublish(document); - document = ServiceContext.ContentService.GetById(document.Id); + document = ContentService.GetById(document.Id); Assert.AreEqual("doc1en", document.Name); Assert.AreEqual("doc1en", document.GetCultureName("en")); Assert.AreEqual("doc1fr", document.GetCultureName("fr")); @@ -1013,9 +946,9 @@ namespace Umbraco.Tests.Services // switch property back to Invariant contentType.PropertyTypes.First(x => x.Alias == "value1").Variations = invariant; - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); - document = ServiceContext.ContentService.GetById(document.Id); + document = ContentService.GetById(document.Id); Assert.AreEqual("v1en2", document.GetValue("value1")); //The variant property value gets copied over to the invariant Assert.AreEqual("v1en2", document.GetValue("value1", published: true)); Assert.IsNull(document.GetValue("value1", "fr")); //The values are there but the business logic returns null @@ -1034,6 +967,8 @@ namespace Umbraco.Tests.Services // can change the composing content type to invariant and back // can change the composed content type to invariant and back + + GetRequiredService(); //hack to ensure events are initialized CreateFrenchAndEnglishLangs(); var composing = CreateContentType(ContentVariation.Culture, "composing"); @@ -1043,7 +978,7 @@ namespace Umbraco.Tests.Services ("value12", ContentVariation.Nothing)); composing.PropertyGroups.Add(new PropertyGroup(properties1) { Name = "Content" }); - ServiceContext.ContentTypeService.Save(composing); + ContentTypeService.Save(composing); var composed = CreateContentType(ContentVariation.Culture, "composed"); @@ -1053,7 +988,7 @@ namespace Umbraco.Tests.Services composed.PropertyGroups.Add(new PropertyGroup(properties2) { Name = "Content" }); composed.AddContentType(composing); - ServiceContext.ContentTypeService.Save(composed); + ContentTypeService.Save(composed); var document = (IContent) new Content("document", -1, composed); document.SetCultureName("doc1en", "en"); @@ -1064,7 +999,7 @@ namespace Umbraco.Tests.Services document.SetValue("value21", "v21en", "en"); document.SetValue("value21", "v21fr", "fr"); document.SetValue("value22", "v22"); - ServiceContext.ContentService.Save(document); + ContentService.Save(document); // both value11 and value21 are variant Console.WriteLine(GetJson(document.Id)); @@ -1072,7 +1007,7 @@ namespace Umbraco.Tests.Services "{'pd':{'value11':[{'c':'en','v':'v11en'},{'c':'fr','v':'v11fr'}],'value12':[{'v':'v12'}],'value21':[{'c':'en','v':'v21en'},{'c':'fr','v':'v21fr'}],'value22':[{'v':'v22'}]},'cd':"); composed.Variations = ContentVariation.Nothing; - ServiceContext.ContentTypeService.Save(composed); + ContentTypeService.Save(composed); // both value11 and value21 are invariant Console.WriteLine(GetJson(document.Id)); @@ -1080,7 +1015,7 @@ namespace Umbraco.Tests.Services "{'pd':{'value11':[{'v':'v11en'}],'value12':[{'v':'v12'}],'value21':[{'v':'v21en'}],'value22':[{'v':'v22'}]},'cd':"); composed.Variations = ContentVariation.Culture; - ServiceContext.ContentTypeService.Save(composed); + ContentTypeService.Save(composed); // value11 is variant again, but value21 is still invariant Console.WriteLine(GetJson(document.Id)); @@ -1088,36 +1023,36 @@ namespace Umbraco.Tests.Services "{'pd':{'value11':[{'c':'en','v':'v11en'},{'c':'fr','v':'v11fr'}],'value12':[{'v':'v12'}],'value21':[{'v':'v21en'}],'value22':[{'v':'v22'}]},'cd':"); composed.PropertyTypes.First(x => x.Alias == "value21").Variations = ContentVariation.Culture; - ServiceContext.ContentTypeService.Save(composed); + ContentTypeService.Save(composed); // we can make it variant again Console.WriteLine(GetJson(document.Id)); AssertJsonStartsWith(document.Id, - "{'pd':{'value11':[{'c':'en','v':'v11en'},{'c':'fr','v':'v11fr'}],'value12':[{'v':'v12'}],'value21':[{'c':'en','v':'v21en'},{'c':'fr','v':'v21fr'}],'value22':[{'v':'v22'}]},'cd':"); + "{'pd':{'value11':[{'c':'en','v':'v11en'},{'c':'fr','v':'v11fr'}],'value12':[{'v':'v12'}],'value21':[{'c':'fr','v':'v21fr'},{'c':'en','v':'v21en'}],'value22':[{'v':'v22'}]},'cd':"); composing.Variations = ContentVariation.Nothing; - ServiceContext.ContentTypeService.Save(composing); + ContentTypeService.Save(composing); // value11 is invariant Console.WriteLine(GetJson(document.Id)); AssertJsonStartsWith(document.Id, - "{'pd':{'value11':[{'v':'v11en'}],'value12':[{'v':'v12'}],'value21':[{'c':'en','v':'v21en'},{'c':'fr','v':'v21fr'}],'value22':[{'v':'v22'}]},'cd':"); + "{'pd':{'value11':[{'v':'v11en'}],'value12':[{'v':'v12'}],'value21':[{'c':'fr','v':'v21fr'},{'c':'en','v':'v21en'}],'value22':[{'v':'v22'}]},'cd':"); composing.Variations = ContentVariation.Culture; - ServiceContext.ContentTypeService.Save(composing); + ContentTypeService.Save(composing); // value11 is still invariant Console.WriteLine(GetJson(document.Id)); AssertJsonStartsWith(document.Id, - "{'pd':{'value11':[{'v':'v11en'}],'value12':[{'v':'v12'}],'value21':[{'c':'en','v':'v21en'},{'c':'fr','v':'v21fr'}],'value22':[{'v':'v22'}]},'cd':"); + "{'pd':{'value11':[{'v':'v11en'}],'value12':[{'v':'v12'}],'value21':[{'c':'fr','v':'v21fr'},{'c':'en','v':'v21en'}],'value22':[{'v':'v22'}]},'cd':"); composing.PropertyTypes.First(x => x.Alias == "value11").Variations = ContentVariation.Culture; - ServiceContext.ContentTypeService.Save(composing); + ContentTypeService.Save(composing); // we can make it variant again Console.WriteLine(GetJson(document.Id)); AssertJsonStartsWith(document.Id, - "{'pd':{'value11':[{'c':'en','v':'v11en'},{'c':'fr','v':'v11fr'}],'value12':[{'v':'v12'}],'value21':[{'c':'en','v':'v21en'},{'c':'fr','v':'v21fr'}],'value22':[{'v':'v22'}]},'cd':"); + "{'pd':{'value11':[{'c':'fr','v':'v11fr'},{'c':'en','v':'v11en'}],'value12':[{'v':'v12'}],'value21':[{'c':'fr','v':'v21fr'},{'c':'en','v':'v21en'}],'value22':[{'v':'v22'}]},'cd':"); } [Test] @@ -1129,6 +1064,7 @@ namespace Umbraco.Tests.Services // can change the composing content type to invariant and back // can change the variant composed content type to invariant and back + GetRequiredService(); //hack to ensure events are initialized CreateFrenchAndEnglishLangs(); var composing = CreateContentType(ContentVariation.Culture, "composing"); @@ -1138,7 +1074,7 @@ namespace Umbraco.Tests.Services ("value12", ContentVariation.Nothing)); composing.PropertyGroups.Add(new PropertyGroup(properties1) { Name = "Content" }); - ServiceContext.ContentTypeService.Save(composing); + ContentTypeService.Save(composing); var composed1 = CreateContentType(ContentVariation.Culture, "composed1"); @@ -1148,7 +1084,7 @@ namespace Umbraco.Tests.Services composed1.PropertyGroups.Add(new PropertyGroup(properties2) { Name = "Content" }); composed1.AddContentType(composing); - ServiceContext.ContentTypeService.Save(composed1); + ContentTypeService.Save(composed1); var composed2 = CreateContentType(ContentVariation.Nothing, "composed2"); @@ -1158,7 +1094,7 @@ namespace Umbraco.Tests.Services composed2.PropertyGroups.Add(new PropertyGroup(properties3) { Name = "Content" }); composed2.AddContentType(composing); - ServiceContext.ContentTypeService.Save(composed2); + ContentTypeService.Save(composed2); var document1 = (IContent) new Content ("document1", -1, composed1); document1.SetCultureName("doc1en", "en"); @@ -1169,7 +1105,7 @@ namespace Umbraco.Tests.Services document1.SetValue("value21", "v21en", "en"); document1.SetValue("value21", "v21fr", "fr"); document1.SetValue("value22", "v22"); - ServiceContext.ContentService.Save(document1); + ContentService.Save(document1); var document2 = (IContent)new Content("document2", -1, composed2); document2.Name = "doc2"; @@ -1177,7 +1113,7 @@ namespace Umbraco.Tests.Services document2.SetValue("value12", "v12"); document2.SetValue("value31", "v31"); document2.SetValue("value32", "v32"); - ServiceContext.ContentService.Save(document2); + ContentService.Save(document2); // both value11 and value21 are variant Console.WriteLine(GetJson(document1.Id)); @@ -1189,7 +1125,7 @@ namespace Umbraco.Tests.Services "{'pd':{'value11':[{'v':'v11'}],'value12':[{'v':'v12'}],'value31':[{'v':'v31'}],'value32':[{'v':'v32'}]},'cd':"); composed1.Variations = ContentVariation.Nothing; - ServiceContext.ContentTypeService.Save(composed1); + ContentTypeService.Save(composed1); // both value11 and value21 are invariant Console.WriteLine(GetJson(document1.Id)); @@ -1201,7 +1137,7 @@ namespace Umbraco.Tests.Services "{'pd':{'value11':[{'v':'v11'}],'value12':[{'v':'v12'}],'value31':[{'v':'v31'}],'value32':[{'v':'v32'}]},'cd':"); composed1.Variations = ContentVariation.Culture; - ServiceContext.ContentTypeService.Save(composed1); + ContentTypeService.Save(composed1); // value11 is variant again, but value21 is still invariant Console.WriteLine(GetJson(document1.Id)); @@ -1213,48 +1149,48 @@ namespace Umbraco.Tests.Services "{'pd':{'value11':[{'v':'v11'}],'value12':[{'v':'v12'}],'value31':[{'v':'v31'}],'value32':[{'v':'v32'}]},'cd':"); composed1.PropertyTypes.First(x => x.Alias == "value21").Variations = ContentVariation.Culture; - ServiceContext.ContentTypeService.Save(composed1); + ContentTypeService.Save(composed1); // we can make it variant again Console.WriteLine(GetJson(document1.Id)); AssertJsonStartsWith(document1.Id, - "{'pd':{'value11':[{'c':'en','v':'v11en'},{'c':'fr','v':'v11fr'}],'value12':[{'v':'v12'}],'value21':[{'c':'en','v':'v21en'},{'c':'fr','v':'v21fr'}],'value22':[{'v':'v22'}]},'cd':"); + "{'pd':{'value11':[{'c':'en','v':'v11en'},{'c':'fr','v':'v11fr'}],'value12':[{'v':'v12'}],'value21':[{'c':'fr','v':'v21fr'},{'c':'en','v':'v21en'}],'value22':[{'v':'v22'}]},'cd':"); Console.WriteLine(GetJson(document2.Id)); AssertJsonStartsWith(document2.Id, "{'pd':{'value11':[{'v':'v11'}],'value12':[{'v':'v12'}],'value31':[{'v':'v31'}],'value32':[{'v':'v32'}]},'cd':"); composing.Variations = ContentVariation.Nothing; - ServiceContext.ContentTypeService.Save(composing); + ContentTypeService.Save(composing); // value11 is invariant Console.WriteLine(GetJson(document1.Id)); AssertJsonStartsWith(document1.Id, - "{'pd':{'value11':[{'v':'v11en'}],'value12':[{'v':'v12'}],'value21':[{'c':'en','v':'v21en'},{'c':'fr','v':'v21fr'}],'value22':[{'v':'v22'}]},'cd':"); + "{'pd':{'value11':[{'v':'v11en'}],'value12':[{'v':'v12'}],'value21':[{'c':'fr','v':'v21fr'},{'c':'en','v':'v21en'}],'value22':[{'v':'v22'}]},'cd':"); Console.WriteLine(GetJson(document2.Id)); AssertJsonStartsWith(document2.Id, "{'pd':{'value11':[{'v':'v11'}],'value12':[{'v':'v12'}],'value31':[{'v':'v31'}],'value32':[{'v':'v32'}]},'cd':"); composing.Variations = ContentVariation.Culture; - ServiceContext.ContentTypeService.Save(composing); + ContentTypeService.Save(composing); // value11 is still invariant Console.WriteLine(GetJson(document1.Id)); AssertJsonStartsWith(document1.Id, - "{'pd':{'value11':[{'v':'v11en'}],'value12':[{'v':'v12'}],'value21':[{'c':'en','v':'v21en'},{'c':'fr','v':'v21fr'}],'value22':[{'v':'v22'}]},'cd':"); + "{'pd':{'value11':[{'v':'v11en'}],'value12':[{'v':'v12'}],'value21':[{'c':'fr','v':'v21fr'},{'c':'en','v':'v21en'}],'value22':[{'v':'v22'}]},'cd':"); Console.WriteLine(GetJson(document2.Id)); AssertJsonStartsWith(document2.Id, "{'pd':{'value11':[{'v':'v11'}],'value12':[{'v':'v12'}],'value31':[{'v':'v31'}],'value32':[{'v':'v32'}]},'cd':"); composing.PropertyTypes.First(x => x.Alias == "value11").Variations = ContentVariation.Culture; - ServiceContext.ContentTypeService.Save(composing); + ContentTypeService.Save(composing); // we can make it variant again Console.WriteLine(GetJson(document1.Id)); AssertJsonStartsWith(document1.Id, - "{'pd':{'value11':[{'c':'en','v':'v11en'},{'c':'fr','v':'v11fr'}],'value12':[{'v':'v12'}],'value21':[{'c':'en','v':'v21en'},{'c':'fr','v':'v21fr'}],'value22':[{'v':'v22'}]},'cd':"); + "{'pd':{'value11':[{'c':'fr','v':'v11fr'},{'c':'en','v':'v11en'}],'value12':[{'v':'v12'}],'value21':[{'c':'fr','v':'v21fr'},{'c':'en','v':'v21en'}],'value22':[{'v':'v22'}]},'cd':"); Console.WriteLine(GetJson(document2.Id)); AssertJsonStartsWith(document2.Id, @@ -1265,9 +1201,9 @@ namespace Umbraco.Tests.Services { var globalSettings = new GlobalSettings(); var languageEn = new Language(globalSettings, "en") { IsDefault = true }; - ServiceContext.LocalizationService.Save(languageEn); + LocalizationService.Save(languageEn); var languageFr = new Language(globalSettings, "fr"); - ServiceContext.LocalizationService.Save(languageFr); + LocalizationService.Save(languageFr); } private IContentType CreateContentType(ContentVariation variance, string alias = "contentType") => new ContentType(ShortStringHelper, -1) diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 965703c308..0eea4cd6d7 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -149,7 +149,6 @@ - @@ -446,9 +445,6 @@ - - - $(NuGetPackageFolders.Split(';')[0])