Skip to content

Add a backing field for EditorUIAlias and track changes when its set. #19733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Umbraco.Core/Models/DataType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class DataType : TreeEntityBase, IDataType
private IDictionary<string, object> _configurationData;
private ValueStorageType _databaseType;
private IDataEditor? _editor;
private string? _editorUiAlias;
private bool _hasConfigurationObject;

/// <summary>
Expand Down Expand Up @@ -60,7 +61,11 @@ public IDataEditor? Editor

/// <inheritdoc />
[DataMember]
public string? EditorUiAlias { get; set; }
public string? EditorUiAlias
{
get => _editorUiAlias;
set => SetPropertyValueAndDetectChanges(value, ref _editorUiAlias, nameof(EditorUiAlias));
}

/// <inheritdoc />
[DataMember]
Expand Down
35 changes: 35 additions & 0 deletions tests/Umbraco.Tests.UnitTests/Umbraco.Core/Models/DataTypeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.

using NUnit.Framework;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Tests.Common.Builders;
using Umbraco.Cms.Tests.Common.Builders.Extensions;

namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Models;

[TestFixture]
public class DataTypeTests
{
[Test]
public void Can_Update_And_Verify_Dirty_Properties()
{
var dataType = new DataTypeBuilder()
.WithName("Test Data Type")
.WithDatabaseType(ValueStorageType.Ntext)
.Build();

dataType.ResetDirtyProperties();

dataType.DatabaseType = ValueStorageType.Nvarchar;
dataType.EditorUiAlias = "Test.EditorUiAlias";

var dirtyProperties = dataType.GetDirtyProperties().OrderBy(x => x).ToList();

Assert.IsTrue(dataType.IsPropertyDirty(nameof(dataType.DatabaseType)));
Assert.IsTrue(dataType.IsPropertyDirty(nameof(dataType.EditorUiAlias)));

Assert.AreEqual(2, dirtyProperties.Count);
Assert.AreEqual($"{nameof(dataType.DatabaseType)},{nameof(dataType.EditorUiAlias)}", string.Join(",", dirtyProperties));
}
}
Loading