コード例 #1
0
        // This code matches desktop HotDocs which operates as follows:
        //	1. It assumes that there are no duplicate strings in the same MultipleChoiceValue.
        //	2. MCV1 is equal to MCV2 if every string in MCV1 is contained exactly once in MCV2
        //		and every string in MCV2 is contained exactly once in MCV1.
        //	3. All string comparisons ignore case, that is, are case insensitive.
        private bool Equals(MultipleChoiceValue operand)
        {
            if (!IsAnswered || !operand.IsAnswered)
            {
                throw new InvalidOperationException();
            }

            if (_value.Length != operand._value.Length)
            {
                return(false);
            }

            for (int i = 0; i < _value.Length; i++)
            {
                int j = 0;
                while ((j < _value.Length) && (String.Compare(_value[i], operand._value[j],
                                                              StringComparison.OrdinalIgnoreCase) != 0))
                {
                    j++;
                }
                if (j >= _value.Length)
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #2
0
        public void Constructors()
        {
            string[] options = { "One", "Two", "Three" };

            string s = null;
            MultipleChoiceValue v = new MultipleChoiceValue(s);
            Assert.IsFalse(v.IsAnswered);

            v = new MultipleChoiceValue(String.Empty);
            Assert.IsTrue(v.IsAnswered);

            v = new MultipleChoiceValue(new string[0]);
            Assert.IsFalse(v.IsAnswered);

            v = new MultipleChoiceValue(options);
            Assert.IsTrue(v.IsAnswered);
            Assert.AreEqual("One|Two|Three", v.Value);
            Assert.AreEqual("One", v.Choices[0]);
            Assert.AreEqual("Two", v.Choices[1]);
            Assert.AreEqual("Three", v.Choices[2]);

            v = new MultipleChoiceValue("One|Two|Three");
            Assert.IsTrue(v.IsAnswered);
            Assert.AreEqual("One|Two|Three", v.Value);
            Assert.AreEqual("One", v.Choices[0]);
            Assert.AreEqual("Two", v.Choices[1]);
            Assert.AreEqual("Three", v.Choices[2]);
        }
コード例 #3
0
        public int CompareTo(object obj)
        {
            if (!(obj is MultipleChoiceValue))
            {
                return(-1);
            }

            MultipleChoiceValue multipleChoiceValue = (MultipleChoiceValue)obj;

            if (!IsAnswered && !multipleChoiceValue.IsAnswered)
            {
                return(0);
            }
            if (!IsAnswered)
            {
                return(1);
            }
            if (!multipleChoiceValue.IsAnswered)
            {
                return(-1);
            }

            if (Equals(multipleChoiceValue.Value))
            {
                return(0);
            }

            return(String.Compare(Value, multipleChoiceValue.Value, StringComparison.OrdinalIgnoreCase));
        }
コード例 #4
0
        public void Casts()
        {
            MultipleChoiceValue v = MultipleChoiceValue.Unanswered;
            Assert.IsFalse(v.IsAnswered);

            v = new MultipleChoiceValue("Hello World");
            Assert.IsTrue(v.IsAnswered);
            Assert.AreEqual("Hello World", v.Value);
        }
コード例 #5
0
        public void Casts()
        {
            TextValue v = TextValue.Unanswered;
            Assert.IsFalse(v.IsAnswered);

            v = "Hello World";
            Assert.IsTrue(v.IsAnswered);
            Assert.AreEqual("Hello World", v.Value);

            v = new MultipleChoiceValue("One|Two|Three");
            Assert.IsTrue(v.IsAnswered);
            Assert.AreEqual("One|Two|Three", v.Value);

            v = new MultipleChoiceValue();
            Assert.IsFalse(v.IsAnswered);
        }
コード例 #6
0
        public void Equals()
        {
            MultipleChoiceValue v1 = new MultipleChoiceValue("One|Two|Three");
            Assert.IsTrue(v1.Equals(new TextValue("One")));
            Assert.IsTrue(v1.Equals(new TextValue("oNe")));
            Assert.IsTrue(v1.Equals(new TextValue("TWO")));
            Assert.IsFalse(v1.Equals(new MultipleChoiceValue("Two")));

            MultipleChoiceValue v2 = new MultipleChoiceValue("One|TWO|ThRee");
            Assert.IsTrue(v1.Equals(v2));

            v2 = new MultipleChoiceValue("Three|Two|One");
            Assert.IsTrue(v1.Equals(v2));

            v2 = new MultipleChoiceValue("Three|Two|One|Four");
            Assert.IsFalse(v1.Equals(v2));

            v2 = new MultipleChoiceValue("One|Four|Three");
            Assert.IsFalse(v1.Equals(v2));
        }
コード例 #7
0
        public void Constructors()
        {
            string[] options = { "One", "Two", "Three" };
            List<string> optionsList = new List<string>(options);

            string s = null;
            MultipleChoiceValue v = new MultipleChoiceValue(s);
            Assert.IsFalse(v.IsAnswered);

            v = new MultipleChoiceValue(String.Empty);
            Assert.IsTrue(v.IsAnswered);

            v = new MultipleChoiceValue(new string[0]);
            Assert.IsFalse(v.IsAnswered);

            v = new MultipleChoiceValue(options);
            Assert.IsTrue(v.IsAnswered);
            Assert.AreEqual("One|Two|Three", v.Value);
            Assert.AreEqual("One", v.Choices[0]);
            Assert.AreEqual("Two", v.Choices[1]);
            Assert.AreEqual("Three", v.Choices[2]);

            v = new MultipleChoiceValue("One|Two|Three");
            Assert.IsTrue(v.IsAnswered);
            Assert.AreEqual("One|Two|Three", v.Value);
            Assert.AreEqual("One", v.Choices[0]);
            Assert.AreEqual("Two", v.Choices[1]);
            Assert.AreEqual("Three", v.Choices[2]);

            // Test implicit conversion of string[] to MultipleChoiceValue
            Assert.AreEqual(((MultipleChoiceValue)options).Choices.Length, 3);
            Assert.AreEqual(((MultipleChoiceValue)options).Choices[0], "One");

            // Test implicit conversion of List<string> to MultipleChoiceValue
            Assert.AreEqual(((MultipleChoiceValue)optionsList).Choices.Length, 3);
            Assert.AreEqual(((MultipleChoiceValue)optionsList).Choices[1], "Two");
        }
コード例 #8
0
        public void UnansEquals1()
        {
            MultipleChoiceValue v = new MultipleChoiceValue("Choice");
            MultipleChoiceValue uv = new MultipleChoiceValue();

            uv.Equals(v);
        }
コード例 #9
0
 public void IsAnswered()
 {
     MultipleChoiceValue v = new MultipleChoiceValue();
     Assert.IsFalse(v.IsAnswered);
 }
コード例 #10
0
        public void UnansEquals3()
        {
            MultipleChoiceValue uv1 = new MultipleChoiceValue();
            MultipleChoiceValue uv2 = new MultipleChoiceValue();

            uv1.Equals(uv2);
        }
コード例 #11
0
 /// <summary>
 /// Static constructor required so static fields are always initialized
 /// </summary>
 static MultipleChoiceValue()
 {
     MultipleChoiceValue.Unanswered       = new MultipleChoiceValue();
     MultipleChoiceValue.UnansweredLocked = new MultipleChoiceValue((string)null, false);
 }
コード例 #12
0
        // This code matches desktop HotDocs which operates as follows:
        //    1. It assumes that there are no duplicate strings in the same MultipleChoiceValue.
        //    2. MCV1 is equal to MCV2 if every string in MCV1 is contained exactly once in MCV2
        //        and every string in MCV2 is contained exactly once in MCV1.
        //    3. All string comparisons ignore case, that is, are case insensitive.
        private bool Equals(MultipleChoiceValue operand)
        {
            if (!IsAnswered || !operand.IsAnswered)
                throw new InvalidOperationException();

            if (_value.Length != operand._value.Length)
                return false;

            for (int i = 0; i < _value.Length; i++)
            {
                int j = 0;
                while ((j < _value.Length) && (String.Compare(_value[i], operand._value[j],
                    StringComparison.OrdinalIgnoreCase) != 0)) j++;
                if (j >= _value.Length)
                    return false;
            }
            return true;
        }
コード例 #13
0
 /// <summary>
 /// Static constructor required so static fields are always initialized
 /// </summary>
 static MultipleChoiceValue()
 {
     MultipleChoiceValue.Unanswered = new MultipleChoiceValue();
     MultipleChoiceValue.UnansweredLocked = new MultipleChoiceValue((string)null, false);
 }