Files
Umbraco-CMS/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Models/RelationTests.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

79 lines
2.6 KiB
C#

// Copyright (c) Umbraco.
// See LICENSE for more details.
using System;
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 RelationTests
{
private RelationBuilder _builder;
[SetUp]
public void SetUp() => _builder = new RelationBuilder();
[Test]
public void Can_Deep_Clone()
{
Relation relation = BuildRelation();
var clone = (Relation)relation.DeepClone();
Assert.AreNotSame(clone, relation);
Assert.AreEqual(clone, relation);
Assert.AreEqual(clone.ChildId, relation.ChildId);
Assert.AreEqual(clone.Comment, relation.Comment);
Assert.AreEqual(clone.CreateDate, relation.CreateDate);
Assert.AreEqual(clone.Id, relation.Id);
Assert.AreEqual(clone.Key, relation.Key);
Assert.AreEqual(clone.ParentId, relation.ParentId);
Assert.AreNotSame(clone.RelationType, relation.RelationType);
Assert.AreEqual(clone.RelationType, relation.RelationType);
Assert.AreEqual(clone.RelationTypeId, relation.RelationTypeId);
Assert.AreEqual(clone.UpdateDate, relation.UpdateDate);
// This double verifies by reflection
PropertyInfo[] allProps = clone.GetType().GetProperties();
foreach (PropertyInfo propertyInfo in allProps)
{
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(relation, null));
}
}
[Test]
public void Can_Serialize_Without_Error()
{
Relation relation = BuildRelation();
var json = JsonConvert.SerializeObject(relation);
Debug.Print(json);
}
private Relation BuildRelation() =>
_builder
.BetweenIds(9, 8)
.WithId(4)
.WithComment("test comment")
.WithCreateDate(DateTime.Now)
.WithUpdateDate(DateTime.Now)
.WithKey(Guid.NewGuid())
.AddRelationType()
.WithId(66)
.WithAlias("test")
.WithName("Test")
.WithIsBidirectional(false)
.WithParentObjectType(Guid.NewGuid())
.WithChildObjectType(Guid.NewGuid())
.Done()
.Build();
}
}