Files
Umbraco-CMS/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Models/MacroTests.cs

78 lines
2.4 KiB
C#
Raw Normal View History

// Copyright (c) Umbraco.
// See LICENSE for more details.
using System.Linq;
2014-05-09 13:26:16 +10:00
using NUnit.Framework;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.Entities;
using Umbraco.Cms.Tests.Common.Builders;
using Umbraco.Cms.Tests.Common.Builders.Extensions;
2014-05-09 13:26:16 +10:00
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Models;
[TestFixture]
public class MacroTests
2014-05-09 13:26:16 +10:00
{
[SetUp]
public void SetUp() => _builder = new MacroBuilder();
private MacroBuilder _builder;
[Test]
public void Can_Deep_Clone()
{
var macro = _builder
.WithId(1)
.WithUseInEditor(true)
.WithCacheDuration(3)
.WithAlias("test")
.WithName("Test")
.WithSource("~/script.cshtml")
.WithCacheByMember(true)
.WithDontRender(true)
.AddProperty()
.WithId(6)
.WithAlias("rewq")
.WithName("REWQ")
.WithSortOrder(1)
.WithEditorAlias("asdfasdf")
.Done()
.Build();
2014-05-09 13:26:16 +10:00
var clone = (Macro)macro.DeepClone();
2014-05-09 13:26:16 +10:00
Assert.AreNotSame(clone, macro);
Assert.AreEqual(clone, macro);
Assert.AreEqual(clone.Id, macro.Id);
2014-05-09 13:26:16 +10:00
Assert.AreEqual(clone.Properties.Count, macro.Properties.Count);
for (var i = 0; i < clone.Properties.Count; i++)
{
Assert.AreEqual(clone.Properties[i], macro.Properties[i]);
Assert.AreNotSame(clone.Properties[i], macro.Properties[i]);
}
Assert.AreNotSame(clone.Properties, macro.Properties);
Assert.AreNotSame(clone.AddedProperties, macro.AddedProperties);
Assert.AreNotSame(clone.RemovedProperties, macro.RemovedProperties);
2014-05-09 13:26:16 +10:00
// 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));
}
2014-05-09 13:26:16 +10:00
// Need to ensure the event handlers are wired.
var asDirty = (ICanBeDirty)clone;
2014-05-09 13:26:16 +10:00
Assert.IsFalse(asDirty.IsPropertyDirty("Properties"));
clone.Properties.Add(new MacroProperty(3, Guid.NewGuid(), "asdf", "SDF", 3, "asdfasdf"));
Assert.IsTrue(asDirty.IsPropertyDirty("Properties"));
Assert.AreEqual(1, clone.AddedProperties.Count());
clone.Properties.Remove("rewq");
Assert.AreEqual(1, clone.RemovedProperties.Count());
2014-05-09 13:26:16 +10:00
}
2017-07-20 11:21:28 +02:00
}