2 using System.Collections.Generic;
7 using Pithos.Client.WPF.SelectiveSynch;
8 using Pithos.Client.WPF.Utils;
9 using Pithos.Interfaces;
12 namespace Pithos.Client.WPF.Test
15 internal class NodeTest
18 public void TestIteration()
20 var root = new Node<int>
32 Path = "Root/Path1/Path11",
37 Path = "Root/Path1/Path11/Path111",
43 "Root/Path1/Path11/Path111/File1"
49 new Node<int> {Path = "Root/Path1/File2"}
54 Assert.That(root.Count(), Is.EqualTo(6));
58 public void TestEquals()
60 var target = new Node<int>
72 Path = "Root/Path1/Path11",
77 Path = "Root/Path1/Path11/Path111",
83 "Root/Path1/Path11/Path111/File1"
89 new Node<int> {Path = "Root/Path1/File2"}
94 var source = new Node<int>
106 Path = "Root/Path1/Path11",
111 Path = "Root/Path1/Path11/Path111",
117 "Root/Path1/Path11/Path111/File1"
123 new Node<int> {Path = "Root/Path1/File2"}
128 Assert.That(source.Equals(target), Is.True);
132 public void TestToTree()
134 var target = new Node<int>
144 new Node<int> {Path = "Root/Path1/File2"},
147 Path = "Root/Path1/Path11",
152 Path = "Root/Path1/Path11/Path111",
158 "Root/Path1/Path11/Path111/File1"
170 Tuple.Create("Root", 0),
171 Tuple.Create("Root/Path1", 0),
172 Tuple.Create("Root/Path1/Path11", 0),
173 Tuple.Create("Root/Path1/Path11/Path111", 0),
174 Tuple.Create("Root/Path1/Path11/Path111/File1", 0),
175 Tuple.Create("Root/Path1/File2", 0)
178 Assert.That(source.ToTree(s => s.Item1, s => s.Item2).First().Equals(target), Is.True);
183 public void TestObjectInfoToTree()
186 var account = "someaccount";
187 var container = "Root";
193 Container = container,
195 Content_Type = "application/directory"
200 Container = container,
201 Name = "Path1/Path11",
202 Content_Type = "application/folder"
205 {Account = account, Container = container, Name = "Path1/Path11/Path111"},
209 Container = container,
210 Name = "Path1/Path11/Path111/File1",
211 Content_Type = "application/octet-stream"
213 new ObjectInfo {Account = account, Container = container, Name = "Path1/File2"},
214 new ObjectInfo {Account = account, Container = container, Name = "Path1/File3"},
215 new ObjectInfo {Account = account, Container = container, Name = "Path1/File"},
216 new ObjectInfo {Account = account, Container = container, Name = "Path2/File2"},
217 new ObjectInfo {Account = account, Container = container, Name = "Path2/Path21/File2"},
218 new ObjectInfo {Account = account, Container = container, Name = "File02"},
219 new ObjectInfo {Account = account, Container = container, Name = "File03"}
222 var tree = source. ToTree();
223 var allNodes = (from DirectoryRecord root in tree
224 from DirectoryRecord record in root
225 select record).ToList();
226 Assert.That(allNodes.Count, Is.EqualTo(5));
228 public void InferFromPath()
231 var account = "someaccount";
232 var container = "Root";
235 new ObjectInfo {Account = account, Container = container, Name = "Path1/File2"},
236 new ObjectInfo {Account = account, Container = container, Name = "Path1/File3"},
237 new ObjectInfo {Account = account, Container = container, Name = "Path1/Path11/Path111/File3"},
238 new ObjectInfo {Account = account, Container = container, Name = "Path2"},
239 new ObjectInfo {Account = account, Container = container, Name = "Path2/Path21",Content_Type="application/directory"},
240 new ObjectInfo {Account = account, Container = container, Name = "Path2/Path21/Path01",Content_Type="application/directory"},
241 new ObjectInfo {Account = account, Container = container, Name = "Path2/Path21/File211"},
242 new ObjectInfo {Account = account, Container = container, Name = "x2",Content_Type="application/directory"},
243 new ObjectInfo {Account = account, Container = container, Name = "x2/x21",Content_Type="application/directory"},
244 new ObjectInfo {Account = account, Container = container, Name = "x2/x22",Content_Type="application/directory"},
247 var tree = source.ToTree();
248 var allNodes = (from DirectoryRecord root in tree
249 from DirectoryRecord record in root
250 select record).ToList();
252 Assert.That(tree.Count, Is.EqualTo(3));
254 Assert.That(allNodes.Count, Is.EqualTo(9));
256 Assert.That(allNodes.Any(r=>r.DisplayName=="Path1"));
257 Assert.That(allNodes.Any(r => r.DisplayName == "Path11"));
258 Assert.That(allNodes.Any(r => r.DisplayName == "Path111"));
259 Assert.That(allNodes.Any(r => r.DisplayName == "Path2"));
260 Assert.That(allNodes.Any(r => r.DisplayName == "Path21"));
265 public void TestShared()
267 var content = File.ReadAllText("json.txt");
268 var items=JsonConvert.DeserializeObject<IList<ObjectInfo>>(content);
269 Assert.That(items.Count,Is.EqualTo(23));
270 var tree = items.ToTree();
271 var allNodes = (from DirectoryRecord root in tree
272 from DirectoryRecord record in root
273 select record).ToList();
274 Assert.That(allNodes.Count,Is.EqualTo(10));
278 public void TestOwn()
280 var content = File.ReadAllText("json2.txt");
281 var items=JsonConvert.DeserializeObject<IList<ObjectInfo>>(content);
282 Assert.That(items.Count,Is.EqualTo(22));
283 var tree = items.ToTree();
284 var allNodes = (from DirectoryRecord root in tree
285 from DirectoryRecord record in root
286 select record).ToList();
287 Assert.That(allNodes.Count,Is.EqualTo(9));
291 public void TestUri()
293 var storageUri = new Uri("http://pithos.okeanos.grnet.gr/v1/pkanavos@gmail.com");
294 var uri = new Uri(storageUri, "pithos");
296 var expected = new Uri("http://pithos.okeanos.grnet.gr/v1/pkanavos@gmail.com/pithos");
297 Assert.That(uri, Is.EqualTo(expected));