2020-12-20 08:36:11 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
|
|
|
|
using System.Diagnostics;
|
2016-01-07 18:59:59 +01:00
|
|
|
using System.Linq;
|
2019-11-07 21:07:09 +11:00
|
|
|
using Newtonsoft.Json;
|
2014-04-15 19:12:42 +10:00
|
|
|
using NUnit.Framework;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Models;
|
|
|
|
|
using Umbraco.Cms.Tests.Common.Builders;
|
|
|
|
|
using Umbraco.Cms.Tests.Common.Builders.Extensions;
|
2014-04-15 19:12:42 +10:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Models;
|
2020-04-19 09:39:30 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[TestFixture]
|
|
|
|
|
public class DictionaryTranslationTests
|
|
|
|
|
{
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void SetUp() => _builder = new DictionaryTranslationBuilder();
|
2019-12-09 14:12:06 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
private DictionaryTranslationBuilder _builder = new();
|
2014-04-15 19:12:42 +10:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Can_Deep_Clone()
|
|
|
|
|
{
|
|
|
|
|
var item = BuildDictionaryTranslation();
|
2014-04-15 19:12:42 +10:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var clone = (DictionaryTranslation)item.DeepClone();
|
2020-12-20 08:36:11 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.AreNotSame(clone, item);
|
|
|
|
|
Assert.AreEqual(clone, item);
|
|
|
|
|
Assert.AreEqual(clone.CreateDate, item.CreateDate);
|
|
|
|
|
Assert.AreEqual(clone.Id, item.Id);
|
|
|
|
|
Assert.AreEqual(clone.Key, item.Key);
|
|
|
|
|
Assert.AreEqual(clone.UpdateDate, item.UpdateDate);
|
|
|
|
|
Assert.AreNotSame(clone.Language, item.Language);
|
2014-04-15 19:12:42 +10:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
// This is null because we are ignoring it from cloning due to caching/cloning issues - we don't really want
|
|
|
|
|
// this entity attached to this item but we're stuck with it for now
|
|
|
|
|
Assert.IsNull(clone.Language);
|
|
|
|
|
Assert.AreEqual(clone.LanguageId, item.LanguageId);
|
|
|
|
|
Assert.AreEqual(clone.Value, item.Value);
|
2014-04-16 16:44:08 +10:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
// This double verifies by reflection
|
|
|
|
|
var allProps = clone.GetType().GetProperties();
|
|
|
|
|
foreach (var propertyInfo in allProps.Where(x => x.Name != "Language"))
|
2014-04-16 16:44:08 +10:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(item, null));
|
2014-04-16 16:44:08 +10:00
|
|
|
}
|
2022-06-21 08:09:38 +02:00
|
|
|
}
|
2020-04-19 09:39:30 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Can_Serialize_Without_Error()
|
|
|
|
|
{
|
|
|
|
|
var item = BuildDictionaryTranslation();
|
|
|
|
|
|
|
|
|
|
var json = JsonConvert.SerializeObject(item);
|
|
|
|
|
Debug.Print(json);
|
2014-04-15 19:12:42 +10:00
|
|
|
}
|
2022-06-21 08:09:38 +02:00
|
|
|
|
|
|
|
|
private IDictionaryTranslation BuildDictionaryTranslation() =>
|
|
|
|
|
_builder
|
|
|
|
|
.AddLanguage()
|
|
|
|
|
.WithCultureInfo("en-AU")
|
|
|
|
|
.Done()
|
|
|
|
|
.WithValue("colour")
|
|
|
|
|
.Build();
|
2017-07-20 11:21:28 +02:00
|
|
|
}
|