Esempio n. 1
0
        public GetAzureRmAlertRuleTests(ITestOutputHelper output)
        {
            XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
            insightsAlertRuleOperationsMock = new Mock <IAlertOperations>();
            insightsManagementClientMock    = new Mock <InsightsManagementClient>();
            commandRuntimeMock = new Mock <ICommandRuntime>();
            cmdlet             = new GetAzureRmAlertRuleCommand()
            {
                CommandRuntime           = commandRuntimeMock.Object,
                InsightsManagementClient = insightsManagementClientMock.Object
            };

            listResponse   = Utilities.InitializeRuleListResponse();
            singleResponse = Utilities.InitializeRuleGetResponse();

            insightsAlertRuleOperationsMock.Setup(f => f.ListRulesAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <RuleListResponse>(listResponse))
            .Callback((string resourceGrp, string nameOrTargetUri, CancellationToken t) =>
            {
                resourceGroup       = resourceGrp;
                ruleNameOrTargetUri = nameOrTargetUri;
            });

            insightsAlertRuleOperationsMock.Setup(f => f.GetRuleAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <RuleGetResponse>(singleResponse))
            .Callback((string resourceGrp, string nameOrTargetUri, CancellationToken t) =>
            {
                resourceGroup       = resourceGrp;
                ruleNameOrTargetUri = nameOrTargetUri;
            });

            insightsManagementClientMock.SetupGet(f => f.AlertOperations).Returns(this.insightsAlertRuleOperationsMock.Object);
        }
Esempio n. 2
0
        /*
         * public static RuleListResponse InitializeRuleListResponse()
         * {
         *  // This is effectively testing the conversion EventData -> PSEventData internally in the execution of the cmdlet
         *  AlertRuleResource ruleResource = Utilities.CreateFakeRuleResource();
         *  return new RuleListResponse()
         *  {
         *      RuleResourceCollection = new RuleResourceCollection()
         *      {
         *          Value = new List<AlertRuleResource>() { ruleResource },
         *      },
         *      RequestId = Guid.NewGuid().ToString(),
         *      StatusCode = HttpStatusCode.OK
         *  };
         * }
         *
         * public static RuleGetResponse InitializeRuleGetResponse()
         * {
         *  // This is effectively testing the conversion EventData -> PSEventData internally in the execution of the cmdlet
         *  AlertRuleResource ruleResource = Utilities.CreateFakeRuleResource();
         *  return new RuleGetResponse()
         *  {
         *      Id = ruleResource.Id,
         *      Location = ruleResource.Location,
         *      Name = ruleResource.Name,
         *      Properties = ruleResource.Properties,
         *      Tags = ruleResource.Tags,
         *      RequestId = Guid.NewGuid().ToString(),
         *      StatusCode = HttpStatusCode.OK
         *  };
         * } */

        public static void VerifyDetailedOutput(GetAzureRmAlertRuleCommand cmdlet, string expectedResourceGroup, ref string resourceGroup, ref string nameOrTargetUri)
        {
            // Calling with detailed output
            cmdlet.DetailedOutput   = true;
            cmdlet.Name             = null;
            cmdlet.TargetResourceId = ResourceUri;
            cmdlet.ExecuteCmdlet();

            Assert.Equal(expectedResourceGroup, resourceGroup);
            Assert.Equal(ResourceUri, nameOrTargetUri);
        }
        public GetAzureRmAlertRuleTests(ITestOutputHelper output)
        {
            ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagement.Common.Models.XunitTracingInterceptor(output));
            insightsAlertRuleOperationsMock = new Mock <IAlertRulesOperations>();
            insightsManagementClientMock    = new Mock <MonitorManagementClient>()
            {
                CallBase = true
            };
            commandRuntimeMock = new Mock <ICommandRuntime>();
            cmdlet             = new GetAzureRmAlertRuleCommand()
            {
                CommandRuntime          = commandRuntimeMock.Object,
                MonitorManagementClient = insightsManagementClientMock.Object
            };

            listResponse = new Rest.Azure.AzureOperationResponse <IEnumerable <AlertRuleResource> >
            {
                Body = Utilities.InitializeRuleListResponse(),
            };

            singleResponse = new Rest.Azure.AzureOperationResponse <AlertRuleResource>
            {
                Body = Utilities.InitializeRuleGetResponse()
            };

            insightsAlertRuleOperationsMock.Setup(f => f.ListByResourceGroupWithHttpMessagesAsync(It.IsAny <string>(), It.IsAny <Dictionary <string, List <string> > >(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <Rest.Azure.AzureOperationResponse <IEnumerable <AlertRuleResource> > >(listResponse))
            .Callback((string resourceGrp, Dictionary <string, List <string> > headers, CancellationToken t) =>
            {
                resourceGroup = resourceGrp;
            });

            insightsAlertRuleOperationsMock.Setup(f => f.GetWithHttpMessagesAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Dictionary <string, List <string> > >(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <Rest.Azure.AzureOperationResponse <AlertRuleResource> >(singleResponse))
            .Callback((string resourceGrp, string nameOrTargetUri, Dictionary <string, List <string> > headers, CancellationToken t) =>
            {
                resourceGroup       = resourceGrp;
                ruleNameOrTargetUri = nameOrTargetUri;
            });

            insightsManagementClientMock.SetupGet(f => f.AlertRules).Returns(this.insightsAlertRuleOperationsMock.Object);
        }