public void CheckAddGroupCommandIsExecutable()
        {
            var nb = new NavigationBuilderViewModel();

            var gr = new NavigationGroupViewModel();
            var model = new NavigationGroupEdit { Name = "Name" };
            Mock.Arrange(() => gr.Model).Returns(model);
            Mock.Arrange(() => nb.IsReadOnly).Returns(false);
            
            nb.NavigationGroups.Add(gr);
            nb.NewGroupName = "Name";
            
            var canExecuteCommand = nb.AddGroupCommand.CanExecute(null);
            Assert.IsFalse(canExecuteCommand);
        }
        public void TurnOnItemVisibilityTurnsOnItsGroupVisibility()
        {
            var ng = new NavigationGroupViewModel { SelectedRoleId = 1 };
            Mock.NonPublic.Arrange(ng, "PopulateNavigationItems").DoNothing();

            var groupEdit = new NavigationGroupEdit();
            var groupConfig = new NavigationGroupSecurityConfigurationEdit { RoleId = 1, CanView = false };
            Mock.Arrange(() => groupConfig.IsChild).Returns(true);
            var groupConfigurations = new NavigationGroupSecurityConfigurationList { groupConfig };

            Mock.Arrange(() => groupConfigurations.IsChild).Returns(true);

            Mock.Arrange(() => groupEdit.SecurityConfigurations).Returns(groupConfigurations);
            ng.Initialize(groupEdit, new NavigationBuilderViewModel());

            var items = new ObservableCollection<INavigationItemViewModel>();

            var itemEdit = new NavigationItemEdit();
            var itemConfig = new NavigationItemSecurityConfigurationEdit { RoleId = 1, CanView = true };
            Mock.Arrange(() => itemConfig.IsChild).Returns(true);
            var itemConfigurations = new NavigationItemSecurityConfigurationList { itemConfig };

            Mock.Arrange(() => itemEdit.SecurityConfigurations).Returns(itemConfigurations);

            for (var i = 0; i < 3; i++)
            {
                var item = new NavigationItemViewModel { SelectedRoleId = 1 };
                item.Initialize(itemEdit, ng);
                item.IsVisible = false;
                items.Add(item);
            }

            ng.NavigationItems.AddRange(items);
            ng.IsVisible = false;

            ng.NavigationItems[0].IsVisible = true;

            Assert.IsTrue(ng.IsVisible);
        }
        public void RemoveItem_RemovesNavigationItemAndViewModel()
        {
            var group = DataPortal.CreateChild<NavigationGroupEdit>();

            group.NavigationItems.Add(DataPortal.CreateChild<NavigationItemEdit>());
            group.NavigationItems.Last().Sequence = 23;
            group.NavigationItems.Last().Guid = Guid.Parse("ECC9FC75-121B-4FBC-AEE2-ECBA3E072714");
            group.NavigationItems.Add(DataPortal.CreateChild<NavigationItemEdit>());
            group.NavigationItems.Last().Sequence = 10;
            group.NavigationItems.Last().Guid = Guid.Parse("8A25F14F-046C-4BCE-B3FB-0364F9B48BED");
            group.NavigationItems.Add(DataPortal.CreateChild<NavigationItemEdit>());
            group.NavigationItems.Last().Sequence = 15;
            group.NavigationItems.Last().Guid = Guid.Parse("E198638F-85BB-4EAA-9ECB-9ED5BB8D92F8");

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

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

            target.Initialize(group, parentMock);

            var item = target.NavigationItems[1];

            target.RemoveItem(item);

            Assert.IsFalse(target.NavigationItems.Contains(item));
            Assert.IsFalse(target.Model.NavigationItems.Contains(item.Model));
        }
        public void WhenItemIsLast_MoveItemDown_DoesNothing()
        {
            var group = DataPortal.CreateChild<NavigationGroupEdit>();

            group.NavigationItems.Add(DataPortal.CreateChild<NavigationItemEdit>());
            group.NavigationItems.Last().Sequence = 23;
            group.NavigationItems.Last().Guid = Guid.Parse("ECC9FC75-121B-4FBC-AEE2-ECBA3E072714");
            group.NavigationItems.Add(DataPortal.CreateChild<NavigationItemEdit>());
            group.NavigationItems.Last().Sequence = 10;
            group.NavigationItems.Last().Guid = Guid.Parse("8A25F14F-046C-4BCE-B3FB-0364F9B48BED");
            group.NavigationItems.Add(DataPortal.CreateChild<NavigationItemEdit>());
            group.NavigationItems.Last().Sequence = 15;
            group.NavigationItems.Last().Guid = Guid.Parse("E198638F-85BB-4EAA-9ECB-9ED5BB8D92F8");

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

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

            target.Initialize(group, parentMock);

            var item = target.NavigationItems.Last();
            var items = target.NavigationItems.ToArray();

            target.MoveItemDown(item);

            Assert.IsTrue(items.SequenceEqual(target.NavigationItems));
            Assert.IsTrue(target.NavigationItems.Select(ni => ni.Model.Sequence).SequenceEqual(target.NavigationItems.Select(ni => ni.Model.Sequence).OrderBy(s => s)));
        }
        public void Initialize_Updates_IsReadOnly()
        {
            var group = DataPortal.CreateChild<NavigationGroupEdit>();

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

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

            var readOnlyPropertyHasChanged = false;

            var identityMock = Mock.Create<IMQ1Identity>();
            Mock.Arrange(() => identityMock.LicenseType).Returns(LicenseTypes.Concurrent);
            var principalMock = Mock.Create<IPrincipal>();
            Mock.Arrange(() => principalMock.Identity).Returns(identityMock);
            ApplicationContext.User = principalMock;

            Assert.IsFalse(target.IsReadOnly);

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

            target.PropertyChanged += (sender, args) =>
                {
                    if (args.PropertyName.Equals("IsReadOnly")) readOnlyPropertyHasChanged = true;
                };

            Assert.IsFalse(readOnlyPropertyHasChanged);

            target.Initialize(group, parentMock);

            Assert.IsTrue(readOnlyPropertyHasChanged);
            Assert.IsTrue(target.IsReadOnly);
        }
        public void Initialize_Updates_NavigationItems()
        {
            var group = DataPortal.CreateChild<NavigationGroupEdit>();

            group.NavigationItems.Add(DataPortal.CreateChild<NavigationItemEdit>());
            group.NavigationItems.Last().Sequence = 23;
            group.NavigationItems.Last().Guid = Guid.Parse("ECC9FC75-121B-4FBC-AEE2-ECBA3E072714");
            group.NavigationItems.Add(DataPortal.CreateChild<NavigationItemEdit>());
            group.NavigationItems.Last().Sequence = 10;
            group.NavigationItems.Last().Guid = Guid.Parse("8A25F14F-046C-4BCE-B3FB-0364F9B48BED");
            group.NavigationItems.Add(DataPortal.CreateChild<NavigationItemEdit>());
            group.NavigationItems.Last().Sequence = 15;
            group.NavigationItems.Last().Guid = Guid.Parse("E198638F-85BB-4EAA-9ECB-9ED5BB8D92F8");

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

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

            target.Initialize(group, parentMock);

            Assert.AreEqual(3, target.NavigationItems.Count);
            Assert.IsTrue(target.NavigationItems.Select(ni => ni.Model.Guid).SequenceEqual(group.NavigationItems.OrderBy(ni => ni.Sequence).Select(ni => ni.Guid)));
            // Remove one item.
            group.NavigationItems.RemoveAt(1);

            // Add one item.
            group.NavigationItems.Add(DataPortal.CreateChild<NavigationItemEdit>());
            group.NavigationItems.Last().Sequence = 123;
            group.NavigationItems.Last().Guid = Guid.Parse("8C0BE64E-A382-4EA2-907E-D7054FE80DE3");

            target.Initialize(group, parentMock);

            Assert.AreEqual(3, target.NavigationItems.Count);
            Assert.IsTrue(target.NavigationItems.Select(ni => ni.Model.Guid).SequenceEqual(group.NavigationItems.OrderBy(ni => ni.Sequence).Select(ni => ni.Guid)));
        }
        public void Initialize_Creates_SortedNavigationItemList()
        {
            var group = DataPortal.CreateChild<NavigationGroupEdit>();

            group.NavigationItems.Add(DataPortal.CreateChild<NavigationItemEdit>());
            group.NavigationItems.Last().Sequence = 23;
            group.NavigationItems.Add(DataPortal.CreateChild<NavigationItemEdit>());
            group.NavigationItems.Last().Sequence = 10;
            group.NavigationItems.Add(DataPortal.CreateChild<NavigationItemEdit>());
            group.NavigationItems.Last().Sequence = 15;
            group.NavigationItems.Add(DataPortal.CreateChild<NavigationItemEdit>());
            group.NavigationItems.Last().Sequence = 30;
            group.NavigationItems.Add(DataPortal.CreateChild<NavigationItemEdit>());
            group.NavigationItems.Last().Sequence = 25;

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

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

            target.Initialize(group, parentMock);

            Assert.AreEqual(group.NavigationItems.Count, target.NavigationItems.Count);
            Assert.IsTrue(target.NavigationItems.Select(ni => ni.Model.Sequence).SequenceEqual(group.NavigationItems.Select(ni => ni.Sequence).OrderBy(s => s)));

            // Remove some items.
            group.NavigationItems.RemoveAt(1);
            group.NavigationItems.RemoveAt(2);

            // Add some new items.
            group.NavigationItems.Add(DataPortal.CreateChild<NavigationItemEdit>());
            group.NavigationItems.Last().Sequence = 49;
            group.NavigationItems.Add(DataPortal.CreateChild<NavigationItemEdit>());
            group.NavigationItems.Last().Sequence = 11;

            target.Initialize(group, parentMock);

            Assert.AreEqual(group.NavigationItems.Count, target.NavigationItems.Count);
        }