Files
Umbraco-CMS/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Configuration/Models/RequestHandlerSettingsTests.cs
Nikolaj Geisle 7aeb400fce V10: fix build warnings in test projects (#12509)
* Run code cleanup

* Dotnet format benchmarks project

* Fix up Test.Common

* Run dotnet format + manual cleanup

* Run code cleanup for unit tests

* Run dotnet format

* Fix up errors

* Manual cleanup of Unit test project

* Update tests/Umbraco.Tests.Benchmarks/HexStringBenchmarks.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Update tests/Umbraco.Tests.Integration/Testing/TestDbMeta.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Update tests/Umbraco.Tests.Benchmarks/TypeFinderBenchmarks.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Update tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Update tests/Umbraco.Tests.Integration/Umbraco.Core/Events/EventAggregatorTests.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Fix according to review

* Fix after merge

* Fix errors

Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk>
Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>
Co-authored-by: Zeegaan <nge@umbraco.dk>
2022-06-21 08:09:38 +02:00

93 lines
3.8 KiB
C#

using System.Linq;
using NUnit.Framework;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Extensions;
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 { UserDefinedCharCollection = userCollection };
var actual = settings.GetCharReplacements().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
{
UserDefinedCharCollection = userCollection,
EnableDefaultCharReplacements = false,
};
var actual = settings.GetCharReplacements().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 { UserDefinedCharCollection = userCollection };
var actual = settings.GetCharReplacements().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 { UserDefinedCharCollection = userCollection };
var actual = settings.GetCharReplacements().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));
}
}