From 85c6af0726fcc9ec8878150392bf77809895e9ba Mon Sep 17 00:00:00 2001 From: pkanavos Date: Sat, 28 Apr 2012 23:17:19 +0300 Subject: [PATCH] Fix for duplicates in selectivesync display code Still needs cleanup --- trunk/Pithos.Client.WPF.Test/NodeTest.cs | 386 +++++++++++++------- .../Pithos.Client.WPF.Test.csproj | 12 + trunk/Pithos.Client.WPF.Test/json.txt | 23 ++ trunk/Pithos.Client.WPF.Test/json2.txt | 22 ++ .../SelectiveSynch/DirectoryRecord.cs | 2 + .../SelectiveSynch/SelectiveSynchViewModel.cs | 3 +- .../Utils/EnumerableExtensions.cs | 61 +++- 7 files changed, 367 insertions(+), 142 deletions(-) create mode 100644 trunk/Pithos.Client.WPF.Test/json.txt create mode 100644 trunk/Pithos.Client.WPF.Test/json2.txt diff --git a/trunk/Pithos.Client.WPF.Test/NodeTest.cs b/trunk/Pithos.Client.WPF.Test/NodeTest.cs index e37d87a..3842eeb 100644 --- a/trunk/Pithos.Client.WPF.Test/NodeTest.cs +++ b/trunk/Pithos.Client.WPF.Test/NodeTest.cs @@ -3,170 +3,288 @@ using System.Collections.Generic; using System.Linq; using System.Text; using NUnit.Framework; +using Newtonsoft.Json; using Pithos.Client.WPF.SelectiveSynch; using Pithos.Client.WPF.Utils; using Pithos.Interfaces; +using System.IO; namespace Pithos.Client.WPF.Test { [TestFixture] - class NodeTest + internal class NodeTest { [Test] public void TestIteration() { - var root = new Node{Path = "Root", - Children = - { - new Node {Path = "Root/Path1", - Children = - { - new Node{Path="Root/Path1/Path11", - Children= - { - new Node{Path="Root/Path1/Path11/Path111", - Children= - { - new Node{Path="Root/Path1/Path11/Path111/File1"} - }} - } - }, - new Node{Path="Root/Path1/File2"} - } - }, - } - }; + var root = new Node + { + Path = "Root", + Children = + { + new Node + { + Path = "Root/Path1", + Children = + { + new Node + { + Path = "Root/Path1/Path11", + Children = + { + new Node + { + Path = "Root/Path1/Path11/Path111", + Children = + { + new Node + { + Path = + "Root/Path1/Path11/Path111/File1" + } + } + } + } + }, + new Node {Path = "Root/Path1/File2"} + } + }, + } + }; Assert.That(root.Count(), Is.EqualTo(6)); } - + [Test] public void TestEquals() { - var target = new Node{Path = "Root", - Children = - { - new Node {Path = "Root/Path1", - Children = - { - new Node{Path="Root/Path1/Path11", - Children= - { - new Node{Path="Root/Path1/Path11/Path111", - Children= - { - new Node{Path="Root/Path1/Path11/Path111/File1"} - }} - } - }, - new Node{Path="Root/Path1/File2"} - } - }, - } - }; - var source= new Node{Path = "Root", - Children = - { - new Node{Path = "Root/Path1", - Children = - { - new Node{Path="Root/Path1/Path11", - Children= - { - new Node{Path="Root/Path1/Path11/Path111", - Children= - { - new Node{Path="Root/Path1/Path11/Path111/File1"} - }} - } - }, - new Node{Path="Root/Path1/File2"} - } - }, - } - }; - Assert.That(source.Equals(target), Is.True); + var target = new Node + { + Path = "Root", + Children = + { + new Node + { + Path = "Root/Path1", + Children = + { + new Node + { + Path = "Root/Path1/Path11", + Children = + { + new Node + { + Path = "Root/Path1/Path11/Path111", + Children = + { + new Node + { + Path = + "Root/Path1/Path11/Path111/File1" + } + } + } + } + }, + new Node {Path = "Root/Path1/File2"} + } + }, + } + }; + var source = new Node + { + Path = "Root", + Children = + { + new Node + { + Path = "Root/Path1", + Children = + { + new Node + { + Path = "Root/Path1/Path11", + Children = + { + new Node + { + Path = "Root/Path1/Path11/Path111", + Children = + { + new Node + { + Path = + "Root/Path1/Path11/Path111/File1" + } + } + } + } + }, + new Node {Path = "Root/Path1/File2"} + } + }, + } + }; + Assert.That(source.Equals(target), Is.True); } [Test] public void TestToTree() { - var target = new Node{Path = "Root", - Children = - { - new Node{Path = "Root/Path1", - Children = - { - new Node{Path="Root/Path1/File2"}, - new Node{Path="Root/Path1/Path11", - Children= - { - new Node{Path="Root/Path1/Path11/Path111", - Children= - { - new Node{Path="Root/Path1/Path11/Path111/File1"} - }} - } - }, - } - }, - } - }; - var source= new[] - { - Tuple.Create("Root",0), - Tuple.Create("Root/Path1",0), - Tuple.Create("Root/Path1/Path11",0), - Tuple.Create("Root/Path1/Path11/Path111",0), - Tuple.Create("Root/Path1/Path11/Path111/File1",0), - Tuple.Create("Root/Path1/File2",0) - }; + var target = new Node + { + Path = "Root", + Children = + { + new Node + { + Path = "Root/Path1", + Children = + { + new Node {Path = "Root/Path1/File2"}, + new Node + { + Path = "Root/Path1/Path11", + Children = + { + new Node + { + Path = "Root/Path1/Path11/Path111", + Children = + { + new Node + { + Path = + "Root/Path1/Path11/Path111/File1" + } + } + } + } + }, + } + }, + } + }; + var source = new[] + { + Tuple.Create("Root", 0), + Tuple.Create("Root/Path1", 0), + Tuple.Create("Root/Path1/Path11", 0), + Tuple.Create("Root/Path1/Path11/Path111", 0), + Tuple.Create("Root/Path1/Path11/Path111/File1", 0), + Tuple.Create("Root/Path1/File2", 0) + }; + + Assert.That(source.ToTree(s => s.Item1, s => s.Item2).First().Equals(target), Is.True); + } + + [Test] - Assert.That(source.ToTree(s=>s.Item1,s=>s.Item2).First().Equals(target), Is.True); - } [Test] - public void TestObjectInfoToTree() { - var target = new DirectoryRecord{ DisplayName= "Root", - Directories = - { - new DirectoryRecord{DisplayName = "Root/DisplayName1", - Directories = - { - new DirectoryRecord{DisplayName="Root/DisplayName1/File2"}, - new DirectoryRecord{DisplayName="Root/DisplayName1/DisplayName11", - Directories= - { - new DirectoryRecord{DisplayName="Root/DisplayName1/DisplayName11/DisplayName111", - Directories= - { - new DirectoryRecord{DisplayName="Root/DisplayName1/DisplayName11/DisplayName111/File1"} - }} - } - }, - } - }, - } - }; + + var account = "someaccount"; + var container = "Root"; + var source = new[] + { + new ObjectInfo + { + Account = account, + Container = container, + Name = "Path1", + Content_Type = "application/directory" + }, + new ObjectInfo + { + Account = account, + Container = container, + Name = "Path1/Path11", + Content_Type = "application/folder" + }, + new ObjectInfo + {Account = account, Container = container, Name = "Path1/Path11/Path111"}, + new ObjectInfo + { + Account = account, + Container = container, + Name = "Path1/Path11/Path111/File1", + Content_Type = "application/octet-stream" + }, + new ObjectInfo {Account = account, Container = container, Name = "Path1/File2"}, + new ObjectInfo {Account = account, Container = container, Name = "Path1/File3"}, + new ObjectInfo {Account = account, Container = container, Name = "Path1/File"}, + new ObjectInfo {Account = account, Container = container, Name = "Path2/File2"}, + new ObjectInfo {Account = account, Container = container, Name = "Path2/Path21/File2"}, + new ObjectInfo {Account = account, Container = container, Name = "File02"}, + new ObjectInfo {Account = account, Container = container, Name = "File03"} + }; + + var tree = source.ToTree(); + var allNodes = (from DirectoryRecord root in tree + from DirectoryRecord record in root + select record).ToList(); + Assert.That(allNodes.Count, Is.EqualTo(5)); + } + public void InferFromPath() + { + var account = "someaccount"; var container = "Root"; - var source= new[] - { - new ObjectInfo{Account=account,Container=container,Name="Path1",Content_Type="application/directory"}, - new ObjectInfo{Account=account,Container=container,Name="Path1/Path11",Content_Type="application/folder"}, - new ObjectInfo{Account=account,Container=container,Name="Path1/Path11/Path111"}, - new ObjectInfo{Account=account,Container=container,Name="Path1/Path11/Path111/File1",Content_Type="application/octet-stream"}, - new ObjectInfo{Account=account,Container=container,Name="Path1/File2"}, - new ObjectInfo{Account=account,Container=container,Name="Path2/File2"}, - new ObjectInfo{Account=account,Container=container,Name="Path2/Path21/File2"}, - new ObjectInfo{Account=account,Container=container,Name="File02"}, - new ObjectInfo{Account=account,Container=container,Name="File03"} - }; + var source = new[] + { + new ObjectInfo {Account = account, Container = container, Name = "Path1/File2"}, + new ObjectInfo {Account = account, Container = container, Name = "Path1/File3"}, + new ObjectInfo {Account = account, Container = container, Name = "Path1/Path11/Path111/File3"}, + new ObjectInfo {Account = account, Container = container, Name = "Path2"}, + new ObjectInfo {Account = account, Container = container, Name = "Path2/Path21",Content_Type="application/directory"}, + new ObjectInfo {Account = account, Container = container, Name = "Path2/Path21/Path01",Content_Type="application/directory"}, + new ObjectInfo {Account = account, Container = container, Name = "Path2/Path21/File211"}, + new ObjectInfo {Account = account, Container = container, Name = "x2",Content_Type="application/directory"}, + new ObjectInfo {Account = account, Container = container, Name = "x2/x21",Content_Type="application/directory"}, + new ObjectInfo {Account = account, Container = container, Name = "x2/x22",Content_Type="application/directory"}, + }; var tree = source.ToTree(); var allNodes = (from DirectoryRecord root in tree from DirectoryRecord record in root - select record).ToList(); - Assert.That(allNodes.Count,Is.EqualTo(5)); + select record).ToList(); + //Root Nodes + Assert.That(tree.Count, Is.EqualTo(3)); + //Total nodes + Assert.That(allNodes.Count, Is.EqualTo(9)); + + Assert.That(allNodes.Any(r=>r.DisplayName=="Path1")); + Assert.That(allNodes.Any(r => r.DisplayName == "Path11")); + Assert.That(allNodes.Any(r => r.DisplayName == "Path111")); + Assert.That(allNodes.Any(r => r.DisplayName == "Path2")); + Assert.That(allNodes.Any(r => r.DisplayName == "Path21")); + } + + + [Test] + public void TestShared() + { + var content = File.ReadAllText("json.txt"); + var items=JsonConvert.DeserializeObject>(content); + Assert.That(items.Count,Is.EqualTo(23)); + var tree = items.ToTree(); + var allNodes = (from DirectoryRecord root in tree + from DirectoryRecord record in root + select record).ToList(); + Assert.That(allNodes.Count,Is.EqualTo(10)); + } + + [Test] + public void TestOwn() + { + var content = File.ReadAllText("json2.txt"); + var items=JsonConvert.DeserializeObject>(content); + Assert.That(items.Count,Is.EqualTo(22)); + var tree = items.ToTree(); + var allNodes = (from DirectoryRecord root in tree + from DirectoryRecord record in root + select record).ToList(); + Assert.That(allNodes.Count,Is.EqualTo(9)); } } } diff --git a/trunk/Pithos.Client.WPF.Test/Pithos.Client.WPF.Test.csproj b/trunk/Pithos.Client.WPF.Test/Pithos.Client.WPF.Test.csproj index b241911..2099060 100644 --- a/trunk/Pithos.Client.WPF.Test/Pithos.Client.WPF.Test.csproj +++ b/trunk/Pithos.Client.WPF.Test/Pithos.Client.WPF.Test.csproj @@ -57,6 +57,10 @@ + + {A9AE40FF-1A21-414A-9FE7-3BE13644CC6D} + Newtonsoft.Json + {4D9406A3-50ED-4672-BB97-A0B3EA4946FE} Pithos.Client.WPF @@ -66,6 +70,14 @@ Pithos.Interfaces + + + PreserveNewest + + + Always + +