Exemplo n.º 1
0
        public void SetCommands()
        {
            var leftClickTrigger = new MouseButtonTrigger();

            leftClickTrigger.AddTag("temporary");
            var leftClickCommand = new Command(LeftMouseButton).Add(leftClickTrigger);

            leftClickCommand.AddTag("temporary");
            var middleDragTrigger = new MouseDragTrigger(MouseButton.Middle);

            middleDragTrigger.AddTag("temporary");
            var middleDragCommand = new Command(MiddleMouseDrag).Add(middleDragTrigger);

            middleDragCommand.AddTag("temporary");
            var dragLeftTrigger = new MouseDragTrigger();

            dragLeftTrigger.AddTag("temporary");
            var dragLeftCommand = new Command(LeftMouseDrag).Add(dragLeftTrigger);

            dragLeftCommand.AddTag("temporary");
            var zoomTrigger = new MouseZoomTrigger();

            zoomTrigger.AddTag("temporary");
            var zoomCommand = new Command(Zoom).Add(zoomTrigger);

            zoomCommand.AddTag("temporary");
            var leftReleaseTrigger = new MouseButtonTrigger(State.Releasing);

            leftReleaseTrigger.AddTag("temporary");
            var leftReleaseCommand = new Command(LeftMouseRelease).Add(leftReleaseTrigger);

            leftReleaseCommand.AddTag("temporary");
        }
Exemplo n.º 2
0
 public void CreateFromString()
 {
     var trigger = new MouseButtonTrigger("Right Pressed");
     Assert.AreEqual(MouseButton.Right, trigger.Button);
     Assert.AreEqual(State.Pressed, trigger.State);
     Assert.Throws<MouseButtonTrigger.CannotCreateMouseButtonTriggerWithoutButton>(
         () => new MouseButtonTrigger(""));
 }
 public void ConditionMatchedWithoutMouse(Type resolver)
 {
     Start(resolver, (InputCommands input) =>
     {
         var trigger = new MouseButtonTrigger(MouseButton.Right, State.Pressing);
         Assert.False(trigger.ConditionMatched(input));
     });
 }
        public void CreateFromString()
        {
            var trigger = new MouseButtonTrigger("Right Pressed");

            Assert.AreEqual(MouseButton.Right, trigger.Button);
            Assert.AreEqual(State.Pressed, trigger.State);
            Assert.Throws <MouseButtonTrigger.CannotCreateMouseButtonTriggerWithoutButton>(
                () => new MouseButtonTrigger(""));
        }
Exemplo n.º 5
0
 public void Create()
 {
     var trigger = new MouseButtonTrigger(MouseButton.Right, State.Pressed);
     Assert.AreEqual(MouseButton.Right, trigger.Button);
     Assert.AreEqual(State.Pressed, trigger.State);
     Assert.AreEqual(MouseButton.Left, new MouseButtonTrigger().Button);
     Assert.AreEqual(State.Pressing, new MouseButtonTrigger().State);
     Assert.AreEqual(MouseButton.Left, new MouseButtonTrigger(State.Pressed).Button);
     Assert.AreEqual(State.Pressed, new MouseButtonTrigger(State.Pressed).State);
 }
        public void Create()
        {
            var trigger = new MouseButtonTrigger(MouseButton.Right, State.Pressed);

            Assert.AreEqual(MouseButton.Right, trigger.Button);
            Assert.AreEqual(State.Pressed, trigger.State);
            Assert.AreEqual(MouseButton.Left, new MouseButtonTrigger().Button);
            Assert.AreEqual(State.Pressing, new MouseButtonTrigger().State);
            Assert.AreEqual(MouseButton.Left, new MouseButtonTrigger(State.Pressed).Button);
            Assert.AreEqual(State.Pressed, new MouseButtonTrigger(State.Pressed).State);
        }
        public void CheckForEquility()
        {
            var trigger = new MouseButtonTrigger(MouseButton.Left, State.Pressing);
            var otherTrigger = new MouseButtonTrigger(MouseButton.Left, State.Released);
            Assert.AreNotEqual(trigger, otherTrigger);
            Assert.AreNotEqual(trigger.GetHashCode(), otherTrigger.GetHashCode());

            var copyOfTrigger = new MouseButtonTrigger(MouseButton.Left, State.Pressing);
            Assert.AreEqual(trigger, copyOfTrigger);
            Assert.AreEqual(trigger.GetHashCode(), copyOfTrigger.GetHashCode());
        }
Exemplo n.º 8
0
 public void AddAndRemoveTrigger(Type resolver)
 {
     Start(resolver, (InputCommands input) =>
     {
         var command = new Command();
         var trigger = new MouseButtonTrigger(MouseButton.Left, State.Releasing);
         command.Add(trigger);
         Assert.AreEqual(1, command.attachedTriggers.Count);
         command.Remove(trigger);
         Assert.AreEqual(0, command.attachedTriggers.Count);
     });
 }
Exemplo n.º 9
0
 public void IsTriggered()
 {
     if (resolver.GetType() != typeof(MockResolver))
         return; //ncrunch: no coverage
     var trigger = new MouseButtonTrigger(MouseButton.Right, State.Pressed);
     bool invoked = false;
     trigger.Invoked += () => invoked = true;
     var mouse = Resolve<MockMouse>();
     mouse.SetButtonState(MouseButton.Right, State.Pressed);
     AdvanceTimeAndUpdateEntities();
     Assert.True(invoked);
 }
Exemplo n.º 10
0
        private static void ChangeMouseButtonInCommandList(string adding, string removing,
                                                           Trigger trigger)
        {
            var mouseButtonTrigger = (MouseButtonTrigger)trigger;

            if (mouseButtonTrigger.Button.ToString() == removing)
            {
                mouseButtonTrigger.Dispose();
                mouseButtonTrigger = new MouseButtonTrigger((MouseButton)Enum.Parse(typeof(MouseButton),
                                                                                    adding));
            }
        }
Exemplo n.º 11
0
        public async Task Menu1_PreventShow_IsNotShown(string triggerId, MouseButtonTrigger mouseButton)
        {
            //Arrange
            var expectedDisplay = "none";

            //Act
            await OpenContextMenuAt(triggerId, mouseButton);

            //Assert
            var menuElement = Browser.FindElement(By.Id("menu1"));
            var display     = menuElement.GetCssValue("display");

            Assert.Equal(expectedDisplay, display);
        }
Exemplo n.º 12
0
        protected override void Preview(string contentName)
        {
            var verdana = ContentLoader.Load <Font>("Verdana12");

            new FontText(verdana, "Play", Rectangle.One);
            if (Sound != null)
            {
                DisposeData();
            }
            Sound   = ContentLoader.Load <Sound>(contentName);
            trigger = new MouseButtonTrigger();
            trigger.AddTag("temporary");
            soundCommand = new Command(() => Sound.Play(1)).Add(trigger);
            soundCommand.AddTag("temporary");
        }
        public void IsTriggered()
        {
            if (!IsMockResolver)
            {
                return;                 //ncrunch: no coverage
            }
            var  trigger = new MouseButtonTrigger(MouseButton.Right, State.Pressed);
            bool invoked = false;

            trigger.Invoked += () => invoked = true;
            var mouse = Resolve <MockMouse>();

            mouse.SetButtonState(MouseButton.Right, State.Pressed);
            AdvanceTimeAndUpdateEntities();
            Assert.True(invoked);
        }
Exemplo n.º 14
0
        private void SetMouseCommands(string obj)
        {
            var leftClickTriggerReleasing = new MouseButtonTrigger(MouseButton.Left, State.Releasing);

            leftClickTriggerReleasing.AddTag("temporary");
            var findEntityCommand = new Command(FindEntity2DOnPosition).Add(leftClickTriggerReleasing);

            findEntityCommand.AddTag("temporary");
            var releaseMiddleMouse = new MouseButtonTrigger(MouseButton.Left, State.Releasing);

            releaseMiddleMouse.AddTag("temporary");
            var setReleasingCommand =
                new Command(position => AddControlToScene(position)).Add(releaseMiddleMouse);

            setReleasingCommand.AddTag("temporary");
            UiEditorScene.SetMousePosition();
        }
 public void ConditionMatched()
 {
     var resolver = new TestResolver();
     var input = resolver.Resolve<InputCommands>();
     var trigger = new MouseButtonTrigger(MouseButton.Left, State.Releasing);
     resolver.SetMouseButtonState(MouseButton.Left, State.Releasing, Point.Half);
     Assert.True(trigger.ConditionMatched(input));
     trigger = new MouseButtonTrigger(MouseButton.Middle, State.Released);
     Assert.True(trigger.ConditionMatched(input));
     trigger = new MouseButtonTrigger(MouseButton.Right, State.Pressing);
     resolver.SetMouseButtonState(MouseButton.Right, State.Pressing, Point.Zero);
     Assert.True(trigger.ConditionMatched(input));
     trigger = new MouseButtonTrigger(MouseButton.X1, State.Released);
     Assert.True(trigger.ConditionMatched(input));
     trigger = new MouseButtonTrigger(MouseButton.X2, State.Released);
     Assert.True(trigger.ConditionMatched(input));
 }
Exemplo n.º 16
0
        public async Task Menu2_MouseOverSubMenu_SubMenuOpens(string triggerId, MouseButtonTrigger mouseButton)
        {
            //Arrange
            var expectedDisplay = "block";

            //Act
            await OpenContextMenuAt(triggerId, mouseButton);

            MouseOverElement("submenu1-trigger");
            await Task.Delay(500); //wait for submenu to popup

            //Assert
            var menuElement = Browser.FindElement(By.Id("submenu1"));
            var display     = menuElement.GetCssValue("display");

            Assert.Equal(expectedDisplay, display);
        }
Exemplo n.º 17
0
        public async Task Menu1_TriggerAndClickOutside_MenuCloses(string triggerId, MouseButtonTrigger mouseButton)
        {
            //Arrange
            var expectedDisplay = "none";

            //Act
            await OpenContextMenuAt(triggerId, mouseButton);

            var headerElement = Browser.FindElement(By.Id("header"));

            headerElement.Click();

            //Assert
            var menuElement = Browser.FindElement(By.Id("menu1"));
            var display     = menuElement.GetCssValue("display");

            Assert.Equal(expectedDisplay, display);
        }
Exemplo n.º 18
0
        public async Task Menu1_SelectDisabledItem_MenuStaysOpen(string triggerId, MouseButtonTrigger mouseButton)
        {
            //Arrange
            var expectedDisplay = "block";

            //Act
            await OpenContextMenuAt(triggerId, mouseButton);

            var menuItem = Browser.FindElement(By.Id("menu1-item3"));

            menuItem.Click();

            //Assert
            var menuElement = Browser.FindElement(By.Id("menu1"));
            var display     = menuElement.GetCssValue("display");

            Assert.Equal(expectedDisplay, display);
        }
Exemplo n.º 19
0
        public async Task Menu1_SelectClearData_DataCleared(string triggerId, MouseButtonTrigger mouseButton)
        {
            //Arrange
            var expectedDisplay = "none";

            //Act
            await OpenContextMenuAt(triggerId, mouseButton);

            var menuItem = Browser.FindElement(By.Id("menu1-item2"));

            menuItem.Click();

            //Assert
            var menuElement     = Browser.FindElement(By.Id("menu1"));
            var textArea        = Browser.FindElement(By.Id("test1-textarea"));
            var display         = menuElement.GetCssValue("display");
            var textAreaDisplay = textArea.GetCssValue("display");

            Assert.Equal(expectedDisplay, display);
            Assert.Equal(expectedDisplay, textAreaDisplay);
        }
Exemplo n.º 20
0
        private bool CheckWhichButtonForMouseButtonTriggerToUse(bool foundFreeKey, MouseButton button,
                                                                int index)
        {
            if (foundFreeKey)
            {
                return(true);
            }
            bool keyAlreadyUsed = false;

            foreach (Trigger newTrigger in GetTriggersOfCommand())
            {
                keyAlreadyUsed = CheckIfMouseButtonIsAlreadyUsed(newTrigger, button, keyAlreadyUsed);
            }
            if (keyAlreadyUsed)
            {
                return(false);
            }
            var mouseButtonTrigger = new MouseButtonTrigger(button, State.Pressed);

            GetTriggersOfCommand()[index] = mouseButtonTrigger;
            return(true);
        }
Exemplo n.º 21
0
        protected async Task OpenContextMenuAt(string triggerElementId, MouseButtonTrigger mouseButton)
        {
            var element = Browser.FindElement(By.Id(triggerElementId));
            var action  = new Actions(Browser);

            switch (mouseButton)
            {
            case MouseButtonTrigger.Left:
                action.Click(element).Perform();
                break;

            case MouseButtonTrigger.DoubleClick:
                action.DoubleClick(element).Perform();
                break;

            case MouseButtonTrigger.Right:
                action.ContextClick(element).Perform();
                break;
            }


            await Task.Delay(500);
        }
Exemplo n.º 22
0
        public async Task Menu1_SelectFetchData_DataFetched(string triggerId, MouseButtonTrigger mouseButton)
        {
            //Arrange
            var expectedDisplay = "none";

            //Act
            await OpenContextMenuAt(triggerId, mouseButton);

            var menuItem = Browser.FindElement(By.Id("menu1-item1"));

            menuItem.Click();
            new WebDriverWait(Browser, TimeSpan.FromSeconds(10))
            .Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Id("test1-textarea")));

            //Assert
            var menuElement = Browser.FindElement(By.Id("menu1"));
            var textArea    = Browser.FindElement(By.Id("test1-textarea"));
            var display     = menuElement.GetCssValue("display");
            var text        = textArea.GetAttribute("value");

            Assert.True(!string.IsNullOrWhiteSpace(text));
            Assert.Equal(expectedDisplay, display);
        }
Exemplo n.º 23
0
        public void SetMousePosition()
        {
            var middleClick = new MouseButtonTrigger();

            middleClick.AddTag("temporary");
            var setLastPositionCommand = new Command(position => SetPosition(position)).Add(middleClick);

            setLastPositionCommand.AddTag("temporary");
            var moveMouse = new MousePositionTrigger(MouseButton.Left, State.Released);

            moveMouse.AddTag("temporary");
            var checkTransformationCommand =
                new Command(position => CheckIfCanTransformControl(position)).Add(moveMouse);

            checkTransformationCommand.AddTag("temporary");
            var pressAndMoveMouse = new MousePositionTrigger(MouseButton.Left, State.Pressed);

            pressAndMoveMouse.AddTag("temporary");
            var pressOnControlCommand =
                new Command(position => TransformSelectedControl(position)).Add(pressAndMoveMouse);

            pressOnControlCommand.AddTag("temporary");
            var pressControl = new KeyTrigger(Key.LeftControl);

            pressControl.AddTag("temporary");
            var multiSelectControl = new Command(() => SetMultiSelection(true)).Add(pressControl);

            multiSelectControl.AddTag("temporary");
            var releaseControl = new KeyTrigger(Key.LeftControl, State.Releasing);

            releaseControl.AddTag("temporary");
            var disableMultiSelectControl =
                new Command(() => SetMultiSelection(false)).Add(releaseControl);

            disableMultiSelectControl.AddTag("temporary");
        }
Exemplo n.º 24
0
        protected override void Preview(string contentName)
        {
            verdana = ContentLoader.Load <Font>("Verdana12");
            new FontText(verdana, "Play/Stop", Rectangle.One);
            music = ContentLoader.Load <Music>(contentName);
            music.Play(1);
            var trigger = new MouseButtonTrigger();

            trigger.AddTag("temporary");
            var musicCommand = new Command(() =>             //ncrunch: no coverage start
            {
                if (music.IsPlaying())
                {
                    music.Stop();
                }
                else
                {
                    music.Play(1);
                }
            }).Add(trigger);

            musicCommand.AddTag("temporary");
            //ncrunch: no coverage end
        }
Exemplo n.º 25
0
        public async Task TodoItemsMenu_UnckeckFirstItemAndTriggerMenu_CheckIsEnabled(string listId, MouseButtonTrigger mouseButton)
        {
            //Arrange
            var settings         = new BlazorContextMenuDefaultCssSettings();
            var notExpectedClass = settings.MenuItemDisabledCssClass;

            //Act
            var list          = Browser.FindElement(By.Id(listId));
            var checkBoxes    = list.FindElements(By.TagName("input"));
            var firstCheckBox = checkBoxes[0];

            firstCheckBox.Click();
            await OpenContextMenuAt($"{listId}-0", mouseButton);

            var menuItem = Browser.FindElement(By.Id("menuitem-check"));
            var classes  = menuItem.GetAttribute("class");

            //Assert
            Assert.DoesNotContain(notExpectedClass, classes);
        }
Exemplo n.º 26
0
        public async Task TodoItemsMenu_TriggerForSecondItemAndSelectCheckAndThenTriggerAgain_CheckIsDisabled(string listId, MouseButtonTrigger mouseButton)
        {
            //Arrange
            var expectedCheckedStatus = true;
            var settings      = new BlazorContextMenuDefaultCssSettings();
            var expectedClass = settings.MenuItemDisabledCssClass;

            //Act
            await OpenContextMenuAt($"{listId}-1", mouseButton);

            var menuItem = Browser.FindElement(By.Id("menuitem-check"));

            menuItem.Click();
            await Task.Delay(1000);

            await OpenContextMenuAt($"{listId}-1", mouseButton);

            menuItem = Browser.FindElement(By.Id("menuitem-check"));
            var classes    = menuItem.GetAttribute("class");
            var list       = Browser.FindElement(By.Id(listId));
            var checkBoxes = list.FindElements(By.TagName("input"));
            var secondBox  = checkBoxes[0];


            //Assert
            Assert.Equal(expectedCheckedStatus, secondBox.Selected);
            Assert.Contains(expectedClass, classes);
        }
Exemplo n.º 27
0
        public async Task TodoItemsMenu_TriggerForThirdItemAndCheckVisibilityOfDelete_ItemIsInvisible(string listId, MouseButtonTrigger mouseButton)
        {
            //Arrange
            var expectedDisplay = "none";

            //Act
            await OpenContextMenuAt($"{listId}-2", mouseButton);

            var menuItem = Browser.FindElement(By.Id("menuitem-delete"));
            var styles   = menuItem.GetAttribute("style");

            //Assert
            Assert.Contains(expectedDisplay, styles);
        }
Exemplo n.º 28
0
        public async Task TodoItemsMenu_TriggerForFourthItem_MenuIsNotShown(string listId, MouseButtonTrigger mouseButton)
        {
            //Arrange
            var expectedDisplay = "none";

            //Act
            await OpenContextMenuAt($"{listId}-3", mouseButton);

            //Assert
            var menuElement = Browser.FindElement(By.Id("todoItemsMenu"));
            var display     = menuElement.GetCssValue("display");

            Assert.Equal(expectedDisplay, display);
        }
Exemplo n.º 29
0
        public async Task TodoItemsMenu_TriggerForSecondItemAndSelectDelete_ItemDeleted(string listId, MouseButtonTrigger mouseButton)
        {
            //Arrange
            var expectedItemsCount = 3;

            //Act
            await OpenContextMenuAt($"{listId}-1", mouseButton);

            var menuItem = Browser.FindElement(By.Id("menuitem-delete"));

            menuItem.Click();
            await Task.Delay(500);

            //Assert
            var list       = Browser.FindElement(By.Id(listId));
            var itemsCount = list.FindElements(By.TagName("li")).Count;

            Assert.Equal(expectedItemsCount, itemsCount);
        }
Exemplo n.º 30
0
        public async Task Menu1_TriggerNested_Menu1OpensButMenu2DoesNot(string triggerId, MouseButtonTrigger mouseButton)
        {
            //Arrange
            var menu1ExpectedDisplay = "block";
            var menu2ExpectedDisplay = "none";

            //Act
            await OpenContextMenuAt(triggerId, mouseButton);

            //Assert
            var menu1Element = Browser.FindElement(By.Id("menu1"));
            var display1     = menu1Element.GetCssValue("display");

            Assert.Equal(menu1ExpectedDisplay, display1);

            var menu2Element = Browser.FindElement(By.Id("menu2"));
            var display2     = menu2Element.GetCssValue("display");

            Assert.Equal(menu2ExpectedDisplay, display2);
        }
Exemplo n.º 31
0
        public async Task TodoItemsMenu_TriggerForFirstItemAndSelectCheck_CheckIsDisabled(string listId, MouseButtonTrigger mouseButton)
        {
            //Arrange
            var settings      = new BlazorContextMenuDefaultCssSettings();
            var expectedClass = settings.MenuItemDisabledCssClass;

            //Act
            await OpenContextMenuAt($"{listId}-0", mouseButton);

            var menuItem = Browser.FindElement(By.Id("menuitem-check"));
            var classes  = menuItem.GetAttribute("class");

            //Assert
            Assert.Contains(expectedClass, classes);
        }
Exemplo n.º 32
0
        public async Task TodoItemsMenu_TriggerForSecondItemAndSelectCheck_ItemIsChecked(string listId, MouseButtonTrigger mouseButton)
        {
            //Arrange
            var expectedCheckedStatus = true;

            //Act
            await OpenContextMenuAt($"{listId}-1", mouseButton);

            var menuItem = Browser.FindElement(By.Id("menuitem-check"));

            menuItem.Click();
            await Task.Delay(500);

            var list           = Browser.FindElement(By.Id(listId));
            var checkBoxes     = list.FindElements(By.TagName("input"));
            var secondCheckBox = checkBoxes[1];

            //Assert
            Assert.Equal(expectedCheckedStatus, secondCheckBox.Selected);
        }