Revision c53aa229 trunk/Pithos.Core.Test/NetworkAgentTest.cs

b/trunk/Pithos.Core.Test/NetworkAgentTest.cs
3 3
using System.IO;
4 4
using System.Linq;
5 5
using System.Text;
6
using System.Threading.Tasks;
6 7
using NUnit.Framework;
7 8
using Pithos.Core.Agents;
8 9
using Pithos.Network;
......
15 16
        [Test]
16 17
        public void TestUpload()
17 18
        {
18
            var agent = new NetworkAgent
19
            {
20
                PithosContainer = "pithos",
21
                BlockSize = 4194304,
22
                BlockHash="sha256",
23
                CloudClient = new CloudFilesClient
24
                                {
25
                                    AuthenticationUrl = @"https://pithos.dev.grnet.gr",
26
                                    UsePithos = true
27
                                }
28
            };
19
            var agent = new NetworkAgent();
29 20

  
30 21
            var account = "890329@vho.grnet.gr";
31
            agent.CloudClient.Authenticate(account, "24989dce4e0fcb072f8cb60c8922be19");
22
            var apiKey = "24989dce4e0fcb072f8cb60c8922be19";
23

  
24
            var client = new CloudFilesClient(account,apiKey)
25
                             {
26
                                 AuthenticationUrl = @"https://pithos.dev.grnet.gr",
27
                                 UsePithos = true
28
                             };
29

  
30
            
31
            var accountInfo=client.Authenticate();
32 32

  
33 33
            var fileName = "012345.dump";
34 34
            var filePath = Path.Combine(@"e:\pithos\", fileName);
......
47 47
            }
48 48

  
49 49

  
50
            agent.CloudClient.DeleteObject(null, agent.PithosContainer, fileName,agent.TrashContainer);
50
            client.DeleteObject(null, FolderConstants.PithosContainer, fileName);
51 51

  
52
            var task = Signature.CalculateTreeHashAsync(filePath, agent.BlockSize, agent.BlockHash);
53
            agent.UploadWithHashMap(account,"pithos",new FileInfo(filePath),fileName,task);
52
            var task = Signature.CalculateTreeHashAsync(filePath, accountInfo.BlockSize, accountInfo.BlockHash);
53
            var tasks=agent.UploadWithHashMap(accountInfo,account,"pithos",new FileInfo(filePath),fileName,task);
54
            Task.Factory.Iterate(tasks).Wait();
54 55

  
55
            var newHash = agent.CloudClient.GetHashMap(null, agent.PithosContainer, fileName).Result;
56
            var newHash = client.GetHashMap(null, FolderConstants.PithosContainer, fileName).Result;
56 57

  
57 58

  
58 59
            var treeHash = task.Result;
......
67 68
        {
68 69
            var fileAgent = new FileAgent {FragmentsPath = @"e:\pithos\Fragments"};
69 70

  
70
            var agent = new NetworkAgent
71
            var agent = new NetworkAgent();
72

  
73
            var account = "890329@vho.grnet.gr";
74
            var apiKey = "24989dce4e0fcb072f8cb60c8922be19";
75
            var client = new CloudFilesClient(account,apiKey)
71 76
            {
72
                PithosContainer = "pithos",
73
                BlockSize = 4194304,
74
                BlockHash="sha256",
75
                CloudClient = new CloudFilesClient
76
                                {
77
                                    AuthenticationUrl = @"https://pithos.dev.grnet.gr",
78
                                    UsePithos = true
79
                                },
80
                FileAgent=fileAgent
77
                AuthenticationUrl = @"https://pithos.dev.grnet.gr",
78
                UsePithos = true
81 79
            };
82 80

  
83
            var account = "890329@vho.grnet.gr";
84
            agent.CloudClient.Authenticate(account, "24989dce4e0fcb072f8cb60c8922be19");
81
            var accountInfo=client.Authenticate();
85 82

  
86 83
            var fileName = @"AccessDatabaseEngine_x64.exe";
87 84

  
88 85
            var filePath = Path.Combine(@"e:\pithos\", fileName);
89 86
            if (File.Exists(filePath))
90
                File.Delete(filePath);            
91
            
92
            var newHash = agent.CloudClient.GetHashMap(null, agent.PithosContainer, fileName).Result;
93
            agent.DownloadWithBlocks(account,agent.PithosContainer,new Uri(fileName,UriKind.Relative),filePath,newHash)
87
                File.Delete(filePath);
88

  
89
            var newHash = client.GetHashMap(null, FolderConstants.PithosContainer, fileName).Result;
90
            agent.DownloadWithBlocks(client, account, FolderConstants.PithosContainer, new Uri(fileName, UriKind.Relative), filePath, newHash)
94 91
                .Wait();
95 92

  
96 93
            Assert.IsTrue(File.Exists(filePath));
97
            var treeHash = Signature.CalculateTreeHashAsync(filePath, agent.BlockSize, agent.BlockHash).Result;
94
            var treeHash = Signature.CalculateTreeHashAsync(filePath, accountInfo.BlockSize, accountInfo.BlockHash).Result;
98 95

  
99 96
            Assert.AreEqual(treeHash.TopHash, newHash.TopHash);
100 97

  

Also available in: Unified diff