* 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>
70 lines
2.4 KiB
C#
70 lines
2.4 KiB
C#
// Copyright (c) Umbraco.
|
|
// See LICENSE for more details.
|
|
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
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 DictionaryTranslationTests
|
|
{
|
|
private DictionaryTranslationBuilder _builder = new DictionaryTranslationBuilder();
|
|
|
|
[SetUp]
|
|
public void SetUp() => _builder = new DictionaryTranslationBuilder();
|
|
|
|
[Test]
|
|
public void Can_Deep_Clone()
|
|
{
|
|
IDictionaryTranslation item = BuildDictionaryTranslation();
|
|
|
|
var clone = (DictionaryTranslation)item.DeepClone();
|
|
|
|
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);
|
|
|
|
// 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);
|
|
|
|
// This double verifies by reflection
|
|
PropertyInfo[] allProps = clone.GetType().GetProperties();
|
|
foreach (PropertyInfo propertyInfo in allProps.Where(x => x.Name != "Language"))
|
|
{
|
|
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(item, null));
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public void Can_Serialize_Without_Error()
|
|
{
|
|
IDictionaryTranslation item = BuildDictionaryTranslation();
|
|
|
|
var json = JsonConvert.SerializeObject(item);
|
|
Debug.Print(json);
|
|
}
|
|
|
|
private IDictionaryTranslation BuildDictionaryTranslation() =>
|
|
_builder
|
|
.AddLanguage()
|
|
.WithCultureInfo("en-AU")
|
|
.Done()
|
|
.WithValue("colour")
|
|
.Build();
|
|
}
|
|
}
|