public void AzureConnectorDelete2Test() { if (String.IsNullOrEmpty(TestCommon.AzureStorageKey)) { Assert.Inconclusive("No Azure Storage Key defined in App.Config, so can't test"); } AzureStorageConnector azureConnector = new AzureStorageConnector(TestCommon.AzureStorageKey, testContainerSecure); // Add a file using (var fileStream = System.IO.File.OpenRead(@".\resources\office365.png")) { azureConnector.SaveFileStream("blabla.png", testContainer, fileStream); } // Delete the file azureConnector.DeleteFile("blabla.png", testContainer); //read the file using (var bytes = azureConnector.GetFileStream("blabla.png", testContainer)) { Assert.IsNull(bytes); } // file will be deleted at end of test since the used storage containers are deleted }
public void AzureConnectorSaveStream3Test() { if (String.IsNullOrEmpty(TestCommon.AzureStorageKey)) { Assert.Inconclusive("No Azure Storage Key defined in App.Config, so can't test"); } AzureStorageConnector azureConnector = new AzureStorageConnector(TestCommon.AzureStorageKey, testContainerSecure); // first save using (var fileStream = System.IO.File.OpenRead(@".\resources\custombg.jpg")) { azureConnector.SaveFileStream("blabla.png", testContainer, fileStream); } // Second save long byteCount = 0; using (var fileStream = System.IO.File.OpenRead(@".\resources\office365.png")) { byteCount = fileStream.Length; azureConnector.SaveFileStream("blabla.png", testContainer, fileStream); } //read the file using (var bytes = azureConnector.GetFileStream("blabla.png", testContainer)) { Assert.IsTrue(byteCount == bytes.Length); } // file will be deleted at end of test since the used storage containers are deleted }
public void AzureConnectorSaveStream2Folder2Test() { if (String.IsNullOrEmpty(TestCommon.AzureStorageKey)) { Assert.Inconclusive("No Azure Storage Key defined in App.Config, so can't test"); } string containerWithFolder = string.Format("{0}/{1}", testContainerSecure, "sub1/sub11/"); AzureStorageConnector azureConnector = new AzureStorageConnector(TestCommon.AzureStorageKey, containerWithFolder); long byteCount = 0; using (var fileStream = System.IO.File.OpenRead(@".\resources\office365.png")) { byteCount = fileStream.Length; azureConnector.SaveFileStream("blabla.png", containerWithFolder, fileStream); } //read the file using (var bytes = azureConnector.GetFileStream("blabla.png", containerWithFolder)) { Assert.IsTrue(byteCount == bytes.Length); } // file will be deleted at end of test since the used storage containers are deleted }
public void AzureConnectorGetFileBytes2Test() { if (String.IsNullOrEmpty(TestCommon.AzureStorageKey)) { Assert.Inconclusive("No Azure Storage Key defined in App.Config, so can't test"); } AzureStorageConnector azureConnector = new AzureStorageConnector(TestCommon.AzureStorageKey, testContainerSecure); using (var bytes = azureConnector.GetFileStream("office365.png", testContainer)) { Assert.IsTrue(bytes.Length > 0); } using (var bytes2 = azureConnector.GetFileStream("Idonotexist.xml", testContainer)) { Assert.IsNull(bytes2); } }
public void AzureConnectorGetFileBytes1Test() { if (String.IsNullOrEmpty(TestCommon.AzureStorageKey)) { Assert.Inconclusive("No Azure Storage Key defined in App.Config, so can't test"); } AzureStorageConnector azureConnector = new AzureStorageConnector(TestCommon.AzureStorageKey, testContainerSecure); using (var bytes = azureConnector.GetFileStream("ProvisioningTemplate-2015-03-Sample-01.xml")) { Assert.IsTrue(bytes.Length > 0); } using (var bytes2 = azureConnector.GetFileStream("Idonotexist.xml")) { Assert.IsNull(bytes2); } }
public void AzureConnectorBackslashSupportTest() { if (String.IsNullOrEmpty(TestCommon.AzureStorageKey)) { Assert.Inconclusive("No Azure Storage Key defined in App.Config, so can't test"); } // Path with backslash-separator var filename = "separator.png"; var containerWithBackslash = string.Format(@"{0}\{1}", testContainerSecure, "sub2"); // Constructor replaces folder delimiter AzureStorageConnector azureConnector = new AzureStorageConnector(TestCommon.AzureStorageKey, containerWithBackslash); Assert.AreEqual($"{testContainerSecure}/sub2", azureConnector.GetContainer()); // Save a file long byteCount = 0; using (var fileStream = System.IO.File.OpenRead(@".\resources\office365.png")) { byteCount = fileStream.Length; azureConnector.SaveFileStream(filename, containerWithBackslash, fileStream); } // List files var files = azureConnector.GetFiles(containerWithBackslash); Assert.IsTrue(files.Contains($"sub2/{filename}")); // Read the file using (var fileStream = azureConnector.GetFileStream(filename, containerWithBackslash)) { Assert.AreEqual(byteCount, fileStream.Length); } // Delete the file azureConnector.DeleteFile(filename, containerWithBackslash); // Folder will be deleted in cleanup }