예제 #1
0
        public RemoveAzureRmAlertRuleTests()
        {
            insightsAlertRuleOperationsMock = new Mock <IAlertOperations>();
            insightsManagementClientMock    = new Mock <InsightsManagementClient>();
            commandRuntimeMock = new Mock <ICommandRuntime>();
            cmdlet             = new RemoveAzureRmAlertRuleCommand()
            {
                CommandRuntime           = commandRuntimeMock.Object,
                InsightsManagementClient = insightsManagementClientMock.Object
            };

            response = new AzureOperationResponse()
            {
                RequestId  = Guid.NewGuid().ToString(),
                StatusCode = HttpStatusCode.OK,
            };

            insightsAlertRuleOperationsMock.Setup(f => f.DeleteRuleAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <AzureOperationResponse>(response))
            .Callback((string resourceGrp, string ruleName, CancellationToken t) =>
            {
                resourceGroup       = resourceGrp;
                ruleNameOrTargetUri = ruleName;
            });

            insightsManagementClientMock.SetupGet(f => f.AlertOperations).Returns(this.insightsAlertRuleOperationsMock.Object);
        }
        public RemoveAzureRmAlertRuleTests(Xunit.Abstractions.ITestOutputHelper output)
        {
            ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
            insightsAlertRuleOperationsMock = new Mock <IAlertOperations>();
            insightsManagementClientMock    = new Mock <MonitorManagementClient>();
            commandRuntimeMock = new Mock <ICommandRuntime>();
            cmdlet             = new RemoveAzureRmAlertRuleCommand()
            {
                CommandRuntime          = commandRuntimeMock.Object,
                MonitorManagementClient = insightsManagementClientMock.Object
            };

            response = new AzureOperationResponse()
            {
                RequestId  = Guid.NewGuid().ToString(),
                StatusCode = HttpStatusCode.OK,
            };

            insightsAlertRuleOperationsMock.Setup(f => f.DeleteRuleAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <AzureOperationResponse>(response))
            .Callback((string resourceGrp, string ruleName, CancellationToken t) =>
            {
                resourceGroup       = resourceGrp;
                ruleNameOrTargetUri = ruleName;
            });

            insightsManagementClientMock.SetupGet(f => f.AlertOperations).Returns(this.insightsAlertRuleOperationsMock.Object);
        }
예제 #3
0
        public RemoveAzureRmAlertRuleTests(Xunit.Abstractions.ITestOutputHelper output)
        {
            ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
            insightsAlertRuleOperationsMock = new Mock <IAlertRulesOperations>();
            insightsManagementClientMock    = new Mock <MonitorManagementClient>()
            {
                CallBase = true
            };
            commandRuntimeMock = new Mock <ICommandRuntime>();
            cmdlet             = new RemoveAzureRmAlertRuleCommand()
            {
                CommandRuntime          = commandRuntimeMock.Object,
                MonitorManagementClient = insightsManagementClientMock.Object
            };

            response = new Rest.Azure.AzureOperationResponse()
            {
                RequestId = Guid.NewGuid().ToString(),
                Response  = new System.Net.Http.HttpResponseMessage
                {
                    StatusCode = HttpStatusCode.OK
                }
            };

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

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

            // Setup Confirmation
            commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny <string>())).Returns(true);
            commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny <string>(), It.IsAny <string>())).Returns(true);
            commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(true);
            commandRuntimeMock.Setup(f => f.ShouldContinue(It.IsAny <string>(), It.IsAny <string>())).Returns(true);
        }