removed nunit command line. Causes hangs
[pithos-ms-client] / trunk / Pithos.Network.Test / ChecksumTest.cs
1 using System;
2 using System.Collections.Generic;
3 using System.IO;
4 using System.Linq;
5 using System.Security.Cryptography;
6 using System.Text;
7 using NUnit.Framework;
8 using Pithos.Interfaces;
9
10
11 namespace Pithos.Network.Test
12 {
13     [TestFixture]
14     class ChecksumTest
15     {
16
17         private string _apiKey = "9d3cb7b231e96f72ebe96af1c6cd5112";
18         private string _userName = "pkanavos";
19         private bool _usePithos = false;
20
21         private ICloudClient client;
22         [SetUp]
23         public void Setup()
24         {
25             client = new CloudFilesClient();
26             client.Authenticate(_userName, _apiKey);
27             
28         }
29
30         [Test]
31         public void TestChecksum()
32         {
33             Assert.DoesNotThrow(() =>
34             {
35
36                 var filePath = "devguide.pdf";
37                 var info=new FileInfo(filePath);
38
39                 using (var file = File.OpenRead(filePath))
40                 {
41                     var hash = CalculateHash(file);
42                     file.Seek(0, 0);
43                     client.PutObject("Shares", info.Name, file, info.Length);
44
45
46                     var meta = client.GetObjectInfo("Shares", "DeveloperGuide.pdf");
47                     Assert.IsNotEmpty(meta.Hash);
48                     
49
50                     Assert.AreEqual(hash,meta.Hash,String.Format("The hashes don't match, expected {0} but got {1}",hash,meta.Hash));
51                 }
52
53             });
54
55         
56         }
57
58         private static string CalculateHash(FileStream file)
59         {
60             string hash;
61             using (var hasher = MD5.Create())
62             {
63                 var hashBuilder = new StringBuilder();
64                 foreach (byte b in hasher.ComputeHash(file))
65                     hashBuilder.Append(b.ToString("x2").ToLower());
66                 hash = hashBuilder.ToString();
67             }
68             return hash;
69         }
70     }
71 }