diff --git a/src/Umbraco.Core/PropertyEditors/ValueListConfiguration.cs b/src/Umbraco.Core/PropertyEditors/ValueListConfiguration.cs index 95dbf9db5c..69279ebad8 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueListConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueListConfiguration.cs @@ -6,10 +6,5 @@ namespace Umbraco.Cms.Core.PropertyEditors; public class ValueListConfiguration { [ConfigurationField("items")] - public List Items { get; set; } = new(); - - public class ValueListItem - { - public string? Value { get; set; } - } + public List Items { get; set; } = new(); } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ValueListUniqueValueValidator.cs b/src/Umbraco.Infrastructure/PropertyEditors/ValueListUniqueValueValidator.cs index f2c75d501f..e481d3d89a 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ValueListUniqueValueValidator.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ValueListUniqueValueValidator.cs @@ -25,10 +25,10 @@ public class ValueListUniqueValueValidator : IValueValidator yield break; } - ValueListConfiguration.ValueListItem[]? items = null; + string[]? items = null; try { - items = _configurationEditorJsonSerializer.Deserialize(stringValue); + items = _configurationEditorJsonSerializer.Deserialize(stringValue); } catch { @@ -42,7 +42,7 @@ public class ValueListUniqueValueValidator : IValueValidator } var duplicateValues = items - .Select(item => item.Value) + .Select(item => item) .GroupBy(v => v) .Where(group => group.Count() > 1) .Select(group => group.First()) diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/EnsureUniqueValuesValidatorTest.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/EnsureUniqueValuesValidatorTest.cs index 75a8b94dfa..07a739d6da 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/EnsureUniqueValuesValidatorTest.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/EnsureUniqueValuesValidatorTest.cs @@ -16,7 +16,7 @@ public class EnsureUniqueValuesValidatorTest => new SystemTextConfigurationEditorJsonSerializer(); [Test] - public void Expects_Array_Of_ValueListItems_Not_Single_String() + public void Expects_Array_Of_String_Not_Single_String() { var validator = new ValueListUniqueValueValidator(ConfigurationEditorJsonSerializer()); var result = validator.Validate( @@ -27,7 +27,7 @@ public class EnsureUniqueValuesValidatorTest } [Test] - public void Expects_Array_Of_ValueListItems_Not_Array_Of_String() + public void Expects_Array_Of_String() { var validator = new ValueListUniqueValueValidator(ConfigurationEditorJsonSerializer()); var result = @@ -35,7 +35,7 @@ public class EnsureUniqueValuesValidatorTest new JsonArray("hello", "world"), null, null); - Assert.AreEqual(1, result.Count()); + Assert.AreEqual(0, result.Count()); } [Test] @@ -44,9 +44,7 @@ public class EnsureUniqueValuesValidatorTest var validator = new ValueListUniqueValueValidator(ConfigurationEditorJsonSerializer()); var result = validator.Validate( - new JsonArray( - JsonNode.Parse("""{"value": "hello"}"""), - JsonNode.Parse("""{"value": "world"}""")), + new JsonArray("one", "two", "three"), null, null); Assert.AreEqual(0, result.Count()); @@ -58,9 +56,7 @@ public class EnsureUniqueValuesValidatorTest var validator = new ValueListUniqueValueValidator(ConfigurationEditorJsonSerializer()); var result = validator.Validate( - new JsonArray( - JsonNode.Parse("""{"value": "hello"}"""), - JsonNode.Parse("""{"value": "hello"}""")), + new JsonArray("one", "one"), null, null); Assert.AreEqual(1, result.Count()); @@ -72,11 +68,7 @@ public class EnsureUniqueValuesValidatorTest var validator = new ValueListUniqueValueValidator(ConfigurationEditorJsonSerializer()); var result = validator.Validate( - new JsonArray( - JsonNode.Parse("""{"value": "hello"}"""), - JsonNode.Parse("""{"value": "hello"}"""), - JsonNode.Parse("""{"value": "world"}"""), - JsonNode.Parse("""{"value": "world"}""")), + new JsonArray("one", "two", "three", "one", "two"), null, null); Assert.AreEqual(2, result.Count()); diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/MultiValuePropertyEditorTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/MultiValuePropertyEditorTests.cs index e5c6809c3e..5b76313c2a 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/MultiValuePropertyEditorTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/MultiValuePropertyEditorTests.cs @@ -1,7 +1,6 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using System.Globalization; using Moq; using NUnit.Framework; using Umbraco.Cms.Core; @@ -42,12 +41,7 @@ public class MultiValuePropertyEditorTests .FromConfigurationObject( new ValueListConfiguration { - Items = new List - { - new() { Value = "Value 1" }, - new() { Value = "Value 2" }, - new() { Value = "Value 3" }, - }, + Items = ["Value 1", "Value 2", "Value 3"] }, serializer); @@ -98,12 +92,7 @@ public class MultiValuePropertyEditorTests .FromConfigurationObject( new ValueListConfiguration { - Items = new List - { - new() { Value = "Value 1" }, - new() { Value = "Value 2" }, - new() { Value = "Value 3" }, - }, + Items = ["Value 1", "Value 2", "Value 3"] }, serializer); @@ -152,12 +141,7 @@ public class MultiValuePropertyEditorTests dataType.ConfigurationData = configurationEditor.FromConfigurationObject( new ValueListConfiguration { - Items = new List - { - new() { Value = "Item 1" }, - new() { Value = "Item 2" }, - new() { Value = "Item 3" }, - }, + Items = ["Item 1", "Item 2", "Item 3"] }, serializer); @@ -167,8 +151,8 @@ public class MultiValuePropertyEditorTests Assert.NotNull(result); Assert.AreEqual(3, result.Items.Count); - Assert.AreEqual("Item 1", result.Items[0].Value); - Assert.AreEqual("Item 2", result.Items[1].Value); - Assert.AreEqual("Item 3", result.Items[2].Value); + Assert.AreEqual("Item 1", result.Items[0]); + Assert.AreEqual("Item 2", result.Items[1]); + Assert.AreEqual("Item 3", result.Items[2]); } }