public void CanCreateVirtualNetwork() { using (var context = FluentMockContext.Start(this.GetType().FullName)) { IResourceManager resourceManager = TestHelper.CreateResourceManager(); try { resourceManager.Deployments .Define(deploymentName1) .WithNewResourceGroup(rgName, Region.USEast) .WithTemplateLink(templateUri, contentVersion) .WithParametersLink(parametersUri, contentVersion) .WithMode(DeploymentMode.Complete) .Create(); // List var deployments = resourceManager.Deployments.ListByResourceGroup(rgName); var found = from dep in deployments where dep.Name.Equals(deploymentName1, StringComparison.OrdinalIgnoreCase) select dep; Assert.True(found != null); // Check existence Assert.True(resourceManager.Deployments.CheckExistence(rgName, deploymentName1)); // Get var deployment = resourceManager.Deployments.GetByResourceGroup(rgName, deploymentName1); Assert.True(deployment != null); Assert.True(deployment.ProvisioningState != null); // Try export template from deployment object var exportedDeployment = deployment.ExportTemplate(); Assert.True(exportedDeployment.Template != null); // Try export template using resourcegroup var resourceGroup = resourceManager.ResourceGroups.GetByName(rgName); var exportedRG = resourceGroup.ExportTemplate(ResourceGroupExportTemplateOptions.IncludeBoth); Assert.True(exportedRG.Template != null); // Deployment operations var deploymentOperations = deployment.DeploymentOperations.List(); Assert.Equal(4, deploymentOperations.Count()); IDeploymentOperation deploymentOperation = deployment.DeploymentOperations.GetById(deploymentOperations.First().OperationId); Assert.NotNull(deploymentOperation); resourceManager.GenericResources.Delete(rgName, "Microsoft.Network", "", "virtualnetworks", "VNet1", "2015-06-15"); } finally { try { TestHelper.CreateResourceManager().ResourceGroups.DeleteByName(rgName); } catch { } } } }
public static void PrintDeploymentOperation(IDeploymentOperation operation) { StringBuilder info = new StringBuilder(); info.Append("Deployment Operation: ").Append(operation.Timestamp) .Append($"\n StatusCode: {operation.StatusCode}"); if (operation.TargetResource != null) { info.Append($"\n ResourceName: {operation.TargetResource.ResourceName}") .Append($"\n ResourceType: {operation.TargetResource.ResourceType}") .Append($"\n ResourceId: {operation.TargetResource.Id}"); } Log(info.ToString()); }