Merge remote-tracking branch 'origin/netcore/netcore' into netcore/feature/migrate-logging
Signed-off-by: Bjarke Berg <mail@bergmania.dk> # Conflicts: # src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs # src/Umbraco.Tests.Integration/Packaging/CreatedPackagesRepositoryTests.cs # src/Umbraco.Tests.Integration/Services/CachedDataTypeServiceTests.cs # src/Umbraco.Tests.Integration/Services/DataTypeServiceTests.cs # src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs # src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs # src/Umbraco.Tests.UnitTests/Umbraco.Core/Services/LocalizedTextServiceTests.cs
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
using System;
|
||||
using Examine;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Composing.CompositionExtensions;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.Grid;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Configuration.Models;
|
||||
using Umbraco.Core.Dashboards;
|
||||
using Umbraco.Core.Dictionary;
|
||||
using Umbraco.Core.Events;
|
||||
@@ -18,7 +19,6 @@ using Umbraco.Core.Migrations;
|
||||
using Umbraco.Core.Migrations.Install;
|
||||
using Umbraco.Core.Migrations.PostMigrations;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Templates;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.PropertyEditors.Validators;
|
||||
@@ -29,6 +29,7 @@ using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Services.Implement;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Core.Sync;
|
||||
using Umbraco.Core.Templates;
|
||||
using Umbraco.Examine;
|
||||
using Umbraco.Infrastructure.Examine;
|
||||
using Umbraco.Infrastructure.Media;
|
||||
@@ -41,6 +42,7 @@ using Umbraco.Web.Features;
|
||||
using Umbraco.Web.HealthCheck;
|
||||
using Umbraco.Web.HealthCheck.NotificationMethods;
|
||||
using Umbraco.Web.Install;
|
||||
using Umbraco.Web.Media;
|
||||
using Umbraco.Web.Media.EmbedProviders;
|
||||
using Umbraco.Web.Migrations.PostMigrations;
|
||||
using Umbraco.Web.Models.PublishedContent;
|
||||
@@ -55,10 +57,8 @@ using Umbraco.Web.Templates;
|
||||
using Umbraco.Web.Trees;
|
||||
using IntegerValidator = Umbraco.Core.PropertyEditors.Validators.IntegerValidator;
|
||||
using TextStringValueConverter = Umbraco.Core.PropertyEditors.ValueConverters.TextStringValueConverter;
|
||||
using Umbraco.Core.Configuration.Models;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Umbraco.Web.Media;
|
||||
|
||||
|
||||
namespace Umbraco.Core.Runtime
|
||||
{
|
||||
@@ -206,13 +206,6 @@ namespace Umbraco.Core.Runtime
|
||||
// Config manipulator
|
||||
composition.RegisterUnique<IConfigManipulator, JsonConfigManipulator>();
|
||||
|
||||
|
||||
// register the http context and umbraco context accessors
|
||||
// we *should* use the HttpContextUmbracoContextAccessor, however there are cases when
|
||||
// we have no http context, eg when booting Umbraco or in background threads, so instead
|
||||
// let's use an hybrid accessor that can fall back to a ThreadStatic context.
|
||||
composition.RegisterUnique<IUmbracoContextAccessor, HybridUmbracoContextAccessor>();
|
||||
|
||||
// register the umbraco context factory
|
||||
// composition.RegisterUnique<IUmbracoContextFactory, UmbracoContextFactory>();
|
||||
composition.RegisterUnique<IPublishedUrlProvider, UrlProvider>();
|
||||
@@ -355,7 +348,6 @@ namespace Umbraco.Core.Runtime
|
||||
return new PublishedContentQuery(umbCtx.UmbracoContext.PublishedSnapshot, factory.GetInstance<IVariationContextAccessor>(), factory.GetInstance<IExamineManager>());
|
||||
}, Lifetime.Request);
|
||||
|
||||
|
||||
composition.RegisterUnique<IPublishedUrlProvider, UrlProvider>();
|
||||
|
||||
// register the http context and umbraco context accessors
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Umbraco.Tests.Common.Builders
|
||||
private string _icon;
|
||||
private string _name;
|
||||
private IEnumerable<string> _permissions = Enumerable.Empty<string>();
|
||||
private IEnumerable<string> _sectionCollection = Enumerable.Empty<string>();
|
||||
private IEnumerable<string> _allowedSections = Enumerable.Empty<string>();
|
||||
private string _suffix;
|
||||
private int? _startContentId;
|
||||
private int? _startMediaId;
|
||||
@@ -55,7 +55,7 @@ namespace Umbraco.Tests.Common.Builders
|
||||
|
||||
public UserGroupBuilder<TParent> WithPermissions(string permissions)
|
||||
{
|
||||
_permissions = permissions.Split();
|
||||
_permissions = permissions.ToCharArray().Select(x => x.ToString());
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -65,6 +65,12 @@ namespace Umbraco.Tests.Common.Builders
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserGroupBuilder<TParent> WithAllowedSections(IList<string> allowedSections)
|
||||
{
|
||||
_allowedSections = allowedSections;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserGroupBuilder<TParent> WithStartContentId(int startContentId)
|
||||
{
|
||||
_startContentId = startContentId;
|
||||
@@ -107,9 +113,9 @@ namespace Umbraco.Tests.Common.Builders
|
||||
userGroup.StartContentId = startContentId;
|
||||
userGroup.StartMediaId = startMediaId;
|
||||
|
||||
foreach (var item in _sectionCollection)
|
||||
foreach (var section in _allowedSections)
|
||||
{
|
||||
userGroup.AddAllowedSection(item);
|
||||
userGroup.AddAllowedSection(section);
|
||||
}
|
||||
|
||||
return userGroup;
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
using Moq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Configuration.Models;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
|
||||
namespace Umbraco.Tests.Common.TestHelpers.Entities
|
||||
{
|
||||
public static class MockedUser
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns a <see cref="Mock{IUser}"/> and ensures that the ToUserCache and FromUserCache methods are mapped correctly for
|
||||
/// dealing with start node caches
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static Mock<IUser> GetUserMock()
|
||||
{
|
||||
var userCache = new Dictionary<string, object>();
|
||||
var userMock = new Mock<IUser>();
|
||||
userMock.Setup(x => x.FromUserCache<int[]>(It.IsAny<string>())).Returns((string key) => userCache.TryGetValue(key, out var val) ? val is int[] iVal ? iVal : null : null);
|
||||
userMock.Setup(x => x.ToUserCache<int[]>(It.IsAny<string>(), It.IsAny<int[]>())).Callback((string key, int[] val) => userCache[key] = val);
|
||||
return userMock;
|
||||
}
|
||||
|
||||
public static User CreateUser(string suffix = "")
|
||||
{
|
||||
var globalSettings = new GlobalSettings();
|
||||
var user = new User(globalSettings)
|
||||
{
|
||||
Language = "en",
|
||||
IsApproved = true,
|
||||
Name = "TestUser" + suffix,
|
||||
RawPasswordValue = "testing",
|
||||
IsLockedOut = false,
|
||||
Email = "test" + suffix + "@test.com",
|
||||
Username = "TestUser" + suffix
|
||||
};
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
public static IEnumerable<IUser> CreateMulipleUsers(int amount, Action<int, IUser> onCreating = null)
|
||||
{
|
||||
var list = new List<IUser>();
|
||||
|
||||
var globalSettings = new GlobalSettings();
|
||||
for (var i = 0; i < amount; i++)
|
||||
{
|
||||
var name = "Member No-" + i;
|
||||
var user = new User(globalSettings, name, "test" + i + "@test.com", "test" + i, "test" + i);
|
||||
|
||||
onCreating?.Invoke(i, user);
|
||||
|
||||
user.ResetDirtyProperties(false);
|
||||
|
||||
list.Add(user);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,40 +6,51 @@ using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.Models;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.Models.Packaging;
|
||||
using Umbraco.Core.Packaging;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.Integration.Testing;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Packaging
|
||||
{
|
||||
[TestFixture]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerFixture)]
|
||||
public class CreatedPackagesRepositoryTests : TestWithDatabaseBase
|
||||
public class CreatedPackagesRepositoryTests : UmbracoIntegrationTest
|
||||
{
|
||||
private Guid _testBaseFolder;
|
||||
|
||||
public override void SetUp()
|
||||
[SetUp]
|
||||
public void SetupTestData()
|
||||
{
|
||||
base.SetUp();
|
||||
_testBaseFolder = Guid.NewGuid();
|
||||
}
|
||||
|
||||
public override void TearDown()
|
||||
[TearDown]
|
||||
public void DeleteTestFolder()
|
||||
{
|
||||
base.TearDown();
|
||||
|
||||
//clear out files/folders
|
||||
Directory.Delete(IOHelper.MapPath("~/" + _testBaseFolder), true);
|
||||
Directory.Delete(HostingEnvironment.MapPathContentRoot("~/" + _testBaseFolder), true);
|
||||
}
|
||||
|
||||
private IContentService ContentService => GetRequiredService<IContentService>();
|
||||
private IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
|
||||
private IDataTypeService DataTypeService => GetRequiredService<IDataTypeService>();
|
||||
private IFileService FileService => GetRequiredService<IFileService>();
|
||||
private IMacroService MacroService => GetRequiredService<IMacroService>();
|
||||
private ILocalizationService LocalizationService => GetRequiredService<ILocalizationService>();
|
||||
private IEntityXmlSerializer EntityXmlSerializer => GetRequiredService<IEntityXmlSerializer>();
|
||||
private IHostingEnvironment HostingEnvironment => GetRequiredService<IHostingEnvironment>();
|
||||
private IUmbracoVersion UmbracoVersion => GetRequiredService<IUmbracoVersion>();
|
||||
|
||||
public ICreatedPackagesRepository PackageBuilder => new PackagesRepository(
|
||||
ServiceContext.ContentService, ServiceContext.ContentTypeService, ServiceContext.DataTypeService,
|
||||
ServiceContext.FileService, ServiceContext.MacroService, ServiceContext.LocalizationService,
|
||||
ContentService, ContentTypeService, DataTypeService,
|
||||
FileService, MacroService, LocalizationService,
|
||||
HostingEnvironment,
|
||||
Factory.GetInstance<IEntityXmlSerializer>(), LoggerFactory,
|
||||
EntityXmlSerializer, LoggerFactory,
|
||||
UmbracoVersion,
|
||||
Microsoft.Extensions.Options.Options.Create(new GlobalSettings()),
|
||||
"createdPackages.config",
|
||||
Binary file not shown.
@@ -9,7 +9,7 @@ using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Integration.Testing;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
namespace Umbraco.Tests.Integration.Services
|
||||
{
|
||||
[TestFixture]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.Integration.Testing;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
@@ -12,8 +14,12 @@ namespace Umbraco.Tests.Services
|
||||
[TestFixture]
|
||||
[Apartment(ApartmentState.STA)]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
||||
public class CachedDataTypeServiceTests : TestWithSomeContentBase
|
||||
public class CachedDataTypeServiceTests : UmbracoIntegrationTest
|
||||
{
|
||||
private IDataTypeService DataTypeService => GetRequiredService<IDataTypeService>();
|
||||
private ILocalizedTextService LocalizedTextService => GetRequiredService<ILocalizedTextService>();
|
||||
private ILocalizationService LocalizationService => GetRequiredService<ILocalizationService>();
|
||||
|
||||
/// <summary>
|
||||
/// This tests validates that with the new scope changes that the underlying cache policies work - in this case it tests that the cache policy
|
||||
/// with Count verification works.
|
||||
@@ -21,15 +27,13 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void DataTypeService_Can_Get_All()
|
||||
{
|
||||
var dataTypeService = ServiceContext.DataTypeService;
|
||||
|
||||
IDataType dataType = new DataType(new LabelPropertyEditor(LoggerFactory, IOHelper, DataTypeService,LocalizedTextService, LocalizationService, ShortStringHelper)) { Name = "Testing Textfield", DatabaseType = ValueStorageType.Ntext };
|
||||
dataTypeService.Save(dataType);
|
||||
IDataType dataType = new DataType(new LabelPropertyEditor(LoggerFactory, IOHelper, DataTypeService, LocalizedTextService, LocalizationService, ShortStringHelper)) { Name = "Testing Textfield", DatabaseType = ValueStorageType.Ntext };
|
||||
DataTypeService.Save(dataType);
|
||||
|
||||
//Get all the first time (no cache)
|
||||
var all = dataTypeService.GetAll();
|
||||
var all = DataTypeService.GetAll();
|
||||
//Get all a second time (with cache)
|
||||
all = dataTypeService.GetAll();
|
||||
all = DataTypeService.GetAll();
|
||||
|
||||
Assert.Pass();
|
||||
}
|
||||
@@ -2,23 +2,24 @@
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.Integration.Testing;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
{
|
||||
[TestFixture]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerFixture)]
|
||||
public class ConsentServiceTests : TestWithDatabaseBase
|
||||
public class ConsentServiceTests : UmbracoIntegrationTest
|
||||
{
|
||||
private IConsentService ConsentService => GetRequiredService<IConsentService>();
|
||||
|
||||
[Test]
|
||||
public void CanCrudConsent()
|
||||
{
|
||||
var consentService = ServiceContext.ConsentService;
|
||||
|
||||
// can register
|
||||
|
||||
var consent = consentService.RegisterConsent("user/1234", "app1", "do-something", ConsentState.Granted, "no comment");
|
||||
var consent = ConsentService.RegisterConsent("user/1234", "app1", "do-something", ConsentState.Granted, "no comment");
|
||||
Assert.AreNotEqual(0, consent.Id);
|
||||
|
||||
Assert.IsTrue(consent.Current);
|
||||
@@ -32,16 +33,16 @@ namespace Umbraco.Tests.Services
|
||||
|
||||
// can register more
|
||||
|
||||
consentService.RegisterConsent("user/1234", "app1", "do-something-else", ConsentState.Granted, "no comment");
|
||||
consentService.RegisterConsent("user/1236", "app1", "do-something", ConsentState.Granted, "no comment");
|
||||
consentService.RegisterConsent("user/1237", "app2", "do-something", ConsentState.Granted, "no comment");
|
||||
ConsentService.RegisterConsent("user/1234", "app1", "do-something-else", ConsentState.Granted, "no comment");
|
||||
ConsentService.RegisterConsent("user/1236", "app1", "do-something", ConsentState.Granted, "no comment");
|
||||
ConsentService.RegisterConsent("user/1237", "app2", "do-something", ConsentState.Granted, "no comment");
|
||||
|
||||
// can get by source
|
||||
|
||||
var consents = consentService.LookupConsent(source: "user/1235").ToArray();
|
||||
var consents = ConsentService.LookupConsent(source: "user/1235").ToArray();
|
||||
Assert.IsEmpty(consents);
|
||||
|
||||
consents = consentService.LookupConsent(source: "user/1234").ToArray();
|
||||
consents = ConsentService.LookupConsent(source: "user/1234").ToArray();
|
||||
Assert.AreEqual(2, consents.Length);
|
||||
Assert.IsTrue(consents.All(x => x.Source == "user/1234"));
|
||||
Assert.IsTrue(consents.Any(x => x.Action == "do-something"));
|
||||
@@ -49,23 +50,23 @@ namespace Umbraco.Tests.Services
|
||||
|
||||
// can get by context
|
||||
|
||||
consents = consentService.LookupConsent(context: "app3").ToArray();
|
||||
consents = ConsentService.LookupConsent(context: "app3").ToArray();
|
||||
Assert.IsEmpty(consents);
|
||||
|
||||
consents = consentService.LookupConsent(context: "app2").ToArray();
|
||||
consents = ConsentService.LookupConsent(context: "app2").ToArray();
|
||||
Assert.AreEqual(1, consents.Length);
|
||||
|
||||
consents = consentService.LookupConsent(context: "app1").ToArray();
|
||||
consents = ConsentService.LookupConsent(context: "app1").ToArray();
|
||||
Assert.AreEqual(3, consents.Length);
|
||||
Assert.IsTrue(consents.Any(x => x.Action == "do-something"));
|
||||
Assert.IsTrue(consents.Any(x => x.Action == "do-something-else"));
|
||||
|
||||
// can get by action
|
||||
|
||||
consents = consentService.LookupConsent(action: "do-whatever").ToArray();
|
||||
consents = ConsentService.LookupConsent(action: "do-whatever").ToArray();
|
||||
Assert.IsEmpty(consents);
|
||||
|
||||
consents = consentService.LookupConsent(context: "app1", action: "do-something").ToArray();
|
||||
consents = ConsentService.LookupConsent(context: "app1", action: "do-something").ToArray();
|
||||
Assert.AreEqual(2, consents.Length);
|
||||
Assert.IsTrue(consents.All(x => x.Action == "do-something"));
|
||||
Assert.IsTrue(consents.Any(x => x.Source == "user/1234"));
|
||||
@@ -73,23 +74,23 @@ namespace Umbraco.Tests.Services
|
||||
|
||||
// can revoke
|
||||
|
||||
consent = consentService.RegisterConsent("user/1234", "app1", "do-something", ConsentState.Revoked, "no comment");
|
||||
consent = ConsentService.RegisterConsent("user/1234", "app1", "do-something", ConsentState.Revoked, "no comment");
|
||||
|
||||
consents = consentService.LookupConsent(source: "user/1234", context: "app1", action: "do-something").ToArray();
|
||||
consents = ConsentService.LookupConsent(source: "user/1234", context: "app1", action: "do-something").ToArray();
|
||||
Assert.AreEqual(1, consents.Length);
|
||||
Assert.IsTrue(consents[0].Current);
|
||||
Assert.AreEqual(ConsentState.Revoked, consents[0].State);
|
||||
|
||||
// can filter
|
||||
|
||||
consents = consentService.LookupConsent(context: "app1", action: "do-", actionStartsWith: true).ToArray();
|
||||
consents = ConsentService.LookupConsent(context: "app1", action: "do-", actionStartsWith: true).ToArray();
|
||||
Assert.AreEqual(3, consents.Length);
|
||||
Assert.IsTrue(consents.All(x => x.Context == "app1"));
|
||||
Assert.IsTrue(consents.All(x => x.Action.StartsWith("do-")));
|
||||
|
||||
// can get history
|
||||
|
||||
consents = consentService.LookupConsent(source: "user/1234", context: "app1", action: "do-something", includeHistory: true).ToArray();
|
||||
consents = ConsentService.LookupConsent(source: "user/1234", context: "app1", action: "do-something", includeHistory: true).ToArray();
|
||||
Assert.AreEqual(1, consents.Length);
|
||||
Assert.IsTrue(consents[0].Current);
|
||||
Assert.AreEqual(ConsentState.Revoked, consents[0].State);
|
||||
@@ -103,19 +104,17 @@ namespace Umbraco.Tests.Services
|
||||
// cannot be stupid
|
||||
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
consentService.RegisterConsent("user/1234", "app1", "do-something", ConsentState.Granted | ConsentState.Revoked, "no comment"));
|
||||
ConsentService.RegisterConsent("user/1234", "app1", "do-something", ConsentState.Granted | ConsentState.Revoked, "no comment"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanRegisterConsentWithoutComment()
|
||||
{
|
||||
var consentService = ServiceContext.ConsentService;
|
||||
|
||||
// Attept to add consent without a comment
|
||||
consentService.RegisterConsent("user/1234", "app1", "consentWithoutComment", ConsentState.Granted);
|
||||
ConsentService.RegisterConsent("user/1234", "app1", "consentWithoutComment", ConsentState.Granted);
|
||||
|
||||
// Attempt to retrieve the consent we just added without a comment
|
||||
var consents = consentService.LookupConsent(source: "user/1234", action: "consentWithoutComment").ToArray();
|
||||
var consents = ConsentService.LookupConsent(source: "user/1234", action: "consentWithoutComment").ToArray();
|
||||
|
||||
// Confirm we got our expected consent record
|
||||
Assert.AreEqual(1, consents.Length);
|
||||
@@ -7,24 +7,29 @@ using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Repositories.Implement;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Services.Implement;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Integration.Testing;
|
||||
using Umbraco.Tests.TestHelpers.Entities;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
namespace Umbraco.Tests.Integration.Services
|
||||
{
|
||||
[TestFixture]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest,
|
||||
PublishedRepositoryEvents = true,
|
||||
WithApplication = true,
|
||||
Logger = UmbracoTestOptions.Logger.Console)]
|
||||
public class ContentServiceEventTests : TestWithSomeContentBase
|
||||
public class ContentServiceEventTests : UmbracoIntegrationTest
|
||||
{
|
||||
private IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
|
||||
private ContentService ContentService => (ContentService)GetRequiredService<IContentService>();
|
||||
private ILocalizationService LocalizationService => GetRequiredService<ILocalizationService>();
|
||||
private IFileService FileService => GetRequiredService<IFileService>();
|
||||
|
||||
private GlobalSettings _globalSettings;
|
||||
|
||||
public override void SetUp()
|
||||
[SetUp]
|
||||
public void SetupTest()
|
||||
{
|
||||
base.SetUp();
|
||||
ContentRepositoryBase.ThrowOnWarning = true;
|
||||
_globalSettings = new GlobalSettings();
|
||||
}
|
||||
@@ -38,28 +43,22 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void Saving_Culture()
|
||||
{
|
||||
var languageService = ServiceContext.LocalizationService;
|
||||
|
||||
languageService.Save(new Language(_globalSettings, "fr-FR"));
|
||||
|
||||
var contentTypeService = ServiceContext.ContentTypeService;
|
||||
LocalizationService.Save(new Language(_globalSettings, "fr-FR"));
|
||||
|
||||
var contentType = MockedContentTypes.CreateTextPageContentType();
|
||||
ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate);
|
||||
FileService.SaveTemplate(contentType.DefaultTemplate);
|
||||
contentType.Variations = ContentVariation.Culture;
|
||||
foreach (var propertyType in contentType.PropertyTypes)
|
||||
propertyType.Variations = ContentVariation.Culture;
|
||||
contentTypeService.Save(contentType);
|
||||
|
||||
var contentService = ServiceContext.ContentService;
|
||||
ContentTypeService.Save(contentType);
|
||||
|
||||
IContent document = new Content("content", -1, contentType);
|
||||
document.SetCultureName("hello", "en-US");
|
||||
document.SetCultureName("bonjour", "fr-FR");
|
||||
contentService.Save(document);
|
||||
ContentService.Save(document);
|
||||
|
||||
//re-get - dirty properties need resetting
|
||||
document = contentService.GetById(document.Id);
|
||||
document = ContentService.GetById(document.Id);
|
||||
|
||||
// properties: title, bodyText, keywords, description
|
||||
document.SetValue("title", "title-en", "en-US");
|
||||
@@ -88,7 +87,7 @@ namespace Umbraco.Tests.Services
|
||||
ContentService.Saved += OnSaved;
|
||||
try
|
||||
{
|
||||
contentService.Save(document);
|
||||
ContentService.Save(document);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -100,13 +99,9 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void Saving_Set_Value()
|
||||
{
|
||||
var contentTypeService = ServiceContext.ContentTypeService;
|
||||
|
||||
var contentType = MockedContentTypes.CreateTextPageContentType();
|
||||
ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate);
|
||||
contentTypeService.Save(contentType);
|
||||
|
||||
var contentService = ServiceContext.ContentService;
|
||||
FileService.SaveTemplate(contentType.DefaultTemplate);
|
||||
ContentTypeService.Save(contentType);
|
||||
|
||||
IContent document = new Content("content", -1, contentType);
|
||||
|
||||
@@ -136,44 +131,37 @@ namespace Umbraco.Tests.Services
|
||||
ContentService.Saved += OnSaved;
|
||||
try
|
||||
{
|
||||
contentService.Save(document);
|
||||
ContentService.Save(document);
|
||||
}
|
||||
finally
|
||||
{
|
||||
ContentService.Saving -= OnSaving;
|
||||
ContentService.Saved -= OnSaved;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Publishing_Culture()
|
||||
{
|
||||
var languageService = ServiceContext.LocalizationService;
|
||||
|
||||
languageService.Save(new Language(_globalSettings, "fr-FR"));
|
||||
|
||||
var contentTypeService = ServiceContext.ContentTypeService;
|
||||
LocalizationService.Save(new Language(_globalSettings, "fr-FR"));
|
||||
|
||||
var contentType = MockedContentTypes.CreateTextPageContentType();
|
||||
ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate);
|
||||
FileService.SaveTemplate(contentType.DefaultTemplate);
|
||||
contentType.Variations = ContentVariation.Culture;
|
||||
foreach (var propertyType in contentType.PropertyTypes)
|
||||
propertyType.Variations = ContentVariation.Culture;
|
||||
contentTypeService.Save(contentType);
|
||||
|
||||
var contentService = ServiceContext.ContentService;
|
||||
ContentTypeService.Save(contentType);
|
||||
|
||||
IContent document = new Content("content", -1, contentType);
|
||||
document.SetCultureName("hello", "en-US");
|
||||
document.SetCultureName("bonjour", "fr-FR");
|
||||
contentService.Save(document);
|
||||
ContentService.Save(document);
|
||||
|
||||
Assert.IsFalse(document.IsCulturePublished("fr-FR"));
|
||||
Assert.IsFalse(document.IsCulturePublished("en-US"));
|
||||
|
||||
//re-get - dirty properties need resetting
|
||||
document = contentService.GetById(document.Id);
|
||||
document = ContentService.GetById(document.Id);
|
||||
|
||||
void OnPublishing(IContentService sender, ContentPublishingEventArgs e)
|
||||
{
|
||||
@@ -199,7 +187,7 @@ namespace Umbraco.Tests.Services
|
||||
ContentService.Published += OnPublished;
|
||||
try
|
||||
{
|
||||
contentService.SaveAndPublish(document, "fr-FR");
|
||||
ContentService.SaveAndPublish(document, "fr-FR");
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -207,7 +195,7 @@ namespace Umbraco.Tests.Services
|
||||
ContentService.Published -= OnPublished;
|
||||
}
|
||||
|
||||
document = contentService.GetById(document.Id);
|
||||
document = ContentService.GetById(document.Id);
|
||||
|
||||
// ensure it works and does not throw
|
||||
Assert.IsTrue(document.IsCulturePublished("fr-FR"));
|
||||
@@ -217,13 +205,9 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void Publishing_Set_Value()
|
||||
{
|
||||
var contentTypeService = ServiceContext.ContentTypeService;
|
||||
|
||||
var contentType = MockedContentTypes.CreateTextPageContentType();
|
||||
ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate);
|
||||
contentTypeService.Save(contentType);
|
||||
|
||||
var contentService = ServiceContext.ContentService;
|
||||
FileService.SaveTemplate(contentType.DefaultTemplate);
|
||||
ContentTypeService.Save(contentType);
|
||||
|
||||
IContent document = new Content("content", -1, contentType);
|
||||
|
||||
@@ -242,21 +226,21 @@ namespace Umbraco.Tests.Services
|
||||
|
||||
Assert.AreSame("title", document.GetValue<string>("title"));
|
||||
|
||||
//we're only dealing with invariant here
|
||||
// We're only dealing with invariant here.
|
||||
var propValue = saved.Properties["title"].Values.First(x => x.Culture == null && x.Segment == null);
|
||||
|
||||
Assert.AreEqual("title", propValue.EditedValue);
|
||||
Assert.AreEqual("title", propValue.PublishedValue);
|
||||
}
|
||||
|
||||
//We are binding to Saving (not Publishing), because the Publishing event is really just used for cancelling, it should not be
|
||||
//used for setting values and it won't actually work! This is because the Publishing event is raised AFTER the values on the model
|
||||
//are published, but Saving is raised BEFORE.
|
||||
// We are binding to Saving (not Publishing), because the Publishing event is really just used for cancelling, it should not be
|
||||
// used for setting values and it won't actually work! This is because the Publishing event is raised AFTER the values on the model
|
||||
// are published, but Saving is raised BEFORE.
|
||||
ContentService.Saving += OnSaving;
|
||||
ContentService.Saved += OnSaved;
|
||||
try
|
||||
{
|
||||
contentService.SaveAndPublish(document);
|
||||
ContentService.SaveAndPublish(document);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -268,19 +252,15 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void Publishing_Set_Mandatory_Value()
|
||||
{
|
||||
var contentTypeService = ServiceContext.ContentTypeService;
|
||||
|
||||
var contentType = MockedContentTypes.CreateTextPageContentType();
|
||||
var titleProperty = contentType.PropertyTypes.First(x => x.Alias == "title");
|
||||
titleProperty.Mandatory = true; // make this required!
|
||||
ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate);
|
||||
contentTypeService.Save(contentType);
|
||||
|
||||
var contentService = ServiceContext.ContentService;
|
||||
FileService.SaveTemplate(contentType.DefaultTemplate);
|
||||
ContentTypeService.Save(contentType);
|
||||
|
||||
IContent document = new Content("content", -1, contentType);
|
||||
|
||||
var result = contentService.SaveAndPublish(document);
|
||||
var result = ContentService.SaveAndPublish(document);
|
||||
Assert.IsFalse(result.Success);
|
||||
Assert.AreEqual("title", result.InvalidProperties.First().Alias);
|
||||
|
||||
@@ -297,13 +277,13 @@ namespace Umbraco.Tests.Services
|
||||
saved.SetValue("title", "title");
|
||||
}
|
||||
|
||||
//We are binding to Saving (not Publishing), because the Publishing event is really just used for cancelling, it should not be
|
||||
//used for setting values and it won't actually work! This is because the Publishing event is raised AFTER the values on the model
|
||||
//are published, but Saving is raised BEFORE.
|
||||
// We are binding to Saving (not Publishing), because the Publishing event is really just used for cancelling, it should not be
|
||||
// used for setting values and it won't actually work! This is because the Publishing event is raised AFTER the values on the model
|
||||
// are published, but Saving is raised BEFORE.
|
||||
ContentService.Saving += OnSaving;
|
||||
try
|
||||
{
|
||||
result = contentService.SaveAndPublish(document);
|
||||
result = ContentService.SaveAndPublish(document);
|
||||
Assert.IsTrue(result.Success); //will succeed now because we were able to specify the required value in the Saving event
|
||||
}
|
||||
finally
|
||||
@@ -315,20 +295,16 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void Unpublishing_Culture()
|
||||
{
|
||||
var languageService = ServiceContext.LocalizationService;
|
||||
|
||||
languageService.Save(new Language(_globalSettings, "fr-FR"));
|
||||
|
||||
var contentTypeService = ServiceContext.ContentTypeService;
|
||||
LocalizationService.Save(new Language(_globalSettings, "fr-FR"));
|
||||
|
||||
var contentType = MockedContentTypes.CreateTextPageContentType();
|
||||
ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate);
|
||||
FileService.SaveTemplate(contentType.DefaultTemplate);
|
||||
contentType.Variations = ContentVariation.Culture;
|
||||
foreach (var propertyType in contentType.PropertyTypes)
|
||||
propertyType.Variations = ContentVariation.Culture;
|
||||
contentTypeService.Save(contentType);
|
||||
ContentTypeService.Save(contentType);
|
||||
|
||||
var contentService = (ContentService)ServiceContext.ContentService;
|
||||
var contentService = (ContentService)ContentService;
|
||||
|
||||
IContent document = new Content("content", -1, contentType);
|
||||
document.SetCultureName("hello", "en-US");
|
||||
@@ -6,8 +6,7 @@ using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration.Models;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.Integration.Testing;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
// ReSharper disable CommentTypo
|
||||
@@ -16,8 +15,12 @@ namespace Umbraco.Tests.Services
|
||||
{
|
||||
[TestFixture]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, PublishedRepositoryEvents = true, WithApplication = true)]
|
||||
public class ContentServicePublishBranchTests : TestWithDatabaseBase
|
||||
public class ContentServicePublishBranchTests : UmbracoIntegrationTest
|
||||
{
|
||||
private IContentService ContentService => GetRequiredService<IContentService>();
|
||||
private ILocalizationService LocalizationService => GetRequiredService<ILocalizationService>();
|
||||
private IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
|
||||
|
||||
[TestCase(1)] // use overload w/ culture: "*"
|
||||
[TestCase(2)] // use overload w/ cultures: new [] { "*" }
|
||||
public void Can_Publish_Invariant_Branch(int method)
|
||||
@@ -26,13 +29,13 @@ namespace Umbraco.Tests.Services
|
||||
|
||||
IContent iRoot = new Content("iroot", -1, iContentType);
|
||||
iRoot.SetValue("ip", "iroot");
|
||||
ServiceContext.ContentService.Save(iRoot);
|
||||
ContentService.Save(iRoot);
|
||||
IContent ii1 = new Content("ii1", iRoot, iContentType);
|
||||
ii1.SetValue("ip", "vii1");
|
||||
ServiceContext.ContentService.Save(ii1);
|
||||
ContentService.Save(ii1);
|
||||
IContent ii2 = new Content("ii2", iRoot, iContentType);
|
||||
ii2.SetValue("ip", "vii2");
|
||||
ServiceContext.ContentService.Save(ii2);
|
||||
ContentService.Save(ii2);
|
||||
|
||||
// iroot !published !edited
|
||||
// ii1 !published !edited
|
||||
@@ -51,24 +54,24 @@ namespace Umbraco.Tests.Services
|
||||
|
||||
// prepare
|
||||
|
||||
ServiceContext.ContentService.SaveAndPublish(iRoot);
|
||||
ServiceContext.ContentService.SaveAndPublish(ii1);
|
||||
ContentService.SaveAndPublish(iRoot);
|
||||
ContentService.SaveAndPublish(ii1);
|
||||
|
||||
IContent ii11 = new Content("ii11", ii1, iContentType);
|
||||
ii11.SetValue("ip", "vii11");
|
||||
ServiceContext.ContentService.SaveAndPublish(ii11);
|
||||
ContentService.SaveAndPublish(ii11);
|
||||
IContent ii12 = new Content("ii12", ii1, iContentType);
|
||||
ii11.SetValue("ip", "vii12");
|
||||
ServiceContext.ContentService.Save(ii12);
|
||||
ContentService.Save(ii12);
|
||||
|
||||
ServiceContext.ContentService.SaveAndPublish(ii2);
|
||||
ContentService.SaveAndPublish(ii2);
|
||||
IContent ii21 = new Content("ii21", ii2, iContentType);
|
||||
ii21.SetValue("ip", "vii21");
|
||||
ServiceContext.ContentService.SaveAndPublish(ii21);
|
||||
ContentService.SaveAndPublish(ii21);
|
||||
IContent ii22 = new Content("ii22", ii2, iContentType);
|
||||
ii22.SetValue("ip", "vii22");
|
||||
ServiceContext.ContentService.Save(ii22);
|
||||
ServiceContext.ContentService.Unpublish(ii2);
|
||||
ContentService.Save(ii22);
|
||||
ContentService.Unpublish(ii2);
|
||||
|
||||
// iroot published !edited
|
||||
// ii1 published !edited
|
||||
@@ -94,9 +97,9 @@ namespace Umbraco.Tests.Services
|
||||
// prepare
|
||||
|
||||
iRoot.SetValue("ip", "changed");
|
||||
ServiceContext.ContentService.Save(iRoot);
|
||||
ContentService.Save(iRoot);
|
||||
ii11.SetValue("ip", "changed");
|
||||
ServiceContext.ContentService.Save(ii11);
|
||||
ContentService.Save(ii11);
|
||||
|
||||
// iroot published edited ***
|
||||
// ii1 published !edited
|
||||
@@ -133,7 +136,7 @@ namespace Umbraco.Tests.Services
|
||||
PublishResultType.SuccessPublishAlready, // was masked
|
||||
PublishResultType.SuccessPublish);
|
||||
|
||||
ii21 = ServiceContext.ContentService.GetById(ii21.Id);
|
||||
ii21 = ContentService.GetById(ii21.Id);
|
||||
Assert.IsTrue(ii21.Published);
|
||||
}
|
||||
|
||||
@@ -151,7 +154,7 @@ namespace Umbraco.Tests.Services
|
||||
vRoot.SetValue("vp", "vroot.de", "de");
|
||||
vRoot.SetValue("vp", "vroot.ru", "ru");
|
||||
vRoot.SetValue("vp", "vroot.es", "es");
|
||||
ServiceContext.ContentService.SaveAndPublish(vRoot);
|
||||
ContentService.SaveAndPublish(vRoot);
|
||||
|
||||
//create/publish child
|
||||
IContent iv1 = new Content("iv1", vRoot, vContentType, "de");
|
||||
@@ -162,13 +165,13 @@ namespace Umbraco.Tests.Services
|
||||
iv1.SetValue("vp", "iv1.de", "de");
|
||||
iv1.SetValue("vp", "iv1.ru", "ru");
|
||||
iv1.SetValue("vp", "iv1.es", "es");
|
||||
ServiceContext.ContentService.SaveAndPublish(iv1);
|
||||
ContentService.SaveAndPublish(iv1);
|
||||
|
||||
//update the child
|
||||
iv1.SetValue("vp", "UPDATED-iv1.de", "de");
|
||||
ServiceContext.ContentService.Save(iv1);
|
||||
ContentService.Save(iv1);
|
||||
|
||||
var r = ServiceContext.ContentService.SaveAndPublishBranch(vRoot, false).ToArray(); //no culture specified so "*" is used, so all cultures
|
||||
var r = ContentService.SaveAndPublishBranch(vRoot, false).ToArray(); //no culture specified so "*" is used, so all cultures
|
||||
Assert.AreEqual(PublishResultType.SuccessPublishAlready, r[0].Result);
|
||||
Assert.AreEqual(PublishResultType.SuccessPublishCulture, r[1].Result);
|
||||
}
|
||||
@@ -187,7 +190,7 @@ namespace Umbraco.Tests.Services
|
||||
vRoot.SetValue("vp", "vroot.de", "de");
|
||||
vRoot.SetValue("vp", "vroot.ru", "ru");
|
||||
vRoot.SetValue("vp", "vroot.es", "es");
|
||||
ServiceContext.ContentService.SaveAndPublish(vRoot);
|
||||
ContentService.SaveAndPublish(vRoot);
|
||||
|
||||
//create/publish child
|
||||
IContent iv1 = new Content("iv1", vRoot, vContentType, "de");
|
||||
@@ -198,13 +201,13 @@ namespace Umbraco.Tests.Services
|
||||
iv1.SetValue("vp", "iv1.de", "de");
|
||||
iv1.SetValue("vp", "iv1.ru", "ru");
|
||||
iv1.SetValue("vp", "iv1.es", "es");
|
||||
ServiceContext.ContentService.SaveAndPublish(iv1);
|
||||
ContentService.SaveAndPublish(iv1);
|
||||
|
||||
//update the child
|
||||
iv1.SetValue("vp", "UPDATED-iv1.de", "de");
|
||||
var saveResult = ServiceContext.ContentService.Save(iv1);
|
||||
var saveResult = ContentService.Save(iv1);
|
||||
|
||||
var r = ServiceContext.ContentService.SaveAndPublishBranch(vRoot, false, "de").ToArray();
|
||||
var r = ContentService.SaveAndPublishBranch(vRoot, false, "de").ToArray();
|
||||
Assert.AreEqual(PublishResultType.SuccessPublishAlready, r[0].Result);
|
||||
Assert.AreEqual(PublishResultType.SuccessPublishCulture, r[1].Result);
|
||||
}
|
||||
@@ -222,7 +225,7 @@ namespace Umbraco.Tests.Services
|
||||
vRoot.SetValue("vp", "vroot.de", "de");
|
||||
vRoot.SetValue("vp", "vroot.ru", "ru");
|
||||
vRoot.SetValue("vp", "vroot.es", "es");
|
||||
ServiceContext.ContentService.Save(vRoot);
|
||||
ContentService.Save(vRoot);
|
||||
|
||||
IContent iv1 = new Content("iv1", vRoot, vContentType, "de");
|
||||
iv1.SetCultureName("iv1.de", "de");
|
||||
@@ -232,7 +235,7 @@ namespace Umbraco.Tests.Services
|
||||
iv1.SetValue("vp", "iv1.de", "de");
|
||||
iv1.SetValue("vp", "iv1.ru", "ru");
|
||||
iv1.SetValue("vp", "iv1.es", "es");
|
||||
ServiceContext.ContentService.Save(iv1);
|
||||
ContentService.Save(iv1);
|
||||
|
||||
IContent iv2 = new Content("iv2", vRoot, vContentType, "de");
|
||||
iv2.SetCultureName("iv2.de", "de");
|
||||
@@ -242,7 +245,7 @@ namespace Umbraco.Tests.Services
|
||||
iv2.SetValue("vp", "iv2.de", "de");
|
||||
iv2.SetValue("vp", "iv2.ru", "ru");
|
||||
iv2.SetValue("vp", "iv2.es", "es");
|
||||
ServiceContext.ContentService.Save(iv2);
|
||||
ContentService.Save(iv2);
|
||||
|
||||
// vroot !published !edited
|
||||
// iv1 !published !edited
|
||||
@@ -251,7 +254,7 @@ namespace Umbraco.Tests.Services
|
||||
// !force = publishes those that are actually published, and have changes
|
||||
// here: nothing
|
||||
|
||||
var r = ServiceContext.ContentService.SaveAndPublishBranch(vRoot, false).ToArray(); // no culture specified = all cultures
|
||||
var r = ContentService.SaveAndPublishBranch(vRoot, false).ToArray(); // no culture specified = all cultures
|
||||
|
||||
// not forcing, iv1 and iv2 not published yet: only root got published
|
||||
AssertPublishResults(r, x => x.Content.Name,
|
||||
@@ -264,15 +267,15 @@ namespace Umbraco.Tests.Services
|
||||
vRoot.SetValue("vp", "changed.de", "de");
|
||||
vRoot.SetValue("vp", "changed.ru", "ru");
|
||||
vRoot.SetValue("vp", "changed.es", "es");
|
||||
ServiceContext.ContentService.Save(vRoot); // now root has drafts in all cultures
|
||||
ContentService.Save(vRoot); // now root has drafts in all cultures
|
||||
|
||||
ServiceContext.ContentService.SaveAndPublish(iv1, new []{"de", "ru"}); // now iv1 de and ru are published
|
||||
ContentService.SaveAndPublish(iv1, new []{"de", "ru"}); // now iv1 de and ru are published
|
||||
|
||||
iv1.SetValue("ip", "changed");
|
||||
iv1.SetValue("vp", "changed.de", "de");
|
||||
iv1.SetValue("vp", "changed.ru", "ru");
|
||||
iv1.SetValue("vp", "changed.es", "es");
|
||||
ServiceContext.ContentService.Save(iv1); // now iv1 has drafts in all cultures
|
||||
ContentService.Save(iv1); // now iv1 has drafts in all cultures
|
||||
|
||||
// validate - everything published for root, because no culture was specified = all
|
||||
Assert.IsTrue(vRoot.Published);
|
||||
@@ -286,7 +289,7 @@ namespace Umbraco.Tests.Services
|
||||
Assert.IsTrue(iv1.IsCulturePublished("ru"));
|
||||
Assert.IsFalse(iv1.IsCulturePublished("es"));
|
||||
|
||||
r = ServiceContext.ContentService.SaveAndPublishBranch(vRoot, false, "de").ToArray();
|
||||
r = ContentService.SaveAndPublishBranch(vRoot, false, "de").ToArray();
|
||||
|
||||
// not forcing, iv2 not published yet: only root and iv1 got published
|
||||
AssertPublishResults(r, x => x.Content.Name,
|
||||
@@ -332,21 +335,21 @@ namespace Umbraco.Tests.Services
|
||||
// invariant root -> invariant -> variant
|
||||
iRoot = new Content("iroot", -1, iContentType);
|
||||
iRoot.SetValue("ip", "iroot");
|
||||
ServiceContext.ContentService.SaveAndPublish(iRoot);
|
||||
ContentService.SaveAndPublish(iRoot);
|
||||
ii1 = new Content("ii1", iRoot, iContentType);
|
||||
ii1.SetValue("ip", "vii1");
|
||||
ServiceContext.ContentService.SaveAndPublish(ii1);
|
||||
ContentService.SaveAndPublish(ii1);
|
||||
ii1.SetValue("ip", "changed");
|
||||
ServiceContext.ContentService.Save(ii1);
|
||||
ContentService.Save(ii1);
|
||||
iv11 = new Content("iv11.de", ii1, vContentType, "de");
|
||||
iv11.SetValue("ip", "iv11");
|
||||
iv11.SetValue("vp", "iv11.de", "de");
|
||||
iv11.SetValue("vp", "iv11.ru", "ru");
|
||||
iv11.SetValue("vp", "iv11.es", "es");
|
||||
ServiceContext.ContentService.Save(iv11);
|
||||
ContentService.Save(iv11);
|
||||
|
||||
iv11.SetCultureName("iv11.ru", "ru");
|
||||
var xxx = ServiceContext.ContentService.SaveAndPublish(iv11, new []{"de", "ru"});
|
||||
var xxx = ContentService.SaveAndPublish(iv11, new []{"de", "ru"});
|
||||
|
||||
Assert.AreEqual("iv11.de", iv11.GetValue("vp", "de", published: true));
|
||||
Assert.AreEqual("iv11.ru", iv11.GetValue("vp", "ru", published: true));
|
||||
@@ -354,7 +357,7 @@ namespace Umbraco.Tests.Services
|
||||
iv11.SetValue("ip", "changed");
|
||||
iv11.SetValue("vp", "changed.de", "de");
|
||||
iv11.SetValue("vp", "changed.ru", "ru");
|
||||
ServiceContext.ContentService.Save(iv11);
|
||||
ContentService.Save(iv11);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -362,7 +365,7 @@ namespace Umbraco.Tests.Services
|
||||
{
|
||||
Can_Publish_Mixed_Branch(out var iRoot, out var ii1, out var iv11);
|
||||
|
||||
var r = ServiceContext.ContentService.SaveAndPublishBranch(iRoot, false, "de").ToArray();
|
||||
var r = ContentService.SaveAndPublishBranch(iRoot, false, "de").ToArray();
|
||||
AssertPublishResults(r, x => x.Content.Name,
|
||||
"iroot", "ii1", "iv11.de");
|
||||
AssertPublishResults(r, x => x.Result,
|
||||
@@ -388,7 +391,7 @@ namespace Umbraco.Tests.Services
|
||||
{
|
||||
Can_Publish_Mixed_Branch(out var iRoot, out var ii1, out var iv11);
|
||||
|
||||
var r = ServiceContext.ContentService.SaveAndPublishBranch(iRoot, false, new[] { "de", "ru" }).ToArray();
|
||||
var r = ContentService.SaveAndPublishBranch(iRoot, false, new[] { "de", "ru" }).ToArray();
|
||||
AssertPublishResults(r, x => x.Content.Name,
|
||||
"iroot", "ii1", "iv11.de");
|
||||
AssertPublishResults(r, x => x.Result,
|
||||
@@ -423,18 +426,18 @@ namespace Umbraco.Tests.Services
|
||||
}
|
||||
|
||||
private void Reload(ref IContent document)
|
||||
=> document = ServiceContext.ContentService.GetById(document.Id);
|
||||
=> document = ContentService.GetById(document.Id);
|
||||
|
||||
private void CreateTypes(out IContentType iContentType, out IContentType vContentType)
|
||||
{
|
||||
var globalSettings = new GlobalSettings();
|
||||
|
||||
var langDe = new Language(globalSettings, "de") { IsDefault = true };
|
||||
ServiceContext.LocalizationService.Save(langDe);
|
||||
LocalizationService.Save(langDe);
|
||||
var langRu = new Language(globalSettings, "ru");
|
||||
ServiceContext.LocalizationService.Save(langRu);
|
||||
LocalizationService.Save(langRu);
|
||||
var langEs = new Language(globalSettings, "es");
|
||||
ServiceContext.LocalizationService.Save(langEs);
|
||||
LocalizationService.Save(langEs);
|
||||
|
||||
iContentType = new ContentType(ShortStringHelper, -1)
|
||||
{
|
||||
@@ -443,7 +446,7 @@ namespace Umbraco.Tests.Services
|
||||
Variations = ContentVariation.Nothing
|
||||
};
|
||||
iContentType.AddPropertyType(new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Nvarchar, "ip") { Variations = ContentVariation.Nothing });
|
||||
ServiceContext.ContentTypeService.Save(iContentType);
|
||||
ContentTypeService.Save(iContentType);
|
||||
|
||||
vContentType = new ContentType(ShortStringHelper, -1)
|
||||
{
|
||||
@@ -453,7 +456,7 @@ namespace Umbraco.Tests.Services
|
||||
};
|
||||
vContentType.AddPropertyType(new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Nvarchar, "ip") { Variations = ContentVariation.Nothing });
|
||||
vContentType.AddPropertyType(new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Nvarchar, "vp") { Variations = ContentVariation.Culture });
|
||||
ServiceContext.ContentTypeService.Save(vContentType);
|
||||
ContentTypeService.Save(vContentType);
|
||||
}
|
||||
|
||||
private IEnumerable<PublishResult> SaveAndPublishInvariantBranch(IContent content, bool force, int method)
|
||||
@@ -463,9 +466,9 @@ namespace Umbraco.Tests.Services
|
||||
switch (method)
|
||||
{
|
||||
case 1:
|
||||
return ServiceContext.ContentService.SaveAndPublishBranch(content, force, culture: "*");
|
||||
return ContentService.SaveAndPublishBranch(content, force, culture: "*");
|
||||
case 2:
|
||||
return ServiceContext.ContentService.SaveAndPublishBranch(content, force, cultures: new [] { "*" });
|
||||
return ContentService.SaveAndPublishBranch(content, force, cultures: new [] { "*" });
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(method));
|
||||
}
|
||||
@@ -3,8 +3,10 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.Integration.Testing;
|
||||
using Umbraco.Tests.TestHelpers.Entities;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
@@ -15,23 +17,26 @@ namespace Umbraco.Tests.Services
|
||||
[TestFixture]
|
||||
[Apartment(ApartmentState.STA)]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
||||
public class DataTypeServiceTests : TestWithSomeContentBase
|
||||
public class DataTypeServiceTests : UmbracoIntegrationTest
|
||||
{
|
||||
|
||||
private IDataTypeService DataTypeService => GetRequiredService<IDataTypeService>();
|
||||
private IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
|
||||
private ILocalizedTextService LocalizedTextService => GetRequiredService<ILocalizedTextService>();
|
||||
private ILocalizationService LocalizationService => GetRequiredService<ILocalizationService>();
|
||||
|
||||
[Test]
|
||||
public void DataTypeService_Can_Persist_New_DataTypeDefinition()
|
||||
{
|
||||
// Arrange
|
||||
var dataTypeService = ServiceContext.DataTypeService;
|
||||
|
||||
// Act
|
||||
IDataType dataType = new DataType(new LabelPropertyEditor(LoggerFactory, IOHelper, DataTypeService, LocalizedTextService,LocalizationService, ShortStringHelper)) { Name = "Testing Textfield", DatabaseType = ValueStorageType.Ntext };
|
||||
dataTypeService.Save(dataType);
|
||||
IDataType dataType = new DataType(new LabelPropertyEditor(LoggerFactory, IOHelper, DataTypeService, LocalizedTextService, LocalizationService, ShortStringHelper)) { Name = "Testing Textfield", DatabaseType = ValueStorageType.Ntext };
|
||||
DataTypeService.Save(dataType);
|
||||
|
||||
// Assert
|
||||
Assert.That(dataType, Is.Not.Null);
|
||||
Assert.That(dataType.HasIdentity, Is.True);
|
||||
|
||||
dataType = dataTypeService.GetDataType(dataType.Id);
|
||||
dataType = DataTypeService.GetDataType(dataType.Id);
|
||||
Assert.That(dataType, Is.Not.Null);
|
||||
}
|
||||
|
||||
@@ -39,22 +44,24 @@ namespace Umbraco.Tests.Services
|
||||
public void DataTypeService_Can_Delete_Textfield_DataType_And_Clear_Usages()
|
||||
{
|
||||
// Arrange
|
||||
var dataTypeService = ServiceContext.DataTypeService;
|
||||
var textfieldId = "Umbraco.Textbox";
|
||||
var dataTypeDefinitions = dataTypeService.GetByEditorAlias(textfieldId);
|
||||
var dataTypeDefinitions = DataTypeService.GetByEditorAlias(textfieldId);
|
||||
var doctype = MockedContentTypes.CreateSimpleContentType("umbTextpage", "Textpage");
|
||||
ContentTypeService.Save(doctype);
|
||||
|
||||
|
||||
// Act
|
||||
var definition = dataTypeDefinitions.First();
|
||||
var definitionId = definition.Id;
|
||||
dataTypeService.Delete(definition);
|
||||
DataTypeService.Delete(definition);
|
||||
|
||||
var deletedDefinition = dataTypeService.GetDataType(definitionId);
|
||||
var deletedDefinition = DataTypeService.GetDataType(definitionId);
|
||||
|
||||
// Assert
|
||||
Assert.That(deletedDefinition, Is.Null);
|
||||
|
||||
//Further assertions against the ContentType that contains PropertyTypes based on the TextField
|
||||
var contentType = ServiceContext.ContentTypeService.Get(NodeDto.NodeIdSeed+1);
|
||||
var contentType = ContentTypeService.Get(doctype.Id);
|
||||
Assert.That(contentType.Alias, Is.EqualTo("umbTextpage"));
|
||||
Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(1));
|
||||
}
|
||||
@@ -62,14 +69,11 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void Cannot_Save_DataType_With_Empty_Name()
|
||||
{
|
||||
// Arrange
|
||||
var dataTypeService = ServiceContext.DataTypeService;
|
||||
|
||||
// Act
|
||||
var dataTypeDefinition = new DataType(new LabelPropertyEditor(LoggerFactory, IOHelper, DataTypeService, LocalizedTextService,LocalizationService, ShortStringHelper)) { Name = string.Empty, DatabaseType = ValueStorageType.Ntext };
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<ArgumentException>(() => dataTypeService.Save(dataTypeDefinition));
|
||||
Assert.Throws<ArgumentException>(() => DataTypeService.Save(dataTypeDefinition));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,10 +7,9 @@ using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration.Models;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Entities;
|
||||
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.Integration.Testing;
|
||||
using Umbraco.Tests.TestHelpers.Entities;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
@@ -22,66 +21,74 @@ namespace Umbraco.Tests.Services
|
||||
[TestFixture]
|
||||
[Apartment(ApartmentState.STA)]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerFixture)]
|
||||
public class EntityServiceTests : TestWithSomeContentBase
|
||||
public class EntityServiceTests : UmbracoIntegrationTest
|
||||
{
|
||||
private Language _langFr;
|
||||
private Language _langEs;
|
||||
|
||||
public override void SetUp()
|
||||
{
|
||||
base.SetUp();
|
||||
private ILocalizationService LocalizationService => GetRequiredService<ILocalizationService>();
|
||||
private IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
|
||||
private IContentService ContentService => GetRequiredService<IContentService>();
|
||||
private IEntityService EntityService => GetRequiredService<IEntityService>();
|
||||
private ISqlContext SqlContext => GetRequiredService<ISqlContext>();
|
||||
private IMediaTypeService MediaTypeService => GetRequiredService<IMediaTypeService>();
|
||||
private IMediaService MediaService => GetRequiredService<IMediaService>();
|
||||
private IFileService FileService => GetRequiredService<IFileService>();
|
||||
|
||||
[SetUp]
|
||||
public void SetupTestData()
|
||||
{
|
||||
if (_langFr == null && _langEs == null)
|
||||
{
|
||||
var globalSettings = new GlobalSettings();
|
||||
_langFr = new Language(globalSettings, "fr-FR");
|
||||
_langEs = new Language(globalSettings, "es-ES");
|
||||
ServiceContext.LocalizationService.Save(_langFr);
|
||||
ServiceContext.LocalizationService.Save(_langEs);
|
||||
LocalizationService.Save(_langFr);
|
||||
LocalizationService.Save(_langEs);
|
||||
}
|
||||
|
||||
CreateTestData();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EntityService_Can_Get_Paged_Descendants_Ordering_Path()
|
||||
{
|
||||
|
||||
var contentType = ServiceContext.ContentTypeService.Get("umbTextpage");
|
||||
var contentType = ContentTypeService.Get("umbTextpage");
|
||||
|
||||
var root = MockedContent.CreateSimpleContent(contentType);
|
||||
ServiceContext.ContentService.Save(root);
|
||||
ContentService.Save(root);
|
||||
var rootId = root.Id;
|
||||
var ids = new List<int>();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
var c1 = MockedContent.CreateSimpleContent(contentType, Guid.NewGuid().ToString(), root);
|
||||
ServiceContext.ContentService.Save(c1);
|
||||
ContentService.Save(c1);
|
||||
ids.Add(c1.Id);
|
||||
root = c1; // make a hierarchy
|
||||
}
|
||||
|
||||
var service = ServiceContext.EntityService;
|
||||
|
||||
long total;
|
||||
|
||||
var entities = service.GetPagedDescendants(rootId, UmbracoObjectTypes.Document, 0, 6, out total).ToArray();
|
||||
var entities = EntityService.GetPagedDescendants(rootId, UmbracoObjectTypes.Document, 0, 6, out total).ToArray();
|
||||
Assert.That(entities.Length, Is.EqualTo(6));
|
||||
Assert.That(total, Is.EqualTo(10));
|
||||
Assert.AreEqual(ids[0], entities[0].Id);
|
||||
|
||||
entities = service.GetPagedDescendants(rootId, UmbracoObjectTypes.Document, 1, 6, out total).ToArray();
|
||||
entities = EntityService.GetPagedDescendants(rootId, UmbracoObjectTypes.Document, 1, 6, out total).ToArray();
|
||||
Assert.That(entities.Length, Is.EqualTo(4));
|
||||
Assert.That(total, Is.EqualTo(10));
|
||||
Assert.AreEqual(ids[6], entities[0].Id);
|
||||
|
||||
//Test ordering direction
|
||||
|
||||
entities = service.GetPagedDescendants(rootId, UmbracoObjectTypes.Document, 0, 6, out total,
|
||||
entities = EntityService.GetPagedDescendants(rootId, UmbracoObjectTypes.Document, 0, 6, out total,
|
||||
ordering: Ordering.By("Path", Direction.Descending)).ToArray();
|
||||
Assert.That(entities.Length, Is.EqualTo(6));
|
||||
Assert.That(total, Is.EqualTo(10));
|
||||
Assert.AreEqual(ids[ids.Count - 1], entities[0].Id);
|
||||
|
||||
entities = service.GetPagedDescendants(rootId, UmbracoObjectTypes.Document, 1, 6, out total,
|
||||
entities = EntityService.GetPagedDescendants(rootId, UmbracoObjectTypes.Document, 1, 6, out total,
|
||||
ordering: Ordering.By("Path", Direction.Descending)).ToArray();
|
||||
Assert.That(entities.Length, Is.EqualTo(4));
|
||||
Assert.That(total, Is.EqualTo(10));
|
||||
@@ -92,41 +99,39 @@ namespace Umbraco.Tests.Services
|
||||
public void EntityService_Can_Get_Paged_Content_Children()
|
||||
{
|
||||
|
||||
var contentType = ServiceContext.ContentTypeService.Get("umbTextpage");
|
||||
var contentType = ContentTypeService.Get("umbTextpage");
|
||||
|
||||
var root = MockedContent.CreateSimpleContent(contentType);
|
||||
ServiceContext.ContentService.Save(root);
|
||||
ContentService.Save(root);
|
||||
var ids = new List<int>();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
var c1 = MockedContent.CreateSimpleContent(contentType, Guid.NewGuid().ToString(), root);
|
||||
ServiceContext.ContentService.Save(c1);
|
||||
ContentService.Save(c1);
|
||||
ids.Add(c1.Id);
|
||||
}
|
||||
|
||||
var service = ServiceContext.EntityService;
|
||||
|
||||
long total;
|
||||
|
||||
var entities = service.GetPagedChildren(root.Id, UmbracoObjectTypes.Document, 0, 6, out total).ToArray();
|
||||
var entities = EntityService.GetPagedChildren(root.Id, UmbracoObjectTypes.Document, 0, 6, out total).ToArray();
|
||||
Assert.That(entities.Length, Is.EqualTo(6));
|
||||
Assert.That(total, Is.EqualTo(10));
|
||||
Assert.AreEqual(ids[0], entities[0].Id);
|
||||
|
||||
entities = service.GetPagedChildren(root.Id, UmbracoObjectTypes.Document, 1, 6, out total).ToArray();
|
||||
entities = EntityService.GetPagedChildren(root.Id, UmbracoObjectTypes.Document, 1, 6, out total).ToArray();
|
||||
Assert.That(entities.Length, Is.EqualTo(4));
|
||||
Assert.That(total, Is.EqualTo(10));
|
||||
Assert.AreEqual(ids[6], entities[0].Id);
|
||||
|
||||
//Test ordering direction
|
||||
|
||||
entities = service.GetPagedChildren(root.Id, UmbracoObjectTypes.Document, 0, 6, out total,
|
||||
entities = EntityService.GetPagedChildren(root.Id, UmbracoObjectTypes.Document, 0, 6, out total,
|
||||
ordering: Ordering.By("SortOrder", Direction.Descending)).ToArray();
|
||||
Assert.That(entities.Length, Is.EqualTo(6));
|
||||
Assert.That(total, Is.EqualTo(10));
|
||||
Assert.AreEqual(ids[ids.Count - 1], entities[0].Id);
|
||||
|
||||
entities = service.GetPagedChildren(root.Id, UmbracoObjectTypes.Document, 1, 6, out total,
|
||||
entities = EntityService.GetPagedChildren(root.Id, UmbracoObjectTypes.Document, 1, 6, out total,
|
||||
ordering: Ordering.By("SortOrder", Direction.Descending)).ToArray();
|
||||
Assert.That(entities.Length, Is.EqualTo(4));
|
||||
Assert.That(total, Is.EqualTo(10));
|
||||
@@ -136,32 +141,30 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void EntityService_Can_Get_Paged_Content_Descendants()
|
||||
{
|
||||
var contentType = ServiceContext.ContentTypeService.Get("umbTextpage");
|
||||
var contentType = ContentTypeService.Get("umbTextpage");
|
||||
|
||||
var root = MockedContent.CreateSimpleContent(contentType);
|
||||
ServiceContext.ContentService.Save(root);
|
||||
ContentService.Save(root);
|
||||
var count = 0;
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
var c1 = MockedContent.CreateSimpleContent(contentType, Guid.NewGuid().ToString(), root);
|
||||
ServiceContext.ContentService.Save(c1);
|
||||
ContentService.Save(c1);
|
||||
count++;
|
||||
|
||||
for (int j = 0; j < 5; j++)
|
||||
{
|
||||
var c2 = MockedContent.CreateSimpleContent(contentType, Guid.NewGuid().ToString(), c1);
|
||||
ServiceContext.ContentService.Save(c2);
|
||||
ContentService.Save(c2);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
var service = ServiceContext.EntityService;
|
||||
|
||||
long total;
|
||||
var entities = service.GetPagedDescendants(root.Id, UmbracoObjectTypes.Document, 0, 31, out total).ToArray();
|
||||
var entities = EntityService.GetPagedDescendants(root.Id, UmbracoObjectTypes.Document, 0, 31, out total).ToArray();
|
||||
Assert.That(entities.Length, Is.EqualTo(31));
|
||||
Assert.That(total, Is.EqualTo(60));
|
||||
entities = service.GetPagedDescendants(root.Id, UmbracoObjectTypes.Document, 1, 31, out total).ToArray();
|
||||
entities = EntityService.GetPagedDescendants(root.Id, UmbracoObjectTypes.Document, 1, 31, out total).ToArray();
|
||||
Assert.That(entities.Length, Is.EqualTo(29));
|
||||
Assert.That(total, Is.EqualTo(60));
|
||||
}
|
||||
@@ -169,15 +172,15 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void EntityService_Can_Get_Paged_Content_Descendants_Including_Recycled()
|
||||
{
|
||||
var contentType = ServiceContext.ContentTypeService.Get("umbTextpage");
|
||||
var contentType = ContentTypeService.Get("umbTextpage");
|
||||
|
||||
var root = MockedContent.CreateSimpleContent(contentType);
|
||||
ServiceContext.ContentService.Save(root);
|
||||
ContentService.Save(root);
|
||||
var toDelete = new List<IContent>();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
var c1 = MockedContent.CreateSimpleContent(contentType, Guid.NewGuid().ToString(), root);
|
||||
ServiceContext.ContentService.Save(c1);
|
||||
ContentService.Save(c1);
|
||||
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
@@ -187,20 +190,18 @@ namespace Umbraco.Tests.Services
|
||||
for (int j = 0; j < 5; j++)
|
||||
{
|
||||
var c2 = MockedContent.CreateSimpleContent(contentType, Guid.NewGuid().ToString(), c1);
|
||||
ServiceContext.ContentService.Save(c2);
|
||||
ContentService.Save(c2);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var content in toDelete)
|
||||
{
|
||||
ServiceContext.ContentService.MoveToRecycleBin(content);
|
||||
ContentService.MoveToRecycleBin(content);
|
||||
}
|
||||
|
||||
var service = ServiceContext.EntityService;
|
||||
|
||||
long total;
|
||||
//search at root to see if it returns recycled
|
||||
var entities = service.GetPagedDescendants(-1, UmbracoObjectTypes.Document, 0, 1000, out total)
|
||||
var entities = EntityService.GetPagedDescendants(-1, UmbracoObjectTypes.Document, 0, 1000, out total)
|
||||
.Select(x => x.Id)
|
||||
.ToArray();
|
||||
|
||||
@@ -213,15 +214,15 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void EntityService_Can_Get_Paged_Content_Descendants_Without_Recycled()
|
||||
{
|
||||
var contentType = ServiceContext.ContentTypeService.Get("umbTextpage");
|
||||
var contentType = ContentTypeService.Get("umbTextpage");
|
||||
|
||||
var root = MockedContent.CreateSimpleContent(contentType);
|
||||
ServiceContext.ContentService.Save(root);
|
||||
ContentService.Save(root);
|
||||
var toDelete = new List<IContent>();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
var c1 = MockedContent.CreateSimpleContent(contentType, Guid.NewGuid().ToString(), root);
|
||||
ServiceContext.ContentService.Save(c1);
|
||||
ContentService.Save(c1);
|
||||
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
@@ -231,20 +232,18 @@ namespace Umbraco.Tests.Services
|
||||
for (int j = 0; j < 5; j++)
|
||||
{
|
||||
var c2 = MockedContent.CreateSimpleContent(contentType, Guid.NewGuid().ToString(), c1);
|
||||
ServiceContext.ContentService.Save(c2);
|
||||
ContentService.Save(c2);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var content in toDelete)
|
||||
{
|
||||
ServiceContext.ContentService.MoveToRecycleBin(content);
|
||||
ContentService.MoveToRecycleBin(content);
|
||||
}
|
||||
|
||||
var service = ServiceContext.EntityService;
|
||||
|
||||
long total;
|
||||
//search at root to see if it returns recycled
|
||||
var entities = service.GetPagedDescendants(UmbracoObjectTypes.Document, 0, 1000, out total, includeTrashed: false)
|
||||
var entities = EntityService.GetPagedDescendants(UmbracoObjectTypes.Document, 0, 1000, out total, includeTrashed: false)
|
||||
.Select(x => x.Id)
|
||||
.ToArray();
|
||||
|
||||
@@ -257,31 +256,29 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void EntityService_Can_Get_Paged_Content_Descendants_With_Search()
|
||||
{
|
||||
var contentType = ServiceContext.ContentTypeService.Get("umbTextpage");
|
||||
var contentType = ContentTypeService.Get("umbTextpage");
|
||||
|
||||
var root = MockedContent.CreateSimpleContent(contentType);
|
||||
ServiceContext.ContentService.Save(root);
|
||||
ContentService.Save(root);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
var c1 = MockedContent.CreateSimpleContent(contentType, "ssss" + Guid.NewGuid(), root);
|
||||
ServiceContext.ContentService.Save(c1);
|
||||
ContentService.Save(c1);
|
||||
|
||||
for (int j = 0; j < 5; j++)
|
||||
{
|
||||
var c2 = MockedContent.CreateSimpleContent(contentType, "tttt" + Guid.NewGuid(), c1);
|
||||
ServiceContext.ContentService.Save(c2);
|
||||
ContentService.Save(c2);
|
||||
}
|
||||
}
|
||||
|
||||
var service = ServiceContext.EntityService;
|
||||
|
||||
long total;
|
||||
var entities = service.GetPagedDescendants(root.Id, UmbracoObjectTypes.Document, 0, 10, out total,
|
||||
var entities = EntityService.GetPagedDescendants(root.Id, UmbracoObjectTypes.Document, 0, 10, out total,
|
||||
filter: SqlContext.Query<IUmbracoEntity>().Where(x => x.Name.Contains("ssss"))).ToArray();
|
||||
Assert.That(entities.Length, Is.EqualTo(10));
|
||||
Assert.That(total, Is.EqualTo(10));
|
||||
entities = service.GetPagedDescendants(root.Id, UmbracoObjectTypes.Document, 0, 50, out total,
|
||||
entities = EntityService.GetPagedDescendants(root.Id, UmbracoObjectTypes.Document, 0, 50, out total,
|
||||
filter: SqlContext.Query<IUmbracoEntity>().Where(x => x.Name.Contains("tttt"))).ToArray();
|
||||
Assert.That(entities.Length, Is.EqualTo(50));
|
||||
Assert.That(total, Is.EqualTo(50));
|
||||
@@ -290,24 +287,22 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void EntityService_Can_Get_Paged_Media_Children()
|
||||
{
|
||||
var folderType = ServiceContext.MediaTypeService.Get(1031);
|
||||
var imageMediaType = ServiceContext.MediaTypeService.Get(1032);
|
||||
var folderType = MediaTypeService.Get(1031);
|
||||
var imageMediaType = MediaTypeService.Get(1032);
|
||||
|
||||
var root = MockedMedia.CreateMediaFolder(folderType, -1);
|
||||
ServiceContext.MediaService.Save(root);
|
||||
MediaService.Save(root);
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
var c1 = MockedMedia.CreateMediaImage(imageMediaType, root.Id);
|
||||
ServiceContext.MediaService.Save(c1);
|
||||
MediaService.Save(c1);
|
||||
}
|
||||
|
||||
var service = ServiceContext.EntityService;
|
||||
|
||||
long total;
|
||||
var entities = service.GetPagedChildren(root.Id, UmbracoObjectTypes.Media, 0, 6, out total).ToArray();
|
||||
var entities = EntityService.GetPagedChildren(root.Id, UmbracoObjectTypes.Media, 0, 6, out total).ToArray();
|
||||
Assert.That(entities.Length, Is.EqualTo(6));
|
||||
Assert.That(total, Is.EqualTo(10));
|
||||
entities = service.GetPagedChildren(root.Id, UmbracoObjectTypes.Media, 1, 6, out total).ToArray();
|
||||
entities = EntityService.GetPagedChildren(root.Id, UmbracoObjectTypes.Media, 1, 6, out total).ToArray();
|
||||
Assert.That(entities.Length, Is.EqualTo(4));
|
||||
Assert.That(total, Is.EqualTo(10));
|
||||
}
|
||||
@@ -315,33 +310,31 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void EntityService_Can_Get_Paged_Media_Descendants()
|
||||
{
|
||||
var folderType = ServiceContext.MediaTypeService.Get(1031);
|
||||
var imageMediaType = ServiceContext.MediaTypeService.Get(1032);
|
||||
var folderType = MediaTypeService.Get(1031);
|
||||
var imageMediaType = MediaTypeService.Get(1032);
|
||||
|
||||
var root = MockedMedia.CreateMediaFolder(folderType, -1);
|
||||
ServiceContext.MediaService.Save(root);
|
||||
MediaService.Save(root);
|
||||
var count = 0;
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
var c1 = MockedMedia.CreateMediaImage(imageMediaType, root.Id);
|
||||
ServiceContext.MediaService.Save(c1);
|
||||
MediaService.Save(c1);
|
||||
count++;
|
||||
|
||||
for (int j = 0; j < 5; j++)
|
||||
{
|
||||
var c2 = MockedMedia.CreateMediaImage(imageMediaType, c1.Id);
|
||||
ServiceContext.MediaService.Save(c2);
|
||||
MediaService.Save(c2);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
var service = ServiceContext.EntityService;
|
||||
|
||||
long total;
|
||||
var entities = service.GetPagedDescendants(root.Id, UmbracoObjectTypes.Media, 0, 31, out total).ToArray();
|
||||
var entities = EntityService.GetPagedDescendants(root.Id, UmbracoObjectTypes.Media, 0, 31, out total).ToArray();
|
||||
Assert.That(entities.Length, Is.EqualTo(31));
|
||||
Assert.That(total, Is.EqualTo(60));
|
||||
entities = service.GetPagedDescendants(root.Id, UmbracoObjectTypes.Media, 1, 31, out total).ToArray();
|
||||
entities = EntityService.GetPagedDescendants(root.Id, UmbracoObjectTypes.Media, 1, 31, out total).ToArray();
|
||||
Assert.That(entities.Length, Is.EqualTo(29));
|
||||
Assert.That(total, Is.EqualTo(60));
|
||||
}
|
||||
@@ -349,16 +342,16 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void EntityService_Can_Get_Paged_Media_Descendants_Including_Recycled()
|
||||
{
|
||||
var folderType = ServiceContext.MediaTypeService.Get(1031);
|
||||
var imageMediaType = ServiceContext.MediaTypeService.Get(1032);
|
||||
var folderType = MediaTypeService.Get(1031);
|
||||
var imageMediaType = MediaTypeService.Get(1032);
|
||||
|
||||
var root = MockedMedia.CreateMediaFolder(folderType, -1);
|
||||
ServiceContext.MediaService.Save(root);
|
||||
MediaService.Save(root);
|
||||
var toDelete = new List<IMedia>();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
var c1 = MockedMedia.CreateMediaImage(imageMediaType, root.Id);
|
||||
ServiceContext.MediaService.Save(c1);
|
||||
MediaService.Save(c1);
|
||||
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
@@ -368,20 +361,18 @@ namespace Umbraco.Tests.Services
|
||||
for (int j = 0; j < 5; j++)
|
||||
{
|
||||
var c2 = MockedMedia.CreateMediaImage(imageMediaType, c1.Id);
|
||||
ServiceContext.MediaService.Save(c2);
|
||||
MediaService.Save(c2);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var content in toDelete)
|
||||
{
|
||||
ServiceContext.MediaService.MoveToRecycleBin(content);
|
||||
MediaService.MoveToRecycleBin(content);
|
||||
}
|
||||
|
||||
var service = ServiceContext.EntityService;
|
||||
|
||||
long total;
|
||||
//search at root to see if it returns recycled
|
||||
var entities = service.GetPagedDescendants(-1, UmbracoObjectTypes.Media, 0, 1000, out total)
|
||||
var entities = EntityService.GetPagedDescendants(-1, UmbracoObjectTypes.Media, 0, 1000, out total)
|
||||
.Select(x => x.Id)
|
||||
.ToArray();
|
||||
|
||||
@@ -394,16 +385,16 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void EntityService_Can_Get_Paged_Media_Descendants_Without_Recycled()
|
||||
{
|
||||
var folderType = ServiceContext.MediaTypeService.Get(1031);
|
||||
var imageMediaType = ServiceContext.MediaTypeService.Get(1032);
|
||||
var folderType = MediaTypeService.Get(1031);
|
||||
var imageMediaType = MediaTypeService.Get(1032);
|
||||
|
||||
var root = MockedMedia.CreateMediaFolder(folderType, -1);
|
||||
ServiceContext.MediaService.Save(root);
|
||||
MediaService.Save(root);
|
||||
var toDelete = new List<IMedia>();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
var c1 = MockedMedia.CreateMediaImage(imageMediaType, root.Id);
|
||||
ServiceContext.MediaService.Save(c1);
|
||||
MediaService.Save(c1);
|
||||
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
@@ -413,20 +404,18 @@ namespace Umbraco.Tests.Services
|
||||
for (int j = 0; j < 5; j++)
|
||||
{
|
||||
var c2 = MockedMedia.CreateMediaImage(imageMediaType, c1.Id);
|
||||
ServiceContext.MediaService.Save(c2);
|
||||
MediaService.Save(c2);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var content in toDelete)
|
||||
{
|
||||
ServiceContext.MediaService.MoveToRecycleBin(content);
|
||||
MediaService.MoveToRecycleBin(content);
|
||||
}
|
||||
|
||||
var service = ServiceContext.EntityService;
|
||||
|
||||
long total;
|
||||
//search at root to see if it returns recycled
|
||||
var entities = service.GetPagedDescendants(UmbracoObjectTypes.Media, 0, 1000, out total, includeTrashed: false)
|
||||
var entities = EntityService.GetPagedDescendants(UmbracoObjectTypes.Media, 0, 1000, out total, includeTrashed: false)
|
||||
.Select(x => x.Id)
|
||||
.ToArray();
|
||||
|
||||
@@ -439,34 +428,32 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void EntityService_Can_Get_Paged_Media_Descendants_With_Search()
|
||||
{
|
||||
var folderType = ServiceContext.MediaTypeService.Get(1031);
|
||||
var imageMediaType = ServiceContext.MediaTypeService.Get(1032);
|
||||
var folderType = MediaTypeService.Get(1031);
|
||||
var imageMediaType = MediaTypeService.Get(1032);
|
||||
|
||||
var root = MockedMedia.CreateMediaFolder(folderType, -1);
|
||||
ServiceContext.MediaService.Save(root);
|
||||
MediaService.Save(root);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
var c1 = MockedMedia.CreateMediaImage(imageMediaType, root.Id);
|
||||
c1.Name = "ssss" + Guid.NewGuid();
|
||||
ServiceContext.MediaService.Save(c1);
|
||||
MediaService.Save(c1);
|
||||
|
||||
for (int j = 0; j < 5; j++)
|
||||
{
|
||||
var c2 = MockedMedia.CreateMediaImage(imageMediaType, c1.Id);
|
||||
c2.Name = "tttt" + Guid.NewGuid();
|
||||
ServiceContext.MediaService.Save(c2);
|
||||
MediaService.Save(c2);
|
||||
}
|
||||
}
|
||||
|
||||
var service = ServiceContext.EntityService;
|
||||
|
||||
long total;
|
||||
var entities = service.GetPagedDescendants(root.Id, UmbracoObjectTypes.Media, 0, 10, out total,
|
||||
var entities = EntityService.GetPagedDescendants(root.Id, UmbracoObjectTypes.Media, 0, 10, out total,
|
||||
filter: SqlContext.Query<IUmbracoEntity>().Where(x => x.Name.Contains("ssss"))).ToArray();
|
||||
Assert.That(entities.Length, Is.EqualTo(10));
|
||||
Assert.That(total, Is.EqualTo(10));
|
||||
entities = service.GetPagedDescendants(root.Id, UmbracoObjectTypes.Media, 0, 50, out total,
|
||||
entities = EntityService.GetPagedDescendants(root.Id, UmbracoObjectTypes.Media, 0, 50, out total,
|
||||
filter: SqlContext.Query<IUmbracoEntity>().Where(x => x.Name.Contains("tttt"))).ToArray();
|
||||
Assert.That(entities.Length, Is.EqualTo(50));
|
||||
Assert.That(total, Is.EqualTo(50));
|
||||
@@ -475,9 +462,7 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void EntityService_Can_Find_All_Content_By_UmbracoObjectTypes()
|
||||
{
|
||||
var service = ServiceContext.EntityService;
|
||||
|
||||
var entities = service.GetAll(UmbracoObjectTypes.Document).ToArray();
|
||||
var entities = EntityService.GetAll(UmbracoObjectTypes.Document).ToArray();
|
||||
|
||||
Assert.That(entities.Any(), Is.True);
|
||||
Assert.That(entities.Length, Is.EqualTo(4));
|
||||
@@ -487,10 +472,8 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void EntityService_Can_Find_All_Content_By_UmbracoObjectType_Id()
|
||||
{
|
||||
var service = ServiceContext.EntityService;
|
||||
|
||||
var objectTypeId = Constants.ObjectTypes.Document;
|
||||
var entities = service.GetAll(objectTypeId).ToArray();
|
||||
var entities = EntityService.GetAll(objectTypeId).ToArray();
|
||||
|
||||
Assert.That(entities.Any(), Is.True);
|
||||
Assert.That(entities.Length, Is.EqualTo(4));
|
||||
@@ -500,9 +483,7 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void EntityService_Can_Find_All_Content_By_Type()
|
||||
{
|
||||
var service = ServiceContext.EntityService;
|
||||
|
||||
var entities = service.GetAll<IContent>().ToArray();
|
||||
var entities = EntityService.GetAll<IContent>().ToArray();
|
||||
|
||||
Assert.That(entities.Any(), Is.True);
|
||||
Assert.That(entities.Length, Is.EqualTo(4));
|
||||
@@ -512,9 +493,7 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void EntityService_Can_Get_Child_Content_By_ParentId_And_UmbracoObjectType()
|
||||
{
|
||||
var service = ServiceContext.EntityService;
|
||||
|
||||
var entities = service.GetChildren(-1, UmbracoObjectTypes.Document).ToArray();
|
||||
var entities = EntityService.GetChildren(-1, UmbracoObjectTypes.Document).ToArray();
|
||||
|
||||
Assert.That(entities.Any(), Is.True);
|
||||
Assert.That(entities.Length, Is.EqualTo(1));
|
||||
@@ -524,19 +503,17 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void EntityService_Can_Get_Content_By_UmbracoObjectType_With_Variant_Names()
|
||||
{
|
||||
var service = ServiceContext.EntityService;
|
||||
|
||||
var alias = "test" + Guid.NewGuid();
|
||||
var contentType = MockedContentTypes.CreateSimpleContentType(alias, alias, false);
|
||||
contentType.Variations = ContentVariation.Culture;
|
||||
ServiceContext.ContentTypeService.Save(contentType);
|
||||
ContentTypeService.Save(contentType);
|
||||
|
||||
var c1 = MockedContent.CreateSimpleContent(contentType, "Test", -1);
|
||||
c1.SetCultureName("Test - FR", _langFr.IsoCode);
|
||||
c1.SetCultureName("Test - ES", _langEs.IsoCode);
|
||||
ServiceContext.ContentService.Save(c1);
|
||||
ContentService.Save(c1);
|
||||
|
||||
var result = service.Get(c1.Id, UmbracoObjectTypes.Document);
|
||||
var result = EntityService.Get(c1.Id, UmbracoObjectTypes.Document);
|
||||
Assert.AreEqual("Test - FR", result.Name); // got name from default culture
|
||||
Assert.IsNotNull(result as IDocumentEntitySlim);
|
||||
var doc = (IDocumentEntitySlim)result;
|
||||
@@ -548,15 +525,13 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void EntityService_Can_Get_Child_Content_By_ParentId_And_UmbracoObjectType_With_Variant_Names()
|
||||
{
|
||||
var service = ServiceContext.EntityService;
|
||||
|
||||
var contentType = MockedContentTypes.CreateSimpleContentType("test1", "Test1", false);
|
||||
contentType.Variations = ContentVariation.Culture;
|
||||
ServiceContext.ContentTypeService.Save(contentType);
|
||||
ContentTypeService.Save(contentType);
|
||||
|
||||
var root = MockedContent.CreateSimpleContent(contentType);
|
||||
root.SetCultureName("Root", _langFr.IsoCode); // else cannot save
|
||||
ServiceContext.ContentService.Save(root);
|
||||
ContentService.Save(root);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
@@ -570,10 +545,10 @@ namespace Umbraco.Tests.Services
|
||||
{
|
||||
c1.SetCultureName("Test", _langFr.IsoCode); // else cannot save
|
||||
}
|
||||
ServiceContext.ContentService.Save(c1);
|
||||
ContentService.Save(c1);
|
||||
}
|
||||
|
||||
var entities = service.GetChildren(root.Id, UmbracoObjectTypes.Document).ToArray();
|
||||
var entities = EntityService.GetChildren(root.Id, UmbracoObjectTypes.Document).ToArray();
|
||||
|
||||
Assert.AreEqual(10, entities.Length);
|
||||
|
||||
@@ -601,9 +576,7 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void EntityService_Can_Get_Children_By_ParentId()
|
||||
{
|
||||
var service = ServiceContext.EntityService;
|
||||
|
||||
var entities = service.GetChildren(folderId);
|
||||
var entities = EntityService.GetChildren(folderId);
|
||||
|
||||
Assert.That(entities.Any(), Is.True);
|
||||
Assert.That(entities.Count(), Is.EqualTo(3));
|
||||
@@ -613,9 +586,7 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void EntityService_Can_Get_Descendants_By_ParentId()
|
||||
{
|
||||
var service = ServiceContext.EntityService;
|
||||
|
||||
var entities = service.GetDescendants(folderId);
|
||||
var entities = EntityService.GetDescendants(folderId);
|
||||
|
||||
Assert.That(entities.Any(), Is.True);
|
||||
Assert.That(entities.Count(), Is.EqualTo(4));
|
||||
@@ -625,19 +596,16 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void EntityService_Throws_When_Getting_All_With_Invalid_Type()
|
||||
{
|
||||
var service = ServiceContext.EntityService;
|
||||
var objectTypeId = Constants.ObjectTypes.ContentItem;
|
||||
|
||||
Assert.Throws<NotSupportedException>(() => service.GetAll<IContentBase>());
|
||||
Assert.Throws<NotSupportedException>(() => service.GetAll(objectTypeId));
|
||||
Assert.Throws<NotSupportedException>(() => EntityService.GetAll<IContentBase>());
|
||||
Assert.Throws<NotSupportedException>(() => EntityService.GetAll(objectTypeId));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EntityService_Can_Find_All_ContentTypes_By_UmbracoObjectTypes()
|
||||
{
|
||||
var service = ServiceContext.EntityService;
|
||||
|
||||
var entities = service.GetAll(UmbracoObjectTypes.DocumentType).ToArray();
|
||||
var entities = EntityService.GetAll(UmbracoObjectTypes.DocumentType).ToArray();
|
||||
|
||||
Assert.That(entities.Any(), Is.True);
|
||||
Assert.That(entities.Count(), Is.EqualTo(1));
|
||||
@@ -646,10 +614,8 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void EntityService_Can_Find_All_ContentTypes_By_UmbracoObjectType_Id()
|
||||
{
|
||||
var service = ServiceContext.EntityService;
|
||||
|
||||
var objectTypeId = Constants.ObjectTypes.DocumentType;
|
||||
var entities = service.GetAll(objectTypeId).ToArray();
|
||||
var entities = EntityService.GetAll(objectTypeId).ToArray();
|
||||
|
||||
Assert.That(entities.Any(), Is.True);
|
||||
Assert.That(entities.Count(), Is.EqualTo(1));
|
||||
@@ -658,9 +624,7 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void EntityService_Can_Find_All_ContentTypes_By_Type()
|
||||
{
|
||||
var service = ServiceContext.EntityService;
|
||||
|
||||
var entities = service.GetAll<IContentType>().ToArray();
|
||||
var entities = EntityService.GetAll<IContentType>().ToArray();
|
||||
|
||||
Assert.That(entities.Any(), Is.True);
|
||||
Assert.That(entities.Count(), Is.EqualTo(1));
|
||||
@@ -669,9 +633,7 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void EntityService_Can_Find_All_Media_By_UmbracoObjectTypes()
|
||||
{
|
||||
var service = ServiceContext.EntityService;
|
||||
|
||||
var entities = service.GetAll(UmbracoObjectTypes.Media).ToArray();
|
||||
var entities = EntityService.GetAll(UmbracoObjectTypes.Media).ToArray();
|
||||
|
||||
Assert.That(entities.Any(), Is.True);
|
||||
Assert.That(entities.Length, Is.EqualTo(5));
|
||||
@@ -686,9 +648,8 @@ namespace Umbraco.Tests.Services
|
||||
|
||||
[Test]
|
||||
public void EntityService_Can_Get_ObjectType()
|
||||
{
|
||||
var service = ServiceContext.EntityService;
|
||||
var mediaObjectType = service.GetObjectType(1031);
|
||||
{ ;
|
||||
var mediaObjectType = EntityService.GetObjectType(1031);
|
||||
|
||||
Assert.NotNull(mediaObjectType);
|
||||
Assert.AreEqual(mediaObjectType, UmbracoObjectTypes.MediaType);
|
||||
@@ -697,8 +658,7 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void EntityService_Can_Get_Key_For_Id_With_Unknown_Type()
|
||||
{
|
||||
var service = ServiceContext.EntityService;
|
||||
var result = service.GetKey(1061, UmbracoObjectTypes.Unknown);
|
||||
var result = EntityService.GetKey(1052, UmbracoObjectTypes.Unknown);
|
||||
|
||||
Assert.IsTrue(result.Success);
|
||||
Assert.AreEqual(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), result.Result);
|
||||
@@ -707,8 +667,7 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void EntityService_Can_Get_Key_For_Id()
|
||||
{
|
||||
var service = ServiceContext.EntityService;
|
||||
var result = service.GetKey(1061, UmbracoObjectTypes.DocumentType);
|
||||
var result = EntityService.GetKey(1052, UmbracoObjectTypes.DocumentType);
|
||||
|
||||
Assert.IsTrue(result.Success);
|
||||
Assert.AreEqual(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), result.Result);
|
||||
@@ -717,9 +676,8 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void EntityService_Cannot_Get_Key_For_Id_With_Incorrect_Object_Type()
|
||||
{
|
||||
var service = ServiceContext.EntityService;
|
||||
var result1 = service.GetKey(1061, UmbracoObjectTypes.DocumentType);
|
||||
var result2 = service.GetKey(1061, UmbracoObjectTypes.MediaType);
|
||||
var result1 = EntityService.GetKey(1052, UmbracoObjectTypes.DocumentType);
|
||||
var result2 = EntityService.GetKey(1052, UmbracoObjectTypes.MediaType);
|
||||
|
||||
Assert.IsTrue(result1.Success);
|
||||
Assert.IsFalse(result2.Success);
|
||||
@@ -728,29 +686,26 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void EntityService_Can_Get_Id_For_Key_With_Unknown_Type()
|
||||
{
|
||||
var service = ServiceContext.EntityService;
|
||||
var result = service.GetId(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), UmbracoObjectTypes.Unknown);
|
||||
var result = EntityService.GetId(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), UmbracoObjectTypes.Unknown);
|
||||
|
||||
Assert.IsTrue(result.Success);
|
||||
Assert.AreEqual(1061, result.Result);
|
||||
Assert.AreEqual(1052, result.Result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EntityService_Can_Get_Id_For_Key()
|
||||
{
|
||||
var service = ServiceContext.EntityService;
|
||||
var result = service.GetId(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), UmbracoObjectTypes.DocumentType);
|
||||
var result = EntityService.GetId(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), UmbracoObjectTypes.DocumentType);
|
||||
|
||||
Assert.IsTrue(result.Success);
|
||||
Assert.AreEqual(1061, result.Result);
|
||||
Assert.AreEqual(1052, result.Result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EntityService_Cannot_Get_Id_For_Key_With_Incorrect_Object_Type()
|
||||
{
|
||||
var service = ServiceContext.EntityService;
|
||||
var result1 = service.GetId(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), UmbracoObjectTypes.DocumentType);
|
||||
var result2 = service.GetId(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), UmbracoObjectTypes.MediaType);
|
||||
var result1 = EntityService.GetId(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), UmbracoObjectTypes.DocumentType);
|
||||
var result2 = EntityService.GetId(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), UmbracoObjectTypes.MediaType);
|
||||
|
||||
Assert.IsTrue(result1.Success);
|
||||
Assert.IsFalse(result2.Success);
|
||||
@@ -759,59 +714,83 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void ReserveId()
|
||||
{
|
||||
var service = ServiceContext.EntityService;
|
||||
var guid = Guid.NewGuid();
|
||||
|
||||
// can reserve
|
||||
var reservedId = service.ReserveId(guid);
|
||||
var reservedId = EntityService.ReserveId(guid);
|
||||
Assert.IsTrue(reservedId > 0);
|
||||
|
||||
// can get it back
|
||||
var id = service.GetId(guid, UmbracoObjectTypes.DocumentType);
|
||||
var id = EntityService.GetId(guid, UmbracoObjectTypes.DocumentType);
|
||||
Assert.IsTrue(id.Success);
|
||||
Assert.AreEqual(reservedId, id.Result);
|
||||
|
||||
// anything goes
|
||||
id = service.GetId(guid, UmbracoObjectTypes.Media);
|
||||
id = EntityService.GetId(guid, UmbracoObjectTypes.Media);
|
||||
Assert.IsTrue(id.Success);
|
||||
Assert.AreEqual(reservedId, id.Result);
|
||||
|
||||
// a random guid won't work
|
||||
Assert.IsFalse(service.GetId(Guid.NewGuid(), UmbracoObjectTypes.DocumentType).Success);
|
||||
Assert.IsFalse(EntityService.GetId(Guid.NewGuid(), UmbracoObjectTypes.DocumentType).Success);
|
||||
}
|
||||
|
||||
private static bool _isSetup = false;
|
||||
|
||||
private int folderId;
|
||||
|
||||
public override void CreateTestData()
|
||||
public void CreateTestData()
|
||||
{
|
||||
if (_isSetup == false)
|
||||
{
|
||||
_isSetup = true;
|
||||
|
||||
base.CreateTestData();
|
||||
//Create and Save ContentType "umbTextpage" -> 1052
|
||||
ContentType contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage", "Textpage");
|
||||
contentType.Key = new Guid("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522");
|
||||
FileService.SaveTemplate(contentType.DefaultTemplate); // else, FK violation on contentType!
|
||||
ContentTypeService.Save(contentType);
|
||||
|
||||
//Create and Save folder-Media -> 1050
|
||||
var folderMediaType = ServiceContext.MediaTypeService.Get(1031);
|
||||
//Create and Save Content "Homepage" based on "umbTextpage" -> 1053
|
||||
Content textpage = MockedContent.CreateSimpleContent(contentType);
|
||||
textpage.Key = new Guid("B58B3AD4-62C2-4E27-B1BE-837BD7C533E0");
|
||||
ContentService.Save(textpage, 0);
|
||||
|
||||
//Create and Save Content "Text Page 1" based on "umbTextpage" -> 1054
|
||||
Content subpage = MockedContent.CreateSimpleContent(contentType, "Text Page 1", textpage.Id);
|
||||
subpage.ContentSchedule.Add(DateTime.Now.AddMinutes(-5), null);
|
||||
ContentService.Save(subpage, 0);
|
||||
|
||||
//Create and Save Content "Text Page 2" based on "umbTextpage" -> 1055
|
||||
Content subpage2 = MockedContent.CreateSimpleContent(contentType, "Text Page 2", textpage.Id);
|
||||
ContentService.Save(subpage2, 0);
|
||||
|
||||
//Create and Save Content "Text Page Deleted" based on "umbTextpage" -> 1056
|
||||
Content trashed = MockedContent.CreateSimpleContent(contentType, "Text Page Deleted", -20);
|
||||
trashed.Trashed = true;
|
||||
ContentService.Save(trashed, 0);
|
||||
|
||||
//Create and Save folder-Media -> 1057
|
||||
var folderMediaType = MediaTypeService.Get(1031);
|
||||
var folder = MockedMedia.CreateMediaFolder(folderMediaType, -1);
|
||||
ServiceContext.MediaService.Save(folder, 0);
|
||||
MediaService.Save(folder, 0);
|
||||
folderId = folder.Id;
|
||||
|
||||
//Create and Save image-Media -> 1051
|
||||
var imageMediaType = ServiceContext.MediaTypeService.Get(1032);
|
||||
//Create and Save image-Media -> 1058
|
||||
var imageMediaType = MediaTypeService.Get(1032);
|
||||
var image = MockedMedia.CreateMediaImage(imageMediaType, folder.Id);
|
||||
ServiceContext.MediaService.Save(image, 0);
|
||||
MediaService.Save(image, 0);
|
||||
|
||||
//Create and Save file-Media -> 1052
|
||||
var fileMediaType = ServiceContext.MediaTypeService.Get(1033);
|
||||
//Create and Save file-Media -> 1059
|
||||
var fileMediaType = MediaTypeService.Get(1033);
|
||||
var file = MockedMedia.CreateMediaFile(fileMediaType, folder.Id);
|
||||
ServiceContext.MediaService.Save(file, 0);
|
||||
MediaService.Save(file, 0);
|
||||
|
||||
// Create and save sub folder -> 1060
|
||||
var subfolder = MockedMedia.CreateMediaFolder(folderMediaType, folder.Id);
|
||||
ServiceContext.MediaService.Save(subfolder, 0);
|
||||
MediaService.Save(subfolder, 0);
|
||||
// Create and save sub folder -> 1061
|
||||
var subfolder2 = MockedMedia.CreateMediaFolder(folderMediaType, subfolder.Id);
|
||||
ServiceContext.MediaService.Save(subfolder2, 0);
|
||||
MediaService.Save(subfolder2, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
75
src/Umbraco.Tests.Integration/Services/FileServiceTests.cs
Normal file
75
src/Umbraco.Tests.Integration/Services/FileServiceTests.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.Integration.Testing;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
{
|
||||
[TestFixture]
|
||||
[Apartment(ApartmentState.STA)]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
||||
public class FileServiceTests : UmbracoIntegrationTest
|
||||
{
|
||||
private IFileService FileService => GetRequiredService<IFileService>();
|
||||
|
||||
[Test]
|
||||
public void Create_Template_Then_Assign_Child()
|
||||
{
|
||||
var child = FileService.CreateTemplateWithIdentity("Child", "child", "test");
|
||||
var parent = FileService.CreateTemplateWithIdentity("Parent", "parent", "test");
|
||||
|
||||
child.SetMasterTemplate(parent);
|
||||
FileService.SaveTemplate(child);
|
||||
|
||||
child = FileService.GetTemplate(child.Id);
|
||||
|
||||
Assert.AreEqual(parent.Alias, child.MasterTemplateAlias);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Create_Template_With_Child_Then_Unassign()
|
||||
{
|
||||
var parent = FileService.CreateTemplateWithIdentity("Parent", "parent", "test");
|
||||
var child = FileService.CreateTemplateWithIdentity("Child", "child", "test", parent);
|
||||
|
||||
child.SetMasterTemplate(null);
|
||||
FileService.SaveTemplate(child);
|
||||
|
||||
child = FileService.GetTemplate(child.Id);
|
||||
|
||||
Assert.AreEqual(null, child.MasterTemplateAlias);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Query_Template_Children()
|
||||
{
|
||||
var parent = FileService.CreateTemplateWithIdentity("Parent", "parent", "test");
|
||||
var child1 = FileService.CreateTemplateWithIdentity("Child1", "child1", "test", parent);
|
||||
var child2 = FileService.CreateTemplateWithIdentity("Child2", "child2", "test", parent);
|
||||
|
||||
var children = FileService.GetTemplates(parent.Id).Select(x => x.Id).ToArray();
|
||||
|
||||
Assert.IsTrue(children.Contains(child1.Id));
|
||||
Assert.IsTrue(children.Contains(child2.Id));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Create_Template_With_Custom_Alias()
|
||||
{
|
||||
var template = FileService.CreateTemplateWithIdentity("Test template", "customTemplateAlias", "test");
|
||||
|
||||
FileService.SaveTemplate(template);
|
||||
|
||||
template = FileService.GetTemplate(template.Id);
|
||||
|
||||
Assert.AreEqual("Test template", template.Name);
|
||||
Assert.AreEqual("customTemplateAlias", template.Alias);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Threading;
|
||||
using NUnit.Framework;
|
||||
using NUnit.Framework.Internal;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.Integration.Testing;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
@@ -14,16 +14,15 @@ namespace Umbraco.Tests.Services
|
||||
[TestFixture]
|
||||
[Apartment(ApartmentState.STA)]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
||||
public class KeyValueServiceTests : TestWithSomeContentBase
|
||||
public class KeyValueServiceTests : UmbracoIntegrationTest
|
||||
{
|
||||
private IKeyValueService KeyValueService => GetRequiredService<IKeyValueService>();
|
||||
|
||||
[Test]
|
||||
public void GetValue_ForMissingKey_ReturnsNull()
|
||||
{
|
||||
// Arrange
|
||||
var keyValueService = ServiceContext.KeyValueService;
|
||||
|
||||
// Act
|
||||
var value = keyValueService.GetValue("foo");
|
||||
var value = KeyValueService.GetValue("foo");
|
||||
|
||||
// Assert
|
||||
Assert.IsNull(value);
|
||||
@@ -32,12 +31,10 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void GetValue_ForExistingKey_ReturnsValue()
|
||||
{
|
||||
// Arrange
|
||||
var keyValueService = ServiceContext.KeyValueService;
|
||||
keyValueService.SetValue("foo", "bar");
|
||||
KeyValueService.SetValue("foo", "bar");
|
||||
|
||||
// Act
|
||||
var value = keyValueService.GetValue("foo");
|
||||
var value = KeyValueService.GetValue("foo");
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual("bar", value);
|
||||
@@ -46,13 +43,11 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void SetValue_ForExistingKey_SavesValue()
|
||||
{
|
||||
// Arrange
|
||||
var keyValueService = ServiceContext.KeyValueService;
|
||||
keyValueService.SetValue("foo", "bar");
|
||||
KeyValueService.SetValue("foo", "bar");
|
||||
|
||||
// Act
|
||||
keyValueService.SetValue("foo", "buzz");
|
||||
var value = keyValueService.GetValue("foo");
|
||||
KeyValueService.SetValue("foo", "buzz");
|
||||
var value = KeyValueService.GetValue("foo");
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual("buzz", value);
|
||||
@@ -61,13 +56,11 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void TrySetValue_ForExistingKeyWithProvidedValue_ReturnsTrueAndSetsValue()
|
||||
{
|
||||
// Arrange
|
||||
var keyValueService = ServiceContext.KeyValueService;
|
||||
keyValueService.SetValue("foo", "bar");
|
||||
KeyValueService.SetValue("foo", "bar");
|
||||
|
||||
// Act
|
||||
var result = keyValueService.TrySetValue("foo", "bar", "buzz");
|
||||
var value = keyValueService.GetValue("foo");
|
||||
var result = KeyValueService.TrySetValue("foo", "bar", "buzz");
|
||||
var value = KeyValueService.GetValue("foo");
|
||||
|
||||
// Assert
|
||||
Assert.IsTrue(result);
|
||||
@@ -77,13 +70,11 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void TrySetValue_ForExistingKeyWithoutProvidedValue_ReturnsFalseAndDoesNotSetValue()
|
||||
{
|
||||
// Arrange
|
||||
var keyValueService = ServiceContext.KeyValueService;
|
||||
keyValueService.SetValue("foo", "bar");
|
||||
KeyValueService.SetValue("foo", "bar");
|
||||
|
||||
// Act
|
||||
var result = keyValueService.TrySetValue("foo", "bang", "buzz");
|
||||
var value = keyValueService.GetValue("foo");
|
||||
var result = KeyValueService.TrySetValue("foo", "bang", "buzz");
|
||||
var value = KeyValueService.GetValue("foo");
|
||||
|
||||
// Assert
|
||||
Assert.IsFalse(result);
|
||||
@@ -6,27 +6,28 @@ using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
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.Common.Builders.Extensions;
|
||||
using Umbraco.Tests.Integration.Testing;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
namespace Umbraco.Tests.Integration.Services
|
||||
{
|
||||
[TestFixture]
|
||||
[Apartment(ApartmentState.STA)]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
||||
public class MacroServiceTests : TestWithSomeContentBase
|
||||
public class MacroServiceTests : UmbracoIntegrationTest
|
||||
{
|
||||
public override void CreateTestData()
|
||||
private IMacroService MacroService => GetRequiredService<IMacroService>();
|
||||
[SetUp]
|
||||
public void SetupTest()
|
||||
{
|
||||
base.CreateTestData();
|
||||
|
||||
var provider = TestObjects.GetScopeProvider(LoggerFactory);
|
||||
using (var scope = provider.CreateScope())
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
var repository = new MacroRepository((IScopeAccessor) provider, AppCaches.Disabled, Mock.Of<ILogger<MacroRepository>>(), ShortStringHelper);
|
||||
var repository = new MacroRepository((IScopeAccessor) sp, AppCaches.Disabled, Mock.Of<ILogger<MacroRepository>>(), ShortStringHelper);
|
||||
|
||||
repository.Save(new Macro(ShortStringHelper, "test1", "Test1", "~/views/macropartials/test1.cshtml"));
|
||||
repository.Save(new Macro(ShortStringHelper, "test2", "Test2", "~/views/macropartials/test2.cshtml"));
|
||||
@@ -35,22 +36,13 @@ namespace Umbraco.Tests.Services
|
||||
}
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public override void TearDown()
|
||||
{
|
||||
base.TearDown();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Get_By_Alias()
|
||||
{
|
||||
// Arrange
|
||||
var macroService = ServiceContext.MacroService;
|
||||
|
||||
// Act
|
||||
var macro = macroService.GetByAlias("test1");
|
||||
var macro = MacroService.GetByAlias("test1");
|
||||
|
||||
//assert
|
||||
// Assert
|
||||
Assert.IsNotNull(macro);
|
||||
Assert.AreEqual("Test1", macro.Name);
|
||||
}
|
||||
@@ -58,37 +50,31 @@ namespace Umbraco.Tests.Services
|
||||
[Test]
|
||||
public void Can_Get_All()
|
||||
{
|
||||
// Arrange
|
||||
var macroService = ServiceContext.MacroService;
|
||||
|
||||
// Act
|
||||
var result = macroService.GetAll();
|
||||
var result = MacroService.GetAll();
|
||||
|
||||
//assert
|
||||
// Assert
|
||||
Assert.AreEqual(3, result.Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Create()
|
||||
{
|
||||
// Arrange
|
||||
var macroService = ServiceContext.MacroService;
|
||||
|
||||
// Act
|
||||
var macro = new Macro(ShortStringHelper, "test", "Test", "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234);
|
||||
macroService.Save(macro);
|
||||
var macro = CreateMacro();
|
||||
MacroService.Save(macro);
|
||||
|
||||
//assert
|
||||
// Assert
|
||||
Assert.IsTrue(macro.HasIdentity);
|
||||
Assert.Greater(macro.Id, 0);
|
||||
Assert.AreNotEqual(Guid.Empty, macro.Key);
|
||||
var result = macroService.GetById(macro.Id);
|
||||
var result = MacroService.GetById(macro.Id);
|
||||
Assert.AreEqual("test", result.Alias);
|
||||
Assert.AreEqual("Test", result.Name);
|
||||
Assert.AreEqual("~/Views/MacroPartials/Test.cshtml", result.MacroSource);
|
||||
Assert.AreEqual(1234, result.CacheDuration);
|
||||
|
||||
result = macroService.GetById(macro.Key);
|
||||
result = MacroService.GetById(macro.Key);
|
||||
Assert.AreEqual("test", result.Alias);
|
||||
Assert.AreEqual("Test", result.Name);
|
||||
Assert.AreEqual("~/Views/MacroPartials/Test.cshtml", result.MacroSource);
|
||||
@@ -99,18 +85,17 @@ namespace Umbraco.Tests.Services
|
||||
public void Can_Delete()
|
||||
{
|
||||
// Arrange
|
||||
var macroService = ServiceContext.MacroService;
|
||||
var macro = new Macro(ShortStringHelper, "test", "Test", "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234);
|
||||
macroService.Save(macro);
|
||||
MacroService.Save(macro);
|
||||
|
||||
// Act
|
||||
macroService.Delete(macro);
|
||||
MacroService.Delete(macro);
|
||||
|
||||
//assert
|
||||
var result = macroService.GetById(macro.Id);
|
||||
// Assert
|
||||
var result = MacroService.GetById(macro.Id);
|
||||
Assert.IsNull(result);
|
||||
|
||||
result = macroService.GetById(macro.Key);
|
||||
result = MacroService.GetById(macro.Key);
|
||||
Assert.IsNull(result);
|
||||
}
|
||||
|
||||
@@ -118,20 +103,18 @@ namespace Umbraco.Tests.Services
|
||||
public void Can_Update()
|
||||
{
|
||||
// Arrange
|
||||
var macroService = ServiceContext.MacroService;
|
||||
IMacro macro = new Macro(ShortStringHelper, "test", "Test", "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234);
|
||||
macroService.Save(macro);
|
||||
var macro = CreateMacro();
|
||||
MacroService.Save(macro);
|
||||
|
||||
// Act
|
||||
var currKey = macro.Key;
|
||||
macro.Name = "New name";
|
||||
macro.Alias = "NewAlias";
|
||||
macroService.Save(macro);
|
||||
MacroService.Save(macro);
|
||||
|
||||
macro = MacroService.GetById(macro.Id);
|
||||
|
||||
macro = macroService.GetById(macro.Id);
|
||||
|
||||
//assert
|
||||
// Assert
|
||||
Assert.AreEqual("New name", macro.Name);
|
||||
Assert.AreEqual("NewAlias", macro.Alias);
|
||||
Assert.AreEqual(currKey, macro.Key);
|
||||
@@ -142,10 +125,9 @@ namespace Umbraco.Tests.Services
|
||||
public void Can_Update_Property()
|
||||
{
|
||||
// Arrange
|
||||
var macroService = ServiceContext.MacroService;
|
||||
IMacro macro = new Macro(ShortStringHelper, "test", "Test", "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234);
|
||||
var macro = CreateMacro();
|
||||
macro.Properties.Add(new MacroProperty("blah", "Blah", 0, "blah"));
|
||||
macroService.Save(macro);
|
||||
MacroService.Save(macro);
|
||||
|
||||
Assert.AreNotEqual(Guid.Empty, macro.Properties[0].Key);
|
||||
|
||||
@@ -155,11 +137,11 @@ namespace Umbraco.Tests.Services
|
||||
macro.Properties[0].Name = "new Name";
|
||||
macro.Properties[0].SortOrder = 1;
|
||||
macro.Properties[0].EditorAlias = "new";
|
||||
macroService.Save(macro);
|
||||
MacroService.Save(macro);
|
||||
|
||||
macro = macroService.GetById(macro.Id);
|
||||
macro = MacroService.GetById(macro.Id);
|
||||
|
||||
//assert
|
||||
// Assert
|
||||
Assert.AreEqual(1, macro.Properties.Count);
|
||||
Assert.AreEqual(currPropKey, macro.Properties[0].Key);
|
||||
Assert.AreEqual("new Alias", macro.Properties[0].Alias);
|
||||
@@ -173,12 +155,11 @@ namespace Umbraco.Tests.Services
|
||||
public void Can_Update_Remove_Property()
|
||||
{
|
||||
// Arrange
|
||||
var macroService = ServiceContext.MacroService;
|
||||
IMacro macro = new Macro(ShortStringHelper, "test", "Test", "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234);
|
||||
var macro = CreateMacro();
|
||||
macro.Properties.Add(new MacroProperty("blah1", "Blah1", 0, "blah1"));
|
||||
macro.Properties.Add(new MacroProperty("blah2", "Blah2", 1, "blah2"));
|
||||
macro.Properties.Add(new MacroProperty("blah3", "Blah3", 2, "blah3"));
|
||||
macroService.Save(macro);
|
||||
MacroService.Save(macro);
|
||||
|
||||
var lastKey = macro.Properties[0].Key;
|
||||
for (var i = 1; i < macro.Properties.Count; i++)
|
||||
@@ -197,11 +178,11 @@ namespace Umbraco.Tests.Services
|
||||
|
||||
var allPropKeys = macro.Properties.Values.Select(x => new { x.Alias, x.Key }).ToArray();
|
||||
|
||||
macroService.Save(macro);
|
||||
MacroService.Save(macro);
|
||||
|
||||
macro = macroService.GetById(macro.Id);
|
||||
macro = MacroService.GetById(macro.Id);
|
||||
|
||||
//assert
|
||||
// Assert
|
||||
Assert.AreEqual(2, macro.Properties.Count);
|
||||
Assert.AreEqual("newAlias", macro.Properties["newAlias"].Alias);
|
||||
Assert.AreEqual("new Name", macro.Properties["newAlias"].Name);
|
||||
@@ -211,39 +192,36 @@ namespace Umbraco.Tests.Services
|
||||
{
|
||||
Assert.AreEqual(propKey.Key, macro.Properties[propKey.Alias].Key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Add_And_Remove_Properties()
|
||||
{
|
||||
var macroService = ServiceContext.MacroService;
|
||||
var macro = new Macro(ShortStringHelper, "test", "Test", "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234);
|
||||
var macro = CreateMacro();
|
||||
|
||||
//adds some properties
|
||||
// Adds some properties
|
||||
macro.Properties.Add(new MacroProperty("blah1", "Blah1", 0, "blah1"));
|
||||
macro.Properties.Add(new MacroProperty("blah2", "Blah2", 0, "blah2"));
|
||||
macro.Properties.Add(new MacroProperty("blah3", "Blah3", 0, "blah3"));
|
||||
macro.Properties.Add(new MacroProperty("blah4", "Blah4", 0, "blah4"));
|
||||
macroService.Save(macro);
|
||||
MacroService.Save(macro);
|
||||
|
||||
var result1 = macroService.GetById(macro.Id);
|
||||
var result1 = MacroService.GetById(macro.Id);
|
||||
Assert.AreEqual(4, result1.Properties.Values.Count());
|
||||
|
||||
//simulate clearing the sections
|
||||
// Simulate clearing the sections
|
||||
foreach (var s in result1.Properties.Values.ToArray())
|
||||
{
|
||||
result1.Properties.Remove(s.Alias);
|
||||
}
|
||||
//now just re-add a couple
|
||||
|
||||
// Now just re-add a couple
|
||||
result1.Properties.Add(new MacroProperty("blah3", "Blah3", 0, "blah3"));
|
||||
result1.Properties.Add(new MacroProperty("blah4", "Blah4", 0, "blah4"));
|
||||
macroService.Save(result1);
|
||||
MacroService.Save(result1);
|
||||
|
||||
//assert
|
||||
|
||||
//re-get
|
||||
result1 = macroService.GetById(result1.Id);
|
||||
// Assert
|
||||
result1 = MacroService.GetById(result1.Id);
|
||||
Assert.AreEqual(2, result1.Properties.Values.Count());
|
||||
|
||||
}
|
||||
@@ -252,25 +230,20 @@ namespace Umbraco.Tests.Services
|
||||
public void Cannot_Save_Macro_With_Empty_Name()
|
||||
{
|
||||
// Arrange
|
||||
var macroService = ServiceContext.MacroService;
|
||||
var macro = new Macro(ShortStringHelper, "test", string.Empty, "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234);
|
||||
var macro = CreateMacro(name: string.Empty);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<ArgumentException>(() => macroService.Save(macro));
|
||||
Assert.Throws<ArgumentException>(() => MacroService.Save(macro));
|
||||
}
|
||||
|
||||
//[Test]
|
||||
//public void Can_Get_Many_By_Alias()
|
||||
//{
|
||||
// // Arrange
|
||||
// var macroService = ServiceContext.MacroService;
|
||||
|
||||
// // Act
|
||||
// var result = macroService.GetAll("test1", "test2");
|
||||
|
||||
// //assert
|
||||
// Assert.AreEqual(2, result.Count());
|
||||
//}
|
||||
|
||||
private static IMacro CreateMacro(string name = "Test")
|
||||
{
|
||||
return new MacroBuilder()
|
||||
.WithAlias("test")
|
||||
.WithName(name)
|
||||
.WithSource("~/Views/MacroPartials/Test.cshtml")
|
||||
.WithCacheDuration(1234)
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,14 @@
|
||||
using NUnit.Framework;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Composing;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Configuration.Models;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Integration.Testing;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Web.Services;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
namespace Umbraco.Tests.Integration.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests covering the SectionService
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Umbraco.Tests.Integration.Services
|
||||
private IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
|
||||
private ITagService TagService => GetRequiredService<ITagService>();
|
||||
private IDataTypeService DataTypeService => GetRequiredService<IDataTypeService>();
|
||||
public PropertyEditorCollection PropertyEditorCollection => GetRequiredService<PropertyEditorCollection>();
|
||||
private PropertyEditorCollection PropertyEditorCollection => GetRequiredService<PropertyEditorCollection>();
|
||||
|
||||
[Test]
|
||||
public void TagApiConsistencyTest()
|
||||
|
||||
@@ -12,11 +12,12 @@ using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Services.Implement;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
using Umbraco.Tests.Integration.Testing;
|
||||
using Umbraco.Tests.TestHelpers.Entities;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Web.Actions;
|
||||
using MockedUser = Umbraco.Tests.Common.TestHelpers.Entities.MockedUser;
|
||||
|
||||
namespace Umbraco.Tests.Integration.Services
|
||||
{
|
||||
@@ -495,10 +496,10 @@ namespace Umbraco.Tests.Integration.Services
|
||||
[Test]
|
||||
public void Find_By_Email_Starts_With()
|
||||
{
|
||||
var users = MockedUser.CreateMulipleUsers(10);
|
||||
var users = CreateMulipleUsers(10);
|
||||
UserService.Save(users);
|
||||
//don't find this
|
||||
var customUser = MockedUser.CreateUser();
|
||||
var customUser = CreateUser();
|
||||
customUser.Email = "hello@hello.com";
|
||||
UserService.Save(customUser);
|
||||
|
||||
@@ -510,10 +511,10 @@ namespace Umbraco.Tests.Integration.Services
|
||||
[Test]
|
||||
public void Find_By_Email_Ends_With()
|
||||
{
|
||||
var users = MockedUser.CreateMulipleUsers(10);
|
||||
var users = CreateMulipleUsers(10);
|
||||
UserService.Save(users);
|
||||
//include this
|
||||
var customUser = MockedUser.CreateUser();
|
||||
var customUser = CreateUser();
|
||||
customUser.Email = "hello@test.com";
|
||||
UserService.Save(customUser);
|
||||
|
||||
@@ -525,10 +526,10 @@ namespace Umbraco.Tests.Integration.Services
|
||||
[Test]
|
||||
public void Find_By_Email_Contains()
|
||||
{
|
||||
var users = MockedUser.CreateMulipleUsers(10);
|
||||
var users = CreateMulipleUsers(10);
|
||||
UserService.Save(users);
|
||||
//include this
|
||||
var customUser = MockedUser.CreateUser();
|
||||
var customUser = CreateUser();
|
||||
customUser.Email = "hello@test.com";
|
||||
UserService.Save(customUser);
|
||||
|
||||
@@ -540,10 +541,10 @@ namespace Umbraco.Tests.Integration.Services
|
||||
[Test]
|
||||
public void Find_By_Email_Exact()
|
||||
{
|
||||
var users = MockedUser.CreateMulipleUsers(10);
|
||||
var users = CreateMulipleUsers(10);
|
||||
UserService.Save(users);
|
||||
//include this
|
||||
var customUser = MockedUser.CreateUser();
|
||||
var customUser = CreateUser();
|
||||
customUser.Email = "hello@test.com";
|
||||
UserService.Save(customUser);
|
||||
|
||||
@@ -555,7 +556,7 @@ namespace Umbraco.Tests.Integration.Services
|
||||
[Test]
|
||||
public void Get_All_Paged_Users()
|
||||
{
|
||||
var users = MockedUser.CreateMulipleUsers(10);
|
||||
var users = CreateMulipleUsers(10);
|
||||
UserService.Save(users);
|
||||
|
||||
var found = UserService.GetAll(0, 2, out var totalRecs);
|
||||
@@ -570,7 +571,7 @@ namespace Umbraco.Tests.Integration.Services
|
||||
[Test]
|
||||
public void Get_All_Paged_Users_With_Filter()
|
||||
{
|
||||
var users = MockedUser.CreateMulipleUsers(10).ToArray();
|
||||
var users = CreateMulipleUsers(10).ToArray();
|
||||
UserService.Save(users);
|
||||
|
||||
var found = UserService.GetAll(0, 2, out var totalRecs, "username", Direction.Ascending, filter: "test");
|
||||
@@ -587,7 +588,7 @@ namespace Umbraco.Tests.Integration.Services
|
||||
var userGroup = MockedUserGroup.CreateUserGroup();
|
||||
UserService.Save(userGroup);
|
||||
|
||||
var users = MockedUser.CreateMulipleUsers(10).ToArray();
|
||||
var users = CreateMulipleUsers(10).ToArray();
|
||||
for (var i = 0; i < 10;)
|
||||
{
|
||||
users[i].AddGroup(userGroup.ToReadOnlyGroup());
|
||||
@@ -610,7 +611,7 @@ namespace Umbraco.Tests.Integration.Services
|
||||
var userGroup = MockedUserGroup.CreateUserGroup();
|
||||
UserService.Save(userGroup);
|
||||
|
||||
var users = MockedUser.CreateMulipleUsers(10).ToArray();
|
||||
var users = CreateMulipleUsers(10).ToArray();
|
||||
for (var i = 0; i < 10;)
|
||||
{
|
||||
users[i].AddGroup(userGroup.ToReadOnlyGroup());
|
||||
@@ -635,9 +636,9 @@ namespace Umbraco.Tests.Integration.Services
|
||||
[Test]
|
||||
public void Count_All_Users()
|
||||
{
|
||||
var users = MockedUser.CreateMulipleUsers(10);
|
||||
var users = CreateMulipleUsers(10);
|
||||
UserService.Save(users);
|
||||
var customUser = MockedUser.CreateUser();
|
||||
var customUser = CreateUser();
|
||||
UserService.Save(customUser);
|
||||
|
||||
var found = UserService.GetCount(MemberCountType.All);
|
||||
@@ -650,20 +651,20 @@ namespace Umbraco.Tests.Integration.Services
|
||||
[Test]
|
||||
public void Count_All_Online_Users()
|
||||
{
|
||||
var users = MockedUser.CreateMulipleUsers(10, (i, member) => member.LastLoginDate = DateTime.Now.AddMinutes(i * -2));
|
||||
var users = CreateMulipleUsers(10, (i, member) => member.LastLoginDate = DateTime.Now.AddMinutes(i * -2));
|
||||
UserService.Save(users);
|
||||
|
||||
var customUser = MockedUser.CreateUser();
|
||||
var customUser = CreateUser();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Count_All_Locked_Users()
|
||||
{
|
||||
var users = MockedUser.CreateMulipleUsers(10, (i, member) => member.IsLockedOut = i % 2 == 0);
|
||||
var users = CreateMulipleUsers(10, (i, member) => member.IsLockedOut = i % 2 == 0);
|
||||
UserService.Save(users);
|
||||
|
||||
var customUser = MockedUser.CreateUser();
|
||||
var customUser = CreateUser();
|
||||
customUser.IsLockedOut = true;
|
||||
UserService.Save(customUser);
|
||||
|
||||
@@ -675,10 +676,10 @@ namespace Umbraco.Tests.Integration.Services
|
||||
[Test]
|
||||
public void Count_All_Approved_Users()
|
||||
{
|
||||
var users = MockedUser.CreateMulipleUsers(10, (i, member) => member.IsApproved = i % 2 == 0);
|
||||
var users = CreateMulipleUsers(10, (i, member) => member.IsApproved = i % 2 == 0);
|
||||
UserService.Save(users);
|
||||
|
||||
var customUser = MockedUser.CreateUser();
|
||||
var customUser = CreateUser();
|
||||
customUser.IsApproved = false;
|
||||
UserService.Save(customUser);
|
||||
|
||||
@@ -896,7 +897,7 @@ namespace Umbraco.Tests.Integration.Services
|
||||
public void Get_By_Profile_Id()
|
||||
{
|
||||
// Arrange
|
||||
var user = (IUser)UserService.CreateUserWithIdentity("test1", "test1@test.com");
|
||||
var user = UserService.CreateUserWithIdentity("test1", "test1@test.com");
|
||||
|
||||
// Act
|
||||
var profile = UserService.GetProfileById((int)user.Id);
|
||||
@@ -908,7 +909,7 @@ namespace Umbraco.Tests.Integration.Services
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_By_Profile_Id_Must_return_null_if_user_not_exists()
|
||||
public void Get_By_Profile_Id_Must_Return_Null_If_User_Does_Not_Exist()
|
||||
{
|
||||
var profile = UserService.GetProfileById(42);
|
||||
|
||||
@@ -917,7 +918,7 @@ namespace Umbraco.Tests.Integration.Services
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetProfilesById_Must_empty_if_users_not_exists()
|
||||
public void GetProfilesById_Must_Return_Empty_If_User_Does_Not_Exist()
|
||||
{
|
||||
var profiles = UserService.GetProfilesById(42);
|
||||
|
||||
@@ -983,6 +984,39 @@ namespace Umbraco.Tests.Integration.Services
|
||||
return startContentItems.ToArray();
|
||||
}
|
||||
|
||||
private static IEnumerable<IUser> CreateMulipleUsers(int amount, Action<int, IUser> onCreating = null)
|
||||
{
|
||||
var list = new List<IUser>();
|
||||
|
||||
for (var i = 0; i < amount; i++)
|
||||
{
|
||||
var name = "User No-" + i;
|
||||
var user = new UserBuilder()
|
||||
.WithName(name)
|
||||
.WithEmail("test" + i + "@test.com")
|
||||
.WithLogin("test" + i, "test" + i)
|
||||
.Build();
|
||||
|
||||
onCreating?.Invoke(i, user);
|
||||
|
||||
user.ResetDirtyProperties(false);
|
||||
|
||||
list.Add(user);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private static User CreateUser(string suffix = "")
|
||||
{
|
||||
return new UserBuilder()
|
||||
.WithIsApproved(true)
|
||||
.WithName("TestUser" + suffix)
|
||||
.WithLogin("TestUser" + suffix, "testing")
|
||||
.WithEmail("test" + suffix + "@test.com")
|
||||
.Build();
|
||||
}
|
||||
|
||||
private IUser CreateTestUser(out IUserGroup userGroup)
|
||||
{
|
||||
userGroup = CreateTestUserGroup();
|
||||
@@ -1018,19 +1052,16 @@ namespace Umbraco.Tests.Integration.Services
|
||||
|
||||
private UserGroup CreateTestUserGroup(string alias = "testGroup", string name = "Test Group")
|
||||
{
|
||||
var userGroup = new UserGroup(ShortStringHelper)
|
||||
{
|
||||
Alias = alias,
|
||||
Name = name,
|
||||
Permissions = "ABCDEFGHIJ1234567".ToCharArray().Select(x => x.ToString())
|
||||
};
|
||||
|
||||
userGroup.AddAllowedSection("content");
|
||||
userGroup.AddAllowedSection("media");
|
||||
var userGroup = new UserGroupBuilder()
|
||||
.WithAlias(alias)
|
||||
.WithName(name)
|
||||
.WithPermissions("ABCDEFGHIJ1234567")
|
||||
.WithAllowedSections(new[] { "content", "media" })
|
||||
.Build();
|
||||
|
||||
UserService.Save(userGroup);
|
||||
|
||||
return userGroup;
|
||||
return (UserGroup)userGroup;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -15,6 +16,7 @@ using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Services.Implement;
|
||||
using Umbraco.Core.Sync;
|
||||
using Umbraco.Core.WebAssets;
|
||||
using Umbraco.Examine;
|
||||
using Umbraco.Web.Compose;
|
||||
@@ -51,6 +53,10 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
|
||||
// replace this service so that it can lookup the correct file locations
|
||||
composition.RegisterUnique<ILocalizedTextService>(GetLocalizedTextService);
|
||||
|
||||
composition.RegisterUnique<IServerMessenger, NoopServerMessenger>();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -101,5 +107,51 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
}
|
||||
}
|
||||
|
||||
private class NoopServerMessenger : IServerMessenger
|
||||
{
|
||||
public NoopServerMessenger()
|
||||
{ }
|
||||
|
||||
public void PerformRefresh<TPayload>(ICacheRefresher refresher, TPayload[] payload)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void PerformRefresh<T>(ICacheRefresher refresher, Func<T, int> getNumericId, params T[] instances)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void PerformRefresh<T>(ICacheRefresher refresher, Func<T, Guid> getGuidId, params T[] instances)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void PerformRemove<T>(ICacheRefresher refresher, Func<T, int> getNumericId, params T[] instances)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void PerformRemove(ICacheRefresher refresher, params int[] numericIds)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void PerformRefresh(ICacheRefresher refresher, params int[] numericIds)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void PerformRefresh(ICacheRefresher refresher, params Guid[] guidIds)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void PerformRefreshAll(ICacheRefresher refresher)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,6 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
[NonParallelizable]
|
||||
public abstract class UmbracoIntegrationTest
|
||||
{
|
||||
|
||||
public static LightInjectContainer CreateUmbracoContainer(out UmbracoServiceProviderFactory serviceProviderFactory)
|
||||
{
|
||||
var container = UmbracoServiceProviderFactory.CreateServiceContainer();
|
||||
@@ -82,6 +81,8 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
{
|
||||
foreach (var a in _testTeardown) a();
|
||||
_testTeardown = null;
|
||||
FirstTestInFixture = false;
|
||||
FirstTestInSession = false;
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
@@ -278,7 +279,7 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
Services.GetRequiredService<IBackofficeSecurityFactory>().EnsureBackofficeSecurity();
|
||||
Services.GetRequiredService<IUmbracoContextFactory>().EnsureUmbracoContext();
|
||||
|
||||
// get the currently set ptions
|
||||
// get the currently set options
|
||||
var testOptions = TestOptionAttributeBase.GetTestOptions<UmbracoTestAttribute>();
|
||||
if (testOptions.Boot)
|
||||
{
|
||||
@@ -399,12 +400,26 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
|
||||
break;
|
||||
case UmbracoTestOptions.Database.NewSchemaPerFixture:
|
||||
// Only attach schema once per fixture
|
||||
// Doing it more than once will block the process since the old db hasn't been detached
|
||||
// and it would be the same as NewSchemaPerTest even if it didn't block
|
||||
if (FirstTestInFixture)
|
||||
{
|
||||
// New DB + Schema
|
||||
var newSchemaFixtureDbId = db.AttachSchema();
|
||||
|
||||
// New DB + Schema
|
||||
var newSchemaFixtureDbId = db.AttachSchema();
|
||||
// Add teardown callback
|
||||
OnFixtureTearDown(() => db.Detach(newSchemaFixtureDbId));
|
||||
}
|
||||
|
||||
// Add teardown callback
|
||||
OnFixtureTearDown(() => db.Detach(newSchemaFixtureDbId));
|
||||
// We must re-configure our current factory since attaching a new LocalDb from the pool changes connection strings
|
||||
if (!databaseFactory.Configured)
|
||||
{
|
||||
databaseFactory.Configure(db.ConnectionString, Constants.DatabaseProviders.SqlServer);
|
||||
}
|
||||
|
||||
// re-run the runtime level check
|
||||
runtimeState.DetermineRuntimeLevel();
|
||||
|
||||
break;
|
||||
case UmbracoTestOptions.Database.NewEmptyPerFixture:
|
||||
@@ -474,5 +489,9 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
protected UserGroupBuilder UserGroupBuilder = new UserGroupBuilder();
|
||||
|
||||
#endregion
|
||||
|
||||
protected static bool FirstTestInSession = true;
|
||||
|
||||
protected bool FirstTestInFixture = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.Packaging;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
|
||||
namespace Umbraco.Tests.Packaging
|
||||
{
|
||||
@@ -16,9 +14,9 @@ namespace Umbraco.Tests.Packaging
|
||||
|
||||
private static FileInfo GetTestPackagePath(string packageName)
|
||||
{
|
||||
const string testPackagesDirName = "Packaging\\Packages";
|
||||
var hosting = TestHelper.GetHostingEnvironment();
|
||||
string path = Path.Combine(hosting.ApplicationPhysicalPath, testPackagesDirName, packageName);
|
||||
const string testPackagesDirName = "Umbraco.Core\\Packaging\\Packages";
|
||||
var testDir = TestContext.CurrentContext.TestDirectory.Split("bin")[0];
|
||||
var path = Path.Combine(testDir, testPackagesDirName, packageName);
|
||||
return new FileInfo(path);
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -5,15 +5,16 @@ using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Tests.TestHelpers.Entities;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
{
|
||||
[TestFixture]
|
||||
[UmbracoTest(WithApplication = true)]
|
||||
public class ContentTypeServiceExtensionsTests : UmbracoTestBase
|
||||
public class ContentTypeServiceExtensionsTests
|
||||
{
|
||||
private IShortStringHelper ShortStringHelper => new DefaultShortStringHelper(new DefaultShortStringHelperConfig());
|
||||
|
||||
[Test]
|
||||
public void GetAvailableCompositeContentTypes_No_Overlap_By_Content_Type_And_Property_Type_Alias()
|
||||
{
|
||||
@@ -2,14 +2,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Services.Implement;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
@@ -7,14 +7,15 @@ using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.PropertyEditors.Validators;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Web.PropertyEditors;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
{
|
||||
[TestFixture]
|
||||
public class PropertyValidationServiceTests : UmbracoTestBase
|
||||
public class PropertyValidationServiceTests
|
||||
{
|
||||
private IShortStringHelper ShortStringHelper => new DefaultShortStringHelper(new DefaultShortStringHelperConfig());
|
||||
|
||||
private void MockObjects(out PropertyValidationService validationService, out IDataType dt)
|
||||
{
|
||||
var textService = new Mock<ILocalizedTextService>();
|
||||
@@ -1,8 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
@@ -10,8 +7,8 @@ using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Entities;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.Common.TestHelpers.Entities;
|
||||
using Umbraco.Tests.TestHelpers.Entities;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
using Umbraco.Web.Editors;
|
||||
|
||||
namespace Umbraco.Tests.Web.Controllers
|
||||
@@ -22,8 +19,8 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
[Test]
|
||||
public void Admin_Is_Authorized()
|
||||
{
|
||||
var currentUser = GetAdminUser();
|
||||
var savingUser = MockedUser.GetUserMock();
|
||||
var currentUser = CreateAdminUser();
|
||||
var savingUser = CreateUser();
|
||||
|
||||
var contentService = new Mock<IContentService>();
|
||||
var mediaService = new Mock<IMediaService>();
|
||||
@@ -36,7 +33,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
userService.Object,
|
||||
entityService.Object);
|
||||
|
||||
var result = authHelper.IsAuthorized(currentUser, savingUser.Object, new int[0], new int[0], new string[0]);
|
||||
var result = authHelper.IsAuthorized(currentUser, savingUser, new int[0], new int[0], new string[0]);
|
||||
|
||||
Assert.IsTrue(result.Success);
|
||||
}
|
||||
@@ -44,8 +41,8 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
[Test]
|
||||
public void Non_Admin_Cannot_Save_Admin()
|
||||
{
|
||||
var currentUser = MockedUser.GetUserMock();
|
||||
var savingUser = GetAdminUser();
|
||||
var currentUser = CreateUser();
|
||||
var savingUser = CreateAdminUser();
|
||||
|
||||
var contentService = new Mock<IContentService>();
|
||||
var mediaService = new Mock<IMediaService>();
|
||||
@@ -58,7 +55,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
userService.Object,
|
||||
entityService.Object);
|
||||
|
||||
var result = authHelper.IsAuthorized(currentUser.Object, savingUser, new int[0], new int[0], new string[0]);
|
||||
var result = authHelper.IsAuthorized(currentUser, savingUser, new int[0], new int[0], new string[0]);
|
||||
|
||||
Assert.IsFalse(result.Success);
|
||||
}
|
||||
@@ -66,12 +63,8 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
[Test]
|
||||
public void Cannot_Grant_Group_Membership_Without_Being_A_Member()
|
||||
{
|
||||
var currentUser = MockedUser.GetUserMock();
|
||||
currentUser.Setup(x => x.Groups).Returns(new[]
|
||||
{
|
||||
new ReadOnlyUserGroup(1, "Test", "icon-user", null, null, "test", new string[0], new string[0])
|
||||
});
|
||||
var savingUser = MockedUser.GetUserMock();
|
||||
var currentUser = CreateUser(withGroup: true);
|
||||
var savingUser = CreateUser();
|
||||
|
||||
var contentService = new Mock<IContentService>();
|
||||
var mediaService = new Mock<IMediaService>();
|
||||
@@ -84,7 +77,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
userService.Object,
|
||||
entityService.Object);
|
||||
|
||||
var result = authHelper.IsAuthorized(currentUser.Object, savingUser.Object, new int[0], new int[0], new[] {"FunGroup"});
|
||||
var result = authHelper.IsAuthorized(currentUser, savingUser, new int[0], new int[0], new[] {"FunGroup"});
|
||||
|
||||
Assert.IsFalse(result.Success);
|
||||
}
|
||||
@@ -92,12 +85,8 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
[Test]
|
||||
public void Can_Grant_Group_Membership_With_Being_A_Member()
|
||||
{
|
||||
var currentUser = MockedUser.GetUserMock();
|
||||
currentUser.Setup(x => x.Groups).Returns(new[]
|
||||
{
|
||||
new ReadOnlyUserGroup(1, "Test", "icon-user", null, null, "test", new string[0], new string[0])
|
||||
});
|
||||
var savingUser = MockedUser.GetUserMock();
|
||||
var currentUser = CreateUser(withGroup: true);
|
||||
var savingUser = CreateUser();
|
||||
|
||||
var contentService = new Mock<IContentService>();
|
||||
var mediaService = new Mock<IMediaService>();
|
||||
@@ -110,7 +99,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
userService.Object,
|
||||
entityService.Object);
|
||||
|
||||
var result = authHelper.IsAuthorized(currentUser.Object, savingUser.Object, new int[0], new int[0], new[] { "test" });
|
||||
var result = authHelper.IsAuthorized(currentUser, savingUser, new int[0], new int[0], new[] { "test" });
|
||||
|
||||
Assert.IsTrue(result.Success);
|
||||
}
|
||||
@@ -126,10 +115,8 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
{4567, "-1,4567"},
|
||||
};
|
||||
|
||||
var currentUser = MockedUser.GetUserMock();
|
||||
currentUser.Setup(x => x.StartContentIds).Returns(new[] { 9876 });
|
||||
var savingUser = MockedUser.GetUserMock();
|
||||
savingUser.Setup(x => x.StartContentIds).Returns(new[] { 1234 });
|
||||
var currentUser = CreateUser(startContentIds: new[] { 9876 });
|
||||
var savingUser = CreateUser(startContentIds: new[] { 1234 });
|
||||
|
||||
var contentService = new Mock<IContentService>();
|
||||
contentService.Setup(x => x.GetById(It.IsAny<int>()))
|
||||
@@ -150,7 +137,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
entityService.Object);
|
||||
|
||||
//adding 5555 which currentUser has access to since it's a child of 9876 ... adding is still ok even though currentUser doesn't have access to 1234
|
||||
var result = authHelper.IsAuthorized(currentUser.Object, savingUser.Object, new[] { 1234, 5555 }, new int[0], new string[0]);
|
||||
var result = authHelper.IsAuthorized(currentUser, savingUser, new[] { 1234, 5555 }, new int[0], new string[0]);
|
||||
|
||||
Assert.IsTrue(result.Success);
|
||||
}
|
||||
@@ -166,10 +153,8 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
{4567, "-1,4567"},
|
||||
};
|
||||
|
||||
var currentUser = MockedUser.GetUserMock();
|
||||
currentUser.Setup(x => x.StartContentIds).Returns(new[] { 9876 });
|
||||
var savingUser = MockedUser.GetUserMock();
|
||||
savingUser.Setup(x => x.StartContentIds).Returns(new[] { 1234, 4567 });
|
||||
var currentUser = CreateUser(startContentIds: new[] { 9876 });
|
||||
var savingUser = CreateUser(startContentIds: new[] { 1234, 4567 });
|
||||
|
||||
var contentService = new Mock<IContentService>();
|
||||
contentService.Setup(x => x.GetById(It.IsAny<int>()))
|
||||
@@ -190,7 +175,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
entityService.Object);
|
||||
|
||||
//removing 4567 start node even though currentUser doesn't have acces to it ... removing is ok
|
||||
var result = authHelper.IsAuthorized(currentUser.Object, savingUser.Object, new[] { 1234 }, new int[0], new string[0]);
|
||||
var result = authHelper.IsAuthorized(currentUser, savingUser, new[] { 1234 }, new int[0], new string[0]);
|
||||
|
||||
Assert.IsTrue(result.Success);
|
||||
}
|
||||
@@ -206,9 +191,8 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
{4567, "-1,4567"},
|
||||
};
|
||||
|
||||
var currentUser = MockedUser.GetUserMock();
|
||||
currentUser.Setup(x => x.StartContentIds).Returns(new[] { 9876 });
|
||||
var savingUser = MockedUser.GetUserMock();
|
||||
var currentUser = CreateUser(startContentIds: new[] { 9876 });
|
||||
var savingUser = CreateUser();
|
||||
|
||||
var contentService = new Mock<IContentService>();
|
||||
contentService.Setup(x => x.GetById(It.IsAny<int>()))
|
||||
@@ -229,7 +213,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
entityService.Object);
|
||||
|
||||
//adding 1234 but currentUser doesn't have access to it ... nope
|
||||
var result = authHelper.IsAuthorized(currentUser.Object, savingUser.Object, new []{1234}, new int[0], new string[0]);
|
||||
var result = authHelper.IsAuthorized(currentUser, savingUser, new []{1234}, new int[0], new string[0]);
|
||||
|
||||
Assert.IsFalse(result.Success);
|
||||
}
|
||||
@@ -245,9 +229,8 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
{4567, "-1,4567"},
|
||||
};
|
||||
|
||||
var currentUser = MockedUser.GetUserMock();
|
||||
currentUser.Setup(x => x.StartContentIds).Returns(new[] { 9876 });
|
||||
var savingUser = MockedUser.GetUserMock();
|
||||
var currentUser = CreateUser(startContentIds: new[] { 9876 });
|
||||
var savingUser = CreateUser();
|
||||
|
||||
var contentService = new Mock<IContentService>();
|
||||
contentService.Setup(x => x.GetById(It.IsAny<int>()))
|
||||
@@ -268,7 +251,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
entityService.Object);
|
||||
|
||||
//adding 5555 which currentUser has access to since it's a child of 9876 ... ok
|
||||
var result = authHelper.IsAuthorized(currentUser.Object, savingUser.Object, new[] { 5555 }, new int[0], new string[0]);
|
||||
var result = authHelper.IsAuthorized(currentUser, savingUser, new[] { 5555 }, new int[0], new string[0]);
|
||||
|
||||
Assert.IsTrue(result.Success);
|
||||
}
|
||||
@@ -285,9 +268,8 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
};
|
||||
|
||||
|
||||
var currentUser = MockedUser.GetUserMock();
|
||||
currentUser.Setup(x => x.StartContentIds).Returns(new[] { 9876 });
|
||||
var savingUser = MockedUser.GetUserMock();
|
||||
var currentUser = CreateUser(startMediaIds: new[] { 9876 });
|
||||
var savingUser = CreateUser();
|
||||
|
||||
var contentService = new Mock<IContentService>();
|
||||
var mediaService = new Mock<IMediaService>();
|
||||
@@ -308,7 +290,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
entityService.Object);
|
||||
|
||||
//adding 1234 but currentUser doesn't have access to it ... nope
|
||||
var result = authHelper.IsAuthorized(currentUser.Object, savingUser.Object, new int[0], new[] {1234}, new string[0]);
|
||||
var result = authHelper.IsAuthorized(currentUser, savingUser, new int[0], new[] {1234}, new string[0]);
|
||||
|
||||
Assert.IsFalse(result.Success);
|
||||
}
|
||||
@@ -324,9 +306,8 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
{4567, "-1,4567"},
|
||||
};
|
||||
|
||||
var currentUser = MockedUser.GetUserMock();
|
||||
currentUser.Setup(x => x.StartMediaIds).Returns(new[] { 9876 });
|
||||
var savingUser = MockedUser.GetUserMock();
|
||||
var currentUser = CreateUser(startMediaIds: new[] { 9876 });
|
||||
var savingUser = CreateUser();
|
||||
|
||||
var contentService = new Mock<IContentService>();
|
||||
var mediaService = new Mock<IMediaService>();
|
||||
@@ -347,7 +328,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
entityService.Object);
|
||||
|
||||
//adding 5555 which currentUser has access to since it's a child of 9876 ... ok
|
||||
var result = authHelper.IsAuthorized(currentUser.Object, savingUser.Object, new int[0], new[] { 5555 }, new string[0]);
|
||||
var result = authHelper.IsAuthorized(currentUser, savingUser, new int[0], new[] { 5555 }, new string[0]);
|
||||
|
||||
Assert.IsTrue(result.Success);
|
||||
}
|
||||
@@ -363,10 +344,8 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
{4567, "-1,4567"},
|
||||
};
|
||||
|
||||
var currentUser = MockedUser.GetUserMock();
|
||||
currentUser.Setup(x => x.StartMediaIds).Returns(new[] { 9876 });
|
||||
var savingUser = MockedUser.GetUserMock();
|
||||
savingUser.Setup(x => x.StartMediaIds).Returns(new[] { 1234 });
|
||||
var currentUser = CreateUser(startMediaIds: new[] { 9876 });
|
||||
var savingUser = CreateUser(startMediaIds: new[] { 1234 });
|
||||
|
||||
var contentService = new Mock<IContentService>();
|
||||
var mediaService = new Mock<IMediaService>();
|
||||
@@ -387,7 +366,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
entityService.Object);
|
||||
|
||||
//adding 5555 which currentUser has access to since it's a child of 9876 ... adding is still ok even though currentUser doesn't have access to 1234
|
||||
var result = authHelper.IsAuthorized(currentUser.Object, savingUser.Object, new int[0], new[] { 1234, 5555 }, new string[0]);
|
||||
var result = authHelper.IsAuthorized(currentUser, savingUser, new int[0], new[] { 1234, 5555 }, new string[0]);
|
||||
|
||||
Assert.IsTrue(result.Success);
|
||||
}
|
||||
@@ -403,10 +382,8 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
{4567, "-1,4567"},
|
||||
};
|
||||
|
||||
var currentUser = MockedUser.GetUserMock();
|
||||
currentUser.Setup(x => x.StartMediaIds).Returns(new[] { 9876 });
|
||||
var savingUser = MockedUser.GetUserMock();
|
||||
savingUser.Setup(x => x.StartMediaIds).Returns(new[] { 1234, 4567 });
|
||||
var currentUser = CreateUser(startMediaIds: new[] { 9876 });
|
||||
var savingUser = CreateUser(startMediaIds: new[] { 1234, 4567 });
|
||||
|
||||
var contentService = new Mock<IContentService>();
|
||||
var mediaService = new Mock<IMediaService>();
|
||||
@@ -427,19 +404,37 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
entityService.Object);
|
||||
|
||||
//removing 4567 start node even though currentUser doesn't have acces to it ... removing is ok
|
||||
var result = authHelper.IsAuthorized(currentUser.Object, savingUser.Object, new int[0], new[] { 1234 }, new string[0]);
|
||||
var result = authHelper.IsAuthorized(currentUser, savingUser, new int[0], new[] { 1234 }, new string[0]);
|
||||
|
||||
Assert.IsTrue(result.Success);
|
||||
}
|
||||
|
||||
private IUser GetAdminUser()
|
||||
private static IUser CreateUser(bool withGroup = false, int[] startContentIds = null, int[] startMediaIds = null)
|
||||
{
|
||||
var admin = MockedUser.GetUserMock();
|
||||
admin.Setup(x => x.Groups).Returns(new[]
|
||||
var builder = new UserBuilder()
|
||||
.WithStartContentIds(startContentIds != null ? startContentIds : new int[0])
|
||||
.WithStartMediaIds(startMediaIds != null ? startMediaIds : new int[0]);
|
||||
if (withGroup)
|
||||
{
|
||||
new ReadOnlyUserGroup(1, "Admin", "icon-user", null, null, Constants.Security.AdminGroupAlias, new string[0], new string[0])
|
||||
});
|
||||
return admin.Object;
|
||||
builder = (UserBuilder)builder
|
||||
.AddUserGroup()
|
||||
.WithName("Test")
|
||||
.WithAlias("test")
|
||||
.Done();
|
||||
}
|
||||
|
||||
return builder.Build();
|
||||
}
|
||||
|
||||
private static IUser CreateAdminUser()
|
||||
{
|
||||
return new UserBuilder()
|
||||
.AddUserGroup()
|
||||
.WithId(1)
|
||||
.WithName("Admin")
|
||||
.WithAlias(Constants.Security.AdminGroupAlias)
|
||||
.Done()
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ using NUnit.Framework;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Services.Implement;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Services
|
||||
{
|
||||
[TestFixture]
|
||||
public class AmbiguousEventTests
|
||||
@@ -75,4 +75,4 @@ namespace Umbraco.Tests.Services
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
@@ -41,7 +41,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
|
||||
Assert.AreEqual(testName, userGroup.Name);
|
||||
Assert.AreEqual(testUserCount, userGroup.UserCount);
|
||||
Assert.AreEqual(testIcon, userGroup.Icon);
|
||||
Assert.AreEqual(testPermissions, string.Join(string.Empty, userGroup.Permissions));
|
||||
Assert.AreEqual(testPermissions.Length, userGroup.Permissions.Count());
|
||||
Assert.AreEqual(testStartContentId, userGroup.StartContentId);
|
||||
Assert.AreEqual(testStartMediaId, userGroup.StartMediaId);
|
||||
}
|
||||
|
||||
@@ -1,27 +1,23 @@
|
||||
using System.Collections.Generic;
|
||||
using Moq;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Entities;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Security;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.Common.TestHelpers.Entities;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
|
||||
namespace Umbraco.Tests.Web.Controllers
|
||||
{
|
||||
[TestFixture]
|
||||
public class ContentControllerUnitTests
|
||||
{
|
||||
|
||||
[Test]
|
||||
public void Access_Allowed_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = MockedUser.GetUserMock();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.Groups).Returns(new[] { new ReadOnlyUserGroup(1, "admin", "", -1, -1, "admin", new string[0], new List<string>()) });
|
||||
var user = userMock.Object;
|
||||
var user = CreateUser(id: 9);
|
||||
var contentMock = new Mock<IContent>();
|
||||
contentMock.Setup(c => c.Path).Returns("-1,1234,5678");
|
||||
var content = contentMock.Object;
|
||||
@@ -44,9 +40,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
public void No_Content_Found()
|
||||
{
|
||||
//arrange
|
||||
var userMock = MockedUser.GetUserMock();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
var user = userMock.Object;
|
||||
var user = CreateUser(id: 9);
|
||||
var contentMock = new Mock<IContent>();
|
||||
contentMock.Setup(c => c.Path).Returns("-1,1234,5678");
|
||||
var content = contentMock.Object;
|
||||
@@ -72,10 +66,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
public void No_Access_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = MockedUser.GetUserMock();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.StartContentIds).Returns(new[] { 9876 });
|
||||
var user = userMock.Object;
|
||||
var user = CreateUser(id: 9, startContentId: 9876);
|
||||
var contentMock = new Mock<IContent>();
|
||||
contentMock.Setup(c => c.Path).Returns("-1,1234,5678");
|
||||
var content = contentMock.Object;
|
||||
@@ -103,9 +94,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
public void No_Access_By_Permission()
|
||||
{
|
||||
//arrange
|
||||
var userMock = MockedUser.GetUserMock();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
var user = userMock.Object;
|
||||
var user = CreateUser(id: 9);
|
||||
var contentMock = new Mock<IContent>();
|
||||
contentMock.Setup(c => c.Path).Returns("-1,1234,5678");
|
||||
var content = contentMock.Object;
|
||||
@@ -134,10 +123,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
public void Access_Allowed_By_Permission()
|
||||
{
|
||||
//arrange
|
||||
var userMock = MockedUser.GetUserMock();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.Groups).Returns(new[] { new ReadOnlyUserGroup(1, "admin", "", -1, -1, "admin", new string[0], new List<string>()) });
|
||||
var user = userMock.Object;
|
||||
var user = CreateUser(id: 9);
|
||||
var contentMock = new Mock<IContent>();
|
||||
contentMock.Setup(c => c.Path).Returns("-1,1234,5678");
|
||||
var content = contentMock.Object;
|
||||
@@ -166,10 +152,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
public void Access_To_Root_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = MockedUser.GetUserMock();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.Groups).Returns(new[] { new ReadOnlyUserGroup(1, "admin", "", -1, -1, "admin", new string[0], new List<string>()) });
|
||||
var user = userMock.Object;
|
||||
var user = CreateUser();
|
||||
var contentServiceMock = new Mock<IContentService>();
|
||||
var contentService = contentServiceMock.Object;
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
@@ -188,10 +171,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
public void Access_To_Recycle_Bin_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = MockedUser.GetUserMock();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.Groups).Returns(new[] { new ReadOnlyUserGroup(1, "admin", "", -1, -1, "admin", new string[0], new List<string>()) });
|
||||
var user = userMock.Object;
|
||||
var user = CreateUser();
|
||||
var contentServiceMock = new Mock<IContentService>();
|
||||
var contentService = contentServiceMock.Object;
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
@@ -210,10 +190,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
public void No_Access_To_Recycle_Bin_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = MockedUser.GetUserMock();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartContentIds).Returns(new[] { 1234 });
|
||||
var user = userMock.Object;
|
||||
var user = CreateUser(startContentId: 1234);
|
||||
var contentServiceMock = new Mock<IContentService>();
|
||||
var contentService = contentServiceMock.Object;
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
@@ -234,10 +211,8 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
public void No_Access_To_Root_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = MockedUser.GetUserMock();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartContentIds).Returns(new[] { 1234 });
|
||||
var user = userMock.Object;
|
||||
var user = CreateUser(startContentId: 1234);
|
||||
|
||||
var contentServiceMock = new Mock<IContentService>();
|
||||
var contentService = contentServiceMock.Object;
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
@@ -258,10 +233,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
public void Access_To_Root_By_Permission()
|
||||
{
|
||||
//arrange
|
||||
var userMock = MockedUser.GetUserMock();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.Groups).Returns(new[] { new ReadOnlyUserGroup(1, "admin", "", -1, -1, "admin", new string[0], new List<string>()) });
|
||||
var user = userMock.Object;
|
||||
var user = CreateUser();
|
||||
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var permissions = new EntityPermissionCollection
|
||||
@@ -276,7 +248,6 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
var entityServiceMock = new Mock<IEntityService>();
|
||||
var entityService = entityServiceMock.Object;
|
||||
|
||||
|
||||
//act
|
||||
var result = ContentPermissionsHelper.CheckPermissions(-1, user, userService, contentService, entityService, out var foundContent, new[] { 'A' });
|
||||
|
||||
@@ -288,9 +259,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
public void No_Access_To_Root_By_Permission()
|
||||
{
|
||||
//arrange
|
||||
var userMock = MockedUser.GetUserMock();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
var user = userMock.Object;
|
||||
var user = CreateUser(withUserGroup: false);
|
||||
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var permissions = new EntityPermissionCollection
|
||||
@@ -316,10 +285,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
public void Access_To_Recycle_Bin_By_Permission()
|
||||
{
|
||||
//arrange
|
||||
var userMock = MockedUser.GetUserMock();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.Groups).Returns(new[] { new ReadOnlyUserGroup(1, "admin", "", -1, -1, "admin", new string[0], new List<string>()) });
|
||||
var user = userMock.Object;
|
||||
var user = CreateUser();
|
||||
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var permissions = new EntityPermissionCollection
|
||||
@@ -346,9 +312,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
public void No_Access_To_Recycle_Bin_By_Permission()
|
||||
{
|
||||
//arrange
|
||||
var userMock = MockedUser.GetUserMock();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
var user = userMock.Object;
|
||||
var user = CreateUser(withUserGroup: false);
|
||||
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var permissions = new EntityPermissionCollection
|
||||
@@ -369,6 +333,24 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
//assert
|
||||
Assert.AreEqual(ContentPermissionsHelper.ContentAccess.Denied, result);
|
||||
}
|
||||
|
||||
private IUser CreateUser(int id = 0, int? startContentId = null, bool withUserGroup = true)
|
||||
{
|
||||
var builder = new UserBuilder()
|
||||
.WithId(id)
|
||||
.WithStartContentIds(startContentId.HasValue ? new[] { startContentId.Value } : new int[0]);
|
||||
if (withUserGroup)
|
||||
{
|
||||
builder = builder
|
||||
.AddUserGroup()
|
||||
.WithId(1)
|
||||
.WithName("admin")
|
||||
.WithAlias("admin")
|
||||
.Done();
|
||||
}
|
||||
|
||||
return builder.Build();
|
||||
}
|
||||
}
|
||||
|
||||
//NOTE: The below self hosted stuff does work so need to get some tests written. Some are not possible atm because
|
||||
|
||||
@@ -5,7 +5,8 @@ using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Entities;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.Common.TestHelpers.Entities;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
using Umbraco.Web.BackOffice.Controllers;
|
||||
using Umbraco.Web.Common.Exceptions;
|
||||
|
||||
@@ -18,10 +19,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
public void Access_Allowed_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = MockedUser.GetUserMock();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.Groups).Returns(new[] { new ReadOnlyUserGroup(1, "admin", "", -1, -1, "admin", new string[0], new List<string>()) });
|
||||
var user = userMock.Object;
|
||||
var user = CreateUser(id: 9);
|
||||
var mediaMock = new Mock<IMedia>();
|
||||
mediaMock.Setup(m => m.Path).Returns("-1,1234,5678");
|
||||
var media = mediaMock.Object;
|
||||
@@ -42,9 +40,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
public void Throws_Exception_When_No_Media_Found()
|
||||
{
|
||||
//arrange
|
||||
var userMock = MockedUser.GetUserMock();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
var user = userMock.Object;
|
||||
var user = CreateUser(id: 9);
|
||||
var mediaMock = new Mock<IMedia>();
|
||||
mediaMock.Setup(m => m.Path).Returns("-1,1234,5678");
|
||||
var media = mediaMock.Object;
|
||||
@@ -62,10 +58,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
public void No_Access_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = MockedUser.GetUserMock();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.StartMediaIds).Returns(new[] { 9876 });
|
||||
var user = userMock.Object;
|
||||
var user = CreateUser(id: 9, startMediaId: 9876);
|
||||
var mediaMock = new Mock<IMedia>();
|
||||
mediaMock.Setup(m => m.Path).Returns("-1,1234,5678");
|
||||
var media = mediaMock.Object;
|
||||
@@ -88,10 +81,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
public void Access_To_Root_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = MockedUser.GetUserMock();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.Groups).Returns(new[] { new ReadOnlyUserGroup(1, "admin", "", -1, -1, "admin", new string[0], new List<string>()) });
|
||||
var user = userMock.Object;
|
||||
var user = CreateUser();
|
||||
var mediaServiceMock = new Mock<IMediaService>();
|
||||
var mediaService = mediaServiceMock.Object;
|
||||
var entityServiceMock = new Mock<IEntityService>();
|
||||
@@ -108,10 +98,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
public void No_Access_To_Root_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = MockedUser.GetUserMock();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartMediaIds).Returns(new[] { 1234 });
|
||||
var user = userMock.Object;
|
||||
var user = CreateUser(startMediaId: 1234);
|
||||
var mediaServiceMock = new Mock<IMediaService>();
|
||||
var mediaService = mediaServiceMock.Object;
|
||||
var entityServiceMock = new Mock<IEntityService>();
|
||||
@@ -130,10 +117,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
public void Access_To_Recycle_Bin_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = MockedUser.GetUserMock();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.Groups).Returns(new[] { new ReadOnlyUserGroup(1, "admin", "", -1, -1, "admin", new string[0], new List<string>()) });
|
||||
var user = userMock.Object;
|
||||
var user = CreateUser();
|
||||
var mediaServiceMock = new Mock<IMediaService>();
|
||||
var mediaService = mediaServiceMock.Object;
|
||||
var entityServiceMock = new Mock<IEntityService>();
|
||||
@@ -150,10 +134,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
public void No_Access_To_Recycle_Bin_By_Path()
|
||||
{
|
||||
//arrange
|
||||
var userMock = MockedUser.GetUserMock();
|
||||
userMock.Setup(u => u.Id).Returns(0);
|
||||
userMock.Setup(u => u.StartMediaIds).Returns(new[] { 1234 });
|
||||
var user = userMock.Object;
|
||||
var user = CreateUser(startMediaId: 1234);
|
||||
var mediaServiceMock = new Mock<IMediaService>();
|
||||
var mediaService = mediaServiceMock.Object;
|
||||
var entityServiceMock = new Mock<IEntityService>();
|
||||
@@ -167,5 +148,18 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
//assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
private IUser CreateUser(int id = 0, int? startMediaId = null)
|
||||
{
|
||||
return new UserBuilder()
|
||||
.WithId(id)
|
||||
.WithStartMediaIds(startMediaId.HasValue ? new[] { startMediaId.Value } : new int[0])
|
||||
.AddUserGroup()
|
||||
.WithId(1)
|
||||
.WithName("admin")
|
||||
.WithAlias("admin")
|
||||
.Done()
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http.Headers;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
@@ -10,11 +9,11 @@ using Umbraco.Core.Models.Entities;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Security;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.Common.TestHelpers.Entities;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
using Umbraco.Web.Actions;
|
||||
using Umbraco.Web.BackOffice.Filters;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.Security;
|
||||
|
||||
namespace Umbraco.Tests.Web.Controllers
|
||||
{
|
||||
@@ -78,10 +77,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
[Test]
|
||||
public void Filter_On_Start_Node()
|
||||
{
|
||||
var userMock = MockedUser.GetUserMock();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.StartContentIds).Returns(new[] { 5 });
|
||||
var user = userMock.Object;
|
||||
var user = CreateUser(id: 9, startContentId: 5);
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
var userService = userServiceMock.Object;
|
||||
var entityServiceMock = new Mock<IEntityService>();
|
||||
@@ -124,10 +120,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
}
|
||||
var ids = list.Select(x => (int)x.Id).ToArray();
|
||||
|
||||
var userMock = MockedUser.GetUserMock();
|
||||
userMock.Setup(u => u.Id).Returns(9);
|
||||
userMock.Setup(u => u.StartContentIds).Returns(new int[0]);
|
||||
var user = userMock.Object;
|
||||
var user = CreateUser(id: 9, startContentId: 0);
|
||||
|
||||
var userServiceMock = new Mock<IUserService>();
|
||||
//we're only assigning 3 nodes browse permissions so that is what we expect as a result
|
||||
@@ -155,6 +148,14 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
Assert.AreEqual(3, list.ElementAt(2).Id);
|
||||
}
|
||||
|
||||
private IUser CreateUser(int id = 0, int? startContentId = null)
|
||||
{
|
||||
return new UserBuilder()
|
||||
.WithId(id)
|
||||
.WithStartContentIds(startContentId.HasValue ? new[] { startContentId.Value } : new int[0])
|
||||
.Build();
|
||||
}
|
||||
|
||||
private class MyTestClass
|
||||
{
|
||||
public IEnumerable<ContentItemBasic> MyList { get; set; }
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Web.WebAssets;
|
||||
|
||||
@@ -8,8 +8,6 @@ namespace Umbraco.Tests.Web.AngularIntegration
|
||||
[TestFixture]
|
||||
public class ServerVariablesParserTests
|
||||
{
|
||||
|
||||
|
||||
[Test]
|
||||
public void Parse()
|
||||
{
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Macros;
|
||||
using Umbraco.Web.Macros;
|
||||
|
||||
namespace Umbraco.Tests.Macros
|
||||
@@ -1,75 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
{
|
||||
[TestFixture]
|
||||
[Apartment(ApartmentState.STA)]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
||||
public class FileServiceTests : TestWithSomeContentBase
|
||||
{
|
||||
[Test]
|
||||
public void Create_Template_Then_Assign_Child()
|
||||
{
|
||||
var child = ServiceContext.FileService.CreateTemplateWithIdentity("Child", "child", "test");
|
||||
var parent = ServiceContext.FileService.CreateTemplateWithIdentity("Parent", "parent", "test");
|
||||
|
||||
child.SetMasterTemplate(parent);
|
||||
ServiceContext.FileService.SaveTemplate(child);
|
||||
|
||||
child = ServiceContext.FileService.GetTemplate(child.Id);
|
||||
|
||||
Assert.AreEqual(parent.Alias, child.MasterTemplateAlias);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Create_Template_With_Child_Then_Unassign()
|
||||
{
|
||||
var parent = ServiceContext.FileService.CreateTemplateWithIdentity("Parent", "parent", "test");
|
||||
var child = ServiceContext.FileService.CreateTemplateWithIdentity("Child", "child", "test", parent);
|
||||
|
||||
child.SetMasterTemplate(null);
|
||||
ServiceContext.FileService.SaveTemplate(child);
|
||||
|
||||
child = ServiceContext.FileService.GetTemplate(child.Id);
|
||||
|
||||
Assert.AreEqual(null, child.MasterTemplateAlias);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Query_Template_Children()
|
||||
{
|
||||
var parent = ServiceContext.FileService.CreateTemplateWithIdentity("Parent", "parent", "test");
|
||||
var child1 = ServiceContext.FileService.CreateTemplateWithIdentity("Child1", "child1", "test", parent);
|
||||
var child2 = ServiceContext.FileService.CreateTemplateWithIdentity("Child2", "child2", "test", parent);
|
||||
|
||||
var children = ServiceContext.FileService.GetTemplates(parent.Id).Select(x => x.Id).ToArray();
|
||||
|
||||
Assert.IsTrue(children.Contains(child1.Id));
|
||||
Assert.IsTrue(children.Contains(child2.Id));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Create_Template_With_Custom_Alias()
|
||||
{
|
||||
var template = ServiceContext.FileService.CreateTemplateWithIdentity("Test template", "customTemplateAlias", "test");
|
||||
|
||||
ServiceContext.FileService.SaveTemplate(template);
|
||||
|
||||
template = ServiceContext.FileService.GetTemplate(template.Id);
|
||||
|
||||
Assert.AreEqual("Test template", template.Name);
|
||||
Assert.AreEqual("customTemplateAlias", template.Alias);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
using System.IO;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Models.Packaging;
|
||||
using Umbraco.Core.Services.Implement;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
{
|
||||
[TestFixture]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
||||
public class PackagingServiceTests : TestWithSomeContentBase
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -152,7 +152,6 @@
|
||||
<Compile Include="Scoping\ScopeEventDispatcherTests.cs" />
|
||||
<Compile Include="Security\BackOfficeOwinUserManagerTests.cs" />
|
||||
<Compile Include="Security\OwinDataProtectorTokenProviderTests.cs" />
|
||||
<Compile Include="Services\KeyValueServiceTests.cs" />
|
||||
<Compile Include="Persistence\Repositories\UserRepositoryTest.cs" />
|
||||
<Compile Include="TestHelpers\Entities\MockedEntity.cs" />
|
||||
<Compile Include="TestHelpers\Entities\MockedPropertyTypes.cs" />
|
||||
@@ -166,23 +165,17 @@
|
||||
<Compile Include="Routing\RoutableDocumentFilterTests.cs" />
|
||||
<Compile Include="Runtimes\StandaloneTests.cs" />
|
||||
<Compile Include="Routing\GetContentUrlsTests.cs" />
|
||||
<Compile Include="Services\AmbiguousEventTests.cs" />
|
||||
<Compile Include="Services\ContentServiceEventTests.cs" />
|
||||
<Compile Include="Services\ContentServicePublishBranchTests.cs" />
|
||||
<Compile Include="Services\ContentServiceTagsTests.cs" />
|
||||
<Compile Include="Services\ContentTypeServiceVariantsTests.cs" />
|
||||
<Compile Include="Services\EntityXmlSerializerTests.cs" />
|
||||
<Compile Include="Packaging\CreatedPackagesRepositoryTests.cs" />
|
||||
<Compile Include="Services\MemberGroupServiceTests.cs" />
|
||||
<Compile Include="Services\MediaTypeServiceTests.cs" />
|
||||
<Compile Include="Services\PropertyValidationServiceTests.cs" />
|
||||
<Compile Include="TestHelpers\RandomIdRamDirectory.cs" />
|
||||
<Compile Include="TestHelpers\Stubs\TestUserPasswordConfig.cs" />
|
||||
<Compile Include="Testing\Objects\TestDataSource.cs" />
|
||||
<Compile Include="Issues\U9560.cs" />
|
||||
<Compile Include="Integration\ContentEventsTests.cs" />
|
||||
<Compile Include="Migrations\AdvancedMigrationTests.cs" />
|
||||
<Compile Include="Packaging\PackageExtractionTests.cs" />
|
||||
<Compile Include="Persistence\NPocoTests\NPocoFetchTests.cs" />
|
||||
<Compile Include="Persistence\NPocoTests\NPocoSqlTemplateTests.cs" />
|
||||
<Compile Include="Routing\ContentFinderByUrlAndTemplateTests.cs" />
|
||||
@@ -198,8 +191,6 @@
|
||||
<Compile Include="Scoping\ScopeFileSystemsTests.cs" />
|
||||
<Compile Include="Scoping\ScopedNuCacheTests.cs" />
|
||||
<Compile Include="Scoping\ScopeTests.cs" />
|
||||
<Compile Include="Services\CachedDataTypeServiceTests.cs" />
|
||||
<Compile Include="Services\ConsentServiceTests.cs" />
|
||||
<Compile Include="TestHelpers\ControllerTesting\AuthenticateEverythingExtensions.cs" />
|
||||
<Compile Include="TestHelpers\ControllerTesting\AuthenticateEverythingMiddleware.cs" />
|
||||
<Compile Include="TestHelpers\ControllerTesting\SpecificAssemblyResolver.cs" />
|
||||
@@ -222,9 +213,6 @@
|
||||
<Compile Include="TestHelpers\TestObjects.cs" />
|
||||
<Compile Include="UmbracoExamine\RandomIdRamDirectory.cs" />
|
||||
<Compile Include="Web\AngularIntegration\AngularAntiForgeryTests.cs" />
|
||||
<Compile Include="Web\AngularIntegration\ContentModelSerializationTests.cs" />
|
||||
<Compile Include="Web\AngularIntegration\JsInitializationTests.cs" />
|
||||
<Compile Include="Web\AngularIntegration\ServerVariablesParserTests.cs" />
|
||||
<Compile Include="Migrations\Stubs\DropForeignKeyMigrationStub.cs" />
|
||||
<Compile Include="Cache\DeepCloneAppCacheTests.cs" />
|
||||
<Compile Include="Cache\DefaultCachePolicyTests.cs" />
|
||||
@@ -241,7 +229,6 @@
|
||||
<Compile Include="Persistence\Repositories\PublicAccessRepositoryTest.cs" />
|
||||
<Compile Include="Routing\RoutesCacheTests.cs" />
|
||||
<Compile Include="Routing\UrlRoutingTestBase.cs" />
|
||||
<Compile Include="Services\ContentTypeServiceExtensionsTests.cs" />
|
||||
<Compile Include="Web\Mvc\RenderNoContentControllerTests.cs" />
|
||||
<Compile Include="Web\Mvc\ValidateUmbracoFormRouteStringAttributeTests.cs" />
|
||||
<Compile Include="Web\PublishedContentQueryTests.cs" />
|
||||
@@ -264,7 +251,6 @@
|
||||
<Compile Include="Cache\AppCacheTests.cs" />
|
||||
<Compile Include="Cache\HttpRequestAppCacheTests.cs" />
|
||||
<Compile Include="Cache\RuntimeAppCacheTests.cs" />
|
||||
<Compile Include="Macros\MacroParserTests.cs" />
|
||||
<Compile Include="Models\ContentExtensionsTests.cs" />
|
||||
<Compile Include="Web\Mvc\MergeParentContextViewDataAttributeTests.cs" />
|
||||
<Compile Include="Web\Mvc\ViewDataDictionaryExtensionTests.cs" />
|
||||
@@ -277,15 +263,11 @@
|
||||
<Compile Include="PublishedContent\PublishedRouterTests.cs" />
|
||||
<Compile Include="PublishedContent\RootNodeTests.cs" />
|
||||
<Compile Include="Scheduling\BackgroundTaskRunnerTests.cs" />
|
||||
<Compile Include="Services\FileServiceTests.cs" />
|
||||
<Compile Include="Services\LocalizedTextServiceTests.cs" />
|
||||
<Compile Include="Services\MemberServiceTests.cs" />
|
||||
<Compile Include="Services\MemberTypeServiceTests.cs" />
|
||||
<Compile Include="Packaging\PackageInstallationTest.cs" />
|
||||
<Compile Include="Services\PackagingServiceTests.cs" />
|
||||
<Compile Include="Services\PerformanceTests.cs" />
|
||||
<Compile Include="Services\RelationServiceTests.cs" />
|
||||
<Compile Include="Services\MacroServiceTests.cs" />
|
||||
<Compile Include="Cache\PublishedCache\PublishedMediaCacheTests.cs" />
|
||||
<Compile Include="Migrations\AlterMigrationTests.cs" />
|
||||
<Compile Include="Migrations\SqlScripts\SqlResources.Designer.cs">
|
||||
@@ -345,8 +327,6 @@
|
||||
<Compile Include="Services\ContentServicePerformanceTest.cs" />
|
||||
<Compile Include="Services\ContentServiceTests.cs" />
|
||||
<Compile Include="Services\ContentTypeServiceTests.cs" />
|
||||
<Compile Include="Services\DataTypeServiceTests.cs" />
|
||||
<Compile Include="Services\EntityServiceTests.cs" />
|
||||
<Compile Include="Packaging\PackageDataInstallationTests.cs" />
|
||||
<Compile Include="Services\Importing\ImportResources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
|
||||
@@ -96,7 +96,6 @@ namespace Umbraco.Web
|
||||
if (currentUmbracoContext != null)
|
||||
return new UmbracoContextReference(currentUmbracoContext, false, _umbracoContextAccessor);
|
||||
|
||||
|
||||
var umbracoContext = CreateUmbracoContext();
|
||||
_umbracoContextAccessor.UmbracoContext = umbracoContext;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user