public GetAlertRuleCommandTests()
        {
            insightsAlertRuleOperationsMock = new Mock<IAlertOperations>();
            insightsManagementClientMock = new Mock<InsightsManagementClient>();
            commandRuntimeMock = new Mock<ICommandRuntime>();
            cmdlet = new GetAlertRuleCommand()
            {
                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);
        }
Ejemplo n.º 2
0
        public static void VerifyDetailedOutput(GetAlertRuleCommand 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);
        }