Fixes deep clone of macro object
This commit is contained in:
@@ -109,9 +109,9 @@ namespace Umbraco.Core.Models
|
||||
private string _scriptAssembly;
|
||||
private string _scriptPath;
|
||||
private string _xslt;
|
||||
private readonly MacroPropertyCollection _properties;
|
||||
private readonly List<string> _addedProperties;
|
||||
private readonly List<string> _removedProperties;
|
||||
private MacroPropertyCollection _properties;
|
||||
private List<string> _addedProperties;
|
||||
private List<string> _removedProperties;
|
||||
|
||||
private static readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo<Macro, string>(x => x.Alias);
|
||||
private static readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo<Macro, string>(x => x.Name);
|
||||
@@ -397,7 +397,19 @@ namespace Umbraco.Core.Models
|
||||
{
|
||||
get { return _properties; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override object DeepClone()
|
||||
{
|
||||
var clone = (Macro)base.DeepClone();
|
||||
|
||||
clone._addedProperties = new List<string>();
|
||||
clone._removedProperties = new List<string>();
|
||||
clone._properties = new MacroPropertyCollection();
|
||||
clone._properties.CollectionChanged += clone.PropertiesChanged;
|
||||
|
||||
clone.ResetDirtyProperties(false);
|
||||
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
}
|
||||
51
src/Umbraco.Tests/Models/MacroTests.cs
Normal file
51
src/Umbraco.Tests/Models/MacroTests.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
|
||||
namespace Umbraco.Tests.Models
|
||||
{
|
||||
[TestFixture]
|
||||
public class MacroTests
|
||||
{
|
||||
[SetUp]
|
||||
public void Init()
|
||||
{
|
||||
var config = SettingsForTests.GetDefault();
|
||||
SettingsForTests.ConfigureSettings(config);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Deep_Clone()
|
||||
{
|
||||
var macro = new Macro(1, true, 3, "test", "Test", "blah", "blah", "xslt", false, true, true, "script");
|
||||
|
||||
var clone = (Macro)macro.DeepClone();
|
||||
|
||||
Assert.AreNotSame(clone, macro);
|
||||
Assert.AreEqual(clone, macro);
|
||||
Assert.AreEqual(clone.Id, macro.Id);
|
||||
|
||||
Assert.AreNotSame(clone.Properties, macro.Properties);
|
||||
Assert.AreNotSame(clone.AddedProperties, macro.AddedProperties);
|
||||
Assert.AreNotSame(clone.RemovedProperties, macro.RemovedProperties);
|
||||
|
||||
//This double verifies by reflection
|
||||
var allProps = clone.GetType().GetProperties();
|
||||
foreach (var propertyInfo in allProps)
|
||||
{
|
||||
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(macro, null));
|
||||
}
|
||||
|
||||
//need to ensure the event handlers are wired
|
||||
|
||||
var asDirty = (ICanBeDirty)clone;
|
||||
|
||||
Assert.IsFalse(asDirty.IsPropertyDirty("Properties"));
|
||||
clone.Properties.Add(new MacroProperty(3, "asdf", "SDF", 3, "asdfasdf"));
|
||||
Assert.IsTrue(asDirty.IsPropertyDirty("Properties"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -178,6 +178,7 @@
|
||||
<Compile Include="Migrations\Stubs\SixZeroMigration2.cs" />
|
||||
<Compile Include="Migrations\Upgrades\ValidateV7TagsUpgradeTest.cs" />
|
||||
<Compile Include="MockTests.cs" />
|
||||
<Compile Include="Models\MacroTests.cs" />
|
||||
<Compile Include="Models\Mapping\AutoMapperTests.cs" />
|
||||
<Compile Include="Models\Collections\Item.cs" />
|
||||
<Compile Include="Models\Collections\OrderItem.cs" />
|
||||
|
||||
Reference in New Issue
Block a user