Microsoft.WindowsAzure.Commands.Test.Utilities.Common.FileSystemHelper.CreateDirectoryWithPrebuiltPackage C# (CSharp) Method

CreateDirectoryWithPrebuiltPackage() public method

public CreateDirectoryWithPrebuiltPackage ( string packageName, string &package, string &configuration ) : void
packageName string
package string
configuration string
return void
        public void CreateDirectoryWithPrebuiltPackage(string packageName, out string package, out string configuration)
        {
            string serviceName = packageName;
            package = Path.Combine(RootPath, packageName + ".cspkg");
            FileUtilities.DataStore.WriteFile(package, "does not matter");
            configuration = Path.Combine(RootPath, "ServiceConfiguration.Cloud.cscfg");
            string template = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" 
                + Environment.NewLine
                + "<ServiceConfiguration serviceName=\"" + serviceName + "\" " 
                + "xmlns=\"http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration\" " 
                + "osFamily=\"2\" osVersion=\"*\" />";
            FileUtilities.DataStore.WriteFile(configuration, template);
            TestMockSupport.TestExecutionFolder = RootPath;
        }
    }

Usage Example

        public void TestUpgradeCloudServiceFromAPackage()
        {
            clientMocks.ComputeManagementClientMock.Setup(
                c =>
                c.HostedServices.CreateAsync(It.IsAny<HostedServiceCreateParameters>(), It.IsAny<CancellationToken>()))
                .Returns(Tasks.FromResult(new OperationResponse
                {
                    RequestId = "request001",
                    StatusCode = HttpStatusCode.OK
                }));

            clientMocks.ComputeManagementClientMock.Setup(
                c =>
                c.Deployments.UpgradeBySlotAsync(It.IsAny<string>(), DeploymentSlot.Production,
                                                 It.IsAny<DeploymentUpgradeParameters>(),
                                                 It.IsAny<CancellationToken>()))
                .Returns(Tasks.FromResult(CreateComputeOperationResponse("req002")));

            clientMocks.ManagementClientMock.Setup(c => c.Locations.ListAsync(It.IsAny<CancellationToken>()))
                .Returns(Tasks.FromResult(new LocationsListResponse
                {
                    Locations =
                    {
                        new LocationsListResponse.Location {DisplayName = "East US", Name = "EastUS"}
                    }
                }));

            using (var files = new FileSystemHelper(this) { EnableMonitoring = true })
            {
                // Setup
                string packageName = serviceName;
                string package, configuration;
                files.CreateDirectoryWithPrebuiltPackage(packageName, out package, out configuration);
                files.CreateAzureSdkDirectoryAndImportPublishSettings();

                // Execute
                ExecuteInTempCurrentDirectory(Path.GetDirectoryName(package),
                    () => client.PublishCloudService(package, configuration, null, null, null, null, null, false, false));

                // Verify
                clientMocks.ComputeManagementClientMock.Verify(c => c.Deployments.UpgradeBySlotAsync(serviceName,
                    DeploymentSlot.Production, It.IsAny<DeploymentUpgradeParameters>(), It.IsAny<CancellationToken>()), Times.Once);
            }
        }