public void Equals_Null_False() { MultiTextBase x = new MultiTextBase(); x["ws"] = "test"; Assert.IsFalse(x.Equals(null)); }
public void SerializeEmptyWithXmlSerializer() { MultiTextBase text = new MultiTextBase(); var answerXpath = "/TestMultiTextHolder[namespace::xsd='http://www.w3.org/2001/XMLSchema' and namespace::xsi='http://www.w3.org/2001/XMLSchema-instance']/name"; CheckSerializeWithXmlSerializer(text, answerXpath, 1); }
public void GetOrderedAndFilteredForms_EmptyMultiText_GivesEmptyList() { MultiTextBase x = new MultiTextBase(); LanguageForm[] forms = x.GetOrderedAndFilteredForms(new string[] { "one", "three" }); Assert.AreEqual(0, forms.Length); }
public void GetEnumerator() { MultiTextBase text = new MultiTextBase(); IEnumerator ienumerator = text.GetEnumerator(); Assert.IsNotNull(ienumerator); }
public void IterateWithForEach() { MultiTextBase text = new MultiTextBase(); text["a"] = "alpha"; text["b"] = "beta"; text["g"] = "gamma"; int i = 0; foreach (LanguageForm l in text) { switch (i) { case 0: Assert.AreEqual("a", l.WritingSystemId); Assert.AreEqual("alpha", l.Form); break; case 1: Assert.AreEqual("b", l.WritingSystemId); Assert.AreEqual("beta", l.Form); break; case 2: Assert.AreEqual("g", l.WritingSystemId); Assert.AreEqual("gamma", l.Form); break; } i++; } }
public void AnnotationOfMisssingAlternative() { MultiTextBase multiTextBase = new MultiTextBase(); Assert.IsFalse(multiTextBase.GetAnnotationOfAlternativeIsStarred("zz")); Assert.IsFalse(multiTextBase.ContainsAlternative("zz"), "should not cause the creation of the alt"); }
/// <summary> Adds each sense of a word to be written out to lift </summary> private void AddSenses(LexEntry entry, Word wordEntry) { for (var i = 0; i < wordEntry.Senses.Count; i++) { // Merge in senses var dict = new Dictionary <string, string>(); foreach (var gloss in wordEntry.Senses[i].Glosses) { dict.Add(gloss.Language, gloss.Def); } var lexSense = new LexSense(); lexSense.Gloss.MergeIn(MultiTextBase.Create(dict)); entry.Senses.Add(lexSense); // Merge in semantic domains foreach (var semdom in wordEntry.Senses[i].SemanticDomains) { var orc = new OptionRefCollection(); orc.Add(semdom.Id + " " + semdom.Name); entry.Senses[i].Properties.Add( new KeyValuePair <string, IPalasoDataObjectProperty>("semantic-domain-ddp4", orc)); } } }
private void WriteMultiTextNoWrapper(string propertyName, MultiText text) // review cp see WriteEmbeddedXmlCollection { if (!MultiTextBase.IsEmpty(text)) { AddMultitextForms(propertyName, text); } }
public void GetOrderedAndFilteredForms_EmptyIdList_GivesEmptyList() { MultiTextBase x = new MultiTextBase(); x["one"] = "test"; Assert.AreEqual(0, x.GetOrderedAndFilteredForms(new string[] { }).Length); }
public void ClearingAnnotationOfEmptyAlternativeRemovesTheAlternative() { MultiTextBase multiTextBase = new MultiTextBase(); multiTextBase.SetAnnotationOfAlternativeIsStarred("zz", true); multiTextBase.SetAnnotationOfAlternativeIsStarred("zz", false); Assert.IsFalse(multiTextBase.ContainsAlternative("zz")); }
public void HasFormWithSameContent_BothEmpty_True() { MultiTextBase x = new MultiTextBase(); MultiTextBase y = new MultiTextBase(); Assert.IsTrue(x.HasFormWithSameContent(y)); Assert.IsTrue(y.HasFormWithSameContent(x)); }
public void CompareTo_MultiTextWithMoreForms_ReturnsLess() { MultiTextBase multiTextBase = new MultiTextBase(); MultiTextBase multiTextBaseToCompare = new MultiTextBase(); multiTextBaseToCompare.SetAlternative("de", "Word 1"); Assert.AreEqual(-1, multiTextBase.CompareTo(multiTextBaseToCompare)); }
public void ClearingAnnotationOfNonEmptyAlternative() { MultiTextBase multiTextBase = new MultiTextBase(); multiTextBase.SetAnnotationOfAlternativeIsStarred("zz", true); multiTextBase["zz"] = "hello"; multiTextBase.SetAnnotationOfAlternativeIsStarred("zz", false); Assert.IsTrue(multiTextBase.ContainsAlternative("zz")); }
public void AddLanguageString(string key, string value, string writingSystemId, bool isCollectionValue) { if (!TextVariables.ContainsKey(key)) { var text = new MultiTextBase(); TextVariables.Add(key, new NamedMutliLingualValue(text, isCollectionValue)); } TextVariables[key].TextAlternatives.SetAlternative(writingSystemId, value); }
public void CompareTo_MultiTextWithFewerForms_ReturnsGreater() { MultiTextBase multiTextBase = new MultiTextBase(); multiTextBase.SetAlternative("de", "Word 1"); MultiTextBase multiTextBaseToCompare = new MultiTextBase(); Assert.AreEqual(1, multiTextBase.CompareTo(multiTextBaseToCompare)); }
public void HasFormWithSameContent_Identity_True() { MultiTextBase x = new MultiTextBase(); x["ws1"] = "testing"; x["ws"] = "test"; x["ws2"] = "testing"; Assert.IsTrue(x.HasFormWithSameContent(x)); }
public void SetAnnotation() { MultiTextBase multiTextBase = new MultiTextBase(); multiTextBase.SetAnnotationOfAlternativeIsStarred("zz", true); Assert.AreEqual(String.Empty, multiTextBase.GetExactAlternative("zz")); Assert.IsTrue(multiTextBase.GetAnnotationOfAlternativeIsStarred("zz")); multiTextBase.SetAnnotationOfAlternativeIsStarred("zz", false); Assert.IsFalse(multiTextBase.GetAnnotationOfAlternativeIsStarred("zz")); }
public void EmptyingTextOfFlaggedAlternativeDoesNotDeleteIfFlagged() { // REVIEW: not clear really what behavior we want here, since user deletes via clearing text MultiTextBase multiTextBase = new MultiTextBase(); multiTextBase["zz"] = "hello"; multiTextBase.SetAnnotationOfAlternativeIsStarred("zz", true); multiTextBase["zz"] = ""; Assert.IsTrue(multiTextBase.ContainsAlternative("zz")); }
public void Count() { MultiTextBase text = new MultiTextBase(); Assert.AreEqual(0, text.Count); text["a"] = "alpha"; text["b"] = "beta"; text["g"] = "gamma"; Assert.AreEqual(3, text.Count); }
public void CompareTo_IdenticalMultiText_ReturnsEqual() { MultiTextBase multiTextBase = new MultiTextBase(); multiTextBase.SetAlternative("de", "Word 1"); MultiTextBase multiTextBaseToCompare = new MultiTextBase(); multiTextBaseToCompare.SetAlternative("de", "Word 1"); Assert.AreEqual(0, multiTextBase.CompareTo(multiTextBaseToCompare)); }
public void CompareTo_MultiTextWithNonIdenticalFormsAndFirstNonidenticalformIsAlphabeticallyLater_ReturnsLess() { MultiTextBase multiTextBase = new MultiTextBase(); multiTextBase.SetAlternative("de", "Word 1"); MultiTextBase multiTextBaseToCompare = new MultiTextBase(); multiTextBaseToCompare.SetAlternative("de", "Word 2"); Assert.AreEqual(-1, multiTextBase.CompareTo(multiTextBaseToCompare)); }
public void CompareTo_MultiTextWithNonIdenticalWritingSystemsAndFirstNonidenticalWritingSystemIsAlphabeticallyEarlier_ReturnsGreater() { MultiTextBase multiTextBase = new MultiTextBase(); multiTextBase.SetAlternative("en", "Word 1"); MultiTextBase multiTextBaseToCompare = new MultiTextBase(); multiTextBaseToCompare.SetAlternative("de", "Word 1"); Assert.AreEqual(1, multiTextBase.CompareTo(multiTextBaseToCompare)); }
public void SerializeWithXmlSerializer() { MultiTextBase text = new MultiTextBase(); text["foo"] = "alpha"; text["boo"] = "beta"; var answerXPath = "/TestMultiTextHolder[namespace::xsd='http://www.w3.org/2001/XMLSchema' and namespace::xsi='http://www.w3.org/2001/XMLSchema-instance']/name/form"; CheckSerializeWithXmlSerializer(text, answerXPath, 2); }
public void HasFormWithSameContent_OneEmpty_False() { MultiTextBase x = new MultiTextBase(); MultiTextBase y = new MultiTextBase(); y["ws"] = "test"; y.SetAnnotationOfAlternativeIsStarred("ws", true); Assert.IsFalse(x.HasFormWithSameContent(y)); Assert.IsFalse(y.HasFormWithSameContent(x)); }
private static void CopyItemToFieldsInPages(HtmlDom dom, string key, string valueAttribute = null, string[] languagePreferences = null) { if (languagePreferences == null) { languagePreferences = new[] { "*", "en" } } ; MultiTextBase source = dom.GetBookSetting(key); if (key == "copyright") { // For CC0, we store the "copyright", but don't display it in the text of the book. var licenseUrl = dom.GetBookSetting("licenseUrl").GetExactAlternative("*"); if (licenseUrl == CreativeCommonsLicense.CC0Url) { source = new MultiTextBase(); } } foreach (XmlElement target in dom.SafeSelectNodes("//*[@data-derived='" + key + "']")) { //just put value into the text of the element if (string.IsNullOrEmpty(valueAttribute)) { //clear out what's there now target.RemoveAttribute("lang"); target.InnerText = ""; var form = source.GetBestAlternative(languagePreferences); if (form != null && !string.IsNullOrWhiteSpace(form.Form)) { // HtmlDom.GetBookSetting(key) returns the result of XmlNode.InnerXml which will be Html encoded (& < etc). // HtmlDom.SetElementFromUserStringPreservingLineBreaks() calls XmlNode.InnerText, which Html encodes if necessary. // So we need to decode here to prevent double encoding. See http://issues.bloomlibrary.org/youtrack/issue/BL-4585. // Note that HtmlDom.SetElementFromUserStringPreservingLineBreaks() handles embedded <br/> elements, but makes no // effort to handle p or div elements. var decoded = System.Web.HttpUtility.HtmlDecode(form.Form); HtmlDom.SetElementFromUserStringSafely(target, decoded); target.SetAttribute("lang", form.WritingSystemId); //this allows us to set the font to suit the language } } else //Put the value into an attribute. The license image goes through this path. { target.SetAttribute(valueAttribute, source.GetBestAlternativeString(languagePreferences)); if (source.Empty) { //if the license image is empty, make sure we don't have some alternative text //about the image being missing or slow to load target.SetAttribute("alt", ""); //over in javascript land, @alt will get set appropriately when the image url is not empty. } } } }
public void UpdateGenericLanguageString(string key, string value, bool isCollectionValue) { var text = new MultiTextBase(); text.SetAlternative("*", value); if (TextVariables.ContainsKey(key)) { TextVariables.Remove(key); } TextVariables.Add(key, new NamedMutliLingualValue(text, isCollectionValue)); }
public void HasFormWithSameContent_DifferentValue_False() { MultiTextBase x = new MultiTextBase(); x["ws"] = "test"; MultiTextBase y = new MultiTextBase(); y["ws"] = "tests"; Assert.IsFalse(x.HasFormWithSameContent(y)); Assert.IsFalse(y.HasFormWithSameContent(x)); }
private void WriteCustomMultiTextField(string type, MultiText text) // review cp see WriteEmbeddedXmlCollection { if (!MultiTextBase.IsEmpty(text)) { Writer.WriteStartElement("field"); Writer.WriteAttributeString("type", type); WriteMultiTextNoWrapper(type, text); Writer.WriteEndElement(); } }
public static Metadata CreateMetadata(MultiTextBase copyright, string licenseUrl, MultiTextBase licenseNotes, BookData bookData) { var metadata = new Metadata(); if (!copyright.Empty) { metadata.CopyrightNotice = GetBestMultiTextBaseValue(copyright, bookData); } if (string.IsNullOrWhiteSpace(licenseUrl)) { //NB: we are mapping "RightsStatement" (which comes from XMP-dc:Rights) to "LicenseNotes" in the html. //custom licenses live in this field, so if we have notes (and no URL) it is a custom one. if (!licenseNotes.Empty) { metadata.License = new CustomLicense { RightsStatement = GetBestMultiTextBaseValue(licenseNotes, bookData) }; } else { // The only remaining current option is a NullLicense metadata.License = new NullLicense(); //"contact the copyright owner } } else // there is a licenseUrl, which means it is a CC license { try { metadata.License = CreativeCommonsLicense.FromLicenseUrl(licenseUrl); } catch (IndexOutOfRangeException) { // Need to handle urls which do not end with the version number. // Simply set it to the default version. if (!licenseUrl.EndsWith("/")) { licenseUrl += "/"; } licenseUrl += CreativeCommonsLicense.kDefaultVersion; metadata.License = CreativeCommonsLicense.FromLicenseUrl(licenseUrl); } catch (Exception e) { throw new ApplicationException("Bloom had trouble parsing this license url: '" + licenseUrl + "'. (ref BL-4108)", e); } //are there notes that go along with that? if (!licenseNotes.Empty) { metadata.License.RightsStatement = GetBestMultiTextBaseValue(licenseNotes, bookData); } } return(metadata); }
public void ContainsEqualForm_DifferentValue_False() { MultiTextBase x = new MultiTextBase(); x["ws"] = "test"; LanguageForm form = new LanguageForm(); form.WritingSystemId = "ws"; form.Form = "tests"; Assert.IsFalse(x.ContainsEqualForm(form)); }