예제 #1
0
파일: Helper.cs 프로젝트: xxjeng/nuxleus
        /// <summary>
        ///     Writes a card, then reads it back and compares fields.
        /// </summary>
        public static void CycleStandard21(vCard card)
        {

            if (card == null)
                throw new ArgumentNullException("cycle");

            // Create a memory stream to hold the contents of the card.

            MemoryStream stream = new MemoryStream();

            StreamWriter textWriter = new StreamWriter(stream);

            // Create a standard vCard writer and export the
            // card data to the stream.

            vCardStandardWriter writer = new vCardStandardWriter();
            writer.Write(card, textWriter);
            textWriter.Flush();

            // Reset the stream (back to its beginning), then
            // create a stream reader capable of reading text
            // lines from the stream.

            stream.Seek(0, SeekOrigin.Begin);
            StreamReader streamReader = new StreamReader(stream);

            vCardStandardReader standardReader = new vCardStandardReader();
            vCard reloaded = standardReader.Read(streamReader);

            Equals(card, reloaded);

        }
예제 #2
0
        public void ReadProperty_String_Name_Subproperty_Subvalue_Value()
        {

            vCardStandardReader reader =
                new vCardStandardReader();

            vCardProperty property =
                reader.ReadProperty("TEL;TYPE=WORK:800-929-5805");

            Assert.AreEqual(
                "TEL",
                property.Name,
                "The name of the property should be TEL");

            Assert.AreEqual(
                1,
                property.Subproperties.Count,
                "There should be exactly one subproperty.");

            Assert.AreEqual(
                "TYPE",
                property.Subproperties[0].Name,
                "The name of the subproperty should be TYPE.");

            Assert.AreEqual(
                "WORK",
                property.Subproperties[0].Value,
                "The value of the subproperty should be WORK.");

            Assert.AreEqual(
                "800-929-5805",
                property.Value,
                "The value of the property is not correct.");

        }
예제 #3
0
        public void ReadProperty_String_Name_Subproperty_Value()
        {

            vCardStandardReader reader =
                new vCardStandardReader();

            vCardProperty property =
                reader.ReadProperty("NAME;SUB:VALUE");

            Assert.AreEqual(
                "NAME",
                property.Name,
                "The Name is incorrect.");

            Assert.AreEqual(
                1,
                property.Subproperties.Count,
                "The Subproperties collection has an incorrect number of items.");

            Assert.AreEqual(
                "SUB",
                property.Subproperties[0].Name,
                "The Subproperty value is incorrect.");

            Assert.AreEqual(
                "VALUE",
                property.Value,
                "The parsed value is incorrect.");

        }
예제 #4
0
        public void ReadProperty_String_Name_Subproperties_Value()
        {

            // This function tests the parser against a property
            // string with two subproperties.

            vCardStandardReader reader =
                new vCardStandardReader();

            vCardProperty property =
                reader.ReadProperty("NAME;SUB1;SUB2:VALUE");

            Assert.AreEqual(
                "NAME",
                property.Name,
                "The Name is incorrect.");

            Assert.AreEqual(
                2,
                property.Subproperties.Count,
                "The Subproperties collection has an incorrect number of items.");

            Assert.AreEqual(
                "SUB1",
                property.Subproperties[0].Name,
                "The Subproperty[0] value is incorrect.");

            Assert.AreEqual(
                "SUB2",
                property.Subproperties[1].Name,
                "The Subproperty[1] value is incorrect.");

            Assert.AreEqual(
                "VALUE",
                property.Value,
                "The parsed value is incorrect.");

        }
예제 #5
0
        public void ReadProperty_String_Name_Value()
        {

            // This function tests the parsing function
            // against a basic string like NAME:VALUE.

            vCardStandardReader reader = new vCardStandardReader();

            vCardProperty property = reader.ReadProperty(
                TestName + ":" + TestValue);

            Assert.AreEqual(
                TestName,
                property.Name);

            Assert.AreEqual(
                TestValue,
                property.Value,
                "The parsed value is incorrect.");

            Assert.IsEmpty(
                property.Subproperties,
                "The Subproperties collection should be empty.");

        }
예제 #6
0
        public void ReadProperty_String_Whitespace()
        {
            vCardStandardReader reader = new vCardStandardReader();
            reader.ReadProperty("  ");

            Assert.AreEqual(
                1,
                reader.Warnings.Count,
                "A string with only whitespace should have caused a warning.");

        }
예제 #7
0
        public void ReadProperty_String_SingleColon()
        {
            vCardStandardReader reader = new vCardStandardReader();
            reader.ReadProperty(":");

            Assert.AreEqual(
                1,
                reader.Warnings.Count,
                "A single colon should have caused a warning.");

        }
예제 #8
0
        public void ReadProperty_String_QuotedPrintable()
        {

            const string encodedValue =
                "LABEL;" +
                "HOME;" +
                "ENCODING=QUOTED-PRINTABLE:" +
                "129 15th Street #3=0D=0A" +
                "Minneapolis, MN 55403=0D=0A" +
                "United States of America";

            const string decodedValue =
                "129 15th Street #3\r\n" +
                "Minneapolis, MN 55403\r\n" +
                "United States of America";

            vCardStandardReader reader =
                new vCardStandardReader();

            // Read the property string.  It should
            // be decoded by the reader.

            vCardProperty property =
                reader.ReadProperty(encodedValue);

            Assert.AreEqual(
                "LABEL",
                property.Name,
                "The name of the property should be LABEL.");

            Assert.IsTrue(
                property.Subproperties.Contains("HOME"),
                "The property should have a subproperty called HOME.");

            // Now for the big test.  The loaded property
            // value should be decoded.  It should not have the
            // quoted-printable escape sequences.

            Assert.AreEqual(
                decodedValue,
                property.ToString());

        }
예제 #9
0
 public void ReadProperty_String_NullParameter()
 {
     vCardStandardReader reader = new vCardStandardReader();
     reader.ReadProperty((string)null);
 }
예제 #10
0
        public void ReadProperty_String_MissingColon()
        {

            vCardStandardReader reader = new vCardStandardReader();
            reader.ReadProperty("TEL 911");

            Assert.AreEqual(
                1,
                reader.Warnings.Count,
                "A missing colon should have caused a warning.");

        }
예제 #11
0
        public void ReadProperty_String_MissingName()
        {
            vCardStandardReader reader = new vCardStandardReader();
            reader.ReadProperty(":VALUE");

            Assert.AreEqual(
                1,
                reader.Warnings.Count,
                "A missing name should have caused a warning.");

        }
예제 #12
0
 public void ReadProperty_String_EmptyParameter()
 {
     vCardStandardReader reader = new vCardStandardReader();
     reader.ReadProperty(string.Empty);
 }
예제 #13
0
파일: vCard.cs 프로젝트: xxjeng/nuxleus
        /// <summary>
        ///     Loads a new instance of the <see cref="vCard"/> class
        ///     from a text file.
        /// </summary>
        /// <param name="path">
        ///     The path to a text file containing vCard data in
        ///     any recognized vCard format.
        /// </param>
        public vCard(string path)
            : this()
        {
            using (StreamReader streamReader = new StreamReader(path))
            {
                vCardReader reader = new vCardStandardReader();
                reader.ReadInto(this, streamReader);
            }

        }
예제 #14
0
파일: vCard.cs 프로젝트: xxjeng/nuxleus
        /// <summary>
        ///     Loads a new instance of the <see cref="vCard"/> class
        ///     from a text reader.
        /// </summary>
        /// <param name="input">
        ///     An initialized text reader.
        /// </param>
        public vCard(TextReader input)
            : this()
        {

            vCardReader reader = new vCardStandardReader();
            reader.ReadInto(this, input);

        }