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)); } }
protected DictionaryModel Create(string itemKey, DictionaryModel parent, Func <CultureInfo, string> valueResolver) { DictionaryModelWrapper parentModel = parent as DictionaryModelWrapper; // Get the dictionary item from Umbraco. Otherwise crete a new. IDictionaryItem dictionaryItem = _localizationService.GetDictionaryItemByKey(itemKey) ?? _localizationService.CreateDictionaryItemWithIdentity(itemKey, parentModel?.Key); // Create the model DictionaryModelWrapper model = new DictionaryModelWrapper(dictionaryItem, parentModel); // If no value resolver are provided, then return the model if (valueResolver == null) { return(model); } // A save indicator bool save = false; // Iterate through all languages foreach (ILanguage language in Languages) { IDictionaryTranslation translation = dictionaryItem.Translations.SingleOrDefault(x => x.Language == language); // If the dictionary translation already has a value, then don't change it if (!string.IsNullOrEmpty(translation?.Value)) { continue; } // Get the culture specific default value from the value resolver string value = valueResolver(language.CultureInfo); // If there is no value, then do nothing if (value == null) { continue; } // Add the value to the Umbraco dictionary item _localizationService.AddOrUpdateDictionaryValue(dictionaryItem, language, value); // Indicate that a value has been added to the dictionary, and ensure save save = true; // Log the addition Log.Information( $"Adding '{language}' value:'{value}' for dictionary item: '{dictionaryItem.ItemKey}'"); } // Save the dictionary item if (save) { _localizationService.Save(dictionaryItem); } // Return the model return(model); }
public void Can_Serialize_Without_Error() { IDictionaryTranslation item = BuildDictionaryTranslation(); var json = JsonConvert.SerializeObject(item); Debug.Print(json); }
public static DictTrans ToDictTrans(this IDictionaryTranslation trans) { return(new DictTrans() { Id = trans.Id, Key = trans.Key, Language = trans.Language.ToDictLang(), Value = trans.Value }); }
private void AssertDictionaryItem(string dictionaryItemName, string expectedValue, string cultureCode) { Assert.That(LocalizationService.DictionaryItemExists(dictionaryItemName), "DictionaryItem key does not exist"); IDictionaryItem dictionaryItem = LocalizationService.GetDictionaryItemByKey(dictionaryItemName); IDictionaryTranslation translation = dictionaryItem.Translations.SingleOrDefault(i => i.Language.IsoCode == cultureCode); Assert.IsNotNull(translation, "Translation to {0} was not added", cultureCode); string value = translation.Value; Assert.That(value, Is.EqualTo(expectedValue), "Translation value was not set"); }
public static LanguageTextDto BuildDto(IDictionaryTranslation entity, Guid uniqueId) { var text = new LanguageTextDto { LanguageId = entity.LanguageId, UniqueId = uniqueId, Value = entity.Value }; if (entity.HasIdentity) { text.PrimaryKey = entity.Id; } return(text); }