public void NotifyPropertyChanged_Test()
        {
            var model = new NavigationItemEditMock(123);
            var parentMock = Mock.Create<INavigationGroupViewModel>();
            var target = new NavigationItemViewModel();

            target.Initialize(model, parentMock);
            target.SelectedRoleId = 45;

            TestsHelper.TestPropertyWithNotifyPropertyChanged(target, () => target.CanMoveDown);
            TestsHelper.TestPropertyWithNotifyPropertyChanged(target, () => target.CanMoveUp);
            TestsHelper.TestPropertyWithNotifyPropertyChanged(target, () => target.IsVisible);
            TestsHelper.TestPropertyWithNotifyPropertyChanged(target, () => target.SelectedRoleId);
        }
        public void Initialize_Test()
        {
            var model = new NavigationItemEditMock(123);
            var parentMock = Mock.Create<INavigationGroupViewModel>();
            var target = new NavigationItemViewModel();
            var propertiesChanged = new List<string>();

            target.PropertyChanged += (o, e) => propertiesChanged.Add(e.PropertyName);

            target.Initialize(model, parentMock);

            Assert.AreSame(model, target.Model);
            Assert.AreSame(parentMock, target.Parent);
            Assert.IsTrue(propertiesChanged.Any(p => p == "IsVisible"));
            Assert.IsTrue(propertiesChanged.Any(p => p == "Model"));
            Assert.IsTrue(propertiesChanged.Any(p => p == "Parent"));
        }
        public void IsVisible_Test()
        {
            const int roleId = 123;

            var model = new NavigationItemEditMock(123);
            var parentMock = Mock.Create<INavigationGroupViewModel>();
            var target = new NavigationItemViewModel();

            target.Initialize(model, parentMock);
            target.SelectedRoleId = null;

            Assert.IsFalse(target.IsVisible);

            target.IsVisible = true;

            Assert.IsFalse(target.IsVisible);

            target.SelectedRoleId = roleId;

            Assert.IsFalse(target.IsVisible);

            target.IsVisible = true;

            Assert.IsTrue(target.IsVisible);
            Assert.IsTrue(model.GetCanView(roleId));

            target.SelectedRoleId = null;
            
            Assert.IsFalse(target.IsVisible);

            target.SelectedRoleId = roleId;
            target.IsVisible = false;

            Assert.IsFalse(target.IsVisible);
            Assert.IsFalse(model.GetCanView(roleId));
        }
        public void MoveDownCommand_Test()
        {
            var identityMock = Mock.Create<IMQ1Identity>();
            var principalMock = Mock.Create<IPrincipal>();
            Mock.Arrange(() => principalMock.Identity).Returns(identityMock);
            ApplicationContext.User = principalMock;

            var systemItem = new NavigationItemEditMock(2, "test");
            var item = new NavigationItemEditMock(1);
            var parentMock = Mock.Create<INavigationGroupViewModel>();
            var target = new NavigationItemViewModel();

            // Can't move down any items
            Mock.Arrange(() => identityMock.LicenseType).Returns(LicenseTypes.Viewonly);

            target.CanMoveDown = false;
            target.Initialize(systemItem, parentMock);
            Assert.IsFalse(target.MoveDownCommand.CanExecute(null));
            target.Initialize(item, parentMock);
            Assert.IsFalse(target.MoveDownCommand.CanExecute(null));
            target.CanMoveDown = true;
            target.Initialize(systemItem, parentMock);
            Assert.IsFalse(target.MoveDownCommand.CanExecute(null));
            target.Initialize(item, parentMock);
            Assert.IsFalse(target.MoveDownCommand.CanExecute(null));

            Mock.Arrange(() => identityMock.LicenseType).Returns(LicenseTypes.Concurrent);

            // When CanMoveDown is false, MoveDownCommand.CanExecute returns false.
            target.CanMoveDown = false;

            // Can't move down system item.
            target.Initialize(systemItem, parentMock);
            Assert.IsFalse(target.MoveDownCommand.CanExecute(null));

            // Can't move down simple item.            
            target.Initialize(item, parentMock);
            Assert.IsFalse(target.MoveDownCommand.CanExecute(null));

            // When CanMoveDown is true, can move down only non-system items.
            target.CanMoveDown = true;

            // Can't move down system item.            
            target.Initialize(systemItem, parentMock);
            Assert.IsFalse(target.MoveDownCommand.CanExecute(null));

            // Can move down simple item.
            target.Initialize(item, parentMock);
            Assert.IsTrue(target.MoveDownCommand.CanExecute(null));

            target.CanMoveDown = true;

            target.MoveDownCommand.Execute(null);

            Mock.Assert(() => parentMock.MoveItemDown(target), Occurs.Once());
        }