Since this is the way it's been previously, we cannot change the behaviour of this. Unfortunately due to how the config binding works, we have to make sure it returns null the very first time it's called by the framework to ensure that overrides actually gets registered.
91 lines
4.0 KiB
C#
91 lines
4.0 KiB
C#
using System.Linq;
|
|
using NUnit.Framework;
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
|
using Umbraco.Cms.Core.Configuration.UmbracoSettings;
|
|
|
|
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Configuration.Models
|
|
{
|
|
[TestFixture]
|
|
public class RequestHandlerSettingsTests
|
|
{
|
|
[Test]
|
|
public void Given_CharCollection_With_DefaultEnabled_MergesCollection()
|
|
{
|
|
var userCollection = new CharItem[]
|
|
{
|
|
new () { Char = "test", Replacement = "replace" },
|
|
new () { Char = "test2", Replacement = "replace2" }
|
|
};
|
|
|
|
|
|
var settings = new RequestHandlerSettings { CharCollection = userCollection };
|
|
var actual = settings.CharCollection.ToList();
|
|
|
|
var expectedCollection = RequestHandlerSettings.DefaultCharCollection.ToList();
|
|
expectedCollection.AddRange(userCollection);
|
|
|
|
Assert.AreEqual(expectedCollection.Count, actual.Count);
|
|
Assert.That(actual, Is.EquivalentTo(expectedCollection));
|
|
}
|
|
|
|
[Test]
|
|
public void Given_CharCollection_With_DefaultDisabled_ReturnsUserCollection()
|
|
{
|
|
var userCollection = new CharItem[]
|
|
{
|
|
new () { Char = "test", Replacement = "replace" },
|
|
new () { Char = "test2", Replacement = "replace2" }
|
|
};
|
|
|
|
var settings = new RequestHandlerSettings { CharCollection = userCollection, EnableDefaultCharReplacements = false };
|
|
var actual = settings.CharCollection.ToList();
|
|
|
|
Assert.AreEqual(userCollection.Length, actual.Count);
|
|
Assert.That(actual, Is.EquivalentTo(userCollection));
|
|
}
|
|
|
|
[Test]
|
|
public void Given_CharCollection_That_OverridesDefaultValues_ReturnsReplacements()
|
|
{
|
|
var userCollection = new CharItem[]
|
|
{
|
|
new () { Char = "%", Replacement = "percent" },
|
|
new () { Char = ".", Replacement = "dot" }
|
|
};
|
|
|
|
var settings = new RequestHandlerSettings { CharCollection = userCollection };
|
|
var actual = settings.CharCollection.ToList();
|
|
|
|
Assert.AreEqual(RequestHandlerSettings.DefaultCharCollection.Length, actual.Count);
|
|
|
|
Assert.That(actual, Has.Exactly(1).Matches<CharItem>(x => x.Char == "%" && x.Replacement == "percent"));
|
|
Assert.That(actual, Has.Exactly(1).Matches<CharItem>(x => x.Char == "." && x.Replacement == "dot"));
|
|
Assert.That(actual, Has.Exactly(0).Matches<CharItem>(x => x.Char == "%" && x.Replacement == string.Empty));
|
|
Assert.That(actual, Has.Exactly(0).Matches<CharItem>(x => x.Char == "." && x.Replacement == string.Empty));
|
|
}
|
|
|
|
[Test]
|
|
public void Given_CharCollection_That_OverridesDefaultValues_And_ContainsNew_ReturnsMergedWithReplacements()
|
|
{
|
|
var userCollection = new CharItem[]
|
|
{
|
|
new () { Char = "%", Replacement = "percent" },
|
|
new () { Char = ".", Replacement = "dot" },
|
|
new () { Char = "new", Replacement = "new" }
|
|
};
|
|
|
|
var settings = new RequestHandlerSettings { CharCollection = userCollection };
|
|
var actual = settings.CharCollection.ToList();
|
|
|
|
// Add 1 to the length, because we're expecting to only add one new one
|
|
Assert.AreEqual(RequestHandlerSettings.DefaultCharCollection.Length + 1, actual.Count);
|
|
|
|
Assert.That(actual, Has.Exactly(1).Matches<CharItem>(x => x.Char == "%" && x.Replacement == "percent"));
|
|
Assert.That(actual, Has.Exactly(1).Matches<CharItem>(x => x.Char == "." && x.Replacement == "dot"));
|
|
Assert.That(actual, Has.Exactly(1).Matches<CharItem>(x => x.Char == "new" && x.Replacement == "new"));
|
|
Assert.That(actual, Has.Exactly(0).Matches<CharItem>(x => x.Char == "%" && x.Replacement == string.Empty));
|
|
Assert.That(actual, Has.Exactly(0).Matches<CharItem>(x => x.Char == "." && x.Replacement == string.Empty));
|
|
}
|
|
}
|
|
}
|