2014-06-08 12:57:24 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2015-07-22 12:10:21 +02:00
|
|
|
|
using System.Diagnostics;
|
2014-06-08 12:57:24 +02:00
|
|
|
|
using System.Linq;
|
2018-03-30 19:31:42 +02:00
|
|
|
|
using System.Threading;
|
2014-06-08 12:57:24 +02:00
|
|
|
|
using NUnit.Framework;
|
2015-01-12 18:52:30 +11:00
|
|
|
|
using Umbraco.Core;
|
2014-06-08 12:57:24 +02:00
|
|
|
|
using Umbraco.Core.Models;
|
2014-03-17 19:44:34 +11:00
|
|
|
|
using Umbraco.Tests.TestHelpers;
|
2016-12-16 10:40:14 +01:00
|
|
|
|
using Umbraco.Tests.Testing;
|
2016-12-16 14:18:37 +01:00
|
|
|
|
using Umbraco.Core.Persistence;
|
2013-11-07 17:16:22 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Tests.Services
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <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>
|
2018-03-30 19:31:42 +02:00
|
|
|
|
[TestFixture]
|
|
|
|
|
|
[Apartment(ApartmentState.STA)]
|
2016-11-05 19:23:55 +01:00
|
|
|
|
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
|
|
|
|
|
public class LocalizationServiceTests : TestWithSomeContentBase
|
2013-11-07 17:16:22 +01:00
|
|
|
|
{
|
2014-06-08 12:57:24 +02:00
|
|
|
|
private Guid _parentItemGuidId;
|
|
|
|
|
|
private int _parentItemIntId;
|
|
|
|
|
|
private Guid _childItemGuidId;
|
|
|
|
|
|
private int _childItemIntId;
|
|
|
|
|
|
private int _danishLangId;
|
|
|
|
|
|
private int _englishLangId;
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2015-01-12 18:52:30 +11:00
|
|
|
|
public void Can_Get_Root_Dictionary_Items()
|
2014-06-08 12:57:24 +02:00
|
|
|
|
{
|
|
|
|
|
|
var rootItems = ServiceContext.LocalizationService.GetRootDictionaryItems();
|
|
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(rootItems);
|
|
|
|
|
|
Assert.IsTrue(rootItems.Any());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2015-01-12 18:52:30 +11:00
|
|
|
|
public void Can_Determint_If_DictionaryItem_Exists()
|
2014-06-08 12:57:24 +02:00
|
|
|
|
{
|
|
|
|
|
|
var exists = ServiceContext.LocalizationService.DictionaryItemExists("Parent");
|
|
|
|
|
|
Assert.IsTrue(exists);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2015-01-12 18:52:30 +11:00
|
|
|
|
public void Can_Get_All_Languages()
|
2014-06-08 12:57:24 +02:00
|
|
|
|
{
|
|
|
|
|
|
var languages = ServiceContext.LocalizationService.GetAllLanguages();
|
|
|
|
|
|
Assert.NotNull(languages);
|
|
|
|
|
|
Assert.IsTrue(languages.Any());
|
|
|
|
|
|
Assert.That(languages.Count(), Is.EqualTo(3));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2015-01-12 18:52:30 +11:00
|
|
|
|
public void Can_Get_Dictionary_Item_By_Int_Id()
|
2014-06-08 12:57:24 +02:00
|
|
|
|
{
|
|
|
|
|
|
var parentItem = ServiceContext.LocalizationService.GetDictionaryItemById(_parentItemIntId);
|
|
|
|
|
|
Assert.NotNull(parentItem);
|
|
|
|
|
|
|
|
|
|
|
|
var childItem = ServiceContext.LocalizationService.GetDictionaryItemById(_childItemIntId);
|
|
|
|
|
|
Assert.NotNull(childItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2015-01-12 18:52:30 +11:00
|
|
|
|
public void Can_Get_Dictionary_Item_By_Guid_Id()
|
2014-06-08 12:57:24 +02:00
|
|
|
|
{
|
|
|
|
|
|
var parentItem = ServiceContext.LocalizationService.GetDictionaryItemById(_parentItemGuidId);
|
|
|
|
|
|
Assert.NotNull(parentItem);
|
|
|
|
|
|
|
|
|
|
|
|
var childItem = ServiceContext.LocalizationService.GetDictionaryItemById(_childItemGuidId);
|
|
|
|
|
|
Assert.NotNull(childItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2015-01-12 18:52:30 +11:00
|
|
|
|
public void Can_Get_Dictionary_Item_By_Key()
|
2014-06-08 12:57:24 +02:00
|
|
|
|
{
|
|
|
|
|
|
var parentItem = ServiceContext.LocalizationService.GetDictionaryItemByKey("Parent");
|
|
|
|
|
|
Assert.NotNull(parentItem);
|
|
|
|
|
|
|
|
|
|
|
|
var childItem = ServiceContext.LocalizationService.GetDictionaryItemByKey("Child");
|
|
|
|
|
|
Assert.NotNull(childItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2015-01-12 18:52:30 +11:00
|
|
|
|
public void Can_Get_Dictionary_Item_Children()
|
2014-06-08 12:57:24 +02:00
|
|
|
|
{
|
|
|
|
|
|
var item = ServiceContext.LocalizationService.GetDictionaryItemChildren(_parentItemGuidId);
|
|
|
|
|
|
Assert.NotNull(item);
|
|
|
|
|
|
Assert.That(item.Count(), Is.EqualTo(1));
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var dictionaryItem in item)
|
|
|
|
|
|
{
|
2015-02-03 14:41:43 +11:00
|
|
|
|
Assert.AreEqual(_parentItemGuidId, dictionaryItem.ParentId);
|
2014-06-08 12:57:24 +02:00
|
|
|
|
Assert.IsFalse(string.IsNullOrEmpty(dictionaryItem.ItemKey));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2015-07-22 12:10:21 +02:00
|
|
|
|
public void Can_Get_Dictionary_Item_Descendants()
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var scope = ScopeProvider.CreateScope())
|
2015-07-22 12:10:21 +02:00
|
|
|
|
{
|
|
|
|
|
|
var en = ServiceContext.LocalizationService.GetLanguageById(_englishLangId);
|
|
|
|
|
|
var dk = ServiceContext.LocalizationService.GetLanguageById(_danishLangId);
|
|
|
|
|
|
|
|
|
|
|
|
var currParentId = _childItemGuidId;
|
|
|
|
|
|
for (int i = 0; i < 25; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
//Create 2 per level
|
|
|
|
|
|
var desc1 = new DictionaryItem(currParentId, "D1" + i)
|
|
|
|
|
|
{
|
|
|
|
|
|
Translations = new List<IDictionaryTranslation>
|
|
|
|
|
|
{
|
|
|
|
|
|
new DictionaryTranslation(en, "ChildValue1 " + i),
|
|
|
|
|
|
new DictionaryTranslation(dk, "BørnVærdi1 " + i)
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
var desc2 = new DictionaryItem(currParentId, "D2" + i)
|
|
|
|
|
|
{
|
|
|
|
|
|
Translations = new List<IDictionaryTranslation>
|
|
|
|
|
|
{
|
|
|
|
|
|
new DictionaryTranslation(en, "ChildValue2 " + i),
|
|
|
|
|
|
new DictionaryTranslation(dk, "BørnVærdi2 " + i)
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
ServiceContext.LocalizationService.Save(desc1);
|
|
|
|
|
|
ServiceContext.LocalizationService.Save(desc2);
|
|
|
|
|
|
|
|
|
|
|
|
currParentId = desc1.Key;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-05-12 14:49:44 +02:00
|
|
|
|
scope.Database.AsUmbracoDatabase().EnableSqlTrace = true;
|
|
|
|
|
|
scope.Database.AsUmbracoDatabase().EnableSqlCount = true;
|
2015-07-22 12:10:21 +02:00
|
|
|
|
|
|
|
|
|
|
var items = ServiceContext.LocalizationService.GetDictionaryItemDescendants(_parentItemGuidId)
|
|
|
|
|
|
.ToArray();
|
|
|
|
|
|
|
2017-05-12 14:49:44 +02:00
|
|
|
|
Debug.WriteLine("SQL CALLS: " + scope.Database.AsUmbracoDatabase().SqlCount);
|
2015-07-22 12:10:21 +02:00
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(51, items.Length);
|
|
|
|
|
|
//there's a call or two to get languages, so apart from that there should only be one call per level
|
2017-05-12 14:49:44 +02:00
|
|
|
|
Assert.Less(scope.Database.AsUmbracoDatabase().SqlCount, 30);
|
2015-07-22 12:10:21 +02:00
|
|
|
|
}
|
2018-04-24 15:59:16 +10:00
|
|
|
|
}
|
2014-06-08 12:57:24 +02:00
|
|
|
|
|
|
|
|
|
|
[Test]
|
2015-01-12 18:52:30 +11:00
|
|
|
|
public void Can_GetLanguageById()
|
2014-06-08 12:57:24 +02:00
|
|
|
|
{
|
|
|
|
|
|
var danish = ServiceContext.LocalizationService.GetLanguageById(_danishLangId);
|
|
|
|
|
|
var english = ServiceContext.LocalizationService.GetLanguageById(_englishLangId);
|
|
|
|
|
|
Assert.NotNull(danish);
|
|
|
|
|
|
Assert.NotNull(english);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2015-01-12 18:52:30 +11:00
|
|
|
|
public void Can_GetLanguageByIsoCode()
|
2014-06-08 12:57:24 +02:00
|
|
|
|
{
|
|
|
|
|
|
var danish = ServiceContext.LocalizationService.GetLanguageByIsoCode("da-DK");
|
|
|
|
|
|
var english = ServiceContext.LocalizationService.GetLanguageByIsoCode("en-GB");
|
|
|
|
|
|
Assert.NotNull(danish);
|
|
|
|
|
|
Assert.NotNull(english);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2015-01-12 18:52:30 +11:00
|
|
|
|
public void Does_Not_Fail_When_Language_Doesnt_Exist()
|
2014-06-08 12:57:24 +02:00
|
|
|
|
{
|
|
|
|
|
|
var language = ServiceContext.LocalizationService.GetLanguageByIsoCode("sv-SE");
|
|
|
|
|
|
Assert.Null(language);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2015-01-12 18:52:30 +11:00
|
|
|
|
public void Does_Not_Fail_When_DictionaryItem_Doesnt_Exist()
|
2014-06-08 12:57:24 +02:00
|
|
|
|
{
|
|
|
|
|
|
var item = ServiceContext.LocalizationService.GetDictionaryItemByKey("RandomKey");
|
|
|
|
|
|
Assert.Null(item);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2015-01-12 18:52:30 +11:00
|
|
|
|
public void Can_Delete_Language()
|
2014-06-08 12:57:24 +02:00
|
|
|
|
{
|
|
|
|
|
|
var norwegian = new Language("nb-NO") { CultureName = "Norwegian" };
|
|
|
|
|
|
ServiceContext.LocalizationService.Save(norwegian, 0);
|
|
|
|
|
|
Assert.That(norwegian.HasIdentity, Is.True);
|
|
|
|
|
|
var languageId = norwegian.Id;
|
|
|
|
|
|
|
|
|
|
|
|
ServiceContext.LocalizationService.Delete(norwegian);
|
|
|
|
|
|
|
|
|
|
|
|
var language = ServiceContext.LocalizationService.GetLanguageById(languageId);
|
|
|
|
|
|
Assert.Null(language);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2015-01-12 18:52:30 +11:00
|
|
|
|
public void Can_Create_DictionaryItem_At_Root()
|
|
|
|
|
|
{
|
|
|
|
|
|
var english = ServiceContext.LocalizationService.GetLanguageByIsoCode("en-US");
|
|
|
|
|
|
|
|
|
|
|
|
var item = (IDictionaryItem)new DictionaryItem("Testing123")
|
|
|
|
|
|
{
|
|
|
|
|
|
Translations = new List<IDictionaryTranslation>
|
|
|
|
|
|
{
|
|
|
|
|
|
new DictionaryTranslation(english, "Hello world")
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
ServiceContext.LocalizationService.Save(item);
|
|
|
|
|
|
|
|
|
|
|
|
//re-get
|
|
|
|
|
|
item = ServiceContext.LocalizationService.GetDictionaryItemById(item.Id);
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Greater(item.Id, 0);
|
|
|
|
|
|
Assert.IsTrue(item.HasIdentity);
|
2015-07-02 17:19:42 +02:00
|
|
|
|
Assert.IsFalse(item.ParentId.HasValue);
|
2015-01-12 18:52:30 +11:00
|
|
|
|
Assert.AreEqual("Testing123", item.ItemKey);
|
|
|
|
|
|
Assert.AreEqual(1, item.Translations.Count());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void Can_Create_DictionaryItem_At_Root_With_Identity()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
var item = ServiceContext.LocalizationService.CreateDictionaryItemWithIdentity(
|
|
|
|
|
|
"Testing12345", null, "Hellooooo");
|
|
|
|
|
|
|
2015-01-12 19:39:30 +11:00
|
|
|
|
//re-get
|
|
|
|
|
|
item = ServiceContext.LocalizationService.GetDictionaryItemById(item.Id);
|
|
|
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(item);
|
2015-01-12 18:52:30 +11:00
|
|
|
|
Assert.Greater(item.Id, 0);
|
|
|
|
|
|
Assert.IsTrue(item.HasIdentity);
|
2015-07-02 17:19:42 +02:00
|
|
|
|
Assert.IsFalse(item.ParentId.HasValue);
|
2015-01-12 18:52:30 +11:00
|
|
|
|
Assert.AreEqual("Testing12345", item.ItemKey);
|
|
|
|
|
|
var allLangs = ServiceContext.LocalizationService.GetAllLanguages();
|
|
|
|
|
|
Assert.Greater(allLangs.Count(), 0);
|
|
|
|
|
|
foreach (var language in allLangs)
|
|
|
|
|
|
{
|
2017-07-20 11:21:28 +02:00
|
|
|
|
Assert.AreEqual("Hellooooo", item.Translations.Single(x => x.Language.CultureName == language.CultureName).Value);
|
2015-01-12 18:52:30 +11:00
|
|
|
|
}
|
2017-07-20 11:21:28 +02:00
|
|
|
|
|
2015-01-12 18:52:30 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void Can_Add_Translation_To_Existing_Dictionary_Item()
|
|
|
|
|
|
{
|
|
|
|
|
|
var english = ServiceContext.LocalizationService.GetLanguageByIsoCode("en-US");
|
|
|
|
|
|
|
2015-01-12 19:39:30 +11:00
|
|
|
|
var item = (IDictionaryItem) new DictionaryItem("Testing123");
|
2015-01-12 18:52:30 +11:00
|
|
|
|
ServiceContext.LocalizationService.Save(item);
|
|
|
|
|
|
|
|
|
|
|
|
//re-get
|
|
|
|
|
|
item = ServiceContext.LocalizationService.GetDictionaryItemById(item.Id);
|
|
|
|
|
|
|
2015-01-12 19:39:30 +11:00
|
|
|
|
item.Translations = new List<IDictionaryTranslation>
|
|
|
|
|
|
{
|
|
|
|
|
|
new DictionaryTranslation(english, "Hello world")
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ServiceContext.LocalizationService.Save(item);
|
|
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(1, item.Translations.Count());
|
|
|
|
|
|
foreach (var translation in item.Translations)
|
|
|
|
|
|
{
|
|
|
|
|
|
Assert.AreEqual("Hello world", translation.Value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
item.Translations = new List<IDictionaryTranslation>(item.Translations)
|
2015-01-12 18:52:30 +11:00
|
|
|
|
{
|
|
|
|
|
|
new DictionaryTranslation(
|
|
|
|
|
|
ServiceContext.LocalizationService.GetLanguageByIsoCode("en-GB"),
|
|
|
|
|
|
"My new value")
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ServiceContext.LocalizationService.Save(item);
|
2015-01-12 19:39:30 +11:00
|
|
|
|
|
2015-01-12 18:52:30 +11:00
|
|
|
|
//re-get
|
|
|
|
|
|
item = ServiceContext.LocalizationService.GetDictionaryItemById(item.Id);
|
|
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(2, item.Translations.Count());
|
2015-01-12 19:39:30 +11:00
|
|
|
|
Assert.AreEqual("Hello world", item.Translations.First().Value);
|
|
|
|
|
|
Assert.AreEqual("My new value", item.Translations.Last().Value);
|
2015-01-12 18:52:30 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void Can_Delete_DictionaryItem()
|
2014-06-08 12:57:24 +02:00
|
|
|
|
{
|
|
|
|
|
|
var item = ServiceContext.LocalizationService.GetDictionaryItemByKey("Child");
|
|
|
|
|
|
Assert.NotNull(item);
|
|
|
|
|
|
|
|
|
|
|
|
ServiceContext.LocalizationService.Delete(item);
|
|
|
|
|
|
|
|
|
|
|
|
var deletedItem = ServiceContext.LocalizationService.GetDictionaryItemByKey("Child");
|
|
|
|
|
|
Assert.Null(deletedItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2015-01-12 18:52:30 +11:00
|
|
|
|
public void Can_Update_Existing_DictionaryItem()
|
2014-06-08 12:57:24 +02:00
|
|
|
|
{
|
|
|
|
|
|
var item = ServiceContext.LocalizationService.GetDictionaryItemByKey("Child");
|
|
|
|
|
|
foreach (var translation in item.Translations)
|
|
|
|
|
|
{
|
|
|
|
|
|
translation.Value = translation.Value + "UPDATED";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ServiceContext.LocalizationService.Save(item);
|
|
|
|
|
|
|
|
|
|
|
|
var updatedItem = ServiceContext.LocalizationService.GetDictionaryItemByKey("Child");
|
|
|
|
|
|
Assert.NotNull(updatedItem);
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var translation in updatedItem.Translations)
|
|
|
|
|
|
{
|
|
|
|
|
|
Assert.That(translation.Value.EndsWith("UPDATED"), Is.True);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-10-03 12:51:27 +10:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Find_BaseData_Language()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
|
|
|
|
|
var localizationService = ServiceContext.LocalizationService;
|
2017-07-20 11:21:28 +02:00
|
|
|
|
|
2014-10-03 12:51:27 +10:00
|
|
|
|
// Act
|
|
|
|
|
|
var languages = localizationService.GetAllLanguages();
|
|
|
|
|
|
|
2017-07-20 11:21:28 +02:00
|
|
|
|
// Assert
|
2014-10-03 12:51:27 +10:00
|
|
|
|
Assert.That(3, Is.EqualTo(languages.Count()));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void Save_Language_And_GetLanguageByIsoCode()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
|
|
|
|
|
var localizationService = ServiceContext.LocalizationService;
|
|
|
|
|
|
var isoCode = "en-AU";
|
|
|
|
|
|
var language = new Core.Models.Language(isoCode);
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
localizationService.Save(language);
|
|
|
|
|
|
var result = localizationService.GetLanguageByIsoCode(isoCode);
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.NotNull(result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void Save_Language_And_GetLanguageById()
|
|
|
|
|
|
{
|
|
|
|
|
|
var localizationService = ServiceContext.LocalizationService;
|
|
|
|
|
|
var isoCode = "en-AU";
|
|
|
|
|
|
var language = new Core.Models.Language(isoCode);
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
localizationService.Save(language);
|
|
|
|
|
|
var result = localizationService.GetLanguageById(language.Id);
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.NotNull(result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-22 23:15:52 +11:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Set_Default_Language()
|
|
|
|
|
|
{
|
|
|
|
|
|
var localizationService = ServiceContext.LocalizationService;
|
|
|
|
|
|
var language = new Core.Models.Language("en-AU");
|
|
|
|
|
|
language.IsDefaultVariantLanguage = true;
|
|
|
|
|
|
localizationService.Save(language);
|
|
|
|
|
|
var result = localizationService.GetLanguageById(language.Id);
|
|
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(result.IsDefaultVariantLanguage);
|
|
|
|
|
|
|
|
|
|
|
|
var language2 = new Core.Models.Language("en-NZ");
|
|
|
|
|
|
language2.IsDefaultVariantLanguage = true;
|
|
|
|
|
|
localizationService.Save(language2);
|
|
|
|
|
|
var result2 = localizationService.GetLanguageById(language2.Id);
|
|
|
|
|
|
//re-get
|
|
|
|
|
|
result = localizationService.GetLanguageById(language.Id);
|
|
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(result2.IsDefaultVariantLanguage);
|
|
|
|
|
|
Assert.IsFalse(result.IsDefaultVariantLanguage);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-10-03 12:51:27 +10:00
|
|
|
|
[Test]
|
|
|
|
|
|
public void Deleted_Language_Should_Not_Exist()
|
|
|
|
|
|
{
|
|
|
|
|
|
var localizationService = ServiceContext.LocalizationService;
|
|
|
|
|
|
var isoCode = "en-AU";
|
|
|
|
|
|
var language = new Core.Models.Language(isoCode);
|
|
|
|
|
|
localizationService.Save(language);
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
localizationService.Delete(language);
|
|
|
|
|
|
var result = localizationService.GetLanguageByIsoCode(isoCode);
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.Null(result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-12 18:52:30 +11:00
|
|
|
|
public override void CreateTestData()
|
|
|
|
|
|
{
|
|
|
|
|
|
var danish = new Language("da-DK") { CultureName = "Danish" };
|
|
|
|
|
|
var english = new Language("en-GB") { CultureName = "English" };
|
|
|
|
|
|
ServiceContext.LocalizationService.Save(danish, 0);
|
|
|
|
|
|
ServiceContext.LocalizationService.Save(english, 0);
|
|
|
|
|
|
_danishLangId = danish.Id;
|
|
|
|
|
|
_englishLangId = english.Id;
|
|
|
|
|
|
|
|
|
|
|
|
var parentItem = new DictionaryItem("Parent")
|
|
|
|
|
|
{
|
|
|
|
|
|
Translations = new List<IDictionaryTranslation>
|
|
|
|
|
|
{
|
|
|
|
|
|
new DictionaryTranslation(english, "ParentValue"),
|
|
|
|
|
|
new DictionaryTranslation(danish, "ForældreVærdi")
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
ServiceContext.LocalizationService.Save(parentItem);
|
|
|
|
|
|
_parentItemGuidId = parentItem.Key;
|
|
|
|
|
|
_parentItemIntId = parentItem.Id;
|
|
|
|
|
|
|
|
|
|
|
|
var childItem = new DictionaryItem(parentItem.Key, "Child")
|
|
|
|
|
|
{
|
|
|
|
|
|
Translations = new List<IDictionaryTranslation>
|
|
|
|
|
|
{
|
|
|
|
|
|
new DictionaryTranslation(english, "ChildValue"),
|
|
|
|
|
|
new DictionaryTranslation(danish, "BørnVærdi")
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
ServiceContext.LocalizationService.Save(childItem);
|
|
|
|
|
|
_childItemGuidId = childItem.Key;
|
|
|
|
|
|
_childItemIntId = childItem.Id;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-11-07 17:16:22 +01:00
|
|
|
|
}
|
2017-07-20 11:21:28 +02:00
|
|
|
|
}
|