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 bool IsDocumentExist(Guid documentStorageId) { using (StorageServiceClient client = new StorageServiceClient()) { return client.IsDocumentExist(documentStorageId); } }
public void AvmServiceTest_StoreInDb_StoreInStorage() { //arrange var orderId = 1; var currentUserId = 1; _orderManager.GetOrderById(1).Returns(new Order { Id = orderId, GeneralInfo = new OrderGeneralInfo { PropertyAddress = new Address(), }, }); //act var address = new AddressViewModel { ZIP = "92037", Street = "5961 LA JOLLA MESA DR" }; _avmRequestsService.SendRequest(orderId, currentUserId); //assert var a = _avmRequestsRepository.Get(q => q.RequestUserId == currentUserId && q.OrderId == orderId); a.Should().HaveCount(1); a.Should().NotBeNull(); foreach (var item in a) { using (var client = new StorageServiceClient()) { var fileExist = client.IsDocumentExist(item.ResponseDocumentId.Value); fileExist.Should().BeTrue(); } } }
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)); } }