TestOnMouseDown() public method

public TestOnMouseDown ( IExplorerItemModel treenode, int clickCount ) : bool
treenode IExplorerItemModel
clickCount int
return bool
Example #1
0
        static void Verify_OnMouseDown_OpenOnDoubleClick_DoesNothing(int clickCount, bool openOnDoubleClick)
        {
            //------------Setup for test--------------------------
            var eventPublisher = new Mock <IEventAggregator>();

            eventPublisher.Setup(p => p.Publish(It.IsAny <object>())).Verifiable();

            var behavior = new TestNavigationItemViewModelMouseDownBehavior(eventPublisher.Object)
            {
                OpenOnDoubleClick = openOnDoubleClick
            };

            var connection = new Mock <IEnvironmentConnection>();

            connection.Setup(c => c.ServerEvents).Returns(new Mock <IEventPublisher>().Object);
            var environmentModel = new Mock <IEnvironmentModel>();

            environmentModel.Setup(e => e.Connection).Returns(connection.Object);

            var resourceModel = new Mock <IContextualResourceModel>();

            resourceModel.Setup(r => r.Environment).Returns(environmentModel.Object);
            resourceModel.Setup(r => r.IsAuthorized(AuthorizationContext.View)).Returns(true);

            var explorerItemModel = new ExplorerItemModel(new Mock <IStudioResourceRepository>().Object, new Mock <IAsyncWorker>().Object, new Mock <IConnectControlSingleton>().Object)
            {
                Permissions = Permissions.Administrator
            };
            //------------Execute Test---------------------------
            var result = behavior.TestOnMouseDown(explorerItemModel, clickCount);

            //------------Assert Results-------------------------
            Assert.IsTrue(result);
            eventPublisher.Verify(p => p.Publish(It.IsAny <object>()), Times.Never());
        }
Example #2
0
        public void NavigationItemViewModelMouseDownBehavior_OnMouseDown_OpenOnDoubleClickIsTrueAndClickCountIsOne_PublishesEvent()
        {
            //------------Setup for test--------------------------
            var eventPublisher = new Mock <IEventAggregator>();
            var behavior       = new TestNavigationItemViewModelMouseDownBehavior(eventPublisher.Object)
            {
                OpenOnDoubleClick = true
            };

            var connection = new Mock <IEnvironmentConnection>();

            connection.Setup(c => c.ServerEvents).Returns(new Mock <IEventPublisher>().Object);
            var environmentModel = new Mock <IEnvironmentModel>();

            environmentModel.Setup(e => e.Connection).Returns(connection.Object);

            var resourceModel = new Mock <IContextualResourceModel>();

            resourceModel.Setup(r => r.Environment).Returns(environmentModel.Object);
            resourceModel.Setup(r => r.IsAuthorized(AuthorizationContext.View)).Returns(true);

            var explorerItemModel = new ExplorerItemModel(new Mock <IStudioResourceRepository>().Object, new Mock <IAsyncWorker>().Object, new Mock <IConnectControlSingleton>().Object);

            //------------Execute Test---------------------------
            var result = behavior.TestOnMouseDown(explorerItemModel, 1);

            //------------Assert Results-------------------------
            Assert.IsTrue(result);
        }
Example #3
0
        public void NavigationItemViewModelMouseDownBehavior_OnMouseDown_TreeNodeIsResourceTreeViewModelWithNullDataContext_DoesNothing()
        {
            //------------Setup for test--------------------------
            var eventPublisher = new Mock <IEventAggregator>();

            eventPublisher.Setup(p => p.Publish(It.IsAny <object>())).Verifiable();

            var behavior = new TestNavigationItemViewModelMouseDownBehavior(eventPublisher.Object);

            var connection = new Mock <IEnvironmentConnection>();

            connection.Setup(c => c.ServerEvents).Returns(new Mock <IEventPublisher>().Object);
            var environmentModel = new Mock <IEnvironmentModel>();

            environmentModel.Setup(e => e.Connection).Returns(connection.Object);

            var resourceModel = new Mock <IContextualResourceModel>();

            resourceModel.Setup(r => r.Environment).Returns(environmentModel.Object);

            //------------Execute Test---------------------------
            var result = behavior.TestOnMouseDown(null, 1);

            //------------Assert Results-------------------------
            Assert.IsFalse(result);
            eventPublisher.Verify(p => p.Publish(It.IsAny <object>()), Times.Never());
        }
Example #4
0
        public void NavigationItemViewModelMouseDownBehavior_OnMouseDown_TreecodeIsNotResourceTreeViewModel_PublishEventsCorrectly()
        {
            //------------Setup for test--------------------------
            var eventPublisher = new Mock <IEventAggregator>();

            var behavior = new TestNavigationItemViewModelMouseDownBehavior(eventPublisher.Object);

            var explorerItemModel = new ExplorerItemModel(new Mock <IStudioResourceRepository>().Object, new Mock <IAsyncWorker>().Object, new Mock <IConnectControlSingleton>().Object);

            //------------Execute Test---------------------------
            var result = behavior.TestOnMouseDown(explorerItemModel, 1);

            //------------Assert Results-------------------------
            Assert.IsTrue(result);
        }
Example #5
0
        static void Verify_OnMouseDown_SelectOnRightClick(bool selectOnRightClick)
        {
            //------------Setup for test--------------------------
            var eventPublisher = new Mock <IEventAggregator>();
            var behavior       = new TestNavigationItemViewModelMouseDownBehavior(eventPublisher.Object)
            {
                SelectOnRightClick = selectOnRightClick
            };

            var explorerItemModel = new ExplorerItemModel(new Mock <IStudioResourceRepository>().Object, new Mock <IAsyncWorker>().Object, new Mock <IConnectControlSingleton>().Object);

            //------------Execute Test---------------------------
            var result = behavior.TestOnMouseDown(explorerItemModel, 1);

            //------------Assert Results-------------------------
            Assert.IsTrue(result);
            Assert.AreEqual(selectOnRightClick, explorerItemModel.IsExplorerSelected);
        }
Example #6
0
        static void Verify_OnMouseDown_SetActiveEnvironmentOnClick(int publishCount, bool setActiveEnvironmentOnClick)
        {
            //------------Setup for test--------------------------
            var eventPublisher = new Mock <IEventAggregator>();

            eventPublisher.Setup(p => p.Publish(It.IsAny <SetActiveEnvironmentMessage>())).Verifiable();

            var behavior = new TestNavigationItemViewModelMouseDownBehavior(eventPublisher.Object)
            {
                SetActiveEnvironmentOnClick = setActiveEnvironmentOnClick
            };

            var explorerItemModel = new ExplorerItemModel(new Mock <IStudioResourceRepository>().Object, new Mock <IAsyncWorker>().Object, new Mock <IConnectControlSingleton>().Object);

            //------------Execute Test---------------------------
            var result = behavior.TestOnMouseDown(explorerItemModel, 1);

            //------------Assert Results-------------------------
            Assert.IsTrue(result);
            eventPublisher.Verify(p => p.Publish(It.IsAny <SetActiveEnvironmentMessage>()), Times.Exactly(publishCount));
        }
Example #7
0
        void Verify_OnMouseDown_UserIsNotAuthorized(int editHitCount, bool isAuthorized)
        {
            //------------Setup for test--------------------------
            var eventPublisher = new Mock <IEventAggregator>();
            var behavior       = new TestNavigationItemViewModelMouseDownBehavior(eventPublisher.Object);

            // ensure EditCommand is ONLY being blocked by authorization check!
            const int ClickCount = 2;

            behavior.DontAllowDoubleClick = false;
            behavior.OpenOnDoubleClick    = true;

            var connection = new Mock <IEnvironmentConnection>();

            connection.Setup(c => c.ServerEvents).Returns(new Mock <IEventPublisher>().Object);
            var environmentModel = new Mock <IEnvironmentModel>();

            environmentModel.Setup(e => e.Connection).Returns(connection.Object);

            var editCommand = new Mock <ICommand>();

            editCommand.Setup(c => c.CanExecute(It.IsAny <object>())).Returns(true);
            editCommand.Setup(c => c.Execute(It.IsAny <object>())).Verifiable();

            Mock <IExplorerItemModel> mock = new Mock <IExplorerItemModel>();

            mock.Setup(model => model.Permissions).Returns(isAuthorized ? Permissions.Administrator : Permissions.None);
            mock.Setup(model => model.EditCommand).Returns(editCommand.Object);
            mock.Setup(model => model.CanEdit).Returns(true);
            var explorerItemModel = mock.Object;
            //------------Execute Test---------------------------
            var result = behavior.TestOnMouseDown(explorerItemModel, ClickCount);

            //------------Assert Results-------------------------
            Assert.IsTrue(result);
            editCommand.Verify(c => c.Execute(It.IsAny <object>()), Times.Exactly(editHitCount));
        }
Example #8
0
        static void Verify_OnMouseDown_OpenOnDoubleClickIsTrueAndClickCountIsTwo(bool dontAllowDoubleClick)
        {
            //------------Setup for test--------------------------
            var eventPublisher = new Mock <IEventAggregator>();

            var behavior = new TestNavigationItemViewModelMouseDownBehavior(eventPublisher.Object)
            {
                OpenOnDoubleClick = true, DontAllowDoubleClick = dontAllowDoubleClick
            };

            var connection = new Mock <IEnvironmentConnection>();

            connection.Setup(c => c.ServerEvents).Returns(new Mock <IEventPublisher>().Object);
            var environmentModel = new Mock <IEnvironmentModel>();

            environmentModel.Setup(e => e.Connection).Returns(connection.Object);

            var resourceModel = new Mock <IContextualResourceModel>();

            resourceModel.Setup(r => r.Environment).Returns(environmentModel.Object);
            resourceModel.Setup(r => r.IsAuthorized(AuthorizationContext.View)).Returns(true);

            var editCommand = new Mock <ICommand>();

            editCommand.Setup(c => c.CanExecute(It.IsAny <object>())).Returns(true);
            editCommand.Setup(c => c.Execute(It.IsAny <object>())).Verifiable();

            var explorerItemModel = new ExplorerItemModel(new Mock <IStudioResourceRepository>().Object, new Mock <IAsyncWorker>().Object, new Mock <IConnectControlSingleton>().Object);

            //------------Execute Test---------------------------
            var result = behavior.TestOnMouseDown(explorerItemModel, 2);

            //------------Assert Results-------------------------
            Assert.AreEqual(dontAllowDoubleClick, result);
            editCommand.Verify(c => c.Execute(It.IsAny <object>()), Times.Exactly(dontAllowDoubleClick ? 0 : 1));
        }
        static void Verify_OnMouseDown_OpenOnDoubleClickIsTrueAndClickCountIsTwo(bool dontAllowDoubleClick)
        {
            //------------Setup for test--------------------------
            var eventPublisher = new Mock<IEventAggregator>();

            var behavior = new TestNavigationItemViewModelMouseDownBehavior(eventPublisher.Object) { OpenOnDoubleClick = true, DontAllowDoubleClick = dontAllowDoubleClick };

            var connection = new Mock<IEnvironmentConnection>();
            connection.Setup(c => c.ServerEvents).Returns(new Mock<IEventPublisher>().Object);
            var environmentModel = new Mock<IEnvironmentModel>();
            environmentModel.Setup(e => e.Connection).Returns(connection.Object);

            var resourceModel = new Mock<IContextualResourceModel>();
            resourceModel.Setup(r => r.Environment).Returns(environmentModel.Object);
            resourceModel.Setup(r => r.IsAuthorized(AuthorizationContext.View)).Returns(true);

            var editCommand = new Mock<ICommand>();
            editCommand.Setup(c => c.CanExecute(It.IsAny<object>())).Returns(true);
            editCommand.Setup(c => c.Execute(It.IsAny<object>())).Verifiable();

            var explorerItemModel = new ExplorerItemModel(new Mock<IStudioResourceRepository>().Object, new Mock<IAsyncWorker>().Object, new Mock<IConnectControlSingleton>().Object);

            //------------Execute Test---------------------------
            var result = behavior.TestOnMouseDown(explorerItemModel, 2);

            //------------Assert Results-------------------------
            Assert.AreEqual(dontAllowDoubleClick, result);
            editCommand.Verify(c => c.Execute(It.IsAny<object>()), Times.Exactly(dontAllowDoubleClick ? 0 : 1));
        }
        public void NavigationItemViewModelMouseDownBehavior_OnMouseDown_OpenOnDoubleClickIsTrueAndClickCountIsOne_PublishesEvent()
        {
            //------------Setup for test--------------------------
            var eventPublisher = new Mock<IEventAggregator>();
            var behavior = new TestNavigationItemViewModelMouseDownBehavior(eventPublisher.Object) { OpenOnDoubleClick = true };

            var connection = new Mock<IEnvironmentConnection>();
            connection.Setup(c => c.ServerEvents).Returns(new Mock<IEventPublisher>().Object);
            var environmentModel = new Mock<IEnvironmentModel>();
            environmentModel.Setup(e => e.Connection).Returns(connection.Object);

            var resourceModel = new Mock<IContextualResourceModel>();
            resourceModel.Setup(r => r.Environment).Returns(environmentModel.Object);
            resourceModel.Setup(r => r.IsAuthorized(AuthorizationContext.View)).Returns(true);

            var explorerItemModel = new ExplorerItemModel(new Mock<IStudioResourceRepository>().Object, new Mock<IAsyncWorker>().Object, new Mock<IConnectControlSingleton>().Object);

            //------------Execute Test---------------------------
            var result = behavior.TestOnMouseDown(explorerItemModel, 1);

            //------------Assert Results-------------------------
            Assert.IsTrue(result);
        }
        static void Verify_OnMouseDown_OpenOnDoubleClick_DoesNothing(int clickCount, bool openOnDoubleClick)
        {
            //------------Setup for test--------------------------
            var eventPublisher = new Mock<IEventAggregator>();
            eventPublisher.Setup(p => p.Publish(It.IsAny<object>())).Verifiable();

            var behavior = new TestNavigationItemViewModelMouseDownBehavior(eventPublisher.Object) { OpenOnDoubleClick = openOnDoubleClick };

            var connection = new Mock<IEnvironmentConnection>();
            connection.Setup(c => c.ServerEvents).Returns(new Mock<IEventPublisher>().Object);
            var environmentModel = new Mock<IEnvironmentModel>();
            environmentModel.Setup(e => e.Connection).Returns(connection.Object);

            var resourceModel = new Mock<IContextualResourceModel>();
            resourceModel.Setup(r => r.Environment).Returns(environmentModel.Object);
            resourceModel.Setup(r => r.IsAuthorized(AuthorizationContext.View)).Returns(true);

            var explorerItemModel = new ExplorerItemModel(new Mock<IStudioResourceRepository>().Object, new Mock<IAsyncWorker>().Object, new Mock<IConnectControlSingleton>().Object) { Permissions = Permissions.Administrator };
            //------------Execute Test---------------------------
            var result = behavior.TestOnMouseDown(explorerItemModel, clickCount);

            //------------Assert Results-------------------------
            Assert.IsTrue(result);
            eventPublisher.Verify(p => p.Publish(It.IsAny<object>()), Times.Never());
        }
        void Verify_OnMouseDown_UserIsNotAuthorized(int editHitCount, bool isAuthorized)
        {
            //------------Setup for test--------------------------
            var eventPublisher = new Mock<IEventAggregator>();
            var behavior = new TestNavigationItemViewModelMouseDownBehavior(eventPublisher.Object);

            // ensure EditCommand is ONLY being blocked by authorization check!
            const int ClickCount = 2;
            behavior.DontAllowDoubleClick = false;
            behavior.OpenOnDoubleClick = true;

            var connection = new Mock<IEnvironmentConnection>();
            connection.Setup(c => c.ServerEvents).Returns(new Mock<IEventPublisher>().Object);
            var environmentModel = new Mock<IEnvironmentModel>();
            environmentModel.Setup(e => e.Connection).Returns(connection.Object);

            var editCommand = new Mock<ICommand>();
            editCommand.Setup(c => c.CanExecute(It.IsAny<object>())).Returns(true);
            editCommand.Setup(c => c.Execute(It.IsAny<object>())).Verifiable();

            Mock<IExplorerItemModel> mock = new Mock<IExplorerItemModel>();
            mock.Setup(model => model.Permissions).Returns(isAuthorized ? Permissions.Administrator : Permissions.None);
            mock.Setup(model => model.EditCommand).Returns(editCommand.Object);
            mock.Setup(model => model.CanEdit).Returns(true);
            var explorerItemModel = mock.Object;
            //------------Execute Test---------------------------
            var result = behavior.TestOnMouseDown(explorerItemModel, ClickCount);

            //------------Assert Results-------------------------
            Assert.IsTrue(result);
            editCommand.Verify(c => c.Execute(It.IsAny<object>()), Times.Exactly(editHitCount));
        }
        public void NavigationItemViewModelMouseDownBehavior_OnMouseDown_TreeNodeIsResourceTreeViewModelWithNullDataContext_DoesNothing()
        {
            //------------Setup for test--------------------------
            var eventPublisher = new Mock<IEventAggregator>();
            eventPublisher.Setup(p => p.Publish(It.IsAny<object>())).Verifiable();

            var behavior = new TestNavigationItemViewModelMouseDownBehavior(eventPublisher.Object);

            var connection = new Mock<IEnvironmentConnection>();
            connection.Setup(c => c.ServerEvents).Returns(new Mock<IEventPublisher>().Object);
            var environmentModel = new Mock<IEnvironmentModel>();
            environmentModel.Setup(e => e.Connection).Returns(connection.Object);

            var resourceModel = new Mock<IContextualResourceModel>();
            resourceModel.Setup(r => r.Environment).Returns(environmentModel.Object);

            //------------Execute Test---------------------------
            var result = behavior.TestOnMouseDown(null, 1);

            //------------Assert Results-------------------------
            Assert.IsFalse(result);
            eventPublisher.Verify(p => p.Publish(It.IsAny<object>()), Times.Never());
        }
        public void NavigationItemViewModelMouseDownBehavior_OnMouseDown_TreecodeIsNotResourceTreeViewModel_PublishEventsCorrectly()
        {
            //------------Setup for test--------------------------
            var eventPublisher = new Mock<IEventAggregator>();

            var behavior = new TestNavigationItemViewModelMouseDownBehavior(eventPublisher.Object);

            var explorerItemModel = new ExplorerItemModel(new Mock<IStudioResourceRepository>().Object, new Mock<IAsyncWorker>().Object, new Mock<IConnectControlSingleton>().Object);

            //------------Execute Test---------------------------
            var result = behavior.TestOnMouseDown(explorerItemModel, 1);

            //------------Assert Results-------------------------
            Assert.IsTrue(result);
        }
        static void Verify_OnMouseDown_SetActiveEnvironmentOnClick(int publishCount, bool setActiveEnvironmentOnClick)
        {
            //------------Setup for test--------------------------
            var eventPublisher = new Mock<IEventAggregator>();
            eventPublisher.Setup(p => p.Publish(It.IsAny<SetActiveEnvironmentMessage>())).Verifiable();

            var behavior = new TestNavigationItemViewModelMouseDownBehavior(eventPublisher.Object) { SetActiveEnvironmentOnClick = setActiveEnvironmentOnClick };

            var explorerItemModel = new ExplorerItemModel(new Mock<IStudioResourceRepository>().Object, new Mock<IAsyncWorker>().Object, new Mock<IConnectControlSingleton>().Object);

            //------------Execute Test---------------------------
            var result = behavior.TestOnMouseDown(explorerItemModel, 1);

            //------------Assert Results-------------------------
            Assert.IsTrue(result);
            eventPublisher.Verify(p => p.Publish(It.IsAny<SetActiveEnvironmentMessage>()), Times.Exactly(publishCount));
        }
        static void Verify_OnMouseDown_SelectOnRightClick(bool selectOnRightClick)
        {
            //------------Setup for test--------------------------
            var eventPublisher = new Mock<IEventAggregator>();
            var behavior = new TestNavigationItemViewModelMouseDownBehavior(eventPublisher.Object) { SelectOnRightClick = selectOnRightClick };

            var explorerItemModel = new ExplorerItemModel(new Mock<IStudioResourceRepository>().Object, new Mock<IAsyncWorker>().Object, new Mock<IConnectControlSingleton>().Object);

            //------------Execute Test---------------------------
            var result = behavior.TestOnMouseDown(explorerItemModel, 1);

            //------------Assert Results-------------------------
            Assert.IsTrue(result);
            Assert.AreEqual(selectOnRightClick, explorerItemModel.IsExplorerSelected);
        }