public void Initialize_Test()
        {
            var model = DataPortal.CreateChild<NavigationGroupEdit>();

            model.NavigationItems.Add(DataPortal.CreateChild<NavigationItemEdit>());
            model.NavigationItems.Add(DataPortal.CreateChild<NavigationItemEdit>()); 
            model.NavigationItems.Add(DataPortal.CreateChild<NavigationItemEdit>());
            model.IconId = 123;

            var parentMock = Mock.Create<INavigationBuilderViewModel>();

            var target = new NavigationGroupViewModelTests
                             {
                                 NavigationItemFactory =
                                     new ExportFactory<INavigationItemViewModel>(
                                     () => new Tuple<INavigationItemViewModel, Action>(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.AreEqual(model.NavigationItems.Count, target.NavigationItems.Count);
            Assert.IsTrue(propertiesChanged.Any(p => p == "IsVisible"));
            Assert.IsTrue(propertiesChanged.Any(p => p == "Model"));
            Assert.IsTrue(propertiesChanged.Any(p => p == "Parent"));
            Assert.IsTrue(propertiesChanged.Any(p => p == "Icon"));
            Assert.IsNotNull(target.Icon);
        }
        public void PropertiesTest()
        {
            var target = new NavigationGroupViewModelTests();

            Assert.IsNotNull(target.NavigationItems);
            TestsHelper.TestPublicPropertiesGetSet(target, x=>target.IsVisible);
        }
        public void NotifyPropertyChanged_Test()
        {
            var model = DataPortal.CreateChild<NavigationGroupEdit>();
            var parentMock = Mock.Create<INavigationBuilderViewModel>();

            var target = new NavigationGroupViewModelTests
                             {
                                 NavigationItemFactory =
                                     new ExportFactory<INavigationItemViewModel>(
                                     () => new Tuple<INavigationItemViewModel, Action>(new NavigationItemViewModel(), () => { }))
                             };

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

            TestsHelper.TestPropertyWithNotifyPropertyChanged(target, () => target.IsExpanded);
            TestsHelper.TestPropertyWithNotifyPropertyChanged(target, () => target.IsVisible);
            TestsHelper.TestPropertyWithNotifyPropertyChanged(target, () => target.CanMoveUp);
            TestsHelper.TestPropertyWithNotifyPropertyChanged(target, () => target.CanMoveDown);
            TestsHelper.TestPropertyWithNotifyPropertyChanged(target, () => target.SelectedRoleId);
            TestsHelper.TestPropertyWithNotifyPropertyChanged(target, () => target.Icon);
        }
        public void AddNewItem_Test()
        {
            var group = DataPortal.CreateChild<NavigationGroupEdit>();

            var parentMock = Mock.Create<INavigationBuilderViewModel>();
            var target = new NavigationGroupViewModelTests
                             {
                                 NavigationItemFactory =
                                     new ExportFactory<INavigationItemViewModel>(
                                     () => new Tuple<INavigationItemViewModel, Action>(new NavigationItemViewModelTest(), () => { }))
                             };

            target.Initialize(group, parentMock);

            target.OnAddedNewItem += (o, args) =>
                                         {
                                             Assert.IsTrue(target.NavigationItems.Last().Model.Name.Equals("Test"));
                                             Assert.IsTrue(target.NavigationItems.Last().Model.SystemName.Equals("Test_p"));
                                         };

            var process = Mock.Create<PublishedProcessInfo>();
            Mock.Arrange(() => process.Name).Returns("Test");
            Mock.Arrange(() => process.SystemName).Returns("Test_p");
            Mock.Arrange(() => process.IconId).Returns(0);
            Mock.Arrange(() => process.ProcessId).Returns(0);

            target.AddItem(process, null, 0);
        }
        public void RemoveCommand_Test()
        {
            var identityMock = Mock.Create<IMQ1Identity>();
            Mock.Arrange(() => identityMock.LicenseType).Returns(LicenseTypes.Viewonly);
            var principalMock = Mock.Create<IPrincipal>();
            Mock.Arrange(() => principalMock.Identity).Returns(identityMock);
            ApplicationContext.User = principalMock;

            var group = DataPortal.CreateChild<NavigationGroupEdit>();
            var systemGroup = DataPortal.CreateChild<NavigationGroupEdit>();
            systemGroup.SystemName = "test";
            var parentMock = Mock.Create<INavigationBuilderViewModel>();

            var target = new NavigationGroupViewModelTests
                             {
                                 NavigationItemFactory =
                                     new ExportFactory<INavigationItemViewModel>(
                                     () => new Tuple<INavigationItemViewModel, Action>(new NavigationItemViewModel(), () => { }))
                             };

            // Can't remove non-system group.
            target.Initialize(group, parentMock);
            Assert.IsFalse(target.RemoveCommand.CanExecute(null));

            // Can remove non-system group.
            Mock.Arrange(() => identityMock.LicenseType).Returns(LicenseTypes.Concurrent);
            target.Initialize(group, parentMock);
            Assert.IsTrue(target.RemoveCommand.CanExecute(null));

            // Can't remove system group.
            target.Initialize(systemGroup, parentMock);
            Assert.IsFalse(target.RemoveCommand.CanExecute(null));

            // Remove group.
            target.Initialize(group, parentMock);
            target.RemoveCommand.Execute(null);

            Mock.Assert(() => parentMock.RemoveGroup(target), Occurs.Once());
        }
        public void MoveDownCommand_Test()
        {
            var identityMock = Mock.Create<IMQ1Identity>();
            var principalMock = Mock.Create<IPrincipal>();
            Mock.Arrange(() => principalMock.Identity).Returns(identityMock);
            ApplicationContext.User = principalMock;

            var group = DataPortal.CreateChild<NavigationGroupEdit>();
            var parentMock = Mock.Create<INavigationBuilderViewModel>();

            var target = new NavigationGroupViewModelTests
                             {
                                 NavigationItemFactory =
                                     new ExportFactory<INavigationItemViewModel>(
                                     () => new Tuple<INavigationItemViewModel, Action>(new NavigationItemViewModel(), () => { }))
                             };

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

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

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

            target.Initialize(group, parentMock);

            target.CanMoveDown = false;
            Assert.IsFalse(target.MoveDownCommand.CanExecute(null));

            target.CanMoveDown = true;
            Assert.IsTrue(target.MoveDownCommand.CanExecute(null));

            target.MoveDownCommand.Execute(null);
            Mock.Assert(() => parentMock.MoveGroupDown(target), Occurs.Once());
        }
        public void IsVisible_Test()
        {
            const int roleId = 123;

            var model = DataPortal.CreateChild<NavigationGroupEdit>();

            var parentMock = Mock.Create<INavigationBuilderViewModel>();

            var target = new NavigationGroupViewModelTests
                             {
                                 NavigationItemFactory =
                                     new ExportFactory<INavigationItemViewModel>(
                                     () => new Tuple<INavigationItemViewModel, Action>(new NavigationItemViewModel(), () => { }))
                             };

            target.Initialize(model, parentMock);

            target.SelectedRoleId = null;
            
            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 WhenSelectedRoleIsChanged_NavigationItemSelectedRoleIsUpdated()
        {
            var model = DataPortal.CreateChild<NavigationGroupEdit>();

            model.NavigationItems.Add(DataPortal.CreateChild<NavigationItemEdit>());
            model.NavigationItems.Add(DataPortal.CreateChild<NavigationItemEdit>());
            model.NavigationItems.Add(DataPortal.CreateChild<NavigationItemEdit>());

            var parentMock = Mock.Create<INavigationBuilderViewModel>();

            var target = new NavigationGroupViewModelTests
                             {
                                 NavigationItemFactory =
                                     new ExportFactory<INavigationItemViewModel>(
                                     () => new Tuple<INavigationItemViewModel, Action>(new NavigationItemViewModel(), () => { }))
                             };

            target.Initialize(model, parentMock);

            Assert.IsTrue(target.NavigationItems.All(ni => ni.SelectedRoleId == target.SelectedRoleId));

            target.SelectedRoleId = 123;

            Assert.IsTrue(target.NavigationItems.All(ni => ni.SelectedRoleId == 123));
        }