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:
@@ -6,6 +6,7 @@ using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Strings;
|
||||
using Umbraco.Cms.Tests.Common.Builders;
|
||||
using Umbraco.Cms.Tests.Common.Builders.Extensions;
|
||||
|
||||
@@ -15,9 +16,27 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Models;
|
||||
public class PropertyTypeTests
|
||||
{
|
||||
[SetUp]
|
||||
public void SetUp() => _builder = new PropertyTypeBuilder();
|
||||
public void SetUp()
|
||||
{
|
||||
_propertyTypeBuilder = new PropertyTypeBuilder();
|
||||
_dataTypeBuilder = new DataTypeBuilder();
|
||||
}
|
||||
|
||||
private PropertyTypeBuilder _builder;
|
||||
private PropertyTypeBuilder _propertyTypeBuilder;
|
||||
private DataTypeBuilder _dataTypeBuilder;
|
||||
|
||||
[Test]
|
||||
public void Can_Create_From_DataType()
|
||||
{
|
||||
var shortStringHelper = new DefaultShortStringHelper(new DefaultShortStringHelperConfig());
|
||||
var dt = BuildDataType();
|
||||
var pt = new PropertyType(shortStringHelper, dt);
|
||||
|
||||
Assert.AreEqual(dt.Id, pt.DataTypeId);
|
||||
Assert.AreEqual(dt.Key, pt.DataTypeKey);
|
||||
Assert.AreEqual(dt.EditorAlias, pt.PropertyEditorAlias);
|
||||
Assert.AreEqual(dt.DatabaseType, pt.ValueStorageType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Deep_Clone()
|
||||
@@ -32,7 +51,7 @@ public class PropertyTypeTests
|
||||
Assert.AreEqual(clone.Alias, pt.Alias);
|
||||
Assert.AreEqual(clone.CreateDate, pt.CreateDate);
|
||||
Assert.AreEqual(clone.DataTypeId, pt.DataTypeId);
|
||||
Assert.AreEqual(clone.DataTypeId, pt.DataTypeId);
|
||||
Assert.AreEqual(clone.DataTypeKey, pt.DataTypeKey);
|
||||
Assert.AreEqual(clone.Description, pt.Description);
|
||||
Assert.AreEqual(clone.Key, pt.Key);
|
||||
Assert.AreEqual(clone.Mandatory, pt.Mandatory);
|
||||
@@ -69,7 +88,7 @@ public class PropertyTypeTests
|
||||
}
|
||||
|
||||
private PropertyType BuildPropertyType() =>
|
||||
_builder
|
||||
_propertyTypeBuilder
|
||||
.WithId(3)
|
||||
.WithPropertyEditorAlias("TestPropertyEditor")
|
||||
.WithAlias("test")
|
||||
@@ -81,4 +100,8 @@ public class PropertyTypeTests
|
||||
.WithMandatory(true)
|
||||
.WithValidationRegExp("xxxx")
|
||||
.Build();
|
||||
|
||||
private DataType BuildDataType() =>
|
||||
_dataTypeBuilder
|
||||
.Build();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user