Migrated relation tests into new project and builder pattern.

This commit is contained in:
Andy Butland
2020-04-04 11:11:47 +02:00
parent 58a1bc0a8f
commit f10971efaa
12 changed files with 319 additions and 103 deletions

View File

@@ -1,70 +0,0 @@
using System;
using System.Diagnostics;
using Newtonsoft.Json;
using NUnit.Framework;
using Umbraco.Core.Models;
using Umbraco.Core.Serialization;
namespace Umbraco.Tests.Models
{
[TestFixture]
public class RelationTests
{
[Test]
public void Can_Deep_Clone()
{
var item = new Relation(9, 8, new RelationType("test", "test", false, Guid.NewGuid(), Guid.NewGuid())
{
Id = 66
})
{
Comment = "test comment",
CreateDate = DateTime.Now,
Id = 4,
Key = Guid.NewGuid(),
UpdateDate = DateTime.Now
};
var clone = (Relation) item.DeepClone();
Assert.AreNotSame(clone, item);
Assert.AreEqual(clone, item);
Assert.AreEqual(clone.ChildId, item.ChildId);
Assert.AreEqual(clone.Comment, item.Comment);
Assert.AreEqual(clone.CreateDate, item.CreateDate);
Assert.AreEqual(clone.Id, item.Id);
Assert.AreEqual(clone.Key, item.Key);
Assert.AreEqual(clone.ParentId, item.ParentId);
Assert.AreNotSame(clone.RelationType, item.RelationType);
Assert.AreEqual(clone.RelationType, item.RelationType);
Assert.AreEqual(clone.RelationTypeId, item.RelationTypeId);
Assert.AreEqual(clone.UpdateDate, item.UpdateDate);
//This double verifies by reflection
var allProps = clone.GetType().GetProperties();
foreach (var propertyInfo in allProps)
{
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(item, null));
}
}
[Test]
public void Can_Serialize_Without_Error()
{
var item = new Relation(9, 8, new RelationType("test", "test", false, Guid.NewGuid(), Guid.NewGuid())
{
Id = 66
})
{
Comment = "test comment",
CreateDate = DateTime.Now,
Id = 4,
Key = Guid.NewGuid(),
UpdateDate = DateTime.Now
};
var json = JsonConvert.SerializeObject(item);
Debug.Print(json);
}
}
}