public void OperatorEquals_GivenNullXmlAndNullWrapper_AreEquivalent() { // Need to test both orders to make sure it's actually commutative bool result = (XmlString.FromXml(null) == null); Assert.That(result, Is.EqualTo(true)); }
public static ErrorResult?ShowFallbackProblemDialog(string levelOfProblem, Exception exception, string detailedMessage, string shortUserLevelMessage, bool isShortMessagePreEncoded = false, string notifySecondaryButtonLabel = null, ErrorResult?notifySecondaryPressedResult = null) { var fallbackReporter = new WinFormsErrorReporter(); if (shortUserLevelMessage == null) { shortUserLevelMessage = ""; } string decodedShortUserLevelMessage = isShortMessagePreEncoded ? XmlString.FromXml(shortUserLevelMessage).Unencoded : shortUserLevelMessage; string message = decodedShortUserLevelMessage; if (!String.IsNullOrEmpty(detailedMessage)) { message += $"\n{detailedMessage}"; } if (levelOfProblem == ProblemLevel.kFatal) { if (exception != null) { fallbackReporter.ReportFatalException(exception); } else { fallbackReporter.ReportFatalMessageWithStackTrace(message, null); } return(null); } else if (levelOfProblem == ProblemLevel.kNonFatal || levelOfProblem == ProblemLevel.kUser) { // FYI, if levelOfProblem==kUser, we're unfortunately going to be // using the messaging from NonFatal even though we would ideally like to have the customized messaging for levelOfProblem==kUser, // but we'll just live with it because there's no easy way to customize it. It's probably an extremely rare situation anyway if (String.IsNullOrEmpty(message)) { fallbackReporter.ReportNonFatalException(exception, new ShowAlwaysPolicy()); } else { fallbackReporter.ReportNonFatalExceptionWithMessage(exception, message); } return(null); } else // Presumably, levelOfProblem = "notify" now { if (String.IsNullOrEmpty(notifySecondaryButtonLabel) || notifySecondaryPressedResult == null) { return(fallbackReporter.NotifyUserOfProblem(new ShowAlwaysPolicy(), null, ErrorResult.OK, message)); } else { return(fallbackReporter.NotifyUserOfProblem(new ShowAlwaysPolicy(), notifySecondaryButtonLabel, notifySecondaryPressedResult ?? ErrorResult.OK, message)); } } }
public void IsNullOrEmpty_GivenNonEmpty_ReturnsFalse(string xmlInput) { var xmlStringObj = XmlString.FromXml(xmlInput); var result = XmlString.IsNullOrEmpty(xmlStringObj); Assert.That(result, Is.False); }
public void SameAs_OneHasExtraTextValue_False() { var first = new DataSet(); var second = new DataSet(); first.AddLanguageString("one", XmlString.FromXml("a value"), "en", false); Assert.That(first.SameAs(second), Is.False); }
public void SameAs_DifferentKeys_False() { var first = new DataSet(); var second = new DataSet(); first.AddLanguageString("one", XmlString.FromXml("a value"), "en", false); second.AddLanguageString("two", XmlString.FromXml("a value"), "en", false); Assert.That(first.SameAs(second), Is.False); }
private static DataSet MakeComplexDataSet() { var ds = new DataSet(); ds.AddLanguageString("one", XmlString.FromXml("a value"), "en", false); ds.AddLanguageString("one", XmlString.FromXml("another value"), "de", false); ds.AddLanguageString("two", XmlString.FromXml("another value"), "fr", false); var values = new HashSet <KeyValuePair <string, string> >(); values.Add(new KeyValuePair <string, string>("key", "value")); ds.UpdateXmatterPageDataAttributeSet("one", values); DataSetElementValue dsv = ds.TextVariables["one"]; dsv.SetAttributeList("en", MakeList("attr1", "val1", "attr2", "val2")); dsv.SetAttributeList("de", MakeList("attr1", "val1de", "attr3", "val3de")); DataSetElementValue dsv2 = ds.TextVariables["one"]; dsv2.SetAttributeList("fr", MakeList("attr1", "val1fr", "attr4", "val4")); return(ds); }
/// <summary> /// Copy the copyright & license info to the originalCopyrightAndLicense, /// then remove the copyright so the translator can put in their own if they /// want. We retain the license, but the translator is allowed to change that. /// If the source is already a translation (already has original copyright or license) /// we keep them unchanged. /// </summary> public static void SetOriginalCopyrightAndLicense(HtmlDom dom, BookData bookData, CollectionSettings collectionSettings) { // If it already has some of this information, just keep it. if (bookData.BookIsDerivative()) { return; //leave the original there. } // If there's no copyright information in a source-collection book, we're presumably making // a new original book, and shouldn't try to record any original copyright and license information. // This is somewhat redundant with the check in BookStarter.SetupNewDocumentContents(), the one // non-unit-test current caller of this method, that doesn't call this at all if the source is // a template book. I was trying for a minimal reasonable change for BL-5131, and therefore // put in this extra check, since previously this method was simply NEVER called in a source // collection. var copyrightNotice = BookCopyrightAndLicense.GetMetadata(dom, bookData).CopyrightNotice; if (String.IsNullOrEmpty(copyrightNotice) && collectionSettings.IsSourceCollection) { return; } bookData.Set("originalLicenseUrl", XmlString.FromXml(BookCopyrightAndLicense.GetLicenseUrl(dom)), "*"); bookData.Set("originalCopyright", XmlString.FromUnencoded(copyrightNotice), "*"); bookData.Set("originalLicenseNotes", XmlString.FromXml(dom.GetBookSetting("licenseNotes").GetFirstAlternative()), "*"); }
public void OperatorEquals_GivenNullWrapperandNullXml_AreEquivalent() { bool result = (null == XmlString.FromXml(null)); Assert.That(result, Is.EqualTo(true)); }
public void UnencodedProperty_GivenEncodedChars_DecodesXml(string xmlInput, string expectedUnencoded) { var result = XmlString.FromXml(xmlInput).Unencoded; Assert.That(result, Is.EqualTo(expectedUnencoded)); }
public void FromXml_GivenXmlInput_ThenXmlPropertyReturnsInputUnchanged(string xmlInput) { var result = XmlString.FromXml(xmlInput).Xml; Assert.That(result, Is.EqualTo(xmlInput)); }