public void HandleRightPanelExpandedEventShouldChangeExpandedState()
        {
            var vm = new ActionManagerViewModel();

            Assert.IsFalse(vm.IsExpanded);
            vm.HandleEvent(new RightPanelExpandEvent(true));
            Assert.IsTrue(vm.IsExpanded);
        }
        public void HandleAuthenticationEventShouldReloadActions()
        {
            var vm = new ActionManagerViewModel();

            Mock.Arrange(() => Utils.CurrentUserPersonId).Returns(1);
            Mock.Arrange(() => ActionRetriever.GetActionRetriever(Arg.IsAny<EventHandler<DataPortalResult<ActionRetriever>>>())).IgnoreArguments().DoNothing();
            vm.HandleEvent(new AuthenticationEvent());
            Mock.Assert(() => ActionRetriever.GetActionRetriever(Arg.IsAny<EventHandler<DataPortalResult<ActionRetriever>>>()), Occurs.Once());
        }
        public void PropertiesTest()
        {
            var vm = new ActionManagerViewModel();

            Assert.IsNotNull(vm.ActionItems);
            Assert.IsNotNull(vm.ActionGroups);
            Assert.IsNotNull(vm.SortedGroups);
            Assert.AreSame(vm.ActionGroups, vm.SortedGroups.Source);
            TestsHelper.TestPublicDeclaredPropertiesGetSet(vm, true);
        }
        public void OpenScreenCommandOpensIntegrationEvent()
        {
            // Arrange.
            var actionItem = new ActionItemInfo(
                123,
                Constants.IntegrationEventProcessName,
                "7FA27365-AF0A-4F98-A927-368D21A8175A",
                321,
                "Integration Service Failed",
                "Subject",
                "Message",
                ActionTypes.Assignment,
                "GroupName",
                DateTime.MinValue,
                true,
                true);

            var windowManager = Mock.Create<IShell>(Behavior.Loose);
            var actionManager = new ActionManagerViewModel();
            var integrationEventViewModel = Mock.Create<IIntegrationEventViewModel>(Behavior.Loose);
            var integrationEventViewModelFactory = Mock.Create<IIntegrationEventViewModelFactory>(Behavior.Loose);
            Mock.Arrange(() => integrationEventViewModelFactory.CreateViewModel()).Returns(integrationEventViewModel);

            var viewModel = new ActionItemViewModel { WindowManager = windowManager, IntegrationEventViewModelFactory = integrationEventViewModelFactory };
            viewModel.Initialize(actionItem, actionManager);

            // Act.
            viewModel.OpenScreenCommand.Execute(null);

            // Assert.
            Mock.Assert(() => integrationEventViewModel.LoadEvent(321), Occurs.Once());
            Mock.Assert(() => windowManager.ShowTaskWindow(integrationEventViewModel, true), Occurs.Once());
        }
        public void HandleLogoutEventShouldClearItems()
        {
            var vm = new ActionManagerViewModel();

            vm.ActionItems.Add(new ActionItemViewModel());
            vm.ActionGroups.Add(new ActionGroupViewModel());

            var wasCalled = false;
            Mock.Arrange(() => new DispatcherTimer().Stop()).IgnoreInstance().DoInstead(() => wasCalled = true);
            //Mock.ArrangeSet(() => vm.PropertyChanged += null).IgnoreArguments().OccursOnce();
            vm.HandleEvent(new LogoutEvent());

            Assert.AreEqual(0, vm.ActionItems.Count);
            Assert.AreEqual(0, vm.ActionGroups.Count);
            Assert.IsTrue(wasCalled);

            Mock.AssertAll(vm);
        }
        public void ImportSatisfied_WhenCalled_SetupsNotifications()
        {
            //Assert
            var classUnderTest = new ActionManagerViewModel();
            var mock = Mock.Create<IEventAggregator>();
            classUnderTest.EventAggregator = mock;
            Mock.Arrange(()=>mock.Subscribe<AuthenticationEvent>(Arg.IsAny<IEventSink<AuthenticationEvent>>())).MustBeCalled();
            var notificationServiceMock = Mock.Create<NotificationService>();
            Mock.Arrange(() => notificationServiceMock.SetupNotifications(Arg.IsAny<Action>())).DoNothing();
            classUnderTest.TheNotificationService = notificationServiceMock;

            //Act
            classUnderTest.OnImportsSatisfied();

            //Assert
            mock.AssertAll();
        }
        public void RefreshCommandShouldResetViewModels()
        {
            // Arrange.
            var actionItem = new ActionItemInfo(
                1, "test", Guid.NewGuid().ToString(), 1, "name", "subject", "message", ActionTypes.Approval, "group", DateTime.Now, true, false);
            var actionItemFactory =
                new ExportFactory<ActionItemViewModel>(() => Tuple.Create(new ActionItemViewModel(), new Action(() => { })));
            var actionGroupFactory =
                new ExportFactory<ActionGroupViewModel>(() => Tuple.Create(new ActionGroupViewModel(), new Action(() => { })));

            var vm = new ActionManagerViewModel { ActionItemFactory = actionItemFactory, ActionGroupFactory = actionGroupFactory };

            var actionRetriever = Mock.Create<ActionRetriever>();
            Mock.Arrange(() => actionRetriever.ActionItems).Returns(new[] { actionItem });

            Mock.Arrange(() => ActionRetriever.GetActionRetriever(Arg.IsAny<EventHandler<DataPortalResult<ActionRetriever>>>()))
                .DoInstead<EventHandler<DataPortalResult<ActionRetriever>>>(
                    callback => callback(null, new DataPortalResult<ActionRetriever>(actionRetriever, null, null)));
            Mock.Arrange(() => Utils.CurrentUserPersonId).Returns(1);

            // Load the action items.
            vm.HandleEvent(new AuthenticationEvent());

            // Change some properties to simulate user activity.
            vm.ActionGroups[0].IsExpanded = true;
            vm.ActionGroups[0].ActionItems[0].IsDetailOpen = true;

            // Act.
            vm.RefreshCommand.Execute(true);

            // Assert.
            Assert.IsFalse(vm.ActionGroups[0].IsExpanded);
            Assert.IsFalse(vm.ActionGroups[0].ActionItems[0].IsDetailOpen);
        }
        public void SelectingItemShouldMakeActionOld()
        {
            var vm = new ActionManagerViewModel();
            var item = new ActionItemViewModel();
            var newActionItem = new ActionItemInfo(1, "test", Guid.NewGuid().ToString(), 1, "name", "subj", "message", ActionTypes.Approval, "group", DateTime.Now, true, false);
            var oldActionItem = new ActionItemInfo(1, "test", Guid.NewGuid().ToString(), 1, "name", "subj", "message", ActionTypes.Approval, "group", DateTime.Now, false, false);
            Mock.Arrange(() => item.Model).Returns(newActionItem);

            var cmd = new MarkActionItemOldCommand();
            Mock.Arrange(() => cmd.ActionItemId).Returns(1);
            Mock.Arrange(() => cmd.Result).Returns(oldActionItem);
            Mock.Arrange(() => MarkActionItemOldCommand.BeginExecute(1, Arg.IsAny<EventHandler<DataPortalResult<MarkActionItemOldCommand>>>())).DoInstead((EventHandler<DataPortalResult<MarkActionItemOldCommand>> e) => e(null, new DataPortalResult<MarkActionItemOldCommand>(cmd, null, null)));

            vm.ActionItems.Add(item);
            vm.SelectedAction = item;

            Assert.AreEqual(1, vm.SelectedAction.Model.Id);
            Assert.IsFalse(vm.SelectedAction.IsActionNew);
        }
        public void SelectingItemShouldMakeItemSelectedAndDeselectPrevious()
        {
            var vm = new ActionManagerViewModel();
            var item1 = new ActionItemViewModel();
            var item2 = new ActionItemViewModel();
            var newActionItem = new ActionItemInfo(1, "test", Guid.NewGuid().ToString(), 1, "name", "subj", "message", ActionTypes.Approval, "group", DateTime.Now, true, false);
            Mock.Arrange(() => item2.Model).Returns(newActionItem);

            var cmd = new MarkActionItemOldCommand();
            Mock.Arrange(() => cmd.ActionItemId).Returns(1);
            Mock.Arrange(() => MarkActionItemOldCommand.BeginExecute(1, Arg.IsAny<EventHandler<DataPortalResult<MarkActionItemOldCommand>>>())).DoNothing();

            vm.ActionItems.Add(item1);
            vm.ActionItems.Add(item2);

            vm.SelectedAction = item1;
            Assert.IsTrue(item1.IsSelected);

            vm.SelectedAction = item2;
            Assert.IsFalse(item1.IsSelected);
            Assert.IsTrue(item2.IsSelected);
        }