* Use language ISO code for language fallback instead of language ID * Remove language and language ID from dictionary item and dictionary item translation * ADd unit test for dictionary item translation value extension * Make the internal service implementations sealed * Rename translation ISO code to be more explicit in its origin (Language) * Add breaking changes suppression * Handle save of invalid fallback iso code * Fixed test * Only allow non-UserCustomCulture's * Fixed and added tests * Rename ISO code validation method * Fix language telemetry test (create Swedish with the correct ISO code) --------- Co-authored-by: Bjarke Berg <mail@bergmania.dk>
63 lines
1.8 KiB
C#
63 lines
1.8 KiB
C#
// Copyright (c) Umbraco.
|
|
// See LICENSE for more details.
|
|
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
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
|
|
{
|
|
[SetUp]
|
|
public void SetUp() => _builder = new DictionaryTranslationBuilder();
|
|
|
|
private DictionaryTranslationBuilder _builder = new();
|
|
|
|
[Test]
|
|
public void Can_Deep_Clone()
|
|
{
|
|
var 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.AreEqual(clone.LanguageIsoCode, item.LanguageIsoCode);
|
|
Assert.AreEqual(clone.Value, item.Value);
|
|
|
|
// This double verifies by reflection
|
|
var allProps = clone.GetType().GetProperties();
|
|
foreach (var 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()
|
|
{
|
|
var item = BuildDictionaryTranslation();
|
|
|
|
var json = JsonConvert.SerializeObject(item);
|
|
Debug.Print(json);
|
|
}
|
|
|
|
private IDictionaryTranslation BuildDictionaryTranslation() =>
|
|
_builder
|
|
.AddLanguage()
|
|
.WithCultureInfo("en-AU")
|
|
.Done()
|
|
.WithValue("colour")
|
|
.Build();
|
|
}
|