Exemplo n.º 1
0
		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));
			}
		}