public void Equals() { TextValue v1 = new TextValue("Hello World"); TextValue v2 = new TextValue("hELLO wORLD"); Assert.IsTrue(v1.Equals(v2)); Assert.IsFalse(v1.Equals(new TextValue("Hello Worl"))); }
public void EqualsTest() { TextValue target = new TextValue("Test"); object obj = "Test"; // string bool expected = false; // we expect them not to be equal because they are not the same type. // Implicit conversion from string to TextValue does not take effect here. // However, even if it did, that might be fine too... this test is just asserting the expected (but not required) behavior. bool actual; actual = target.Equals(obj); Assert.AreEqual(expected, actual); obj = new TextValue("Test"); expected = true; actual = target.Equals(obj); Assert.AreEqual(expected, actual); }
/// <summary> /// Writes the XML representation of the answer. /// </summary> /// <param name="writer">The XmlWriter to which to write the answer value.</param> public void WriteXml(System.Xml.XmlWriter writer) { writer.WriteStartElement("MCValue"); if (_protect) { writer.WriteAttributeString("userModifiable", System.Xml.XmlConvert.ToString(!_protect)); } if (IsAnswered) { for (int i = 0; i < _value.Length; i++) { writer.WriteElementString("SelValue", TextValue.XMLEscape(_value[i])); } } else { writer.WriteAttributeString("unans", System.Xml.XmlConvert.ToString(true)); } writer.WriteEndElement(); }
public int CompareTo(object obj) { if (!(obj is TextValue)) { return(-1); } TextValue textValue = (TextValue)obj; if (!IsAnswered && !textValue.IsAnswered) { return(0); } if (!IsAnswered) { return(1); } if (!textValue.IsAnswered) { return(-1); } return(String.Compare(Value, textValue.Value, StringComparison.OrdinalIgnoreCase)); }
public void UnansEquals3() { TextValue uv1 = new TextValue(); TextValue uv2 = new TextValue(); uv1.Equals(uv2); }
public void UnansEquals2() { TextValue v = new TextValue("Hello World"); TextValue uv = new TextValue(); v.Equals(uv); }
public void UnansEquals1() { TextValue v = new TextValue("Hello World"); TextValue uv = new TextValue(); uv.Equals(v); }
public void TextValueConstructorTest2() { TextValue target = new TextValue("Test\nValue", false); Assert.IsTrue(target.IsAnswered); Assert.AreEqual(target.Type, HotDocs.Sdk.ValueType.Text); Assert.IsFalse(target.UserModifiable); Assert.AreEqual(target.Value, "Test\r\nValue"); }
public void IsAnswered() { TextValue v = new TextValue(); Assert.IsFalse(v.IsAnswered); }
public void EqualsTest1() { TextValue target = new TextValue("my value"); TextValue operand = new TextValue("my value"); bool expected = true; bool actual; actual = target.Equals(operand); Assert.AreEqual(expected, actual); operand = new TextValue("my other value"); expected = false; actual = target.Equals(operand); Assert.AreEqual(expected, actual); }
/// <summary> /// Static constructor required so static fields are always initialized /// </summary> static TextValue() { TextValue.Unanswered = new TextValue(); TextValue.UnansweredLocked = new TextValue(null, false); TextValue.s_xmlEscaper = null; }
/// <summary> /// Reads a TextReader into the answer collection without first clearing existing answers. /// </summary> /// <param name="input">A TextReader containing a HotDocs answer file.</param> public void OverlayXml(System.IO.TextReader input) { // create an XmlTextReader XmlReaderSettings settings = new XmlReaderSettings(); settings.ConformanceLevel = ConformanceLevel.Auto; settings.IgnoreWhitespace = false; settings.IgnoreProcessingInstructions = true; settings.IgnoreComments = true; settings.ValidationType = ValidationType.None; //settings.ProhibitDtd = false; // obsolete in .NET 4.0, replaced with: settings.DtdProcessing = DtdProcessing.Ignore; // .NET 4.0 only //try //{ using (XmlReader reader = XmlReader.Create(input, settings)) { // then read the XML and create the answers... reader.MoveToContent(); if (reader.Name == "AnswerSet") { if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.Name == "title") { _title = reader.Value; } else if (reader.Name == "version") { _version = XmlConvert.ToSingle(reader.Value); } } } } else { throw new XmlException("Expected an AnswerSet element."); } int[] repeatStack = RepeatIndices.Empty; // read answers: while (reader.Read()) { reader.MoveToContent(); if (reader.Name == "Answer" && reader.HasAttributes) { string answerName = null; bool? answerSave = null; bool? userExtendible = null; while (reader.MoveToNextAttribute()) { if (reader.Name == "name") { answerName = TextValue.XMLUnescape(reader.Value).Trim(); } else if (reader.Name == "save") { switch (reader.Value) { case "true": answerSave = true; break; case "false": answerSave = false; break; // else no change } } else if (reader.Name == "userExtendible") { userExtendible = XmlConvert.ToBoolean(reader.Value); } } if (String.IsNullOrEmpty(answerName)) { throw new XmlException("Answer name is missing."); } Answer ans = null; reader.Read(); reader.MoveToContent(); ReadValue(reader, ref ans, answerName, repeatStack); if (answerSave.HasValue && !answerSave.Value) { ans.Save = false; } if (userExtendible.HasValue) { ans.UserExtendible = userExtendible.Value; } } } } //} //catch //{ // // Just eat any exceptions that are thrown for now. //} }
private bool Equals(TextValue operand) { if (!IsAnswered || !operand.IsAnswered) throw new InvalidOperationException(); return String.Compare(Value, operand.Value, StringComparison.OrdinalIgnoreCase) == 0; }
/// <summary> /// Equals summary /// </summary> /// <param name="operand">operand</param> /// <returns>True or False</returns> private bool Equals(TextValue operand) { if (!IsAnswered || !operand.IsAnswered) throw new InvalidOperationException(); for (int i = 0; i < _value.Length; i++) { if (String.Compare(_value[i], operand.Value, StringComparison.OrdinalIgnoreCase) == 0) return true; } return false; }