Ejemplo n.º 1
0
        /// <summary>
        /// Get cached countries.
        /// </summary>
        /// <param name="context">Web service request context.</param>
        /// <returns>Cached countries.</returns>
        private static Hashtable GetCachedCountries(WebServiceContext context)
        {
            Hashtable  countries;
            WebCountry country;

            // Get cached information.
            countries = (Hashtable)context.GetCachedObject(Settings.Default.CountryCacheKey);

            // Data not in cache - store it in the cache.
            if (countries.IsNull())
            {
                // Get information from database.
                using (DataReader dataReader = context.GetUserDatabase().GetCountries())
                {
                    countries = new Hashtable();
                    while (dataReader.Read())
                    {
                        country = new WebCountry();
                        country.LoadData(dataReader);

                        // Add object to Hashtable.
                        countries.Add(country.Id, country);
                    }
                    // Add information to cache.
                    context.AddCachedObject(Settings.Default.CountryCacheKey,
                                            countries,
                                            DateTime.Now + new TimeSpan(1, 0, 0, 0),
                                            CacheItemPriority.High);
                }
            }
            return(countries);
        }
Ejemplo n.º 2
0
        public void PhoneNumberPrefix()
        {
            WebCountry country = GetCountry();

            country.PhoneNumberPrefix = 46;
            Assert.AreEqual(country.PhoneNumberPrefix, 46);
        }
Ejemplo n.º 3
0
        public void ISOName()
        {
            WebCountry country = GetCountry();

            country.ISOName = "Namn";
            Assert.AreEqual(country.ISOName, "Namn");
        }
Ejemplo n.º 4
0
        public void ISOCode()
        {
            WebCountry country = GetCountry();

            country.ISOAlpha2Code = "Namn";
            Assert.AreEqual(country.ISOAlpha2Code, "Namn");
        }
Ejemplo n.º 5
0
        public void Constructor()
        {
            WebCountry country;

            country = new WebCountry();
            Assert.IsNotNull(country);
        }
Ejemplo n.º 6
0
        public void Id()
        {
            WebCountry country = GetCountry();

            country.Id = 1;
            Assert.AreEqual(country.Id, 1);
        }
Ejemplo n.º 7
0
 public WebCountry GetCountry(Boolean refresh)
 {
     if (_country.IsNull() || refresh)
     {
         _country = CountryManager.GetCountries(GetContext())[25];
     }
     return(_country);
 }
Ejemplo n.º 8
0
 private WebCountry GetCountry(Boolean refresh)
 {
     if (_country.IsNull() || refresh)
     {
         _country = new WebCountry();
     }
     return(_country);
 }
 /// <summary>
 /// Load data into the WebCountry instance.
 /// </summary>
 /// <param name="country">This country.</param>
 /// <param name='dataReader'>An open data reader.</param>
 public static void LoadData(this WebCountry country,
                             DataReader dataReader)
 {
     country.Id                = dataReader.GetInt32(CountryData.ID);
     country.Name              = dataReader.GetString(CountryData.NAME);
     country.NativeName        = dataReader.GetString(CountryData.NATIVE_NAME, DEFAULT_NAME);
     country.ISOName           = dataReader.GetString(CountryData.ISO_NAME);
     country.ISOAlpha2Code     = dataReader.GetString(CountryData.ISO_CODE);
     country.PhoneNumberPrefix = dataReader.GetInt32(CountryData.PHONE_NUMBER_PREFIX, _int32Default);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Get country with specified id.
        /// </summary>
        /// <param name="context">Web service request context.</param>
        /// <param name="countryId">Requested country id</param>
        /// <returns>Country with specified id.</returns>
        public static WebCountry GetCountry(WebServiceContext context,
                                            Int32 countryId)
        {
            WebCountry webCountry = (WebCountry)(GetCachedCountries(context)[countryId]);

            if (webCountry.IsNull())
            {
                throw new ArgumentException("Country not found. CountryId = " + countryId);
            }
            return(webCountry);
        }
 /// <summary>
 /// Get country from web country.
 /// </summary>
 /// <param name="userContext">User context.</param>
 /// <param name="webCountry">Web country.</param>
 /// <returns>Country.</returns>
 protected ICountry GetCountry(IUserContext userContext,
                               WebCountry webCountry)
 {
     return(new Country(webCountry.Id,
                        webCountry.ISOAlpha2Code,
                        webCountry.ISOName,
                        webCountry.Name,
                        webCountry.NativeName,
                        webCountry.PhoneNumberPrefix,
                        GetDataContext(userContext)));
 }
        /// <summary>
        /// Get web country from country.
        /// </summary>
        /// <param name="userContext">User context.</param>
        /// <param name="country">country.</param>
        /// <returns>Web country.</returns>
        protected WebCountry GetCountry(IUserContext userContext,
                                        ICountry country)
        {
            WebCountry webCountry;

            webCountry                   = new WebCountry();
            webCountry.Id                = country.Id;
            webCountry.ISOAlpha2Code     = country.ISOCode;
            webCountry.ISOName           = country.ISOName;
            webCountry.Name              = country.Name;
            webCountry.NativeName        = country.NativeName;
            webCountry.PhoneNumberPrefix = country.PhoneNumberPrefix;
            return(webCountry);
        }
        public void UpdateOrganizationAddress()
        {
            String city, postalAddress1, postalAddress2, zipCode;

            WebOrganization organization, updatedOrganization;
            WebAddress      address;
            WebCountry      country;
            WebAddressType  addressType;

            organization           = new WebOrganization();
            organization           = GetOneOrganization();
            address                = new WebAddress();
            city                   = "Uppsala";
            address.City           = city;
            country                = new WebCountry();
            country                = CountryManager.GetCountry(GetContext(), Settings.Default.TestCountryId);
            address.Country        = country;
            postalAddress1         = "";
            address.PostalAddress1 = postalAddress1;
            postalAddress2         = "ArtDatabanken, SLU";
            address.PostalAddress2 = postalAddress2;
            zipCode                = "752 52";
            address.ZipCode        = zipCode;
            addressType            = new WebAddressType();
            addressType.Id         = 1;
            address.Type           = addressType;
            organization.Addresses.Add(address);

            updatedOrganization = new WebOrganization();
            updatedOrganization = OrganizationManager.UpdateOrganization(GetContext(), organization);

            Assert.IsNotNull(updatedOrganization);
            Assert.IsTrue(updatedOrganization.Addresses.IsNotEmpty());
            Assert.AreEqual(1, updatedOrganization.Addresses.Count);
            Assert.AreEqual(city, updatedOrganization.Addresses[0].City);
            Assert.AreEqual(country.Id, updatedOrganization.Addresses[0].Country.Id);
            Assert.AreEqual(postalAddress1, updatedOrganization.Addresses[0].PostalAddress1);
            Assert.AreEqual(postalAddress2, updatedOrganization.Addresses[0].PostalAddress2);
            Assert.AreEqual(zipCode, updatedOrganization.Addresses[0].ZipCode);
        }
Ejemplo n.º 14
0
 public WebCountryExtensionTest()
 {
     _country = null;
 }
Ejemplo n.º 15
0
 public WebCountryTest()
 {
     _country = null;
 }