public void DeleteDocument(Guid documentId) { using (var client = new StorageServiceClient()) { client.Delete(documentId); } }
public void DocumentStorageTest_Load() { using (var client = new StorageServiceClient()) { Stopwatch sw = new Stopwatch(); sw.Start(); //int testContentLength = 1024 * 1024 * 100;// 100 Mb int testContentLength = 1024 * 1024;// 1 Mb MemoryStream memoryStream = new MemoryStream(); Random r = new Random(); for (int i = 0; i < testContentLength; i++) { memoryStream.WriteByte((byte)r.Next(0, 255)); } memoryStream.Position = 0; Trace.WriteLine(String.Format("Fill array at [{0}] ms", sw.ElapsedMilliseconds)); sw.Restart(); Guid documentId = Guid.NewGuid(); client.StoreDocumentStream(documentId, memoryStream); Trace.WriteLine(String.Format("Storedocument at [{0}] ms", sw.ElapsedMilliseconds)); //Assert.IsTrue(5000 >= sw.ElapsedMilliseconds); //5 s max DocumentInfo documentInfo = client.GetDocumentInfo(documentId); Assert.IsNull(documentInfo); Assert.IsTrue(client.IsDocumentExist(documentId)); client.Delete(documentId); Assert.IsFalse(client.IsDocumentExist(documentId)); } }
public void DocumentStorageTest_Base() { using (var client = new StorageServiceClient()) { byte[] testFileContent = ASCIIEncoding.Default.GetBytes("Test file content"); Stream s = new MemoryStream(testFileContent); Guid documentId = client.BeginStoreDocument(new DocumentInfo { Name = "DocName", Size = testFileContent.Length, IsEncrypted = false }); client.StoreDocumentStream(documentId, s); using (Stream documentStream = client.GetDocumentStream(documentId)) { using (MemoryStream ms = new MemoryStream()) { documentStream.CopyTo(ms); byte[] outFileContent = ms.ToArray(); CollectionAssert.AreEqual(testFileContent, outFileContent); } } DocumentInfo documentInfo = client.GetDocumentInfo(documentId); Assert.AreEqual("DocName", documentInfo.Name); Assert.AreEqual(testFileContent.Length, documentInfo.Size); Assert.IsTrue(client.IsDocumentExist(documentId)); client.Delete(documentId); documentInfo = client.GetDocumentInfo(documentId); Assert.IsNull(documentInfo); Assert.IsFalse(client.IsDocumentExist(documentId)); } }
public void DocumentChunkedStorageTest_Load() { using (var client = new StorageServiceClient()) { int testContentLength = 1024 * 1024;// 1 Mb MemoryStream memoryStream = new MemoryStream(); Random r = new Random(); for (int i = 0; i < testContentLength; i++) { memoryStream.WriteByte((byte)r.Next(0, 255)); } memoryStream.Position = 0; int chunkedSize = 16 * 1024; byte[] buffer = new byte[chunkedSize]; int count = 0; Guid documentId = client.BeginStoreDocument(new DocumentInfo { Name = "DocName", IsEncrypted = false }); client.BeginStoreChunkedDocument(documentId); while ((count = memoryStream.Read(buffer, 0, chunkedSize)) > 0) { client.StoreChunkedDocument(buffer, documentId); } client.EndStoreChunkedDocument(documentId); using (Stream documentStream = client.GetDocumentStream(documentId)) { using (MemoryStream ms = new MemoryStream()) { documentStream.CopyTo(ms); byte[] inFileContent = memoryStream.ToArray(); byte[] outFileContent = ms.ToArray(); CollectionAssert.AreEqual(inFileContent, outFileContent); } } Assert.IsTrue(client.IsDocumentExist(documentId)); client.Delete(documentId); Assert.IsFalse(client.IsDocumentExist(documentId)); } }