Revision 10523ad9

b/trunk/Pithos.Interfaces/ICloudClient.cs
30 30
        void MoveObject(string container, string oldObjectName, string newObjectName);
31 31
        bool ObjectExists(string container,string objectName);
32 32
        ObjectInfo GetObjectInfo(string container, string objectName);
33
        void CreateFolder(string container, string folder);
33 34
    }
34 35

  
35 36

  
......
161 162

  
162 163
            return default(ObjectInfo);
163 164
        }
165

  
166
        public void CreateFolder(string container, string folder)
167
        {
168
            Contract.Requires(!String.IsNullOrWhiteSpace(Token));
169
            Contract.Requires(StorageUrl != null);
170
            Contract.Requires(!String.IsNullOrWhiteSpace(container));
171
            Contract.Requires(!String.IsNullOrWhiteSpace(folder));            
172
        }
164 173
    }
165 174

  
166 175
    public class ContainerInfo
b/trunk/Pithos.Network.Test/FolderTests.cs
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

  
12
namespace Pithos.Network.Test
13
{
14
    [TestFixture]
15
    class FolderTests
16
    {
17
        private string _apiKey = "9d3cb7b231e96f72ebe96af1c6cd5112";
18
        private string _userName = "pkanavos";
19

  
20
        [SetUp]
21
        public void Setup()
22
        {
23
            Directory.CreateDirectory("RootFolder");
24
            File.WriteAllText(@"RootFolder\TestFile1.txt", "This is a test file");
25
            Directory.CreateDirectory(@"RootFolder\Folder1");
26
            File.WriteAllText(@"RootFolder\Folder1\TestFile1.txt", "This is a test file");
27
            Directory.CreateDirectory(@"RootFolder\Folder1\Subfolder1");
28
            File.WriteAllText(@"RootFolder\Folder1\Subfolder1\TestFile1.txt", "This is a test file");
29
            Directory.CreateDirectory(@"RootFolder\Folder2");
30
            File.WriteAllText(@"RootFolder\Folder2\TestFile1.txt", "This is a test file");
31

  
32
        }
33

  
34
        [TearDown]
35
        public void TearDown()
36
        {
37
            Directory.Delete("RootFolder",true);
38
        }
39
        
40
        [Test]
41
        public void TestCreateSingleFolder([Values(true, false)]bool usePithos)
42
        {
43
            ICloudClient client = new CloudFilesClient { UsePithos = usePithos };
44
            client.Authenticate(_userName, _apiKey);
45

  
46
            client.CreateContainer("Pithos");
47

  
48
            client.CreateFolder("Pithos", "RootFolder");
49

  
50
            Assert.IsTrue(client.ObjectExists("Pithos","RootFolder"));
51
            var info = client.GetObjectInfo("Pithos", "RootFolder");
52
            Assert.AreEqual(@"application/directory",info.Content_Type);
53
            
54
        } 
55
        
56
        [Test]
57
        public void TestCreateSubFolders([Values(true, false)]bool usePithos)
58
        {
59
            ICloudClient client = new CloudFilesClient { UsePithos = usePithos };
60
            client.Authenticate(_userName, _apiKey);
61

  
62
            client.CreateContainer("Pithos");
63

  
64
            client.CreateFolder("Pithos", "RootFolder");
65
            client.CreateFolder("Pithos", "RootFolder/Folder1");
66
            var localInfo = new FileInfo("test.txt");
67
            client.PutObject("Pithos","RootFolder/Folder1/test.txt","test.txt",localInfo.Length);
68

  
69

  
70
            Assert.IsTrue(client.ObjectExists("Pithos", "RootFolder/Folder1"));
71
            var folderInfo = client.GetObjectInfo("Pithos", "RootFolder/Folder1");
72
            Assert.AreEqual(@"application/directory",folderInfo.Content_Type);
73

  
74

  
75
            Assert.IsTrue(client.ObjectExists("Pithos", "RootFolder/Folder1/test.txt"));
76
            var fileInfo = client.GetObjectInfo("Pithos", "RootFolder/Folder1/test.txt");
77
            Assert.AreEqual(@"application/octet-stream", fileInfo.Content_Type);
78
            
79
        }
80
        
81
        [Test]
82
        public void TestDeleteSubFolders([Values(true, false)]bool usePithos)
83
        {
84
            throw new NotImplementedException();
85
            ICloudClient client = new CloudFilesClient { UsePithos = usePithos };
86
            client.Authenticate(_userName, _apiKey);
87

  
88
            client.CreateContainer("Pithos");
89

  
90
            client.CreateFolder("Pithos", "RootFolder");
91
            client.CreateFolder("Pithos", "RootFolder/Folder1");
92
            var localInfo = new FileInfo("test.txt");
93
            client.PutObject("Pithos","RootFolder/Folder1/test.txt","test.txt",localInfo.Length);
94

  
95
            client.DeleteObject("Pithos", "RootFolder/Folder1");
96

  
97
            Assert.IsTrue(client.ObjectExists("Pithos", "RootFolder/Folder1"));
98
            var folderInfo = client.GetObjectInfo("Pithos", "RootFolder/Folder1");
99
            Assert.AreEqual(@"application/directory",folderInfo.Content_Type);
100

  
101

  
102
            Assert.IsTrue(client.ObjectExists("Pithos", "RootFolder/Folder1/test.txt"));
103
            var fileInfo = client.GetObjectInfo("Pithos", "RootFolder/Folder1/test.txt");
104
            Assert.AreEqual(@"application/octet-stream", fileInfo.Content_Type);
105
            
106
        } 
107
        
108
        [Test]
109
        public void TestCreateSubFoldersInOneStep([Values(true, false)]bool usePithos)
110
        {
111
            ICloudClient client = new CloudFilesClient { UsePithos = usePithos };
112
            client.Authenticate(_userName, _apiKey);
113

  
114
            client.CreateContainer("Pithos");
115
            
116
            client.CreateFolder("Pithos", "RootFolder2/Folder1");
117

  
118
            Assert.IsTrue(client.ObjectExists("Pithos", "RootFolder2/Folder1"));
119
            var folderInfo = client.GetObjectInfo("Pithos", "RootFolder2/Folder1");
120
            Assert.AreEqual(@"application/directory",folderInfo.Content_Type);
121

  
122
            Assert.IsTrue(client.ObjectExists("Pithos", "RootFolder2"));
123
            folderInfo = client.GetObjectInfo("Pithos", "RootFolder2");
124
            Assert.AreEqual(@"application/directory", folderInfo.Content_Type);
125

  
126

  
127
            Assert.IsTrue(client.ObjectExists("Pithos", "RootFolder2/Folder1/test.txt"));
128
            var fileInfo = client.GetObjectInfo("Pithos", "RootFolder2/Folder1/test.txt");
129
            Assert.AreEqual(@"application/octet-stream", fileInfo.Content_Type);
130
            
131
        }
132
    }
133
}
b/trunk/Pithos.Network.Test/NetworkOpsTest.cs
318 318
            });
319 319

  
320 320
        }
321

  
322

  
321 323
    }
322 324

  
323 325
    
b/trunk/Pithos.Network.Test/Pithos.Network.Test.csproj
64 64
  </ItemGroup>
65 65
  <ItemGroup>
66 66
    <Compile Include="ChecksumTest.cs" />
67
    <Compile Include="FolderTests.cs" />
67 68
    <Compile Include="NetworkOpsTest.cs" />
68 69
    <Compile Include="Properties\AssemblyInfo.cs" />
69 70
  </ItemGroup>
b/trunk/Pithos.Network/CloudFilesClient.cs
224 224
            }
225 225
        }
226 226

  
227
        public void CreateFolder(string container, string folder)
228
        {
229
            if (String.IsNullOrWhiteSpace(container))
230
                throw new ArgumentNullException("container", "The container property can't be empty");
231
            if (String.IsNullOrWhiteSpace(folder))
232
                throw new ArgumentNullException("folder", "The folder property can't be empty");
233

  
234
            var folderUrl=String.Format("{0}/{1}",container,folder);
235
            var request = new RestRequest { Path = folderUrl, Method = WebMethod.Put };
236
            request.AddHeader("Content-Type", @"application/directory");
237
            request.AddHeader("Content-Length", "0");
238

  
239
            var response = _client.Request(request);
240

  
241
            if (response.StatusCode != HttpStatusCode.Created && response.StatusCode != HttpStatusCode.Accepted)
242
                throw new WebException(String.Format("CreateFolder failed with unexpected status code {0}", response.StatusCode));
243

  
244
        }
245

  
227 246
        public ContainerInfo GetContainerInfo(string container)
228 247
        {
229 248
            if (String.IsNullOrWhiteSpace(container))

Also available in: Unified diff