Extracted upload/download functionality from NetworkAgent to Uploader.cs and Download...
[pithos-ms-client] / trunk / Pithos.Core.Test / NetworkAgentTest.cs
index 9cdb0e2..d84fdcb 100644 (file)
@@ -1,4 +1,5 @@
 using System;
+using System.Collections.Concurrent;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
@@ -6,6 +7,7 @@ using System.Text;
 using System.Threading.Tasks;
 using NUnit.Framework;
 using Pithos.Core.Agents;
+using Pithos.Interfaces;
 using Pithos.Network;
 
 namespace Pithos.Core.Test
@@ -14,7 +16,7 @@ namespace Pithos.Core.Test
     class NetworkAgentTest
     {
         [Test]
-        public void TestUpload()
+        public async void TestUpload()
         {
             var agent = new NetworkAgent();
 
@@ -49,14 +51,17 @@ namespace Pithos.Core.Test
 
             client.DeleteObject(null, FolderConstants.PithosContainer, fileName);
 
-            var task = Signature.CalculateTreeHashAsync(filePath, accountInfo.BlockSize, accountInfo.BlockHash);
-            var tasks=agent.UploadWithHashMap(accountInfo,account,"pithos",new FileInfo(filePath),fileName,task);
-            Task.Factory.Iterate(tasks).Wait();
+            var treeHash = await Signature.CalculateTreeHashAsync(filePath, accountInfo.BlockSize, accountInfo.BlockHash, 2);
+            var cloudFile = new ObjectInfo {Account = account, Container = "pithos"};
+            var fileInfo = new FileInfo(filePath);
 
-            var newHash = client.GetHashMap(null, FolderConstants.PithosContainer, fileName).Result;
+            var uploader = new Uploader();
+            uploader.UploadWithHashMap(accountInfo,cloudFile,fileInfo,fileName,treeHash);
+            
+            var newHash = await client.GetHashMap(null, FolderConstants.PithosContainer, fileName);
 
 
-            var treeHash = task.Result;
+            
             Assert.AreEqual(treeHash.TopHash, newHash.TopHash);
 
             Assert.AreEqual(treeHash.Hashes, newHash.Hashes);
@@ -66,12 +71,10 @@ namespace Pithos.Core.Test
         [Test]
         public void TestDownload()
         {
-            var fileAgent = new FileAgent {FragmentsPath = @"e:\pithos\Fragments"};
-
             var agent = new NetworkAgent();
 
-            var account = "890329@vho.grnet.gr";
-            var apiKey = "24989dce4e0fcb072f8cb60c8922be19";
+            var account = "";
+            var apiKey = "";
             var client = new CloudFilesClient(account,apiKey)
             {
                 AuthenticationUrl = @"https://pithos.dev.grnet.gr",
@@ -86,12 +89,15 @@ namespace Pithos.Core.Test
             if (File.Exists(filePath))
                 File.Delete(filePath);
 
+            var cloudFile = new ObjectInfo {Account = account, Container = FolderConstants.PithosContainer};
+
             var newHash = client.GetHashMap(null, FolderConstants.PithosContainer, fileName).Result;
-            agent.DownloadWithBlocks(client, account, FolderConstants.PithosContainer, new Uri(fileName, UriKind.Relative), filePath, newHash)
+            var downloader = new Downloader();
+            downloader.DownloadWithBlocks(accountInfo, client, cloudFile, new Uri(fileName, UriKind.Relative), filePath, newHash)
                 .Wait();
 
             Assert.IsTrue(File.Exists(filePath));
-            var treeHash = Signature.CalculateTreeHashAsync(filePath, accountInfo.BlockSize, accountInfo.BlockHash).Result;
+            var treeHash = Signature.CalculateTreeHashAsync(filePath, accountInfo.BlockSize, accountInfo.BlockHash, 2).Result;
 
             Assert.AreEqual(treeHash.TopHash, newHash.TopHash);