示例#1
0
        private vCardDeliveryAddress GetAddress(HtmlDocument detailsDoc, int ix)
        {
            var street = GetNextTDText(detailsDoc, "Gateadresse", ix);
            var box = GetNextTDText(detailsDoc, "Postboks", ix);
            var postalNr = GetNextTDText(detailsDoc, "Postnr", ix);
            var city = GetNextTDText(detailsDoc, "By", ix);
            var country = GetNextTDText(detailsDoc, "Land", ix);

            if (!string.IsNullOrEmpty(street + box + postalNr + city))
            {
                var address = new vCardDeliveryAddress();

                if (!string.IsNullOrEmpty(box))
                {
                    address.Street = box + "\n" + street;
                }
                else
                {
                    address.Street = street;
                }
                address.PostalCode = postalNr;
                address.City = city;
                address.Country = country;

                return address;
            }
            return null;
        }
        public void Constructor()
        {

            // Tests the default values of the address constructor.

            vCardDeliveryAddress address = new vCardDeliveryAddress();

            Assert.IsEmpty(
                address.City,
                "The City property should default to String.Empty.");

            Assert.IsEmpty(
                address.Country,
                "The Country property should default to String.Empty.");

            Assert.IsEmpty(
                address.PostalCode,
                "The PostalCode property should default to String.Empty.");

            Assert.IsEmpty(
                address.Region,
                "The Region property should default to String.Empty.");

            Assert.IsEmpty(
                address.Street,
                "The Street property should default to String.Empty.");

        }
        public void EmptyString_Country()
        {

            vCardDeliveryAddress address = new vCardDeliveryAddress();

            Assert.IsEmpty(
                address.Country,
                "The Country property should default to String.Empty.");

            address.Country = null;

            Assert.IsEmpty(
                address.Country,
                "The Country property should return String.Empty instead of null.");

        }
示例#4
0
        public static void Equals(
            vCardDeliveryAddress da1,
            vCardDeliveryAddress da2)
        {

            Assert.AreEqual(
                da1.AddressType,
                da2.AddressType,
                "vCardDeliveryAddress.AddressType differs.");

            Assert.AreEqual(
                da1.City,
                da2.City,
                "vCardDeliveryAddress.City differs.");

            Assert.AreEqual(
                da1.Country,
                da2.Country,
                "vCardDeliveryAddress.Country differs.");

            Assert.AreEqual(
                da1.IsDomestic,
                da2.IsDomestic,
                "vCardDeliveryAddress.IsDomestic differs.");

            Assert.AreEqual(
                da1.IsHome,
                da2.IsHome,
                "vCardDeliveryAddress.IsHome differs.");

            Assert.AreEqual(
                da1.IsInternational,
                da2.IsInternational,
                "vCardDeliveryAddress.IsInternational differs.");

            Assert.AreEqual(
                da1.IsParcel,
                da2.IsParcel,
                "vCardDeliveryAddress.IsParcel differs.");

            Assert.AreEqual(
                da1.IsPostal,
                da2.IsPostal,
                "vCardDeliveryAddress.IsPostal differs.");

            Assert.AreEqual(
                da1.IsWork,
                da2.IsWork,
                "vCardDeliveryAddress.IsWork differs.");

            Assert.AreEqual(
                da1.PostalCode,
                da2.PostalCode,
                "vCardDeliveryAddress.PostalCode differs.");

            Assert.AreEqual(
                da1.Region,
                da2.Region,
                "vCardDeliveryAddress.Region differs.");

            Assert.AreEqual(
                da1.Street,
                da2.Street,
                "vCardDeliveryAddress.Street differs.");

            Assert.AreEqual(
                da1.ToString(),
                da2.ToString(),
                "vCardDeliveryAddress.ToString differs.");

        }
        public void EmptyString_PostalCode()
        {

            vCardDeliveryAddress address = new vCardDeliveryAddress();

            Assert.IsEmpty(
                address.PostalCode,
                "The PostalCode property should default to String.Empty.");

            address.PostalCode = null;

            Assert.IsEmpty(
                address.PostalCode,
                "The PostalCode property should return String.Empty instead of null.");

        }
        public void ReadWriteProperty_Street()
        {

            vCardDeliveryAddress address = new vCardDeliveryAddress();

            address.Street = "1490 Lark Avenue";
            Assert.AreEqual(
                "1490 Lark Avenue",
                address.Street,
                "The Street property is not working.");
        }
        public void ReadWriteProperty_Region()
        {

            vCardDeliveryAddress address = new vCardDeliveryAddress();

            address.Region = "North Pole";
            Assert.AreEqual(
                "North Pole",
                address.Region,
                "The Region property is not working.");
        }
        public void ReadWriteProperty_PostalCode()
        {

            vCardDeliveryAddress address = new vCardDeliveryAddress();

            address.PostalCode = "55109";
            Assert.AreEqual(
                "55109",
                address.PostalCode,
                "The PostalCode property is not working.");
        }
        public void ReadWriteProperty_Country()
        {

            vCardDeliveryAddress address = new vCardDeliveryAddress();

            address.Country = "Jordan";
            Assert.AreEqual(
                "Jordan",
                address.Country,
                "The Country property is not working.");
        }
        public void ReadWriteProperty_City()
        {

            vCardDeliveryAddress address = new vCardDeliveryAddress();

            address.City = "Warroad";
            Assert.AreEqual(
                "Warroad",
                address.City,
                "The City property is not working.");
        }
        public void ReadWriteProperty_AddressType()
        {

            vCardDeliveryAddress address = new vCardDeliveryAddress();

            address.AddressType.Add(vCardDeliveryAddressTypes.Domestic);
            Assert.AreEqual(
                vCardDeliveryAddressTypes.Domestic,
                address.AddressType,
                "The AddressType property is not working.");

        }
        public void EmptyString_Street()
        {

            vCardDeliveryAddress address = new vCardDeliveryAddress();

            Assert.IsEmpty(
                address.Street,
                "The Street property should default to String.Empty.");

            address.Street = null;

            Assert.IsEmpty(
                address.Street,
                "The Street property should return String.Empty instead of null.");

        }
        public void EmptyString_Region()
        {

            vCardDeliveryAddress address = new vCardDeliveryAddress();

            Assert.IsEmpty(
                address.Region,
                "The Region property should default to String.Empty.");

            address.Region = null;

            Assert.IsEmpty(
                address.Region,
                "The Region property should return String.Empty instead of null.");

        }
        // The following functions (ReadInfo_xxx) implement the logic
        // for each recognized vCard property.  A separate function
        // for each property is implemented for easier organization.
        //
        // Each function is a private function.  It is not necessary
        // for a function to double-check the name of a property, or
        // check for null parameters.

        #region [ ReadInto_ADR() ]

        /// <summary>
        ///     Reads an ADR property.
        /// </summary>
        private void ReadInto_ADR(vCard card, vCardProperty property)
        {

            // The ADR property defines a delivery address, such
            // as a home postal address.  The property contains
            // the following components separated by semicolons:
            //
            //   0. Post office box
            //   1. Extended address
            //   2. Street
            //   3. Locality (e.g. city)
            //   4. Region (e.g. state or province)
            //   5. Postal code
            //   6. Country name
            //
            // This version of the reader ignores any ADR properties
            // with a lesser number of components.  If more than 7
            // components exist, then the lower seven components are
            // assumed to still match the specification (e.g. the
            // additional components may be from a future specification).

            string[] addressParts =
                property.Value.ToString().Split(new char[] { ';' });

            vCardDeliveryAddress deliveryAddress = new vCardDeliveryAddress();

            if (addressParts.Length >= 7)
                deliveryAddress.Country = addressParts[6].Trim();

            if (addressParts.Length >= 6)
                deliveryAddress.PostalCode = addressParts[5].Trim();

            if (addressParts.Length >= 5)
                deliveryAddress.Region = addressParts[4].Trim();

            if (addressParts.Length >= 4)
                deliveryAddress.City = addressParts[3].Trim();

            if (addressParts.Length >= 3)
                deliveryAddress.Street = addressParts[2].Trim();

			if (addressParts.Length >= 2)
				deliveryAddress.ExtendedAddress = addressParts[1].Trim();

			if (addressParts.Length >= 1)
				deliveryAddress.PostOfficeBox = addressParts[0].Trim();

			if (deliveryAddress.IsEmpty())
            {

                // No address appears to be defined.
                // Ignore.

                return;

            }

            // Handle the old 2.1 format in which the ADR type names (e.g.
            // DOM, HOME, etc) were written directly as subproperties.
            // For example, "ADR;HOME;POSTAL:...".

            deliveryAddress.AddressType =
                ParseDeliveryAddressType(property.Subproperties.GetNames(DeliveryAddressTypeNames));

            // Handle the new 3.0 format in which the delivery address
            // type is a comma-delimited list, e.g. "ADR;TYPE=HOME,POSTAL:".
            // It is possible for the TYPE subproperty to be listed multiple
            // times (this is allowed by the RFC, although irritating that
            // the authors allowed it).

            foreach (vCardSubproperty sub in property.Subproperties)
            {

                // If this subproperty is a TYPE subproperty and
                // has a non-null value, then parse it.

                if (
                    (!string.IsNullOrEmpty(sub.Value)) &&
                    (string.Compare("TYPE", sub.Name, StringComparison.OrdinalIgnoreCase) == 0))
                {

                    deliveryAddress.AddressType |=
                        ParseDeliveryAddressType(sub.Value.Split(new char[] { ',' }));

                }

            }

            card.DeliveryAddresses.Add(deliveryAddress);

        }
        public void ReadWriteProperty_IsWork()
        {

            vCardDeliveryAddress address = new vCardDeliveryAddress();
            address.IsWork = true;
            Assert.IsTrue(
                address.IsWork,
                "IsWork should have been set to true.");

            address.IsWork = false;
            Assert.IsFalse(
                address.IsWork,
                "IsWork should have been set to false.");
        }
        public void ReadWriteProperty_IsInternational()
        {

            vCardDeliveryAddress address = new vCardDeliveryAddress();
            address.IsInternational = true;
            Assert.IsTrue(
                address.IsInternational,
                "IsInternational should have been set to true.");

            address.IsInternational = false;
            Assert.IsFalse(
                address.IsInternational,
                "IsInternational should have been set to false.");
        }