2 using System.Collections.Generic;
5 using System.Security.Cryptography;
8 using Pithos.Interfaces;
11 namespace Pithos.Network.Test
17 private string _apiKey = "9d3cb7b231e96f72ebe96af1c6cd5112";
18 private string _userName = "pkanavos";
19 private bool _usePithos = false;
21 private ICloudClient client;
25 client = new CloudFilesClient();
26 client.Authenticate(_userName, _apiKey);
31 public void TestChecksum()
33 Assert.DoesNotThrow(() =>
36 var filePath = "devguide.pdf";
37 var info=new FileInfo(filePath);
39 using (var file = File.OpenRead(filePath))
41 var hash = CalculateHash(file);
43 client.PutObject("Shares", info.Name, file, info.Length);
46 var meta = client.GetObjectInfo("Shares", "DeveloperGuide.pdf");
47 Assert.IsNotEmpty(meta.Hash);
50 Assert.AreEqual(hash,meta.Hash,String.Format("The hashes don't match, expected {0} but got {1}",hash,meta.Hash));
58 private static string CalculateHash(FileStream file)
61 using (var hasher = MD5.Create())
63 var hashBuilder = new StringBuilder();
64 foreach (byte b in hasher.ComputeHash(file))
65 hashBuilder.Append(b.ToString("x2").ToLower());
66 hash = hashBuilder.ToString();