public void GetStorageConfigurationTest()
        {
            string storageConfigurationContent =
                @"{
	                'location': 'location1',
	                'name': 'name1',
	                'properties': {
		                'logging': {
			                'delete': true,
			                'read': false,
			                'retention': 'P30D',
			                'write': true
		                },
		                'metrics': {
			                'aggregations': [{
				                'level': 'Service',
				                'retention': 'P10D',
				                'scheduledTransferPeriod': 'P1D'
			                }]
		                }
	                },
	                'requestId': 'requestid1'	
                }";

            StorageConfigurationGetResponse expectedStorageConfiguration = GetStorageConfiguration();
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(storageConfigurationContent)
            };

            var handler = new RecordedDelegatingHandler(response);
            var insightsClient = GetInsightsManagementClient(handler);
            StorageConfigurationGetResponse actualStorageConfiguration = insightsClient.MonitoringConfigurationOperations.GetStorageConfiguration(resourceUri: "r1");
            AreEqual(expectedStorageConfiguration.Properties, actualStorageConfiguration.Properties);
        }
コード例 #2
0
        public void LogProfiles_DeleteTest()
        {
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(string.Empty)
            };

            var handler = new RecordedDelegatingHandler(response);
            InsightsManagementClient customClient = this.GetInsightsManagementClient(handler);

            customClient.LogProfilesOperations.Delete(DefaultName);
        }
コード例 #3
0
        public void CreateOrUpdateSettingTest()
        {
            var handler = new RecordedDelegatingHandler();
            InsightsManagementClient customClient = this.GetInsightsManagementClient(handler);

            AutoscaleSettingCreateOrUpdateParameters parameters = new AutoscaleSettingCreateOrUpdateParameters
            {
                Properties = CreateAutoscaleSetting(ResourceUri, "CpuPercentage", string.Empty),
                Location = "East US",
                Tags = new Dictionary<string, string> { { "tag1", "value1" } }
            };

            customClient.AutoscaleOperations.CreateOrUpdateSetting("resourceGroup1", "setting1", parameters);
            var actualResponse = JsonExtensions.FromJson<AutoscaleSettingCreateOrUpdateParameters>(handler.Request);
            AreEqual(parameters.Properties, actualResponse.Properties);
        }
コード例 #4
0
        public void ListUsageTest()
        {
            string resourceUri = "/subscriptions/123456789/resourceGroups/rg/providers/rp/rUri";
            string filterString = "name.value eq 'CPUTime' or name.value eq 'Requests'";

            UsageMetricCollection expectedUsageMetricCollection = GetUsageMetricCollection(resourceUri);
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(expectedUsageMetricCollection.ToJson())
            };

            RecordedDelegatingHandler handler = new RecordedDelegatingHandler(response);
            var insightsClient = GetInsightsClient(handler);


            UsageMetricListResponse actualRespose = insightsClient.UsageMetricOperations.List(resourceUri: resourceUri, filterString: filterString, apiVersion: "2014-04-01");

            AreEqual(expectedUsageMetricCollection, actualRespose.UsageMetricCollection);
        }
コード例 #5
0
        public void GetIncidentTest()
        {
            var expectedIncident = GetIncidents().First();

            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(expectedIncident.ToJson())
            };

            var handler = new RecordedDelegatingHandler(response);
            var insightsClient = GetInsightsManagementClient(handler);

            var actualIncident = insightsClient.AlertOperations.GetIncident(
                resourceGroupName: "rg1",
                ruleName: "r1",
                incidentName: "i1");

            AreEqual(expectedIncident, actualIncident.Incident);
        }
コード例 #6
0
        public void LogProfiles_CreateOrUpdateTest()
        {
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(string.Empty)
            };

            var handler = new RecordedDelegatingHandler(response);
            InsightsManagementClient customClient = this.GetInsightsManagementClient(handler);

            var parameters = new LogProfileCreatOrUpdateParameters
            {
                Properties = CreateLogProfile()
            };

            customClient.LogProfilesOperations.CreateOrUpdate(DefaultName, parameters);

            var actualRequest = JsonExtensions.FromJson<LogProfileCreatOrUpdateParameters>(handler.Request);
            AreEqual(parameters.Properties, actualRequest.Properties);
        }
コード例 #7
0
        public void GetMetricsTest()
        {
            MetricCollection expectedMetricCollection = GetMetricCollection(ResourceUri);

            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(expectedMetricCollection.ToJson())
            };

            RecordedDelegatingHandler handler = new RecordedDelegatingHandler(response);
            var insightsClient = GetInsightsClient(handler);

            string filterString = "timeGrain eq duration'PT1M' and startTime eq 2014-01-01T06:00:00Z and endTime eq 2014-01-10T06:00:00Z";
            MetricListResponse actualMetrics = (insightsClient.MetricOperations as MetricOperations)
                .GetMetricsAsync(
                    ResourceUri,
                    filterString,
                    CancellationToken.None).Result;

            AreEqual(expectedMetricCollection, actualMetrics.MetricCollection);
        }
コード例 #8
0
        public void GetMetricDefinitionsTest()
        {
            MetricDefinitionCollection expectedMetricDefinitionCollection = GetMetricDefinitionCollection(ResourceUri);

            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(expectedMetricDefinitionCollection.ToJson())
            };

            RecordedDelegatingHandler handler = new RecordedDelegatingHandler(response);
            var insightsClient = GetInsightsClient(handler);

            string filterString = "names eq 'CpuPercentage'";
            MetricDefinitionListResponse actualMetricDefinitions =
                (insightsClient.MetricDefinitionOperations as MetricDefinitionOperations)
                    .GetMetricDefinitionsAsync(
                        ResourceUri,
                        filterString,
                        new CancellationToken()).Result;

            AreEqual(expectedMetricDefinitionCollection, actualMetricDefinitions.MetricDefinitionCollection);
        }
コード例 #9
0
        public void ListEventsTest()
        {
            EventDataCollection expectedEventDataCollection = GetEventDataCollection();

            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(expectedEventDataCollection.ToJson())
            };
            
            var handler = new RecordedDelegatingHandler(response) { StatusCodeToReturn = HttpStatusCode.OK };

            var startTime = DateTimeOffset.Parse("2014-03-11T01:00:00.00Z");
            var endTime = DateTimeOffset.Parse("2014-03-11T02:00:00.00Z");

            var insightsClient = GetInsightsClient(handler);

            var filterString = FilterString.Generate<ListEventsParameters>(
                    p => (p.EventTimestamp >= startTime) && (p.EventTimestamp < endTime));

            var actualEventDataCollection = insightsClient.EventOperations.ListEvents(filterString, selectedProperties: string.Empty);

            AreEqual(expectedEventDataCollection, actualEventDataCollection.EventDataCollection);       
        }
コード例 #10
0
        public void Autoscale_GetSetting()
        {
            var expectedAutoscaleSetting = CreateAutoscaleSetting(ResourceUri, "CpuPercentage", string.Empty);
            var expectedAutoscaleSettingGetResponse = new AutoscaleSettingGetResponse()
            {
                Id = ResourceUri,
                Location = "East US",
                Tags = new Dictionary<string, string> {{"tag1", "value1"}},
                Name = expectedAutoscaleSetting.Name,
                Properties = expectedAutoscaleSetting,
                RequestId = "request id",
                StatusCode = HttpStatusCode.OK
            };

            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(expectedAutoscaleSettingGetResponse.ToJson()),
            };

            var handler = new RecordedDelegatingHandler(response);
            InsightsManagementClient customClient = this.GetInsightsManagementClient(handler);
            AutoscaleSettingGetResponse actualResponse = customClient.AutoscaleOperations.GetSetting("resourceGroup1", "setting1");
            AreEqual(expectedAutoscaleSettingGetResponse.Properties, actualResponse.Properties);
        }
コード例 #11
0
 protected InsightsManagementClient GetInsightsManagementClient(RecordedDelegatingHandler handler)
 {
     var token = new TokenCloudCredentials(Guid.NewGuid().ToString(), "abc123");
     handler.IsPassThrough = false;
     return new InsightsManagementClient(token).WithHandler(handler);
 }
        public void GetConfigurationTest()
        {
            string expectedMonitoringConfigurationContent =
                @"{
	                'location': 'l1',
	                'name': 'n1',
	                'properties': {
		                'description': 'd1',
		                'name': 'n1',
		                'publicConfiguration': {
			                'odata.type': 'Microsoft.Azure.Management.Insights.Models.PublicMonitoringConfiguration',
			                'diagnosticMonitorConfiguration': {
				                'crashDumps': {
					                'containerName': 'c1',
					                'directoryQuotaPercentage': 50,
					                'dumpType': 'Mini',
					                'processes': ['w3wp.exe']
				                },
				                'diagnosticInfrastructureLogs': {
					                'scheduledTransferLogLevelFilter': 'Verbose',
					                'scheduledTransferPeriod': 'PT10M'
				                },
				                'directories': {
					                'dataSources': [{
						                'containerName': 'c1',
						                'path': {
                                            'odata.type': 'Microsoft.Azure.Management.Insights.Models.DirectoryAbsolute',
							                'expandEnvironment': true,
							                'path': 'p1'
						                }
					                }],
					                'failedRequestLogs': 'f1',
					                'iisLogs': 'i1',
					                'scheduledTransferPeriod': 'P1D'
				                },
				                'etwProviders': {
					                'eventSourceProviders': [{
						                'defaultDestination': 'dd1',
						                'events': [{
							                'destination': 'dd1',
							                'eventId': 23
						                }],
						                'provider': 'p1',
						                'scheduledTransferKeywordFilter': 10,
						                'scheduledTransferLogLevelFilter': 'Verbose',
						                'scheduledTransferPeriod': 'P2D'
					                }],
					                'manifestProviders': [{
						                'defaultDestination': 'dd1',
						                'events': [{
							                'destination': 'dd1',
							                'eventId': 23
						                }],
						                'provider': 'p1',
						                'scheduledTransferKeywordFilter': 10,
						                'scheduledTransferLogLevelFilter': 'Verbose',
						                'scheduledTransferPeriod': 'P2D'
					                }]
				                },
				                'metrics': {
					                'aggregations': [{
						                'scheduledTransferPeriod': 'PT0.01S'
					                }],
					                'resourceId': 'r1'
				                },
				                'overallQuotaInMB': 100,
				                'performanceCounters': {
					                'counters': [{
						                'annotations': [{
							                'locale': 'en-US',
							                'value': 'val1'
						                }],
						                'counterSpecifier': 'c1',
						                'sampleRate': 'P2D',
						                'unit': 'Bytes'
					                }],
					                'scheduledTransferPeriod': 'P1D'
				                },
				                'windowsEventLog': {
					                'dataSources': ['d1'],
					                'scheduledTransferPeriod': 'PT10S'
				                }
			                },
			                'localResourceDirectory': null,
			                'storageAccount': null
		                }
	                },
	                'requestId': 'r1'
                }";
            MonitoringConfigurationGetResponse expectedResponse = GetMonitoringConfiguration();
            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(expectedMonitoringConfigurationContent)
            };
            var handler = new RecordedDelegatingHandler(response);
            var insightsClient = GetInsightsManagementClient(handler);
            MonitoringConfigurationGetResponse actualResponse = insightsClient.MonitoringConfigurationOperations.GetConfiguration(resourceUri: "res1");
            AreEqual(expectedResponse.Properties, actualResponse.Properties);
        }
コード例 #13
0
        public void ListIncidentsTest()
        {
            var expectedIncidentsResponse = new IncidentListResponse()
            {
                Value = new List<Incident>()
                {
                    new Incident()
                    {
                        ActivatedTime = DateTime.Parse("2014-08-01T00:00:00Z"),
                        IsActive = false,
                        Name = "i1",
                        ResolvedTime = DateTime.Parse("2014-08-01T00:00:00Z"),
                        RuleName = "r1"
                    }
                }
            };

            string listIncidentsContent = @"{
                'value': [{
	                'activatedTime': '2014-08-01T00:00:00Z',
	                'isActive': false,
	                'name': 'i1',
	                'resolvedTime': '2014-08-01T00:00:00Z',
	                'ruleName': 'r1'
                }]
            }";

            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(listIncidentsContent)
            };

            var handler = new RecordedDelegatingHandler(response);
            var insightsClient = GetInsightsManagementClient(handler);

            IncidentListResponse actualIncidents = insightsClient.AlertOperations.ListIncidentsForRule(
                resourceGroupName: "rg1",
                ruleName: "r1");

            AreEqual(expectedIncidentsResponse.Value, actualIncidents.Value);
        }
        public void CreateOrUpdateConfigurationTest()
        {
            MonitoringConfigurationCreateOrUpdateParameters expectedParameters = GetCreateOrUpdateConfigurationParameters();
            var handler = new RecordedDelegatingHandler();
            var insightsClient = GetInsightsManagementClient(handler);
            insightsClient.MonitoringConfigurationOperations.CreateOrUpdateConfiguration(
                resourceUri: "res1",
                parameters: expectedParameters);

            var fixedRequestString = handler.Request
                .Replace("\"aggregations\":", "\"metricAggregations\":");
            var actualParameters = JsonExtensions.FromJson<MonitoringConfigurationCreateOrUpdateParameters>(fixedRequestString);
            AreEqual(expectedParameters.Properties, actualParameters.Properties);
        }
コード例 #15
0
        public void CreateOrUpdateRuleTest()
        {
            RuleCreateOrUpdateParameters expectedParameters = GetCreateOrUpdateRuleParameter();
            var handler = new RecordedDelegatingHandler();
            var insightsClient = GetInsightsManagementClient(handler);

            insightsClient.AlertOperations.CreateOrUpdateRule(resourceGroupName: "rg1", parameters: expectedParameters);

            var actualParameters = JsonExtensions.FromJson<RuleCreateOrUpdateParameters>(handler.Request);

            AreEqual(expectedParameters, actualParameters);
        }
コード例 #16
0
        public void ListRulesTest()
        {
            RuleResourceCollection expectedRuleResourceCollection = JsonExtensions.FromJson<RuleResourceCollection>(ListRulesContent);

            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(ListRulesContent)
            };

            var handler = new RecordedDelegatingHandler(response);
            var insightsClient = GetInsightsManagementClient(handler);
            RuleListResponse actualResponse = insightsClient.AlertOperations.ListRules(resourceGroupName: " rg1", targetResourceUri: "resUri");

            AreEqual(expectedRuleResourceCollection, actualResponse.RuleResourceCollection);
        }
コード例 #17
0
        public void LogProfiles_GetTest()
        {
            var logProfile = CreateLogProfile();
            var expectedResponse = new LogProfileGetResponse()
            {
                Id = ResourceId,
                Name = DefaultName,
                Properties = logProfile,
                RequestId = "request id",
                StatusCode = HttpStatusCode.OK
            };

            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(expectedResponse.ToJson()),
            };

            var handler = new RecordedDelegatingHandler(response);
            InsightsManagementClient customClient = this.GetInsightsManagementClient(handler);

            LogProfileGetResponse actualResponse = customClient.LogProfilesOperations.Get(DefaultName);
            AreEqual(expectedResponse.Properties, actualResponse.Properties);
        }
コード例 #18
0
        public void ListEventStatusCountSummaryItemsTest()
        {
            EventStatusCountSummaryItemCollection eventStatusCountSummaryItemCollection = GetEventStatusCountSummaryItemCollection();

            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(eventStatusCountSummaryItemCollection.ToJson())
            };

            var handler = new RecordedDelegatingHandler(response) { StatusCodeToReturn = HttpStatusCode.OK };

            var startTime = DateTimeOffset.Parse("2014-03-11T01:00:00.00Z");
            var endTime = DateTimeOffset.Parse("2014-03-11T02:00:00.00Z");

            var insightsClient = GetInsightsClient(handler);

            var filterString = FilterString.Generate<ListEventsParameters>(
                    p => (p.EventTimestamp >= startTime) && (p.EventTimestamp < endTime));

            var actualEventStatusCountSummaryResponse = insightsClient.EventOperations.ListEventStatusCountSummaryItemsAsync(filterString).Result;

            AreEqual(eventStatusCountSummaryItemCollection, actualEventStatusCountSummaryResponse.EventStatusCountSummaryItemCollection);
        }
コード例 #19
0
        public void LogProfiles_ListTest()
        {
            var logProfile = CreateLogProfile();

            var expectedResponse = new LogProfileListResponse
            {
                LogProfileCollection = new LogProfileCollection
                {
                    Value = new List<LogProfileResource>
                    {
                        new LogProfileResource()
                        {
                            Id = ResourceId,
                            Name = DefaultName,
                            Properties = logProfile
                        }
                    }
                }
            };

            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(expectedResponse.LogProfileCollection.ToJson()),
            };

            var handler = new RecordedDelegatingHandler(response);
            InsightsManagementClient customClient = this.GetInsightsManagementClient(handler);

            LogProfileListResponse actualResponse = customClient.LogProfilesOperations.List();

            Assert.Equal(expectedResponse.LogProfileCollection.Value.Count, actualResponse.LogProfileCollection.Value.Count);
            AreEqual(
                expectedResponse.LogProfileCollection.Value[0].Properties,
                actualResponse.LogProfileCollection.Value[0].Properties);
        }
コード例 #20
0
        public void ListEventsNextTest()
        {
            EventDataCollection expectedEventDataCollection = GetEventDataCollection();

            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(expectedEventDataCollection.ToJson())
            };

            var handler = new RecordedDelegatingHandler(response) { StatusCodeToReturn = HttpStatusCode.OK };
            var insightsClient = GetInsightsClient(handler);

            var actualEventDataCollection = insightsClient.EventOperations.ListEventsNext("http://www.microsoft.com");
            AreEqual(expectedEventDataCollection, actualEventDataCollection.EventDataCollection);       
        }