public void FlickrConfigurationSettingsConstructorTest() { const string xml = "<flickrNet apiKey=\"apikey\" secret=\"secret\" token=\"thetoken\" " + "cacheDisabled=\"true\" cacheSize=\"1024\" cacheTimeout=\"01:00:00\" " + "cacheLocation=\"testlocation\" service=\"flickr\">" + "<proxy ipaddress=\"localhost\" port=\"8800\" username=\"testusername\" " + "password=\"testpassword\" domain=\"testdomain\"/>" + "</flickrNet>"; var doc = new XmlDocument(); doc.LoadXml(xml); var configNode = doc.SelectSingleNode("flickrNet"); var target = new FlickrConfigurationSettings(configNode); Assert.AreEqual("apikey", target.ApiKey); Assert.AreEqual("secret", target.SharedSecret); Assert.AreEqual("thetoken", target.ApiToken); Assert.IsTrue(target.CacheDisabled); Assert.AreEqual(1024, target.CacheSize); Assert.AreEqual(new TimeSpan(1, 0, 0), target.CacheTimeout); Assert.AreEqual("testlocation", target.CacheLocation); Assert.IsTrue(target.IsProxyDefined, "IsProxyDefined should be true"); Assert.AreEqual("localhost", target.ProxyIPAddress); Assert.AreEqual(8800, target.ProxyPort); Assert.AreEqual("testusername", target.ProxyUsername); Assert.AreEqual("testpassword", target.ProxyPassword); Assert.AreEqual("testdomain", target.ProxyDomain); }
/// <summary> /// Constructor loads configuration settings from app.config or web.config file if they exist. /// </summary> public Flickr() { #if !(MONOTOUCH || WindowsCE || SILVERLIGHT) FlickrConfigurationSettings settings = FlickrConfigurationManager.Settings; if (settings == null) { return; } if (settings.CacheSize != 0) { CacheSizeLimit = settings.CacheSize; } if (settings.CacheTimeout != TimeSpan.MinValue) { CacheTimeout = settings.CacheTimeout; } ApiKey = settings.ApiKey; AuthToken = settings.ApiToken; ApiSecret = settings.SharedSecret; if (settings.IsProxyDefined) { Proxy = new WebProxy(); Proxy.Address = new Uri("http://" + settings.ProxyIPAddress + ":" + settings.ProxyPort); if (settings.ProxyUsername != null && settings.ProxyUsername.Length > 0) { NetworkCredential creds = new NetworkCredential(); creds.UserName = settings.ProxyUsername; creds.Password = settings.ProxyPassword; creds.Domain = settings.ProxyDomain; Proxy.Credentials = creds; } } #endif InstanceCacheDisabled = CacheDisabled; CurrentService = DefaultService; }