Back to 10.2.0-ish
This commit is contained in:
@@ -29,6 +29,25 @@ public class EnumExtensionsTests
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
[TestCase(TreeUse.Dialog, TreeUse.Dialog, true)]
|
||||
[TestCase(TreeUse.Dialog, TreeUse.Main, false)]
|
||||
[TestCase(TreeUse.Dialog | TreeUse.Main, TreeUse.Dialog, true)]
|
||||
[TestCase(TreeUse.Dialog, TreeUse.Dialog | TreeUse.Main, false)]
|
||||
public void HasFlagAllTest(TreeUse value, TreeUse test, bool expected)
|
||||
{
|
||||
// The HasFlagAll() extension method determines whether
|
||||
// all bits from <test> are set (other bits can be set too).
|
||||
if (expected)
|
||||
{
|
||||
Assert.IsTrue(value.HasFlagAll(test));
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsFalse(value.HasFlagAll(test));
|
||||
}
|
||||
}
|
||||
|
||||
[TestCase(TreeUse.Dialog, TreeUse.Dialog, true)]
|
||||
[TestCase(TreeUse.Dialog, TreeUse.Main, false)]
|
||||
[TestCase(TreeUse.Dialog | TreeUse.Main, TreeUse.Dialog, true)]
|
||||
|
||||
@@ -13,25 +13,24 @@ 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");
|
||||
@@ -71,7 +70,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");
|
||||
|
||||
@@ -86,7 +85,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");
|
||||
|
||||
@@ -101,11 +100,10 @@ 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);
|
||||
@@ -119,11 +117,10 @@ 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);
|
||||
@@ -140,10 +137,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]
|
||||
@@ -152,10 +149,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]
|
||||
@@ -171,27 +168,28 @@ public class CultureImpactTests
|
||||
var success = BasicImpactFactory.TryCreate(null, false, ContentVariation.Nothing, false, false, out var impact);
|
||||
Assert.IsTrue(success);
|
||||
|
||||
Assert.AreSame(BasicImpactFactory.ImpactInvariant(), impact);
|
||||
}
|
||||
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 ContentSettings
|
||||
[Test]
|
||||
[TestCase(true)]
|
||||
[TestCase(false)]
|
||||
public void Edit_Invariant_From_Non_Default_Impacts_Invariant_Properties(bool allowEditInvariantFromNonDefault)
|
||||
{
|
||||
AllowEditInvariantFromNonDefault = allowEditInvariantFromNonDefault
|
||||
});
|
||||
var impact = sut.ImpactExplicit("da", false);
|
||||
var sut = createCultureImpactService(new SecuritySettings { AllowEditInvariantFromNonDefault = allowEditInvariantFromNonDefault });
|
||||
var impact = sut.ImpactExplicit("da", false);
|
||||
|
||||
Assert.AreEqual(allowEditInvariantFromNonDefault, impact.ImpactsAlsoInvariantProperties);
|
||||
Assert.AreEqual(allowEditInvariantFromNonDefault, impact.ImpactsAlsoInvariantProperties);
|
||||
}
|
||||
|
||||
private CultureImpactFactory createCultureImpactService(ContentSettings contentSettings = null)
|
||||
{
|
||||
contentSettings ??= new ContentSettings { AllowEditInvariantFromNonDefault = false, };
|
||||
private CultureImpactFactory createCultureImpactService(SecuritySettings securitySettings = null)
|
||||
{
|
||||
securitySettings ??= new SecuritySettings
|
||||
{
|
||||
AllowEditInvariantFromNonDefault = false,
|
||||
};
|
||||
|
||||
return new CultureImpactFactory(new TestOptionsMonitor<SecuritySettings>(securitySettings));
|
||||
}
|
||||
|
||||
return new CultureImpactFactory(new TestOptionsMonitor<ContentSettings>(contentSettings));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,132 +0,0 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public class ModelTypeTests
|
||||
|
||||
// Note the inner assembly qualified name
|
||||
Assert.AreEqual(
|
||||
"System.Collections.Generic.IEnumerable`1[[System.Int32[], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]",
|
||||
"System.Collections.Generic.IEnumerable`1[[System.Int32[], System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]",
|
||||
typeof(IEnumerable<>).MakeGenericType(type.MakeArrayType()).FullName);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ public class DefaultShortStringHelperTestsWithoutSetup
|
||||
{
|
||||
var requestHandlerSettings = new RequestHandlerSettings
|
||||
{
|
||||
UserDefinedCharCollection = Array.Empty<CharItem>(),
|
||||
CharCollection = Array.Empty<CharItem>(),
|
||||
EnableDefaultCharReplacements = false,
|
||||
ConvertUrlsToAscii = "false",
|
||||
};
|
||||
@@ -47,7 +47,7 @@ public class DefaultShortStringHelperTestsWithoutSetup
|
||||
{
|
||||
var requestHandlerSettings = new RequestHandlerSettings
|
||||
{
|
||||
UserDefinedCharCollection = Array.Empty<CharItem>(),
|
||||
CharCollection = Array.Empty<CharItem>(),
|
||||
EnableDefaultCharReplacements = false,
|
||||
ConvertUrlsToAscii = "false",
|
||||
};
|
||||
@@ -383,7 +383,7 @@ public class DefaultShortStringHelperTestsWithoutSetup
|
||||
{
|
||||
var requestHandlerSettings = new RequestHandlerSettings
|
||||
{
|
||||
UserDefinedCharCollection = Array.Empty<CharItem>(),
|
||||
CharCollection = Array.Empty<CharItem>(),
|
||||
EnableDefaultCharReplacements = false,
|
||||
ConvertUrlsToAscii = "false",
|
||||
};
|
||||
|
||||
@@ -4,9 +4,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core.Strings;
|
||||
@@ -325,49 +323,4 @@ public class StringExtensionsTests
|
||||
var output = input.ReplaceMany(toReplace.ToArray(), replacement);
|
||||
Assert.AreEqual(expected, output);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsFullPath()
|
||||
{
|
||||
bool isWindows = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
||||
|
||||
// These are full paths on Windows, but not on Linux
|
||||
TryIsFullPath(@"C:\dir\file.ext", isWindows);
|
||||
TryIsFullPath(@"C:\dir\", isWindows);
|
||||
TryIsFullPath(@"C:\dir", isWindows);
|
||||
TryIsFullPath(@"C:\", isWindows);
|
||||
TryIsFullPath(@"\\unc\share\dir\file.ext", isWindows);
|
||||
TryIsFullPath(@"\\unc\share", isWindows);
|
||||
|
||||
// These are full paths on Linux, but not on Windows
|
||||
TryIsFullPath(@"/some/file", !isWindows);
|
||||
TryIsFullPath(@"/dir", !isWindows);
|
||||
TryIsFullPath(@"/", !isWindows);
|
||||
|
||||
// Not full paths on either Windows or Linux
|
||||
TryIsFullPath(@"file.ext", false);
|
||||
TryIsFullPath(@"dir\file.ext", false);
|
||||
TryIsFullPath(@"\dir\file.ext", false);
|
||||
TryIsFullPath(@"C:", false);
|
||||
TryIsFullPath(@"C:dir\file.ext", false);
|
||||
TryIsFullPath(@"\dir", false); // An "absolute", but not "full" path
|
||||
|
||||
// Invalid on both Windows and Linux
|
||||
TryIsFullPath("", false, false);
|
||||
TryIsFullPath(" ", false, false); // technically, a valid filename on Linux
|
||||
}
|
||||
|
||||
private static void TryIsFullPath(string path, bool expectedIsFull, bool expectedIsValid = true)
|
||||
{
|
||||
Assert.AreEqual(expectedIsFull, path.IsFullPath(), "IsFullPath('" + path + "')");
|
||||
|
||||
if (expectedIsFull)
|
||||
{
|
||||
Assert.AreEqual(path, Path.GetFullPath(path));
|
||||
}
|
||||
else if (expectedIsValid)
|
||||
{
|
||||
Assert.AreNotEqual(path, Path.GetFullPath(path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user