root / trunk / Pithos.Network.Test / FolderTests.cs @ 1b4a7550
History | View | Annotate | Download (6.6 kB)
1 | 10523ad9 | Panagiotis Kanavos | using System; |
---|---|---|---|
2 | 10523ad9 | Panagiotis Kanavos | using System.Collections.Generic; |
3 | 10523ad9 | Panagiotis Kanavos | using System.Diagnostics; |
4 | 10523ad9 | Panagiotis Kanavos | using System.Diagnostics.Contracts; |
5 | 10523ad9 | Panagiotis Kanavos | using System.Linq; |
6 | 10523ad9 | Panagiotis Kanavos | using System.Text; |
7 | 10523ad9 | Panagiotis Kanavos | using NUnit.Framework; |
8 | 10523ad9 | Panagiotis Kanavos | using Pithos.Interfaces; |
9 | 10523ad9 | Panagiotis Kanavos | using System.IO; |
10 | 10523ad9 | Panagiotis Kanavos | |
11 | 10523ad9 | Panagiotis Kanavos | |
12 | 10523ad9 | Panagiotis Kanavos | namespace Pithos.Network.Test |
13 | 10523ad9 | Panagiotis Kanavos | { |
14 | 10523ad9 | Panagiotis Kanavos | [TestFixture] |
15 | 10523ad9 | Panagiotis Kanavos | class FolderTests |
16 | 10523ad9 | Panagiotis Kanavos | { |
17 | 10523ad9 | Panagiotis Kanavos | [SetUp] |
18 | 10523ad9 | Panagiotis Kanavos | public void Setup() |
19 | 10523ad9 | Panagiotis Kanavos | { |
20 | 10523ad9 | Panagiotis Kanavos | Directory.CreateDirectory("RootFolder"); |
21 | 10523ad9 | Panagiotis Kanavos | File.WriteAllText(@"RootFolder\TestFile1.txt", "This is a test file"); |
22 | 10523ad9 | Panagiotis Kanavos | Directory.CreateDirectory(@"RootFolder\Folder1"); |
23 | 10523ad9 | Panagiotis Kanavos | File.WriteAllText(@"RootFolder\Folder1\TestFile1.txt", "This is a test file"); |
24 | 10523ad9 | Panagiotis Kanavos | Directory.CreateDirectory(@"RootFolder\Folder1\Subfolder1"); |
25 | 10523ad9 | Panagiotis Kanavos | File.WriteAllText(@"RootFolder\Folder1\Subfolder1\TestFile1.txt", "This is a test file"); |
26 | 10523ad9 | Panagiotis Kanavos | Directory.CreateDirectory(@"RootFolder\Folder2"); |
27 | 10523ad9 | Panagiotis Kanavos | File.WriteAllText(@"RootFolder\Folder2\TestFile1.txt", "This is a test file"); |
28 | 10523ad9 | Panagiotis Kanavos | |
29 | 10523ad9 | Panagiotis Kanavos | } |
30 | 10523ad9 | Panagiotis Kanavos | |
31 | 10523ad9 | Panagiotis Kanavos | [TearDown] |
32 | 10523ad9 | Panagiotis Kanavos | public void TearDown() |
33 | 10523ad9 | Panagiotis Kanavos | { |
34 | 10523ad9 | Panagiotis Kanavos | Directory.Delete("RootFolder",true); |
35 | 10523ad9 | Panagiotis Kanavos | } |
36 | 10523ad9 | Panagiotis Kanavos | |
37 | 10523ad9 | Panagiotis Kanavos | [Test] |
38 | 10523ad9 | Panagiotis Kanavos | public void TestCreateSingleFolder([Values(true, false)]bool usePithos) |
39 | 10523ad9 | Panagiotis Kanavos | { |
40 | c53aa229 | Panagiotis Kanavos | var account = "890329@vho.grnet.gr"; |
41 | c53aa229 | Panagiotis Kanavos | var apiKey = "24989dce4e0fcb072f8cb60c8922be19"; |
42 | c53aa229 | Panagiotis Kanavos | var client = new CloudFilesClient(account, apiKey){ UsePithos = usePithos }; |
43 | c53aa229 | Panagiotis Kanavos | client.Authenticate(); |
44 | 10523ad9 | Panagiotis Kanavos | |
45 | cfed7823 | Panagiotis Kanavos | client.CreateContainer(null, "Pithos"); |
46 | 10523ad9 | Panagiotis Kanavos | |
47 | cfed7823 | Panagiotis Kanavos | client.CreateFolder(null, "Pithos", "RootFolder"); |
48 | 10523ad9 | Panagiotis Kanavos | |
49 | cfed7823 | Panagiotis Kanavos | Assert.IsTrue(client.ObjectExists(null, "Pithos","RootFolder")); |
50 | cfed7823 | Panagiotis Kanavos | var info = client.GetObjectInfo(null, "Pithos", "RootFolder"); |
51 | 10523ad9 | Panagiotis Kanavos | Assert.AreEqual(@"application/directory",info.Content_Type); |
52 | 10523ad9 | Panagiotis Kanavos | |
53 | 10523ad9 | Panagiotis Kanavos | } |
54 | 10523ad9 | Panagiotis Kanavos | |
55 | 10523ad9 | Panagiotis Kanavos | [Test] |
56 | 10523ad9 | Panagiotis Kanavos | public void TestCreateSubFolders([Values(true, false)]bool usePithos) |
57 | 10523ad9 | Panagiotis Kanavos | { |
58 | c53aa229 | Panagiotis Kanavos | var account = "890329@vho.grnet.gr"; |
59 | c53aa229 | Panagiotis Kanavos | var apiKey = "24989dce4e0fcb072f8cb60c8922be19"; |
60 | c53aa229 | Panagiotis Kanavos | var client = new CloudFilesClient(account, apiKey) { UsePithos = usePithos }; |
61 | c53aa229 | Panagiotis Kanavos | client.Authenticate(); |
62 | 10523ad9 | Panagiotis Kanavos | |
63 | cfed7823 | Panagiotis Kanavos | client.CreateContainer(null, "Pithos"); |
64 | 10523ad9 | Panagiotis Kanavos | |
65 | cfed7823 | Panagiotis Kanavos | client.CreateFolder(null, "Pithos", "RootFolder"); |
66 | cfed7823 | Panagiotis Kanavos | client.CreateFolder(null, "Pithos", "RootFolder/Folder1"); |
67 | cfed7823 | Panagiotis Kanavos | client.PutObject(null, "Pithos","RootFolder/Folder1/test.txt","test.txt"); |
68 | 10523ad9 | Panagiotis Kanavos | |
69 | 10523ad9 | Panagiotis Kanavos | |
70 | cfed7823 | Panagiotis Kanavos | Assert.IsTrue(client.ObjectExists(null, "Pithos", "RootFolder/Folder1")); |
71 | cfed7823 | Panagiotis Kanavos | var folderInfo = client.GetObjectInfo(null, "Pithos", "RootFolder/Folder1"); |
72 | 10523ad9 | Panagiotis Kanavos | Assert.AreEqual(@"application/directory",folderInfo.Content_Type); |
73 | 10523ad9 | Panagiotis Kanavos | |
74 | 10523ad9 | Panagiotis Kanavos | |
75 | cfed7823 | Panagiotis Kanavos | Assert.IsTrue(client.ObjectExists(null, "Pithos", "RootFolder/Folder1/test.txt")); |
76 | cfed7823 | Panagiotis Kanavos | var fileInfo = client.GetObjectInfo(null, "Pithos", "RootFolder/Folder1/test.txt"); |
77 | 10523ad9 | Panagiotis Kanavos | Assert.AreEqual(@"application/octet-stream", fileInfo.Content_Type); |
78 | 10523ad9 | Panagiotis Kanavos | |
79 | 10523ad9 | Panagiotis Kanavos | } |
80 | 10523ad9 | Panagiotis Kanavos | |
81 | 10523ad9 | Panagiotis Kanavos | [Test] |
82 | 10523ad9 | Panagiotis Kanavos | public void TestDeleteSubFolders([Values(true, false)]bool usePithos) |
83 | 10523ad9 | Panagiotis Kanavos | { |
84 | c53aa229 | Panagiotis Kanavos | var account = "890329@vho.grnet.gr"; |
85 | c53aa229 | Panagiotis Kanavos | var apiKey = "24989dce4e0fcb072f8cb60c8922be19"; |
86 | c53aa229 | Panagiotis Kanavos | var client = new CloudFilesClient(account, apiKey) { UsePithos = usePithos }; |
87 | c53aa229 | Panagiotis Kanavos | client.Authenticate(); |
88 | 10523ad9 | Panagiotis Kanavos | |
89 | cfed7823 | Panagiotis Kanavos | client.CreateContainer(null, "Pithos"); |
90 | 10523ad9 | Panagiotis Kanavos | |
91 | cfed7823 | Panagiotis Kanavos | client.CreateFolder(null, "Pithos", "RootFolder"); |
92 | cfed7823 | Panagiotis Kanavos | client.CreateFolder(null, "Pithos", "RootFolder/Folder1"); |
93 | 10523ad9 | Panagiotis Kanavos | var localInfo = new FileInfo("test.txt"); |
94 | cfed7823 | Panagiotis Kanavos | client.PutObject(null, "Pithos","RootFolder/Folder1/test.txt","test.txt"); |
95 | 10523ad9 | Panagiotis Kanavos | |
96 | c53aa229 | Panagiotis Kanavos | client.DeleteObject(null, "pithos", "RootFolder/Folder1"); |
97 | 10523ad9 | Panagiotis Kanavos | |
98 | cfed7823 | Panagiotis Kanavos | Assert.IsTrue(client.ObjectExists(null, "Pithos", "RootFolder/Folder1")); |
99 | cfed7823 | Panagiotis Kanavos | var folderInfo = client.GetObjectInfo(null, "Pithos", "RootFolder/Folder1"); |
100 | 10523ad9 | Panagiotis Kanavos | Assert.AreEqual(@"application/directory",folderInfo.Content_Type); |
101 | 10523ad9 | Panagiotis Kanavos | |
102 | 10523ad9 | Panagiotis Kanavos | |
103 | cfed7823 | Panagiotis Kanavos | Assert.IsTrue(client.ObjectExists(null, "Pithos", "RootFolder/Folder1/test.txt")); |
104 | cfed7823 | Panagiotis Kanavos | var fileInfo = client.GetObjectInfo(null, "Pithos", "RootFolder/Folder1/test.txt"); |
105 | 10523ad9 | Panagiotis Kanavos | Assert.AreEqual(@"application/octet-stream", fileInfo.Content_Type); |
106 | 10523ad9 | Panagiotis Kanavos | |
107 | 10523ad9 | Panagiotis Kanavos | } |
108 | 637bc368 | Panagiotis Kanavos | |
109 | 637bc368 | Panagiotis Kanavos | [Test] |
110 | 637bc368 | Panagiotis Kanavos | public void ListFolderContents([Values(true, false)]bool usePithos) |
111 | 637bc368 | Panagiotis Kanavos | { |
112 | c53aa229 | Panagiotis Kanavos | var account = "890329@vho.grnet.gr"; |
113 | c53aa229 | Panagiotis Kanavos | var apiKey = "24989dce4e0fcb072f8cb60c8922be19"; |
114 | c53aa229 | Panagiotis Kanavos | var client = new CloudFilesClient(account, apiKey) { UsePithos = usePithos }; |
115 | c53aa229 | Panagiotis Kanavos | client.Authenticate(); |
116 | 637bc368 | Panagiotis Kanavos | |
117 | cfed7823 | Panagiotis Kanavos | client.CreateContainer(null, "Pithos"); |
118 | cfed7823 | Panagiotis Kanavos | client.CreateFolder(null, "Pithos", "RootFolder3"); |
119 | cfed7823 | Panagiotis Kanavos | client.CreateFolder(null, "Pithos", "RootFolder3/Folder1"); |
120 | 637bc368 | Panagiotis Kanavos | |
121 | 637bc368 | Panagiotis Kanavos | |
122 | cfed7823 | Panagiotis Kanavos | client.PutObject(null, "Pithos", "RootFolder3/test1.txt", "test.txt"); |
123 | cfed7823 | Panagiotis Kanavos | client.PutObject(null, "Pithos", "RootFolder3/test2.txt", "test.txt"); |
124 | cfed7823 | Panagiotis Kanavos | client.PutObject(null, "Pithos", "RootFolder3/Folder1/test2.txt", "test.txt"); |
125 | 637bc368 | Panagiotis Kanavos | |
126 | 637bc368 | Panagiotis Kanavos | var files=client.ListObjects("Pithos", "RootFolder3"); |
127 | 637bc368 | Panagiotis Kanavos | Assert.AreEqual(3,files.Count,"Unexpected number of root items"); |
128 | 637bc368 | Panagiotis Kanavos | |
129 | 637bc368 | Panagiotis Kanavos | files = client.ListObjects("Pithos", "RootFolder3/Folder1"); |
130 | 637bc368 | Panagiotis Kanavos | Assert.AreEqual(1, files.Count, "Unexpected number of subfolder items"); |
131 | 637bc368 | Panagiotis Kanavos | |
132 | 637bc368 | Panagiotis Kanavos | |
133 | 637bc368 | Panagiotis Kanavos | |
134 | 637bc368 | Panagiotis Kanavos | } |
135 | 10523ad9 | Panagiotis Kanavos | |
136 | 10523ad9 | Panagiotis Kanavos | [Test] |
137 | 10523ad9 | Panagiotis Kanavos | public void TestCreateSubFoldersInOneStep([Values(true, false)]bool usePithos) |
138 | 10523ad9 | Panagiotis Kanavos | { |
139 | c53aa229 | Panagiotis Kanavos | var account = "890329@vho.grnet.gr"; |
140 | c53aa229 | Panagiotis Kanavos | var apiKey = "24989dce4e0fcb072f8cb60c8922be19"; |
141 | c53aa229 | Panagiotis Kanavos | var client = new CloudFilesClient(account, apiKey) { UsePithos = usePithos }; |
142 | c53aa229 | Panagiotis Kanavos | client.Authenticate(); |
143 | 10523ad9 | Panagiotis Kanavos | |
144 | cfed7823 | Panagiotis Kanavos | client.CreateContainer(null, "Pithos"); |
145 | 10523ad9 | Panagiotis Kanavos | |
146 | cfed7823 | Panagiotis Kanavos | client.CreateFolder(null, "Pithos", "RootFolder2/Folder1"); |
147 | 10523ad9 | Panagiotis Kanavos | |
148 | cfed7823 | Panagiotis Kanavos | Assert.IsTrue(client.ObjectExists(null, "Pithos", "RootFolder2/Folder1")); |
149 | cfed7823 | Panagiotis Kanavos | var folderInfo = client.GetObjectInfo(null, "Pithos", "RootFolder2/Folder1"); |
150 | 10523ad9 | Panagiotis Kanavos | Assert.AreEqual(@"application/directory",folderInfo.Content_Type); |
151 | 10523ad9 | Panagiotis Kanavos | |
152 | cfed7823 | Panagiotis Kanavos | Assert.IsTrue(client.ObjectExists(null, "Pithos", "RootFolder2")); |
153 | cfed7823 | Panagiotis Kanavos | folderInfo = client.GetObjectInfo(null, "Pithos", "RootFolder2"); |
154 | 10523ad9 | Panagiotis Kanavos | Assert.AreEqual(@"application/directory", folderInfo.Content_Type); |
155 | 10523ad9 | Panagiotis Kanavos | |
156 | 10523ad9 | Panagiotis Kanavos | |
157 | cfed7823 | Panagiotis Kanavos | Assert.IsTrue(client.ObjectExists(null, "Pithos", "RootFolder2/Folder1/test.txt")); |
158 | cfed7823 | Panagiotis Kanavos | var fileInfo = client.GetObjectInfo(null, "Pithos", "RootFolder2/Folder1/test.txt"); |
159 | 10523ad9 | Panagiotis Kanavos | Assert.AreEqual(@"application/octet-stream", fileInfo.Content_Type); |
160 | 10523ad9 | Panagiotis Kanavos | |
161 | 10523ad9 | Panagiotis Kanavos | } |
162 | 10523ad9 | Panagiotis Kanavos | } |
163 | 10523ad9 | Panagiotis Kanavos | } |