Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3286)

Side by Side Diff: Src/GoogleApis.Tools.CodeGen.Tests/CachedWebDiscoveryDeviceTests.cs

Issue 12020043: Issue 325 - Remove discovery and codegen (Closed) Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Patch Set: Sir miceli comment Created 10 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 Copyright 2011 Google Inc
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 using System;
18 using System.IO;
19
20 using NUnit.Framework;
21
22 using Google.Apis.Tools.CodeGen;
23
24 namespace Google.Apis.Tests
25 {
26 /// <summary>
27 /// Tests the cache functionallity of the discovery devices
28 /// IntegrationTest·
29 /// -- requires File IO access to the cache dir
30 /// -- requires Internet access to http://google.com
31 /// </summary>
32 [TestFixture]
33 public class CachedWebDiscoveryDeviceTests
34 {
35 /// <summary>
36 /// Tests the cache procedure
37 /// </summary>
38 [Test]
39 public void Cache()
40 {
41 var device = new CachedWebDiscoveryDevice { DiscoveryUri = new Uri(" http://google.com") };
42
43 // Get the cache file info
44 FileInfo cacheFile = device.GetCacheFile();
45 Assert.IsNotNull(cacheFile);
46
47 // Delete the file (if it exists)
48 if (cacheFile.Exists)
49 {
50 cacheFile.Delete();
51 }
52
53 // Check that the file does not exist anymore
54 cacheFile = device.GetCacheFile();
55 Assert.IsFalse(cacheFile.Exists);
56
57 // Execute the fetch
58 using (Stream stream = device.Fetch())
59 {
60 Assert.IsNotNull(stream);
61 }
62
63 // Check if the file was cached
64 cacheFile = device.GetCacheFile();
65 Assert.IsTrue(cacheFile.Exists);
66 Assert.That(cacheFile.Length, Is.GreaterThan(0));
67
68 // Remove the newly created file
69 cacheFile.Delete();
70 }
71
72 /// <summary>
73 /// Tests if the constructor works
74 /// </summary>
75 [Test]
76 public void ConstructTest()
77 {
78 Assert.DoesNotThrow(() => new CachedWebDiscoveryDevice());
79 }
80
81 /// <summary>
82 /// Tests if invalid file names are escaped
83 /// </summary>
84 [Test]
85 public void InvalidFilenames()
86 {
87 var device = new CachedWebDiscoveryDevice
88 {
89 DiscoveryUri = new Uri("http://google.com/$#@!%^&*()[]+=/\\< >:;")
90 };
91
92 // Check if the file name was escaped at all
93 FileInfo cacheFile = device.GetCacheFile();
94 Assert.That(cacheFile.Name.Contains("_"));
95
96 // Check the result
97 Assert.IsFalse(cacheFile.Name.Contains("/"));
98
99 if (Environment.OSVersion.Platform != PlatformID.Unix)
100 {
101 // Don't check this on mono, as mono automatically escapes the f ile name
102 Assert.IsTrue(cacheFile.Name.StartsWith("http___google.com_$#@!% 25^&_()[]+=_____;-"));
103 }
104 }
105
106 /// <summary>
107 /// Tests if an URI can be assigned to this device
108 /// </summary>
109 [Test]
110 public void SetCacheDurationTest()
111 {
112 // Check that the cache duration is set to 3 days per default
113 var device = new CachedWebDiscoveryDevice();
114 Assert.That(device.CacheDuration, Is.EqualTo(3 * 24 * 60 * 60));
115
116 device.CacheDuration = 100;
117 Assert.That(device.CacheDuration, Is.EqualTo(100));
118 }
119
120 /// <summary>
121 /// Tests if an URI can be assigned to this device
122 /// </summary>
123 [Test]
124 public void SetURITest()
125 {
126 var device = new CachedWebDiscoveryDevice { DiscoveryUri = new Uri(" http://google.com") };
127 Assert.IsNotNull(device.DiscoveryUri);
128 Assert.AreEqual("http://google.com/", device.DiscoveryUri.ToString() );
129 }
130 }
131 }
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b