2020-12-23 11:35:49 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
2018-06-29 19:52:40 +02:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NUnit.Framework;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Umbraco.Cms.Core.Models;
|
|
|
|
|
using Umbraco.Cms.Core.Services;
|
2021-02-12 13:36:50 +01:00
|
|
|
using Umbraco.Cms.Infrastructure.Persistence;
|
2021-02-10 14:45:44 +01:00
|
|
|
using Umbraco.Cms.Tests.Common.Builders;
|
|
|
|
|
using Umbraco.Cms.Tests.Common.Builders.Extensions;
|
|
|
|
|
using Umbraco.Cms.Tests.Common.Testing;
|
2021-02-11 08:30:27 +01:00
|
|
|
using Umbraco.Cms.Tests.Integration.Testing;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services;
|
2022-04-26 10:22:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Tests covering all methods in the LocalizationService class.
|
|
|
|
|
/// This is more of an integration test as it involves multiple layers
|
|
|
|
|
/// as well as configuration.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[TestFixture]
|
|
|
|
|
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
|
|
|
|
public class LocalizationServiceTests : UmbracoIntegrationTest
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
[SetUp]
|
|
|
|
|
public void SetUp() => CreateTestData();
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
private Guid _parentItemGuidId;
|
|
|
|
|
private int _parentItemIntId;
|
|
|
|
|
private Guid _childItemGuidId;
|
|
|
|
|
private int _childItemIntId;
|
|
|
|
|
private int _danishLangId;
|
|
|
|
|
private int _englishLangId;
|
2020-08-24 16:06:09 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
private ILocalizationService LocalizationService => GetRequiredService<ILocalizationService>();
|
2020-08-24 16:06:09 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Can_Get_Root_Dictionary_Items()
|
|
|
|
|
{
|
|
|
|
|
var rootItems = LocalizationService.GetRootDictionaryItems();
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.NotNull(rootItems);
|
|
|
|
|
Assert.IsTrue(rootItems.Any());
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Can_Determint_If_DictionaryItem_Exists()
|
|
|
|
|
{
|
|
|
|
|
var exists = LocalizationService.DictionaryItemExists("Parent");
|
|
|
|
|
Assert.IsTrue(exists);
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Can_Get_All_Languages()
|
|
|
|
|
{
|
|
|
|
|
var languages = LocalizationService.GetAllLanguages();
|
|
|
|
|
Assert.NotNull(languages);
|
|
|
|
|
Assert.IsTrue(languages.Any());
|
|
|
|
|
Assert.That(languages.Count(), Is.EqualTo(3));
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Can_Get_Dictionary_Item_By_Int_Id()
|
|
|
|
|
{
|
|
|
|
|
var parentItem = LocalizationService.GetDictionaryItemById(_parentItemIntId);
|
|
|
|
|
Assert.NotNull(parentItem);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var childItem = LocalizationService.GetDictionaryItemById(_childItemIntId);
|
|
|
|
|
Assert.NotNull(childItem);
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Can_Get_Dictionary_Item_By_Guid_Id()
|
|
|
|
|
{
|
|
|
|
|
var parentItem = LocalizationService.GetDictionaryItemById(_parentItemGuidId);
|
|
|
|
|
Assert.NotNull(parentItem);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var childItem = LocalizationService.GetDictionaryItemById(_childItemGuidId);
|
|
|
|
|
Assert.NotNull(childItem);
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-10-05 12:14:43 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Can_Get_Dictionary_Items_By_Guid_Ids()
|
|
|
|
|
{
|
|
|
|
|
var items = LocalizationService.GetDictionaryItemsByIds(_parentItemGuidId, _childItemGuidId);
|
|
|
|
|
Assert.AreEqual(2, items.Count());
|
|
|
|
|
Assert.NotNull(items.FirstOrDefault(i => i.Key == _parentItemGuidId));
|
|
|
|
|
Assert.NotNull(items.FirstOrDefault(i => i.Key == _childItemGuidId));
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Can_Get_Dictionary_Item_By_Key()
|
|
|
|
|
{
|
|
|
|
|
var parentItem = LocalizationService.GetDictionaryItemByKey("Parent");
|
|
|
|
|
Assert.NotNull(parentItem);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var childItem = LocalizationService.GetDictionaryItemByKey("Child");
|
|
|
|
|
Assert.NotNull(childItem);
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-10-05 12:14:43 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Can_Get_Dictionary_Items_By_Keys()
|
|
|
|
|
{
|
|
|
|
|
var items = LocalizationService.GetDictionaryItemsByKeys("Parent", "Child");
|
|
|
|
|
Assert.AreEqual(2, items.Count());
|
|
|
|
|
Assert.NotNull(items.FirstOrDefault(i => i.ItemKey == "Parent"));
|
|
|
|
|
Assert.NotNull(items.FirstOrDefault(i => i.ItemKey == "Child"));
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Can_Get_Dictionary_Item_Children()
|
|
|
|
|
{
|
|
|
|
|
var item = LocalizationService.GetDictionaryItemChildren(_parentItemGuidId);
|
|
|
|
|
Assert.NotNull(item);
|
|
|
|
|
Assert.That(item.Count(), Is.EqualTo(1));
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
foreach (var dictionaryItem in item)
|
|
|
|
|
{
|
|
|
|
|
Assert.AreEqual(_parentItemGuidId, dictionaryItem.ParentId);
|
|
|
|
|
Assert.IsFalse(string.IsNullOrEmpty(dictionaryItem.ItemKey));
|
2018-06-29 19:52:40 +02:00
|
|
|
}
|
2022-06-21 08:09:38 +02:00
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Can_Get_Dictionary_Item_Descendants()
|
|
|
|
|
{
|
|
|
|
|
using (var scope = ScopeProvider.CreateScope())
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
var en = LocalizationService.GetLanguageById(_englishLangId);
|
|
|
|
|
var dk = LocalizationService.GetLanguageById(_danishLangId);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var currParentId = _childItemGuidId;
|
|
|
|
|
for (var i = 0; i < 25; i++)
|
|
|
|
|
{
|
|
|
|
|
// Create 2 per level
|
|
|
|
|
var desc1 = new DictionaryItem(currParentId, "D1" + i)
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
Translations = new List<IDictionaryTranslation>
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
new DictionaryTranslation(en, "ChildValue1 " + i),
|
|
|
|
|
new DictionaryTranslation(dk, "BørnVærdi1 " + i)
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
var desc2 = new DictionaryItem(currParentId, "D2" + i)
|
|
|
|
|
{
|
|
|
|
|
Translations = new List<IDictionaryTranslation>
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
new DictionaryTranslation(en, "ChildValue2 " + i),
|
|
|
|
|
new DictionaryTranslation(dk, "BørnVærdi2 " + i)
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
LocalizationService.Save(desc1);
|
|
|
|
|
LocalizationService.Save(desc2);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
currParentId = desc1.Key;
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlTrace = true;
|
|
|
|
|
ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().EnableSqlCount = true;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var items = LocalizationService.GetDictionaryItemDescendants(_parentItemGuidId).ToArray();
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
Debug.WriteLine("SQL CALLS: " + ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().SqlCount);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.AreEqual(51, items.Length);
|
2020-12-23 11:35:49 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
// There's a call or two to get languages, so apart from that there should only be one call per level.
|
|
|
|
|
Assert.Less(ScopeAccessor.AmbientScope.Database.AsUmbracoDatabase().SqlCount, 30);
|
2018-06-29 19:52:40 +02:00
|
|
|
}
|
2022-06-21 08:09:38 +02:00
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Can_GetLanguageById()
|
|
|
|
|
{
|
|
|
|
|
var danish = LocalizationService.GetLanguageById(_danishLangId);
|
|
|
|
|
var english = LocalizationService.GetLanguageById(_englishLangId);
|
|
|
|
|
Assert.NotNull(danish);
|
|
|
|
|
Assert.NotNull(english);
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Can_GetLanguageByIsoCode()
|
|
|
|
|
{
|
|
|
|
|
var danish = LocalizationService.GetLanguageByIsoCode("da-DK");
|
|
|
|
|
var english = LocalizationService.GetLanguageByIsoCode("en-GB");
|
|
|
|
|
Assert.NotNull(danish);
|
|
|
|
|
Assert.NotNull(english);
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Does_Not_Fail_When_Language_Doesnt_Exist()
|
|
|
|
|
{
|
|
|
|
|
var language = LocalizationService.GetLanguageByIsoCode("sv-SE");
|
|
|
|
|
Assert.Null(language);
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Does_Not_Fail_When_DictionaryItem_Doesnt_Exist()
|
|
|
|
|
{
|
|
|
|
|
var item = LocalizationService.GetDictionaryItemByKey("RandomKey");
|
|
|
|
|
Assert.Null(item);
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Can_Delete_Language()
|
|
|
|
|
{
|
|
|
|
|
var languageNbNo = new LanguageBuilder()
|
|
|
|
|
.WithCultureInfo("nb-NO")
|
|
|
|
|
.Build();
|
2023-08-16 23:37:10 +02:00
|
|
|
LocalizationService.Save(languageNbNo, -1);
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.That(languageNbNo.HasIdentity, Is.True);
|
|
|
|
|
var languageId = languageNbNo.Id;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
LocalizationService.Delete(languageNbNo);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var language = LocalizationService.GetLanguageById(languageId);
|
|
|
|
|
Assert.Null(language);
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Can_Delete_Language_Used_As_Fallback()
|
|
|
|
|
{
|
|
|
|
|
var languageDaDk = LocalizationService.GetLanguageByIsoCode("da-DK");
|
|
|
|
|
var languageNbNo = new LanguageBuilder()
|
|
|
|
|
.WithCultureInfo("nb-NO")
|
|
|
|
|
.WithFallbackLanguageId(languageDaDk.Id)
|
|
|
|
|
.Build();
|
2023-08-16 23:37:10 +02:00
|
|
|
LocalizationService.Save(languageNbNo, -1);
|
2022-06-21 08:09:38 +02:00
|
|
|
var languageId = languageDaDk.Id;
|
|
|
|
|
|
|
|
|
|
LocalizationService.Delete(languageDaDk);
|
|
|
|
|
|
|
|
|
|
var language = LocalizationService.GetLanguageById(languageId);
|
|
|
|
|
Assert.Null(language);
|
|
|
|
|
}
|
2018-07-21 08:24:08 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Can_Create_DictionaryItem_At_Root()
|
|
|
|
|
{
|
|
|
|
|
var english = LocalizationService.GetLanguageByIsoCode("en-US");
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var item = (IDictionaryItem)new DictionaryItem("Testing123")
|
|
|
|
|
{
|
|
|
|
|
Translations = new List<IDictionaryTranslation> { new DictionaryTranslation(english, "Hello world") }
|
|
|
|
|
};
|
|
|
|
|
LocalizationService.Save(item);
|
|
|
|
|
|
|
|
|
|
// re-get
|
|
|
|
|
item = LocalizationService.GetDictionaryItemById(item.Id);
|
|
|
|
|
|
|
|
|
|
Assert.Greater(item.Id, 0);
|
|
|
|
|
Assert.IsTrue(item.HasIdentity);
|
|
|
|
|
Assert.IsFalse(item.ParentId.HasValue);
|
|
|
|
|
Assert.AreEqual("Testing123", item.ItemKey);
|
|
|
|
|
Assert.AreEqual(1, item.Translations.Count());
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Can_Create_DictionaryItem_At_Root_With_Identity()
|
|
|
|
|
{
|
|
|
|
|
var item = LocalizationService.CreateDictionaryItemWithIdentity(
|
|
|
|
|
"Testing12345", null, "Hellooooo");
|
|
|
|
|
|
|
|
|
|
// re-get
|
|
|
|
|
item = LocalizationService.GetDictionaryItemById(item.Id);
|
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(item);
|
|
|
|
|
Assert.Greater(item.Id, 0);
|
|
|
|
|
Assert.IsTrue(item.HasIdentity);
|
|
|
|
|
Assert.IsFalse(item.ParentId.HasValue);
|
|
|
|
|
Assert.AreEqual("Testing12345", item.ItemKey);
|
|
|
|
|
var allLangs = LocalizationService.GetAllLanguages();
|
|
|
|
|
Assert.Greater(allLangs.Count(), 0);
|
|
|
|
|
foreach (var language in allLangs)
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.AreEqual("Hellooooo",
|
|
|
|
|
item.Translations.Single(x => x.Language.CultureName == language.CultureName).Value);
|
2018-06-29 19:52:40 +02:00
|
|
|
}
|
2022-06-21 08:09:38 +02:00
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Can_Add_Translation_To_Existing_Dictionary_Item()
|
|
|
|
|
{
|
|
|
|
|
var english = LocalizationService.GetLanguageByIsoCode("en-US");
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var item = (IDictionaryItem)new DictionaryItem("Testing123");
|
|
|
|
|
LocalizationService.Save(item);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
// re-get
|
|
|
|
|
item = LocalizationService.GetDictionaryItemById(item.Id);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
item.Translations = new List<IDictionaryTranslation> { new DictionaryTranslation(english, "Hello world") };
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
LocalizationService.Save(item);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.AreEqual(1, item.Translations.Count());
|
|
|
|
|
foreach (var translation in item.Translations)
|
|
|
|
|
{
|
|
|
|
|
Assert.AreEqual("Hello world", translation.Value);
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
item.Translations = new List<IDictionaryTranslation>(item.Translations)
|
|
|
|
|
{
|
|
|
|
|
new DictionaryTranslation(
|
|
|
|
|
LocalizationService.GetLanguageByIsoCode("en-GB"),
|
|
|
|
|
"My new value")
|
|
|
|
|
};
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
LocalizationService.Save(item);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
// re-get
|
|
|
|
|
item = LocalizationService.GetDictionaryItemById(item.Id);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.AreEqual(2, item.Translations.Count());
|
|
|
|
|
Assert.AreEqual("Hello world", item.Translations.First().Value);
|
|
|
|
|
Assert.AreEqual("My new value", item.Translations.Last().Value);
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Can_Delete_DictionaryItem()
|
|
|
|
|
{
|
|
|
|
|
var item = LocalizationService.GetDictionaryItemByKey("Child");
|
|
|
|
|
Assert.NotNull(item);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
LocalizationService.Delete(item);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var deletedItem = LocalizationService.GetDictionaryItemByKey("Child");
|
|
|
|
|
Assert.Null(deletedItem);
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Can_Update_Existing_DictionaryItem()
|
|
|
|
|
{
|
|
|
|
|
var item = LocalizationService.GetDictionaryItemByKey("Child");
|
|
|
|
|
foreach (var translation in item.Translations)
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
translation.Value += "UPDATED";
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
LocalizationService.Save(item);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var updatedItem = LocalizationService.GetDictionaryItemByKey("Child");
|
|
|
|
|
Assert.NotNull(updatedItem);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
foreach (var translation in updatedItem.Translations)
|
|
|
|
|
{
|
|
|
|
|
Assert.That(translation.Value.EndsWith("UPDATED"), Is.True);
|
2018-06-29 19:52:40 +02:00
|
|
|
}
|
2022-06-21 08:09:38 +02:00
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Find_BaseData_Language()
|
|
|
|
|
{
|
|
|
|
|
// Act
|
|
|
|
|
var languages = LocalizationService.GetAllLanguages();
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
// Assert
|
|
|
|
|
Assert.That(3, Is.EqualTo(languages.Count()));
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Save_Language_And_GetLanguageByIsoCode()
|
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
var isoCode = "en-AU";
|
|
|
|
|
var languageEnAu = new LanguageBuilder()
|
|
|
|
|
.WithCultureInfo(isoCode)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
LocalizationService.Save(languageEnAu);
|
|
|
|
|
var result = LocalizationService.GetLanguageByIsoCode(isoCode);
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
Assert.NotNull(result);
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Save_Language_And_GetLanguageById()
|
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
var languageEnAu = new LanguageBuilder()
|
|
|
|
|
.WithCultureInfo("en-AU")
|
|
|
|
|
.Build();
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
// Act
|
|
|
|
|
LocalizationService.Save(languageEnAu);
|
|
|
|
|
var result = LocalizationService.GetLanguageById(languageEnAu.Id);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
// Assert
|
|
|
|
|
Assert.NotNull(result);
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Set_Default_Language()
|
|
|
|
|
{
|
|
|
|
|
var languageEnAu = new LanguageBuilder()
|
|
|
|
|
.WithCultureInfo("en-AU")
|
|
|
|
|
.WithIsDefault(true)
|
|
|
|
|
.Build();
|
|
|
|
|
LocalizationService.Save(languageEnAu);
|
|
|
|
|
var result = LocalizationService.GetLanguageById(languageEnAu.Id);
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(result.IsDefault);
|
|
|
|
|
|
|
|
|
|
var languageEnNz = new LanguageBuilder()
|
|
|
|
|
.WithCultureInfo("en-NZ")
|
|
|
|
|
.WithIsDefault(true)
|
|
|
|
|
.Build();
|
|
|
|
|
LocalizationService.Save(languageEnNz);
|
|
|
|
|
var result2 = LocalizationService.GetLanguageById(languageEnNz.Id);
|
|
|
|
|
|
|
|
|
|
// re-get
|
|
|
|
|
result = LocalizationService.GetLanguageById(languageEnAu.Id);
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(result2.IsDefault);
|
|
|
|
|
Assert.IsFalse(result.IsDefault);
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Deleted_Language_Should_Not_Exist()
|
|
|
|
|
{
|
|
|
|
|
var isoCode = "en-AU";
|
|
|
|
|
var languageEnAu = new LanguageBuilder()
|
|
|
|
|
.WithCultureInfo(isoCode)
|
|
|
|
|
.Build();
|
|
|
|
|
LocalizationService.Save(languageEnAu);
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
LocalizationService.Delete(languageEnAu);
|
|
|
|
|
var result = LocalizationService.GetLanguageByIsoCode(isoCode);
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
Assert.Null(result);
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public void CreateTestData()
|
|
|
|
|
{
|
|
|
|
|
var languageDaDk = new LanguageBuilder()
|
|
|
|
|
.WithCultureInfo("da-DK")
|
|
|
|
|
.Build();
|
|
|
|
|
var languageEnGb = new LanguageBuilder()
|
|
|
|
|
.WithCultureInfo("en-GB")
|
|
|
|
|
.Build();
|
|
|
|
|
|
2023-08-16 23:37:10 +02:00
|
|
|
LocalizationService.Save(languageDaDk, -1);
|
|
|
|
|
LocalizationService.Save(languageEnGb, -1);
|
2022-06-21 08:09:38 +02:00
|
|
|
_danishLangId = languageDaDk.Id;
|
|
|
|
|
_englishLangId = languageEnGb.Id;
|
|
|
|
|
|
|
|
|
|
var parentItem = new DictionaryItem("Parent")
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
Translations = new List<IDictionaryTranslation>
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
new DictionaryTranslation(languageEnGb, "ParentValue"),
|
|
|
|
|
new DictionaryTranslation(languageDaDk, "ForældreVærdi")
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
LocalizationService.Save(parentItem);
|
|
|
|
|
_parentItemGuidId = parentItem.Key;
|
|
|
|
|
_parentItemIntId = parentItem.Id;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var childItem = new DictionaryItem(parentItem.Key, "Child")
|
|
|
|
|
{
|
|
|
|
|
Translations = new List<IDictionaryTranslation>
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
new DictionaryTranslation(languageEnGb, "ChildValue"),
|
|
|
|
|
new DictionaryTranslation(languageDaDk, "BørnVærdi")
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
LocalizationService.Save(childItem);
|
|
|
|
|
_childItemGuidId = childItem.Key;
|
|
|
|
|
_childItemIntId = childItem.Id;
|
2018-06-29 19:52:40 +02:00
|
|
|
}
|
|
|
|
|
}
|