Beispiel #1
0
        public static void VerifyContinuationToken(EventDataListResponse response, Mock <IEventOperations> insinsightsEventOperationsMockightsClientMock, EventCmdletBase cmdlet)
        {
            // Make sure calls to Next work also
            response.EventDataCollection.NextLink = Utilities.ContinuationToken;
            var responseNext = new EventDataListResponse()
            {
                EventDataCollection = new EventDataCollection()
                {
                    Value = new List <EventData>()
                    {
                        Utilities.CreateFakeEvent(),
                    },
                    NextLink = null,
                },
                RequestId  = Guid.NewGuid().ToString(),
                StatusCode = HttpStatusCode.OK
            };

            string nextToken = null;

            insinsightsEventOperationsMockightsClientMock.Setup(f => f.ListEventsNextAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <EventDataListResponse>(responseNext))
            .Callback((string n, CancellationToken t) => nextToken = n);

            // Calling without optional parameters
            cmdlet.ExecuteCmdlet();
            Assert.True(string.Equals(Utilities.ContinuationToken, nextToken, StringComparison.OrdinalIgnoreCase), "Incorrect continuation token");
        }
        public static void ExecuteVerifications(EventCmdletBase cmdlet, Mock<IEventOperations> insinsightsEventOperationsMockightsClientMock, string requiredFieldName, string requiredFieldValue, ref string filter, ref string selected, DateTime startDate, EventDataListResponse response)
        {
            // Calling without optional parameters
            cmdlet.ExecuteCmdlet();

            VerifyFilterIsUsable(filter: filter);
            VerifyStartDateInFilter(filter: filter, startDate: null);
            VerifyConditionInFilter(filter: filter, field: requiredFieldName, value: requiredFieldValue);
            Assert.True(string.Equals(PSEventDataNoDetails.SelectedFieldsForQuery, selected, StringComparison.OrdinalIgnoreCase), "Incorrect nameOrTargetUri clause without optional parameters");

            // Calling with only start date
            cmdlet.StartTime = startDate;
            cmdlet.ExecuteCmdlet();

            VerifyFilterIsUsable(filter: filter);
            VerifyStartDateInFilter(filter: filter, startDate: startDate);
            VerifyConditionInFilter(filter: filter, field: requiredFieldName, value: requiredFieldValue);

            // Calling with only start and end date
            cmdlet.EndTime = startDate.AddSeconds(2);
            cmdlet.ExecuteCmdlet();

            VerifyFilterIsUsable(filter: filter);
            VerifyStartDateInFilter(filter: filter, startDate: startDate);
            VerifyEndDateInFilter(filter: filter, endDate: startDate.AddSeconds(2));
            VerifyConditionInFilter(filter: filter, field: requiredFieldName, value: requiredFieldValue);

            // Calling with only caller
            cmdlet.EndTime = null;
            cmdlet.Caller = Utilities.Caller;
            cmdlet.ExecuteCmdlet();

            VerifyCallerInCall(filter: filter, startDate: startDate, filedName: requiredFieldName, fieldValue: requiredFieldValue);

            // Calling with caller and status
            cmdlet.Status = Utilities.Status;
            cmdlet.ExecuteCmdlet();

            VerifyStatusAndCallerInCall(filter: filter, startDate: startDate, filedName: requiredFieldName, fieldValue: requiredFieldValue);

            VerifyDetailedOutput(cmdlet: cmdlet, selected: ref selected);
            VerifyContinuationToken(response: response, insinsightsEventOperationsMockightsClientMock: insinsightsEventOperationsMockightsClientMock, cmdlet: cmdlet);

            // Execute negative tests
            cmdlet.StartTime = DateTime.Now.AddSeconds(1);
            Assert.Throws<ArgumentException>(() => cmdlet.ExecuteCmdlet());

            cmdlet.StartTime = DateTime.Now.Subtract(TimeSpan.FromSeconds(20));
            cmdlet.EndTime = DateTime.Now.Subtract(TimeSpan.FromSeconds(21));
            Assert.Throws<ArgumentException>(() => cmdlet.ExecuteCmdlet());

            cmdlet.StartTime = DateTime.Now.Subtract(TimeSpan.FromDays(30));
            cmdlet.EndTime = DateTime.Now.Subtract(TimeSpan.FromDays(14));
            Assert.Throws<ArgumentException>(() => cmdlet.ExecuteCmdlet());
        }
Beispiel #3
0
        public static void VerifyContinuationToken(AzureOperationResponse <IPage <EventData> > response, Mock <IEventsOperations> insinsightsEventOperationsMockightsClientMock, EventCmdletBase cmdlet)
        {
            // Make sure calls to Next work also
            string nextToken = ContinuationToken;

            insinsightsEventOperationsMockightsClientMock.Setup(f => f.ListNextWithHttpMessagesAsync(It.IsAny <string>(), It.IsAny <Dictionary <string, List <string> > >(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <AzureOperationResponse <IPage <EventData> > >(response))
            .Callback((string n, Dictionary <string, List <string> > h, CancellationToken t) => nextToken = n);

            // Calling without optional parameters
            cmdlet.ExecuteCmdlet();
            Assert.Equal(Utilities.ContinuationToken, nextToken, ignoreCase: true, ignoreLineEndingDifferences: true, ignoreWhiteSpaceDifferences: true);
        }
        public static void VerifyContinuationToken(EventDataListResponse response, Mock<IEventOperations> insinsightsEventOperationsMockightsClientMock, EventCmdletBase cmdlet)
        {
            // Make sure calls to Next work also
            response.EventDataCollection.NextLink = Utilities.ContinuationToken;
            var responseNext = new EventDataListResponse()
            {
                EventDataCollection = new EventDataCollection()
                {
                    Value = new List<EventData>()
                    {
                        Utilities.CreateFakeEvent(),
                    },
                    NextLink = null,
                },
                RequestId = Guid.NewGuid().ToString(),
                StatusCode = HttpStatusCode.OK
            };

            string nextToken = null;
            insinsightsEventOperationsMockightsClientMock.Setup(f => f.ListEventsNextAsync(It.IsAny<string>(), It.IsAny<CancellationToken>()))
                .Returns(Task.FromResult<EventDataListResponse>(responseNext))
                .Callback((string n, CancellationToken t) => nextToken = n);

            // Calling without optional parameters
            cmdlet.ExecuteCmdlet();
            Assert.True(string.Equals(Utilities.ContinuationToken, nextToken, StringComparison.OrdinalIgnoreCase), "Incorrect continuation token");
        }
 public static void VerifyDetailedOutput(EventCmdletBase cmdlet, ref string selected)
 {
     // Calling with detailed output
     cmdlet.DetailedOutput = true;
     cmdlet.ExecuteCmdlet();
     Assert.Null(selected); // Incorrect nameOrTargetUri clause with detailed output on
 }
        void TestEvent(EventCmdletBase cmdlet, params AutomationProperty[] properties)
        {
            // Arrange
            IAutomation automation = Substitute.For <IAutomation>();

            automation.RawViewCondition.Returns(Condition.TrueCondition);
            cmdlet.UiaAutomation = automation;
            var command =
                AutomationFactory.GetCommand <EventCommand>(cmdlet);

            // Act
            command.Execute();

            // Assert
            foreach (var element in cmdlet.InputObject)
            {
                switch (cmdlet.GetType().Name)
                {
                case "RegisterUiaFocusChangedEventCommand":
                    automation.Received(1).AddAutomationFocusChangedEventHandler(
                        new AutomationFocusChangedEventHandler(cmdlet.AutomationEventHandler));
                    break;

                case "RegisterUiaInvokedEventCommand":
                    automation.Received(1).AddAutomationEventHandler(
                        InvokePattern.InvokedEvent,
                        Arg.Any <IUiElement>(),
                        TreeScope.Element,
                        new AutomationEventHandler(cmdlet.AutomationEventHandler));
                    break;

                case "RegisterUiaMenuClosedEventCommand":
                    automation.Received(1).AddAutomationEventHandler(
                        AutomationElement.MenuClosedEvent,
                        Arg.Any <IUiElement>(),
                        TreeScope.Subtree,
                        new AutomationEventHandler(cmdlet.AutomationEventHandler));
                    break;

                case "RegisterUiaMenuOpenedEventCommand":
                    automation.Received(1).AddAutomationEventHandler(
                        AutomationElement.MenuOpenedEvent,
                        Arg.Any <IUiElement>(),
                        TreeScope.Subtree,
                        new AutomationEventHandler(cmdlet.AutomationEventHandler));
                    break;

//                    case "RegisterUiaPropertyChangedEventCommand":
//                    case "RegisterUiaGridRowCountChangedEventCommand":
//                    case "RegisterUiaGridColumnCountChangedEventCommand":
//                    case "RegisterUiaRangeValueChangedEventCommand":
//                    case "RegisterUiaTableColumnCountChangedEventCommand":
//                    case "RegisterUiaTableRowCountChangedEventCommand":
//                    case "RegisterUiaValueChangedEventCommand":
//                        automation.Received(1).AddAutomationPropertyChangedEventHandler(
//                            Arg.Any<IUiElement>(),
//                            TreeScope.Subtree,
//                            new AutomationPropertyChangedEventHandler(cmdlet.AutomationPropertyChangedEventHandler),
//                            cmdlet.AutomationProperty);
////if (null == properties) {
////    Console.WriteLine("null == properties");
////} else {
////    Console.WriteLine("null != properties");
////    Console.WriteLine(properties.All(p => { Console.WriteLine("expected: {0}", p.ProgrammaticName); return true; } ));
////}
////if (null == cmdlet.AutomationProperty) {
////    Console.WriteLine("null == cmdlet.AutomationProperty");
////} else {
////    Console.WriteLine("null != cmdlet.AutomationProperty");
////    Console.WriteLine(cmdlet.AutomationProperty.All(p => { Console.WriteLine("actual: {0}", p.ProgrammaticName); return true; } ));
////}
//                        MbUnit.Framework.Assert.AreEqual<AutomationProperty[]>(properties, cmdlet.AutomationProperty);
//                        Xunit.Assert.Equal<AutomationProperty[]>(properties, cmdlet.AutomationProperty);
//                        break;
                case "RegisterUiaStructureChangedEventCommand":
                    automation.Received(1).AddStructureChangedEventHandler(
                        Arg.Any <IUiElement>(),
                        TreeScope.Subtree,
                        new StructureChangedEventHandler(cmdlet.StructureChangedEventHandler));
                    break;

                case "RegisterUiaTextChangedEventCommand":
                    automation.Received(1).AddAutomationEventHandler(
                        TextPattern.TextChangedEvent,
                        Arg.Any <IUiElement>(),
                        TreeScope.Element,
                        new AutomationEventHandler(cmdlet.AutomationEventHandler));
                    break;

                case "RegisterUiaTextSelectionChangedEventCommand":
                    automation.Received(1).AddAutomationEventHandler(
                        TextPattern.TextSelectionChangedEvent,
                        Arg.Any <IUiElement>(),
                        TreeScope.Element,
                        new AutomationEventHandler(cmdlet.AutomationEventHandler));
                    break;

                case "RegisterUiaToolTipClosedEventCommand":
                    automation.Received(1).AddAutomationEventHandler(
                        AutomationElement.ToolTipClosedEvent,
                        Arg.Any <IUiElement>(),
                        TreeScope.Subtree,
                        new AutomationEventHandler(cmdlet.AutomationEventHandler));
                    break;

                case "RegisterUiaToolTipOpenedEventCommand":
                    automation.Received(1).AddAutomationEventHandler(
                        AutomationElement.ToolTipOpenedEvent,
                        Arg.Any <IUiElement>(),
                        TreeScope.Subtree,
                        new AutomationEventHandler(cmdlet.AutomationEventHandler));
                    break;

                case "RegisterUiaWindowClosedEventCommand":
                    automation.Received(1).AddAutomationEventHandler(
                        WindowPattern.WindowClosedEvent,
                        Arg.Any <IUiElement>(),
                        TreeScope.Subtree,
                        new AutomationEventHandler(cmdlet.AutomationEventHandler));
                    break;

                case "RegisterUiaWindowOpenedEventCommand":
                    automation.Received(1).AddAutomationEventHandler(
                        WindowPattern.WindowOpenedEvent,
                        Arg.Any <IUiElement>(),
                        TreeScope.Subtree,
                        new AutomationEventHandler(cmdlet.AutomationEventHandler));
                    break;

                default:
                    automation.Received(1).AddAutomationPropertyChangedEventHandler(
                        Arg.Any <IUiElement>(),
                        TreeScope.Subtree,
                        new AutomationPropertyChangedEventHandler(cmdlet.AutomationPropertyChangedEventHandler),
                        cmdlet.AutomationProperty);
                    MbUnit.Framework.Assert.AreEqual <AutomationProperty[]>(properties, cmdlet.AutomationProperty);
                    Assert.Equal <AutomationProperty[]>(properties, cmdlet.AutomationProperty);
                    break;
                }
            }
        }
 public static void VerifyDetailedOutput(EventCmdletBase cmdlet, ref string selected)
 {
     // Calling with detailed output
     cmdlet.DetailedOutput = true;
     cmdlet.ExecuteCmdlet();
     Assert.True(string.Equals(null, selected, StringComparison.OrdinalIgnoreCase), "Incorrect selected clause with detailed output on");
 }
Beispiel #8
0
        public static void VerifyContinuationToken(AzureOperationResponse<IPage<EventData>> response, Mock<IEventsOperations> insinsightsEventOperationsMockightsClientMock, EventCmdletBase cmdlet)
        {
            // Make sure calls to Next work also
            string nextToken = ContinuationToken;
            insinsightsEventOperationsMockightsClientMock.Setup(f => f.ListNextWithHttpMessagesAsync(It.IsAny<string>(), It.IsAny<Dictionary<string, List<string>>>(), It.IsAny<CancellationToken>()))
                .Returns(Task.FromResult<AzureOperationResponse<IPage<EventData>>>(response))
                .Callback((string n, Dictionary<string, List<string>> h, CancellationToken t) => nextToken = n);

            // Calling without optional parameters
            cmdlet.ExecuteCmdlet();
            Assert.Equal(Utilities.ContinuationToken, nextToken, ignoreCase:true, ignoreLineEndingDifferences:true,ignoreWhiteSpaceDifferences:true);
        }