root / trunk / Pithos.Network.Test / NetworkOpsTest.cs @ 3c43ec9b
History | View | Annotate | Download (11.3 kB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Diagnostics; |
4 |
using System.Diagnostics.Contracts; |
5 |
using System.Linq; |
6 |
using System.Text; |
7 |
using NUnit.Framework; |
8 |
using Pithos.Interfaces; |
9 |
using System.IO; |
10 |
|
11 |
namespace Pithos.Network.Test |
12 |
{ |
13 |
[TestFixture] |
14 |
class NetworkOpsTest |
15 |
{ |
16 |
private string _apiKey = "9d3cb7b231e96f72ebe96af1c6cd5112"; |
17 |
private string _userName = "pkanavos"; |
18 |
|
19 |
|
20 |
|
21 |
[Test] |
22 |
public void TestAuthenticate([Values(true,false)]bool usePithos) |
23 |
{ |
24 |
ICloudClient client = new CloudFilesClient{UsePithos=usePithos}; |
25 |
client.Authenticate(_userName, _apiKey); |
26 |
Uri storageUrl=client.StorageUrl; |
27 |
string token = client.Token; |
28 |
|
29 |
Assert.IsNotNull(storageUrl, "Storage Url was empty"); |
30 |
Assert.IsNotEmpty(token, "Token was empty"); |
31 |
} |
32 |
|
33 |
[Test] |
34 |
public void TestListContainers([Values(true, false)]bool usePithos) |
35 |
{ |
36 |
ICloudClient client = new CloudFilesClient { UsePithos = usePithos }; |
37 |
client.Authenticate(_userName, _apiKey); |
38 |
client.CreateContainer("PITHOS"); |
39 |
|
40 |
IList<ContainerInfo> containers=client.ListContainers(); |
41 |
Assert.IsTrue(containers.Count()>1); |
42 |
} |
43 |
|
44 |
[Test] |
45 |
public void TestListObjects([Values(true, false)]bool usePithos) |
46 |
{ |
47 |
ICloudClient client = new CloudFilesClient { UsePithos = usePithos }; |
48 |
client.Authenticate(_userName, _apiKey); |
49 |
client.CreateContainer("PITHOS"); |
50 |
client.PutObject("PITHOS","devguide.pdf","devguide.pdf"); |
51 |
|
52 |
IList<ObjectInfo> objects=client.ListObjects("PITHOS"); |
53 |
Assert.IsTrue(objects.Count()>=1); |
54 |
} |
55 |
|
56 |
[Test] |
57 |
public void TestContainerExists([Values(true, false)]bool usePithos) |
58 |
{ |
59 |
ICloudClient client = new CloudFilesClient { UsePithos = usePithos }; |
60 |
client.Authenticate(_userName, _apiKey); |
61 |
client.CreateContainer("TestContainer"); |
62 |
bool dnzExists=client.ContainerExists("TestContainer"); |
63 |
|
64 |
bool mooExists = client.ContainerExists("Moo"); |
65 |
Assert.IsTrue(dnzExists); |
66 |
|
67 |
Assert.IsFalse(mooExists); |
68 |
} |
69 |
|
70 |
[Test] |
71 |
public void TestGetContainerInfo([Values(true, false)]bool usePithos) |
72 |
{ |
73 |
ICloudClient client = new CloudFilesClient { UsePithos = usePithos }; |
74 |
client.Authenticate(_userName, _apiKey); |
75 |
|
76 |
client.CreateContainer("PITHOS"); |
77 |
client.CreateContainer("DotNetZone"); |
78 |
|
79 |
var dnzInfo =client.GetContainerInfo("DotNetZone"); |
80 |
Assert.AreNotEqual(ContainerInfo.Empty, dnzInfo,"Expected DotNetZone container not found"); |
81 |
|
82 |
var pithosInfo = client.GetContainerInfo("PITHOS"); |
83 |
Assert.AreNotEqual(ContainerInfo.Empty, pithosInfo,"Expected PITHOS container not found"); |
84 |
|
85 |
var mooInfo = client.GetContainerInfo("moo"); |
86 |
Assert.AreEqual(ContainerInfo.Empty, mooInfo); |
87 |
} |
88 |
|
89 |
[Test] |
90 |
public void TestCreateContainer([Values(true, false)]bool usePithos) |
91 |
{ |
92 |
Assert.DoesNotThrow(() => |
93 |
{ |
94 |
ICloudClient client = new CloudFilesClient{UsePithos=usePithos}; |
95 |
client.Authenticate(_userName, _apiKey); |
96 |
|
97 |
client.CreateContainer("Shares2"); |
98 |
Assert.IsTrue(client.ContainerExists("Shares2")); |
99 |
client.DeleteContainer("Shares2"); |
100 |
|
101 |
client.CreateContainer("Shares"); |
102 |
Assert.IsTrue(client.ContainerExists("Shares")); |
103 |
client.CreateContainer("DotNetZone"); |
104 |
Assert.IsTrue(client.ContainerExists("DotNetZone")); |
105 |
}); |
106 |
} |
107 |
|
108 |
[Test] |
109 |
public void TestGetObject([Values(true, false)]bool usePithos) |
110 |
{ |
111 |
Assert.DoesNotThrow(() => |
112 |
{ |
113 |
ICloudClient client = new CloudFilesClient { UsePithos = usePithos }; |
114 |
client.Authenticate(_userName, _apiKey); |
115 |
//Prepare test file |
116 |
client.CreateContainer("Shares"); |
117 |
string testFileName = "test.txt"; |
118 |
var info = new FileInfo(testFileName); |
119 |
client.PutObject("Shares",testFileName,testFileName); |
120 |
|
121 |
|
122 |
string downloadFile = "test2.txt"; |
123 |
client.GetObject("Shares", testFileName, downloadFile) |
124 |
.Wait(); |
125 |
|
126 |
Assert.IsTrue(File.Exists(downloadFile)); |
127 |
|
128 |
}); |
129 |
|
130 |
} |
131 |
|
132 |
[Test] |
133 |
public void TestPutObject([Values(true, false)]bool usePithos) |
134 |
{ |
135 |
Assert.DoesNotThrow(() => |
136 |
{ |
137 |
ICloudClient client = new CloudFilesClient {UsePithos = usePithos}; |
138 |
client.Authenticate(_userName, _apiKey); |
139 |
|
140 |
client.CreateContainer("Shares"); |
141 |
Assert.IsTrue(client.ContainerExists("Shares")); |
142 |
|
143 |
var filePath = "devguide.pdf"; |
144 |
FileInfo info = new FileInfo(filePath); |
145 |
|
146 |
|
147 |
client.PutObject("Shares", info.Name, filePath); |
148 |
|
149 |
|
150 |
}); |
151 |
|
152 |
} |
153 |
|
154 |
[Test] |
155 |
public void TestGetObjectMetadata([Values(true, false)]bool usePithos) |
156 |
{ |
157 |
Assert.DoesNotThrow(() => |
158 |
{ |
159 |
ICloudClient client = new CloudFilesClient { UsePithos = usePithos }; |
160 |
client.Authenticate(_userName, _apiKey); |
161 |
|
162 |
client.CreateContainer("Shares"); |
163 |
Assert.IsTrue(client.ContainerExists("Shares")); |
164 |
|
165 |
var filePath = "devguide.pdf"; |
166 |
FileInfo info = new FileInfo(filePath); |
167 |
|
168 |
|
169 |
client.PutObject("Shares", info.Name, filePath); |
170 |
|
171 |
|
172 |
|
173 |
|
174 |
var meta=client.GetObjectInfo("Shares", filePath); |
175 |
Assert.IsNotEmpty(meta.Hash); |
176 |
Assert.AreEqual(meta.Name,filePath); |
177 |
|
178 |
}); |
179 |
|
180 |
} |
181 |
|
182 |
[Test] |
183 |
public void TestDeleteObject([Values(true, false)]bool usePithos) |
184 |
{ |
185 |
Assert.DoesNotThrow(() => |
186 |
{ |
187 |
ICloudClient client = new CloudFilesClient { UsePithos = usePithos }; |
188 |
client.Authenticate(_userName, _apiKey); |
189 |
|
190 |
client.CreateContainer("Shares"); |
191 |
Assert.IsTrue(client.ContainerExists("Shares"),"Container Exists"); |
192 |
|
193 |
var filePath = "devguide.pdf"; |
194 |
FileInfo info=new FileInfo(filePath); |
195 |
|
196 |
|
197 |
client.PutObject("Shares",info.Name, filePath); |
198 |
|
199 |
|
200 |
Assert.IsTrue(client.ObjectExists("Shares",info.Name),"File Created"); |
201 |
|
202 |
client.DeleteObject("Shares/devguide.pdf",info.Name); |
203 |
|
204 |
}); |
205 |
|
206 |
} |
207 |
|
208 |
[Test] |
209 |
public void TestDeleteContainer([Values(true, false)]bool usePithos) |
210 |
{ |
211 |
Assert.DoesNotThrow(() => |
212 |
{ |
213 |
ICloudClient client = new CloudFilesClient { UsePithos = usePithos }; |
214 |
client.Authenticate(_userName, _apiKey); |
215 |
|
216 |
client.CreateContainer("Shares"); |
217 |
Assert.IsTrue(client.ContainerExists("Shares"),"Container Exists"); |
218 |
|
219 |
var filePath = "devguide.pdf"; |
220 |
FileInfo info=new FileInfo(filePath); |
221 |
|
222 |
|
223 |
client.PutObject("Shares",info.Name, filePath ); |
224 |
|
225 |
|
226 |
Assert.IsTrue(client.ObjectExists("Shares",info.Name),"File Created"); |
227 |
|
228 |
client.DeleteObject("Shares",info.Name); |
229 |
Assert.IsFalse(client.ObjectExists("Shares", info.Name),"Container Deleted"); |
230 |
|
231 |
client.DeleteObject("Moo",info.Name); |
232 |
Assert.IsFalse(client.ObjectExists("Moo", info.Name),"Container Deleted"); |
233 |
|
234 |
}); |
235 |
|
236 |
} |
237 |
|
238 |
/* [Test] |
239 |
public void TestFilesWithSpaces([Values(true, false)]bool usePithos) |
240 |
{ |
241 |
ICloudClient client = new CloudFilesClient { UsePithos = usePithos }; |
242 |
client.Authenticate(_userName, _apiKey); |
243 |
|
244 |
var testName = "Name with spaces.txt"; |
245 |
|
246 |
using(var stream=new MemoryStream()) |
247 |
using (var writer = new File.(stream)) |
248 |
{ |
249 |
|
250 |
writer.WriteLine("This is a test line"); |
251 |
stream.Seek(0, 0); |
252 |
|
253 |
client.PutObject("PITHOS",testName,stream,stream.Length); |
254 |
} |
255 |
|
256 |
Assert.DoesNotThrow(() => |
257 |
{ |
258 |
var info = client.GetObjectInfo("PITHOS", testName); |
259 |
Assert.AreEqual(testName, info.Name); |
260 |
}); |
261 |
Assert.DoesNotThrow(() => |
262 |
{ |
263 |
client.DeleteObject("PITHOS", testName); |
264 |
}); |
265 |
}*/ |
266 |
|
267 |
[Test] |
268 |
public void TestMoveObject([Values(true, false)]bool usePithos) |
269 |
{ |
270 |
Assert.DoesNotThrow(() => |
271 |
{ |
272 |
ICloudClient client = new CloudFilesClient { UsePithos = usePithos }; |
273 |
client.Authenticate(_userName, _apiKey); |
274 |
|
275 |
client.CreateContainer("Shares"); |
276 |
Assert.IsTrue(client.ContainerExists("Shares"),"Container Exists"); |
277 |
|
278 |
var filePath = "devguide.pdf"; |
279 |
FileInfo info=new FileInfo(filePath); |
280 |
|
281 |
|
282 |
client.PutObject("Shares",info.Name, filePath); |
283 |
|
284 |
|
285 |
Assert.IsTrue(client.ObjectExists("Shares",info.Name),"File Created"); |
286 |
|
287 |
client.MoveObject("Shares",info.Name,"Shares","smoo.pdf"); |
288 |
Assert.IsFalse(client.ObjectExists("Shares", info.Name),"Original File Deleted"); |
289 |
Assert.IsTrue(client.ObjectExists("Shares", "smoo.pdf"), "Target File Created"); |
290 |
|
291 |
}); |
292 |
|
293 |
} |
294 |
|
295 |
[Test] |
296 |
public void TestGetObjectMissing() |
297 |
{ |
298 |
|
299 |
} |
300 |
|
301 |
|
302 |
[Test] |
303 |
public void TestAuthenticateMissingArguments([Values(true, false)]bool usePithos) |
304 |
{ |
305 |
Assert.Catch<ArgumentNullException>(() => |
306 |
{ |
307 |
ICloudClient client = new CloudFilesClient { UsePithos = usePithos }; |
308 |
client.Authenticate("someUser",null); |
309 |
}); |
310 |
|
311 |
Assert.Catch<ArgumentNullException>(() => |
312 |
{ |
313 |
ICloudClient client = new CloudFilesClient { UsePithos = usePithos }; |
314 |
client.Authenticate(null,"someKey"); |
315 |
}); |
316 |
|
317 |
} |
318 |
|
319 |
|
320 |
} |
321 |
|
322 |
|
323 |
} |