public void testChecksums() { // Create a byte array to test int size = 10 * 1024 * 1024; byte[] testData = new byte[size]; for (int i = 0; i < size; i++) { testData[i] = (byte)(i % 0x93); } UploadHelper uh = new UploadHelper(this.esu, null); uh.ComputeChecksums = true; MemoryStream ms = new MemoryStream(); ms.Write(testData, 0, testData.Length); ms.Seek(0, SeekOrigin.Begin); ObjectId id = uh.CreateObject(ms, null, null, true); cleanup.Add(id); MemoryStream baos = new MemoryStream(); DownloadHelper dl = new DownloadHelper(this.esu, new byte[4 * 1024 * 1024]); dl.Checksumming = true; dl.ReadObject(id, baos, true); Assert.IsFalse(dl.Failed, "Download should have been OK"); Assert.IsNull(dl.Error, "Error should have been null"); byte[] outData = baos.ToArray(); // Check the files Assert.AreEqual(testData.Length, outData.Length, "File lengths differ"); for (int i = 0; i < testData.Length; i++) { Assert.AreEqual(testData[i], outData[i], "Arrays differ at offset " + i); } }
public void testDownloadHelperPath() { string dir = rand8char(); string file = rand8char(); ObjectPath op = new ObjectPath("/" + dir + "/" + file); // Create an object with content. ObjectId id = this.esu.CreateObjectOnPath( op, null, null, Encoding.UTF8.GetBytes("Four score and twenty years ago"), "text/plain"); Assert.IsNotNull(id, "null ID returned"); cleanup.Add(id); // Download the content DownloadHelper downloadHelper = new DownloadHelper(this.esu, null); MemoryStream ms = new MemoryStream(); downloadHelper.ReadObject(op, ms, false); ms.Close(); // Check the download string data = Encoding.UTF8.GetString(ms.ToArray()); Assert.AreEqual(data, "Four score and twenty years ago", "object content wrong"); // Download again 1 byte in a request downloadHelper = new DownloadHelper(this.esu, new byte[1]); ms = new MemoryStream(); downloadHelper.ReadObject(op, ms, false); ms.Close(); // Check the download data = Encoding.UTF8.GetString(ms.ToArray()); Assert.AreEqual("Four score and twenty years ago", data, "object content wrong"); }