public void Cache()
        {
            var device = new CachedWebDiscoveryDevice { DiscoveryUri = new Uri("http://google.com") };

            // Get the cache file info
            FileInfo cacheFile = device.GetCacheFile();
            Assert.IsNotNull(cacheFile);

            // Delete the file (if it exists)
            if (cacheFile.Exists)
            {
                cacheFile.Delete();
            }

            // Check that the file does not exist anymore
            cacheFile = device.GetCacheFile();
            Assert.IsFalse(cacheFile.Exists);

            // Execute the fetch
            using (Stream stream = device.Fetch())
            {
                Assert.IsNotNull(stream);
            }

            // Check if the file was cached
            cacheFile = device.GetCacheFile();
            Assert.IsTrue(cacheFile.Exists);
            Assert.That(cacheFile.Length, Is.GreaterThan(0));

            // Remove the newly created file
            cacheFile.Delete();
        }
Beispiel #2
0
        private static IService DiscoverService(string serviceName, string serviceVersion)
        {
            // Create the discovery URL
            var discoveryURL = string.Format(GoogleServiceGenerator.GoogleDiscoveryURL, serviceName, serviceVersion);
            var device = new CachedWebDiscoveryDevice(new Uri(discoveryURL));

            // Discover the servi2ce using the hand-coded discovery service
            var discovery = new DiscoveryService(device);
            return discovery.GetService(DiscoveryVersion.Version_1_0);
        }
        public void InvalidFilenames()
        {
            var device = new CachedWebDiscoveryDevice
                             { DiscoveryUri = new Uri("http://google.com/$#@!%^&*()[]+=/\\<>:;") };

            // Check if the file name was escaped at all
            FileInfo cacheFile = device.GetCacheFile();
            Assert.That(cacheFile.Name.Contains("_"));

            // Check the result
            Assert.IsFalse(cacheFile.Name.Contains("/"));
            
            if (Environment.OSVersion.Platform != PlatformID.Unix)
            {
                // Don't check this on mono, as mono automatically escapes the file name
                Assert.IsTrue(cacheFile.Name.StartsWith("http___google.com_$#@!%25^&_()[]+=_____;-"));
            }
        }
 /// <summary>
 /// Creates a cached web discovery device
 /// </summary>
 internal static IDiscoveryService CreateDefaultCachingDiscovery(string serviceUrl)
 {
     // Set up how discovery works.
     string cacheDirectory = Path.Combine(
         Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "GoogleApis.Tools.CodeGenCache");
     if (Directory.Exists(cacheDirectory) == false)
     {
         Directory.CreateDirectory(cacheDirectory);
     }
     var webfetcher = new CachedWebDiscoveryDevice(new Uri(serviceUrl), new DirectoryInfo(cacheDirectory));
     return new DiscoveryService(webfetcher);
 }
 public void SetURITest()
 {
     var device = new CachedWebDiscoveryDevice { DiscoveryUri = new Uri("http://google.com") };
     Assert.IsNotNull(device.DiscoveryUri);
     Assert.AreEqual("http://google.com/", device.DiscoveryUri.ToString());
 }
        public void SetCacheDurationTest()
        {
            // Check that the cache duration is set to 3 days per default
            var device = new CachedWebDiscoveryDevice();
            Assert.That(device.CacheDuration, Is.EqualTo(3 * 24 * 60 * 60));

            device.CacheDuration = 100;
            Assert.That(device.CacheDuration, Is.EqualTo(100));
        }