Models: PropertyType constructor sets the DataTypeKey if IDataType has identity (#20301)

* PropertyType constructor sets the DataTypeKey if passed IDataType has identity

* Updated unit tests to verify behaviour.

---------

Co-authored-by: Andy Butland <abutland73@gmail.com>
This commit is contained in:
Pantelis
2025-09-30 08:18:26 +03:00
committed by GitHub
parent 82fc41a459
commit 65393ff3d9
5 changed files with 44 additions and 5 deletions

View File

@@ -1,7 +1,6 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.
using System;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Strings;
@@ -38,6 +37,7 @@ public class PropertyTypeBuilder<TParent>
private string _alias;
private DateTime? _createDate;
private int? _dataTypeId;
private Guid? _dataTypeKey;
private string _description;
private int? _id;
private Guid? _key;
@@ -132,6 +132,12 @@ public class PropertyTypeBuilder<TParent>
return this;
}
public PropertyTypeBuilder<TParent> WithDataTypeKey(Guid dataTypeKey)
{
_dataTypeKey = dataTypeKey;
return this;
}
public PropertyTypeBuilder<TParent> WithPropertyGroupId(int propertyGroupId)
{
_propertyGroupId = new Lazy<int>(() => propertyGroupId);
@@ -176,6 +182,7 @@ public class PropertyTypeBuilder<TParent>
var updateDate = _updateDate ?? DateTime.Now;
var sortOrder = _sortOrder ?? 0;
var dataTypeId = _dataTypeId ?? -88;
var dataTypeKey = _dataTypeKey ?? Guid.Empty;
var description = _description ?? string.Empty;
var propertyGroupId = _propertyGroupId;
var mandatory = _mandatory ?? false;
@@ -196,6 +203,7 @@ public class PropertyTypeBuilder<TParent>
Name = name,
SortOrder = sortOrder,
DataTypeId = dataTypeId,
DataTypeKey = dataTypeKey,
Description = description,
CreateDate = createDate,
UpdateDate = updateDate,