public void Install(RunningDeployment deployment) { var package = deployment.Variables.Get(SpecialVariables.Action.Azure.CloudServicePackagePath); Log.Info("Uploading package to Azure blob storage: '{0}'", package); var packageHash = HashCalculator.Hash(package); var nugetPackageVersion = deployment.Variables.Get(SpecialVariables.Package.NuGetPackageVersion); var uploadedFileName = Path.ChangeExtension(Path.GetFileName(package), "." + nugetPackageVersion + "_" + packageHash + ".cspkg"); var credentials = credentialsFactory.GetCredentials( deployment.Variables.Get(SpecialVariables.Action.Azure.SubscriptionId), deployment.Variables.Get(SpecialVariables.Action.Azure.CertificateThumbprint), deployment.Variables.Get(SpecialVariables.Action.Azure.CertificateBytes) ); var storageAccountName = deployment.Variables.Get(SpecialVariables.Action.Azure.StorageAccountName); var storageEndpointSuffix = deployment.Variables.Get(SpecialVariables.Action.Azure.StorageEndPointSuffix, DefaultVariables.StorageEndpointSuffix); var defaultServiceManagementEndpoint = deployment.Variables.Get(SpecialVariables.Action.Azure.ServiceManagementEndPoint, DefaultVariables.ServiceManagementEndpoint); var uploadedUri = azurePackageUploader.Upload(credentials, storageAccountName, package, uploadedFileName, storageEndpointSuffix, defaultServiceManagementEndpoint); Log.SetOutputVariable(SpecialVariables.Action.Azure.UploadedPackageUri, uploadedUri.ToString(), deployment.Variables); Log.Info("Package uploaded to " + uploadedUri.ToString()); }
public void ShouldUploadPackage() { const string packageFileName = "Acme.cspkg"; var packageFilePath = Path.Combine(stagingDirectory, packageFileName); variables.Set(SpecialVariables.Package.NuGetPackageVersion, "1.0.0"); variables.Set(SpecialVariables.Action.Azure.CloudServicePackagePath, packageFilePath); fileSystem.EnumerateFiles(stagingDirectory, "*.cspkg") .Returns(new[] { packageFilePath }); fileSystem.OpenFile(packageFilePath, Arg.Any <FileMode>()) .Returns(new MemoryStream(Encoding.UTF8.GetBytes("blah blah blah"))); var uploadedUri = new Uri("http://azure.com/wherever/my-package.cspkg"); packageUploader.Upload( Arg.Is <SubscriptionCloudCredentials>(cred => cred.SubscriptionId == azureSubscriptionId), storageAccountName, packageFilePath, Arg.Any <string>()) .Returns(uploadedUri); convention.Install(deployment); Assert.AreEqual(uploadedUri.ToString(), variables.Get(SpecialVariables.Action.Azure.UploadedPackageUri)); }