Ejemplo n.º 1
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.");

        }
Ejemplo n.º 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.");

        }
Ejemplo n.º 3
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.");

        }
Ejemplo n.º 4
0
        public void ReadProperty_Blank_Subproperty()
        {
            vCardStandardReader reader =
                new vCardStandardReader();

            Assert.DoesNotThrow(
                () => { reader.ReadProperty("NAME;:VALUE"); },
                "Exception was thrown.");
        }
Ejemplo n.º 5
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.");

        }
Ejemplo n.º 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.");

        }
Ejemplo n.º 7
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.");

        }
        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.");
        }
Ejemplo n.º 9
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());

        }
Ejemplo n.º 10
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.");

        }
Ejemplo n.º 11
0
 public void ReadProperty_String_NullParameter()
 {
     vCardStandardReader reader = new vCardStandardReader();
     Assert.Throws<ArgumentNullException>(()=>reader.ReadProperty((string)null));
 }
Ejemplo n.º 12
0
        /*
         * BEGIN:VLIST
         * UID:4250-58658600-5-45D0678.vlf
         * VERSION:1.0
         * FN:Simpsons
         * CARD;[email protected];FN="Simpson, Homer":5228bf7b-f3a6-4c16-ae3e-90102d86ab43.vcf
         * CARD;[email protected];FN="Simpson, Marge":c520e3ad-3d19-4c2f-b093-3f17736bce8e.vcf
         * END:VLIST
         */

        protected override bool TryDeserialize(string vcardData, out DistributionList vcard, WebResourceName uriOfAddressbookForLogging, int deserializationThreadLocal, ILoadEntityLogger logger)
        {
            var cardReader = new vCardStandardReader();

            vcard = new DistributionList();

            using (var reader = new StringReader(vcardData))
            {
                vCardProperty property;
                do
                {
                    property = cardReader.ReadProperty(reader);
                    if (!string.IsNullOrEmpty(property?.Name))
                    {
                        var propNameToProcess = property.Name.ToUpperInvariant();

                        switch (propNameToProcess)
                        {
                        case "UID":
                            vcard.Uid = property.ToString();
                            break;

                        case "FN":
                            vcard.Name = property.ToString();
                            break;

                        case "DESCRIPTION":
                            vcard.Description = property.ToString();
                            break;

                        case "NICKNAME":
                            vcard.Nickname = property.ToString();
                            break;

                        case "CARD":
                            if (property.Value != null)
                            {
                                var emailAddress = property.Subproperties.GetValue("EMAIL");
                                var displayName  = property.Subproperties.GetValue("FN");
                                vcard.Members.Add(new KnownDistributionListMember(emailAddress, displayName, property.Value.ToString()));
                            }

                            break;

                        case NonAddressBookMemberValueName:
                            if (property.Value != null)
                            {
                                var    displayName  = property.Subproperties.GetValue("CN");
                                string emailAddress = null;
                                var    value        = property.Value.ToString();
                                if (!string.IsNullOrEmpty(value))
                                {
                                    if (value.StartsWith("mailto:", StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        emailAddress = value.Substring(7);     //skip mailto:
                                    }
                                }

                                vcard.NonAddressBookMembers.Add(new DistributionListMember(emailAddress, displayName));
                            }

                            break;
                        }
                    }
                } while (property != null);
            }

            return(true);
        }
        public void ReadProperty_String_NullParameter()
        {
            vCardStandardReader reader = new vCardStandardReader();

            reader.ReadProperty((string)null);
        }
        public void ReadProperty_String_EmptyParameter()
        {
            vCardStandardReader reader = new vCardStandardReader();

            reader.ReadProperty(string.Empty);
        }