Files
Umbraco-CMS/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Models/PropertyGroupTests.cs
Paul Johnson 00133e880d Move test projects from src/ to tests/ (#11357)
* Update gitignore

* Move csproj

* Update project references

* Update solutions

* Update build scripts

* Tests used to share editorconfig with projects in src

* Fix broken tests.

* Stop copying around .editorconfig

merged root one with linting

* csharp_style_expression_bodied -> suggestion

* Move StyleCop rulesets to matching directories and update shared build properties

* Remove legacy build files, update NuGet.cofig and solution files

* Restore myget source

* Clean up .gitignore

* Update .gitignore

* Move new test classes to tests after merge

* Gitignore + nuget config

* Move new test

Co-authored-by: Ronald Barendse <ronald@barend.se>
2021-10-18 08:14:04 +01:00

84 lines
2.8 KiB
C#

// Copyright (c) Umbraco.
// See LICENSE for more details.
using System.Diagnostics;
using System.Reflection;
using Newtonsoft.Json;
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 PropertyGroupTests
{
private PropertyGroupBuilder _builder;
[SetUp]
public void SetUp() => _builder = new PropertyGroupBuilder();
[Test]
public void Can_Deep_Clone()
{
PropertyGroup pg = BuildPropertyGroup();
var clone = (PropertyGroup)pg.DeepClone();
Assert.AreNotSame(clone, pg);
Assert.AreEqual(clone, pg);
Assert.AreEqual(clone.Id, pg.Id);
Assert.AreEqual(clone.CreateDate, pg.CreateDate);
Assert.AreEqual(clone.Key, pg.Key);
Assert.AreEqual(clone.Name, pg.Name);
Assert.AreEqual(clone.SortOrder, pg.SortOrder);
Assert.AreEqual(clone.UpdateDate, pg.UpdateDate);
Assert.AreNotSame(clone.PropertyTypes, pg.PropertyTypes);
Assert.AreEqual(clone.PropertyTypes, pg.PropertyTypes);
Assert.AreEqual(clone.PropertyTypes.Count, pg.PropertyTypes.Count);
for (var i = 0; i < pg.PropertyTypes.Count; i++)
{
Assert.AreNotSame(clone.PropertyTypes[i], pg.PropertyTypes[i]);
Assert.AreEqual(clone.PropertyTypes[i], pg.PropertyTypes[i]);
}
// This double verifies by reflection
PropertyInfo[] allProps = clone.GetType().GetProperties();
foreach (PropertyInfo propertyInfo in allProps)
{
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(pg, null));
}
}
[Test]
public void Can_Serialize_Without_Error()
{
PropertyGroup pg = BuildPropertyGroup();
var json = JsonConvert.SerializeObject(pg);
Debug.Print(json);
}
private PropertyGroup BuildPropertyGroup() =>
_builder
.WithId(77)
.WithName("Group1")
.AddPropertyType()
.WithId(3)
.WithAlias("test")
.WithName("Test")
.WithDescription("testing")
.WithPropertyGroupId(11)
.WithMandatory(true)
.WithValidationRegExp("xxxx")
.Done()
.AddPropertyType()
.WithId(4)
.WithAlias("test2")
.WithName("Test2")
.Done()
.Build();
}
}