public static PSResourceGroup ToPSResourceGroup(this ResourceGroup resourceGroup, ResourcesClient client) { List<PSResource> resources = client.FilterResources(new FilterResourcesOptions { ResourceGroup = resourceGroup.Name }) .Select(r => r.ToPSResource(client)).ToList(); return new PSResourceGroup() { ResourceGroupName = resourceGroup.Name, Location = resourceGroup.Location, Resources = resources, ResourcesTable = ConstructResourcesTable(resources), ProvisioningState = resourceGroup.ProvisioningState }; }
public static PSResource ToPSResource(this Resource resource, ResourcesClient client) { ResourceIdentifier identifier = new ResourceIdentifier(resource.Id); return(new PSResource() { Name = identifier.ResourceName, Location = resource.Location, ResourceType = identifier.ResourceType, ResourceGroupName = identifier.ResourceGroupName, ParentResource = identifier.ParentResource, Properties = JsonUtilities.DeserializeJson(resource.Properties), PropertiesText = resource.Properties }); }
public ResourceClientTests() { ResourceManagementClientMock = new Mock<IResourceManagementClient>(); deploymentsMock = new Mock<IDeploymentOperations>(); resourceGroupMock = new Mock<IResourceGroupOperations>(); resourceOperationsMock = new Mock<IResourceOperations>(); galleryTemplatesClientMock = new Mock<GalleryTemplatesClient>(); eventsClientMock = new Mock<IEventsClient>(); deploymentOperationsMock = new Mock<IDeploymentOperationOperations>(); eventDataOperationsMock = new Mock<IEventDataOperations>(); providersMock = new Mock<IProviderOperations>(); providersMock.Setup(f => f.ListAsync(null, new CancellationToken())) .Returns(Task.Factory.StartNew(() => new ProviderListResult { Providers = new List<Provider>() })); progressLoggerMock = new Mock<Action<string>>(); errorLoggerMock = new Mock<Action<string>>(); ResourceManagementClientMock.Setup(f => f.Deployments).Returns(deploymentsMock.Object); ResourceManagementClientMock.Setup(f => f.ResourceGroups).Returns(resourceGroupMock.Object); ResourceManagementClientMock.Setup(f => f.Resources).Returns(resourceOperationsMock.Object); ResourceManagementClientMock.Setup(f => f.DeploymentOperations).Returns(deploymentOperationsMock.Object); ResourceManagementClientMock.Setup(f => f.Providers).Returns(providersMock.Object); eventsClientMock.Setup(f => f.EventData).Returns(eventDataOperationsMock.Object); storageClientWrapperMock = new Mock<IStorageClientWrapper>(); resourcesClient = new ResourcesClient( ResourceManagementClientMock.Object, storageClientWrapperMock.Object, galleryTemplatesClientMock.Object, eventsClientMock.Object) { VerboseLogger = progressLoggerMock.Object, ErrorLogger = errorLoggerMock.Object }; resourceIdentity = new ResourceIdentity { ParentResourcePath = "sites/siteA", ResourceName = "myResource", ResourceProviderNamespace = "Microsoft.Web", ResourceType = "sites" }; properties = new Dictionary<string, object> { {"name", "site1"}, {"siteMode", "Standard"}, {"computeMode", "Dedicated"}, {"misc", new Dictionary<string, object> { {"key1", "value1"}, {"key2", "value2"} }} }; serializedProperties = JsonConvert.SerializeObject(properties, new JsonSerializerSettings { TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple, TypeNameHandling = TypeNameHandling.None }); sampleEvents = new List<EventData>(); sampleEvents.Add(new EventData { EventDataId = "ac7d2ab5-698a-4c33-9c19-0a93d3d7f527", EventName = new LocalizableString {LocalizedValue = "Start request"}, EventSource = new LocalizableString {LocalizedValue = "Microsoft Resources"}, EventChannels = EventChannels.Operation, Level = EventLevel.Informational, EventTimestamp = DateTime.Now, OperationId = "c0f2e85f-efb0-47d0-bf90-f983ec8be91d", SubscriptionId = "c0f2e85f-efb0-47d0-bf90-f983ec8be91d", CorrelationId = "c0f2e85f-efb0-47d0-bf90-f983ec8be91d", OperationName = new LocalizableString { LocalizedValue = "Microsoft.Resources/subscriptions/resourcegroups/deployments/write" }, Status = new LocalizableString {LocalizedValue = "Succeeded"}, SubStatus = new LocalizableString {LocalizedValue = "Created"}, ResourceGroupName = "foo", ResourceProviderName = new LocalizableString {LocalizedValue = "Microsoft Resources"}, ResourceUri = "/subscriptions/ffce8037-a374-48bf-901d-dac4e3ea8c09/resourcegroups/foo/deployments/testdeploy", HttpRequest = new HttpRequestInfo { Uri = "http://path/subscriptions/ffce8037-a374-48bf-901d-dac4e3ea8c09/resourcegroups/foo/deployments/testdeploy", Method = "PUT", ClientRequestId = "1234", ClientIpAddress = "123.123.123.123" }, Authorization = new SenderAuthorization { Action = "PUT", Condition = "", Role = "Sender", Scope = "None" }, Claims = new Dictionary<string, string> { {"aud", "https://management.core.windows.net/"}, {"iss", "https://sts.windows.net/123456/"}, {"iat", "h123445"}, {"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name", "*****@*****.**"} }, Properties = new Dictionary<string,string>() }); sampleEvents.Add(new EventData { EventDataId = "ac7d2ab5-698a-4c33-9c19-0sdfsdf34r54", EventName = new LocalizableString { LocalizedValue = "End request" }, EventSource = new LocalizableString { LocalizedValue = "Microsoft Resources" }, EventChannels = EventChannels.Operation, Level = EventLevel.Informational, EventTimestamp = DateTime.Now, OperationId = "c0f2e85f-efb0-47d0-bf90-f983ec8be91d", OperationName = new LocalizableString { LocalizedValue = "Microsoft.Resources/subscriptions/resourcegroups/deployments/write" }, Status = new LocalizableString { LocalizedValue = "Succeeded" }, SubStatus = new LocalizableString { LocalizedValue = "Created" }, ResourceGroupName = "foo", ResourceProviderName = new LocalizableString { LocalizedValue = "Microsoft Resources" }, ResourceUri = "/subscriptions/ffce8037-a374-48bf-901d-dac4e3ea8c09/resourcegroups/foo/deployments/testdeploy", HttpRequest = new HttpRequestInfo { Uri = "http://path/subscriptions/ffce8037-a374-48bf-901d-dac4e3ea8c09/resourcegroups/foo/deployments/testdeploy", Method = "PUT", ClientRequestId = "1234", ClientIpAddress = "123.123.123.123" }, Authorization = new SenderAuthorization { Action = "PUT", Condition = "", Role = "Sender", Scope = "None" }, Claims = new Dictionary<string, string> { {"aud", "https://management.core.windows.net/"}, {"iss", "https://sts.windows.net/123456/"}, {"iat", "h123445"} }, Properties = new Dictionary<string, string>() }); }
public static PSResourceGroup ToPSResourceGroup(this ResourceGroup resourceGroup, ResourcesClient client) { List <PSResource> resources = client.FilterResources(new FilterResourcesOptions { ResourceGroup = resourceGroup.Name }) .Select(r => r.ToPSResource(client)).ToList(); return(new PSResourceGroup() { ResourceGroupName = resourceGroup.Name, Location = resourceGroup.Location, Resources = resources, ResourcesTable = ConstructResourcesTable(resources), ProvisioningState = resourceGroup.ProvisioningState }); }
public static PSResource ToPSResource(this Resource resource, ResourcesClient client) { ResourceIdentifier identifier = new ResourceIdentifier(resource.Id); return new PSResource() { Name = identifier.ResourceName, Location = resource.Location, ResourceType = identifier.ResourceType, ResourceGroupName = identifier.ResourceGroupName, ParentResource = identifier.ParentResource, Properties = JsonUtilities.DeserializeJson(resource.Properties), PropertiesText = resource.Properties }; }