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 testCreateHelper() { // use a blocksize of 1 to test multiple transfers. UploadHelper uploadHelper = new UploadHelper(this.esu, new byte[1]); uploadHelper.ContentType = "text/plain"; MemoryStream ms = new MemoryStream(); ms.Write(Encoding.UTF8.GetBytes("hello"), 0, 5); ms.Seek(0, SeekOrigin.Begin); // Create an object from our file stream ObjectId id = uploadHelper.CreateObject( ms, null, null, true); cleanup.Add(id); // Read contents back and check them string content = Encoding.UTF8.GetString(this.esu.ReadObject(id, null, null)); Assert.AreEqual("hello", content, "object content wrong"); }
public void testUpdateHelperPath() { string dir = rand8char(); string file = rand8char(); ObjectPath op = new ObjectPath("/" + dir + "/" + file); // use a blocksize of 1 to test multiple transfers. UploadHelper uploadHelper = new UploadHelper(this.esu, new byte[1]); uploadHelper.ContentType = "text/plain"; // 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); // update the object contents MemoryStream ms = new MemoryStream(); ms.Write(Encoding.UTF8.GetBytes("hello"), 0, 5); ms.Seek(0, SeekOrigin.Begin); uploadHelper.UpdateObject(op, ms, null, null, true); // Read contents back and check them string content = Encoding.UTF8.GetString(this.esu.ReadObject(op, null, null)); Assert.AreEqual("hello", content, "object content wrong"); }