Merge remote-tracking branch 'origin/v10/dev' into v11/dev
# Conflicts: # src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Configuration.cs # src/Umbraco.Core/Models/Mapping/DictionaryMapDefinition.cs # src/Umbraco.Web.BackOffice/Install/InstallApiController.cs # version.json
This commit is contained in:
@@ -0,0 +1,195 @@
|
||||
/// <reference types="Cypress" />
|
||||
|
||||
import {MediaBuilder} from 'umbraco-cypress-testhelpers';
|
||||
|
||||
context('Media', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
cy.umbracoLogin(Cypress.env('username'), Cypress.env('password'));
|
||||
cy.umbracoSection("media");
|
||||
});
|
||||
|
||||
function refreshMediaTree() {
|
||||
// Refresh to update the tree
|
||||
cy.get('li .umb-tree-root:contains("Media")').should("be.visible").rightclick();
|
||||
//Needs to wait or it can give an error
|
||||
cy.wait(1000);
|
||||
cy.get(".umb-outline").contains("Reload").click();
|
||||
}
|
||||
|
||||
it('Create folder', () => {
|
||||
const folderName = 'Media Folder';
|
||||
//Ensures that there is not already an existing folder with the same name
|
||||
cy.umbracoEnsureMediaNameNotExists(folderName);
|
||||
|
||||
//Action
|
||||
//Creates folder
|
||||
cy.get(".dropdown-toggle").contains("Create").click({force: true});
|
||||
cy.get('[role="menuitem"]').contains("Folder").click({force: true});
|
||||
cy.get('[data-element="editor-name-field"]').type(folderName);
|
||||
cy.umbracoButtonByLabelKey("buttons_save").click();
|
||||
|
||||
//Assert
|
||||
cy.umbracoSuccessNotification().should("be.visible");
|
||||
|
||||
//Cleans up
|
||||
cy.umbracoEnsureMediaNameNotExists(folderName);
|
||||
});
|
||||
|
||||
it('Create folder inside of folder', () => {
|
||||
const folderName = 'Folder';
|
||||
const insideFolderName = 'Folder in folder';
|
||||
//Ensures that there is not already existing folders with the same names
|
||||
cy.umbracoEnsureMediaNameNotExists(folderName);
|
||||
cy.umbracoEnsureMediaNameNotExists(insideFolderName);
|
||||
|
||||
//Action
|
||||
//Creates the first folder with an API call
|
||||
const mediaFolder = new MediaBuilder()
|
||||
.withName(folderName)
|
||||
.withContentTypeAlias('Folder')
|
||||
.build()
|
||||
cy.saveMedia(mediaFolder, null);
|
||||
//Creates second folder
|
||||
refreshMediaTree();
|
||||
cy.umbracoTreeItem('media', [folderName]).click();
|
||||
cy.get(".dropdown-toggle").contains("Create").click({force: true});
|
||||
cy.get('[role="menuitem"]').contains("Folder").click({force: true});
|
||||
cy.get('[data-element="editor-name-field"]').type(insideFolderName);
|
||||
cy.umbracoButtonByLabelKey("buttons_save").click();
|
||||
|
||||
//Assert
|
||||
cy.umbracoSuccessNotification().should("be.visible");
|
||||
|
||||
//Cleans up
|
||||
cy.umbracoEnsureMediaNameNotExists(folderName);
|
||||
cy.umbracoEnsureMediaNameNotExists(insideFolderName);
|
||||
});
|
||||
|
||||
it('Create image', () => {
|
||||
const imageName = 'ImageTest';
|
||||
//Ensures that there is not already an existing image with the name
|
||||
cy.umbracoEnsureMediaNameNotExists(imageName);
|
||||
const umbracoFileValue = {"src": "Umbraco.png,"}
|
||||
|
||||
//Action
|
||||
const mediaImage = new MediaBuilder()
|
||||
.withName(imageName)
|
||||
.withContentTypeAlias('Image')
|
||||
.addProperty()
|
||||
.withAlias("umbracoFile")
|
||||
.withValue(umbracoFileValue)
|
||||
.done()
|
||||
.build()
|
||||
const blob = Cypress.Blob.base64StringToBlob("iVBORw0KGgoAAAANSUhEUgAAADcAAAAjCAYAAAAwnJLLAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAGpSURBVFhH7ZRNq0FRFIbPbzD3A/wKSUkZmCgzAyUpkhhRyMT8TIwlEylDI2WgJMyMmJAB+SqS5OvVXjY599ad3eyt/dRpnbXW7rSf1upo+GKUnKwoOVlRcrKi5GRFycmKkpMVJScrSk5WhJDr9/uIRqPYbDa8Aux2O2QyGVitVjidTrTbbd55cLvdUKlUUCgUcDqdeNXIR+XYBev1OtxuNzweD1ar1auu6zrK5TK9j8dj+P1+LJdL6jOazSZisRj2+z2v/OajcuxitVoNk8kEwWDQIMdqh8OBcjbFcDiM0WhE+Xw+RyKRoPgXQqwlk3qX+0m320UymcTxeKQnHo/D4XDA5XIhn89jvV7zk0aEl2MrydbvOaVerwefz4fZbIbr9YpqtYp0Oo3L5UL9d4SWY2KRSITik1arhWKxyDNgOp0ilUq9VvgdYeWYUCgUwnA45JUHg8EA2WwW5/OZ8kajgVwuJ+bk2F/RZrPBbDZTZPl2u4XX64XFYoHJZIKmaRQ7nQ5JlEol2O12Oh8IBLBYLPjXjAgxuf9CycmKkpMVJScrSk5WvlgOuANsVZDROrcwfgAAAABJRU5ErkJggg==");
|
||||
const testFile = new File([blob], "test.jpg");
|
||||
cy.saveMedia(mediaImage, testFile);
|
||||
refreshMediaTree();
|
||||
|
||||
//Assert
|
||||
cy.get('[data-element="tree-item-ImageTest"]').should("be.visible");
|
||||
|
||||
//Cleans up
|
||||
cy.umbracoEnsureMediaNameNotExists(imageName);
|
||||
});
|
||||
|
||||
it('Create SVG', () => {
|
||||
const svgName = 'svgTest';
|
||||
//Ensures that there is not already an existing SVG with the name
|
||||
cy.umbracoEnsureMediaNameNotExists(svgName);
|
||||
|
||||
//Action
|
||||
const mediaSVG = new MediaBuilder()
|
||||
.withName(svgName)
|
||||
.withContentTypeAlias('umbracoMediaVectorGraphics')
|
||||
.build()
|
||||
cy.saveMedia(mediaSVG, null);
|
||||
refreshMediaTree();
|
||||
|
||||
//Assert
|
||||
cy.get('[data-element="tree-item-svgTest"]').should("be.visible");
|
||||
|
||||
//Cleans up
|
||||
cy.umbracoEnsureMediaNameNotExists(svgName);
|
||||
});
|
||||
|
||||
it('Create Audio', () => {
|
||||
const audioName = 'audioTest';
|
||||
//Ensures that there is not already an existing audio with the name
|
||||
cy.umbracoEnsureMediaNameNotExists(audioName);
|
||||
|
||||
//Action
|
||||
const mediaAudio = new MediaBuilder()
|
||||
.withName(audioName)
|
||||
.withContentTypeAlias('umbracoMediaAudio')
|
||||
.build()
|
||||
cy.saveMedia(mediaAudio, null);
|
||||
refreshMediaTree();
|
||||
|
||||
//Assert
|
||||
cy.get('[data-element="tree-item-audioTest"]').should("be.visible");
|
||||
|
||||
//Cleans up
|
||||
cy.umbracoEnsureMediaNameNotExists(audioName);
|
||||
});
|
||||
|
||||
it('Create File', () => {
|
||||
const fileName = 'fileTest';
|
||||
//Ensures that there is not already an existing file with the name
|
||||
cy.umbracoEnsureMediaNameNotExists(fileName);
|
||||
|
||||
//Action
|
||||
const mediaFile = new MediaBuilder()
|
||||
.withName(fileName)
|
||||
.withContentTypeAlias('File')
|
||||
.build()
|
||||
cy.saveMedia(mediaFile, null);
|
||||
refreshMediaTree();
|
||||
|
||||
//Assert
|
||||
cy.get('[data-element="tree-item-fileTest"]').should("be.visible");
|
||||
|
||||
//Cleans up
|
||||
cy.umbracoEnsureMediaNameNotExists(fileName);
|
||||
});
|
||||
|
||||
it('Create Video', () => {
|
||||
const videoName = 'videoTest';
|
||||
//Ensures that there is not already an existing video with the name
|
||||
cy.umbracoEnsureMediaNameNotExists(videoName);
|
||||
|
||||
//Action
|
||||
const mediaVideo = new MediaBuilder()
|
||||
.withName(videoName)
|
||||
.withContentTypeAlias('umbracoMediaVideo')
|
||||
.build()
|
||||
cy.saveMedia(mediaVideo, null);
|
||||
refreshMediaTree();
|
||||
|
||||
//Assert
|
||||
cy.get('[data-element="tree-item-videoTest"]').should("be.visible");
|
||||
|
||||
//Cleans up
|
||||
cy.umbracoEnsureMediaNameNotExists(videoName);
|
||||
});
|
||||
|
||||
it('Create Article', () => {
|
||||
const articleName = 'articleTest';
|
||||
//Ensures that there is not already an existing article with the name
|
||||
cy.umbracoEnsureMediaNameNotExists(articleName);
|
||||
|
||||
//Action
|
||||
const mediaArticle = new MediaBuilder()
|
||||
.withName(articleName)
|
||||
.withContentTypeAlias('umbracoMediaArticle')
|
||||
.build()
|
||||
cy.saveMedia(mediaArticle, null);
|
||||
refreshMediaTree();
|
||||
|
||||
//Assert
|
||||
cy.get('[data-element="tree-item-articleTest"]').should("be.visible");
|
||||
|
||||
//Cleans up
|
||||
cy.umbracoEnsureMediaNameNotExists(articleName);
|
||||
});
|
||||
});
|
||||
@@ -214,9 +214,9 @@ import {
|
||||
cy.get('.umb-group-builder__tab-sort-order > .umb-property-editor-tiny').first().type('3');
|
||||
cy.get('[alias="reorder"]').click();
|
||||
//Assert
|
||||
cy.get('.umb-group-builder__group-title-input').eq(0).invoke('attr', 'title').should('eq', 'aTab 2')
|
||||
cy.get('.umb-group-builder__group-title-input').eq(1).invoke('attr', 'title').should('eq', 'aTab 3')
|
||||
cy.get('.umb-group-builder__group-title-input').eq(2).invoke('attr', 'title').should('eq', 'aTab 1')
|
||||
cy.get('.umb-group-builder__tab-name').eq(0).invoke('attr', 'title').should('eq', 'aTab 2')
|
||||
cy.get('.umb-group-builder__tab-name').eq(1).invoke('attr', 'title').should('eq', 'aTab 3')
|
||||
cy.get('.umb-group-builder__group-title-input').eq(0).invoke('attr', 'title').should('eq', 'aTab 1')
|
||||
});
|
||||
|
||||
it('Reorders groups in a tab', () => {
|
||||
|
||||
14
tests/Umbraco.Tests.AcceptanceTest/package-lock.json
generated
14
tests/Umbraco.Tests.AcceptanceTest/package-lock.json
generated
@@ -16,7 +16,7 @@
|
||||
"del": "^6.0.0",
|
||||
"ncp": "^2.0.0",
|
||||
"prompt": "^1.2.0",
|
||||
"umbraco-cypress-testhelpers": "^1.0.0-beta-69"
|
||||
"umbraco-cypress-testhelpers": "^1.0.0-beta-73"
|
||||
}
|
||||
},
|
||||
"node_modules/@cypress/request": {
|
||||
@@ -2176,9 +2176,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/umbraco-cypress-testhelpers": {
|
||||
"version": "1.0.0-beta-69",
|
||||
"resolved": "https://registry.npmjs.org/umbraco-cypress-testhelpers/-/umbraco-cypress-testhelpers-1.0.0-beta-69.tgz",
|
||||
"integrity": "sha512-2IM+C2XtmiA3txyWatZxgKuNxLdcKLGKICPf0ZqYbOrPeSxTiIPAM9tuoh3heDP6/CdtUnvpaiTUl1c8O6A5Fw==",
|
||||
"version": "1.0.0-beta-73",
|
||||
"resolved": "https://registry.npmjs.org/umbraco-cypress-testhelpers/-/umbraco-cypress-testhelpers-1.0.0-beta-73.tgz",
|
||||
"integrity": "sha512-VZy7QFjY5o1oTWdpYGb9xrwr4qUw5BcbEwz0GYZexiKCr+Vqq3MllmLMWfkRl4/9O/tbu+ggKx3OZ49GRAGUyg==",
|
||||
"dev": true,
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
@@ -3964,9 +3964,9 @@
|
||||
"integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q=="
|
||||
},
|
||||
"umbraco-cypress-testhelpers": {
|
||||
"version": "1.0.0-beta-69",
|
||||
"resolved": "https://registry.npmjs.org/umbraco-cypress-testhelpers/-/umbraco-cypress-testhelpers-1.0.0-beta-69.tgz",
|
||||
"integrity": "sha512-2IM+C2XtmiA3txyWatZxgKuNxLdcKLGKICPf0ZqYbOrPeSxTiIPAM9tuoh3heDP6/CdtUnvpaiTUl1c8O6A5Fw==",
|
||||
"version": "1.0.0-beta-73",
|
||||
"resolved": "https://registry.npmjs.org/umbraco-cypress-testhelpers/-/umbraco-cypress-testhelpers-1.0.0-beta-73.tgz",
|
||||
"integrity": "sha512-VZy7QFjY5o1oTWdpYGb9xrwr4qUw5BcbEwz0GYZexiKCr+Vqq3MllmLMWfkRl4/9O/tbu+ggKx3OZ49GRAGUyg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"camelize": "^1.0.0",
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
"del": "^6.0.0",
|
||||
"ncp": "^2.0.0",
|
||||
"prompt": "^1.2.0",
|
||||
"umbraco-cypress-testhelpers": "^1.0.0-beta-69"
|
||||
"umbraco-cypress-testhelpers": "^1.0.0-beta-73"
|
||||
},
|
||||
"dependencies": {
|
||||
"typescript": "^3.9.2"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
@@ -104,7 +105,7 @@ public abstract class UmbracoIntegrationTest : UmbracoIntegrationTestBase
|
||||
context.HostingEnvironment = TestHelper.GetWebHostEnvironment();
|
||||
configBuilder.Sources.Clear();
|
||||
configBuilder.AddInMemoryCollection(InMemoryConfiguration);
|
||||
configBuilder.AddConfiguration(GlobalSetupTeardown.TestConfiguration);
|
||||
SetUpTestConfiguration(configBuilder);
|
||||
|
||||
Configuration = configBuilder.Build();
|
||||
})
|
||||
@@ -193,4 +194,12 @@ public abstract class UmbracoIntegrationTest : UmbracoIntegrationTestBase
|
||||
}
|
||||
|
||||
protected virtual T GetRequiredService<T>() => Services.GetRequiredService<T>();
|
||||
|
||||
protected virtual void SetUpTestConfiguration(IConfigurationBuilder configBuilder)
|
||||
{
|
||||
if (GlobalSetupTeardown.TestConfiguration is not null)
|
||||
{
|
||||
configBuilder.AddConfiguration(GlobalSetupTeardown.TestConfiguration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.ManagementApi.Filters;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Cms.ManagementApi.Filters;
|
||||
|
||||
[TestFixture]
|
||||
public class RequireRuntimeLevelAttributeTest
|
||||
{
|
||||
[Test]
|
||||
[TestCase(RuntimeLevel.Install, RuntimeLevel.Run, true)]
|
||||
[TestCase(RuntimeLevel.Install, RuntimeLevel.Unknown, true)]
|
||||
[TestCase(RuntimeLevel.Install, RuntimeLevel.Boot, true)]
|
||||
[TestCase(RuntimeLevel.Install, RuntimeLevel.Upgrade, true)]
|
||||
[TestCase(RuntimeLevel.Run, RuntimeLevel.Upgrade, true)]
|
||||
[TestCase(RuntimeLevel.Install, RuntimeLevel.Install, false)]
|
||||
[TestCase(RuntimeLevel.Upgrade, RuntimeLevel.Upgrade, false)]
|
||||
public void BlocksWhenIncorrectRuntime(RuntimeLevel requiredLevel, RuntimeLevel actualLevel, bool shouldFail)
|
||||
{
|
||||
var executionContext = CreateActionExecutingContext(actualLevel);
|
||||
|
||||
var sut = new RequireRuntimeLevelAttribute(requiredLevel);
|
||||
sut.OnActionExecuting(executionContext);
|
||||
|
||||
if (shouldFail)
|
||||
{
|
||||
AssertFailure(executionContext);
|
||||
return;
|
||||
}
|
||||
|
||||
// Assert success, result being null == we haven't short circuited.
|
||||
Assert.IsNull(executionContext.Result);
|
||||
}
|
||||
|
||||
private void AssertFailure(ActionExecutingContext executionContext)
|
||||
{
|
||||
var result = executionContext.Result;
|
||||
Assert.IsInstanceOf<ObjectResult>(result);
|
||||
|
||||
var objectResult = (ObjectResult)result;
|
||||
|
||||
Assert.AreEqual(StatusCodes.Status428PreconditionRequired, objectResult?.StatusCode);
|
||||
Assert.IsInstanceOf<ProblemDetails>(objectResult?.Value);
|
||||
}
|
||||
|
||||
private ActionExecutingContext CreateActionExecutingContext(RuntimeLevel targetRuntimeLevel)
|
||||
{
|
||||
var actionContext = new ActionContext()
|
||||
{
|
||||
HttpContext = new DefaultHttpContext(),
|
||||
RouteData = new RouteData(),
|
||||
ActionDescriptor = new ActionDescriptor()
|
||||
};
|
||||
|
||||
var executingContext = new ActionExecutingContext(
|
||||
actionContext,
|
||||
new List<IFilterMetadata>(),
|
||||
new Dictionary<string, object>(),
|
||||
new());
|
||||
|
||||
var fakeRuntime = new Mock<IRuntimeState>();
|
||||
fakeRuntime.Setup(x => x.Level).Returns(targetRuntimeLevel);
|
||||
|
||||
var fakeServiceProvider = new Mock<IServiceProvider>();
|
||||
fakeServiceProvider.Setup(x => x.GetService(typeof(IRuntimeState))).Returns(fakeRuntime.Object);
|
||||
actionContext.HttpContext.RequestServices = fakeServiceProvider.Object;
|
||||
|
||||
return executingContext;
|
||||
}
|
||||
}
|
||||
@@ -24,10 +24,10 @@ public class DistributedCacheTests
|
||||
|
||||
var cacheRefresherCollection = new CacheRefresherCollection(() => new[] { new TestCacheRefresher() });
|
||||
|
||||
_distributedCache = new Cms.Core.Cache.DistributedCache(ServerMessenger, cacheRefresherCollection);
|
||||
_distributedCache = new global::Umbraco.Cms.Core.Cache.DistributedCache(ServerMessenger, cacheRefresherCollection);
|
||||
}
|
||||
|
||||
private Cms.Core.Cache.DistributedCache _distributedCache;
|
||||
private global::Umbraco.Cms.Core.Cache.DistributedCache _distributedCache;
|
||||
|
||||
private IServerRoleAccessor ServerRegistrar { get; set; }
|
||||
|
||||
|
||||
@@ -13,24 +13,25 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Models;
|
||||
[TestFixture]
|
||||
public class CultureImpactTests
|
||||
{
|
||||
private CultureImpactFactory BasicImpactFactory => createCultureImpactService();
|
||||
private CultureImpactFactory BasicImpactFactory => createCultureImpactService();
|
||||
|
||||
[Test]
|
||||
public void Get_Culture_For_Invariant_Errors()
|
||||
{
|
||||
var result = BasicImpactFactory.GetCultureForInvariantErrors(
|
||||
var result = BasicImpactFactory.GetCultureForInvariantErrors(
|
||||
Mock.Of<IContent>(x => x.Published == true),
|
||||
new[] { "en-US", "fr-FR" },
|
||||
"en-US");
|
||||
Assert.AreEqual("en-US", result); // default culture is being saved so use it
|
||||
|
||||
result = BasicImpactFactory.GetCultureForInvariantErrors(
|
||||
result = BasicImpactFactory.GetCultureForInvariantErrors(
|
||||
Mock.Of<IContent>(x => x.Published == false),
|
||||
new[] { "fr-FR" },
|
||||
"en-US");
|
||||
Assert.AreEqual("fr-FR", result); // default culture not being saved with not published version, use the first culture being saved
|
||||
Assert.AreEqual("fr-FR",
|
||||
result); // default culture not being saved with not published version, use the first culture being saved
|
||||
|
||||
result = BasicImpactFactory.GetCultureForInvariantErrors(
|
||||
result = BasicImpactFactory.GetCultureForInvariantErrors(
|
||||
Mock.Of<IContent>(x => x.Published == true),
|
||||
new[] { "fr-FR" },
|
||||
"en-US");
|
||||
@@ -70,7 +71,7 @@ public class CultureImpactTests
|
||||
[Test]
|
||||
public void Explicit_Default_Culture()
|
||||
{
|
||||
var impact = BasicImpactFactory.ImpactExplicit("en-US", true);
|
||||
var impact = BasicImpactFactory.ImpactExplicit("en-US", true);
|
||||
|
||||
Assert.AreEqual(impact.Culture, "en-US");
|
||||
|
||||
@@ -85,7 +86,7 @@ public class CultureImpactTests
|
||||
[Test]
|
||||
public void Explicit_NonDefault_Culture()
|
||||
{
|
||||
var impact = BasicImpactFactory.ImpactExplicit("en-US", false);
|
||||
var impact = BasicImpactFactory.ImpactExplicit("en-US", false);
|
||||
|
||||
Assert.AreEqual(impact.Culture, "en-US");
|
||||
|
||||
@@ -100,10 +101,11 @@ public class CultureImpactTests
|
||||
[Test]
|
||||
public void TryCreate_Explicit_Default_Culture()
|
||||
{
|
||||
var success = BasicImpactFactory.TryCreate("en-US", true, ContentVariation.Culture, false, false, out var impact);
|
||||
var success =
|
||||
BasicImpactFactory.TryCreate("en-US", true, ContentVariation.Culture, false, false, out var impact);
|
||||
Assert.IsTrue(success);
|
||||
|
||||
Assert.IsNotNull(impact);
|
||||
Assert.IsNotNull(impact);
|
||||
Assert.AreEqual(impact.Culture, "en-US");
|
||||
|
||||
Assert.IsTrue(impact.ImpactsInvariantProperties);
|
||||
@@ -117,10 +119,11 @@ public class CultureImpactTests
|
||||
[Test]
|
||||
public void TryCreate_Explicit_NonDefault_Culture()
|
||||
{
|
||||
var success = BasicImpactFactory.TryCreate("en-US", false, ContentVariation.Culture, false, false, out var impact);
|
||||
var success =
|
||||
BasicImpactFactory.TryCreate("en-US", false, ContentVariation.Culture, false, false, out var impact);
|
||||
Assert.IsTrue(success);
|
||||
|
||||
Assert.IsNotNull(impact);
|
||||
Assert.IsNotNull(impact);
|
||||
Assert.AreEqual(impact.Culture, "en-US");
|
||||
|
||||
Assert.IsFalse(impact.ImpactsInvariantProperties);
|
||||
@@ -137,10 +140,10 @@ public class CultureImpactTests
|
||||
var success = BasicImpactFactory.TryCreate("*", false, ContentVariation.Nothing, false, false, out var impact);
|
||||
Assert.IsTrue(success);
|
||||
|
||||
Assert.IsNotNull(impact);
|
||||
Assert.IsNotNull(impact);
|
||||
Assert.AreEqual(impact.Culture, null);
|
||||
|
||||
Assert.AreSame(BasicImpactFactory.ImpactInvariant(), impact);
|
||||
Assert.AreSame(BasicImpactFactory.ImpactInvariant(), impact);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -149,10 +152,10 @@ public class CultureImpactTests
|
||||
var success = BasicImpactFactory.TryCreate("*", false, ContentVariation.Culture, false, false, out var impact);
|
||||
Assert.IsTrue(success);
|
||||
|
||||
Assert.IsNotNull(impact);
|
||||
Assert.IsNotNull(impact);
|
||||
Assert.AreEqual(impact.Culture, "*");
|
||||
|
||||
Assert.AreSame(BasicImpactFactory.ImpactAll(), impact);
|
||||
Assert.AreSame(BasicImpactFactory.ImpactAll(), impact);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -168,28 +171,27 @@ public class CultureImpactTests
|
||||
var success = BasicImpactFactory.TryCreate(null, false, ContentVariation.Nothing, false, false, out var impact);
|
||||
Assert.IsTrue(success);
|
||||
|
||||
Assert.AreSame(BasicImpactFactory.ImpactInvariant(), impact);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCase(true)]
|
||||
[TestCase(false)]
|
||||
public void Edit_Invariant_From_Non_Default_Impacts_Invariant_Properties(bool allowEditInvariantFromNonDefault)
|
||||
{
|
||||
var sut = createCultureImpactService(new SecuritySettings { AllowEditInvariantFromNonDefault = allowEditInvariantFromNonDefault });
|
||||
var impact = sut.ImpactExplicit("da", false);
|
||||
|
||||
Assert.AreEqual(allowEditInvariantFromNonDefault, impact.ImpactsAlsoInvariantProperties);
|
||||
Assert.AreSame(BasicImpactFactory.ImpactInvariant(), impact);
|
||||
}
|
||||
|
||||
private CultureImpactFactory createCultureImpactService(SecuritySettings securitySettings = null)
|
||||
[Test]
|
||||
[TestCase(true)]
|
||||
[TestCase(false)]
|
||||
public void Edit_Invariant_From_Non_Default_Impacts_Invariant_Properties(bool allowEditInvariantFromNonDefault)
|
||||
{
|
||||
var sut = createCultureImpactService(new ContentSettings
|
||||
{
|
||||
securitySettings ??= new SecuritySettings
|
||||
{
|
||||
AllowEditInvariantFromNonDefault = false,
|
||||
};
|
||||
AllowEditInvariantFromNonDefault = allowEditInvariantFromNonDefault
|
||||
});
|
||||
var impact = sut.ImpactExplicit("da", false);
|
||||
|
||||
return new CultureImpactFactory(new TestOptionsMonitor<SecuritySettings>(securitySettings));
|
||||
}
|
||||
Assert.AreEqual(allowEditInvariantFromNonDefault, impact.ImpactsAlsoInvariantProperties);
|
||||
}
|
||||
|
||||
private CultureImpactFactory createCultureImpactService(ContentSettings contentSettings = null)
|
||||
{
|
||||
contentSettings ??= new ContentSettings { AllowEditInvariantFromNonDefault = false, };
|
||||
|
||||
return new CultureImpactFactory(new TestOptionsMonitor<ContentSettings>(contentSettings));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core.IO;
|
||||
using Umbraco.Cms.Core.PropertyEditors;
|
||||
using Umbraco.Cms.Core.Serialization;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Strings;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.PropertyEditors;
|
||||
|
||||
[TestFixture]
|
||||
public class DataValueEditorReuseTests
|
||||
{
|
||||
private Mock<IDataValueEditorFactory> _dataValueEditorFactoryMock;
|
||||
private PropertyEditorCollection _propertyEditorCollection;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_dataValueEditorFactoryMock = new Mock<IDataValueEditorFactory>();
|
||||
|
||||
_dataValueEditorFactoryMock
|
||||
.Setup(m => m.Create<TextOnlyValueEditor>(It.IsAny<DataEditorAttribute>()))
|
||||
.Returns(() => new TextOnlyValueEditor(
|
||||
new DataEditorAttribute("a", "b", "c"),
|
||||
Mock.Of<ILocalizedTextService>(),
|
||||
Mock.Of<IShortStringHelper>(),
|
||||
Mock.Of<IJsonSerializer>(),
|
||||
Mock.Of<IIOHelper>()));
|
||||
|
||||
_propertyEditorCollection = new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty<IDataEditor>));
|
||||
|
||||
_dataValueEditorFactoryMock
|
||||
.Setup(m =>
|
||||
m.Create<BlockEditorPropertyEditor.BlockEditorPropertyValueEditor>(It.IsAny<DataEditorAttribute>()))
|
||||
.Returns(() => new BlockEditorPropertyEditor.BlockEditorPropertyValueEditor(
|
||||
new DataEditorAttribute("a", "b", "c"),
|
||||
_propertyEditorCollection,
|
||||
Mock.Of<IDataTypeService>(),
|
||||
Mock.Of<IContentTypeService>(),
|
||||
Mock.Of<ILocalizedTextService>(),
|
||||
Mock.Of<ILogger<BlockEditorPropertyEditor.BlockEditorPropertyValueEditor>>(),
|
||||
Mock.Of<IShortStringHelper>(),
|
||||
Mock.Of<IJsonSerializer>(),
|
||||
Mock.Of<IIOHelper>(),
|
||||
Mock.Of<IPropertyValidationService>()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetValueEditor_Reusable_Value_Editor_Is_Reused_When_Created_Without_Configuration()
|
||||
{
|
||||
var textboxPropertyEditor = new TextboxPropertyEditor(
|
||||
_dataValueEditorFactoryMock.Object,
|
||||
Mock.Of<IIOHelper>(),
|
||||
Mock.Of<IEditorConfigurationParser>());
|
||||
|
||||
// textbox is set to reuse its data value editor when created *without* configuration
|
||||
var dataValueEditor1 = textboxPropertyEditor.GetValueEditor();
|
||||
Assert.NotNull(dataValueEditor1);
|
||||
var dataValueEditor2 = textboxPropertyEditor.GetValueEditor();
|
||||
Assert.NotNull(dataValueEditor2);
|
||||
Assert.AreSame(dataValueEditor1, dataValueEditor2);
|
||||
_dataValueEditorFactoryMock.Verify(
|
||||
m => m.Create<TextOnlyValueEditor>(It.IsAny<DataEditorAttribute>()),
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetValueEditor_Reusable_Value_Editor_Is_Not_Reused_When_Created_With_Configuration()
|
||||
{
|
||||
var textboxPropertyEditor = new TextboxPropertyEditor(
|
||||
_dataValueEditorFactoryMock.Object,
|
||||
Mock.Of<IIOHelper>(),
|
||||
Mock.Of<IEditorConfigurationParser>());
|
||||
|
||||
// no matter what, a property editor should never reuse its data value editor when created *with* configuration
|
||||
var dataValueEditor1 = textboxPropertyEditor.GetValueEditor("config");
|
||||
Assert.NotNull(dataValueEditor1);
|
||||
Assert.AreEqual("config", ((DataValueEditor)dataValueEditor1).Configuration);
|
||||
var dataValueEditor2 = textboxPropertyEditor.GetValueEditor("config");
|
||||
Assert.NotNull(dataValueEditor2);
|
||||
Assert.AreEqual("config", ((DataValueEditor)dataValueEditor2).Configuration);
|
||||
Assert.AreNotSame(dataValueEditor1, dataValueEditor2);
|
||||
_dataValueEditorFactoryMock.Verify(
|
||||
m => m.Create<TextOnlyValueEditor>(It.IsAny<DataEditorAttribute>()),
|
||||
Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetValueEditor_Not_Reusable_Value_Editor_Is_Not_Reused_When_Created_Without_Configuration()
|
||||
{
|
||||
var blockListPropertyEditor = new BlockListPropertyEditor(
|
||||
_dataValueEditorFactoryMock.Object,
|
||||
new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty<IDataEditor>)),
|
||||
Mock.Of<IIOHelper>(),
|
||||
Mock.Of<IEditorConfigurationParser>());
|
||||
|
||||
// block list is *not* set to reuse its data value editor
|
||||
var dataValueEditor1 = blockListPropertyEditor.GetValueEditor();
|
||||
Assert.NotNull(dataValueEditor1);
|
||||
var dataValueEditor2 = blockListPropertyEditor.GetValueEditor();
|
||||
Assert.NotNull(dataValueEditor2);
|
||||
Assert.AreNotSame(dataValueEditor1, dataValueEditor2);
|
||||
_dataValueEditorFactoryMock.Verify(
|
||||
m => m.Create<BlockEditorPropertyEditor.BlockEditorPropertyValueEditor>(It.IsAny<DataEditorAttribute>()),
|
||||
Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetValueEditor_Not_Reusable_Value_Editor_Is_Not_Reused_When_Created_With_Configuration()
|
||||
{
|
||||
var blockListPropertyEditor = new BlockListPropertyEditor(
|
||||
_dataValueEditorFactoryMock.Object,
|
||||
new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty<IDataEditor>)),
|
||||
Mock.Of<IIOHelper>(),
|
||||
Mock.Of<IEditorConfigurationParser>());
|
||||
|
||||
// no matter what, a property editor should never reuse its data value editor when created *with* configuration
|
||||
var dataValueEditor1 = blockListPropertyEditor.GetValueEditor("config");
|
||||
Assert.NotNull(dataValueEditor1);
|
||||
Assert.AreEqual("config", ((DataValueEditor)dataValueEditor1).Configuration);
|
||||
var dataValueEditor2 = blockListPropertyEditor.GetValueEditor("config");
|
||||
Assert.NotNull(dataValueEditor2);
|
||||
Assert.AreEqual("config", ((DataValueEditor)dataValueEditor2).Configuration);
|
||||
Assert.AreNotSame(dataValueEditor1, dataValueEditor2);
|
||||
_dataValueEditorFactoryMock.Verify(
|
||||
m => m.Create<BlockEditorPropertyEditor.BlockEditorPropertyValueEditor>(It.IsAny<DataEditorAttribute>()),
|
||||
Times.Exactly(2));
|
||||
}
|
||||
}
|
||||
@@ -346,7 +346,7 @@ public class DefaultShortStringHelperTestsWithoutSetup
|
||||
public void Utf8ToAsciiConverter()
|
||||
{
|
||||
const string str = "a\U00010F00z\uA74Ftéô";
|
||||
var output = Cms.Core.Strings.Utf8ToAsciiConverter.ToAsciiString(str);
|
||||
var output = global::Umbraco.Cms.Core.Strings.Utf8ToAsciiConverter.ToAsciiString(str);
|
||||
Assert.AreEqual("a?zooteo", output);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.New.Cms.Core.Installer;
|
||||
using Umbraco.New.Cms.Core.Models.Installer;
|
||||
using Umbraco.New.Cms.Core.Services.Installer;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.New.Cms.Core.Services;
|
||||
|
||||
[TestFixture]
|
||||
public class InstallServiceTests
|
||||
{
|
||||
[Test]
|
||||
public void RequiresInstallRuntimeToInstall()
|
||||
{
|
||||
var runtimeStateMock = new Mock<IRuntimeState>();
|
||||
runtimeStateMock.Setup(x => x.Level).Returns(RuntimeLevel.Run);
|
||||
var stepCollection = new NewInstallStepCollection(Enumerable.Empty<IInstallStep>);
|
||||
|
||||
var sut = new InstallService(Mock.Of<ILogger<InstallService>>(), stepCollection, runtimeStateMock.Object);
|
||||
|
||||
Assert.ThrowsAsync<InvalidOperationException>(async () => await sut.Install(new InstallData()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task OnlyRunsStepsThatRequireExecution()
|
||||
{
|
||||
var steps = new[]
|
||||
{
|
||||
new TestInstallStep { ShouldRun = true },
|
||||
new TestInstallStep { ShouldRun = false },
|
||||
new TestInstallStep { ShouldRun = true },
|
||||
};
|
||||
|
||||
var sut = CreateInstallService(steps);
|
||||
await sut.Install(new InstallData());
|
||||
|
||||
foreach (var step in steps)
|
||||
{
|
||||
Assert.AreEqual(step.ShouldRun, step.HasRun);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task StepsRunInCollectionOrder()
|
||||
{
|
||||
List<TestInstallStep> runOrder = new List<TestInstallStep>();
|
||||
|
||||
var steps = new[]
|
||||
{
|
||||
new TestInstallStep { Id = 1 },
|
||||
new TestInstallStep { Id = 2 },
|
||||
new TestInstallStep { Id = 3 },
|
||||
};
|
||||
|
||||
// Add an method delegate that will add the step itself, that way we can know the executed order.
|
||||
foreach (var step in steps)
|
||||
{
|
||||
step.AdditionalExecution = _ =>
|
||||
{
|
||||
runOrder.Add(step);
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
}
|
||||
|
||||
var sut = CreateInstallService(steps);
|
||||
await sut.Install(new InstallData());
|
||||
|
||||
// The ID's are strictly not necessary, but it makes potential debugging easier.
|
||||
var expectedRunOrder = steps.Select(x => x.Id);
|
||||
var actualRunOrder = runOrder.Select(x => x.Id);
|
||||
Assert.AreEqual(expectedRunOrder, actualRunOrder);
|
||||
}
|
||||
|
||||
private InstallService CreateInstallService(IEnumerable<IInstallStep> steps)
|
||||
{
|
||||
var logger = Mock.Of<ILogger<InstallService>>();
|
||||
var stepCollection = new NewInstallStepCollection(() => steps);
|
||||
var runtimeStateMock = new Mock<IRuntimeState>();
|
||||
runtimeStateMock.Setup(x => x.Level).Returns(RuntimeLevel.Install);
|
||||
|
||||
return new InstallService(logger, stepCollection, runtimeStateMock.Object);
|
||||
}
|
||||
|
||||
private class TestInstallStep : IInstallStep
|
||||
{
|
||||
public bool HasRun;
|
||||
|
||||
public bool ShouldRun = true;
|
||||
|
||||
public int Id;
|
||||
|
||||
public Func<InstallData, Task> AdditionalExecution;
|
||||
|
||||
public Task ExecuteAsync(InstallData model)
|
||||
{
|
||||
HasRun = true;
|
||||
|
||||
AdditionalExecution?.Invoke(model);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task<bool> RequiresExecutionAsync(InstallData model) => Task.FromResult(ShouldRun);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.New.Cms.Core.Installer;
|
||||
using UpgradeService = Umbraco.New.Cms.Core.Services.Installer.UpgradeService;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.New.Cms.Core.Services;
|
||||
|
||||
[TestFixture]
|
||||
public class UpgradeServiceTests
|
||||
{
|
||||
|
||||
[Test]
|
||||
[TestCase(RuntimeLevel.Install)]
|
||||
[TestCase(RuntimeLevel.Boot)]
|
||||
[TestCase(RuntimeLevel.Run)]
|
||||
[TestCase(RuntimeLevel.Unknown)]
|
||||
public void RequiresUpgradeRuntimeToUpgrade(RuntimeLevel level)
|
||||
{
|
||||
var sut = CreateUpgradeService(Enumerable.Empty<IUpgradeStep>(), level);
|
||||
|
||||
Assert.ThrowsAsync<InvalidOperationException>(async () => await sut.Upgrade());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task OnlyRunsStepsThatRequireExecution()
|
||||
{
|
||||
var steps = new[]
|
||||
{
|
||||
new TestUpgradeStep { ShouldRun = true },
|
||||
new TestUpgradeStep { ShouldRun = false },
|
||||
new TestUpgradeStep { ShouldRun = true },
|
||||
};
|
||||
|
||||
var sut = CreateUpgradeService(steps);
|
||||
|
||||
await sut.Upgrade();
|
||||
|
||||
foreach (var step in steps)
|
||||
{
|
||||
Assert.AreEqual(step.ShouldRun, step.HasRun);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task StepsRunInCollectionOrder()
|
||||
{
|
||||
List<TestUpgradeStep> runOrder = new List<TestUpgradeStep>();
|
||||
|
||||
var steps = new[]
|
||||
{
|
||||
new TestUpgradeStep { Id = 1 },
|
||||
new TestUpgradeStep { Id = 2 },
|
||||
new TestUpgradeStep { Id = 3 },
|
||||
};
|
||||
|
||||
// Add an method delegate that will add the step itself, that way we can know the executed order.
|
||||
foreach (var step in steps)
|
||||
{
|
||||
step.AdditionalExecution = () => runOrder.Add(step);
|
||||
}
|
||||
|
||||
var sut = CreateUpgradeService(steps);
|
||||
await sut.Upgrade();
|
||||
|
||||
// The ID's are strictly not necessary, but it makes potential debugging easier.
|
||||
var expectedRunOrder = steps.Select(x => x.Id);
|
||||
var actualRunOrder = runOrder.Select(x => x.Id);
|
||||
Assert.AreEqual(expectedRunOrder, actualRunOrder);
|
||||
}
|
||||
|
||||
private UpgradeService CreateUpgradeService(IEnumerable<IUpgradeStep> steps, RuntimeLevel runtimeLevel = RuntimeLevel.Upgrade)
|
||||
{
|
||||
var logger = Mock.Of<ILogger<UpgradeService>>();
|
||||
var stepCollection = new UpgradeStepCollection(() => steps);
|
||||
var runtimeStateMock = new Mock<IRuntimeState>();
|
||||
runtimeStateMock.Setup(x => x.Level).Returns(runtimeLevel);
|
||||
|
||||
return new UpgradeService(stepCollection, runtimeStateMock.Object, logger);
|
||||
}
|
||||
|
||||
private class TestUpgradeStep : IUpgradeStep
|
||||
{
|
||||
public bool HasRun;
|
||||
|
||||
public bool ShouldRun = true;
|
||||
|
||||
public int Id;
|
||||
|
||||
public Action AdditionalExecution;
|
||||
|
||||
public Task ExecuteAsync()
|
||||
{
|
||||
HasRun = true;
|
||||
|
||||
AdditionalExecution?.Invoke();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task<bool> RequiresExecutionAsync() => Task.FromResult(ShouldRun);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
using Umbraco.Cms.Core.Install.Models;
|
||||
using Umbraco.Cms.Core.Mapping;
|
||||
using Umbraco.Cms.Core.Scoping;
|
||||
using Umbraco.Cms.Infrastructure.Persistence;
|
||||
using Umbraco.Cms.ManagementApi.Mapping.Installer;
|
||||
using Umbraco.Cms.Tests.Common;
|
||||
using Umbraco.New.Cms.Core.Models.Installer;
|
||||
using Umbraco.New.Cms.Infrastructure.Factories.Installer;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.New.Cms.Infrastructure.Factories;
|
||||
|
||||
[TestFixture]
|
||||
public class DatabaseSettingsFactoryTests
|
||||
{
|
||||
[Test]
|
||||
public void CanBuildDatabaseSettings()
|
||||
{
|
||||
var metadata = CreateTestMetadata();
|
||||
var connectionString = new TestOptionsMonitor<ConnectionStrings>(new ConnectionStrings());
|
||||
var mapper = CreateMapper();
|
||||
|
||||
var factory = new DatabaseSettingsFactory(metadata, connectionString, mapper);
|
||||
|
||||
var settingsModels = factory.GetDatabaseSettings();
|
||||
Assert.AreEqual(metadata.Count, settingsModels.Count);
|
||||
AssertMapping(metadata, settingsModels);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsConfiguredSetCorrectly()
|
||||
{
|
||||
var connectionString = new ConnectionStrings
|
||||
{
|
||||
ConnectionString = "SomeConnectionString",
|
||||
ProviderName = "HostedTestMeta",
|
||||
};
|
||||
var optionsMonitor = new TestOptionsMonitor<ConnectionStrings>(connectionString);
|
||||
var mapper = CreateMapper();
|
||||
var metadata = CreateTestMetadata();
|
||||
|
||||
var factory = new DatabaseSettingsFactory(metadata, optionsMonitor, mapper);
|
||||
|
||||
var settingsModels = factory.GetDatabaseSettings();
|
||||
|
||||
Assert.AreEqual(1, settingsModels.Count, "Expected only one database settings model, if a database is preconfigured we should only return the configured one.");
|
||||
AssertMapping(metadata, settingsModels);
|
||||
Assert.IsTrue(settingsModels.First().IsConfigured);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SpecifiedProviderMustExist()
|
||||
{
|
||||
var connectionString = new ConnectionStrings
|
||||
{
|
||||
ConnectionString = "SomeConnectionString",
|
||||
ProviderName = "NoneExistentProvider",
|
||||
};
|
||||
var optionsMonitor = new TestOptionsMonitor<ConnectionStrings>(connectionString);
|
||||
var mapper = CreateMapper();
|
||||
var metadata = CreateTestMetadata();
|
||||
|
||||
var factory = new DatabaseSettingsFactory(metadata, optionsMonitor, mapper);
|
||||
Assert.Throws<InvalidOperationException>(() => factory.GetDatabaseSettings());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asserts that the mapping is correct, in other words that the values in DatabaseSettingsModel is as expected.
|
||||
/// </summary>
|
||||
private void AssertMapping(
|
||||
IEnumerable<IDatabaseProviderMetadata> expected,
|
||||
ICollection<DatabaseSettingsModel> actual)
|
||||
{
|
||||
expected = expected.ToList();
|
||||
foreach (var model in actual)
|
||||
{
|
||||
var metadata = expected.FirstOrDefault(x => x.Id == model.Id);
|
||||
Assert.IsNotNull(metadata);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(metadata?.SortOrder, model.SortOrder);
|
||||
Assert.AreEqual(metadata.DisplayName, model.DisplayName);
|
||||
Assert.AreEqual(metadata.DefaultDatabaseName, model.DefaultDatabaseName);
|
||||
Assert.AreEqual(metadata.ProviderName ?? string.Empty, model.ProviderName);
|
||||
Assert.AreEqual(metadata.RequiresServer, model.RequiresServer);
|
||||
Assert.AreEqual(metadata.ServerPlaceholder ?? string.Empty, model.ServerPlaceholder);
|
||||
Assert.AreEqual(metadata.RequiresCredentials, model.RequiresCredentials);
|
||||
Assert.AreEqual(metadata.SupportsIntegratedAuthentication, model.SupportsIntegratedAuthentication);
|
||||
Assert.AreEqual(metadata.RequiresConnectionTest, model.RequiresConnectionTest);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private IUmbracoMapper CreateMapper()
|
||||
{
|
||||
var mapper = new UmbracoMapper(
|
||||
new MapDefinitionCollection(Enumerable.Empty<IMapDefinition>),
|
||||
Mock.Of<ICoreScopeProvider>());
|
||||
|
||||
var definition = new InstallerViewModelsMapDefinition();
|
||||
definition.DefineMaps(mapper);
|
||||
return mapper;
|
||||
}
|
||||
|
||||
private List<IDatabaseProviderMetadata> CreateTestMetadata()
|
||||
{
|
||||
|
||||
var metadata = new List<IDatabaseProviderMetadata>
|
||||
{
|
||||
new TestDatabaseProviderMetadata
|
||||
{
|
||||
Id = Guid.Parse("EC8ACD63-8CDE-4CA5-B2A3-06322720F274"),
|
||||
SortOrder = 1,
|
||||
DisplayName = "FirstMetadata",
|
||||
DefaultDatabaseName = "TestDatabase",
|
||||
IsAvailable = true,
|
||||
GenerateConnectionStringDelegate = _ => "FirstTestMetadataConnectionString",
|
||||
ProviderName = "SimpleTestMeta"
|
||||
},
|
||||
new TestDatabaseProviderMetadata
|
||||
{
|
||||
Id = Guid.Parse("C5AB4E1D-B7E4-47E5-B1A4-C9343B5F59CA"),
|
||||
SortOrder = 2,
|
||||
DisplayName = "SecondMetadata",
|
||||
DefaultDatabaseName = "HostedTest",
|
||||
IsAvailable = true,
|
||||
RequiresServer = true,
|
||||
ServerPlaceholder = "SomeServerPlaceholder",
|
||||
RequiresCredentials = true,
|
||||
RequiresConnectionTest = true,
|
||||
ForceCreateDatabase = true,
|
||||
GenerateConnectionStringDelegate = _ => "HostedDatabaseConnectionString",
|
||||
ProviderName = "HostedTestMeta"
|
||||
},
|
||||
};
|
||||
|
||||
return metadata;
|
||||
}
|
||||
|
||||
#nullable enable
|
||||
public class TestDatabaseProviderMetadata : IDatabaseProviderMetadata
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public int SortOrder { get; set; }
|
||||
|
||||
public string DisplayName { get; set; } = string.Empty;
|
||||
|
||||
public string DefaultDatabaseName { get; set; } = string.Empty;
|
||||
|
||||
public string? ProviderName { get; set; }
|
||||
|
||||
public bool SupportsQuickInstall { get; set; }
|
||||
|
||||
public bool IsAvailable { get; set; }
|
||||
|
||||
public bool RequiresServer { get; set; }
|
||||
|
||||
public string? ServerPlaceholder { get; set; }
|
||||
|
||||
public bool RequiresCredentials { get; set; }
|
||||
|
||||
public bool SupportsIntegratedAuthentication { get; set; }
|
||||
|
||||
public bool RequiresConnectionTest { get; set; }
|
||||
|
||||
public bool ForceCreateDatabase { get; set; }
|
||||
|
||||
public Func<DatabaseModel, string> GenerateConnectionStringDelegate { get; set; } =
|
||||
_ => "ConnectionString";
|
||||
|
||||
public string? GenerateConnectionString(DatabaseModel databaseModel) => GenerateConnectionStringDelegate(databaseModel);
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Umbraco.Cms.ManagementApi\Umbraco.Cms.ManagementApi.csproj" />
|
||||
<ProjectReference Include="..\..\src\Umbraco.PublishedCache.NuCache\Umbraco.PublishedCache.NuCache.csproj" />
|
||||
<ProjectReference Include="..\Umbraco.Tests.Common\Umbraco.Tests.Common.csproj" />
|
||||
<ProjectReference Include="..\..\src\Umbraco.Web.BackOffice\Umbraco.Web.BackOffice.csproj" />
|
||||
|
||||
@@ -562,7 +562,7 @@ public class MemberControllerUnitTests
|
||||
|
||||
var map = new MapDefinitionCollection(() => new List<IMapDefinition>
|
||||
{
|
||||
new Cms.Core.Models.Mapping.MemberMapDefinition(),
|
||||
new global::Umbraco.Cms.Core.Models.Mapping.MemberMapDefinition(),
|
||||
memberMapDefinition,
|
||||
new ContentTypeMapDefinition(
|
||||
commonMapper,
|
||||
|
||||
Reference in New Issue
Block a user