From fb5faa3db7a895153fd635ed037e8ca1dd2d0cf4 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 7 Jan 2016 18:59:59 +0100 Subject: [PATCH] Fixes tests, adds LanguageId to the interface --- src/Umbraco.Core/Models/IDictionaryTranslation.cs | 2 ++ .../Persistence/Factories/DictionaryItemFactory.cs | 2 +- .../Persistence/Factories/DictionaryTranslationFactory.cs | 2 +- .../Persistence/Repositories/DictionaryRepository.cs | 5 ++++- src/Umbraco.Core/Services/LocalizationService.cs | 1 - src/Umbraco.Tests/Models/DictionaryTranslationTests.cs | 8 ++++++-- .../Persistence/Repositories/DictionaryRepositoryTest.cs | 6 +++--- 7 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/Umbraco.Core/Models/IDictionaryTranslation.cs b/src/Umbraco.Core/Models/IDictionaryTranslation.cs index cf813bf72f..25aa1e4395 100644 --- a/src/Umbraco.Core/Models/IDictionaryTranslation.cs +++ b/src/Umbraco.Core/Models/IDictionaryTranslation.cs @@ -12,6 +12,8 @@ namespace Umbraco.Core.Models [DataMember] ILanguage Language { get; set; } + int LanguageId { get; } + /// /// Gets or sets the translated text /// diff --git a/src/Umbraco.Core/Persistence/Factories/DictionaryItemFactory.cs b/src/Umbraco.Core/Persistence/Factories/DictionaryItemFactory.cs index 14dca6b366..1b9d73bdd4 100644 --- a/src/Umbraco.Core/Persistence/Factories/DictionaryItemFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/DictionaryItemFactory.cs @@ -42,7 +42,7 @@ namespace Umbraco.Core.Persistence.Factories { var text = new LanguageTextDto { - LanguageId = translation.Language.Id, + LanguageId = translation.LanguageId, UniqueId = translation.Key, Value = translation.Value }; diff --git a/src/Umbraco.Core/Persistence/Factories/DictionaryTranslationFactory.cs b/src/Umbraco.Core/Persistence/Factories/DictionaryTranslationFactory.cs index 635722e78d..65297b9529 100644 --- a/src/Umbraco.Core/Persistence/Factories/DictionaryTranslationFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/DictionaryTranslationFactory.cs @@ -30,7 +30,7 @@ namespace Umbraco.Core.Persistence.Factories { var text = new LanguageTextDto { - LanguageId = entity.Language.Id, + LanguageId = entity.LanguageId, UniqueId = _uniqueId, Value = entity.Value }; diff --git a/src/Umbraco.Core/Persistence/Repositories/DictionaryRepository.cs b/src/Umbraco.Core/Persistence/Repositories/DictionaryRepository.cs index dde25ddac6..971efc4f2d 100644 --- a/src/Umbraco.Core/Persistence/Repositories/DictionaryRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/DictionaryRepository.cs @@ -223,7 +223,10 @@ namespace Umbraco.Core.Persistence.Repositories var list = new List(); foreach (var textDto in dto.LanguageTextDtos) - { + { + if (textDto.LanguageId <= 0) + continue; + var translationFactory = new DictionaryTranslationFactory(dto.UniqueId); list.Add(translationFactory.BuildEntity(textDto)); } diff --git a/src/Umbraco.Core/Services/LocalizationService.cs b/src/Umbraco.Core/Services/LocalizationService.cs index a9e6eb7cce..261db8672b 100644 --- a/src/Umbraco.Core/Services/LocalizationService.cs +++ b/src/Umbraco.Core/Services/LocalizationService.cs @@ -376,7 +376,6 @@ namespace Umbraco.Core.Services /// private void EnsureDictionaryItemLanguageCallback(IDictionaryItem d) { - if (d == null) throw new ArgumentNullException("d"); var item = d as DictionaryItem; if (item == null) return; diff --git a/src/Umbraco.Tests/Models/DictionaryTranslationTests.cs b/src/Umbraco.Tests/Models/DictionaryTranslationTests.cs index d0a8c21581..46d6ea1022 100644 --- a/src/Umbraco.Tests/Models/DictionaryTranslationTests.cs +++ b/src/Umbraco.Tests/Models/DictionaryTranslationTests.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Serialization; @@ -36,12 +37,15 @@ namespace Umbraco.Tests.Models Assert.AreEqual(clone.Key, item.Key); Assert.AreEqual(clone.UpdateDate, item.UpdateDate); Assert.AreNotSame(clone.Language, item.Language); - Assert.AreEqual(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 var allProps = clone.GetType().GetProperties(); - foreach (var propertyInfo in allProps) + foreach (var propertyInfo in allProps.Where(x => x.Name != "Language")) { Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(item, null)); } diff --git a/src/Umbraco.Tests/Persistence/Repositories/DictionaryRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/DictionaryRepositoryTest.cs index f992495263..6b56181eac 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/DictionaryRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/DictionaryRepositoryTest.cs @@ -318,12 +318,12 @@ namespace Umbraco.Tests.Persistence.Repositories repository.AddOrUpdate(item); unitOfWork.Commit(); - var dictionaryItem = repository.Get(1); - + var dictionaryItem = (DictionaryItem)repository.Get(1); + // Assert Assert.That(dictionaryItem, Is.Not.Null); Assert.That(dictionaryItem.Translations.Count(), Is.EqualTo(3)); - Assert.That(dictionaryItem.Translations.Single(t => t.Language.IsoCode == "nb-NO").Value, Is.EqualTo("Les mer")); + Assert.That(dictionaryItem.Translations.Single(t => t.LanguageId == languageNo.Id).Value, Is.EqualTo("Les mer")); } [Test]