示例#1
0
		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));
			}
		}
示例#2
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));
			}
		}